From 04c1e358e4f014053cae583c1f897f9b462db371 Mon Sep 17 00:00:00 2001 From: wuyiwuyiwywy Date: Wed, 2 Aug 2023 17:12:21 +0800 Subject: [PATCH] add subheader & treeview Signed-off-by: wuyiwuyiwywy --- interface/subheader/BUILD.gn | 53 + interface/subheader/subheader.cpp | 54 + interface/subheader/subheader.js | 1141 +++++++++ interface/treeview/BUILD.gn | 55 + interface/treeview/treeview.cpp | 55 + interface/treeview/treeview.js | 3666 +++++++++++++++++++++++++++++ source/SubHeader/SubHeader.ets | 399 ++++ source/TreeView/TreeView.ets | 3327 ++++++++++++++++++++++++++ 8 files changed, 8750 insertions(+) create mode 100644 interface/subheader/BUILD.gn create mode 100644 interface/subheader/subheader.cpp create mode 100644 interface/subheader/subheader.js create mode 100644 interface/treeview/BUILD.gn create mode 100644 interface/treeview/treeview.cpp create mode 100644 interface/treeview/treeview.js create mode 100644 source/SubHeader/SubHeader.ets create mode 100644 source/TreeView/TreeView.ets diff --git a/interface/subheader/BUILD.gn b/interface/subheader/BUILD.gn new file mode 100644 index 0000000..52c64a8 --- /dev/null +++ b/interface/subheader/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") +import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") + +es2abc_gen_abc("gen_subheader_abc") { + src_js = rebase_path("subheader.js") + dst_file = rebase_path(target_out_dir + "/subheader.abc") + in_puts = [ "subheader.js" ] + out_puts = [ target_out_dir + "/subheader.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("subheader_abc") { + input = get_label_info(":gen_subheader_abc", "target_out_dir") + "/subheader.abc" + output = target_out_dir + "/subheader_abc.o" + dep = ":gen_subheader_abc" +} + +ohos_shared_library("subheader") { + sources = [ "subheader.cpp" ] + + deps = [ ":subheader_abc" ] + + if (is_standard_system) { + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + ] + } else { + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + ] + } + + subsystem_name = "arkui" + part_name = "advanced_ui_component" + + relative_install_dir = "module/arkui/advanced" +} \ No newline at end of file diff --git a/interface/subheader/subheader.cpp b/interface/subheader/subheader.cpp new file mode 100644 index 0000000..89d8b92 --- /dev/null +++ b/interface/subheader/subheader.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_engine/native_engine.h" + +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +extern const char _binary_subheader_abc_start[]; +extern const char _binary_subheader_abc_end[]; + +// Napi get abc code function +extern "C" __attribute__((visibility("default"))) +void NAPI_arkui_advanced_SubHeader_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_subheader_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_subheader_abc_end - _binary_subheader_abc_start; + } +} + +/* + * Module define + */ +static napi_module subheaderModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_modname = "arkui.advanced.SubHeader", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +/* + * Module register function + */ +extern "C" __attribute__((constructor)) void subheaderRegisterModule(void) +{ + napi_module_register(&subheaderModule); +} \ No newline at end of file diff --git a/interface/subheader/subheader.js b/interface/subheader/subheader.js new file mode 100644 index 0000000..651a883 --- /dev/null +++ b/interface/subheader/subheader.js @@ -0,0 +1,1141 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const SPACE_MARGIN = 8; +const MARGIN_NUM = 4; +const IMAGE_WIDTH_NUM = 16; +const IMAGE_HEIGHT_NUM = 24; +const BUTTON_SIZE = 32; +const SINGLE_LINE_HEIGHT = 48; +const DOUBLE_LINE_HEIGHT = 64; +const BUTTON_HEIGHT = 28; +const IMAGE_WIDTH = 12; +const BORDER_WIDTH = 2; +const SINGLE_LINE_NUM = 1; +const DOUBLE_LINE_NUM = 2; +const MIN_FONT_SIZE = 14; +const MAIN_TEXT_SIZE = 10; +const MIN_CONSTRAINT_WIDTH = 3; + +export var OperationType; +!function(e){ + e[e.TEXT_ARROW=0] = "TEXT_ARROW"; + e[e.BUTTON=1] = "BUTTON"; + e[e.ICON_GROUP=2] = "ICON_GROUP"; + e[e.LOADING=3] = "LOADING" +}(OperationType || (OperationType = {})); + +class ButtonStyle extends ViewPU { + constructor(e, o, t, s = -1) { + super(e, t, s); + this.__buttonBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "buttonBgColor"); + this.__isButtonFocus = new ObservedPropertySimplePU(!1, this, "isButtonFocus"); + this.button = void 0; + this.focusBorderWidth = 2; + this.setInitiallyProvidedValue(o) + } + + setInitiallyProvidedValue(e) { + void 0 !== e.buttonBgColor && (this.buttonBgColor = e.buttonBgColor); + void 0 !== e.isButtonFocus && (this.isButtonFocus = e.isButtonFocus); + void 0 !== e.button && (this.button = e.button); + void 0 !== e.focusBorderWidth && (this.focusBorderWidth = e.focusBorderWidth) + } + + updateStateVars(e) { + } + + purgeVariableDependenciesOnElmtId(e) { + this.__buttonBgColor.purgeDependencyOnElmtId(e); + this.__isButtonFocus.purgeDependencyOnElmtId(e) + } + + aboutToBeDeleted() { + this.__buttonBgColor.aboutToBeDeleted(); + this.__isButtonFocus.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal() + } + + get buttonBgColor() { + return this.__buttonBgColor.get() + } + + set buttonBgColor(e) { + this.__buttonBgColor.set(e) + } + + get isButtonFocus() { + return this.__isButtonFocus.get() + } + + set isButtonFocus(e) { + this.__isButtonFocus.set(e) + } + + initialRender() { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.align(Alignment.End); + Row.justifyContent(FlexAlign.Center); + Row.focusable(!0); + Row.height(28); + Row.margin({ left: 8, right: 8 }); + Row.borderRadius(16); + Row.backgroundColor(ObservedObject.GetRawObject(this.buttonBgColor)); + Row.onTouch((e => { + if (e.type === TouchType.Down) { + this.button.action && this.button.action(); + this.buttonBgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_click_effect"], + bundleName: "", + moduleName: "" + } + } + e.type === TouchType.Up && (this.buttonBgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }) + })); + Row.onHover((e => { + this.buttonBgColor = e ? { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_hover"], + bundleName: "", + moduleName: "" + } : { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + } + })); + Row.border(this.isButtonFocus ? { + width: this.focusBorderWidth, + color: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_focused_outline"], + bundleName: "", + moduleName: "" + }, + style: BorderStyle.Solid + } : { width: 0 }); + Row.onFocus((() => { + this.isButtonFocus = !0 + })); + Row.onBlur((() => { + this.isButtonFocus = !1 + })); + Row.onKeyEvent((e => { + 2054 !== e.keyCode && 2050 !== e.keyCode || this.button.action && this.button.action() + })); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Text.create(this.button.value); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_primary_activated"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_button2"], + bundleName: "", + moduleName: "" + }); + Text.fontWeight(FontWeight.Medium); + Text.margin({ left: 8, right: 8 }); + Text.focusable(!0); + Text.maxLines(2); + o || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Row.pop() + } + + rerender() { + this.updateDirtyElements() + } +} + +class IconGroup extends ViewPU { + constructor(e, o, t, s = -1) { + super(e, t, s); + this.__bgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "bgColor"); + this.__isFocus = new ObservedPropertySimplePU(!1, this, "isFocus"); + this.item = void 0; + this.focusBorderWidth = 2; + this.setInitiallyProvidedValue(o) + } + + setInitiallyProvidedValue(e) { + void 0 !== e.bgColor && (this.bgColor = e.bgColor); + void 0 !== e.isFocus && (this.isFocus = e.isFocus); + void 0 !== e.item && (this.item = e.item); + void 0 !== e.focusBorderWidth && (this.focusBorderWidth = e.focusBorderWidth) + } + + updateStateVars(e) { + } + + purgeVariableDependenciesOnElmtId(e) { + this.__bgColor.purgeDependencyOnElmtId(e); + this.__isFocus.purgeDependencyOnElmtId(e) + } + + aboutToBeDeleted() { + this.__bgColor.aboutToBeDeleted(); + this.__isFocus.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal() + } + + get bgColor() { + return this.__bgColor.get() + } + + set bgColor(e) { + this.__bgColor.set(e) + } + + get isFocus() { + return this.__isFocus.get() + } + + set isFocus(e) { + this.__isFocus.set(e) + } + + initialRender() { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.focusable(!0); + Row.width(32); + Row.height(32); + Row.margin({ right: 8 }); + Row.justifyContent(FlexAlign.Center); + Row.borderRadius({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_clicked"], + bundleName: "", + moduleName: "" + }); + Row.backgroundColor(ObservedObject.GetRawObject(this.bgColor)); + Row.onTouch((e => { + if (e.type === TouchType.Down) { + this.item.action && this.item.action(); + this.bgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_click_effect"], + bundleName: "", + moduleName: "" + } + } + e.type === TouchType.Up && (this.bgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }) + })); + Row.onHover((e => { + this.bgColor = e ? { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_hover"], + bundleName: "", + moduleName: "" + } : { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + } + })); + Row.border(this.isFocus ? { + width: this.focusBorderWidth, + color: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_emphasize"], + bundleName: "", + moduleName: "" + }, + style: BorderStyle.Solid + } : { width: 0 }); + Row.onFocus((() => { + this.isFocus = !0 + })); + Row.onBlur((() => { + this.isFocus = !1 + })); + Row.onKeyEvent((e => { + 2054 !== e.keyCode && 2050 !== e.keyCode || this.item.action && this.item.action() + })); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(this.item.value); + Image.fillColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary"], + bundleName: "", + moduleName: "" + }); + Image.width(24); + Image.height(24); + Image.focusable(!0); + o || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + } + + rerender() { + this.updateDirtyElements() + } +} + +export class SubHeader extends ViewPU { + constructor(e, o, t, s = -1) { + super(e, t, s); + this.__icon = new SynchedPropertyObjectOneWayPU(o.icon, this, "icon"); + this.__primaryTitle = new SynchedPropertySimpleOneWayPU(o.primaryTitle, this, "primaryTitle"); + this.__secondaryTitle = new SynchedPropertySimpleOneWayPU(o.secondaryTitle, this, "secondaryTitle"); + this.__select = new SynchedPropertyObjectOneWayPU(o.select, this, "select"); + this.__operationType = new SynchedPropertySimpleOneWayPU(o.operationType, this, "operationType"); + this.operationItem = void 0; + this.__isDuplicateLine = new ObservedPropertySimplePU(!1, this, "isDuplicateLine"); + this.__textArrowBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "textArrowBgColor"); + this.__buttonBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "buttonBgColor"); + this.__iconBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "iconBgColor"); + this.__firstIconBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "firstIconBgColor"); + this.__SecondaryIconBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "SecondaryIconBgColor"); + this.__thirdIconBgColor = new ObservedPropertyObjectPU({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }, this, "thirdIconBgColor"); + this.__flag = new ObservedPropertySimplePU(!1, this, "flag"); + this.__isTextArrowFocus = new ObservedPropertySimplePU(!1, this, "isTextArrowFocus"); + this.focusBorderWidth = 2; + this.setInitiallyProvidedValue(o) + } + + setInitiallyProvidedValue(e) { + void 0 !== e.operationType ? this.__operationType.set(e.operationType) : this.__operationType.set(OperationType.BUTTON); + void 0 !== e.operationItem && (this.operationItem = e.operationItem); + void 0 !== e.isDuplicateLine && (this.isDuplicateLine = e.isDuplicateLine); + void 0 !== e.textArrowBgColor && (this.textArrowBgColor = e.textArrowBgColor); + void 0 !== e.buttonBgColor && (this.buttonBgColor = e.buttonBgColor); + void 0 !== e.iconBgColor && (this.iconBgColor = e.iconBgColor); + void 0 !== e.firstIconBgColor && (this.firstIconBgColor = e.firstIconBgColor); + void 0 !== e.SecondaryIconBgColor && (this.SecondaryIconBgColor = e.SecondaryIconBgColor); + void 0 !== e.thirdIconBgColor && (this.thirdIconBgColor = e.thirdIconBgColor); + void 0 !== e.flag && (this.flag = e.flag); + void 0 !== e.isTextArrowFocus && (this.isTextArrowFocus = e.isTextArrowFocus); + void 0 !== e.focusBorderWidth && (this.focusBorderWidth = e.focusBorderWidth) + } + + updateStateVars(e) { + this.__icon.reset(e.icon); + this.__primaryTitle.reset(e.primaryTitle); + this.__secondaryTitle.reset(e.secondaryTitle); + this.__select.reset(e.select); + this.__operationType.reset(e.operationType) + } + + purgeVariableDependenciesOnElmtId(e) { + this.__icon.purgeDependencyOnElmtId(e); + this.__primaryTitle.purgeDependencyOnElmtId(e); + this.__secondaryTitle.purgeDependencyOnElmtId(e); + this.__select.purgeDependencyOnElmtId(e); + this.__operationType.purgeDependencyOnElmtId(e); + this.__isDuplicateLine.purgeDependencyOnElmtId(e); + this.__textArrowBgColor.purgeDependencyOnElmtId(e); + this.__buttonBgColor.purgeDependencyOnElmtId(e); + this.__iconBgColor.purgeDependencyOnElmtId(e); + this.__firstIconBgColor.purgeDependencyOnElmtId(e); + this.__SecondaryIconBgColor.purgeDependencyOnElmtId(e); + this.__thirdIconBgColor.purgeDependencyOnElmtId(e); + this.__flag.purgeDependencyOnElmtId(e); + this.__isTextArrowFocus.purgeDependencyOnElmtId(e) + } + + aboutToBeDeleted() { + this.__icon.aboutToBeDeleted(); + this.__primaryTitle.aboutToBeDeleted(); + this.__secondaryTitle.aboutToBeDeleted(); + this.__select.aboutToBeDeleted(); + this.__operationType.aboutToBeDeleted(); + this.__isDuplicateLine.aboutToBeDeleted(); + this.__textArrowBgColor.aboutToBeDeleted(); + this.__buttonBgColor.aboutToBeDeleted(); + this.__iconBgColor.aboutToBeDeleted(); + this.__firstIconBgColor.aboutToBeDeleted(); + this.__SecondaryIconBgColor.aboutToBeDeleted(); + this.__thirdIconBgColor.aboutToBeDeleted(); + this.__flag.aboutToBeDeleted(); + this.__isTextArrowFocus.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal() + } + + get icon() { + return this.__icon.get() + } + + set icon(e) { + this.__icon.set(e) + } + + get primaryTitle() { + return this.__primaryTitle.get() + } + + set primaryTitle(e) { + this.__primaryTitle.set(e) + } + + get secondaryTitle() { + return this.__secondaryTitle.get() + } + + set secondaryTitle(e) { + this.__secondaryTitle.set(e) + } + + get select() { + return this.__select.get() + } + + set select(e) { + this.__select.set(e) + } + + get operationType() { + return this.__operationType.get() + } + + set operationType(e) { + this.__operationType.set(e) + } + + get isDuplicateLine() { + return this.__isDuplicateLine.get() + } + + set isDuplicateLine(e) { + this.__isDuplicateLine.set(e) + } + + get textArrowBgColor() { + return this.__textArrowBgColor.get() + } + + set textArrowBgColor(e) { + this.__textArrowBgColor.set(e) + } + + get buttonBgColor() { + return this.__buttonBgColor.get() + } + + set buttonBgColor(e) { + this.__buttonBgColor.set(e) + } + + get iconBgColor() { + return this.__iconBgColor.get() + } + + set iconBgColor(e) { + this.__iconBgColor.set(e) + } + + get firstIconBgColor() { + return this.__firstIconBgColor.get() + } + + set firstIconBgColor(e) { + this.__firstIconBgColor.set(e) + } + + get SecondaryIconBgColor() { + return this.__SecondaryIconBgColor.get() + } + + set SecondaryIconBgColor(e) { + this.__SecondaryIconBgColor.set(e) + } + + get thirdIconBgColor() { + return this.__thirdIconBgColor.get() + } + + set thirdIconBgColor(e) { + this.__thirdIconBgColor.set(e) + } + + get flag() { + return this.__flag.get() + } + + set flag(e) { + this.__flag.set(e) + } + + get isTextArrowFocus() { + return this.__isTextArrowFocus.get() + } + + set isTextArrowFocus(e) { + this.__isTextArrowFocus.set(e) + } + + ListTextStyle(e, o = null) { + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.content); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_secondary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title3"], + bundleName: "", + moduleName: "" + }); + Text.maxLines(2); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + Text.margin({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_max_padding_end"], + bundleName: "", + moduleName: "" + }, + bottom: 8, + right: 4 + }); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop() + } + + ListIconStyle(e, o, t = null) { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.margin({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_max_padding_end"], + bundleName: "", + moduleName: "" + }, + bottom: 8, + right: 4 + }); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(o); + Image.width(16); + Image.height(16); + Image.margin({ right: 8 }); + t || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.content); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_secondary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title3"], + bundleName: "", + moduleName: "" + }); + Text.maxLines(2); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Row.pop() + } + + ContentTextStyle(e, o = null) { + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.content); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_primary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title2"], + bundleName: "", + moduleName: "" + }); + Text.maxLines(2); + Text.maxFontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title2"], + bundleName: "", + moduleName: "" + }); + Text.minFontSize(14); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + Text.margin({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_max_padding_start"], + bundleName: "", + moduleName: "" + }, + right: 4, + bottom: 8 + }); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop() + } + + SubTextStyle(e, o = null) { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Column.create(); + Column.alignItems(HorizontalAlign.Start); + Column.onAppear((() => { + this.isDuplicateLine = !0 + })); + Column.margin({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_max_padding_start"], + bundleName: "", + moduleName: "" + }, + right: 4, + bottom: 8 + }); + o || Column.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.content); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_primary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title2"], + bundleName: "", + moduleName: "" + }); + Text.maxLines(1); + Text.maxFontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title2"], + bundleName: "", + moduleName: "" + }); + Text.minFontSize(14); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.subContent); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_secondary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title3"], + bundleName: "", + moduleName: "" + }); + Text.maxLines(1); + Text.maxFontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_sub_title3"], + bundleName: "", + moduleName: "" + }); + Text.minFontSize(10); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Column.pop() + } + + SelectStyle(e, o = null) { + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Select.create(e.options); + Select.selected(e.selected); + Select.value(e.value); + Select.onSelect(((o, t) => { + e.onSelect && e.onSelect(o, t) + })); + Select.margin({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_default_padding_start"], + bundleName: "", + moduleName: "" + }, + right: 4 + }); + t || Select.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Select.pop() + } + + LoadingProcessStyle(e = null) { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + LoadingProgress.create(); + LoadingProgress.width(24); + LoadingProgress.height(24); + LoadingProgress.focusable(!0); + LoadingProgress.margin({ + right: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_default_padding_end"], + bundleName: "", + moduleName: "" + } + }); + o || LoadingProgress.pop(); + ViewStackProcessor.StopGetAccessRecording() + })) + } + + TextArrowStyle(e, o = null) { + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Row.create(); + Row.focusable(!0); + Row.margin({ left: 4, right: 4, bottom: 4 }); + Row.borderRadius({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_subtab"], + bundleName: "", + moduleName: "" + }); + Row.backgroundColor(ObservedObject.GetRawObject(this.textArrowBgColor)); + Row.onTouch((o => { + if (o.type === TouchType.Down) { + e.action && e.action(); + this.textArrowBgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_click_effect"], + bundleName: "", + moduleName: "" + } + } + o.type === TouchType.Up && (this.textArrowBgColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }) + })); + Row.onHover((e => { + this.textArrowBgColor = e ? { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_hover"], + bundleName: "", + moduleName: "" + } : { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + } + })); + Row.border(this.isTextArrowFocus ? { + width: this.focusBorderWidth, + color: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_focused_outline"], + bundleName: "", + moduleName: "" + }, + style: BorderStyle.Solid + } : { width: 0 }); + Row.onFocus((() => { + this.isTextArrowFocus = !0 + })); + Row.onBlur((() => { + this.isTextArrowFocus = !1 + })); + Row.onKeyEvent((o => { + 2054 !== o.keyCode && 2050 !== o.keyCode || e.action && e.action() + })); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.margin({ left: 8, right: 8 }); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((o, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Text.create(e.value); + Text.fontColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_secondary"], + bundleName: "", + moduleName: "" + }); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body2"], + bundleName: "", + moduleName: "" + }); + Text.margin({ right: 4 }); + Text.focusable(!0); + Text.maxLines(2); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create({ + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_right"], + bundleName: "", + moduleName: "" + }); + Image.fillColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_tertiary"], + bundleName: "", + moduleName: "" + }); + Image.width(12); + Image.height(24); + Image.focusable(!0); + o || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop(); + Row.pop() + } + + initialRender() { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Flex.create({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.End }); + Flex.padding({ + right: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_default_padding_end"], + bundleName: "", + moduleName: "" + } + }); + Flex.height(this.isDuplicateLine ? 64 : 48); + o || Flex.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + null != this.secondaryTitle && null != this.icon ? this.ifElseBranchUpdateFunction(0, (() => { + this.ListIconStyle.bind(this)({ content: this.secondaryTitle }, ObservedObject.GetRawObject(this.icon)) + })) : null != this.secondaryTitle && null != this.primaryTitle ? this.ifElseBranchUpdateFunction(1, (() => { + this.SubTextStyle.bind(this)(makeBuilderParameterProxy("SubTextStyle", { + content: () => this.__primaryTitle ? this.__primaryTitle : this.primaryTitle, + subContent: () => this.__secondaryTitle ? this.__secondaryTitle : this.secondaryTitle + })) + })) : null != this.secondaryTitle ? this.ifElseBranchUpdateFunction(2, (() => { + this.ListTextStyle.bind(this)(makeBuilderParameterProxy("ListTextStyle", { + content: () => this.__secondaryTitle ? this.__secondaryTitle : this.secondaryTitle + })) + })) : null != this.select ? this.ifElseBranchUpdateFunction(3, (() => { + this.SelectStyle.bind(this)(ObservedObject.GetRawObject(this.select)) + })) : null != this.primaryTitle && this.ifElseBranchUpdateFunction(4, (() => { + this.ContentTextStyle.bind(this)(makeBuilderParameterProxy("ContentTextStyle", { + content: () => this.__primaryTitle ? this.__primaryTitle : this.primaryTitle + })) + })); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.operationType === OperationType.BUTTON && null != this.operationItem ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + __Common__.create(); + __Common__.margin({ bottom: 4 }); + o || __Common__.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + o ? ViewPU.create(new ButtonStyle(this, { + button: this.operationItem[0] + }, void 0, e)) : this.updateStateVarsOfChildByElmtId(e, {}); + ViewStackProcessor.StopGetAccessRecording() + })); + __Common__.pop() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.operationType === OperationType.ICON_GROUP && null != this.operationItem ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.margin({ bottom: 4 }); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + ForEach.create(); + this.forEachUpdateFunction(e, this.operationItem, ((e, o) => { + const t = e; + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + 0 == o ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + o ? ViewPU.create(new IconGroup(this, { + item: t + }, void 0, e)) : this.updateStateVarsOfChildByElmtId(e, {}); + ViewStackProcessor.StopGetAccessRecording() + })) + })) : If.branchId(1); + s || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + 1 == o ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + o ? ViewPU.create(new IconGroup(this, { + item: t + }, void 0, e)) : this.updateStateVarsOfChildByElmtId(e, {}); + ViewStackProcessor.StopGetAccessRecording() + })) + })) : If.branchId(1); + s || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + 2 == o ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + o ? ViewPU.create(new IconGroup(this, { + item: t + }, void 0, e)) : this.updateStateVarsOfChildByElmtId(e, {}); + ViewStackProcessor.StopGetAccessRecording() + })) + })) : If.branchId(1); + s || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop() + }), void 0,!0,!1); + o || ForEach.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + ForEach.pop(); + Row.pop() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.operationType === OperationType.TEXT_ARROW && null != this.operationItem ? this.ifElseBranchUpdateFunction(0, (() => { + this.TextArrowStyle.bind(this)(this.operationItem[0]) + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.operationType === OperationType.LOADING ? this.ifElseBranchUpdateFunction(0, (() => { + this.LoadingProcessStyle.bind(this)() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Flex.pop() + } + + rerender() { + this.updateDirtyElements() + } +} + +export default { OperationStyle, SubHeader } \ No newline at end of file diff --git a/interface/treeview/BUILD.gn b/interface/treeview/BUILD.gn new file mode 100644 index 0000000..636f9b4 --- /dev/null +++ b/interface/treeview/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2023-2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/arkui/ace_engine/ace_config.gni") +import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") + +es2abc_gen_abc("gen_treeview_abc") { + src_js = rebase_path("treeview.js") + dst_file = rebase_path(target_out_dir + "/treeview.abc") + in_puts = [ "treeview.js" ] + out_puts = [ target_out_dir + "/treeview.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("treeview_abc") { + input = get_label_info(":gen_treeview_abc", "target_out_dir") + "/treeview.abc" + output = target_out_dir + "/treeview_abc.o" + dep = ":gen_treeview_abc" +} + +ohos_shared_library("treeview") { + sources = [ "treeview.cpp" ] + + deps = [ ":treeview_abc" ] + + if (is_standard_system) { + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + ] + } else { + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + ] + } + + subsystem_name = "arkui" + part_name = "advanced_ui_component" + + relative_install_dir = "module/arkui/advanced" +} + + diff --git a/interface/treeview/treeview.cpp b/interface/treeview/treeview.cpp new file mode 100644 index 0000000..1c51ddb --- /dev/null +++ b/interface/treeview/treeview.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_engine/native_engine.h" + +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +extern const char _binary_treeview_abc_start[]; +extern const char _binary_treeview_abc_end[]; + +// Napi get abc code function +extern "C" __attribute__((visibility("default"))) +void NAPI_arkui_advanced_TreeView_GetABCCode(const char **buf, int *buflen) +{ + + if (buf != nullptr) { + *buf = _binary_treeview_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_treeview_abc_end - _binary_treeview_abc_start; + } +} + +/* + * Module define + */ +static napi_module treeviewModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_modname = "arkui.advanced.TreeView", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +/* + * Module register function + */ +extern "C" __attribute__((constructor)) void treeviewRegisterModule(void) +{ + napi_module_register(&treeviewModule); +} \ No newline at end of file diff --git a/interface/treeview/treeview.js b/interface/treeview/treeview.js new file mode 100644 index 0000000..25425d8 --- /dev/null +++ b/interface/treeview/treeview.js @@ -0,0 +1,3666 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var __decorate = this && this.__decorate || function (e, t, o, i) { + var s, a = arguments.length, d = a < 3 ? t : null === i ? i = Object.getOwnPropertyDescriptor(t, o) : i; + if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) d = Reflect.decorate(e, t, o, i); else for (var r = e.length - 1;r >= 0; r--) (s = e[r]) && (d = (a < 3 ? s(d) : a > 3 ? s(t, o, d) : s(t, o)) || d); + return a > 3 && d && Object.defineProperty(t, o, d), d +}; + +export var TreeView; +!function(e){ + const t = "#00000000"; + const o = "#FFFFFF"; + + class i { + constructor() { + this._events = [] + } + + on(e, t) { + if (Array.isArray(e)) for (let o = 0, + i = e.length;o < i; o++) this.on(e[o], t); else (this._events[e] || (this._events[e] = [])).push(t) + } + + once(e, t) { + let o = this; + + function i() { + o.off(e, i); + t.apply(null, [e, t]) + } + + i.callback = t; + this.on(e, i) + } + + off(e, t) { + null == e && (this._events = []); + if (Array.isArray(e)) for (let o = 0, i = e.length;o < i; o++) this.off(e[o], t); + const o = this._events[e]; + if (!o) return; + null == t && (this._events[e] = null); + let i, s = o.length; + for (; s--; ) { + i = o[s]; + if (i === t || i.callback === t) { + o.splice(s, 1); + break + } + } + } + + emit(e, t) { + let o = this; + if (!this._events[e]) return; + let i = [...this._events[e]]; + if (i) for (let e = 0, s = i.length;e < s; e++) try { + i[e].apply(o, t) + } catch (e) { + new Error(e) + } + } + } + + e.TreeListener = i; + let s; + !function(e){ + e.NODE_ADD = "NodeAdd"; + e.NODE_DELETE = "NodeDelete"; + e.NODE_MODIFY = "NodeModify"; + e.NODE_MOVE = "NodeMove"; + e.NODE_CLICK = "NodeClick" + }(s = e.TreeListenType || (e.TreeListenType = {})); + + class a { + constructor() { + this.appEventBus = new i + } + + static getInstance() { + null == AppStorage.Get(this.APP_KEY_EVENT_BUS) && AppStorage.SetOrCreate(this.APP_KEY_EVENT_BUS, new a); + return AppStorage.Get(this.APP_KEY_EVENT_BUS) + } + + getTreeListener() { + return this.appEventBus + } + } + + a.APP_KEY_EVENT_BUS = "app_key_event_bus"; + e.TreeListenerManager = a; + + class d { + constructor() { + this.listeners = [] + } + + totalCount() { + return 0 + } + + getData(e) { + } + + registerDataChangeListener(e) { + this.listeners.indexOf(e) < 0 && this.listeners.push(e) + } + + unregisterDataChangeListener(e) { + const t = this.listeners.indexOf(e); + t >= 0 && this.listeners.splice(t, 1) + } + + notifyDataReload() { + this.listeners.forEach((e => { + e.onDataReloaded() + })) + } + + notifyDataAdd(e) { + this.listeners.forEach((t => { + t.onDataAdd(e) + })) + } + + notifyDataChange(e) { + this.listeners.forEach((t => { + t.onDataChange(e) + })) + } + + notifyDataDelete(e) { + this.listeners.forEach((t => { + t.onDataDelete(e) + })) + } + + notifyDataMove(e, t) { + this.listeners.forEach((o => { + o.onDataMove(e, t) + })) + } + } + + let r; + !function(e){ + e[e.TOUCH_DOWN=0] = "TOUCH_DOWN"; + e[e.TOUCH_UP=1] = "TOUCH_UP"; + e[e.HOVER=3] = "HOVER"; + e[e.HOVER_OVER=4] = "HOVER_OVER"; + e[e.FOCUS=5] = "FOCUS"; + e[e.BLUR=6] = "BLUR"; + e[e.MOUSE_BUTTON_RIGHT=7] = "MOUSE_BUTTON_RIGHT"; + e[e.DRAG=8] = "DRAG" + }(r = e.Event || (e.Event = {})); + let n; + !function(e){ + e[e.ADD_NODE=0] = "ADD_NODE"; + e[e.REMOVE_NODE=1] = "REMOVE_NODE"; + e[e.MODIFY_NODE=2] = "MODIFY_NODE"; + e[e.COMMIT_NODE=3] = "COMMIT_NODE" + }(n = e.MenuOperation || (e.MenuOperation = {})); + let l; + !function(e){ + e[e.HINTS=0] = "HINTS"; + e[e.WARNINGS=1] = "WARNINGS" + }(l = e.PopUpType || (e.PopUpType = {})); + let h; + !function(e){ + e[e.INVALID_ERROR=0] = "INVALID_ERROR"; + e[e.LENGTH_ERROR=1] = "LENGTH_ERROR"; + e[e.NONE=2] = "NONE" + }(h = e.InputError || (e.InputError = {})); + let g; + !function(e){ + e[e.DOWN_FLAG=0] = "DOWN_FLAG"; + e[e.UP_FLAG=1] = "UP_FLAG"; + e[e.NONE=2] = "NONE" + }(g = e.Flag || (e.Flag = {})); + + class c { + constructor(e) { + this.data = e; + this.nodeLevel = -1; + this.parentNodeId = -1; + this.nodeItem = { imageNode: null, mainTitleNode: null, imageCollapse: null }; + this.childNodeInfo = { isHasChildNode: !1, childNum: 0, allChildNum: 0 }; + this.menu = e.menu; + e.icon && (this.nodeItem.imageNode = new p(e.icon, e.selectedIcon, e.editIcon, { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_alpha_content_fourth"], + bundleName: "", + moduleName: "" + }, 24, 24)); + e.primaryTitle && (this.nodeItem.mainTitleNode = new m(e.primaryTitle)); + this.children = [] + } + + addImageCollapse(e) { + if (e) { + this.nodeItem.imageCollapse = new p({ + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_right"], + bundleName: "", + moduleName: "" + }, null, null, { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_alpha_content_tertiary"], + bundleName: "", + moduleName: "" + }, 24, 24); + this.nodeItem.imageCollapse.itemRightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_paragraph_margin_xs"], + bundleName: "", + moduleName: "" + } + } else this.nodeItem.imageCollapse = null + } + + getNodeItem() { + return this.nodeItem + } + + getChildNodeInfo() { + return this.childNodeInfo + } + + getMenu() { + return this.menu + } + + getCurrentNodeId() { + return this.currentNodeId + } + + getIsFolder() { + return this.data.isFolder + } + } + + e.NodeItem = c; + + class N { + constructor() { + } + + set itemWidth(e) { + this.width = e + } + + get itemWidth() { + return this.width + } + + set itemHeight(e) { + this.height = e + } + + get itemHeight() { + return this.height + } + + set itemRightMargin(e) { + this.rightMargin = e + } + + get itemRightMargin() { + return this.rightMargin + } + } + + let I; + !function(e){ + e[e.Expand=0] = "Expand"; + e[e.Collapse=1] = "Collapse" + }(I = e.NodeStatus || (e.NodeStatus = {})); + let u; + !function(e){ + e[e.Normal=0] = "Normal"; + e[e.Selected=1] = "Selected"; + e[e.Edit=2] = "Edit"; + e[e.FinishEdit=3] = "FinishEdit"; + e[e.DragInsert=4] = "DragInsert"; + e[e.FinishDragInsert=5] = "FinishDragInsert" + }(u = e.InteractionStatus || (e.InteractionStatus = {})); + + class p extends N { + constructor(e, t, o, i, s, a) { + super(); + this.rightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_elements_margin_horizontal_m"], + bundleName: "", + moduleName: "" + }; + this.imageSource = e; + this.imageNormalSource = e; + this.imageSelectedSource = null != t ? t : this.imageNormalSource; + this.imageEditSource = null != o ? o : this.imageNormalSource; + this.imageOpacity = i; + this.itemWidth = s; + this.itemHeight = a; + this.imageCollapseSource = e; + this.imageCollapseDownSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_down"], + bundleName: "", + moduleName: "" + }; + this.imageCollapseRightSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_right"], + bundleName: "", + moduleName: "" + }; + this.isImageCollapse = !0 + } + + get source() { + return this.imageSource + } + + get normalSource() { + return this.imageNormalSource + } + + get selectedSource() { + return this.imageSelectedSource + } + + get editSource() { + return this.imageEditSource + } + + get opacity() { + return this.imageOpacity + } + + get noOpacity() { + return 1 + } + + get collapseSource() { + return this.imageCollapseSource + } + + get isCollapse() { + return this.isImageCollapse + } + + changeImageCollapseSource(e) { + e == I.Expand ? this.imageCollapseSource = this.imageCollapseDownSource : e == I.Collapse && (this.imageCollapseSource = this.imageCollapseRightSource) + } + + setImageCollapseSource(e, t) { + if (e === u.Edit || e === u.DragInsert) { + this.imageCollapseDownSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_down"], + bundleName: "", + moduleName: "" + }; + this.imageCollapseRightSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_right"], + bundleName: "", + moduleName: "" + }; + this.isImageCollapse = !1 + } else if (e === u.FinishEdit || e === u.FinishDragInsert) { + this.imageCollapseDownSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_down"], + bundleName: "", + moduleName: "" + }; + this.imageCollapseRightSource = { + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_right"], + bundleName: "", + moduleName: "" + }; + this.isImageCollapse = !0 + } + this.imageCollapseSource = t == I.Collapse ? this.imageCollapseRightSource : this.imageCollapseDownSource + } + + setImageSource(e) { + switch (e) { + case u.Normal: + this.imageSource = this.imageNormalSource; + this.currentInteractionStatus = e; + break; + case u.Selected: + if (this.currentInteractionStatus !== u.Edit) { + this.imageSource = this.imageSelectedSource; + this.currentInteractionStatus = e + } + break; + case u.Edit: + this.imageSource = this.imageEditSource; + this.currentInteractionStatus = e; + break; + case u.FinishEdit: + this.imageSource = this.imageSelectedSource; + this.currentInteractionStatus = e; + break; + case u.DragInsert: + this.imageSource = this.imageEditSource; + this.currentInteractionStatus = e; + break; + case u.FinishDragInsert: + this.imageSource = this.imageNormalSource; + this.currentInteractionStatus = e + } + } + } + + e.ImageNode = p; + + class m extends N { + constructor(e) { + super(); + this.mainTitleName = e; + this.itemWidth = 0; + this.itemHeight = 44; + this.rightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_paragraph_margin_xs"], + bundleName: "", + moduleName: "" + }; + this.mainTitleSetting = { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Normal + }; + this.showPopUpTimeout = 0 + } + + setMainTitleSelected(e) { + this.mainTitleSetting = e ? { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_primary_activated"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Regular + } : { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Normal + } + } + + set title(e) { + this.mainTitleName = e + } + + get title() { + return this.mainTitleName + } + + set popUpTimeout(e) { + this.showPopUpTimeout = e + } + + get popUpTimeout() { + return this.showPopUpTimeout + } + + get color() { + return this.mainTitleSetting.fontColor + } + + get size() { + return this.mainTitleSetting.fontSize + } + + get weight() { + return this.mainTitleSetting.fontWeight + } + + setMainTitleHighLight(e) { + this.mainTitleSetting = e ? { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary_contrary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Regular + } : { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Normal + } + } + } + + e.MainTitleNode = m; + + class f extends N { + constructor() { + super(); + this.statusColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }; + this.editItemColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_emphasize"], + bundleName: "", + moduleName: "" + }; + this.radius = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_default_xs"], + bundleName: "", + moduleName: "" + }; + this.itemWidth = 0; + this.itemHeight = 32; + this.rightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_paragraph_margin_xs"], + bundleName: "", + moduleName: "" + }; + this.inputTextSetting = { + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_primary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Normal + } + } + + get color() { + return this.inputTextSetting.fontColor + } + + get size() { + return this.inputTextSetting.fontSize + } + + get weight() { + return this.inputTextSetting.fontWeight + } + + get borderRadius() { + return this.radius + } + + get backgroundColor() { + return this.statusColor + } + + get editColor() { + return this.editItemColor + } + + get textInputStatusColor() { + return this.status + } + } + + e.InputText = f; + + class S { + constructor(e) { + this.borderWidth = { has: 2, none: 0 }; + this.canShowFlagLine = !1; + this.isOverBorder = !1; + this.canShowBottomFlagLine = !1; + this.isHighLight = !1; + this.isModify = !1; + this.childNodeInfo = e.getChildNodeInfo(); + this.nodeItem = { imageNode: null, inputText: null, mainTitleNode: null, imageCollapse: null }; + this.popUpInfo = { + popUpIsShow: !1, + popUpEnableArrow: !1, + popUpColor: null, + popUpText: "", + popUpTextColor: null + }; + this.nodeItem.imageNode = e.getNodeItem().imageNode; + this.nodeItem.inputText = new f; + this.nodeItem.mainTitleNode = e.getNodeItem().mainTitleNode; + this.nodeItem.imageCollapse = e.getNodeItem().imageCollapse; + this.menu = e.menu; + this.parentNodeId = e.parentNodeId; + this.currentNodeId = e.currentNodeId; + this.nodeHeight = 44; + this.nodeLevel = e.nodeLevel; + this.nodeLeftPadding = 12 * e.nodeLevel + 8; + this.nodeColor = { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }; + this.nodeIsShow = !(this.nodeLevel > 0); + this.listItemHeight = this.nodeLevel > 0 ? 0 : 48; + this.isShowTitle = !0; + this.isShowInputText = !1; + this.isSelected = !1; + this.status = { + normal: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background_transparent"], + bundleName: "", + moduleName: "" + }, + hover: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_hover"], + bundleName: "", + moduleName: "" + }, + press: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_click_effect"], + bundleName: "", + moduleName: "" + }, + selected: "#1A0A59F7", + highLight: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_activated"], + bundleName: "", + moduleName: "" + } + }; + this.nodeBorder = { + borderWidth: 0, + borderColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_focused_outline"], + bundleName: "", + moduleName: "" + }, + borderRadius: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_clicked"], + bundleName: "", + moduleName: "" + } + }; + this.flagLineLeftMargin = 12 * e.nodeLevel + 8; + this.node = e; + this.nodeParam = e.data + } + + getPopUpInfo() { + return this.popUpInfo + } + + setPopUpIsShow(e) { + this.popUpInfo.popUpIsShow = e + } + + setPopUpEnableArrow(e) { + this.popUpInfo.popUpEnableArrow = e + } + + setPopUpColor(e) { + this.popUpInfo.popUpColor = e + } + + setPopUpText(e) { + this.popUpInfo.popUpText = e + } + + setPopUpTextColor(e) { + this.popUpInfo.popUpTextColor = e + } + + getIsShowTitle() { + return this.isShowTitle + } + + getIsShowInputText() { + return this.isShowInputText + } + + setTitleAndInputTextStatus(e) { + if (e) { + this.isShowTitle = !1; + this.isShowInputText = !0 + } else { + this.isShowTitle = !0; + this.isShowInputText = !1 + } + } + + handleImageCollapseAfterAddNode(e) { + if (e) { + this.nodeItem.imageCollapse = new p({ + id: -1, + type: 2e4, + params: ["sys.media.ohos_ic_public_arrow_down"], + bundleName: "", + moduleName: "" + }, null, null, { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_alpha_content_tertiary"], + bundleName: "", + moduleName: "" + }, 24, 24); + this.nodeItem.imageCollapse.itemRightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_paragraph_margin_xs"], + bundleName: "", + moduleName: "" + } + } else this.nodeItem.imageCollapse = null + } + + setNodeColor(e) { + this.nodeColor = e + } + + getNodeColor() { + return this.nodeColor + } + + setListItemHeight(e) { + this.listItemHeight = e + } + + getListItemHeight() { + return this.listItemHeight + } + + getNodeCurrentNodeId() { + return this.currentNodeId + } + + getNodeParentNodeId() { + return this.parentNodeId + } + + getNodeLeftPadding() { + return this.nodeLeftPadding + } + + getNodeHeight() { + return this.nodeHeight + } + + setNodeIsShow(e) { + this.nodeIsShow = e + } + + getNodeIsShow() { + return this.nodeIsShow + } + + getNodeItem() { + return this.nodeItem + } + + getNodeStatus() { + return this.status + } + + getNodeBorder() { + return this.nodeBorder + } + + setNodeBorder(e) { + this.nodeBorder.borderWidth = e ? this.borderWidth.has : this.borderWidth.none + } + + getChildNodeInfo() { + return this.childNodeInfo + } + + getCurrentNodeId() { + return this.currentNodeId + } + + getMenu() { + return this.menu + } + + setIsSelected(e) { + this.isSelected = e + } + + getIsSelected() { + return this.isSelected + } + + getNodeInfoData() { + return this.nodeParam + } + + getNodeInfoNode() { + return this.node + } + + getIsFolder() { + return this.nodeParam.isFolder + } + + setCanShowFlagLine(e) { + this.canShowFlagLine = e + } + + getCanShowFlagLine() { + return this.canShowFlagLine + } + + setFlagLineLeftMargin(e) { + this.flagLineLeftMargin = 12 * e + 8 + } + + getFlagLineLeftMargin() { + return this.flagLineLeftMargin + } + + getNodeLevel() { + return this.nodeLevel + } + + setIsOverBorder(e) { + this.isOverBorder = e + } + + getIsOverBorder() { + return this.isOverBorder + } + + setCanShowBottomFlagLine(e) { + this.canShowBottomFlagLine = e + } + + getCanShowBottomFlagLine() { + return this.canShowBottomFlagLine + } + + setIsHighLight(e) { + this.isHighLight = e + } + + getIsHighLight() { + return this.isHighLight + } + + setIsModify(e) { + this.isModify = e + } + + getIsModify() { + return this.isModify + } + } + + e.NodeInfo = S; + + class C { + constructor() { + this.MaxNodeLevel = 50; + this.MAX_CN_LENGTH = 254; + this.MAX_EN_LENGTH = 255; + this.INITIAL_INVALID_VALUE = -1; + this._root = new c({}); + this._root.nodeLevel = -1; + this._root.parentNodeId = -1; + this._root.currentNodeId = -1 + } + + getNewNodeId() { + return this.addNewNodeId + } + + traverseNodeDF(e, t = this._root) { + let o = [], i = !1; + o.unshift(t); + let s = o.shift(); + for (;!i && s; ) { + i = !0 === e(s); + if (!i) { + o.unshift(...s.children); + s = o.shift() + } + } + } + + traverseNodeBF(e) { + let t = []; + let o = !1; + t.push(this._root); + let i = t.shift(); + for (;!o && i; ) { + try { + o = e(i) + } catch (e) { + e.name, e.message + } + if (!o) { + t.push(...i.children); + i = t.shift() + } + } + } + + contains(e, t) { + t.call(this, e,!0) + } + + updateParentChildNum(e, t, o) { + let i = e.parentNodeId; + for (; i >= 0; ) this.traverseNodeDF((e => { + if (e.currentNodeId == i) { + e.getChildNodeInfo().allChildNum = t ? e.getChildNodeInfo().allChildNum + o : e.getChildNodeInfo() + .allChildNum - o; + i = e.parentNodeId; + return !1 + } + return !1 + })) + } + + findParentNodeId(e) { + let t = null; + this.contains((function (o) { + if (o.currentNodeId == e) { + t = o; + return !0 + } + return !1 + }), this.traverseNodeBF); + return t.parentNodeId + } + + addNode(e, t, o) { + if (null === this._root) { + this._root = new c({}); + this._root.nodeLevel = -1; + this._root.parentNodeId = -1; + this._root.currentNodeId = -1 + } + let i = null; + this.contains((function (t) { + if (t.currentNodeId == e) { + i = t; + return !0 + } + return !1 + }), this.traverseNodeBF); + if (i) { + let s = new c(o); + if (i.nodeLevel > this.MaxNodeLevel) throw new Error("ListNodeUtils[addNode]: The level of the tree view cannot exceed 50."); + s.nodeLevel = i.nodeLevel + 1; + s.parentNodeId = e; + s.currentNodeId = t; + i.children.push(s); + i.getChildNodeInfo().isHasChildNode = !0; + i.getChildNodeInfo().childNum = i.children.length; + i.getChildNodeInfo().allChildNum += 1; + i.addImageCollapse(i.getChildNodeInfo().isHasChildNode); + this.updateParentChildNum(i,!0, 1); + return this + } + throw new Error("ListNodeUtils[addNode]: Parent node not found.") + } + + findNodeIndex(e, t) { + let o = this.INITIAL_INVALID_VALUE; + for (let i = 0, s = e.length;i < s; i++) if (e[i].currentNodeId === t) { + o = i; + break + } + return o + } + + freeNodeMemory(e, t) { + let o = []; + this.traverseNodeDF((function (e) { + o.push(e); + return !1 + }), e); + o.forEach((e => { + t.push(e.currentNodeId); + e = null + })) + } + + removeNode(e, t, o) { + let i = null; + this.contains((function (e) { + if (e.currentNodeId == t) { + i = e; + return !0 + } + return !1 + }), o); + if (i) { + let t = []; + let o = this.findNodeIndex(i.children, e); + if (o < 0) throw new Error("Node does not exist."); + { + var s = i.children[o].getChildNodeInfo().allChildNum + 1; + this.freeNodeMemory(i.children[o], t); + let e = i.children.splice(o, 1); + e = null; + 0 == i.children.length && i.addImageCollapse(!1) + } + i.getChildNodeInfo().childNum = i.children.length; + i.getChildNodeInfo().allChildNum -= s; + this.updateParentChildNum(i,!1, s); + return t + } + throw new Error("Parent does not exist.") + } + + getNewNodeInfo(e) { + let t = null; + this.contains((function (o) { + if (o.currentNodeId == e) { + t = o; + return !0 + } + return !1 + }), this.traverseNodeBF); + let o = { + isFolder: !0, + icon: null, + selectedIcon: null, + editIcon: null, + menu: null, + secondaryTitle: "" + }; + if (t) if (0 === t.children.length) if (null != t.getNodeItem().imageNode) { + o.icon = t.getNodeItem().imageNode.normalSource; + o.selectedIcon = t.getNodeItem().imageNode.selectedSource; + o.editIcon = t.getNodeItem().imageNode.editSource; + o.menu = t.getMenu() + } else { + o.icon = null; + o.selectedIcon = null; + o.editIcon = null; + o.menu = t.getMenu() + } else if (t.children.length > 0) if (null != t.getNodeItem().imageNode) { + o.icon = null != t.children[0].getNodeItem().imageNode ? t.children[0].getNodeItem() + .imageNode + .normalSource : null; + o.selectedIcon = null != t.children[0].getNodeItem().imageNode ? t.children[0].getNodeItem() + .imageNode + .selectedSource : null; + o.editIcon = null != t.children[0].getNodeItem().imageNode ? t.children[0].getNodeItem() + .imageNode + .editSource : null; + o.menu = t.children[0].getMenu() + } else { + o.icon = null; + o.selectedIcon = null; + o.editIcon = null; + o.menu = t.children[0].getMenu() + } + return o + } + + getClickChildId(e) { + let t = null; + this.contains((function (o) { + if (o.currentNodeId == e) { + t = o; + return !0 + } + return !1 + }), this.traverseNodeBF); + if (t) { + if (0 === t.children.length) return []; + if (t.children.length > 0) { + var o = new Array(t.children.length); + for (let e = 0;e < o.length; e++) o[e] = 0; + for (let e = 0;e < t.children.length && e < o.length; e++) o[e] = t.children[e].currentNodeId; + return o + } + } + return [] + } + + getClickNodeChildrenInfo(e) { + let t = null; + this.contains((function (o) { + if (o.currentNodeId == e) { + t = o; + return !0 + } + return !1 + }), this.traverseNodeBF); + if (t) { + if (0 === t.children.length) return []; + if (t.children.length > 0) { + var o = new Array(t.children.length); + for (let e = 0;e < o.length; e++) o[e] = { itemId: null, itemIcon: null, itemTitle: null, isFolder: null }; + for (let e = 0;e < t.children.length && e < o.length; e++) { + o[e].itemId = t.children[e].currentNodeId; + t.children[e].getNodeItem().imageNode && (o[e].itemIcon = t.children[e].getNodeItem().imageNode.source); + t.children[e].getNodeItem().mainTitleNode && (o[e].itemTitle = t.children[e].getNodeItem() + .mainTitleNode + .title); + o[e].isFolder = t.children[e].getIsFolder() + } + return o + } + } + return [] + } + + checkMainTitleIsValid(e) { + let t = /^[\u4e00-\u9fa5]+$/; + return!/[\\\/:*?"<>|]/.test(e) && !(t.test(e) && e.length > this.MAX_CN_LENGTH || !t.test(e) && e.length > this.MAX_EN_LENGTH) + } + + dragTraverseNodeDF(e, t = this._root, o) { + let i = [], s = !1; + i.unshift(t); + let a = i.shift(); + for (;!s && a; ) { + s = !0 === e(a, o); + if (!s) { + i.unshift(...a.children); + a = i.shift() + } + } + } + + addDragNode(e, t, o, i, s) { + if (null === this._root) { + this._root = new c({}); + this._root.nodeLevel = this.INITIAL_INVALID_VALUE; + this._root.parentNodeId = this.INITIAL_INVALID_VALUE; + this._root.currentNodeId = this.INITIAL_INVALID_VALUE + } + let a = null; + this.contains((function (t) { + if (t.currentNodeId == e) { + a = t; + return !0 + } + return !1 + }), this.traverseNodeBF); + if (a) { + let d = new c(s); + if (a.nodeLevel > this.MaxNodeLevel) throw new Error("ListNodeUtils[addNode]: The level of the tree view cannot exceed 50."); + d.nodeLevel = a.nodeLevel + 1; + d.parentNodeId = e; + d.currentNodeId = t; + let r = this.INITIAL_INVALID_VALUE; + if (a.children.length) { + for (let e = 0;e < a.children.length; e++) if (a.children[e].getCurrentNodeId() == o) { + r = e; + break + } + i ? a.children.splice(r + 1, 0, d) : a.children.splice(r, 0, d) + } else a.children.push(d); + a.getChildNodeInfo().isHasChildNode = !0; + a.getChildNodeInfo().childNum = a.children.length; + a.getChildNodeInfo().allChildNum += 1; + a.addImageCollapse(a.getChildNodeInfo().isHasChildNode); + this.updateParentChildNum(a,!0, 1); + return this + } + throw new Error("ListNodeUtils[addNode]: Parent node not found.") + } + } + + e.ListNodeUtils = C; + + class D extends d { + constructor() { + super(...arguments); + this.ROOT_NODE_ID = -1; + this.listNodeUtils = new C; + this.listNode = []; + this.INITIAL_INVALID_VALUE = -1; + this.lastIndex = -1; + this.thisIndex = -1; + this.modifyNodeIndex = -1; + this.modifyNodeId = -1; + this.expandAndCollapseInfo = new Map; + this.loadedNodeIdAndIndexMap = new Map; + this.isTouchDown = !1; + this.appEventBus = a.getInstance().getTreeListener(); + this.isInnerDrag = !1; + this.isDrag = !1; + this.draggingCurrentNodeId = this.INITIAL_INVALID_VALUE; + this.draggingParentNodeId = this.INITIAL_INVALID_VALUE; + this.currentNodeInfo = null; + this.listItemOpacity = 1; + this.lastPassIndex = this.INITIAL_INVALID_VALUE; + this.lastPassId = this.INITIAL_INVALID_VALUE; + this.thisPassIndex = this.INITIAL_INVALID_VALUE; + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE; + this.timeoutExpandId = this.INITIAL_INVALID_VALUE; + this.lastTimeoutExpandId = this.INITIAL_INVALID_VALUE; + this.clearTimeoutExpandId = this.INITIAL_INVALID_VALUE; + this.timeoutHighLightId = this.INITIAL_INVALID_VALUE; + this.lastTimeoutHighLightId = this.INITIAL_INVALID_VALUE; + this.clearTimeoutHighLightId = this.INITIAL_INVALID_VALUE; + this.lastDelayHighLightIndex = this.INITIAL_INVALID_VALUE; + this.lastDelayHighLightId = this.INITIAL_INVALID_VALUE; + this.nodeIdAndSubtitleMap = new Map; + this.flag = g.NONE; + this.selectedParentNodeId = this.INITIAL_INVALID_VALUE; + this.selectedParentNodeSubtitle = ""; + this.insertNodeSubtitle = ""; + this.currentFocusNodeId = this.INITIAL_INVALID_VALUE; + this.lastFocusNodeId = this.INITIAL_INVALID_VALUE; + this.addFocusNodeId = this.INITIAL_INVALID_VALUE; + this.FLAG_LINE = { + flagLineHeight: "1.5vp", + flagLineColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_activated"], + bundleName: "", + moduleName: "" + }, + xOffset: "0vp", + yTopOffset: "2.75vp", + yBottomOffset: "-1.25vp", + yBasePlateOffset: "1.5vp" + }; + this.DRAG_POPUP = { + floorConstraintSize: { minWidth: "128vp", maxWidth: "208vp" }, + textConstraintSize: { minWidth1: "80vp", maxWidth1: "160vp", minWidth2: "112vp", maxWidth2: "192vp" }, + padding: { left: "8vp", right: "8vp" }, + backgroundColor: o, + height: "48", + shadow: { + radius: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_default_m"], + bundleName: "", + moduleName: "" + }, + color: "#00001E", + offsetX: 0, + offsetY: 10 + }, + borderRadius: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_corner_radius_clicked"], + bundleName: "", + moduleName: "" + }, + fontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body1"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Regular, + imageOpacity: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_alpha_content_fourth"], + bundleName: "", + moduleName: "" + } + }; + this.subTitle = { + normalFontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_secondary"], + bundleName: "", + moduleName: "" + }, + highLightFontColor: { + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_primary_contrary"], + bundleName: "", + moduleName: "" + }, + fontSize: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body2"], + bundleName: "", + moduleName: "" + }, + fontWeight: FontWeight.Regular, + margin: { left: "4vp", right: "24" } + } + } + + changeNodeColor(e, t) { + this.listNode[e].setNodeColor(t) + } + + getNodeColor(e) { + return this.listNode[e].getNodeColor() + } + + handleFocusEffect(e, t) { + this.listNode[e].getNodeIsShow() && this.listNode[e].setNodeBorder(t) + } + + setImageSource(e, t) { + let o = this.listNode[e]; + o.setIsSelected(t === u.Selected || t === u.Edit || t === u.FinishEdit); + null != o.getNodeItem().mainTitleNode && t != u.DragInsert && t != u.FinishDragInsert && o.getNodeItem() + .mainTitleNode + .setMainTitleSelected(t === u.Selected || t === u.FinishEdit); + null != o.getNodeItem().imageNode && o.getNodeItem().imageNode.setImageSource(t) + } + + setImageCollapseSource(e, t) { + let o = this.listNode[e]; + null != o.getNodeItem().imageCollapse && o.getNodeItem() + .imageCollapse + .setImageCollapseSource(t, this.expandAndCollapseInfo.get(o.getCurrentNodeId())) + } + + clearLastIndexStatus() { + if (!(-1 == this.lastIndex || this.lastIndex >= this.listNode.length)) { + this.setImageSource(this.lastIndex, u.Normal); + this.changeNodeColor(this.lastIndex, this.listNode[this.lastIndex].getNodeStatus().normal); + this.handleFocusEffect(this.lastIndex,!1); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.listNode[this.lastIndex].getCurrentNodeId())) + } + } + + changeNodeStatus(e) { + let t = e; + let o = this.ListNode; + let i = o[e].getCurrentNodeId(); + if (this.expandAndCollapseInfo.get(i) == I.Expand) { + this.expandAndCollapseInfo.set(i, I.Collapse); + o[t].getNodeItem().imageCollapse.changeImageCollapseSource(I.Collapse) + } else if (this.expandAndCollapseInfo.get(i) == I.Collapse) { + this.expandAndCollapseInfo.set(i, I.Expand); + o[t].getNodeItem().imageCollapse.changeImageCollapseSource(I.Expand) + } + } + + handleExpandAndCollapse(e) { + let t = e; + let o = this.ListNode; + let i = o[t].getCurrentNodeId(); + if (!this.expandAndCollapseInfo.has(i)) return; + let s = this.expandAndCollapseInfo.get(i); + if (o[t].getChildNodeInfo().isHasChildNode && s == I.Collapse) { + for (var a = 0;a < o[t].getChildNodeInfo().allChildNum; a++) { + o[t + 1+a].setNodeIsShow(!1); + o[t + 1+a].setListItemHeight(0) + } + this.notifyDataReload(); + return + } + let d = new Array(o[t].getChildNodeInfo().childNum); + d[0] = t + 1; + let r = 1; + for (; r < o[t].getChildNodeInfo().childNum; ) { + d[r] = d[r-1] + o[d[r-1]].getChildNodeInfo().allChildNum + 1; + r++ + } + if (s == I.Expand) for (a = 0; a < d.length; a++) { + o[d[a]].setNodeIsShow(!0); + o[d[a]].setListItemHeight(48); + let e = o[d[a]].getCurrentNodeId(); + this.expandAndCollapseInfo.get(e) == I.Expand && this.handleExpandAndCollapse(d[a]) + } + d = null; + this.notifyDataReload() + } + + init(e) { + let t = 0; + this.listNode = []; + this.listNodeUtils = e; + this.loadedNodeIdAndIndexMap.clear(); + this.listNodeUtils.traverseNodeDF((e => { + if (e.currentNodeId >= 0) { + var o = new S(e); + this.listNode.push(o); + o.getChildNodeInfo().isHasChildNode && this.expandAndCollapseInfo.set(o.getCurrentNodeId(), I.Collapse); + o.getNodeIsShow() && this.loadedNodeIdAndIndexMap.set(o.getCurrentNodeId(), t++); + o.getIsFolder() && this.nodeIdAndSubtitleMap.set(o.getCurrentNodeId(), o.getNodeInfoData() + .secondaryTitle || 0 == o.getNodeInfoData() + .secondaryTitle ? o.getNodeInfoData().secondaryTitle : "") + } + return !1 + })) + } + + refreshRemoveNodeData(e, t) { + let o = []; + for (let t = 0;t < e.length; t++) for (let i = 0;i < this.listNode.length; i++) if (this.listNode[i].getNodeCurrentNodeId() == e[t]) { + let s = this.listNode[i].getNodeCurrentNodeId(); + this.loadedNodeIdAndIndexMap.has(s) && o.push(this.loadedNodeIdAndIndexMap.get(s)); + let a = this.listNode.splice(i, 1); + a = null; + this.expandAndCollapseInfo.has(e[t]) && this.expandAndCollapseInfo.delete(e[t]); + break + } + o.forEach((e => { + this.notifyDataDelete(e); + this.notifyDataChange(e) + })); + for (let e = 0;e < this.listNode.length; e++) if (this.listNode[e].getNodeCurrentNodeId() == t.getNodeCurrentNodeId()) { + if (null == t.getNodeItem().imageCollapse) { + this.listNode[e].handleImageCollapseAfterAddNode(!1); + this.expandAndCollapseInfo.delete(t.getNodeCurrentNodeId()); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.listNode[e].getNodeCurrentNodeId())) + } + break + } + let i = { currentNodeId: t.getNodeCurrentNodeId(), parentNodeId: t.getNodeParentNodeId() }; + this.appEventBus.emit(s.NODE_DELETE, [i]) + } + + refreshAddNodeData(e) { + var t; + this.listNodeUtils.traverseNodeDF((o => { + if (o.currentNodeId === e[0]) { + t = new S(o); + return !0 + } + return !1 + })); + t.setIsModify(!0); + let o = 0; + for (let e = 0;e < this.listNode.length; e++) if (this.listNode[e].getNodeCurrentNodeId() == t.getNodeParentNodeId()) { + o = e; + if (null == this.listNode[e].getNodeItem().imageCollapse) { + this.listNode[e].handleImageCollapseAfterAddNode(!0); + this.notifyDataChange(o) + } else this.expandAndCollapseInfo.get(this.listNode[e].getNodeCurrentNodeId()) == I.Collapse && this.changeNodeStatus(o); + this.listNode.splice(e + 1, 0, t); + this.listNode[e+1].setTitleAndInputTextStatus(!0); + this.listNode[e+1].setNodeIsShow(!0); + this.listNode[e+1].setListItemHeight(48); + this.setImageSource(e + 1, u.Edit); + this.currentOperation = n.ADD_NODE; + this.notifyDataAdd(e + 1); + this.notificationNodeInfo(e + 1, this.currentOperation); + break + } + this.modifyNodeIndex = o + 1; + this.expandAndCollapseInfo.set(t.getNodeParentNodeId(), I.Expand); + this.handleExpandAndCollapse(o) + } + + refreshData(e, t, o, i) { + let s; + this.listNodeUtils = e; + this.listNodeUtils.traverseNodeDF((e => { + if (e.currentNodeId == o) { + s = new S(e); + return !0 + } + return !1 + })); + if (t === n.REMOVE_NODE) { + this.nodeIdAndSubtitleMap.set(o, this.selectedParentNodeSubtitle); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(o)); + this.refreshRemoveNodeData(i, s) + } + if (t === n.ADD_NODE) { + this.addFocusNodeId = i[0]; + this.nodeIdAndSubtitleMap.set(this.getClickNodeId(), this.selectedParentNodeSubtitle); + this.nodeIdAndSubtitleMap.set(i[0], this.insertNodeSubtitle); + this.refreshAddNodeData(i) + } + } + + setClickIndex(e) { + this.thisIndex = e + } + + getClickNodeId() { + return this.thisIndex < 0 || this.thisIndex >= this.ListNode.length ? -1 : this.ListNode[this.thisIndex].getCurrentNodeId() + } + + expandAndCollapseNode(e) { + this.changeNodeStatus(e); + this.handleExpandAndCollapse(e) + } + + getIsTouchDown() { + return this.isTouchDown + } + + getLastIndex() { + return this.lastIndex + } + + handleEvent(e, t) { + if (this.isDrag) return; + e !== r.TOUCH_DOWN && e !== r.TOUCH_UP && e !== r.MOUSE_BUTTON_RIGHT || t != this.lastIndex && this.clearLastIndexStatus(); + let o = this.loadedNodeIdAndIndexMap.get(this.listNode[t].getCurrentNodeId()); + switch (e) { + case r.TOUCH_DOWN: + this.isTouchDown = !0; + this.changeNodeColor(t, this.listNode[t].getNodeStatus().press); + break; + case r.TOUCH_UP: { + this.isInnerDrag && (this.isInnerDrag = !1); + this.isTouchDown = !1; + let e = this.listNode[t]; + this.setImageSource(t, u.Selected); + this.lastIndex = t; + this.changeNodeColor(t, e.getNodeStatus().selected); + this.notifyDataChange(o); + break + } + case r.HOVER: + if (this.getNodeColor(t) != this.listNode[t].getNodeStatus().selected) { + this.changeNodeColor(t, this.listNode[t].getNodeStatus().hover); + this.notifyDataChange(o) + } + break; + case r.HOVER_OVER: + if (this.getNodeColor(t) != this.listNode[t].getNodeStatus().selected) { + this.changeNodeColor(t, this.listNode[t].getNodeStatus().normal); + this.notifyDataChange(o) + } + break; + case r.FOCUS: + this.handleFocusEffect(t,!0); + this.notifyDataChange(o); + break; + case r.BLUR: + this.handleFocusEffect(t,!1); + this.notifyDataChange(o); + break; + case r.MOUSE_BUTTON_RIGHT: + this.lastIndex = t; + this.finishEditing(); + break; + case r.DRAG: + this.isTouchDown = !1; + let e = this.listNode[t]; + this.setImageSource(t, u.Selected); + this.lastIndex = t; + this.changeNodeColor(t, e.getNodeStatus().selected); + this.notifyDataChange(o) + } + } + + notificationNodeInfo(e, t) { + if (t === n.MODIFY_NODE) { + let e = this.listNode[this.modifyNodeIndex]; + let t = { currentNodeId: e.getNodeCurrentNodeId(), parentNodeId: e.getNodeParentNodeId() }; + this.appEventBus.emit(s.NODE_MODIFY, [t]) + } else if (t === n.ADD_NODE) { + let t = this.listNode[e]; + null != t.getNodeItem().imageNode && t.getNodeItem().imageNode.source; + null != t.getNodeItem().imageNode && t.getNodeItem().imageNode.selectedSource; + null != t.getNodeItem().imageNode && t.getNodeItem().imageNode.editSource; + let o = { currentNodeId: t.getNodeCurrentNodeId(), parentNodeId: t.getNodeParentNodeId() }; + this.appEventBus.emit(s.NODE_ADD, [o]) + } + } + + finishEditing() { + if (-1 != this.modifyNodeIndex) { + this.setImageSource(this.modifyNodeIndex, u.FinishEdit); + this.setImageCollapseSource(this.modifyNodeIndex, u.FinishEdit); + this.listNode[this.modifyNodeIndex].setIsModify(!1); + this.listNode[this.modifyNodeIndex].setTitleAndInputTextStatus(!1); + this.notificationNodeInfo(this.modifyNodeIndex, this.currentOperation); + this.notifyDataChange(this.modifyNodeIndex) + } + } + + setItemVisibilityOnEdit(e, t) { + let o = -1; + if (-1 != e) { + if (t === n.MODIFY_NODE) { + for (let t = 0;t < this.listNode.length; t++) if (this.listNode[t].getCurrentNodeId() == e) { + o = t; + break + } + let t = this.listNode[o]; + t.setIsModify(!0); + if (null === t.getNodeItem().mainTitleNode) return; + this.currentOperation = n.MODIFY_NODE; + t.setTitleAndInputTextStatus(!0); + this.setImageSource(o, u.Edit); + this.setImageCollapseSource(o, u.Edit); + this.modifyNodeIndex = o; + t.getNodeItem().inputText && (null != t.getNodeItem().imageCollapse ? t.getNodeItem() + .inputText + .rightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_paragraph_margin_xs"], + bundleName: "", + moduleName: "" + } : t.getNodeItem().inputText.rightMargin = { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_elements_margin_horizontal_m"], + bundleName: "", + moduleName: "" + }); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(e)) + } + o = e; + if (t === n.COMMIT_NODE) { + let e = this.listNode[o]; + e.setTitleAndInputTextStatus(!1); + e.setIsModify(!1); + this.setImageSource(o, u.FinishEdit); + this.setImageCollapseSource(o, u.FinishEdit); + this.notificationNodeInfo(this.modifyNodeIndex, this.currentOperation); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(e.getCurrentNodeId())) + } + } + } + + setPopUpInfo(e, t, o, i) { + let s = this.listNode[i]; + s.setPopUpIsShow(o); + let a = this.loadedNodeIdAndIndexMap.get(s.getCurrentNodeId()); + if (o) { + if (e === l.HINTS) { + if (null != s.getNodeItem().mainTitleNode) s.setPopUpText(s.getNodeItem().mainTitleNode.title); else { + s.setPopUpText(""); + s.setPopUpIsShow(!1) + } + s.setPopUpEnableArrow(!1); + s.setPopUpColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_background"], + bundleName: "", + moduleName: "" + }); + s.setPopUpTextColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_secondary"], + bundleName: "", + moduleName: "" + }) + } else if (e === l.WARNINGS && null != s.getNodeItem().inputText) { + t === h.INVALID_ERROR ? s.setPopUpText("invalid error") : t === h.LENGTH_ERROR && s.setPopUpText("length error"); + s.setPopUpEnableArrow(!0); + s.setPopUpColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_help_tip_bg"], + bundleName: "", + moduleName: "" + }); + s.setPopUpTextColor({ + id: -1, + type: 10001, + params: ["sys.color.ohos_id_color_text_hint_contrary"], + bundleName: "", + moduleName: "" + }) + } + this.notifyDataChange(a) + } else this.notifyDataChange(a) + } + + setShowPopUpTimeout(e, t) { + null != this.listNode[t].getNodeItem().mainTitleNode && (this.listNode[t].getNodeItem() + .mainTitleNode + .popUpTimeout = e); + let o = this.loadedNodeIdAndIndexMap.get(this.listNode[t].getCurrentNodeId()); + this.notifyDataChange(o) + } + + setMainTitleNameOnEdit(e, t) { + this.modifyNodeIndex = e; + if (null != this.listNode[e].getNodeItem().mainTitleNode) { + this.listNode[e].getNodeItem().mainTitleNode.title = t; + let o = this.loadedNodeIdAndIndexMap.get(this.listNode[e].getCurrentNodeId()); + this.notifyDataChange(o) + } + } + + get ListNode() { + return this.listNode + } + + totalCount() { + let e = 0; + let t = 0; + this.loadedNodeIdAndIndexMap.clear(); + for (let o = 0;o < this.listNode.length; o++) if (this.listNode[o].getNodeIsShow()) { + this.loadedNodeIdAndIndexMap.set(this.listNode[o].getCurrentNodeId(), t++); + e++ + } + return e + } + + getData(e) { + let t = 0; + for (let o = 0;o < this.listNode.length; o++) if (this.listNode[o].getNodeIsShow()) { + if (e == t) return this.listNode[o]; + t++ + } + return null + } + + addData(e, t) { + this.listNode.splice(e, 0, t); + this.notifyDataAdd(e) + } + + pushData(e) { + this.listNode.push(e); + this.notifyDataAdd(this.listNode.length - 1) + } + + setIsInnerDrag(e) { + this.isInnerDrag = e + } + + getIsInnerDrag() { + return this.isInnerDrag + } + + setIsDrag(e) { + this.isDrag = e + } + + getIsDrag() { + return this.isDrag + } + + setCurrentNodeInfo(e) { + this.currentNodeInfo = e + } + + getCurrentNodeInfo() { + return this.currentNodeInfo + } + + setDraggingParentNodeId(e) { + this.draggingParentNodeId = e + } + + getDraggingParentNodeId() { + return this.draggingParentNodeId + } + + getDraggingCurrentNodeId() { + return this.draggingCurrentNodeId + } + + setDraggingCurrentNodeId(e) { + this.draggingCurrentNodeId = e + } + + setListItemOpacity(e) { + this.listItemOpacity = e + } + + getListItemOpacity(e) { + return e.getCurrentNodeId() == this.getDraggingCurrentNodeId() ? this.listItemOpacity : 1 + } + + getDragPopupPara() { + return this.DRAG_POPUP + } + + setLastPassIndex(e) { + this.lastPassIndex = e + } + + getLastPassIndex() { + return this.lastPassIndex + } + + getIsParentOfInsertNode(e) { + let t = this.currentNodeInfo.getNodeInfoNode(); + let o = !1; + this.listNodeUtils.traverseNodeDF((function (t) { + if (t.currentNodeId == e) { + o = !0; + return !0 + } + return !1 + }), t); + return o + } + + setPassIndex(e) { + this.thisPassIndex = e + } + + getPassIndex() { + return this.thisPassIndex + } + + clearTimeOutAboutDelayHighLightAndExpand(e) { + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let e = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + let t = this; + this.ListNode.forEach((function (e) { + e.getNodeCurrentNodeId() == t.lastPassId && e.setCanShowFlagLine(!1) + })); + this.notifyDataChange(e) + } + if (this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && this.clearTimeoutHighLightId != this.lastTimeoutHighLightId) { + clearTimeout(this.lastTimeoutHighLightId); + if (this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE) { + this.clearHighLight(this.lastDelayHighLightIndex); + let e = this.loadedNodeIdAndIndexMap.get(this.listNode[this.lastDelayHighLightIndex].getCurrentNodeId()); + this.notifyDataChange(e) + } + this.clearTimeoutHighLightId = this.lastTimeoutHighLightId + } + this.lastTimeoutHighLightId = this.timeoutHighLightId; + this.lastDelayHighLightIndex = e; + if (this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && this.clearTimeoutExpandId != this.lastTimeoutExpandId) { + clearTimeout(this.lastTimeoutExpandId); + this.clearTimeoutExpandId = this.lastTimeoutExpandId + } + this.lastTimeoutExpandId = this.timeoutExpandId; + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE + } + + clearHighLight(e) { + this.changeNodeColor(e, this.listNode[e].getNodeStatus().normal); + this.changeNodeHighLightColor(e,!1); + this.setImageSource(e, u.FinishDragInsert); + this.setImageCollapseSource(e, u.FinishDragInsert); + this.listNode[e].setIsHighLight(!1) + } + + changeNodeHighLightColor(e, t) { + this.listNode[e].getNodeItem() + .mainTitleNode && this.listNode[e].getIsShowTitle() && this.listNode[e].getNodeItem() + .mainTitleNode + .setMainTitleHighLight(t) + } + + setVisibility(e, t, o) { + let i = this.thisPassIndex != t || this.flag != e; + this.thisPassIndex = t; + if ((i || o) && this.isInnerDrag) { + this.flag = e; + let o = this.getData(t).getCurrentNodeId(); + let i = this.expandAndCollapseInfo.get(o) == I.Expand && this.flag == g.DOWN_FLAG ? this.getData(t) + .getNodeLevel() + 1 : this.getData(t) + .getNodeLevel(); + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let e = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + let t = this; + this.ListNode.forEach((function (e) { + e.getNodeCurrentNodeId() == t.lastPassId && e.setCanShowFlagLine(!1) + })); + this.notifyDataChange(e) + } + if (this.flag == g.DOWN_FLAG && t < this.totalCount() - 1) { + this.getData(t).setCanShowFlagLine(!1); + this.getData(t + 1).setCanShowFlagLine(!0); + this.getData(t).setCanShowBottomFlagLine(!1); + this.getData(t + 1).setFlagLineLeftMargin(i); + this.notifyDataChange(t); + this.notifyDataChange(t + 1); + this.lastPassId = this.getData(t + 1).getNodeCurrentNodeId() + } else if (this.flag == g.UP_FLAG && t < this.totalCount() - 1) { + this.getData(t).setCanShowFlagLine(!0); + this.getData(t + 1).setCanShowFlagLine(!1); + this.getData(t).setCanShowBottomFlagLine(!1); + this.getData(t).setFlagLineLeftMargin(i); + this.notifyDataChange(t); + this.notifyDataChange(t + 1); + this.lastPassId = this.getData(t).getNodeCurrentNodeId() + } else if (t >= this.totalCount() - 1) { + if (this.flag == g.DOWN_FLAG) { + this.getData(t).setCanShowFlagLine(!1); + this.getData(t).setCanShowBottomFlagLine(!0) + } else { + this.getData(t).setCanShowFlagLine(!0); + this.getData(t).setCanShowBottomFlagLine(!1) + } + this.getData(t).setFlagLineLeftMargin(i); + this.notifyDataChange(t); + this.lastPassId = this.getData(t).getNodeCurrentNodeId() + } + } + } + + delayHighLightAndExpandNode(e, t, o) { + let i = e != this.lastDelayExpandIndex; + let s = this.getData(o).getIsOverBorder(); + this.lastDelayExpandIndex = s ? this.INITIAL_INVALID_VALUE : e; + if (s || i) { + let i = this; + if (!s && (!this.isInnerDrag || this.expandAndCollapseInfo.get(t) == I.Collapse && this.isInnerDrag || !this.expandAndCollapseInfo.has(t) && this.listNode[e].getIsFolder())) { + this.changeNodeColor(e, this.listNode[e].getNodeStatus().hover); + this.notifyDataChange(o); + let t = this.isInnerDrag ? 1e3 : 0; + this.timeoutHighLightId = setTimeout((function () { + i.delayHighLight(e) + }), t) + } + if (s || this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && this.clearTimeoutHighLightId != this.lastTimeoutHighLightId) { + clearTimeout(this.lastTimeoutHighLightId); + if (this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE) { + this.clearHighLight(this.lastDelayHighLightIndex); + this.notifyDataReload() + } + this.clearTimeoutHighLightId = this.lastTimeoutHighLightId + } + this.lastTimeoutHighLightId = this.timeoutHighLightId; + this.lastDelayHighLightIndex = e; + if (!s && this.expandAndCollapseInfo.get(t) == I.Collapse) { + let t = this.getData(o).getNodeInfoNode().children[0].currentNodeId; + let s = 2e3; + this.timeoutExpandId = setTimeout((function () { + i.clearHighLight(i.lastDelayHighLightIndex); + i.alterFlagLineAndExpandNode(e, t) + }), s) + } + if (s || this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && this.clearTimeoutExpandId != this.lastTimeoutExpandId) { + clearTimeout(this.lastTimeoutExpandId); + this.clearTimeoutExpandId = this.lastTimeoutExpandId + } + this.lastTimeoutExpandId = this.timeoutExpandId + } + } + + delayHighLight(e) { + let t = this; + this.ListNode.forEach((function (e) { + if (e.getNodeCurrentNodeId() == t.lastPassId) { + e.setCanShowFlagLine(!1); + e.setCanShowBottomFlagLine(!1) + } + })); + this.changeNodeColor(e, this.listNode[e].getNodeStatus().highLight); + this.listNode[e].setIsHighLight(!0); + this.changeNodeHighLightColor(e,!0); + this.setImageSource(e, u.DragInsert); + this.setImageCollapseSource(e, u.DragInsert); + this.notifyDataReload() + } + + alterFlagLineAndExpandNode(e, t) { + let o = this; + this.ListNode.forEach((function (e) { + if (e.getNodeCurrentNodeId() == o.lastPassId) { + e.setCanShowFlagLine(!1); + e.setCanShowBottomFlagLine(!1) + } + })); + this.ListNode.forEach((function (e) { + o.isInnerDrag && e.getNodeCurrentNodeId() == t && e.setCanShowFlagLine(!0) + })); + this.changeNodeStatus(e); + this.handleExpandAndCollapse(e); + this.lastPassId = t + } + + hideLastLine() { + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let e = this; + this.ListNode.forEach((function (t) { + if (t.getNodeCurrentNodeId() == e.lastPassId) { + t.setCanShowFlagLine(!1); + t.setCanShowBottomFlagLine(!1) + } + })); + let t = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + this.notifyDataChange(t) + } + } + + clearLastTimeoutHighLight() { + if (this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && this.clearTimeoutHighLightId != this.lastTimeoutHighLightId) { + clearTimeout(this.lastTimeoutHighLightId); + this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE && this.clearHighLight(this.lastDelayHighLightIndex) + } + } + + clearLastTimeoutExpand() { + this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && this.clearTimeoutExpandId != this.lastTimeoutExpandId && clearTimeout(this.lastTimeoutExpandId) + } + + getSubtitle(e) { + return this.nodeIdAndSubtitleMap.has(e) ? "number" == typeof this.nodeIdAndSubtitleMap.get(e) ? this.nodeIdAndSubtitleMap.get(e) + .toString() : this.nodeIdAndSubtitleMap.get(e) : "" + } + + hasSubtitle(e) { + return this.nodeIdAndSubtitleMap.has(e) + } + + initialParameterAboutDelayHighLightAndExpandIndex() { + this.lastDelayHighLightIndex = this.INITIAL_INVALID_VALUE; + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE; + this.lastPassIndex = this.INITIAL_INVALID_VALUE; + this.draggingCurrentNodeId = this.INITIAL_INVALID_VALUE; + this.flag = g.NONE + } + + refreshSubtitle(e) { + this.nodeIdAndSubtitleMap.set(this.selectedParentNodeId, this.selectedParentNodeSubtitle); + this.nodeIdAndSubtitleMap.set(e, this.insertNodeSubtitle); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.selectedParentNodeId)); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(e)) + } + + setNodeSubtitlePara(e, t, o) { + this.selectedParentNodeId = e; + this.selectedParentNodeSubtitle = t; + this.insertNodeSubtitle = o + } + + getInsertNodeSubtitle() { + return this.insertNodeSubtitle + } + + getExpandAndCollapseInfo(e) { + return this.expandAndCollapseInfo.get(e) + } + + getLastDelayHighLightId() { + return this.lastDelayHighLightId + } + + setLastDelayHighLightId() { + this.ListNode.forEach(((e, t) => { + t == this.lastDelayHighLightIndex && (this.lastDelayHighLightId = e.getCurrentNodeId()) + })) + } + + setLastPassId(e) { + this.lastPassId = e + } + + setLastDelayHighLightIndex(e) { + this.lastDelayHighLightIndex = e + } + + alterDragNode(e, t, o, i, a, d) { + let r = []; + let n = e; + let l = a; + let h = d.getNodeInfoData(); + let c = null; + let N = d.getNodeInfoNode(); + let u = !1; + let p = this.INITIAL_INVALID_VALUE; + let m = this.INITIAL_INVALID_VALUE; + let f = this.flag == g.DOWN_FLAG; + m = this.getChildIndex(i, a); + p = this.getChildIndex(e, t); + p = e != i ? f ? p + 1 : p : p > m ? f ? p : p - 1 : f ? p + 1 : p; + for (let e = 0;e < this.listNode.length; e++) if (this.listNode[e].getCurrentNodeId() == t) { + u = this.listNode[e].getIsHighLight(); + if (this.flag == g.DOWN_FLAG && this.expandAndCollapseInfo.get(t) == I.Expand) { + n = t; + p = 0 + } else if (this.flag == g.UP_FLAG && this.expandAndCollapseInfo.get(t) == I.Expand && 0 == this.listNode[e].getCanShowFlagLine()) { + n = t; + p = 0 + } else if (u) { + n = t; + p = 0 + } + break + } + let S = { currentNodeId: l, parentNodeId: n, childIndex: p }; + this.appEventBus.emit(s.NODE_MOVE, [S]); + r.push({ parentId: n, currentId: l, data: h }); + let C = null; + this.listNodeUtils.dragTraverseNodeDF((function (e, t) { + if (e) { + C = e; + n = C.parentNodeId; + l = C.currentNodeId; + for (let e = 0;e < t.length; e++) if (t[e].getNodeCurrentNodeId() == l) { + c = t[e]; + break + } + h = c.getNodeInfoData(); + n != i && r.push({ parentId: n, currentId: l, data: h }); + return !1 + } + return !1 + }), N, this.listNode); + this.listNodeUtils.removeNode(a, i, this.listNodeUtils.traverseNodeBF); + let D = t; + let _ = f; + if (this.expandAndCollapseInfo.get(t) == I.Expand) { + _ = !1; + this.listNode.forEach((e => { + e.getCurrentNodeId() == t && 0 == e.getCanShowFlagLine() && (D = e.getNodeInfoNode() + .children + .length ? e.getNodeInfoNode() + .children[0] + .currentNodeId : this.INITIAL_INVALID_VALUE) + })) + } else !this.expandAndCollapseInfo.get(t) && u && this.expandAndCollapseInfo.set(t, I.Expand); + this.listNodeUtils.addDragNode(r[0].parentId, r[0].currentId, D, _, r[0].data); + for (let e = 1;e < r.length; e++) this.listNodeUtils.addNode(r[e].parentId, r[e].currentId, r[e].data); + for (let e = 0;e < this.listNode.length; e++) if (this.listNode[e].getCurrentNodeId() == i && null == this.listNode[e].getNodeInfoNode() + .getNodeItem() + .imageCollapse) { + this.listNode[e].handleImageCollapseAfterAddNode(!1); + this.expandAndCollapseInfo.delete(i); + break + } + let T = [...this.listNode]; + this.reloadListNode(this.listNodeUtils, T) + } + + reloadListNode(e, t) { + let o = 0; + this.listNode = []; + this.listNodeUtils = e; + this.loadedNodeIdAndIndexMap.clear(); + this.listNodeUtils.traverseNodeDF((e => { + if (e.currentNodeId >= 0) { + var i = new S(e); + this.listNode.push(i); + this.expandAndCollapseInfo.get(e.currentNodeId) == I.Expand ? i.getNodeItem() + .imageCollapse + .changeImageCollapseSource(I.Expand) : this.expandAndCollapseInfo.get(e.currentNodeId) == I.Collapse && i.getNodeItem() + .imageCollapse + .changeImageCollapseSource(I.Collapse); + for (let e = 0;e < t.length; e++) if (t[e].getCurrentNodeId() == i.getCurrentNodeId()) { + i.setNodeIsShow(t[e].getNodeIsShow()); + i.setListItemHeight(t[e].getListItemHeight()); + i.getNodeItem().mainTitleNode && i.getIsShowTitle() && (i.getNodeItem() + .mainTitleNode + .title = t[e].getNodeItem().mainTitleNode.title); + break + } + i.getNodeIsShow() && this.loadedNodeIdAndIndexMap.set(i.getCurrentNodeId(), o++) + } + return !1 + })) + } + + getFlagLine() { + return this.FLAG_LINE + } + + getVisibility(e) { + let t = this.loadedNodeIdAndIndexMap.get(e.getCurrentNodeId()) - 1; + if (t > this.INITIAL_INVALID_VALUE) { + let o = this.getData(t); + return 1 != e.getCanShowFlagLine() || e.getIsHighLight() || o.getIsHighLight() ? Visibility.Hidden : Visibility.Visible + } + return 1 != e.getCanShowFlagLine() || e.getIsHighLight() ? Visibility.Hidden : Visibility.Visible + } + + getSubTitlePara() { + return this.subTitle + } + + getIsFolder(e) { + return!!this.loadedNodeIdAndIndexMap.has(e) && this.getData(this.loadedNodeIdAndIndexMap.get(e)).getIsFolder() + } + + getSubTitleFontColor(e) { + return e ? this.subTitle.highLightFontColor : this.subTitle.normalFontColor + } + + getChildIndex(e, t) { + let o = this.INITIAL_INVALID_VALUE; + this.listNodeUtils.traverseNodeBF((function (i) { + if (i.getCurrentNodeId() == e) { + i.children.forEach(((e, i) => { + e.getCurrentNodeId() == t && (o = i) + })); + return !0 + } + return !1 + })); + return o + } + + setCurrentFocusNodeId(e) { + this.currentFocusNodeId = e + } + + getCurrentFocusNodeId() { + return this.currentFocusNodeId + } + + setLastFocusNodeId(e) { + this.lastFocusNodeId = e + } + + getLastFocusNodeId() { + return this.lastFocusNodeId + } + + getAddFocusNodeId() { + return this.addFocusNodeId + } + + setFlag(e) { + this.flag = e + } + } + + e.ListNodeDataSource = D; + + function _(e) { + let t = 0; + this.listNodeDataSource.ListNode.forEach((function (o, i) { + o.getNodeCurrentNodeId() == e && (t = i) + })); + return t + } + + class T extends ViewPU { + constructor(e, t, o, i = -1) { + super(e, o, i); + this.listNodeDataSource = void 0; + this.treeController = void 0; + this.__dropSelectedIndex = new ObservedPropertySimplePU(0, this, "dropSelectedIndex"); + this.listTreeViewMenu = null; + this.__listTreeViewWidth = new SynchedPropertySimpleOneWayPU(t.listTreeViewWidth, this, "listTreeViewWidth"); + this.__listTreeViewHeight = new SynchedPropertySimpleOneWayPU(t.listTreeViewHeight, this, "listTreeViewHeight"); + this.MAX_CN_LENGTH = 254; + this.MAX_EN_LENGTH = 255; + this.INITIAL_INVALID_VALUE = -1; + this.MAX_TOUCH_DOWN_COUNT = 0; + this.isMultiPress = !1; + this.touchDownCount = this.INITIAL_INVALID_VALUE; + this.appEventBus = a.getInstance().getTreeListener(); + this.itemPadding = { + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_card_margin_middle"], + bundleName: "", + moduleName: "" + }, + right: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_card_margin_middle"], + bundleName: "", + moduleName: "" + }, + top: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_margin_vertical"], + bundleName: "", + moduleName: "" + }, + bottom: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_margin_vertical"], + bundleName: "", + moduleName: "" + } + }; + this.textInputPadding = { left: "0vp", right: "0vp", top: "0vp", bottom: "0vp" }; + this.setInitiallyProvidedValue(t) + } + + setInitiallyProvidedValue(e) { + void 0 !== e.listNodeDataSource && (this.listNodeDataSource = e.listNodeDataSource); + void 0 !== e.treeController && (this.treeController = e.treeController); + void 0 !== e.dropSelectedIndex && (this.dropSelectedIndex = e.dropSelectedIndex); + void 0 !== e.listTreeViewMenu && (this.listTreeViewMenu = e.listTreeViewMenu); + void 0 !== e.MAX_CN_LENGTH && (this.MAX_CN_LENGTH = e.MAX_CN_LENGTH); + void 0 !== e.MAX_EN_LENGTH && (this.MAX_EN_LENGTH = e.MAX_EN_LENGTH); + void 0 !== e.INITIAL_INVALID_VALUE && (this.INITIAL_INVALID_VALUE = e.INITIAL_INVALID_VALUE); + void 0 !== e.MAX_TOUCH_DOWN_COUNT && (this.MAX_TOUCH_DOWN_COUNT = e.MAX_TOUCH_DOWN_COUNT); + void 0 !== e.isMultiPress && (this.isMultiPress = e.isMultiPress); + void 0 !== e.touchDownCount && (this.touchDownCount = e.touchDownCount); + void 0 !== e.appEventBus && (this.appEventBus = e.appEventBus); + void 0 !== e.itemPadding && (this.itemPadding = e.itemPadding); + void 0 !== e.textInputPadding && (this.textInputPadding = e.textInputPadding) + } + + updateStateVars(e) { + this.__listTreeViewWidth.reset(e.listTreeViewWidth); + this.__listTreeViewHeight.reset(e.listTreeViewHeight) + } + + purgeVariableDependenciesOnElmtId(e) { + this.__dropSelectedIndex.purgeDependencyOnElmtId(e); + this.__listTreeViewWidth.purgeDependencyOnElmtId(e); + this.__listTreeViewHeight.purgeDependencyOnElmtId(e) + } + + aboutToBeDeleted() { + this.__dropSelectedIndex.aboutToBeDeleted(); + this.__listTreeViewWidth.aboutToBeDeleted(); + this.__listTreeViewHeight.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal() + } + + get dropSelectedIndex() { + return this.__dropSelectedIndex.get() + } + + set dropSelectedIndex(e) { + this.__dropSelectedIndex.set(e) + } + + get listTreeViewWidth() { + return this.__listTreeViewWidth.get() + } + + set listTreeViewWidth(e) { + this.__listTreeViewWidth.set(e) + } + + get listTreeViewHeight() { + return this.__listTreeViewHeight.get() + } + + set listTreeViewHeight(e) { + this.__listTreeViewHeight.set(e) + } + + aboutToAppear() { + this.listTreeViewWidth = void 0 === this.listTreeViewWidth ? 200 : this.listTreeViewWidth; + this.listNodeDataSource = this.treeController.getListNodeDataSource() + } + + checkInvalidPattern(e) { + return /[\\\/:*?"<>|]/.test(e) + } + + checkIsAllCN(e) { + return /^[\u4e00-\u9fa5]+$/.test(e) + } + + popupForShowTitle(e, t, o, i = null) { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(t); + Row.border({ + radius: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_elements_margin_horizontal_l"], + bundleName: "", + moduleName: "" + } + }); + Row.padding({ + left: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_elements_margin_horizontal_l"], + bundleName: "", + moduleName: "" + }, + right: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_elements_margin_horizontal_l"], + bundleName: "", + moduleName: "" + }, + top: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_card_margin_middle"], + bundleName: "", + moduleName: "" + }, + bottom: { + id: -1, + type: 10002, + params: ["sys.float.ohos_id_card_margin_middle"], + bundleName: "", + moduleName: "" + } + }); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((t, i) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + Text.create(e); + Text.fontSize({ + id: -1, + type: 10002, + params: ["sys.float.ohos_id_text_size_body2"], + bundleName: "", + moduleName: "" + }); + Text.fontWeight("regular"); + Text.fontColor(o); + i || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Row.pop() + } + + builder(e = null) { + this.listTreeViewMenu.bind(this)() + } + + draggingPopup(e, o = null) { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.constraintSize({ + minWidth: this.listNodeDataSource.getDragPopupPara().floorConstraintSize.minWidth, + maxWidth: this.listNodeDataSource.getDragPopupPara().floorConstraintSize.maxWidth + }); + Row.height(this.listNodeDataSource.getDragPopupPara().height); + Row.backgroundColor(this.listNodeDataSource.getDragPopupPara().backgroundColor); + Row.padding({ + left: this.listNodeDataSource.getDragPopupPara().padding.left, + right: this.listNodeDataSource.getDragPopupPara().padding.right + }); + Row.shadow({ + radius: this.listNodeDataSource.getDragPopupPara().shadow.radius, + color: this.listNodeDataSource.getDragPopupPara().shadow.color, + offsetY: this.listNodeDataSource.getDragPopupPara().shadow.offsetY + }); + Row.borderRadius(this.listNodeDataSource.getDragPopupPara().borderRadius); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((o, i) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + If.create(); + e.getNodeItem().imageNode ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((o, i) => { + ViewStackProcessor.StartGetAccessRecordingFor(o); + Row.create(); + Row.backgroundColor(t); + Row.margin({ right: e.getNodeItem().imageNode.itemRightMargin }); + Row.height(e.getNodeItem().imageNode.itemHeight); + Row.width(e.getNodeItem().imageNode.itemWidth); + i || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((t, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + Image.create(e.getNodeItem().imageNode.normalSource); + Image.objectFit(ImageFit.Contain); + Image.height(e.getNodeItem().imageNode.itemHeight); + Image.width(e.getNodeItem().imageNode.itemWidth); + Image.opacity(this.listNodeDataSource.getDragPopupPara().imageOpacity); + o || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + i || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((t, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + Row.create(); + Row.constraintSize({ + minWidth: e.getNodeItem().imageNode ? this.listNodeDataSource.getDragPopupPara() + .textConstraintSize + .minWidth1 : this.listNodeDataSource.getDragPopupPara() + .textConstraintSize + .minWidth2, + maxWidth: e.getNodeItem().imageNode ? this.listNodeDataSource.getDragPopupPara() + .textConstraintSize + .maxWidth1 : this.listNodeDataSource.getDragPopupPara() + .textConstraintSize + .maxWidth2 + }); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((t, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + If.create(); + e.getNodeItem().mainTitleNode && e.getIsShowTitle() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((t, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + Text.create(e.getNodeItem().mainTitleNode.title); + Text.maxLines(1); + Text.fontSize(e.getNodeItem().mainTitleNode.size); + Text.fontColor(this.listNodeDataSource.getDragPopupPara().fontColor); + Text.fontWeight(this.listNodeDataSource.getDragPopupPara().fontWeight); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + o || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Row.pop(); + Row.pop() + } + + initialRender() { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + List.create({}); + List.width(this.listTreeViewWidth); + List.height(this.listTreeViewHeight); + List.onDragMove((e => { + if (this.isMultiPress) { + console.error("drag error, a item has been dragged"); + return + } + let t = Math.floor(e.getY() / 24) % 2 ? g.DOWN_FLAG : g.UP_FLAG; + let o = Math.floor(e.getY() / 48); + let i = !1; + if (o >= this.listNodeDataSource.totalCount()) { + t = g.DOWN_FLAG; + o = this.listNodeDataSource.totalCount() - 1; + this.listNodeDataSource.getData(o).setIsOverBorder(!0); + i = !0 + } else this.listNodeDataSource.getData(o).setIsOverBorder(!1); + let s = this.listNodeDataSource.getData(o).getCurrentNodeId(); + if (o != this.listNodeDataSource.getLastPassIndex() && this.listNodeDataSource.getIsInnerDrag()) { + if (this.listNodeDataSource.getIsParentOfInsertNode(s)) { + this.listNodeDataSource.setPassIndex(o); + let e = this; + this.listNodeDataSource.clearTimeOutAboutDelayHighLightAndExpand(_.call(e, s)); + this.listNodeDataSource.setFlag(g.NONE); + return + } + } + this.listNodeDataSource.setLastPassIndex(o); + this.listNodeDataSource.setVisibility(t, o, i); + if (s != this.listNodeDataSource.getDraggingCurrentNodeId()) { + let e = this; + this.listNodeDataSource.delayHighLightAndExpandNode(_.call(e, s), s, o) + } + })); + List.onDragEnter(((e, t) => { + if (this.listNodeDataSource.getIsInnerDrag()) { + this.listNodeDataSource.setIsDrag(!0); + let e = .4; + this.listNodeDataSource.setListItemOpacity(e) + } + })); + List.onDragLeave(((e, t) => { + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.clearLastTimeoutExpand(); + this.listNodeDataSource.setListItemOpacity(1); + this.listNodeDataSource.setIsDrag(!1); + this.listNodeDataSource.notifyDataReload() + })); + List.onDrop(((e, t) => { + this.listNodeDataSource.clearLastTimeoutExpand(); + this.listNodeDataSource.setListItemOpacity(1); + let o = this.listNodeDataSource.getPassIndex(); + let i = this.dropSelectedIndex; + if (i - 1 > this.listNodeDataSource.totalCount() || null == i) { + console.error("drag error, currentNodeIndex is not found"); + this.listNodeDataSource.setIsDrag(!1); + return + } + if (o == this.listNodeDataSource.totalCount()) { + console.log("need to insert into the position of the last line, now insertNodeIndex = insertNodeIndex - 1"); + o -= 1 + } + let s = this.listNodeDataSource.getData(o); + let a = s.getNodeCurrentNodeId(); + if (!this.listNodeDataSource.getIsDrag() || !this.listNodeDataSource.getIsInnerDrag()) { + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.setIsInnerDrag(!1); + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.refreshSubtitle(a); + this.listNodeDataSource.notifyDataReload(); + return + } + let d = this.listNodeDataSource.getCurrentNodeInfo(); + let n = s.getNodeParentNodeId(); + let l = this.listNodeDataSource.getDraggingCurrentNodeId(); + let h = this.listNodeDataSource.getDraggingParentNodeId(); + if (this.listNodeDataSource.getIsParentOfInsertNode(a)) { + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.setIsInnerDrag(!1); + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.notifyDataChange(o); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.setIsDrag(!1); + let e = this; + let t = _.call(e, l); + this.listNodeDataSource.setClickIndex(t); + this.listNodeDataSource.handleEvent(r.DRAG, t); + return + } + if (this.listNodeDataSource.getExpandAndCollapseInfo(l) == I.Expand) { + let e = this; + this.listNodeDataSource.expandAndCollapseNode(_.call(e, l)) + } + if (this.listNodeDataSource.getExpandAndCollapseInfo(a) == I.Collapse) { + let e = this; + let t = _.call(e, a); + this.listNodeDataSource.ListNode[t].getIsHighLight() && this.listNodeDataSource.expandAndCollapseNode(t) + } + this.listNodeDataSource.setLastDelayHighLightId(); + if (l != a) { + this.listNodeDataSource.alterDragNode(n, a, s, h, l, d); + this.listNodeDataSource.hideLastLine() + } else { + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.setLastPassId(l); + this.listNodeDataSource.hideLastLine() + } + let g = _.call(this, this.listNodeDataSource.getLastDelayHighLightId()); + this.listNodeDataSource.setLastDelayHighLightIndex(g); + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.setIsDrag(!1); + let c = _.call(this, l); + this.listNodeDataSource.setClickIndex(c); + this.listNodeDataSource.handleEvent(r.DRAG, c); + this.listNodeDataSource.setIsInnerDrag(!1); + this.listNodeDataSource.notifyDataReload() + })); + t || List.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + { + const e = e => { + const i = e; + { + const e = void 0 !== globalThis.__lazyForEachItemGenFunction && !0; + const a = (t, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(t); + ListItem.create(g, e); + ListItem.width("100%"); + ListItem.height(i.getListItemHeight()); + ListItem.padding({ left: this.itemPadding.left, right: this.itemPadding.right }); + ListItem.align(Alignment.Start); + ListItem.onDragStart(((e, t) => { + if (this.listNodeDataSource.getIsDrag() || this.listNodeDataSource.getIsInnerDrag() || this.isMultiPress) { + console.error("drag error, a item has been dragged"); + return + } + this.dropSelectedIndex = JSON.parse(t).selectedIndex; + let o = JSON.parse(t).selectedIndex; + let s = this.listNodeDataSource.getData(o); + let a = i.getNodeCurrentNodeId(); + if (o >= this.listNodeDataSource.totalCount() || null == o) { + console.error("drag error, currentNodeIndex is not found in onDragStart"); + return + } + this.listNodeDataSource.setIsInnerDrag(!0); + this.listNodeDataSource.setIsDrag(!0); + this.listNodeDataSource.setCurrentNodeInfo(s); + this.listNodeDataSource.setDraggingCurrentNodeId(s.getNodeCurrentNodeId()); + this.listNodeDataSource.setDraggingParentNodeId(s.getNodeParentNodeId()); + this.listNodeDataSource.setListItemOpacity(.4); + this.listNodeDataSource.notifyDataChange(o); + if (a == s.getNodeCurrentNodeId()) return { builder: () => { + this.draggingPopup.call(this, s) + } }; + console.error("drag is too fast,it attribute a fault to OH"); + this.listNodeDataSource.setIsDrag(!1) + })); + o || ListItem.pop(); + ViewStackProcessor.StopGetAccessRecording() + }; + const d = () => { + this.observeComponentCreation(a); + this.observeComponentCreation(((e, a) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeIsShow() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Column.create(); + Column.focusable(!0); + Column.onMouse((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + if (e.button == MouseButton.Right) { + t.listNodeDataSource.handleEvent(r.MOUSE_BUTTON_RIGHT, _.call(t, i.getNodeCurrentNodeId())); + this.listTreeViewMenu = i.getMenu(); + t.listNodeDataSource.setClickIndex(o); + t.listNodeDataSource.setPopUpInfo(l.HINTS, h.NONE,!1, o); + clearTimeout(i.getNodeItem().mainTitleNode.popUpTimeout) + } + e.stopPropagation() + })); + Column.padding({ top: this.itemPadding.top, bottom: this.itemPadding.bottom }); + Column.bindPopup(i.getPopUpInfo().popUpIsShow, { + builder: { builder: () => { + this.popupForShowTitle.call(this, i.getPopUpInfo().popUpText, i.getPopUpInfo() + .popUpColor, i.getPopUpInfo().popUpTextColor) + } }, + placement: Placement.BottomLeft, + placementOnTop: !1, + popupColor: i.getPopUpInfo().popUpColor, + autoCancel: !0, + enableArrow: i.getPopUpInfo().popUpEnableArrow + }); + t || Column.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Divider.create(); + Divider.height(this.listNodeDataSource.getFlagLine().flagLineHeight); + Divider.color(this.listNodeDataSource.getFlagLine().flagLineColor); + Divider.visibility(this.listNodeDataSource.getVisibility(i)); + Divider.lineCap(LineCapStyle.Round); + Divider.margin({ left: i.getFlagLineLeftMargin() }); + Divider.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yTopOffset + }); + t || Divider.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create({}); + Row.opacity(this.listNodeDataSource.getListItemOpacity(i)); + Row.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBasePlateOffset + }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create({}); + Row.width("100%"); + Row.onTouch((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + let a = i.getNodeCurrentNodeId(); + t.listNodeDataSource.setClickIndex(o); + if (e.type === TouchType.Down) { + this.touchDownCount++; + this.isMultiPress = this.touchDownCount > this.MAX_TOUCH_DOWN_COUNT; + this.listNodeDataSource.getIsTouchDown() || t.listNodeDataSource.handleEvent(r.TOUCH_DOWN, o) + } + if (e.type === TouchType.Up) { + this.touchDownCount--; + this.touchDownCount < this.MAX_TOUCH_DOWN_COUNT && (this.isMultiPress = !1); + let e = { currentNodeId: a }; + this.appEventBus.emit(s.NODE_CLICK, [e]); + t.listNodeDataSource.handleEvent(r.TOUCH_UP, o) + } + })); + Row.onHover((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + e ? t.listNodeDataSource.handleEvent(r.HOVER, o) : t.listNodeDataSource.getIsTouchDown() || t.listNodeDataSource.handleEvent(r.HOVER_OVER, o) + })); + Gesture.create(GesturePriority.Low); + TapGesture.create({ count: 2 }); + TapGesture.onAction((e => { + this.listNodeDataSource.expandAndCollapseNode(_.call(this, i.getNodeCurrentNodeId())) + })); + TapGesture.pop(); + Gesture.pop(); + Row.height(i.getNodeHeight()); + Row.padding({ left: i.getNodeLeftPadding() }); + Row.backgroundColor(i.getNodeItem().mainTitleNode && i.getNodeItem() + .inputText && i.getIsShowInputText() ? i.getNodeItem().inputText.editColor : i.getNodeColor()); + Row.border({ + width: i.getNodeBorder().borderWidth, + color: i.getNodeBorder().borderColor, + radius: i.getNodeBorder().borderRadius + }); + Row.bindContextMenu({ builder: this.builder.bind(this) }, ResponseType.RightClick); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().imageNode ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(t); + Row.margin({ right: i.getNodeItem().imageNode.itemRightMargin }); + Row.height(i.getNodeItem().imageNode.itemHeight); + Row.width(i.getNodeItem().imageNode.itemWidth); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(i.getNodeItem().imageNode.source); + Image.objectFit(ImageFit.Contain); + Image.height(i.getNodeItem().imageNode.itemHeight); + Image.width(i.getNodeItem().imageNode.itemWidth); + Image.opacity(i.getIsSelected() || i.getIsHighLight() ? i.getNodeItem() + .imageNode + .noOpacity : i.getNodeItem() + .imageNode + .opacity); + Image.focusable(null == i.getNodeItem().mainTitleNode); + Image.onFocus((() => { + this.listNodeDataSource.handleEvent(r.FOCUS, _.call(this, i.getNodeCurrentNodeId())) + })); + Image.onBlur((() => { + this.listNodeDataSource.handleEvent(r.BLUR, _.call(this, i.getNodeCurrentNodeId())) + })); + t || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.layoutWeight(1); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().mainTitleNode && i.getIsShowTitle() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Text.create(i.getNodeItem().mainTitleNode.title); + Text.maxLines(1); + Text.fontSize(i.getNodeItem().mainTitleNode.size); + Text.fontColor(i.getNodeItem().mainTitleNode.color); + Text.margin({ right: i.getNodeItem().mainTitleNode.itemRightMargin }); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + Text.fontWeight(i.getNodeItem().mainTitleNode.weight); + Text.focusable(!0); + Text.onFocus((() => { + this.listNodeDataSource.handleEvent(r.FOCUS, _.call(this, i.getNodeCurrentNodeId())) + })); + Text.onBlur((() => { + this.listNodeDataSource.handleEvent(r.BLUR, _.call(this, i.getNodeCurrentNodeId())) + })); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().mainTitleNode && i.getNodeItem() + .inputText && i.getIsShowInputText() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(i.getNodeItem().inputText.backgroundColor); + Row.borderRadius(i.getNodeItem().inputText.borderRadius); + Row.margin({ right: i.getNodeItem().inputText.itemRightMargin }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + TextInput.create({ text: i.getNodeItem().mainTitleNode.title }); + TextInput.height(i.getNodeItem().inputText.itemHeight); + TextInput.fontSize(i.getNodeItem().inputText.size); + TextInput.fontColor(i.getNodeItem().inputText.color); + TextInput.borderRadius(i.getNodeItem().inputText.borderRadius); + TextInput.backgroundColor(i.getNodeItem().inputText.backgroundColor); + TextInput.enterKeyType(EnterKeyType.Done); + TextInput.padding({ + left: this.textInputPadding.left, + right: this.textInputPadding.right, + top: this.textInputPadding.top, + bottom: this.textInputPadding.bottom + }); + TextInput.onChange((e => { + let t = this; + var o = _.call(t, i.getNodeCurrentNodeId()); + let s = ""; + let a = !1; + let d = !1; + if (t.checkInvalidPattern(e)) { + for (let o = 0;o < e.length; o++) t.checkInvalidPattern(e[o]) || (s += e[o]); + a = !0; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.INVALID_ERROR,!0, o) + } else { + s = e; + a = !1; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.INVALID_ERROR,!1, o) + } + if (t.checkIsAllCN(s) && s.length > this.MAX_CN_LENGTH || !t.checkIsAllCN(s) && s.length > this.MAX_EN_LENGTH) { + s = t.checkIsAllCN(s) ? s.substr(0, this.MAX_CN_LENGTH) : s.substr(0, this.MAX_EN_LENGTH); + d = !0; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.LENGTH_ERROR,!0, o) + } else d = !1; + if (!d && !a) { + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.LENGTH_ERROR,!1, o); + t.listNodeDataSource.setMainTitleNameOnEdit(o, s) + } + })); + TextInput.onSubmit((e => { + let t = this; + var o = _.call(t, i.getNodeCurrentNodeId()); + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.NONE,!1, o); + t.listNodeDataSource.setItemVisibilityOnEdit(o, n.COMMIT_NODE) + })); + t || TextInput.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Blank.create(); + t || Blank.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Blank.pop(); + Row.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.listNodeDataSource.hasSubtitle(i.getCurrentNodeId()) ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.margin({ + left: this.listNodeDataSource.getSubTitlePara().margin.left, + right: i.getNodeItem().imageCollapse ? 0 : this.listNodeDataSource.getSubTitlePara() + .margin + .right + }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Text.create(this.listNodeDataSource.getSubtitle(i.getCurrentNodeId())); + Text.fontSize(this.listNodeDataSource.getSubTitlePara().fontSize); + Text.fontColor(this.listNodeDataSource.getSubTitleFontColor(i.getIsHighLight() || i.getIsModify())); + Text.fontWeight(this.listNodeDataSource.getSubTitlePara().fontWeight); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Row.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().imageCollapse ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(t); + Row.height(i.getNodeItem().imageCollapse.itemHeight); + Row.width(i.getNodeItem().imageCollapse.itemWidth); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(i.getNodeItem().imageCollapse.collapseSource); + Image.fillColor(i.getNodeItem().imageCollapse.isCollapse ? t : o); + Image.align(Alignment.End); + Image.objectFit(ImageFit.Contain); + Image.height(i.getNodeItem().imageCollapse.itemHeight); + Image.width(i.getNodeItem().imageCollapse.itemWidth); + Image.opacity(i.getIsHighLight() ? i.getNodeItem().imageCollapse.noOpacity : i.getNodeItem() + .imageCollapse + .opacity); + Image.onTouch((e => { + if (e.type === TouchType.Down) { + let e = this; + e.listNodeDataSource.expandAndCollapseNode(_.call(e, i.getNodeCurrentNodeId())); + this.listNodeDataSource.setCurrentFocusNodeId(i.getCurrentNodeId()) + } + e.stopPropagation() + })); + s || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + s || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Row.pop(); + Row.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getCanShowBottomFlagLine() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.listNodeDataSource.getPassIndex() != this.listNodeDataSource.totalCount() - 1 || i.getIsHighLight() ? If.branchId(1) : this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Divider.create(); + Divider.height(this.listNodeDataSource.getFlagLine().flagLineHeight); + Divider.color(this.listNodeDataSource.getFlagLine().flagLineColor); + Divider.visibility(Visibility.Visible); + Divider.lineCap(LineCapStyle.Round); + Divider.margin({ left: i.getFlagLineLeftMargin() }); + Divider.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBottomOffset + }); + t || Divider.pop(); + ViewStackProcessor.StopGetAccessRecording() + })) + })); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Column.pop() + })) : If.branchId(1); + a || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + ListItem.pop() + }; + const g = (e, d) => { + a(e, d); + this.updateFuncByElmtId.set(e, a); + this.observeComponentCreation(((e, a) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeIsShow() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Column.create(); + Column.focusable(!0); + Column.onMouse((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + if (e.button == MouseButton.Right) { + t.listNodeDataSource.handleEvent(r.MOUSE_BUTTON_RIGHT, _.call(t, i.getNodeCurrentNodeId())); + this.listTreeViewMenu = i.getMenu(); + t.listNodeDataSource.setClickIndex(o); + t.listNodeDataSource.setPopUpInfo(l.HINTS, h.NONE,!1, o); + clearTimeout(i.getNodeItem().mainTitleNode.popUpTimeout) + } + e.stopPropagation() + })); + Column.padding({ top: this.itemPadding.top, bottom: this.itemPadding.bottom }); + Column.bindPopup(i.getPopUpInfo().popUpIsShow, { + builder: { builder: () => { + this.popupForShowTitle.call(this, i.getPopUpInfo().popUpText, i.getPopUpInfo() + .popUpColor, i.getPopUpInfo().popUpTextColor) + } }, + placement: Placement.BottomLeft, + placementOnTop: !1, + popupColor: i.getPopUpInfo().popUpColor, + autoCancel: !0, + enableArrow: i.getPopUpInfo().popUpEnableArrow + }); + t || Column.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Divider.create(); + Divider.height(this.listNodeDataSource.getFlagLine().flagLineHeight); + Divider.color(this.listNodeDataSource.getFlagLine().flagLineColor); + Divider.visibility(this.listNodeDataSource.getVisibility(i)); + Divider.lineCap(LineCapStyle.Round); + Divider.margin({ left: i.getFlagLineLeftMargin() }); + Divider.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yTopOffset + }); + t || Divider.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create({}); + Row.opacity(this.listNodeDataSource.getListItemOpacity(i)); + Row.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBasePlateOffset + }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create({}); + Row.width("100%"); + Row.onTouch((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + let a = i.getNodeCurrentNodeId(); + t.listNodeDataSource.setClickIndex(o); + if (e.type === TouchType.Down) { + this.touchDownCount++; + this.isMultiPress = this.touchDownCount > this.MAX_TOUCH_DOWN_COUNT; + this.listNodeDataSource.getIsTouchDown() || t.listNodeDataSource.handleEvent(r.TOUCH_DOWN, o) + } + if (e.type === TouchType.Up) { + this.touchDownCount--; + this.touchDownCount < this.MAX_TOUCH_DOWN_COUNT && (this.isMultiPress = !1); + let e = { currentNodeId: a }; + this.appEventBus.emit(s.NODE_CLICK, [e]); + t.listNodeDataSource.handleEvent(r.TOUCH_UP, o) + } + })); + Row.onHover((e => { + let t = this; + let o = _.call(t, i.getNodeCurrentNodeId()); + e ? t.listNodeDataSource.handleEvent(r.HOVER, o) : t.listNodeDataSource.getIsTouchDown() || t.listNodeDataSource.handleEvent(r.HOVER_OVER, o) + })); + Gesture.create(GesturePriority.Low); + TapGesture.create({ count: 2 }); + TapGesture.onAction((e => { + this.listNodeDataSource.expandAndCollapseNode(_.call(this, i.getNodeCurrentNodeId())) + })); + TapGesture.pop(); + Gesture.pop(); + Row.height(i.getNodeHeight()); + Row.padding({ left: i.getNodeLeftPadding() }); + Row.backgroundColor(i.getNodeItem().mainTitleNode && i.getNodeItem() + .inputText && i.getIsShowInputText() ? i.getNodeItem().inputText.editColor : i.getNodeColor()); + Row.border({ + width: i.getNodeBorder().borderWidth, + color: i.getNodeBorder().borderColor, + radius: i.getNodeBorder().borderRadius + }); + Row.bindContextMenu({ builder: this.builder.bind(this) }, ResponseType.RightClick); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().imageNode ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(t); + Row.margin({ right: i.getNodeItem().imageNode.itemRightMargin }); + Row.height(i.getNodeItem().imageNode.itemHeight); + Row.width(i.getNodeItem().imageNode.itemWidth); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(i.getNodeItem().imageNode.source); + Image.objectFit(ImageFit.Contain); + Image.height(i.getNodeItem().imageNode.itemHeight); + Image.width(i.getNodeItem().imageNode.itemWidth); + Image.opacity(i.getIsSelected() || i.getIsHighLight() ? i.getNodeItem() + .imageNode + .noOpacity : i.getNodeItem() + .imageNode + .opacity); + Image.focusable(null == i.getNodeItem().mainTitleNode); + Image.onFocus((() => { + this.listNodeDataSource.handleEvent(r.FOCUS, _.call(this, i.getNodeCurrentNodeId())) + })); + Image.onBlur((() => { + this.listNodeDataSource.handleEvent(r.BLUR, _.call(this, i.getNodeCurrentNodeId())) + })); + t || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + o || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.layoutWeight(1); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().mainTitleNode && i.getIsShowTitle() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Text.create(i.getNodeItem().mainTitleNode.title); + Text.maxLines(1); + Text.fontSize(i.getNodeItem().mainTitleNode.size); + Text.fontColor(i.getNodeItem().mainTitleNode.color); + Text.margin({ right: i.getNodeItem().mainTitleNode.itemRightMargin }); + Text.textOverflow({ overflow: TextOverflow.Ellipsis }); + Text.fontWeight(i.getNodeItem().mainTitleNode.weight); + Text.focusable(!0); + Text.onFocus((() => { + this.listNodeDataSource.handleEvent(r.FOCUS, _.call(this, i.getNodeCurrentNodeId())) + })); + Text.onBlur((() => { + this.listNodeDataSource.handleEvent(r.BLUR, _.call(this, i.getNodeCurrentNodeId())) + })); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().mainTitleNode && i.getNodeItem() + .inputText && i.getIsShowInputText() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(i.getNodeItem().inputText.backgroundColor); + Row.borderRadius(i.getNodeItem().inputText.borderRadius); + Row.margin({ right: i.getNodeItem().inputText.itemRightMargin }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + TextInput.create({ text: i.getNodeItem().mainTitleNode.title }); + TextInput.height(i.getNodeItem().inputText.itemHeight); + TextInput.fontSize(i.getNodeItem().inputText.size); + TextInput.fontColor(i.getNodeItem().inputText.color); + TextInput.borderRadius(i.getNodeItem().inputText.borderRadius); + TextInput.backgroundColor(i.getNodeItem().inputText.backgroundColor); + TextInput.enterKeyType(EnterKeyType.Done); + TextInput.padding({ + left: this.textInputPadding.left, + right: this.textInputPadding.right, + top: this.textInputPadding.top, + bottom: this.textInputPadding.bottom + }); + TextInput.onChange((e => { + let t = this; + var o = _.call(t, i.getNodeCurrentNodeId()); + let s = ""; + let a = !1; + let d = !1; + if (t.checkInvalidPattern(e)) { + for (let o = 0;o < e.length; o++) t.checkInvalidPattern(e[o]) || (s += e[o]); + a = !0; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.INVALID_ERROR,!0, o) + } else { + s = e; + a = !1; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.INVALID_ERROR,!1, o) + } + if (t.checkIsAllCN(s) && s.length > this.MAX_CN_LENGTH || !t.checkIsAllCN(s) && s.length > this.MAX_EN_LENGTH) { + s = t.checkIsAllCN(s) ? s.substr(0, this.MAX_CN_LENGTH) : s.substr(0, this.MAX_EN_LENGTH); + d = !0; + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.LENGTH_ERROR,!0, o) + } else d = !1; + if (!d && !a) { + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.LENGTH_ERROR,!1, o); + t.listNodeDataSource.setMainTitleNameOnEdit(o, s) + } + })); + TextInput.onSubmit((e => { + let t = this; + var o = _.call(t, i.getNodeCurrentNodeId()); + t.listNodeDataSource.setPopUpInfo(l.WARNINGS, h.NONE,!1, o); + t.listNodeDataSource.setItemVisibilityOnEdit(o, n.COMMIT_NODE) + })); + t || TextInput.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Blank.create(); + t || Blank.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Blank.pop(); + Row.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.listNodeDataSource.hasSubtitle(i.getCurrentNodeId()) ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.margin({ + left: this.listNodeDataSource.getSubTitlePara().margin.left, + right: i.getNodeItem().imageCollapse ? 0 : this.listNodeDataSource.getSubTitlePara() + .margin + .right + }); + t || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Text.create(this.listNodeDataSource.getSubtitle(i.getCurrentNodeId())); + Text.fontSize(this.listNodeDataSource.getSubTitlePara().fontSize); + Text.fontColor(this.listNodeDataSource.getSubTitleFontColor(i.getIsHighLight() || i.getIsModify())); + Text.fontWeight(this.listNodeDataSource.getSubTitlePara().fontWeight); + t || Text.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Text.pop(); + Row.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getNodeItem().imageCollapse ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, o) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Row.create(); + Row.backgroundColor(t); + Row.height(i.getNodeItem().imageCollapse.itemHeight); + Row.width(i.getNodeItem().imageCollapse.itemWidth); + o || Row.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + this.observeComponentCreation(((e, s) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Image.create(i.getNodeItem().imageCollapse.collapseSource); + Image.fillColor(i.getNodeItem().imageCollapse.isCollapse ? t : o); + Image.align(Alignment.End); + Image.objectFit(ImageFit.Contain); + Image.height(i.getNodeItem().imageCollapse.itemHeight); + Image.width(i.getNodeItem().imageCollapse.itemWidth); + Image.opacity(i.getIsHighLight() ? i.getNodeItem().imageCollapse.noOpacity : i.getNodeItem() + .imageCollapse + .opacity); + Image.onTouch((e => { + if (e.type === TouchType.Down) { + let e = this; + e.listNodeDataSource.expandAndCollapseNode(_.call(e, i.getNodeCurrentNodeId())); + this.listNodeDataSource.setCurrentFocusNodeId(i.getCurrentNodeId()) + } + e.stopPropagation() + })); + s || Image.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + Row.pop() + })) : If.branchId(1); + s || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Row.pop(); + Row.pop(); + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + i.getCanShowBottomFlagLine() ? this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + If.create(); + this.listNodeDataSource.getPassIndex() != this.listNodeDataSource.totalCount() - 1 || i.getIsHighLight() ? If.branchId(1) : this.ifElseBranchUpdateFunction(0, (() => { + this.observeComponentCreation(((e, t) => { + ViewStackProcessor.StartGetAccessRecordingFor(e); + Divider.create(); + Divider.height(this.listNodeDataSource.getFlagLine().flagLineHeight); + Divider.color(this.listNodeDataSource.getFlagLine().flagLineColor); + Divider.visibility(Visibility.Visible); + Divider.lineCap(LineCapStyle.Round); + Divider.margin({ left: i.getFlagLineLeftMargin() }); + Divider.markAnchor({ + x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBottomOffset + }); + t || Divider.pop(); + ViewStackProcessor.StopGetAccessRecording() + })) + })); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop() + })) : If.branchId(1); + t || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + Column.pop() + })) : If.branchId(1); + a || If.pop(); + ViewStackProcessor.StopGetAccessRecording() + })); + If.pop(); + ListItem.pop() + }; + e ? (() => { + this.observeComponentCreation(a); + ListItem.pop() + })() : d() + } + }; + const i = e => JSON.stringify(e); + LazyForEach.create("1", this, this.listNodeDataSource, e, i); + LazyForEach.pop() + } + List.pop() + } + + rerender() { + this.updateDirtyElements() + } + } + + __decorate([], T.prototype, "popupForShowTitle", null); + __decorate([], T.prototype, "builder", null); + __decorate([], T.prototype, "draggingPopup", null); + e.TreeView = T; + e.TreeController = class { + constructor() { + this.ROOT_NODE_ID = -1; + this.nodeIdList = []; + this.listNodeUtils = new C; + this.listNodeDataSource = new D + } + + getListNodeDataSource() { + return this.listNodeDataSource + } + + getClickNodeChildrenInfo() { + let e = this.listNodeDataSource.getClickNodeId(); + return this.listNodeUtils.getClickNodeChildrenInfo(e) + } + + getChildrenId() { + let e = this.listNodeDataSource.getClickNodeId(); + return this.listNodeUtils.getClickChildId(e) + } + + removeNode() { + let e = this.listNodeDataSource.getClickNodeId(); + let t = this.listNodeUtils.findParentNodeId(e); + let o = this.listNodeUtils.removeNode(e, t, this.listNodeUtils.traverseNodeBF); + this.listNodeDataSource.refreshData(this.listNodeUtils, n.REMOVE_NODE, t, o); + this.nodeIdList.splice(this.nodeIdList.indexOf(e), 1) + } + + modifyNode() { + let e = this.listNodeDataSource.getClickNodeId(); + this.listNodeDataSource.setItemVisibilityOnEdit(e, n.MODIFY_NODE) + } + + add() { + let e = this.listNodeDataSource.getClickNodeId(); + if (e == this.listNodeDataSource.ROOT_NODE_ID || !this.listNodeDataSource.getIsFolder(e)) return; + let t = { + isFolder: !0, + icon: null, + selectedIcon: null, + editIcon: null, + menu: null, + secondaryTitle: "" + }; + t = this.listNodeUtils.getNewNodeInfo(e); + this.nodeIdList.push(this.nodeIdList[this.nodeIdList.length-1] + 1); + let o = this.nodeIdList[this.nodeIdList.length-1]; + this.listNodeUtils.addNewNodeId = o; + this.listNodeUtils.addNode(e, o, { + isFolder: t.isFolder, + icon: t.icon, + selectedIcon: t.selectedIcon, + editIcon: t.editIcon, + primaryTitle: "新建文件夹", + menu: t.menu, + secondaryTitle: t.secondaryTitle + }); + this.listNodeDataSource.refreshData(this.listNodeUtils, n.ADD_NODE, e, [o]) + } + + addNodeParam(e) { + if (null != e.primaryTitle && !this.listNodeUtils.checkMainTitleIsValid(e.primaryTitle)) throw new Error('ListTreeNode[addNode]: The directory name cannot contain the following characters /: *? "< > | or exceeds the maximum length.'); + if (null == e.primaryTitle && null == e.icon) throw new Error("ListTreeNode[addNode]: The icon and directory name cannot be empty at the same time."); + if (e.currentNodeId === this.ROOT_NODE_ID || null === e.currentNodeId) throw new Error("ListTreeNode[addNode]: currentNodeId can not be -1 or null."); + this.nodeIdList.push(e.currentNodeId); + this.listNodeUtils.addNode(e.parentNodeId, e.currentNodeId, e); + return this + } + + addNode(e) { + if (null != e) { + if (null != e.primaryTitle && !this.listNodeUtils.checkMainTitleIsValid(e.primaryTitle)) throw new Error('ListTreeNode[addNode]: The directory name cannot contain the following characters /: *? "< > | or exceeds the maximum length.'); + if (null == e.primaryTitle && null == e.icon) throw new Error("ListTreeNode[addNode]: The icon and directory name cannot be empty at the same time."); + if (e.currentNodeId === this.ROOT_NODE_ID || null === e.currentNodeId) throw new Error("ListTreeNode[addNode]: currentNodeId can not be -1 or null."); + this.nodeIdList.push(e.currentNodeId); + this.listNodeUtils.addNode(e.parentNodeId, e.currentNodeId, e); + return this + } + this.add() + } + + buildDone() { + this.listNodeDataSource.init(this.listNodeUtils); + this.nodeIdList.sort(((e, t) => e - t)) + } + + refreshNode(e, t = "", o = "") { + this.listNodeDataSource.setNodeSubtitlePara(e, t, o) + } + } +}(TreeView || (TreeView = {})); + +export default TreeView \ No newline at end of file diff --git a/source/SubHeader/SubHeader.ets b/source/SubHeader/SubHeader.ets new file mode 100644 index 0000000..da40ac5 --- /dev/null +++ b/source/SubHeader/SubHeader.ets @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const SPACE_MARGIN: number = 8 +const MARGIN_NUM: number = 4 +const IMAGE_WIDTH_NUM: number = 16 +const IMAGE_HEIGHT_NUM: number = 24 +const BUTTON_SIZE: number = 32 +const SINGLE_LINE_HEIGHT: number = 48 +const DOUBLE_LINE_HEIGHT: number = 64 +const BUTTON_HEIGHT: number = 28 +const IMAGE_WIDTH: number = 12 +const BORDER_WIDTH = 2 +const DIVIDEND_WIDTH = 3 +const SINGLE_LINE_NUM: number = 1 +const DOUBLE_LINE_NUM: number = 2 +const MIN_FONT_SIZE: number = 14 +const MAIN_TEXT_SIZE: number = 10 +const CONSTRAINT_WIDTH: number = 40 +const CONSTRAINT_NUM: number = 44 + +export enum OperationType { + TEXT_ARROW = 0, + BUTTON = 1, + ICON_GROUP = 2, + LOADING = 3, +} + +export declare type OperationOption = { + value: ResourceStr; + action?: () => void; +} + +export declare type SelectOptions = { + options: Array; + selected?: number; + value?: string; + onSelect?: (index: number, value?: string) => void; +} + +@Component +struct IconGroup { + @State bgColor: Resource = $r('sys.color.ohos_id_color_background') + @State isFocus: boolean = false + item: OperationOption + focusBorderWidth = BORDER_WIDTH + + build() { + Row() { + Image(this.item.value) + .fillColor($r('sys.color.ohos_id_color_primary')) + .width(IMAGE_HEIGHT_NUM) + .height(IMAGE_HEIGHT_NUM) + .focusable(true) + } + .focusable(true) + .width(BUTTON_SIZE) + .height(BUTTON_SIZE) + .margin({ right: SPACE_MARGIN, bottom: MARGIN_NUM }) + .justifyContent(FlexAlign.Center) + .borderRadius($r('sys.float.ohos_id_corner_radius_clicked')) + .backgroundColor(this.bgColor) + .onTouch((event) => { + if (event.type === TouchType.Down) { + this.item.action && this.item.action() + this.bgColor = $r('sys.color.ohos_id_color_click_effect') + } + if (event.type === TouchType.Up) { + this.bgColor = $r('sys.color.ohos_id_color_background') + } + }) + .onHover((isHover: boolean) => { + if (isHover) { + this.bgColor = $r('sys.color.ohos_id_color_hover') + } else { + this.bgColor = $r('sys.color.ohos_id_color_background') + } + }) + .border(this.isFocus ? + { width: this.focusBorderWidth, + color: $r('sys.color.ohos_id_color_emphasize'), + style: BorderStyle.Solid + } : { width: 0 }) + .onFocus(() => { + this.isFocus = true; + }) + .onBlur(() => { + this.isFocus = false; + }) + .onKeyEvent((event) => { + if (event.keyCode === 2054 || event.keyCode === 2050) { + this.item.action && this.item.action() + } + }) + } +} + +@Component +export struct SubHeader1 { + @Prop icon: Resource + @Prop primaryTitle: string + @Prop secondaryTitle: string + @Prop select: SelectOptions + @Prop operationType: OperationType = OperationType.BUTTON + operationItem: Array + @State isDuplicateLine: boolean = false + @State textArrowBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State buttonBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State iconBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State firstIconBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State SecondaryIconBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State thirdIconBgColor: Resource = $r('sys.color.ohos_id_color_background') + @State flag: boolean = false + @State isTextArrowFocus: boolean = false + @State flexWidth: number = 0 + @State titleWidth: number = 0 + @State titleWidth1: number = 0 + @State isButtonFocus: boolean = false + focusBorderWidth = BORDER_WIDTH + + @Builder ListTextStyle($$: { content: ResourceStr }) { + Text($$.content) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title3')) + .fontWeight(FontWeight.Medium) + .maxLines(DOUBLE_LINE_NUM) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .constraintSize({ minWidth: this.titleWidth }) + .margin({ left: $r('sys.float.ohos_id_max_padding_end'), bottom: SPACE_MARGIN, right: MARGIN_NUM }).borderWidth(1) + } + + @Builder ListIconStyle($$: { content: ResourceStr }, icon: ResourceStr) { + Row() { + Image(icon) + .width(IMAGE_WIDTH_NUM) + .height(IMAGE_WIDTH_NUM) + .margin({ right: SPACE_MARGIN }) + Text($$.content) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title3')) + .fontWeight(FontWeight.Medium) + .maxLines(DOUBLE_LINE_NUM) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .constraintSize({ minWidth: this.titleWidth - CONSTRAINT_WIDTH }) + } + .margin({ left: $r('sys.float.ohos_id_max_padding_end'), bottom: SPACE_MARGIN, right: MARGIN_NUM }) + } + + @Builder ContentTextStyle($$: { content: ResourceStr }) { + Text($$.content) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) + .fontWeight(FontWeight.Medium) + .maxLines(DOUBLE_LINE_NUM) + .maxFontSize($r('sys.float.ohos_id_text_size_sub_title2')) + .minFontSize(MIN_FONT_SIZE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .constraintSize({ maxWidth: this.titleWidth }) + .margin({ left: $r('sys.float.ohos_id_max_padding_start'), + right: MARGIN_NUM, bottom: SPACE_MARGIN }) + } + + @Builder SubTextStyle($$: { content: ResourceStr, subContent: ResourceStr }) { + Column() { + Text($$.content) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title2')) + .fontWeight(FontWeight.Medium) + .maxLines(SINGLE_LINE_NUM) + .maxFontSize($r('sys.float.ohos_id_text_size_sub_title2')) + .minFontSize(MIN_FONT_SIZE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + Text($$.subContent) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_sub_title3')) + .fontWeight(FontWeight.Medium) + .maxLines(SINGLE_LINE_NUM) + .maxFontSize($r('sys.float.ohos_id_text_size_sub_title3')) + .minFontSize(MAIN_TEXT_SIZE) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + } + .constraintSize({ maxWidth: this.titleWidth }) + .alignItems(HorizontalAlign.Start) + .onAppear(() => { + this.isDuplicateLine = true + }) + .margin({ left: $r('sys.float.ohos_id_max_padding_start'), + right: MARGIN_NUM, bottom: SPACE_MARGIN }) + } + + @Builder SelectStyle(selectParam: SelectOptions) { + Select(selectParam.options) + .selected(selectParam.selected) + .value(selectParam.value) + .onSelect((index: number, value?: string) => { + if (selectParam.onSelect) { + selectParam.onSelect(index, value) + } + }) + .constraintSize({ maxWidth: this.titleWidth }) + .margin({ left: $r('sys.float.ohos_id_default_padding_start'), right: MARGIN_NUM}) + } + + @Builder LoadingProcessStyle() { + LoadingProgress() + .width(IMAGE_HEIGHT_NUM) + .height(IMAGE_HEIGHT_NUM) + .focusable(true) + .margin({ right: $r('sys.float.ohos_id_default_padding_end'), bottom: MARGIN_NUM }) + } + + @Builder TextArrowStyle(textArrow: OperationOption) { + Row() { + Row() { + if (textArrow != null) { + Text(textArrow.value) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .margin({ right: MARGIN_NUM }) + .focusable(true) + .maxLines(DOUBLE_LINE_NUM) + } + Image($r('sys.media.ohos_ic_public_arrow_right')) + .fillColor($r('sys.color.ohos_id_color_tertiary')) + .width(IMAGE_WIDTH) + .height(IMAGE_HEIGHT_NUM) + .focusable(true) + }.margin({ left: SPACE_MARGIN, right: SPACE_MARGIN }) + } + .justifyContent(FlexAlign.End) + .focusable(true) + .margin({ left:MARGIN_NUM, right: MARGIN_NUM, bottom: MARGIN_NUM }) + .borderRadius($r('sys.float.ohos_id_corner_radius_subtab')) + .backgroundColor(this.textArrowBgColor) + .onTouch((event) => { + if (event.type === TouchType.Down) { + if (textArrow.action) { + textArrow.action() + } + this.textArrowBgColor = $r('sys.color.ohos_id_color_click_effect') + } + if (event.type === TouchType.Up) { + this.textArrowBgColor = $r('sys.color.ohos_id_color_background') + } + }) + .onHover((isHover: boolean) => { + if (isHover) { + this.textArrowBgColor = $r('sys.color.ohos_id_color_hover') + } else { + this.textArrowBgColor = $r('sys.color.ohos_id_color_background') + } + }) + .border(this.isTextArrowFocus ? + { width: this.focusBorderWidth, + color: $r('sys.color.ohos_id_color_focused_outline'), + style: BorderStyle.Solid + } : { width: 0 }) + .onFocus(() => { + this.isTextArrowFocus = true; + }) + .onBlur(() => { + this.isTextArrowFocus = false; + }) + .onKeyEvent((event) => { + if (event.keyCode === 2054 || event.keyCode === 2050) { + textArrow.action && textArrow.action() + } + }) + } + + @Builder ButtonStyle(button: OperationOption) { + Row() { + if (button != null) { + Text(button.value) + .maxLines(1) + .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) + .fontSize($r('sys.float.ohos_id_text_size_button2')) + .fontWeight(FontWeight.Medium) + .margin({ left: SPACE_MARGIN, right: SPACE_MARGIN }) + .focusable(true) + } + } + .onAreaChange((oldValue: Area, newValue: Area) => { + Number(parseInt(newValue.width.toString(), 0)) + console.log('wy buttonStyle1'+Number(parseInt(newValue.width.toString(), 0))) + }) + .justifyContent(FlexAlign.End) + .alignItems(VerticalAlign.Center) + .constraintSize({ maxWidth: this.flexWidth-this.titleWidth1 + 36 }) + .focusable(true) + .height(BUTTON_HEIGHT) + .margin({ left: SPACE_MARGIN, right: MARGIN_NUM }) + .borderRadius(IMAGE_WIDTH_NUM) + .backgroundColor(this.buttonBgColor) + .onTouch((event) => { + if (event.type === TouchType.Down) { + if (button.action) { + button.action() + } + this.buttonBgColor = $r('sys.color.ohos_id_color_click_effect') + } + if (event.type === TouchType.Up) { + this.buttonBgColor = $r('sys.color.ohos_id_color_background') + } + }) + .onHover((isHover: boolean) => { + if (isHover) { + this.buttonBgColor = $r('sys.color.ohos_id_color_hover') + } else { + this.buttonBgColor = $r('sys.color.ohos_id_color_background') + } + }) + .border(this.isButtonFocus ? + { width: this.focusBorderWidth, + color: $r('sys.color.ohos_id_color_focused_outline'), + style: BorderStyle.Solid + } : { width: 0 }) + .onFocus(() => { + this.isButtonFocus = true; + }) + .onBlur(() => { + this.isButtonFocus = false; + }) + .onKeyEvent((event) => { + if (event.keyCode === 2054 || event.keyCode === 2050) { + button.action && button.action() + } + }) + } + + build() { + Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.End }) { + Row() { + if (this.secondaryTitle != null && this.icon != null) { + this.ListIconStyle({ content: this.secondaryTitle }, this.icon) + } else if (this.secondaryTitle != null && this.primaryTitle != null) { + this.SubTextStyle({ content: this.primaryTitle, subContent: this.secondaryTitle }) + } else if (this.secondaryTitle != null) { + this.ListTextStyle({ content: this.secondaryTitle }) + } else if (this.select != null) { + this.SelectStyle(this.select) + } else if (this.primaryTitle != null) { + this.ContentTextStyle({ content: this.primaryTitle }) + } + } + .onAreaChange((oldValue: Area, newValue: Area) => { + this.titleWidth1 = Number(parseInt(newValue.width.toString(), 0)) + console.log('wy titleWidth1'+this.titleWidth.toString()) + }) + + Row() { + if (this.operationType === OperationType.BUTTON && this.operationItem != null) { + this.ButtonStyle(this.operationItem[0] ) + } + if (this.operationType === OperationType.ICON_GROUP && this.operationItem != null) { + Row() { + ForEach(this.operationItem, (item, index?: number) => { + if (index == 0) { + IconGroup({ item: item }) + } + if (index == 1) { + IconGroup({ item: item }) + } + if (index == 2) { // Image count + IconGroup({ item: item }) + } + }) + } + } + if (this.operationType === OperationType.TEXT_ARROW && this.operationItem != null) { + this.TextArrowStyle(this.operationItem[0]) + } + if (this.operationType === OperationType.LOADING) { + this.LoadingProcessStyle() + } + } + } + .onAreaChange((oldValue: Area, newValue: Area) => { + let flexWidth = Number(parseInt(newValue.width.toString(), 0)) + this.flexWidth = flexWidth - CONSTRAINT_NUM + this.titleWidth = this.flexWidth / DIVIDEND_WIDTH * BORDER_WIDTH + console.log('wy flexWidth'+this.flexWidth.toString()) + }) + .padding({ right: $r('sys.float.ohos_id_default_padding_end') }) + .height(this.isDuplicateLine ? DOUBLE_LINE_HEIGHT : SINGLE_LINE_HEIGHT) + } +} \ No newline at end of file diff --git a/source/TreeView/TreeView.ets b/source/TreeView/TreeView.ets new file mode 100644 index 0000000..8f56915 --- /dev/null +++ b/source/TreeView/TreeView.ets @@ -0,0 +1,3327 @@ +/* + * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export namespace TreeView { + const IMAGE_NODE_HEIGHT: number = 24 + const IMAGE_NODE_WIDTH: number = 24 + const ITEM_WIDTH: number = 0 + const ITEM_HEIGHT: number = 44 + const ITEM_HEIGHT_INPUT: number = 32 + const BORDER_WIDTH_HAS: number = 2 + const BORDER_WIDTH_NONE: number = 0 + const NODE_HEIGHT: number = 44 + const LIST_ITEM_HEIGHT_NONE: number = 0 + const LIST_ITEM_HEIGHT: number = 48 + const SHADOW_OFFSETY: number = 10 + const FLAG_NUMBER: number = 2 + const DRAG_OPACITY: number = 0.4 + const DRAG_OPACITY_NONE: number = 1 + const FLAG_LINE_HEIGHT: string = '1.5vp' + const X_OFF_SET: string = '0vp' + const Y_OFF_SET: string = '2.75vp' + const Y_BOTTOM_OFF_SET: string = '-1.25vp' + const Y_BASE_PLATE_OFF_SET: string = '1.5vp' + const COLOR_SELECT: string = '#1A0A59F7' + const COLOR_IMAGE_ROW: string = '#00000000' + const COLOR_IMAGE_EDIT: string = '#FFFFFF' + const SHADOW_COLOR: string = '#00001E' + const GRAG_POP_UP_HEIGHT: string = '48' + const LEFT_PADDING: string = '8vp' + const RIGHT_PADDING: string = '8vp' + const FLOOR_MIN_WIDTH: string = '128vp' + const FLOOR_MAX_WIDTH: string = '208vp' + const TEXT_MIN_WIDTH: string = '80vp' + const TEXT_MAX_WIDTH: string = '160vp' + const MIN_WIDTH: string = '112vp' + const MAX_WIDTH: string = '192vp' + + export class TreeListener { + _events = [] + + constructor() { + } + + /* + * Event registration and processing. + * + * The event will not be destroyed after being processed. + * + * @param type Registered Events. + * @param callback Event callback. + * @since 10 + */ + public on(type: TreeListenType, callback: (callbackParam: CallbackParam) => void) { + if (Array.isArray(type)) { + for (let i = 0, l = type.length; i < l; i++) { + this.on(type[i], callback) + } + } else { + (this._events[type] || (this._events[type] = [])).push(callback) + } + } + + /* + * Event registration and processing. + * + * After the event is processed once, it will be destroyed. + * + * @param type Registered Events. + * @param callback Event callback. + * @since 10 + */ + public once(type: TreeListenType, callback: (callbackParam: CallbackParam) => void) { + let _self = this; + function handler() { + _self.off(type, handler); + callback.apply(null, [type, callback]); + } + + handler.callback = callback; + this.on(type, handler); + } + + /* + * Destroy event. + * + * @param type Registered Events. + * @param callback Event callback. + * @since 10 + */ + public off(type: TreeListenType, callback: (callbackParam: CallbackParam) => void) { + if (type == null) { + this._events = []; + } + if (Array.isArray(type)) { + for (let i = 0, l = type.length; i < l; i++) { + this.off(type[i], callback) + } + } + const cbs = this._events[type]; + if (!cbs) { + return; + } + if (callback == null) { + this._events[type] = null + } + let cb, i = cbs.length + while (i--) { + cb = cbs[i] + if (cb === callback || cb.callback === callback) { + cbs.splice(i, 1) + break + } + } + } + + /* + * Triggers all callbacks of an event with parameters. + * + * @param event Registered Events. + * @param argument Parameters returned by the callback event. + * @since 10 + */ + public emit(event, argument: any[]) { + let _self = this + if (!this._events[event]) { + return + } + let cbs = [...this._events[event]]; + if (cbs) { + for (let i = 0, l = cbs.length; i < l; i++) { + try { + cbs[i].apply(_self,argument) + } catch (e) { + new Error(e) + } + } + } + } + } + + /* + * TreeListenType listen type. + * + * @since 10 + */ + export enum TreeListenType { + NODE_ADD = "NodeAdd", + NODE_DELETE = "NodeDelete", + NODE_MODIFY = "NodeModify", + NODE_MOVE = "NodeMove", + NODE_CLICK = 'NodeClick', + } + + /* + * TreeListenerManager. + * + * @since 10 + */ + export class TreeListenerManager { + static readonly APP_KEY_EVENT_BUS = "app_key_event_bus"; + private appEventBus: TreeListener; + private constructor() { + this.appEventBus = new TreeListener(); + } + + /* + * Obtains the EventBusManager object. + * + * @since 10 + */ + public static getInstance(): TreeListenerManager { + if (AppStorage.Get(this.APP_KEY_EVENT_BUS) == null) { + AppStorage.SetOrCreate(this.APP_KEY_EVENT_BUS, new TreeListenerManager()) + } + return AppStorage.Get(this.APP_KEY_EVENT_BUS); + } + + /* + * Obtains the EventBus object. + * + * @since 10 + */ + public getTreeListener(): TreeListener { + return this.appEventBus; + } + } + + class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = [] + + public totalCount(): number { + return 0 + } + public getData(index: number): any { + return undefined + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + this.listeners.push(listener) + } + } + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + this.listeners.splice(pos, 1) + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded() + }) + } + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index) + }) + } + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index) + }) + } + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index) + }) + } + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to) + }) + } + } + + export enum Event { + TOUCH_DOWN = 0, + TOUCH_UP = 1, + HOVER = 3, + HOVER_OVER = 4, + FOCUS = 5, + BLUR = 6, + MOUSE_BUTTON_RIGHT = 7, + DRAG = 8 + } + + export enum MenuOperation { + ADD_NODE = 0, + REMOVE_NODE = 1, + MODIFY_NODE = 2, + COMMIT_NODE = 3 + } + + export enum PopUpType { + HINTS = 0, + WARNINGS = 1 + } + + export enum InputError { + INVALID_ERROR = 0, + LENGTH_ERROR = 1, + NONE = 2 + } + + export enum Flag { + DOWN_FLAG = 0, + UP_FLAG = 1, + NONE = 2 + } + + export class NodeItem { + private nodeItem: { imageNode?: ImageNode, + mainTitleNode?: MainTitleNode, + imageCollapse?: ImageNode}; + private childNodeInfo: { isHasChildNode: boolean, childNum: number, allChildNum: number }; + menu: () => void; + nodeLevel: number; + parentNodeId: number; + currentNodeId: number; + children: Array; + data: { isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon?: Resource, + primaryTitle?: string, + menu?: () => void, + objectCount?: number | string } + + constructor(data: { isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon?: Resource, + primaryTitle?: string, + menu?: () => void, + objectCount?: number | string }) { + this.data = data; + this.nodeLevel = -1; + this.parentNodeId = -1; + this.nodeItem = { imageNode: null, mainTitleNode: null, imageCollapse: null }; + this.childNodeInfo = { isHasChildNode: false, childNum: 0, allChildNum: 0 }; + this.menu = data.menu; + if (data.icon) { + this.nodeItem.imageNode = new ImageNode(data.icon, data.selectedIcon, data.editIcon, + $r('sys.float.ohos_id_alpha_content_fourth'), + IMAGE_NODE_HEIGHT, + IMAGE_NODE_WIDTH); + } + if (data.primaryTitle) { + this.nodeItem.mainTitleNode = new MainTitleNode(data.primaryTitle); + } + this.children = []; + } + + addImageCollapse(isHasChildNode: boolean) { + if (isHasChildNode) { + this.nodeItem.imageCollapse = new ImageNode($r('sys.media.ohos_ic_public_arrow_right'), null, null, + $r('sys.float.ohos_id_alpha_content_tertiary'), + IMAGE_NODE_HEIGHT, + IMAGE_NODE_WIDTH); + this.nodeItem.imageCollapse.itemRightMargin = ($r('sys.float.ohos_id_text_paragraph_margin_xs')); + } else { + this.nodeItem.imageCollapse = null; + } + } + + getNodeItem() { + return this.nodeItem; + } + + getChildNodeInfo() { + return this.childNodeInfo; + } + + getMenu(): () => void { + return this.menu; + } + + getCurrentNodeId() { + return this.currentNodeId; + } + + getIsFolder() { + return this.data.isFolder; + } + } + + class NodeBaseInfo { + public rightMargin: Resource | number; + private width: number; + private height: number; + constructor() { + } + + set itemWidth(width: number) { + this.width = width; + } + + get itemWidth(): number { + return this.width; + } + + set itemHeight(height: number) { + this.height = height; + } + + get itemHeight(): number { + return this.height; + } + + set itemRightMargin(rightMargin: Resource | number) { + this.rightMargin = rightMargin; + } + + get itemRightMargin() { + return this.rightMargin; + } + } + + export enum NodeStatus { + Expand = 0, + Collapse + } + + export enum InteractionStatus { + Normal = 0, + Selected, + Edit, + FinishEdit, + DragInsert, + FinishDragInsert + } + + export class ImageNode extends NodeBaseInfo { + private imageSource: Resource; + private imageNormalSource: Resource; + private imageSelectedSource: Resource; + private imageEditSource: Resource; + private imageOpacity: Resource; + private currentInteractionStatus: InteractionStatus; + private imageCollapseSource: Resource; + private imageCollapseDownSource: Resource; + private isImageCollapse: boolean; + private imageCollapseRightSource: Resource; + constructor(imageSource: Resource, itemSelectedIcon: Resource, itemEditIcon: Resource, + imageOpacity: Resource, itemWidth: number, itemHeight: number) { + super(); + this.rightMargin = $r('sys.float.ohos_id_elements_margin_horizontal_m'); + this.imageSource = imageSource; + this.imageNormalSource = imageSource; + if (itemSelectedIcon != null) { + this.imageSelectedSource = itemSelectedIcon; + } else { + this.imageSelectedSource = this.imageNormalSource; + } + if (itemEditIcon != null) { + this.imageEditSource = itemEditIcon; + } else { + this.imageEditSource = this.imageNormalSource; + } + this.imageOpacity = imageOpacity; + this.itemWidth = itemWidth; + this.itemHeight = itemHeight; + this.imageCollapseSource = imageSource; + this.imageCollapseDownSource = $r('sys.media.ohos_ic_public_arrow_down'); + this.imageCollapseRightSource = $r('sys.media.ohos_ic_public_arrow_right'); + this.isImageCollapse = true; + } + + get source() { + return this.imageSource; + } + + get normalSource() { + return this.imageNormalSource; + } + + get selectedSource() { + return this.imageSelectedSource; + } + + get editSource() { + return this.imageEditSource; + } + + get opacity() { + return this.imageOpacity; + } + + get noOpacity() { + return 1; + } + + get collapseSource() { + return this.imageCollapseSource; + } + + get isCollapse() { + return this.isImageCollapse; + } + + changeImageCollapseSource(nodeStatus: NodeStatus) { + if (nodeStatus == NodeStatus.Expand) { + this.imageCollapseSource = this.imageCollapseDownSource; + } else if (nodeStatus == NodeStatus.Collapse) { + this.imageCollapseSource = this.imageCollapseRightSource; + } + } + + setImageCollapseSource(interactionStatus: InteractionStatus, nodeStatus: NodeStatus) { + if (interactionStatus === InteractionStatus.Edit || interactionStatus === InteractionStatus.DragInsert) { + this.imageCollapseDownSource = $r('sys.media.ohos_ic_public_arrow_down'); + this.imageCollapseRightSource = $r('sys.media.ohos_ic_public_arrow_right'); + this.isImageCollapse = false; + } else if (interactionStatus === InteractionStatus.FinishEdit || + interactionStatus === InteractionStatus.FinishDragInsert) { + this.imageCollapseDownSource = $r('sys.media.ohos_ic_public_arrow_down'); + this.imageCollapseRightSource = $r('sys.media.ohos_ic_public_arrow_right'); + this.isImageCollapse = true; + } + this.imageCollapseSource = (nodeStatus == NodeStatus.Collapse) ? + this.imageCollapseRightSource : this.imageCollapseDownSource; + } + + setImageSource(interactionStatus: InteractionStatus) { + switch (interactionStatus) { + case InteractionStatus.Normal: + this.imageSource = this.imageNormalSource; + this.currentInteractionStatus = interactionStatus; + break; + case InteractionStatus.Selected: + if (this.currentInteractionStatus !== InteractionStatus.Edit) { + this.imageSource = this.imageSelectedSource; + this.currentInteractionStatus = interactionStatus; + } + break; + case InteractionStatus.Edit: + this.imageSource = this.imageEditSource; + this.currentInteractionStatus = interactionStatus; + break; + case InteractionStatus.FinishEdit: + this.imageSource = this.imageSelectedSource; + this.currentInteractionStatus = interactionStatus; + break; + case InteractionStatus.DragInsert: + this.imageSource = this.imageEditSource; + this.currentInteractionStatus = interactionStatus; + break; + case InteractionStatus.FinishDragInsert: + this.imageSource = this.imageNormalSource; + this.currentInteractionStatus = interactionStatus; + break; + default: + break; + } + } + } + + export class MainTitleNode extends NodeBaseInfo { + private mainTitleName: string; + private mainTitleSetting: { fontColor: Resource, fontSize: Resource, fontWeight: FontWeight } + private showPopUpTimeout: number; + constructor(mainTitleName: string) { + super(); + this.mainTitleName = mainTitleName; + this.itemWidth = ITEM_WIDTH; + this.itemHeight = ITEM_HEIGHT; + this.rightMargin = $r('sys.float.ohos_id_text_paragraph_margin_xs'); + this.mainTitleSetting = { fontColor: $r('sys.color.ohos_id_color_primary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Normal }; + this.showPopUpTimeout = 0; + } + setMainTitleSelected(isSelected: boolean): void { + if (isSelected) { + this.mainTitleSetting = { fontColor: $r('sys.color.ohos_id_color_text_primary_activated'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Regular }; + } else { + this.mainTitleSetting = { fontColor: $r('sys.color.ohos_id_color_primary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Normal }; + } + } + set title(text: string) { + this.mainTitleName = text; + } + get title(): string { + return this.mainTitleName; + } + + set popUpTimeout(showPopUpTimeout: number) { + this.showPopUpTimeout = showPopUpTimeout; + } + + get popUpTimeout() { + return this.showPopUpTimeout; + } + + get color(): Resource { + return this.mainTitleSetting.fontColor; + } + + + get size(): Resource { + return this.mainTitleSetting.fontSize; + } + + get weight(): FontWeight { + return this.mainTitleSetting.fontWeight; + } + + setMainTitleHighLight(isHighLight: boolean): void { + if (isHighLight) { + this.mainTitleSetting = { fontColor: $r('sys.color.ohos_id_color_primary_contrary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Regular }; + } else { + this.mainTitleSetting = { fontColor: $r('sys.color.ohos_id_color_primary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Normal }; + } + } + + } + + export class InputText extends NodeBaseInfo { + private inputTextSetting: { fontColor: Resource, fontSize: Resource, fontWeight: FontWeight } + private status: { normal: Resource, hover: Resource, press: Resource }; + private statusColor: Resource = $r('sys.color.ohos_id_color_background'); + private editItemColor: Resource = $r('sys.color.ohos_id_color_emphasize'); + private radius: Resource = $r('sys.float.ohos_id_corner_radius_default_xs') + constructor() { + super(); + this.itemWidth = ITEM_WIDTH; + this.itemHeight = ITEM_HEIGHT_INPUT; + this.rightMargin = $r('sys.float.ohos_id_text_paragraph_margin_xs'); + this.inputTextSetting = { + fontColor: $r('sys.color.ohos_id_color_text_primary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Normal }; + } + + get color(): Resource { + return this.inputTextSetting.fontColor; + } + + get size(): Resource { + return this.inputTextSetting.fontSize; + } + + get weight(): FontWeight { + return this.inputTextSetting.fontWeight; + } + + get borderRadius(): Resource { + return this.radius; + } + + get backgroundColor() { + return this.statusColor; + } + + get editColor() { + return this.editItemColor; + } + + get textInputStatusColor() { + return this.status; + } + } + + export class NodeInfo { + private childNodeInfo: { isHasChildNode: boolean, childNum: number, allChildNum: number }; + private parentNodeId: number; + private currentNodeId: number; + private nodeHeight: Resource | number; + private nodeLevel: number; + private nodeItem: { imageNode?: ImageNode, + inputText: InputText, + mainTitleNode?: MainTitleNode, + imageCollapse?: ImageNode }; + private nodeLeftPadding: number; + private nodeColor: Resource | string; + private nodeIsShow: boolean; + private status: { normal: Resource, hover: Resource, press: Resource, selected: string, highLight: Resource }; + private nodeBorder: { borderWidth: Resource | number, borderColor: Resource, borderRadius: Resource }; + private popUpInfo: { popUpIsShow: boolean, + popUpEnableArrow: boolean, + popUpColor: Resource, + popUpText: string | Resource, + popUpTextColor: Resource}; + private listItemHeight: number; + private menu: () => void; + private isShowTitle: boolean; + private isShowInputText: boolean; + private isSelected: boolean; + readonly borderWidth: {has: Resource | number, none: Resource | number } = + {has: BORDER_WIDTH_HAS/* 2vp */, none: BORDER_WIDTH_NONE/* 0vp */} + + /* parameter of the drag event.*/ + private nodeParam: { + isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon?: Resource, + primaryTitle?: string, + menu?: () => void, + secondaryTitle?: number | string + }; + private node: NodeItem; + private canShowFlagLine: boolean = false; + private isOverBorder: boolean = false; + private canShowBottomFlagLine: boolean = false; + private isHighLight: boolean = false; + private flagLineLeftMargin: number; + private isModify: boolean = false; + + constructor(node: NodeItem) { + this.childNodeInfo = node.getChildNodeInfo(); + this.nodeItem = { imageNode: null, inputText: null, mainTitleNode: null, imageCollapse: null }; + this.popUpInfo = { popUpIsShow: false, + popUpEnableArrow: false, + popUpColor: null, + popUpText: '', + popUpTextColor: null }; + this.nodeItem.imageNode = node.getNodeItem().imageNode; + this.nodeItem.inputText = new InputText(); + this.nodeItem.mainTitleNode = node.getNodeItem().mainTitleNode; + this.nodeItem.imageCollapse = node.getNodeItem().imageCollapse; + this.menu = node.menu; + this.parentNodeId = node.parentNodeId; + this.currentNodeId = node.currentNodeId; + this.nodeHeight = NODE_HEIGHT; + this.nodeLevel = node.nodeLevel; + this.nodeLeftPadding = node.nodeLevel * 12 + 8; // calculate left padding + this.nodeColor = $r('sys.color.ohos_id_color_background'); + this.nodeIsShow = (this.nodeLevel > 0) ? false : true; + this.listItemHeight = (this.nodeLevel > 0) ? LIST_ITEM_HEIGHT_NONE : LIST_ITEM_HEIGHT; + this.isShowTitle = true; + this.isShowInputText = false; + this.isSelected = false; + this.status = { normal: $r('sys.color.ohos_id_color_background_transparent'), + hover: $r('sys.color.ohos_id_color_hover'), + press: $r('sys.color.ohos_id_color_click_effect'), + selected: COLOR_SELECT, + highLight: $r('sys.color.ohos_id_color_activated') + }; + this.nodeBorder = { borderWidth: BORDER_WIDTH_NONE, + borderColor: $r('sys.color.ohos_id_color_focused_outline'), + borderRadius: $r('sys.float.ohos_id_corner_radius_clicked') + }; + this.flagLineLeftMargin = node.nodeLevel * 12 + 8; + this.node = node; + this.nodeParam = node.data; + } + + getPopUpInfo() { + return this.popUpInfo; + } + + setPopUpIsShow(isShow: boolean) { + this.popUpInfo.popUpIsShow = isShow; + } + + setPopUpEnableArrow(popUpEnableArrow: boolean) { + this.popUpInfo.popUpEnableArrow = popUpEnableArrow; + } + + setPopUpColor(color: Resource) { + this.popUpInfo.popUpColor = color; + } + + setPopUpText(text: string | Resource) { + this.popUpInfo.popUpText = text; + } + + setPopUpTextColor(popUpTextColor: Resource) { + this.popUpInfo.popUpTextColor = popUpTextColor; + } + + getIsShowTitle() { + return this.isShowTitle; + } + + getIsShowInputText() { + return this.isShowInputText; + } + + setTitleAndInputTextStatus(isModify: boolean) { + if (isModify) { + this.isShowTitle = false; + this.isShowInputText = true; + } else { + this.isShowTitle = true; + this.isShowInputText = false; + } + } + + handleImageCollapseAfterAddNode(isAddImageCollapse: boolean) { + // listTree this node already has ImageCollapse. + if (isAddImageCollapse) { + this.nodeItem.imageCollapse = new ImageNode($r('sys.media.ohos_ic_public_arrow_down'), null, null, + $r('sys.float.ohos_id_alpha_content_tertiary'), + IMAGE_NODE_HEIGHT, + IMAGE_NODE_WIDTH); + this.nodeItem.imageCollapse.itemRightMargin = ($r('sys.float.ohos_id_text_paragraph_margin_xs')); + } else { + this.nodeItem.imageCollapse = null; + } + } + + setNodeColor(nodeColor: Resource | string): void { + this.nodeColor = nodeColor; + } + + getNodeColor(): Resource | string { + return this.nodeColor; + } + + setListItemHeight(listItemHeight: number): void { + this.listItemHeight = listItemHeight; + } + + getListItemHeight(): number { + return this.listItemHeight; + } + + getNodeCurrentNodeId(): number { + return this.currentNodeId; + } + + getNodeParentNodeId(): number { + return this.parentNodeId; + } + + getNodeLeftPadding(): number { + return this.nodeLeftPadding; + } + + getNodeHeight(): Resource | number { + return this.nodeHeight; + } + + setNodeIsShow(nodeIsShow: boolean): void { + this.nodeIsShow = nodeIsShow; + } + + getNodeIsShow(): boolean { + return this.nodeIsShow; + } + + getNodeItem() { + return this.nodeItem; + } + + getNodeStatus() { + return this.status; + } + + getNodeBorder() { + return this.nodeBorder; + } + + setNodeBorder(isClearFocusStatus: boolean): void { + this.nodeBorder.borderWidth = isClearFocusStatus ? this.borderWidth.has : this.borderWidth.none; + } + + getChildNodeInfo() { + return this.childNodeInfo; + } + + getCurrentNodeId() { + return this.currentNodeId; + } + + getMenu() { + return this.menu; + } + + setIsSelected(isSelected: boolean) { + this.isSelected = isSelected; + } + + getIsSelected() { + return this.isSelected; + } + + /* To gain the information while to alter node. */ + getNodeInfoData() { + return this.nodeParam; + } + + /* To gain the tree Node(NodeItem) while to alter node. */ + public getNodeInfoNode() { + return this.node; + } + + public getIsFolder() { + return this.nodeParam.isFolder; + } + + public setCanShowFlagLine(canShowFlagLine: boolean) { + this.canShowFlagLine = canShowFlagLine; + } + + public getCanShowFlagLine(): boolean { + return this.canShowFlagLine; + } + + public setFlagLineLeftMargin(currentNodeLevel: number) { + this.flagLineLeftMargin = currentNodeLevel * 12 + 8; // calculate + } + + public getFlagLineLeftMargin(): number { + return this.flagLineLeftMargin; + } + + public getNodeLevel(): number { + return this.nodeLevel; + } + + public setIsOverBorder(isOverBorder: boolean) { + this.isOverBorder = isOverBorder; + } + + public getIsOverBorder() { + return this.isOverBorder; + } + + public setCanShowBottomFlagLine(canShowBottomFlagLine: boolean) { + this.canShowBottomFlagLine = canShowBottomFlagLine; + } + + public getCanShowBottomFlagLine() { + return this.canShowBottomFlagLine; + } + + public setIsHighLight(isHighLight: boolean) { + this.isHighLight = isHighLight; + } + + public getIsHighLight(): boolean { + return this.isHighLight; + } + + public setIsModify(isModify: boolean) { + this.isModify = isModify; + } + + public getIsModify(): boolean { + return this.isModify; + } + + } + + + export class ListNodeUtils { + private _root: NodeItem; + public addNewNodeId: number; + private readonly MaxNodeLevel = 50; + private readonly MAX_CN_LENGTH: number = 254; + private readonly MAX_EN_LENGTH: number = 255; + private readonly INITIAL_INVALID_VALUE = -1; + constructor() { + this._root = new NodeItem({}); + this._root.nodeLevel = -1; + this._root.parentNodeId = -1; + this._root.currentNodeId = -1; + } + + getNewNodeId() { + return this.addNewNodeId; + } + + traverseNodeDF(callback, root: NodeItem = this._root) { + let stack = [], found = false; + stack.unshift(root); + let currentNode = stack.shift(); + while(!found && currentNode) { + found = callback(currentNode) === true; + if (!found) { + stack.unshift(...currentNode.children); + currentNode = stack.shift(); + } + } + } + + traverseNodeBF(callback) { + let queue = []; + let found: boolean = false; + queue.push(this._root); + let currentNode: NodeItem = queue.shift(); + while(!found && currentNode) { + try { + found = callback(currentNode); + } catch(err) { + var e = err.name + " == " + err.message; + } + if (!found) { + queue.push(...currentNode.children) + currentNode = queue.shift(); + } + } + } + + private contains(callback, traversal) { + traversal.call(this, callback, true); + } + + private updateParentChildNum(parentNode: NodeItem, isAdd: boolean, count: number) { + let parentNodeId: number = parentNode.parentNodeId; + while(parentNodeId >= 0) { + this.traverseNodeDF((node: NodeItem): boolean => { + if (node.currentNodeId == parentNodeId) { + node.getChildNodeInfo().allChildNum = + isAdd ? node.getChildNodeInfo().allChildNum + count : node.getChildNodeInfo().allChildNum - count; + parentNodeId = node.parentNodeId; + return false; + } + return false; + }) + } + } + + findParentNodeId(currentNodeId: number): number { + let current = null, + callback = function(node): boolean { + if (node.currentNodeId == currentNodeId ) { + current = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + return current.parentNodeId; + } + + addNode(parentNodeId: number, + currentNodeId: number, + data: { isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon?: Resource, + primaryTitle?: string, + secondaryTitle?: number | string, + menu?: () => void, + }): ListNodeUtils { + if (this._root === null) { + this._root = new NodeItem({}); + this._root.nodeLevel = -1; + this._root.parentNodeId = -1; + this._root.currentNodeId = -1; + } + + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == parentNodeId ) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + if (parent) { + let currentNode: NodeItem = new NodeItem(data); + if (parent.nodeLevel > this.MaxNodeLevel) { + throw new Error('ListNodeUtils[addNode]: The level of the tree view cannot exceed 50.'); + } + currentNode.nodeLevel = parent.nodeLevel + 1; // nodeLevel + currentNode.parentNodeId = parentNodeId; + currentNode.currentNodeId = currentNodeId; + parent.children.push(currentNode); + parent.getChildNodeInfo().isHasChildNode = true; + parent.getChildNodeInfo().childNum = parent.children.length; + parent.getChildNodeInfo().allChildNum += 1; // childNum + parent.addImageCollapse(parent.getChildNodeInfo().isHasChildNode); + this.updateParentChildNum(parent, true, 1); + return this; + } else { + throw new Error('ListNodeUtils[addNode]: Parent node not found.'); + } + } + + findNodeIndex(children, currentNodeId: number) { + let index = this.INITIAL_INVALID_VALUE; + for (let i = 0, len = children.length; i < len; i++) { + if (children[i].currentNodeId === currentNodeId) { + index = i; + break; + } + } + return index; + } + + private freeNodeMemory(rootNode: NodeItem, removeNodeIdList: number[]) { + let deleteNode: NodeItem[] = []; + let callback = function(node): boolean { + deleteNode.push(node); + return false; + }; + this.traverseNodeDF(callback, rootNode); + deleteNode.forEach((value)=>{ + removeNodeIdList.push(value.currentNodeId); + value = null; + }) + } + + removeNode(currentNodeId: number, parentNodeId: number, traversal: any) { + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == parentNodeId) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, traversal); + + if (parent) { + let removeNodeIdList: number[] = []; + let index = this.findNodeIndex(parent.children, currentNodeId); + if (index < 0) { + throw new Error('Node does not exist.'); + } else { + var deleteNodeAllChildNum = parent.children[index].getChildNodeInfo().allChildNum + 1; + this.freeNodeMemory(parent.children[index], removeNodeIdList); + let node = parent.children.splice(index, 1); + node = null; + if (parent.children.length == 0) { + parent.addImageCollapse(false); + } + } + parent.getChildNodeInfo().childNum = parent.children.length; + parent.getChildNodeInfo().allChildNum -= (deleteNodeAllChildNum); + this.updateParentChildNum(parent, false, deleteNodeAllChildNum); + return removeNodeIdList; + } else { + throw new Error('Parent does not exist.'); + } + } + + getNewNodeInfo(nodeId: number) { + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == nodeId) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + let newNodeInfo: { isFolder: boolean, icon: Resource, selectedIcon: Resource, editIcon: Resource, menu: () => any, secondaryTitle: number | string } = + { isFolder: true, icon: null, selectedIcon: null, editIcon: null, menu: null, secondaryTitle: '' }; + if (parent) { + if (parent.children.length === 0) { + if (parent.getNodeItem().imageNode != null) { + newNodeInfo.icon = parent.getNodeItem().imageNode.normalSource; + newNodeInfo.selectedIcon = parent.getNodeItem().imageNode.selectedSource; + newNodeInfo.editIcon = parent.getNodeItem().imageNode.editSource; + newNodeInfo.menu = parent.getMenu(); + } else { + newNodeInfo.icon = null; + newNodeInfo.selectedIcon = null; + newNodeInfo.editIcon = null; + newNodeInfo.menu = parent.getMenu(); + } + } else if (parent.children.length > 0) { + if (parent.getNodeItem().imageNode != null) { + newNodeInfo.icon = (parent.children[0].getNodeItem().imageNode != null) ? + parent.children[0].getNodeItem().imageNode.normalSource : null; + newNodeInfo.selectedIcon = (parent.children[0].getNodeItem().imageNode != null) ? + parent.children[0].getNodeItem().imageNode.selectedSource : null; + newNodeInfo.editIcon = (parent.children[0].getNodeItem().imageNode != null) ? + parent.children[0].getNodeItem().imageNode.editSource : null; + newNodeInfo.menu = parent.children[0].getMenu(); + } else { + newNodeInfo.icon = null; + newNodeInfo.selectedIcon = null; + newNodeInfo.editIcon = null; + newNodeInfo.menu = parent.children[0].getMenu(); + } + } + } + return newNodeInfo; + } + + getClickChildId(nodeId: number) { + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == nodeId) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + if (parent) { + if (parent.children.length === 0) { + return []; + } else if (parent.children.length > 0) { + var nodeInfo: { itemId: number, itemIcon: Resource, itemTitle: string } = + { itemId: null, itemIcon: null, itemTitle: null } + var childrenNodeInfo: Array = new Array(parent.children.length); + for (let i = 0; i < childrenNodeInfo.length; i++) { + childrenNodeInfo[i] = 0; + } + for (let i = 0; i < parent.children.length && i < childrenNodeInfo.length; i++) { + childrenNodeInfo[i] = parent.children[i].currentNodeId; + } + return childrenNodeInfo; + } + } + return []; + } + + getClickNodeChildrenInfo(nodeId: number) { + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == nodeId) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + if (parent) { + if (parent.children.length === 0) { + return []; + } else if (parent.children.length > 0) { + var nodeInfo: { itemId: number, itemIcon: Resource, itemTitle: string } = + { itemId: null, itemIcon: null, itemTitle: null } + var childrenNodeInfo: Array<{ itemId: number, itemIcon: Resource, itemTitle: string, isFolder: boolean }> = new Array(parent.children.length); + for (let i = 0; i < childrenNodeInfo.length; i++) { + childrenNodeInfo[i] = { itemId: null, itemIcon: null, itemTitle: null, isFolder: null }; + } + for (let i = 0; i < parent.children.length && i < childrenNodeInfo.length; i++) { + childrenNodeInfo[i].itemId = parent.children[i].currentNodeId; + if (parent.children[i].getNodeItem().imageNode) { + childrenNodeInfo[i].itemIcon = parent.children[i].getNodeItem().imageNode.source; + } + if (parent.children[i].getNodeItem().mainTitleNode) { + childrenNodeInfo[i].itemTitle = parent.children[i].getNodeItem().mainTitleNode.title; + } + childrenNodeInfo[i].isFolder = parent.children[i].getIsFolder(); + } + return childrenNodeInfo; + } + } + return []; + } + + public checkMainTitleIsValid(title: string) : boolean { + let invalid = /[\\\/:*?"<>|]/; + let invalidLength = /^[\u4e00-\u9fa5]+$/; + if (invalid.test(title)) { + return false; + } + if ((invalidLength.test(title) && title.length > this.MAX_CN_LENGTH) || + (!invalidLength.test(title) && title.length > this.MAX_EN_LENGTH)) { + return false; + } + return true; + } + + /* + * DFS: Depth first traversal in drag event. + * @param callback + */ + dragTraverseNodeDF(callback, root: NodeItem = this._root, listNode) { + let stack = [], found = false; + stack.unshift(root); + let currentNode = stack.shift(); + while(!found && currentNode) { + found = callback(currentNode, listNode) === true; + if (!found) { + stack.unshift(...currentNode.children); + currentNode = stack.shift(); + } + } + } + + /* + * Add the first dragging node in dragging nodes + * 1.the first dragging node needs to distinguish the position to insert + */ + addDragNode(parentNodeId: number, + currentNodeId: number, + insertCurrentNodeId: number, + isAfter: boolean, + data: { isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon?: Resource, + primaryTitle?: string, + menu?: () => any, + objectCount?: number }): ListNodeUtils { + + if (this._root === null) { + this._root = new NodeItem({}); + this._root.nodeLevel = this.INITIAL_INVALID_VALUE; + this._root.parentNodeId = this.INITIAL_INVALID_VALUE; + this._root.currentNodeId = this.INITIAL_INVALID_VALUE; + } + + let parent = null, + callback = function(node): boolean { + if (node.currentNodeId == parentNodeId ) { + parent = node; + return true; + } + return false; + }; + this.contains(callback, this.traverseNodeBF); + if (parent) { + let currentNode: NodeItem = new NodeItem(data); + if (parent.nodeLevel > this.MaxNodeLevel) { + throw new Error('ListNodeUtils[addNode]: The level of the tree view cannot exceed 50.'); + } + currentNode.nodeLevel = parent.nodeLevel + 1; + currentNode.parentNodeId = parentNodeId; + currentNode.currentNodeId = currentNodeId; + let insertIndex: number = this.INITIAL_INVALID_VALUE; + if (parent.children.length) { + for (let i = 0; i < parent.children.length; i++) { + if ( parent.children[i].getCurrentNodeId() == insertCurrentNodeId) { + insertIndex = i; + break; + } + } + if (isAfter) { + parent.children.splice(insertIndex + 1, 0, currentNode); + } else { + parent.children.splice(insertIndex, 0, currentNode); + } + } else { + parent.children.push(currentNode); + } + parent.getChildNodeInfo().isHasChildNode = true; + parent.getChildNodeInfo().childNum = parent.children.length; + parent.getChildNodeInfo().allChildNum += 1; + parent.addImageCollapse(parent.getChildNodeInfo().isHasChildNode); + this.updateParentChildNum(parent, true, 1); + return this; + } else { + throw new Error('ListNodeUtils[addNode]: Parent node not found.'); + } + } + + } + + + export class ListNodeDataSource extends BasicDataSource { + readonly ROOT_NODE_ID = -1; + private listNodeUtils: ListNodeUtils = new ListNodeUtils(); + private listNode: NodeInfo[] = []; + private readonly INITIAL_INVALID_VALUE = -1; + private lastIndex: number = -1; // record the last focused node. + thisIndex: number = -1; // records clicked nodes in the current period. + private modifyNodeIndex: number = -1; // records the nodes edited in the current period. + modifyNodeId: number = -1 + private currentOperation: MenuOperation; + private expandAndCollapseInfo = new Map(); + private loadedNodeIdAndIndexMap = new Map(); // [currentNodeId, index] + private isTouchDown: boolean = false; + private appEventBus: TreeListener = TreeListenerManager.getInstance().getTreeListener(); + + /* parameter of the drag event. */ + private isInnerDrag: boolean = false; // Judge whether it is an internal drag event. + private isDrag: boolean = false; // It is used to handle events(For example, prevent press events) during global drag. + private draggingCurrentNodeId: number = this.INITIAL_INVALID_VALUE; // Record the current ID of the dragged node. + private draggingParentNodeId: number = this.INITIAL_INVALID_VALUE; // Record the parent ID of the dragged node. + private currentNodeInfo: NodeInfo = null; // To solve the problem of currentIndex missed in onDrop event. + private listItemOpacity : number = 1; // It is used to set the opacity of the node when dragged. + private lastPassIndex: number = this.INITIAL_INVALID_VALUE; // record the last passing node index in drag. + private lastPassId: number = this.INITIAL_INVALID_VALUE; // record the last passing node Id in drag. + private thisPassIndex: number = this.INITIAL_INVALID_VALUE; // record the current passing node in drag. + private lastDelayExpandIndex: number = this.INITIAL_INVALID_VALUE; // record last passing node in delay expand event. + private timeoutExpandId: number = this.INITIAL_INVALID_VALUE; + private lastTimeoutExpandId: number = this.INITIAL_INVALID_VALUE; + private clearTimeoutExpandId: number = this.INITIAL_INVALID_VALUE; + private timeoutHighLightId: number = this.INITIAL_INVALID_VALUE; + private lastTimeoutHighLightId: number = this.INITIAL_INVALID_VALUE; + private clearTimeoutHighLightId: number = this.INITIAL_INVALID_VALUE; + private lastDelayHighLightIndex: number = this.INITIAL_INVALID_VALUE; // record last passing node in HighLight event. + private lastDelayHighLightId: number = this.INITIAL_INVALID_VALUE; //record last passing node Id in HighLight event. + private nodeIdAndSubtitleMap = new Map(); // [currentNodeId, subtitle] + private flag: Flag = Flag.NONE; + private selectedParentNodeId: number = this.INITIAL_INVALID_VALUE; + private selectedParentNodeSubtitle: any = ''; + private insertNodeSubtitle: any = ''; + private currentFocusNodeId: number = this.INITIAL_INVALID_VALUE; + private lastFocusNodeId: number = this.INITIAL_INVALID_VALUE; + private addFocusNodeId: number = this.INITIAL_INVALID_VALUE; + + readonly FLAG_LINE: { flagLineHeight: string, + flagLineColor: Resource, + xOffset: string, + yTopOffset: string, + yBottomOffset: string, + yBasePlateOffset: string } = { + flagLineHeight: FLAG_LINE_HEIGHT, + flagLineColor: $r('sys.color.ohos_id_color_activated'), + xOffset: X_OFF_SET, + yTopOffset: Y_OFF_SET, + yBottomOffset: Y_BOTTOM_OFF_SET, + yBasePlateOffset: Y_BASE_PLATE_OFF_SET + } + + private readonly DRAG_POPUP: { floorConstraintSize: { minWidth: string, maxWidth: string }, + textConstraintSize: { minWidth1: string, maxWidth1: string, + minWidth2: string, maxWidth2: string }, + padding: { left: string, right: string }, + backgroundColor: ResourceColor, + height: string, + shadow: { radius: Resource, color: ResourceColor, offsetX?: number, offsetY?: number }, + borderRadius : Resource, + fontColor: Resource, + fontSize: Resource, + fontWeight: FontWeight + imageOpacity: Resource } = { + floorConstraintSize: { minWidth: FLOOR_MIN_WIDTH, maxWidth: FLOOR_MAX_WIDTH }, + textConstraintSize: { minWidth1: TEXT_MIN_WIDTH, maxWidth1: TEXT_MAX_WIDTH, minWidth2: MIN_WIDTH, maxWidth2: MAX_WIDTH }, + padding: { left: LEFT_PADDING, right: RIGHT_PADDING }, + backgroundColor: COLOR_IMAGE_EDIT, + height: GRAG_POP_UP_HEIGHT, + shadow: { radius: $r('sys.float.ohos_id_corner_radius_default_m'), color: SHADOW_COLOR, offsetX: 0, offsetY: SHADOW_OFFSETY }, + borderRadius: $r('sys.float.ohos_id_corner_radius_clicked'), + fontColor: $r('sys.color.ohos_id_color_primary'), + fontSize: $r('sys.float.ohos_id_text_size_body1'), + fontWeight: FontWeight.Regular, + imageOpacity: $r('sys.float.ohos_id_alpha_content_fourth') + } + + private readonly subTitle: { normalFontColor: Resource, + highLightFontColor: Resource, + fontSize: Resource, + fontWeight: FontWeight, + margin: { left: string, right: string } } = { + normalFontColor: $r('sys.color.ohos_id_color_secondary'), + highLightFontColor: $r('sys.color.ohos_id_color_primary_contrary'), + fontSize: $r('sys.float.ohos_id_text_size_body2'), + fontWeight: FontWeight.Regular, + margin: { left: '4vp', right: '24' } + } + + private changeNodeColor(index: number, color: Resource | string): void { + this.listNode[index].setNodeColor(color); + } + + private getNodeColor(index) { + return this.listNode[index].getNodeColor(); + } + + private handleFocusEffect(index: number, isClearFocusStatus: boolean) { + if (this.listNode[index].getNodeIsShow()) { + this.listNode[index].setNodeBorder(isClearFocusStatus); + } + } + + private setImageSource(index: number, interactionStatus: InteractionStatus) { + let nodeInfo: NodeInfo = this.listNode[index]; + nodeInfo.setIsSelected(interactionStatus === InteractionStatus.Selected || + interactionStatus === InteractionStatus.Edit || interactionStatus === InteractionStatus.FinishEdit); + if (nodeInfo.getNodeItem().mainTitleNode != null && interactionStatus != InteractionStatus.DragInsert && + interactionStatus != InteractionStatus.FinishDragInsert) { + nodeInfo.getNodeItem().mainTitleNode.setMainTitleSelected(interactionStatus === InteractionStatus.Selected || + interactionStatus === InteractionStatus.FinishEdit); + } + if (nodeInfo.getNodeItem().imageNode != null) { + nodeInfo.getNodeItem().imageNode.setImageSource(interactionStatus); + } + } + + private setImageCollapseSource(index: number, interactionStatus: InteractionStatus) { + let nodeInfo: NodeInfo = this.listNode[index]; + if (nodeInfo.getNodeItem().imageCollapse != null) { + nodeInfo.getNodeItem().imageCollapse.setImageCollapseSource(interactionStatus, + this.expandAndCollapseInfo.get(nodeInfo.getCurrentNodeId())); + } + } + + public clearLastIndexStatus() { + if (this.lastIndex == -1 || this.lastIndex >= this.listNode.length) { + return; + } + this.setImageSource(this.lastIndex, InteractionStatus.Normal); + this.changeNodeColor(this.lastIndex, this.listNode[this.lastIndex].getNodeStatus().normal); + this.handleFocusEffect(this.lastIndex, false); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.listNode[this.lastIndex].getCurrentNodeId())); + } + + private changeNodeStatus(clickIndex: number): void { + let thisIndex: number = clickIndex; + let tmp: NodeInfo[] = this.ListNode; + let nodeId = tmp[clickIndex].getCurrentNodeId(); + if (this.expandAndCollapseInfo.get(nodeId) == NodeStatus.Expand) { + this.expandAndCollapseInfo.set(nodeId, NodeStatus.Collapse); + tmp[thisIndex].getNodeItem().imageCollapse.changeImageCollapseSource(NodeStatus.Collapse); + } else if (this.expandAndCollapseInfo.get(nodeId) == NodeStatus.Collapse) { + this.expandAndCollapseInfo.set(nodeId, NodeStatus.Expand); + tmp[thisIndex].getNodeItem().imageCollapse.changeImageCollapseSource(NodeStatus.Expand); + } + } + + private handleExpandAndCollapse(clickIndex: number) { + let thisIndex: number = clickIndex; + let tmp: NodeInfo[] = this.ListNode; + let nodeId = tmp[thisIndex].getCurrentNodeId(); + if (!this.expandAndCollapseInfo.has(nodeId)) { + return; + } + + let rootNodeStatus: NodeStatus = this.expandAndCollapseInfo.get(nodeId); + if (tmp[thisIndex].getChildNodeInfo().isHasChildNode && rootNodeStatus == NodeStatus.Collapse) { + for(var i = 0; i < tmp[thisIndex].getChildNodeInfo().allChildNum; i++) { + tmp[thisIndex + 1 + i].setNodeIsShow(false); + tmp[thisIndex + 1 + i].setListItemHeight(LIST_ITEM_HEIGHT_NONE); + } + this.notifyDataReload(); + return; + } + + let childNum: number[] = new Array(tmp[thisIndex].getChildNodeInfo().childNum); + childNum[0] = thisIndex + 1; + let index = 1; + while(index < tmp[thisIndex].getChildNodeInfo().childNum) { + childNum[index] = childNum[index -1] + tmp[childNum[index - 1]].getChildNodeInfo().allChildNum + 1; + index++; + } + if (rootNodeStatus == NodeStatus.Expand) { + for(var i = 0; i < childNum.length; i++) { + tmp[childNum[i]].setNodeIsShow(true); + tmp[childNum[i]].setListItemHeight(LIST_ITEM_HEIGHT); + let nodeId = tmp[childNum[i]].getCurrentNodeId(); + if(this.expandAndCollapseInfo.get(nodeId) == NodeStatus.Expand) { + this.handleExpandAndCollapse(childNum[i]); + } + } + } + childNum = null; + this.notifyDataReload(); + } + + public init(listNodeUtils: ListNodeUtils) { + let index = 0; + this.listNode = []; + this.listNodeUtils = listNodeUtils; + this.loadedNodeIdAndIndexMap.clear(); + this.listNodeUtils.traverseNodeDF((node: NodeItem): boolean => { + if (node.currentNodeId >= 0) { + var nodeInfo: NodeInfo = new NodeInfo(node); + this.listNode.push(nodeInfo); + if (nodeInfo.getChildNodeInfo().isHasChildNode) { + this.expandAndCollapseInfo.set(nodeInfo.getCurrentNodeId(), NodeStatus.Collapse); + } + if (nodeInfo.getNodeIsShow()) { + this.loadedNodeIdAndIndexMap.set(nodeInfo.getCurrentNodeId(), index++); + } + if (nodeInfo.getIsFolder()) { + this.nodeIdAndSubtitleMap.set(nodeInfo.getCurrentNodeId(), + nodeInfo.getNodeInfoData().secondaryTitle || nodeInfo.getNodeInfoData().secondaryTitle == 0 ? + nodeInfo.getNodeInfoData().secondaryTitle : ''); + } + } + return false; + }); + } + + private refreshRemoveNodeData(removeNodeIdList: number[], parentNodeInfo: NodeInfo) { + let deleteIndexList: number[] = []; + for (let i = 0; i < removeNodeIdList.length; i++) { + for (let j = 0; j < this.listNode.length; j++) { + if (this.listNode[j].getNodeCurrentNodeId() == removeNodeIdList[i]) { + let currentNodeId = this.listNode[j].getNodeCurrentNodeId(); + if (this.loadedNodeIdAndIndexMap.has(currentNodeId)) { + // this.listNode index to lazyForEach index. + deleteIndexList.push(this.loadedNodeIdAndIndexMap.get(currentNodeId)); + } + let deleteNode = this.listNode.splice(j, 1); + deleteNode = null; // free memory + if (this.expandAndCollapseInfo.has(removeNodeIdList[i])) { + this.expandAndCollapseInfo.delete(removeNodeIdList[i]); // delete deleteNode expandAndCollapseInfo. + } + break; + } + } + } + deleteIndexList.forEach((value)=>{ + this.notifyDataDelete(value); // notifyDataDelete do not update data. + this.notifyDataChange(value); // call notifyDataChange to update data. + }) + let index: number = 0; + for (let i = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getNodeCurrentNodeId() == parentNodeInfo.getNodeCurrentNodeId()) { + if (parentNodeInfo.getNodeItem().imageCollapse == null) { + this.listNode[i].handleImageCollapseAfterAddNode(false); + // delete deleteNode parentNode expandAndCollapseInfo. + this.expandAndCollapseInfo.delete(parentNodeInfo.getNodeCurrentNodeId()); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.listNode[i].getNodeCurrentNodeId())); + } + break; + } + } + let callbackParam: CallbackParam = {currentNodeId: parentNodeInfo.getNodeCurrentNodeId(), parentNodeId: parentNodeInfo.getNodeParentNodeId()}; + this.appEventBus.emit(TreeListenType.NODE_DELETE, [callbackParam]); + } + + private refreshAddNodeData(addNodeIdList: number[]) { + var addNodeInfo: NodeInfo; + this.listNodeUtils.traverseNodeDF((node: NodeItem): boolean => { + if (node.currentNodeId === addNodeIdList[0]) { + addNodeInfo = new NodeInfo(node); + return true; + } + return false; + }); + addNodeInfo.setIsModify(true); + + let index: number = 0; + for (let i = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getNodeCurrentNodeId() == addNodeInfo.getNodeParentNodeId()) { + index = i; + if (this.listNode[i].getNodeItem().imageCollapse == null) { + this.listNode[i].handleImageCollapseAfterAddNode(true); + this.notifyDataChange(index); + } else if (this.expandAndCollapseInfo.get(this.listNode[i].getNodeCurrentNodeId()) == NodeStatus.Collapse) { + this.changeNodeStatus(index); + } + this.listNode.splice(i + 1, 0, addNodeInfo); + this.listNode[i + 1].setTitleAndInputTextStatus(true); // false->true: realize inner Interaction. + this.listNode[i + 1].setNodeIsShow(true); + this.listNode[i + 1].setListItemHeight(LIST_ITEM_HEIGHT); + this.setImageSource(i + 1, InteractionStatus.Edit); // Normal->Edit : realize inner Interaction. + this.currentOperation = MenuOperation.ADD_NODE; + this.notifyDataAdd(i + 1); + this.notificationNodeInfo(i+1, this.currentOperation); + break; + } + } + this.modifyNodeIndex = index + 1; + this.expandAndCollapseInfo.set(addNodeInfo.getNodeParentNodeId(), NodeStatus.Expand); + this.handleExpandAndCollapse(index); + } + + public refreshData(listNodeUtils: ListNodeUtils, operation: MenuOperation, + parentNodeId: number, changeNodeIdList: number[]) { + let parentNodeInfo: NodeInfo; + this.listNodeUtils = listNodeUtils; + this.listNodeUtils.traverseNodeDF((node: NodeItem): boolean => { + if (node.currentNodeId == parentNodeId) { + parentNodeInfo = new NodeInfo(node); + return true; + } + return false; + }); + + if (operation === MenuOperation.REMOVE_NODE) { + this.nodeIdAndSubtitleMap.set(parentNodeId, this.selectedParentNodeSubtitle); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(parentNodeId)); + this.refreshRemoveNodeData(changeNodeIdList, parentNodeInfo); + } + + if (operation === MenuOperation.ADD_NODE) { + this.addFocusNodeId = changeNodeIdList[0]; + this.nodeIdAndSubtitleMap.set(this.getClickNodeId(), this.selectedParentNodeSubtitle); + this.nodeIdAndSubtitleMap.set(changeNodeIdList[0], this.insertNodeSubtitle); + this.refreshAddNodeData(changeNodeIdList); + } + } + + public setClickIndex(index: number) { + this.thisIndex = index; + } + + public getClickNodeId(): number { + if (this.thisIndex < 0 || this.thisIndex >= this.ListNode.length) { + return -1; + } + return this.ListNode[this.thisIndex].getCurrentNodeId(); + } + + public expandAndCollapseNode(clickIndex: number) { + this.changeNodeStatus(clickIndex); + this.handleExpandAndCollapse(clickIndex) + } + + public getIsTouchDown(): boolean { + return this.isTouchDown; + } + + public getLastIndex(): number { + return this.lastIndex; + } + + public handleEvent(event: Event, index: number) { + /* Return while the event is dragging event. */ + if (this.isDrag) { + return; + } + + if (event === Event.TOUCH_DOWN || event === Event.TOUCH_UP || event === Event.MOUSE_BUTTON_RIGHT) { + if (index != this.lastIndex) { + this.clearLastIndexStatus(); + } + } + let lazyForEachIndex = this.loadedNodeIdAndIndexMap.get(this.listNode[index].getCurrentNodeId()); + switch(event) { + case Event.TOUCH_DOWN: + this.isTouchDown = true; + this.changeNodeColor(index, this.listNode[index].getNodeStatus().press); + break; + case Event.TOUCH_UP: { + if (this.isInnerDrag) { + this.isInnerDrag = false; + } + this.isTouchDown = false; + let nodeInfo: NodeInfo = this.listNode[index]; + this.setImageSource(index, InteractionStatus.Selected); + this.lastIndex = index; + this.changeNodeColor(index, nodeInfo.getNodeStatus().selected); + this.notifyDataChange(lazyForEachIndex); + break; + } + case Event.HOVER: + if (this.getNodeColor(index) != this.listNode[index].getNodeStatus().selected) { + this.changeNodeColor(index, this.listNode[index].getNodeStatus().hover); + this.notifyDataChange(lazyForEachIndex); + } + break; + case Event.HOVER_OVER: + if (this.getNodeColor(index) != this.listNode[index].getNodeStatus().selected) { + this.changeNodeColor(index, this.listNode[index].getNodeStatus().normal); + this.notifyDataChange(lazyForEachIndex); + } + break; + case Event.FOCUS: + this.handleFocusEffect(index, true); + this.notifyDataChange(lazyForEachIndex); + break; + case Event.BLUR: + this.handleFocusEffect(index, false); + this.notifyDataChange(lazyForEachIndex); + break; + case Event.MOUSE_BUTTON_RIGHT: + this.lastIndex = index; + this.finishEditing(); + break; + case Event.DRAG: + this.isTouchDown = false; + let nodeInfo: NodeInfo = this.listNode[index]; + this.setImageSource(index, InteractionStatus.Selected); + this.lastIndex = index; + this.changeNodeColor(index, nodeInfo.getNodeStatus().selected); + this.notifyDataChange(lazyForEachIndex); + break; + default: + break; + } + } + + private notificationNodeInfo(addNodeId: number, operation: MenuOperation) { + if (operation === MenuOperation.MODIFY_NODE) { + let modifyNodeInfo: NodeInfo = this.listNode[this.modifyNodeIndex]; + let backParamModify: CallbackParam = { currentNodeId: modifyNodeInfo.getNodeCurrentNodeId(), + parentNodeId: modifyNodeInfo.getNodeParentNodeId() } + this.appEventBus.emit(TreeListenType.NODE_MODIFY, + [backParamModify]); + } else if (operation === MenuOperation.ADD_NODE) { + let addNodeInfo: NodeInfo = this.listNode[addNodeId]; + let icon: Resource = (addNodeInfo.getNodeItem().imageNode != null) ? + addNodeInfo.getNodeItem().imageNode.source : null; + let selectedIcon: Resource = (addNodeInfo.getNodeItem().imageNode != null) ? + addNodeInfo.getNodeItem().imageNode.selectedSource : null; + let editIcon: Resource = (addNodeInfo.getNodeItem().imageNode != null) ? + addNodeInfo.getNodeItem().imageNode.editSource : null; + let callbackParam: CallbackParam = { currentNodeId: addNodeInfo.getNodeCurrentNodeId(), + parentNodeId: addNodeInfo.getNodeParentNodeId() } + this.appEventBus.emit(TreeListenType.NODE_ADD, + [callbackParam]); + } + } + + public finishEditing() { + if (this.modifyNodeIndex!= -1) { + this.setImageSource(this.modifyNodeIndex, InteractionStatus.FinishEdit); + this.setImageCollapseSource(this.modifyNodeIndex, InteractionStatus.FinishEdit); + this.listNode[this.modifyNodeIndex].setIsModify(false); + this.listNode[this.modifyNodeIndex].setTitleAndInputTextStatus(false); + this.notificationNodeInfo(this.modifyNodeIndex, this.currentOperation); + this.notifyDataChange(this.modifyNodeIndex); + } + } + + public setItemVisibilityOnEdit(nodeId: number, operation: MenuOperation) { + let index: number = -1; + if (nodeId == -1) { + return; + } + if (operation === MenuOperation.MODIFY_NODE) { + for (let i = 0; i < this.listNode.length; i++) { // nodeId to find index + if (this.listNode[i].getCurrentNodeId() == nodeId) { + index = i; + break; + } + } + let nodeInfo: NodeInfo = this.listNode[index]; + nodeInfo.setIsModify(true); + if (nodeInfo.getNodeItem().mainTitleNode === null) { + return; // no title + } + + this.currentOperation = MenuOperation.MODIFY_NODE; + nodeInfo.setTitleAndInputTextStatus(true); + this.setImageSource(index, InteractionStatus.Edit); + this.setImageCollapseSource(index, InteractionStatus.Edit); + this.modifyNodeIndex = index; + if (nodeInfo.getNodeItem().inputText) { + if (nodeInfo.getNodeItem().imageCollapse != null) { + nodeInfo.getNodeItem().inputText.rightMargin = + $r('sys.float.ohos_id_text_paragraph_margin_xs') + } else { + nodeInfo.getNodeItem().inputText.rightMargin = + $r('sys.float.ohos_id_elements_margin_horizontal_m') + } + } + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(nodeId)); + } + index = nodeId; + if (operation === MenuOperation.COMMIT_NODE) { + let nodeInfo: NodeInfo = this.listNode[index]; + nodeInfo.setTitleAndInputTextStatus(false); + nodeInfo.setIsModify(false); + this.setImageSource(index, InteractionStatus.FinishEdit); + this.setImageCollapseSource(index, InteractionStatus.FinishEdit); + this.notificationNodeInfo(this.modifyNodeIndex, this.currentOperation); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(nodeInfo.getCurrentNodeId())); + } + } + + public setPopUpInfo(popUpType: PopUpType, inputError: InputError, isShow: boolean, index: number) { + let nodeInfo: NodeInfo = this.listNode[index]; + nodeInfo.setPopUpIsShow(isShow); + // this.listNode index to lazyForEach index. + let lazyForEachIndex = this.loadedNodeIdAndIndexMap.get(nodeInfo.getCurrentNodeId()); + if (!isShow) { + this.notifyDataChange(lazyForEachIndex); + return; + } + if (popUpType === PopUpType.HINTS) { + if (nodeInfo.getNodeItem().mainTitleNode != null) { + nodeInfo.setPopUpText(nodeInfo.getNodeItem().mainTitleNode.title); + } else { + nodeInfo.setPopUpText(''); + nodeInfo.setPopUpIsShow(false); + } + nodeInfo.setPopUpEnableArrow(false); + nodeInfo.setPopUpColor($r('sys.color.ohos_id_color_background')); + nodeInfo.setPopUpTextColor($r('sys.color.ohos_id_color_text_secondary')); + } else if (popUpType === PopUpType.WARNINGS) { + if (nodeInfo.getNodeItem().inputText != null) { + if (inputError === InputError.INVALID_ERROR) { + nodeInfo.setPopUpText("invalid error"); + } else if (inputError === InputError.LENGTH_ERROR) { + nodeInfo.setPopUpText("length error"); + } + nodeInfo.setPopUpEnableArrow(true); + nodeInfo.setPopUpColor($r('sys.color.ohos_id_color_help_tip_bg')); + nodeInfo.setPopUpTextColor($r('sys.color.ohos_id_color_text_hint_contrary')); + } + } + this.notifyDataChange(lazyForEachIndex); + } + + public setShowPopUpTimeout(timeout: number, index: number) { + if (this.listNode[index].getNodeItem().mainTitleNode != null) { + this.listNode[index].getNodeItem().mainTitleNode.popUpTimeout = timeout; + } + // this.notifyDataChange(index) lazyForEachIndex; + let lazyForEachIndex = this.loadedNodeIdAndIndexMap.get(this.listNode[index].getCurrentNodeId()); + this.notifyDataChange(lazyForEachIndex); + } + + public setMainTitleNameOnEdit(index: number, text: string) { + this.modifyNodeIndex = index; + if (this.listNode[index].getNodeItem().mainTitleNode != null) { + this.listNode[index].getNodeItem().mainTitleNode.title = text; + // this.listNode index to lazyForEach index. + let lazyForEachIndex = this.loadedNodeIdAndIndexMap.get(this.listNode[index].getCurrentNodeId()); + this.notifyDataChange(lazyForEachIndex); + } + } + + public get ListNode(): NodeInfo[] { + return this.listNode; + } + + public totalCount(): number { + let count: number = 0; + let index: number = 0; + this.loadedNodeIdAndIndexMap.clear(); + for (let i =0 ; i < this.listNode.length; i++) { + if (this.listNode[i].getNodeIsShow()) { + this.loadedNodeIdAndIndexMap.set(this.listNode[i].getCurrentNodeId(), index++); + count++; + } + } + return count; + } + + public getData(index: number): any { + let count = 0; + for (let i = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getNodeIsShow()) { + if (index == count) { + return this.listNode[i]; + } + count++; + } + } + return null; + } + + public addData(index: number, data: NodeInfo): void { + this.listNode.splice(index, 0, data) + this.notifyDataAdd(index) + } + + public pushData(data: NodeInfo): void { + this.listNode.push(data) + this.notifyDataAdd(this.listNode.length - 1) + } + + public setIsInnerDrag(isInnerDrag: boolean) { + this.isInnerDrag = isInnerDrag; + } + + public getIsInnerDrag(): boolean { + return this.isInnerDrag; + } + + public setIsDrag(isDrag: boolean) { + this.isDrag = isDrag; + } + + public getIsDrag(): boolean { + return this.isDrag; + } + + public setCurrentNodeInfo(currentNodeInfo: NodeInfo) { + this.currentNodeInfo = currentNodeInfo; + } + + public getCurrentNodeInfo() { + return this.currentNodeInfo; + } + + public setDraggingParentNodeId(draggingParentNodeId: number) { + this.draggingParentNodeId = draggingParentNodeId; + } + + public getDraggingParentNodeId() { + return this.draggingParentNodeId; + } + + public getDraggingCurrentNodeId() { + return this.draggingCurrentNodeId; + } + + public setDraggingCurrentNodeId(draggingCurrentNodeId: number) { + this.draggingCurrentNodeId = draggingCurrentNodeId; + } + + public setListItemOpacity(listItemOpacity: number) { + this.listItemOpacity = listItemOpacity; + } + + public getListItemOpacity(item: NodeInfo) { + return item.getCurrentNodeId() == this.getDraggingCurrentNodeId() ? this.listItemOpacity : 1; + } + + public getDragPopupPara() { + return this.DRAG_POPUP; + } + + public setLastPassIndex(lastPassIndex: number) { + this.lastPassIndex = lastPassIndex; + } + + public getLastPassIndex(): number { + return this.lastPassIndex; + } + + public getIsParentOfInsertNode(insertNodeId: number): boolean { + let selectedNodeItem: NodeItem = this.currentNodeInfo.getNodeInfoNode(); + let isParentNodeOfInsertNode = false, + callback = function(node): boolean { + if (node.currentNodeId == insertNodeId ) { + isParentNodeOfInsertNode = true; + return true; + } + return false; + }; + this.listNodeUtils.traverseNodeDF(callback, selectedNodeItem); + return isParentNodeOfInsertNode; + } + + public setPassIndex(thisPassIndex: number) { + this.thisPassIndex = thisPassIndex; + } + + public getPassIndex(): number { + return this.thisPassIndex; + } + + public clearTimeOutAboutDelayHighLightAndExpand(currentIndex: number) { + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let index: number = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + let that =this; + this.ListNode.forEach(function(value) { + if (value.getNodeCurrentNodeId() == that.lastPassId) { + value.setCanShowFlagLine(false); + } + }) + this.notifyDataChange(index); + } + + if ((this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutHighLightId != this.lastTimeoutHighLightId)) { + clearTimeout(this.lastTimeoutHighLightId); + if (this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE) { + this.clearHighLight(this.lastDelayHighLightIndex); + let index: number = this.loadedNodeIdAndIndexMap + .get(this.listNode[this.lastDelayHighLightIndex].getCurrentNodeId()); + this.notifyDataChange(index); + } + this.clearTimeoutHighLightId = this.lastTimeoutHighLightId; + } + this.lastTimeoutHighLightId = this.timeoutHighLightId; + this.lastDelayHighLightIndex = currentIndex; + + if ((this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutExpandId != this.lastTimeoutExpandId)) { + clearTimeout(this.lastTimeoutExpandId); + this.clearTimeoutExpandId = this.lastTimeoutExpandId; + } + this.lastTimeoutExpandId = this.timeoutExpandId; + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE; + } + + public clearHighLight(currentIndex: number) { + this.changeNodeColor(currentIndex, this.listNode[currentIndex].getNodeStatus().normal); + this.changeNodeHighLightColor(currentIndex, false); + this.setImageSource(currentIndex, InteractionStatus.FinishDragInsert); + this.setImageCollapseSource(currentIndex, InteractionStatus.FinishDragInsert); + this.listNode[currentIndex].setIsHighLight(false); + } + + private changeNodeHighLightColor(index: number, isHighLight: boolean): void { + if (this.listNode[index].getNodeItem().mainTitleNode && this.listNode[index].getIsShowTitle()) { + this.listNode[index].getNodeItem().mainTitleNode.setMainTitleHighLight(isHighLight); + } + } + + public setVisibility(flag: Flag, index: number, isOverBorder: boolean) { + let isChanged: boolean = (this.thisPassIndex != index || this.flag != flag) ? true : false; + this.thisPassIndex = index; + if ((isChanged || isOverBorder) && this.isInnerDrag) { + this.flag = flag; + let currentNodeId: number = this.getData(index).getCurrentNodeId(); + let currentNodeLevel: number = this.expandAndCollapseInfo.get(currentNodeId) == NodeStatus.Expand && + this.flag == Flag.DOWN_FLAG ? this.getData(index).getNodeLevel() + 1 : this.getData(index).getNodeLevel(); + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let lastIndex: number = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + let that = this; + this.ListNode.forEach(function (value) { + if (value.getNodeCurrentNodeId() == that.lastPassId) { + value.setCanShowFlagLine(false); + } + }) + this.notifyDataChange(lastIndex); + } + if (this.flag == Flag.DOWN_FLAG && index < this.totalCount() - 1) { + this.getData(index).setCanShowFlagLine(false); + this.getData(index+1).setCanShowFlagLine(true); + this.getData(index).setCanShowBottomFlagLine(false); + this.getData(index+1).setFlagLineLeftMargin(currentNodeLevel); + this.notifyDataChange(index); + this.notifyDataChange(index + 1); + this.lastPassId = this.getData(index + 1).getNodeCurrentNodeId(); + } else if (this.flag == Flag.UP_FLAG && index < this.totalCount() - 1) { + this.getData(index).setCanShowFlagLine(true); + this.getData(index+1).setCanShowFlagLine(false); + this.getData(index).setCanShowBottomFlagLine(false); + this.getData(index).setFlagLineLeftMargin(currentNodeLevel); + this.notifyDataChange(index); + this.notifyDataChange(index + 1); + this.lastPassId = this.getData(index).getNodeCurrentNodeId(); + } else if (index >= this.totalCount() - 1) { + if (this.flag == Flag.DOWN_FLAG) { + this.getData(index).setCanShowFlagLine(false); + this.getData(index).setCanShowBottomFlagLine(true); + } else { + this.getData(index).setCanShowFlagLine(true); + this.getData(index).setCanShowBottomFlagLine(false); + } + this.getData(index).setFlagLineLeftMargin(currentNodeLevel); + this.notifyDataChange(index); + this.lastPassId = this.getData(index).getNodeCurrentNodeId(); + } + } + } + + public delayHighLightAndExpandNode(currentIndex: number, currentNodeId: number, showIndex: number) { + let isChangIndex: boolean = currentIndex != this.lastDelayExpandIndex ? true : false; + let isOverBorder: boolean = this.getData(showIndex).getIsOverBorder(); + if (isOverBorder) { + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE; + } else { + this.lastDelayExpandIndex = currentIndex; + } + if (isOverBorder || isChangIndex) { + let that = this; + + /* highLight node time-out. */ + let canDelayHighLight: boolean = !isOverBorder && (!this.isInnerDrag || + (this.expandAndCollapseInfo.get(currentNodeId) == NodeStatus.Collapse && this.isInnerDrag) || + (!this.expandAndCollapseInfo.has(currentNodeId) && this.listNode[currentIndex].getIsFolder())); + if (canDelayHighLight) { + /* set hoverState color before highLight. */ + this.changeNodeColor(currentIndex, this.listNode[currentIndex].getNodeStatus().hover); + this.notifyDataChange(showIndex); + + let delayHighLightTime: number = this.isInnerDrag ? 1000 : 0; // ms + this.timeoutHighLightId = setTimeout(function() { + that.delayHighLight(currentIndex); + }, delayHighLightTime) + } + if (isOverBorder || (this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutHighLightId != this.lastTimeoutHighLightId)) { + clearTimeout(this.lastTimeoutHighLightId); + if (this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE) { + this.clearHighLight(this.lastDelayHighLightIndex); + this.notifyDataReload(); + } + this.clearTimeoutHighLightId = this.lastTimeoutHighLightId; + } + this.lastTimeoutHighLightId = this.timeoutHighLightId; + this.lastDelayHighLightIndex = currentIndex; + + /* alter flagLine and expand node time-out. */ + if (!isOverBorder && this.expandAndCollapseInfo.get(currentNodeId) == NodeStatus.Collapse) { + let firstChildNodeId: number = this.getData(showIndex).getNodeInfoNode().children[0].currentNodeId; + let delayAlterFlagLineAndExpandNodeTime: number = 2000; // ms + this.timeoutExpandId = setTimeout(function() { + that.clearHighLight(that.lastDelayHighLightIndex); + that.alterFlagLineAndExpandNode(currentIndex, firstChildNodeId); + }, delayAlterFlagLineAndExpandNodeTime) + } + if (isOverBorder || (this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutExpandId != this.lastTimeoutExpandId)) { + clearTimeout(this.lastTimeoutExpandId); + this.clearTimeoutExpandId = this.lastTimeoutExpandId; + } + this.lastTimeoutExpandId = this.timeoutExpandId; + } + } + + public delayHighLight(currentIndex: number) { + let that =this; + this.ListNode.forEach(function (value) { + if (value.getNodeCurrentNodeId() == that.lastPassId) { + value.setCanShowFlagLine(false); + value.setCanShowBottomFlagLine(false); + } + }) + this.changeNodeColor(currentIndex, this.listNode[currentIndex].getNodeStatus().highLight); + this.listNode[currentIndex].setIsHighLight(true); + this.changeNodeHighLightColor(currentIndex, true); + this.setImageSource(currentIndex, InteractionStatus.DragInsert); + this.setImageCollapseSource(currentIndex, InteractionStatus.DragInsert); + this.notifyDataReload(); + } + + public alterFlagLineAndExpandNode(currentIndex: number, firstChildNodeId: number) { + let that =this; + this.ListNode.forEach(function (value) { + if (value.getNodeCurrentNodeId() == that.lastPassId) { + value.setCanShowFlagLine(false); + value.setCanShowBottomFlagLine(false); + } + }) + this.ListNode.forEach(function (value) { + if (that.isInnerDrag && value.getNodeCurrentNodeId() == firstChildNodeId) { + value.setCanShowFlagLine(true); + } + }) + this.changeNodeStatus(currentIndex); + this.handleExpandAndCollapse(currentIndex); + this.lastPassId = firstChildNodeId; + } + + public hideLastLine() { + if (this.lastPassId != this.INITIAL_INVALID_VALUE && this.loadedNodeIdAndIndexMap.has(this.lastPassId)) { + let that = this; + this.ListNode.forEach(function (value) { + if (value.getNodeCurrentNodeId() == that.lastPassId) { + value.setCanShowFlagLine(false); + value.setCanShowBottomFlagLine(false); + } + }) + let index: number = this.loadedNodeIdAndIndexMap.get(this.lastPassId); + this.notifyDataChange(index); + } + } + + public clearLastTimeoutHighLight() { + if (this.lastTimeoutHighLightId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutHighLightId != this.lastTimeoutHighLightId) { + clearTimeout(this.lastTimeoutHighLightId); + if (this.lastDelayHighLightIndex != this.INITIAL_INVALID_VALUE) { + this.clearHighLight(this.lastDelayHighLightIndex); + } + } + } + + public clearLastTimeoutExpand() { + if (this.lastTimeoutExpandId != this.INITIAL_INVALID_VALUE && + this.clearTimeoutExpandId != this.lastTimeoutExpandId) { + clearTimeout(this.lastTimeoutExpandId); + } + } + + public getSubtitle(currentNodeId: number): string { + if (this.nodeIdAndSubtitleMap.has(currentNodeId)) { + if (typeof this.nodeIdAndSubtitleMap.get(currentNodeId) == "number") { + return this.nodeIdAndSubtitleMap.get(currentNodeId).toString(); + } else { + return this.nodeIdAndSubtitleMap.get(currentNodeId) + } + } else { + return ''; + } + } + + public hasSubtitle(currentNodeId: number) { + return this.nodeIdAndSubtitleMap.has(currentNodeId); + } + + public initialParameterAboutDelayHighLightAndExpandIndex() { + this.lastDelayHighLightIndex = this.INITIAL_INVALID_VALUE; + this.lastDelayExpandIndex = this.INITIAL_INVALID_VALUE; + this.lastPassIndex = this.INITIAL_INVALID_VALUE; + this.draggingCurrentNodeId = this.INITIAL_INVALID_VALUE; + this.flag = Flag.NONE; + } + + public refreshSubtitle(insertNodeCurrentNodeId: number) { + this.nodeIdAndSubtitleMap.set(this.selectedParentNodeId, this.selectedParentNodeSubtitle); + this.nodeIdAndSubtitleMap.set(insertNodeCurrentNodeId, this.insertNodeSubtitle); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(this.selectedParentNodeId)); + this.notifyDataChange(this.loadedNodeIdAndIndexMap.get(insertNodeCurrentNodeId)); + } + + public setNodeSubtitlePara( + selectedParentNodeId: number, + selectedParentNodeSubtitle: ResourceStr, + insertNodeSubtitle: ResourceStr + ) { + this.selectedParentNodeId = selectedParentNodeId; + this.selectedParentNodeSubtitle = selectedParentNodeSubtitle; + this.insertNodeSubtitle = insertNodeSubtitle; + } + + public getInsertNodeSubtitle() { + return this.insertNodeSubtitle; + } + + public getExpandAndCollapseInfo(currentNodeId: number) { + return this.expandAndCollapseInfo.get(currentNodeId); + } + + public getLastDelayHighLightId() { + return this.lastDelayHighLightId; + } + + public setLastDelayHighLightId() { + this.ListNode.forEach((value, index) => { + if (index == this.lastDelayHighLightIndex) { + this.lastDelayHighLightId = value.getCurrentNodeId(); + } + }) + } + + public setLastPassId(lastPassId: number) { + this.lastPassId = lastPassId; + } + + public setLastDelayHighLightIndex(lastDelayHighLightIndex) { + this.lastDelayHighLightIndex = lastDelayHighLightIndex; + } + + /* + * Alter the current node location to a needful position. + * 1.Create an array named 'dragNodeParam' to store dragging node information. + * 2.Delete the dragging node from the tree. + * 3.Add the dragging node to the tree. + */ + public alterDragNode(rearParentNodeId: number, rearCurrentNodeId: number, insertNodeInfo: NodeInfo, + dragParentNodeId: number, dragCurrentNodeId: number, frontNodeInfoItem: NodeInfo) { + let dragNodeParam: { parentId: number, currentId: number, data: any }[] = []; + let parentNodeId: number = rearParentNodeId; + let currentNodeId: number = dragCurrentNodeId; + let nodeParam = frontNodeInfoItem.getNodeInfoData(); + let nodeInfo: NodeInfo = null; + let nodeInfoNode: NodeItem = frontNodeInfoItem.getNodeInfoNode(); + let isHighLight : boolean = false; + let insertChildIndex: number = this.INITIAL_INVALID_VALUE; + let currentChildIndex: number = this.INITIAL_INVALID_VALUE; + let isDownFlag: boolean = this.flag == Flag.DOWN_FLAG ? true : false; + + currentChildIndex = this.getChildIndex(dragParentNodeId, dragCurrentNodeId); + insertChildIndex = this.getChildIndex(rearParentNodeId, rearCurrentNodeId); + + if (rearParentNodeId != dragParentNodeId) { + insertChildIndex = isDownFlag ? insertChildIndex + 1 : insertChildIndex; + } else { + if (insertChildIndex > currentChildIndex) { + insertChildIndex = isDownFlag ? insertChildIndex : insertChildIndex - 1; + } else { + insertChildIndex = isDownFlag ? insertChildIndex + 1 : insertChildIndex; + } + } + + for (let i = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getCurrentNodeId() == rearCurrentNodeId) { + isHighLight = this.listNode[i].getIsHighLight(); + if (this.flag == Flag.DOWN_FLAG && this.expandAndCollapseInfo.get(rearCurrentNodeId) == NodeStatus.Expand) { + parentNodeId = rearCurrentNodeId; + insertChildIndex = 0; + } else if (this.flag == Flag.UP_FLAG && this.expandAndCollapseInfo.get(rearCurrentNodeId) == NodeStatus.Expand + && this.listNode[i].getCanShowFlagLine() == false) { + parentNodeId = rearCurrentNodeId; + insertChildIndex = 0; + } else if (isHighLight) { + parentNodeId = rearCurrentNodeId; + insertChildIndex = 0; + } + break; + } + } + + let callbackParam: CallbackParam = { currentNodeId: currentNodeId, parentNodeId: parentNodeId, childIndex: insertChildIndex } + + /* export inner drag node Id. */ + this.appEventBus.emit(TreeListenType.NODE_MOVE, [callbackParam]); + + /* To store dragging node information by the array named 'dragNodeParam'. */ + dragNodeParam.push({parentId: parentNodeId, currentId: currentNodeId, data: nodeParam}); + + let oneself = null, + callback = function(node, listNode): boolean { + if (node) { + oneself = node; + parentNodeId = oneself.parentNodeId; + currentNodeId = oneself.currentNodeId; + for (let i = 0; i < listNode.length; i++) { + if (listNode[i].getNodeCurrentNodeId() == currentNodeId) { + nodeInfo = listNode[i]; + break; + } + } + nodeParam = nodeInfo.getNodeInfoData(); + if (parentNodeId != dragParentNodeId) { + dragNodeParam.push({parentId: parentNodeId, currentId: currentNodeId, data: nodeParam}); + } + return false; + } + return false; + } + this.listNodeUtils.dragTraverseNodeDF(callback, nodeInfoNode, this.listNode); + + /* Delete the dragging node from the tree. */ + this.listNodeUtils.removeNode(dragCurrentNodeId, dragParentNodeId, this.listNodeUtils.traverseNodeBF); + + /* + * Add the dragging node to the tree + * 1.The first dragging node is added singly, because it needs to distinguish the position to insert + * + * Add first node. + */ + let insertCurrentNodeId: number = rearCurrentNodeId; + let isAfter: boolean = isDownFlag; + if (this.expandAndCollapseInfo.get(rearCurrentNodeId) == NodeStatus.Expand) { + isAfter = false; + this.listNode.forEach((value) => { + if (value.getCurrentNodeId() == rearCurrentNodeId && value.getCanShowFlagLine() == false) { + if (value.getNodeInfoNode().children.length) { + insertCurrentNodeId = value.getNodeInfoNode().children[0].currentNodeId; + } else { + insertCurrentNodeId = this.INITIAL_INVALID_VALUE; + } + } + }) + } else if (!this.expandAndCollapseInfo.get(rearCurrentNodeId) && isHighLight) { + this.expandAndCollapseInfo.set(rearCurrentNodeId, NodeStatus.Expand); + } + + this.listNodeUtils.addDragNode(dragNodeParam[0].parentId, dragNodeParam[0].currentId, insertCurrentNodeId, + isAfter, dragNodeParam[0].data); + + /* Add remaining node. */ + for (let j = 1; j < dragNodeParam.length; j++) { + this.listNodeUtils.addNode(dragNodeParam[j].parentId, dragNodeParam[j].currentId, dragNodeParam[j].data); + } + + /* Update node data and reload the array named 'listNode'. */ + for (let i = 0; i < this.listNode.length; i++) { + if (this.listNode[i].getCurrentNodeId() == dragParentNodeId) { + if (this.listNode[i].getNodeInfoNode().getNodeItem().imageCollapse == null) { + this.listNode[i].handleImageCollapseAfterAddNode(false); + this.expandAndCollapseInfo.delete(dragParentNodeId); + break; + } + } + } + let tmp: NodeInfo[] = [...this.listNode]; + this.reloadListNode(this.listNodeUtils, tmp); + + } + + /* + * Reload the array named 'listNode' + * @param listNodeUtils + * @param tmp + */ + public reloadListNode(listNodeUtils: ListNodeUtils, tmp: NodeInfo[]) { + let index = 0; + this.listNode = []; + this.listNodeUtils = listNodeUtils; + this.loadedNodeIdAndIndexMap.clear(); + this.listNodeUtils.traverseNodeDF((node: NodeItem): boolean => { + if (node.currentNodeId >= 0) { + var nodeInfo: NodeInfo = new NodeInfo(node); + this.listNode.push(nodeInfo); + + if (this.expandAndCollapseInfo.get(node.currentNodeId) == NodeStatus.Expand) { + nodeInfo.getNodeItem().imageCollapse.changeImageCollapseSource(NodeStatus.Expand); + } else if (this.expandAndCollapseInfo.get(node.currentNodeId) == NodeStatus.Collapse) { + nodeInfo.getNodeItem().imageCollapse.changeImageCollapseSource(NodeStatus.Collapse); + } + + for (let i = 0; i < tmp.length; i++){ + if (tmp[i].getCurrentNodeId() == nodeInfo.getCurrentNodeId()) { + nodeInfo.setNodeIsShow(tmp[i].getNodeIsShow()); + nodeInfo.setListItemHeight(tmp[i].getListItemHeight()); + if (nodeInfo.getNodeItem().mainTitleNode && nodeInfo.getIsShowTitle()) { + nodeInfo.getNodeItem().mainTitleNode.title = tmp[i].getNodeItem().mainTitleNode.title; + } + break; + } + } + if (nodeInfo.getNodeIsShow()) { + this.loadedNodeIdAndIndexMap.set(nodeInfo.getCurrentNodeId(), index++); + } + } + return false; + }); + } + + public getFlagLine() { + return this.FLAG_LINE; + } + + public getVisibility(nodeInfo: NodeInfo): any { + let lastShowIndex: number = this.loadedNodeIdAndIndexMap.get(nodeInfo.getCurrentNodeId()) - 1; + if (lastShowIndex > this.INITIAL_INVALID_VALUE) { + let lastNodeInfo: NodeInfo = this.getData(lastShowIndex); + return (nodeInfo.getCanShowFlagLine() == true && !nodeInfo.getIsHighLight() && !lastNodeInfo.getIsHighLight()) ? + Visibility.Visible : Visibility.Hidden; + } else { + return (nodeInfo.getCanShowFlagLine() == true && !nodeInfo.getIsHighLight()) ? + Visibility.Visible : Visibility.Hidden; + } + } + + public getSubTitlePara() { + return this.subTitle; + } + + public getIsFolder(nodeId: number) { + if (this.loadedNodeIdAndIndexMap.has(nodeId)) { + return this.getData(this.loadedNodeIdAndIndexMap.get(nodeId)).getIsFolder(); + } + return false; + } + + public getSubTitleFontColor(isHighLight: boolean) { + return isHighLight ? this.subTitle.highLightFontColor : this.subTitle.normalFontColor; + } + + private getChildIndex(rearParentNodeId: number, rearCurrentNodeId: number) { + let insertChildIndex: number = this.INITIAL_INVALID_VALUE; + this.listNodeUtils.traverseNodeBF(function(node): boolean { + if (node.getCurrentNodeId() == rearParentNodeId) { + node.children.forEach((value, index) => { + if (value.getCurrentNodeId() == rearCurrentNodeId) { + insertChildIndex = index; + } + }) + return true; + } + return false; + }); + return insertChildIndex; + } + + public setCurrentFocusNodeId(focusNodeId: number) { + this.currentFocusNodeId = focusNodeId; + } + + public getCurrentFocusNodeId(): number { + return this.currentFocusNodeId; + } + + public setLastFocusNodeId(focusNodeId: number) { + this.lastFocusNodeId = focusNodeId; + } + + public getLastFocusNodeId(): number { + return this.lastFocusNodeId; + } + + public getAddFocusNodeId(): number { + return this.addFocusNodeId; + } + + public setFlag(flag: Flag) { + this.flag = flag; + } + } + + /* nodeId to find index */ + function findCurrentNodeIndex(this, currentNodeId: number): number { + let thisIndex: number = 0; + this.listNodeDataSource.ListNode.forEach(function (value, index) { + if (value.getNodeCurrentNodeId() == currentNodeId) { + thisIndex = index; + } + }) + return thisIndex; + } + + /** + * Tree view control, which is created by using the TreeController class. + * + * When you create this component, you must initialize the listNodeDataSource. + * You can run the listTreeViewWidth command to set the width of the component. + * The default width is 200vp. + * + * @since 10 + */ + @Component + export struct TreeView { + listNodeDataSource: ListNodeDataSource; + treeController: TreeController; + @State dropSelectedIndex: number = 0; + @BuilderParam private listTreeViewMenu: () => void = null; + @Prop listTreeViewWidth: string | number; + @Prop listTreeViewHeight: number | string; + private readonly MAX_CN_LENGTH: number = 254; + private readonly MAX_EN_LENGTH: number = 255; + private readonly INITIAL_INVALID_VALUE = -1; + private readonly MAX_TOUCH_DOWN_COUNT = 0; + private isMultiPress: boolean = false; + private touchDownCount: number = this.INITIAL_INVALID_VALUE; + private appEventBus: TreeListener = TreeListenerManager.getInstance().getTreeListener(); + private readonly itemPadding: { left: Resource, right: Resource, top: Resource, bottom: Resource } = + { left: $r('sys.float.ohos_id_card_margin_middle'), + right: $r('sys.float.ohos_id_card_margin_middle'), + top: $r('sys.float.ohos_id_text_margin_vertical'), + bottom: $r('sys.float.ohos_id_text_margin_vertical')}; + /* { left: '12vp', right: '12vp', top: '2vp', bottom: '2vp' } */ + private readonly textInputPadding: { left : string, right: string, top: string, bottom: string } = + { left : '0vp', right: '0vp', top: '0vp', bottom: '0vp'} + aboutToAppear(): void { + this.listTreeViewWidth = (this.listTreeViewWidth === undefined) ? 200 : this.listTreeViewWidth; + this.listNodeDataSource = this.treeController.getListNodeDataSource(); + } + + private checkInvalidPattern(title: string): boolean { + let pattern = /[\\\/:*?"<>|]/; + return pattern.test(title) + } + + private checkIsAllCN(title: string): boolean { + let pattern = /^[\u4e00-\u9fa5]+$/; + return pattern.test(title) + } + + @Builder popupForShowTitle(text: string | Resource, backgroundColor: Resource, fontColor: Resource ) { + Row() { + Text(text).fontSize($r('sys.float.ohos_id_text_size_body2')).fontWeight('regular').fontColor(fontColor) + }.backgroundColor(backgroundColor) + .border({radius: $r('sys.float.ohos_id_elements_margin_horizontal_l')}) + .padding({left: $r('sys.float.ohos_id_elements_margin_horizontal_l'), + right: $r('sys.float.ohos_id_elements_margin_horizontal_l'), + top: $r('sys.float.ohos_id_card_margin_middle'), + bottom: $r('sys.float.ohos_id_card_margin_middle')}) + } + + @Builder builder() { + this.listTreeViewMenu() + } + + /* Set the popup of dragging node. */ + @Builder draggingPopup(item: NodeInfo) { + Row() { + if (item.getNodeItem().imageNode) { + Row() { + Image(item.getNodeItem().imageNode.normalSource) + .objectFit(ImageFit.Contain) + .height(item.getNodeItem().imageNode.itemHeight) + .width(item.getNodeItem().imageNode.itemWidth) + .opacity(this.listNodeDataSource.getDragPopupPara().imageOpacity) + } + .backgroundColor(COLOR_IMAGE_ROW) + .margin({ right: item.getNodeItem().imageNode.itemRightMargin }) + .height(item.getNodeItem().imageNode.itemHeight) + .width(item.getNodeItem().imageNode.itemWidth) + } + Row() { + if (item.getNodeItem().mainTitleNode && item.getIsShowTitle()) { + Text(item.getNodeItem().mainTitleNode.title) + .maxLines(1) + .fontSize(item.getNodeItem().mainTitleNode.size) + .fontColor(this.listNodeDataSource.getDragPopupPara().fontColor) + .fontWeight(this.listNodeDataSource.getDragPopupPara().fontWeight) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + } + } + .constraintSize({ + minWidth: item.getNodeItem().imageNode ? + this.listNodeDataSource.getDragPopupPara().textConstraintSize.minWidth1 : + this.listNodeDataSource.getDragPopupPara().textConstraintSize.minWidth2, + maxWidth: item.getNodeItem().imageNode ? + this.listNodeDataSource.getDragPopupPara().textConstraintSize.maxWidth1 : + this.listNodeDataSource.getDragPopupPara().textConstraintSize.maxWidth2 }) + } + .constraintSize({ minWidth: this.listNodeDataSource.getDragPopupPara().floorConstraintSize.minWidth, + maxWidth: this.listNodeDataSource.getDragPopupPara().floorConstraintSize.maxWidth }) + .height(this.listNodeDataSource.getDragPopupPara().height) + .backgroundColor(this.listNodeDataSource.getDragPopupPara().backgroundColor) + .padding({ left: this.listNodeDataSource.getDragPopupPara().padding.left, + right: this.listNodeDataSource.getDragPopupPara().padding.right }) + .shadow({ radius: this.listNodeDataSource.getDragPopupPara().shadow.radius, + color: this.listNodeDataSource.getDragPopupPara().shadow.color, + offsetY: this.listNodeDataSource.getDragPopupPara().shadow.offsetY }) + .borderRadius(this.listNodeDataSource.getDragPopupPara().borderRadius) // need to doubleCheck. + } + + build() { + List({ }) { + LazyForEach(this.listNodeDataSource, (item: NodeInfo) => { + ListItem() { + if (item.getNodeIsShow()) { + Column() { + Divider() + .height(this.listNodeDataSource.getFlagLine().flagLineHeight) + .color(this.listNodeDataSource.getFlagLine().flagLineColor) + .visibility(this.listNodeDataSource.getVisibility(item)) + .lineCap(LineCapStyle.Round) + .margin({ left: item.getFlagLineLeftMargin() }) + .markAnchor({ x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yTopOffset }) + Row({}) { + Row({}) { + if (item.getNodeItem().imageNode) { + Row() { + Image(item.getNodeItem().imageNode.source) + .objectFit(ImageFit.Contain) + .height(item.getNodeItem().imageNode.itemHeight) + .width(item.getNodeItem().imageNode.itemWidth) + .opacity(!item.getIsSelected() && !item.getIsHighLight() ? + item.getNodeItem().imageNode.opacity : item.getNodeItem().imageNode.noOpacity) + .focusable(item.getNodeItem().mainTitleNode != null ? false : true) + .onFocus(() => { + let that = this; + that.listNodeDataSource.handleEvent(Event.FOCUS, + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + }) + .onBlur(() => { + let that = this; + that.listNodeDataSource.handleEvent(Event.BLUR, + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + }) + } + .backgroundColor(COLOR_IMAGE_ROW) + .margin({ right: item.getNodeItem().imageNode.itemRightMargin }) + .height(item.getNodeItem().imageNode.itemHeight) + .width(item.getNodeItem().imageNode.itemWidth) + } + Row() { + if (item.getNodeItem().mainTitleNode && item.getIsShowTitle()) { + Text(item.getNodeItem().mainTitleNode.title) + .maxLines(1) // max line + .fontSize(item.getNodeItem().mainTitleNode.size) + .fontColor(item.getNodeItem().mainTitleNode.color) + .margin({ right: item.getNodeItem().mainTitleNode.itemRightMargin }) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .fontWeight(item.getNodeItem().mainTitleNode.weight) + .focusable(true) + .onFocus(() => { + let that = this; + this.listNodeDataSource.handleEvent(Event.FOCUS, + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + }) + .onBlur(() => { + let that = this; + that.listNodeDataSource.handleEvent(Event.BLUR, + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + }) + } + if (item.getNodeItem().mainTitleNode && + item.getNodeItem().inputText && + item.getIsShowInputText()) { + Row() { + TextInput({ text: item.getNodeItem().mainTitleNode.title }) + .height(item.getNodeItem().inputText.itemHeight) + .fontSize(item.getNodeItem().inputText.size) + .fontColor(item.getNodeItem().inputText.color) + .borderRadius(item.getNodeItem().inputText.borderRadius) + .backgroundColor(item.getNodeItem().inputText.backgroundColor) + .enterKeyType(EnterKeyType.Done) + .padding({ left: this.textInputPadding.left, right: this.textInputPadding.right, + top: this.textInputPadding.top, bottom: this.textInputPadding.bottom }) + .onChange((value: string) => { + let that = this; + var thisIndex = findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId()); + let res: string = ''; + let isInvalidError: boolean = false; + let isLengthError: boolean = false; + if (that.checkInvalidPattern(value)) { + for (let i = 0; i < value.length; i++) { + if (!that.checkInvalidPattern(value[i])) { + res += value[i]; + } + } + isInvalidError = true; + that.listNodeDataSource.setPopUpInfo(PopUpType.WARNINGS, + InputError.INVALID_ERROR, true, thisIndex); + } else { + res = value; + isInvalidError = false; + that.listNodeDataSource.setPopUpInfo(PopUpType.WARNINGS, + InputError.INVALID_ERROR, false, thisIndex); + } + if ((that.checkIsAllCN(res) && res.length > this.MAX_CN_LENGTH) || + (!that.checkIsAllCN(res) && res.length > this.MAX_EN_LENGTH)) { + res = that.checkIsAllCN(res) ? + res.substr(0, this.MAX_CN_LENGTH) : res.substr(0, this.MAX_EN_LENGTH); + isLengthError = true; + that.listNodeDataSource.setPopUpInfo(PopUpType.WARNINGS, + InputError.LENGTH_ERROR, true, thisIndex); + } else { + isLengthError = false; + } + if (!isLengthError && !isInvalidError) { + that.listNodeDataSource.setPopUpInfo(PopUpType.WARNINGS, + InputError.LENGTH_ERROR, false, thisIndex); + that.listNodeDataSource.setMainTitleNameOnEdit(thisIndex, res); + } + + }) + .onSubmit((enterKey: EnterKeyType) => { + let that = this; + var thisIndex = findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId()); + that.listNodeDataSource.setPopUpInfo(PopUpType.WARNINGS, InputError.NONE, false, thisIndex); + that.listNodeDataSource.setItemVisibilityOnEdit(thisIndex, MenuOperation.COMMIT_NODE); + }) + }.backgroundColor(item.getNodeItem().inputText.backgroundColor) + .borderRadius(item.getNodeItem().inputText.borderRadius) + .margin({ right: item.getNodeItem().inputText.itemRightMargin }) + } + Blank() + }.layoutWeight(1) + + if (this.listNodeDataSource.hasSubtitle(item.getCurrentNodeId())) { + Row() { + Text(this.listNodeDataSource.getSubtitle(item.getCurrentNodeId())) + .fontSize(this.listNodeDataSource.getSubTitlePara().fontSize) + .fontColor(this.listNodeDataSource.getSubTitleFontColor(item.getIsHighLight() || item.getIsModify())) + .fontWeight(this.listNodeDataSource.getSubTitlePara().fontWeight) + } + .margin({ left: this.listNodeDataSource.getSubTitlePara().margin.left, + right: item.getNodeItem().imageCollapse ? + 0 : this.listNodeDataSource.getSubTitlePara().margin.right }) + } + + if (item.getNodeItem().imageCollapse) { + Row() { + Image(item.getNodeItem().imageCollapse.collapseSource) + .fillColor(item.getNodeItem().imageCollapse.isCollapse ? COLOR_IMAGE_ROW : COLOR_IMAGE_EDIT) + .align(Alignment.End) + .objectFit(ImageFit.Contain) + .height(item.getNodeItem().imageCollapse.itemHeight) + .width(item.getNodeItem().imageCollapse.itemWidth) + .opacity(!item.getIsHighLight() ? + item.getNodeItem().imageCollapse.opacity : item.getNodeItem().imageCollapse.noOpacity) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + let that = this; + that.listNodeDataSource.expandAndCollapseNode( + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + this.listNodeDataSource.setCurrentFocusNodeId(item.getCurrentNodeId()); + } + event.stopPropagation(); + }) + } + .backgroundColor(COLOR_IMAGE_ROW) + .height(item.getNodeItem().imageCollapse.itemHeight) + .width(item.getNodeItem().imageCollapse.itemWidth) + } + } + .width('100%') + .onTouch((event: TouchEvent) => { + let that = this; + let index = findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId()); + let currentId = item.getNodeCurrentNodeId(); + that.listNodeDataSource.setClickIndex(index); + if (event.type === TouchType.Down) { + this.touchDownCount ++; + this.isMultiPress = this.touchDownCount > this.MAX_TOUCH_DOWN_COUNT ? true : false; + if (!this.listNodeDataSource.getIsTouchDown()) { + that.listNodeDataSource.handleEvent(Event.TOUCH_DOWN, index); + } + } + if (event.type === TouchType.Up) { + this.touchDownCount--; + if (this.touchDownCount < this.MAX_TOUCH_DOWN_COUNT) { + this.isMultiPress = false; + } + let callbackParam = { currentNodeId: currentId } + this.appEventBus.emit(TreeListenType.NODE_CLICK, [callbackParam]); + that.listNodeDataSource.handleEvent(Event.TOUCH_UP, index); + } + }) + .onHover((isHover: boolean) => { + let that = this; + let index = findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId()) + if (isHover) { + that.listNodeDataSource.handleEvent(Event.HOVER, index); + } else { + if (!that.listNodeDataSource.getIsTouchDown()) { + that.listNodeDataSource.handleEvent(Event.HOVER_OVER, index); + } + } + }) + .gesture( + TapGesture({ count: 2 }) // doubleClick + .onAction((event: GestureEvent) => { + let that = this; + that.listNodeDataSource.expandAndCollapseNode( + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + }) + ) + .height(item.getNodeHeight()) + .padding({ left: item.getNodeLeftPadding() }) + /* backgroundColor when editing and in other states. */ + .backgroundColor((item.getNodeItem().mainTitleNode && item.getNodeItem().inputText && + item.getIsShowInputText()) ? item.getNodeItem().inputText.editColor : item.getNodeColor()) + .border({ + width: item.getNodeBorder().borderWidth, + color: item.getNodeBorder().borderColor, + radius: item.getNodeBorder().borderRadius + }) + .bindContextMenu(this.builder, ResponseType.RightClick) + } + .opacity(this.listNodeDataSource.getListItemOpacity(item)) + .markAnchor({ x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBasePlateOffset }) + if (item.getCanShowBottomFlagLine()) { + if (this.listNodeDataSource.getPassIndex() == this.listNodeDataSource.totalCount() - 1 && + !item.getIsHighLight()) { + Divider() + .height(this.listNodeDataSource.getFlagLine().flagLineHeight) + .color(this.listNodeDataSource.getFlagLine().flagLineColor) + .visibility(Visibility.Visible) + .lineCap(LineCapStyle.Round) + .margin({ left: item.getFlagLineLeftMargin() }) + .markAnchor({ x: this.listNodeDataSource.getFlagLine().xOffset, + y: this.listNodeDataSource.getFlagLine().yBottomOffset }) + } + } + } + .focusable(true) + .onMouse((event: MouseEvent) => { + let that = this; + let thisIndex = findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId()); + if (event.button == MouseButton.Right) { + that.listNodeDataSource.handleEvent(Event.MOUSE_BUTTON_RIGHT, + findCurrentNodeIndex.call(that, item.getNodeCurrentNodeId())); + this.listTreeViewMenu = item.getMenu(); + that.listNodeDataSource.setClickIndex(thisIndex); + that.listNodeDataSource.setPopUpInfo(PopUpType.HINTS, InputError.NONE, false, thisIndex); + clearTimeout(item.getNodeItem().mainTitleNode.popUpTimeout); + } + event.stopPropagation(); + }) + .padding({ top: this.itemPadding.top, bottom: this.itemPadding.bottom }) + .bindPopup(item.getPopUpInfo().popUpIsShow, { + builder: this.popupForShowTitle(item.getPopUpInfo().popUpText, item.getPopUpInfo().popUpColor, + item.getPopUpInfo().popUpTextColor), + placement: Placement.BottomLeft, + placementOnTop: false, + popupColor: item.getPopUpInfo().popUpColor, + autoCancel: true, + enableArrow: item.getPopUpInfo().popUpEnableArrow + }) + } + + } + .width('100%').height(item.getListItemHeight()) + .padding({ left: this.itemPadding.left, right: this.itemPadding.right}) + .align(Alignment.Start) + .onDragStart((event: DragEvent, extraParams: string) => { + if (this.listNodeDataSource.getIsDrag() || this.listNodeDataSource.getIsInnerDrag() || this.isMultiPress) { + console.error('drag error, a item has been dragged'); + return; + } + this.dropSelectedIndex = JSON.parse(extraParams).selectedIndex; + let currentNodeIndex = JSON.parse(extraParams).selectedIndex; + let currentNodeInfo = this.listNodeDataSource.getData(currentNodeIndex); + let currentItemNodeId = item.getNodeCurrentNodeId(); + + /* handle the situation of drag error, currentNodeIndex is not found in onDragStart. */ + if (currentNodeIndex >= this.listNodeDataSource.totalCount() || currentNodeIndex == undefined) { + console.error('drag error, currentNodeIndex is not found in onDragStart'); + return; + } + + this.listNodeDataSource.setIsInnerDrag(true); + this.listNodeDataSource.setIsDrag(true); + this.listNodeDataSource.setCurrentNodeInfo(currentNodeInfo); + this.listNodeDataSource.setDraggingCurrentNodeId(currentNodeInfo.getNodeCurrentNodeId()); + this.listNodeDataSource.setDraggingParentNodeId(currentNodeInfo.getNodeParentNodeId()); + + /* set the opacity of the dragging node. */ + let draggingNodeOpacity: number = DRAG_OPACITY; + this.listNodeDataSource.setListItemOpacity(draggingNodeOpacity); + this.listNodeDataSource.notifyDataChange(currentNodeIndex); + + /* + * handle the situation of drag is too fast,it attribute a fault to OH. + * OH has Solved on real machine. + */ + if (currentItemNodeId != currentNodeInfo.getNodeCurrentNodeId()) { + console.error('drag is too fast,it attribute a fault to OH'); + this.listNodeDataSource.setIsDrag(false); + return; + } + return this.draggingPopup(currentNodeInfo); + }) + }, item => JSON.stringify(item)) + }.width(this.listTreeViewWidth).height(this.listTreeViewHeight) + + /* Move the dragged node. */ + .onDragMove((event: DragEvent) => { + if (this.isMultiPress) { + console.error('drag error, a item has been dragged'); + return; + } + let nodeHeight: number = LIST_ITEM_HEIGHT; + + /* flag the position of the focus on the node. */ + let flag: Flag = Math.floor(event.getY() / (nodeHeight / FLAG_NUMBER)) % FLAG_NUMBER ? Flag.DOWN_FLAG : Flag.UP_FLAG; + + /* Record the node position to which the dragged node moves. */ + let index: number = Math.floor(event.getY() / nodeHeight); + + /* Handle the situation where the focus(index) exceeds the list area. */ + let isOverBorder: boolean = false; + if (index >= this.listNodeDataSource.totalCount()) { + flag = Flag.DOWN_FLAG; + index = this.listNodeDataSource.totalCount() - 1; + this.listNodeDataSource.getData(index).setIsOverBorder(true); + isOverBorder = true; + } else { + this.listNodeDataSource.getData(index).setIsOverBorder(false); + } + + let currentNodeInfo: NodeInfo = this.listNodeDataSource.getData(index); + let currentNodeId: number = currentNodeInfo.getCurrentNodeId(); + + /* + * handle a situation that "draggingCurrentNodeId" is parent of "insertNodeCurrentNodeId"; + * do not perform some functions. + */ + if (index != this.listNodeDataSource.getLastPassIndex() && this.listNodeDataSource.getIsInnerDrag()) { + let isParentNodeOfInsertNode: boolean = this.listNodeDataSource.getIsParentOfInsertNode(currentNodeId); + if (isParentNodeOfInsertNode) { + this.listNodeDataSource.setPassIndex(index); + let that = this; + this.listNodeDataSource.clearTimeOutAboutDelayHighLightAndExpand(findCurrentNodeIndex.call(that, + currentNodeId)); + this.listNodeDataSource.setFlag(Flag.NONE); + return; + } + } + this.listNodeDataSource.setLastPassIndex(index); + + /* Set the visibility of the flag line. */ + this.listNodeDataSource.setVisibility(flag, index, isOverBorder); + + /* Automatically HighLight one second delay and expand after two second delay. */ + if (currentNodeId != this.listNodeDataSource.getDraggingCurrentNodeId()) { + let that = this; + this.listNodeDataSource.delayHighLightAndExpandNode(findCurrentNodeIndex.call(that, currentNodeId), + currentNodeId, index); + } + }) + + /* DragEvent Enter. */ + .onDragEnter((event: DragEvent, extraParams: string) => { + if (this.listNodeDataSource.getIsInnerDrag()) { + this.listNodeDataSource.setIsDrag(true); + + /* set the opacity of the dragging node. */ + let draggingNodeOpacity: number = DRAG_OPACITY; + this.listNodeDataSource.setListItemOpacity(draggingNodeOpacity); + } + }) + + /* DragEvent Leave. */ + .onDragLeave((event: DragEvent, extraParams: string) => { + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.clearLastTimeoutExpand(); + let draggingNodeOpacity: number = DRAG_OPACITY_NONE; + this.listNodeDataSource.setListItemOpacity(draggingNodeOpacity); + this.listNodeDataSource.setIsDrag(false); + this.listNodeDataSource.notifyDataReload(); + }) + + /* DragEvent Drop. */ + .onDrop((event: DragEvent, extraParams: string) => { + this.listNodeDataSource.clearLastTimeoutExpand(); + let draggingNodeOpacity: number = DRAG_OPACITY_NONE; + this.listNodeDataSource.setListItemOpacity(draggingNodeOpacity); + let insertNodeIndex: number = this.listNodeDataSource.getPassIndex(); + let currentNodeIndex: number = this.dropSelectedIndex; + + if (currentNodeIndex - 1 > this.listNodeDataSource.totalCount() || currentNodeIndex == undefined) { + console.error('drag error, currentNodeIndex is not found'); + this.listNodeDataSource.setIsDrag(false); + return; + } + + if (insertNodeIndex == this.listNodeDataSource.totalCount()) { + console.log('need to insert into the position of the last line, now insertNodeIndex = insertNodeIndex - 1'); + insertNodeIndex -= 1; + } + + let insertNodeInfo: NodeInfo = this.listNodeDataSource.getData(insertNodeIndex); + let insertNodeCurrentNodeId: number = insertNodeInfo.getNodeCurrentNodeId(); + + /* outer node is move in. */ + if (!this.listNodeDataSource.getIsDrag() || !this.listNodeDataSource.getIsInnerDrag()) { + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.setIsInnerDrag(false); + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.refreshSubtitle(insertNodeCurrentNodeId); + this.listNodeDataSource.notifyDataReload(); + return; + } + + let currentNodeInfo: NodeInfo = this.listNodeDataSource.getCurrentNodeInfo(); + let insertNodeParentNodeId: number = insertNodeInfo.getNodeParentNodeId(); + let draggingCurrentNodeId: number = this.listNodeDataSource.getDraggingCurrentNodeId(); + let draggingParentNodeId: number = this.listNodeDataSource.getDraggingParentNodeId(); + + /* + * handle a situation that "draggingCurrentNodeId" is parent of "insertNodeCurrentNodeId". + * drag is fail. + */ + let isParentNodeOfInsertNode: boolean = this.listNodeDataSource.getIsParentOfInsertNode(insertNodeCurrentNodeId); + if (isParentNodeOfInsertNode) { + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.setIsInnerDrag(false); + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.notifyDataChange(insertNodeIndex); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.setIsDrag(false); + + /* set the position of focus. */ + let that = this; + let currentFocusIndex: number = findCurrentNodeIndex.call(that, draggingCurrentNodeId); + this.listNodeDataSource.setClickIndex(currentFocusIndex); + this.listNodeDataSource.handleEvent(Event.DRAG, currentFocusIndex); + return; + } + + /* Collapse drag node. */ + if (this.listNodeDataSource.getExpandAndCollapseInfo(draggingCurrentNodeId) == NodeStatus.Expand) { + let that = this; + this.listNodeDataSource.expandAndCollapseNode( + findCurrentNodeIndex.call(that, draggingCurrentNodeId)); + } + + /* Expand insert node. */ + if (this.listNodeDataSource.getExpandAndCollapseInfo(insertNodeCurrentNodeId) == NodeStatus.Collapse) { + let that = this; + let currentIndex: number = findCurrentNodeIndex.call(that, insertNodeCurrentNodeId); + if (this.listNodeDataSource.ListNode[currentIndex].getIsHighLight()) { + this.listNodeDataSource.expandAndCollapseNode(currentIndex); + } + } + + /* alter dragNode. */ + this.listNodeDataSource.setLastDelayHighLightId(); + if (draggingCurrentNodeId != insertNodeCurrentNodeId) { + this.listNodeDataSource.alterDragNode(insertNodeParentNodeId, insertNodeCurrentNodeId, insertNodeInfo, + draggingParentNodeId, draggingCurrentNodeId, currentNodeInfo); + this.listNodeDataSource.hideLastLine(); + } else { + /*the position of dragNode is equal with the position of insertNode. */ + this.listNodeDataSource.hideLastLine(); + this.listNodeDataSource.setLastPassId(draggingCurrentNodeId); + this.listNodeDataSource.hideLastLine(); + } + + let that = this; + let lastDelayHighLightIndex: number = findCurrentNodeIndex.call(that, + this.listNodeDataSource.getLastDelayHighLightId()); + this.listNodeDataSource.setLastDelayHighLightIndex(lastDelayHighLightIndex); + this.listNodeDataSource.clearLastTimeoutHighLight(); + this.listNodeDataSource.initialParameterAboutDelayHighLightAndExpandIndex(); + this.listNodeDataSource.setIsDrag(false); + + /* set the position of focus. */ + let currentFocusIndex: number = findCurrentNodeIndex.call(that, draggingCurrentNodeId); + this.listNodeDataSource.setClickIndex(currentFocusIndex); + this.listNodeDataSource.handleEvent(Event.DRAG, currentFocusIndex); + + /* innerDrag is over. */ + this.listNodeDataSource.setIsInnerDrag(false); + this.listNodeDataSource.notifyDataReload(); + }) + } + } + + // Declare NodeParam + export interface NodeParam { + parentNodeId?: number, + currentNodeId?: number, + isFolder?: boolean, + icon?: Resource, + selectedIcon?: Resource, + editIcon? : Resource, + primaryTitle?: string, + secondaryTitle?: number | string, + menu?: () => void, + } + + + // Declare CallbackParam + export interface CallbackParam { + currentNodeId: number, + parentNodeId?: number, + childIndex?: number, + } + + /** + * Create a tree view control proxy class to generate a tree view. + * + * @since 10 + */ + export class TreeController { + readonly ROOT_NODE_ID: number = -1; + private nodeIdList: number[] = []; + private listNodeUtils : ListNodeUtils = new ListNodeUtils(); + private listNodeDataSource : ListNodeDataSource = new ListNodeDataSource(); + + /** + * After the addNode interface is invoked, + * this interface is used to obtain the initialization data of + * the tree view component for creating a tree view component. + * + * @return ListNodeDataSource Obtains the initialization data of the tree view component. + * + * @since 10 + */ + public getListNodeDataSource(): ListNodeDataSource { + return this.listNodeDataSource; + } + + /** + * Obtains the subNode information of the currently clicked node. + * + * @return Array Returns an array that stores the configuration information of each node. + * If there is no child node, an empty array is returned. + * + * @since 10 + */ + public getClickNodeChildrenInfo(): Array<{ itemId: number, itemIcon: Resource, itemTitle: string, + isFolder: boolean }> { + let clickNodeId = this.listNodeDataSource.getClickNodeId(); + return this.listNodeUtils.getClickNodeChildrenInfo(clickNodeId); + } + + public getChildrenId(): Array { + let clickNodeId = this.listNodeDataSource.getClickNodeId(); + return this.listNodeUtils.getClickChildId(clickNodeId); + } + + /** + * Delete a node. + * + * Register an ON_ITEM_DELETE callback through the EventBus mechanism to obtain the IDs of all deleted nodes. + * + * @since 10 + */ + public removeNode(): void { + let clickNodeId = this.listNodeDataSource.getClickNodeId(); + let parentNodeId = this.listNodeUtils.findParentNodeId(clickNodeId); + let removeNodeIdList: number[] = this.listNodeUtils.removeNode(clickNodeId, + parentNodeId, this.listNodeUtils.traverseNodeBF); + this.listNodeDataSource.refreshData(this.listNodeUtils, MenuOperation.REMOVE_NODE, parentNodeId, removeNodeIdList); + this.nodeIdList.splice(this.nodeIdList.indexOf(clickNodeId), 1); + } + + /** + * Modify the node name. + * + * Register an ON_ITEM_MODIFY callback to obtain the ID, parent node ID, and node name of the modified node. + * + * @since 10 + */ + public modifyNode(): void { + let clickNodeId = this.listNodeDataSource.getClickNodeId(); + this.listNodeDataSource.setItemVisibilityOnEdit(clickNodeId, MenuOperation.MODIFY_NODE); + } + + /** + * Add a node. + * + * Icon of a new node, which is generated by the system by default. + * If there is a same-level node, the icon of the first node of the same-level node is used. + * If no icon is set for the first node of the same-level node, the new node does not have an icon. + * If there is no peer node, the icon of the parent node is used. + * If no icon is set for the parent node, the new node does not have an icon. + * The system generates an ID for the new node and registers an ON_ITEM_ADD callback through + * the EventBus mechanism to obtain the ID, parent node ID, node name, normal icon, selected icon, + * edit icon of the new node. + * + * @since 10 + */ + public add(): void { + let clickNodeId: number = this.listNodeDataSource.getClickNodeId(); + if (clickNodeId == this.listNodeDataSource.ROOT_NODE_ID || !this.listNodeDataSource.getIsFolder(clickNodeId)) { + return; + } + let newNodeInfo: { isFolder: boolean, icon: Resource, selectedIcon: Resource, editIcon: Resource, + menu: () =>any, secondaryTitle: number | string } = + { isFolder: true, icon: null, selectedIcon: null, editIcon: null, menu: null, secondaryTitle: '' }; + newNodeInfo = this.listNodeUtils.getNewNodeInfo(clickNodeId); + this.nodeIdList.push(this.nodeIdList[this.nodeIdList.length - 1] + 1); + let newNodeId: number = this.nodeIdList[this.nodeIdList.length - 1]; + this.listNodeUtils.addNewNodeId = newNodeId; + this.listNodeUtils.addNode(clickNodeId, newNodeId, + { isFolder: newNodeInfo.isFolder, icon: newNodeInfo.icon, selectedIcon: newNodeInfo.selectedIcon, + editIcon: newNodeInfo.editIcon, primaryTitle: '新建文件夹', menu: newNodeInfo.menu, + secondaryTitle: newNodeInfo.secondaryTitle }); + this.listNodeDataSource.refreshData(this.listNodeUtils, MenuOperation.ADD_NODE, clickNodeId, [newNodeId]); + } + + public addNodeParam(nodeParam: NodeParam): TreeController { + if (nodeParam.primaryTitle != null && + !this.listNodeUtils.checkMainTitleIsValid(nodeParam.primaryTitle)) { + throw new Error('ListTreeNode[addNode]: ' + + 'The directory name cannot contain the following characters\ /: *? "< > | or exceeds the maximum length.'); + return null; + } + if (nodeParam.primaryTitle == null && nodeParam.icon == null) { + throw new Error('ListTreeNode[addNode]: ' + + 'The icon and directory name cannot be empty at the same time.'); + return null; + } + if (nodeParam.currentNodeId === this.ROOT_NODE_ID || nodeParam.currentNodeId === null) { + throw new Error('ListTreeNode[addNode]: currentNodeId can not be -1 or null.'); + return null; + } + this.nodeIdList.push(nodeParam.currentNodeId); + this.listNodeUtils.addNode(nodeParam.parentNodeId, nodeParam.currentNodeId, nodeParam); + return this; + } + + /** + * Initialize the interface of the tree view. This interface is used to generate ListNodeDataSource data. + * addNode is only designed for initialization. It can only be invoked during initialization. + * + * A maximum of 50 directory levels can be added. + * + * @param parentNodeId ID of the parent node. + * @param currentNodeId ID of the new node. The value cannot be -1 or null. + * @param nodeParam Configuration information of the newly added node. + * For details, see the comment description of NodeParam. + * @return ListTreeNode Tree view component proxy class. + * + * @since 10 + */ + public addNode(nodeParam?: NodeParam): TreeController { + if (nodeParam == null) { + this.add(); + } else { + if (nodeParam.primaryTitle != null && + !this.listNodeUtils.checkMainTitleIsValid(nodeParam.primaryTitle)) { + throw new Error('ListTreeNode[addNode]: ' + + 'The directory name cannot contain the following characters\ /: *? "< > | or exceeds the maximum length.'); + return null; + } + if (nodeParam.primaryTitle == null && nodeParam.icon == null) { + throw new Error('ListTreeNode[addNode]: ' + + 'The icon and directory name cannot be empty at the same time.'); + return null; + } + if (nodeParam.currentNodeId === this.ROOT_NODE_ID || nodeParam.currentNodeId === null) { + throw new Error('ListTreeNode[addNode]: currentNodeId can not be -1 or null.'); + return null; + } + this.nodeIdList.push(nodeParam.currentNodeId); + this.listNodeUtils.addNode(nodeParam.parentNodeId, nodeParam.currentNodeId, nodeParam); + return this; + } + } + + /** + * After the initialization is complete by calling the addNode interface, + * call this interface to complete initialization. + * + * This interface must be called when you finish initializing the ListTreeView by addNode. + * @since 10 + */ + public buildDone() { + this.listNodeDataSource.init(this.listNodeUtils); + this.nodeIdList.sort((a, b) => a - b); + } + + public refreshNode(parentId: number, parentSubTitle: ResourceStr = '', + currentSubtitle: ResourceStr = '') { + this.listNodeDataSource.setNodeSubtitlePara(parentId, parentSubTitle, currentSubtitle); + } + } +} \ No newline at end of file