vue-devui 1.0.0-rc.11 → 1.0.0-rc.12

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 (94) hide show
  1. package/README.md +2 -2
  2. package/auto-complete/index.es.js +29 -8
  3. package/auto-complete/index.umd.js +16 -16
  4. package/auto-complete/style.css +1 -1
  5. package/badge/index.es.js +3 -1
  6. package/badge/index.umd.js +1 -1
  7. package/button/index.es.js +3 -2
  8. package/button/index.umd.js +6 -6
  9. package/collapse/index.es.js +20 -186
  10. package/collapse/index.umd.js +1 -1
  11. package/collapse/style.css +1 -1
  12. package/countdown/index.es.js +56 -13
  13. package/countdown/index.umd.js +1 -1
  14. package/{date-picker → date-picker-pro}/index.d.ts +0 -0
  15. package/date-picker-pro/index.es.js +10856 -0
  16. package/date-picker-pro/index.umd.js +27 -0
  17. package/date-picker-pro/package.json +7 -0
  18. package/date-picker-pro/style.css +1 -0
  19. package/dropdown/index.es.js +1 -1
  20. package/dropdown/index.umd.js +1 -1
  21. package/editable-select/index.es.js +98 -56
  22. package/editable-select/index.umd.js +1 -1
  23. package/editable-select/style.css +1 -1
  24. package/icon/index.es.js +3 -2
  25. package/icon/index.umd.js +1 -1
  26. package/input/index.es.js +35 -8
  27. package/input/index.umd.js +7 -7
  28. package/input/style.css +1 -1
  29. package/modal/index.es.js +3 -2
  30. package/modal/index.umd.js +1 -1
  31. package/modal/style.css +1 -1
  32. package/notification/index.es.js +3 -2
  33. package/notification/index.umd.js +1 -1
  34. package/nuxt/components/DRangeDatePickerPro.js +3 -0
  35. package/nuxt/components/DatePickerPro.js +3 -0
  36. package/nuxt/components/OptionGroup.js +3 -0
  37. package/nuxt/components/Step.js +3 -0
  38. package/nuxt/components/Steps.js +3 -0
  39. package/nuxt/components/TimePicker.js +3 -0
  40. package/nuxt/components/datePickerProCommonProps.js +3 -0
  41. package/nuxt/components/datePickerProPanelProps.js +3 -0
  42. package/nuxt/components/datePickerProProps.js +3 -0
  43. package/nuxt/components/stepProps.js +3 -0
  44. package/nuxt/components/stepsProps.js +3 -0
  45. package/nuxt/components/timerPickerPanelProps.js +3 -0
  46. package/package.json +1 -1
  47. package/pagination/index.es.js +25 -7
  48. package/pagination/index.umd.js +1 -1
  49. package/result/index.es.js +3 -2
  50. package/result/index.umd.js +1 -1
  51. package/search/index.es.js +39 -10
  52. package/search/index.umd.js +7 -7
  53. package/search/style.css +1 -1
  54. package/select/index.es.js +156 -219
  55. package/select/index.umd.js +13 -13
  56. package/select/style.css +1 -1
  57. package/splitter/index.es.js +27 -7
  58. package/splitter/index.umd.js +10 -10
  59. package/steps/index.d.ts +7 -0
  60. package/steps/index.es.js +385 -0
  61. package/steps/index.umd.js +1 -0
  62. package/{date-picker → steps}/package.json +1 -1
  63. package/steps/style.css +1 -0
  64. package/style.css +1 -1
  65. package/table/index.es.js +542 -267
  66. package/table/index.umd.js +15 -15
  67. package/table/style.css +1 -1
  68. package/tabs/index.es.js +1 -1
  69. package/tabs/index.umd.js +1 -1
  70. package/tabs/style.css +1 -1
  71. package/time-picker/index.d.ts +7 -0
  72. package/{date-picker → time-picker}/index.es.js +1371 -1038
  73. package/time-picker/index.umd.js +27 -0
  74. package/time-picker/package.json +7 -0
  75. package/time-picker/style.css +1 -0
  76. package/time-select/index.es.js +157 -219
  77. package/time-select/index.umd.js +14 -14
  78. package/time-select/style.css +1 -1
  79. package/timeline/index.es.js +3 -2
  80. package/timeline/index.umd.js +1 -1
  81. package/tooltip/index.es.js +1 -1
  82. package/tooltip/index.umd.js +1 -1
  83. package/tree/index.es.js +186 -59
  84. package/tree/index.umd.js +16 -16
  85. package/tree/style.css +1 -1
  86. package/upload/index.es.js +51 -25
  87. package/upload/index.umd.js +1 -1
  88. package/upload/style.css +1 -1
  89. package/vue-devui.es.js +3963 -1421
  90. package/vue-devui.umd.js +23 -23
  91. package/date-picker/index.umd.js +0 -27
  92. package/date-picker/style.css +0 -1
  93. package/nuxt/components/DatePicker.js +0 -3
  94. package/nuxt/components/StickSlider.js +0 -3
