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 static identity: Symbol = Symbol('richEditorCopyOptions'); 68 applyPeer(node: KNode, reset: boolean): void { 69 if (reset) { 70 getUINativeModule().richEditor.resetCopyOptions(node); 71 } else { 72 getUINativeModule().richEditor.setCopyOptions(node, this.value!); 73 } 74 } 75 checkObjectDiff(): boolean { 76 return this.stageValue !== this.value; 77 } 78} 79 80class RichEditorSelectedBackgroundColorModifier extends ModifierWithKey<ResourceColor> { 81 constructor(value: ResourceColor) { 82 super(value); 83 } 84 static identity: Symbol = Symbol('richEditorSelectedBackgroundColor'); 85 applyPeer(node: KNode, reset: boolean): void { 86 if (reset) { 87 getUINativeModule().richEditor.resetSelectedBackgroundColor(node); 88 } else { 89 getUINativeModule().richEditor.setSelectedBackgroundColor(node, this.value!); 90 } 91 } 92 checkObjectDiff(): boolean { 93 return this.stageValue !== this.value; 94 } 95} 96 97class RichEditorOnSelectionChangeModifier extends ModifierWithKey<(value: RichEditorRange) => void> { 98 constructor(value: (value: RichEditorRange) => void) { 99 super(value); 100 } 101 static identity = Symbol('richEditorOnSelectionChange'); 102 applyPeer(node: KNode, reset: boolean): void { 103 if (reset) { 104 getUINativeModule().richEditor.resetOnSelectionChange(node); 105 } else { 106 getUINativeModule().richEditor.setOnSelectionChange(node, this.value); 107 } 108 } 109} 110 111class RichEditorCaretColorModifier extends ModifierWithKey<ResourceColor> { 112 constructor(value: ResourceColor) { 113 super(value); 114 } 115 static identity: Symbol = Symbol('richEditorCaretColor'); 116 applyPeer(node: KNode, reset: boolean): void { 117 if (reset) { 118 getUINativeModule().richEditor.resetCaretColor(node); 119 } else { 120 getUINativeModule().richEditor.setCaretColor(node, this.value!); 121 } 122 } 123 checkObjectDiff(): boolean { 124 return this.stageValue !== this.value; 125 } 126} 127 128class RichEditorOnSelectModifier extends ModifierWithKey<(value: RichEditorSelection) => void> { 129 constructor(value: (value: RichEditorSelection) => void) { 130 super(value); 131 } 132 static identity = Symbol('richEditorOnSelect'); 133 applyPeer(node: KNode, reset: boolean): void { 134 if (reset) { 135 getUINativeModule().richEditor.resetOnSelect(node); 136 } else { 137 getUINativeModule().richEditor.setOnSelect(node, this.value); 138 } 139 } 140} 141 142class RichEditorOnSubmitModifier extends ModifierWithKey<SubmitCallback> { 143 constructor(value: SubmitCallback) { 144 super(value); 145 } 146 static identity: Symbol = Symbol('richEditorOnSubmit'); 147 applyPeer(node: KNode, reset: boolean): void { 148 if (reset) { 149 getUINativeModule().richEditor.resetOnSubmit(node); 150 } else { 151 getUINativeModule().richEditor.setOnSubmit(node, this.value); 152 } 153 } 154} 155 156class RichEditorAboutToIMEInputModifier extends ModifierWithKey<(value: RichEditorInsertValue) => boolean> { 157 constructor(value: (value: RichEditorInsertValue) => boolean) { 158 super(value); 159 } 160 static identity = Symbol('richEditorAboutToIMEInput'); 161 applyPeer(node: KNode, reset: boolean): void { 162 if (reset) { 163 getUINativeModule().richEditor.resetAboutToIMEInput(node); 164 } else { 165 getUINativeModule().richEditor.setAboutToIMEInput(node, this.value); 166 } 167 } 168} 169 170class RichEditorOnReadyModifier extends ModifierWithKey<() => void> { 171 constructor(value: () => void) { 172 super(value); 173 } 174 static identity = Symbol('richEditorOnReady'); 175 applyPeer(node: KNode, reset: boolean): void { 176 if (reset) { 177 getUINativeModule().richEditor.resetOnReady(node); 178 } else { 179 getUINativeModule().richEditor.setOnReady(node, this.value); 180 } 181 } 182} 183 184class RichEditorOnDeleteCompleteModifier extends ModifierWithKey<() => void> { 185 constructor(value: () => void) { 186 super(value); 187 } 188 static identity = Symbol('richEditorOnDeleteComplete'); 189 applyPeer(node: KNode, reset: boolean): void { 190 if (reset) { 191 getUINativeModule().richEditor.resetOnDeleteComplete(node); 192 } else { 193 getUINativeModule().richEditor.setOnDeleteComplete(node, this.value); 194 } 195 } 196} 197 198class RichEditorOnEditingChangeModifier extends ModifierWithKey<(value: boolean) => void> { 199 constructor(value: (value: boolean) => void) { 200 super(value); 201 } 202 static identity = Symbol('richEditorOnEditingChange'); 203 applyPeer(node: KNode, reset: boolean): void { 204 if (reset) { 205 getUINativeModule().richEditor.resetEditingChange(node); 206 } else { 207 getUINativeModule().richEditor.setEditingChange(node, this.value); 208 } 209 } 210} 211 212class RichEditorOnPasteModifier extends ModifierWithKey<(event?: PasteEvent) => void> { 213 constructor(value: (event?: PasteEvent) => void) { 214 super(value); 215 } 216 static identity = Symbol('richEditorOnPaste'); 217 applyPeer(node: KNode, reset: boolean): void { 218 if (reset) { 219 getUINativeModule().richEditor.resetOnPaste(node); 220 } else { 221 getUINativeModule().richEditor.setOnPaste(node, this.value); 222 } 223 } 224} 225 226class RichEditorOnCutModifier extends ModifierWithKey<Callback<CutEvent>> { 227 constructor(value: Callback<CutEvent>) { 228 super(value); 229 } 230 static identity = Symbol('richEditorOnCut'); 231 applyPeer(node: KNode, reset: boolean): void { 232 if (reset) { 233 getUINativeModule().richEditor.resetOnCut(node); 234 } else { 235 getUINativeModule().richEditor.setOnCut(node, this.value); 236 } 237 } 238} 239 240class RichEditorOnCopyModifier extends ModifierWithKey<Callback<CopyEvent>> { 241 constructor(value: Callback<CopyEvent>) { 242 super(value); 243 } 244 static identity = Symbol('richEditorOnCopy'); 245 applyPeer(node: KNode, reset: boolean): void { 246 if (reset) { 247 getUINativeModule().richEditor.resetOnCopy(node); 248 } else { 249 getUINativeModule().richEditor.setOnCopy(node, this.value); 250 } 251 } 252} 253 254 255class RichEditorEnterKeyTypeModifier extends ModifierWithKey<EnterKeyType> { 256 constructor(value: EnterKeyType) { 257 super(value); 258 } 259 static identity: Symbol = Symbol('richEditorEnterKeyType'); 260 applyPeer(node: KNode, reset: boolean): void { 261 if (reset) { 262 getUINativeModule().richEditor.resetEnterKeyType(node); 263 } else { 264 getUINativeModule().richEditor.setEnterKeyType(node, this.value!); 265 } 266 } 267 checkObjectDiff(): boolean { 268 return this.stageValue !== this.value; 269 } 270} 271 272class ArkRichEditorComponent extends ArkComponent implements CommonMethod<RichEditorAttribute> { 273 constructor(nativePtr: KNode, classType?: ModifierType) { 274 super(nativePtr, classType); 275 } 276 enableDataDetector(value: boolean): RichEditorAttribute { 277 modifierWithKey(this._modifiersWithKeys, RichEditorEnableDataDetectorModifier.identity, RichEditorEnableDataDetectorModifier, value); 278 return this; 279 } 280 281 dataDetectorConfig(config: TextDataDetectorConfig): this { 282 let detectorConfig = new TextDataDetectorConfig(); 283 detectorConfig.types = config.types; 284 detectorConfig.onDetectResultUpdate = config.onDetectResultUpdate; 285 modifierWithKey(this._modifiersWithKeys, RichEditorDataDetectorConfigModifier.identity, RichEditorDataDetectorConfigModifier, detectorConfig); 286 return this; 287 } 288 289 copyOptions(value: CopyOptions): RichEditorAttribute { 290 modifierWithKey(this._modifiersWithKeys, RichEditorCopyOptionsModifier.identity, RichEditorCopyOptionsModifier, value); 291 return this; 292 } 293 294 caretColor(value: ResourceColor): RichEditorAttribute { 295 modifierWithKey(this._modifiersWithKeys, RichEditorCaretColorModifier.identity, RichEditorCaretColorModifier, value); 296 return this; 297 } 298 299 selectedBackgroundColor(value: ResourceColor): RichEditorAttribute { 300 modifierWithKey(this._modifiersWithKeys, RichEditorSelectedBackgroundColorModifier.identity, RichEditorSelectedBackgroundColorModifier, value); 301 return this; 302 } 303 304 onPaste(callback: (event?: PasteEvent) => void): RichEditorAttribute { 305 modifierWithKey(this._modifiersWithKeys, RichEditorOnPasteModifier.identity, RichEditorOnPasteModifier, callback); 306 return this; 307 } 308 309 onReady(callback: () => void): RichEditorAttribute { 310 modifierWithKey(this._modifiersWithKeys, RichEditorOnReadyModifier.identity, RichEditorOnReadyModifier, callback); 311 return this; 312 } 313 onSelect(callback: (value: RichEditorSelection) => void): RichEditorAttribute { 314 modifierWithKey(this._modifiersWithKeys, RichEditorOnSelectModifier.identity, RichEditorOnSelectModifier, callback); 315 return this; 316 } 317 318 onSubmit(callback: SubmitCallback): RichEditorAttribute { 319 modifierWithKey(this._modifiersWithKeys, RichEditorOnSubmitModifier.identity, RichEditorOnSubmitModifier, callback); 320 return this; 321 } 322 onSelectionChange(callback: (value: RichEditorRange) => void): RichEditorAttribute { 323 modifierWithKey(this._modifiersWithKeys, RichEditorOnSelectionChangeModifier.identity, RichEditorOnSelectionChangeModifier, callback); 324 return this; 325 } 326 onSubmit(callback: SubmitCallback): RichEditorAttribute { 327 modifierWithKey(this._modifiersWithKeys, RichEditorOnSubmitModifier.identity, RichEditorOnSubmitModifier, callback); 328 return this; 329 } 330 aboutToIMEInput(callback: (value: RichEditorInsertValue) => boolean): RichEditorAttribute { 331 modifierWithKey(this._modifiersWithKeys, RichEditorAboutToIMEInputModifier.identity, RichEditorAboutToIMEInputModifier, callback); 332 return this; 333 } 334 onIMEInputComplete(callback: (value: RichEditorTextSpanResult) => void): RichEditorAttribute { 335 modifierWithKey(this._modifiersWithKeys, RichEditorOnIMEInputCompleteModifier.identity, RichEditorOnIMEInputCompleteModifier, callback); 336 return this; 337 } 338 aboutToDelete(callback: (value: RichEditorDeleteValue) => boolean): RichEditorAttribute { 339 throw new Error('Method not implemented.'); 340 } 341 onDeleteComplete(callback: () => void): RichEditorAttribute { 342 modifierWithKey(this._modifiersWithKeys, RichEditorOnDeleteCompleteModifier.identity, RichEditorOnDeleteCompleteModifier, callback); 343 return this; 344 } 345 bindSelectionMenu(spanType: RichEditorSpanType, content: CustomBuilder, responseType: ResponseType, options?: SelectionMenuOptions): RichEditorAttribute { 346 throw new Error('Method not implemented.'); 347 } 348 customKeyboard(value: CustomBuilder): RichEditorAttribute { 349 throw new Error('Method not implemented.'); 350 } 351 onEditingChange(callback: (value: boolean) => void): RichEditorAttribute { 352 modifierWithKey(this._modifiersWithKeys, RichEditorOnEditingChangeModifier.identity, RichEditorOnEditingChangeModifier, callback); 353 return this; 354 } 355 onCut(callback: Callback<CutEvent>): RichEditorAttribute { 356 modifierWithKey(this._modifiersWithKeys, RichEditorOnCutModifier.identity, RichEditorOnCutModifier, callback); 357 return this; 358 } 359 onCopy(callback: Callback<CopyEvent>): RichEditorAttribute { 360 modifierWithKey(this._modifiersWithKeys, RichEditorOnCopyModifier.identity, RichEditorOnCopyModifier, callback); 361 return this; 362 } 363 enterKeyType(value: EnterKeyType): RichEditorAttribute { 364 modifierWithKey(this._modifiersWithKeys, RichEditorEnterKeyTypeModifier.identity, RichEditorEnterKeyTypeModifier, value); 365 return this; 366 } 367} 368 369// @ts-ignore 370globalThis.RichEditor.attributeModifier = function (modifier: ArkComponent): void { 371 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 372 return new ArkRichEditorComponent(nativePtr); 373 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 374 return new modifierJS.RichEditorModifier(nativePtr, classType); 375 }); 376}; 377