bkui-vue 0.0.1-beta.58 → 0.0.1-beta.60

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.
Files changed (46) hide show
  1. package/dist/index.cjs.js +26 -26
  2. package/dist/index.esm.js +319 -205
  3. package/dist/index.umd.js +26 -26
  4. package/dist/style.css +1 -1
  5. package/lib/breadcrumb/breadcrumb.css +2 -2
  6. package/lib/breadcrumb/breadcrumb.variable.css +2 -2
  7. package/lib/button/button.less +2 -1
  8. package/lib/card/card.css +10 -10
  9. package/lib/card/card.less +12 -8
  10. package/lib/card/card.variable.css +10 -10
  11. package/lib/container/container.css +5 -5
  12. package/lib/container/container.less +1 -1
  13. package/lib/container/container.variable.css +5 -5
  14. package/lib/dialog/dialog.css +0 -2
  15. package/lib/dialog/dialog.less +4 -2
  16. package/lib/dialog/dialog.variable.css +0 -2
  17. package/lib/input/input.css +3 -3
  18. package/lib/input/input.less +2 -1
  19. package/lib/input/input.variable.css +3 -3
  20. package/lib/loading/loading.css +2 -2
  21. package/lib/loading/loading.variable.css +2 -2
  22. package/lib/menu/menu.css +2 -2
  23. package/lib/menu/menu.variable.css +2 -2
  24. package/lib/progress/progress.css +2 -2
  25. package/lib/progress/progress.variable.css +2 -2
  26. package/lib/styles/mixins/clearfix.css +2 -2
  27. package/lib/styles/mixins/clearfix.less +2 -2
  28. package/lib/styles/mixins/clearfix.variable.css +2 -2
  29. package/lib/styles/mixins/mixins.css +2 -2
  30. package/lib/styles/mixins/mixins.variable.css +2 -2
  31. package/lib/switcher/switcher.css +2 -2
  32. package/lib/switcher/switcher.variable.css +2 -2
  33. package/lib/table/plugins/settings.css +41 -41
  34. package/lib/table/plugins/settings.less +28 -22
  35. package/lib/table/plugins/settings.variable.css +41 -41
  36. package/lib/table/table.css +47 -47
  37. package/lib/table/table.less +10 -8
  38. package/lib/table/table.variable.css +47 -47
  39. package/lib/tree/index.d.ts +31 -52
  40. package/lib/tree/index.js +1 -1
  41. package/lib/tree/props.d.ts +10 -0
  42. package/lib/tree/tree.d.ts +16 -17
  43. package/lib/tree/use-async.d.ts +5 -0
  44. package/lib/tree/use-node-action.d.ts +6 -0
  45. package/lib/tree/use-node-attribute.d.ts +13 -0
  46. package/package.json +4 -4
package/dist/index.esm.js CHANGED
@@ -20239,6 +20239,7 @@ const Transfer = withInstall(Component$1);
20239
20239
  const treeProps = {
20240
20240
  data: PropTypes.arrayOf(PropTypes.any).def([]),
20241
20241
  label: PropTypes.oneOfType([PropTypes.func.def(void 0), PropTypes.string.def("label")]),
20242
+ nodeKey: PropTypes.string.def(null),
20242
20243
  children: PropTypes.string.def("children"),
20243
20244
  indent: PropTypes.number.def(18),
20244
20245
  lineHeight: PropTypes.number.def(32),
@@ -20255,10 +20256,49 @@ const treeProps = {
20255
20256
  ]).def(true),
20256
20257
  async: PropTypes.shape({
20257
20258
  callback: PropTypes.func.def(null),
20258
- cache: PropTypes.bool.def(true)
20259
+ cache: PropTypes.bool.def(true),
20260
+ deepAutoOpen: PropTypes.commonType(["once", "every"], "columnType").def("once")
20259
20261
  }),
20260
20262
  offsetLeft: PropTypes.number.def(5)
20261
20263
  };
