@svar-ui/react-menu 2.5.0 → 2.5.1
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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.es.js +225 -209
- package/dist/index.es.js.map +1 -1
- package/dist-full/index.css +1 -1
- package/package.json +4 -4
package/dist/index.es.js
CHANGED
|
@@ -1,301 +1,317 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { uid as
|
|
4
|
-
import { Portal as
|
|
5
|
-
function
|
|
6
|
-
return
|
|
7
|
-
const
|
|
8
|
-
return
|
|
1
|
+
import { jsxs as N, jsx as o, Fragment as R } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as D, useCallback as k, useMemo as E, useState as C, useEffect as A, Fragment as B, forwardRef as X, useImperativeHandle as F } from "react";
|
|
3
|
+
import { uid as T, setID as W, calculatePosition as J, clickOutside as _, locateID as nn } from "@svar-ui/lib-dom";
|
|
4
|
+
import { Portal as G } from "@svar-ui/react-core";
|
|
5
|
+
function K(c, t) {
|
|
6
|
+
return c.map((n) => {
|
|
7
|
+
const l = t(n);
|
|
8
|
+
return n.data && n.data.length && (l.data = K(n.data, t)), l;
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
const
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
15
|
-
const a =
|
|
16
|
-
a.length &&
|
|
11
|
+
function U(c, t) {
|
|
12
|
+
const n = [];
|
|
13
|
+
return c.forEach((l) => {
|
|
14
|
+
if (l.data) {
|
|
15
|
+
const a = U(l.data, t);
|
|
16
|
+
a.length && n.push({ ...l, data: a });
|
|
17
17
|
} else
|
|
18
|
-
t(
|
|
19
|
-
}),
|
|
18
|
+
t(l) && n.push(l);
|
|
19
|
+
}), n;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
23
|
-
const
|
|
24
|
-
return
|
|
21
|
+
function V(c) {
|
|
22
|
+
return K(c, (t) => {
|
|
23
|
+
const n = { ...t, id: t.id || T() };
|
|
24
|
+
return n.type && (n.comp = n.type), n;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
const
|
|
28
|
-
function
|
|
29
|
-
return
|
|
27
|
+
const Y = {};
|
|
28
|
+
function en(c) {
|
|
29
|
+
return Y[c] || c;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
31
|
+
function sn(c, t) {
|
|
32
|
+
Y[c] = t;
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
t(
|
|
37
|
-
}, [t,
|
|
38
|
-
if (
|
|
39
|
-
|
|
34
|
+
function tn({ onClick: c, onShow: t, option: n }) {
|
|
35
|
+
const l = D(null), a = k(() => {
|
|
36
|
+
t(n.data ? n.id : !1, l.current);
|
|
37
|
+
}, [t, n]), w = k((u) => {
|
|
38
|
+
if (n.data) {
|
|
39
|
+
u.stopPropagation(), t(n.id, l.current);
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
}, [
|
|
44
|
-
return /* @__PURE__ */
|
|
42
|
+
c(u);
|
|
43
|
+
}, [c, t, n]), f = E(() => n && n.comp ? en(n.comp) : null, [n]);
|
|
44
|
+
return /* @__PURE__ */ N(
|
|
45
45
|
"div",
|
|
46
46
|
{
|
|
47
|
-
ref:
|
|
48
|
-
className: `wx-cDCz9rZQ wx-option ${
|
|
49
|
-
"data-id":
|
|
47
|
+
ref: l,
|
|
48
|
+
className: `wx-cDCz9rZQ wx-option ${n.css || ""} ${n.disabled ? "wx-disabled" : ""}`,
|
|
49
|
+
"data-id": W(n.id),
|
|
50
50
|
onMouseEnter: a,
|
|
51
|
-
onClick:
|
|
51
|
+
onClick: w,
|
|
52
52
|
children: [
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
n.icon ? /* @__PURE__ */ o("i", { className: `wx-cDCz9rZQ wx-icon ${n.icon}` }) : null,
|
|
54
|
+
n.comp ? f ? /* @__PURE__ */ o(f, { item: n, option: n }) : null : /* @__PURE__ */ N("span", { className: "wx-cDCz9rZQ wx-value", children: [
|
|
55
55
|
" ",
|
|
56
|
-
|
|
56
|
+
n.text,
|
|
57
57
|
" "
|
|
58
58
|
] }),
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
n.subtext ? /* @__PURE__ */ o("span", { className: "wx-cDCz9rZQ wx-subtext", children: n.subtext }) : null,
|
|
60
|
+
n.data ? /* @__PURE__ */ o("i", { className: "wx-cDCz9rZQ wx-sub-icon wxi-angle-right" }) : null
|
|
61
61
|
]
|
|
62
62
|
}
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
options:
|
|
65
|
+
function S({
|
|
66
|
+
options: c,
|
|
67
67
|
left: t = 0,
|
|
68
|
-
top:
|
|
69
|
-
at:
|
|
68
|
+
top: n = 0,
|
|
69
|
+
at: l = "bottom",
|
|
70
70
|
parent: a = null,
|
|
71
|
-
mount:
|
|
72
|
-
context:
|
|
73
|
-
css:
|
|
74
|
-
onClick:
|
|
71
|
+
mount: w = null,
|
|
72
|
+
context: f = null,
|
|
73
|
+
css: u = "",
|
|
74
|
+
onClick: h,
|
|
75
|
+
onCancel: i
|
|
75
76
|
}) {
|
|
76
|
-
const [
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}, [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
i && (w(i.x), C(i.y), s(i.z), M(i.width));
|
|
83
|
-
}, [a, n, t, e]);
|
|
84
|
-
z(() => {
|
|
85
|
-
x && x(m);
|
|
77
|
+
const [m, p] = C(-1e4), [g, x] = C(-1e4), [r, e] = C(20), [M, Z] = C(), $ = D(null), [P, y] = C(!1), [Q, H] = C(null), z = k(() => {
|
|
78
|
+
const s = J($.current, a, l, t, n);
|
|
79
|
+
s && (p(s.x), x(s.y), e(s.z), Z(s.width));
|
|
80
|
+
}, [a, l, t, n]);
|
|
81
|
+
A(() => {
|
|
82
|
+
w && w(z);
|
|
86
83
|
}, []);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
}, []),
|
|
90
|
-
|
|
91
|
-
}, []),
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
const O = k(() => {
|
|
85
|
+
y(!1);
|
|
86
|
+
}, []), d = k((s, I) => {
|
|
87
|
+
y(s), H(I);
|
|
88
|
+
}, []), L = E(() => V(c), [c]);
|
|
89
|
+
A(() => {
|
|
90
|
+
z();
|
|
91
|
+
}, [a, z]);
|
|
92
|
+
const b = D(h), v = D(i);
|
|
93
|
+
return A(() => void (b.current = h), [h]), A(() => void (v.current = i), [i]), A(() => {
|
|
94
|
+
if (!$.current) return;
|
|
95
|
+
function s(I) {
|
|
96
|
+
v.current ? v.current(I) : b.current && b.current({ action: null, option: null });
|
|
97
|
+
}
|
|
98
|
+
return _($.current, { callback: s, modal: !0 }).destroy;
|
|
99
|
+
}, []), /* @__PURE__ */ o(
|
|
100
100
|
"div",
|
|
101
101
|
{
|
|
102
|
-
ref:
|
|
102
|
+
ref: $,
|
|
103
103
|
"data-wx-menu": "true",
|
|
104
|
-
className: `wx-XMmAGqVx wx-menu ${
|
|
104
|
+
className: `wx-XMmAGqVx wx-menu ${u}`,
|
|
105
105
|
style: {
|
|
106
106
|
position: "absolute",
|
|
107
|
-
top:
|
|
108
|
-
left:
|
|
109
|
-
width:
|
|
110
|
-
zIndex:
|
|
107
|
+
top: g + "px",
|
|
108
|
+
left: m + "px",
|
|
109
|
+
width: M,
|
|
110
|
+
zIndex: r
|
|
111
111
|
},
|
|
112
|
-
onMouseLeave:
|
|
113
|
-
children:
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
onMouseLeave: O,
|
|
113
|
+
children: L.map((s) => /* @__PURE__ */ N(B, { children: [
|
|
114
|
+
s.comp === "separator" ? /* @__PURE__ */ o("div", { className: "wx-XMmAGqVx wx-separator" }) : /* @__PURE__ */ o(
|
|
115
|
+
tn,
|
|
116
116
|
{
|
|
117
|
-
option:
|
|
118
|
-
onShow:
|
|
119
|
-
onClick: (
|
|
120
|
-
if (!
|
|
121
|
-
const
|
|
122
|
-
|
|
117
|
+
option: s,
|
|
118
|
+
onShow: d,
|
|
119
|
+
onClick: (I) => {
|
|
120
|
+
if (!s.data && !I.defaultPrevented) {
|
|
121
|
+
const q = { context: f, action: s, option: s, event: I };
|
|
122
|
+
s.handler && s.handler(q), h && h(q), I.stopPropagation();
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
),
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
s.data && P === s.id ? /* @__PURE__ */ o(
|
|
128
|
+
S,
|
|
129
129
|
{
|
|
130
|
-
css:
|
|
131
|
-
options:
|
|
130
|
+
css: u,
|
|
131
|
+
options: s.data,
|
|
132
132
|
at: "right-overlap",
|
|
133
133
|
parent: Q,
|
|
134
|
-
context:
|
|
135
|
-
onClick:
|
|
134
|
+
context: f,
|
|
135
|
+
onClick: h,
|
|
136
|
+
onCancel: i
|
|
136
137
|
}
|
|
137
138
|
) : null
|
|
138
|
-
] },
|
|
139
|
+
] }, s.id))
|
|
139
140
|
}
|
|
140
141
|
);
|
|
141
142
|
}
|
|
142
|
-
const
|
|
143
|
+
const j = X(function(t, n) {
|
|
143
144
|
const {
|
|
144
|
-
options:
|
|
145
|
+
options: l,
|
|
145
146
|
at: a = "bottom",
|
|
146
|
-
resolver:
|
|
147
|
-
dataKey:
|
|
148
|
-
filter:
|
|
149
|
-
css:
|
|
150
|
-
children:
|
|
151
|
-
onClick:
|
|
152
|
-
} = t, [
|
|
153
|
-
() => `data-${
|
|
154
|
-
[
|
|
155
|
-
),
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
resolver: w = null,
|
|
148
|
+
dataKey: f = "contextId",
|
|
149
|
+
filter: u = null,
|
|
150
|
+
css: h = "",
|
|
151
|
+
children: i,
|
|
152
|
+
onClick: m
|
|
153
|
+
} = t, [p, g] = C(null), [x, r] = C(null), [e, M] = C(0), [Z, $] = C(0), P = D(null), y = E(
|
|
154
|
+
() => `data-${f.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase()}`,
|
|
155
|
+
[f]
|
|
156
|
+
), Q = E(() => p !== null && u ? U(l, (d) => u(d, p)) : l, [p, u, l]);
|
|
157
|
+
function H(d) {
|
|
158
|
+
r(null), m && m(d);
|
|
159
|
+
}
|
|
160
|
+
function z(d) {
|
|
161
|
+
if (P.current === d) {
|
|
162
|
+
P.current = null;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
r(null), m && m({ action: null, option: null });
|
|
166
|
+
}
|
|
167
|
+
const O = k(
|
|
168
|
+
(d, L) => {
|
|
169
|
+
if (!d) {
|
|
170
|
+
r(null);
|
|
164
171
|
return;
|
|
165
172
|
}
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
if (d.defaultPrevented) return;
|
|
174
|
+
const b = d.target;
|
|
175
|
+
if (b && b.dataset && b.dataset.menuIgnore) return;
|
|
176
|
+
if (x && x === b) {
|
|
177
|
+
r(null), d.preventDefault();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
M(d.clientX + 1), $(d.clientY + 1);
|
|
181
|
+
let v = typeof L < "u" ? L : nn(b, y);
|
|
182
|
+
w && (v = w(v, d), !v) || (g(v), r(b), P.current = d.nativeEvent || d, d.preventDefault());
|
|
172
183
|
},
|
|
173
|
-
[
|
|
184
|
+
[x, y, w]
|
|
174
185
|
);
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
186
|
+
return F(n, () => ({ show: O }), [O]), /* @__PURE__ */ N(R, { children: [
|
|
187
|
+
i ? /* @__PURE__ */ o("span", { onClick: O, "data-menu-ignore": "true", children: typeof i == "function" ? i() : i }) : null,
|
|
188
|
+
x ? /* @__PURE__ */ o(G, { children: /* @__PURE__ */ o(
|
|
189
|
+
S,
|
|
179
190
|
{
|
|
180
|
-
css:
|
|
191
|
+
css: h,
|
|
181
192
|
at: a,
|
|
182
|
-
top:
|
|
183
|
-
left:
|
|
184
|
-
parent:
|
|
185
|
-
context:
|
|
186
|
-
onClick:
|
|
187
|
-
|
|
193
|
+
top: Z,
|
|
194
|
+
left: e,
|
|
195
|
+
parent: x,
|
|
196
|
+
context: p,
|
|
197
|
+
onClick: H,
|
|
198
|
+
onCancel: z,
|
|
199
|
+
options: Q
|
|
188
200
|
},
|
|
189
|
-
|
|
201
|
+
x
|
|
190
202
|
) }) : null
|
|
191
203
|
] });
|
|
192
204
|
});
|
|
193
|
-
function
|
|
194
|
-
const { css: t = "", menuCss:
|
|
195
|
-
function
|
|
196
|
-
|
|
205
|
+
function an(c) {
|
|
206
|
+
const { css: t = "", menuCss: n = "", options: l, onClick: a } = c, w = E(() => V(l), [l]), [f, u] = C(!1), [h, i] = C([]), m = D(null);
|
|
207
|
+
function p(r) {
|
|
208
|
+
u(null), a && a(r);
|
|
197
209
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
210
|
+
function g(r, e, M) {
|
|
211
|
+
e.data && e.data.length ? f && M ? u(null) : (i(e.data), u(e.id), m.current.show(r, e)) : (m.current.show(null), M ? (a && a({ action: e, option: e }), u(null)) : u(-1));
|
|
200
212
|
}
|
|
201
|
-
function
|
|
202
|
-
|
|
213
|
+
function x(r, e) {
|
|
214
|
+
f && g(r, e);
|
|
203
215
|
}
|
|
204
|
-
return /* @__PURE__ */
|
|
205
|
-
/* @__PURE__ */ o("div", { className: `wx-UfhPCLL4 wx-menubar ${t}`, children:
|
|
216
|
+
return /* @__PURE__ */ N(R, { children: [
|
|
217
|
+
/* @__PURE__ */ o("div", { className: `wx-UfhPCLL4 wx-menubar ${t}`, children: w.map((r) => /* @__PURE__ */ o(
|
|
206
218
|
"button",
|
|
207
219
|
{
|
|
208
|
-
className: `wx-UfhPCLL4 wx-option ${
|
|
209
|
-
onMouseEnter: (
|
|
210
|
-
onClick: (
|
|
211
|
-
children:
|
|
220
|
+
className: `wx-UfhPCLL4 wx-option ${f === r.id ? "wx-active" : ""} ${r.disabled ? "wx-disabled" : ""}`,
|
|
221
|
+
onMouseEnter: (e) => x(e, r),
|
|
222
|
+
onClick: (e) => g(e, r, !0),
|
|
223
|
+
children: r.text
|
|
212
224
|
},
|
|
213
|
-
|
|
225
|
+
r.id
|
|
214
226
|
)) }),
|
|
215
227
|
/* @__PURE__ */ o(
|
|
216
|
-
|
|
228
|
+
j,
|
|
217
229
|
{
|
|
218
|
-
css:
|
|
219
|
-
onClick:
|
|
220
|
-
options:
|
|
221
|
-
ref:
|
|
230
|
+
css: n,
|
|
231
|
+
onClick: p,
|
|
232
|
+
options: h,
|
|
233
|
+
ref: m
|
|
222
234
|
}
|
|
223
235
|
)
|
|
224
236
|
] });
|
|
225
237
|
}
|
|
226
|
-
const
|
|
227
|
-
const { options:
|
|
228
|
-
function
|
|
229
|
-
|
|
238
|
+
const on = X(function(t, n) {
|
|
239
|
+
const { options: l, at: a = "bottom", css: w = "", children: f, onClick: u } = t, [h, i] = C(null), m = D(null);
|
|
240
|
+
function p(e) {
|
|
241
|
+
i(null), u && u(e);
|
|
230
242
|
}
|
|
231
|
-
|
|
232
|
-
|
|
243
|
+
function g(e) {
|
|
244
|
+
if (m.current === e) {
|
|
245
|
+
m.current = null;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
i(null), u && u({ action: null, option: null });
|
|
249
|
+
}
|
|
250
|
+
const x = k((e) => {
|
|
251
|
+
i(e.target), m.current = e.nativeEvent || e, e.preventDefault();
|
|
233
252
|
}, []);
|
|
234
|
-
|
|
235
|
-
function
|
|
236
|
-
let M =
|
|
253
|
+
F(n, () => ({ show: x }), [x]);
|
|
254
|
+
function r(e) {
|
|
255
|
+
let M = e.target;
|
|
237
256
|
for (; !M.dataset.menuIgnore; )
|
|
238
|
-
|
|
257
|
+
i(M), M = M.parentNode;
|
|
239
258
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
/* @__PURE__ */ o("span", { onClick: C, "data-menu-ignore": "true", children: d }),
|
|
245
|
-
u ? /* @__PURE__ */ o(K, { children: /* @__PURE__ */ o(
|
|
246
|
-
X,
|
|
259
|
+
return /* @__PURE__ */ N(R, { children: [
|
|
260
|
+
/* @__PURE__ */ o("span", { onClick: r, "data-menu-ignore": "true", children: f }),
|
|
261
|
+
h ? /* @__PURE__ */ o(G, { children: /* @__PURE__ */ o(
|
|
262
|
+
S,
|
|
247
263
|
{
|
|
248
|
-
css:
|
|
264
|
+
css: w,
|
|
249
265
|
at: a,
|
|
250
|
-
parent:
|
|
251
|
-
options:
|
|
252
|
-
onClick:
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
parent: h,
|
|
267
|
+
options: l,
|
|
268
|
+
onClick: p,
|
|
269
|
+
onCancel: g
|
|
270
|
+
}
|
|
255
271
|
) }) : null
|
|
256
272
|
] });
|
|
257
|
-
}),
|
|
273
|
+
}), dn = X(function(t, n) {
|
|
258
274
|
const {
|
|
259
|
-
options:
|
|
275
|
+
options: l,
|
|
260
276
|
at: a = "bottom",
|
|
261
|
-
resolver:
|
|
262
|
-
dataKey:
|
|
263
|
-
filter:
|
|
264
|
-
css:
|
|
265
|
-
children:
|
|
266
|
-
onClick:
|
|
267
|
-
} = t,
|
|
268
|
-
|
|
277
|
+
resolver: w = null,
|
|
278
|
+
dataKey: f = "contextId",
|
|
279
|
+
filter: u = null,
|
|
280
|
+
css: h = "",
|
|
281
|
+
children: i,
|
|
282
|
+
onClick: m
|
|
283
|
+
} = t, p = D(null), g = k((x, r) => {
|
|
284
|
+
p.current.show(x, r);
|
|
269
285
|
}, []);
|
|
270
|
-
return
|
|
271
|
-
|
|
286
|
+
return F(
|
|
287
|
+
n,
|
|
272
288
|
() => ({
|
|
273
|
-
show:
|
|
289
|
+
show: g
|
|
274
290
|
}),
|
|
275
|
-
[
|
|
276
|
-
), /* @__PURE__ */
|
|
277
|
-
|
|
291
|
+
[g]
|
|
292
|
+
), /* @__PURE__ */ N(R, { children: [
|
|
293
|
+
i ? /* @__PURE__ */ o("span", { onContextMenu: g, "data-menu-ignore": "true", children: i }) : null,
|
|
278
294
|
/* @__PURE__ */ o(
|
|
279
|
-
|
|
295
|
+
j,
|
|
280
296
|
{
|
|
281
|
-
css:
|
|
297
|
+
css: h,
|
|
282
298
|
at: a,
|
|
283
|
-
options:
|
|
284
|
-
resolver:
|
|
285
|
-
dataKey:
|
|
286
|
-
filter:
|
|
287
|
-
ref:
|
|
288
|
-
onClick:
|
|
299
|
+
options: l,
|
|
300
|
+
resolver: w,
|
|
301
|
+
dataKey: f,
|
|
302
|
+
filter: u,
|
|
303
|
+
ref: p,
|
|
304
|
+
onClick: m
|
|
289
305
|
}
|
|
290
306
|
)
|
|
291
307
|
] });
|
|
292
308
|
});
|
|
293
309
|
export {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
310
|
+
j as ActionMenu,
|
|
311
|
+
dn as ContextMenu,
|
|
312
|
+
on as DropDownMenu,
|
|
313
|
+
S as Menu,
|
|
314
|
+
an as MenuBar,
|
|
315
|
+
sn as registerMenuItem
|
|
300
316
|
};
|
|
301
317
|
//# sourceMappingURL=index.es.js.map
|