vue-devui 1.0.0-rc.16 → 1.0.0-rc.17

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 (69) hide show
  1. package/README.md +2 -0
  2. package/auto-complete/index.es.js +3 -1
  3. package/auto-complete/index.umd.js +1 -1
  4. package/auto-complete/style.css +1 -1
  5. package/button/style.css +1 -1
  6. package/checkbox/index.es.js +3 -1
  7. package/checkbox/index.umd.js +1 -1
  8. package/date-picker-pro/index.es.js +16 -12
  9. package/date-picker-pro/index.umd.js +9 -9
  10. package/date-picker-pro/style.css +1 -1
  11. package/drawer/index.es.js +1 -1
  12. package/drawer/index.umd.js +1 -1
  13. package/dropdown/index.es.js +2 -9
  14. package/dropdown/index.umd.js +1 -1
  15. package/editable-select/style.css +1 -1
  16. package/form/index.es.js +3 -1
  17. package/form/index.umd.js +1 -1
  18. package/input/index.es.js +3 -1
  19. package/input/index.umd.js +4 -4
  20. package/loading/style.css +1 -1
  21. package/mention/index.d.ts +7 -0
  22. package/mention/index.es.js +8326 -0
  23. package/mention/index.umd.js +47 -0
  24. package/mention/package.json +7 -0
  25. package/mention/style.css +1 -0
  26. package/menu/index.d.ts +7 -0
  27. package/menu/index.es.js +927 -0
  28. package/menu/index.umd.js +1 -0
  29. package/menu/package.json +7 -0
  30. package/menu/style.css +1 -0
  31. package/message/index.es.js +0 -1
  32. package/message/index.umd.js +1 -1
  33. package/message/style.css +1 -1
  34. package/modal/index.es.js +3 -1
  35. package/modal/index.umd.js +1 -1
  36. package/nuxt/components/Mention.js +3 -0
  37. package/nuxt/components/Menu.js +3 -0
  38. package/nuxt/components/MenuItem.js +3 -0
  39. package/nuxt/components/SubMenu.js +3 -0
  40. package/nuxt/components/mentionProps.js +3 -0
  41. package/nuxt/components/treeNodeProps.js +3 -0
  42. package/package.json +2 -2
  43. package/popover/index.es.js +3 -1
  44. package/popover/index.umd.js +6 -6
  45. package/radio/index.es.js +3 -1
  46. package/radio/index.umd.js +7 -7
  47. package/search/index.es.js +3 -1
  48. package/search/index.umd.js +8 -8
  49. package/select/index.es.js +3 -1
  50. package/select/index.umd.js +1 -1
  51. package/style.css +1 -1
  52. package/switch/index.es.js +3 -1
  53. package/switch/index.umd.js +1 -1
  54. package/switch/style.css +1 -1
  55. package/table/index.es.js +9 -11
  56. package/table/index.umd.js +3 -3
  57. package/table/style.css +1 -1
  58. package/textarea/index.es.js +5 -2
  59. package/textarea/index.umd.js +16 -16
  60. package/time-picker/index.es.js +3 -1
  61. package/time-picker/index.umd.js +1 -1
  62. package/time-picker/style.css +1 -1
  63. package/time-select/index.es.js +3 -1
  64. package/time-select/index.umd.js +5 -5
  65. package/tree/index.es.js +11097 -9839
  66. package/tree/index.umd.js +27 -27
  67. package/tree/style.css +1 -1
  68. package/vue-devui.es.js +11745 -9417
  69. package/vue-devui.umd.js +29 -28
