asterui 0.12.24 → 0.12.26

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/index94.js CHANGED
@@ -1,483 +1,566 @@
1
- import { jsx as b, jsxs as F } from "react/jsx-runtime";
2
- import { forwardRef as Je, useId as Qe, useState as H, useRef as de, useMemo as se, useCallback as P, useEffect as ue } from "react";
3
- function d(t, a, u) {
4
- if (a === "title") {
5
- const l = u?.label || "title";
6
- return t[l];
1
+ import { jsx as v, jsxs as z } from "react/jsx-runtime";
2
+ import rn, { forwardRef as sn, useId as on, useState as F, useRef as be, useMemo as oe, useCallback as T, useEffect as ve } from "react";
3
+ const cn = "SHOW_ALL", ln = "SHOW_PARENT", an = "SHOW_CHILD";
4
+ function u(r, d, p) {
5
+ if (d === "title") {
6
+ const l = p?.label || "title";
7
+ return r[l];
7
8
  }
8
- if (a === "key") {
9
- const l = u?.value || "key";
10
- return t[l];
9
+ if (d === "key") {
10
+ const l = p?.value || "key";
11
+ return r[l];
11
12
  }
12
- if (a === "children") {
13
- const l = u?.children || "children";
14
- return t[l];
13
+ if (d === "children") {
14
+ const l = p?.children || "children";
15
+ return r[l];
15
16
  }
16
17
  }
17
- function Ie(t, a = [], u) {
18
+ function Me(r, d = [], p) {
18
19
  const l = [];
19
- return t.forEach((h) => {
20
- const p = d(h, "title", u), y = d(h, "children", u), w = [...a, p];
21
- l.push({ node: h, path: w }), y && l.push(...Ie(y, w, u));
20
+ return r.forEach((f) => {
21
+ const b = u(f, "title", p), g = u(f, "children", p), k = [...d, b];
22
+ l.push({ node: f, path: k }), g && l.push(...Me(g, k, p));
22
23
  }), l;
23
24
  }
24
- function Xe(t, a) {
25
- const u = [], l = (h) => {
26
- h.forEach((p) => {
27
- const y = d(p, "key", a), w = d(p, "children", a);
28
- u.push(y), w && l(w);
25
+ function un(r, d) {
26
+ const p = [], l = (f) => {
27
+ f.forEach((b) => {
28
+ const g = u(b, "key", d), k = u(b, "children", d);
29
+ p.push(g), k && l(k);
29
30
  });
30
31
  };
31
- return l(t), u;
32
+ return l(r), p;
32
33
  }
33
- function I(t, a, u) {
34
- for (const l of t) {
35
- const h = d(l, "key", u), p = d(l, "children", u);
36
- if (h === a) return l;
37
- if (p) {
38
- const y = I(p, a, u);
39
- if (y) return y;
34
+ function $(r, d, p) {
35
+ for (const l of r) {
36
+ const f = u(l, "key", p), b = u(l, "children", p);
37
+ if (f === d) return l;
38
+ if (b) {
39
+ const g = $(b, d, p);
40
+ if (g) return g;
40
41
  }
41
42
  }
42
43
  return null;
43
44
  }
44
- function $e(t, a) {
45
- const u = [], l = (h) => {
46
- const p = d(h, "children", a);
47
- p && p.forEach((y) => {
48
- const w = d(y, "key", a);
49
- u.push(w), l(y);
45
+ function Oe(r, d) {
46
+ const p = [], l = (f) => {
47
+ const b = u(f, "children", d);
48
+ b && b.forEach((g) => {
49
+ const k = u(g, "key", d);
50
+ p.push(k), l(g);
50
51
  });
51
52
  };
52
- return l(t), u;
53
+ return l(r), p;
53
54
  }
54
- function fe(t, a, u, l = []) {
55
- for (const h of t) {
56
- const p = d(h, "key", u), y = d(h, "children", u);
57
- if (p === a) return l;
58
- if (y) {
59
- const w = fe(y, a, u, [...l, p]);
60
- if (w) return w;
55
+ function ge(r, d, p, l = []) {
56
+ for (const f of r) {
57
+ const b = u(f, "key", p), g = u(f, "children", p);
58
+ if (b === d) return l;
59
+ if (g) {
60
+ const k = ge(g, d, p, [...l, b]);
61
+ if (k) return k;
61
62
  }
62
63
  }
63
64
  return null;
64
65
  }
65
- function Ye({
66
- node: t,
67
- level: a,
68
- expanded: u,
66
+ function dn({
67
+ node: r,
68
+ level: d,
69
+ expanded: p,
69
70
  selected: l,
70
- checked: h,
71
- indeterminate: p,
72
- treeCheckable: y,
73
- treeLine: w,
74
- focused: O,
75
- loading: E,
76
- baseTestId: ie,
77
- id: z,
78
- fieldNames: V,
79
- switcherIcon: B,
80
- onToggle: S,
81
- onSelect: Q,
82
- onCheck: T,
83
- renderChildren: U
71
+ checked: f,
72
+ indeterminate: b,
73
+ treeCheckable: g,
74
+ treeLine: k,
75
+ treeIcon: V,
76
+ focused: H,
77
+ loading: ce,
78
+ baseTestId: U,
79
+ id: le,
80
+ fieldNames: q,
81
+ switcherIcon: L,
82
+ onToggle: X,
83
+ onSelect: Y,
84
+ onCheck: M,
85
+ renderChildren: Z
84
86
  }) {
85
- const C = d(t, "children", V), q = d(t, "title", V), M = d(t, "key", V), W = C && C.length > 0, L = t.isLeaf ?? !W, R = (k) => {
86
- k.stopPropagation(), L || S(M);
87
- }, X = () => {
88
- t.disabled || (y ? T(M, t) : Q(M, t));
89
- }, Y = (k) => {
90
- k.stopPropagation(), t.disabled || T(M, t);
91
- }, G = (k) => {
92
- (k.key === "Enter" || k.key === " ") && (k.preventDefault(), X());
93
- }, s = () => E ? /* @__PURE__ */ b("span", { className: "loading loading-spinner loading-xs" }) : B ? typeof B == "function" ? B({ expanded: u }) : B : /* @__PURE__ */ b(
87
+ const C = u(r, "children", q), P = u(r, "title", q), W = u(r, "key", q), D = r.icon, G = C && C.length > 0, E = r.isLeaf ?? !G, B = (K) => {
88
+ K.stopPropagation(), E || X(W);
89
+ }, m = () => {
90
+ r.disabled || (g ? M(W, r) : Y(W, r));
91
+ }, j = (K) => {
92
+ K.stopPropagation(), r.disabled || M(W, r);
93
+ }, J = (K) => {
94
+ (K.key === "Enter" || K.key === " ") && (K.preventDefault(), m());
95
+ }, N = () => ce ? /* @__PURE__ */ v("span", { className: "loading loading-spinner loading-xs" }) : L ? typeof L == "function" ? L({ expanded: p }) : L : /* @__PURE__ */ v(
94
96
  "svg",
95
97
  {
96
- className: `w-3 h-3 transition-transform ${u ? "rotate-90" : ""}`,
98
+ className: `w-3 h-3 transition-transform ${p ? "rotate-90" : ""}`,
97
99
  fill: "none",
98
100
  viewBox: "0 0 24 24",
99
101
  stroke: "currentColor",
100
102
  "aria-hidden": "true",
101
- children: /* @__PURE__ */ b("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" })
103
+ children: /* @__PURE__ */ v("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" })
102
104
  }
103
105
  );
104
- return /* @__PURE__ */ F(
106
+ return /* @__PURE__ */ z(
105
107
  "div",
106
108
  {
107
109
  className: "tree-select-node",
108
110
  role: "treeitem",
109
- id: z,
110
- "aria-selected": l || h,
111
- "aria-expanded": W ? u : void 0,
112
- "data-testid": `${ie}-option-${M}`,
113
- "data-state": l || h ? "selected" : "unselected",
114
- "data-disabled": t.disabled || void 0,
111
+ id: le,
112
+ "aria-selected": l || f,
113
+ "aria-expanded": G ? p : void 0,
114
+ "data-testid": `${U}-option-${W}`,
115
+ "data-state": l || f ? "selected" : "unselected",
116
+ "data-disabled": r.disabled || void 0,
115
117
  children: [
116
- /* @__PURE__ */ F(
118
+ /* @__PURE__ */ z(
117
119
  "div",
118
120
  {
119
121
  className: [
120
122
  "flex items-center py-1.5 px-2 cursor-pointer hover:bg-base-200 transition-colors outline-none",
121
- (l || h) && "bg-primary/10 text-primary",
122
- t.disabled && "opacity-50 cursor-not-allowed",
123
- O && "ring-2 ring-primary ring-inset",
124
- w && a > 0 && "border-l border-base-300 ml-2"
123
+ (l || f) && "bg-primary/10 text-primary",
124
+ r.disabled && "opacity-50 cursor-not-allowed",
125
+ H && "ring-2 ring-primary ring-inset",
126
+ k && d > 0 && "border-l border-base-300 ml-2"
125
127
  ].filter(Boolean).join(" "),
126
- style: { paddingLeft: `${a * 16 + 8}px` },
127
- onClick: X,
128
- onKeyDown: G,
128
+ style: { paddingLeft: `${d * 16 + 8}px` },
129
+ onClick: m,
130
+ onKeyDown: J,
129
131
  tabIndex: -1,
130
132
  children: [
131
- /* @__PURE__ */ b(
133
+ /* @__PURE__ */ v(
132
134
  "span",
133
135
  {
134
136
  className: [
135
137
  "w-4 h-4 flex items-center justify-center flex-shrink-0 mr-1",
136
- !L && "cursor-pointer"
138
+ !E && "cursor-pointer"
137
139
  ].filter(Boolean).join(" "),
138
- onClick: R,
140
+ onClick: B,
139
141
  "aria-hidden": "true",
140
- children: !L && s()
142
+ children: !E && N()
141
143
  }
142
144
  ),
143
- y && /* @__PURE__ */ b("span", { className: "mr-2 flex-shrink-0", onClick: Y, children: /* @__PURE__ */ b(
145
+ g && /* @__PURE__ */ v("span", { className: "mr-2 flex-shrink-0", onClick: j, children: /* @__PURE__ */ v(
144
146
  "input",
145
147
  {
146
148
  type: "checkbox",
147
149
  className: "checkbox checkbox-sm checkbox-primary",
148
- checked: h,
149
- ref: (k) => {
150
- k && (k.indeterminate = p);
150
+ checked: f,
151
+ ref: (K) => {
152
+ K && (K.indeterminate = b);
151
153
  },
152
- disabled: t.disabled,
153
- onChange: X,
154
- "aria-label": typeof q == "string" ? q : void 0,
154
+ disabled: r.disabled,
155
+ onChange: m,
156
+ "aria-label": typeof P == "string" ? P : void 0,
155
157
  tabIndex: -1
156
158
  }
157
159
  ) }),
158
- /* @__PURE__ */ b("span", { className: "flex-1 truncate select-none text-sm", children: q })
160
+ V && D && /* @__PURE__ */ v("span", { className: "mr-1.5 flex-shrink-0 flex items-center", children: D }),
161
+ /* @__PURE__ */ v("span", { className: "flex-1 truncate select-none text-sm", children: P })
159
162
  ]
160
163
  }
161
164
  ),
162
- W && u && /* @__PURE__ */ b("div", { role: "group", children: U(C, a + 1) })
165
+ G && p && /* @__PURE__ */ v("div", { role: "group", children: Z(C, d + 1) })
163
166
  ]
164
167
  }
165
168
  );
166
169
  }
167
- const Ze = {
170
+ const fn = {
168
171
  xs: "min-h-6 text-xs",
169
172
  sm: "min-h-8 text-sm",
170
173
  md: "min-h-10 text-base",
171
174
  lg: "min-h-12 text-lg",
172
175
  xl: "min-h-14 text-xl"
173
- }, De = {
176
+ }, hn = {
174
177
  primary: "border-primary focus-within:border-primary",
175
178
  secondary: "border-secondary focus-within:border-secondary",
176
179
  accent: "border-accent focus-within:border-accent",
180
+ neutral: "border-neutral focus-within:border-neutral",
177
181
  info: "border-info focus-within:border-info",
178
182
  success: "border-success focus-within:border-success",
179
183
  warning: "border-warning focus-within:border-warning",
180
184
  error: "border-error focus-within:border-error"
181
- }, Ne = {
185
+ }, pn = {
182
186
  error: "border-error focus-within:border-error",
183
187
  warning: "border-warning focus-within:border-warning"
184
- }, en = Je(
188
+ }, bn = {
189
+ outlined: "border border-base-300",
190
+ filled: "bg-base-200 border-transparent",
191
+ borderless: "border-transparent"
192
+ }, Pe = sn(
185
193
  ({
186
- treeData: t,
187
- value: a,
188
- defaultValue: u = [],
194
+ treeData: r,
195
+ value: d,
196
+ defaultValue: p = [],
189
197
  onChange: l,
190
- multiple: h = !1,
191
- treeCheckable: p = !1,
192
- treeCheckStrictly: y = !1,
193
- showCheckedStrategy: w = "SHOW_ALL",
194
- showSearch: O = !1,
195
- searchValue: E,
196
- onSearch: ie,
197
- filterTreeNode: z,
198
- placeholder: V = "Please select",
199
- allowClear: B = !0,
200
- disabled: S = !1,
201
- treeDefaultExpandAll: Q = !1,
202
- treeDefaultExpandedKeys: T = [],
203
- treeExpandedKeys: U,
204
- onTreeExpand: C,
205
- size: q = "md",
206
- color: M,
198
+ multiple: f = !1,
199
+ treeCheckable: b = !1,
200
+ treeCheckStrictly: g = !1,
201
+ showCheckedStrategy: k = "SHOW_ALL",
202
+ showSearch: V = !1,
203
+ searchValue: H,
204
+ onSearch: ce,
205
+ filterTreeNode: U,
206
+ placeholder: le = "Please select",
207
+ allowClear: q = !0,
208
+ disabled: L = !1,
209
+ treeDefaultExpandAll: X = !1,
210
+ treeDefaultExpandedKeys: Y = [],
211
+ treeExpandedKeys: M,
212
+ onTreeExpand: Z,
213
+ size: C = "md",
214
+ color: P,
207
215
  status: W,
208
- maxTagCount: L,
209
- maxTagPlaceholder: R,
210
- labelInValue: X = !1,
211
- treeLine: Y = !1,
212
- loadData: G,
213
- fieldNames: s,
214
- open: k,
215
- onDropdownVisibleChange: he,
216
- suffixIcon: Ee,
217
- switcherIcon: pe,
218
- notFoundContent: Se = "No results found",
219
- dropdownRender: be,
220
- popupClassName: Me = "",
221
- className: je = "",
222
- "data-testid": Ae,
223
- ..._e
224
- }, Z) => {
225
- const K = Ae ?? "treeselect", D = Qe(), ge = `${D}-listbox`, [Be, Ce] = H(!1), [We, N] = H(""), [x, j] = H(null), [ye, ve] = H(/* @__PURE__ */ new Set()), oe = de(null), ce = de(null), ee = de(null), J = E ?? We, v = k ?? Be, xe = (e) => e === void 0 ? [] : Array.isArray(e) ? e : [e], Re = xe(u), [He, ne] = H(Re), f = a !== void 0 ? xe(a) : He, Pe = se(() => Q ? Xe(t, s) : T, [t, Q, T, s]), [Fe, Oe] = H(Pe), $ = U ?? Fe, m = se(() => {
226
- const e = [], r = (o) => {
227
- o.forEach((n) => {
228
- const i = d(n, "key", s), c = d(n, "children", s);
229
- e.push({ key: i, node: n }), c && $.includes(i) && r(c);
216
+ variant: D = "outlined",
217
+ ghost: G = !1,
218
+ maxTagCount: E,
219
+ maxTagPlaceholder: B,
220
+ maxCount: m,
221
+ labelInValue: j = !1,
222
+ tagRender: J,
223
+ treeLine: N = !1,
224
+ treeIcon: K = !1,
225
+ loadData: ae,
226
+ fieldNames: i,
227
+ open: ue,
228
+ onDropdownVisibleChange: ye,
229
+ suffixIcon: Be,
230
+ switcherIcon: we,
231
+ notFoundContent: Re = "No results found",
232
+ dropdownRender: xe,
233
+ popupClassName: Fe = "",
234
+ className: Te = "",
235
+ "data-testid": ze,
236
+ ...Ve
237
+ }, ee) => {
238
+ const _ = ze ?? "treeselect", ne = on(), ke = `${ne}-listbox`, [Ue, qe] = F(!1), [Ce, te] = F(""), [w, I] = F(null), [Le, me] = F(/* @__PURE__ */ new Set()), de = be(null), fe = be(null), re = be(null), Q = H ?? Ce, y = ue ?? Ue, Ke = (e) => e === void 0 ? [] : Array.isArray(e) ? e.map((n) => typeof n == "object" && n !== null ? n.value : n) : typeof e == "object" && e !== null ? [e.value] : [e], Ge = Ke(p), [Je, se] = F(Ge), h = d !== void 0 ? Ke(d) : Je, Qe = oe(() => X ? un(r, i) : Y, [r, X, Y, i]), [Xe, Ye] = F(Qe), A = M ?? Xe, S = oe(() => {
239
+ const e = [], n = (c) => {
240
+ c.forEach((t) => {
241
+ const o = u(t, "key", i), s = u(t, "children", i);
242
+ e.push({ key: o, node: t }), s && A.includes(o) && n(s);
230
243
  });
231
244
  };
232
- return r(t), e;
233
- }, [t, $, s]), A = P(
245
+ return n(r), e;
246
+ }, [r, A, i]), O = T(
234
247
  (e) => {
235
- k === void 0 && Ce(e), he?.(e);
248
+ ue === void 0 && qe(e), ye?.(e);
236
249
  },
237
- [k, he]
250
+ [ue, ye]
238
251
  );
239
- ue(() => {
240
- const e = (r) => {
241
- oe.current && !oe.current.contains(r.target) && (A(!1), E === void 0 && N(""));
252
+ ve(() => {
253
+ const e = (n) => {
254
+ de.current && !de.current.contains(n.target) && (O(!1), H === void 0 && te(""));
242
255
  };
243
256
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
244
- }, [A, E]), ue(() => {
245
- v && O && ce.current ? ce.current.focus() : v && ee.current && ee.current.focus();
246
- }, [v, O]), ue(() => {
247
- v && m.length > 0 ? f.length > 0 ? j(f[0]) : j(m[0].key) : v || j(null);
248
- }, [v, m, f]);
249
- const we = se(() => {
250
- if (!J) return t;
251
- const e = Ie(t, [], s), r = /* @__PURE__ */ new Set();
252
- e.forEach(({ node: n }) => {
253
- const i = d(n, "title", s), c = d(n, "key", s);
254
- let g = !1;
255
- z ? g = z(J, n) : g = (typeof i == "string" ? i : String(i)).toLowerCase().includes(J.toLowerCase()), g && r.add(c);
257
+ }, [O, H]), ve(() => {
258
+ y && V && fe.current ? fe.current.focus() : y && re.current && re.current.focus();
259
+ }, [y, V]), ve(() => {
260
+ y && S.length > 0 ? h.length > 0 ? I(h[0]) : I(S[0].key) : y || I(null);
261
+ }, [y, S, h]);
262
+ const $e = oe(() => {
263
+ if (!Q) return r;
264
+ const e = Me(r, [], i), n = /* @__PURE__ */ new Set();
265
+ e.forEach(({ node: t }) => {
266
+ const o = u(t, "title", i), s = u(t, "key", i);
267
+ let a = !1;
268
+ U ? a = U(Q, t) : a = (typeof o == "string" ? o : String(o)).toLowerCase().includes(Q.toLowerCase()), a && n.add(s);
256
269
  });
257
- const o = (n) => n.map((i) => {
258
- const c = d(i, "children", s), g = d(i, "key", s), _ = c && o(c).length > 0;
259
- return r.has(g) || _ ? {
260
- ...i,
261
- children: c ? o(c) : void 0
270
+ const c = (t) => t.map((o) => {
271
+ const s = u(o, "children", i), a = u(o, "key", i), x = s && c(s).length > 0;
272
+ return n.has(a) || x ? {
273
+ ...o,
274
+ children: s ? c(s) : void 0
262
275
  } : null;
263
276
  }).filter(Boolean);
264
- return o(t);
265
- }, [t, J, z, s]), te = P(
277
+ return c(r);
278
+ }, [r, Q, U, i]), ie = T(
266
279
  async (e) => {
267
- const r = I(t, e, s);
268
- if (G && r) {
269
- const n = d(r, "children", s);
270
- if (!n || n.length === 0) {
271
- ve((i) => new Set(i).add(e));
280
+ const n = $(r, e, i);
281
+ if (ae && n) {
282
+ const t = u(n, "children", i);
283
+ if (!t || t.length === 0) {
284
+ me((o) => new Set(o).add(e));
272
285
  try {
273
- await G(r);
286
+ await ae(n);
274
287
  } finally {
275
- ve((i) => {
276
- const c = new Set(i);
277
- return c.delete(e), c;
288
+ me((o) => {
289
+ const s = new Set(o);
290
+ return s.delete(e), s;
278
291
  });
279
292
  }
280
293
  }
281
294
  }
282
- const o = $.includes(e) ? $.filter((n) => n !== e) : [...$, e];
283
- U === void 0 && Oe(o), C?.(o);
295
+ const c = A.includes(e) ? A.filter((t) => t !== e) : [...A, e];
296
+ M === void 0 && Ye(c), Z?.(c);
284
297
  },
285
- [$, U, C, G, t, s]
286
- ), le = P(
287
- (e, r) => {
288
- let o;
289
- h ? f.includes(e) ? o = f.filter((i) => i !== e) : o = [...f, e] : (o = [e], A(!1), E === void 0 && N("")), a === void 0 && ne(o);
290
- const n = o.map((i) => {
291
- const c = I(t, i, s);
292
- return c ? d(c, "title", s) : i;
298
+ [A, M, Z, ae, r, i]
299
+ ), he = T(
300
+ (e, n) => {
301
+ let c;
302
+ if (f)
303
+ if (h.includes(e))
304
+ c = h.filter((o) => o !== e);
305
+ else {
306
+ if (m !== void 0 && h.length >= m)
307
+ return;
308
+ c = [...h, e];
309
+ }
310
+ else
311
+ c = [e], O(!1), H === void 0 && te("");
312
+ d === void 0 && se(c);
313
+ const t = c.map((o) => {
314
+ const s = $(r, o, i);
315
+ return s ? u(s, "title", i) : o;
293
316
  });
294
- l?.(h ? o : o[0] || "", n);
317
+ if (j) {
318
+ const o = c.map((s) => {
319
+ const a = $(r, s, i);
320
+ return {
321
+ value: s,
322
+ label: a ? u(a, "title", i) : s
323
+ };
324
+ });
325
+ l?.(
326
+ f ? o : o[0] || { value: "", label: "" },
327
+ t,
328
+ { triggerValue: e, triggerNode: n }
329
+ );
330
+ } else
331
+ l?.(f ? c : c[0] || "", t, { triggerValue: e, triggerNode: n });
295
332
  },
296
333
  [
297
- f,
298
334
  h,
299
- a,
335
+ f,
336
+ m,
337
+ d,
300
338
  l,
301
- t,
302
- A,
303
- E,
304
- s
339
+ r,
340
+ O,
341
+ H,
342
+ i,
343
+ j
305
344
  ]
306
- ), ae = P(
307
- (e, r) => {
308
- const o = f.includes(e);
309
- let n = [...f];
310
- if (y)
311
- o ? n = n.filter((c) => c !== e) : n.push(e);
345
+ ), pe = T(
346
+ (e, n) => {
347
+ const c = h.includes(e);
348
+ let t = [...h];
349
+ if (g)
350
+ if (c)
351
+ t = t.filter((s) => s !== e);
352
+ else {
353
+ if (m !== void 0 && h.length >= m)
354
+ return;
355
+ t.push(e);
356
+ }
312
357
  else {
313
- const c = $e(r, s);
314
- o ? n = n.filter((g) => g !== e && !c.includes(g)) : (n.push(e), c.forEach((g) => {
315
- n.includes(g) || n.push(g);
316
- }));
358
+ const s = Oe(n, i);
359
+ if (c)
360
+ t = t.filter((a) => a !== e && !s.includes(a));
361
+ else {
362
+ const a = [e, ...s.filter((x) => !t.includes(x))];
363
+ if (m !== void 0 && t.length + a.length > m) {
364
+ const x = m - t.length;
365
+ if (x <= 0) return;
366
+ a.slice(0, x).forEach((R) => t.push(R));
367
+ } else
368
+ t.push(e), s.forEach((x) => {
369
+ t.includes(x) || t.push(x);
370
+ });
371
+ }
317
372
  }
318
- a === void 0 && ne(n);
319
- const i = n.map((c) => {
320
- const g = I(t, c, s);
321
- return g ? d(g, "title", s) : c;
373
+ d === void 0 && se(t);
374
+ const o = t.map((s) => {
375
+ const a = $(r, s, i);
376
+ return a ? u(a, "title", i) : s;
322
377
  });
323
- l?.(n, i);
378
+ if (j) {
379
+ const s = t.map((a) => {
380
+ const x = $(r, a, i);
381
+ return {
382
+ value: a,
383
+ label: x ? u(x, "title", i) : a
384
+ };
385
+ });
386
+ l?.(s, o, { triggerValue: e, triggerNode: n });
387
+ } else
388
+ l?.(t, o, { triggerValue: e, triggerNode: n });
324
389
  },
325
- [f, a, l, t, y, s]
326
- ), ze = (e) => {
390
+ [h, d, l, r, g, i, m, j]
391
+ ), Ze = (e) => {
327
392
  e.stopPropagation();
328
- const r = [];
329
- a === void 0 && ne(r), l?.(h || p ? r : "", []);
330
- }, Ve = (e, r) => {
331
- r.stopPropagation();
332
- const o = f.filter((i) => i !== e);
333
- a === void 0 && ne(o);
334
- const n = o.map((i) => {
335
- const c = I(t, i, s);
336
- return c ? d(c, "title", s) : i;
393
+ const n = [];
394
+ d === void 0 && se(n), j ? l?.(f || b ? [] : { value: "", label: "" }, []) : l?.(f || b ? n : "", []);
395
+ }, Se = (e, n) => {
396
+ n.stopPropagation();
397
+ const c = h.filter((o) => o !== e);
398
+ d === void 0 && se(c);
399
+ const t = c.map((o) => {
400
+ const s = $(r, o, i);
401
+ return s ? u(s, "title", i) : o;
337
402
  });
338
- l?.(h || p ? o : o[0] || "", n);
339
- }, Te = (e) => {
340
- const r = e.target.value;
341
- E === void 0 && N(r), ie?.(r);
342
- }, Ue = (e) => {
343
- if (!S)
403
+ if (j) {
404
+ const o = c.map((s) => {
405
+ const a = $(r, s, i);
406
+ return {
407
+ value: s,
408
+ label: a ? u(a, "title", i) : s
409
+ };
410
+ });
411
+ l?.(
412
+ f || b ? o : o[0] || { value: "", label: "" },
413
+ t
414
+ );
415
+ } else
416
+ l?.(f || b ? c : c[0] || "", t);
417
+ }, De = (e) => {
418
+ const n = e.target.value;
419
+ H === void 0 && te(n), ce?.(n);
420
+ }, Ne = (e) => {
421
+ if (!L)
344
422
  switch (e.key) {
345
423
  case "Enter":
346
424
  case " ":
347
- if (!v)
348
- e.preventDefault(), A(!0);
349
- else if (x) {
425
+ if (!y)
426
+ e.preventDefault(), O(!0);
427
+ else if (w) {
350
428
  e.preventDefault();
351
- const r = I(t, x, s);
352
- r && !r.disabled && (p ? ae(x, r) : le(x, r));
429
+ const n = $(r, w, i);
430
+ n && !n.disabled && (b ? pe(w, n) : he(w, n));
353
431
  }
354
432
  break;
355
433
  case "Escape":
356
- e.preventDefault(), A(!1), E === void 0 && N(""), ee.current?.focus();
434
+ e.preventDefault(), O(!1), H === void 0 && te(""), re.current?.focus();
357
435
  break;
358
436
  case "ArrowDown":
359
- if (e.preventDefault(), !v)
360
- A(!0);
437
+ if (e.preventDefault(), !y)
438
+ O(!0);
361
439
  else {
362
- const r = m.findIndex((n) => n.key === x), o = r < m.length - 1 ? r + 1 : 0;
363
- j(m[o]?.key || null);
440
+ const n = S.findIndex((t) => t.key === w), c = n < S.length - 1 ? n + 1 : 0;
441
+ I(S[c]?.key || null);
364
442
  }
365
443
  break;
366
444
  case "ArrowUp":
367
- if (e.preventDefault(), v) {
368
- const r = m.findIndex((n) => n.key === x), o = r > 0 ? r - 1 : m.length - 1;
369
- j(m[o]?.key || null);
445
+ if (e.preventDefault(), y) {
446
+ const n = S.findIndex((t) => t.key === w), c = n > 0 ? n - 1 : S.length - 1;
447
+ I(S[c]?.key || null);
370
448
  }
371
449
  break;
372
450
  case "ArrowRight":
373
- if (v && x) {
451
+ if (y && w) {
374
452
  e.preventDefault();
375
- const r = I(t, x, s), o = r ? d(r, "children", s) : void 0;
376
- o && o.length > 0 && !$.includes(x) && te(x);
453
+ const n = $(r, w, i), c = n ? u(n, "children", i) : void 0;
454
+ c && c.length > 0 && !A.includes(w) && ie(w);
377
455
  }
378
456
  break;
379
457
  case "ArrowLeft":
380
- if (v && x)
381
- if (e.preventDefault(), $.includes(x))
382
- te(x);
458
+ if (y && w)
459
+ if (e.preventDefault(), A.includes(w))
460
+ ie(w);
383
461
  else {
384
- const r = fe(t, x, s);
385
- r && r.length > 0 && j(r[r.length - 1]);
462
+ const n = ge(r, w, i);
463
+ n && n.length > 0 && I(n[n.length - 1]);
386
464
  }
387
465
  break;
388
466
  case "Home":
389
- v && (e.preventDefault(), j(m[0]?.key || null));
467
+ y && (e.preventDefault(), I(S[0]?.key || null));
390
468
  break;
391
469
  case "End":
392
- v && (e.preventDefault(), j(m[m.length - 1]?.key || null));
470
+ y && (e.preventDefault(), I(S[S.length - 1]?.key || null));
393
471
  break;
394
472
  }
395
- }, ke = P(
473
+ }, Ee = T(
396
474
  (e) => {
397
- const r = d(e, "key", s), o = d(e, "children", s);
398
- if (y)
399
- return { checked: f.includes(r), indeterminate: !1 };
400
- if (!o || o.length === 0)
401
- return { checked: f.includes(r), indeterminate: !1 };
402
- const n = $e(e, s), i = n.filter((c) => f.includes(c));
403
- return i.length === 0 ? { checked: f.includes(r), indeterminate: !1 } : i.length === n.length ? { checked: !0, indeterminate: !1 } : { checked: !1, indeterminate: !0 };
475
+ const n = u(e, "key", i), c = u(e, "children", i);
476
+ if (g)
477
+ return { checked: h.includes(n), indeterminate: !1 };
478
+ if (!c || c.length === 0)
479
+ return { checked: h.includes(n), indeterminate: !1 };
480
+ const t = Oe(e, i), o = t.filter((s) => h.includes(s));
481
+ return o.length === 0 ? { checked: h.includes(n), indeterminate: !1 } : o.length === t.length ? { checked: !0, indeterminate: !1 } : { checked: !1, indeterminate: !0 };
404
482
  },
405
- [f, y, s]
406
- ), me = P(
407
- (e, r) => e.map((o) => {
408
- const n = d(o, "key", s), { checked: i, indeterminate: c } = ke(o);
409
- return /* @__PURE__ */ b(
410
- Ye,
483
+ [h, g, i]
484
+ ), _e = T(
485
+ (e, n) => e.map((c) => {
486
+ const t = u(c, "key", i), { checked: o, indeterminate: s } = Ee(c);
487
+ return /* @__PURE__ */ v(
488
+ dn,
411
489
  {
412
- node: o,
413
- level: r,
414
- expanded: $.includes(n),
415
- selected: f.includes(n),
416
- checked: i,
417
- indeterminate: c,
418
- treeCheckable: p,
419
- treeLine: Y,
420
- focused: x === n,
421
- loading: ye.has(n),
422
- baseTestId: K,
423
- id: `${D}-option-${n}`,
424
- fieldNames: s,
425
- switcherIcon: pe,
426
- onToggle: te,
427
- onSelect: le,
428
- onCheck: ae,
429
- renderChildren: me
490
+ node: c,
491
+ level: n,
492
+ expanded: A.includes(t),
493
+ selected: h.includes(t),
494
+ checked: o,
495
+ indeterminate: s,
496
+ treeCheckable: b,
497
+ treeLine: N,
498
+ treeIcon: K,
499
+ focused: w === t,
500
+ loading: Le.has(t),
501
+ baseTestId: _,
502
+ id: `${ne}-option-${t}`,
503
+ fieldNames: i,
504
+ switcherIcon: we,
505
+ onToggle: ie,
506
+ onSelect: he,
507
+ onCheck: pe,
508
+ renderChildren: _e
430
509
  },
431
- n
510
+ t
432
511
  );
433
512
  }),
434
513
  [
435
- $,
436
- f,
437
- p,
438
- Y,
439
- x,
440
- ye,
514
+ A,
515
+ h,
516
+ b,
517
+ N,
441
518
  K,
442
- D,
443
- s,
519
+ w,
520
+ Le,
521
+ _,
522
+ ne,
523
+ i,
524
+ we,
525
+ ie,
526
+ he,
444
527
  pe,
445
- te,
446
- le,
447
- ae,
448
- ke
528
+ Ee
449
529
  ]
450
- ), qe = se(() => {
451
- if (f.length === 0) return null;
452
- let e = f;
453
- if ((p || h) && w !== "SHOW_ALL" && (w === "SHOW_PARENT" ? e = f.filter((n) => {
454
- const i = fe(t, n, s);
455
- return i ? !i.some((c) => f.includes(c)) : !0;
456
- }) : w === "SHOW_CHILD" && (e = f.filter((n) => {
457
- const i = I(t, n, s);
458
- if (!i) return !0;
459
- const c = d(i, "children", s);
460
- return !c || c.length === 0;
461
- }))), h || p) {
462
- let n = e, i = 0;
463
- L !== void 0 && L !== "responsive" && e.length > L && (n = e.slice(0, L), i = e.length - L);
464
- const c = n.map((g) => {
465
- const _ = I(t, g, s), re = _ ? d(_, "title", s) : g;
466
- return /* @__PURE__ */ F(
530
+ ), en = oe(() => {
531
+ if (h.length === 0) return null;
532
+ let e = h;
533
+ if ((b || f) && k !== "SHOW_ALL" && (k === "SHOW_PARENT" ? e = h.filter((t) => {
534
+ const o = ge(r, t, i);
535
+ return o ? !o.some((s) => h.includes(s)) : !0;
536
+ }) : k === "SHOW_CHILD" && (e = h.filter((t) => {
537
+ const o = $(r, t, i);
538
+ if (!o) return !0;
539
+ const s = u(o, "children", i);
540
+ return !s || s.length === 0;
541
+ }))), f || b) {
542
+ let t = e, o = 0;
543
+ E !== void 0 && E !== "responsive" && e.length > E && (t = e.slice(0, E), o = e.length - E);
544
+ const s = t.map((a) => {
545
+ const x = $(r, a, i), R = x ? u(x, "title", i) : a, We = R, je = !L, tn = () => {
546
+ Se(a, { stopPropagation: () => {
547
+ } });
548
+ };
549
+ return J ? /* @__PURE__ */ v(rn.Fragment, { children: J({ label: We, value: a, closable: je, onClose: tn }) }, a) : /* @__PURE__ */ z(
467
550
  "span",
468
551
  {
469
552
  className: "inline-flex items-center gap-1 px-2 py-0.5 bg-base-200 rounded text-sm mr-1 mb-1",
470
- "data-testid": `${K}-tag-${g}`,
553
+ "data-testid": `${_}-tag-${a}`,
471
554
  children: [
472
- re,
473
- /* @__PURE__ */ b(
555
+ We,
556
+ je && /* @__PURE__ */ v(
474
557
  "button",
475
558
  {
476
559
  type: "button",
477
560
  className: "hover:text-error",
478
- onClick: (Ge) => Ve(g, Ge),
479
- "aria-label": `Remove ${typeof re == "string" ? re : g}`,
480
- children: /* @__PURE__ */ b(
561
+ onClick: (Ie) => Se(a, Ie),
562
+ "aria-label": `Remove ${typeof R == "string" ? R : a}`,
563
+ children: /* @__PURE__ */ v(
481
564
  "svg",
482
565
  {
483
566
  className: "w-3 h-3",
@@ -485,7 +568,7 @@ const Ze = {
485
568
  viewBox: "0 0 24 24",
486
569
  stroke: "currentColor",
487
570
  "aria-hidden": "true",
488
- children: /* @__PURE__ */ b(
571
+ children: /* @__PURE__ */ v(
489
572
  "path",
490
573
  {
491
574
  strokeLinecap: "round",
@@ -500,88 +583,91 @@ const Ze = {
500
583
  )
501
584
  ]
502
585
  },
503
- g
586
+ a
504
587
  );
505
588
  });
506
- if (i > 0) {
507
- const g = e.slice(L), _ = typeof R == "function" ? R(g) : R || `+${i} more`;
508
- c.push(
509
- /* @__PURE__ */ b(
589
+ if (o > 0) {
590
+ const a = e.slice(E), x = typeof B == "function" ? B(a) : B || `+${o} more`;
591
+ s.push(
592
+ /* @__PURE__ */ v(
510
593
  "span",
511
594
  {
512
595
  className: "inline-flex items-center px-2 py-0.5 bg-base-200 rounded text-sm mr-1 mb-1",
513
- children: _
596
+ children: x
514
597
  },
515
598
  "__more__"
516
599
  )
517
600
  );
518
601
  }
519
- return c;
602
+ return s;
520
603
  }
521
- const r = I(t, f[0], s);
522
- return r ? d(r, "title", s) : f[0];
604
+ const n = $(r, h[0], i);
605
+ return n ? u(n, "title", i) : h[0];
523
606
  }, [
524
- f,
525
- t,
526
607
  h,
527
- p,
528
- w,
608
+ r,
609
+ f,
610
+ b,
611
+ k,
612
+ E,
613
+ B,
614
+ _,
615
+ i,
529
616
  L,
530
- R,
531
- K,
532
- s
533
- ]), Le = W ? Ne[W] : M ? De[M] : "", Ke = /* @__PURE__ */ b("div", { className: "py-1", role: "tree", "aria-label": "Tree options", children: we.length > 0 ? me(we, 0) : /* @__PURE__ */ b(
617
+ J
618
+ ]), Ae = W ? pn[W] : P ? hn[P] : "", nn = G ? "bg-transparent border-transparent" : bn[D], He = /* @__PURE__ */ v("div", { className: "py-1", role: "tree", "aria-label": "Tree options", children: $e.length > 0 ? _e($e, 0) : /* @__PURE__ */ v(
534
619
  "div",
535
620
  {
536
621
  className: "px-4 py-2 text-base-content/50 text-sm text-center",
537
- "data-testid": `${K}-empty`,
538
- children: Se
622
+ "data-testid": `${_}-empty`,
623
+ children: Re
539
624
  }
540
625
  ) });
541
- return /* @__PURE__ */ F(
626
+ return /* @__PURE__ */ z(
542
627
  "div",
543
628
  {
544
629
  ref: (e) => {
545
- oe.current = e, typeof Z == "function" ? Z(e) : Z && (Z.current = e);
630
+ de.current = e, typeof ee == "function" ? ee(e) : ee && (ee.current = e);
546
631
  },
547
- className: `relative ${je}`,
548
- "data-testid": K,
549
- "data-state": v ? "open" : "closed",
550
- "data-disabled": S || void 0,
551
- onKeyDown: Ue,
552
- ..._e,
632
+ className: `relative ${Te}`,
633
+ "data-testid": _,
634
+ "data-state": y ? "open" : "closed",
635
+ "data-disabled": L || void 0,
636
+ onKeyDown: Ne,
637
+ ...Ve,
553
638
  children: [
554
- /* @__PURE__ */ F(
639
+ /* @__PURE__ */ z(
555
640
  "div",
556
641
  {
557
- ref: ee,
642
+ ref: re,
558
643
  role: "combobox",
559
- "aria-expanded": v,
644
+ "aria-expanded": y,
560
645
  "aria-haspopup": "tree",
561
- "aria-owns": v ? ge : void 0,
562
- "aria-activedescendant": v && x ? `${D}-option-${x}` : void 0,
563
- "aria-disabled": S,
564
- tabIndex: S ? -1 : 0,
646
+ "aria-owns": y ? ke : void 0,
647
+ "aria-activedescendant": y && w ? `${ne}-option-${w}` : void 0,
648
+ "aria-disabled": L,
649
+ tabIndex: L ? -1 : 0,
565
650
  className: [
566
- "input input-bordered flex items-center gap-2 cursor-pointer flex-wrap",
567
- Ze[q],
568
- Le,
569
- S && "input-disabled opacity-50 cursor-not-allowed",
570
- v && !Le && "input-primary"
651
+ "input flex items-center gap-2 cursor-pointer flex-wrap",
652
+ fn[C],
653
+ nn,
654
+ Ae,
655
+ L && "input-disabled opacity-50 cursor-not-allowed",
656
+ y && !Ae && "border-primary"
571
657
  ].filter(Boolean).join(" "),
572
- onClick: () => !S && A(!v),
573
- "data-testid": `${K}-trigger`,
658
+ onClick: () => !L && O(!y),
659
+ "data-testid": `${_}-trigger`,
574
660
  children: [
575
- /* @__PURE__ */ b("div", { className: "flex-1 flex flex-wrap items-center gap-1 min-w-0", children: qe || /* @__PURE__ */ b("span", { className: "text-base-content/50", children: V }) }),
576
- B && f.length > 0 && !S && /* @__PURE__ */ b(
661
+ /* @__PURE__ */ v("div", { className: "flex-1 flex flex-wrap items-center gap-1 min-w-0", children: en || /* @__PURE__ */ v("span", { className: "text-base-content/50", children: le }) }),
662
+ q && h.length > 0 && !L && /* @__PURE__ */ v(
577
663
  "button",
578
664
  {
579
665
  type: "button",
580
666
  className: "hover:text-error flex-shrink-0",
581
- onClick: ze,
667
+ onClick: Ze,
582
668
  "aria-label": "Clear selection",
583
- "data-testid": `${K}-clear`,
584
- children: /* @__PURE__ */ b(
669
+ "data-testid": `${_}-clear`,
670
+ children: /* @__PURE__ */ v(
585
671
  "svg",
586
672
  {
587
673
  className: "w-4 h-4",
@@ -589,7 +675,7 @@ const Ze = {
589
675
  viewBox: "0 0 24 24",
590
676
  stroke: "currentColor",
591
677
  "aria-hidden": "true",
592
- children: /* @__PURE__ */ b(
678
+ children: /* @__PURE__ */ v(
593
679
  "path",
594
680
  {
595
681
  strokeLinecap: "round",
@@ -602,15 +688,15 @@ const Ze = {
602
688
  )
603
689
  }
604
690
  ),
605
- Ee || /* @__PURE__ */ b(
691
+ Be || /* @__PURE__ */ v(
606
692
  "svg",
607
693
  {
608
- className: `w-4 h-4 flex-shrink-0 transition-transform ${v ? "rotate-180" : ""}`,
694
+ className: `w-4 h-4 flex-shrink-0 transition-transform ${y ? "rotate-180" : ""}`,
609
695
  fill: "none",
610
696
  viewBox: "0 0 24 24",
611
697
  stroke: "currentColor",
612
698
  "aria-hidden": "true",
613
- children: /* @__PURE__ */ b(
699
+ children: /* @__PURE__ */ v(
614
700
  "path",
615
701
  {
616
702
  strokeLinecap: "round",
@@ -624,28 +710,28 @@ const Ze = {
624
710
  ]
625
711
  }
626
712
  ),
627
- v && /* @__PURE__ */ F(
713
+ y && /* @__PURE__ */ z(
628
714
  "div",
629
715
  {
630
- id: ge,
631
- className: `absolute z-50 mt-1 w-full bg-base-100 border border-base-300 rounded-lg shadow-lg max-h-64 overflow-auto ${Me}`,
632
- "data-testid": `${K}-dropdown`,
716
+ id: ke,
717
+ className: `absolute z-50 mt-1 w-full bg-base-100 border border-base-300 rounded-lg shadow-lg max-h-64 overflow-auto ${Fe}`,
718
+ "data-testid": `${_}-dropdown`,
633
719
  children: [
634
- O && /* @__PURE__ */ b("div", { className: "p-2 border-b border-base-300", children: /* @__PURE__ */ b(
720
+ V && /* @__PURE__ */ v("div", { className: "p-2 border-b border-base-300", children: /* @__PURE__ */ v(
635
721
  "input",
636
722
  {
637
- ref: ce,
723
+ ref: fe,
638
724
  type: "text",
639
- className: "input input-bordered input-sm w-full",
725
+ className: "input input-sm w-full",
640
726
  placeholder: "Search...",
641
- value: J,
642
- onChange: Te,
727
+ value: Q,
728
+ onChange: De,
643
729
  onClick: (e) => e.stopPropagation(),
644
730
  "aria-label": "Search tree options",
645
- "data-testid": `${K}-search`
731
+ "data-testid": `${_}-search`
646
732
  }
647
733
  ) }),
648
- be ? be(Ke) : Ke
734
+ xe ? xe(He) : He
649
735
  ]
650
736
  }
651
737
  )
@@ -654,8 +740,15 @@ const Ze = {
654
740
  );
655
741
  }
656
742
  );
657
- en.displayName = "TreeSelect";
743
+ Pe.displayName = "TreeSelect";
744
+ const yn = Object.assign(Pe, {
745
+ SHOW_ALL: cn,
746
+ SHOW_PARENT: ln,
747
+ SHOW_CHILD: an
748
+ });
658
749
  export {
659
- en as TreeSelect
750
+ Pe as TreeSelect,
751
+ yn as TreeSelectComponent,
752
+ yn as default
660
753
  };
661
754
  //# sourceMappingURL=index94.js.map