vue-devui 1.0.0-rc.10 → 1.0.0-rc.13

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 (137) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +156 -149
  3. package/auto-complete/index.es.js +53 -23
  4. package/auto-complete/index.umd.js +15 -15
  5. package/auto-complete/style.css +1 -1
  6. package/badge/index.es.js +8 -2
  7. package/badge/index.umd.js +1 -1
  8. package/badge/style.css +1 -1
  9. package/button/index.es.js +5 -3
  10. package/button/index.umd.js +6 -6
  11. package/button/style.css +1 -1
  12. package/card/index.es.js +5 -1
  13. package/card/index.umd.js +1 -1
  14. package/card/style.css +1 -1
  15. package/checkbox/index.es.js +22 -14
  16. package/checkbox/index.umd.js +7 -7
  17. package/checkbox/style.css +1 -1
  18. package/collapse/index.es.js +20 -186
  19. package/collapse/index.umd.js +1 -1
  20. package/collapse/style.css +1 -1
  21. package/countdown/index.es.js +56 -13
  22. package/countdown/index.umd.js +1 -1
  23. package/{date-picker → date-picker-pro}/index.d.ts +0 -0
  24. package/date-picker-pro/index.es.js +10867 -0
  25. package/date-picker-pro/index.umd.js +27 -0
  26. package/date-picker-pro/package.json +7 -0
  27. package/date-picker-pro/style.css +1 -0
  28. package/dropdown/index.es.js +9 -2
  29. package/dropdown/index.umd.js +1 -1
  30. package/editable-select/index.es.js +98 -56
  31. package/editable-select/index.umd.js +1 -1
  32. package/editable-select/style.css +1 -1
  33. package/form/index.es.js +22 -14
  34. package/form/index.umd.js +11 -11
  35. package/icon/index.es.js +5 -3
  36. package/icon/index.umd.js +1 -1
  37. package/icon/style.css +1 -1
  38. package/image-preview/style.css +1 -1
  39. package/input/index.es.js +59 -23
  40. package/input/index.umd.js +7 -7
  41. package/input/style.css +1 -1
  42. package/input-number/index.es.js +1 -4
  43. package/input-number/index.umd.js +1 -1
  44. package/input-number/style.css +1 -1
  45. package/modal/index.es.js +5 -3
  46. package/modal/index.umd.js +1 -1
  47. package/modal/style.css +1 -1
  48. package/notification/index.es.js +32 -34
  49. package/notification/index.umd.js +1 -1
  50. package/notification/style.css +1 -1
  51. package/nuxt/components/DRangeDatePickerPro.js +3 -0
  52. package/nuxt/components/DatePickerPro.js +3 -0
  53. package/nuxt/components/OptionGroup.js +3 -0
  54. package/nuxt/components/Step.js +3 -0
  55. package/nuxt/components/Steps.js +3 -0
  56. package/nuxt/components/TABLE_TOKEN.js +3 -0
  57. package/nuxt/components/TimePicker.js +3 -0
  58. package/nuxt/components/TimeSelect.js +3 -0
  59. package/nuxt/components/datePickerProCommonProps.js +3 -0
  60. package/nuxt/components/datePickerProPanelProps.js +3 -0
  61. package/nuxt/components/datePickerProProps.js +3 -0
  62. package/nuxt/components/stepProps.js +3 -0
  63. package/nuxt/components/stepsProps.js +3 -0
  64. package/nuxt/components/tableProps.js +3 -0
  65. package/nuxt/components/timerPickerPanelProps.js +3 -0
  66. package/package.json +2 -1
  67. package/pagination/index.es.js +25 -7
  68. package/pagination/index.umd.js +1 -1
  69. package/pagination/style.css +1 -1
  70. package/panel/style.css +1 -1
  71. package/radio/index.es.js +22 -14
  72. package/radio/index.umd.js +8 -8
  73. package/radio/style.css +1 -1
  74. package/rate/style.css +1 -1
  75. package/result/index.es.js +5 -3
  76. package/result/index.umd.js +1 -1
  77. package/result/style.css +1 -1
  78. package/search/index.es.js +65 -26
  79. package/search/index.umd.js +7 -7
  80. package/search/style.css +1 -1
  81. package/select/index.es.js +270 -269
  82. package/select/index.umd.js +13 -13
  83. package/select/style.css +1 -1
  84. package/slider/index.es.js +116 -143
  85. package/slider/index.umd.js +1 -1
  86. package/slider/style.css +1 -1
  87. package/splitter/index.es.js +27 -7
  88. package/splitter/index.umd.js +10 -10
  89. package/statistic/index.es.js +34 -16
  90. package/statistic/index.umd.js +1 -1
  91. package/statistic/style.css +1 -1
  92. package/status/style.css +1 -1
  93. package/steps/index.d.ts +7 -0
  94. package/steps/index.es.js +386 -0
  95. package/steps/index.umd.js +1 -0
  96. package/{date-picker → steps}/package.json +1 -1
  97. package/steps/style.css +1 -0
  98. package/style.css +1 -1
  99. package/switch/index.es.js +22 -14
  100. package/switch/index.umd.js +9 -9
  101. package/switch/style.css +1 -1
  102. package/table/index.es.js +873 -441
  103. package/table/index.umd.js +15 -15
  104. package/table/style.css +1 -1
  105. package/tabs/index.es.js +25 -13
  106. package/tabs/index.umd.js +1 -1
  107. package/tabs/style.css +1 -1
  108. package/textarea/index.es.js +22 -14
  109. package/textarea/index.umd.js +10 -10
  110. package/textarea/style.css +1 -1
  111. package/time-picker/index.d.ts +7 -0
  112. package/{date-picker → time-picker}/index.es.js +1408 -1053
  113. package/time-picker/index.umd.js +27 -0
  114. package/time-picker/package.json +7 -0
  115. package/time-picker/style.css +1 -0
  116. package/time-select/index.d.ts +7 -0
  117. package/time-select/index.es.js +9435 -0
  118. package/time-select/index.umd.js +27 -0
  119. package/time-select/package.json +7 -0
  120. package/time-select/style.css +1 -0
  121. package/timeline/index.es.js +5 -3
  122. package/timeline/index.umd.js +1 -1
  123. package/timeline/style.css +1 -1
  124. package/tooltip/index.es.js +1 -1
  125. package/tooltip/index.umd.js +1 -1
  126. package/tree/index.es.js +1322 -126
  127. package/tree/index.umd.js +17 -17
  128. package/tree/style.css +1 -1
  129. package/upload/index.es.js +128 -67
  130. package/upload/index.umd.js +1 -1
  131. package/upload/style.css +1 -1
  132. package/vue-devui.es.js +6605 -2566
  133. package/vue-devui.umd.js +23 -23
  134. package/date-picker/index.umd.js +0 -27
  135. package/date-picker/style.css +0 -1
  136. package/nuxt/components/DatePicker.js +0 -3
  137. 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 } from "vue";
32
+ import { createVNode, defineComponent, toRefs, inject, getCurrentInstance, watch, provide, reactive, onUnmounted, Transition, mergeProps, ref, unref, nextTick, Comment, Text, h, Fragment, withDirectives, cloneVNode, computed, onMounted, Teleport, createTextVNode, onBeforeUnmount, toRef, 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", {
@@ -141,6 +142,37 @@ var DTreeNodeToggle = defineComponent({
141
142
  };
142
143
  }
143
144
  });
145
+ const camelize = (name) => name.substring(1).replace(/^\S/, (s) => s.toLocaleLowerCase());
146
+ function get(object4, path) {
147
+ const keys = path.split(".");
148
+ let result = object4;
149
+ keys.forEach((key) => {
150
+ var _a;
151
+ result = (_a = result[key]) != null ? _a : "";
152
+ });
153
+ return result;
154
+ }
155
+ function createI18nTranslate(name, app, newPrefix) {
156
+ const prefix = newPrefix || camelize(name) + ".";
157
+ return (path) => {
158
+ const messages2 = app == null ? void 0 : app.appContext.config.globalProperties.langMessages.value;
159
+ const message = get(messages2, prefix + path) || get(messages2, path);
160
+ return message;
161
+ };
162
+ }
163
+ var DTreeNodeLoading = defineComponent({
164
+ name: "DTreeNodeLoading",
165
+ setup() {
166
+ const app = getCurrentInstance();
167
+ const t = createI18nTranslate("DTree", app);
168
+ const ns2 = useNamespace("loading-children ");
169
+ return () => {
170
+ return createVNode("span", {
171
+ "class": ns2.b()
172
+ }, [`${t("loading") || "Loading"}...`]);
173
+ };
174
+ }
175
+ });
144
176
  const commonProps = {
145
177
  name: {
146
178
  type: String,
@@ -1384,7 +1416,7 @@ var lodash = { exports: {} };
1384
1416
  function baseAt(object4, paths) {
1385
1417
  var index2 = -1, length = paths.length, result2 = Array2(length), skip = object4 == null;
1386
1418
  while (++index2 < length) {
1387
- result2[index2] = skip ? undefined$1 : get(object4, paths[index2]);
1419
+ result2[index2] = skip ? undefined$1 : get2(object4, paths[index2]);
1388
1420
  }
1389
1421
  return result2;
1390
1422
  }
@@ -1483,7 +1515,7 @@ var lodash = { exports: {} };
1483
1515
  if (typeof func != "function") {
1484
1516
  throw new TypeError2(FUNC_ERROR_TEXT);
1485
1517
  }
1486
- return setTimeout(function() {
1518
+ return setTimeout2(function() {
1487
1519
  func.apply(undefined$1, args);
1488
1520
  }, wait);
1489
1521
  }
@@ -1829,7 +1861,7 @@ var lodash = { exports: {} };
1829
1861
  return matchesStrictComparable(toKey(path), srcValue);
1830
1862
  }
1831
1863
  return function(object4) {
1832
- var objValue = get(object4, path);
1864
+ var objValue = get2(object4, path);
1833
1865
  return objValue === undefined$1 && objValue === srcValue ? hasIn(object4, path) : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
1834
1866
  };
1835
1867
  }
@@ -2263,7 +2295,7 @@ var lodash = { exports: {} };
2263
2295
  end = end === undefined$1 ? length : end;
2264
2296
  return !start && end >= length ? array4 : baseSlice(array4, start, end);
2265
2297
  }