@@ -0,0 +1,927 @@
1
+ import { ref, defineComponent, getCurrentInstance, inject, toRefs, computed, createVNode, watch, onMounted, Transition, withDirectives, vShow, watchEffect, provide, reactive } from "vue";
2
+ function createBem(namespace, element, modifier) {
3
+ let cls = namespace;
4
+ if (element) {
5
+ cls += `__${element}`;
6
+ }
7
+ if (modifier) {
8
+ cls += `--${modifier}`;
9
+ }
10
+ return cls;
11
+ }
12
+ function useNamespace(block, needDot = false) {
13
+ const namespace = needDot ? `.devui-${block}` : `devui-${block}`;
14
+ const b = () => createBem(namespace);
15
+ const e = (element) => element ? createBem(namespace, element) : "";
16
+ const m = (modifier) => modifier ? createBem(namespace, "", modifier) : "";
17
+ const em = (element, modifier) => element && modifier ? createBem(namespace, element, modifier) : "";
18
+ return {
19
+ b,
20
+ e,
21
+ m,
22
+ em
23
+ };
24
+ }
25
+ const elements = [];
26
+ let parents = [];
27
+ const defaultIndent = ref(24);
28
+ const ns$5 = useNamespace("menu");
29
+ const subNs$2 = useNamespace("submenu");
30
+ const menuClass = ns$5.b();
31
+ const menuItemHorizontalWrapper = `${ns$5.b()}-item-horizontal-wrapper`;
32
+ const menuItemSelect$1 = `${ns$5.b()}-item-select`;
33
+ const menuActiveParent = `${ns$5.b()}-active-parent`;
34
+ function setDefaultIndent(indent) {
35
+ defaultIndent.value = indent;
36
+ }
37
+ function pushElement(element) {
38
+ elements.push(element);
39
+ }
40
+ function addLayer() {
41
+ parents = [];
42
+ elements.forEach((val) => {
43
+ parents.push(val.el.parentElement);
44
+ });
45
+ const stack = [...parents];
46
+ const getLayerFromClass = (className) => {
47
+ var _a;
48
+ return (_a = /layer_(\d*)/gim.exec(className)) == null ? void 0 : _a[1];
49
+ };
50
+ while (stack.length) {
51
+ const shiftItem = stack.shift();
52
+ if (shiftItem == null ? void 0 : shiftItem.classList.contains(menuClass)) {
53
+ const children = shiftItem.children;
54
+ stack.unshift(...Array.from(children));
55
+ continue;
56
+ } else {
57
+ if (shiftItem.tagName === "DIV") {
58
+ if (shiftItem.classList.contains(`${ns$5.b()}-item-vertical-wrapper`) || shiftItem.classList.contains(`${subNs$2.b()}-menu-item-vertical-wrapper`)) {
59
+ const parent = shiftItem.parentElement;
60
+ stack.unshift(...Array.from(shiftItem.children));
61
+ if (parent == null ? void 0 : parent.classList.contains(menuClass)) {
62
+ shiftItem.classList.add("layer_1");
63
+ } else {
64
+ let layer = getLayerFromClass((parent == null ? void 0 : parent.classList.value) || "");
65
+ layer = Number(layer);
66
+ shiftItem.classList.add(`layer_${layer}`);
67
+ }
68
+ } else {
69
+ const parent = shiftItem.parentElement;
70
+ let layer = getLayerFromClass((parent == null ? void 0 : parent.classList.value) || "");
71
+ layer = Number(layer);
72
+ shiftItem.classList.add(`layer_${layer}`);
73
+ shiftItem.style.paddingLeft = `${(layer === 2 ? 1 : layer - 1) * defaultIndent.value}px`;
74
+ }
75
+ }
76
+ if (shiftItem.tagName === "UL") {
77
+ const parent = shiftItem.parentElement;
78
+ const children = shiftItem.children;
79
+ for (let i = 0; i < children.length; i++) {
80
+ stack.unshift(children[i]);
81
+ }
82
+ const classList = (parent == null ? void 0 : parent.classList.value) || "";
83
+ let layer = getLayerFromClass(classList);
84
+ if (parent == null ? void 0 : parent.classList.contains(menuClass)) {
85
+ layer = 1;
86
+ shiftItem.classList.add(`layer_${2}`);
87
+ } else {
88
+ shiftItem.classList.add(`layer_${Number(layer) + 1}`);
89
+ layer = Number(layer) + 1;
90
+ }
91
+ }
92
+ if (shiftItem.tagName === "LI") {
93
+ const parent = shiftItem.parentElement;
94
+ const parentClassList = (parent == null ? void 0 : parent.classList.value) || "";
95
+ let layer = getLayerFromClass(parentClassList);
96
+ getLayerFromClass(parentClassList);
97
+ layer = Number(layer);
98
+ shiftItem.style.padding = `0 ${layer * defaultIndent.value}px`;
99
+ }
100
+ }
101
+ }
102
+ }
103
+ function getRoot(path) {
104
+ var _a;
105
+ const paths = path;
106
+ let rootElement = null;
107
+ for (let i = 0; i < paths.length; i++) {
108
+ const p = paths[i];
109
+ if ((_a = p == null ? void 0 : p.classList) == null ? void 0 : _a.contains(`${ns$5.b()}-horizontal`)) {
110
+ rootElement = p;
111
+ }
112
+ }
113
+ return rootElement;
114
+ }
115
+ function clearSelect_isHorizontal(ele, event) {
116
+ let element = event.target;
117
+ let stack = [];
118
+ const { path } = event;
119
+ const root = getRoot(path);
120
+ stack = [...Array.from(root.children)];
121
+ if (element.tagName === "SPAN") {
122
+ element = element.parentElement;
123
+ }
124
+ while (stack.length) {
125
+ const shiftItem = stack.shift();
126
+ if ((shiftItem == null ? void 0 : shiftItem.tagName) === "UL" || (shiftItem == null ? void 0 : shiftItem.classList.contains(menuItemHorizontalWrapper))) {
127
+ const children = shiftItem == null ? void 0 : shiftItem.children;
128
+ stack.unshift(...Array.from(children));
129
+ }
130
+ if (shiftItem !== element) {
131
+ shiftItem == null ? void 0 : shiftItem.classList.remove(menuItemSelect$1);
132
+ shiftItem == null ? void 0 : shiftItem.classList.remove(menuActiveParent);
133
+ }
134
+ }
135
+ }
136
+ function clearSelect_notHorizontal(ele, event) {
137
+ const stack = [];
138
+ const path = event.path || event.composedPath && event.composedPath();
139
+ for (let i = 0; i < path.length; i++) {
140
+ const e = path[i];
141
+ if (!e.classList.contains(menuClass)) {
142
+ stack.push(...Array.from(e.children));
143
+ } else {
144
+ stack.push(...Array.from(e.children));
145
+ break;
146
+ }
147
+ }
148
+ while (stack.length) {
149
+ const shiftItem = stack.shift();
150
+ if ((shiftItem == null ? void 0 : shiftItem.tagName) === "UL" || (shiftItem == null ? void 0 : shiftItem.classList.contains(menuItemHorizontalWrapper))) {
151
+ stack.push(...Array.from(shiftItem == null ? void 0 : shiftItem.children));
152
+ }
153
+ if (shiftItem !== ele) {
154
+ if ((shiftItem == null ? void 0 : shiftItem.tagName) === "DIV") {
155
+ stack.unshift(...Array.from(shiftItem == null ? void 0 : shiftItem.children));
156
+ }
157
+ shiftItem == null ? void 0 : shiftItem.classList.remove(menuItemSelect$1);
158
+ shiftItem == null ? void 0 : shiftItem.classList.remove(menuActiveParent);
159
+ }
160
+ }
161
+ }
162
+ function clearSelect(ele, event, isHorizontal = false) {
163
+ if (isHorizontal) {
164
+ clearSelect_isHorizontal(ele, event);
165
+ } else {
166
+ clearSelect_notHorizontal(ele, event);
167
+ }
168
+ }
169
+ function getLayer(el) {
170
+ var _a;
171
+ const getLayerReg = /layer_(\d{1,})/gim;
172
+ const className = el.className;
173
+ return (_a = getLayerReg.exec(className)) == null ? void 0 : _a[1];
174
+ }
175
+ const menuItemProps = {
176
+ disabled: {
177
+ type: Boolean,
178
+ default: false
179
+ },
180
+ href: {
181
+ type: String,
182
+ default: ""
183
+ },
184
+ route: {
185
+ type: [String, Object]
186
+ }
187
+ };
188
+ const ns$4 = useNamespace("menu");
189
+ function initSelect(defaultSelectKeys, keys, isMultiple, disabled) {
190
+ const isSelect = ref(false);
191
+ if (!isMultiple) {
192
+ if (defaultSelectKeys[0] === keys && !disabled.value) {
193
+ isSelect.value = true;
194
+ } else {
195
+ isSelect.value = false;
196
+ }
197
+ } else {
198
+ if (defaultSelectKeys.includes(keys)) {
199
+ isSelect.value = true;
200
+ } else {
201
+ isSelect.value = false;
202
+ }
203
+ }
204
+ return isSelect.value;
205
+ }
206
+ function addActiveParent(ele) {
207
+ var _a, _b;
208
+ let cur = ele.parentElement;
209
+ while (!cur.classList.contains(ns$4.b())) {
210
+ if (((_a = cur.firstElementChild) == null ? void 0 : _a.tagName) === "DIV") {
211
+ (_b = cur == null ? void 0 : cur.firstElementChild) == null ? void 0 : _b.classList.add(`${ns$4.b()}-active-parent`);
212
+ }
213
+ cur = cur.parentElement;
214
+ }
215
+ return cur;
216
+ }
217
+ function changeRoute(props, router, useRouter, key) {
218
+ if (useRouter && router) {
219
+ const route = props.route || key;
220
+ const routerResult = router.push(route).then((res) => {
221
+ return res;
222
+ });
223
+ return { route, routerResult };
224
+ }
225
+ return void 0;
226
+ }
227
+ const ns$3 = useNamespace("menu");
228
+ function useClick(e) {
229
+ const paths = e.path;
230
+ for (let i = 0; i < paths.length; i++) {
231
+ const path = paths[i];
232
+ if (path.classList.contains(`${ns$3.b()}-horizontal`)) {
233
+ break;
234
+ } else if (path.classList.contains(`${ns$3.b()}-item-horizontal-wrapper`)) {
235
+ continue;
236
+ } else {
237
+ if (path.tagName !== "SPAN") {
238
+ path.classList.add(`${ns$3.b()}-item-select`);
239
+ }
240
+ }
241
+ }
242
+ }
243
+ const ns$2 = useNamespace("menu");
244
+ const menuItemSelect = `${ns$2.b()}-item-select`;
245
+ const menuItemDisabled = `${ns$2.b()}-item-disabled`;
246
+ var MenuItem = defineComponent({
247
+ name: "DMenuItem",
248
+ props: menuItemProps,
249
+ setup(props, ctx) {
250
+ var _a, _b;
251
+ const instance = getCurrentInstance();
252
+ const key = String(instance == null ? void 0 : instance.vnode.key);
253
+ const menuStore = inject("menuStore");
254
+ const mode = inject("mode");
255
+ const multiple = inject("multiple");
256
+ const indent = inject("defaultIndent");
257
+ const isCollapsed = inject("isCollapsed");
258
+ const defaultSelectKey = inject("defaultSelectKey");
259
+ const {
260
+ disabled
261
+ } = toRefs(props);
262
+ const isSelect = ref(initSelect(defaultSelectKey, key, multiple, disabled));
263
+ const isLayer1 = ref(true);
264
+ const rootMenuEmit = inject("rootMenuEmit");
265
+ const useRouter = inject("useRouter");
266
+ const router = instance == null ? void 0 : instance.appContext.config.globalProperties.$router;
267
+ const classObject = computed(() => ({
268
+ [`${ns$2.b()}-item`]: true,
269
+ [`${ns$2.b()}-item-isCollapsed`]: isCollapsed.value,
270
+ [menuItemSelect]: isSelect.value,
271
+ [menuItemDisabled]: disabled.value
272
+ }));
273
+ menuStore.on("menuItem:clear:select", () => {
274
+ isSelect.value = false;
275
+ });
276
+ const onClick = (e) => {
277
+ var _a2;
278
+ e.stopPropagation();
279
+ const ele = e.currentTarget;
280
+ let changeRouteResult = void 0;
281
+ props.disabled && e.preventDefault();
282
+ if (!props.disabled) {
283
+ if (!multiple) {
284
+ menuStore.emit("menuItem:clear:select");
285
+ clearSelect(ele, e, mode.value === "horizontal");
286
+ if (mode.value === "horizontal") {
287
+ useClick(e);
288
+ }
289
+ isSelect.value = true;
290
+ changeRouteResult = changeRoute(props, router, useRouter, key);
291
+ } else {
292
+ if (ele.classList.contains(menuItemSelect)) {
293
+ rootMenuEmit("deselect", {
294
+ type: "deselect",
295
+ key,
296
+ el: ele,
297
+ e
298
+ });
299
+ isSelect.value = false;
300
+ return;
301
+ } else {
302
+ isSelect.value = true;
303
+ ele.classList.add(menuItemSelect);
304
+ }
305
+ }
306
+ if (changeRouteResult === void 0) {
307
+ rootMenuEmit("select", {
308
+ type: "select",
309
+ key,
310
+ el: ele,
311
+ e
312
+ });
313
+ } else {
314
+ rootMenuEmit("select", {
315
+ type: "select",
316
+ key,
317
+ el: ele,
318
+ e,
319
+ route: changeRouteResult
320
+ });
321
+ }
322
+ }
323
+ if (mode.value === "vertical") {
324
+ const target = e.currentTarget;
325
+ addActiveParent(target);
326
+ }
327
+ if (mode.value === "horizontal") {
328
+ const ul = (_a2 = ele.parentElement) == null ? void 0 : _a2.parentElement;
329
+ ul == null ? void 0 : ul.classList.add(`${ns$2.b()}-active-parent`);
330
+ }
331
+ };
332
+ const icons = createVNode("span", {
333
+ "class": `${ns$2.b()}-icon`
334
+ }, [(_b = (_a = ctx.slots).icon) == null ? void 0 : _b.call(_a)]);
335
+ const menuItems = ref(null);
336
+ watch(disabled, () => {
337
+ if (!multiple) {
338
+ classObject.value[menuItemSelect] = false;
339
+ }
340
+ });
341
+ watch(() => defaultSelectKey, (n) => {
342
+ isSelect.value = initSelect(n, key, multiple, disabled);
343
+ classObject.value[menuItemSelect] = isSelect.value;
344
+ });
345
+ onMounted(() => {
346
+ var _a2, _b2;
347
+ let oldPadding = "";
348
+ const ele = menuItems.value;
349
+ if (mode.value === "vertical") {
350
+ if ((_b2 = (_a2 = ele.parentElement) == null ? void 0 : _a2.parentElement) == null ? void 0 : _b2.classList.contains(ns$2.b())) {
351
+ isLayer1.value = true;
352
+ if (isLayer1.value) {
353
+ ele.style.paddingRight = ``;
354
+ ele.style.paddingLeft = `${indent}px`;
355
+ }
356
+ watch(isCollapsed, (val) => {
357
+ if (val) {
358
+ if (ele.style.padding !== "0") {
359
+ oldPadding = ele.style.padding;
360
+ }
361
+ setTimeout(() => {
362
+ ele.style.padding = "0";
363
+ ele.style.width = "";
364
+ ele.style.textAlign = `center`;
365
+ }, 300);
366
+ ele.style.display = `block`;
367
+ } else {
368
+ ele.style.padding = `${oldPadding}`;
369
+ ele.style.textAlign = ``;
370
+ ele.style.display = `flex`;
371
+ }
372
+ });
373
+ } else {
374
+ isLayer1.value = false;
375
+ }
376
+ }
377
+ });
378
+ return () => {
379
+ return mode.value === "vertical" ? createVNode("div", {
380
+ "class": `${ns$2.b()}-item-vertical-wrapper`
381
+ }, [createVNode("li", {
382
+ "class": classObject.value,
383
+ "onClick": onClick,
384
+ "ref": menuItems
385
+ }, [ctx.slots.icon !== void 0 && icons, props.href === "" ? createVNode(Transition, {
386
+ "name": "fade"
387
+ }, {
388
+ default: () => {
389
+ var _a2, _b2;
390
+ return [withDirectives(createVNode("span", null, [(_b2 = (_a2 = ctx.slots).default) == null ? void 0 : _b2.call(_a2)]), [[vShow, !isCollapsed.value]])];
391
+ }
392
+ }) : createVNode("a", {
393
+ "href": props.href
394
+ }, [createVNode(Transition, {
395
+ "name": "fade"
396
+ }, {
397
+ default: () => {
398
+ var _a2, _b2;
399
+ return [(_b2 = (_a2 = ctx.slots).default) == null ? void 0 : _b2.call(_a2)];
400
+ }
401
+ })])])]) : createVNode("li", {
402
+ "class": classObject.value,
403
+ "onClick": onClick,
404
+ "ref": menuItems
405
+ }, [ctx.slots.icon !== void 0 && icons, props.href === "" ? createVNode(Transition, {
406
+ "name": "fade"
407
+ }, {
408
+ default: () => {
409
+ var _a2, _b2;
410
+ return [withDirectives(createVNode("span", null, [(_b2 = (_a2 = ctx.slots).default) == null ? void 0 : _b2.call(_a2)]), [[vShow, !isCollapsed.value]])];
411
+ }
412
+ }) : createVNode("a", {
413
+ "href": props.href
414
+ }, [createVNode(Transition, {
415
+ "name": "fade"
416
+ }, {
417
+ default: () => {
418
+ var _a2, _b2;
419
+ return [(_b2 = (_a2 = ctx.slots).default) == null ? void 0 : _b2.call(_a2)];
420
+ }
421
+ })])]);
422
+ };
423
+ }
424
+ });
425
+ function randomId(n = 8) {
426
+ const str = "abcdefghijklmnopqrstuvwxyz0123456789";
427
+ let result = "";
428
+ for (let i = 0; i < n; i++) {
429
+ result += str[parseInt((Math.random() * str.length).toString())];
430
+ }
431
+ return result;
432
+ }
433
+ function useNearestMenuElement(ele) {
434
+ while (ele && ele.tagName !== "LI" && ele.tagName !== "UL") {
435
+ ele = ele.parentElement;
436
+ }
437
+ return ele;
438
+ }
439
+ const elTransition = "0.3s height ease-in-out, 0.3s padding-top ease-in-out, 0.3s padding-bottom ease-in-out";
440
+ const TransitionObj = {
441
+ "before-enter"(el) {
442
+ el.style.transition = elTransition;
443
+ el.setAttribute("data-oldPadding", el.style.padding);
444
+ el.setAttribute("data-oldMargin", el.style.margin);
445
+ el.style.height = "0";
446
+ el.style.padding = "0";
447
+ el.style.margin = "0";
448
+ },
449
+ enter(el) {
450
+ el.dataset.oldOverflow = el.style.overflow;
451
+ if (el.scrollHeight !== 0) {
452
+ el.style.height = el.scrollHeight + "px";
453
+ } else {
454
+ el.style.height = "";
455
+ }
456
+ el.style.padding = el.getAttribute("data-oldPadding");
457
+ el.style.margin = el.getAttribute("data-oldMargin");
458
+ el.style.overflow = "hidden";
459
+ },
460
+ "after-enter"(el) {
461
+ el.style.transition = "";
462
+ el.style.transition = "";
463
+ el.style.height = "";
464
+ el.style.overflow = el.getAttribute("data-overflow");
465
+ },
466
+ "before-leave"(el) {
467
+ if (!el.dataset) {
468
+ el.dataset = {};
469
+ }
470
+ el.dataset.oldPaddingTop = el.style.paddingTop;
471
+ el.dataset.oldPaddingBottom = el.style.paddingBottom;
472
+ el.dataset.oldOverflow = el.style.overflow;
473
+ el.style.height = el.scrollHeight + "px";
474
+ el.style.overflow = "hidden";
475
+ },
476
+ leave(el) {
477
+ if (el.scrollHeight !== 0) {
478
+ el.style.transition = elTransition;
479
+ el.style.height = "0";
480
+ el.style.paddingTop = "0";
481
+ el.style.paddingBottom = "0";
482
+ }
483
+ },
484
+ "after-leave"(el) {
485
+ el.style.transition = "";
486
+ el.style.height = "";
487
+ el.style.overflow = el.dataset.oldOverflow;
488
+ el.style.paddingTop = el.dataset.oldPaddingTop;
489
+ el.style.paddingBottom = el.dataset.oldPaddingBottom;
490
+ }
491
+ };
492
+ var MenuTransition = defineComponent({
493
+ name: "DMenuTransition",
494
+ setup(prop, ctx) {
495
+ return () => {
496
+ return createVNode(Transition, {
497
+ "onBeforeEnter": (e) => TransitionObj["before-enter"](e),
498
+ "onBeforeLeave": (e) => TransitionObj["before-leave"](e),
499
+ "onEnter": (e) => TransitionObj["enter"](e),
500
+ "onAfterEnter": (e) => TransitionObj["after-enter"](e),
501
+ "onLeave": (e) => TransitionObj["leave"](e),
502
+ "onAfterLeave": (e) => TransitionObj["after-leave"](e)
503
+ }, {
504
+ default: () => {
505
+ var _a, _b;
506
+ return [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)];
507
+ }
508
+ });
509
+ };
510
+ }
511
+ });
512
+ const subMenuProps = {
513
+ title: {
514
+ type: String,
515
+ default: ""
516
+ },
517
+ disabled: {
518
+ type: Boolean,
519
+ default: false
520
+ }
521
+ };
522
+ const ns$1 = useNamespace("menu");
523
+ const subNs$1 = useNamespace("submenu");
524
+ const menuItemHorizontalWrapperHidden = `${ns$1.b()}-item-horizontal-wrapper-hidden`;
525
+ const menuItemHorizontalWrapperShow = `${ns$1.b()}-item-horizontal-wrapper-show`;
526
+ function useShowSubMenu(eventName, e, wrapper) {
527
+ const target = e.currentTarget;
528
+ const targetParent = target.parentElement;
529
+ const wrapperChildren = wrapper.children;
530
+ wrapper.style.padding = `0 20px !important`;
531
+ if (eventName === "mouseenter") {
532
+ if ((targetParent == null ? void 0 : targetParent.tagName) === "DIV") {
533
+ wrapper.classList.add(`${ns$1.b()}-item-horizontal-wrapper-level`);
534
+ const { width } = target.getClientRects()[0];
535
+ wrapper.style.top = `0px`;
536
+ wrapper.style.left = `${width}px`;
537
+ } else {
538
+ wrapper.style.top = `26px`;
539
+ wrapper.style.left = `0px`;
540
+ }
541
+ wrapper.classList.remove(menuItemHorizontalWrapperHidden);
542
+ wrapper.classList.add(menuItemHorizontalWrapperShow);
543
+ for (let i = 0; i < wrapperChildren.length; i++) {
544
+ const ul = wrapperChildren[i];
545
+ if (ul.tagName === "UL" && ul.classList.contains(subNs$1.b())) {
546
+ const levelUlWrapper = ul.getElementsByClassName(`${ns$1.b()}-item-horizontal-wrapper`)[0];
547
+ ul.addEventListener("mouseenter", (ev) => {
548
+ ev.stopPropagation();
549
+ useShowSubMenu("mouseenter", ev, levelUlWrapper);
550
+ levelUlWrapper.classList.remove(menuItemHorizontalWrapperHidden);
551
+ levelUlWrapper.classList.add(menuItemHorizontalWrapperShow);
552
+ });
553
+ ul.addEventListener("mouseleave", (ev) => {
554
+ ev.stopPropagation();
555
+ useShowSubMenu("mouseleave", ev, levelUlWrapper);
556
+ levelUlWrapper.classList.remove(menuItemHorizontalWrapperShow);
557
+ levelUlWrapper.classList.add(menuItemHorizontalWrapperHidden);
558
+ });
559
+ }
560
+ }
561
+ }
562
+ if (eventName === "mouseleave") {
563
+ wrapper.classList.remove(menuItemHorizontalWrapperShow);
564
+ wrapper.classList.add(menuItemHorizontalWrapperHidden);
565
+ }
566
+ }
567
+ const ns = useNamespace("menu");
568
+ const subNs = useNamespace("submenu");
569
+ const subMenuClass = subNs.b();
570
+ var SubMenu = defineComponent({
571
+ name: "DSubMenu",
572
+ props: subMenuProps,
573
+ setup(props, ctx) {
574
+ const isShow = ref(true);
575
+ const {
576
+ vnode: {
577
+ key
578
+ }
579
+ } = getCurrentInstance();
580
+ let key_ = String(key);
581
+ const defaultOpenKeys = inject("openKeys");
582
+ const isOpen = ref(defaultOpenKeys.value.includes(key_));
583
+ const indent = inject("defaultIndent");
584
+ const isCollapsed = inject("isCollapsed");
585
+ const mode = inject("mode");
586
+ const subMenuItemContainer = ref(null);
587
+ const parentEmit = inject("rootMenuEmit");
588
+ const isHorizontal = mode.value === "horizontal";
589
+ if (key_ === "null") {
590
+ console.warn(`[devui][menu]: Key can not be null`);
591
+ key_ = `randomKey-${randomId(16)}`;
592
+ }
593
+ const clickHandle = (e) => {
594
+ e.stopPropagation();
595
+ const ele = useNearestMenuElement(e.target);
596
+ if (ele.classList.contains(subMenuClass) && isHorizontal) {
597
+ return;
598
+ }
599
+ if (isHorizontal) {
600
+ clearSelect(ele, e, true);
601
+ useClick(e);
602
+ }
603
+ if (!props.disabled && mode.value !== "horizontal") {
604
+ const cur = useNearestMenuElement(e.target);
605
+ const idx = defaultOpenKeys.value.indexOf(key_);
606
+ if (idx >= 0 && cur.tagName === "UL") {
607
+ defaultOpenKeys.value.splice(idx, 1);
608
+ } else {
609
+ if (cur.tagName === "UL") {
610
+ defaultOpenKeys.value.push(key_);
611
+ }
612
+ }
613
+ isOpen.value = defaultOpenKeys.value.indexOf(key_) >= 0;
614
+ parentEmit("submenu-change", {
615
+ type: "submenu-change",
616
+ state: isOpen.value,
617
+ key: key_,
618
+ el: ele
619
+ });
620
+ }
621
+ };
622
+ const wrapper = ref(null);
623
+ let wrapperDom;
624
+ const subMenu = ref(null);
625
+ const title = ref(null);
626
+ let oldPadding = "";
627
+ const class_layer = ref("");
628
+ watchEffect(() => {
629
+ wrapperDom = wrapper.value;
630
+ pushElement({
631
+ el: subMenu.value
632
+ });
633
+ }, {
634
+ flush: "post"
635
+ });
636
+ watch(() => defaultOpenKeys, (n) => {
637
+ if (n.value.includes(key_)) {
638
+ isOpen.value = true;
639
+ } else {
640
+ isOpen.value = false;
641
+ }
642
+ }, {
643
+ deep: true
644
+ });
645
+ onMounted(() => {
646
+ var _a;
647
+ const subMenuTitle = title.value;
648
+ const subMenuWrapper = subMenu.value;
649
+ addLayer();
650
+ class_layer.value = `layer_${(_a = Array.from(subMenuWrapper.classList).at(-1)) == null ? void 0 : _a.replace("layer_", "")}`;
651
+ if (isHorizontal && !props.disabled) {
652
+ subMenu.value.addEventListener("mouseenter", (ev) => {
653
+ ev.stopPropagation();
654
+ useShowSubMenu("mouseenter", ev, wrapperDom);
655
+ });
656
+ subMenu.value.addEventListener("mouseleave", (ev) => {
657
+ ev.stopPropagation();
658
+ useShowSubMenu("mouseleave", ev, wrapperDom);
659
+ });
660
+ }
661
+ watch(isCollapsed, (newValue) => {
662
+ const layer = Number(getLayer(subMenuWrapper));
663
+ if (!Number.isNaN(layer)) {
664
+ layer > 2 && (isShow.value = !isCollapsed.value);
665
+ }
666
+ if (newValue) {
667
+ subMenuTitle.style.padding !== "0" && (oldPadding = subMenuTitle.style.padding);
668
+ setTimeout(() => {
669
+ subMenuTitle.style.padding = "0";
670
+ subMenuTitle.style.width = "";
671
+ subMenuTitle.style.textAlign = `center`;
672
+ }, 300);
673
+ subMenuTitle.style.display = `block`;
674
+ } else {
675
+ subMenuTitle.style.padding = `${oldPadding}`;
676
+ subMenuTitle.style.textAlign = ``;
677
+ subMenuTitle.style.display = `flex`;
678
+ }
679
+ });
680
+ });
681
+ return () => {
682
+ var _a, _b, _c, _d;
683
+ return withDirectives(createVNode("ul", {
684
+ "onClick": clickHandle,
685
+ "class": [subMenuClass, class_layer.value, props["disabled"] && `${subMenuClass}-disabled`],
686
+ "ref": subMenu
687
+ }, [createVNode("div", {
688
+ "class": [`${subMenuClass}-title`],
689
+ "style": `padding: 0 ${indent}px`,
690
+ "ref": title
691
+ }, [createVNode("span", {
692
+ "class": `${ns.b()}-icon`
693
+ }, [(_b = (_a = ctx.slots) == null ? void 0 : _a.icon) == null ? void 0 : _b.call(_a)]), withDirectives(createVNode("span", {
694
+ "class": `${subMenuClass}-title-content`
695
+ }, [props.title]), [[vShow, !isCollapsed.value]]), withDirectives(createVNode("i", {
696
+ "class": {
697
+ "icon icon-chevron-up": class_layer.value !== `layer_${subMenuClass}`,
698
+ "icon icon-chevron-right": class_layer.value === `layer_${subMenuClass}`,
699
+ "is-opened": isOpen.value
700
+ }
701
+ }, null), [[vShow, !isCollapsed.value && key !== "overflowContainer"]])]), isHorizontal ? withDirectives(createVNode("div", {
702
+ "class": `${ns.b()}-item-horizontal-wrapper ${ns.b()}-item-horizontal-wrapper-hidden`,
703
+ "ref": wrapper
704
+ }, [(_d = (_c = ctx.slots).default) == null ? void 0 : _d.call(_c)]), [[vShow, !props.disabled]]) : createVNode(MenuTransition, null, {
705
+ default: () => {
706
+ var _a2, _b2;
707
+ return [withDirectives(createVNode("div", {
708
+ "class": [`${subMenuClass}-menu-item-vertical-wrapper`],
709
+ "ref": subMenuItemContainer
710
+ }, [(_b2 = (_a2 = ctx.slots).default) == null ? void 0 : _b2.call(_a2)]), [[vShow, isOpen.value]])];
711
+ }
712
+ })]), [[vShow, isShow.value]]);
713
+ };
714
+ }
715
+ });
716
+ const menuProps = {
717
+ width: {
718
+ type: String,
719
+ default: ""
720
+ },
721
+ collapsed: {
722
+ type: Boolean,
723
+ default: false
724
+ },
725
+ collapsedIndent: {
726
+ type: Number,
727
+ default: 24
728
+ },
729
+ indentSize: {
730
+ type: Number,
731
+ default: 24
732
+ },
733
+ multiple: {
734
+ type: Boolean,
735
+ default: false
736
+ },
737
+ openKeys: {
738
+ type: Array,
739
+ default: []
740
+ },
741
+ defaultSelectKeys: {
742
+ type: Array,
743
+ default: []
744
+ },
745
+ mode: {
746
+ type: String,
747
+ default: "vertical"
748
+ },
749
+ router: {
750
+ type: Boolean,
751
+ default: false
752
+ }
753
+ };
754
+ var menu = "";
755
+ const recordTable = {};
756
+ class Store {
757
+ constructor(rootName) {
758
+ this.rootMenuName = rootName;
759
+ }
760
+ on(eventName, fn) {
761
+ var _a;
762
+ if (!((_a = recordTable == null ? void 0 : recordTable[this.rootMenuName]) == null ? void 0 : _a[eventName])) {
763
+ Reflect.set(recordTable[this.rootMenuName], eventName, []);
764
+ }
765
+ recordTable[this.rootMenuName][eventName].push(fn);
766
+ }
767
+ emit(eventName, ...args) {
768
+ recordTable[this.rootMenuName][eventName].forEach((fn) => fn(...args));
769
+ }
770
+ off(eventName, fn) {
771
+ const idx = recordTable[this.rootMenuName][eventName].indexOf(fn);
772
+ if (idx >= 0) {
773
+ recordTable[this.rootMenuName][eventName].splice(idx, 1);
774
+ }
775
+ }
776
+ }
777
+ function useStore(rootName) {
778
+ if (!recordTable[rootName]) {
779
+ Reflect.set(recordTable, rootName, {});
780
+ }
781
+ return new Store(rootName);
782
+ }
783
+ var Menu = defineComponent({
784
+ name: "DMenu",
785
+ props: menuProps,
786
+ emits: ["select", "deselect", "submenu-change"],
787
+ setup(props, ctx) {
788
+ const ns2 = useNamespace("menu");
789
+ const {
790
+ openKeys,
791
+ mode,
792
+ collapsed
793
+ } = toRefs(props);
794
+ const menuId = randomId(16);
795
+ const store = useStore(menuId);
796
+ provide("menuStore", store);
797
+ provide("isCollapsed", collapsed);
798
+ provide("defaultIndent", props["indentSize"]);
799
+ provide("multiple", props["multiple"]);
800
+ provide("openKeys", openKeys);
801
+ provide("defaultSelectKey", props.defaultSelectKeys);
802
+ provide("mode", mode);
803
+ provide("collapsedIndent", props["collapsedIndent"]);
804
+ provide("rootMenuEmit", ctx.emit);
805
+ provide("useRouter", props.router);
806
+ setDefaultIndent(props["indentSize"]);
807
+ const menuRoot = ref(null);
808
+ const overflowItemLength = ref(0);
809
+ const overflowContainer = ref(null);
810
+ const selectClassName = `${ns2.b()}-item-select`;
811
+ const rootClassName = computed(() => ({
812
+ [`${ns2.b()}`]: true,
813
+ [`${ns2.b()}-vertical`]: mode.value === "vertical",
814
+ [`${ns2.b()}-horizontal`]: mode.value === "horizontal",
815
+ [`${ns2.b()}-collapsed`]: collapsed.value
816
+ }));
817
+ const overflowContainerClassName = reactive({
818
+ [selectClassName]: false,
819
+ [`${ns2.b()}-overflow-container`]: true
820
+ });
821
+ const resetOverflowContainerSelectState = (e) => {
822
+ const children = Array.from(e.children);
823
+ for (const item of children) {
824
+ if (item.classList.contains(selectClassName)) {
825
+ overflowContainerClassName[selectClassName] = true;
826
+ break;
827
+ } else {
828
+ overflowContainerClassName[selectClassName] = false;
829
+ }
830
+ }
831
+ };
832
+ onMounted(() => {
833
+ var _a;
834
+ if (props["mode"] === "horizontal") {
835
+ let flag = false;
836
+ const overflowContainerElement = (_a = overflowContainer.value) == null ? void 0 : _a.$el;
837
+ const root = menuRoot.value;
838
+ const children = root.children;
839
+ const container = overflowContainerElement.children[1];
840
+ const ob = new IntersectionObserver((entries) => {
841
+ entries.forEach((entry) => {
842
+ if (!entry.isIntersecting) {
843
+ const cloneNode = entry.target.cloneNode(true);
844
+ if (entry.target.classList.contains(`${ns2.b()}-overflow-container`)) {
845
+ if (flag && entry.target.previousElementSibling && container.children.length) {
846
+ root.appendChild(entry.target.previousElementSibling);
847
+ } else {
848
+ flag = true;
849
+ }
850
+ } else {
851
+ overflowItemLength.value += 1;
852
+ entry.target.style.visibility = "hidden";
853
+ if (overflowContainerElement.nextSibling) {
854
+ root.insertBefore(entry.target, overflowContainerElement.nextSibling);
855
+ } else {
856
+ root.appendChild(entry.target);
857
+ }
858
+ container.appendChild(cloneNode);
859
+ resetOverflowContainerSelectState(container);
860
+ }
861
+ } else {
862
+ if (!entry.target.classList.contains(`${ns2.b()}-overflow-container`) && entry.target.style.visibility === "hidden") {
863
+ ob.unobserve(entry.target);
864
+ root.insertBefore(entry.target, overflowContainerElement);
865
+ entry.target.style.visibility = "";
866
+ const obItem = overflowContainerElement.previousElementSibling;
867
+ const canObAgin = obItem && entry.boundingClientRect.width % entry.target.getBoundingClientRect().width === 0;
868
+ if (canObAgin) {
869
+ ob.observe(obItem);
870
+ }
871
+ if (obItem == null ? void 0 : obItem.classList.contains("devui-submenu")) {
872
+ const sub = obItem;
873
+ const wrapper = obItem.children[1];
874
+ sub.addEventListener("mouseenter", (ev) => {
875
+ ev.stopPropagation();
876
+ useShowSubMenu("mouseenter", ev, wrapper);
877
+ });
878
+ sub.addEventListener("mouseleave", (ev) => {
879
+ ev.stopPropagation();
880
+ useShowSubMenu("mouseleave", ev, wrapper);
881
+ });
882
+ }
883
+ overflowItemLength.value -= 1;
884
+ ob.observe(entry.target);
885
+ if (container.lastChild) {
886
+ container.removeChild(container.lastChild);
887
+ }
888
+ resetOverflowContainerSelectState(container);
889
+ }
890
+ }
891
+ });
892
+ }, {
893
+ root,
894
+ threshold: 1,
895
+ rootMargin: "8px"
896
+ });
897
+ for (let i = 0; i < children.length; i++) {
898
+ ob.observe(children[i]);
899
+ }
900
+ }
901
+ });
902
+ return () => {
903
+ var _a, _b;
904
+ return createVNode("ul", {
905
+ "ref": menuRoot,
906
+ "class": rootClassName.value,
907
+ "style": [props["collapsed"] ? `width:${props["collapsedIndent"] * 2}px` : `width: ${props["width"]}`]
908
+ }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a), withDirectives(createVNode(SubMenu, {
909
+ "ref": overflowContainer,
910
+ "key": "overflowContainer",
911
+ "title": "...",
912
+ "class": overflowContainerClassName
913
+ }, null), [[vShow, overflowItemLength.value > 0 && mode.value === "horizontal"]])]);
914
+ };
915
+ }
916
+ });
917
+ var index = {
918
+ title: "Menu \u83DC\u5355",
919
+ category: "\u5BFC\u822A",
920
+ status: "100%",
921
+ install(app) {
922
+ app.component(Menu.name, Menu);
923
+ app.component(MenuItem.name, MenuItem);
924
+ app.component(SubMenu.name, SubMenu);
925
+ }
926
+ };
927
+ export { Menu, MenuItem, SubMenu, index as default };