1/* 2 * Copyright (c) 2023-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 */ 15const pasteboard = requireNapi('pasteboard'); 16const hilog = requireNapi('hilog'); 17 18if (!('finalizeConstruction' in ViewPU.prototype)) { 19 Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { 20 }); 21} 22 23const WITHOUT_BUILDER = -2; 24const defaultTheme = { 25 imageSize: 24, 26 buttonSize: 48, 27 menuSpacing: 8, 28 editorOptionMargin: 1, 29 expandedOptionPadding: 3, 30 defaultMenuWidth: 256, 31 imageFillColor: { 32 'id': -1, 33 'type': 10001, 34 params: ['sys.color.ohos_id_color_primary'], 35 'bundleName': '__harDefaultBundleName__', 36 'moduleName': '__harDefaultModuleName__' 37 }, 38 backGroundColor: { 39 'id': -1, 40 'type': 10001, 41 params: ['sys.color.ohos_id_color_dialog_bg'], 42 'bundleName': '__harDefaultBundleName__', 43 'moduleName': '__harDefaultModuleName__' 44 }, 45 iconBorderRadius: { 46 'id': -1, 47 'type': 10002, 48 params: ['sys.float.ohos_id_corner_radius_default_m'], 49 'bundleName': '__harDefaultBundleName__', 50 'moduleName': '__harDefaultModuleName__' 51 }, 52 containerBorderRadius: { 53 'id': -1, 54 'type': 10002, 55 params: ['sys.float.ohos_id_corner_radius_card'], 56 'bundleName': '__harDefaultBundleName__', 57 'moduleName': '__harDefaultModuleName__' 58 }, 59 cutIcon: { 60 'id': -1, 61 'type': 20000, 62 params: ['sys.media.ohos_ic_public_cut'], 63 'bundleName': '__harDefaultBundleName__', 64 'moduleName': '__harDefaultModuleName__' 65 }, 66 copyIcon: { 67 'id': -1, 68 'type': 20000, 69 params: ['sys.media.ohos_ic_public_copy'], 70 'bundleName': '__harDefaultBundleName__', 71 'moduleName': '__harDefaultModuleName__' 72 }, 73 pasteIcon: { 74 'id': -1, 75 'type': 20000, 76 params: ['sys.media.ohos_ic_public_paste'], 77 'bundleName': '__harDefaultBundleName__', 78 'moduleName': '__harDefaultModuleName__' 79 }, 80 selectAllIcon: { 81 'id': -1, 82 'type': 20000, 83 params: ['sys.media.ohos_ic_public_select_all'], 84 'bundleName': '__harDefaultBundleName__', 85 'moduleName': '__harDefaultModuleName__' 86 }, 87 shareIcon: { 88 'id': -1, 89 'type': 20000, 90 params: ['sys.media.ohos_ic_public_share'], 91 'bundleName': '__harDefaultBundleName__', 92 'moduleName': '__harDefaultModuleName__' 93 }, 94 translateIcon: { 95 'id': -1, 96 'type': 20000, 97 params: ['sys.media.ohos_ic_public_translate_c2e'], 98 'bundleName': '__harDefaultBundleName__', 99 'moduleName': '__harDefaultModuleName__' 100 }, 101 searchIcon: { 102 'id': -1, 103 'type': 20000, 104 params: ['sys.media.ohos_ic_public_search_filled'], 105 'bundleName': '__harDefaultBundleName__', 106 'moduleName': '__harDefaultModuleName__' 107 }, 108 arrowDownIcon: { 109 'id': -1, 110 'type': 20000, 111 params: ['sys.media.ohos_ic_public_arrow_down'], 112 'bundleName': '__harDefaultBundleName__', 113 'moduleName': '__harDefaultModuleName__' 114 }, 115 aiWriteIcon: { 116 'id': -1, 117 'type': 20000, 118 params: ['sys.media.ic_public_ai_write'], 119 'bundleName': '__harDefaultBundleName__', 120 'moduleName': '__harDefaultModuleName__' 121 }, 122 iconPanelShadowStyle: ShadowStyle.OUTER_DEFAULT_MD, 123}; 124 125class SelectionMenuComponent extends ViewPU { 126 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 127 super(parent, __localStorage, elmtId, extraInfo); 128 if (typeof paramsLambda === 'function') { 129 this.paramsGenerator_ = paramsLambda; 130 } 131 this.editorMenuOptions = undefined; 132 this.expandedMenuOptions = undefined; 133 this.controller = undefined; 134 this.onPaste = undefined; 135 this.onCopy = undefined; 136 this.onCut = undefined; 137 this.onSelectAll = undefined; 138 this.theme = defaultTheme; 139 this.builder = this.CloserFun; 140 this.__showExpandedMenuOptions = new ObservedPropertySimplePU(false, this, 'showExpandedMenuOptions'); 141 this.__showCustomerIndex = new ObservedPropertySimplePU(-1, this, 'showCustomerIndex'); 142 this.__customerChange = new ObservedPropertySimplePU(false, this, 'customerChange'); 143 this.__cutAndCopyEnable = new ObservedPropertySimplePU(false, this, 'cutAndCopyEnable'); 144 this.__pasteEnable = new ObservedPropertySimplePU(false, this, 'pasteEnable'); 145 this.__visibilityValue = new ObservedPropertySimplePU(Visibility.Visible, this, 'visibilityValue'); 146 this.__customMenuSize = new ObservedPropertySimplePU('100%', this, 'customMenuSize'); 147 this.customMenuHeight = this.theme.menuSpacing; 148 this.fontWeightTable = ['100', '200', '300', '400', '500', '600', '700', '800', '900', 'bold', 'normal', 'bolder', 'lighter', 'medium', 'regular']; 149 this.setInitiallyProvidedValue(params); 150 this.finalizeConstruction(); 151 } 152 153 setInitiallyProvidedValue(params) { 154 if (params.editorMenuOptions !== undefined) { 155 this.editorMenuOptions = params.editorMenuOptions; 156 } 157 if (params.expandedMenuOptions !== undefined) { 158 this.expandedMenuOptions = params.expandedMenuOptions; 159 } 160 if (params.controller !== undefined) { 161 this.controller = params.controller; 162 } 163 if (params.onPaste !== undefined) { 164 this.onPaste = params.onPaste; 165 } 166 if (params.onCopy !== undefined) { 167 this.onCopy = params.onCopy; 168 } 169 if (params.onCut !== undefined) { 170 this.onCut = params.onCut; 171 } 172 if (params.onSelectAll !== undefined) { 173 this.onSelectAll = params.onSelectAll; 174 } 175 if (params.theme !== undefined) { 176 this.theme = params.theme; 177 } 178 if (params.builder !== undefined) { 179 this.builder = params.builder; 180 } 181 if (params.showExpandedMenuOptions !== undefined) { 182 this.showExpandedMenuOptions = params.showExpandedMenuOptions; 183 } 184 if (params.showCustomerIndex !== undefined) { 185 this.showCustomerIndex = params.showCustomerIndex; 186 } 187 if (params.customerChange !== undefined) { 188 this.customerChange = params.customerChange; 189 } 190 if (params.cutAndCopyEnable !== undefined) { 191 this.cutAndCopyEnable = params.cutAndCopyEnable; 192 } 193 if (params.pasteEnable !== undefined) { 194 this.pasteEnable = params.pasteEnable; 195 } 196 if (params.visibilityValue !== undefined) { 197 this.visibilityValue = params.visibilityValue; 198 } 199 if (params.customMenuSize !== undefined) { 200 this.customMenuSize = params.customMenuSize; 201 } 202 if (params.customMenuHeight !== undefined) { 203 this.customMenuHeight = params.customMenuHeight; 204 } 205 if (params.fontWeightTable !== undefined) { 206 this.fontWeightTable = params.fontWeightTable; 207 } 208 } 209 210 updateStateVars(params) { 211 } 212 213 purgeVariableDependenciesOnElmtId(rmElmtId) { 214 this.__showExpandedMenuOptions.purgeDependencyOnElmtId(rmElmtId); 215 this.__showCustomerIndex.purgeDependencyOnElmtId(rmElmtId); 216 this.__customerChange.purgeDependencyOnElmtId(rmElmtId); 217 this.__cutAndCopyEnable.purgeDependencyOnElmtId(rmElmtId); 218 this.__pasteEnable.purgeDependencyOnElmtId(rmElmtId); 219 this.__visibilityValue.purgeDependencyOnElmtId(rmElmtId); 220 this.__customMenuSize.purgeDependencyOnElmtId(rmElmtId); 221 } 222 223 aboutToBeDeleted() { 224 this.__showExpandedMenuOptions.aboutToBeDeleted(); 225 this.__showCustomerIndex.aboutToBeDeleted(); 226 this.__customerChange.aboutToBeDeleted(); 227 this.__cutAndCopyEnable.aboutToBeDeleted(); 228 this.__pasteEnable.aboutToBeDeleted(); 229 this.__visibilityValue.aboutToBeDeleted(); 230 this.__customMenuSize.aboutToBeDeleted(); 231 SubscriberManager.Get().delete(this.id__()); 232 this.aboutToBeDeletedInternal(); 233 } 234 235 CloserFun(parent = null) { 236 } 237 238 get showExpandedMenuOptions() { 239 return this.__showExpandedMenuOptions.get(); 240 } 241 242 set showExpandedMenuOptions(newValue) { 243 this.__showExpandedMenuOptions.set(newValue); 244 } 245 246 get showCustomerIndex() { 247 return this.__showCustomerIndex.get(); 248 } 249 250 set showCustomerIndex(newValue) { 251 this.__showCustomerIndex.set(newValue); 252 } 253 254 get customerChange() { 255 return this.__customerChange.get(); 256 } 257 258 set customerChange(newValue) { 259 this.__customerChange.set(newValue); 260 } 261 262 get cutAndCopyEnable() { 263 return this.__cutAndCopyEnable.get(); 264 } 265 266 set cutAndCopyEnable(newValue) { 267 this.__cutAndCopyEnable.set(newValue); 268 } 269 270 get pasteEnable() { 271 return this.__pasteEnable.get(); 272 } 273 274 set pasteEnable(newValue) { 275 this.__pasteEnable.set(newValue); 276 } 277 278 get visibilityValue() { 279 return this.__visibilityValue.get(); 280 } 281 282 set visibilityValue(newValue) { 283 this.__visibilityValue.set(newValue); 284 } 285 286 get customMenuSize() { 287 return this.__customMenuSize.get(); 288 } 289 290 set customMenuSize(newValue) { 291 this.__customMenuSize.set(newValue); 292 } 293 294 aboutToAppear() { 295 if (this.controller) { 296 let richEditorSelection = this.controller.getSelection(); 297 let start = richEditorSelection.selection[0]; 298 let end = richEditorSelection.selection[1]; 299 if (start !== end) { 300 this.cutAndCopyEnable = true; 301 } 302 if (start === 0 && this.controller.getSpans({ start: end + 1, end: end + 1 }).length === 0) { 303 this.visibilityValue = Visibility.None; 304 } 305 else { 306 this.visibilityValue = Visibility.Visible; 307 } 308 } 309 else if (this.expandedMenuOptions && this.expandedMenuOptions.length > 0) { 310 this.showExpandedMenuOptions = true; 311 } 312 let sysBoard = pasteboard.getSystemPasteboard(); 313 if (sysBoard && sysBoard.hasDataSync()) { 314 this.pasteEnable = true; 315 } 316 if (!(this.editorMenuOptions && this.editorMenuOptions.length > 0)) { 317 this.customMenuHeight = 0; 318 } 319 } 320 321 initialRender() { 322 this.observeComponentCreation2((elmtId, isInitialRender) => { 323 Column.create(); 324 Column.useShadowBatching(true); 325 Column.flexShrink(1); 326 Column.height(this.customMenuSize); 327 }, Column); 328 this.observeComponentCreation2((elmtId, isInitialRender) => { 329 If.create(); 330 if (this.editorMenuOptions && this.editorMenuOptions.length > 0) { 331 this.ifElseBranchUpdateFunction(0, () => { 332 this.IconPanel.bind(this)(this); 333 }); 334 } 335 else { 336 this.ifElseBranchUpdateFunction(1, () => { 337 }); 338 } 339 }, If); 340 If.pop(); 341 this.observeComponentCreation2((elmtId, isInitialRender) => { 342 Scroll.create(); 343 Scroll.backgroundColor(this.theme.backGroundColor); 344 Scroll.flexShrink(1); 345 Scroll.shadow(this.theme.iconPanelShadowStyle); 346 Scroll.borderRadius(this.theme.containerBorderRadius); 347 Scroll.onAreaChange((oldValue, newValue) => { 348 let newValueHeight = newValue.height; 349 let oldValueHeight = oldValue.height; 350 this.customMenuHeight += newValueHeight - oldValueHeight; 351 this.customMenuSize = this.customMenuHeight; 352 }); 353 }, Scroll); 354 this.SystemMenu.bind(this)(this); 355 Scroll.pop(); 356 Column.pop(); 357 } 358 359 pushDataToPasteboard(richEditorSelection) { 360 let sysBoard = pasteboard.getSystemPasteboard(); 361 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, ''); 362 if (richEditorSelection.spans && richEditorSelection.spans.length > 0) { 363 let count = richEditorSelection.spans.length; 364 for (let i = count - 1; i >= 0; i--) { 365 let item = richEditorSelection.spans[i]; 366 if (item?.textStyle) { 367 let span = item; 368 let style = span.textStyle; 369 let data = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN, span.value.substring(span.offsetInSpan[0], span.offsetInSpan[1])); 370 let prop = pasteData.getProperty(); 371 let temp = { 372 'color': style.fontColor, 373 'size': style.fontSize, 374 'style': style.fontStyle, 375 'weight': this.fontWeightTable[style.fontWeight], 376 'fontFamily': style.fontFamily, 377 'decorationType': style.decoration.type, 378 'decorationColor': style.decoration.color 379 }; 380 prop.additions[i] = temp; 381 pasteData.addRecord(data); 382 pasteData.setProperty(prop); 383 } 384 } 385 } 386 sysBoard.clearData(); 387 sysBoard.setData(pasteData).then(() => { 388 hilog.info(0x3900, 'Ace', 'SelectionMenu copy option, Succeeded in setting PasteData.'); 389 }).catch((err) => { 390 hilog.info(0x3900, 'Ace', 'SelectionMenu copy option, Failed to set PasteData. Cause:' + err.message); 391 }); 392 } 393 394 popDataFromPasteboard(richEditorSelection) { 395 let start = richEditorSelection.selection[0]; 396 let end = richEditorSelection.selection[1]; 397 if (start === end && this.controller) { 398 start = this.controller.getCaretOffset(); 399 end = this.controller.getCaretOffset(); 400 } 401 let moveOffset = 0; 402 let sysBoard = pasteboard.getSystemPasteboard(); 403 sysBoard.getData((err, data) => { 404 if (err) { 405 return; 406 } 407 let count = data.getRecordCount(); 408 for (let i = 0; i < count; i++) { 409 const element = data.getRecord(i); 410 let tex = { 411 fontSize: 16, 412 fontColor: Color.Black, 413 fontWeight: FontWeight.Normal, 414 fontFamily: 'HarmonyOS Sans', 415 fontStyle: FontStyle.Normal, 416 decoration: { type: TextDecorationType.None, color: '#FF000000' } 417 }; 418 if (data.getProperty() && data.getProperty().additions[i]) { 419 const tmp = data.getProperty().additions[i]; 420 if (tmp.color) { 421 tex.fontColor = tmp.color; 422 } 423 if (tmp.size) { 424 tex.fontSize = tmp.size; 425 } 426 if (tmp.style) { 427 tex.fontStyle = tmp.style; 428 } 429 if (tmp.weight) { 430 tex.fontWeight = tmp.weight; 431 } 432 if (tmp.fontFamily) { 433 tex.fontFamily = tmp.fontFamily; 434 } 435 if (tmp.decorationType && tex.decoration) { 436 tex.decoration.type = tmp.decorationType; 437 } 438 if (tmp.decorationColor && tex.decoration) { 439 tex.decoration.color = tmp.decorationColor; 440 } 441 if (tex.decoration) { 442 tex.decoration = { type: tex.decoration.type, color: tex.decoration.color }; 443 } 444 } 445 if (element && element.plainText && element.mimeType === pasteboard.MIMETYPE_TEXT_PLAIN && this.controller) { 446 this.controller.addTextSpan(element.plainText, { 447 style: tex, 448 offset: start + moveOffset 449 }); 450 moveOffset += element.plainText.length; 451 } 452 } 453 if (this.controller) { 454 this.controller.setCaretOffset(start + moveOffset); 455 } 456 if (start !== end && this.controller) { 457 this.controller.deleteSpans({ start: start + moveOffset, end: end + moveOffset }); 458 } 459 }); 460 } 461 462 measureButtonWidth() { 463 if (this.editorMenuOptions && this.editorMenuOptions.length < 5) { 464 return (this.theme.defaultMenuWidth - this.theme.expandedOptionPadding * 2 - 465 this.theme.editorOptionMargin * 2 * this.editorMenuOptions.length) / this.editorMenuOptions.length; 466 } 467 return this.theme.buttonSize; 468 } 469 470 IconPanel(parent = null) { 471 this.observeComponentCreation2((elmtId, isInitialRender) => { 472 Flex.create({ wrap: FlexWrap.Wrap }); 473 Flex.onAreaChange((oldValue, newValue) => { 474 let newValueHeight = newValue.height; 475 let oldValueHeight = oldValue.height; 476 this.customMenuHeight += newValueHeight - oldValueHeight; 477 this.customMenuSize = this.customMenuHeight; 478 }); 479 Flex.clip(true); 480 Flex.width(this.theme.defaultMenuWidth); 481 Flex.padding(this.theme.expandedOptionPadding); 482 Flex.borderRadius(this.theme.containerBorderRadius); 483 Flex.margin({ bottom: this.theme.menuSpacing }); 484 Flex.backgroundColor(this.theme.backGroundColor); 485 Flex.shadow(this.theme.iconPanelShadowStyle); 486 }, Flex); 487 this.observeComponentCreation2((elmtId, isInitialRender) => { 488 If.create(); 489 if (this.editorMenuOptions) { 490 this.ifElseBranchUpdateFunction(0, () => { 491 this.observeComponentCreation2((elmtId, isInitialRender) => { 492 ForEach.create(); 493 const forEachItemGenFunction = (_item, index) => { 494 const item = _item; 495 this.observeComponentCreation2((elmtId, isInitialRender) => { 496 Button.createWithChild(); 497 Button.enabled(!(!item.action && !item.builder)); 498 Button.type(ButtonType.Normal); 499 Button.margin(this.theme.editorOptionMargin); 500 Button.backgroundColor(this.theme.backGroundColor); 501 Button.onClick(() => { 502 if (item.builder) { 503 this.builder = item.builder; 504 this.showCustomerIndex = index; 505 this.showExpandedMenuOptions = false; 506 this.customerChange = !this.customerChange; 507 } 508 else { 509 this.showCustomerIndex = WITHOUT_BUILDER; 510 if (!this.controller) { 511 this.showExpandedMenuOptions = true; 512 } 513 } 514 if (item.action) { 515 item.action(); 516 } 517 }); 518 Button.borderRadius(this.theme.iconBorderRadius); 519 Button.width(this.measureButtonWidth()); 520 Button.height(this.theme.buttonSize); 521 }, Button); 522 this.observeComponentCreation2((elmtId, isInitialRender) => { 523 Image.create(item.icon); 524 Image.width(this.theme.imageSize); 525 Image.height(this.theme.imageSize); 526 Image.fillColor(this.theme.imageFillColor); 527 Image.focusable(true); 528 Image.draggable(false); 529 }, Image); 530 Button.pop(); 531 }; 532 this.forEachUpdateFunction(elmtId, this.editorMenuOptions, forEachItemGenFunction, undefined, true, false); 533 }, ForEach); 534 ForEach.pop(); 535 }); 536 } 537 else { 538 this.ifElseBranchUpdateFunction(1, () => { 539 }); 540 } 541 }, If); 542 If.pop(); 543 Flex.pop(); 544 } 545 546 SystemMenu(parent = null) { 547 this.observeComponentCreation2((elmtId, isInitialRender) => { 548 Column.create(); 549 Column.width(this.theme.defaultMenuWidth); 550 }, Column); 551 this.observeComponentCreation2((elmtId, isInitialRender) => { 552 If.create(); 553 if (this.showCustomerIndex === -1 && 554 (this.controller || (this.expandedMenuOptions && this.expandedMenuOptions.length > 0))) { 555 this.ifElseBranchUpdateFunction(0, () => { 556 this.observeComponentCreation2((elmtId, isInitialRender) => { 557 Menu.create(); 558 Menu.onVisibleAreaChange([0.0, 1.0], () => { 559 if (!this.controller) { 560 return; 561 } 562 let richEditorSelection = this.controller.getSelection(); 563 let start = richEditorSelection.selection[0]; 564 let end = richEditorSelection.selection[1]; 565 if (start !== end) { 566 this.cutAndCopyEnable = true; 567 } 568 if (start === 0 && this.controller.getSpans({ 569 start: end + 1, 570 end: end + 1 571 }).length === 0) { 572 this.visibilityValue = Visibility.None; 573 } 574 else { 575 this.visibilityValue = Visibility.Visible; 576 } 577 }); 578 Menu.radius(this.theme.containerBorderRadius); 579 Menu.clip(true); 580 Menu.width(this.theme.defaultMenuWidth); 581 }, Menu); 582 this.observeComponentCreation2((elmtId, isInitialRender) => { 583 If.create(); 584 if (this.controller) { 585 this.ifElseBranchUpdateFunction(0, () => { 586 this.observeComponentCreation2((elmtId, isInitialRender) => { 587 MenuItemGroup.create(); 588 }, MenuItemGroup); 589 this.observeComponentCreation2((elmtId, isInitialRender) => { 590 MenuItem.create({ 591 startIcon: this.theme.cutIcon, 592 content: '剪切', 593 labelInfo: 'Ctrl+X' 594 }); 595 MenuItem.enabled(this.cutAndCopyEnable); 596 MenuItem.onClick(() => { 597 if (!this.controller) { 598 return; 599 } 600 let richEditorSelection = this.controller.getSelection(); 601 if (this.onCut) { 602 this.onCut({ content: richEditorSelection }); 603 } 604 else { 605 this.pushDataToPasteboard(richEditorSelection); 606 this.controller.deleteSpans({ 607 start: richEditorSelection.selection[0], 608 end: richEditorSelection.selection[1] 609 }); 610 } 611 }); 612 }, MenuItem); 613 MenuItem.pop(); 614 this.observeComponentCreation2((elmtId, isInitialRender) => { 615 MenuItem.create({ 616 startIcon: this.theme.copyIcon, 617 content: '复制', 618 labelInfo: 'Ctrl+C' 619 }); 620 MenuItem.enabled(this.cutAndCopyEnable); 621 MenuItem.onClick(() => { 622 if (!this.controller) { 623 return; 624 } 625 let richEditorSelection = this.controller.getSelection(); 626 if (this.onCopy) { 627 this.onCopy({ content: richEditorSelection }); 628 } 629 else { 630 this.pushDataToPasteboard(richEditorSelection); 631 this.controller.closeSelectionMenu(); 632 } 633 }); 634 }, MenuItem); 635 MenuItem.pop(); 636 this.observeComponentCreation2((elmtId, isInitialRender) => { 637 MenuItem.create({ 638 startIcon: this.theme.pasteIcon, 639 content: '粘贴', 640 labelInfo: 'Ctrl+V' 641 }); 642 MenuItem.enabled(this.pasteEnable); 643 MenuItem.onClick(() => { 644 if (!this.controller) { 645 return; 646 } 647 let richEditorSelection = this.controller.getSelection(); 648 if (this.onPaste) { 649 this.onPaste({ content: richEditorSelection }); 650 } 651 else { 652 this.popDataFromPasteboard(richEditorSelection); 653 this.controller.closeSelectionMenu(); 654 } 655 }); 656 }, MenuItem); 657 MenuItem.pop(); 658 this.observeComponentCreation2((elmtId, isInitialRender) => { 659 MenuItem.create({ 660 startIcon: this.theme.selectAllIcon, 661 content: '全选', 662 labelInfo: 'Ctrl+A' 663 }); 664 MenuItem.visibility(this.visibilityValue); 665 MenuItem.onClick(() => { 666 if (!this.controller) { 667 return; 668 } 669 if (this.onSelectAll) { 670 let richEditorSelection = this.controller.getSelection(); 671 this.onSelectAll({ content: richEditorSelection }); 672 } 673 else { 674 this.controller.setSelection(-1, -1); 675 this.visibilityValue = Visibility.None; 676 } 677 this.controller.closeSelectionMenu(); 678 }); 679 }, MenuItem); 680 MenuItem.pop(); 681 MenuItemGroup.pop(); 682 }); 683 } 684 else { 685 this.ifElseBranchUpdateFunction(1, () => { 686 }); 687 } 688 }, If); 689 If.pop(); 690 this.observeComponentCreation2((elmtId, isInitialRender) => { 691 If.create(); 692 if (this.controller && !this.showExpandedMenuOptions && this.expandedMenuOptions && this.expandedMenuOptions.length > 0) { 693 this.ifElseBranchUpdateFunction(0, () => { 694 this.observeComponentCreation2((elmtId, isInitialRender) => { 695 MenuItem.create({ content: '更多', endIcon: this.theme.arrowDownIcon }); 696 MenuItem.onClick(() => { 697 this.showExpandedMenuOptions = true; 698 this.customMenuSize = '100%'; 699 }); 700 }, MenuItem); 701 MenuItem.pop(); 702 }); 703 } 704 else if (this.showExpandedMenuOptions && this.expandedMenuOptions && this.expandedMenuOptions.length > 0) { 705 this.ifElseBranchUpdateFunction(1, () => { 706 this.observeComponentCreation2((elmtId, isInitialRender) => { 707 ForEach.create(); 708 const forEachItemGenFunction = (_item, index) => { 709 const expandedMenuOptionItem = _item; 710 this.observeComponentCreation2((elmtId, isInitialRender) => { 711 MenuItem.create({ 712 startIcon: expandedMenuOptionItem.startIcon, 713 content: expandedMenuOptionItem.content, 714 endIcon: expandedMenuOptionItem.endIcon, 715 labelInfo: expandedMenuOptionItem.labelInfo, 716 builder: expandedMenuOptionItem.builder 717 }); 718 MenuItem.onClick(() => { 719 if (expandedMenuOptionItem.action) { 720 expandedMenuOptionItem.action(); 721 } 722 }); 723 }, MenuItem); 724 MenuItem.pop(); 725 }; 726 this.forEachUpdateFunction(elmtId, this.expandedMenuOptions, forEachItemGenFunction, undefined, true, false); 727 }, ForEach); 728 ForEach.pop(); 729 }); 730 } 731 else { 732 this.ifElseBranchUpdateFunction(2, () => { 733 }); 734 } 735 }, If); 736 If.pop(); 737 Menu.pop(); 738 }); 739 } 740 else if (this.showCustomerIndex > -1 && this.builder) { 741 this.ifElseBranchUpdateFunction(1, () => { 742 this.observeComponentCreation2((elmtId, isInitialRender) => { 743 If.create(); 744 if (this.customerChange) { 745 this.ifElseBranchUpdateFunction(0, () => { 746 this.builder.bind(this)(parent ? parent : this); 747 }); 748 } 749 else { 750 this.ifElseBranchUpdateFunction(1, () => { 751 this.builder.bind(this)(parent ? parent : this); 752 }); 753 } 754 }, If); 755 If.pop(); 756 }); 757 } 758 else { 759 this.ifElseBranchUpdateFunction(2, () => { 760 }); 761 } 762 }, If); 763 If.pop(); 764 Column.pop(); 765 } 766 767 rerender() { 768 this.updateDirtyElements(); 769 } 770} 771 772export function SelectionMenu(options, parent = null) { 773 const __options__ = options; 774 { 775 (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, options = __options__) => { 776 if (isInitialRender) { 777 let componentCall = new SelectionMenuComponent(typeof PUV2ViewBase !== 'undefined' && parent instanceof PUV2ViewBase ? parent : this, { 778 editorMenuOptions: options.editorMenuOptions, 779 expandedMenuOptions: options.expandedMenuOptions, 780 controller: options.controller, 781 onPaste: options.onPaste, 782 onCopy: options.onCopy, 783 onCut: options.onCut, 784 onSelectAll: options.onSelectAll 785 }, undefined, elmtId, () => { 786 }, { page: 'library/src/main/ets/components/mainpage/MainPage.ets', line: 459, col: 3 }); 787 ViewPU.create(componentCall); 788 let paramsLambda = () => { 789 return { 790 editorMenuOptions: options.editorMenuOptions, 791 expandedMenuOptions: options.expandedMenuOptions, 792 controller: options.controller, 793 onPaste: options.onPaste, 794 onCopy: options.onCopy, 795 onCut: options.onCut, 796 onSelectAll: options.onSelectAll 797 }; 798 }; 799 componentCall.paramsGenerator_ = paramsLambda; 800 } 801 else { 802 (parent ? parent : this).updateStateVarsOfChildByElmtId(elmtId, {}); 803 } 804 }, { name: 'SelectionMenuComponent' }); 805 } 806} 807export default { SelectionMenu };