2266
- var clearTimeout = ctxClearTimeout || function(id) {
2298
+ var clearTimeout2 = ctxClearTimeout || function(id) {
2267
2299
  return root.clearTimeout(id);
2268
2300
  };
2269
2301
  function cloneBuffer(buffer, isDeep) {
@@ -3292,7 +3324,7 @@ var lodash = { exports: {} };
3292
3324
  return object4[key];
3293
3325
  }
3294
3326
  var setData = shortOut(baseSetData);
3295
- var setTimeout = ctxSetTimeout || function(func, wait) {
3327
+ var setTimeout2 = ctxSetTimeout || function(func, wait) {
3296
3328
  return root.setTimeout(func, wait);
3297
3329
  };
3298
3330
  var setToString = shortOut(baseSetToString);
@@ -4084,7 +4116,7 @@ var lodash = { exports: {} };
4084
4116
  }
4085
4117
  function leadingEdge(time) {
4086
4118
  lastInvokeTime = time;
4087
- timerId = setTimeout(timerExpired, wait);
4119
+ timerId = setTimeout2(timerExpired, wait);
4088
4120
  return leading ? invokeFunc(time) : result2;
4089
4121
  }
4090
4122
  function remainingWait(time) {
@@ -4100,7 +4132,7 @@ var lodash = { exports: {} };
4100
4132
  if (shouldInvoke(time)) {
4101
4133
  return trailingEdge(time);
4102
4134
  }
4103
- timerId = setTimeout(timerExpired, remainingWait(time));
4135
+ timerId = setTimeout2(timerExpired, remainingWait(time));
4104
4136
  }
4105
4137
  function trailingEdge(time) {
4106
4138
  timerId = undefined$1;
@@ -4112,7 +4144,7 @@ var lodash = { exports: {} };
4112
4144
  }
4113
4145
  function cancel() {
4114
4146
  if (timerId !== undefined$1) {
4115
- clearTimeout(timerId);
4147
+ clearTimeout2(timerId);
4116
4148
  }
4117
4149
  lastInvokeTime = 0;
4118
4150
  lastArgs = lastCallTime = lastThis = timerId = undefined$1;
@@ -4130,13 +4162,13 @@ var lodash = { exports: {} };
4130
4162
  return leadingEdge(lastCallTime);
4131
4163
  }
4132
4164
  if (maxing) {
4133
- clearTimeout(timerId);
4134
- timerId = setTimeout(timerExpired, wait);
4165
+ clearTimeout2(timerId);
4166
+ timerId = setTimeout2(timerExpired, wait);
4135
4167
  return invokeFunc(lastCallTime);
4136
4168
  }
4137
4169
  }
4138
4170
  if (timerId === undefined$1) {
4139
- timerId = setTimeout(timerExpired, wait);
4171
+ timerId = setTimeout2(timerExpired, wait);
4140
4172
  }
4141
4173
  return result2;
4142
4174
  }
@@ -4562,7 +4594,7 @@ var lodash = { exports: {} };
4562
4594
  function functionsIn(object4) {
4563
4595
  return object4 == null ? [] : baseFunctions(object4, keysIn(object4));
4564
4596
  }
