• 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 ArkAlphabetIndexerComponent extends ArkComponent implements AlphabetIndexerAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  onSelected(callback: (index: number) => void): this {
22    throw new Error('Method not implemented.');
23  }
24  color(value: ResourceColor): this {
25    modifierWithKey(this._modifiersWithKeys, ColorModifier.identity, ColorModifier, value);
26    return this;
27  }
28  selectedColor(value: ResourceColor): this {
29    modifierWithKey(this._modifiersWithKeys, SelectedColorModifier.identity, SelectedColorModifier, value);
30    return this;
31  }
32  popupColor(value: ResourceColor): this {
33    modifierWithKey(this._modifiersWithKeys, PopupColorModifier.identity, PopupColorModifier, value);
34    return this;
35  }
36  selectedBackgroundColor(value: ResourceColor): this {
37    modifierWithKey(this._modifiersWithKeys, SelectedBackgroundColorModifier.identity, SelectedBackgroundColorModifier, value);
38    return this;
39  }
40  popupBackground(value: ResourceColor): this {
41    modifierWithKey(this._modifiersWithKeys, PopupBackgroundModifier.identity, PopupBackgroundModifier, value);
42    return this;
43  }
44  popupSelectedColor(value: ResourceColor): this {
45    modifierWithKey(this._modifiersWithKeys, PopupSelectedColorModifier.identity, PopupSelectedColorModifier, value);
46    return this;
47  }
48  popupUnselectedColor(value: ResourceColor): this {
49    modifierWithKey(this._modifiersWithKeys, PopupUnselectedColorModifier.identity, PopupUnselectedColorModifier, value);
50    return this;
51  }
52  popupItemBackgroundColor(value: ResourceColor): this {
53    modifierWithKey(this._modifiersWithKeys, PopupItemBackgroundColorModifier.identity, PopupItemBackgroundColorModifier, value);
54    return this;
55  }
56  usingPopup(value: boolean): this {
57    modifierWithKey(this._modifiersWithKeys, UsingPopupModifier.identity, UsingPopupModifier, value);
58    return this;
59  }
60  selectedFont(value: Font): this {
61    modifierWithKey(this._modifiersWithKeys, SelectedFontModifier.identity, SelectedFontModifier, value);
62    return this;
63  }
64  popupFont(value: Font): this {
65    modifierWithKey(this._modifiersWithKeys, PopupFontModifier.identity, PopupFontModifier, value);
66    return this;
67  }
68  popupItemFont(value: Font): this {
69    modifierWithKey(this._modifiersWithKeys, PopupItemFontModifier.identity, PopupItemFontModifier, value);
70    return this;
71  }
72  itemSize(value: string | number): this {
73    modifierWithKey(this._modifiersWithKeys, ItemSizeModifier.identity, ItemSizeModifier, value);
74    return this;
75  }
76  font(value: Font): this {
77    modifierWithKey(this._modifiersWithKeys, AlphabetIndexerFontModifier.identity, AlphabetIndexerFontModifier, value);
78    return this;
79  }
80  alignStyle(value: IndexerAlign, offset?: any): this {
81    let alignStyle = new ArkAlignStyle;
82    alignStyle.indexerAlign = value;
83    alignStyle.offset = offset;
84    modifierWithKey(this._modifiersWithKeys, AlignStyleModifier.identity, AlignStyleModifier, alignStyle);
85    return this;
86  }
87  onSelect(callback: (index: number) => void): this {
88    throw new Error('Method not implemented.');
89  }
90  onRequestPopupData(callback: (index: number) => string[]): this {
91    throw new Error('Method not implemented.');
92  }
93  onPopupSelect(callback: (index: number) => void): this {
94    throw new Error('Method not implemented.');
95  }
96  selected(index: number): this {
97    modifierWithKey(this._modifiersWithKeys, AlphabetIndexerSelectedModifier.identity, AlphabetIndexerSelectedModifier, index);
98    return this;
99  }
100  popupPosition(value: Position): this {
101    modifierWithKey(this._modifiersWithKeys, PopupPositionModifier.identity, PopupPositionModifier, value);
102    return this;
103  }
104  popupItemBorderRadius(value: number): this {
105    modifierWithKey(this._modifiersWithKeys, PopupItemBorderRadiusModifier.identity, PopupItemBorderRadiusModifier, value);
106    return this;
107  }
108  itemBorderRadius(value: number): this {
109    modifierWithKey(this._modifiersWithKeys, ItemBorderRadiusModifier.identity, ItemBorderRadiusModifier, value);
110    return this;
111  }
112  popupBackgroundBlurStyle(value: BlurStyle): this {
113    modifierWithKey(this._modifiersWithKeys, PopupBackgroundBlurStyleModifier.identity, PopupBackgroundBlurStyleModifier, value);
114    return this;
115  }
116  popupTitleBackground(value: ResourceColor): this {
117    modifierWithKey(this._modifiersWithKeys, PopupTitleBackgroundModifier.identity, PopupTitleBackgroundModifier, value);
118    return this;
119  }
120  width(value: Length): this {
121    modifierWithKey(this._modifiersWithKeys, AdaptiveWidthModifier.identity, AdaptiveWidthModifier, value);
122    return this;
123  }
124  autoCollapse(value: boolean): this {
125    modifierWithKey(this._modifiersWithKeys, AutoCollapseModifier.identity, AutoCollapseModifier, value);
126    return this;
127  }
128  enableHapticFeedback(value: boolean): this {
129    modifierWithKey(this._modifiersWithKeys, EnableHapticFeedbackModifier.identity, EnableHapticFeedbackModifier, value);
130    return this;
131  }
132}
133// @ts-ignore
134globalThis.AlphabetIndexer.attributeModifier = function (modifier: ArkComponent): void {
135  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
136    return new ArkAlphabetIndexerComponent(nativePtr);
137  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
138    return new modifierJS.AlphabetIndexerModifier(nativePtr, classType);
139  });
140};
141
142class PopupItemFontModifier extends ModifierWithKey<Font> {
143  constructor(value: Font) {
144    super(value);
145  }
146  static identity: Symbol = Symbol('popupItemFont');
147  applyPeer(node: KNode, reset: boolean) {
148    if (reset) {
149      getUINativeModule().alphabetIndexer.resetPopupItemFont(node);
150    } else {
151      getUINativeModule().alphabetIndexer.setPopupItemFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
152    }
153  }
154
155  checkObjectDiff(): boolean {
156    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
157    let weightEQ = this.stageValue.weight === this.value.weight;
158    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
159    let styleEQ = this.stageValue.style === this.value.style;
160    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
161  }
162}
163
164class SelectedFontModifier extends ModifierWithKey<Font> {
165  constructor(value: Font) {
166    super(value);
167  }
168  static identity: Symbol = Symbol('alphaBetIndexerSelectedFont');
169  applyPeer(node: KNode, reset: boolean) {
170    if (reset) {
171      getUINativeModule().alphabetIndexer.resetSelectedFont(node);
172    } else {
173      getUINativeModule().alphabetIndexer.setSelectedFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
174    }
175  }
176
177  checkObjectDiff(): boolean {
178    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
179    let weightEQ = this.stageValue.weight === this.value.weight;
180    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
181    let styleEQ = this.stageValue.style === this.value.style;
182    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
183  }
184}
185
186class PopupFontModifier extends ModifierWithKey<Font> {
187  constructor(value: Font) {
188    super(value);
189  }
190  static identity: Symbol = Symbol('popupFont');
191  applyPeer(node: KNode, reset: boolean) {
192    if (reset) {
193      getUINativeModule().alphabetIndexer.resetPopupFont(node);
194    } else {
195      getUINativeModule().alphabetIndexer.setPopupFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
196    }
197  }
198
199  checkObjectDiff(): boolean {
200    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
201    let weightEQ = this.stageValue.weight === this.value.weight;
202    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
203    let styleEQ = this.stageValue.style === this.value.style;
204    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
205  }
206}
207
208class AlphabetIndexerFontModifier extends ModifierWithKey<Font> {
209  constructor(value: Font) {
210    super(value);
211  }
212  static identity: Symbol = Symbol('alphaBetIndexerFont');
213  applyPeer(node: KNode, reset: boolean) {
214    if (reset) {
215      getUINativeModule().alphabetIndexer.resetFont(node);
216    } else {
217      getUINativeModule().alphabetIndexer.setFont(node, this.value.size, this.value.weight, this.value.family, this.value.style);
218    }
219  }
220
221  checkObjectDiff(): boolean {
222    let sizeEQ = isBaseOrResourceEqual(this.stageValue.size, this.value.size);
223    let weightEQ = this.stageValue.weight === this.value.weight;
224    let familyEQ = isBaseOrResourceEqual(this.stageValue.family, this.value.family);
225    let styleEQ = this.stageValue.style === this.value.style;
226    return !sizeEQ || !weightEQ || !familyEQ || !styleEQ;
227  }
228}
229
230class PopupItemBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
231  constructor(value: ResourceColor) {
232    super(value);
233  }
234  static identity: Symbol = Symbol('popupItemBackgroundColor');
235  applyPeer(node: KNode, reset: boolean): void {
236    if (reset) {
237      getUINativeModule().alphabetIndexer.resetPopupItemBackgroundColor(node);
238    } else {
239      getUINativeModule().alphabetIndexer.setPopupItemBackgroundColor(node, this.value);
240    }
241  }
242
243  checkObjectDiff(): boolean {
244    return !isBaseOrResourceEqual(this.stageValue, this.value);
245  }
246}
247
248class ColorModifier extends ModifierWithKey<ResourceColor> {
249  constructor(value: ResourceColor) {
250    super(value);
251  }
252  static identity: Symbol = Symbol('alphabetColor');
253  applyPeer(node: KNode, reset: boolean): void {
254    if (reset) {
255      getUINativeModule().alphabetIndexer.resetColor(node);
256    } else {
257      getUINativeModule().alphabetIndexer.setColor(node, this.value);
258    }
259  }
260
261  checkObjectDiff(): boolean {
262    return !isBaseOrResourceEqual(this.stageValue, this.value);
263  }
264}
265
266class PopupColorModifier extends ModifierWithKey<ResourceColor> {
267  constructor(value: ResourceColor) {
268    super(value);
269  }
270  static identity: Symbol = Symbol('popupColor');
271  applyPeer(node: KNode, reset: boolean): void {
272    if (reset) {
273      getUINativeModule().alphabetIndexer.resetPopupColor(node);
274    } else {
275      getUINativeModule().alphabetIndexer.setPopupColor(node, this.value);
276    }
277  }
278
279  checkObjectDiff(): boolean {
280    return !isBaseOrResourceEqual(this.stageValue, this.value);
281  }
282}
283
284class SelectedColorModifier extends ModifierWithKey<ResourceColor> {
285  constructor(value: ResourceColor) {
286    super(value);
287  }
288  static identity: Symbol = Symbol('selectedColor');
289  applyPeer(node: KNode, reset: boolean): void {
290    if (reset) {
291      getUINativeModule().alphabetIndexer.resetSelectedColor(node);
292    } else {
293      getUINativeModule().alphabetIndexer.setSelectedColor(node, this.value);
294    }
295  }
296
297  checkObjectDiff(): boolean {
298    return !isBaseOrResourceEqual(this.stageValue, this.value);
299  }
300}
301
302class PopupBackgroundModifier extends ModifierWithKey<ResourceColor> {
303  constructor(value: ResourceColor) {
304    super(value);
305  }
306  static identity: Symbol = Symbol('popupBackground');
307  applyPeer(node: KNode, reset: boolean): void {
308    if (reset) {
309      getUINativeModule().alphabetIndexer.resetPopupBackground(node);
310    } else {
311      getUINativeModule().alphabetIndexer.setPopupBackground(node, this.value);
312    }
313  }
314
315  checkObjectDiff(): boolean {
316    return !isBaseOrResourceEqual(this.stageValue, this.value);
317  }
318}
319
320class SelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> {
321  constructor(value: ResourceColor) {
322    super(value);
323  }
324  static identity: Symbol = Symbol('selectedBackgroundColor');
325  applyPeer(node: KNode, reset: boolean): void {
326    if (reset) {
327      getUINativeModule().alphabetIndexer.resetSelectedBackgroundColor(node);
328    } else {
329      getUINativeModule().alphabetIndexer.setSelectedBackgroundColor(node, this.value);
330    }
331  }
332
333  checkObjectDiff(): boolean {
334    return !isBaseOrResourceEqual(this.stageValue, this.value);
335  }
336}
337
338class PopupUnselectedColorModifier extends ModifierWithKey<ResourceColor> {
339  constructor(value: ResourceColor) {
340    super(value);
341  }
342  static identity: Symbol = Symbol('popupUnselectedColor');
343  applyPeer(node: KNode, reset: boolean): void {
344    if (reset) {
345      getUINativeModule().alphabetIndexer.resetPopupUnselectedColor(node);
346    } else {
347      getUINativeModule().alphabetIndexer.setPopupUnselectedColor(node, this.value);
348    }
349  }
350
351  checkObjectDiff(): boolean {
352    return !isBaseOrResourceEqual(this.stageValue, this.value);
353  }
354}
355
356class PopupSelectedColorModifier extends ModifierWithKey<ResourceColor> {
357  constructor(value: ResourceColor) {
358    super(value);
359  }
360  static identity: Symbol = Symbol('popupSelectedColor');
361  applyPeer(node: KNode, reset: boolean): void {
362    if (reset) {
363      getUINativeModule().alphabetIndexer.resetPopupSelectedColor(node);
364    } else {
365      getUINativeModule().alphabetIndexer.setPopupSelectedColor(node, this.value);
366    }
367  }
368
369  checkObjectDiff(): boolean {
370    return !isBaseOrResourceEqual(this.stageValue, this.value);
371  }
372}
373
374class AlignStyleModifier extends ModifierWithKey<ArkAlignStyle> {
375  constructor(value: ArkAlignStyle) {
376    super(value);
377  }
378  static identity = Symbol('alignStyle');
379  applyPeer(node: KNode, reset: boolean): void {
380    if (reset) {
381      getUINativeModule().alphabetIndexer.resetAlignStyle(node);
382    } else {
383      getUINativeModule().alphabetIndexer.setAlignStyle(node, this.value.indexerAlign, this.value.offset);
384    }
385  }
386
387  checkObjectDiff(): boolean {
388    let indexerAlignEQ = isBaseOrResourceEqual(this.stageValue.indexerAlign, this.value.indexerAlign);
389    let offsetEQ = isBaseOrResourceEqual(this.stageValue.offset, this.value.offset);
390    return !indexerAlignEQ || !offsetEQ;
391  }
392}
393
394class UsingPopupModifier extends ModifierWithKey<boolean> {
395  constructor(value: boolean) {
396    super(value);
397  }
398  static identity = Symbol('usingPopup');
399  applyPeer(node: KNode, reset: boolean): void {
400    if (reset) {
401      getUINativeModule().alphabetIndexer.resetUsingPopup(node);
402    } else {
403      getUINativeModule().alphabetIndexer.setUsingPopup(node, this.value);
404    }
405  }
406}
407
408class AlphabetIndexerSelectedModifier extends ModifierWithKey<number> {
409  constructor(value: number) {
410    super(value);
411  }
412  static identity = Symbol('alphabetIndexerSelected');
413  applyPeer(node: KNode, reset: boolean): void {
414    if (reset) {
415      getUINativeModule().alphabetIndexer.resetSelected(node);
416    } else {
417      getUINativeModule().alphabetIndexer.setSelected(node, this.value);
418    }
419  }
420}
421
422class ItemSizeModifier extends ModifierWithKey<number | string> {
423  constructor(value: number | string) {
424    super(value);
425  }
426  static identity: Symbol = Symbol('itemSize');
427  applyPeer(node: KNode, reset: boolean): void {
428    if (reset) {
429      getUINativeModule().alphabetIndexer.resetItemSize(node);
430    } else {
431      getUINativeModule().alphabetIndexer.setItemSize(node, this.value);
432    }
433  }
434}
435
436class PopupPositionModifier extends ModifierWithKey<Position> {
437  constructor(value: Position) {
438    super(value);
439  }
440  static identity: Symbol = Symbol('popupPosition');
441  applyPeer(node: KNode, reset: boolean): void {
442    if (reset) {
443      getUINativeModule().alphabetIndexer.resetPopupPosition(node);
444    } else {
445      getUINativeModule().alphabetIndexer.setPopupPosition(node, this.value.x, this.value.y);
446    }
447  }
448
449  checkObjectDiff(): boolean {
450    let xEQ = isBaseOrResourceEqual(this.stageValue.x, this.value.x);
451    let yEQ = isBaseOrResourceEqual(this.stageValue.y, this.value.y);
452    return !xEQ || !yEQ;
453  }
454}
455
456class PopupItemBorderRadiusModifier extends ModifierWithKey<number> {
457  constructor(value: number) {
458    super(value);
459  }
460  static identity: Symbol = Symbol('popupItemBorderRadius');
461  applyPeer(node: KNode, reset: boolean): void {
462    if (reset) {
463      getUINativeModule().alphabetIndexer.resetPopupItemBorderRadius(node);
464    } else {
465      getUINativeModule().alphabetIndexer.setPopupItemBorderRadius(node, this.value);
466    }
467  }
468}
469
470class ItemBorderRadiusModifier extends ModifierWithKey<number> {
471  constructor(value: number) {
472    super(value);
473  }
474  static identity: Symbol = Symbol('itemBorderRadius');
475  applyPeer(node: KNode, reset: boolean): void {
476    if (reset) {
477      getUINativeModule().alphabetIndexer.resetItemBorderRadius(node);
478    } else {
479      getUINativeModule().alphabetIndexer.setItemBorderRadius(node, this.value);
480    }
481  }
482}
483
484class PopupBackgroundBlurStyleModifier extends ModifierWithKey<BlurStyle> {
485  constructor(value: BlurStyle) {
486    super(value);
487  }
488  static identity: Symbol = Symbol('popupBackgroundBlurStyle');
489  applyPeer(node: KNode, reset: boolean): void {
490    if (reset) {
491      getUINativeModule().alphabetIndexer.resetPopupBackgroundBlurStyle(node);
492    } else {
493      getUINativeModule().alphabetIndexer.setPopupBackgroundBlurStyle(node, this.value);
494    }
495  }
496}
497
498class PopupTitleBackgroundModifier extends ModifierWithKey<ResourceColor> {
499  constructor(value: ResourceColor) {
500    super(value);
501  }
502  static identity: Symbol = Symbol('popupTitleBackground');
503  applyPeer(node: KNode, reset: boolean): void {
504    if (reset) {
505      getUINativeModule().alphabetIndexer.resetPopupTitleBackground(node);
506    } else {
507      getUINativeModule().alphabetIndexer.setPopupTitleBackground(node, this.value);
508    }
509  }
510}
511
512class AdaptiveWidthModifier extends ModifierWithKey<Length> {
513  constructor(value: Length) {
514    super(value);
515  }
516  static identity: Symbol = Symbol('adaptiveWidth');
517
518  applyPeer(node: KNode, reset: boolean): void {
519    if (reset) {
520      getUINativeModule().alphabetIndexer.resetAdaptiveWidth(node);
521    } else {
522      getUINativeModule().alphabetIndexer.setAdaptiveWidth(node, this.value);
523    }
524  }
525}
526
527class AutoCollapseModifier extends ModifierWithKey<boolean> {
528  constructor(value: boolean) {
529    super(value);
530  }
531  static identity = Symbol('autoCollapse');
532  applyPeer(node: KNode, reset: boolean): void {
533    if (reset) {
534      getUINativeModule().alphabetIndexer.resetAutoCollapse(node);
535    } else {
536      getUINativeModule().alphabetIndexer.setAutoCollapse(node, this.value);
537    }
538  }
539
540  checkObjectDiff(): boolean {
541    return !isBaseOrResourceEqual(this.stageValue, this.value);
542  }
543}
544
545class EnableHapticFeedbackModifier extends ModifierWithKey<boolean> {
546  constructor(value: boolean) {
547    super(value);
548  }
549  static identity = Symbol('enableHapticFeedback');
550  applyPeer(node: KNode, reset: boolean): void {
551    if (reset) {
552      getUINativeModule().alphabetIndexer.resetEnableHapticFeedback(node);
553    } else {
554      getUINativeModule().alphabetIndexer.setEnableHapticFeedback(node, this.value);
555    }
556  }
557
558  checkObjectDiff(): boolean {
559    return !isBaseOrResourceEqual(this.stageValue, this.value);
560  }
561}