@wfrog/vc-ui 1.11.10 → 1.11.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 (141) hide show
  1. package/dist/es/chunk/Bw0Rhd-r.mjs +110 -0
  2. package/dist/es/chunk/CqTdDZkE.mjs +31 -0
  3. package/dist/es/chunk/{DAnWZLYj.mjs → CzWfBa_8.mjs} +96 -2
  4. package/dist/es/chunk/D229kQ56.mjs +28 -0
  5. package/dist/es/chunk/{Cxx_YWUC.mjs → DcouM6gM.mjs} +6 -548
  6. package/dist/es/chunk/Fo0dZYnz.mjs +128 -0
  7. package/dist/es/chunk/KanuIcmc.mjs +412 -0
  8. package/dist/es/chunk/{B71xEPfK.mjs → uuUHUjSk.mjs} +4 -35
  9. package/dist/es/components/backbottom/backbottom.mjs +3 -2
  10. package/dist/es/components/button/button.mjs +14 -13
  11. package/dist/es/components/choice/choice.mjs +11 -9
  12. package/dist/es/components/choice/index.css +1 -1
  13. package/dist/es/components/choice-boolean/choice-boolean.mjs +3 -3
  14. package/dist/es/components/color-switch/color-switch.mjs +73 -1046
  15. package/dist/es/components/color-switch/index.css +1 -1
  16. package/dist/es/components/cropper/cropper.mjs +11 -117
  17. package/dist/es/components/cropper/index.css +1 -1
  18. package/dist/es/components/currency/currency.mjs +10 -12
  19. package/dist/es/components/daterange-picker/daterange-picker.mjs +10 -6255
  20. package/dist/es/components/dialog/dialog.mjs +14 -408
  21. package/dist/es/components/dialog/index.css +1 -1
  22. package/dist/es/components/dialog-camera-upload/dialog-camera-upload.mjs +11 -14
  23. package/dist/es/components/dialog-map-point/dialog-map-point.mjs +4 -4
  24. package/dist/es/components/dialog-upload-images/dialog-upload-images.mjs +14 -1380
  25. package/dist/es/components/dialog-upload-images/index.css +1 -1
  26. package/dist/es/components/drag-verify/drag-verify.mjs +3 -2
  27. package/dist/es/components/drawer/drawer.mjs +16 -359
  28. package/dist/es/components/drawer/index.css +3 -3
  29. package/dist/es/components/easy-pagination/easy-pagination.mjs +3 -2
  30. package/dist/es/components/explorer/explorer.mjs +8 -8
  31. package/dist/es/components/explorer-column-table/explorer-column-table.mjs +5 -7
  32. package/dist/es/components/explorer-column-table/index.css +1 -1
  33. package/dist/es/components/explorer-container/explorer-container.d.ts +1 -1
  34. package/dist/es/components/explorer-container/explorer-container.mjs +4 -3
  35. package/dist/es/components/explorer-filter/explorer-filter.mjs +5 -4
  36. package/dist/es/components/explorer-footer/explorer-footer.mjs +4 -8
  37. package/dist/es/components/explorer-form/explorer-form.mjs +4 -3
  38. package/dist/es/components/explorer-list/explorer-list.mjs +18 -13
  39. package/dist/es/components/explorer-list/explorer-list.vue.d.ts +1 -1
  40. package/dist/es/components/explorer-list/index.css +16 -16
  41. package/dist/es/components/explorer-modal-form/explorer-modal-form.mjs +8 -7
  42. package/dist/es/components/explorer-panel/explorer-panel.mjs +3 -3
  43. package/dist/es/components/explorer-query/explorer-query.mjs +9 -2201
  44. package/dist/es/components/explorer-query/index.css +1 -1
  45. package/dist/es/components/explorer-table/explorer-table.mjs +5 -8
  46. package/dist/es/components/explorer-tools/explorer-tools.mjs +23 -271
  47. package/dist/es/components/explorer-tools/index.css +9 -9
  48. package/dist/es/components/explorer-tree/explorer-tree.mjs +4 -5
  49. package/dist/es/components/explorer-tree/explorer-tree.vue.d.ts +1 -1
  50. package/dist/es/components/form-item/form-item.mjs +3 -3
  51. package/dist/es/components/icon-picker/icon-picker.mjs +8 -12
  52. package/dist/es/components/image/image.mjs +4 -4
  53. package/dist/es/components/info-tooltip/info-tooltip.mjs +336 -4
  54. package/dist/es/components/input/input.mjs +3 -2
  55. package/dist/es/components/input-number/input-number.mjs +3 -3
  56. package/dist/es/components/pca-picker/index.css +1 -1
  57. package/dist/es/components/pca-picker/pca-picker.mjs +443 -601
  58. package/dist/es/components/screenfull/screenfull.mjs +4 -3
  59. package/dist/es/components/scrollbar/index.css +1 -1
  60. package/dist/es/components/scrollbar/scrollbar.mjs +10 -10
  61. package/dist/es/components/select/index.css +1 -1
  62. package/dist/es/components/select/select.mjs +9 -10
  63. package/dist/es/components/single-player/index.css +1 -1
  64. package/dist/es/components/single-player/single-player.mjs +10 -1087
  65. package/dist/es/components/splitter/splitter.mjs +3 -3
  66. package/dist/es/components/splitter-panel/splitter-panel.mjs +3 -3
  67. package/dist/es/components/switch/index.css +1 -1
  68. package/dist/es/components/switch/switch.mjs +9 -395
  69. package/dist/es/components/tags/tags.mjs +7 -9
  70. package/dist/es/components/text-ellipsis/text-ellipsis.mjs +3 -3
  71. package/dist/es/components/thousand-input/thousand-input.mjs +39 -8
  72. package/dist/es/components/tinymce/tinymce.mjs +4 -3
  73. package/dist/es/components/transfer/transfer.mjs +3 -4
  74. package/dist/es/components/transfer-panel/transfer-panel.mjs +5 -4
  75. package/dist/es/components/tree-picker/popover-cascader.css +1 -1
  76. package/dist/es/components/tree-picker/tree-picker.mjs +5 -10
  77. package/dist/es/index.mjs +1 -1
  78. package/dist/index.css +41 -68
  79. package/package.json +1 -1
  80. package/dist/es/chunk/B-rxnVJv.mjs +0 -3
  81. package/dist/es/chunk/B5HpgPRt.mjs +0 -69
  82. package/dist/es/chunk/BBhZKpIc.mjs +0 -2179
  83. package/dist/es/chunk/BDcsaNYa.mjs +0 -59
  84. package/dist/es/chunk/BTSSEFfD.mjs +0 -319
  85. package/dist/es/chunk/BTpNRPQW.mjs +0 -55
  86. package/dist/es/chunk/BVBK1U57.mjs +0 -96
  87. package/dist/es/chunk/Bc6yUGLs.mjs +0 -45
  88. package/dist/es/chunk/BjVI1XMz.mjs +0 -40
  89. package/dist/es/chunk/BlzQCBDu.mjs +0 -5741
  90. package/dist/es/chunk/BpJKnxlF.mjs +0 -476
  91. package/dist/es/chunk/Brp-qSBw.mjs +0 -2003
  92. package/dist/es/chunk/BunQI8Jb.mjs +0 -390
  93. package/dist/es/chunk/C0XgBrDz.mjs +0 -775
  94. package/dist/es/chunk/C0pTANRX.mjs +0 -109
  95. package/dist/es/chunk/CBMjhoFP.mjs +0 -101
  96. package/dist/es/chunk/CBiNtNvQ.mjs +0 -242
  97. package/dist/es/chunk/CBlJeNBO.mjs +0 -890
  98. package/dist/es/chunk/CCVL_Zj-.mjs +0 -427
  99. package/dist/es/chunk/CEl4MyfJ.mjs +0 -252
  100. package/dist/es/chunk/CJK5_jsA.mjs +0 -53
  101. package/dist/es/chunk/CKOcwq5V.mjs +0 -44
  102. package/dist/es/chunk/COs9dJZa.mjs +0 -66
  103. package/dist/es/chunk/CPt6MxJW.mjs +0 -375
  104. package/dist/es/chunk/CVqW0jzp.mjs +0 -107
  105. package/dist/es/chunk/CccIsEqA.mjs +0 -128
  106. package/dist/es/chunk/CjLR27-a.mjs +0 -582
  107. package/dist/es/chunk/CoGexPPD.mjs +0 -2192
  108. package/dist/es/chunk/CsLIbnzG.mjs +0 -64
  109. package/dist/es/chunk/Ct6q2FXg.mjs +0 -5
  110. package/dist/es/chunk/Cuq5meQh.mjs +0 -184
  111. package/dist/es/chunk/CvYIOfT1.mjs +0 -23
  112. package/dist/es/chunk/CxHJBf4l.mjs +0 -31
  113. package/dist/es/chunk/CzdaOBtA.mjs +0 -66
  114. package/dist/es/chunk/D0QTifnI.mjs +0 -54
  115. package/dist/es/chunk/D1QnA2iT.mjs +0 -229
  116. package/dist/es/chunk/D3AvJlVX.mjs +0 -188
  117. package/dist/es/chunk/D9Lr0Bzb.mjs +0 -1136
  118. package/dist/es/chunk/DCkPv0hy.mjs +0 -29
  119. package/dist/es/chunk/DRwwUUhy.mjs +0 -49
  120. package/dist/es/chunk/DX-2VRY2.mjs +0 -836
  121. package/dist/es/chunk/DZ2oTFad.mjs +0 -687
  122. package/dist/es/chunk/D_bou1py.mjs +0 -55
  123. package/dist/es/chunk/Da199A5L.mjs +0 -314
  124. package/dist/es/chunk/DbhQlaOz.mjs +0 -94
  125. package/dist/es/chunk/Dgu95mOy.mjs +0 -237
  126. package/dist/es/chunk/DhGOsWxx.mjs +0 -6
  127. package/dist/es/chunk/Dm_Sj5aH.mjs +0 -487
  128. package/dist/es/chunk/Dmi-1GRO.mjs +0 -163
  129. package/dist/es/chunk/DodoD9a9.mjs +0 -52
  130. package/dist/es/chunk/DrrVDcwm.mjs +0 -955
  131. package/dist/es/chunk/Du_zJ1Fz.mjs +0 -49
  132. package/dist/es/chunk/DxxbB5jY.mjs +0 -34
  133. package/dist/es/chunk/Gk1J52Yw.mjs +0 -207
  134. package/dist/es/chunk/NsldgdCh.mjs +0 -704
  135. package/dist/es/chunk/V6KjsUQN.mjs +0 -35
  136. package/dist/es/chunk/eEsLFV3s.mjs +0 -76
  137. package/dist/es/chunk/fqiLhk0V.mjs +0 -2065
  138. package/dist/es/chunk/nxVM7re4.mjs +0 -35
  139. package/dist/es/chunk/s7HLrANj.mjs +0 -215
  140. package/dist/es/chunk/vPhxogl3.mjs +0 -19
  141. package/dist/es/components/icon/icon2.mjs +0 -27