4565
- function get(object4, path, defaultValue) {
4597
+ function get2(object4, path, defaultValue) {
4566
4598
  var result2 = object4 == null ? undefined$1 : baseGet(object4, path);
4567
4599
  return result2 === undefined$1 ? defaultValue : result2;
4568
4600
  }
@@ -5417,7 +5449,7 @@ var lodash = { exports: {} };
5417
5449
  lodash2.forInRight = forInRight;
5418
5450
  lodash2.forOwn = forOwn;
5419
5451
  lodash2.forOwnRight = forOwnRight;
5420
- lodash2.get = get;
5452
+ lodash2.get = get2;
5421
5453
  lodash2.gt = gt;
5422
5454
  lodash2.gte = gte;
5423
5455
  lodash2.has = has;
@@ -7676,6 +7708,16 @@ Schema.register = function register(type4, validator) {
7676
7708
  Schema.warning = warning;
7677
7709
  Schema.messages = messages;
7678
7710
  Schema.validators = validators;
7711
+ function getFieldValue(obj, path) {
7712
+ return {
7713
+ get value() {
7714
+ return lodash.exports.get(obj, path);
7715
+ },
7716
+ set value(val) {
7717
+ lodash.exports.set(obj, path, val);
7718
+ }
7719
+ };
7720
+ }
7679
7721
  function useFormItem(messageType, _rules, validateState) {
7680
7722
  const formContext = inject(FORM_TOKEN);
7681
7723
  const ns2 = useNamespace("form");
@@ -7714,17 +7756,12 @@ function useFormItemValidate(props, _rules) {
7714
7756
  const computedField = computed(() => {
7715
7757
  return typeof props.field === "string" ? props.field : "";
7716
7758
  });
7717
- const fieldValue = computed({
7718
- get: () => {
7719
- const formData = formContext.data;
7720
- if (!formData || !props.field) {
7721
- return;
7722
- }
7723
- return formData[props.field];
7724
- },
7725
- set: (val) => {
7726
- formContext.data[props.field] = val;
7759
+ const fieldValue = computed(() => {
7760
+ const formData = formContext.data;
7761
+ if (!formData || !props.field) {
7762
+ return;
7727
7763
  }
7764
+ return getFieldValue(formData, props.field).value;
7728
7765
  });
7729
7766
  const getRuleByTrigger = (triggerVal) => {
7730
7767
  return _rules.value.filter((rule) => {
@@ -7737,7 +7774,7 @@ function useFormItemValidate(props, _rules) {
7737
7774
  return rule.trigger === triggerVal;
7738
7775
  }
7739
7776
  }).map((_a) => {
7740
- var _b = _a, { trigger } = _b, rule = __objRest(_b, ["trigger"]);
7777
+ var rule = __objRest(_a, []);
7741
7778
  return rule;
7742
7779
  });
7743
7780
  };
@@ -7793,13 +7830,16 @@ function useFormItemValidate(props, _rules) {
7793
7830
  if (!formContext.data || !props.field) {
7794
7831
  return;
7795
7832
  }
7796
- isResetting = true;
7797
- fieldValue.value = initFieldValue;
7833
+ const currentValue = getFieldValue(formContext.data, props.field);
7834
+ if (!lodash.exports.isEqual(currentValue.value, initFieldValue)) {
7835
+ isResetting = true;
7836
+ }
7837
+ currentValue.value = initFieldValue;
7798
7838
  await nextTick();
7799
7839
  clearValidate();
7800
7840
  };
7801
7841
  onMounted(() => {
7802
- initFieldValue = lodash.exports.cloneDeep(formContext.data[props.field]);
7842
+ initFieldValue = lodash.exports.clone(fieldValue.value);
7803
7843
  });
7804
7844
  return { validateState, validateMessage, validate, resetField, clearValidate };
7805
7845
  }
@@ -8258,7 +8298,6 @@ defineComponent({
8258
8298
  });
8259
8299
  const ns = useNamespace("tree");
8260
8300
  function useTreeNode(data) {
8261
- const { getChildren } = inject(USE_TREE_TOKEN);
8262
8301
  const nodeClass = computed(() => {
8263
8302
  var _a;
8264
8303
  return [ns.e("node"), ((_a = data.value) == null ? void 0 : _a.expanded) && ns.em("node", "open")];
@@ -8268,16 +8307,19 @@ function useTreeNode(data) {
8268
8307
  return { paddingLeft: `${NODE_INDENT * (((_a = data.value) == null ? void 0 : _a.level) - 1)}px` };
8269
8308
  });
8270
8309
  const nodeVLineClass = computed(() => {
8271
- var _a, _b;
8272
- return [!((_a = data.value) == null ? void 0 : _a.isLeaf) && ((_b = data.value) == null ? void 0 : _b.expanded) && ns.e("node-vline")];
8273
- });
8274
- const nodeVLineStyle = computed(() => {
8275
8310
  var _a;
8276
- return {
8277
- height: `${NODE_HEIGHT * (getChildren(data.value, { expanded: true }).length - 1) + NODE_HEIGHT / 2 + 1}px`,
8278
- left: `${NODE_INDENT * (((_a = data.value) == null ? void 0 : _a.level) - 1) + 9}px`,
8279
- top: `${NODE_HEIGHT}px`
8280
- };
8311
+ return [((_a = data.value) == null ? void 0 : _a.level) !== 1 && ns.e("node-vline")];
8312
+ });
8313
+ const nodeVLineStyles = computed(() => {
8314
+ if (!data.value || data.value.level === 1) {
8315
+ return [];
8316
+ }
8317
+ const { currentIndex = 0, parentChildNodeCount = 0, level, expanded, isLeaf } = data.value;
8318
+ return Array.from({ length: data.value.level - 1 }).map((_, index2) => ({
8319
+ height: `${currentIndex + 1 === parentChildNodeCount && index2 === 0 ? isLeaf || !expanded ? NODE_HEIGHT / 2 : NODE_HEIGHT : NODE_HEIGHT}px`,
8320
+ left: `${NODE_INDENT * (level - index2 - 2) + 9}px`,
8321
+ top: `0px`
8322
+ }));
8281
8323
  });
8282
8324
  const nodeHLineClass = computed(() => {
8283
8325
  var _a;
@@ -8291,14 +8333,16 @@ function useTreeNode(data) {
8291
8333
  var _a;
8292
8334
  return [ns.e("node-title"), ((_a = data.value) == null ? void 0 : _a.disableSelect) && "select-disabled"];
8293
8335
  });
8336
+ const nodeOperationAreaClass = computed(() => ns.e("node-operation-area"));
8294
8337
  return {
8295
8338
  nodeClass,
8296
8339
  nodeStyle,
8297
8340
  nodeContentClass,
8298
8341
  nodeTitleClass,
8299
8342
  nodeVLineClass,
8300
- nodeVLineStyle,
8301
- nodeHLineClass
8343
+ nodeVLineStyles,
8344
+ nodeHLineClass,
8345
+ nodeOperationAreaClass
8302
8346
  };
8303
8347
  }
8304
8348
  var DTreeNodeContent = defineComponent({
@@ -8324,6 +8368,9 @@ var DTreeNodeContent = defineComponent({
8324
8368
  };
8325
8369
  }
8326
8370
  });
8371
+ const formatCheckStatus = (check) => {
8372
+ return typeof check === "boolean" ? check ? "both" : "none" : check;
8373
+ };
8327
8374
  var DTreeNode = defineComponent({
8328
8375
  name: "DTreeNode",
8329
8376
  props: {
@@ -8332,65 +8379,95 @@ var DTreeNode = defineComponent({
8332
8379
  default: () => ({})
8333
8380
  },
8334
8381
  check: {
8335
- type: Boolean,
8382
+ type: [Boolean, String],
8383
+ default: false
8384
+ },
8385
+ operate: {
8386
+ type: [Boolean, String, Array],
8336
8387
  default: false
8337
8388
  }
8338
8389
  },
8339
8390
  setup(props, {
8340
8391
  slots
8341
8392
  }) {
8393
+ const app = getCurrentInstance();
8394
+ const t = createI18nTranslate("DTree", app);
8342
8395
  const {
8343
8396
  data,
8344
- check
8397
+ check,
8398
+ operate
8345
8399
  } = toRefs(props);
8346
8400
  const {
8347
8401
  toggleSelectNode,
8348
8402
  toggleCheckNode,
8349
8403
  toggleNode,
8350
- getChildren
8404
+ getChildren,
8405
+ insertBefore,
8406
+ removeNode,
8407
+ getNode
8351
8408
  } = inject(USE_TREE_TOKEN);
8409
+ const treeInstance = inject(TREE_INSTANCE);
8352
8410
  const ns2 = useNamespace("tree");
8353
8411
  const {
8354
8412
  nodeClass,
8355
8413
  nodeStyle,
8356
8414
  nodeContentClass,
8357
8415
  nodeVLineClass,
8358
- nodeVLineStyle,
8359
- nodeHLineClass
8416
+ nodeVLineStyles,
8417
+ nodeHLineClass,
8418
+ nodeOperationAreaClass
8360
8419
  } = useTreeNode(data);
8361
8420
  const halfChecked = computed(() => {
8362
- const children = getChildren == null ? void 0 : getChildren(data.value);
8363
- const checkedChildren = children == null ? void 0 : children.filter((item) => item.checked);
8364
- if (["upward", "both"].includes(check.value)) {
8421
+ var _a;
8422
+ if (!((_a = data.value) == null ? void 0 : _a.checked)) {
8423
+ return false;
8424
+ }
8425
+ const checkFormat = formatCheckStatus(check.value);
8426
+ if (["upward", "both"].includes(checkFormat)) {
8427
+ const children = (getChildren == null ? void 0 : getChildren(data.value)) || [];
8428
+ const checkedChildren = children == null ? void 0 : children.filter((item) => item.checked);
8365
8429
  return checkedChildren.length > 0 && checkedChildren.length < children.length;
8366
8430
  } else {
8367
8431
  return false;
8368
8432
  }
8369
8433
  });
8370
- return () => {
8434
+ const checkboxProps2 = computed(() => {
8371
8435
  var _a, _b, _c;
8372
- const checkboxProps2 = {
8436
+ return {
8373
8437
  key: (_a = data.value) == null ? void 0 : _a.id,
8374
8438
  disabled: (_b = data.value) == null ? void 0 : _b.disableCheck,
8375
- halfchecked: halfChecked.value,
8439
+ halfChecked: halfChecked.value,
8376
8440
  modelValue: (_c = data.value) == null ? void 0 : _c.checked,
8377
8441
  "onUpdate:modelValue": () => {
8378
- toggleCheckNode(data.value);
8442
+ toggleCheckNode == null ? void 0 : toggleCheckNode(data.value);
8379
8443
  },
8380
8444
  onClick: (event) => {
8381
8445
  event.stopPropagation();
8382
8446
  }
8383
8447
  };
8448
+ });
8449
+ const isShowOperationArea = ref(false);
8450
+ const showOperationArea = () => {
8451
+ isShowOperationArea.value = true;
8452
+ };
8453
+ const hideOperationArea = () => {
8454
+ isShowOperationArea.value = false;
8455
+ };
8456
+ return () => {
8457
+ var _a;
8384
8458
  return createVNode("div", {
8385
8459
  "class": nodeClass.value,
8386
- "style": nodeStyle.value
8387
- }, [createVNode("span", {
8460
+ "style": nodeStyle.value,
8461
+ "onMouseenter": showOperationArea,
8462
+ "onMouseleave": hideOperationArea
8463
+ }, [nodeVLineStyles.value.map((item) => createVNode("span", {
8388
8464
  "class": nodeVLineClass.value,
8389
- "style": nodeVLineStyle.value
8390
- }, null), createVNode("div", {
8465
+ "style": item
8466
+ }, null)), createVNode("div", {
8391
8467
  "class": nodeContentClass.value,
8392
8468
  "onClick": () => {
8393
- toggleSelectNode(data.value);
8469
+ toggleSelectNode == null ? void 0 : toggleSelectNode(data.value);
8470
+ treeInstance.emit("node-click", data.value);
8394
8471
  }
8395
8472
  }, [createVNode("span", {
8396
8473
  "class": nodeHLineClass.value
@@ -8404,38 +8481,1026 @@ var DTreeNode = defineComponent({
8404
8481
  "style": {
8405
8482
  height: `${NODE_HEIGHT}px`
8406
8483
  }
8407
- }, [check.value && createVNode(Checkbox, checkboxProps2, null), slots.default ? renderSlot(useSlots(), "default", {
8484
+ }, [check.value && createVNode(Checkbox, checkboxProps2.value, null), slots.default ? renderSlot(useSlots(), "default", {
8408
8485
  nodeData: data
8409
8486
  }) : createVNode(DTreeNodeContent, {
8410
- "data": data
8487
+ "data": data.value
8488
+ }, null), ((_a = getNode == null ? void 0 : getNode(data.value)) == null ? void 0 : _a.loading) ? slots.loading ? renderSlot(useSlots(), "loading") : createVNode(DTreeNodeLoading, null, null) : ""]), operate.value && isShowOperationArea.value && createVNode("div", {
8489
+ "class": nodeOperationAreaClass.value
8490
+ }, [createVNode(resolveComponent("d-icon"), {
8491
+ "name": "add",
8492
+ "onClick": () => {
8493
+ insertBefore(data.value, {
8494
+ label: t("newNode") || "New node"
8495
+ });
8496
+ }
8497
+ }, null), createVNode(resolveComponent("d-icon"), {
8498
+ "name": "delete",
8499
+ "onClick": () => {
8500
+ removeNode(data.value);
8501
+ }
8411
8502
  }, null)])])]);
8412
8503
  };
8413
8504
  }
8414
8505
  });
8506
+ const virtualListProps = {
8507
+ data: {
8508
+ type: Array,
8509
+ default: () => []
8510
+ },
8511
+ component: {
8512
+ type: String,
8513
+ default: "div"
8514
+ },
8515
+ height: {
8516
+ type: Number,
8517
+ default: 100
8518
+ },
8519
+ itemHeight: {
8520
+ type: Number,
8521
+ default: 0
8522
+ },
8523
+ virtual: {
8524
+ type: Boolean,
8525
+ default: true
8526
+ },
8527
+ fullHeight: {
8528
+ type: Boolean
8529
+ },
8530
+ itemKey: {
8531
+ type: [String, Number, Function]
8532
+ }
8533
+ };
8534
+ const resizeObserverContainerProps = {
8535
+ height: {
8536
+ type: Number
8537
+ },
8538
+ offset: {
8539
+ type: Number || void 0
8540
+ },
8541
+ disabled: {
8542
+ type: Function
8543
+ },
8544
+ onInnerResize: {
8545
+ type: Function
8546
+ }
8547
+ };
8548
+ const scrollBarProps = {
8549
+ scrollTop: {
8550
+ type: Number
8551
+ },
8552
+ scrollHeight: {
8553
+ type: Number
8554
+ },
8555
+ height: {
8556
+ type: Number
8557
+ },
8558
+ count: {
8559
+ type: Number
8560
+ },
8561
+ onScroll: {
8562
+ type: Function
8563
+ },
8564
+ onStartMove: {
8565
+ type: Function
8566
+ },
8567
+ onStopMove: {
8568
+ type: Function
8569
+ }
8570
+ };
8571
+ const resizeObserverProps = {
8572
+ disabled: {
8573
+ type: Boolean
8574
+ },
8575
+ onResize: {
8576
+ type: Function
8577
+ }
8578
+ };
8579
+ function useVirtual(props) {
8580
+ const isVirtual = computed(() => {
8581
+ const {
8582
+ height,
8583
+ virtual
8584
+ } = props;
8585
+ return !!(virtual !== false && height);
8586
+ });
8587
+ const inVirtual = computed(() => {
8588
+ const {
8589
+ height,
8590
+ data
8591
+ } = props;
8592
+ return isVirtual.value && data && 20 * data.length > height;
8593
+ });
8594
+ return {
8595
+ isVirtual,
8596
+ inVirtual
8597
+ };
8598
+ }
8599
+ function useHeights(mergedData, getKey) {
8600
+ const instance = /* @__PURE__ */ new Map();
8601
+ let heights = /* @__PURE__ */ new Map();
8602
+ const updatedMark = ref(Symbol("update"));
8603
+ watch(mergedData, () => {
8604
+ heights = /* @__PURE__ */ new Map();
8605
+ updatedMark.value = Symbol("update");
8606
+ });
8607
+ let heightUpdateId = 0;
8608
+ function collectHeight() {
8609
+ heightUpdateId += 1;
8610
+ const currentId = heightUpdateId;
8611
+ Promise.resolve().then(() => {
8612
+ if (currentId !== heightUpdateId) {
8613
+ return;
8614
+ }
8615
+ instance.forEach((element, key) => {
8616
+ if (element && element.offsetParent) {
8617
+ const {
8618
+ offsetHeight
8619
+ } = element;
8620
+ if (heights.get(key) !== offsetHeight) {
8621
+ updatedMark.value = Symbol("update");
8622
+ heights.set(key, element.offsetHeight);
8623
+ }
8624
+ }
8625
+ });
8626
+ });
8627
+ }
8628
+ function setInstance(item, ins) {
8629
+ const key = getKey(item);
8630
+ if (ins) {
8631
+ instance.set(key, ins.$el || ins);
8632
+ collectHeight();
8633
+ } else {
8634
+ instance.delete(key);
8635
+ }
8636
+ }
8637
+ return [setInstance, collectHeight, heights, updatedMark];
8638
+ }
8639
+ var useOriginScroll = (isScrollAtTop, isScrollAtBottom) => {
8640
+ let lock = false;
8641
+ let lockTimeout = null;
8642
+ function lockScroll2() {
8643
+ if (lockTimeout) {
8644
+ clearTimeout(lockTimeout);
8645
+ }
8646
+ lock = true;
8647
+ lockTimeout = setTimeout(() => {
8648
+ lock = false;
8649
+ }, 50);
8650
+ }
8651
+ return (deltaY, smoothOffset = false) => {
8652
+ const originScroll = deltaY < 0 && isScrollAtTop.value || deltaY > 0 && isScrollAtBottom.value;
8653
+ if (smoothOffset && originScroll) {
8654
+ if (lockTimeout) {
8655
+ clearTimeout(lockTimeout);
8656
+ }
8657
+ lock = false;
8658
+ } else if (!originScroll || lock) {
8659
+ lockScroll2();
8660
+ }
8661
+ return !lock && originScroll;
8662
+ };
8663
+ };
8664
+ const isValid = (value) => {
8665
+ return value !== void 0 && value !== null && value !== "";
8666
+ };
8667
+ const isEmptyElement = (c) => {
8668
+ var _a, _b;
8669
+ return !!c && (c.type === Comment || c.type === Fragment && ((_a = c == null ? void 0 : c.children) == null ? void 0 : _a.length) === 0 || c.type === Text && ((_b = c == null ? void 0 : c.children) == null ? void 0 : _b.trim()) === "");
8670
+ };
8671
+ const flattenChildren = (children, filterEmpty = true) => {
8672
+ const temp = Array.isArray(children) ? children : [children];
8673
+ const res = [];
8674
+ temp.forEach((child) => {
8675
+ if (Array.isArray(child)) {
8676
+ res.push(...flattenChildren(child, filterEmpty));
8677
+ } else if (child && child.type === Fragment) {
8678
+ res.push(...flattenChildren(child.children, filterEmpty));
8679
+ } else if (child && isVNode(child)) {
8680
+ if (filterEmpty && !isEmptyElement(child)) {
8681
+ res.push(child);
8682
+ } else if (!filterEmpty) {
8683
+ res.push(child);
8684
+ }
8685
+ } else if (isValid(child)) {
8686
+ res.push(child);
8687
+ }
8688
+ });
8689
+ return res;
8690
+ };
8691
+ const findDOMNode = (instance) => {
8692
+ var _a;
8693
+ let node = ((_a = instance == null ? void 0 : instance.vnode) == null ? void 0 : _a.el) || instance && ((instance == null ? void 0 : instance.$el) || instance);
8694
+ while (node && !node.tagName) {
8695
+ node = node.nextSibling;
8696
+ }
8697
+ return node;
8698
+ };
8699
+ const isFF = typeof navigator === "object" && /Firefox/i.test(navigator.userAgent);
8700
+ function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, onWheelDelta) {
8701
+ let offsetRef = 0;
8702
+ let nextFrame = null;
8703
+ let wheelValue = null;
8704
+ let isMouseScroll = false;
8705
+ const originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom);
8706
+ const onRawWheel = (event) => {
8707
+ var _a;
8708
+ if (!inVirtual.value) {
8709
+ return;
8710
+ }
8711
+ if (nextFrame) {
8712
+ window.cancelAnimationFrame(nextFrame);
8713
+ }
8714
+ const {
8715
+ deltaY
8716
+ } = event;
8717
+ offsetRef += deltaY;
8718
+ wheelValue = deltaY;
8719
+ if (originScroll(deltaY, false)) {
8720
+ return;
8721
+ }
8722
+ if (!isFF) {
8723
+ (_a = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a.call(event);
8724
+ }
8725
+ nextFrame = window.requestAnimationFrame(() => {
8726
+ const patchMultiple = isMouseScroll ? 10 : 1;
8727
+ onWheelDelta(offsetRef * patchMultiple);
8728
+ offsetRef = 0;
8729
+ });
8730
+ };
8731
+ const onFireFoxScroll = (event) => {
8732
+ if (!inVirtual.value) {
8733
+ return;
8734
+ }
8735
+ isMouseScroll = event.detail === wheelValue;
8736
+ };
8737
+ return [onRawWheel, onFireFoxScroll];
8738
+ }
8739
+ const SMOOTH_PTG = 14 / 15;
8740
+ function useMobileTouchMove(inVirtual, listRef, callback) {
8741
+ let touched = false;
8742
+ let touchY = 0;
8743
+ let element = null;
8744
+ let interval = null;
8745
+ const onTouchMove = (e) => {
8746
+ if (touched) {
8747
+ const currentY = Math.ceil(e.touches[0].pageY);
8748
+ let offsetY = touchY - currentY;
8749
+ touchY = currentY;
8750
+ if (callback(offsetY)) {
8751
+ e.preventDefault();
8752
+ }
8753
+ if (interval) {
8754
+ clearInterval(interval);
8755
+ }
8756
+ interval = setInterval(() => {
8757
+ offsetY *= SMOOTH_PTG;
8758
+ if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) {
8759
+ if (interval) {
8760
+ clearInterval(interval);
8761
+ }
8762
+ }
8763
+ }, 16);
8764
+ }
8765
+ };
8766
+ const cleanUpEvents = () => {
8767
+ if (element) {
8768
+ element.removeEventListener("touchmove", onTouchMove);
8769
+ element.removeEventListener("touchend", () => {
8770
+ touched = false;
8771
+ cleanUpEvents();
8772
+ });
8773
+ }
8774
+ };
8775
+ const onTouchEnd = () => {
8776
+ touched = false;
8777
+ cleanUpEvents();
8778
+ };
8779
+ const onTouchStart = (e) => {
8780
+ cleanUpEvents();
8781
+ if (e.touches.length === 1 && !touched) {
8782
+ touched = true;
8783
+ touchY = Math.ceil(e.touches[0].pageY);
8784
+ element = e.target;
8785
+ element.addEventListener("touchmove", onTouchMove, {
8786
+ passive: false
8787
+ });
8788
+ element.addEventListener("touchend", onTouchEnd);
8789
+ }
8790
+ };
8791
+ onMounted(() => {
8792
+ watch(inVirtual, (val) => {
8793
+ var _a, _b;
8794
+ (_a = listRef.value) == null ? void 0 : _a.removeEventListener("touchstart", onTouchStart);
8795
+ cleanUpEvents();
8796
+ if (interval) {
8797
+ clearInterval(interval);
8798
+ }
8799
+ if (val) {
8800
+ (_b = listRef.value) == null ? void 0 : _b.addEventListener("touchstart", onTouchStart, {
8801
+ passive: false
8802
+ });
8803
+ }
8804
+ }, {
8805
+ immediate: true
8806
+ });
8807
+ });
8808
+ }
8809
+ var ResizeObserver$1 = defineComponent({
8810
+ name: "ResizeObserver",
8811
+ props: resizeObserverProps,
8812
+ emits: ["resize"],
8813
+ setup(props, {
8814
+ slots
8815
+ }) {
8816
+ const state = reactive({
8817
+ width: 0,
8818
+ height: 0,
8819
+ offsetHeight: 0,
8820
+ offsetWidth: 0
8821
+ });
8822
+ const currentElement = ref(null);
8823
+ const resizeObserver = ref(null);
8824
+ const destroyObserver = () => {
8825
+ if (resizeObserver.value) {
8826
+ resizeObserver.value.disconnect();
8827
+ resizeObserver.value = null;
8828
+ }
8829
+ };
8830
+ const onTriggerResize = (entries) => {
8831
+ const {
8832
+ onResize
8833
+ } = props;
8834
+ const target = entries[0].target;
8835
+ const {
8836
+ width,
8837
+ height
8838
+ } = target.getBoundingClientRect();
8839
+ const {
8840
+ offsetWidth,
8841
+ offsetHeight
8842
+ } = target;
8843
+ const fixedWidth = Math.floor(width);
8844
+ const fixedHeight = Math.floor(height);
8845
+ if (state.width !== fixedWidth || state.height !== fixedHeight || state.offsetWidth !== offsetWidth || state.offsetHeight !== offsetHeight) {
8846
+ const size = {
8847
+ width: fixedWidth,
8848
+ height: fixedHeight,
8849
+ offsetWidth,
8850
+ offsetHeight
8851
+ };
8852
+ Object.assign(state, size);
8853
+ if (onResize) {
8854
+ Promise.resolve().then(() => {
8855
+ onResize(__spreadProps(__spreadValues({}, size), {
8856
+ offsetWidth,
8857
+ offsetHeight
8858
+ }), target);
8859
+ });
8860
+ }
8861
+ }
8862
+ };
8863
+ const instance = getCurrentInstance();
8864
+ const registerObserver = () => {
8865
+ const {
8866
+ disabled
8867
+ } = props;
8868
+ if (disabled) {
8869
+ destroyObserver();
8870
+ return;
8871
+ }
8872
+ if (instance) {
8873
+ const element = findDOMNode(instance);
8874
+ const elementChanged = element !== currentElement.value;
8875
+ if (elementChanged) {
8876
+ destroyObserver();
8877
+ currentElement.value = element;
8878
+ }
8879
+ if (!resizeObserver.value && element) {
8880
+ resizeObserver.value = new ResizeObserver(onTriggerResize);
8881
+ resizeObserver.value.observe(element);
8882
+ }
8883
+ }
8884
+ };
8885
+ onMounted(() => {
8886
+ registerObserver();
8887
+ });
8888
+ onUpdated(() => {
8889
+ registerObserver();
8890
+ });
8891
+ onUnmounted(() => {
8892
+ destroyObserver();
8893
+ });
8894
+ return () => {
8895
+ var _a;
8896
+ return (_a = slots.default) == null ? void 0 : _a.call(slots)[0];
8897
+ };
8898
+ }
8899
+ });
8900
+ const INIT_INNER_STYLE = {
8901
+ display: "flex",
8902
+ flexDirection: "column"
8903
+ };
8904
+ var ResizeObserverContainer = defineComponent({
8905
+ name: "ResizeObserverContainer",
8906
+ props: resizeObserverContainerProps,
8907
+ setup(props, ctx) {
8908
+ const {
8909
+ height,
8910
+ offset: offset2
8911
+ } = toRefs(props);
8912
+ const outerStyle = ref({});
8913
+ const innerStyle = ref(INIT_INNER_STYLE);
8914
+ watch([() => height.value, () => offset2.value], () => {
8915
+ if (props.offset !== void 0) {
8916
+ outerStyle.value = {
8917
+ height: `${height.value}px`,
8918
+ position: "relative",
8919
+ overflow: "hidden"
8920
+ };
8921
+ innerStyle.value = __spreadProps(__spreadValues({}, innerStyle.value), {
8922
+ transform: `translateY(${offset2.value}px)`,
8923
+ position: "absolute",
8924
+ left: 0,
8925
+ right: 0,
8926
+ top: 0
8927
+ });
8928
+ }
8929
+ }, {
8930
+ immediate: true
8931
+ });
8932
+ return () => createVNode("div", {
8933
+ "style": outerStyle.value
8934
+ }, [createVNode(ResizeObserver$1, {
8935
+ "onResize": ({
8936
+ offsetHeight
8937
+ }) => {
8938
+ if (offsetHeight && props.onInnerResize) {
8939
+ props.onInnerResize();
8940
+ }
8941
+ }
8942
+ }, {
8943
+ default: () => {
8944
+ var _a, _b;
8945
+ return [createVNode("div", {
8946
+ "style": innerStyle.value
8947
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)])];
8948
+ }
8949
+ })]);
8950
+ }
8951
+ });
8952
+ function getPageY(e) {
8953
+ return "touches" in e ? e.touches[0].pageY : e.pageY;
8954
+ }
8955
+ var ScrollBar = defineComponent({
8956
+ name: "ScrollBar",
8957
+ props: scrollBarProps,
8958
+ setup(props, ctx) {
8959
+ const scrollbarRef = ref(null);
8960
+ const thumbRef = ref(null);
8961
+ const moveRaf = ref(0);
8962
+ const state = reactive({
8963
+ dragging: false,
8964
+ pageY: null,
8965
+ startTop: null,
8966
+ visible: false
8967
+ });
8968
+ const visibleTimeout = ref(null);
8969
+ const canScroll = computed(() => {
8970
+ return (props.scrollHeight || 0) > (props.height || 0);
8971
+ });
8972
+ const getSpinHeight = () => {
8973
+ const {
8974
+ height = 0,
8975
+ count = 0
8976
+ } = props;
8977
+ let baseHeight = height / count * 10;
8978
+ baseHeight = Math.max(baseHeight, 20);
8979
+ baseHeight = Math.min(baseHeight, height / 2);
8980
+ return Math.floor(baseHeight);
8981
+ };
8982
+ const getEnableScrollRange = () => {
8983
+ const {
8984
+ scrollHeight = 0,
8985
+ height = 0
8986
+ } = props;
8987
+ return scrollHeight - height || 0;
8988
+ };
8989
+ const getEnableHeightRange = () => {
8990
+ const {
8991
+ height = 0
8992
+ } = props;
8993
+ const spinHeight = getSpinHeight();
8994
+ return height - spinHeight || 0;
8995
+ };
8996
+ const getTop = () => {
8997
+ const {
8998
+ scrollTop = 0
8999
+ } = props;
9000
+ const enableScrollRange = getEnableScrollRange();
9001
+ const enableHeightRange = getEnableHeightRange();
9002
+ if (scrollTop === 0 || enableScrollRange === 0) {
9003
+ return 0;
9004
+ }
9005
+ const ptg = scrollTop / enableScrollRange;
9006
+ return ptg * enableHeightRange;
9007
+ };
9008
+ const onMouseMove = (e) => {
9009
+ const {
9010
+ dragging,
9011
+ pageY,
9012
+ startTop
9013
+ } = state;
9014
+ const {
9015
+ onScroll
9016
+ } = props;
9017
+ window.cancelAnimationFrame(moveRaf.value);
9018
+ if (dragging) {
9019
+ const offsetY = getPageY(e) - (pageY || 0);
9020
+ const newTop = (startTop || 0) + offsetY;
9021
+ const enableScrollRange = getEnableScrollRange();
9022
+ const enableHeightRange = getEnableHeightRange();
9023
+ const ptg = enableHeightRange ? newTop / enableHeightRange : 0;
9024
+ const newScrollTop = Math.ceil(ptg * enableScrollRange);
9025
+ moveRaf.value = window.requestAnimationFrame(() => {
9026
+ if (onScroll) {
9027
+ onScroll(newScrollTop);
9028
+ }
9029
+ });
9030
+ }
9031
+ };
9032
+ const onMouseUp = (callback) => {
9033
+ const {
9034
+ onStopMove
9035
+ } = props;
9036
+ state.dragging = false;
9037
+ if (onStopMove) {
9038
+ onStopMove();
9039
+ }
9040
+ if (callback) {
9041
+ callback();
9042
+ }
9043
+ };
9044
+ const onMouseDown = (e, callback) => {
9045
+ var _a, _b;
9046
+ const {
9047
+ onStartMove
9048
+ } = props;
9049
+ Object.assign(state, {
9050
+ dragging: true,
9051
+ pageY: getPageY(e),
9052
+ startTop: getTop()
9053
+ });
9054
+ if (onStartMove) {
9055
+ onStartMove();
9056
+ }
9057
+ window.addEventListener("mousemove", onMouseMove);
9058
+ window.addEventListener("mouseup", () => onMouseUp(callback));
9059
+ (_a = thumbRef == null ? void 0 : thumbRef.value) == null ? void 0 : _a.addEventListener("touchmove", onMouseMove, {
9060
+ passive: false
9061
+ });
9062
+ (_b = thumbRef == null ? void 0 : thumbRef.value) == null ? void 0 : _b.addEventListener("touchend", () => onMouseUp(callback));
9063
+ e.stopPropagation();
9064
+ e.preventDefault();
9065
+ };
9066
+ const removeEvents = () => {
9067
+ var _a, _b, _c, _d;
9068
+ window.removeEventListener("mousemove", onMouseMove);
9069
+ window.removeEventListener("mouseup", () => onMouseUp(removeEvents));
9070
+ (_a = scrollbarRef == null ? void 0 : scrollbarRef.value) == null ? void 0 : _a.removeEventListener("touchstart", (e) => {
9071
+ e.preventDefault();
9072
+ }, {
9073
+ passive: false
9074
+ });
9075
+ (_b = thumbRef == null ? void 0 : thumbRef.value) == null ? void 0 : _b.removeEventListener("touchstart", (e) => onMouseDown(e, removeEvents), {
9076
+ passive: false
9077
+ });
9078
+ (_c = thumbRef == null ? void 0 : thumbRef.value) == null ? void 0 : _c.removeEventListener("touchmove", onMouseMove, {
9079
+ passive: false
9080
+ });
9081
+ (_d = thumbRef == null ? void 0 : thumbRef.value) == null ? void 0 : _d.removeEventListener("touchend", () => onMouseUp(removeEvents));
9082
+ window.cancelAnimationFrame(moveRaf.value);
9083
+ };
9084
+ const onContainerMouseDown = (e) => {
9085
+ e.stopPropagation();
9086
+ e.preventDefault();
9087
+ };
9088
+ onBeforeUnmount(() => {
9089
+ removeEvents();
9090
+ if (visibleTimeout.value) {
9091
+ clearTimeout(visibleTimeout.value);
9092
+ }
9093
+ });
9094
+ onMounted(() => {
9095
+ var _a, _b;
9096
+ (_a = scrollbarRef == null ? void 0 : scrollbarRef.value) == null ? void 0 : _a.addEventListener("touchstart", (e) => {
9097
+ e.preventDefault();
9098
+ }, {
9099
+ passive: false
9100
+ });
9101
+ (_b = thumbRef.value) == null ? void 0 : _b.addEventListener("touchstart", (e) => onMouseDown(e, removeEvents), {
9102
+ passive: false
9103
+ });
9104
+ });
9105
+ const onShowBar = () => {
9106
+ if (visibleTimeout.value) {
9107
+ clearTimeout(visibleTimeout.value);
9108
+ }
9109
+ state.visible = true;
9110
+ visibleTimeout.value = setTimeout(() => {
9111
+ state.visible = false;
9112
+ }, 1e3);
9113
+ };
9114
+ ctx.expose({
9115
+ onShowBar
9116
+ });
9117
+ return () => {
9118
+ const display = canScroll.value && state.visible ? void 0 : "none";
9119
+ return createVNode("div", {
9120
+ "ref": scrollbarRef,
9121
+ "style": {
9122
+ width: "8px",
9123
+ top: 0,
9124
+ bottom: 0,
9125
+ right: 0,
9126
+ position: "absolute",
9127
+ display
9128
+ },
9129
+ "onMousedown": onContainerMouseDown,
9130
+ "onMousemove": onShowBar
9131
+ }, [createVNode("div", {
9132
+ "ref": thumbRef,
9133
+ "style": {
9134
+ width: "100%",
9135
+ height: getSpinHeight() + "px",
9136
+ top: getTop() + "px",
9137
+ left: 0,
9138
+ position: "absolute",
9139
+ background: "rgba(0, 0, 0, 0.5)",
9140
+ borderRadius: "99px",
9141
+ cursor: "pointer",
9142
+ userSelect: "none"
9143
+ },
9144
+ "onMousedown": (e) => onMouseDown(e, removeEvents)
9145
+ }, null)]);
9146
+ };
9147
+ }
9148
+ });
9149
+ function _isSlot(s) {
9150
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
9151
+ }
9152
+ const Item = ({
9153
+ setRef
9154
+ }, {
9155
+ slots
9156
+ }) => {
9157
+ var _a;
9158
+ const children = flattenChildren((_a = slots.default) == null ? void 0 : _a.call(slots));
9159
+ return children && children.length ? cloneVNode(children[0], {
9160
+ ref: setRef
9161
+ }) : children;
9162
+ };
9163
+ Item.props = {
9164
+ setRef: {
9165
+ type: Function
9166
+ }
9167
+ };
9168
+ function renderChildren(list, startIndex, endIndex, setNodeRef, {
9169
+ getKey
9170
+ }, renderFunc) {
9171
+ if (renderFunc === void 0) {
9172
+ return "";
9173
+ }
9174
+ return list.slice(startIndex, endIndex + 1).map((item, index2) => {
9175
+ const eleIndex = startIndex + index2;
9176
+ const node = renderFunc(item, eleIndex, {});
9177
+ const key = getKey(item);
9178
+ return createVNode(Item, {
9179
+ "key": key,
9180
+ "setRef": (ele) => setNodeRef(item, ele)
9181
+ }, _isSlot(node) ? node : {
9182
+ default: () => [node]
9183
+ });
9184
+ });
9185
+ }
9186
+ const ScrollStyle = {
9187
+ overflowY: "auto",
9188
+ overflowAnchor: "none"
9189
+ };
9190
+ const DEFAULT_HEIGHT = 20;
9191
+ var VirtualList = defineComponent({
9192
+ name: "DVirtualList",
9193
+ props: virtualListProps,
9194
+ setup(props, ctx) {
9195
+ const {
9196
+ isVirtual,
9197
+ inVirtual
9198
+ } = useVirtual(props);
9199
+ const state = reactive({
9200
+ scrollTop: 0,
9201
+ scrollMoving: false
9202
+ });
9203
+ const data = computed(() => {
9204
+ return props.data || [];
9205
+ });
9206
+ const mergedData = shallowRef([]);
9207
+ watch(data, () => {
9208
+ mergedData.value = toRaw(data.value).slice();
9209
+ }, {
9210
+ immediate: true
9211
+ });
9212
+ const itemKey = shallowRef(null);
9213
+ watch(() => props.itemKey, (val) => {
9214
+ if (typeof val === "function") {
9215
+ itemKey.value = val;
9216
+ } else {
9217
+ if (val) {
9218
+ itemKey.value = (item) => item == null ? void 0 : item[val];
9219
+ }
9220
+ }
9221
+ }, {
9222
+ immediate: true
9223
+ });
9224
+ const componentRef = ref();
9225
+ const fillerInnerRef = ref();
9226
+ const barRef = ref();
9227
+ const getKey = (item) => {
9228
+ if (!itemKey.value || !props.itemKey) {
9229
+ return;
9230
+ }
9231
+ return itemKey.value(item);
9232
+ };
9233
+ const [setInstance, collectHeight, heights, updatedMark] = useHeights(mergedData, getKey);
9234
+ const calRes = reactive({
9235
+ scrollHeight: void 0,
9236
+ start: 0,
9237
+ end: 0,
9238
+ offset: void 0
9239
+ });
9240
+ const offsetHeight = ref(0);
9241
+ onMounted(() => {
9242
+ nextTick(() => {
9243
+ var _a;
9244
+ offsetHeight.value = ((_a = fillerInnerRef.value) == null ? void 0 : _a.offsetHeight) || 0;
9245
+ });
9246
+ });
9247
+ onUpdated(() => {
9248
+ nextTick(() => {
9249
+ var _a;
9250
+ offsetHeight.value = ((_a = fillerInnerRef.value) == null ? void 0 : _a.offsetHeight) || 0;
9251
+ });
9252
+ });
9253
+ watch([isVirtual, mergedData], () => {
9254
+ if (!isVirtual.value) {
9255
+ Object.assign(calRes, {
9256
+ scrollHeight: void 0,
9257
+ start: 0,
9258
+ end: mergedData.value.length - 1,
9259
+ offset: void 0
9260
+ });
9261
+ }
9262
+ }, {
9263
+ immediate: true
9264
+ });
9265
+ watch([isVirtual, mergedData, offsetHeight, inVirtual], () => {
9266
+ if (isVirtual.value && !inVirtual.value) {
9267
+ Object.assign(calRes, {
9268
+ scrollHeight: offsetHeight.value,
9269
+ start: 0,
9270
+ end: mergedData.value.length - 1,
9271
+ offset: void 0
9272
+ });
9273
+ }
9274
+ }, {
9275
+ immediate: true
9276
+ });
9277
+ watch([inVirtual, isVirtual, () => state.scrollTop, mergedData, updatedMark, () => props.height, offsetHeight], () => {
9278
+ if (!isVirtual.value || !inVirtual.value) {
9279
+ return;
9280
+ }
9281
+ let itemTop = 0;
9282
+ let startIndex;
9283
+ let startOffset;
9284
+ let endIndex;
9285
+ const mergedDataValue = unref(mergedData);
9286
+ const scrollTop = state.scrollTop;
9287
+ const {
9288
+ height
9289
+ } = props;
9290
+ const scrollTopHeight = scrollTop + height;
9291
+ for (let i = 0; i < mergedDataValue.length; i += 1) {
9292
+ const mergedDataItem = mergedDataValue[i];
9293
+ let cacheHeight;
9294
+ if (props.itemKey) {
9295
+ const key = getKey(mergedDataItem);
9296
+ cacheHeight = heights.get(key);
9297
+ }
9298
+ if (cacheHeight === void 0) {
9299
+ cacheHeight = props.itemHeight || DEFAULT_HEIGHT;
9300
+ }
9301
+ const currentItemBottom = itemTop + cacheHeight;
9302
+ if (startIndex === void 0 && currentItemBottom >= scrollTop) {
9303
+ startIndex = i;
9304
+ startOffset = itemTop;
9305
+ }
9306
+ if (endIndex === void 0 && currentItemBottom > scrollTopHeight) {
9307
+ endIndex = i;
9308
+ }
9309
+ itemTop = currentItemBottom;
9310
+ }
9311
+ if (startIndex === void 0) {
9312
+ startIndex = 0;
9313
+ startOffset = 0;
9314
+ }
9315
+ if (endIndex === void 0) {
9316
+ endIndex = mergedDataValue.length - 1;
9317
+ }
9318
+ endIndex = Math.min(endIndex + 1, mergedDataValue.length);
9319
+ Object.assign(calRes, {
9320
+ scrollHeight: itemTop,
9321
+ start: startIndex,
9322
+ end: endIndex,
9323
+ offset: startOffset
9324
+ });
9325
+ }, {
9326
+ immediate: true
9327
+ });
9328
+ const maxScrollHeight = computed(() => (calRes.scrollHeight || 0) - props.height);
9329
+ const keepInRange = (newScrollTop) => {
9330
+ let newTop = newScrollTop;
9331
+ if (!Number.isNaN(maxScrollHeight.value)) {
9332
+ newTop = Math.min(newTop, maxScrollHeight.value);
9333
+ }
9334
+ newTop = Math.max(newTop, 0);
9335
+ return newTop;
9336
+ };
9337
+ const isScrollAtTop = computed(() => state.scrollTop <= 0);
9338
+ const isScrollAtBottom = computed(() => state.scrollTop >= maxScrollHeight.value);
9339
+ const originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom);
9340
+ const syncScrollTop = (newTop) => {
9341
+ let value;
9342
+ if (typeof newTop === "function") {
9343
+ value = newTop(state.scrollTop);
9344
+ } else {
9345
+ value = newTop;
9346
+ }
9347
+ const alignedTop = keepInRange(value);
9348
+ if (componentRef.value) {
9349
+ componentRef.value.scrollTop = alignedTop;
9350
+ }
9351
+ state.scrollTop = alignedTop;
9352
+ };
9353
+ const onScrollBar = (newScrollTop) => {
9354
+ const newTop = newScrollTop;
9355
+ syncScrollTop(newTop);
9356
+ };
9357
+ const onComponentScroll = (e) => {
9358
+ var _a, _b;
9359
+ const {
9360
+ scrollTop: newScrollTop
9361
+ } = e.currentTarget;
9362
+ if (Math.abs(newScrollTop - state.scrollTop) >= 1) {
9363
+ syncScrollTop(newScrollTop);
9364
+ }
9365
+ (_b = (_a = barRef == null ? void 0 : barRef.value) == null ? void 0 : _a.onShowBar) == null ? void 0 : _b.call(_a);
9366
+ ctx.emit("scroll", e);
9367
+ };
9368
+ const [onRawWheel, onFireFoxScroll] = useFrameWheel(isVirtual, isScrollAtTop, isScrollAtBottom, (offsetY) => {
9369
+ syncScrollTop((top) => {
9370
+ const newTop = top + offsetY;
9371
+ return newTop;
9372
+ });
9373
+ });
9374
+ useMobileTouchMove(isVirtual, componentRef, (deltaY, smoothOffset) => {
9375
+ if (originScroll(deltaY, !!smoothOffset)) {
9376
+ return false;
9377
+ }
9378
+ onRawWheel({
9379
+ deltaY
9380
+ });
9381
+ return true;
9382
+ });
9383
+ const onMozMousePixelScroll = (e) => {
9384
+ if (isVirtual.value) {
9385
+ e.preventDefault();
9386
+ }
9387
+ };
9388
+ const removeEventListener = () => {
9389
+ if (componentRef.value) {
9390
+ componentRef.value.removeEventListener("wheel", onRawWheel, {
9391
+ passive: false
9392
+ });
9393
+ componentRef.value.removeEventListener("DOMMouseScroll", onFireFoxScroll);
9394
+ componentRef.value.removeEventListener("MozMousePixelScroll", onMozMousePixelScroll);
9395
+ }
9396
+ };
9397
+ watchEffect(() => {
9398
+ nextTick(() => {
9399
+ if (componentRef.value) {
9400
+ removeEventListener();
9401
+ componentRef.value.addEventListener("wheel", onRawWheel, {
9402
+ passive: false
9403
+ });
9404
+ componentRef.value.addEventListener("DOMMouseScroll", onFireFoxScroll);
9405
+ componentRef.value.addEventListener("MozMousePixelScroll", onMozMousePixelScroll);
9406
+ }
9407
+ });
9408
+ });
9409
+ onBeforeUnmount(() => {
9410
+ removeEventListener();
9411
+ });
9412
+ const componentStyle = computed(() => {
9413
+ let cs = null;
9414
+ if (props.height) {
9415
+ cs = __spreadValues({
9416
+ maxHeight: isVirtual.value ? props.height + "px" : void 0
9417
+ }, ScrollStyle);
9418
+ if (isVirtual.value) {
9419
+ cs.overflowY = "hidden";
9420
+ if (state.scrollMoving) {
9421
+ cs.pointerEvents = "none";
9422
+ }
9423
+ }
9424
+ }
9425
+ return cs;
9426
+ });
9427
+ watch([() => calRes.start, () => calRes.end, mergedData], () => {
9428
+ const renderList = mergedData.value.slice(calRes.start, calRes.end + 1);
9429
+ ctx.emit("show-change", renderList, mergedData.value);
9430
+ }, {
9431
+ flush: "post"
9432
+ });
9433
+ ctx.expose({
9434
+ scrollTo(index2) {
9435
+ syncScrollTop(index2 * (props.itemHeight || DEFAULT_HEIGHT));
9436
+ }
9437
+ });
9438
+ return () => {
9439
+ const Component = props.component;
9440
+ return createVNode("div", {
9441
+ "style": {
9442
+ position: "relative"
9443
+ }
9444
+ }, [createVNode(Component, {
9445
+ "style": componentStyle.value,
9446
+ "ref": componentRef,
9447
+ "onScroll": onComponentScroll
9448
+ }, {
9449
+ default: () => [createVNode(ResizeObserverContainer, {
9450
+ "height": calRes.scrollHeight,
9451
+ "offset": calRes.offset,
9452
+ "onInnerResize": collectHeight,
9453
+ "ref": fillerInnerRef
9454
+ }, {
9455
+ default: () => renderChildren(mergedData.value, calRes.start, calRes.end, setInstance, {
9456
+ getKey
9457
+ }, ctx.slots.item)
9458
+ })]
9459
+ }), isVirtual.value && createVNode(ScrollBar, {
9460
+ "ref": barRef,
9461
+ "scrollTop": state.scrollTop,
9462
+ "height": props.height,
9463
+ "scrollHeight": calRes.scrollHeight,
9464
+ "count": mergedData.value.length,
9465
+ "onScroll": onScrollBar,
9466
+ "onStartMove": () => {
9467
+ state.scrollMoving = true;
9468
+ },
9469
+ "onStopMove": () => {
9470
+ state.scrollMoving = false;
9471
+ }
9472
+ }, null)]);
9473
+ };
9474
+ }
9475
+ });
8415
9476
  function useToggle() {
8416
- return function useToggle2(data, core) {
9477
+ return function useToggle2(data, core, context, lazyLode) {
8417
9478
  const { getNode, setNodeValue } = core;
9479
+ const { lazyLoadNodes } = lazyLode;
8418
9480
  const expandNode = (node) => {
8419
- if (node.disableToggle) {
9481
+ if (node.disableToggle || node.loading) {
8420
9482
  return;
8421
9483
  }
8422
9484
  setNodeValue(node, "expanded", true);
9485
+ context.emit("toggle-change", node);
8423
9486
  };
8424
9487
  const collapseNode = (node) => {
8425
- if (node.disableToggle) {
9488
+ if (node.disableToggle || node.loading) {
8426
9489
  return;
8427
9490
  }
8428
9491
  setNodeValue(node, "expanded", false);
9492
+ context.emit("toggle-change", node);
8429
9493
  };
8430
9494
  const toggleNode = (node) => {
8431
- if (node.disableToggle) {
9495
+ if (node.disableToggle || node.loading) {
8432
9496
  return;
8433
9497
  }
8434
9498
  if (getNode(node).expanded) {
8435
- setNodeValue(node, "expanded", false);
9499
+ collapseNode(node);
8436
9500
  } else {
8437
- setNodeValue(node, "expanded", true);
9501
+ expandNode(node);
8438
9502
  }
9503
+ lazyLoadNodes(node);
8439
9504
  };
8440
9505
  const expandAllNodes = () => {
8441
9506
  data.value.forEach((node) => {
@@ -8463,16 +9528,19 @@ function omit(obj, ...keys) {
8463
9528
  }
8464
9529
  function generateInnerTree(tree2, key = "children", level = 0, path = []) {
8465
9530
  level++;
8466
- return tree2.reduce((acc, item) => {
8467
- var _a, _b;
9531
+ return tree2.reduce((acc, item, currentIndex) => {
9532
+ var _a, _b, _c;
8468
9533
  const newItem = Object.assign({}, item);
8469
9534
  if (newItem.id === void 0) {
8470
9535
  newItem.id = randomId();
8471
9536
  newItem.idType = "random";
8472
9537
  }
8473
9538
  newItem.level = level;
8474
- if (path.length > 0 && ((_a = path[path.length - 1]) == null ? void 0 : _a.level) >= level) {
8475
- while (((_b = path[path.length - 1]) == null ? void 0 : _b.level) >= level) {
9539
+ newItem.parentChildNodeCount = tree2.length;
9540
+ newItem.currentIndex = currentIndex;
9541
+ newItem.childNodeCount = ((_a = newItem.children) == null ? void 0 : _a.length) || 0;
9542
+ if (path.length > 0 && ((_b = path[path.length - 1]) == null ? void 0 : _b.level) >= level) {
9543
+ while (((_c = path[path.length - 1]) == null ? void 0 : _c.level) >= level) {
8476
9544
  path.pop();
8477
9545
  }
8478
9546
  }
@@ -8482,7 +9550,7 @@ function generateInnerTree(tree2, key = "children", level = 0, path = []) {
8482
9550
  newItem.parentId = parentNode.id;
8483
9551
  }
8484
9552
  if (!newItem[key]) {
8485
- return acc.concat(__spreadProps(__spreadValues({}, newItem), { isLeaf: true }));
9553
+ return acc.concat(__spreadProps(__spreadValues({}, newItem), { isLeaf: newItem.isLeaf === false ? false : true }));
8486
9554
  } else {
8487
9555
  return acc.concat(omit(newItem, "children"), generateInnerTree(newItem[key], key, level, path));
8488
9556
  }
@@ -8492,12 +9560,23 @@ const DEFAULT_CONFIG = {
8492
9560
  expanded: false,
8493
9561
  recursive: true
8494
9562
  };
9563
+ const nodeMap = /* @__PURE__ */ new Map();
8495
9564
  function useCore() {
8496
9565
  return function useCore2(data) {
8497
9566
  const getLevel = (node) => {
8498
- return data.value.find((item) => item.id === node.id).level;
9567
+ var _a;
9568
+ return (_a = data.value.find((item) => item.id === node.id)) == null ? void 0 : _a.level;
8499
9569
  };
8500
9570
  const getChildren = (node, userConfig = DEFAULT_CONFIG) => {
9571
+ if (node.isLeaf) {
9572
+ return [];
9573
+ }
9574
+ if (node.id && nodeMap.has(node.id)) {
9575
+ const cacheNode = nodeMap.get(node.id);
9576
+ if (cacheNode) {
9577
+ return cacheNode;
9578
+ }
9579
+ }
8501
9580
  const getInnerExpendedTree = () => {
8502
9581
  return computed(() => {
8503
9582
  let excludeNodes = [];
@@ -8507,7 +9586,7 @@ function useCore() {
8507
9586
  if (excludeNodes.map((innerNode) => innerNode.id).includes(item.id)) {
8508
9587
  continue;
8509
9588
  }
8510
- if (item.expanded !== true) {
9589
+ if (item.expanded !== true && !item.isLeaf) {
8511
9590
  excludeNodes = getChildren(item);
8512
9591
  }
8513
9592
  result2.push(item);
@@ -8526,6 +9605,9 @@ function useCore() {
8526
9605
  result.push(treeData.value[i]);
8527
9606
  }
8528
9607
  }
9608
+ if (node.id) {
9609
+ nodeMap.set(node.id, result);
9610
+ }
8529
9611
  return result;
8530
9612
  };
8531
9613
  const getParent = (node) => {
@@ -8549,17 +9631,30 @@ function useCore() {
8549
9631
  });
8550
9632
  };
8551
9633
  const getIndex = (node) => {
9634
+ if (!node) {
9635
+ return -1;
9636
+ }
8552
9637
  return data.value.findIndex((item) => item.id === node.id);
8553
9638
  };
8554
9639
  const getNode = (node) => {
8555
9640
  return data.value.find((item) => item.id === node.id);
8556
9641
  };
8557
9642
  const setNodeValue = (node, key, value) => {
8558
- data.value[getIndex(node)][key] = value;
9643
+ nodeMap.clear();
9644
+ if (getIndex(node) !== -1) {
9645
+ data.value[getIndex(node)][key] = value;
9646
+ }
8559
9647
  };
8560
9648
  const setTree = (newTree) => {
9649
+ nodeMap.clear();
8561
9650
  data.value = generateInnerTree(newTree);
8562
9651
  };
9652
+ const getTree = () => {
9653
+ return data.value;
9654
+ };
9655
+ onUnmounted(() => {
9656
+ nodeMap.clear();
9657
+ });
8563
9658
  return {
8564
9659
  getLevel,
8565
9660
  getChildren,
@@ -8568,76 +9663,130 @@ function useCore() {
8568
9663
  getIndex,
8569
9664
  getNode,
8570
9665
  setNodeValue,
8571
- setTree
9666
+ setTree,
9667
+ getTree
9668
+ };
9669
+ };
9670
+ }
9671
+ function useLazyLoad() {
9672
+ return function useLazyLoad2(data, core, context) {
9673
+ const { getNode, setNodeValue, getIndex, getChildren } = core;
9674
+ const setCommonParent = (node, nodes) => {
9675
+ nodes.value.forEach((item) => {
9676
+ if (item.level - 1 === node.level && !item.parentId) {
9677
+ item.parentId = node.id;
9678
+ }
9679
+ });
9680
+ };
9681
+ const insertChildrenNodes = (parent, nodes) => {
9682
+ const parentIndex = getIndex(parent);
9683
+ if (parentIndex !== -1) {
9684
+ data.value.splice(parentIndex + 1, 0, ...nodes.value);
9685
+ }
9686
+ };
9687
+ const dealChildNodes = (result) => {
9688
+ const node = getNode(result.node);
9689
+ setNodeValue(node, "loading", false);
9690
+ const childNodes = ref(generateInnerTree(result.treeItems, "children", node.level));
9691
+ setCommonParent(node, childNodes);
9692
+ insertChildrenNodes(node, childNodes);
9693
+ const childrenNodes = getChildren(node);
9694
+ setNodeValue(node, "childNodeCount", childrenNodes.length);
9695
+ };
9696
+ const lazyLoadNodes = (node) => {
9697
+ const innerNode = getNode(node);
9698
+ if (!innerNode.isLeaf && !innerNode.childNodeCount) {
9699
+ setNodeValue(node, "loading", true);
9700
+ context.emit("lazy-load", node, dealChildNodes);
9701
+ }
9702
+ };
9703
+ return {
9704
+ lazyLoadNodes
8572
9705
  };
8573
9706
  };
8574
9707
  }
8575
9708
  const DEFAULT_TREE_PLUGINS = [useCore(), useToggle()];
8576
- function useTree(tree2, plugins = []) {
9709
+ function useTree(tree2, plugins = [], context) {
8577
9710
  const treeData = ref(generateInnerTree(tree2));
8578
9711
  const core = useCore()(treeData);
9712
+ const lazyLode = useLazyLoad()(treeData, core, context);
8579
9713
  const pluginMethods = DEFAULT_TREE_PLUGINS.concat(plugins).reduce((acc, plugin) => {
8580
- return __spreadValues(__spreadValues({}, acc), plugin(treeData, core));
9714
+ return __spreadValues(__spreadValues({}, acc), plugin(treeData, core, context, lazyLode));
8581
9715
  }, {});
8582
9716
  return __spreadValues({
8583
9717
  treeData
8584
9718
  }, pluginMethods);
8585
9719
  }
8586
9720
  function useCheck(options = ref({ checkStrategy: "both" })) {
8587
- return function useCheck2(data, core) {
9721
+ return function useCheck2(data, core, context) {
8588
9722
  const { setNodeValue, getNode, getChildren, getParent } = core;
8589
9723
  const checkNode = (node) => {
8590
9724
  setNodeValue(node, "checked", true);
9725
+ context.emit("check-change", node);
8591
9726
  };
8592
9727
  const uncheckNode = (node) => {
8593
9728
  setNodeValue(node, "checked", false);
9729
+ context.emit("check-change", node);
8594
9730
  };
8595
- const controlParentNodeChecked = (node) => {
9731
+ const controlParentNodeChecked = (node, checked) => {
9732
+ if (!node.parentId) {
9733
+ return;
9734
+ }
8596
9735
  const parentNode = getParent(node);
8597
9736
  if (!parentNode) {
8598
9737
  return;
8599
9738
  }
8600
- const siblingNodes = getChildren(parentNode, { recursive: false });
8601
- const checkedSiblingNodes = siblingNodes.filter((item) => item.checked);
8602
- const toggleParentChecked = () => {
9739
+ let childChecked = checked;
9740
+ if (checked) {
9741
+ if (!parentNode.checked) {
9742
+ setNodeValue(parentNode, "checked", true);
9743
+ }
9744
+ } else {
9745
+ const siblingNodes = getChildren(parentNode);
9746
+ const checkedSiblingNodes = siblingNodes.filter((item) => item.checked && item.id !== node.id);
8603
9747
  if (checkedSiblingNodes.length === 0) {
8604
9748
  setNodeValue(parentNode, "checked", false);
8605
- } else if (checkedSiblingNodes.length === siblingNodes.length) {
9749
+ } else {
8606
9750
  setNodeValue(parentNode, "checked", true);
9751
+ childChecked = true;
8607
9752
  }
8608
- };
9753
+ }
8609
9754
  if (parentNode.parentId) {
8610
- toggleParentChecked();
8611
- controlParentNodeChecked(parentNode);
8612
- } else {
8613
- toggleParentChecked();
9755
+ controlParentNodeChecked(parentNode, childChecked);
8614
9756
  }
8615
9757
  };
8616
9758
  const toggleCheckNode = (node) => {
8617
- if (getNode(node).checked) {
9759
+ const checked = getNode(node).checked;
9760
+ if (checked) {
8618
9761
  setNodeValue(node, "checked", false);
9762
+ context.emit("check-change", node);
8619
9763
  if (["downward", "both"].includes(options.value.checkStrategy)) {
8620
9764
  getChildren(node).forEach((item) => setNodeValue(item, "checked", false));
8621
9765
  }
8622
9766
  } else {
8623
9767
  setNodeValue(node, "checked", true);
9768
+ context.emit("check-change", node);
8624
9769
  if (["downward", "both"].includes(options.value.checkStrategy)) {
8625
9770
  getChildren(node).forEach((item) => setNodeValue(item, "checked", true));
8626
9771
  }
8627
9772
  }
8628
9773
  if (["upward", "both"].includes(options.value.checkStrategy)) {
8629
- controlParentNodeChecked(node);
9774
+ controlParentNodeChecked(node, !checked);
8630
9775
  }
8631
9776
  };
9777
+ const getCheckedNodes = () => {
9778
+ return data.value.filter((node) => node.checked);
9779
+ };
8632
9780
  return {
8633
9781
  checkNode,
8634
9782
  uncheckNode,
8635
- toggleCheckNode
9783
+ toggleCheckNode,
9784
+ getCheckedNodes
8636
9785
  };
8637
9786
  };
8638
9787
  }
8639
9788
  function useSelect() {
8640
- return function useSelect2(data, core) {
9789
+ return function useSelect2(data, core, context) {
8641
9790
  const { setNodeValue } = core;
8642
9791
  let prevActiveNode;
8643
9792
  const selectNode = (node) => {
@@ -8649,10 +9798,12 @@ function useSelect() {
8649
9798
  setNodeValue(data.value[prevActiveNodeIndex], "selected", false);
8650
9799
  }
8651
9800
  setNodeValue(node, "selected", true);
9801
+ context.emit("select-change", node);
8652
9802
  prevActiveNode = node;
8653
9803
  };
8654
9804
  const deselectNode = (node) => {
8655
9805
  setNodeValue(node, "selected", false);
9806
+ context.emit("select-change", node);
8656
9807
  };
8657
9808
  const toggleSelectNode = (node) => {
8658
9809
  if (node.selected) {
@@ -8661,10 +9812,14 @@ function useSelect() {
8661
9812
  selectNode(node);
8662
9813
  }
8663
9814
  };
9815
+ const getSelectedNode = () => {
9816
+ return data.value.find((node) => node.selected);
9817
+ };
8664
9818
  return {
8665
9819
  selectNode,
8666
9820
  deselectNode,
8667
- toggleSelectNode
9821
+ toggleSelectNode,
9822
+ getSelectedNode
8668
9823
  };
8669
9824
  };
8670
9825
  }
@@ -8672,7 +9827,9 @@ function useOperate() {
8672
9827
  return function useOperate2(data, core) {
8673
9828
  const { setNodeValue, getChildren, getIndex, getLevel } = core;
8674
9829
  const insertBefore = (parentNode, node, referenceNode) => {
8675
- const children = getChildren(parentNode);
9830
+ const children = getChildren(parentNode, {
9831
+ recursive: false
9832
+ });
8676
9833
  const lastChild = children[children.length - 1];
8677
9834
  let insertedIndex = getIndex(parentNode) + 1;
8678
9835
  if (referenceNode) {
@@ -8682,12 +9839,20 @@ function useOperate() {
8682
9839
  }
8683
9840
  setNodeValue(parentNode, "expanded", true);
8684
9841
  setNodeValue(parentNode, "isLeaf", false);
8685
- const currentNode = __spreadProps(__spreadValues({}, node), {
9842
+ if (lastChild) {
9843
+ setNodeValue(lastChild, "parentChildNodeCount", children.length + 1);
9844
+ }
9845
+ const currentNode = ref(__spreadProps(__spreadValues({}, node), {
8686
9846
  level: getLevel(parentNode) + 1,
8687
9847
  parentId: parentNode.id,
8688
- isLeaf: true
8689
- });
8690
- data.value = data.value.slice(0, insertedIndex).concat(currentNode, data.value.slice(insertedIndex, data.value.length));
9848
+ isLeaf: true,
9849
+ parentChildNodeCount: children.length + 1,
9850
+ currentIndex: (lastChild == null ? void 0 : lastChild.currentIndex) + 1
9851
+ }));
9852
+ if (currentNode.value.id === void 0) {
9853
+ currentNode.value.id = randomId();
9854
+ }
9855
+ data.value = data.value.slice(0, insertedIndex).concat(currentNode.value, data.value.slice(insertedIndex, data.value.length));
8691
9856
  };
8692
9857
  const removeNode = (node, config = { recursive: true }) => {
8693
9858
  if (!config.recursive) {
@@ -8756,32 +9921,43 @@ const treeProps = {
8756
9921
  check: {
8757
9922
  type: [Boolean, String],
8758
9923
  default: false
9924
+ },
9925
+ operate: {
9926
+ type: [Boolean, String, Array],
9927
+ default: false
9928
+ },
9929
+ height: {
9930
+ type: [Number, String]
8759
9931
  }
8760
9932
  };
8761
9933
  var tree = "";
8762
9934
  var Tree = defineComponent({
8763
9935
  name: "DTree",
8764
9936
  props: treeProps,
8765
- setup(props, {
8766
- slots,
8767
- expose
8768
- }) {
9937
+ emits: ["toggle-change", "check-change", "select-change", "node-click", "lazy-load"],
9938
+ setup(props, context) {
9939
+ const {
9940
+ slots,
9941
+ expose
9942
+ } = context;
9943
+ const treeInstance = getCurrentInstance();
8769
9944
  const {
8770
9945
  data,
8771
- check
9946
+ check,
9947
+ operate
8772
9948
  } = toRefs(props);
8773
9949
  const ns2 = useNamespace("tree");
8774
9950
  const userPlugins = [useSelect(), useOperate(), useMergeNodes()];
8775
9951
  const checkOptions = ref({
8776
- checkStrategy: check.value || "both"
9952
+ checkStrategy: formatCheckStatus(check.value)
8777
9953
  });
8778
9954
  watch(check, (newVal) => {
8779
- checkOptions.value.checkStrategy = newVal;
9955
+ checkOptions.value.checkStrategy = formatCheckStatus(newVal);
8780
9956
  });
8781
9957
  if (check.value) {
8782
9958
  userPlugins.push(useCheck(checkOptions));
8783
9959
  }
8784
- const treeFactory = useTree(data.value, userPlugins);
9960
+ const treeFactory = useTree(data.value, userPlugins, context);
8785
9961
  const {
8786
9962
  setTree,
8787
9963
  getExpendedTree,
@@ -8789,38 +9965,58 @@ var Tree = defineComponent({
8789
9965
  } = treeFactory;
8790
9966
  watch(data, setTree);
8791
9967
  provide(USE_TREE_TOKEN, treeFactory);
9968
+ provide(TREE_INSTANCE, treeInstance);
8792
9969
  expose({
8793
9970
  treeFactory
8794
9971
  });
9972
+ const renderDTreeNode = (treeNode) => slots.default ? renderSlot(useSlots(), "default", {
9973
+ treeFactory,
9974
+ nodeData: treeNode
9975
+ }) : createVNode(DTreeNode, {
9976
+ "data": treeNode,
9977
+ "check": check.value,
9978
+ "operate": operate.value
9979
+ }, {
9980
+ default: () => slots.content ? renderSlot(useSlots(), "content", {
9981
+ nodeData: treeNode
9982
+ }) : createVNode(DTreeNodeContent, {
9983
+ "data": treeNode
9984
+ }, null),
9985
+ icon: () => slots.icon ? renderSlot(useSlots(), "icon", {
9986
+ nodeData: treeNode,
9987
+ toggleNode
9988
+ }) : createVNode(DTreeNodeToggle, {
9989
+ "data": treeNode
9990
+ }, null),
9991
+ loading: () => slots.loading ? renderSlot(useSlots(), "loading", {
9992
+ nodeData: treeNode
9993
+ }) : createVNode(DTreeNodeLoading, null, null)
9994
+ });
8795
9995
  return () => {
8796
- return createVNode("div", {
9996
+ const Component = props.height ? VirtualList : "div";
9997
+ const treeData = getExpendedTree == null ? void 0 : getExpendedTree().value;
9998
+ const vSlotsProps = {
9999
+ default: () => treeData == null ? void 0 : treeData.map(renderDTreeNode),
10000
+ item: props.height && ((treeNode) => renderDTreeNode(treeNode))
10001
+ };
10002
+ let virtualListProps2 = {};
10003
+ if (props.height) {
10004
+ virtualListProps2 = {
10005
+ height: props.height,
10006
+ data: treeData,
10007
+ itemHeight: NODE_HEIGHT
10008
+ };
10009
+ }
10010
+ return createVNode(Component, mergeProps({
8797
10011
  "class": ns2.b()
8798
- }, [getExpendedTree == null ? void 0 : getExpendedTree().value.map((treeNode) => slots.default ? renderSlot(useSlots(), "default", {
8799
- treeFactory,
8800
- nodeData: treeNode
8801
- }) : createVNode(DTreeNode, {
8802
- "data": treeNode,
8803
- "check": check.value
8804
- }, {
8805
- default: () => slots.content ? renderSlot(useSlots(), "content", {
8806
- nodeData: treeNode
8807
- }) : createVNode(DTreeNodeContent, {
8808
- "data": treeNode
8809
- }, null),
8810
- icon: () => slots.icon ? renderSlot(useSlots(), "icon", {
8811
- nodeData: treeNode,
8812
- toggleNode
8813
- }) : createVNode(DTreeNodeToggle, {
8814
- "data": treeNode
8815
- }, null)
8816
- }))]);
10012
+ }, virtualListProps2), vSlotsProps);
8817
10013
  };
8818
10014
  }
8819
10015
  });
8820
10016
  var index = {
8821
10017
  title: "Tree \u6811",
8822
10018
  category: "\u6570\u636E\u5C55\u793A",
8823
- status: "20%",
10019
+ status: "50%",
8824
10020
  install(app) {
8825
10021
  app.component(Tree.name, Tree);
8826
10022
  }