lew-ui 2.7.41 → 2.7.44
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.
- package/dist/index.css +1 -1
- package/dist/index.js +37555 -227
- package/dist/index.umd.cjs +6 -6
- package/package.json +1 -1
- package/dist/LewContextMenu-BhQMFiKK.js +0 -219
- package/dist/index-Ba0vjDlo.js +0 -37360
package/package.json
CHANGED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { defineComponent, computed, shallowRef, onMounted, nextTick, onBeforeUnmount, createBlock, openBlock, unref, withCtx, createElementBlock, Fragment, renderList, normalizeClass, createElementVNode, normalizeStyle, createCommentVNode, createVNode, createApp, h, defineAsyncComponent } from "vue";
|
|
2
|
-
import { c as contextMenuProps, g as getUniqueId, L as LewFlex, C as CommonIcon, _ as _sfc_main$1, a as LewEmpty, i as isFunction, b as initLewContextMenu, t as tippy, d as _export_sfc } from "./index-Ba0vjDlo.js";
|
|
3
|
-
const contextMenuEmits = {
|
|
4
|
-
change: (item) => item
|
|
5
|
-
};
|
|
6
|
-
const _hoisted_1 = ["onClick"];
|
|
7
|
-
const _hoisted_2 = {
|
|
8
|
-
key: 0,
|
|
9
|
-
class: "lew-context-menu-checkable"
|
|
10
|
-
};
|
|
11
|
-
const _hoisted_3 = { class: "lew-context-menu-label" };
|
|
12
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
13
|
-
__name: "LewContextMenu",
|
|
14
|
-
props: contextMenuProps,
|
|
15
|
-
emits: contextMenuEmits,
|
|
16
|
-
setup(__props, { emit: __emit }) {
|
|
17
|
-
const props = __props;
|
|
18
|
-
const emit = __emit;
|
|
19
|
-
const _options = computed(() => props.options);
|
|
20
|
-
const hasCheckableItems = computed(() => _options.value.some((item) => item.checkable));
|
|
21
|
-
const hasChildrenItems = computed(
|
|
22
|
-
() => _options.value.some((item) => item.children?.length)
|
|
23
|
-
);
|
|
24
|
-
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
25
|
-
function createItemProxy(item) {
|
|
26
|
-
if (proxyCache.has(item)) {
|
|
27
|
-
return proxyCache.get(item);
|
|
28
|
-
}
|
|
29
|
-
const proxy = new Proxy(item, {
|
|
30
|
-
get(target, prop, receiver) {
|
|
31
|
-
return Reflect.get(target, prop, receiver);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
proxyCache.set(item, proxy);
|
|
35
|
-
return proxy;
|
|
36
|
-
}
|
|
37
|
-
function clickItem(item) {
|
|
38
|
-
if (item.disabled)
|
|
39
|
-
return;
|
|
40
|
-
const instance = props.dropdownInstance || window.LewContextMenu?.instance || null;
|
|
41
|
-
if (isFunction(item.onClick)) {
|
|
42
|
-
try {
|
|
43
|
-
const proxyItem = createItemProxy(item);
|
|
44
|
-
const proxyOptions = new Proxy(_options.value, {
|
|
45
|
-
get(target, prop, receiver) {
|
|
46
|
-
return Reflect.get(target, prop, receiver);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
item.onClick?.(proxyItem, proxyOptions, instance);
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error("[LewContextMenu] Error in onClick handler:", error);
|
|
52
|
-
}
|
|
53
|
-
} else {
|
|
54
|
-
instance?.hide();
|
|
55
|
-
}
|
|
56
|
-
emit("change", item);
|
|
57
|
-
}
|
|
58
|
-
const TIPPY_CONFIG = {
|
|
59
|
-
theme: "light",
|
|
60
|
-
animation: "shift-away-subtle",
|
|
61
|
-
trigger: "mouseenter",
|
|
62
|
-
interactive: true,
|
|
63
|
-
placement: "right-start",
|
|
64
|
-
duration: [250, 250],
|
|
65
|
-
delay: [120, 120],
|
|
66
|
-
arrow: false,
|
|
67
|
-
offset: [0, 0],
|
|
68
|
-
allowHTML: true,
|
|
69
|
-
hideOnClick: false,
|
|
70
|
-
zIndex: 2001
|
|
71
|
-
};
|
|
72
|
-
const uniqueId = getUniqueId();
|
|
73
|
-
const subMenuInstances = /* @__PURE__ */ new Map();
|
|
74
|
-
const itemRefs = shallowRef([]);
|
|
75
|
-
function setItemRef(el, index) {
|
|
76
|
-
if (el && el instanceof HTMLElement) {
|
|
77
|
-
itemRefs.value[index] = el;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function createSubMenu(options) {
|
|
81
|
-
const menuDom = document.createElement("div");
|
|
82
|
-
const app = createApp({
|
|
83
|
-
render() {
|
|
84
|
-
return h(
|
|
85
|
-
defineAsyncComponent(() => Promise.resolve().then(() => LewContextMenu$1)),
|
|
86
|
-
{
|
|
87
|
-
options,
|
|
88
|
-
onChange: (item) => emit("change", item)
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
app.mount(menuDom);
|
|
94
|
-
return { element: menuDom, app };
|
|
95
|
-
}
|
|
96
|
-
function initTippy() {
|
|
97
|
-
itemRefs.value.forEach((el, index) => {
|
|
98
|
-
const option = _options.value[index];
|
|
99
|
-
if (!el || option?.disabled || !option?.children?.length) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
if (!window.LewContextMenu) {
|
|
104
|
-
initLewContextMenu();
|
|
105
|
-
}
|
|
106
|
-
const { element: menuDom, app } = createSubMenu(option.children);
|
|
107
|
-
const tippyInstances = tippy(el, {
|
|
108
|
-
...TIPPY_CONFIG,
|
|
109
|
-
content: menuDom
|
|
110
|
-
});
|
|
111
|
-
const tippyInstance = Array.isArray(tippyInstances) ? tippyInstances[0] : tippyInstances;
|
|
112
|
-
subMenuInstances.set(index, { app, tippy: tippyInstance });
|
|
113
|
-
window.LewContextMenu.menuInstance[`${uniqueId}-${index}`] = tippyInstance;
|
|
114
|
-
const popperElement = tippyInstance.popper?.children?.[0];
|
|
115
|
-
popperElement?.setAttribute("data-lew", "popover");
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.error("[LewContextMenu] Failed to initialize submenu:", error);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
function cleanup() {
|
|
122
|
-
subMenuInstances.forEach(({ app, tippy: tippy2 }, index) => {
|
|
123
|
-
try {
|
|
124
|
-
app?.unmount?.();
|
|
125
|
-
tippy2?.destroy?.();
|
|
126
|
-
const key = `${uniqueId}-${index}`;
|
|
127
|
-
if (window.LewContextMenu?.menuInstance?.[key]) {
|
|
128
|
-
delete window.LewContextMenu.menuInstance[key];
|
|
129
|
-
}
|
|
130
|
-
} catch (error) {
|
|
131
|
-
console.warn("[LewContextMenu] Failed to cleanup submenu instance:", error);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
subMenuInstances.clear();
|
|
135
|
-
}
|
|
136
|
-
onMounted(() => {
|
|
137
|
-
nextTick(() => {
|
|
138
|
-
initTippy();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
onBeforeUnmount(() => {
|
|
142
|
-
cleanup();
|
|
143
|
-
});
|
|
144
|
-
return (_ctx, _cache) => {
|
|
145
|
-
return openBlock(), createBlock(unref(LewFlex), {
|
|
146
|
-
direction: "y",
|
|
147
|
-
gap: "0",
|
|
148
|
-
class: "lew-context-menu"
|
|
149
|
-
}, {
|
|
150
|
-
default: withCtx(() => [
|
|
151
|
-
unref(_options).length > 0 ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(unref(_options), (item, index) => {
|
|
152
|
-
return openBlock(), createElementBlock("div", {
|
|
153
|
-
key: `menu-item-${index}`,
|
|
154
|
-
class: normalizeClass(["lew-context-menu-box", {
|
|
155
|
-
"lew-context-menu-box-disabled": item.disabled,
|
|
156
|
-
"lew-context-menu-box-divider-line": item.isDividerLine
|
|
157
|
-
}])
|
|
158
|
-
}, [
|
|
159
|
-
createElementVNode("div", {
|
|
160
|
-
ref_for: true,
|
|
161
|
-
ref: (el) => setItemRef(el, index),
|
|
162
|
-
class: normalizeClass(["lew-context-menu-item", {
|
|
163
|
-
"lew-context-menu-item-active": item.active,
|
|
164
|
-
"lew-context-menu-item-disabled": item.disabled
|
|
165
|
-
}]),
|
|
166
|
-
style: normalizeStyle({ "animation-delay": `${index * 10}ms` }),
|
|
167
|
-
onClick: ($event) => clickItem(item)
|
|
168
|
-
}, [
|
|
169
|
-
unref(hasCheckableItems) ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
|
170
|
-
item.checked ? (openBlock(), createBlock(CommonIcon, {
|
|
171
|
-
key: 0,
|
|
172
|
-
size: 12,
|
|
173
|
-
"stroke-width": 2.5,
|
|
174
|
-
type: "check"
|
|
175
|
-
})) : createCommentVNode("", true)
|
|
176
|
-
])) : createCommentVNode("", true),
|
|
177
|
-
createElementVNode("div", _hoisted_3, [
|
|
178
|
-
item.icon ? (openBlock(), createBlock(_sfc_main$1, {
|
|
179
|
-
key: 0,
|
|
180
|
-
"render-fn": item.icon
|
|
181
|
-
}, null, 8, ["render-fn"])) : createCommentVNode("", true),
|
|
182
|
-
createVNode(_sfc_main$1, {
|
|
183
|
-
class: "lew-context-menu-label-text",
|
|
184
|
-
"render-fn": item.label
|
|
185
|
-
}, null, 8, ["render-fn"])
|
|
186
|
-
]),
|
|
187
|
-
unref(hasChildrenItems) ? (openBlock(), createBlock(CommonIcon, {
|
|
188
|
-
key: 1,
|
|
189
|
-
class: "lew-context-menu-item-chevron",
|
|
190
|
-
size: 14,
|
|
191
|
-
style: normalizeStyle({
|
|
192
|
-
opacity: item.children?.length ? 1 : 0
|
|
193
|
-
}),
|
|
194
|
-
type: "chevron-right"
|
|
195
|
-
}, null, 8, ["style"])) : createCommentVNode("", true)
|
|
196
|
-
], 14, _hoisted_1)
|
|
197
|
-
], 2);
|
|
198
|
-
}), 128)) : (openBlock(), createBlock(unref(LewEmpty), {
|
|
199
|
-
key: 1,
|
|
200
|
-
width: "120px",
|
|
201
|
-
padding: "5px",
|
|
202
|
-
"font-size": "12px",
|
|
203
|
-
type: "search",
|
|
204
|
-
title: "暂无操作"
|
|
205
|
-
}))
|
|
206
|
-
]),
|
|
207
|
-
_: 1
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
const LewContextMenu = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-07a78cb9"]]);
|
|
213
|
-
const LewContextMenu$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
214
|
-
__proto__: null,
|
|
215
|
-
default: LewContextMenu
|
|
216
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
217
|
-
export {
|
|
218
|
-
LewContextMenu as default
|
|
219
|
-
};
|