@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 g, jsxs as w } from "react/jsx-runtime";
2
- import { useMemo as V, useCallback as d, useState as Q } from "react";
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 R } from "../../lib/utils.js";
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 = (N) => {
8
- const x = /* @__PURE__ */ new Map(), k = [];
9
- N.forEach((s) => {
10
- const h = s.key.split(".");
11
- let n = "";
12
- h.forEach((o, p) => {
13
- const m = p === h.length - 1;
14
- if (n = n ? `${n}.${o}` : o, x.has(n)) {
15
- if (m) {
16
- const b = x.get(n);
17
- b.label = s.label, b.disabled = s.disabled, b.hint = s.hint, b.isLeaf = !0;
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 b = {
21
- id: n,
22
- label: m ? s.label : o,
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: m ? s.disabled : void 0,
26
- hint: m ? s.hint : void 0,
27
- isLeaf: m
25
+ disabled: p ? s.disabled : void 0,
26
+ hint: p ? s.hint : void 0,
27
+ isLeaf: p
28
28
  };
29
- x.set(n, b);
29
+ g.set(a, m);
30
30
  }
31
31
  });
32
- }), x.forEach((s, h) => {
33
- const n = h.split(".");
34
- if (n.length === 1)
35
- k.push(s);
32
+ }), g.forEach((s, u) => {
33
+ const a = u.split(".");
34
+ if (a.length === 1)
35
+ v.push(s);
36
36
  else {
37
- const o = n.slice(0, -1).join("."), p = x.get(o);
38
- p && !p.children.find((m) => m.id === s.id) && p.children.push(s);
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 c = (s) => s.sort((h, n) => h.label.localeCompare(n.label)).map((h) => ({
42
- ...h,
43
- children: h.children && h.children.length > 0 ? c(h.children) : void 0
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 c(k);
45
+ return n(v);
46
46
  }, de = ({
47
- items: N,
48
- defaultValue: x = [],
49
- onChange: k,
50
- selectionMode: c = "all-nodes",
47
+ items: I,
48
+ defaultValue: g = [],
49
+ onChange: v,
50
+ selectionMode: n = "all-nodes",
51
51
  defaultExpandedIds: s,
52
- searchable: h = !0,
53
- searchPlaceholder: n = "Search items...",
54
- filterFn: o,
55
- onSearchChange: p,
56
- showSelectAll: m = !0,
57
- selectAllLabel: b = "Select all",
58
- cascade: z = !0,
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: v = !1
62
+ disabled: x = !1
63
63
  }) => {
64
- const S = V(() => le(N), [N]), U = d((e) => e.map((t) => t.id), []), [f, W] = Q(new Set(x)), [I, X] = Q(
65
- new Set(s || U(S))
66
- ), [j, Y] = Q(""), C = d(
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 t = [], i = (l) => {
69
- l.children && l.children.forEach((r) => {
70
- r.disabled || (c === "leaves-only" ? (!r.children || r.children.length === 0) && t.push(r.id) : t.push(r.id)), i(r);
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 i(e), t;
73
+ return c(e), l;
74
74
  },
75
- [c]
76
- ), L = d(
77
- (e, t, i) => {
78
- for (const l of e) {
79
- if (l.id === t) return i || null;
80
- if (l.children) {
81
- const r = L(l.children, t, l.id);
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
- ), y = d((e, t) => e.label.toLowerCase().includes(t.toLowerCase()), []), F = d(
89
- (e, t) => {
90
- if (!t) return e;
91
- const i = o || y, l = (u) => i(u, t) ? !0 : u.children ? u.children.some((a) => l(a)) : !1, r = (u) => u.filter((a) => l(a)).map((a) => i(a, t) ? a.children && a.children.length > 0 ? {
92
- ...a,
93
- children: a.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
- } : a : {
96
- ...a,
97
- children: a.children ? r(a.children) : void 0
95
+ } : d : {
96
+ ...d,
97
+ children: d.children ? r(d.children) : void 0
98
98
  });
99
99
  return r(e);
100
100
  },
101
- [o, y]
102
- ), Z = V(() => F(S, j), [S, j, F]), B = d(
103
- (e, t = 0) => {
104
- const i = [];
105
- return e.forEach((l) => {
106
- const r = !!(l.children && l.children.length > 0), u = I.has(l.id);
107
- i.push({
108
- node: l,
109
- level: t,
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: u && l.children ? l.children.length : 0
112
- }), u && l.children && i.push(...B(l.children, t + 1));
113
- }), i;
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
- [I]
116
- ), E = V(() => B(Z), [Z, B]), P = d(
115
+ [y]
116
+ ), N = T(() => B(Z), [Z, B]), S = h(
117
117
  (e) => {
118
- const t = f.has(e.id);
118
+ const l = b.has(e.id);
119
119
  if (!e.children || e.children.length === 0)
120
- return t ? "checked" : "unchecked";
121
- const i = C(e);
122
- if (i.length === 0)
123
- return t ? "checked" : "unchecked";
124
- const l = i.filter((r) => f.has(r));
125
- return l.length === 0 ? t && c === "all-nodes" ? "checked" : "unchecked" : l.length === i.length ? "checked" : "mixed";
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
- [f, C, c]
128
- ), A = d(
127
+ [b, n]
128
+ ), P = h(
129
129
  (e) => {
130
- W(e), k == null || k(Array.from(e));
130
+ W(e), v == null || v(Array.from(e));
131
131
  },
132
- [k]
133
- ), G = d((e) => {
132
+ [v]
133
+ ), G = h((e) => {
134
134
  X(e);
135
- }, []), T = d(
135
+ }, []), D = h(
136
136
  (e) => {
137
- if (e.disabled || v) return;
138
- const t = new Set(f), i = P(e);
139
- if (z && e.children && e.children.length > 0) {
140
- const l = C(e);
141
- i === "checked" ? (l.forEach((r) => t.delete(r)), c === "all-nodes" && t.delete(e.id)) : (l.forEach((r) => t.add(r)), c === "all-nodes" && t.add(e.id));
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
- (c === "all-nodes" || !e.children || e.children.length === 0) && (f.has(e.id) ? t.delete(e.id) : t.add(e.id));
144
- A(t);
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
- f,
148
- P,
147
+ b,
148
+ S,
149
+ R,
150
+ n,
149
151
  z,
150
- c,
151
- C,
152
- v,
153
- A
152
+ x,
153
+ P
154
154
  ]
155
- ), _ = d(() => {
156
- const t = E.filter(
157
- ({ node: r }) => !r.disabled && (c === "all-nodes" || !r.children || r.children.length === 0)
158
- ).map(({ node: r }) => r.id), i = t.every((r) => f.has(r)), l = new Set(f);
159
- i ? t.forEach((r) => l.delete(r)) : t.forEach((r) => l.add(r)), A(l);
160
- }, [E, f, c, A]), H = d(() => {
161
- const e = E.filter(
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 t = e.map(({ node: l }) => l.id), i = t.filter((l) => f.has(l)).length;
166
- return i === 0 ? "unchecked" : i === t.length ? "checked" : "mixed";
167
- }, [E, f, c]), q = d(
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), p == null || p(e), e) {
170
- const t = new Set(I), i = (l, r) => {
171
- l.forEach((u) => {
172
- if ((o || y)(u, e)) {
173
- let D = r;
174
- for (; D; )
175
- t.add(D), D = L(S, D) || void 0;
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
- u.children && i(u.children, u.id);
175
+ i.children && c(i.children, i.id);
178
176
  });
179
177
  };
180
- i(S), G(t);
178
+ c(w), G(l);
181
179
  }
182
180
  },
183
- [I, o, y, L, S, G, p]
184
- ), M = d(
185
- ({ node: e, level: t }) => {
186
- const i = P(e), l = !0, r = !!(e.children && e.children.length > 0);
187
- return /* @__PURE__ */ g(
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: R([
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__ */ w(
193
+ children: /* @__PURE__ */ E(
196
194
  "div",
197
195
  {
198
- className: R(["flex items-center gap-2"]),
196
+ className: Q(["flex items-center gap-2"]),
199
197
  role: "treeitem",
200
- "aria-level": t + 1,
201
- "aria-expanded": r ? l : void 0,
202
- "aria-checked": i === "mixed" ? "mixed" : i === "checked",
203
- style: { paddingLeft: `${t * 23 + 6}px` },
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__ */ g(
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__ */ g("path", { d: "M1 1V1C1 4.86599 4.13401 8 8 8V8", stroke: "#E0E0E0", strokeLinecap: "round" })
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__ */ g(
216
+ /* @__PURE__ */ k(
219
217
  J,
220
218
  {
221
- checked: i === "checked" ? !0 : i === "mixed" ? "indeterminate" : !1,
222
- onCheckedChange: () => T(e),
223
- disabled: e.disabled || v,
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__ */ w(
225
+ /* @__PURE__ */ E(
228
226
  "span",
229
227
  {
230
228
  className: "cursor-pointer select-none",
231
- onClick: () => !e.disabled && !v && T(e),
229
+ onClick: () => !e.disabled && !x && D(e),
232
230
  children: [
233
231
  $ ? $(e) : e.label,
234
- e.hint && /* @__PURE__ */ w("span", { children: [
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
- [P, v, T, $]
246
+ [S, x, D, $]
249
247
  );
250
- return /* @__PURE__ */ w(
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__ */ w(
256
+ /* @__PURE__ */ E(
259
257
  "div",
260
258
  {
261
- className: R([
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
- m && /* @__PURE__ */ w("div", { role: "treeitem", "aria-level": 1, className: "flex items-center gap-2", children: [
268
- /* @__PURE__ */ g(
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: v,
274
- "aria-label": b
271
+ disabled: x,
272
+ "aria-label": m
275
273
  }
276
274
  ),
277
- /* @__PURE__ */ g("span", { children: b })
275
+ /* @__PURE__ */ k("span", { children: m })
278
276
  ] }),
279
- h && /* @__PURE__ */ g(
277
+ u && /* @__PURE__ */ k(
280
278
  ee,
281
279
  {
282
280
  size: "small",
283
281
  type: "text",
284
- leftIcon: /* @__PURE__ */ g(te, {}),
285
- placeholder: n,
282
+ leftIcon: /* @__PURE__ */ k(te, {}),
283
+ placeholder: a,
286
284
  value: j,
287
285
  onChange: (e) => q(e.target.value),
288
- disabled: v
286
+ disabled: x
289
287
  }
290
288
  )
291
289
  ]
292
290
  }
293
291
  ),
294
- /* @__PURE__ */ g("div", { role: "group", children: E.map((e) => M(e)) })
292
+ /* @__PURE__ */ k("div", { role: "group", children: N.map((e) => M(e)) })
295
293
  ]
296
294
  }
297
295
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztwoint/z-ui",
3
- "version": "0.1.136",
3
+ "version": "0.1.137",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",