package/tree/index.es.js CHANGED
@@ -29,9 +29,10 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
- import { createVNode, defineComponent, toRefs, inject, watch, provide, reactive, onUnmounted, Transition, mergeProps, ref, unref, nextTick, Comment, Text, h, Fragment, withDirectives, cloneVNode, computed, onMounted, Teleport, createTextVNode, onBeforeUnmount, toRef, renderSlot, useSlots, isVNode, getCurrentInstance, onUpdated, shallowRef, toRaw, watchEffect } from "vue";
32
+ import { createVNode, defineComponent, toRefs, inject, watch, provide, reactive, onUnmounted, Transition, mergeProps, ref, unref, nextTick, Comment, Text, h, Fragment, withDirectives, cloneVNode, computed, onMounted, Teleport, createTextVNode, onBeforeUnmount, toRef, getCurrentInstance, renderSlot, useSlots, resolveComponent, isVNode, onUpdated, shallowRef, toRaw, watchEffect } from "vue";
33
33
  import { offset, autoPlacement, arrow, shift, computePosition } from "@floating-ui/dom";
34
34
  const USE_TREE_TOKEN = "use-tree-token";
35
+ const TREE_INSTANCE = "tree-instance";
35
36
  const NODE_HEIGHT = 30;
36
37
  const NODE_INDENT = 24;
37
38
  const IconClose = () => createVNode("svg", {
@@ -1384,7 +1385,7 @@ var lodash = { exports: {} };
1384
1385
  function baseAt(object4, paths) {
1385
1386
  var index2 = -1, length = paths.length, result2 = Array2(length), skip = object4 == null;
1386
1387
  while (++index2 < length) {
1387
- result2[index2] = skip ? undefined$1 : get(object4, paths[index2]);
1388
+ result2[index2] = skip ? undefined$1 : get2(object4, paths[index2]);
1388
1389
  }
1389
1390
  return result2;
1390
1391
  }
@@ -1829,7 +1830,7 @@ var lodash = { exports: {} };
1829
1830
  return matchesStrictComparable(toKey(path), srcValue);
1830
1831
  }
1831
1832
  return function(object4) {
1832
- var objValue = get(object4, path);
1833
+ var objValue = get2(object4, path);
1833
1834
  return objValue === undefined$1 && objValue === srcValue ? hasIn(object4, path) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
1834
1835
  };
1835
1836
  }
@@ -4562,7 +4563,7 @@ var lodash = { exports: {} };
4562
4563
  function functionsIn(object4) {
4563
4564
  return object4 == null ? [] : baseFunctions(object4, keysIn(object4));
4564
4565
  }
4565
- function get(object4, path, defaultValue) {
4566
+ function get2(object4, path, defaultValue) {
4566
4567
  var result2 = object4 == null ? undefined$1 : baseGet(object4, path);
4567
4568
  return result2 === undefined$1 ? defaultValue : result2;
4568
4569
  }
@@ -5417,7 +5418,7 @@ var lodash = { exports: {} };
5417
5418
  lodash2.forInRight = forInRight;
5418
5419
  lodash2.forOwn = forOwn;
5419
5420
  lodash2.forOwnRight = forOwnRight;
5420
- lodash2.get = get;
5421
+ lodash2.get = get2;
5421
5422
  lodash2.gt = gt;
5422
5423
  lodash2.gte = gte;
5423
5424
  lodash2.has = has;
@@ -8301,6 +8302,7 @@ function useTreeNode(data) {
8301
8302
  var _a;
8302
8303
  return [ns.e("node-title"), ((_a = data.value) == null ? void 0 : _a.disableSelect) && "select-disabled"];
8303
8304
  });
