bkui-vue 2.1.0-dev-beta.9 → 2.1.0-dev-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tree/index.js CHANGED
@@ -17505,6 +17505,7 @@ var EVENTS;
17505
17505
  EVENTS["NODE_CHECKED"] = "nodeChecked";
17506
17506
  EVENTS["NODE_CLICK"] = "nodeClick";
17507
17507
  EVENTS["NODE_COLLAPSE"] = "nodeCollapse";
17508
+ EVENTS["NODE_DATA_CHANGE"] = "nodeDataChange";
17508
17509
  EVENTS["NODE_DRAG_LEAVE"] = "nodeDragLeave";
17509
17510
  EVENTS["NODE_DRAG_OVER"] = "nodeDragOver";
17510
17511
  EVENTS["NODE_DRAG_SORT"] = "nodeDragSort";
@@ -17517,7 +17518,7 @@ var EVENTS;
17517
17518
  var EMPTY = function EMPTY() {
17518
17519
  return true;
17519
17520
  };
17520
- var TreeEmitEventsType = (_TreeEmitEventsType = {}, defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(_TreeEmitEventsType, EVENTS.NODE_ASYNC_LOAD, EMPTY), EVENTS.NODE_ASYNC_LOAD_ERROR, EMPTY), EVENTS.NODE_CLICK, EMPTY), EVENTS.NODE_COLLAPSE, EMPTY), EVENTS.NODE_EXPAND, EMPTY), EVENTS.NODE_CHECKED, EMPTY), EVENTS.NODE_DRAG_START, EMPTY), EVENTS.NODE_DRAG_OVER, EMPTY), EVENTS.NODE_DRAG_LEAVE, EMPTY), EVENTS.NODE_DRAG_SORT, EMPTY), defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(_TreeEmitEventsType, EVENTS.NODE_DROP, EMPTY), EVENTS.NODE_ENTER_VIEW, EMPTY), EVENTS.NODE_SELECTED, EMPTY));
17521
+ var TreeEmitEventsType = (_TreeEmitEventsType = {}, defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(_TreeEmitEventsType, EVENTS.NODE_ASYNC_LOAD, EMPTY), EVENTS.NODE_ASYNC_LOAD_ERROR, EMPTY), EVENTS.NODE_CLICK, EMPTY), EVENTS.NODE_COLLAPSE, EMPTY), EVENTS.NODE_EXPAND, EMPTY), EVENTS.NODE_CHECKED, EMPTY), EVENTS.NODE_DATA_CHANGE, EMPTY), EVENTS.NODE_DRAG_START, EMPTY), EVENTS.NODE_DRAG_OVER, EMPTY), EVENTS.NODE_DRAG_LEAVE, EMPTY), defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(defineProperty_defineProperty(_TreeEmitEventsType, EVENTS.NODE_DRAG_SORT, EMPTY), EVENTS.NODE_DROP, EMPTY), EVENTS.NODE_ENTER_VIEW, EMPTY), EVENTS.NODE_SELECTED, EMPTY));
17521
17522
  /**
17522
17523
  * 节点扩展属性
17523
17524
  */