20264
+ var useNodeAttribute = (flatData) => {
20265
+ const schemaValues = computed(() => Array.from(flatData.schema.values()));
20266
+ const getSchemaVal2 = (key) => flatData.schema.get(key);
20267
+ const getNodeAttr2 = (node, attr) => {
20268
+ var _a;
20269
+ return (_a = getSchemaVal2(node.__uuid)) == null ? void 0 : _a[attr];
20270
+ };
20271
+ const setNodeAttr = (node, attr, val) => flatData.schema.set(node.__uuid, __spreadProps(__spreadValues({}, getSchemaVal2(node.__uuid)), {
20272
+ [attr]: val
20273
+ }));
20274
+ const getNodePath = (node) => getNodeAttr2(node, "__path");
20275
+ const isRootNode = (node) => getNodeAttr2(node, "__isRoot");
20276
+ const isNodeOpened = (node) => getNodeAttr2(node, "__isOpen");
20277
+ const hasChildNode = (node) => getNodeAttr2(node, "__hasChild");
20278
+ const isItemOpen = (item) => {
20279
+ var _a;
20280
+ if (typeof item === "object") {
20281
+ return isNodeOpened(item);
20282
+ }
20283
+ if (typeof item === "string") {
20284
+ return (_a = getSchemaVal2(item)) == null ? void 0 : _a.__isOpen;
20285
+ }
20286
+ return false;
20287
+ };
20288
+ const checkNodeIsOpen = (node) => isRootNode(node) || isItemOpen(node) || isItemOpen(getNodeAttr2(node, "__parentId"));
20289
+ return {
20290
+ schemaValues,
20291
+ getSchemaVal: getSchemaVal2,
20292
+ getNodeAttr: getNodeAttr2,
20293
+ setNodeAttr,
20294
+ getNodePath,
20295
+ isRootNode,
20296
+ isNodeOpened,
20297
+ hasChildNode,
20298
+ isItemOpen,
20299
+ checkNodeIsOpen
20300
+ };
20301
+ };
20262
20302
  var rngBrowser = { exports: {} };
20263
20303
  var getRandomValues = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != "undefined" && typeof window.msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto);