@@ -1,2003 +0,0 @@
1
- import { defineComponent, createBlock, openBlock, Transition, mergeProps, unref, toHandlers, withCtx, renderSlot, reactive, nextTick, inject, h, onBeforeUnmount, provide, ref, resolveComponent, withDirectives, createElementBlock, withModifiers, normalizeClass, createElementVNode, createVNode, normalizeStyle, createCommentVNode, resolveDynamicComponent, Fragment, renderList, vShow, getCurrentInstance, watch, onMounted, onUpdated, toDisplayString, computed } from 'vue';
2
- import { u as useNamespace, h as hasOwn, c as isArray, f as isFunction, i as isString, N as NOOP, j as isObject, a as debugWarn, b as buildProps, d as definePropType } from './Gk1J52Yw.mjs';
3
- import { d as isBoolean, i as isNil, c as isUndefined, g as isPropAbsent } from './Bc6yUGLs.mjs';
4
- import { _ as _export_sfc, w as withInstall } from './V6KjsUQN.mjs';
5
- import { a as ElCheckbox } from './NsldgdCh.mjs';
6
- import { E as ElIcon } from './D0QTifnI.mjs';
7
- import { Loading, CaretRight } from '@element-plus/icons-vue';
8
- import { E as ElText } from './DbhQlaOz.mjs';
9
- import { r as removeClass, b as addClass } from './DodoD9a9.mjs';
10
- import { useEventListener } from '@vueuse/core';
11
- import { g as getEventCode, E as EVENT_CODE } from './BTpNRPQW.mjs';
12
- import { i as iconPropType } from '../components/icon/icon2.mjs';
13
- import { u as useLocale } from './CEl4MyfJ.mjs';
14
- import { a as formItemContextKey } from './nxVM7re4.mjs';
15
- import { i as isEqual } from './B71xEPfK.mjs';
16
-
17
- const _sfc_main$3 = defineComponent({
18
- ...{
19
- name: "ElCollapseTransition"
20
- },
21
- __name: "collapse-transition",
22
- setup(__props) {
23
- const ns = useNamespace("collapse-transition");
24
- const reset = (el) => {
25
- el.style.maxHeight = "";
26
- el.style.overflow = el.dataset.oldOverflow;
27
- el.style.paddingTop = el.dataset.oldPaddingTop;
28
- el.style.paddingBottom = el.dataset.oldPaddingBottom;
29
- };
30
- const on = {
31
- beforeEnter(el) {
32
- if (!el.dataset)
33
- el.dataset = {};
34
- el.dataset.oldPaddingTop = el.style.paddingTop;
35
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
36
- if (el.style.height)
37
- el.dataset.elExistsHeight = el.style.height;
38
- el.style.maxHeight = 0;
39
- el.style.paddingTop = 0;
40
- el.style.paddingBottom = 0;
41
- },
42
- enter(el) {
43
- requestAnimationFrame(() => {
44
- el.dataset.oldOverflow = el.style.overflow;
45
- if (el.dataset.elExistsHeight) {
46
- el.style.maxHeight = el.dataset.elExistsHeight;
47
- } else if (el.scrollHeight !== 0) {
48
- el.style.maxHeight = `${el.scrollHeight}px`;
49
- } else {
50
- el.style.maxHeight = 0;
51
- }
52
- el.style.paddingTop = el.dataset.oldPaddingTop;
53
- el.style.paddingBottom = el.dataset.oldPaddingBottom;
54
- el.style.overflow = "hidden";
55
- });
56
- },
57
- afterEnter(el) {
58
- el.style.maxHeight = "";
59
- el.style.overflow = el.dataset.oldOverflow;
60
- },
61
- enterCancelled(el) {
62
- reset(el);
63
- },
64
- beforeLeave(el) {
65
- if (!el.dataset)
66
- el.dataset = {};
67
- el.dataset.oldPaddingTop = el.style.paddingTop;
68
- el.dataset.oldPaddingBottom = el.style.paddingBottom;
69
- el.dataset.oldOverflow = el.style.overflow;
70
- el.style.maxHeight = `${el.scrollHeight}px`;
71
- el.style.overflow = "hidden";
72
- },
73
- leave(el) {
74
- if (el.scrollHeight !== 0) {
75
- el.style.maxHeight = 0;
76
- el.style.paddingTop = 0;
77
- el.style.paddingBottom = 0;
78
- }
79
- },
80
- afterLeave(el) {
81
- reset(el);
82
- },
83
- leaveCancelled(el) {
84
- reset(el);
85
- }
86
- };
87
- return (_ctx, _cache) => {
88
- return openBlock(), createBlock(Transition, mergeProps({
89
- name: unref(ns).b()
90
- }, toHandlers(on)), {
91
- default: withCtx(() => [
92
- renderSlot(_ctx.$slots, "default")
93
- ]),
94
- _: 3
95
- }, 16, ["name"]);
96
- };
97
- }
98
- });
99
- var CollapseTransition = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/collapse-transition/src/collapse-transition.vue"]]);
100
-
101
- const ElCollapseTransition = withInstall(CollapseTransition);
102
-
103
- const NODE_KEY = "$treeNodeId";
104
- const markNodeData = function(node, data) {
105
- if (!data || data[NODE_KEY])
106
- return;
107
- Object.defineProperty(data, NODE_KEY, {
108
- value: node.id,
109
- enumerable: false,
110
- configurable: false,
111
- writable: false
112
- });
113
- };
114
- const getNodeKey = (key, data) => data == null ? void 0 : data[key || NODE_KEY];
115
- const handleCurrentChange = (store, emit, setCurrent) => {
116
- const preCurrentNode = store.value.currentNode;
117
- setCurrent();
118
- const currentNode = store.value.currentNode;
119
- if (preCurrentNode === currentNode)
120
- return;
121
- emit("current-change", currentNode ? currentNode.data : null, currentNode);
122
- };
123
-
124
- const getChildState = (node) => {
125
- let all = true;
126
- let none = true;
127
- let allWithoutDisable = true;
128
- let isEffectivelyChecked = true;
129
- for (let i = 0, j = node.length; i < j; i++) {
130
- const n = node[i];
131
- if (n.checked !== true || n.indeterminate) {
132
- all = false;
133
- if (!n.disabled) {
134
- allWithoutDisable = false;
135
- }
136
- }
137
- if (n.checked !== false || n.indeterminate) {
138
- none = false;
139
- }
140
- if (!n.isEffectivelyChecked) {
141
- isEffectivelyChecked = false;
142
- }
143
- }
144
- return {
145
- all,
146
- none,
147
- allWithoutDisable,
148
- half: !all && !none,
149
- isEffectivelyChecked
150
- };
151
- };
152
- const reInitChecked = function(node) {
153
- if (node.childNodes.length === 0 || node.loading) {
154
- node.isEffectivelyChecked = node.disabled || node.checked;
155
- return;
156
- }
157
- const { all, none, half, isEffectivelyChecked } = getChildState(
158
- node.childNodes
159
- );
160
- node.isEffectivelyChecked = isEffectivelyChecked;
161
- if (all) {
162
- node.checked = true;
163
- node.indeterminate = false;
164
- } else if (half) {
165
- node.checked = false;
166
- node.indeterminate = true;
167
- } else if (none) {
168
- node.checked = false;
169
- node.indeterminate = false;
170
- }
171
- const parent = node.parent;
172
- if (!parent || parent.level === 0)
173
- return;
174
- if (!node.store.checkStrictly) {
175
- reInitChecked(parent);
176
- }
177
- };
178
- const getPropertyFromData = function(node, prop) {
179
- const props = node.store.props;
180
- const data = node.data || {};
181
- const config = props[prop];
182
- if (isFunction(config)) {
183
- return config(data, node);
184
- } else if (isString(config)) {
185
- return data[config];
186
- } else if (isUndefined(config)) {
187
- const dataProp = data[prop];
188
- return isUndefined(dataProp) ? "" : dataProp;
189
- }
190
- };
191
- const setCanFocus = function(childNodes, focus) {
192
- childNodes.forEach((item) => {
193
- item.canFocus = focus;
194
- setCanFocus(item.childNodes, focus);
195
- });
196
- };
197
- let nodeIdSeed = 0;
198
- class Node {
199
- constructor(options) {
200
- this.isLeafByUser = void 0;
201
- this.isLeaf = void 0;
202
- this.isEffectivelyChecked = false;
203
- this.id = nodeIdSeed++;
204
- this.text = null;
205
- this.checked = false;
206
- this.indeterminate = false;
207
- this.data = null;
208
- this.expanded = false;
209
- this.parent = null;
210
- this.visible = true;
211
- this.isCurrent = false;
212
- this.canFocus = false;
213
- for (const name in options) {
214
- if (hasOwn(options, name)) {
215
- this[name] = options[name];
216
- }
217
- }
218
- this.level = 0;
219
- this.loaded = false;
220
- this.childNodes = [];
221
- this.loading = false;
222
- if (this.parent) {
223
- this.level = this.parent.level + 1;
224
- }
225
- }
226
- initialize() {
227
- var _a;
228
- const store = this.store;
229
- if (!store) {
230
- throw new Error("[Node]store is required!");
231
- }
232
- store.registerNode(this);
233
- const props = store.props;
234
- if (props && typeof props.isLeaf !== "undefined") {
235
- const isLeaf = getPropertyFromData(this, "isLeaf");
236
- if (isBoolean(isLeaf)) {
237
- this.isLeafByUser = isLeaf;
238
- }
239
- }
240
- if (store.lazy !== true && this.data) {
241
- this.setData(this.data);
242
- if (store.defaultExpandAll) {
243
- this.expanded = true;
244
- this.canFocus = true;
245
- }
246
- } else if (this.level > 0 && store.lazy && store.defaultExpandAll && !this.isLeafByUser) {
247
- this.expand();
248
- }
249
- if (!isArray(this.data)) {
250
- markNodeData(this, this.data);
251
- }
252
- if (!this.data)
253
- return;
254
- const defaultExpandedKeys = store.defaultExpandedKeys;
255
- const key = store.key;
256
- if (key && !isNil(this.key) && defaultExpandedKeys && defaultExpandedKeys.includes(this.key)) {
257
- this.expand(null, store.autoExpandParent);
258
- }
259
- if (key && store.currentNodeKey !== void 0 && this.key === store.currentNodeKey) {
260
- store.currentNode && (store.currentNode.isCurrent = false);
261
- store.currentNode = this;
262
- store.currentNode.isCurrent = true;
263
- }
264
- if (store.lazy) {
265
- store._initDefaultCheckedNode(this);
266
- }
267
- this.updateLeafState();
268
- if (this.level === 1 || ((_a = this.parent) == null ? void 0 : _a.expanded) === true)
269
- this.canFocus = true;
270
- }
271
- setData(data) {
272
- if (!isArray(data)) {
273
- markNodeData(this, data);
274
- }
275
- this.data = data;
276
- this.childNodes = [];
277
- let children;
278
- if (this.level === 0 && isArray(this.data)) {
279
- children = this.data;
280
- } else {
281
- children = getPropertyFromData(this, "children") || [];
282
- }
283
- for (let i = 0, j = children.length; i < j; i++) {
284
- this.insertChild({ data: children[i] });
285
- }
286
- }
287
- get label() {
288
- return getPropertyFromData(this, "label");
289
- }
290
- get key() {
291
- const nodeKey = this.store.key;
292
- if (this.data)
293
- return this.data[nodeKey];
294
- return null;
295
- }
296
- get disabled() {
297
- return getPropertyFromData(this, "disabled");
298
- }
299
- get nextSibling() {
300
- const parent = this.parent;
301
- if (parent) {
302
- const index = parent.childNodes.indexOf(this);
303
- if (index > -1) {
304
- return parent.childNodes[index + 1];
305
- }
306
- }
307
- return null;
308
- }
309
- get previousSibling() {
310
- const parent = this.parent;
311
- if (parent) {
312
- const index = parent.childNodes.indexOf(this);
313
- if (index > -1) {
314
- return index > 0 ? parent.childNodes[index - 1] : null;
315
- }
316
- }
317
- return null;
318
- }
319
- contains(target, deep = true) {
320
- return (this.childNodes || []).some(
321
- (child) => child === target || deep && child.contains(target)
322
- );
323
- }
324
- remove() {
325
- const parent = this.parent;
326
- if (parent) {
327
- parent.removeChild(this);
328
- }
329
- }
330
- insertChild(child, index, batch) {
331
- if (!child)
332
- throw new Error("InsertChild error: child is required.");
333
- if (!(child instanceof Node)) {
334
- if (!batch) {
335
- const children = this.getChildren(true);
336
- if (!(children == null ? void 0 : children.includes(child.data))) {
337
- if (isUndefined(index) || index < 0) {
338
- children == null ? void 0 : children.push(child.data);
339
- } else {
340
- children == null ? void 0 : children.splice(index, 0, child.data);
341
- }
342
- }
343
- }
344
- Object.assign(child, {
345
- parent: this,
346
- store: this.store
347
- });
348
- child = reactive(new Node(child));
349
- if (child instanceof Node) {
350
- child.initialize();
351
- }
352
- }
353
- child.level = this.level + 1;
354
- if (isUndefined(index) || index < 0) {
355
- this.childNodes.push(child);
356
- } else {
357
- this.childNodes.splice(index, 0, child);
358
- }
359
- this.updateLeafState();
360
- }
361
- insertBefore(child, ref) {
362
- let index;
363
- if (ref) {
364
- index = this.childNodes.indexOf(ref);
365
- }
366
- this.insertChild(child, index);
367
- }
368
- insertAfter(child, ref) {
369
- let index;
370
- if (ref) {
371
- index = this.childNodes.indexOf(ref);
372
- if (index !== -1)
373
- index += 1;
374
- }
375
- this.insertChild(child, index);
376
- }
377
- removeChild(child) {
378
- const children = this.getChildren() || [];
379
- const dataIndex = children.indexOf(child.data);
380
- if (dataIndex > -1) {
381
- children.splice(dataIndex, 1);
382
- }
383
- const index = this.childNodes.indexOf(child);
384
- if (index > -1) {
385
- this.store && this.store.deregisterNode(child);
386
- child.parent = null;
387
- this.childNodes.splice(index, 1);
388
- }
389
- this.updateLeafState();
390
- }
391
- removeChildByData(data) {
392
- const targetNode = this.childNodes.find((child) => child.data === data);
393
- if (targetNode) {
394
- this.removeChild(targetNode);
395
- }
396
- }
397
- expand(callback, expandParent) {
398
- const done = () => {
399
- if (expandParent) {
400
- let parent = this.parent;
401
- while (parent && parent.level > 0) {
402
- parent.expanded = true;
403
- parent = parent.parent;
404
- }
405
- }
406
- this.expanded = true;
407
- if (callback)
408
- callback();
409
- setCanFocus(this.childNodes, true);
410
- };
411
- if (this.shouldLoadData()) {
412
- this.loadData((data) => {
413
- if (isArray(data)) {
414
- if (this.checked) {
415
- this.setChecked(true, true);
416
- } else if (!this.store.checkStrictly) {
417
- reInitChecked(this);
418
- }
419
- done();
420
- }
421
- });
422
- } else {
423
- done();
424
- }
425
- }
426
- doCreateChildren(array, defaultProps = {}) {
427
- array.forEach((item) => {
428
- this.insertChild(
429
- Object.assign({ data: item }, defaultProps),
430
- void 0,
431
- true
432
- );
433
- });
434
- }
435
- collapse() {
436
- this.expanded = false;
437
- setCanFocus(this.childNodes, false);
438
- }
439
- shouldLoadData() {
440
- return Boolean(this.store.lazy === true && this.store.load && !this.loaded);
441
- }
442
- updateLeafState() {
443
- if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== "undefined") {
444
- this.isLeaf = this.isLeafByUser;
445
- this.isEffectivelyChecked = this.isLeaf && this.disabled;
446
- return;
447
- }
448
- const childNodes = this.childNodes;
449
- if (!this.store.lazy || this.store.lazy === true && this.loaded === true) {
450
- this.isLeaf = !childNodes || childNodes.length === 0;
451
- this.isEffectivelyChecked = this.isLeaf && this.disabled;
452
- return;
453
- }
454
- this.isLeaf = false;
455
- }
456
- setChecked(value, deep, recursion, passValue) {
457
- this.indeterminate = value === "half";
458
- this.checked = value === true;
459
- this.isEffectivelyChecked = !this.childNodes.length && (this.disabled || this.checked);
460
- if (this.store.checkStrictly)
461
- return;
462
- if (!(this.shouldLoadData() && !this.store.checkDescendants)) {
463
- const handleDescendants = () => {
464
- if (deep) {
465
- const childNodes = this.childNodes;
466
- for (let i = 0, j = childNodes.length; i < j; i++) {
467
- const child = childNodes[i];
468
- passValue = passValue || value !== false;
469
- const isCheck = child.disabled && child.isLeaf ? child.checked : passValue;
470
- child.setChecked(isCheck, deep, true, passValue);
471
- }
472
- const { half, all, isEffectivelyChecked } = getChildState(childNodes);
473
- if (!all) {
474
- this.checked = all;
475
- this.indeterminate = half;
476
- }
477
- this.isEffectivelyChecked = !this.childNodes.length ? this.disabled || this.checked : isEffectivelyChecked;
478
- }
479
- };
480
- if (this.shouldLoadData()) {
481
- this.loadData(
482
- () => {
483
- handleDescendants();
484
- reInitChecked(this);
485
- },
486
- {
487
- checked: value !== false
488
- }
489
- );
490
- return;
491
- } else {
492
- handleDescendants();
493
- }
494
- }
495
- const parent = this.parent;
496
- if (!parent || parent.level === 0)
497
- return;
498
- if (!recursion) {
499
- reInitChecked(parent);
500
- }
501
- }
502
- getChildren(forceInit = false) {
503
- if (this.level === 0)
504
- return this.data;
505
- const data = this.data;
506
- if (!data)
507
- return null;
508
- const props = this.store.props;
509
- let children = "children";
510
- if (props) {
511
- children = props.children || "children";
512
- }
513
- if (isUndefined(data[children])) {
514
- data[children] = null;
515
- }
516
- if (forceInit && !data[children]) {
517
- data[children] = [];
518
- }
519
- return data[children];
520
- }
521
- updateChildren() {
522
- const newData = this.getChildren() || [];
523
- const oldData = this.childNodes.map((node) => node.data);
524
- const newDataMap = {};
525
- const newNodes = [];
526
- newData.forEach((item, index) => {
527
- const key = item[NODE_KEY];
528
- const isNodeExists = !!key && oldData.some((data) => (data == null ? void 0 : data[NODE_KEY]) === key);
529
- if (isNodeExists) {
530
- newDataMap[key] = { index, data: item };
531
- } else {
532
- newNodes.push({ index, data: item });
533
- }
534
- });
535
- if (!this.store.lazy) {
536
- oldData.forEach((item) => {
537
- if (!newDataMap[item == null ? void 0 : item[NODE_KEY]])
538
- this.removeChildByData(item);
539
- });
540
- }
541
- newNodes.forEach(({ index, data }) => {
542
- this.insertChild({ data }, index);
543
- });
544
- this.updateLeafState();
545
- }
546
- loadData(callback, defaultProps = {}) {
547
- if (this.store.lazy === true && this.store.load && !this.loaded && (!this.loading || Object.keys(defaultProps).length)) {
548
- this.loading = true;
549
- const resolve = (children) => {
550
- this.childNodes = [];
551
- this.doCreateChildren(children, defaultProps);
552
- this.loaded = true;
553
- this.loading = false;
554
- this.updateLeafState();
555
- if (callback) {
556
- callback.call(this, children);
557
- }
558
- };
559
- const reject = () => {
560
- this.loading = false;
561
- };
562
- this.store.load(this, resolve, reject);
563
- } else {
564
- if (callback) {
565
- callback.call(this);
566
- }
567
- }
568
- }
569
- eachNode(callback) {
570
- const arr = [this];
571
- while (arr.length) {
572
- const node = arr.shift();
573
- arr.unshift(...node.childNodes);
574
- callback(node);
575
- }
576
- }
577
- reInitChecked() {
578
- if (this.store.checkStrictly)
579
- return;
580
- reInitChecked(this);
581
- }
582
- }
583
-
584
- class TreeStore {
585
- constructor(options) {
586
- this.lazy = false;
587
- this.checkStrictly = false;
588
- this.autoExpandParent = false;
589
- this.defaultExpandAll = false;
590
- this.checkDescendants = false;
591
- this.currentNode = null;
592
- this.currentNodeKey = null;
593
- for (const option in options) {
594
- if (hasOwn(options, option)) {
595
- this[option] = options[option];
596
- }
597
- }
598
- this.nodesMap = {};
599
- }
600
- initialize() {
601
- this.root = new Node({
602
- data: this.data,
603
- store: this
604
- });
605
- this.root.initialize();
606
- if (this.lazy && this.load) {
607
- const loadFn = this.load;
608
- loadFn(
609
- this.root,
610
- (data) => {
611
- this.root.doCreateChildren(data);
612
- this._initDefaultCheckedNodes();
613
- },
614
- NOOP
615
- );
616
- } else {
617
- this._initDefaultCheckedNodes();
618
- }
619
- }
620
- filter(value) {
621
- const filterNodeMethod = this.filterNodeMethod;
622
- const lazy = this.lazy;
623
- const traverse = async function(node) {
624
- const childNodes = node.root ? node.root.childNodes : node.childNodes;
625
- for (const [index, child] of childNodes.entries()) {
626
- child.visible = !!(filterNodeMethod == null ? void 0 : filterNodeMethod.call(
627
- child,
628
- value,
629
- child.data,
630
- child
631
- ));
632
- if (index % 80 === 0 && index > 0) {
633
- await nextTick();
634
- }
635
- await traverse(child);
636
- }
637
- if (!node.visible && childNodes.length) {
638
- let allHidden = true;
639
- allHidden = !childNodes.some((child) => child.visible);
640
- if (node.root) {
641
- node.root.visible = allHidden === false;
642
- } else {
643
- node.visible = allHidden === false;
644
- }
645
- }
646
- if (!value)
647
- return;
648
- if (node.visible && !node.isLeaf) {
649
- if (!lazy || node.loaded) {
650
- node.expand();
651
- }
652
- }
653
- };
654
- traverse(this);
655
- }
656
- setData(newVal) {
657
- const instanceChanged = newVal !== this.root.data;
658
- if (instanceChanged) {
659
- this.nodesMap = {};
660
- this.root.setData(newVal);
661
- this._initDefaultCheckedNodes();
662
- this.setCurrentNodeKey(this.currentNodeKey);
663
- } else {
664
- this.root.updateChildren();
665
- }
666
- }
667
- getNode(data) {
668
- if (data instanceof Node)
669
- return data;
670
- const key = isObject(data) ? getNodeKey(this.key, data) : data;
671
- return this.nodesMap[key] || null;
672
- }
673
- insertBefore(data, refData) {
674
- var _a;
675
- const refNode = this.getNode(refData);
676
- (_a = refNode.parent) == null ? void 0 : _a.insertBefore({ data }, refNode);
677
- }
678
- insertAfter(data, refData) {
679
- var _a;
680
- const refNode = this.getNode(refData);
681
- (_a = refNode.parent) == null ? void 0 : _a.insertAfter({ data }, refNode);
682
- }
683
- remove(data) {
684
- const node = this.getNode(data);
685
- if (node && node.parent) {
686
- if (node === this.currentNode) {
687
- this.currentNode = null;
688
- }
689
- node.parent.removeChild(node);
690
- }
691
- }
692
- append(data, parentData) {
693
- const parentNode = !isPropAbsent(parentData) ? this.getNode(parentData) : this.root;
694
- if (parentNode) {
695
- parentNode.insertChild({ data });
696
- }
697
- }
698
- _initDefaultCheckedNodes() {
699
- const defaultCheckedKeys = this.defaultCheckedKeys || [];
700
- const nodesMap = this.nodesMap;
701
- defaultCheckedKeys.forEach((checkedKey) => {
702
- const node = nodesMap[checkedKey];
703
- if (node) {
704
- node.setChecked(true, !this.checkStrictly);
705
- }
706
- });
707
- }
708
- _initDefaultCheckedNode(node) {
709
- const defaultCheckedKeys = this.defaultCheckedKeys || [];
710
- if (!isNil(node.key) && defaultCheckedKeys.includes(node.key)) {
711
- node.setChecked(true, !this.checkStrictly);
712
- }
713
- }
714
- setDefaultCheckedKey(newVal) {
715
- if (newVal !== this.defaultCheckedKeys) {
716
- this.defaultCheckedKeys = newVal;
717
- this._initDefaultCheckedNodes();
718
- }
719
- }
720
- registerNode(node) {
721
- const key = this.key;
722
- if (!node || !node.data)
723
- return;
724
- if (!key) {
725
- this.nodesMap[node.id] = node;
726
- } else {
727
- const nodeKey = node.key;
728
- if (!isNil(nodeKey))
729
- this.nodesMap[nodeKey] = node;
730
- }
731
- }
732
- deregisterNode(node) {
733
- const key = this.key;
734
- if (!key || !node || !node.data)
735
- return;
736
- node.childNodes.forEach((child) => {
737
- this.deregisterNode(child);
738
- });
739
- delete this.nodesMap[node.key];
740
- }
741
- getCheckedNodes(leafOnly = false, includeHalfChecked = false) {
742
- const checkedNodes = [];
743
- const traverse = function(node) {
744
- const childNodes = node.root ? node.root.childNodes : node.childNodes;
745
- childNodes.forEach((child) => {
746
- if ((child.checked || includeHalfChecked && child.indeterminate) && (!leafOnly || leafOnly && child.isLeaf)) {
747
- checkedNodes.push(child.data);
748
- }
749
- traverse(child);
750
- });
751
- };
752
- traverse(this);
753
- return checkedNodes;
754
- }
755
- getCheckedKeys(leafOnly = false) {
756
- return this.getCheckedNodes(leafOnly).map((data) => (data || {})[this.key]);
757
- }
758
- getHalfCheckedNodes() {
759
- const nodes = [];
760
- const traverse = function(node) {
761
- const childNodes = node.root ? node.root.childNodes : node.childNodes;
762
- childNodes.forEach((child) => {
763
- if (child.indeterminate) {
764
- nodes.push(child.data);
765
- }
766
- traverse(child);
767
- });
768
- };
769
- traverse(this);
770
- return nodes;
771
- }
772
- getHalfCheckedKeys() {
773
- return this.getHalfCheckedNodes().map((data) => (data || {})[this.key]);
774
- }
775
- _getAllNodes() {
776
- const allNodes = [];
777
- const nodesMap = this.nodesMap;
778
- for (const nodeKey in nodesMap) {
779
- if (hasOwn(nodesMap, nodeKey)) {
780
- allNodes.push(nodesMap[nodeKey]);
781
- }
782
- }
783
- return allNodes;
784
- }
785
- updateChildren(key, data) {
786
- const node = this.nodesMap[key];
787
- if (!node)
788
- return;
789
- const childNodes = node.childNodes;
790
- for (let i = childNodes.length - 1; i >= 0; i--) {
791
- const child = childNodes[i];
792
- this.remove(child.data);
793
- }
794
- for (let i = 0, j = data.length; i < j; i++) {
795
- const child = data[i];
796
- this.append(child, node.data);
797
- }
798
- }
799
- _setCheckedKeys(key, leafOnly = false, checkedKeys) {
800
- const allNodes = this._getAllNodes().sort((a, b) => a.level - b.level);
801
- const cache = /* @__PURE__ */ Object.create(null);
802
- const keys = Object.keys(checkedKeys);
803
- allNodes.forEach((node) => node.setChecked(false, false));
804
- const cacheCheckedChild = (node) => {
805
- node.childNodes.forEach((child) => {
806
- var _a;
807
- cache[child.data[key]] = true;
808
- if ((_a = child.childNodes) == null ? void 0 : _a.length) {
809
- cacheCheckedChild(child);
810
- }
811
- });
812
- };
813
- for (let i = 0, j = allNodes.length; i < j; i++) {
814
- const node = allNodes[i];
815
- const nodeKey = node.data[key].toString();
816
- const checked = keys.includes(nodeKey);
817
- if (!checked) {
818
- if (node.checked && !cache[nodeKey]) {
819
- node.setChecked(false, false);
820
- }
821
- continue;
822
- }
823
- if (node.childNodes.length) {
824
- cacheCheckedChild(node);
825
- }
826
- if (node.isLeaf || this.checkStrictly) {
827
- node.setChecked(true, false);
828
- continue;
829
- }
830
- node.setChecked(true, true);
831
- if (leafOnly) {
832
- node.setChecked(false, false);
833
- const traverse = function(node2) {
834
- const childNodes = node2.childNodes;
835
- childNodes.forEach((child) => {
836
- if (!child.isLeaf) {
837
- child.setChecked(false, false);
838
- }
839
- traverse(child);
840
- });
841
- };
842
- traverse(node);
843
- }
844
- }
845
- }
846
- setCheckedNodes(array, leafOnly = false) {
847
- const key = this.key;
848
- const checkedKeys = {};
849
- array.forEach((item) => {
850
- checkedKeys[(item || {})[key]] = true;
851
- });
852
- this._setCheckedKeys(key, leafOnly, checkedKeys);
853
- }
854
- setCheckedKeys(keys, leafOnly = false) {
855
- this.defaultCheckedKeys = keys;
856
- const key = this.key;
857
- const checkedKeys = {};
858
- keys.forEach((key2) => {
859
- checkedKeys[key2] = true;
860
- });
861
- this._setCheckedKeys(key, leafOnly, checkedKeys);
862
- }
863
- setDefaultExpandedKeys(keys) {
864
- keys = keys || [];
865
- this.defaultExpandedKeys = keys;
866
- keys.forEach((key) => {
867
- const node = this.getNode(key);
868
- if (node)
869
- node.expand(null, this.autoExpandParent);
870
- });
871
- }
872
- setChecked(data, checked, deep) {
873
- const node = this.getNode(data);
874
- if (node) {
875
- node.setChecked(!!checked, deep);
876
- }
877
- }
878
- getCurrentNode() {
879
- return this.currentNode;
880
- }
881
- setCurrentNode(currentNode) {
882
- const prevCurrentNode = this.currentNode;
883
- if (prevCurrentNode) {
884
- prevCurrentNode.isCurrent = false;
885
- }
886
- this.currentNode = currentNode;
887
- this.currentNode.isCurrent = true;
888
- }
889
- setUserCurrentNode(node, shouldAutoExpandParent = true) {
890
- var _a;
891
- const key = node[this.key];
892
- const currNode = this.nodesMap[key];
893
- this.setCurrentNode(currNode);
894
- if (shouldAutoExpandParent && this.currentNode && this.currentNode.level > 1) {
895
- (_a = this.currentNode.parent) == null ? void 0 : _a.expand(null, true);
896
- }
897
- }
898
- setCurrentNodeKey(key, shouldAutoExpandParent = true) {
899
- var _a;
900
- this.currentNodeKey = key;
901
- if (isPropAbsent(key)) {
902
- this.currentNode && (this.currentNode.isCurrent = false);
903
- this.currentNode = null;
904
- return;
905
- }
906
- const node = this.getNode(key);
907
- if (node) {
908
- this.setCurrentNode(node);
909
- if (shouldAutoExpandParent && this.currentNode && this.currentNode.level > 1) {
910
- (_a = this.currentNode.parent) == null ? void 0 : _a.expand(null, true);
911
- }
912
- }
913
- }
914
- }
915
-
916
- const ROOT_TREE_INJECTION_KEY = "RootTree";
917
- const NODE_INSTANCE_INJECTION_KEY = "NodeInstance";
918
- const TREE_NODE_MAP_INJECTION_KEY = "TreeNodeMap";
919
-
920
- const _sfc_main$2 = defineComponent({
921
- name: "ElTreeNodeContent",
922
- props: {
923
- node: {
924
- type: Object,
925
- required: true
926
- },
927
- renderContent: Function
928
- },
929
- setup(props) {
930
- const ns = useNamespace("tree");
931
- const nodeInstance = inject(
932
- NODE_INSTANCE_INJECTION_KEY
933
- );
934
- const tree = inject(ROOT_TREE_INJECTION_KEY);
935
- return () => {
936
- const node = props.node;
937
- const { data, store } = node;
938
- return props.renderContent ? props.renderContent(h, { _self: nodeInstance, node, data, store }) : renderSlot(tree.ctx.slots, "default", { node, data }, () => [
939
- h(
940
- ElText,
941
- { tag: "span", truncated: true, class: ns.be("node", "label") },
942
- () => [node.label]
943
- )
944
- ]);
945
- };
946
- }
947
- });
948
- var NodeContent = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__file", "/home/runner/work/element-plus/element-plus/packages/components/tree/src/tree-node-content.vue"]]);
949
-
950
- function useNodeExpandEventBroadcast(props) {
951
- const parentNodeMap = inject(
952
- TREE_NODE_MAP_INJECTION_KEY,
953
- null
954
- );
955
- let currentNodeMap = {
956
- treeNodeExpand: (node) => {
957
- var _a;
958
- if (props.node !== node) {
959
- (_a = props.node) == null ? void 0 : _a.collapse();
960
- }
961
- },
962
- children: /* @__PURE__ */ new Set()
963
- };
964
- if (parentNodeMap) {
965
- parentNodeMap.children.add(currentNodeMap);
966
- }
967
- onBeforeUnmount(() => {
968
- if (parentNodeMap) {
969
- parentNodeMap.children.delete(currentNodeMap);
970
- }
971
- currentNodeMap = null;
972
- });
973
- provide(TREE_NODE_MAP_INJECTION_KEY, currentNodeMap);
974
- return {
975
- broadcastExpanded: (node) => {
976
- if (!props.accordion)
977
- return;
978
- for (const childNode of currentNodeMap.children) {
979
- childNode.treeNodeExpand(node);
980
- }
981
- }
982
- };
983
- }
984
-
985
- const dragEventsKey = Symbol("dragEvents");
986
- function useDragNodeHandler({
987
- props,
988
- ctx,
989
- el$,
990
- dropIndicator$,
991
- store
992
- }) {
993
- const ns = useNamespace("tree");
994
- const dragState = ref({
995
- showDropIndicator: false,
996
- draggingNode: null,
997
- dropNode: null,
998
- allowDrop: true,
999
- dropType: null
1000
- });
1001
- const treeNodeDragStart = ({ event, treeNode }) => {
1002
- if (!event.dataTransfer)
1003
- return;
1004
- if (isFunction(props.allowDrag) && !props.allowDrag(treeNode.node)) {
1005
- event.preventDefault();
1006
- return false;
1007
- }
1008
- event.dataTransfer.effectAllowed = "move";
1009
- try {
1010
- event.dataTransfer.setData("text/plain", "");
1011
- } catch (e) {
1012
- }
1013
- dragState.value.draggingNode = treeNode;
1014
- ctx.emit("node-drag-start", treeNode.node, event);
1015
- };
1016
- const treeNodeDragOver = ({ event, treeNode }) => {
1017
- if (!event.dataTransfer)
1018
- return;
1019
- const dropNode = treeNode;
1020
- const oldDropNode = dragState.value.dropNode;
1021
- if (oldDropNode && oldDropNode.node.id !== dropNode.node.id) {
1022
- removeClass(oldDropNode.$el, ns.is("drop-inner"));
1023
- }
1024
- const draggingNode = dragState.value.draggingNode;
1025
- if (!draggingNode || !dropNode)
1026
- return;
1027
- let dropPrev = true;
1028
- let dropInner = true;
1029
- let dropNext = true;
1030
- let userAllowDropInner = true;
1031
- if (isFunction(props.allowDrop)) {
1032
- dropPrev = props.allowDrop(draggingNode.node, dropNode.node, "prev");
1033
- userAllowDropInner = dropInner = props.allowDrop(
1034
- draggingNode.node,
1035
- dropNode.node,
1036
- "inner"
1037
- );
1038
- dropNext = props.allowDrop(draggingNode.node, dropNode.node, "next");
1039
- }
1040
- event.dataTransfer.dropEffect = dropInner || dropPrev || dropNext ? "move" : "none";
1041
- if ((dropPrev || dropInner || dropNext) && (oldDropNode == null ? void 0 : oldDropNode.node.id) !== dropNode.node.id) {
1042
- if (oldDropNode) {
1043
- ctx.emit("node-drag-leave", draggingNode.node, oldDropNode.node, event);
1044
- }
1045
- ctx.emit("node-drag-enter", draggingNode.node, dropNode.node, event);
1046
- }
1047
- if (dropPrev || dropInner || dropNext) {
1048
- dragState.value.dropNode = dropNode;
1049
- } else {
1050
- dragState.value.dropNode = null;
1051
- }
1052
- if (dropNode.node.nextSibling === draggingNode.node) {
1053
- dropNext = false;
1054
- }
1055
- if (dropNode.node.previousSibling === draggingNode.node) {
1056
- dropPrev = false;
1057
- }
1058
- if (dropNode.node.contains(draggingNode.node, false)) {
1059
- dropInner = false;
1060
- }
1061
- if (draggingNode.node === dropNode.node || draggingNode.node.contains(dropNode.node)) {
1062
- dropPrev = false;
1063
- dropInner = false;
1064
- dropNext = false;
1065
- }
1066
- const dropEl = dropNode.$el;
1067
- const targetPosition = dropEl.querySelector(`.${ns.be("node", "content")}`).getBoundingClientRect();
1068
- const treePosition = el$.value.getBoundingClientRect();
1069
- const treeScrollTop = el$.value.scrollTop;
1070
- let dropType;
1071
- const prevPercent = dropPrev ? dropInner ? 0.25 : dropNext ? 0.45 : 1 : Number.NEGATIVE_INFINITY;
1072
- const nextPercent = dropNext ? dropInner ? 0.75 : dropPrev ? 0.55 : 0 : Number.POSITIVE_INFINITY;
1073
- let indicatorTop = -9999;
1074
- const distance = event.clientY - targetPosition.top;
1075
- if (distance < targetPosition.height * prevPercent) {
1076
- dropType = "before";
1077
- } else if (distance > targetPosition.height * nextPercent) {
1078
- dropType = "after";
1079
- } else if (dropInner) {
1080
- dropType = "inner";
1081
- } else {
1082
- dropType = "none";
1083
- }
1084
- const iconPosition = dropEl.querySelector(`.${ns.be("node", "expand-icon")}`).getBoundingClientRect();
1085
- const dropIndicator = dropIndicator$.value;
1086
- if (dropType === "before") {
1087
- indicatorTop = iconPosition.top - treePosition.top + treeScrollTop;
1088
- } else if (dropType === "after") {
1089
- indicatorTop = iconPosition.bottom - treePosition.top + treeScrollTop;
1090
- }
1091
- dropIndicator.style.top = `${indicatorTop}px`;
1092
- dropIndicator.style.left = `${iconPosition.right - treePosition.left}px`;
1093
- if (dropType === "inner") {
1094
- addClass(dropEl, ns.is("drop-inner"));
1095
- } else {
1096
- removeClass(dropEl, ns.is("drop-inner"));
1097
- }
1098
- dragState.value.showDropIndicator = dropType === "before" || dropType === "after";
1099
- dragState.value.allowDrop = dragState.value.showDropIndicator || userAllowDropInner;
1100
- dragState.value.dropType = dropType;
1101
- ctx.emit("node-drag-over", draggingNode.node, dropNode.node, event);
1102
- };
1103
- const treeNodeDragEnd = (event) => {
1104
- var _a, _b;
1105
- const { draggingNode, dropType, dropNode } = dragState.value;
1106
- event.preventDefault();
1107
- if (event.dataTransfer) {
1108
- event.dataTransfer.dropEffect = "move";
1109
- }
1110
- if ((draggingNode == null ? void 0 : draggingNode.node.data) && dropNode) {
1111
- const draggingNodeCopy = { data: draggingNode.node.data };
1112
- if (dropType !== "none") {
1113
- draggingNode.node.remove();
1114
- }
1115
- if (dropType === "before") {
1116
- (_a = dropNode.node.parent) == null ? void 0 : _a.insertBefore(draggingNodeCopy, dropNode.node);
1117
- } else if (dropType === "after") {
1118
- (_b = dropNode.node.parent) == null ? void 0 : _b.insertAfter(draggingNodeCopy, dropNode.node);
1119
- } else if (dropType === "inner") {
1120
- dropNode.node.insertChild(draggingNodeCopy);
1121
- }
1122
- if (dropType !== "none") {
1123
- store.value.registerNode(draggingNodeCopy);
1124
- if (store.value.key) {
1125
- draggingNode.node.eachNode((node) => {
1126
- var _a2;
1127
- (_a2 = store.value.nodesMap[node.data[store.value.key]]) == null ? void 0 : _a2.setChecked(
1128
- node.checked,
1129
- !store.value.checkStrictly
1130
- );
1131
- });
1132
- }
1133
- }
1134
- removeClass(dropNode.$el, ns.is("drop-inner"));
1135
- ctx.emit(
1136
- "node-drag-end",
1137
- draggingNode.node,
1138
- dropNode.node,
1139
- dropType,
1140
- event
1141
- );
1142
- if (dropType !== "none") {
1143
- ctx.emit(
1144
- "node-drop",
1145
- draggingNode.node,
1146
- dropNode.node,
1147
- dropType,
1148
- event
1149
- );
1150
- }
1151
- }
1152
- if (draggingNode && !dropNode) {
1153
- ctx.emit("node-drag-end", draggingNode.node, null, dropType, event);
1154
- }
1155
- dragState.value.showDropIndicator = false;
1156
- dragState.value.draggingNode = null;
1157
- dragState.value.dropNode = null;
1158
- dragState.value.allowDrop = true;
1159
- };
1160
- provide(dragEventsKey, {
1161
- treeNodeDragStart,
1162
- treeNodeDragOver,
1163
- treeNodeDragEnd
1164
- });
1165
- return {
1166
- dragState
1167
- };
1168
- }
1169
-
1170
- const _sfc_main$1 = defineComponent({
1171
- name: "ElTreeNode",
1172
- components: {
1173
- ElCollapseTransition,
1174
- ElCheckbox,
1175
- NodeContent,
1176
- ElIcon,
1177
- Loading
1178
- },
1179
- props: {
1180
- node: {
1181
- type: Node,
1182
- default: () => ({})
1183
- },
1184
- props: {
1185
- type: Object,
1186
- default: () => ({})
1187
- },
1188
- accordion: Boolean,
1189
- renderContent: Function,
1190
- renderAfterExpand: Boolean,
1191
- showCheckbox: Boolean
1192
- },
1193
- emits: ["node-expand"],
1194
- setup(props, ctx) {
1195
- const ns = useNamespace("tree");
1196
- const { broadcastExpanded } = useNodeExpandEventBroadcast(props);
1197
- const tree = inject(ROOT_TREE_INJECTION_KEY);
1198
- const expanded = ref(false);
1199
- const childNodeRendered = ref(false);
1200
- const oldChecked = ref();
1201
- const oldIndeterminate = ref();
1202
- const node$ = ref();
1203
- const dragEvents = inject(dragEventsKey);
1204
- const instance = getCurrentInstance();
1205
- provide(NODE_INSTANCE_INJECTION_KEY, instance);
1206
- if (!tree) {
1207
- debugWarn("Tree", "Can not find node's tree.");
1208
- }
1209
- if (props.node.expanded) {
1210
- expanded.value = true;
1211
- childNodeRendered.value = true;
1212
- }
1213
- const childrenKey = tree.props.props["children"] || "children";
1214
- watch(
1215
- () => {
1216
- var _a;
1217
- const children = (_a = props.node.data) == null ? void 0 : _a[childrenKey];
1218
- return children && [...children];
1219
- },
1220
- () => {
1221
- props.node.updateChildren();
1222
- }
1223
- );
1224
- watch(
1225
- () => props.node.indeterminate,
1226
- (val) => {
1227
- handleSelectChange(props.node.checked, val);
1228
- }
1229
- );
1230
- watch(
1231
- () => props.node.checked,
1232
- (val) => {
1233
- handleSelectChange(val, props.node.indeterminate);
1234
- }
1235
- );
1236
- watch(
1237
- () => props.node.childNodes.length,
1238
- () => props.node.reInitChecked()
1239
- );
1240
- watch(
1241
- () => props.node.expanded,
1242
- (val) => {
1243
- nextTick(() => expanded.value = val);
1244
- if (val) {
1245
- childNodeRendered.value = true;
1246
- }
1247
- }
1248
- );
1249
- const getNodeKey$1 = (node) => {
1250
- return getNodeKey(tree.props.nodeKey, node.data);
1251
- };
1252
- const getNodeClass = (node) => {
1253
- const nodeClassFunc = props.props.class;
1254
- if (!nodeClassFunc) {
1255
- return {};
1256
- }
1257
- let className;
1258
- if (isFunction(nodeClassFunc)) {
1259
- const { data } = node;
1260
- className = nodeClassFunc(data, node);
1261
- } else {
1262
- className = nodeClassFunc;
1263
- }
1264
- if (isString(className)) {
1265
- return { [className]: true };
1266
- } else {
1267
- return className;
1268
- }
1269
- };
1270
- const handleSelectChange = (checked, indeterminate) => {
1271
- if (oldChecked.value !== checked || oldIndeterminate.value !== indeterminate) {
1272
- tree.ctx.emit("check-change", props.node.data, checked, indeterminate);
1273
- }
1274
- oldChecked.value = checked;
1275
- oldIndeterminate.value = indeterminate;
1276
- };
1277
- const handleClick = (e) => {
1278
- handleCurrentChange(tree.store, tree.ctx.emit, () => {
1279
- var _a;
1280
- const nodeKeyProp = (_a = tree == null ? void 0 : tree.props) == null ? void 0 : _a.nodeKey;
1281
- if (nodeKeyProp) {
1282
- const curNodeKey = getNodeKey$1(props.node);
1283
- tree.store.value.setCurrentNodeKey(curNodeKey);
1284
- } else {
1285
- tree.store.value.setCurrentNode(props.node);
1286
- }
1287
- });
1288
- tree.currentNode.value = props.node;
1289
- if (tree.props.expandOnClickNode) {
1290
- handleExpandIconClick();
1291
- }
1292
- if ((tree.props.checkOnClickNode || props.node.isLeaf && tree.props.checkOnClickLeaf && props.showCheckbox) && !props.node.disabled) {
1293
- handleCheckChange(!props.node.checked);
1294
- }
1295
- tree.ctx.emit("node-click", props.node.data, props.node, instance, e);
1296
- };
1297
- const handleContextMenu = (event) => {
1298
- var _a;
1299
- if ((_a = tree.instance.vnode.props) == null ? void 0 : _a["onNodeContextmenu"]) {
1300
- event.stopPropagation();
1301
- event.preventDefault();
1302
- }
1303
- tree.ctx.emit(
1304
- "node-contextmenu",
1305
- event,
1306
- props.node.data,
1307
- props.node,
1308
- instance
1309
- );
1310
- };
1311
- const handleExpandIconClick = () => {
1312
- if (props.node.isLeaf)
1313
- return;
1314
- if (expanded.value) {
1315
- tree.ctx.emit("node-collapse", props.node.data, props.node, instance);
1316
- props.node.collapse();
1317
- } else {
1318
- props.node.expand(() => {
1319
- ctx.emit("node-expand", props.node.data, props.node, instance);
1320
- });
1321
- }
1322
- };
1323
- const handleCheckChange = (value) => {
1324
- const checkStrictly = tree == null ? void 0 : tree.props.checkStrictly;
1325
- const childNodes = props.node.childNodes;
1326
- if (!checkStrictly && childNodes.length) {
1327
- value = childNodes.some((node) => !node.isEffectivelyChecked);
1328
- }
1329
- props.node.setChecked(value, !checkStrictly);
1330
- nextTick(() => {
1331
- const store = tree.store.value;
1332
- tree.ctx.emit("check", props.node.data, {
1333
- checkedNodes: store.getCheckedNodes(),
1334
- checkedKeys: store.getCheckedKeys(),
1335
- halfCheckedNodes: store.getHalfCheckedNodes(),
1336
- halfCheckedKeys: store.getHalfCheckedKeys()
1337
- });
1338
- });
1339
- };
1340
- const handleChildNodeExpand = (nodeData, node, instance2) => {
1341
- broadcastExpanded(node);
1342
- tree.ctx.emit("node-expand", nodeData, node, instance2);
1343
- };
1344
- const handleDragStart = (event) => {
1345
- if (!tree.props.draggable)
1346
- return;
1347
- dragEvents.treeNodeDragStart({ event, treeNode: props });
1348
- };
1349
- const handleDragOver = (event) => {
1350
- event.preventDefault();
1351
- if (!tree.props.draggable)
1352
- return;
1353
- dragEvents.treeNodeDragOver({
1354
- event,
1355
- treeNode: { $el: node$.value, node: props.node }
1356
- });
1357
- };
1358
- const handleDrop = (event) => {
1359
- event.preventDefault();
1360
- };
1361
- const handleDragEnd = (event) => {
1362
- if (!tree.props.draggable)
1363
- return;
1364
- dragEvents.treeNodeDragEnd(event);
1365
- };
1366
- return {
1367
- ns,
1368
- node$,
1369
- tree,
1370
- expanded,
1371
- childNodeRendered,
1372
- oldChecked,
1373
- oldIndeterminate,
1374
- getNodeKey: getNodeKey$1,
1375
- getNodeClass,
1376
- handleSelectChange,
1377
- handleClick,
1378
- handleContextMenu,
1379
- handleExpandIconClick,
1380
- handleCheckChange,
1381
- handleChildNodeExpand,
1382
- handleDragStart,
1383
- handleDragOver,
1384
- handleDrop,
1385
- handleDragEnd,
1386
- CaretRight
1387
- };
1388
- }
1389
- });
1390
- const _hoisted_1 = ["aria-expanded", "aria-disabled", "aria-checked", "draggable", "data-key"];
1391
- const _hoisted_2 = ["aria-expanded"];
1392
- function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
1393
- const _component_el_icon = resolveComponent("el-icon");
1394
- const _component_el_checkbox = resolveComponent("el-checkbox");
1395
- const _component_loading = resolveComponent("loading");
1396
- const _component_node_content = resolveComponent("node-content");
1397
- const _component_el_tree_node = resolveComponent("el-tree-node");
1398
- const _component_el_collapse_transition = resolveComponent("el-collapse-transition");
1399
- return withDirectives((openBlock(), createElementBlock("div", {
1400
- ref: "node$",
1401
- class: normalizeClass([
1402
- _ctx.ns.b("node"),
1403
- _ctx.ns.is("expanded", _ctx.expanded),
1404
- _ctx.ns.is("current", _ctx.node.isCurrent),
1405
- _ctx.ns.is("hidden", !_ctx.node.visible),
1406
- _ctx.ns.is("focusable", !_ctx.node.disabled),
1407
- _ctx.ns.is("checked", !_ctx.node.disabled && _ctx.node.checked),
1408
- _ctx.getNodeClass(_ctx.node)
1409
- ]),
1410
- role: "treeitem",
1411
- tabindex: "-1",
1412
- "aria-expanded": _ctx.expanded,
1413
- "aria-disabled": _ctx.node.disabled,
1414
- "aria-checked": _ctx.node.checked,
1415
- draggable: _ctx.tree.props.draggable,
1416
- "data-key": _ctx.getNodeKey(_ctx.node),
1417
- onClick: _cache[2] || (_cache[2] = withModifiers((...args) => _ctx.handleClick && _ctx.handleClick(...args), ["stop"])),
1418
- onContextmenu: _cache[3] || (_cache[3] = (...args) => _ctx.handleContextMenu && _ctx.handleContextMenu(...args)),
1419
- onDragstart: _cache[4] || (_cache[4] = withModifiers((...args) => _ctx.handleDragStart && _ctx.handleDragStart(...args), ["stop"])),
1420
- onDragover: _cache[5] || (_cache[5] = withModifiers((...args) => _ctx.handleDragOver && _ctx.handleDragOver(...args), ["stop"])),
1421
- onDragend: _cache[6] || (_cache[6] = withModifiers((...args) => _ctx.handleDragEnd && _ctx.handleDragEnd(...args), ["stop"])),
1422
- onDrop: _cache[7] || (_cache[7] = withModifiers((...args) => _ctx.handleDrop && _ctx.handleDrop(...args), ["stop"]))
1423
- }, [
1424
- createElementVNode(
1425
- "div",
1426
- {
1427
- class: normalizeClass(_ctx.ns.be("node", "content")),
1428
- style: normalizeStyle({ paddingLeft: (_ctx.node.level - 1) * _ctx.tree.props.indent + "px" })
1429
- },
1430
- [
1431
- _ctx.tree.props.icon || _ctx.CaretRight ? (openBlock(), createBlock(_component_el_icon, {
1432
- key: 0,
1433
- class: normalizeClass([
1434
- _ctx.ns.be("node", "expand-icon"),
1435
- _ctx.ns.is("leaf", _ctx.node.isLeaf),
1436
- {
1437
- expanded: !_ctx.node.isLeaf && _ctx.expanded
1438
- }
1439
- ]),
1440
- onClick: withModifiers(_ctx.handleExpandIconClick, ["stop"])
1441
- }, {
1442
- default: withCtx(() => [
1443
- (openBlock(), createBlock(resolveDynamicComponent(_ctx.tree.props.icon || _ctx.CaretRight)))
1444
- ]),
1445
- _: 1
1446
- }, 8, ["class", "onClick"])) : createCommentVNode("v-if", true),
1447
- _ctx.showCheckbox ? (openBlock(), createBlock(_component_el_checkbox, {
1448
- key: 1,
1449
- "model-value": _ctx.node.checked,
1450
- indeterminate: _ctx.node.indeterminate,
1451
- disabled: !!_ctx.node.disabled,
1452
- onClick: _cache[0] || (_cache[0] = withModifiers(() => {
1453
- }, ["stop"])),
1454
- onChange: _ctx.handleCheckChange
1455
- }, null, 8, ["model-value", "indeterminate", "disabled", "onChange"])) : createCommentVNode("v-if", true),
1456
- _ctx.node.loading ? (openBlock(), createBlock(_component_el_icon, {
1457
- key: 2,
1458
- class: normalizeClass([_ctx.ns.be("node", "loading-icon"), _ctx.ns.is("loading")])
1459
- }, {
1460
- default: withCtx(() => [
1461
- createVNode(_component_loading)
1462
- ]),
1463
- _: 1
1464
- }, 8, ["class"])) : createCommentVNode("v-if", true),
1465
- createVNode(_component_node_content, {
1466
- node: _ctx.node,
1467
- "render-content": _ctx.renderContent
1468
- }, null, 8, ["node", "render-content"])
1469
- ],
1470
- 6
1471
- ),
1472
- createVNode(_component_el_collapse_transition, null, {
1473
- default: withCtx(() => [
1474
- !_ctx.renderAfterExpand || _ctx.childNodeRendered ? withDirectives((openBlock(), createElementBlock("div", {
1475
- key: 0,
1476
- class: normalizeClass(_ctx.ns.be("node", "children")),
1477
- role: "group",
1478
- "aria-expanded": _ctx.expanded,
1479
- onClick: _cache[1] || (_cache[1] = withModifiers(() => {
1480
- }, ["stop"]))
1481
- }, [
1482
- (openBlock(true), createElementBlock(
1483
- Fragment,
1484
- null,
1485
- renderList(_ctx.node.childNodes, (child) => {
1486
- return openBlock(), createBlock(_component_el_tree_node, {
1487
- key: _ctx.getNodeKey(child),
1488
- "render-content": _ctx.renderContent,
1489
- "render-after-expand": _ctx.renderAfterExpand,
1490
- "show-checkbox": _ctx.showCheckbox,
1491
- node: child,
1492
- accordion: _ctx.accordion,
1493
- props: _ctx.props,
1494
- onNodeExpand: _ctx.handleChildNodeExpand
1495
- }, null, 8, ["render-content", "render-after-expand", "show-checkbox", "node", "accordion", "props", "onNodeExpand"]);
1496
- }),
1497
- 128
1498
- ))
1499
- ], 10, _hoisted_2)), [
1500
- [vShow, _ctx.expanded]
1501
- ]) : createCommentVNode("v-if", true)
1502
- ]),
1503
- _: 1
1504
- })
1505
- ], 42, _hoisted_1)), [
1506
- [vShow, _ctx.node.visible]
1507
- ]);
1508
- }
1509
- var ElTreeNode = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__file", "/home/runner/work/element-plus/element-plus/packages/components/tree/src/tree-node.vue"]]);
1510
-
1511
- function useKeydown({ el$ }, store) {
1512
- const ns = useNamespace("tree");
1513
- onMounted(() => {
1514
- initTabIndex();
1515
- });
1516
- onUpdated(() => {
1517
- var _a;
1518
- (_a = el$.value) == null ? void 0 : _a.querySelectorAll("input[type=checkbox]").forEach((checkbox) => {
1519
- checkbox.setAttribute("tabindex", "-1");
1520
- });
1521
- });
1522
- function canNodeFocus(treeItems, nextIndex) {
1523
- var _a, _b;
1524
- const currentNode = store.value.getNode(treeItems[nextIndex].dataset.key);
1525
- return currentNode.canFocus && currentNode.visible && (((_a = currentNode.parent) == null ? void 0 : _a.expanded) || ((_b = currentNode.parent) == null ? void 0 : _b.level) === 0);
1526
- }
1527
- const handleKeydown = (ev) => {
1528
- const currentItem = ev.target;
1529
- if (!currentItem.className.includes(ns.b("node")))
1530
- return;
1531
- const code = getEventCode(ev);
1532
- const treeItems = Array.from(
1533
- el$.value.querySelectorAll(`.${ns.is("focusable")}[role=treeitem]`)
1534
- );
1535
- const currentIndex = treeItems.indexOf(currentItem);
1536
- let nextIndex;
1537
- if ([EVENT_CODE.up, EVENT_CODE.down].includes(code)) {
1538
- ev.preventDefault();
1539
- if (code === EVENT_CODE.up) {
1540
- nextIndex = currentIndex === -1 ? 0 : currentIndex !== 0 ? currentIndex - 1 : treeItems.length - 1;
1541
- const startIndex = nextIndex;
1542
- while (true) {
1543
- if (canNodeFocus(treeItems, nextIndex)) {
1544
- break;
1545
- }
1546
- nextIndex--;
1547
- if (nextIndex === startIndex) {
1548
- nextIndex = -1;
1549
- break;
1550
- }
1551
- if (nextIndex < 0) {
1552
- nextIndex = treeItems.length - 1;
1553
- }
1554
- }
1555
- } else {
1556
- nextIndex = currentIndex === -1 ? 0 : currentIndex < treeItems.length - 1 ? currentIndex + 1 : 0;
1557
- const startIndex = nextIndex;
1558
- while (true) {
1559
- if (canNodeFocus(treeItems, nextIndex)) {
1560
- break;
1561
- }
1562
- nextIndex++;
1563
- if (nextIndex === startIndex) {
1564
- nextIndex = -1;
1565
- break;
1566
- }
1567
- if (nextIndex >= treeItems.length) {
1568
- nextIndex = 0;
1569
- }
1570
- }
1571
- }
1572
- nextIndex !== -1 && treeItems[nextIndex].focus();
1573
- }
1574
- if ([EVENT_CODE.left, EVENT_CODE.right].includes(code)) {
1575
- ev.preventDefault();
1576
- currentItem.click();
1577
- }
1578
- const hasInput = currentItem.querySelector(
1579
- '[type="checkbox"]'
1580
- );
1581
- if ([EVENT_CODE.enter, EVENT_CODE.numpadEnter, EVENT_CODE.space].includes(
1582
- code
1583
- ) && hasInput) {
1584
- ev.preventDefault();
1585
- hasInput.click();
1586
- }
1587
- };
1588
- useEventListener(el$, "keydown", handleKeydown);
1589
- const initTabIndex = () => {
1590
- var _a;
1591
- if (!el$.value)
1592
- return;
1593
- const treeItems = Array.from(
1594
- el$.value.querySelectorAll(`.${ns.is("focusable")}[role=treeitem]`)
1595
- );
1596
- const checkboxItems = Array.from(
1597
- el$.value.querySelectorAll("input[type=checkbox]")
1598
- );
1599
- checkboxItems.forEach((checkbox) => {
1600
- checkbox.setAttribute("tabindex", "-1");
1601
- });
1602
- const checkedItem = el$.value.querySelectorAll(
1603
- `.${ns.is("checked")}[role=treeitem]`
1604
- );
1605
- if (checkedItem.length) {
1606
- checkedItem[0].setAttribute("tabindex", "0");
1607
- return;
1608
- }
1609
- (_a = treeItems[0]) == null ? void 0 : _a.setAttribute("tabindex", "0");
1610
- };
1611
- }
1612
-
1613
- const treeProps = buildProps({
1614
- data: {
1615
- type: definePropType(Array),
1616
- default: () => []
1617
- },
1618
- emptyText: {
1619
- type: String
1620
- },
1621
- renderAfterExpand: {
1622
- type: Boolean,
1623
- default: true
1624
- },
1625
- nodeKey: String,
1626
- checkStrictly: Boolean,
1627
- defaultExpandAll: Boolean,
1628
- expandOnClickNode: {
1629
- type: Boolean,
1630
- default: true
1631
- },
1632
- checkOnClickNode: Boolean,
1633
- checkOnClickLeaf: {
1634
- type: Boolean,
1635
- default: true
1636
- },
1637
- checkDescendants: Boolean,
1638
- autoExpandParent: {
1639
- type: Boolean,
1640
- default: true
1641
- },
1642
- defaultCheckedKeys: {
1643
- type: Array
1644
- },
1645
- defaultExpandedKeys: {
1646
- type: Array
1647
- },
1648
- currentNodeKey: {
1649
- type: [String, Number]
1650
- },
1651
- renderContent: {
1652
- type: definePropType(Function)
1653
- },
1654
- showCheckbox: Boolean,
1655
- draggable: Boolean,
1656
- allowDrag: {
1657
- type: definePropType(Function)
1658
- },
1659
- allowDrop: {
1660
- type: definePropType(Function)
1661
- },
1662
- props: {
1663
- type: Object,
1664
- default: () => ({
1665
- children: "children",
1666
- label: "label",
1667
- disabled: "disabled"
1668
- })
1669
- },
1670
- lazy: Boolean,
1671
- highlightCurrent: Boolean,
1672
- load: {
1673
- type: Function
1674
- },
1675
- filterNodeMethod: {
1676
- type: Function
1677
- },
1678
- accordion: Boolean,
1679
- indent: {
1680
- type: Number,
1681
- default: 18
1682
- },
1683
- icon: {
1684
- type: iconPropType
1685
- }
1686
- });
1687
- const treeEmits = {
1688
- "check-change": (data, checked, indeterminate) => data && isBoolean(checked) && isBoolean(indeterminate),
1689
- "current-change": (data, node) => true,
1690
- "node-click": (data, node, nodeInstance, evt) => data && node && evt instanceof Event,
1691
- "node-contextmenu": (evt, data, node, nodeInstance) => evt instanceof Event && data && node,
1692
- "node-collapse": (data, node, nodeInstance) => data && node,
1693
- "node-expand": (data, node, nodeInstance) => data && node,
1694
- check: (data, checkedInfo) => data && checkedInfo,
1695
- "node-drag-start": (node, evt) => node && evt,
1696
- "node-drag-end": (draggingNode, dropNode, dropType, evt) => draggingNode && evt,
1697
- "node-drop": (draggingNode, dropNode, dropType, evt) => draggingNode && dropNode && evt,
1698
- "node-drag-leave": (draggingNode, oldDropNode, evt) => draggingNode && oldDropNode && evt,
1699
- "node-drag-enter": (draggingNode, dropNode, evt) => draggingNode && dropNode && evt,
1700
- "node-drag-over": (draggingNode, dropNode, evt) => draggingNode && dropNode && evt
1701
- };
1702
-
1703
- const _sfc_main = defineComponent({
1704
- name: "ElTree",
1705
- components: { ElTreeNode },
1706
- props: treeProps,
1707
- emits: treeEmits,
1708
- setup(props, ctx) {
1709
- const { t } = useLocale();
1710
- const ns = useNamespace("tree");
1711
- const store = ref(
1712
- new TreeStore({
1713
- key: props.nodeKey,
1714
- data: props.data,
1715
- lazy: props.lazy,
1716
- props: props.props,
1717
- load: props.load,
1718
- currentNodeKey: props.currentNodeKey,
1719
- checkStrictly: props.checkStrictly,
1720
- checkDescendants: props.checkDescendants,
1721
- defaultCheckedKeys: props.defaultCheckedKeys,
1722
- defaultExpandedKeys: props.defaultExpandedKeys,
1723
- autoExpandParent: props.autoExpandParent,
1724
- defaultExpandAll: props.defaultExpandAll,
1725
- filterNodeMethod: props.filterNodeMethod
1726
- })
1727
- );
1728
- store.value.initialize();
1729
- const root = ref(store.value.root);
1730
- const currentNode = ref(null);
1731
- const el$ = ref(null);
1732
- const dropIndicator$ = ref(null);
1733
- const { broadcastExpanded } = useNodeExpandEventBroadcast(props);
1734
- const { dragState } = useDragNodeHandler({
1735
- props,
1736
- ctx,
1737
- el$,
1738
- dropIndicator$,
1739
- store
1740
- });
1741
- useKeydown({ el$ }, store);
1742
- const instance = getCurrentInstance();
1743
- const isSelectTree = computed(() => {
1744
- let parent = instance == null ? void 0 : instance.parent;
1745
- while (parent) {
1746
- if (parent.type.name === "ElTreeSelect") {
1747
- return true;
1748
- }
1749
- parent = parent.parent;
1750
- }
1751
- return false;
1752
- });
1753
- const isEmpty = computed(() => {
1754
- const { childNodes } = root.value;
1755
- return (!childNodes || childNodes.length === 0 || childNodes.every(({ visible }) => !visible)) && !isSelectTree.value;
1756
- });
1757
- watch(
1758
- () => props.currentNodeKey,
1759
- (newVal) => {
1760
- store.value.setCurrentNodeKey(newVal != null ? newVal : null);
1761
- }
1762
- );
1763
- watch(
1764
- () => props.defaultCheckedKeys,
1765
- (newVal, oldVal) => {
1766
- if (isEqual(newVal, oldVal))
1767
- return;
1768
- store.value.setDefaultCheckedKey(newVal != null ? newVal : []);
1769
- }
1770
- );
1771
- watch(
1772
- () => props.defaultExpandedKeys,
1773
- (newVal) => {
1774
- store.value.setDefaultExpandedKeys(newVal != null ? newVal : []);
1775
- }
1776
- );
1777
- watch(
1778
- () => props.data,
1779
- (newVal) => {
1780
- store.value.setData(newVal);
1781
- },
1782
- { deep: true }
1783
- );
1784
- watch(
1785
- () => props.checkStrictly,
1786
- (newVal) => {
1787
- store.value.checkStrictly = newVal;
1788
- }
1789
- );
1790
- const filter = (value) => {
1791
- if (!props.filterNodeMethod)
1792
- throw new Error("[Tree] filterNodeMethod is required when filter");
1793
- store.value.filter(value);
1794
- };
1795
- const getNodeKey$1 = (node) => {
1796
- return getNodeKey(props.nodeKey, node.data);
1797
- };
1798
- const requireNodeKey = (methodName) => {
1799
- if (!props.nodeKey) {
1800
- throw new Error(`[Tree] nodeKey is required in ${methodName}`);
1801
- }
1802
- };
1803
- const getNodePath = (data) => {
1804
- requireNodeKey("getNodePath");
1805
- const node = store.value.getNode(data);
1806
- if (!node)
1807
- return [];
1808
- const path = [node.data];
1809
- let parent = node.parent;
1810
- while (parent && parent !== root.value) {
1811
- path.push(parent.data);
1812
- parent = parent.parent;
1813
- }
1814
- return path.reverse();
1815
- };
1816
- const getCheckedNodes = (leafOnly, includeHalfChecked) => {
1817
- return store.value.getCheckedNodes(leafOnly, includeHalfChecked);
1818
- };
1819
- const getCheckedKeys = (leafOnly) => {
1820
- return store.value.getCheckedKeys(leafOnly);
1821
- };
1822
- const getCurrentNode = () => {
1823
- const currentNode2 = store.value.getCurrentNode();
1824
- return currentNode2 ? currentNode2.data : null;
1825
- };
1826
- const getCurrentKey = () => {
1827
- requireNodeKey("getCurrentKey");
1828
- const currentNode2 = getCurrentNode();
1829
- return currentNode2 ? currentNode2[props.nodeKey] : null;
1830
- };
1831
- const setCheckedNodes = (nodes, leafOnly) => {
1832
- requireNodeKey("setCheckedNodes");
1833
- store.value.setCheckedNodes(nodes, leafOnly);
1834
- };
1835
- const setCheckedKeys = (keys, leafOnly) => {
1836
- requireNodeKey("setCheckedKeys");
1837
- store.value.setCheckedKeys(keys, leafOnly);
1838
- };
1839
- const setChecked = (data, checked, deep) => {
1840
- store.value.setChecked(data, checked, deep);
1841
- };
1842
- const getHalfCheckedNodes = () => {
1843
- return store.value.getHalfCheckedNodes();
1844
- };
1845
- const getHalfCheckedKeys = () => {
1846
- return store.value.getHalfCheckedKeys();
1847
- };
1848
- const setCurrentNode = (node, shouldAutoExpandParent = true) => {
1849
- requireNodeKey("setCurrentNode");
1850
- handleCurrentChange(store, ctx.emit, () => {
1851
- broadcastExpanded(node);
1852
- store.value.setUserCurrentNode(node, shouldAutoExpandParent);
1853
- });
1854
- };
1855
- const setCurrentKey = (key = null, shouldAutoExpandParent = true) => {
1856
- requireNodeKey("setCurrentKey");
1857
- handleCurrentChange(store, ctx.emit, () => {
1858
- broadcastExpanded();
1859
- store.value.setCurrentNodeKey(key, shouldAutoExpandParent);
1860
- });
1861
- };
1862
- const getNode = (data) => {
1863
- return store.value.getNode(data);
1864
- };
1865
- const remove = (data) => {
1866
- store.value.remove(data);
1867
- };
1868
- const append = (data, parentNode) => {
1869
- store.value.append(data, parentNode);
1870
- };
1871
- const insertBefore = (data, refNode) => {
1872
- store.value.insertBefore(data, refNode);
1873
- };
1874
- const insertAfter = (data, refNode) => {
1875
- store.value.insertAfter(data, refNode);
1876
- };
1877
- const handleNodeExpand = (nodeData, node, instance2) => {
1878
- broadcastExpanded(node);
1879
- ctx.emit("node-expand", nodeData, node, instance2);
1880
- };
1881
- const updateKeyChildren = (key, data) => {
1882
- requireNodeKey("updateKeyChild");
1883
- store.value.updateChildren(key, data);
1884
- };
1885
- provide(ROOT_TREE_INJECTION_KEY, {
1886
- ctx,
1887
- props,
1888
- store,
1889
- root,
1890
- currentNode,
1891
- instance
1892
- });
1893
- provide(formItemContextKey, void 0);
1894
- return {
1895
- ns,
1896
- store,
1897
- root,
1898
- currentNode,
1899
- dragState,
1900
- el$,
1901
- dropIndicator$,
1902
- isEmpty,
1903
- filter,
1904
- getNodeKey: getNodeKey$1,
1905
- getNodePath,
1906
- getCheckedNodes,
1907
- getCheckedKeys,
1908
- getCurrentNode,
1909
- getCurrentKey,
1910
- setCheckedNodes,
1911
- setCheckedKeys,
1912
- setChecked,
1913
- getHalfCheckedNodes,
1914
- getHalfCheckedKeys,
1915
- setCurrentNode,
1916
- setCurrentKey,
1917
- t,
1918
- getNode,
1919
- remove,
1920
- append,
1921
- insertBefore,
1922
- insertAfter,
1923
- handleNodeExpand,
1924
- updateKeyChildren
1925
- };
1926
- }
1927
- });
1928
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
1929
- const _component_el_tree_node = resolveComponent("el-tree-node");
1930
- return openBlock(), createElementBlock(
1931
- "div",
1932
- {
1933
- ref: "el$",
1934
- class: normalizeClass([
1935
- _ctx.ns.b(),
1936
- _ctx.ns.is("dragging", !!_ctx.dragState.draggingNode),
1937
- _ctx.ns.is("drop-not-allow", !_ctx.dragState.allowDrop),
1938
- _ctx.ns.is("drop-inner", _ctx.dragState.dropType === "inner"),
1939
- { [_ctx.ns.m("highlight-current")]: _ctx.highlightCurrent }
1940
- ]),
1941
- role: "tree"
1942
- },
1943
- [
1944
- (openBlock(true), createElementBlock(
1945
- Fragment,
1946
- null,
1947
- renderList(_ctx.root.childNodes, (child) => {
1948
- return openBlock(), createBlock(_component_el_tree_node, {
1949
- key: _ctx.getNodeKey(child),
1950
- node: child,
1951
- props: _ctx.props,
1952
- accordion: _ctx.accordion,
1953
- "render-after-expand": _ctx.renderAfterExpand,
1954
- "show-checkbox": _ctx.showCheckbox,
1955
- "render-content": _ctx.renderContent,
1956
- onNodeExpand: _ctx.handleNodeExpand
1957
- }, null, 8, ["node", "props", "accordion", "render-after-expand", "show-checkbox", "render-content", "onNodeExpand"]);
1958
- }),
1959
- 128
1960
- )),
1961
- _ctx.isEmpty ? (openBlock(), createElementBlock(
1962
- "div",
1963
- {
1964
- key: 0,
1965
- class: normalizeClass(_ctx.ns.e("empty-block"))
1966
- },
1967
- [
1968
- renderSlot(_ctx.$slots, "empty", {}, () => {
1969
- var _a;
1970
- return [
1971
- createElementVNode(
1972
- "span",
1973
- {
1974
- class: normalizeClass(_ctx.ns.e("empty-text"))
1975
- },
1976
- toDisplayString((_a = _ctx.emptyText) != null ? _a : _ctx.t("el.tree.emptyText")),
1977
- 3
1978
- )
1979
- ];
1980
- })
1981
- ],
1982
- 2
1983
- )) : createCommentVNode("v-if", true),
1984
- withDirectives(createElementVNode(
1985
- "div",
1986
- {
1987
- ref: "dropIndicator$",
1988
- class: normalizeClass(_ctx.ns.e("drop-indicator"))
1989
- },
1990
- null,
1991
- 2
1992
- ), [
1993
- [vShow, _ctx.dragState.showDropIndicator]
1994
- ])
1995
- ],
1996
- 2
1997
- );
1998
- }
1999
- var Tree = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/element-plus/element-plus/packages/components/tree/src/tree.vue"]]);
2000
-
2001
- const ElTree = withInstall(Tree);
2002
-
2003
- export { ElTree as E };