8305
+ const nodeOperationAreaClass = computed(() => ns.e("node-operation-area"));
8304
8306
  return {
8305
8307
  nodeClass,
8306
8308
  nodeStyle,
@@ -8308,7 +8310,8 @@ function useTreeNode(data) {
8308
8310
  nodeTitleClass,
8309
8311
  nodeVLineClass,
8310
8312
  nodeVLineStyles,
8311
- nodeHLineClass
8313
+ nodeHLineClass,
8314
+ nodeOperationAreaClass
8312
8315
  };
8313
8316
  }
8314
8317
  var DTreeNodeContent = defineComponent({
@@ -8334,6 +8337,27 @@ var DTreeNodeContent = defineComponent({
8334
8337
  };
8335
8338
  }
8336
8339
  });
8340
+ const formatCheckStatus = (check) => {
8341
+ return typeof check === "boolean" ? check ? "both" : "none" : check;
8342
+ };
8343
+ const camelize = (name) => name.substring(1).replace(/^\S/, (s) => s.toLocaleLowerCase());
8344
+ function get(object4, path) {
8345
+ const keys = path.split(".");
8346
+ let result = object4;
8347
+ keys.forEach((key) => {
8348
+ var _a;
8349
+ result = (_a = result[key]) != null ? _a : "";
8350
+ });
8351
+ return result;
8352
+ }
8353
+ function createI18nTranslate(name, app, newPrefix) {
8354
+ const prefix = newPrefix || camelize(name) + ".";
8355
+ return (path) => {
8356
+ const messages2 = app == null ? void 0 : app.appContext.config.globalProperties.langMessages.value;
8357
+ const message = get(messages2, prefix + path) || get(messages2, path);
8358
+ return message;
8359
+ };
8360
+ }
8337
8361
  var DTreeNode = defineComponent({
8338
8362
  name: "DTreeNode",
8339
8363
  props: {
@@ -8342,23 +8366,33 @@ var DTreeNode = defineComponent({
8342
8366
  default: () => ({})
8343
8367
  },
8344
8368
  check: {
8345
- type: Boolean,
8369
+ type: [Boolean, String],
8370
+ default: false
8371
+ },
8372
+ operate: {
8373
+ type: [Boolean, String, Array],
8346
8374
  default: false
8347
8375
  }
8348
8376
  },
8349
8377
  setup(props, {
8350
8378
  slots
8351
8379
  }) {
8380
+ const app = getCurrentInstance();
8381
+ const t = createI18nTranslate("DTree", app);
8352
8382
  const {
8353
8383
  data,
8354
- check
8384
+ check,
8385
+ operate
8355
8386
  } = toRefs(props);
8356
8387
  const {
8357
8388
  toggleSelectNode,
8358
8389
  toggleCheckNode,
8359
8390
  toggleNode,
8360
- getChildren
8391
+ getChildren,
8392
+ insertBefore,
8393
+ removeNode
8361
8394
  } = inject(USE_TREE_TOKEN);
8395
+ const treeInstance = inject(TREE_INSTANCE);
8362
8396
  const ns2 = useNamespace("tree");
8363
8397
  const {
8364
8398
  nodeClass,
@@ -8366,23 +8400,29 @@ var DTreeNode = defineComponent({
8366
8400
  nodeContentClass,
8367
8401
  nodeVLineClass,
8368
8402
  nodeVLineStyles,
8369
- nodeHLineClass
8403
+ nodeHLineClass,
8404
+ nodeOperationAreaClass
8370
8405
  } = useTreeNode(data);
8371
8406
  const halfChecked = computed(() => {
8372
- const children = getChildren == null ? void 0 : getChildren(data.value);
8373
- const checkedChildren = children == null ? void 0 : children.filter((item) => item.checked);
8374
- if (["upward", "both"].includes(check.value)) {
8407
+ var _a;
8408
+ if (!((_a = data.value) == null ? void 0 : _a.checked)) {
8409
+ return false;
8410
+ }
8411
+ const checkFormat = formatCheckStatus(check.value);
8412
+ if (["upward", "both"].includes(checkFormat)) {
8413
+ const children = (getChildren == null ? void 0 : getChildren(data.value)) || [];
8414
+ const checkedChildren = children == null ? void 0 : children.filter((item) => item.checked);
8375
8415
  return checkedChildren.length > 0 && checkedChildren.length < children.length;
8376
8416
  } else {
8377
8417
  return false;
8378
8418
  }
8379
8419
  });
8380
- return () => {
8420
+ const checkboxProps2 = computed(() => {
8381
8421
  var _a, _b, _c;
8382
- const checkboxProps2 = {
8422
+ return {
8383
8423
  key: (_a = data.value) == null ? void 0 : _a.id,
8384
8424
  disabled: (_b = data.value) == null ? void 0 : _b.disableCheck,
8385
- halfchecked: halfChecked.value,
8425
+ halfChecked: halfChecked.value,
8386
8426
  modelValue: (_c = data.value) == null ? void 0 : _c.checked,
8387
8427
  "onUpdate:modelValue": () => {
8388
8428
  toggleCheckNode == null ? void 0 : toggleCheckNode(data.value);
@@ -8391,9 +8431,20 @@ var DTreeNode = defineComponent({
8391
8431
  event.stopPropagation();
8392
8432
  }
8393
8433
  };
8434
+ });
8435
+ const isShowOperationArea = ref(false);
8436
+ const showOperationArea = () => {
8437
+ isShowOperationArea.value = true;
8438
+ };
8439
+ const hideOperationArea = () => {
8440
+ isShowOperationArea.value = false;
8441
+ };
8442
+ return () => {
8394
8443
  return createVNode("div", {
8395
8444
  "class": nodeClass.value,
8396
- "style": nodeStyle.value
8445
+ "style": nodeStyle.value,
8446
+ "onMouseenter": showOperationArea,
8447
+ "onMouseleave": hideOperationArea
8397
8448
  }, [nodeVLineStyles.value.map((item) => createVNode("span", {
8398
8449
  "class": nodeVLineClass.value,
8399
8450
  "style": item
@@ -8401,6 +8452,7 @@ var DTreeNode = defineComponent({
8401
8452
  "class": nodeContentClass.value,
8402
8453
  "onClick": () => {
8403
8454
  toggleSelectNode == null ? void 0 : toggleSelectNode(data.value);
8455
+ treeInstance.emit("node-click", data.value);
8404
8456
  }
8405
8457
  }, [createVNode("span", {
8406
8458
  "class": nodeHLineClass.value
@@ -8414,10 +8466,24 @@ var DTreeNode = defineComponent({
8414
8466
  "style": {
8415
8467
  height: `${NODE_HEIGHT}px`
8416
8468
  }
8417
- }, [check.value && createVNode(Checkbox, checkboxProps2, null), slots.default ? renderSlot(useSlots(), "default", {
8469
+ }, [check.value && createVNode(Checkbox, checkboxProps2.value, null), slots.default ? renderSlot(useSlots(), "default", {
8418
8470
  nodeData: data
8419
8471
  }) : createVNode(DTreeNodeContent, {
8420
8472
  "data": data.value
8473
+ }, null)]), operate.value && isShowOperationArea.value && createVNode("div", {
8474
+ "class": nodeOperationAreaClass.value
8475
+ }, [createVNode(resolveComponent("d-icon"), {
8476
+ "name": "add",
8477
+ "onClick": () => {
8478
+ insertBefore(data.value, {
8479
+ label: t("newNode") || "New node"
8480
+ });
8481
+ }
8482
+ }, null), createVNode(resolveComponent("d-icon"), {
8483
+ "name": "delete",
8484
+ "onClick": () => {
8485
+ removeNode(data.value);
8486
+ }
8421
8487
  }, null)])])]);
8422
8488
  };
8423
8489
  }
@@ -8845,6 +8911,8 @@ var ResizeObserverContainer = defineComponent({
8845
8911
  top: 0
8846
8912
  });
8847
8913
  }
8914
+ }, {
8915
+ immediate: true
8848
8916
  });
8849
8917
  return () => createVNode("div", {
8850
8918
  "style": outerStyle.value
@@ -9104,6 +9172,7 @@ const ScrollStyle = {
9104
9172
  overflowY: "auto",
9105
9173
  overflowAnchor: "none"
9106
9174
  };
9175
+ const DEFAULT_HEIGHT = 20;
9107
9176
  var VirtualList = defineComponent({
9108
9177
  name: "DVirtualList",
9109
9178
  props: virtualListProps,
@@ -9212,7 +9281,7 @@ var VirtualList = defineComponent({
9212
9281
  cacheHeight = heights.get(key);
9213
9282
  }
9214
9283
  if (cacheHeight === void 0) {
9215
- cacheHeight = props.itemHeight || 20;
9284
+ cacheHeight = props.itemHeight || DEFAULT_HEIGHT;
9216
9285
  }
9217
9286
  const currentItemBottom = itemTop + cacheHeight;
9218
9287
  if (startIndex === void 0 && currentItemBottom >= scrollTop) {
@@ -9346,6 +9415,11 @@ var VirtualList = defineComponent({
9346
9415
  }, {
9347
9416
  flush: "post"
9348
9417
  });
9418
+ ctx.expose({
9419
+ scrollTo(index2) {
9420
+ syncScrollTop(index2 * (props.itemHeight || DEFAULT_HEIGHT));
9421
+ }
9422
+ });
9349
9423
  return () => {
9350
9424
  const Component = props.component;
9351
9425
  return createVNode("div", {
@@ -9385,28 +9459,30 @@ var VirtualList = defineComponent({
9385
9459
  }
9386
9460
  });
9387
9461
  function useToggle() {
9388
- return function useToggle2(data, core) {
9462
+ return function useToggle2(data, core, context) {
9389
9463
  const { getNode, setNodeValue } = core;
9390
9464
  const expandNode = (node) => {
9391
9465
  if (node.disableToggle) {
9392
9466
  return;
9393
9467
  }
9394
9468
  setNodeValue(node, "expanded", true);
9469
+ context.emit("toggle-change", node);
9395
9470
  };
9396
9471
  const collapseNode = (node) => {
9397
9472
  if (node.disableToggle) {
9398
9473
  return;
9399
9474
  }
9400
9475
  setNodeValue(node, "expanded", false);
9476
+ context.emit("toggle-change", node);
9401
9477
  };
9402
9478
  const toggleNode = (node) => {
9403
9479
  if (node.disableToggle) {
9404
9480
  return;
9405
9481
  }
9406
9482
  if (getNode(node).expanded) {
9407
- setNodeValue(node, "expanded", false);
9483
+ collapseNode(node);
9408
9484
  } else {
9409
- setNodeValue(node, "expanded", true);
9485
+ expandNode(node);
9410
9486
  }
9411
9487
  };
9412
9488
  const expandAllNodes = () => {
@@ -9466,11 +9542,12 @@ const DEFAULT_CONFIG = {
9466
9542
  expanded: false,
9467
9543
  recursive: true
9468
9544
  };
9545
+ const nodeMap = /* @__PURE__ */ new Map();
9469
9546
  function useCore() {
9470
- const nodeMap = /* @__PURE__ */ new Map();
9471
9547
  return function useCore2(data) {
9472
9548
  const getLevel = (node) => {
9473
- return data.value.find((item) => item.id === node.id).level;
9549
+ var _a;
9550
+ return (_a = data.value.find((item) => item.id === node.id)) == null ? void 0 : _a.level;
9474
9551
  };
9475
9552
  const getChildren = (node, userConfig = DEFAULT_CONFIG) => {
9476
9553
  if (node.isLeaf) {
@@ -9536,6 +9613,9 @@ function useCore() {
9536
9613
  });
9537
9614
  };
9538
9615
  const getIndex = (node) => {
9616
+ if (!node) {
9617
+ return -1;
9618
+ }
9539
9619
  return data.value.findIndex((item) => item.id === node.id);
9540
9620
  };
9541
9621
  const getNode = (node) => {
@@ -9543,12 +9623,17 @@ function useCore() {
9543
9623
  };
9544
9624
  const setNodeValue = (node, key, value) => {
9545
9625
  nodeMap.clear();
9546
- data.value[getIndex(node)][key] = value;
9626
+ if (getIndex(node) !== -1) {
9627
+ data.value[getIndex(node)][key] = value;
9628
+ }
9547
9629
  };
9548
9630
  const setTree = (newTree) => {
9549
9631
  nodeMap.clear();
9550
9632
  data.value = generateInnerTree(newTree);
9551
9633
  };
9634
+ const getTree = () => {
9635
+ return data.value;
9636
+ };
9552
9637
  onUnmounted(() => {
9553
9638
  nodeMap.clear();
9554
9639
  });
@@ -9560,76 +9645,92 @@ function useCore() {
9560
9645
  getIndex,
9561
9646
  getNode,
9562
9647
  setNodeValue,
9563
- setTree
9648
+ setTree,
9649
+ getTree
9564
9650
  };
9565
9651
  };
9566
9652
  }
9567
9653
  const DEFAULT_TREE_PLUGINS = [useCore(), useToggle()];
9568
- function useTree(tree2, plugins = []) {
9654
+ function useTree(tree2, plugins = [], context) {
9569
9655
  const treeData = ref(generateInnerTree(tree2));
9570
9656
  const core = useCore()(treeData);
9571
9657
  const pluginMethods = DEFAULT_TREE_PLUGINS.concat(plugins).reduce((acc, plugin) => {
9572
- return __spreadValues(__spreadValues({}, acc), plugin(treeData, core));
9658
+ return __spreadValues(__spreadValues({}, acc), plugin(treeData, core, context));
9573
9659
  }, {});
9574
9660
  return __spreadValues({
9575
9661
  treeData
9576
9662
  }, pluginMethods);
9577
9663
  }
9578
9664
  function useCheck(options = ref({ checkStrategy: "both" })) {
9579
- return function useCheck2(data, core) {
9665
+ return function useCheck2(data, core, context) {
9580
9666
  const { setNodeValue, getNode, getChildren, getParent } = core;
9581
9667
  const checkNode = (node) => {
9582
9668
  setNodeValue(node, "checked", true);
9669
+ context.emit("check-change", node);
9583
9670
  };
9584
9671
  const uncheckNode = (node) => {
9585
9672
  setNodeValue(node, "checked", false);
9673
+ context.emit("check-change", node);
9586
9674
  };
9587
- const controlParentNodeChecked = (node) => {
9675
+ const controlParentNodeChecked = (node, checked) => {
9676
+ if (!node.parentId) {
9677
+ return;
9678
+ }
9588
9679
  const parentNode = getParent(node);
9589
9680
  if (!parentNode) {
9590
9681
  return;
9591
9682
  }
9592
- const siblingNodes = getChildren(parentNode, { recursive: false });
9593
- const checkedSiblingNodes = siblingNodes.filter((item) => item.checked);
9594
- const toggleParentChecked = () => {
9683
+ let childChecked = checked;
9684
+ if (checked) {
9685
+ if (!parentNode.checked) {
9686
+ setNodeValue(parentNode, "checked", true);
9687
+ }
9688
+ } else {
9689
+ const siblingNodes = getChildren(parentNode);
9690
+ const checkedSiblingNodes = siblingNodes.filter((item) => item.checked && item.id !== node.id);
9595
9691
  if (checkedSiblingNodes.length === 0) {
9596
9692
  setNodeValue(parentNode, "checked", false);
9597
- } else if (checkedSiblingNodes.length === siblingNodes.length) {
9693
+ } else {
9598
9694
  setNodeValue(parentNode, "checked", true);
9695
+ childChecked = true;
9599
9696
  }
9600
- };
9697
+ }
9601
9698
  if (parentNode.parentId) {
9602
- toggleParentChecked();
9603
- controlParentNodeChecked(parentNode);
9604
- } else {
9605
- toggleParentChecked();
9699
+ controlParentNodeChecked(parentNode, childChecked);
9606
9700
  }
9607
9701
  };
9608
9702
  const toggleCheckNode = (node) => {
9609
- if (getNode(node).checked) {
9703
+ const checked = getNode(node).checked;
9704
+ if (checked) {
9610
9705
  setNodeValue(node, "checked", false);
9706
+ context.emit("check-change", node);
9611
9707
  if (["downward", "both"].includes(options.value.checkStrategy)) {
9612
9708
  getChildren(node).forEach((item) => setNodeValue(item, "checked", false));
9613
9709
  }
9614
9710
  } else {
9615
9711
  setNodeValue(node, "checked", true);
9712
+ context.emit("check-change", node);
9616
9713
  if (["downward", "both"].includes(options.value.checkStrategy)) {
9617
9714
  getChildren(node).forEach((item) => setNodeValue(item, "checked", true));
9618
9715
  }
9619
9716
  }
9620
9717
  if (["upward", "both"].includes(options.value.checkStrategy)) {
9621
- controlParentNodeChecked(node);
9718
+ controlParentNodeChecked(node, !checked);
9622
9719
  }
9623
9720
  };
9721
+ const getCheckedNodes = () => {
9722
+ return data.value.filter((node) => node.checked);
9723
+ };
9624
9724
  return {
9625
9725
  checkNode,
9626
9726
  uncheckNode,
9627
- toggleCheckNode
9727
+ toggleCheckNode,
9728
+ getCheckedNodes
9628
9729
  };
9629
9730
  };
9630
9731
  }
9631
9732
  function useSelect() {
9632
- return function useSelect2(data, core) {
9733
+ return function useSelect2(data, core, context) {
9633
9734
  const { setNodeValue } = core;
9634
9735
  let prevActiveNode;
9635
9736
  const selectNode = (node) => {
@@ -9641,10 +9742,12 @@ function useSelect() {
9641
9742
  setNodeValue(data.value[prevActiveNodeIndex], "selected", false);
9642
9743
  }
9643
9744
  setNodeValue(node, "selected", true);
9745
+ context.emit("select-change", node);
9644
9746
  prevActiveNode = node;
9645
9747
  };
9646
9748
  const deselectNode = (node) => {
9647
9749
  setNodeValue(node, "selected", false);
9750
+ context.emit("select-change", node);
9648
9751
  };
9649
9752
  const toggleSelectNode = (node) => {
9650
9753
  if (node.selected) {
@@ -9653,10 +9756,14 @@ function useSelect() {
9653
9756
  selectNode(node);
9654
9757
  }
9655
9758
  };
9759
+ const getSelectedNode = () => {
9760
+ return data.value.find((node) => node.selected);
9761
+ };
9656
9762
  return {
9657
9763
  selectNode,
9658
9764
  deselectNode,
9659
- toggleSelectNode
9765
+ toggleSelectNode,
9766
+ getSelectedNode
9660
9767
  };
9661
9768
  };
9662
9769
  }
@@ -9664,7 +9771,9 @@ function useOperate() {
9664
9771
  return function useOperate2(data, core) {
9665
9772
  const { setNodeValue, getChildren, getIndex, getLevel } = core;
9666
9773
  const insertBefore = (parentNode, node, referenceNode) => {
9667
- const children = getChildren(parentNode);
9774
+ const children = getChildren(parentNode, {
9775
+ recursive: false
9776
+ });
9668
9777
  const lastChild = children[children.length - 1];
9669
9778
  let insertedIndex = getIndex(parentNode) + 1;
9670
9779
  if (referenceNode) {
@@ -9674,12 +9783,20 @@ function useOperate() {
9674
9783
  }
9675
9784
  setNodeValue(parentNode, "expanded", true);
9676
9785
  setNodeValue(parentNode, "isLeaf", false);
9677
- const currentNode = __spreadProps(__spreadValues({}, node), {
9786
+ if (lastChild) {
9787
+ setNodeValue(lastChild, "parentChildNode", children.length + 1);
9788
+ }
9789
+ const currentNode = ref(__spreadProps(__spreadValues({}, node), {
9678
9790
  level: getLevel(parentNode) + 1,
9679
9791
  parentId: parentNode.id,
9680
- isLeaf: true
9681
- });
9682
- data.value = data.value.slice(0, insertedIndex).concat(currentNode, data.value.slice(insertedIndex, data.value.length));
9792
+ isLeaf: true,
9793
+ parentChildNode: children.length + 1,
9794
+ currentIndex: (lastChild == null ? void 0 : lastChild.currentIndex) + 1
9795
+ }));
9796
+ if (currentNode.value.id === void 0) {
9797
+ currentNode.value.id = randomId();
9798
+ }
9799
+ data.value = data.value.slice(0, insertedIndex).concat(currentNode.value, data.value.slice(insertedIndex, data.value.length));
9683
9800
  };
9684
9801
  const removeNode = (node, config = { recursive: true }) => {
9685
9802
  if (!config.recursive) {
@@ -9749,6 +9866,10 @@ const treeProps = {
9749
9866
  type: [Boolean, String],
9750
9867
  default: false
9751
9868
  },
9869
+ operate: {
9870
+ type: [Boolean, String, Array],
9871
+ default: false
9872
+ },
9752
9873
  height: {
9753
9874
  type: [Number, String]
9754
9875
  }
@@ -9757,26 +9878,30 @@ var tree = "";
9757
9878
  var Tree = defineComponent({
9758
9879
  name: "DTree",
9759
9880
  props: treeProps,
9760
- setup(props, {
9761
- slots,
9762
- expose
9763
- }) {
9881
+ emits: ["toggle-change", "check-change", "select-change", "node-click"],
9882
+ setup(props, context) {
9883
+ const {
9884
+ slots,
9885
+ expose
9886
+ } = context;
9887
+ const treeInstance = getCurrentInstance();
9764
9888
  const {
9765
9889
  data,
9766
- check
9890
+ check,
9891
+ operate
9767
9892
  } = toRefs(props);
9768
9893
  const ns2 = useNamespace("tree");
9769
9894
  const userPlugins = [useSelect(), useOperate(), useMergeNodes()];
9770
9895
  const checkOptions = ref({
9771
- checkStrategy: check.value || "both"
9896
+ checkStrategy: formatCheckStatus(check.value)
9772
9897
  });
9773
9898
  watch(check, (newVal) => {
9774
- checkOptions.value.checkStrategy = newVal;
9899
+ checkOptions.value.checkStrategy = formatCheckStatus(newVal);
9775
9900
  });
9776
9901
  if (check.value) {
9777
9902
  userPlugins.push(useCheck(checkOptions));
9778
9903
  }
9779
- const treeFactory = useTree(data.value, userPlugins);
9904
+ const treeFactory = useTree(data.value, userPlugins, context);
9780
9905
  const {
9781
9906
  setTree,
9782
9907
  getExpendedTree,
@@ -9784,6 +9909,7 @@ var Tree = defineComponent({
9784
9909
  } = treeFactory;
9785
9910
  watch(data, setTree);
9786
9911
  provide(USE_TREE_TOKEN, treeFactory);
9912
+ provide(TREE_INSTANCE, treeInstance);
9787
9913
  expose({
9788
9914
  treeFactory
9789
9915
  });
@@ -9792,7 +9918,8 @@ var Tree = defineComponent({
9792
9918
  nodeData: treeNode
9793
9919
  }) : createVNode(DTreeNode, {
9794
9920
  "data": treeNode,
9795
- "check": check.value
9921
+ "check": check.value,
9922
+ "operate": operate.value
9796
9923
  }, {
9797
9924
  default: () => slots.content ? renderSlot(useSlots(), "content", {
9798
9925
  nodeData: treeNode
@@ -9830,7 +9957,7 @@ var Tree = defineComponent({
9830
9957
  var index = {
9831
9958
  title: "Tree \u6811",
9832
9959
  category: "\u6570\u636E\u5C55\u793A",
9833
- status: "20%",
9960
+ status: "50%",
9834
9961
  install(app) {
9835
9962
  app.component(Tree.name, Tree);
9836
9963
  }