@tetrascience-npm/tetrascience-react-ui 1.0.0-beta.163.1 → 1.0.0-beta.164.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/ui/tree.js CHANGED
@@ -1,53 +1,58 @@
1
- import { jsx as i, jsxs as q, Fragment as se } from "react/jsx-runtime";
1
+ import { jsx as i, jsxs as O, Fragment as ie } from "react/jsx-runtime";
2
2
  import { useControllableState as J } from "@radix-ui/react-use-controllable-state";
3
- import { cva as le } from "class-variance-authority";
4
- import { ChevronRightIcon as ie } from "lucide-react";
5
- import * as o from "react";
6
- import { TooltipProvider as ce, Tooltip as ue, TooltipTrigger as de, TooltipContent as fe } from "./tooltip.js";
7
- import { cn as N } from "../lib/utils.js";
8
- const ee = o.createContext(null), te = o.createContext(null);
9
- function re(e) {
10
- const r = o.useContext(ee);
3
+ import { cva as de } from "class-variance-authority";
4
+ import { ChevronRightIcon as ce } from "lucide-react";
5
+ import * as a from "react";
6
+ import { TooltipProvider as ue, Tooltip as fe, TooltipTrigger as me, TooltipContent as pe } from "./tooltip.js";
7
+ import { cn as I } from "../lib/utils.js";
8
+ const te = a.createContext(null), re = a.createContext(null);
9
+ function ne(e) {
10
+ const r = a.useContext(te);
11
11
  if (!r)
12
12
  throw new Error(`\`${e}\` must be rendered inside a \`Tree\`.`);
13
13
  return r;
14
14
  }
15
- const U = o.createContext(1), ne = o.createContext({
15
+ const j = a.createContext(1), ae = a.createContext({
16
16
  posinset: 1,
17
17
  setsize: 1,
18
18
  lastBranchPos: 0
19
- }), W = o.createContext(null), me = [];
19
+ }), G = a.createContext(null), ge = [];
20
20
  function Y(e) {
21
- const r = o.useContext(W);
21
+ const r = a.useContext(G);
22
22
  if (!r)
23
23
  throw new Error(`\`${e}\` must be rendered inside a \`TreeItem\`.`);
24
24
  return r;
25
25
  }
26
- function Se() {
26
+ function Me() {
27
27
  return Y("useTreeItem");
28
28
  }
29
- function pe(e) {
30
- return o.useMemo(() => {
31
- const r = o.Children.toArray(e), t = r.filter(o.isValidElement), s = t.length, a = (l) => l.props?.hasChildren === !0, c = t.reduce((l, m, p) => a(m) ? p + 1 : l, 0);
32
- let u = 0;
33
- return r.map((l, m) => o.isValidElement(l) ? (u += 1, /* @__PURE__ */ i(ne.Provider, { value: { posinset: u, setsize: s, lastBranchPos: c }, children: l }, l.key ?? m)) : l);
29
+ function Q(e) {
30
+ return e.type === Re || e.type === Pe;
31
+ }
32
+ function he(e) {
33
+ return a.useMemo(() => {
34
+ const r = a.Children.toArray(e), t = r.filter(
35
+ (l) => a.isValidElement(l) && !Q(l)
36
+ ), s = t.length, o = (l) => l.props?.hasChildren === !0, d = t.reduce((l, f, p) => o(f) ? p + 1 : l, 0);
37
+ let c = 0;
38
+ return r.map((l, f) => !a.isValidElement(l) || Q(l) ? l : (c += 1, /* @__PURE__ */ i(ae.Provider, { value: { posinset: c, setsize: s, lastBranchPos: d }, children: l }, l.key ?? f)));
34
39
  }, [e]);
35
40
  }
36
- const M = '[role="treeitem"]';
37
- function D(e) {
38
- return e ? [...e.querySelectorAll(M)] : [];
41
+ const z = '[role="treeitem"][data-tree-item-id]';
42
+ function A(e) {
43
+ return e ? [...e.querySelectorAll(z)] : [];
39
44
  }
40
- const he = '[role="group"], [role="tree"]';
41
- function G(e, r) {
42
- return D(e).find((t) => t.dataset.treeItemId === r);
45
+ const xe = '[role="group"], [role="tree"]';
46
+ function U(e, r) {
47
+ return A(e).find((t) => t.dataset.treeItemId === r);
43
48
  }
44
- function Q(e) {
45
- return e.parentElement?.closest(he) ?? null;
49
+ function Z(e) {
50
+ return e.parentElement?.closest(xe) ?? null;
46
51
  }
47
- function ge(e) {
52
+ function be(e) {
48
53
  const r = [];
49
- for (let t = e.parentElement?.closest(M); t; )
50
- t.dataset.treeItemId && r.unshift(t.dataset.treeItemId), t = t.parentElement?.closest(M);
54
+ for (let t = e.parentElement?.closest(z); t; )
55
+ t.dataset.treeItemId && r.unshift(t.dataset.treeItemId), t = t.parentElement?.closest(z);
51
56
  return r;
52
57
  }
53
58
  function oe(e) {
@@ -57,53 +62,53 @@ function oe(e) {
57
62
  for (const t of e.childNodes) r += oe(t);
58
63
  return r;
59
64
  }
60
- function xe(e) {
65
+ function ve(e) {
61
66
  const r = e.getAttribute("aria-labelledby"), t = r ? e.ownerDocument.getElementById(r) : null;
62
67
  return (t ? oe(t) : "").trim().toLowerCase();
63
68
  }
64
- function be(e, r, t) {
65
- const s = G(e, r);
69
+ function Ie(e, r, t) {
70
+ const s = U(e, r);
66
71
  if (s) return s;
67
- for (let a = t.length - 1; a >= 0; a -= 1) {
68
- const c = G(e, t[a]);
69
- if (c) return c;
72
+ for (let o = t.length - 1; o >= 0; o -= 1) {
73
+ const d = U(e, t[o]);
74
+ if (d) return d;
70
75
  }
71
- return D(e)[0];
76
+ return A(e)[0];
72
77
  }
73
- function Ie(e, r) {
78
+ function Te(e, r) {
74
79
  const t = e?.dataset.treeItemId;
75
80
  !e || !t || (r(t), e.focus());
76
81
  }
77
- const Te = 600, ve = 800;
82
+ const ye = 600, Ce = 800;
78
83
  function K({ event: e, setFocusedId: r }, t) {
79
- e.preventDefault(), Ie(t, r);
84
+ e.preventDefault(), Te(t, r);
80
85
  }
81
- function Z(e, r) {
82
- const t = D(e.root);
86
+ function ee(e, r) {
87
+ const t = A(e.root);
83
88
  K(e, t[t.indexOf(e.current) + r]);
84
89
  }
85
- const ye = {
86
- ArrowDown: (e) => Z(e, 1),
87
- ArrowUp: (e) => Z(e, -1),
90
+ const we = {
91
+ ArrowDown: (e) => ee(e, 1),
92
+ ArrowUp: (e) => ee(e, -1),
88
93
  ArrowRight: (e) => {
89
- const { event: r, current: t, id: s, hasChildren: a, expanded: c, setExpanded: u } = e;
90
- if (a && !c) {
91
- r.preventDefault(), u(s, !0);
94
+ const { event: r, current: t, id: s, hasChildren: o, expanded: d, setExpanded: c } = e;
95
+ if (o && !d) {
96
+ r.preventDefault(), c(s, !0);
92
97
  return;
93
98
  }
94
- c && K(e, t.querySelector(M));
99
+ d && K(e, t.querySelector(z));
95
100
  },
96
101
  ArrowLeft: (e) => {
97
- const { event: r, current: t, id: s, expanded: a, setExpanded: c } = e;
98
- if (a) {
99
- r.preventDefault(), c(s, !1);
102
+ const { event: r, current: t, id: s, expanded: o, setExpanded: d } = e;
103
+ if (o) {
104
+ r.preventDefault(), d(s, !1);
100
105
  return;
101
106
  }
102
- K(e, t.parentElement?.closest(M));
107
+ K(e, t.parentElement?.closest(z));
103
108
  },
104
- Home: (e) => K(e, D(e.root)[0]),
109
+ Home: (e) => K(e, A(e.root)[0]),
105
110
  End: (e) => {
106
- const r = D(e.root);
111
+ const r = A(e.root);
107
112
  K(e, r[r.length - 1]);
108
113
  },
109
114
  Enter: (e) => {
@@ -111,151 +116,151 @@ const ye = {
111
116
  },
112
117
  /** Expands every collapsed branch among the focused node's siblings, the node itself included. */
113
118
  "*": (e) => {
114
- const { event: r, root: t, current: s, expandIds: a } = e;
119
+ const { event: r, root: t, current: s, expandIds: o } = e;
115
120
  r.preventDefault();
116
- const c = Q(s) ?? t, u = D(c).filter((l) => Q(l) === c).filter((l) => l.dataset.treeHasChildren === "true" && l.getAttribute("aria-expanded") !== "true").map((l) => l.dataset.treeItemId).filter((l) => !!l);
117
- u.length && a(u);
121
+ const d = Z(s) ?? t, c = A(d).filter((l) => Z(l) === d).filter((l) => l.dataset.treeHasChildren === "true" && l.getAttribute("aria-expanded") !== "true").map((l) => l.dataset.treeItemId).filter((l) => !!l);
122
+ c.length && o(c);
118
123
  }
119
124
  };
120
- function Ce(e) {
125
+ function Ee(e) {
121
126
  return e.key.length === 1 && e.key !== " ";
122
127
  }
123
- function Ee(e) {
124
- const { event: r, root: t, current: s, typeahead: a, setTypeaheadMatch: c } = e;
125
- r.preventDefault(), clearTimeout(a.timer), clearTimeout(a.fadeTimer), a.buffer += r.key.toLowerCase();
126
- const { buffer: u } = a, m = u.length > 1 && [...u].every((x) => x === u[0]) ? u[0] : u;
127
- c({ query: m, fading: !1 }), a.timer = setTimeout(() => {
128
- a.buffer = "", c({ query: m, fading: !0 }), a.fadeTimer = setTimeout(() => c(null), ve);
129
- }, Te);
130
- const p = D(t), T = p.indexOf(s);
128
+ function ke(e) {
129
+ const { event: r, root: t, current: s, typeahead: o, setTypeaheadMatch: d } = e;
130
+ r.preventDefault(), clearTimeout(o.timer), clearTimeout(o.fadeTimer), o.buffer += r.key.toLowerCase();
131
+ const { buffer: c } = o, f = c.length > 1 && [...c].every((x) => x === c[0]) ? c[0] : c;
132
+ d({ query: f, fading: !1 }), o.timer = setTimeout(() => {
133
+ o.buffer = "", d({ query: f, fading: !0 }), o.fadeTimer = setTimeout(() => d(null), Ce);
134
+ }, ye);
135
+ const p = A(t), T = p.indexOf(s);
131
136
  for (let x = 1; x <= p.length; x += 1) {
132
- const v = p[(T + x) % p.length];
133
- if (xe(v).startsWith(m)) {
134
- K(e, v);
137
+ const y = p[(T + x) % p.length];
138
+ if (ve(y).startsWith(f)) {
139
+ K(e, y);
135
140
  return;
136
141
  }
137
142
  }
138
143
  }
139
- function _e({
144
+ function Fe({
140
145
  className: e,
141
146
  children: r,
142
147
  expandedIds: t,
143
148
  defaultExpandedIds: s,
144
- onExpandedChange: a,
145
- selectedId: c,
146
- defaultSelectedId: u = null,
149
+ onExpandedChange: o,
150
+ selectedId: d,
151
+ defaultSelectedId: c = null,
147
152
  onSelectedChange: l,
148
- onActivate: m,
153
+ onActivate: f,
149
154
  expandOnSelect: p = !0,
150
155
  guides: T = "hover",
151
156
  onFocus: x,
152
- onBlur: v,
153
- ...P
157
+ onBlur: y,
158
+ ...D
154
159
  }) {
155
- const R = o.useRef(null), [y, E] = J({
160
+ const R = a.useRef(null), [C, E] = J({
156
161
  prop: t,
157
162
  defaultProp: s ?? /* @__PURE__ */ new Set(),
158
- onChange: a
159
- }), [C, b] = J({
160
- prop: c,
161
- defaultProp: u,
163
+ onChange: o
164
+ }), [w, b] = J({
165
+ prop: d,
166
+ defaultProp: c,
162
167
  onChange: (n) => {
163
168
  n != null && l?.(n);
164
169
  }
165
- }), [h, L] = o.useState(null), [w, S] = o.useState(null), [f, k] = o.useState(null), O = o.useRef([]), _ = o.useRef(!1), B = o.useRef({ buffer: "", timer: void 0, fadeTimer: void 0 });
166
- o.useEffect(
170
+ }), [g, L] = a.useState(null), [k, S] = a.useState(null), [m, N] = a.useState(null), B = a.useRef([]), _ = a.useRef(!1), $ = a.useRef({ buffer: "", timer: void 0, fadeTimer: void 0 });
171
+ a.useEffect(
167
172
  () => () => {
168
- clearTimeout(B.current.timer), clearTimeout(B.current.fadeTimer);
173
+ clearTimeout($.current.timer), clearTimeout($.current.fadeTimer);
169
174
  },
170
175
  []
171
176
  );
172
- const A = o.useCallback(
173
- (n, g) => {
174
- E((d) => {
175
- const I = new Set(d);
176
- return g ? I.add(n) : I.delete(n), I;
177
+ const P = a.useCallback(
178
+ (n, h) => {
179
+ E((u) => {
180
+ const v = new Set(u);
181
+ return h ? v.add(n) : v.delete(n), v;
177
182
  });
178
183
  },
179
184
  [E]
180
- ), z = o.useCallback(
185
+ ), M = a.useCallback(
181
186
  (n) => {
182
- E((g) => {
183
- const d = new Set(g);
184
- for (const I of n) d.add(I);
185
- return d;
187
+ E((h) => {
188
+ const u = new Set(h);
189
+ for (const v of n) u.add(v);
190
+ return u;
186
191
  });
187
192
  },
188
193
  [E]
189
- ), H = o.useCallback(
190
- (n, g, d) => {
191
- b(n), p && g && A(n, !d), m?.(n);
194
+ ), H = a.useCallback(
195
+ (n, h, u) => {
196
+ b(n), p && h && P(n, !u), f?.(n);
192
197
  },
193
- [b, p, A, m]
194
- ), F = o.useCallback(
198
+ [b, p, P, f]
199
+ ), F = a.useCallback(
195
200
  (n) => {
196
- const g = R.current, d = n.target?.closest(M), I = d?.dataset.treeItemId;
197
- if (!g || !d || !I || !g.contains(d) || d !== n.currentTarget || n.ctrlKey || n.metaKey || n.altKey) return;
198
- const j = ye[n.key] ?? (Ce(n) ? Ee : void 0);
199
- j && j({
201
+ const h = R.current, u = n.target?.closest(z), v = u?.dataset.treeItemId;
202
+ if (!h || !u || !v || !h.contains(u) || u !== n.currentTarget || n.ctrlKey || n.metaKey || n.altKey) return;
203
+ const W = we[n.key] ?? (Ee(n) ? ke : void 0);
204
+ W && W({
200
205
  event: n,
201
- root: g,
202
- current: d,
203
- id: I,
204
- hasChildren: d.dataset.treeHasChildren === "true",
205
- expanded: d.getAttribute("aria-expanded") === "true",
206
- disabled: d.getAttribute("aria-disabled") === "true",
207
- setExpanded: A,
208
- expandIds: z,
206
+ root: h,
207
+ current: u,
208
+ id: v,
209
+ hasChildren: u.dataset.treeHasChildren === "true",
210
+ expanded: u.getAttribute("aria-expanded") === "true",
211
+ disabled: u.getAttribute("aria-disabled") === "true",
212
+ setExpanded: P,
213
+ expandIds: M,
209
214
  setFocusedId: L,
210
215
  activate: H,
211
- typeahead: B.current,
212
- setTypeaheadMatch: k
216
+ typeahead: $.current,
217
+ setTypeaheadMatch: N
213
218
  });
214
219
  },
215
- [A, z, H]
216
- ), $ = o.useCallback(() => {
220
+ [P, M, H]
221
+ ), q = a.useCallback(() => {
217
222
  const n = R.current;
218
223
  if (!n) return;
219
- if (h == null) {
220
- const X = C != null && !G(n, C) ? D(n)[0]?.dataset.treeItemId ?? null : null;
221
- X !== w && S(X);
224
+ if (g == null) {
225
+ const X = w != null && !U(n, w) ? A(n)[0]?.dataset.treeItemId ?? null : null;
226
+ X !== k && S(X);
222
227
  return;
223
228
  }
224
- const g = be(n, h, O.current), d = g?.dataset.treeItemId;
225
- if (!g || !d) return;
226
- d === h ? O.current = ge(g) : L(d);
227
- const I = n.ownerDocument.activeElement;
228
- _.current && (!n.contains(I) || I === n) && g.focus();
229
- }, [h, C, w]);
230
- o.useLayoutEffect($);
231
- const V = o.useMemo(
229
+ const h = Ie(n, g, B.current), u = h?.dataset.treeItemId;
230
+ if (!h || !u) return;
231
+ u === g ? B.current = be(h) : L(u);
232
+ const v = n.ownerDocument.activeElement;
233
+ _.current && (!n.contains(v) || v === n) && h.focus();
234
+ }, [g, w, k]);
235
+ a.useLayoutEffect(q);
236
+ const V = a.useMemo(
232
237
  () => ({
233
- expandedIds: y ?? /* @__PURE__ */ new Set(),
234
- setExpanded: A,
235
- expandIds: z,
236
- selectedId: C ?? null,
238
+ expandedIds: C ?? /* @__PURE__ */ new Set(),
239
+ setExpanded: P,
240
+ expandIds: M,
241
+ selectedId: w ?? null,
237
242
  activateItem: H,
238
- focusedId: h,
243
+ focusedId: g,
239
244
  setFocusedId: L,
240
- entryId: w,
245
+ entryId: k,
241
246
  expandOnSelect: p,
242
247
  guides: T,
243
248
  onItemKeyDown: F
244
249
  }),
245
250
  [
246
- y,
247
- A,
248
- z,
249
251
  C,
250
- H,
251
- h,
252
+ P,
253
+ M,
252
254
  w,
255
+ H,
256
+ g,
257
+ k,
253
258
  p,
254
259
  T,
255
260
  F
256
261
  ]
257
262
  );
258
- return /* @__PURE__ */ i(ee.Provider, { value: V, children: /* @__PURE__ */ i(te.Provider, { value: f, children: /* @__PURE__ */ i(U.Provider, { value: 1, children: /* @__PURE__ */ i(
263
+ return /* @__PURE__ */ i(te.Provider, { value: V, children: /* @__PURE__ */ i(re.Provider, { value: m, children: /* @__PURE__ */ i(j.Provider, { value: 1, children: /* @__PURE__ */ i(
259
264
  "div",
260
265
  {
261
266
  ref: R,
@@ -267,80 +272,80 @@ function _e({
267
272
  x?.(n), _.current = !0;
268
273
  },
269
274
  onBlur: (n) => {
270
- v?.(n), n.currentTarget.contains(n.relatedTarget) || (_.current = !1);
275
+ y?.(n), n.currentTarget.contains(n.relatedTarget) || (_.current = !1);
271
276
  },
272
- className: N(
277
+ className: I(
273
278
  "group/tree text-foreground flex w-full flex-col text-sm",
274
279
  "[--tree-indent:1.25rem] [--tree-guide-color:color-mix(in_oklch,var(--muted-foreground)_40%,var(--background))]",
275
280
  e
276
281
  ),
277
- ...P,
278
- children: /* @__PURE__ */ i(ce, { delayDuration: 500, children: /* @__PURE__ */ i(ae, { children: r }) })
282
+ ...D,
283
+ children: /* @__PURE__ */ i(ue, { delayDuration: 500, children: /* @__PURE__ */ i(se, { children: r }) })
279
284
  }
280
285
  ) }) }) });
281
286
  }
282
- function ae({ children: e }) {
283
- return pe(e);
287
+ function se({ children: e }) {
288
+ return he(e);
284
289
  }
285
- function Me({
290
+ function Ke({
286
291
  className: e,
287
292
  children: r,
288
293
  id: t,
289
294
  hasChildren: s = !1,
290
- disabled: a = !1,
291
- onClick: c,
292
- onFocus: u,
295
+ disabled: o = !1,
296
+ onClick: d,
297
+ onFocus: c,
293
298
  onKeyDown: l,
294
- style: m,
299
+ style: f,
295
300
  ...p
296
301
  }) {
297
- const { expandedIds: T, setExpanded: x, selectedId: v, activateItem: P, focusedId: R, setFocusedId: y, entryId: E, onItemKeyDown: C } = re("TreeItem"), b = o.useContext(U), { posinset: h, setsize: L, lastBranchPos: w } = o.useContext(ne), S = `${o.useId()}-label`, f = s && T.has(t), k = v === t, O = o.useCallback(() => {
298
- s && x(t, !f);
299
- }, [s, x, t, f]), _ = o.useCallback(() => {
300
- a || (y(t), P(t, s, f));
301
- }, [a, y, t, P, s, f]), B = b === 1 && h === 1, A = v == null ? B : v === t, z = R ? R === t : E ? E === t : A, F = o.useContext(W)?.trunkLevels ?? me, $ = o.useMemo(
302
- () => b > 1 && h < w ? [...F, b - 1] : F,
303
- [F, b, h, w]
304
- ), V = o.useMemo(
302
+ const { expandedIds: T, setExpanded: x, selectedId: y, activateItem: D, focusedId: R, setFocusedId: C, entryId: E, onItemKeyDown: w } = ne("TreeItem"), b = a.useContext(j), { posinset: g, setsize: L, lastBranchPos: k } = a.useContext(ae), S = `${a.useId()}-label`, m = s && T.has(t), N = y === t, B = a.useCallback(() => {
303
+ s && x(t, !m);
304
+ }, [s, x, t, m]), _ = a.useCallback(() => {
305
+ o || (C(t), D(t, s, m));
306
+ }, [o, C, t, D, s, m]), $ = b === 1 && g === 1, P = y == null ? $ : y === t, M = R ? R === t : E ? E === t : P, F = a.useContext(G)?.trunkLevels ?? ge, q = a.useMemo(
307
+ () => b > 1 && g < k ? [...F, b - 1] : F,
308
+ [F, b, g, k]
309
+ ), V = a.useMemo(
305
310
  () => ({
306
311
  id: t,
307
312
  labelId: S,
308
313
  level: b,
309
- expanded: f,
314
+ expanded: m,
310
315
  hasChildren: s,
311
- selected: k,
312
- disabled: a,
313
- trunkLevels: $,
314
- toggle: O,
316
+ selected: N,
317
+ disabled: o,
318
+ trunkLevels: q,
319
+ toggle: B,
315
320
  select: _
316
321
  }),
317
- [t, S, b, f, s, k, a, $, O, _]
322
+ [t, S, b, m, s, N, o, q, B, _]
318
323
  );
319
- return /* @__PURE__ */ i(W.Provider, { value: V, children: /* @__PURE__ */ i(
324
+ return /* @__PURE__ */ i(G.Provider, { value: V, children: /* @__PURE__ */ i(
320
325
  "div",
321
326
  {
322
327
  ...p,
323
328
  "data-slot": "tree-item",
324
329
  "data-tree-item-id": t,
325
330
  "data-tree-has-children": s,
326
- "data-state": f ? "expanded" : "collapsed",
331
+ "data-state": m ? "expanded" : "collapsed",
327
332
  role: "treeitem",
328
333
  "aria-labelledby": S,
329
- "aria-expanded": s ? f : void 0,
334
+ "aria-expanded": s ? m : void 0,
330
335
  "aria-level": b,
331
- "aria-posinset": h,
336
+ "aria-posinset": g,
332
337
  "aria-setsize": L,
333
- "aria-selected": k,
334
- "aria-disabled": a || void 0,
335
- tabIndex: z ? 0 : -1,
338
+ "aria-selected": N,
339
+ "aria-disabled": o || void 0,
340
+ tabIndex: M ? 0 : -1,
336
341
  onKeyDown: (n) => {
337
- l?.(n), !n.defaultPrevented && C(n);
342
+ l?.(n), !n.defaultPrevented && w(n);
338
343
  },
339
344
  onClick: (n) => {
340
- c?.(n), !n.defaultPrevented && n.target.closest(M) === n.currentTarget && _();
345
+ d?.(n), !n.defaultPrevented && n.target.closest(z) === n.currentTarget && _();
341
346
  },
342
347
  onFocus: (n) => {
343
- u?.(n), n.target === n.currentTarget && y(t);
348
+ c?.(n), n.target === n.currentTarget && C(t);
344
349
  },
345
350
  style: {
346
351
  // Inherited by the label, which draws the elbow from the same two values.
@@ -351,9 +356,9 @@ function Me({
351
356
  // Shared by the elbow's corner and by where the same-column trunk picks up, so the two
352
357
  // meet exactly instead of overlapping or leaving a gap.
353
358
  "--tree-elbow-radius": "0.5rem",
354
- ...m
359
+ ...f
355
360
  },
356
- className: N(
361
+ className: I(
357
362
  "relative outline-none",
358
363
  // Direct-child selectors, deliberately not `group-*/tree-item`: tree items nest, and a
359
364
  // group variant matches *any* ancestor, so a focused or selected parent painted its focus
@@ -366,7 +371,7 @@ function Me({
366
371
  }
367
372
  ) });
368
373
  }
369
- const we = le(
374
+ const le = de(
370
375
  "flex w-full min-w-0 cursor-default items-center gap-1.5 rounded-md pr-2 text-left transition-colors select-none",
371
376
  {
372
377
  variants: {
@@ -381,27 +386,27 @@ const we = le(
381
386
  }
382
387
  }
383
388
  );
384
- function ze({ className: e, children: r, size: t, style: s, icon: a, trailing: c, ...u }) {
385
- const { labelId: l, level: m, expanded: p, hasChildren: T, selected: x, disabled: v, trunkLevels: P, toggle: R } = Y("TreeItemLabel"), { guides: y } = re("TreeItemLabel"), E = o.useContext(te), C = y !== "none" && m > 1 && T, b = y !== "none" && (C || P.length > 0), h = o.useRef(null), [L, w] = o.useState(!1), S = (f) => {
386
- const k = h.current;
387
- w(f && !!k && k.scrollWidth > k.clientWidth);
389
+ function Oe({ className: e, children: r, size: t, style: s, icon: o, trailing: d, ...c }) {
390
+ const { labelId: l, level: f, expanded: p, hasChildren: T, selected: x, disabled: y, trunkLevels: D, toggle: R } = Y("TreeItemLabel"), { guides: C } = ne("TreeItemLabel"), E = a.useContext(re), w = C !== "none" && f > 1 && T, b = C !== "none" && (w || D.length > 0), g = a.useRef(null), [L, k] = a.useState(!1), S = (m) => {
391
+ const N = g.current;
392
+ k(m && !!N && N.scrollWidth > N.clientWidth);
388
393
  };
389
- return /* @__PURE__ */ q(
394
+ return /* @__PURE__ */ O(
390
395
  "div",
391
396
  {
392
- ...u,
397
+ ...c,
393
398
  id: l,
394
399
  "data-slot": "tree-item-label",
395
- style: { paddingInlineStart: `calc(var(--tree-indent) * ${m - 1} + 0.25rem)`, ...s },
396
- className: N(
397
- we({ size: t }),
400
+ style: { paddingInlineStart: `calc(var(--tree-indent) * ${f - 1} + 0.25rem)`, ...s },
401
+ className: I(
402
+ le({ size: t }),
398
403
  "relative border border-transparent",
399
404
  // Only selection paints a background — an open folder is already marked by its rotated
400
405
  // chevron, open-folder icon and the connectors running down from it.
401
406
  x ? "bg-accent text-accent-foreground font-medium" : "hover:bg-muted",
402
407
  // From this node's own state, not an ancestor selector: `aria-disabled` is per-node, so a
403
408
  // disabled folder must not dim the contents underneath it.
404
- v && "pointer-events-none opacity-50",
409
+ y && "pointer-events-none opacity-50",
405
410
  e
406
411
  ),
407
412
  children: [
@@ -418,29 +423,29 @@ function ze({ className: e, children: r, size: t, style: s, icon: a, trailing: c
418
423
  // *padding* box. The label carries `border border-transparent` for its focus ring while the
419
424
  // `TreeItem` carries none, so one `--tree-guide-left` landed 1px apart on the two elements
420
425
  // and the elbow/trunk overlap read as a 2px line. Both now share this container.
421
- /* @__PURE__ */ q(
426
+ /* @__PURE__ */ O(
422
427
  "span",
423
428
  {
424
429
  "data-slot": "tree-item-guides",
425
430
  "aria-hidden": "true",
426
- className: N(
431
+ className: I(
427
432
  "pointer-events-none absolute inset-0",
428
433
  // The fade lives on the container, not on each line. Opacity on the parent renders the
429
434
  // whole layer into one buffer and composites it once, so a seam between two segments
430
435
  // can never double-expose mid-transition.
431
- y === "hover" && "opacity-0 transition-opacity group-hover/tree:opacity-100 motion-reduce:transition-none"
436
+ C === "hover" && "opacity-0 transition-opacity group-hover/tree:opacity-100 motion-reduce:transition-none"
432
437
  ),
433
438
  children: [
434
- P.map((f) => /* @__PURE__ */ i(
439
+ D.map((m) => /* @__PURE__ */ i(
435
440
  "span",
436
441
  {
437
442
  "data-slot": "tree-item-guide-trunk",
438
- style: { left: `calc(var(--tree-indent) * ${f - 1} + 0.6875rem)` },
443
+ style: { left: `calc(var(--tree-indent) * ${m - 1} + 0.6875rem)` },
439
444
  className: "absolute top-[-0.4375rem] bottom-0 w-0 border-l border-[var(--tree-guide-color)]"
440
445
  },
441
- f
446
+ m
442
447
  )),
443
- C ? (
448
+ w ? (
444
449
  // Down the guide line, then a rounded turn right, stopping just short of this row's
445
450
  // chevron. Starts half a chevron above the row so the line emerges from under the
446
451
  // parent's chevron instead of leaving a half-row gap.
@@ -448,7 +453,7 @@ function ze({ className: e, children: r, size: t, style: s, icon: a, trailing: c
448
453
  "span",
449
454
  {
450
455
  "data-slot": "tree-item-guide-elbow",
451
- className: N(
456
+ className: I(
452
457
  "absolute top-[-0.4375rem] left-[var(--tree-guide-left)] border-[var(--tree-guide-color)]",
453
458
  "h-[calc(50%+0.4375rem)] w-[var(--tree-elbow-run)] border-b border-l",
454
459
  "rounded-bl-[var(--tree-elbow-radius)]"
@@ -470,54 +475,54 @@ function ze({ className: e, children: r, size: t, style: s, icon: a, trailing: c
470
475
  {
471
476
  "data-slot": "tree-item-indicator",
472
477
  "aria-hidden": "true",
473
- onClick: (f) => {
474
- f.stopPropagation(), R();
478
+ onClick: (m) => {
479
+ m.stopPropagation(), R();
475
480
  },
476
481
  className: "flex size-3.5 shrink-0 items-center justify-center text-muted-foreground",
477
- children: /* @__PURE__ */ i(ie, { className: N("size-3.5 transition-transform", p && "rotate-90") })
482
+ children: /* @__PURE__ */ i(ce, { className: I("size-3.5 transition-transform", p && "rotate-90") })
478
483
  }
479
484
  )
480
485
  ) : /* @__PURE__ */ i("span", { "data-slot": "tree-item-indicator-spacer", "aria-hidden": "true", className: "size-3.5 shrink-0" }),
481
- a ? /* @__PURE__ */ i(
486
+ o ? /* @__PURE__ */ i(
482
487
  "span",
483
488
  {
484
489
  "data-slot": "tree-item-icon",
485
490
  "aria-hidden": "true",
486
- className: N(
491
+ className: I(
487
492
  "flex size-4 shrink-0 items-center justify-center [&_svg]:size-4 [&_svg]:shrink-0",
488
493
  x ? "text-accent-foreground" : "text-muted-foreground"
489
494
  ),
490
- children: a
495
+ children: o
491
496
  }
492
497
  ) : null,
493
- /* @__PURE__ */ q(ue, { open: L, onOpenChange: S, children: [
494
- /* @__PURE__ */ i(de, { asChild: !0, children: /* @__PURE__ */ i(
498
+ /* @__PURE__ */ O(fe, { open: L, onOpenChange: S, children: [
499
+ /* @__PURE__ */ i(me, { asChild: !0, children: /* @__PURE__ */ i(
495
500
  "span",
496
501
  {
497
- ref: h,
502
+ ref: g,
498
503
  "data-slot": "tree-item-text",
499
504
  className: "-mx-1 min-w-0 flex-1 truncate px-1",
500
- children: /* @__PURE__ */ i(ke, { match: E, children: r })
505
+ children: /* @__PURE__ */ i(Ne, { match: E, children: r })
501
506
  }
502
507
  ) }),
503
- /* @__PURE__ */ i(fe, { children: r })
508
+ /* @__PURE__ */ i(pe, { children: r })
504
509
  ] }),
505
- c ? /* @__PURE__ */ i("span", { "data-slot": "tree-item-trailing", className: "ml-auto flex shrink-0 items-center gap-1 [&_svg]:size-3.5", children: c }) : null
510
+ d ? /* @__PURE__ */ i("span", { "data-slot": "tree-item-trailing", className: "ml-auto flex shrink-0 items-center gap-1 [&_svg]:size-3.5", children: d }) : null
506
511
  ]
507
512
  }
508
513
  );
509
514
  }
510
- function ke({ match: e, children: r }) {
515
+ function Ne({ match: e, children: r }) {
511
516
  if (!e || typeof r != "string" || !r.toLowerCase().startsWith(e.query))
512
517
  return r;
513
518
  const { query: t, fading: s } = e;
514
- return /* @__PURE__ */ q(se, { children: [
519
+ return /* @__PURE__ */ O(ie, { children: [
515
520
  /* @__PURE__ */ i(
516
521
  "span",
517
522
  {
518
523
  "data-slot": "tree-item-typeahead-match",
519
524
  "data-state": s ? "fading" : "active",
520
- className: N(
525
+ className: I(
521
526
  // The SW-2445 selected-state tokens: a primary tint that reads as "this is the match" on
522
527
  // a resting, hovered or selected row, in both themes. Plain spans, not `<mark>`, so the
523
528
  // label's accessible name is unchanged.
@@ -536,16 +541,75 @@ function ke({ match: e, children: r }) {
536
541
  r.slice(t.length)
537
542
  ] });
538
543
  }
539
- function Fe({ className: e, children: r, ...t }) {
540
- const { expanded: s, level: a } = Y("TreeItemGroup");
541
- return s ? /* @__PURE__ */ i(U.Provider, { value: a + 1, children: /* @__PURE__ */ i("div", { ...t, "data-slot": "tree-item-group", role: "group", className: N("flex flex-col", e), children: /* @__PURE__ */ i(ae, { children: r }) }) }) : null;
544
+ function Be({ className: e, children: r, ...t }) {
545
+ const { expanded: s, level: o } = Y("TreeItemGroup");
546
+ return s ? /* @__PURE__ */ i(j.Provider, { value: o + 1, children: /* @__PURE__ */ i("div", { ...t, "data-slot": "tree-item-group", role: "group", className: I("flex flex-col", e), children: /* @__PURE__ */ i(se, { children: r }) }) }) : null;
547
+ }
548
+ function Re({ className: e, children: r, style: t, ...s }) {
549
+ const o = a.useContext(j);
550
+ return /* @__PURE__ */ O(
551
+ "div",
552
+ {
553
+ ...s,
554
+ "data-slot": "tree-empty",
555
+ role: "treeitem",
556
+ "aria-selected": "false",
557
+ tabIndex: -1,
558
+ style: { paddingInlineStart: `calc(var(--tree-indent) * ${o - 1} + 0.25rem)`, ...t },
559
+ className: I(
560
+ "text-muted-foreground flex h-7 w-full min-w-0 items-center gap-1.5 rounded-md border border-transparent pr-2 text-left text-sm [&_svg]:size-4 [&_svg]:shrink-0",
561
+ e
562
+ ),
563
+ children: [
564
+ /* @__PURE__ */ i("span", { "data-slot": "tree-item-indicator-spacer", "aria-hidden": "true", className: "size-3.5 shrink-0" }),
565
+ r
566
+ ]
567
+ }
568
+ );
569
+ }
570
+ function Pe({ className: e, children: r = "Load more", icon: t, size: s, style: o, onClick: d, ...c }) {
571
+ const l = a.useContext(j);
572
+ return /* @__PURE__ */ i("div", { "data-slot": "tree-load-more", role: "treeitem", "aria-selected": "false", className: "flex w-full", children: /* @__PURE__ */ O(
573
+ "button",
574
+ {
575
+ ...c,
576
+ type: "button",
577
+ onClick: (f) => {
578
+ f.stopPropagation(), d?.(f);
579
+ },
580
+ style: { paddingInlineStart: `calc(var(--tree-indent) * ${l - 1} + 0.25rem)`, ...o },
581
+ className: I(
582
+ le({ size: s }),
583
+ "text-muted-foreground border border-transparent outline-none",
584
+ "hover:bg-muted hover:text-foreground",
585
+ "focus-visible:border-ring focus-visible:shadow-focus",
586
+ "active:bg-accent active:text-accent-foreground",
587
+ e
588
+ ),
589
+ children: [
590
+ /* @__PURE__ */ i("span", { "data-slot": "tree-item-indicator-spacer", "aria-hidden": "true", className: "size-3.5 shrink-0" }),
591
+ t ? /* @__PURE__ */ i(
592
+ "span",
593
+ {
594
+ "data-slot": "tree-item-icon",
595
+ "aria-hidden": "true",
596
+ className: "flex size-4 shrink-0 items-center justify-center [&_svg]:size-4 [&_svg]:shrink-0",
597
+ children: t
598
+ }
599
+ ) : null,
600
+ /* @__PURE__ */ i("span", { className: "min-w-0 flex-1 truncate", children: r })
601
+ ]
602
+ }
603
+ ) });
542
604
  }
543
605
  export {
544
- _e as Tree,
545
- Me as TreeItem,
546
- Fe as TreeItemGroup,
547
- ze as TreeItemLabel,
548
- we as treeItemLabelVariants,
549
- Se as useTreeItem
606
+ Fe as Tree,
607
+ Re as TreeEmpty,
608
+ Ke as TreeItem,
609
+ Be as TreeItemGroup,
610
+ Oe as TreeItemLabel,
611
+ Pe as TreeLoadMore,
612
+ le as treeItemLabelVariants,
613
+ Me as useTreeItem
550
614
  };
551
615
  //# sourceMappingURL=tree.js.map