• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/// <reference path='./import.ts' />
17class RichEditorEnableDataDetectorModifier extends ModifierWithKey<boolean> {
18  constructor(value: boolean) {
19    super(value);
20  }
21  static identity: Symbol = Symbol('richEditorEnableDataDetector');
22  applyPeer(node: KNode, reset: boolean): void {
23    if (reset) {
24      getUINativeModule().richEditor.resetEnableDataDetector(node);
25    } else {
26      getUINativeModule().richEditor.setEnableDataDetector(node, this.value!);
27    }
28  }
29  checkObjectDiff(): boolean {
30    return !isBaseOrResourceEqual(this.stageValue, this.value);
31  }
32}
33
34class RichEditorDataDetectorConfigModifier extends ModifierWithKey<TextDataDetectorConfig> {
35  constructor(value: TextDataDetectorConfig) {
36    super(value);
37  }
38  static identity: Symbol = Symbol('richEditorDataDetectorConfig');
39  applyPeer(node: KNode, reset: boolean): void {
40    if (reset) {
41      getUINativeModule().richEditor.resetDataDetectorConfig(node);
42    } else {
43      getUINativeModule().richEditor.setDataDetectorConfig(node, this.value.types, this.value.onDetectResultUpdate);
44    }
45  }
46  checkObjectDiff(): boolean {
47    return !isBaseOrResourceEqual(this.stageValue.types, this.value.types) ||
48    !isBaseOrResourceEqual(this.stageValue.onDetectResultUpdate, this.value.onDetectResultUpdate);
49  }
50}
51
52class RichEditorOnIMEInputCompleteModifier extends ModifierWithKey<(value:RichEditorTextSpanResult) => void> {
53  constructor(value: (value:RichEditorTextSpanResult) => void) {
54    super(value);
55  }
56  static identity = Symbol('richEditorOnIMEInputComplete');
57  applyPeer(node: KNode, reset: boolean): void {
58    if (reset) {
59      getUINativeModule().richEditor.resetOnIMEInputComplete(node);
60    } else {
61      getUINativeModule().richEditor.setOnIMEInputComplete(node, this.value);
62    }
63  }
64}
65
66class RichEditorCopyOptionsModifier extends ModifierWithKey<CopyOptions> {
67  constructor(value: CopyOptions) {
68    super(value);
69  }
70  static identity: Symbol = Symbol('richEditorCopyOptions');
71  applyPeer(node: KNode, reset: boolean): void {
72    if (reset) {
73      getUINativeModule().richEditor.resetCopyOptions(node);
74    } else {
75      getUINativeModule().richEditor.setCopyOptions(node, this.value!);
76    }
77  }
78  checkObjectDiff(): boolean {
79    return this.stageValue !== this.value;
80  }
81}
82
83class RichEditorSelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
84  constructor(value: ResourceColor) {
85    super(value);
86  }
87  static identity: Symbol = Symbol('richEditorSelectedBackgroundColor');
88  applyPeer(node: KNode, reset: boolean): void {
89    if (reset) {
90      getUINativeModule().richEditor.resetSelectedBackgroundColor(node);
91    } else {
92      getUINativeModule().richEditor.setSelectedBackgroundColor(node, this.value!);
93    }
94  }
95  checkObjectDiff(): boolean {
96    return this.stageValue !== this.value;
97  }
98}
99
100class RichEditorOnSelectionChangeModifier extends ModifierWithKey<(value: RichEditorRange) => void> {
101  constructor(value: (value: RichEditorRange) => void) {
102    super(value);
103  }
104  static identity = Symbol('richEditorOnSelectionChange');
105  applyPeer(node: KNode, reset: boolean): void {
106    if (reset) {
107      getUINativeModule().richEditor.resetOnSelectionChange(node);
108    } else {
109      getUINativeModule().richEditor.setOnSelectionChange(node, this.value);
110    }
111  }
112}
113
114class RichEditorCaretColorModifier extends ModifierWithKey<ResourceColor> {
115  constructor(value: ResourceColor) {
116    super(value);
117  }
118  static identity: Symbol = Symbol('richEditorCaretColor');
119  applyPeer(node: KNode, reset: boolean): void {
120    if (reset) {
121      getUINativeModule().richEditor.resetCaretColor(node);
122    } else {
123      getUINativeModule().richEditor.setCaretColor(node, this.value!);
124    }
125  }
126  checkObjectDiff(): boolean {
127    return this.stageValue !== this.value;
128  }
129}
130
131class RichEditorOnSelectModifier extends ModifierWithKey<(value: RichEditorSelection) => void> {
132  constructor(value: (value: RichEditorSelection) => void) {
133    super(value);
134  }
135  static identity = Symbol('richEditorOnSelect');
136  applyPeer(node: KNode, reset: boolean): void {
137    if (reset) {
138      getUINativeModule().richEditor.resetOnSelect(node);
139    } else {
140      getUINativeModule().richEditor.setOnSelect(node, this.value);
141    }
142  }
143}
144
145class RichEditorOnSubmitModifier extends ModifierWithKey<SubmitCallback> {
146  constructor(value: SubmitCallback) {
147    super(value);
148  }
149  static identity: Symbol = Symbol('richEditorOnSubmit');
150  applyPeer(node: KNode, reset: boolean): void {
151    if (reset) {
152      getUINativeModule().richEditor.resetOnSubmit(node);
153    } else {
154      getUINativeModule().richEditor.setOnSubmit(node, this.value);
155    }
156  }
157}
158
159class RichEditorAboutToIMEInputModifier extends ModifierWithKey<(value: RichEditorInsertValue) => boolean> {
160  constructor(value: (value: RichEditorInsertValue) => boolean) {
161    super(value);
162  }
163  static identity = Symbol('richEditorAboutToIMEInput');
164  applyPeer(node: KNode, reset: boolean): void {
165    if (reset) {
166      getUINativeModule().richEditor.resetAboutToIMEInput(node);
167    } else {
168      getUINativeModule().richEditor.setAboutToIMEInput(node, this.value);
169    }
170  }
171}
172
173class RichEditorOnWillChangeModifier extends ModifierWithKey<(value: RichEditorChangeValue) => boolean> {
174  constructor(value: (value: RichEditorChangeValue) => boolean) {
175    super(value);
176  }
177  static identity = Symbol('richEditorOnWillChange');
178  applyPeer(node: KNode, reset: boolean): void {
179    if (reset) {
180      getUINativeModule().richEditor.resetOnWillChange(node);
181    } else {
182      getUINativeModule().richEditor.setOnWillChange(node, this.value);
183    }
184  }
185}
186
187class RichEditorOnDidChangeModifier extends ModifierWithKey<OnDidChangeCallback> {
188  constructor(value: OnDidChangeCallback) {
189    super(value);
190  }
191  static identity = Symbol('richEditorOnDidChange');
192  applyPeer(node: KNode, reset: boolean): void {
193    if (reset) {
194      getUINativeModule().richEditor.resetOnDidChange(node);
195    } else {
196      getUINativeModule().richEditor.setOnDidChange(node, this.value);
197    }
198  }
199}
200
201class RichEditorPlaceholderModifier extends ModifierWithKey<ArkPlaceholder> {
202  constructor(value: ArkPlaceholder) {
203    super(value);
204  }
205  static identity = Symbol('richEditorPlaceholder');
206  applyPeer(node: KNode, reset: boolean): void {
207    if (reset) {
208      getUINativeModule().richEditor.resetPlaceholder(node);
209    } else {
210      getUINativeModule().richEditor.setPlaceholder(node, this.value.value, this.value.style);
211    }
212  }
213  checkObjectDiff(): boolean {
214    return !(this.stageValue as ArkPlaceholder).isEqual(this.value as ArkPlaceholder);
215  }
216}
217
218class RichEditorAboutToDeleteModifier extends ModifierWithKey<(value: RichEditorDeleteValue) => boolean> {
219  constructor(value: (value: RichEditorDeleteValue) => boolean) {
220    super(value);
221  }
222  static identity = Symbol('richEditorAboutToDelete');
223  applyPeer(node: KNode, reset: boolean): void {
224    if (reset) {
225      getUINativeModule().richEditor.resetAboutToDelete(node);
226    } else {
227      getUINativeModule().richEditor.setAboutToDelete(node, this.value);
228    }
229  }
230}
231
232class RichEditorOnReadyModifier extends ModifierWithKey<() => void> {
233  constructor(value: () => void) {
234    super(value);
235  }
236  static identity = Symbol('richEditorOnReady');
237  applyPeer(node: KNode, reset: boolean): void {
238    if (reset) {
239      getUINativeModule().richEditor.resetOnReady(node);
240    } else {
241      getUINativeModule().richEditor.setOnReady(node, this.value);
242    }
243  }
244}
245
246class RichEditorOnDeleteCompleteModifier extends ModifierWithKey<() => void> {
247  constructor(value: () => void) {
248    super(value);
249  }
250  static identity = Symbol('richEditorOnDeleteComplete');
251  applyPeer(node: KNode, reset: boolean): void {
252    if (reset) {
253      getUINativeModule().richEditor.resetOnDeleteComplete(node);
254    } else {
255      getUINativeModule().richEditor.setOnDeleteComplete(node, this.value);
256    }
257  }
258}
259
260class RichEditorOnEditingChangeModifier extends ModifierWithKey<(value: boolean) => void> {
261  constructor(value: (value: boolean) => void) {
262    super(value);
263  }
264  static identity = Symbol('richEditorOnEditingChange');
265  applyPeer(node: KNode, reset: boolean): void {
266    if (reset) {
267      getUINativeModule().richEditor.resetEditingChange(node);
268    } else {
269      getUINativeModule().richEditor.setEditingChange(node, this.value);
270    }
271  }
272}
273
274class RichEditorOnPasteModifier extends ModifierWithKey<(event?: PasteEvent) => void> {
275  constructor(value: (event?: PasteEvent) => void) {
276    super(value);
277  }
278  static identity = Symbol('richEditorOnPaste');
279  applyPeer(node: KNode, reset: boolean): void {
280    if (reset) {
281      getUINativeModule().richEditor.resetOnPaste(node);
282    } else {
283      getUINativeModule().richEditor.setOnPaste(node, this.value);
284    }
285  }
286}
287
288class RichEditorOnCutModifier extends ModifierWithKey<Callback<CutEvent>> {
289  constructor(value: Callback<CutEvent>) {
290    super(value);
291  }
292  static identity = Symbol('richEditorOnCut');
293  applyPeer(node: KNode, reset: boolean): void {
294    if (reset) {
295      getUINativeModule().richEditor.resetOnCut(node);
296    } else {
297      getUINativeModule().richEditor.setOnCut(node, this.value);
298    }
299  }
300}
301
302class RichEditorOnCopyModifier extends ModifierWithKey<Callback<CopyEvent>> {
303  constructor(value: Callback<CopyEvent>) {
304    super(value);
305  }
306  static identity = Symbol('richEditorOnCopy');
307  applyPeer(node: KNode, reset: boolean): void {
308    if (reset) {
309      getUINativeModule().richEditor.resetOnCopy(node);
310    } else {
311      getUINativeModule().richEditor.setOnCopy(node, this.value);
312    }
313  }
314}
315
316class RichEditorEnterKeyTypeModifier extends ModifierWithKey<EnterKeyType> {
317  constructor(value: EnterKeyType) {
318    super(value);
319  }
320  static identity: Symbol = Symbol('richEditorEnterKeyType');
321  applyPeer(node: KNode, reset: boolean): void {
322    if (reset) {
323      getUINativeModule().richEditor.resetEnterKeyType(node);
324    } else {
325      getUINativeModule().richEditor.setEnterKeyType(node, this.value!);
326    }
327  }
328  checkObjectDiff(): boolean {
329    return this.stageValue !== this.value;
330  }
331}
332
333class RichEditorEnableKeyboardOnFocusModifier extends ModifierWithKey<boolean> {
334  constructor(value: boolean) {
335    super(value);
336  }
337  static identity = Symbol('richEditorEnableKeyboardOnFocus');
338  applyPeer(node: KNode, reset: boolean): void {
339    if (reset) {
340      getUINativeModule().richEditor.resetEnableKeyboardOnFocus(node);
341    } else {
342      getUINativeModule().richEditor.setEnableKeyboardOnFocus(node, this.value);
343    }
344  }
345}
346
347class RichEditorEnablePreviewTextModifier extends ModifierWithKey<boolean> {
348  constructor(value: boolean) {
349    super(value);
350  }
351  static identity = Symbol('richEditorEnablePreviewText');
352  applyPeer(node: KNode, reset: boolean): void {
353    if (reset) {
354      getUINativeModule().richEditor.resetEnablePreviewText(node);
355    } else {
356      getUINativeModule().richEditor.setEnablePreviewText(node, this.value);
357    }
358  }
359}
360
361class RichEditorEditMenuOptionsModifier extends ModifierWithKey<EditMenuOptions> {
362  constructor(value: EditMenuOptions) {
363    super(value);
364  }
365  static identity: Symbol = Symbol('richEditorEditMenuOptions');
366  applyPeer(node: KNode, reset: boolean): void {
367    if (reset) {
368      getUINativeModule().richEditor.resetEditMenuOptions(node);
369    } else {
370      getUINativeModule().richEditor.setEditMenuOptions(node, this.value);
371    }
372  }
373}
374
375class RichEditorBarStateModifier extends ModifierWithKey<BarState> {
376  constructor(value: BarState) {
377    super(value);
378  }
379  static identity: Symbol = Symbol('richEditorBarState');
380  applyPeer(node: KNode, reset: boolean): void {
381    if (reset) {
382      getUINativeModule().richEditor.resetBarState(node);
383    } else {
384      getUINativeModule().richEditor.setBarState(node, this.value);
385    }
386  }
387}
388
389class RichEditorMaxLengthModifier extends ModifierWithKey<number> {
390  constructor(value: number) {
391    super(value);
392  }
393  static identity: Symbol = Symbol('richEditorMaxLength');
394  applyPeer(node: KNode, reset: boolean): void {
395    if (reset) {
396      getUINativeModule().richEditor.resetMaxLength(node);
397    } else {
398      getUINativeModule().richEditor.setMaxLength(node, this.value!);
399    }
400  }
401  checkObjectDiff(): boolean {
402    return !isBaseOrResourceEqual(this.stageValue, this.value);
403  }
404}
405
406class RichEditorMaxLinesModifier extends ModifierWithKey<number | undefined> {
407  constructor(value: number | undefined) {
408    super(value);
409  }
410  static identity: Symbol = Symbol('richEditorMaxLines');
411  applyPeer(node: KNode, reset: boolean): void {
412    if (reset) {
413      getUINativeModule().richEditor.resetMaxLines(node);
414    } else {
415      getUINativeModule().richEditor.setMaxLines(node, this.value!);
416    }
417  }
418  checkObjectDiff(): boolean {
419    return !isBaseOrResourceEqual(this.stageValue, this.value);
420  }
421}
422
423class ArkRichEditorComponent extends ArkComponent implements CommonMethod<RichEditorAttribute> {
424  constructor(nativePtr: KNode, classType?: ModifierType) {
425    super(nativePtr, classType);
426  }
427  enableDataDetector(value: boolean): RichEditorAttribute {
428    modifierWithKey(this._modifiersWithKeys, RichEditorEnableDataDetectorModifier.identity, RichEditorEnableDataDetectorModifier, value);
429    return this;
430  }
431
432  dataDetectorConfig(config: TextDataDetectorConfig): this {
433    let detectorConfig = new TextDataDetectorConfig();
434    detectorConfig.types = config.types;
435    detectorConfig.onDetectResultUpdate = config.onDetectResultUpdate;
436    modifierWithKey(this._modifiersWithKeys, RichEditorDataDetectorConfigModifier.identity, RichEditorDataDetectorConfigModifier, detectorConfig);
437    return this;
438  }
439
440  copyOptions(value: CopyOptions): RichEditorAttribute {
441    modifierWithKey(this._modifiersWithKeys, RichEditorCopyOptionsModifier.identity, RichEditorCopyOptionsModifier, value);
442    return this;
443  }
444
445  caretColor(value: ResourceColor): RichEditorAttribute {
446    modifierWithKey(this._modifiersWithKeys, RichEditorCaretColorModifier.identity, RichEditorCaretColorModifier, value);
447    return this;
448  }
449
450  selectedBackgroundColor(value: ResourceColor): RichEditorAttribute {
451    modifierWithKey(this._modifiersWithKeys, RichEditorSelectedBackgroundColorModifier.identity, RichEditorSelectedBackgroundColorModifier, value);
452    return this;
453  }
454
455  onPaste(callback: (event?: PasteEvent) => void): RichEditorAttribute {
456    modifierWithKey(this._modifiersWithKeys, RichEditorOnPasteModifier.identity, RichEditorOnPasteModifier, callback);
457    return this;
458  }
459
460  onReady(callback: () => void): RichEditorAttribute {
461    modifierWithKey(this._modifiersWithKeys, RichEditorOnReadyModifier.identity, RichEditorOnReadyModifier, callback);
462    return this;
463  }
464  onSelect(callback: (value: RichEditorSelection) => void): RichEditorAttribute {
465    modifierWithKey(this._modifiersWithKeys, RichEditorOnSelectModifier.identity, RichEditorOnSelectModifier, callback);
466    return this;
467  }
468  onSubmit(callback: SubmitCallback): RichEditorAttribute {
469    modifierWithKey(this._modifiersWithKeys, RichEditorOnSubmitModifier.identity, RichEditorOnSubmitModifier, callback);
470    return this;
471  }
472  onSelectionChange(callback: (value: RichEditorRange) => void): RichEditorAttribute {
473    modifierWithKey(this._modifiersWithKeys, RichEditorOnSelectionChangeModifier.identity, RichEditorOnSelectionChangeModifier, callback);
474    return this;
475  }
476  aboutToIMEInput(callback: (value: RichEditorInsertValue) => boolean): RichEditorAttribute {
477    modifierWithKey(this._modifiersWithKeys, RichEditorAboutToIMEInputModifier.identity, RichEditorAboutToIMEInputModifier, callback);
478    return this;
479  }
480  onIMEInputComplete(callback: (value: RichEditorTextSpanResult) => void): RichEditorAttribute {
481    modifierWithKey(this._modifiersWithKeys, RichEditorOnIMEInputCompleteModifier.identity, RichEditorOnIMEInputCompleteModifier, callback);
482    return this;
483  }
484  onWillChange(callback: (value: RichEditorChangeValue) => boolean): RichEditorAttribute {
485    modifierWithKey(this._modifiersWithKeys, RichEditorOnWillChangeModifier.identity, RichEditorOnWillChangeModifier, callback);
486    return this;
487  }
488  onDidChange(callback: OnDidChangeCallback): RichEditorAttribute {
489    modifierWithKey(this._modifiersWithKeys, RichEditorOnDidChangeModifier.identity, RichEditorOnDidChangeModifier, callback);
490    return this;
491  }
492  placeholder(value: ResourceStr, style?: PlaceholderStyle): RichEditorAttribute {
493    let placeholder: ArkPlaceholder = new ArkPlaceholder();
494    placeholder.value = value;
495    placeholder.style = style;
496    modifierWithKey(this._modifiersWithKeys, RichEditorPlaceholderModifier.identity, RichEditorPlaceholderModifier, placeholder);
497    return this;
498  }
499  aboutToDelete(callback: (value: RichEditorDeleteValue) => boolean): RichEditorAttribute {
500    modifierWithKey(this._modifiersWithKeys, RichEditorAboutToDeleteModifier.identity, RichEditorAboutToDeleteModifier, callback);
501    return this;
502  }
503  onDeleteComplete(callback: () => void): RichEditorAttribute {
504    modifierWithKey(this._modifiersWithKeys, RichEditorOnDeleteCompleteModifier.identity, RichEditorOnDeleteCompleteModifier, callback);
505    return this;
506  }
507  bindSelectionMenu(spanType: RichEditorSpanType, content: CustomBuilder, responseType: ResponseType, options?: SelectionMenuOptions): RichEditorAttribute {
508    throw new Error('Method not implemented.');
509  }
510  customKeyboard(value: CustomBuilder): RichEditorAttribute {
511    throw new Error('Method not implemented.');
512  }
513  onEditingChange(callback: (value: boolean) => void): RichEditorAttribute {
514    modifierWithKey(this._modifiersWithKeys, RichEditorOnEditingChangeModifier.identity, RichEditorOnEditingChangeModifier, callback);
515    return this;
516  }
517  onCut(callback: Callback<CutEvent>): RichEditorAttribute {
518    modifierWithKey(this._modifiersWithKeys, RichEditorOnCutModifier.identity, RichEditorOnCutModifier, callback);
519    return this;
520  }
521  onCopy(callback: Callback<CopyEvent>): RichEditorAttribute {
522    modifierWithKey(this._modifiersWithKeys, RichEditorOnCopyModifier.identity, RichEditorOnCopyModifier, callback);
523    return this;
524  }
525  enterKeyType(value: EnterKeyType): RichEditorAttribute {
526    modifierWithKey(this._modifiersWithKeys, RichEditorEnterKeyTypeModifier.identity, RichEditorEnterKeyTypeModifier, value);
527    return this;
528  }
529  enableKeyboardOnFocus(value: boolean): RichEditorAttribute {
530    modifierWithKey(this._modifiersWithKeys, RichEditorEnableKeyboardOnFocusModifier.identity, RichEditorEnableKeyboardOnFocusModifier, value);
531    return this;
532  }
533  enablePreviewText(value: boolean): RichEditorAttribute {
534    modifierWithKey(this._modifiersWithKeys, RichEditorEnablePreviewTextModifier.identity, RichEditorEnablePreviewTextModifier, value);
535    return this;
536  }
537  editMenuOptions(value: EditMenuOptions): RichEditorAttribute {
538    modifierWithKey(this._modifiersWithKeys, RichEditorEditMenuOptionsModifier.identity, RichEditorEditMenuOptionsModifier, value);
539    return this;
540  }
541  barState(value: BarState): RichEditorAttribute {
542    modifierWithKey(this._modifiersWithKeys, RichEditorBarStateModifier.identity, RichEditorBarStateModifier, value);
543    return this;
544  }
545  maxLength(value: number): RichEditorAttribute {
546    modifierWithKey(this._modifiersWithKeys, RichEditorMaxLengthModifier.identity, RichEditorMaxLengthModifier, value);
547    return this;
548  }
549  maxLines(value: number): RichEditorAttribute {
550    modifierWithKey(this._modifiersWithKeys, RichEditorMaxLinesModifier.identity, RichEditorMaxLinesModifier, value);
551    return this;
552  }
553}
554
555// @ts-ignore
556globalThis.RichEditor.attributeModifier = function (modifier: ArkComponent): void {
557  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
558    return new ArkRichEditorComponent(nativePtr);
559  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
560    return new modifierJS.RichEditorModifier(nativePtr, classType);
561  });
562};
563