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 TextAreaFontStyleModifier extends ModifierWithKey<FontStyle> { 18 constructor(value: FontStyle) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('textAreaFontStyle'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().textArea.resetFontStyle(node); 25 } else { 26 getUINativeModule().textArea.setFontStyle(node, this.value!); 27 } 28 } 29 checkObjectDiff(): boolean { 30 return !isBaseOrResourceEqual(this.stageValue, this.value); 31 } 32} 33 34class TextAreaCopyOptionModifier extends ModifierWithKey<CopyOptions> { 35 constructor(value: CopyOptions) { 36 super(value); 37 } 38 static identity: Symbol = Symbol('textAreaCopyOption'); 39 applyPeer(node: KNode, reset: boolean): void { 40 if (reset) { 41 getUINativeModule().textArea.resetCopyOption(node); 42 } else { 43 getUINativeModule().textArea.setCopyOption(node, this.value!); 44 } 45 } 46 checkObjectDiff(): boolean { 47 return !isBaseOrResourceEqual(this.stageValue, this.value); 48 } 49} 50 51class TextAreaMaxLinesModifier extends ModifierWithKey<number | undefined> { 52 constructor(value: number | undefined) { 53 super(value); 54 } 55 static identity: Symbol = Symbol('textAreaMaxLines'); 56 applyPeer(node: KNode, reset: boolean): void { 57 if (reset) { 58 getUINativeModule().textArea.resetMaxLines(node); 59 } else { 60 getUINativeModule().textArea.setMaxLines(node, this.value!); 61 } 62 } 63 checkObjectDiff(): boolean { 64 return !isBaseOrResourceEqual(this.stageValue, this.value); 65 } 66} 67 68class TextAreaFontSizeModifier extends ModifierWithKey<string | number> { 69 constructor(value: string | number) { 70 super(value); 71 } 72 static identity: Symbol = Symbol('textAreaFontSize'); 73 applyPeer(node: KNode, reset: boolean): void { 74 if (reset) { 75 getUINativeModule().textArea.resetFontSize(node); 76 } else { 77 getUINativeModule().textArea.setFontSize(node, this.value!); 78 } 79 } 80 checkObjectDiff(): boolean { 81 return !isBaseOrResourceEqual(this.stageValue, this.value); 82 } 83} 84 85class TextAreaPlaceholderColorModifier extends ModifierWithKey<ResourceColor> { 86 constructor(value: ResourceColor) { 87 super(value); 88 } 89 static identity: Symbol = Symbol('textAreaPlaceholderColor'); 90 applyPeer(node: KNode, reset: boolean): void { 91 if (reset) { 92 getUINativeModule().textArea.resetPlaceholderColor(node); 93 } else { 94 getUINativeModule().textArea.setPlaceholderColor(node, this.value!); 95 } 96 } 97 checkObjectDiff(): boolean { 98 return !isBaseOrResourceEqual(this.stageValue, this.value); 99 } 100} 101 102class TextAreaFontColorModifier extends ModifierWithKey<ResourceColor> { 103 constructor(value: ResourceColor) { 104 super(value); 105 } 106 static identity: Symbol = Symbol('textAreaFontColor'); 107 applyPeer(node: KNode, reset: boolean): void { 108 if (reset) { 109 getUINativeModule().textArea.resetFontColor(node); 110 } else { 111 getUINativeModule().textArea.setFontColor(node, this.value!); 112 } 113 } 114 checkObjectDiff(): boolean { 115 return !isBaseOrResourceEqual(this.stageValue, this.value); 116 } 117} 118 119class TextAreaFontWeightModifier extends ModifierWithKey<number | FontWeight | string> { 120 constructor(value: number | FontWeight | string) { 121 super(value); 122 } 123 static identity: Symbol = Symbol('textAreaFontWeight'); 124 applyPeer(node: KNode, reset: boolean): void { 125 if (reset) { 126 getUINativeModule().textArea.resetFontWeight(node); 127 } else { 128 getUINativeModule().textArea.setFontWeight(node, this.value!); 129 } 130 } 131 checkObjectDiff(): boolean { 132 return !isBaseOrResourceEqual(this.stageValue, this.value); 133 } 134} 135 136class TextAreaBarStateModifier extends ModifierWithKey<BarState> { 137 constructor(value: BarState) { 138 super(value); 139 } 140 static identity: Symbol = Symbol('textAreaBarState'); 141 applyPeer(node: KNode, reset: boolean): void { 142 if (reset) { 143 getUINativeModule().textArea.resetBarState(node); 144 } else { 145 getUINativeModule().textArea.setBarState(node, this.value!); 146 } 147 } 148 checkObjectDiff(): boolean { 149 return !isBaseOrResourceEqual(this.stageValue, this.value); 150 } 151} 152 153class TextAreaEnableKeyboardOnFocusModifier extends ModifierWithKey<boolean> { 154 constructor(value: boolean) { 155 super(value); 156 } 157 static identity: Symbol = Symbol('textAreaEnableKeyboardOnFocus'); 158 applyPeer(node: KNode, reset: boolean): void { 159 if (reset) { 160 getUINativeModule().textArea.resetEnableKeyboardOnFocus(node); 161 } else { 162 getUINativeModule().textArea.setEnableKeyboardOnFocus(node, this.value!); 163 } 164 } 165 checkObjectDiff(): boolean { 166 return !isBaseOrResourceEqual(this.stageValue, this.value); 167 } 168} 169 170class TextAreaFontFamilyModifier extends ModifierWithKey<ResourceColor | string> { 171 constructor(value: ResourceColor | string) { 172 super(value); 173 } 174 static identity: Symbol = Symbol('textAreaFontFamily'); 175 applyPeer(node: KNode, reset: boolean): void { 176 if (reset) { 177 getUINativeModule().textArea.resetFontFamily(node); 178 } else { 179 getUINativeModule().textArea.setFontFamily(node, this.value!); 180 } 181 } 182 183 checkObjectDiff(): boolean { 184 return !isBaseOrResourceEqual(this.stageValue, this.value); 185 } 186} 187 188class TextAreaCaretColorModifier extends ModifierWithKey<ResourceColor> { 189 constructor(value: ResourceColor) { 190 super(value); 191 } 192 static identity: Symbol = Symbol('textAreaCaretColor'); 193 applyPeer(node: KNode, reset: boolean): void { 194 if (reset) { 195 getUINativeModule().textArea.resetCaretColor(node); 196 } else { 197 getUINativeModule().textArea.setCaretColor(node, this.value!); 198 } 199 } 200 checkObjectDiff(): boolean { 201 return !isBaseOrResourceEqual(this.stageValue, this.value); 202 } 203} 204 205class TextAreaMaxLengthModifier extends ModifierWithKey<number> { 206 constructor(value: number) { 207 super(value); 208 } 209 static identity: Symbol = Symbol('textAreaMaxLength'); 210 applyPeer(node: KNode, reset: boolean): void { 211 if (reset) { 212 getUINativeModule().textArea.resetMaxLength(node); 213 } else { 214 getUINativeModule().textArea.setMaxLength(node, this.value!); 215 } 216 } 217 checkObjectDiff(): boolean { 218 return !isBaseOrResourceEqual(this.stageValue, this.value); 219 } 220} 221 222class TextAreaStyleModifier extends ModifierWithKey<TextContentStyle> { 223 constructor(value: TextContentStyle) { 224 super(value); 225 } 226 static identity: Symbol = Symbol('textAreaStyle'); 227 applyPeer(node: KNode, reset: boolean): void { 228 if (reset) { 229 getUINativeModule().textArea.resetStyle(node); 230 } else { 231 getUINativeModule().textArea.setStyle(node, this.value!); 232 } 233 } 234 checkObjectDiff(): boolean { 235 return !isBaseOrResourceEqual(this.stageValue, this.value); 236 } 237} 238 239class TextAreaSelectionMenuHiddenModifier extends ModifierWithKey<boolean> { 240 constructor(value: boolean) { 241 super(value); 242 } 243 static identity: Symbol = Symbol('textAreaSelectionMenuHidden'); 244 applyPeer(node: KNode, reset: boolean): void { 245 if (reset) { 246 getUINativeModule().textArea.resetSelectionMenuHidden(node); 247 } else { 248 getUINativeModule().textArea.setSelectionMenuHidden(node, this.value!); 249 } 250 } 251 checkObjectDiff(): boolean { 252 return !isBaseOrResourceEqual(this.stageValue, this.value); 253 } 254} 255 256class TextAreaPlaceholderFontModifier extends ModifierWithKey<Font> { 257 constructor(value: Font) { 258 super(value); 259 } 260 static identity: Symbol = Symbol('textAreaPlaceholderFont'); 261 applyPeer(node: KNode, reset: boolean): void { 262 if (reset) { 263 getUINativeModule().textArea.resetPlaceholderFont(node); 264 } else { 265 getUINativeModule().textArea.setPlaceholderFont(node, this.value.size, 266 this.value.weight, this.value.family, this.value.style); 267 } 268 } 269 270 checkObjectDiff(): boolean { 271 if (!(this.stageValue.weight === this.value.weight && 272 this.stageValue.style === this.value.style)) { 273 return true; 274 } else { 275 return !isBaseOrResourceEqual(this.stageValue.size, this.value.size) || 276 !isBaseOrResourceEqual(this.stageValue.family, this.value.family); 277 } 278 } 279} 280 281class TextAreaTextAlignModifier extends ModifierWithKey<TextAlign> { 282 constructor(value: TextAlign) { 283 super(value); 284 } 285 static identity: Symbol = Symbol('textAreaTextAlign'); 286 applyPeer(node: KNode, reset: boolean): void { 287 if (reset) { 288 getUINativeModule().textArea.resetTextAlign(node); 289 } else { 290 getUINativeModule().textArea.setTextAlign(node, this.value!); 291 } 292 } 293 checkObjectDiff(): boolean { 294 return !isBaseOrResourceEqual(this.stageValue, this.value); 295 } 296} 297 298class TextAreaShowCounterModifier extends ModifierWithKey<ArkTextAreaShowCounter> { 299 constructor(value: ArkTextAreaShowCounter) { 300 super(value); 301 } 302 static identity: Symbol = Symbol('textAreaShowCounter'); 303 applyPeer(node: KNode, reset: boolean): void { 304 if (reset) { 305 getUINativeModule().textArea.resetShowCounter(node); 306 } else { 307 getUINativeModule().textArea.setShowCounter(node, this.value.value!, this.value.options); 308 } 309 } 310 checkObjectDiff(): boolean { 311 return !isBaseOrResourceEqual(this.stageValue.value, this.value.value) || 312 !isBaseOrResourceEqual(this.stageValue.options, this.value.options); 313 } 314} 315 316class ArkTextAreaComponent extends ArkComponent implements CommonMethod<TextAreaAttribute> { 317 constructor(nativePtr: KNode) { 318 super(nativePtr); 319 } 320 type(value: TextAreaType): TextAreaAttribute { 321 throw new Error('Method not implemented.'); 322 } 323 placeholderColor(value: ResourceColor): TextAreaAttribute { 324 modifierWithKey(this._modifiersWithKeys, TextAreaPlaceholderColorModifier.identity, TextAreaPlaceholderColorModifier, value); 325 return this; 326 } 327 placeholderFont(value: Font): TextAreaAttribute { 328 modifierWithKey(this._modifiersWithKeys, TextAreaPlaceholderFontModifier.identity, TextAreaPlaceholderFontModifier, value); 329 return this; 330 } 331 332 textAlign(value: TextAlign): TextAreaAttribute { 333 modifierWithKey(this._modifiersWithKeys, TextAreaTextAlignModifier.identity, TextAreaTextAlignModifier, value); 334 return this; 335 } 336 caretColor(value: ResourceColor): TextAreaAttribute { 337 modifierWithKey(this._modifiersWithKeys, TextAreaCaretColorModifier.identity, TextAreaCaretColorModifier, value); 338 return this; 339 } 340 fontColor(value: ResourceColor): TextAreaAttribute { 341 modifierWithKey(this._modifiersWithKeys, TextAreaFontColorModifier.identity, TextAreaFontColorModifier, value); 342 return this; 343 } 344 fontSize(value: Length): TextAreaAttribute { 345 modifierWithKey(this._modifiersWithKeys, TextAreaFontSizeModifier.identity, TextAreaFontSizeModifier, value); 346 return this; 347 } 348 fontStyle(value: FontStyle): TextAreaAttribute { 349 modifierWithKey(this._modifiersWithKeys, TextAreaFontStyleModifier.identity, TextAreaFontStyleModifier, value); 350 return this; 351 } 352 fontWeight(value: number | FontWeight | string): TextAreaAttribute { 353 modifierWithKey(this._modifiersWithKeys, TextAreaFontWeightModifier.identity, TextAreaFontWeightModifier, value); 354 return this; 355 } 356 fontFamily(value: ResourceStr): TextAreaAttribute { 357 modifierWithKey(this._modifiersWithKeys, TextAreaFontFamilyModifier.identity, TextAreaFontFamilyModifier, value); 358 return this; 359 } 360 inputFilter(value: ResourceStr, error?: (value: string) => void): TextAreaAttribute { 361 throw new Error('Method not implemented.'); 362 } 363 onChange(callback: (value: string) => void): TextAreaAttribute { 364 throw new Error('Method not implemented.'); 365 } 366 onTextSelectionChange(callback: (selectionStart: number, selectionEnd: number) => void): TextAreaAttribute { 367 throw new Error('Method not implemented.'); 368 } 369 onContentScroll(callback: (totalOffsetX: number, totalOffsetY: number) => void): TextAreaAttribute { 370 throw new Error('Method not implemented.'); 371 } 372 onEditChange(callback: (isEditing: boolean) => void): TextAreaAttribute { 373 throw new Error('Method not implemented.'); 374 } 375 onCopy(callback: (value: string) => void): TextAreaAttribute { 376 throw new Error('Method not implemented.'); 377 } 378 onCut(callback: (value: string) => void): TextAreaAttribute { 379 throw new Error('Method not implemented.'); 380 } 381 onPaste(callback: (value: string) => void): TextAreaAttribute { 382 throw new Error('Method not implemented.'); 383 } 384 copyOption(value: CopyOptions): TextAreaAttribute { 385 modifierWithKey(this._modifiersWithKeys, TextAreaCopyOptionModifier.identity, TextAreaCopyOptionModifier, value); 386 return this; 387 } 388 389 enableKeyboardOnFocus(value: boolean): TextAreaAttribute { 390 modifierWithKey(this._modifiersWithKeys, TextAreaEnableKeyboardOnFocusModifier.identity, TextAreaEnableKeyboardOnFocusModifier, value); 391 return this; 392 } 393 394 maxLength(value: number): TextAreaAttribute { 395 modifierWithKey(this._modifiersWithKeys, TextAreaMaxLengthModifier.identity, TextAreaMaxLengthModifier, value); 396 return this; 397 } 398 showCounter(value: boolean, options?: InputCounterOptions): TextAreaAttribute { 399 let arkValue: ArkTextAreaShowCounter = new ArkTextAreaShowCounter(); 400 arkValue.value = value; 401 arkValue.options = options; 402 modifierWithKey(this._modifiersWithKeys, TextAreaShowCounterModifier.identity, TextAreaShowCounterModifier, arkValue); 403 return this; 404 } 405 style(value: TextContentStyle): TextAreaAttribute { 406 modifierWithKey(this._modifiersWithKeys, TextAreaStyleModifier.identity, TextAreaStyleModifier, value); 407 return this; 408 } 409 barState(value: BarState): TextAreaAttribute { 410 modifierWithKey(this._modifiersWithKeys, TextAreaBarStateModifier.identity, TextAreaBarStateModifier, value); 411 return this; 412 } 413 selectionMenuHidden(value: boolean): TextAreaAttribute { 414 modifierWithKey(this._modifiersWithKeys, TextAreaSelectionMenuHiddenModifier.identity, TextAreaSelectionMenuHiddenModifier, value); 415 return this; 416 } 417 maxLines(value: number): TextAreaAttribute { 418 modifierWithKey(this._modifiersWithKeys, TextAreaMaxLinesModifier.identity, TextAreaMaxLinesModifier, value); 419 return this; 420 } 421 customKeyboard(value: CustomBuilder): TextAreaAttribute { 422 throw new Error('Method not implemented.'); 423 } 424} 425// @ts-ignore 426globalThis.TextArea.attributeModifier = function (modifier) { 427 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 428 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 429 430 let component = this.createOrGetNode(elmtId, () => { 431 return new ArkTextAreaComponent(nativeNode); 432 }); 433 applyUIAttributes(modifier, nativeNode, component); 434 component.applyModifierPatch(); 435}; 436