@@ -17590,7 +17591,7 @@ var treeProps = {
17590
17591
  label: shared_namespaceObject.PropTypes.oneOfType([shared_namespaceObject.PropTypes.func.def(undefined), shared_namespaceObject.PropTypes.string.def('label')]),
17591
17592
  /**
17592
17593
  * 每个树节点用来作为唯一标识的属性,此标识应该是唯一的
17593
- * 启用拖拽、异步、受控选中/勾选等复杂能力时强烈建议显式设置
17594
+ * 如果设置系统会默认自动生成唯一id
17594
17595
  */
17595
17596
  nodeKey: shared_namespaceObject.PropTypes.string.def(undefined),
17596
17597
  /**
@@ -17780,18 +17781,13 @@ var treeProps = {
17780
17781
  */
17781
17782
  keepSlotData: shared_namespaceObject.PropTypes.bool.def(false),
17782
17783
  /**
17783
- * 是否启用父子节点勾选联动
17784
- * true: 父子联动
17785
- * false: 父子不联动(语义与行业常见 checkStrictly 相反,为兼容历史行为暂保留)
17784
+ * 在显示复选框的情况下,是否严格的遵循父子互相关联的做法
17786
17785
  */
17787
17786
  checkStrictly: shared_namespaceObject.PropTypes.bool.def(true),
17788
17787
  /**
17789
- * 是否深度监听 props.data 变化
17790
- * - false (默认): 仅监听 props.data 引用变化,性能更优
17791
- * - true: 深度监听 props.data 内部节点变化(已废弃,将在下个主版本移除)
17792
- * @deprecated 请使用 onDataChange 回调更新数据,避免直接修改 props.data 内部节点
17788
+ * 是否开启父子勾选级联;未传时沿用 checkStrictly 历史语义
17793
17789
  */
17794
- deepWatch: shared_namespaceObject.PropTypes.bool.def(false),
17790
+ cascade: shared_namespaceObject.PropTypes.bool.def(undefined),
17795
17791
  /**
17796
17792
  * 是否开启监听Tree节点进入Tree容器可视区域
17797
17793
  */
@@ -18041,16 +18037,10 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18041
18037
  var getSchemaVal = function getSchemaVal(node) {
18042
18038
  return flatData.schema.get(node);
18043
18039
  };
18044
- /**
18045
- * 获取节点属性
18046
- * @param node 当前节点
18047
- * @param attr 节点属性
18048
- * @returns
18049
- */
18050
- var getNodeAttr = function getNodeAttr(node, attr) {
18040
+ function getNodeAttr(node, attr) {
18051
18041
  var _getSchemaVal;
18052
- return (_getSchemaVal = getSchemaVal(node)) === null || _getSchemaVal === void 0 ? void 0 : _getSchemaVal[attr];
18053
- };
18042
+ return node ? (_getSchemaVal = getSchemaVal(node)) === null || _getSchemaVal === void 0 ? void 0 : _getSchemaVal[attr] : undefined;
18043
+ }
18054
18044
  /**
18055
18045
  * 设置节点属性
18056
18046
  * @param node 指定节点
@@ -18066,8 +18056,9 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18066
18056
  flatData.schema.set(node, Object.assign({}, getSchemaVal(node), defineProperty_defineProperty({}, attr, val)));
18067
18057
  };
18068
18058
  var getNodeById = function getNodeById(id) {
18069
- return flatData.data.find(function (item) {
18070
- return getNodeId(item) === id;
18059
+ var _flatData$nodeMap$get, _flatData$nodeMap;
18060
+ return (_flatData$nodeMap$get = (_flatData$nodeMap = flatData.nodeMap) === null || _flatData$nodeMap === void 0 ? void 0 : _flatData$nodeMap.get("".concat(id))) !== null && _flatData$nodeMap$get !== void 0 ? _flatData$nodeMap$get : flatData.data.find(function (item) {
18061
+ return "".concat(getNodeId(item)) === "".concat(id);
18071
18062
  });
18072
18063
  };
18073
18064
  var setNodeAttrById = function setNodeAttrById(id, attr, val) {
@@ -18086,33 +18077,31 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18086
18077
  return getNodeAttr(node, NODE_ATTRIBUTES.UUID);
18087
18078
  };
18088
18079
  var isNodeOpened = function isNodeOpened(node) {
18089
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_OPEN);
18080
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_OPEN);
18090
18081
  };
18091
18082
  var hasChildNode = function hasChildNode(node) {
18092
- return getNodeAttr(node, NODE_ATTRIBUTES.HAS_CHILD);
18083
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.HAS_CHILD);
18093
18084
  };
18094
18085
  var isNodeMatched = function isNodeMatched(node) {
18095
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_MATCH);
18086
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_MATCH);
18096
18087
  };
18097
18088
  var isNodeChecked = function isNodeChecked(node) {
18098
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_CHECKED);
18089
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_CHECKED);
18099
18090
  };
18100
18091
  var getNodeParentId = function getNodeParentId(node) {
18101
18092
  return getNodeAttr(getNodeAttr(node, NODE_ATTRIBUTES.PARENT), NODE_ATTRIBUTES.UUID);
18102
18093
  };
18103
18094
  var isNodeLoading = function isNodeLoading(node) {
18104
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_LOADING);
18095
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_LOADING);
18105
18096
  };
18106
18097
  var getParentNode = function getParentNode(node) {
18107
18098
  return getNodeAttr(node, NODE_ATTRIBUTES.PARENT);
18108
18099
  };
18109
18100
  var isMatchedNode = function isMatchedNode(node) {
18110
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_MATCH);
18101
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_MATCH);
18111
18102
  };
18112
18103
  var getNodeAttrById = function getNodeAttrById(id, attr) {
18113
- var target = flatData.data.find(function (item) {
18114
- return getNodeId(item) === id;
18115
- });
18104
+ var target = getNodeById(id);
18116
18105
  return getNodeAttr(target, attr);
18117
18106
  };
18118
18107
  /**
@@ -18133,20 +18122,16 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18133
18122
  };
18134
18123
  var isRootNode = function isRootNode(node) {
18135
18124
  if (typeof node === 'string') {
18136
- return getNodeAttrById(node, NODE_ATTRIBUTES.IS_ROOT);
18125
+ return !!getNodeAttrById(node, NODE_ATTRIBUTES.IS_ROOT);
18137
18126
  }
18138
- return getNodeAttr(node, NODE_ATTRIBUTES.IS_ROOT);
18127
+ return !!getNodeAttr(node, NODE_ATTRIBUTES.IS_ROOT);
18139
18128
  };
18140
18129
  var getNodeParentIdById = function getNodeParentIdById(id) {
18141
- var target = flatData.data.find(function (item) {
18142
- return getNodeId(item) === id;
18143
- });
18130
+ var target = getNodeById(id);
18144
18131
  return getNodeParentId(target);
18145
18132
  };
18146
18133
  var getNodePathById = function getNodePathById(id) {
18147
- var target = flatData.data.find(function (item) {
18148
- return getNodeId(item) === id;
18149
- });
18134
+ var target = getNodeById(id);
18150
18135
  return getNodePath(target);
18151
18136
  };
18152
18137
  var setTreeNodeLoading = function setTreeNodeLoading(node, value) {
@@ -18199,18 +18184,13 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18199
18184
  return target;
18200
18185
  };
18201
18186
  var getChildNodes = function getChildNodes(node) {
18202
- var children = [];
18203
- flatData.data.forEach(function (item) {
18204
- if (getParentNode(item) === node) {
18205
- children.push(item);
18206
- }
18187
+ var _flatData$childMap$ge, _flatData$childMap;
18188
+ return (_flatData$childMap$ge = (_flatData$childMap = flatData.childMap) === null || _flatData$childMap === void 0 ? void 0 : _flatData$childMap.get(node)) !== null && _flatData$childMap$ge !== void 0 ? _flatData$childMap$ge : flatData.data.filter(function (item) {
18189
+ return getParentNode(item) === node;
18207
18190
  });
18208
- return children;
18209
18191
  };
18210
18192
  var getSourceNodeByUID = function getSourceNodeByUID(uid) {
18211
- return flatData.data.find(function (item) {
18212
- return getNodeId(item) === uid;
18213
- });
18193
+ return getNodeById(uid);
18214
18194
  };
18215
18195
  var getParentNodeData = function getParentNodeData(node) {
18216
18196
  var target = node;
@@ -18245,7 +18225,6 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18245
18225
  * @returns
18246
18226
  */
18247
18227
  var getIntersectionResponse = function getIntersectionResponse(target) {
18248
- var _parent$props$childre;
18249
18228
  if (!target) {
18250
18229
  return null;
18251
18230
  }
@@ -18256,7 +18235,8 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18256
18235
  var level = getNodeAttr(node, NODE_ATTRIBUTES.DEPTH);
18257
18236
  var isRoot = getNodeAttr(node, NODE_ATTRIBUTES.IS_ROOT);
18258
18237
  var parent = getNodeAttr(node, NODE_ATTRIBUTES.PARENT);
18259
- var index = isRoot ? getNodeAttr(node, NODE_ATTRIBUTES.INDEX) : parent === null || parent === void 0 || (_parent$props$childre = parent[props.children]) === null || _parent$props$childre === void 0 ? void 0 : _parent$props$childre.findIndex(function (child) {
18238
+ var children = parent === null || parent === void 0 ? void 0 : parent[props.children];
18239
+ var index = isRoot ? getNodeAttr(node, NODE_ATTRIBUTES.INDEX) : children === null || children === void 0 ? void 0 : children.findIndex(function (child) {
18260
18240
  return child === node;
18261
18241
  });
18262
18242
  return {
@@ -18269,7 +18249,8 @@ const icon_namespaceObject = icon_x({ ["DownShape"]: () => __WEBPACK_EXTERNAL_MO
18269
18249
  };
18270
18250
  };
18271
18251
  var getRootNodeList = function getRootNodeList() {
18272
- return flatData.data.filter(function (item) {
18252
+ var _flatData$rootNodes;
18253
+ return (_flatData$rootNodes = flatData.rootNodes) !== null && _flatData$rootNodes !== void 0 ? _flatData$rootNodes : flatData.data.filter(function (item) {
18273
18254
  return isRootNode(item);
18274
18255
  });
18275
18256
  };
@@ -18374,23 +18355,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
18374
18355
 
18375
18356
 
18376
18357
  var DEFAULT_LEVLE_LINE = '1px dashed #c3cdd7';
18377
- var _cloneTreeNode = function cloneTreeNode(node) {
18378
- if (Array.isArray(node)) {
18379
- return node.map(function (item) {
18380
- return _cloneTreeNode(item);
18381
- });
18382
- }
18383
- if (node && _typeof(node) === 'object') {
18384
- return Object.keys(node).reduce(function (acc, key) {
18385
- var value = node[key];
18386
- acc[key] = Array.isArray(value) ? value.map(function (item) {
18387
- return _cloneTreeNode(item);
18388
- }) : value;
18389
- return acc;
18390
- }, {});
18391
- }
18392
- return node;
18393
- };
18394
18358
  /**
18395
18359
  * 获取配置项可为Bool|String|Function类型,如果为Bool则配置默认值
18396
18360
  * @param props
@@ -18515,11 +18479,13 @@ var getNodeRowClass = function getNodeRowClass(item, schema) {
18515
18479
  // eslint-disable-next-line @typescript-eslint/naming-convention
18516
18480
  var _ref3 = schema.get(item) || {},
18517
18481
  __is_checked = _ref3.__is_checked,
18482
+ __is_indeterminate = _ref3.__is_indeterminate,
18518
18483
  __is_selected = _ref3.__is_selected;
18519
18484
  var _usePrefix2 = (0,config_provider_namespaceObject.usePrefix)(),
18520
18485
  resolveClassName = _usePrefix2.resolveClassName;
18521
18486
  return defineProperty_defineProperty({
18522
18487
  'is-checked': __is_checked,
18488
+ 'is-indeterminate': __is_indeterminate,
18523
18489
  'is-selected': __is_selected,
18524
18490
  'node-folder': item.is_folder,
18525
18491
  'node-leaf': item.is_leaf
@@ -18536,6 +18502,21 @@ var getNodeRowClass = function getNodeRowClass(item, schema) {
18536
18502
  var updateTreeNode = function updateTreeNode(path, treeData, childKey, nodekey, nodeValue) {
18537
18503
  assignTreeNode(path, treeData, childKey, _defineProperty({}, nodekey, nodeValue));
18538
18504
  };
18505
+ var _cloneTreeNode = function cloneTreeNode(node) {
18506
+ if (Array.isArray(node)) {
18507
+ return node.map(function (item) {
18508
+ return _cloneTreeNode(item);
18509
+ });
18510
+ }
18511
+ if (node && _typeof(node) === 'object') {
18512
+ return Object.keys(node).reduce(function (acc, key) {
18513
+ var value = node[key];
18514
+ acc[key] = Array.isArray(value) ? value.slice() : value;
18515
+ return acc;
18516
+ }, {});
18517
+ }
18518
+ return node;
18519
+ };
18539
18520
  var _cloneTreeData = function cloneTreeData() {
18540
18521
  var treeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
18541
18522
  var childKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'children';
@@ -18548,6 +18529,15 @@ var _cloneTreeData = function cloneTreeData() {
18548
18529
  });
18549
18530
  };
18550
18531
 
18532
+ var isSameNodeId = function isSameNodeId(left, right) {
18533
+ if (left === right) {
18534
+ return true;
18535
+ }
18536
+ if (left === undefined || left === null || right === undefined || right === null) {
18537
+ return false;
18538
+ }
18539
+ return "".concat(left) === "".concat(right);
18540
+ };
18551
18541
  var _findNodeById = function findNodeById() {
18552
18542
  var treeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
18553
18543
  var nodeId = arguments.length > 1 ? arguments[1] : undefined;
@@ -18558,7 +18548,7 @@ var _findNodeById = function findNodeById() {
18558
18548
  try {
18559
18549
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
18560
18550
  var node = _step.value;
18561
- if ((node === null || node === void 0 ? void 0 : node[nodeKey]) === nodeId) {
18551
+ if (isSameNodeId(node === null || node === void 0 ? void 0 : node[nodeKey], nodeId)) {
18562
18552
  return node;
18563
18553
  }
18564
18554
  var children = node === null || node === void 0 ? void 0 : node[childKey];
@@ -18597,7 +18587,7 @@ var removeTreeNodeById = function removeTreeNodeById() {
18597
18587
  var _loop = function loop(list, parentNode) {
18598
18588
  for (var index = 0; index < list.length; index++) {
18599
18589
  var current = list[index];
18600
- if ((current === null || current === void 0 ? void 0 : current[nodeKey]) === nodeId) {
18590
+ if (isSameNodeId(current === null || current === void 0 ? void 0 : current[nodeKey], nodeId)) {
18601
18591
  var _list$splice = list.splice(index, 1),
18602
18592
  _list$splice2 = _slicedToArray(_list$splice, 1),
18603
18593
  node = _list$splice2[0];
@@ -18661,7 +18651,7 @@ var insertTreeNodeById = function insertTreeNodeById() {
18661
18651
  var _loop2 = function loop(list, parentNode) {
18662
18652
  for (var index = 0; index < list.length; index++) {
18663
18653
  var current = list[index];
18664
- if ((current === null || current === void 0 ? void 0 : current[nodeKey]) === targetNodeId) {
18654
+ if (isSameNodeId(current === null || current === void 0 ? void 0 : current[nodeKey], targetNodeId)) {
18665
18655
  var insertIndex = willInsertAfter ? index + 1 : index;
18666
18656
  list.splice(insertIndex, 0, node);
18667
18657
  return {
@@ -18702,7 +18692,7 @@ var moveTreeNodeById = function moveTreeNodeById() {
18702
18692
  return null;
18703
18693
  }
18704
18694
  var insertResult = insertTreeNodeById(nextTreeData, removeResult.node, targetNodeId, nodeKey, childKey, options);
18705
- if (!insertResult.targetNode && options.dropType !== 'child') {
18695
+ if (!insertResult.targetNode) {
18706
18696
  return null;
18707
18697
  }
18708
18698
  return {
@@ -18735,7 +18725,9 @@ var assignTreeNode = function assignTreeNode(path, treeData, childKey, assignVal
18735
18725
  var resolveNodeItem = function resolveNodeItem(node) {
18736
18726
  if (node === undefined || node === null) {
18737
18727
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
18738
- return defineProperty_defineProperty({}, NODE_ATTRIBUTES.IS_NULL, true);
18728
+ return {
18729
+ __IS_NULL: true
18730
+ };
18739
18731
  }
18740
18732
  return node;
18741
18733
  };
@@ -18746,7 +18738,7 @@ var _resolvePropIsMatched = function resolvePropIsMatched(node, prop, id) {
18746
18738
  });
18747
18739
  }
18748
18740
  if (typeof prop === 'string' || typeof prop === 'number') {
18749
- return prop === id;
18741
+ return isSameNodeId(prop, id);
18750
18742
  }
18751
18743
  return node === prop;
18752
18744
  };
@@ -18757,8 +18749,15 @@ var showCheckbox = function showCheckbox(props, node) {
18757
18749
  }
18758
18750
  return props.showCheckbox;
18759
18751
  };
18752
+ var isCascadeEnabled = function isCascadeEnabled(props) {
18753
+ if (typeof props.cascade === 'boolean') {
18754
+ return props.cascade;
18755
+ }
18756
+ return !!props.checkStrictly;
18757
+ };
18760
18758
  ;// CONCATENATED MODULE: ../../packages/tree/src/use-node-async.tsx
18761
18759
 
18760
+
18762
18761
  /*
18763
18762
  * Tencent is pleased to support the open source community by making
18764
18763
  * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
@@ -18766,55 +18765,52 @@ var showCheckbox = function showCheckbox(props, node) {
18766
18765
  * Copyright (C) 2025 Tencent. All rights reserved.
18767
18766
  *
18768
18767
  * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
18769
- *
18770
- * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
18771
- *
18772
- * ---------------------------------------------------
18773
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
18774
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
18775
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
18776
- * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18777
- *
18778
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
18779
- * the Software.
18780
- *
18781
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
18782
- * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18783
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18784
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18785
- * IN THE SOFTWARE.
18786
18768
  */
18787
18769
 
18788
18770
 
18789
18771
 
18790
18772
  /* harmony default export */ const use_node_async = (function (props, flatData, ctx) {
18773
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
18791
18774
  var _useNodeAttribute = use_node_attribute(flatData, props),
18792
18775
  setNodeAttr = _useNodeAttribute.setNodeAttr,
18793
18776
  getNodeId = _useNodeAttribute.getNodeId,
18777
+ getNodePath = _useNodeAttribute.getNodePath,
18794
18778
  getNodeAttr = _useNodeAttribute.getNodeAttr,
18795
18779
  resolveScopedSlotParam = _useNodeAttribute.resolveScopedSlotParam,
18796
18780
  setTreeNodeLoading = _useNodeAttribute.setTreeNodeLoading;
18797
18781
  var requestVersionMap = new Map();
18798
18782
  var emitTreeDataChange = function emitTreeDataChange(payload) {
18799
- var _props$onDataChange;
18800
- (_props$onDataChange = props.onDataChange) === null || _props$onDataChange === void 0 || _props$onDataChange.call(props, payload);
18783
+ var _options$onTreeDataCh;
18784
+ (_options$onTreeDataCh = options.onTreeDataChange) === null || _options$onTreeDataCh === void 0 || _options$onTreeDataCh.call(options, payload);
18801
18785
  ctx === null || ctx === void 0 || ctx.emit(EVENTS.NODE_ASYNC_LOAD, payload);
18802
18786
  };
18803
- /**
18804
- * 处理异步加载节点数据返回结果
18805
- * @param resp 异步请求返回结果
18806
- * @param item 当前节点
18807
- */
18808
18787
  var setNodeRemoteLoad = function setNodeRemoteLoad(resp, item, requestVersion) {
18809
18788
  if (_typeof(resp) === 'object' && resp !== null) {
18810
- var nodeId = getNodeId(item);
18789
+ var _options$getTreeData, _options$getTreeData2;
18790
+ var nodeId = "".concat(getNodeId(item));
18811
18791
  if (requestVersion !== undefined && requestVersionMap.get(nodeId) !== requestVersion) {
18812
18792
  return Promise.resolve(resp);
18813
18793
  }
18814
18794
  setNodeAttr(item, NODE_ATTRIBUTES.IS_OPEN, true);
18815
18795
  var nodeValue = Array.isArray(resp) ? resp : [resp];
18816
- var nextTreeData = _cloneTreeData(props.data, props.children);
18796
+ if (!options.onTreeDataChange) {
18797
+ mutateTreeById(props.data, nodeId, props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, function (targetNode) {
18798
+ targetNode[props.children] = nodeValue;
18799
+ });
18800
+ if (!props.nodeKey && getNodePath(item)) {
18801
+ // nodeKey 缺失时保留旧版按 path 写入的兜底行为。
18802
+ var paths = "".concat(getNodePath(item)).split('-');
18803
+ var targetNode = paths.reduce(function (pre, nodeIndex) {
18804
+ var index = Number(nodeIndex);
18805
+ return Array.isArray(pre) ? pre[index] : pre[props.children][index];
18806
+ }, props.data);
18807
+ Object.assign(targetNode, defineProperty_defineProperty({}, props.children, nodeValue));
18808
+ }
18809
+ return Promise.resolve(resp);
18810
+ }
18811
+ var nextTreeData = _cloneTreeData((_options$getTreeData = (_options$getTreeData2 = options.getTreeData) === null || _options$getTreeData2 === void 0 ? void 0 : _options$getTreeData2.call(options)) !== null && _options$getTreeData !== void 0 ? _options$getTreeData : props.data, props.children);
18817
18812
  mutateTreeById(nextTreeData, nodeId, props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, function (targetNode) {
18813
+ targetNode[NODE_SOURCE_ATTRS[NODE_ATTRIBUTES.IS_OPEN]] = true;
18818
18814
  targetNode[props.children] = nodeValue;
18819
18815
  });
18820
18816
  emitTreeDataChange({
@@ -18834,7 +18830,7 @@ var showCheckbox = function showCheckbox(props, node) {
18834
18830
  _ref$cache = _ref.cache,
18835
18831
  cache = _ref$cache === void 0 ? true : _ref$cache;
18836
18832
  if (typeof callback === 'function' && getNodeAttr(item, NODE_ATTRIBUTES.IS_ASYNC)) {
18837
- var nodeId = getNodeId(item);
18833
+ var nodeId = "".concat(getNodeId(item));
18838
18834
  var requestVersion = (requestVersionMap.get(nodeId) || 0) + 1;
18839
18835
  requestVersionMap.set(nodeId, requestVersion);
18840
18836
  setNodeAttr(item, NODE_ATTRIBUTES.IS_ASYNC_INIT, true);
@@ -18849,11 +18845,11 @@ var showCheckbox = function showCheckbox(props, node) {
18849
18845
  if (callbackResult instanceof Promise) {
18850
18846
  return Promise.resolve(callbackResult.then(function (resp) {
18851
18847
  return setNodeRemoteLoad(resp, item, requestVersion);
18852
- })["catch"](function (err) {
18848
+ })["catch"](function (error) {
18853
18849
  if (requestVersionMap.get(nodeId) === requestVersion) {
18854
18850
  ctx === null || ctx === void 0 || ctx.emit(EVENTS.NODE_ASYNC_LOAD_ERROR, {
18855
18851
  node: item,
18856
- error: err,
18852
+ error: error,
18857
18853
  requestVersion: requestVersion
18858
18854
  });
18859
18855
  }
@@ -18875,7 +18871,6 @@ var showCheckbox = function showCheckbox(props, node) {
18875
18871
  return Promise.resolve(true);
18876
18872
  };
18877
18873
  var _deepAutoOpen = function deepAutoOpen() {
18878
- /** 过滤节点为异步加载 & 默认为展开 & 没有初始化过的节点 */
18879
18874
  var autoOpenNodes = flatData.data.filter(function (item) {
18880
18875
  return getNodeAttr(item, NODE_ATTRIBUTES.IS_ASYNC) && item[NODE_SOURCE_ATTRS[NODE_ATTRIBUTES.IS_OPEN]] && !getNodeAttr(item, NODE_ATTRIBUTES.IS_ASYNC_INIT);
18881
18876
  });
@@ -18934,10 +18929,6 @@ var use_node_action_this = undefined;
18934
18929
 
18935
18930
  /* harmony default export */ const use_node_action = (function (props, ctx, flatData, _renderData, initOption) {
18936
18931
  // const checkedNodes = [];
18937
- var getSelectedNodeId = function getSelectedNodeId() {
18938
- var _props$selected;
18939
- return (_props$selected = props.selected) !== null && _props$selected !== void 0 ? _props$selected : selectedNodeId;
18940
- };
18941
18932
  var selectedNodeId = props.selected;
18942
18933
  var _useNodeAttribute = use_node_attribute(flatData, props),
18943
18934
  setNodeAttr = _useNodeAttribute.setNodeAttr,
@@ -18960,7 +18951,7 @@ var use_node_action_this = undefined;
18960
18951
  var _usePrefix = (0,config_provider_namespaceObject.usePrefix)(),
18961
18952
  resolveClassName = _usePrefix.resolveClassName;
18962
18953
  var registerNextLoop = initOption.registerNextLoop;
18963
- var _useNodeAsync = use_node_async(props, flatData, ctx),
18954
+ var _useNodeAsync = use_node_async(props, flatData, ctx, initOption),
18964
18955
  asyncNodeClick = _useNodeAsync.asyncNodeClick,
18965
18956
  deepAutoOpen = _useNodeAsync.deepAutoOpen;
18966
18957
  /**
@@ -19062,17 +19053,18 @@ var use_node_action_this = undefined;
19062
19053
  };
19063
19054
  var _updateParentChecked = function updateParentChecked(item, isChecked) {
19064
19055
  var parent = getParentNode(item);
19065
- if (parent) {
19066
- var isNeedChecked = isChecked ? isChecked : (getChildNodes(parent) || []).some(function (node) {
19067
- return isNodeChecked(node);
19068
- });
19069
- setNodeAttr(parent, NODE_ATTRIBUTES.IS_CHECKED, isNeedChecked);
19070
- setNodeAttr(parent, NODE_ATTRIBUTES.IS_INDETERMINATE, (getChildNodes(parent) || []).some(function (node) {
19071
- return !isNodeChecked(node) || isIndeterminate(node);
19072
- }));
19073
- if (!isRootNode(parent)) {
19074
- _updateParentChecked(parent, isChecked);
19075
- }
19056
+ if (!parent) {
19057
+ return;
19058
+ }
19059
+ var isNeedChecked = isChecked ? isChecked : (getChildNodes(parent) || []).some(function (node) {
19060
+ return isNodeChecked(node);
19061
+ });
19062
+ setNodeAttr(parent, NODE_ATTRIBUTES.IS_CHECKED, isNeedChecked);
19063
+ setNodeAttr(parent, NODE_ATTRIBUTES.IS_INDETERMINATE, (getChildNodes(parent) || []).some(function (node) {
19064
+ return !isNodeChecked(node) || isIndeterminate(node);
19065
+ }));
19066
+ if (!isRootNode(parent)) {
19067
+ _updateParentChecked(parent, isChecked);
19076
19068
  }
19077
19069
  };
19078
19070
  var _deepUpdateChildNode = function deepUpdateChildNode(node, attr, value) {
@@ -19103,7 +19095,6 @@ var use_node_action_this = undefined;
19103
19095
  if (value) {
19104
19096
  setNodeAttr(item, NODE_ATTRIBUTES.IS_INDETERMINATE, false);
19105
19097
  }
19106
- // 历史语义:checkStrictly=true 表示启用父子联动
19107
19098
  if (props.checkStrictly) {
19108
19099
  _deepUpdateChildNode(item, [NODE_ATTRIBUTES.IS_CHECKED, NODE_ATTRIBUTES.IS_INDETERMINATE], [!!value, false]);
19109
19100
  _updateParentChecked(item, value);
@@ -19207,6 +19198,9 @@ var use_node_action_this = undefined;
19207
19198
  });
19208
19199
  if (!isRootNode(resolvedItem)) {
19209
19200
  var parent = getParentNode(resolvedItem);
19201
+ if (!parent) {
19202
+ return;
19203
+ }
19210
19204
  attrNames.forEach(function (name, index) {
19211
19205
  var parentVal = getNodeAttr(parent, name);
19212
19206
  if (parentVal !== value) {
@@ -19282,8 +19276,9 @@ var use_node_action_this = undefined;
19282
19276
  var resolvedItem = resolveNodeItem(nodeList[0]);
19283
19277
  if (typeof resolvedItem === 'string' || typeof resolvedItem === 'number' || _typeof(resolvedItem) === 'symbol') {
19284
19278
  var _flatData$data$find;
19279
+ var nodeId = resolvedItem;
19285
19280
  resolvedItem = (_flatData$data$find = flatData.data.find(function (item) {
19286
- return getNodeId(item) === resolvedItem;
19281
+ return getNodeId(item) === nodeId;
19287
19282
  })) !== null && _flatData$data$find !== void 0 ? _flatData$data$find : defineProperty_defineProperty({}, NODE_ATTRIBUTES.IS_NULL, true);
19288
19283
  }
19289
19284
  if (resolvedItem[NODE_ATTRIBUTES.IS_NULL]) {
@@ -19293,23 +19288,19 @@ var use_node_action_this = undefined;
19293
19288
  console.warn('props.selectable is false or undefined, please set selectable with true');
19294
19289
  return;
19295
19290
  }
19296
- var currentSelectedNodeId = getSelectedNodeId();
19297
- if (currentSelectedNodeId !== null && currentSelectedNodeId !== undefined) {
19298
- setNodeAttrById(currentSelectedNodeId, NODE_ATTRIBUTES.IS_SELECTED, !selected);
19291
+ if (selectedNodeId !== null && selectedNodeId !== undefined) {
19292
+ setNodeAttrById(selectedNodeId, NODE_ATTRIBUTES.IS_SELECTED, !selected);
19299
19293
  }
19300
- if (props.selected && props.selected !== currentSelectedNodeId) {
19294
+ if (props.selected && props.selected !== selectedNodeId) {
19301
19295
  setNodeAttrById(props.selected, NODE_ATTRIBUTES.IS_SELECTED, !selected);
19302
19296
  }
19303
19297
  setNodeAttr(resolvedItem, NODE_ATTRIBUTES.IS_SELECTED, selected);
19304
- if (props.selected === undefined) {
19305
- selectedNodeId = getNodeId(resolvedItem);
19306
- }
19298
+ selectedNodeId = getNodeId(resolvedItem);
19307
19299
  if (triggerEvent) {
19308
- var payload = {
19300
+ ctx.emit(EVENTS.NODE_SELECTED, {
19309
19301
  selected: selected,
19310
19302
  node: resolvedItem
19311
- };
19312
- ctx.emit(EVENTS.NODE_SELECTED, payload);
19303
+ });
19313
19304
  }
19314
19305
  /**
19315
19306
  * 如果设置了自动展开
@@ -22881,40 +22872,20 @@ Sortable.mount(Remove, Revert);
22881
22872
  * Copyright (C) 2025 Tencent. All rights reserved.
22882
22873
  *
22883
22874
  * 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) is licensed under the MIT License.
22884
- *
22885
- * License for 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition):
22886
- *
22887
- * ---------------------------------------------------
22888
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
22889
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
22890
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
22891
- * permit persons to whom the Software is furnished to do so, subject to the following conditions:
22892
- *
22893
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
22894
- * the Software.
22895
- *
22896
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
22897
- * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22898
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22899
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22900
- * IN THE SOFTWARE.
22901
22875
  */
22902
22876
 
22903
22877
 
22904
22878
 
22905
22879
 
22906
22880
 
22907
- /* harmony default export */ const use_node_drag = (function (props, ctx, root, flatData, options) {
22881
+
22882
+ /* harmony default export */ const use_node_drag = (function (props, ctx, root, flatData) {
22883
+ var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
22908
22884
  var _useNodeAttribute = use_node_attribute(flatData, props),
22909
22885
  getSourceNodeByUID = _useNodeAttribute.getSourceNodeByUID,
22910
22886
  getParentNode = _useNodeAttribute.getParentNode,
22911
22887
  extendNodeAttr = _useNodeAttribute.extendNodeAttr,
22912
- getNodeAttr = _useNodeAttribute.getNodeAttr,
22913
- getNodeId = _useNodeAttribute.getNodeId,
22914
- setNodeAttr = _useNodeAttribute.setNodeAttr;
22915
- var _ref = options || {},
22916
- moveTreeNodeById = _ref.moveTreeNodeById,
22917
- onTreeDataChange = _ref.onTreeDataChange;
22888
+ getNodeId = _useNodeAttribute.getNodeId;
22918
22889
  var _usePrefix = (0,config_provider_namespaceObject.usePrefix)(),
22919
22890
  resolveClassName = _usePrefix.resolveClassName;
22920
22891
  var isNeedCheckDraggable = (0,external_vue_namespaceObject.computed)(function () {
@@ -22926,20 +22897,12 @@ Sortable.mount(Remove, Revert);
22926
22897
  var dragThreshold = props.dragThreshold || 0.2;
22927
22898
  var sortableInstance = null;
22928
22899
  var dragNodeId = '';
22929
- /** 当前拖拽的放置类型,在 onMove 中实时计算,onEnd 中消费 */
22930
22900
  var currentDropType = 'move';
22931
- /** 当前拖拽目标节点 ID,在 onMove 中实时计算,onEnd 中消费 */
22932
22901
  var currentRelatedId = '';
22933
- /** sortablejs willInsertAfter,在 onMove 中记录,onEnd 中消费 */
22902
+ var currentRelatedEl = null;
22934
22903
  var currentWillInsertAfter = true;
22935
- var isDragging = (0,external_vue_namespaceObject.ref)(false);
22936
- /**
22937
- * 放置指示器 DOM 元素(动态创建的线条/高亮)
22938
- */
22939
22904
  var indicatorEl = null;
22940
- /**
22941
- * 创建放置指示器元素
22942
- */
22905
+ var isDragging = (0,external_vue_namespaceObject.ref)(false);
22943
22906
  var createIndicator = function createIndicator() {
22944
22907
  if (indicatorEl) return indicatorEl;
22945
22908
  indicatorEl = document.createElement('div');
@@ -22947,25 +22910,20 @@ Sortable.mount(Remove, Revert);
22947
22910
  document.body.appendChild(indicatorEl);
22948
22911
  return indicatorEl;
22949
22912
  };
22950
- /**
22951
- * 移除放置指示器元素
22952
- */
22953
22913
  var removeIndicator = function removeIndicator() {
22914
+ var _indicatorEl;
22915
+ (_indicatorEl = indicatorEl) === null || _indicatorEl === void 0 || _indicatorEl.remove();
22916
+ indicatorEl = null;
22917
+ };
22918
+ var hideIndicator = function hideIndicator() {
22954
22919
  if (indicatorEl) {
22955
- indicatorEl.remove();
22956
- indicatorEl = null;
22920
+ indicatorEl.style.display = 'none';
22957
22921
  }
22958
22922
  };
22959
- /**
22960
- * 更新指示器位置和样式
22961
- * - sort/move: 显示水平线(两端圆点),指示插入位置
22962
- * - child: 显示在目标节点内部的高亮边框,指示嵌入为子节点
22963
- */
22964
22923
  var updateIndicator = function updateIndicator(targetEl, dropType, willInsertAfter) {
22965
22924
  var indicator = createIndicator();
22966
22925
  var rect = targetEl.getBoundingClientRect();
22967
22926
  if (dropType === 'child') {
22968
- // 作为子节点:显示在目标节点内部的高亮边框
22969
22927
  indicator.className = "".concat(resolveClassName('tree-drop-indicator'), " ").concat(resolveClassName('tree-drop-inner'));
22970
22928
  Object.assign(indicator.style, {
22971
22929
  display: '',
@@ -22977,236 +22935,101 @@ Sortable.mount(Remove, Revert);
22977
22935
  pointerEvents: 'none',
22978
22936
  zIndex: '9999'
22979
22937
  });
22980
- } else {
22981
- // 作为同级(sort/move):显示水平线 + 两端圆点
22982
- var lineTop = willInsertAfter ? rect.bottom : rect.top;
22983
- indicator.className = "".concat(resolveClassName('tree-drop-indicator'), " ").concat(resolveClassName('tree-drop-line'));
22984
- Object.assign(indicator.style, {
22985
- display: '',
22986
- position: 'fixed',
22987
- left: "".concat(rect.left, "px"),
22988
- top: "".concat(lineTop - 1, "px"),
22989
- width: "".concat(rect.width, "px"),
22990
- height: '2px',
22991
- pointerEvents: 'none',
22992
- zIndex: '9999'
22993
- });
22994
- }
22995
- };
22996
- /**
22997
- * 隐藏指示器
22998
- */
22999
- var hideIndicator = function hideIndicator() {
23000
- if (indicatorEl) {
23001
- indicatorEl.style.display = 'none';
22938
+ return;
23002
22939
  }
23003
- };
23004
- /**
23005
- * 保存所有节点的展开状态
23006
- */
23007
- var saveAllOpenStates = function saveAllOpenStates() {
23008
- var openStates = new Map();
23009
- flatData.data.forEach(function (node) {
23010
- var isOpen = getNodeAttr(node, NODE_ATTRIBUTES.IS_OPEN);
23011
- openStates.set(node, isOpen);
23012
- });
23013
- return openStates;
23014
- };
23015
- /**
23016
- * 恢复所有节点的展开状态
23017
- */
23018
- var restoreAllOpenStates = function restoreAllOpenStates(openStates) {
23019
- openStates.forEach(function (isOpen, node) {
23020
- if (flatData.schema.has(node)) {
23021
- setNodeAttr(node, NODE_ATTRIBUTES.IS_OPEN, isOpen);
23022
- }
22940
+ var lineTop = willInsertAfter ? rect.bottom : rect.top;
22941
+ indicator.className = "".concat(resolveClassName('tree-drop-indicator'), " ").concat(resolveClassName('tree-drop-line'));
22942
+ Object.assign(indicator.style, {
22943
+ display: '',
22944
+ position: 'fixed',
22945
+ left: "".concat(rect.left, "px"),
22946
+ top: "".concat(lineTop - 1, "px"),
22947
+ width: "".concat(rect.width, "px"),
22948
+ height: '2px',
22949
+ pointerEvents: 'none',
22950
+ zIndex: '9999'
23023
22951
  });
23024
22952
  };
23025
- var emitTreeDataChange = function emitTreeDataChange(payload) {
23026
- if (!payload) {
23027
- return null;
23028
- }
23029
- onTreeDataChange === null || onTreeDataChange === void 0 || onTreeDataChange(payload);
23030
- return payload;
23031
- };
23032
- /**
23033
- * 更新节点的 HAS_CHILD 属性
23034
- */
23035
- var updateHasChildAttr = function updateHasChildAttr(node) {
23036
- if (!node) return;
23037
- var children = node[props.children];
23038
- var hasChildren = children && children.length > 0;
23039
- setNodeAttr(node, NODE_ATTRIBUTES.HAS_CHILD, hasChildren);
23040
- };
23041
- /**
23042
- * 根据 onMove 中的鼠标位置计算放置类型
23043
- *
23044
- * 两种模式:
23045
- * 1. dragSort 模式(仅排序,不支持改变层级):
23046
- * - 上方/下方区域 → sort(同级排序)
23047
- * - 中间区域 → sort(同级排序,不支持 child)
23048
- *
23049
- * 2. draggable 模式(支持排序和改变层级):
23050
- * - 上方/下方区域 → move(作为同级节点)
23051
- * - 中间区域 → child(作为子节点)
23052
- */
23053
22953
  var calcDropType = function calcDropType(clientY, targetEl) {
23054
- var rect = targetEl.getBoundingClientRect();
23055
- var offsetY = clientY - rect.top;
23056
- var threshold = rect.height * dragThreshold;
23057
22954
  if (props.dragSort) {
23058
- // dragSort 模式:仅支持同级排序,不支持改变层级
23059
22955
  return 'sort';
23060
22956
  }
23061
- // draggable 模式:支持排序和改变层级
23062
- if (offsetY < threshold) {
23063
- return 'move';
23064
- } else if (offsetY > rect.height - threshold) {
22957
+ var rect = targetEl.getBoundingClientRect();
22958
+ var offsetY = clientY - rect.top;
22959
+ var threshold = rect.height * dragThreshold;
22960
+ if (offsetY < threshold || offsetY > rect.height - threshold) {
23065
22961
  return 'move';
23066
22962
  }
23067
22963
  return 'child';
23068
22964
  };
23069
- /**
23070
- * 将源数据树结构重新展开为 flatData(DFS 顺序)
23071
- * 同时重新计算所有节点属性(深度、路径、索引等)
23072
- * 与 v1 版本保持一致:从 props.data 出发进行遍历,不依赖旧 schema 状态
23073
- */
23074
- var rebuildFlatDataWithAttributes = function rebuildFlatDataWithAttributes() {
23075
- var newFlatData = [];
23076
- var orderIndex = 0;
23077
- var _traverse = function traverse(nodes, level, parentPath, parent) {
23078
- for (var i = 0; i < nodes.length; i++) {
23079
- var node = nodes[i];
23080
- var path = parentPath !== '' ? "".concat(parentPath, "-").concat(i) : "".concat(i);
23081
- // 重新构建 flatData
23082
- newFlatData.push(node);
23083
- // 重新计算所有节点属性
23084
- setNodeAttr(node, NODE_ATTRIBUTES.INDEX, orderIndex);
23085
- setNodeAttr(node, NODE_ATTRIBUTES.ORDER, orderIndex);
23086
- setNodeAttr(node, NODE_ATTRIBUTES.DEPTH, level);
23087
- setNodeAttr(node, NODE_ATTRIBUTES.PATH, path);
23088
- setNodeAttr(node, NODE_ATTRIBUTES.IS_ROOT, level === 0);
23089
- setNodeAttr(node, NODE_ATTRIBUTES.PARENT, parent);
23090
- setNodeAttr(node, NODE_ATTRIBUTES.HAS_CHILD, !!(node[props.children] || []).length);
23091
- orderIndex += 1;
23092
- var children = node[props.children] || [];
23093
- if (children.length > 0) {
23094
- _traverse(children, level + 1, path, node);
23095
- }
23096
- }
23097
- };
23098
- _traverse(props.data, 0, '', null);
23099
- flatData.data = newFlatData;
23100
- };
23101
- /**
23102
- * 拖拽排序:同级节点间排序(dragSort 模式)
23103
- * 直接操作 children 数组:移除源节点 -> 插入到目标节点前/后
23104
- */
23105
- var dragSortData = function dragSortData(sourceNodeData, targetNodeData, willInsertAfter, savedOpenStates) {
23106
- var sourceParent = getParentNode(sourceNodeData);
23107
- var targetParent = getParentNode(targetNodeData);
23108
- if (props.dragSortMode === 'next' && sourceParent !== targetParent) return null;
23109
- var payload = emitTreeDataChange(moveTreeNodeById === null || moveTreeNodeById === void 0 ? void 0 : moveTreeNodeById(props.data, getNodeId(sourceNodeData), getNodeId(targetNodeData), props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, {
23110
- dropType: 'sort',
23111
- willInsertAfter: willInsertAfter
23112
- }));
23113
- if (!payload) {
23114
- return null;
23115
- }
23116
- rebuildFlatDataWithAttributes();
23117
- updateHasChildAttr(sourceParent);
23118
- restoreAllOpenStates(savedOpenStates);
23119
- var dragSortPayload = {
23120
- sourceNode: sourceNodeData,
23121
- targetNode: targetNodeData,
23122
- sourceIndex: payload.sourceIndex,
23123
- targetIndex: payload.targetIndex,
23124
- data: payload.data,
23125
- parentNode: payload.parentNode,
23126
- oldParentNode: payload.oldParentNode,
23127
- dropType: payload.dropType
23128
- };
23129
- ctx.emit(EVENTS.NODE_DRAG_SORT, dragSortPayload);
23130
- return payload;
23131
- };
23132
- /**
23133
- * 将源节点作为目标节点的子节点
23134
- * 直接操作 children 数组:移除源节点 -> push 到目标节点 children
23135
- */
23136
- var dragAsChildNode = function dragAsChildNode(sourceNodeData, targetNodeData, savedOpenStates) {
23137
- var sourceParent = getParentNode(sourceNodeData);
23138
- var payload = emitTreeDataChange(moveTreeNodeById === null || moveTreeNodeById === void 0 ? void 0 : moveTreeNodeById(props.data, getNodeId(sourceNodeData), getNodeId(targetNodeData), props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, {
23139
- dropType: 'child'
23140
- }));
23141
- if (!payload) {
23142
- return null;
23143
- }
23144
- rebuildFlatDataWithAttributes();
23145
- updateHasChildAttr(sourceParent);
23146
- setNodeAttr(targetNodeData, NODE_ATTRIBUTES.HAS_CHILD, true);
23147
- restoreAllOpenStates(savedOpenStates);
23148
- return payload;
23149
- };
23150
- /**
23151
- * 将源节点作为目标节点的同级节点插入(可跨级)
23152
- * 直接操作 children 数组:移除源节点 -> 在目标节点前/后插入
23153
- */
23154
- var dragAsSiblingNode = function dragAsSiblingNode(sourceNodeData, targetNodeData, willInsertAfter, savedOpenStates) {
23155
- var sourceParent = getParentNode(sourceNodeData);
23156
- var targetParent = getParentNode(targetNodeData);
23157
- var payload = emitTreeDataChange(moveTreeNodeById === null || moveTreeNodeById === void 0 ? void 0 : moveTreeNodeById(props.data, getNodeId(sourceNodeData), getNodeId(targetNodeData), props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, {
23158
- dropType: 'move',
23159
- willInsertAfter: willInsertAfter
23160
- }));
23161
- if (!payload) {
23162
- return null;
23163
- }
23164
- rebuildFlatDataWithAttributes();
23165
- updateHasChildAttr(sourceParent);
23166
- updateHasChildAttr(targetParent);
23167
- restoreAllOpenStates(savedOpenStates);
23168
- return payload;
23169
- };
23170
- /**
23171
- * 检查是否禁止拖拽
23172
- */
23173
22965
  var isDragDisabled = function isDragDisabled(nodeId) {
23174
22966
  var _props$disableDrag;
23175
22967
  var nodeData = getSourceNodeByUID(nodeId);
23176
22968
  if (!nodeData) return true;
23177
22969
  if (isNeedCheckDraggable.value && (_props$disableDrag = props.disableDrag) !== null && _props$disableDrag !== void 0 && _props$disableDrag.call(props, nodeData)) return true;
23178
- if (nodeData.draggable === false) return true;
22970
+ return nodeData.draggable === false;
22971
+ };
22972
+ var isDescendantTarget = function isDescendantTarget(draggedData, relatedData) {
22973
+ var parent = getParentNode(relatedData);
22974
+ while (parent) {
22975
+ if (parent === draggedData) return true;
22976
+ parent = getParentNode(parent);
22977
+ }
23179
22978
  return false;
23180
22979
  };
23181
- /**
23182
- * 检查是否禁止放置
23183
- */
23184
22980
  var isDropDisabled = function isDropDisabled(draggedId, relatedId, dropType) {
23185
22981
  var _props$disableDrop;
23186
22982
  var draggedData = getSourceNodeByUID(draggedId);
23187
22983
  var relatedData = extendNodeAttr(getSourceNodeByUID(relatedId));
23188
- if (isNeedCheckDroppable.value && (_props$disableDrop = props.disableDrop) !== null && _props$disableDrop !== void 0 && _props$disableDrop.call(props, draggedData, dropType, relatedData)) return true;
23189
- return false;
22984
+ if (!draggedData || !relatedData) return true;
22985
+ return !!(isNeedCheckDroppable.value && (_props$disableDrop = props.disableDrop) !== null && _props$disableDrop !== void 0 && _props$disableDrop.call(props, draggedData, dropType, relatedData));
23190
22986
  };
23191
- /**
23192
- * 恢复 sortablejs 的 DOM 操作
23193
- * 因为我们由数据驱动 Vue 更新,需要先恢复 sortablejs 已做的 DOM 移动
23194
- */
23195
22987
  var restoreSortableDOM = function restoreSortableDOM(evt) {
23196
22988
  var item = evt.item,
23197
22989
  from = evt.from,
22990
+ to = evt.to,
23198
22991
  oldIndex = evt.oldIndex,
23199
22992
  newIndex = evt.newIndex;
23200
- if (oldIndex === undefined || newIndex === undefined || !from || oldIndex === newIndex) return;
23201
- if (newIndex < oldIndex) {
22993
+ if (oldIndex === undefined || !from) return;
22994
+ var sameContainer = from === to;
22995
+ if (sameContainer && oldIndex === newIndex) return;
22996
+ if (!sameContainer && to && item.parentNode === to) {
22997
+ to.removeChild(item);
22998
+ }
22999
+ if (sameContainer && newIndex !== undefined && newIndex < oldIndex) {
23202
23000
  from.insertBefore(item, from.children[oldIndex + 1] || null);
23203
23001
  } else {
23204
23002
  from.insertBefore(item, from.children[oldIndex] || null);
23205
23003
  }
23206
23004
  };
23207
- /**
23208
- * 初始化 Sortable 实例
23209
- */
23005
+ var emitTreeDataChange = function emitTreeDataChange(payload) {
23006
+ var _options$onTreeDataCh;
23007
+ if (!payload) return null;
23008
+ (_options$onTreeDataCh = options.onTreeDataChange) === null || _options$onTreeDataCh === void 0 || _options$onTreeDataCh.call(options, payload);
23009
+ return payload;
23010
+ };
23011
+ var moveNode = function moveNode(sourceNodeData, targetNodeData, dropType) {
23012
+ var _options$getTreeData, _options$getTreeData2;
23013
+ var willInsertAfter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
23014
+ return emitTreeDataChange(moveTreeNodeById((_options$getTreeData = (_options$getTreeData2 = options.getTreeData) === null || _options$getTreeData2 === void 0 ? void 0 : _options$getTreeData2.call(options)) !== null && _options$getTreeData !== void 0 ? _options$getTreeData : props.data, "".concat(getNodeId(sourceNodeData)), "".concat(getNodeId(targetNodeData)), props.nodeKey || NODE_ATTRIBUTES.UUID, props.children, {
23015
+ dropType: dropType,
23016
+ willInsertAfter: willInsertAfter
23017
+ }));
23018
+ };
23019
+ var cleanup = function cleanup() {
23020
+ dragNodeId = '';
23021
+ currentDropType = 'move';
23022
+ currentRelatedId = '';
23023
+ currentRelatedEl = null;
23024
+ currentWillInsertAfter = true;
23025
+ isDragging.value = false;
23026
+ removeIndicator();
23027
+ };
23028
+ var destroySortable = function destroySortable() {
23029
+ var _sortableInstance;
23030
+ (_sortableInstance = sortableInstance) === null || _sortableInstance === void 0 || _sortableInstance.destroy();
23031
+ sortableInstance = null;
23032
+ };
23210
23033
  var initSortable = function initSortable() {
23211
23034
  if (!root.value) return;
23212
23035
  var container = root.value.$el;
@@ -23221,55 +23044,78 @@ Sortable.mount(Remove, Revert);
23221
23044
  filter: ".".concat(resolveClassName('tree-drag-disabled')),
23222
23045
  onStart: function onStart(evt) {
23223
23046
  var nodeId = evt.item.getAttribute('data-tree-node');
23224
- if (!nodeId || isDragDisabled(nodeId)) return;
23047
+ if (!nodeId || isDragDisabled(nodeId)) {
23048
+ return;
23049
+ }
23225
23050
  dragNodeId = nodeId;
23226
- isDragging.value = true;
23227
23051
  currentDropType = props.dragSort ? 'sort' : 'move';
23228
23052
  currentRelatedId = '';
23053
+ currentRelatedEl = null;
23229
23054
  currentWillInsertAfter = true;
23230
- ctx.emit(EVENTS.NODE_DRAG_START, evt, evt.item);
23055
+ isDragging.value = true;
23056
+ ctx.emit(EVENTS.NODE_DRAG_START, extendNodeAttr(getSourceNodeByUID(nodeId)), evt);
23057
+ },
23058
+ onMove: function onMove(evt, originalEvent) {
23059
+ var _evt$willInsertAfter;
23060
+ var relatedEl = evt.related;
23061
+ var draggedEl = evt.dragged;
23062
+ var relatedId = relatedEl === null || relatedEl === void 0 ? void 0 : relatedEl.getAttribute('data-tree-node');
23063
+ var draggedId = draggedEl === null || draggedEl === void 0 ? void 0 : draggedEl.getAttribute('data-tree-node');
23064
+ if (!relatedId || !draggedId) return -1;
23065
+ var draggedData = getSourceNodeByUID(draggedId);
23066
+ var relatedData = getSourceNodeByUID(relatedId);
23067
+ if (!draggedData || !relatedData || draggedId === relatedId || isDescendantTarget(draggedData, relatedData)) {
23068
+ return -1;
23069
+ }
23070
+ var dropType = calcDropType(originalEvent.clientY, relatedEl);
23071
+ if (dropType === 'sort' && props.dragSortMode === 'next' && getParentNode(draggedData) !== getParentNode(relatedData)) {
23072
+ return -1;
23073
+ }
23074
+ if (isDropDisabled(draggedId, relatedId, dropType)) return -1;
23075
+ currentDropType = dropType;
23076
+ currentRelatedId = relatedId;
23077
+ currentRelatedEl = relatedEl;
23078
+ currentWillInsertAfter = (_evt$willInsertAfter = evt.willInsertAfter) !== null && _evt$willInsertAfter !== void 0 ? _evt$willInsertAfter : true;
23079
+ updateIndicator(relatedEl, dropType, currentWillInsertAfter);
23080
+ ctx.emit(EVENTS.NODE_DRAG_OVER, extendNodeAttr(relatedData), originalEvent, relatedEl);
23081
+ return true;
23231
23082
  },
23232
23083
  onEnd: function onEnd(evt) {
23233
- // 恢复 sortablejs 的 DOM 移动,由数据驱动 Vue 更新
23234
23084
  restoreSortableDOM(evt);
23235
- // 隐藏指示器
23236
23085
  hideIndicator();
23237
- // 使用 onMove 中实时计算的放置信息
23238
- var targetNodeId = currentRelatedId;
23239
- if (!targetNodeId || !dragNodeId || dragNodeId === targetNodeId) {
23240
- cleanup();
23241
- return;
23242
- }
23243
23086
  var sourceNodeData = getSourceNodeByUID(dragNodeId);
23244
- var targetNodeData = getSourceNodeByUID(targetNodeId);
23245
- var targetEl = evt.related;
23246
- if (!sourceNodeData || !targetNodeData || !targetEl) {
23087
+ var targetNodeData = getSourceNodeByUID(currentRelatedId);
23088
+ var targetEl = currentRelatedEl;
23089
+ if (!sourceNodeData || !targetNodeData || !targetEl || dragNodeId === currentRelatedId) {
23247
23090
  cleanup();
23248
23091
  return;
23249
23092
  }
23250
- if (isDropDisabled(dragNodeId, targetNodeId, currentDropType)) {
23093
+ if (isDropDisabled(dragNodeId, currentRelatedId, currentDropType)) {
23251
23094
  cleanup();
23252
23095
  return;
23253
23096
  }
23254
- // 保存展开状态
23255
- var savedOpenStates = saveAllOpenStates();
23256
- var payload = null;
23257
- if (currentDropType === 'child') {
23258
- payload = dragAsChildNode(sourceNodeData, targetNodeData, savedOpenStates);
23259
- } else if (currentDropType === 'sort') {
23260
- payload = dragSortData(sourceNodeData, targetNodeData, currentWillInsertAfter, savedOpenStates);
23261
- } else {
23262
- payload = dragAsSiblingNode(sourceNodeData, targetNodeData, currentWillInsertAfter, savedOpenStates);
23263
- }
23097
+ var payload = moveNode(sourceNodeData, targetNodeData, currentDropType, currentWillInsertAfter);
23264
23098
  if (!payload) {
23265
23099
  cleanup();
23266
23100
  return;
23267
23101
  }
23268
- var targetData = extendNodeAttr(targetNodeData);
23102
+ if (currentDropType === 'sort') {
23103
+ var dragSortPayload = {
23104
+ sourceNode: sourceNodeData,
23105
+ targetNode: targetNodeData,
23106
+ sourceIndex: payload.sourceIndex,
23107
+ targetIndex: payload.targetIndex,
23108
+ data: payload.data,
23109
+ parentNode: payload.parentNode,
23110
+ oldParentNode: payload.oldParentNode,
23111
+ dropType: payload.dropType
23112
+ };
23113
+ ctx.emit(EVENTS.NODE_DRAG_SORT, dragSortPayload);
23114
+ }
23269
23115
  var dropPayload = {
23270
23116
  event: evt,
23271
23117
  element: targetEl,
23272
- targetNode: targetData,
23118
+ targetNode: extendNodeAttr(targetNodeData),
23273
23119
  sourceNode: sourceNodeData,
23274
23120
  data: payload.data,
23275
23121
  parentNode: payload.parentNode,
@@ -23281,75 +23127,38 @@ Sortable.mount(Remove, Revert);
23281
23127
  ctx.emit(EVENTS.NODE_DROP, dropPayload);
23282
23128
  cleanup();
23283
23129
  },
23284
- onMove: function onMove(evt, originalEvent) {
23285
- var _evt$willInsertAfter;
23286
- var relatedEl = evt.related;
23287
- var draggedEl = evt.dragged;
23288
- var relatedId = relatedEl.getAttribute('data-tree-node');
23289
- var draggedId = draggedEl.getAttribute('data-tree-node');
23290
- if (!relatedId || !draggedId) return -1;
23291
- // 不能拖到自己的子节点中
23292
- var draggedData = getSourceNodeByUID(draggedId);
23293
- if (draggedData) {
23294
- var relatedData = getSourceNodeByUID(relatedId);
23295
- var parent = getParentNode(relatedData);
23296
- while (parent) {
23297
- if (parent === draggedData) return -1;
23298
- parent = getParentNode(parent);
23299
- }
23300
- }
23301
- // 使用 originalEvent 坐标实时计算放置类型
23302
- var clientY = originalEvent.clientY;
23303
- var dropType = calcDropType(clientY, relatedEl);
23304
- // dragSort 模式下:如果源节点和目标节点不同父且 dragSortMode === 'next',禁止放置
23305
- if (dropType === 'sort' && props.dragSortMode === 'next') {
23306
- var sourceParent = getParentNode(getSourceNodeByUID(draggedId));
23307
- var targetParent = getParentNode(getSourceNodeByUID(relatedId));
23308
- if (sourceParent !== targetParent) return -1;
23130
+ onUnchoose: function onUnchoose(evt) {
23131
+ var _evt$item;
23132
+ var nodeId = ((_evt$item = evt.item) === null || _evt$item === void 0 ? void 0 : _evt$item.getAttribute('data-tree-node')) || dragNodeId;
23133
+ var nodeData = nodeId ? getSourceNodeByUID(nodeId) : null;
23134
+ if (nodeData) {
23135
+ ctx.emit(EVENTS.NODE_DRAG_LEAVE, extendNodeAttr(nodeData), evt);
23309
23136
  }
23310
- // 检查是否禁止放置
23311
- if (isDropDisabled(draggedId, relatedId, dropType)) return -1;
23312
- // 记录当前放置信息,供 onEnd 消费
23313
- // evt.willInsertAfter 是 sortablejs 提供的原生属性,
23314
- // 表示拖拽元素将被插入到目标元素之后(true)还是之前(false)
23315
- currentDropType = dropType;
23316
- currentRelatedId = relatedId;
23317
- currentWillInsertAfter = (_evt$willInsertAfter = evt.willInsertAfter) !== null && _evt$willInsertAfter !== void 0 ? _evt$willInsertAfter : true;
23318
- // 使用 overlay 指示器显示放置位置
23319
- updateIndicator(relatedEl, dropType, currentWillInsertAfter);
23320
- ctx.emit(EVENTS.NODE_DRAG_OVER, originalEvent, relatedEl, extendNodeAttr(getSourceNodeByUID(relatedId)));
23321
- return true;
23322
23137
  }
23323
23138
  });
23324
23139
  };
23325
- /**
23326
- * 销毁 Sortable 实例
23327
- */
23328
- var destroySortable = function destroySortable() {
23329
- if (sortableInstance) {
23330
- sortableInstance.destroy();
23331
- sortableInstance = null;
23140
+ var syncSortable = function syncSortable() {
23141
+ if (props.draggable || props.dragSort) {
23142
+ initSortable();
23143
+ } else {
23144
+ destroySortable();
23145
+ removeIndicator();
23332
23146
  }
23333
23147
  };
23334
- /**
23335
- * 清理拖拽状态
23336
- * 拖拽结束后移除节点的选中状态,避免拖拽完毕节点保持选中
23337
- */
23338
- var cleanup = function cleanup() {
23339
- dragNodeId = '';
23340
- currentDropType = 'move';
23341
- currentRelatedId = '';
23342
- currentWillInsertAfter = true;
23343
- isDragging.value = false;
23344
- removeIndicator();
23345
- };
23346
23148
  (0,external_vue_namespaceObject.onMounted)(function () {
23347
- if ((props.draggable || props.dragSort) && root.value) {
23149
+ if (props.draggable || props.dragSort) {
23348
23150
  (0,external_vue_namespaceObject.nextTick)(function () {
23349
- initSortable();
23151
+ return initSortable();
23350
23152
  });
23351
23153
  }
23352
23154
  });
23155
+ (0,external_vue_namespaceObject.watch)(function () {
23156
+ return [props.draggable, props.dragSort];
23157
+ }, function () {
23158
+ return (0,external_vue_namespaceObject.nextTick)(function () {
23159
+ return syncSortable();
23160
+ });
23161
+ });
23353
23162
  (0,external_vue_namespaceObject.onUnmounted)(function () {
23354
23163
  destroySortable();
23355
23164
  removeIndicator();
@@ -23579,16 +23388,8 @@ var use_tree_init_this = undefined;
23579
23388
 
23580
23389
 
23581
23390
 
23582
- var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23583
- var _props$async, _props$checked;
23584
- var needsStableNodeKey = !!props.draggable || !!props.dragSort || !!((_props$async = props.async) !== null && _props$async !== void 0 && _props$async.callback) || props.selected !== undefined || !!((_props$checked = props.checked) !== null && _props$checked !== void 0 && _props$checked.length);
23585
- if (needsStableNodeKey && !props.nodeKey) {
23586
- console.warn('[Tree] `nodeKey` is recommended when using drag, async, selected, or checked state.');
23587
- }
23588
- };
23589
23391
  /* harmony default export */ const use_tree_init = (function (props) {
23590
- var _props$async4;
23591
- warnRequiredNodeKey(props);
23392
+ var _props$async3;
23592
23393
  /**
23593
23394
  * 扁平化当前数据
23594
23395
  * @param treeData 树形结构数据
@@ -23603,11 +23404,10 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23603
23404
  var checkedList = [];
23604
23405
  var outputData = [];
23605
23406
  var order = 0;
23606
- // TODO P2: 考虑将 WeakMap<TreeNode, meta> 切换为 Map<nodeKey, meta>
23607
- // 优势:序列化友好、跨实例共享、避免对象引用泄漏
23608
- // 劣势:需要手动管理内存、依赖 nodeKey 唯一性
23609
- // 当前保留 WeakMap 以保证兼容性和自动 GC
23610
23407
  var treeSchema = new WeakMap();
23408
+ var nodeMap = new Map();
23409
+ var childMap = new WeakMap();
23410
+ var rootNodes = [];
23611
23411
  /**
23612
23412
  * 递归更新节点属性
23613
23413
  * @param node 当前节点
@@ -23750,6 +23550,12 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23750
23550
  var currentPath = path !== null ? "".concat(path, "-").concat(i) : "".concat(i);
23751
23551
  var uuid = "".concat(getUid(item));
23752
23552
  var hasChildren = !!(item[children] || []).length;
23553
+ if (!props.nodeKey) {
23554
+ item[NODE_ATTRIBUTES.UUID] = uuid;
23555
+ }
23556
+ if (nodeMap.has(uuid)) {
23557
+ console.warn("[bk-tree] duplicate node key \"".concat(uuid, "\" found, please check nodeKey."));
23558
+ }
23753
23559
  /**
23754
23560
  * 当前节点设置是否为展开状态
23755
23561
  */
@@ -23774,6 +23580,14 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23774
23580
  checkedList.push(item);
23775
23581
  }
23776
23582
  treeSchema.set(item, attributes);
23583
+ nodeMap.set(uuid, item);
23584
+ if (parent === null) {
23585
+ rootNodes.push(item);
23586
+ } else {
23587
+ var siblings = childMap.get(parent) || [];
23588
+ siblings.push(item);
23589
+ childMap.set(parent, siblings);
23590
+ }
23777
23591
  outputData.push(item);
23778
23592
  order += 1;
23779
23593
  if (Object.prototype.hasOwnProperty.call(item, children)) {
@@ -23784,13 +23598,12 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23784
23598
  }
23785
23599
  }
23786
23600
  flatten(treeData !== null && treeData !== void 0 ? treeData : data);
23787
- // 历史语义:checkStrictly=true 表示启用父子联动
23788
23601
  if (props.showCheckbox !== false && props.checkStrictly) {
23789
23602
  checkedList === null || checkedList === void 0 || checkedList.forEach(function (value) {
23790
23603
  loopUpdateNodeAttr(value, NODE_ATTRIBUTES.IS_CHECKED, true, loopUpdateCheckedEvent);
23791
23604
  });
23792
23605
  }
23793
- return [outputData, treeSchema];
23606
+ return [outputData, treeSchema, nodeMap, childMap, rootNodes];
23794
23607
  };
23795
23608
  var formatData = getFlatdata();
23796
23609
  var nextLoopEvents = new Map();
@@ -23803,6 +23616,9 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23803
23616
  var flatData = (0,external_vue_namespaceObject.reactive)({
23804
23617
  data: formatData[0],
23805
23618
  schema: formatData[1],
23619
+ nodeMap: formatData[2],
23620
+ childMap: formatData[3],
23621
+ rootNodes: formatData[4],
23806
23622
  levelLineSchema: {}
23807
23623
  });
23808
23624
  var _useNodeAsync = use_node_async(props, flatData),
@@ -23872,17 +23688,22 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23872
23688
  };
23873
23689
  /**
23874
23690
  * 监听组件配置Data改变
23875
- * 注意:外部应通过 onDataChange 回调更新数据,而非直接修改 props.data 内部节点
23876
- * 默认不使用 deep: true 以避免不必要的深度遍历开销
23877
23691
  */
23878
- (0,external_vue_namespaceObject.watch)(function () {
23879
- return props.data;
23880
- }, function (newData) {
23881
- var _props$async2, _props$async3;
23882
- var formatData = getFlatdata(newData, flatData.schema);
23692
+ var rebuildData = function rebuildData(treeData) {
23693
+ var cachedSchema = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : flatData.schema;
23694
+ var formatData = getFlatdata(treeData, cachedSchema);
23883
23695
  flatData.data = formatData[0];
23884
23696
  flatData.schema = formatData[1];
23885
- if ((_props$async2 = props.async) !== null && _props$async2 !== void 0 && _props$async2.callback && ((_props$async3 = props.async) === null || _props$async3 === void 0 ? void 0 : _props$async3.deepAutoOpen) === 'every') {
23697
+ flatData.nodeMap = formatData[2];
23698
+ flatData.childMap = formatData[3];
23699
+ flatData.rootNodes = formatData[4];
23700
+ };
23701
+ (0,external_vue_namespaceObject.watch)(function () {
23702
+ return [props.data];
23703
+ }, function (newData) {
23704
+ var _props$async, _props$async2;
23705
+ rebuildData(newData[0], flatData.schema);
23706
+ if ((_props$async = props.async) !== null && _props$async !== void 0 && _props$async.callback && ((_props$async2 = props.async) === null || _props$async2 === void 0 ? void 0 : _props$async2.deepAutoOpen) === 'every') {
23886
23707
  deepAutoOpen();
23887
23708
  }
23888
23709
  /**
@@ -23891,12 +23712,8 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23891
23712
  */
23892
23713
  executeNextEvent();
23893
23714
  }, {
23894
- deep: props.deepWatch
23715
+ deep: true
23895
23716
  });
23896
- // deepWatch 已废弃警告
23897
- if (props.deepWatch) {
23898
- console.warn('[BkTree] deepWatch is deprecated and will be removed in the next major version. ' + 'Please use onDataChange callback to update data instead of directly modifying props.data internal nodes.');
23899
- }
23900
23717
  if (props.selectable) {
23901
23718
  (0,external_vue_namespaceObject.onMounted)(function () {
23902
23719
  (0,external_vue_namespaceObject.watch)(function () {
@@ -23924,7 +23741,7 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23924
23741
  registerNextLoop('afterDataUpdate', callFn);
23925
23742
  };
23926
23743
  /** 如果设置了异步请求 */
23927
- if ((_props$async4 = props.async) !== null && _props$async4 !== void 0 && _props$async4.callback) {
23744
+ if ((_props$async3 = props.async) !== null && _props$async3 !== void 0 && _props$async3.callback) {
23928
23745
  deepAutoOpen();
23929
23746
  }
23930
23747
  return {
@@ -23933,6 +23750,7 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23933
23750
  deepAutoOpen: deepAutoOpen,
23934
23751
  afterDataUpdate: afterDataUpdate,
23935
23752
  registerNextLoop: registerNextLoop,
23753
+ rebuildData: rebuildData,
23936
23754
  onSelected: onSelected
23937
23755
  };
23938
23756
  });
@@ -23986,14 +23804,12 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
23986
23804
  emits: TreeEmitEventsType,
23987
23805
  setup: function setup(props, ctx) {
23988
23806
  var root = (0,external_vue_namespaceObject.ref)();
23807
+ var treeDataRef = (0,external_vue_namespaceObject.ref)(props.data);
23989
23808
  var _useTreeInit = use_tree_init(props),
23990
23809
  flatData = _useTreeInit.flatData,
23991
23810
  onSelected = _useTreeInit.onSelected,
23811
+ rebuildData = _useTreeInit.rebuildData,
23992
23812
  registerNextLoop = _useTreeInit.registerNextLoop;
23993
- var handleTreeDataChange = function handleTreeDataChange(payload) {
23994
- var _props$onDataChange;
23995
- (_props$onDataChange = props.onDataChange) === null || _props$onDataChange === void 0 || _props$onDataChange.call(props, payload);
23996
- };
23997
23813
  var _useNodeAttribute = use_node_attribute(flatData, props),
23998
23814
  checkNodeIsOpen = _useNodeAttribute.checkNodeIsOpen,
23999
23815
  isRootNode = _useNodeAttribute.isRootNode,
@@ -24048,7 +23864,18 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
24048
23864
  var _useIntersectionObser = use_intersection_observer(props),
24049
23865
  getLastVisibleElement = _useIntersectionObser.getLastVisibleElement,
24050
23866
  intersectionObserver = _useIntersectionObser.intersectionObserver;
23867
+ var onTreeDataChange = function onTreeDataChange(payload) {
23868
+ var _payload$data, _props$onDataChange;
23869
+ treeDataRef.value = (_payload$data = payload.data) !== null && _payload$data !== void 0 ? _payload$data : [];
23870
+ rebuildData(treeDataRef.value);
23871
+ ctx.emit(EVENTS.NODE_DATA_CHANGE, payload);
23872
+ (_props$onDataChange = props.onDataChange) === null || _props$onDataChange === void 0 || _props$onDataChange.call(props, payload);
23873
+ };
24051
23874
  var _useNodeAction = use_node_action(props, ctx, flatData, renderData, {
23875
+ getTreeData: function getTreeData() {
23876
+ return treeDataRef.value;
23877
+ },
23878
+ onTreeDataChange: onTreeDataChange,
24052
23879
  registerNextLoop: registerNextLoop
24053
23880
  }),
24054
23881
  renderTreeNode = _useNodeAction.renderTreeNode,
@@ -24118,7 +23945,7 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
24118
23945
  if (checked) {
24119
23946
  setNodeAction(resolvedNode, NODE_ATTRIBUTES.IS_INDETERMINATE, false);
24120
23947
  }
24121
- // 历史语义:checkStrictly=true 表示启用父子联动
23948
+ // 如果设置了 checkStrictly,需要同步更新子节点和父节点的状态
24122
23949
  if (props.checkStrictly) {
24123
23950
  deepUpdateChildNode(resolvedNode, [NODE_ATTRIBUTES.IS_CHECKED, NODE_ATTRIBUTES.IS_INDETERMINATE], [checked, false]);
24124
23951
  updateParentChecked(resolvedNode, checked);
@@ -24135,46 +23962,37 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
24135
23962
  onSelected(function (newData) {
24136
23963
  setSelect(newData, true, props.autoOpenParentNode, true);
24137
23964
  });
24138
- var buildChildrenIndex = function buildChildrenIndex() {
24139
- var childrenMap = new Map();
24140
- flatData.data.forEach(function (node) {
24141
- var _getParentNode;
24142
- var parentNode = (_getParentNode = getParentNode(node)) !== null && _getParentNode !== void 0 ? _getParentNode : null;
24143
- if (!childrenMap.has(parentNode)) {
24144
- childrenMap.set(parentNode, []);
24145
- }
24146
- childrenMap.get(parentNode).push(node);
24147
- });
24148
- return childrenMap;
24149
- };
23965
+ (0,external_vue_namespaceObject.watch)(function () {
23966
+ return props.data;
23967
+ }, function (value) {
23968
+ treeDataRef.value = value;
23969
+ });
24150
23970
  /**
24151
23971
  * 根据最新的schema生成最新的Tree结构数据
24152
23972
  * @returns
24153
23973
  */
24154
23974
  var getLastTreeDataBySchema = function getLastTreeDataBySchema() {
24155
- var _childrenMap$get2;
24156
- var childrenMap = buildChildrenIndex();
24157
23975
  var _loopData = function loopData(rootNodeList) {
24158
23976
  return (rootNodeList !== null && rootNodeList !== void 0 ? rootNodeList : []).map(function (node) {
24159
- var _childrenMap$get;
24160
23977
  var copyData = (0,lodash.cloneDeep)(node);
24161
23978
  if (!copyData) {
24162
23979
  return copyData;
24163
23980
  }
24164
- var children = (_childrenMap$get = childrenMap.get(node)) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
23981
+ var children = flatData.data.filter(function (item) {
23982
+ return getParentNode(item) === node;
23983
+ });
24165
23984
  copyData[props.children] = _loopData(children);
24166
23985
  return copyData;
24167
23986
  });
24168
23987
  };
24169
- return _loopData((_childrenMap$get2 = childrenMap.get(null)) !== null && _childrenMap$get2 !== void 0 ? _childrenMap$get2 : getRootNodeList());
23988
+ return _loopData(getRootNodeList());
24170
23989
  };
24171
23990
  /**
24172
23991
  * 获取当前树形结构相关数据
24173
23992
  * @param newTree 如果启用了排序,拖拽功能,这里数据结构会改变,需要设置为true,获取最新的数据
24174
23993
  * @returns
24175
23994
  */
24176
- var getData = function getData() {
24177
- var newTree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
23995
+ var getData = function getData(newTree) {
24178
23996
  if (!newTree) {
24179
23997
  return flatData;
24180
23998
  }
@@ -24274,8 +24092,10 @@ var warnRequiredNodeKey = function warnRequiredNodeKey(props) {
24274
24092
  var _useEmpty = use_empty(props),
24275
24093
  renderEmpty = _useEmpty.renderEmpty;
24276
24094
  use_node_drag(props, ctx, root, flatData, {
24277
- moveTreeNodeById: moveTreeNodeById,
24278
- onTreeDataChange: handleTreeDataChange
24095
+ getTreeData: function getTreeData() {
24096
+ return treeDataRef.value;
24097
+ },
24098
+ onTreeDataChange: onTreeDataChange
24279
24099
  });
24280
24100
  var renderTreeContent = function renderTreeContent(scopedData) {
24281
24101
  var _ctx$slots$empty, _ctx$slots$empty2, _ctx$slots;