@ztwoint/z-ui 0.1.136 → 0.1.137
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.
|
@@ -1,209 +1,207 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { jsx as k, jsxs as E } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as T, useCallback as h, useState as V } from "react";
|
|
3
3
|
import { Z2Checkbox as J } from "../checkbox/checkbox.js";
|
|
4
|
-
import { cn as
|
|
4
|
+
import { cn as Q } from "../../lib/utils.js";
|
|
5
5
|
import { Input as ee } from "../input/input.js";
|
|
6
6
|
import { MagnifierIcon as te } from "../assets/icons/magnifier-icon.js";
|
|
7
|
-
const le = (
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
|
|
7
|
+
const le = (I) => {
|
|
8
|
+
const g = /* @__PURE__ */ new Map(), v = [];
|
|
9
|
+
I.forEach((s) => {
|
|
10
|
+
const u = s.key.split(".");
|
|
11
|
+
let a = "";
|
|
12
|
+
u.forEach((f, o) => {
|
|
13
|
+
const p = o === u.length - 1;
|
|
14
|
+
if (a = a ? `${a}.${f}` : f, g.has(a)) {
|
|
15
|
+
if (p) {
|
|
16
|
+
const m = g.get(a);
|
|
17
|
+
m.label = s.label, m.disabled = s.disabled, m.hint = s.hint, m.isLeaf = !0;
|
|
18
18
|
}
|
|
19
19
|
} else {
|
|
20
|
-
const
|
|
21
|
-
id:
|
|
22
|
-
label:
|
|
20
|
+
const m = {
|
|
21
|
+
id: a,
|
|
22
|
+
label: p ? s.label : f,
|
|
23
23
|
// Use original label for leaf, path part for intermediate
|
|
24
24
|
children: [],
|
|
25
|
-
disabled:
|
|
26
|
-
hint:
|
|
27
|
-
isLeaf:
|
|
25
|
+
disabled: p ? s.disabled : void 0,
|
|
26
|
+
hint: p ? s.hint : void 0,
|
|
27
|
+
isLeaf: p
|
|
28
28
|
};
|
|
29
|
-
|
|
29
|
+
g.set(a, m);
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
}),
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
32
|
+
}), g.forEach((s, u) => {
|
|
33
|
+
const a = u.split(".");
|
|
34
|
+
if (a.length === 1)
|
|
35
|
+
v.push(s);
|
|
36
36
|
else {
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const f = a.slice(0, -1).join("."), o = g.get(f);
|
|
38
|
+
o && !o.children.find((p) => p.id === s.id) && o.children.push(s);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
const
|
|
42
|
-
...
|
|
43
|
-
children:
|
|
41
|
+
const n = (s) => s.sort((u, a) => u.label.localeCompare(a.label)).map((u) => ({
|
|
42
|
+
...u,
|
|
43
|
+
children: u.children && u.children.length > 0 ? n(u.children) : void 0
|
|
44
44
|
}));
|
|
45
|
-
return
|
|
45
|
+
return n(v);
|
|
46
46
|
}, de = ({
|
|
47
|
-
items:
|
|
48
|
-
defaultValue:
|
|
49
|
-
onChange:
|
|
50
|
-
selectionMode:
|
|
47
|
+
items: I,
|
|
48
|
+
defaultValue: g = [],
|
|
49
|
+
onChange: v,
|
|
50
|
+
selectionMode: n = "all-nodes",
|
|
51
51
|
defaultExpandedIds: s,
|
|
52
|
-
searchable:
|
|
53
|
-
searchPlaceholder:
|
|
54
|
-
filterFn:
|
|
55
|
-
onSearchChange:
|
|
56
|
-
showSelectAll:
|
|
57
|
-
selectAllLabel:
|
|
58
|
-
cascade:
|
|
52
|
+
searchable: u = !0,
|
|
53
|
+
searchPlaceholder: a = "Search items...",
|
|
54
|
+
filterFn: f,
|
|
55
|
+
onSearchChange: o,
|
|
56
|
+
showSelectAll: p = !0,
|
|
57
|
+
selectAllLabel: m = "Select all",
|
|
58
|
+
cascade: R = !0,
|
|
59
59
|
renderLabel: $,
|
|
60
60
|
ariaLabel: K,
|
|
61
61
|
ariaLabelledby: O,
|
|
62
|
-
disabled:
|
|
62
|
+
disabled: x = !1
|
|
63
63
|
}) => {
|
|
64
|
-
const
|
|
65
|
-
new Set(s || U(
|
|
66
|
-
), [j, Y] =
|
|
64
|
+
const w = T(() => le(I), [I]), U = h((e) => e.map((l) => l.id), []), [b, W] = V(new Set(g)), [y, X] = V(
|
|
65
|
+
new Set(s || U(w))
|
|
66
|
+
), [j, Y] = V(""), z = h(
|
|
67
67
|
(e) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
r.disabled || (
|
|
68
|
+
const l = [], c = (t) => {
|
|
69
|
+
t.children && t.children.forEach((r) => {
|
|
70
|
+
r.disabled || (n === "leaves-only" ? (!r.children || r.children.length === 0) && l.push(r.id) : l.push(r.id)), c(r);
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
-
return
|
|
73
|
+
return c(e), l;
|
|
74
74
|
},
|
|
75
|
-
[
|
|
76
|
-
), L =
|
|
77
|
-
(e,
|
|
78
|
-
for (const
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
const r = L(
|
|
75
|
+
[n]
|
|
76
|
+
), L = h(
|
|
77
|
+
(e, l, c) => {
|
|
78
|
+
for (const t of e) {
|
|
79
|
+
if (t.id === l) return c || null;
|
|
80
|
+
if (t.children) {
|
|
81
|
+
const r = L(t.children, l, t.id);
|
|
82
82
|
if (r !== null) return r;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
return null;
|
|
86
86
|
},
|
|
87
87
|
[]
|
|
88
|
-
),
|
|
89
|
-
(e,
|
|
90
|
-
if (!
|
|
91
|
-
const
|
|
92
|
-
...
|
|
93
|
-
children:
|
|
88
|
+
), C = h((e, l) => e.label.toLowerCase().includes(l.toLowerCase()), []), F = h(
|
|
89
|
+
(e, l) => {
|
|
90
|
+
if (!l) return e;
|
|
91
|
+
const c = f || C, t = (i) => c(i, l) ? !0 : i.children ? i.children.some((d) => t(d)) : !1, r = (i) => i.filter((d) => t(d)).map((d) => c(d, l) ? d.children && d.children.length > 0 ? {
|
|
92
|
+
...d,
|
|
93
|
+
children: d.children
|
|
94
94
|
// Include all children as-is
|
|
95
|
-
} :
|
|
96
|
-
...
|
|
97
|
-
children:
|
|
95
|
+
} : d : {
|
|
96
|
+
...d,
|
|
97
|
+
children: d.children ? r(d.children) : void 0
|
|
98
98
|
});
|
|
99
99
|
return r(e);
|
|
100
100
|
},
|
|
101
|
-
[
|
|
102
|
-
), Z =
|
|
103
|
-
(e,
|
|
104
|
-
const
|
|
105
|
-
return e.forEach((
|
|
106
|
-
const r = !!(
|
|
107
|
-
|
|
108
|
-
node:
|
|
109
|
-
level:
|
|
101
|
+
[f, C]
|
|
102
|
+
), Z = T(() => F(w, j), [w, j, F]), B = h(
|
|
103
|
+
(e, l = 0) => {
|
|
104
|
+
const c = [];
|
|
105
|
+
return e.forEach((t) => {
|
|
106
|
+
const r = !!(t.children && t.children.length > 0), i = y.has(t.id);
|
|
107
|
+
c.push({
|
|
108
|
+
node: t,
|
|
109
|
+
level: l,
|
|
110
110
|
isBranch: r,
|
|
111
|
-
visibleChildrenCount:
|
|
112
|
-
}),
|
|
113
|
-
}),
|
|
111
|
+
visibleChildrenCount: i && t.children ? t.children.length : 0
|
|
112
|
+
}), i && t.children && c.push(...B(t.children, l + 1));
|
|
113
|
+
}), c;
|
|
114
114
|
},
|
|
115
|
-
[
|
|
116
|
-
),
|
|
115
|
+
[y]
|
|
116
|
+
), N = T(() => B(Z), [Z, B]), S = h(
|
|
117
117
|
(e) => {
|
|
118
|
-
const
|
|
118
|
+
const l = b.has(e.id);
|
|
119
119
|
if (!e.children || e.children.length === 0)
|
|
120
|
-
return
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
return
|
|
124
|
-
const
|
|
125
|
-
return
|
|
120
|
+
return l ? "checked" : "unchecked";
|
|
121
|
+
const c = e.children.filter((i) => !i.disabled).map((i) => S(i));
|
|
122
|
+
if (c.length === 0)
|
|
123
|
+
return l ? "checked" : "unchecked";
|
|
124
|
+
const t = c.every((i) => i === "checked"), r = c.every((i) => i === "unchecked");
|
|
125
|
+
return t ? "checked" : r ? l && n === "all-nodes" ? "checked" : "unchecked" : "mixed";
|
|
126
126
|
},
|
|
127
|
-
[
|
|
128
|
-
),
|
|
127
|
+
[b, n]
|
|
128
|
+
), P = h(
|
|
129
129
|
(e) => {
|
|
130
|
-
W(e),
|
|
130
|
+
W(e), v == null || v(Array.from(e));
|
|
131
131
|
},
|
|
132
|
-
[
|
|
133
|
-
), G =
|
|
132
|
+
[v]
|
|
133
|
+
), G = h((e) => {
|
|
134
134
|
X(e);
|
|
135
|
-
}, []),
|
|
135
|
+
}, []), D = h(
|
|
136
136
|
(e) => {
|
|
137
|
-
if (e.disabled ||
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
const
|
|
141
|
-
|
|
137
|
+
if (e.disabled || x) return;
|
|
138
|
+
const l = new Set(b), c = S(e);
|
|
139
|
+
if (R && e.children && e.children.length > 0) {
|
|
140
|
+
const t = z(e);
|
|
141
|
+
c === "checked" ? (t.forEach((r) => l.delete(r)), n === "all-nodes" && l.delete(e.id)) : (t.forEach((r) => l.add(r)), n === "all-nodes" && l.add(e.id));
|
|
142
142
|
} else
|
|
143
|
-
(
|
|
144
|
-
|
|
143
|
+
(n === "all-nodes" || !e.children || e.children.length === 0) && (b.has(e.id) ? l.delete(e.id) : l.add(e.id));
|
|
144
|
+
P(l);
|
|
145
145
|
},
|
|
146
146
|
[
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
b,
|
|
148
|
+
S,
|
|
149
|
+
R,
|
|
150
|
+
n,
|
|
149
151
|
z,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
v,
|
|
153
|
-
A
|
|
152
|
+
x,
|
|
153
|
+
P
|
|
154
154
|
]
|
|
155
|
-
), _ =
|
|
156
|
-
const
|
|
157
|
-
({ node: r }) => !r.disabled && (
|
|
158
|
-
).map(({ node: r }) => r.id),
|
|
159
|
-
|
|
160
|
-
}, [
|
|
161
|
-
const e =
|
|
162
|
-
({ node: l }) => !l.disabled && (c === "all-nodes" || !l.children || l.children.length === 0)
|
|
163
|
-
);
|
|
155
|
+
), _ = h(() => {
|
|
156
|
+
const l = N.filter(
|
|
157
|
+
({ node: r }) => !r.disabled && (n === "all-nodes" || !r.children || r.children.length === 0)
|
|
158
|
+
).map(({ node: r }) => r.id), c = l.every((r) => b.has(r)), t = new Set(b);
|
|
159
|
+
c ? l.forEach((r) => t.delete(r)) : l.forEach((r) => t.add(r)), P(t);
|
|
160
|
+
}, [N, b, n, P]), H = h(() => {
|
|
161
|
+
const e = N.map(({ node: t }) => t.disabled || n === "leaves-only" && t.children && t.children.length > 0 ? null : S(t)).filter((t) => t !== null);
|
|
164
162
|
if (e.length === 0) return "unchecked";
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
}, [
|
|
163
|
+
const l = e.every((t) => t === "checked"), c = e.every((t) => t === "unchecked");
|
|
164
|
+
return l ? "checked" : c ? "unchecked" : "mixed";
|
|
165
|
+
}, [N, n, S]), q = h(
|
|
168
166
|
(e) => {
|
|
169
|
-
if (Y(e),
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
if ((
|
|
173
|
-
let
|
|
174
|
-
for (;
|
|
175
|
-
|
|
167
|
+
if (Y(e), o == null || o(e), e) {
|
|
168
|
+
const l = new Set(y), c = (t, r) => {
|
|
169
|
+
t.forEach((i) => {
|
|
170
|
+
if ((f || C)(i, e)) {
|
|
171
|
+
let A = r;
|
|
172
|
+
for (; A; )
|
|
173
|
+
l.add(A), A = L(w, A) || void 0;
|
|
176
174
|
}
|
|
177
|
-
|
|
175
|
+
i.children && c(i.children, i.id);
|
|
178
176
|
});
|
|
179
177
|
};
|
|
180
|
-
|
|
178
|
+
c(w), G(l);
|
|
181
179
|
}
|
|
182
180
|
},
|
|
183
|
-
[
|
|
184
|
-
), M =
|
|
185
|
-
({ node: e, level:
|
|
186
|
-
const
|
|
187
|
-
return /* @__PURE__ */
|
|
181
|
+
[y, f, C, L, w, G, o]
|
|
182
|
+
), M = h(
|
|
183
|
+
({ node: e, level: l }) => {
|
|
184
|
+
const c = S(e), t = !0, r = !!(e.children && e.children.length > 0);
|
|
185
|
+
return /* @__PURE__ */ k(
|
|
188
186
|
"div",
|
|
189
187
|
{
|
|
190
|
-
className:
|
|
188
|
+
className: Q([
|
|
191
189
|
"flex items-center gap-2 py-1.5",
|
|
192
190
|
"leading-none-medium-sm",
|
|
193
191
|
"text-text-neutral-primary"
|
|
194
192
|
]),
|
|
195
|
-
children: /* @__PURE__ */
|
|
193
|
+
children: /* @__PURE__ */ E(
|
|
196
194
|
"div",
|
|
197
195
|
{
|
|
198
|
-
className:
|
|
196
|
+
className: Q(["flex items-center gap-2"]),
|
|
199
197
|
role: "treeitem",
|
|
200
|
-
"aria-level":
|
|
201
|
-
"aria-expanded": r ?
|
|
202
|
-
"aria-checked":
|
|
203
|
-
style: { paddingLeft: `${
|
|
198
|
+
"aria-level": l + 1,
|
|
199
|
+
"aria-expanded": r ? t : void 0,
|
|
200
|
+
"aria-checked": c === "mixed" ? "mixed" : c === "checked",
|
|
201
|
+
style: { paddingLeft: `${l * 23 + 6}px` },
|
|
204
202
|
"data-testid": `tree-node-${e.id}`,
|
|
205
203
|
children: [
|
|
206
|
-
/* @__PURE__ */
|
|
204
|
+
/* @__PURE__ */ k(
|
|
207
205
|
"svg",
|
|
208
206
|
{
|
|
209
207
|
className: "self-start ml-auto",
|
|
@@ -212,26 +210,26 @@ const le = (N) => {
|
|
|
212
210
|
height: "9",
|
|
213
211
|
viewBox: "0 0 9 9",
|
|
214
212
|
fill: "none",
|
|
215
|
-
children: /* @__PURE__ */
|
|
213
|
+
children: /* @__PURE__ */ k("path", { d: "M1 1V1C1 4.86599 4.13401 8 8 8V8", stroke: "#E0E0E0", strokeLinecap: "round" })
|
|
216
214
|
}
|
|
217
215
|
),
|
|
218
|
-
/* @__PURE__ */
|
|
216
|
+
/* @__PURE__ */ k(
|
|
219
217
|
J,
|
|
220
218
|
{
|
|
221
|
-
checked:
|
|
222
|
-
onCheckedChange: () =>
|
|
223
|
-
disabled: e.disabled ||
|
|
219
|
+
checked: c === "checked" ? !0 : c === "mixed" ? "indeterminate" : !1,
|
|
220
|
+
onCheckedChange: () => D(e),
|
|
221
|
+
disabled: e.disabled || x,
|
|
224
222
|
"aria-label": `Select ${e.label}`
|
|
225
223
|
}
|
|
226
224
|
),
|
|
227
|
-
/* @__PURE__ */
|
|
225
|
+
/* @__PURE__ */ E(
|
|
228
226
|
"span",
|
|
229
227
|
{
|
|
230
228
|
className: "cursor-pointer select-none",
|
|
231
|
-
onClick: () => !e.disabled && !
|
|
229
|
+
onClick: () => !e.disabled && !x && D(e),
|
|
232
230
|
children: [
|
|
233
231
|
$ ? $(e) : e.label,
|
|
234
|
-
e.hint && /* @__PURE__ */
|
|
232
|
+
e.hint && /* @__PURE__ */ E("span", { children: [
|
|
235
233
|
" ",
|
|
236
234
|
e.hint
|
|
237
235
|
] })
|
|
@@ -245,9 +243,9 @@ const le = (N) => {
|
|
|
245
243
|
}
|
|
246
244
|
);
|
|
247
245
|
},
|
|
248
|
-
[
|
|
246
|
+
[S, x, D, $]
|
|
249
247
|
);
|
|
250
|
-
return /* @__PURE__ */
|
|
248
|
+
return /* @__PURE__ */ E(
|
|
251
249
|
"div",
|
|
252
250
|
{
|
|
253
251
|
role: "tree",
|
|
@@ -255,43 +253,43 @@ const le = (N) => {
|
|
|
255
253
|
"aria-label": K,
|
|
256
254
|
"aria-labelledby": O,
|
|
257
255
|
children: [
|
|
258
|
-
/* @__PURE__ */
|
|
256
|
+
/* @__PURE__ */ E(
|
|
259
257
|
"div",
|
|
260
258
|
{
|
|
261
|
-
className:
|
|
259
|
+
className: Q([
|
|
262
260
|
"flex items-center gap-2 justify-between",
|
|
263
261
|
"leading-none-medium-sm",
|
|
264
262
|
"text-text-neutral-primary"
|
|
265
263
|
]),
|
|
266
264
|
children: [
|
|
267
|
-
|
|
268
|
-
/* @__PURE__ */
|
|
265
|
+
p && /* @__PURE__ */ E("div", { role: "treeitem", "aria-level": 1, className: "flex items-center gap-2", children: [
|
|
266
|
+
/* @__PURE__ */ k(
|
|
269
267
|
J,
|
|
270
268
|
{
|
|
271
269
|
checked: H() === "checked" ? !0 : H() === "mixed" ? "indeterminate" : !1,
|
|
272
270
|
onCheckedChange: _,
|
|
273
|
-
disabled:
|
|
274
|
-
"aria-label":
|
|
271
|
+
disabled: x,
|
|
272
|
+
"aria-label": m
|
|
275
273
|
}
|
|
276
274
|
),
|
|
277
|
-
/* @__PURE__ */
|
|
275
|
+
/* @__PURE__ */ k("span", { children: m })
|
|
278
276
|
] }),
|
|
279
|
-
|
|
277
|
+
u && /* @__PURE__ */ k(
|
|
280
278
|
ee,
|
|
281
279
|
{
|
|
282
280
|
size: "small",
|
|
283
281
|
type: "text",
|
|
284
|
-
leftIcon: /* @__PURE__ */
|
|
285
|
-
placeholder:
|
|
282
|
+
leftIcon: /* @__PURE__ */ k(te, {}),
|
|
283
|
+
placeholder: a,
|
|
286
284
|
value: j,
|
|
287
285
|
onChange: (e) => q(e.target.value),
|
|
288
|
-
disabled:
|
|
286
|
+
disabled: x
|
|
289
287
|
}
|
|
290
288
|
)
|
|
291
289
|
]
|
|
292
290
|
}
|
|
293
291
|
),
|
|
294
|
-
/* @__PURE__ */
|
|
292
|
+
/* @__PURE__ */ k("div", { role: "group", children: N.map((e) => M(e)) })
|
|
295
293
|
]
|
|
296
294
|
}
|
|
297
295
|
);
|