20264
20304
  if (getRandomValues) {
@@ -20403,6 +20443,13 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
20403
20443
  const outputData = [];
20404
20444
  let order2 = 0;
20405
20445
  const schema = /* @__PURE__ */ new Map();
20446
+ function getUid(item) {
20447
+ let uid = null;
20448
+ if (typeof props.nodeKey === "string") {
20449
+ uid = item[props.nodeKey];
20450
+ }
20451
+ return uid || item.__uuid || uuid_1.v4();
20452
+ }
20406
20453
  function getCachedTreeNodeAttr(uuid2, node, attr, cachedAttr) {
20407
20454
  const cached = (cachedSchema || []).find((item) => item.__uuid === uuid2);
20408
20455
  if (cached) {
@@ -20424,7 +20471,7 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
20424
20471
  flatten(item, depth, parent, path);
20425
20472
  } else {
20426
20473
  if (typeof item === "object" && item !== null) {
20427
- const uuid2 = item.__uuid || uuid_1.v4();
20474
+ const uuid2 = getUid(item);
20428
20475
  const currentPath = path !== null ? `${path}-${i}` : `${i}`;
20429
20476
  const hasChildren = !!(item[children] || []).length;
20430
20477
  const attrs = {
@@ -20436,7 +20483,7 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
20436
20483
  __path: currentPath,
20437
20484
  __isRoot: parent === null,
20438
20485
  __order: order2,
20439
- __isOpen: isCachedTreeNodeOpened(uuid2, item) && hasChildren,
20486
+ __isOpen: isCachedTreeNodeOpened(uuid2, item),
20440
20487
  __checked: isCachedTreeNodeChecked(uuid2, item),
20441
20488
  [children]: null
20442
20489
  };
@@ -20538,202 +20585,302 @@ const assignTreeNode = (path, treeData, childKey, assignVal) => {
20538
20585
  }, treeData);
20539
20586
  Object.assign(targetNode, assignVal || {});
20540
20587
  };
20588
+ var useAsync = (props, flatData) => {
20589
+ const {
20590
+ setNodeAttr,
20591
+ getNodePath,
20592
+ getNodeAttr: getNodeAttr2
20593
+ } = useNodeAttribute(flatData);
20594
+ const setNodeRemoteLoad = (resp, item) => {
20595
+ if (typeof resp === "object" && resp !== null) {
20596
+ setNodeAttr(item, "__isOpen", true);
20597
+ const nodeValue = Array.isArray(resp) ? resp : [resp];
20598
+ updateTreeNode(getNodePath(item), props.data, props.children, props.children, nodeValue);
20599
+ }
20600
+ };
20601
+ const asyncNodeClick = (item) => {
20602
+ if (item.async) {
20603
+ const {
20604
+ callback = null,
20605
+ cache = true
20606
+ } = props.async || {};
20607
+ setNodeAttr(item, "__isAsyncInit", true);
20608
+ if (typeof callback === "function") {
20609
+ if (!item.cached) {
20610
+ Object.assign(item, {
20611
+ loading: true
20612
+ });
20613
+ return Promise.resolve(callback(item, (resp) => setNodeRemoteLoad(resp, item)).then((resp) => setNodeRemoteLoad(resp, item)).catch((err) => console.error("load remote data error:", err)).finally(() => {
20614
+ assignTreeNode(getNodePath(item), props.data, props.children, __spreadValues({
20615
+ loading: false
20616
+ }, cache ? {
20617
+ cached: true
20618
+ } : {}));
20619
+ }));
20620
+ }
20621
+ return Promise.resolve(true);
20622
+ }
20623
+ return Promise.reject("async need to set prop: asyncLoad with function wich will return promise object");
20624
+ }
20625
+ };
20626
+ const deepAutoOpen = () => {
20627
+ const autoOpenNodes = flatData.data.filter((item) => item.async && item.isOpen && !getNodeAttr2(item, "__isAsyncInit"));
20628
+ if (autoOpenNodes.length) {
20629
+ Promise.all(autoOpenNodes.map((item) => asyncNodeClick(item))).then(() => {
20630
+ deepAutoOpen();
20631
+ }).catch((err) => {
20632
+ console.warn(err);
20633
+ });
20634
+ }
20635
+ };
20636
+ return {
20637
+ asyncNodeClick,
20638
+ deepAutoOpen
20639
+ };
20640
+ };
20641
+ var useNodeAction = (props, ctx, flatData, renderData) => {
20642
+ const checkedNodes = [];
20643
+ const {
20644
+ setNodeAttr,
20645
+ getNodePath,
20646
+ getSchemaVal: getSchemaVal2,
20647
+ getNodeAttr: getNodeAttr2,
20648
+ isRootNode,
20649
+ hasChildNode,
20650
+ isItemOpen,
20651
+ isNodeOpened,
20652
+ schemaValues
20653
+ } = useNodeAttribute(flatData);
20654
+ const {
20655
+ asyncNodeClick,
20656
+ deepAutoOpen
20657
+ } = useAsync(props, flatData);
20658
+ const getRootIcon = (item) => isItemOpen(item) ? createVNode(folderShapeOpen, {
20659
+ "class": resolveClassName("tree-icon")
20660
+ }, null) : createVNode(folder, {
20661
+ "class": resolveClassName("tree-icon")
20662
+ }, null);
20663
+ const renderPrefixVal = (val) => {
20664
+ if (typeof val === "string") {
20665
+ return val;
20666
+ }
20667
+ if (typeof val === "object" && val !== null) {
20668
+ if (val.__v_isVNode) {
20669
+ return val;
20670
+ }
20671
+ const {
20672
+ node,
20673
+ className,
20674
+ text,
20675
+ style
20676
+ } = val;
20677
+ return h$1(node, {
20678
+ class: className,
20679
+ style
20680
+ }, text);
20681
+ }
20682
+ return null;
20683
+ };
20684
+ const getActionIcon = (item) => {
20685
+ let prefixFnVal = null;
20686
+ if (typeof props.prefixIcon === "function") {
20687
+ prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "action", item);
20688
+ if (prefixFnVal !== "default") {
20689
+ return renderPrefixVal(prefixFnVal);
20690
+ }
20691
+ }
20692
+ if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
20693
+ if (hasChildNode(item) || item.async) {
20694
+ return isItemOpen(item) ? createVNode(downShape, null, null) : createVNode(rightShape, null, null);
20695
+ }
20696
+ }
20697
+ return null;
20698
+ };
20699
+ const getNodePrefixIcon = (item) => {
20700
+ let prefixFnVal = null;
20701
+ if (typeof props.prefixIcon === "function") {
20702
+ prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "node_type", item);
20703
+ if (prefixFnVal !== "default") {
20704
+ return renderPrefixVal(prefixFnVal);
20705
+ }
20706
+ }
20707
+ if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
20708
+ return isRootNode(item) || hasChildNode(item) ? getRootIcon(item) : createVNode(textFile, {
20709
+ "class": resolveClassName("tree-icon")
20710
+ }, null);
20711
+ }
20712
+ return null;
20713
+ };
20714
+ const getLoadingIcon = (item) => item.loading ? createVNode(spinner, null, null) : "";
20715
+ const setNodeOpened = (item) => {
20716
+ const newVal = !isItemOpen(item);
20717
+ setNodeAttr(item, "__isOpen", newVal);
20718
+ if (newVal) {
20719
+ return;
20720
+ }
20721
+ renderData.value.filter((node) => String.prototype.startsWith.call(getNodePath(node), getNodePath(item))).forEach((filterNode) => setNodeAttr(filterNode, "__isOpen", newVal));
20722
+ };
20723
+ const hanldeTreeNodeClick = (item) => {
20724
+ asyncNodeClick(item);
20725
+ if (hasChildNode(item)) {
20726
+ setNodeOpened(item);
20727
+ }
20728
+ };
20729
+ const handleNodeActionClick = (e, node) => {
20730
+ e.stopImmediatePropagation();
20731
+ e.stopPropagation();
20732
+ e.preventDefault();
20733
+ hanldeTreeNodeClick(node);
20734
+ };
20735
+ const handleNodeContentClick = (item) => {
20736
+ if (!checkedNodes.includes(item.__uuid)) {
20737
+ checkedNodes.forEach((__uuid) => setNodeAttr({
20738
+ __uuid
20739
+ }, "__checked", false));
20740
+ checkedNodes.length = 0;
20741
+ setNodeAttr(item, "__checked", true);
20742
+ checkedNodes.push(item.__uuid);
20743
+ if (!isNodeOpened(item)) {
20744
+ hanldeTreeNodeClick(item);
20745
+ }
20746
+ ctx.emit("check", item, getSchemaVal2(item.__uuid));
20747
+ }
20748
+ };
20749
+ const filterNextNode = (depth, node) => {
20750
+ if (isRootNode(node)) {
20751
+ return false;
20752
+ }
20753
+ const nodepath = getNodePath(node);
20754
+ const paths = `${nodepath}`.split("-").slice(0, depth + 1);
20755
+ const currentPath = paths.join("-");
20756
+ if (currentPath === nodepath) {
20757
+ return true;
20758
+ }
20759
+ const lastLevel = paths.pop();
20760
+ const nextLevel = parseInt(lastLevel, 10);
20761
+ paths.push(`${nextLevel + 1}`);
20762
+ const nextNodePath = paths.join("-");
20763
+ return schemaValues.value.some((val) => val.__path === nextNodePath);
20764
+ };
20765
+ const getVirtualLines = (node) => {
20766
+ if (!props.levelLine) {
20767
+ return null;
20768
+ }
20769
+ const getNodeLineStyle = (dpth) => ({
20770
+ "--depth": dpth
20771
+ });
20772
+ const maxDeep = getNodeAttr2(node, "__depth") + 1;
20773
+ return new Array(maxDeep).fill("").map((_2, index) => index).filter((depth) => filterNextNode(depth, node)).filter((depth) => depth > 0).map((index) => createVNode("span", {
20774
+ "class": "node-virtual-line",
20775
+ "style": getNodeLineStyle(maxDeep - index)
20776
+ }, null));
20777
+ };
20778
+ const renderTreeNode = (item) => {
20779
+ var _a, _b, _c, _d, _e;
20780
+ return createVNode("div", {
20781
+ "class": getNodeRowClass(item, flatData.schema)
20782
+ }, [createVNode("div", {
20783
+ "class": getNodeItemClass(item, flatData.schema, props),
20784
+ "style": getNodeItemStyle(item, props, flatData),
20785
+ "onClick": () => handleNodeContentClick(item)
20786
+ }, [createVNode("span", {
20787
+ "class": resolveClassName("node-action"),
20788
+ "onClick": (e) => handleNodeActionClick(e, item)
20789
+ }, [getActionIcon(item)]), createVNode("span", {
20790
+ "class": resolveClassName("node-content")
20791
+ }, [[getNodePrefixIcon(item), getLoadingIcon(item)], createVNode("span", {
20792
+ "class": resolveClassName("node-text")
20793
+ }, [(_e = (_b = (_a = ctx.slots).node) == null ? void 0 : _b.call(_a, item)) != null ? _e : [getLabel(item, props), (_d = (_c = ctx.slots).nodeAppend) == null ? void 0 : _d.call(_c, item)]])]), getVirtualLines(item)])]);
20794
+ };
20795
+ return {
20796
+ renderTreeNode,
20797
+ hanldeTreeNodeClick,
20798
+ deepAutoOpen
20799
+ };
20800
+ };
20541
20801
  var Component = defineComponent({
20542
20802
  name: "Tree",
20543
20803
  props: treeProps,
20544
20804
  emits: ["check"],
20545
20805
  setup(props, ctx) {
20806
+ var _a;
20546
20807
  const formatData = getFlatdata(props);
20547
- const checkedNodes = [];
20548
20808
  const flatData = reactive({
20549
20809
  data: formatData[0],
20550
20810
  schema: formatData[1],
20551
20811
  levelLineSchema: {}
20552
20812
  });
20813
+ const {
20814
+ schemaValues,
20815
+ setNodeAttr,
20816
+ checkNodeIsOpen,
20817
+ getNodeAttr: getNodeAttr2,
20818
+ isRootNode
20819
+ } = useNodeAttribute(flatData);
20820
+ const renderData = computed(() => flatData.data.filter((item) => checkNodeIsOpen(item)));
20821
+ const {
20822
+ renderTreeNode,
20823
+ hanldeTreeNodeClick,
20824
+ deepAutoOpen
20825
+ } = useNodeAction(props, ctx, flatData, renderData);
20826
+ if ((_a = props.async) == null ? void 0 : _a.callback) {
20827
+ deepAutoOpen();
20828
+ }
20553
20829
  watch(() => [props.data], (newData) => {
20830
+ var _a2, _b;
20554
20831
  const formatData2 = getFlatdata(props, newData, schemaValues.value);
20555
20832
  flatData.data = formatData2[0];
20556
20833
  flatData.schema = formatData2[1];
20834
+ if (((_a2 = props.async) == null ? void 0 : _a2.callback) && ((_b = props.async) == null ? void 0 : _b.deepAutoOpen) === "every") {
20835
+ deepAutoOpen();
20836
+ }
20557
20837
  }, {
20558
20838
  deep: true
20559
20839
  });
20560
- const schemaValues = computed(() => Array.from(flatData.schema.values()));
20561
- const getSchemaVal2 = (key) => flatData.schema.get(key);
20562
- const getNodeAttr2 = (node, attr) => {
20563
- var _a;
20564
- return (_a = getSchemaVal2(node.__uuid)) == null ? void 0 : _a[attr];
20565
- };
20566
- const setNodeAttr = (node, attr, val) => flatData.schema.set(node.__uuid, __spreadProps(__spreadValues({}, getSchemaVal2(node.__uuid)), {
20567
- [attr]: val
20568
- }));
20569
- const getNodePath = (node) => getNodeAttr2(node, "__path");
20570
- const isRootNode = (node) => getNodeAttr2(node, "__isRoot");
20571
- const isNodeOpened = (node) => getNodeAttr2(node, "__isOpen");
20572
- const hasChildNode = (node) => getNodeAttr2(node, "__hasChild");
20573
- const renderData = computed(() => flatData.data.filter((item) => checkNodeIsOpen(item)));
20574
- const isItemOpen = (item) => {
20575
- var _a;
20576
- if (typeof item === "object") {
20577
- return isNodeOpened(item);
20578
- }
20579
- if (typeof item === "string") {
20580
- return (_a = getSchemaVal2(item)) == null ? void 0 : _a.__isOpen;
20581
- }
20582
- return false;
20583
- };
20584
- const getRootIcon = (item) => isItemOpen(item) ? createVNode(folderShapeOpen, {
20585
- "class": resolveClassName("tree-icon")
20586
- }, null) : createVNode(folder, {
20587
- "class": resolveClassName("tree-icon")
20588
- }, null);
20589
- const renderPrefixVal = (val) => {
20590
- if (typeof val === "string") {
20591
- return val;
20592
- }
20593
- if (typeof val === "object" && val !== null) {
20594
- if (val.__v_isVNode) {
20595
- return val;
20596
- }
20597
- const {
20598
- node,
20599
- className,
20600
- text,
20601
- style
20602
- } = val;
20603
- return h$1(node, {
20604
- class: className,
20605
- style
20606
- }, text);
20607
- }
20608
- return null;
20609
- };
20610
- const getActionIcon = (item) => {
20611
- let prefixFnVal = null;
20612
- if (typeof props.prefixIcon === "function") {
20613
- prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "action", item);
20614
- if (prefixFnVal !== "default") {
20615
- return renderPrefixVal(prefixFnVal);
20616
- }
20617
- }
20618
- if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
20619
- if (hasChildNode(item) || item.async) {
20620
- return isItemOpen(item) ? createVNode(downShape, null, null) : createVNode(rightShape, null, null);
20621
- }
20622
- }
20623
- return null;
20624
- };
20625
- const getNodePrefixIcon = (item) => {
20626
- let prefixFnVal = null;
20627
- if (typeof props.prefixIcon === "function") {
20628
- prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "node_type", item);
20629
- if (prefixFnVal !== "default") {
20630
- return renderPrefixVal(prefixFnVal);
20631
- }
20840
+ const resolveNodeItem = (node) => {
20841
+ if (typeof node === "string") {
20842
+ return {
20843
+ __uuid: node
20844
+ };
20632
20845
  }
20633
- if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
20634
- return isRootNode(item) || hasChildNode(item) ? getRootIcon(item) : createVNode(textFile, {
20635
- "class": resolveClassName("tree-icon")
20636
- }, null);
20846
+ if (Object.prototype.hasOwnProperty.call(node, "__uuid")) {
20847
+ return node;
20637
20848
  }
20638
- return null;
20849
+ console.error("setNodeAction Error: cannot find uid for the ndoe item");
20850
+ return node;
20639
20851
  };
20640
- const getLoadingIcon = (item) => item.loading ? createVNode(spinner, null, null) : "";
20641
- const setNodeOpened = (item) => {
20642
- const newVal = !isItemOpen(item);
20643
- setNodeAttr(item, "__isOpen", newVal);
20644
- if (newVal) {
20852
+ const setNodeAction = (args, action, value) => {
20853
+ if (Array.isArray(args)) {
20854
+ args.forEach((node) => setNodeAttr(resolveNodeItem(node), action, value));
20645
20855
  return;
20646
20856
  }
20647
- renderData.value.filter((node) => String.prototype.startsWith.call(getNodePath(node), getNodePath(item))).forEach((filterNode) => setNodeAttr(filterNode, "__isOpen", newVal));
20648
- };
20649
- const setNodeRemoteLoad = (resp, item) => {
20650
- if (typeof resp === "object" && resp !== null) {
20651
- setNodeAttr(item, "__isOpen", true);
20652
- const nodeValue = Array.isArray(resp) ? resp : [resp];
20653
- updateTreeNode(getNodePath(item), props.data, props.children, props.children, nodeValue);
20654
- }
20857
+ setNodeAttr(resolveNodeItem(args), action, value);
20655
20858
  };
20656
- const hanldeTreeNodeClick = (item) => {
20657
- if (item.async) {
20658
- const {
20659
- callback = null,
20660
- cache = true
20661
- } = props.async || {};
20662
- if (typeof callback === "function") {
20663
- if (!item.cached) {
20664
- Object.assign(item, {
20665
- loading: true
20666
- });
20667
- callback(item, (resp) => setNodeRemoteLoad(resp, item)).then((resp) => setNodeRemoteLoad(resp, item)).catch((err) => console.error("load remote data error:", err)).finally(() => {
20668
- assignTreeNode(getNodePath(item), props.data, props.children, __spreadValues({
20669
- loading: false
20670
- }, cache ? {
20671
- cached: true
20672
- } : {}));
20673
- });
20674
- }
20675
- } else {
20676
- console.error("async need to set prop: asyncLoad with function wich will return promise object");
20859
+ const setOpen = (item, isOpen = true, autoOpenParents = false) => {
20860
+ const resolvedItem = resolveNodeItem(item);
20861
+ if (autoOpenParents && isOpen) {
20862
+ setNodeAction(resolvedItem, "__isOpen", isOpen);
20863
+ if (!isRootNode(resolvedItem)) {
20864
+ const parentId = getNodeAttr2(resolvedItem, "__parentId");
20865
+ setOpen(parentId, true, true);
20677
20866
  }
20678
- }
20679
- if (hasChildNode(item)) {
20680
- setNodeOpened(item);
20681
- }
20682
- };
20683
- const handleNodeActionClick = (e, node) => {
20684
- e.stopImmediatePropagation();
20685
- e.stopPropagation();
20686
- e.preventDefault();
20687
- hanldeTreeNodeClick(node);
20688
- };
20689
- const handleNodeContentClick = (item) => {
20690
- if (!checkedNodes.includes(item.__uuid)) {
20691
- checkedNodes.forEach((__uuid) => setNodeAttr({
20692
- __uuid
20693
- }, "__checked", false));
20694
- checkedNodes.length = 0;
20695
- setNodeAttr(item, "__checked", true);
20696
- checkedNodes.push(item.__uuid);
20697
- if (!isNodeOpened(item)) {
20698
- hanldeTreeNodeClick(item);
20699
- }
20700
- ctx.emit("check", item, getSchemaVal2(item.__uuid));
20867
+ } else {
20868
+ setNodeAction(resolvedItem, "__isOpen", isOpen);
20701
20869
  }
20702
20870
  };
20703
- const checkNodeIsOpen = (node) => isRootNode(node) || isItemOpen(node) || isItemOpen(getNodeAttr2(node, "__parentId"));
20704
- const filterNextNode = (depth, node) => {
20705
- if (isRootNode(node)) {
20706
- return false;
20707
- }
20708
- const nodepath = getNodePath(node);
20709
- const paths = `${nodepath}`.split("-").slice(0, depth + 1);
20710
- const currentPath = paths.join("-");
20711
- if (currentPath === nodepath) {
20712
- return true;
20713
- }
20714
- const lastLevel = paths.pop();
20715
- const nextLevel = parseInt(lastLevel, 10);
20716
- paths.push(`${nextLevel + 1}`);
20717
- const nextNodePath = paths.join("-");
20718
- return schemaValues.value.some((val) => val.__path === nextNodePath);
20719
- };
20720
- const getVirtualLines = (node) => {
20721
- if (!props.levelLine) {
20722
- return null;
20723
- }
20724
- const getNodeLineStyle = (dpth) => ({
20725
- "--depth": dpth
20726
- });
20727
- const maxDeep = getNodeAttr2(node, "__depth") + 1;
20728
- return new Array(maxDeep).fill("").map((_2, index) => index).filter((depth) => filterNextNode(depth, node)).filter((depth) => depth > 0).map((index) => createVNode("span", {
20729
- "class": "node-virtual-line",
20730
- "style": getNodeLineStyle(maxDeep - index)
20731
- }, null));
20871
+ const setChecked = (item, checked = true) => {
20872
+ setNodeAction(resolveNodeItem(item), "__checked", checked);
20732
20873
  };
20874
+ ctx.expose({
20875
+ hanldeTreeNodeClick,
20876
+ setOpen,
20877
+ setChecked,
20878
+ setNodeAction
20879
+ });
20733
20880
  const root = ref();
20734
20881
  const setNodeTextStyle = () => {
20735
- var _a;
20736
- if ((_a = root.value) == null ? void 0 : _a.$el) {
20882
+ var _a2;
20883
+ if ((_a2 = root.value) == null ? void 0 : _a2.$el) {
20737
20884
  const selector = `.${resolveClassName("tree-node")}`;
20738
20885
  const ctxSelector = `.${resolveClassName("node-content")}`;
20739
20886
  Array.prototype.forEach.call(root.value.$el.querySelectorAll(selector), (nodeEl) => {
@@ -20752,48 +20899,15 @@ var Component = defineComponent({
20752
20899
  onUpdated(() => {
20753
20900
  setNodeTextStyle();
20754
20901
  });
20755
- return {
20756
- renderData,
20757
- flatData,
20758
- root,
20759
- hanldeTreeNodeClick,
20760
- handleNodeContentClick,
20761
- handleNodeActionClick,
20762
- getActionIcon,
20763
- getRootIcon,
20764
- getVirtualLines,
20765
- getNodePrefixIcon,
20766
- getLoadingIcon
20767
- };
20768
- },
20769
- render() {
20770
- const props = this.$props;
20771
- const renderTreeNode = (item) => {
20772
- var _a, _b, _c, _d, _e;
20773
- return createVNode("div", {
20774
- "class": getNodeRowClass(item, this.flatData.schema)
20775
- }, [createVNode("div", {
20776
- "class": getNodeItemClass(item, this.flatData.schema, props),
20777
- "style": getNodeItemStyle(item, props, this.flatData),
20778
- "onClick": () => this.handleNodeContentClick(item)
20779
- }, [createVNode("span", {
20780
- "class": resolveClassName("node-action"),
20781
- "onClick": (e) => this.handleNodeActionClick(e, item)
20782
- }, [this.getActionIcon(item)]), createVNode("span", {
20783
- "class": resolveClassName("node-content")
20784
- }, [[this.getNodePrefixIcon(item), this.getLoadingIcon(item)], createVNode("span", {
20785
- "class": resolveClassName("node-text")
20786
- }, [(_e = (_b = (_a = this.$slots).node) == null ? void 0 : _b.call(_a, item)) != null ? _e : [getLabel(item, props), (_d = (_c = this.$slots).nodeAppend) == null ? void 0 : _d.call(_c, item)]])]), this.getVirtualLines(item)])]);
20787
- };
20788
- return createVNode(BkVirtualRender, {
20902
+ return () => createVNode(BkVirtualRender, {
20789
20903
  "class": resolveClassName("tree"),
20790
20904
  "style": getTreeStyle(null, props),
20791
- "list": this.renderData,
20905
+ "list": renderData.value,
20792
20906
  "lineHeight": props.lineHeight,
20793
20907
  "enabled": props.virtualRender,
20794
20908
  "contentClassName": resolveClassName("container"),
20795
20909
  "throttleDelay": 0,
20796
- "ref": "root"
20910
+ "ref": root
20797
20911
  }, {
20798
20912
  default: (scoped) => (scoped.data || []).map(renderTreeNode)
20799
20913
  });