jenosize-ui 0.1.0
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/LICENSE +28 -0
- package/README.md +100 -0
- package/THIRD-PARTY-NOTICES.md +163 -0
- package/dist/Button-Bt7pzM4R.d.ts +82 -0
- package/dist/PaymentInput-CKPIPNWH.d.ts +141 -0
- package/dist/Select-CVbEQ2Ep.d.ts +118 -0
- package/dist/TagInput-CTJYOB4J.d.ts +90 -0
- package/dist/avatar.d.ts +161 -0
- package/dist/avatar.js +11 -0
- package/dist/badge.d.ts +109 -0
- package/dist/badge.js +10 -0
- package/dist/breadcrumb.d.ts +58 -0
- package/dist/breadcrumb.js +7 -0
- package/dist/button.d.ts +54 -0
- package/dist/button.js +14 -0
- package/dist/calendar.d.ts +368 -0
- package/dist/calendar.js +21 -0
- package/dist/callout.d.ts +70 -0
- package/dist/callout.js +16 -0
- package/dist/card-nWicloNi.d.ts +80 -0
- package/dist/card.d.ts +2 -0
- package/dist/card.js +7 -0
- package/dist/checkbox.d.ts +133 -0
- package/dist/checkbox.js +11 -0
- package/dist/chunk-24TO7E32.js +42 -0
- package/dist/chunk-3Y5X7B5C.js +146 -0
- package/dist/chunk-4OLULPQG.js +202 -0
- package/dist/chunk-4P2NBLBW.js +103 -0
- package/dist/chunk-52IFGFTL.js +11 -0
- package/dist/chunk-5FATN5YD.js +115 -0
- package/dist/chunk-5NOBSXJN.js +297 -0
- package/dist/chunk-5RAPA22E.js +106 -0
- package/dist/chunk-7EUAMHMU.js +16 -0
- package/dist/chunk-7EWQKTNQ.js +1336 -0
- package/dist/chunk-7HOIZ3UO.js +110 -0
- package/dist/chunk-7IU5TMFL.js +452 -0
- package/dist/chunk-7JBNLEJ7.js +29 -0
- package/dist/chunk-7S2TBALK.js +23 -0
- package/dist/chunk-BJUZVYQC.js +188 -0
- package/dist/chunk-BVJWBYIG.js +66 -0
- package/dist/chunk-CME4DIML.js +65 -0
- package/dist/chunk-CYPPEUX5.js +73 -0
- package/dist/chunk-D5BTFSL7.js +71 -0
- package/dist/chunk-D6TPWNRK.js +387 -0
- package/dist/chunk-DJSXIAFH.js +66 -0
- package/dist/chunk-DRZCJCBO.js +46 -0
- package/dist/chunk-DWKILXHE.js +17 -0
- package/dist/chunk-E7ZSWBAK.js +70 -0
- package/dist/chunk-EDSK6FEH.js +8 -0
- package/dist/chunk-F2K7VJUV.js +114 -0
- package/dist/chunk-F6NLE6XJ.js +40 -0
- package/dist/chunk-FHHAPGCR.js +32 -0
- package/dist/chunk-FXIBGTS5.js +14 -0
- package/dist/chunk-GCVA3OIV.js +72 -0
- package/dist/chunk-GFOAJVW5.js +336 -0
- package/dist/chunk-GRLSUQQE.js +136 -0
- package/dist/chunk-GTHJWR3Q.js +77 -0
- package/dist/chunk-HMUZE6EK.js +67 -0
- package/dist/chunk-I7WU4GTY.js +503 -0
- package/dist/chunk-J2BCKBHC.js +151 -0
- package/dist/chunk-J36M3KRX.js +1315 -0
- package/dist/chunk-J7ZQQFPT.js +113 -0
- package/dist/chunk-JP26LPCY.js +234 -0
- package/dist/chunk-JTNFJLIY.js +1046 -0
- package/dist/chunk-JVJRHBTD.js +50 -0
- package/dist/chunk-JYGR44ZC.js +133 -0
- package/dist/chunk-KDLPXXD2.js +173 -0
- package/dist/chunk-KMSYEE23.js +224 -0
- package/dist/chunk-KNYKWUYX.js +52 -0
- package/dist/chunk-LME57Z6J.js +138 -0
- package/dist/chunk-MFJP5FA7.js +20 -0
- package/dist/chunk-MKC5HNA7.js +1692 -0
- package/dist/chunk-MQGD2OUF.js +39 -0
- package/dist/chunk-MUFHLP4S.js +566 -0
- package/dist/chunk-O2LG3PNI.js +74 -0
- package/dist/chunk-O4GRKO3I.js +66 -0
- package/dist/chunk-OHUFNYGN.js +791 -0
- package/dist/chunk-PWKWNDBS.js +243 -0
- package/dist/chunk-QA74ITR4.js +103 -0
- package/dist/chunk-R6RGJF4L.js +170 -0
- package/dist/chunk-S7NNXWIN.js +7 -0
- package/dist/chunk-SV56BSUQ.js +162 -0
- package/dist/chunk-T7FCG7XV.js +435 -0
- package/dist/chunk-THC2ISYP.js +57 -0
- package/dist/chunk-VWC72TR3.js +115 -0
- package/dist/chunk-W46K56XU.js +216 -0
- package/dist/chunk-W5GGOUUI.js +75 -0
- package/dist/chunk-WEUJYDCV.js +269 -0
- package/dist/chunk-WFY7DKQD.js +279 -0
- package/dist/chunk-WZQFC7ZN.js +448 -0
- package/dist/chunk-Z3ETJN5G.js +136 -0
- package/dist/chunk-ZOOX3TUB.js +192 -0
- package/dist/chunk-ZSNJ6UA3.js +42 -0
- package/dist/chunk-ZZA2LUTL.js +130 -0
- package/dist/chunk-ZZT2E5VT.js +24 -0
- package/dist/color-CtSxc1Rh.d.ts +6 -0
- package/dist/combobox.d.ts +184 -0
- package/dist/combobox.js +21 -0
- package/dist/date-input.d.ts +83 -0
- package/dist/date-input.js +16 -0
- package/dist/date-picker.d.ts +249 -0
- package/dist/date-picker.js +29 -0
- package/dist/date-utils-7hTFTXNK.d.ts +34 -0
- package/dist/date-vMJBKAFK.d.ts +22 -0
- package/dist/dialog.d.ts +86 -0
- package/dist/dialog.js +15 -0
- package/dist/drawer.d.ts +77 -0
- package/dist/drawer.js +14 -0
- package/dist/dropdown-menu.d.ts +218 -0
- package/dist/dropdown-menu.js +10 -0
- package/dist/file-trigger.d.ts +42 -0
- package/dist/file-trigger.js +3 -0
- package/dist/form.d.ts +487 -0
- package/dist/form.js +1179 -0
- package/dist/header-navigation.d.ts +74 -0
- package/dist/header-navigation.js +23 -0
- package/dist/icons/app.d.ts +48 -0
- package/dist/icons/app.js +282 -0
- package/dist/icons/flag.d.ts +817 -0
- package/dist/icons/flag.js +58336 -0
- package/dist/icons/integration.d.ts +36 -0
- package/dist/icons/integration.js +531 -0
- package/dist/icons/payment.d.ts +116 -0
- package/dist/icons/payment.js +2418 -0
- package/dist/icons.d.ts +2013 -0
- package/dist/icons.js +2012 -0
- package/dist/illustration.d.ts +48 -0
- package/dist/illustration.js +4 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +73 -0
- package/dist/indicator.d.ts +51 -0
- package/dist/indicator.js +7 -0
- package/dist/input.d.ts +66 -0
- package/dist/input.js +15 -0
- package/dist/multi-value-CJb_tnvi.d.ts +8 -0
- package/dist/nav-Bla0o_-1.d.ts +98 -0
- package/dist/number-input.d.ts +80 -0
- package/dist/number-input.js +15 -0
- package/dist/options-CPEIgjtd.d.ts +68 -0
- package/dist/overflow-Df0h42Oi.d.ts +29 -0
- package/dist/pagination.d.ts +77 -0
- package/dist/pagination.js +17 -0
- package/dist/payment-input.d.ts +7 -0
- package/dist/payment-input.js +15 -0
- package/dist/popover.d.ts +60 -0
- package/dist/popover.js +14 -0
- package/dist/progress.d.ts +87 -0
- package/dist/progress.js +5 -0
- package/dist/radio.d.ts +77 -0
- package/dist/radio.js +12 -0
- package/dist/select.d.ts +68 -0
- package/dist/select.js +24 -0
- package/dist/shared-BNXAdgh2.d.ts +9 -0
- package/dist/shared-BYXJPnsN.d.ts +11 -0
- package/dist/shared-Dc-GgA16.d.ts +42 -0
- package/dist/sidebar-navigation.d.ts +129 -0
- package/dist/sidebar-navigation.js +15 -0
- package/dist/styles.css +2 -0
- package/dist/switch.d.ts +23 -0
- package/dist/switch.js +7 -0
- package/dist/table.d.ts +692 -0
- package/dist/table.js +44 -0
- package/dist/tabs.d.ts +111 -0
- package/dist/tabs.js +8 -0
- package/dist/tag-input.d.ts +12 -0
- package/dist/tag-input.js +19 -0
- package/dist/tag.d.ts +98 -0
- package/dist/tag.js +9 -0
- package/dist/textarea.d.ts +40 -0
- package/dist/textarea.js +12 -0
- package/dist/theme-script.d.ts +29 -0
- package/dist/theme-script.js +15 -0
- package/dist/theme.css +929 -0
- package/dist/theme.d.ts +71 -0
- package/dist/theme.js +15 -0
- package/dist/toast.d.ts +242 -0
- package/dist/toast.js +15 -0
- package/dist/tooltip.d.ts +70 -0
- package/dist/tooltip.js +6 -0
- package/dist/tree.d.ts +308 -0
- package/dist/tree.js +11 -0
- package/package.json +352 -0
|
@@ -0,0 +1,1336 @@
|
|
|
1
|
+
import { useAutoScroll, useDrag } from './chunk-KMSYEE23.js';
|
|
2
|
+
import { SkeletonBar } from './chunk-FXIBGTS5.js';
|
|
3
|
+
import { useDebounced } from './chunk-F6NLE6XJ.js';
|
|
4
|
+
import { Slot } from './chunk-52IFGFTL.js';
|
|
5
|
+
import { useIsomorphicLayoutEffect } from './chunk-EDSK6FEH.js';
|
|
6
|
+
import { LoaderCircleIcon, CircleAlertIcon, ChevronRightIcon, GripVerticalIcon, CheckIcon, MinusIcon } from './chunk-24TO7E32.js';
|
|
7
|
+
import { devWarn, warnNonNegativeInt, warnNeedsName } from './chunk-GCVA3OIV.js';
|
|
8
|
+
import { cn } from './chunk-ZSNJ6UA3.js';
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
11
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
12
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
13
|
+
|
|
14
|
+
// src/components/tree/nodes.ts
|
|
15
|
+
function isBranch(node) {
|
|
16
|
+
return node.hasChildren ?? node.children != null;
|
|
17
|
+
}
|
|
18
|
+
function isUnloadedBranch(node) {
|
|
19
|
+
return isBranch(node) && node.children == null;
|
|
20
|
+
}
|
|
21
|
+
function walkTree(nodes, visit) {
|
|
22
|
+
const step2 = (list, depth, parentId) => {
|
|
23
|
+
for (const node of list) {
|
|
24
|
+
if (visit(node, depth, parentId) === false) continue;
|
|
25
|
+
if (node.children) step2(node.children, depth + 1, node.id);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
step2(nodes, 0, null);
|
|
29
|
+
}
|
|
30
|
+
function buildNodeMap(nodes) {
|
|
31
|
+
const map = /* @__PURE__ */ new Map();
|
|
32
|
+
walkTree(nodes, (node) => {
|
|
33
|
+
map.set(node.id, node);
|
|
34
|
+
});
|
|
35
|
+
return map;
|
|
36
|
+
}
|
|
37
|
+
function buildParentMap(nodes) {
|
|
38
|
+
const map = /* @__PURE__ */ new Map();
|
|
39
|
+
walkTree(nodes, (node, _depth, parentId) => {
|
|
40
|
+
map.set(node.id, parentId);
|
|
41
|
+
});
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
function ancestorIds(nodes, id) {
|
|
45
|
+
const trail = [];
|
|
46
|
+
let found = null;
|
|
47
|
+
const step2 = (list) => {
|
|
48
|
+
for (const node of list) {
|
|
49
|
+
if (node.id === id) return true;
|
|
50
|
+
if (node.children) {
|
|
51
|
+
trail.push(node.id);
|
|
52
|
+
if (step2(node.children)) return true;
|
|
53
|
+
trail.pop();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
if (step2(nodes)) found = [...trail];
|
|
59
|
+
return found ?? [];
|
|
60
|
+
}
|
|
61
|
+
function isDescendant(nodes, id, candidate) {
|
|
62
|
+
const subtree = findNode(nodes, id);
|
|
63
|
+
if (!subtree) return false;
|
|
64
|
+
let hit = false;
|
|
65
|
+
walkTree([subtree], (node) => {
|
|
66
|
+
if (node.id === candidate) hit = true;
|
|
67
|
+
});
|
|
68
|
+
return hit;
|
|
69
|
+
}
|
|
70
|
+
function findNode(nodes, id) {
|
|
71
|
+
let found;
|
|
72
|
+
walkTree(nodes, (node) => {
|
|
73
|
+
if (node.id === id) found = node;
|
|
74
|
+
});
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
function detach(nodes, id) {
|
|
78
|
+
const step2 = (list) => list.filter((node) => node.id !== id).map((node) => node.children ? { ...node, children: step2(node.children) } : node);
|
|
79
|
+
return step2(nodes);
|
|
80
|
+
}
|
|
81
|
+
function attach(nodes, move, node) {
|
|
82
|
+
const step2 = (list) => {
|
|
83
|
+
const at = list.findIndex((n) => n.id === move.target);
|
|
84
|
+
if (at !== -1 && move.position !== "child") {
|
|
85
|
+
const next = [...list];
|
|
86
|
+
next.splice(move.position === "before" ? at : at + 1, 0, node);
|
|
87
|
+
return next;
|
|
88
|
+
}
|
|
89
|
+
return list.map((n) => {
|
|
90
|
+
if (n.id === move.target && move.position === "child") {
|
|
91
|
+
return { ...n, children: [...n.children ?? [], node] };
|
|
92
|
+
}
|
|
93
|
+
return n.children ? { ...n, children: step2(n.children) } : n;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return step2(nodes);
|
|
97
|
+
}
|
|
98
|
+
function applyTreeMove(nodes, move) {
|
|
99
|
+
const moving = findNode(nodes, move.id);
|
|
100
|
+
if (!moving) {
|
|
101
|
+
devWarn(`applyTreeMove: no node with id \`${move.id}\` \u2014 the move was ignored.`);
|
|
102
|
+
return nodes;
|
|
103
|
+
}
|
|
104
|
+
if (!findNode(nodes, move.target)) {
|
|
105
|
+
devWarn(`applyTreeMove: no target with id \`${move.target}\` \u2014 the move was ignored.`);
|
|
106
|
+
return nodes;
|
|
107
|
+
}
|
|
108
|
+
if (isDescendant(nodes, move.id, move.target)) {
|
|
109
|
+
devWarn(`applyTreeMove: \`${move.target}\` is inside \`${move.id}\`'s own subtree \u2014 the move was ignored.`);
|
|
110
|
+
return nodes;
|
|
111
|
+
}
|
|
112
|
+
return attach(detach(nodes, move.id), move, moving);
|
|
113
|
+
}
|
|
114
|
+
function attachChildren(nodes, id, children) {
|
|
115
|
+
let hit = false;
|
|
116
|
+
const step2 = (list) => list.map((node) => {
|
|
117
|
+
if (node.id === id) {
|
|
118
|
+
hit = true;
|
|
119
|
+
return { ...node, children };
|
|
120
|
+
}
|
|
121
|
+
return node.children ? { ...node, children: step2(node.children) } : node;
|
|
122
|
+
});
|
|
123
|
+
const next = step2(nodes);
|
|
124
|
+
if (!hit) {
|
|
125
|
+
devWarn(`attachChildren: no node with id \`${id}\` \u2014 nothing was attached.`);
|
|
126
|
+
return nodes;
|
|
127
|
+
}
|
|
128
|
+
return next;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/components/tree/dnd.ts
|
|
132
|
+
function rowHitbox(pt, rect, ctx) {
|
|
133
|
+
if (rect.height <= 0) return null;
|
|
134
|
+
if (pt.y < rect.top || pt.y > rect.bottom) return null;
|
|
135
|
+
const ratio = (pt.y - rect.top) / rect.height;
|
|
136
|
+
if (!ctx.canHaveChildren) return ratio < 0.5 ? "before" : "after";
|
|
137
|
+
if (ratio < 0.25) return "before";
|
|
138
|
+
if (ratio >= 0.75) return "after";
|
|
139
|
+
return "child";
|
|
140
|
+
}
|
|
141
|
+
function outdentSteps(pt, rect, ctx) {
|
|
142
|
+
const left = rect.left - pt.x;
|
|
143
|
+
if (left <= 0) return 0;
|
|
144
|
+
return Math.min(ctx.depth, Math.floor(left / ctx.indent));
|
|
145
|
+
}
|
|
146
|
+
function structurallyAllowed(move, ctx) {
|
|
147
|
+
if (ctx.isFiltering) return false;
|
|
148
|
+
if (ctx.isDescendant(move.id, move.target)) return false;
|
|
149
|
+
if (move.position === "child" && ctx.isUnloaded(move.target)) return false;
|
|
150
|
+
if (ctx.isDisabled(move.id) || ctx.isDisabled(move.target)) return false;
|
|
151
|
+
return !isNoOp(move, ctx);
|
|
152
|
+
}
|
|
153
|
+
function isNoOp(move, ctx) {
|
|
154
|
+
const parent = ctx.parentOf(move.id);
|
|
155
|
+
const targetParent = ctx.parentOf(move.target);
|
|
156
|
+
if (move.position === "child") {
|
|
157
|
+
return parent === move.target && ctx.indexOf(move.id) === ctx.siblingCountOf(move.id) - 1;
|
|
158
|
+
}
|
|
159
|
+
if (parent !== targetParent) return false;
|
|
160
|
+
const from = ctx.indexOf(move.id);
|
|
161
|
+
const to = ctx.indexOf(move.target);
|
|
162
|
+
const slot = move.position === "before" ? to - 1 : to + 1;
|
|
163
|
+
return from === slot;
|
|
164
|
+
}
|
|
165
|
+
function toMove(dragged, target, position, steps, ancestorAt) {
|
|
166
|
+
if (position === "after" && steps > 0) {
|
|
167
|
+
const outdented = ancestorAt(target, steps);
|
|
168
|
+
if (outdented !== null) return { id: dragged, target: outdented, position: "after" };
|
|
169
|
+
}
|
|
170
|
+
return { id: dragged, target, position };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/components/tree/use-tree.ts
|
|
174
|
+
var toSet = (v) => v === void 0 ? void 0 : v instanceof Set ? v : new Set(v);
|
|
175
|
+
var EMPTY_SET = /* @__PURE__ */ new Set();
|
|
176
|
+
var emptySet = () => EMPTY_SET;
|
|
177
|
+
function useTree(options) {
|
|
178
|
+
const { nodes, onExpandedChange, onSelectedChange, onActivate, disabledNodes } = options;
|
|
179
|
+
const nodeMap = React.useMemo(() => buildNodeMap(nodes), [nodes]);
|
|
180
|
+
const parentMap = React.useMemo(() => buildParentMap(nodes), [nodes]);
|
|
181
|
+
React.useEffect(() => {
|
|
182
|
+
warnNonNegativeInt("Tree", "filterDelay", options.filterDelay);
|
|
183
|
+
}, [options.filterDelay]);
|
|
184
|
+
const [expandedState, setExpandedState] = React.useState(() => toSet(options.defaultExpanded) ?? emptySet());
|
|
185
|
+
const expanded = toSet(options.expanded) ?? expandedState;
|
|
186
|
+
const maybeFetch = React.useRef(() => false);
|
|
187
|
+
const filteringRef = React.useRef(false);
|
|
188
|
+
const latestExpanded = React.useRef(expanded);
|
|
189
|
+
latestExpanded.current = expanded;
|
|
190
|
+
const commitExpanded = React.useCallback(
|
|
191
|
+
(next) => {
|
|
192
|
+
let pruned = next;
|
|
193
|
+
for (const id of next) {
|
|
194
|
+
if (!nodeMap.has(id)) {
|
|
195
|
+
pruned = new Set([...next].filter((candidate) => nodeMap.has(candidate)));
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
latestExpanded.current = pruned;
|
|
200
|
+
if (options.expanded === void 0) setExpandedState(pruned);
|
|
201
|
+
onExpandedChange?.(pruned);
|
|
202
|
+
},
|
|
203
|
+
[nodeMap, onExpandedChange, options.expanded]
|
|
204
|
+
);
|
|
205
|
+
const expand = React.useCallback(
|
|
206
|
+
(id) => {
|
|
207
|
+
const base = latestExpanded.current;
|
|
208
|
+
if (base.has(id)) return;
|
|
209
|
+
maybeFetch.current(id);
|
|
210
|
+
commitExpanded(new Set(base).add(id));
|
|
211
|
+
},
|
|
212
|
+
[commitExpanded]
|
|
213
|
+
);
|
|
214
|
+
const collapse = React.useCallback(
|
|
215
|
+
(id) => {
|
|
216
|
+
const base = latestExpanded.current;
|
|
217
|
+
if (!base.has(id)) return;
|
|
218
|
+
const next = new Set(base);
|
|
219
|
+
next.delete(id);
|
|
220
|
+
commitExpanded(next);
|
|
221
|
+
},
|
|
222
|
+
[commitExpanded]
|
|
223
|
+
);
|
|
224
|
+
const toggleExpanded = React.useCallback(
|
|
225
|
+
(id) => {
|
|
226
|
+
const next = new Set(latestExpanded.current);
|
|
227
|
+
if (next.has(id)) next.delete(id);
|
|
228
|
+
else {
|
|
229
|
+
next.add(id);
|
|
230
|
+
maybeFetch.current(id);
|
|
231
|
+
}
|
|
232
|
+
commitExpanded(next);
|
|
233
|
+
},
|
|
234
|
+
[commitExpanded]
|
|
235
|
+
);
|
|
236
|
+
const expandAll = React.useCallback(() => {
|
|
237
|
+
if (filteringRef.current) return;
|
|
238
|
+
const base = latestExpanded.current;
|
|
239
|
+
const next = new Set(base);
|
|
240
|
+
for (const node of nodeMap.values()) {
|
|
241
|
+
if (!isBranch(node)) continue;
|
|
242
|
+
if (node.children != null) {
|
|
243
|
+
next.add(node.id);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (maybeFetch.current(node.id)) next.add(node.id);
|
|
247
|
+
}
|
|
248
|
+
if (next.size === base.size) return;
|
|
249
|
+
commitExpanded(next);
|
|
250
|
+
}, [commitExpanded, nodeMap]);
|
|
251
|
+
const collapseAll = React.useCallback(() => {
|
|
252
|
+
if (latestExpanded.current.size === 0) return;
|
|
253
|
+
commitExpanded(emptySet());
|
|
254
|
+
}, [commitExpanded]);
|
|
255
|
+
const revealNode = React.useCallback(
|
|
256
|
+
(id) => {
|
|
257
|
+
if (!nodeMap.has(id)) return;
|
|
258
|
+
const base = latestExpanded.current;
|
|
259
|
+
const trail = ancestorIds(nodes, id);
|
|
260
|
+
const missing = trail.filter((ancestor) => !base.has(ancestor));
|
|
261
|
+
if (missing.length === 0) return;
|
|
262
|
+
const next = new Set(base);
|
|
263
|
+
for (const ancestor of missing) next.add(ancestor);
|
|
264
|
+
commitExpanded(next);
|
|
265
|
+
},
|
|
266
|
+
[commitExpanded, nodeMap, nodes]
|
|
267
|
+
);
|
|
268
|
+
const rawQuery = options.filter ?? "";
|
|
269
|
+
const filterDelay = options.filterDelay ?? 150;
|
|
270
|
+
const debounced = useDebounced(rawQuery, filterDelay);
|
|
271
|
+
const query = rawQuery === "" ? "" : debounced;
|
|
272
|
+
const isFiltering = query.trim().length > 0;
|
|
273
|
+
filteringRef.current = isFiltering;
|
|
274
|
+
const match = options.match;
|
|
275
|
+
const { kept, matches } = React.useMemo(() => {
|
|
276
|
+
if (!isFiltering) return { kept: null, matches: emptySet() };
|
|
277
|
+
const needle = query.trim().toLowerCase();
|
|
278
|
+
const hit = (node) => {
|
|
279
|
+
if (match) return match(node, query);
|
|
280
|
+
return typeof node.label === "string" && node.label.toLowerCase().includes(needle);
|
|
281
|
+
};
|
|
282
|
+
const keptIds = /* @__PURE__ */ new Set();
|
|
283
|
+
const matchIds = /* @__PURE__ */ new Set();
|
|
284
|
+
const step2 = (list) => {
|
|
285
|
+
let any = false;
|
|
286
|
+
for (const node of list) {
|
|
287
|
+
const self = hit(node);
|
|
288
|
+
if (self) matchIds.add(node.id);
|
|
289
|
+
const below = node.children ? step2(node.children) : false;
|
|
290
|
+
const unloaded = isUnloadedBranch(node);
|
|
291
|
+
if (self || below || unloaded) {
|
|
292
|
+
keptIds.add(node.id);
|
|
293
|
+
any = true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return any;
|
|
297
|
+
};
|
|
298
|
+
step2(nodes);
|
|
299
|
+
return { kept: keptIds, matches: matchIds };
|
|
300
|
+
}, [isFiltering, match, nodes, query]);
|
|
301
|
+
const visible = React.useMemo(() => {
|
|
302
|
+
const out = [];
|
|
303
|
+
const step2 = (list, depth, parentId) => {
|
|
304
|
+
const rendered = kept === null ? list : list.filter((node) => kept.has(node.id));
|
|
305
|
+
const siblingCount = rendered.length;
|
|
306
|
+
for (const [index, node] of rendered.entries()) {
|
|
307
|
+
out.push({ node, depth, parentId, index, siblingCount });
|
|
308
|
+
const children = node.children;
|
|
309
|
+
const open = kept === null ? expanded.has(node.id) : true;
|
|
310
|
+
if (isBranch(node) && children && children.length > 0 && open) {
|
|
311
|
+
step2(children, depth + 1, node.id);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
step2(nodes, 0, null);
|
|
316
|
+
return out;
|
|
317
|
+
}, [expanded, kept, nodes]);
|
|
318
|
+
const expandSiblings = React.useCallback(
|
|
319
|
+
(id) => {
|
|
320
|
+
const row = visible.find((v) => v.node.id === id);
|
|
321
|
+
if (!row) return;
|
|
322
|
+
const next = new Set(latestExpanded.current);
|
|
323
|
+
const before = next.size;
|
|
324
|
+
for (const candidate of visible) {
|
|
325
|
+
if (candidate.parentId !== row.parentId || candidate.depth !== row.depth) continue;
|
|
326
|
+
const node = nodeMap.get(candidate.node.id);
|
|
327
|
+
if (!node || !isBranch(node)) continue;
|
|
328
|
+
if (node.children != null || maybeFetch.current(candidate.node.id)) next.add(candidate.node.id);
|
|
329
|
+
}
|
|
330
|
+
if (next.size === before) return;
|
|
331
|
+
commitExpanded(next);
|
|
332
|
+
},
|
|
333
|
+
[commitExpanded, nodeMap, visible]
|
|
334
|
+
);
|
|
335
|
+
const nodeById = React.useCallback((id) => nodeMap.get(id), [nodeMap]);
|
|
336
|
+
const parentOf = React.useCallback((id) => parentMap.get(id) ?? null, [parentMap]);
|
|
337
|
+
const isDisabled = React.useCallback(
|
|
338
|
+
(id) => {
|
|
339
|
+
const node = nodeMap.get(id);
|
|
340
|
+
if (!node) return false;
|
|
341
|
+
return node.disabled === true || disabledNodes?.(node) === true;
|
|
342
|
+
},
|
|
343
|
+
[disabledNodes, nodeMap]
|
|
344
|
+
);
|
|
345
|
+
const isBranchById = React.useCallback(
|
|
346
|
+
(id) => {
|
|
347
|
+
const node = nodeMap.get(id);
|
|
348
|
+
return node ? isBranch(node) : false;
|
|
349
|
+
},
|
|
350
|
+
[nodeMap]
|
|
351
|
+
);
|
|
352
|
+
const selection = options.selection ?? "none";
|
|
353
|
+
const checkboxes = options.checkboxes ?? false;
|
|
354
|
+
const cascade = selection === "multiple" && checkboxes;
|
|
355
|
+
const [selectedState, setSelectedState] = React.useState(() => toSet(options.defaultSelected) ?? emptySet());
|
|
356
|
+
const selected = toSet(options.selected) ?? selectedState;
|
|
357
|
+
const latestSelected = React.useRef(selected);
|
|
358
|
+
latestSelected.current = selected;
|
|
359
|
+
const anchor = React.useRef(null);
|
|
360
|
+
const commitSelected = React.useCallback(
|
|
361
|
+
(next) => {
|
|
362
|
+
latestSelected.current = next;
|
|
363
|
+
if (options.selected === void 0) setSelectedState(next);
|
|
364
|
+
onSelectedChange?.(next);
|
|
365
|
+
},
|
|
366
|
+
[onSelectedChange, options.selected]
|
|
367
|
+
);
|
|
368
|
+
const checkedState = React.useCallback(
|
|
369
|
+
(id) => {
|
|
370
|
+
if (selected.has(id)) return "checked";
|
|
371
|
+
if (!cascade) return "unchecked";
|
|
372
|
+
for (const ancestor of ancestorIds(nodes, id)) if (selected.has(ancestor)) return "checked";
|
|
373
|
+
const node = nodeMap.get(id);
|
|
374
|
+
if (!node || !isBranch(node)) return "unchecked";
|
|
375
|
+
let hit = false;
|
|
376
|
+
walkTree(node.children ?? [], (descendant) => {
|
|
377
|
+
if (selected.has(descendant.id)) hit = true;
|
|
378
|
+
});
|
|
379
|
+
return hit ? "mixed" : "unchecked";
|
|
380
|
+
},
|
|
381
|
+
[cascade, nodeMap, nodes, selected]
|
|
382
|
+
);
|
|
383
|
+
const checkedLeaves = React.useMemo(() => {
|
|
384
|
+
if (selection === "none") return emptySet();
|
|
385
|
+
const out = /* @__PURE__ */ new Set();
|
|
386
|
+
const step2 = (list, inherited) => {
|
|
387
|
+
for (const node of list) {
|
|
388
|
+
const claimed = inherited || selected.has(node.id);
|
|
389
|
+
if (isBranch(node)) step2(node.children ?? [], cascade && claimed);
|
|
390
|
+
else if (claimed) out.add(node.id);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
step2(nodes, false);
|
|
394
|
+
return out;
|
|
395
|
+
}, [cascade, nodes, selected, selection]);
|
|
396
|
+
const explodeAncestor = React.useCallback(
|
|
397
|
+
(base, ancestor, id) => {
|
|
398
|
+
const next = new Set(base);
|
|
399
|
+
next.delete(ancestor);
|
|
400
|
+
const trail = ancestorIds(nodes, id);
|
|
401
|
+
const path = [...trail.slice(trail.indexOf(ancestor) + 1), id];
|
|
402
|
+
let current = ancestor;
|
|
403
|
+
for (const stepId of path) {
|
|
404
|
+
const siblings = nodeMap.get(current)?.children ?? [];
|
|
405
|
+
for (const child of siblings) {
|
|
406
|
+
if (child.id !== stepId) next.add(child.id);
|
|
407
|
+
}
|
|
408
|
+
current = stepId;
|
|
409
|
+
}
|
|
410
|
+
return next;
|
|
411
|
+
},
|
|
412
|
+
[nodeMap, nodes]
|
|
413
|
+
);
|
|
414
|
+
const rangeIds = React.useCallback(
|
|
415
|
+
(from, to) => {
|
|
416
|
+
const a = visible.findIndex((v) => v.node.id === from);
|
|
417
|
+
const b = visible.findIndex((v) => v.node.id === to);
|
|
418
|
+
if (a === -1 || b === -1) return [to];
|
|
419
|
+
return visible.slice(Math.min(a, b), Math.max(a, b) + 1).map((v) => v.node.id);
|
|
420
|
+
},
|
|
421
|
+
[visible]
|
|
422
|
+
);
|
|
423
|
+
const toggleSelected = React.useCallback(
|
|
424
|
+
(id, opts) => {
|
|
425
|
+
if (selection === "none") return;
|
|
426
|
+
if (isDisabled(id)) return;
|
|
427
|
+
const base = latestSelected.current;
|
|
428
|
+
if (selection === "single") {
|
|
429
|
+
if (base.size === 1 && base.has(id)) return;
|
|
430
|
+
anchor.current = id;
|
|
431
|
+
commitSelected(/* @__PURE__ */ new Set([id]));
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (opts?.range && anchor.current !== null) {
|
|
435
|
+
const next = new Set(base);
|
|
436
|
+
for (const rangeId of rangeIds(anchor.current, id)) {
|
|
437
|
+
if (!isDisabled(rangeId)) next.add(rangeId);
|
|
438
|
+
}
|
|
439
|
+
commitSelected(next);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const additive = cascade || opts?.additive === true;
|
|
443
|
+
if (!additive) {
|
|
444
|
+
anchor.current = id;
|
|
445
|
+
commitSelected(/* @__PURE__ */ new Set([id]));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
anchor.current = id;
|
|
449
|
+
if (base.has(id)) {
|
|
450
|
+
const next = new Set(base);
|
|
451
|
+
next.delete(id);
|
|
452
|
+
commitSelected(next);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (cascade) {
|
|
456
|
+
const inheritedFrom = ancestorIds(nodes, id).find((a) => base.has(a));
|
|
457
|
+
if (inheritedFrom !== void 0) {
|
|
458
|
+
commitSelected(explodeAncestor(base, inheritedFrom, id));
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const next = new Set(base);
|
|
462
|
+
const node = nodeMap.get(id);
|
|
463
|
+
if (node) walkTree(node.children ?? [], (descendant) => void next.delete(descendant.id));
|
|
464
|
+
next.add(id);
|
|
465
|
+
commitSelected(next);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
commitSelected(new Set(base).add(id));
|
|
469
|
+
},
|
|
470
|
+
[cascade, commitSelected, explodeAncestor, isDisabled, nodeMap, nodes, rangeIds, selection]
|
|
471
|
+
);
|
|
472
|
+
const clearSelected = React.useCallback(() => {
|
|
473
|
+
if (latestSelected.current.size === 0) return;
|
|
474
|
+
anchor.current = null;
|
|
475
|
+
commitSelected(emptySet());
|
|
476
|
+
}, [commitSelected]);
|
|
477
|
+
const [loading, setLoading] = React.useState(() => emptySet());
|
|
478
|
+
const [failed, setFailed] = React.useState(() => emptySet());
|
|
479
|
+
const attemptState = React.useRef(/* @__PURE__ */ new Map());
|
|
480
|
+
const attempt = React.useRef(/* @__PURE__ */ new Map());
|
|
481
|
+
const mounted = React.useRef(true);
|
|
482
|
+
React.useEffect(() => {
|
|
483
|
+
mounted.current = true;
|
|
484
|
+
return () => {
|
|
485
|
+
mounted.current = false;
|
|
486
|
+
};
|
|
487
|
+
}, []);
|
|
488
|
+
const loadRef = React.useRef(options.loadChildren);
|
|
489
|
+
const loadedRef = React.useRef(options.onChildrenLoaded);
|
|
490
|
+
const nodeMapRef = React.useRef(nodeMap);
|
|
491
|
+
loadRef.current = options.loadChildren;
|
|
492
|
+
loadedRef.current = options.onChildrenLoaded;
|
|
493
|
+
nodeMapRef.current = nodeMap;
|
|
494
|
+
const fetchChildren = React.useCallback((node) => {
|
|
495
|
+
const load = loadRef.current;
|
|
496
|
+
if (!load) return;
|
|
497
|
+
const id = node.id;
|
|
498
|
+
attemptState.current.set(id, "flight");
|
|
499
|
+
const mine = (attempt.current.get(id) ?? 0) + 1;
|
|
500
|
+
attempt.current.set(id, mine);
|
|
501
|
+
setLoading((prev) => new Set(prev).add(id));
|
|
502
|
+
setFailed((prev) => {
|
|
503
|
+
if (!prev.has(id)) return prev;
|
|
504
|
+
const next = new Set(prev);
|
|
505
|
+
next.delete(id);
|
|
506
|
+
return next;
|
|
507
|
+
});
|
|
508
|
+
const settle = (fn) => {
|
|
509
|
+
if (!mounted.current) return;
|
|
510
|
+
if (attempt.current.get(id) !== mine) return;
|
|
511
|
+
if (!nodeMapRef.current.has(id)) return;
|
|
512
|
+
fn();
|
|
513
|
+
};
|
|
514
|
+
const release = (next) => {
|
|
515
|
+
if (attempt.current.get(id) !== mine) return;
|
|
516
|
+
if (next === null) attemptState.current.delete(id);
|
|
517
|
+
else attemptState.current.set(id, next);
|
|
518
|
+
};
|
|
519
|
+
void load(node).then(
|
|
520
|
+
(children) => {
|
|
521
|
+
release(null);
|
|
522
|
+
settle(() => {
|
|
523
|
+
setLoading((prev) => {
|
|
524
|
+
const next = new Set(prev);
|
|
525
|
+
next.delete(id);
|
|
526
|
+
return next;
|
|
527
|
+
});
|
|
528
|
+
loadedRef.current?.(id, children);
|
|
529
|
+
});
|
|
530
|
+
},
|
|
531
|
+
() => {
|
|
532
|
+
release("failed");
|
|
533
|
+
settle(() => {
|
|
534
|
+
setLoading((prev) => {
|
|
535
|
+
const next = new Set(prev);
|
|
536
|
+
next.delete(id);
|
|
537
|
+
return next;
|
|
538
|
+
});
|
|
539
|
+
setFailed((prev) => new Set(prev).add(id));
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
);
|
|
543
|
+
}, []);
|
|
544
|
+
const shouldFetch = React.useCallback(
|
|
545
|
+
(id) => {
|
|
546
|
+
if (!loadRef.current) return false;
|
|
547
|
+
const node = nodeMap.get(id);
|
|
548
|
+
if (!node || !isUnloadedBranch(node)) return false;
|
|
549
|
+
return !attemptState.current.has(id);
|
|
550
|
+
},
|
|
551
|
+
[nodeMap]
|
|
552
|
+
);
|
|
553
|
+
const retryLoad = React.useCallback(
|
|
554
|
+
(id) => {
|
|
555
|
+
const node = nodeMapRef.current.get(id);
|
|
556
|
+
if (!node || !isUnloadedBranch(node)) return;
|
|
557
|
+
fetchChildren(node);
|
|
558
|
+
},
|
|
559
|
+
[fetchChildren]
|
|
560
|
+
);
|
|
561
|
+
maybeFetch.current = (id) => {
|
|
562
|
+
if (shouldFetch(id)) {
|
|
563
|
+
const node = nodeMap.get(id);
|
|
564
|
+
if (node) fetchChildren(node);
|
|
565
|
+
}
|
|
566
|
+
return attemptState.current.has(id);
|
|
567
|
+
};
|
|
568
|
+
const reorderEnabled = options.reorder != null && options.reorder !== false && !isFiltering;
|
|
569
|
+
const reorderOptions = options.reorder === false ? void 0 : options.reorder;
|
|
570
|
+
const moveContext = React.useMemo(
|
|
571
|
+
() => ({
|
|
572
|
+
isDescendant: (id, candidate) => isDescendant(nodes, id, candidate),
|
|
573
|
+
isDisabled: (id) => {
|
|
574
|
+
const node = nodeMap.get(id);
|
|
575
|
+
return node ? node.disabled === true || disabledNodes?.(node) === true : false;
|
|
576
|
+
},
|
|
577
|
+
isUnloaded: (id) => {
|
|
578
|
+
const node = nodeMap.get(id);
|
|
579
|
+
return node ? isUnloadedBranch(node) : false;
|
|
580
|
+
},
|
|
581
|
+
parentOf: (id) => parentMap.get(id) ?? null,
|
|
582
|
+
indexOf: (id) => visible.find((v) => v.node.id === id)?.index ?? -1,
|
|
583
|
+
siblingCountOf: (id) => visible.find((v) => v.node.id === id)?.siblingCount ?? 0,
|
|
584
|
+
isFiltering
|
|
585
|
+
}),
|
|
586
|
+
[disabledNodes, isFiltering, nodeMap, nodes, parentMap, visible]
|
|
587
|
+
);
|
|
588
|
+
const canMove = React.useCallback(
|
|
589
|
+
(move2) => {
|
|
590
|
+
if (!reorderEnabled || !reorderOptions) return false;
|
|
591
|
+
if (!structurallyAllowed(move2, moveContext)) return false;
|
|
592
|
+
return reorderOptions.canMove?.(move2) ?? true;
|
|
593
|
+
},
|
|
594
|
+
[moveContext, reorderEnabled, reorderOptions]
|
|
595
|
+
);
|
|
596
|
+
const move = React.useCallback(
|
|
597
|
+
(candidate) => {
|
|
598
|
+
if (!canMove(candidate)) return;
|
|
599
|
+
reorderOptions?.onMove(candidate);
|
|
600
|
+
},
|
|
601
|
+
[canMove, reorderOptions]
|
|
602
|
+
);
|
|
603
|
+
return {
|
|
604
|
+
nodes,
|
|
605
|
+
visible,
|
|
606
|
+
expanded,
|
|
607
|
+
toggleExpanded,
|
|
608
|
+
expand,
|
|
609
|
+
collapse,
|
|
610
|
+
expandAll,
|
|
611
|
+
collapseAll,
|
|
612
|
+
expandSiblings,
|
|
613
|
+
revealNode,
|
|
614
|
+
selection,
|
|
615
|
+
checkboxes,
|
|
616
|
+
selected,
|
|
617
|
+
checkedState,
|
|
618
|
+
checkedLeaves,
|
|
619
|
+
toggleSelected,
|
|
620
|
+
clearSelected,
|
|
621
|
+
loading,
|
|
622
|
+
failed,
|
|
623
|
+
retryLoad,
|
|
624
|
+
isFiltering,
|
|
625
|
+
matches,
|
|
626
|
+
query,
|
|
627
|
+
reorderEnabled,
|
|
628
|
+
reorderHandle: reorderOptions?.handle ?? "row",
|
|
629
|
+
canMove,
|
|
630
|
+
move,
|
|
631
|
+
isDisabled,
|
|
632
|
+
isBranch: isBranchById,
|
|
633
|
+
nodeById,
|
|
634
|
+
parentOf,
|
|
635
|
+
onActivate
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// src/components/tree/keyboard.ts
|
|
640
|
+
var TYPEAHEAD_RESET_MS = 500;
|
|
641
|
+
var labelText = (node) => typeof node.label === "string" ? node.label : null;
|
|
642
|
+
var landable = (ctx) => ctx.visible.filter((v) => !ctx.isDisabled(v.node.id));
|
|
643
|
+
var focus = (id, extend = false) => id === void 0 ? null : extend ? { kind: "focus", id, extend: true } : { kind: "focus", id };
|
|
644
|
+
function step(ctx, delta, extend = false) {
|
|
645
|
+
const rows = landable(ctx);
|
|
646
|
+
if (rows.length === 0) return null;
|
|
647
|
+
if (ctx.focusedId === null) return focus(rows[delta > 0 ? 0 : rows.length - 1]?.node.id, extend);
|
|
648
|
+
const at = rows.findIndex((v) => v.node.id === ctx.focusedId);
|
|
649
|
+
if (at === -1) return focus(nearestLandable(ctx, delta), extend);
|
|
650
|
+
return focus(rows[at + delta]?.node.id, extend);
|
|
651
|
+
}
|
|
652
|
+
function nearestLandable(ctx, delta) {
|
|
653
|
+
const at = ctx.visible.findIndex((v) => v.node.id === ctx.focusedId);
|
|
654
|
+
if (at === -1) return void 0;
|
|
655
|
+
for (let i = at + delta; i >= 0 && i < ctx.visible.length; i += delta) {
|
|
656
|
+
const candidate = ctx.visible[i];
|
|
657
|
+
if (!ctx.isDisabled(candidate.node.id)) return candidate.node.id;
|
|
658
|
+
}
|
|
659
|
+
return void 0;
|
|
660
|
+
}
|
|
661
|
+
var rowOf = (ctx, id) => id === null ? void 0 : ctx.visible.find((v) => v.node.id === id);
|
|
662
|
+
function siblingsOf(ctx, row) {
|
|
663
|
+
return ctx.visible.filter((v) => v.parentId === row.parentId && v.depth === row.depth);
|
|
664
|
+
}
|
|
665
|
+
function typeahead(ctx, char) {
|
|
666
|
+
const t = ctx.typeahead;
|
|
667
|
+
const stale = ctx.now - t.at > TYPEAHEAD_RESET_MS;
|
|
668
|
+
const buffer = stale ? char : t.buffer + char;
|
|
669
|
+
const cycling = buffer.length > 1 && [...buffer].every((c) => c === buffer[0]);
|
|
670
|
+
const needle = (cycling ? buffer[0] : buffer).toLowerCase();
|
|
671
|
+
t.buffer = buffer;
|
|
672
|
+
t.at = ctx.now;
|
|
673
|
+
const rows = landable(ctx);
|
|
674
|
+
if (rows.length === 0) return null;
|
|
675
|
+
const from = rows.findIndex((v) => v.node.id === ctx.focusedId);
|
|
676
|
+
const offset = cycling || buffer.length > 1 ? 1 : 0;
|
|
677
|
+
const start = from === -1 ? 0 : from + offset;
|
|
678
|
+
for (let i = 0; i < rows.length; i++) {
|
|
679
|
+
const row = rows[(start + i) % rows.length];
|
|
680
|
+
const text = labelText(row.node);
|
|
681
|
+
if (text && text.toLowerCase().startsWith(needle)) return { kind: "focus", id: row.node.id };
|
|
682
|
+
}
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
function reorderIntent(ctx, key, row) {
|
|
686
|
+
const id = row.node.id;
|
|
687
|
+
const siblings = siblingsOf(ctx, row);
|
|
688
|
+
const at = siblings.findIndex((v) => v.node.id === id);
|
|
689
|
+
const prev = at > 0 ? siblings[at - 1].node.id : void 0;
|
|
690
|
+
const next = at !== -1 && at < siblings.length - 1 ? siblings[at + 1].node.id : void 0;
|
|
691
|
+
switch (key) {
|
|
692
|
+
case "ArrowUp": {
|
|
693
|
+
return prev === void 0 ? null : { kind: "move", move: { id, target: prev, position: "before" } };
|
|
694
|
+
}
|
|
695
|
+
case "ArrowDown": {
|
|
696
|
+
return next === void 0 ? null : { kind: "move", move: { id, target: next, position: "after" } };
|
|
697
|
+
}
|
|
698
|
+
// Outdent: become the next sibling of the parent. This is also the "reparent" instruction a
|
|
699
|
+
// hitbox library would emit as a fourth case — it collapses to `after` the parent, which is why
|
|
700
|
+
// three positions are enough (`.claude/plans/tree/07-reorder.md`).
|
|
701
|
+
case "ArrowLeft": {
|
|
702
|
+
return row.parentId === null ? null : { kind: "move", move: { id, target: row.parentId, position: "after" } };
|
|
703
|
+
}
|
|
704
|
+
// Indent: become the last child of the previous sibling.
|
|
705
|
+
case "ArrowRight": {
|
|
706
|
+
return prev === void 0 ? null : { kind: "move", move: { id, target: prev, position: "child" } };
|
|
707
|
+
}
|
|
708
|
+
default: {
|
|
709
|
+
return null;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function treeKeydown(event, ctx) {
|
|
714
|
+
const { key } = event;
|
|
715
|
+
if (event.altKey) {
|
|
716
|
+
if (event.ctrlKey || event.metaKey) return null;
|
|
717
|
+
const focused = rowOf(ctx, ctx.focusedId);
|
|
718
|
+
if (!ctx.reorderEnabled || !focused) return null;
|
|
719
|
+
return reorderIntent(ctx, key, focused);
|
|
720
|
+
}
|
|
721
|
+
if (event.ctrlKey || event.metaKey) return null;
|
|
722
|
+
const row = rowOf(ctx, ctx.focusedId);
|
|
723
|
+
const id = row?.node.id;
|
|
724
|
+
switch (key) {
|
|
725
|
+
case "ArrowDown": {
|
|
726
|
+
return step(ctx, 1, event.shiftKey && ctx.selection === "multiple");
|
|
727
|
+
}
|
|
728
|
+
case "ArrowUp": {
|
|
729
|
+
return step(ctx, -1, event.shiftKey && ctx.selection === "multiple");
|
|
730
|
+
}
|
|
731
|
+
case "ArrowRight": {
|
|
732
|
+
if (!row || id === void 0) return null;
|
|
733
|
+
if (!ctx.isBranch(id)) return null;
|
|
734
|
+
if (!ctx.expanded.has(id)) return { kind: "expand", id };
|
|
735
|
+
const at = ctx.visible.indexOf(row);
|
|
736
|
+
const child = ctx.visible[at + 1];
|
|
737
|
+
if (!child || child.parentId !== id) return null;
|
|
738
|
+
return focus(child.node.id);
|
|
739
|
+
}
|
|
740
|
+
case "ArrowLeft": {
|
|
741
|
+
if (!row || id === void 0) return null;
|
|
742
|
+
if (ctx.isBranch(id) && ctx.expanded.has(id)) return { kind: "collapse", id };
|
|
743
|
+
return row.parentId === null ? null : focus(row.parentId);
|
|
744
|
+
}
|
|
745
|
+
case "Home": {
|
|
746
|
+
const rows = landable(ctx);
|
|
747
|
+
return focus(rows[0]?.node.id);
|
|
748
|
+
}
|
|
749
|
+
case "End": {
|
|
750
|
+
const rows = landable(ctx);
|
|
751
|
+
return focus(rows.at(-1)?.node.id);
|
|
752
|
+
}
|
|
753
|
+
case "Enter": {
|
|
754
|
+
return id === void 0 ? null : { kind: "activate", id };
|
|
755
|
+
}
|
|
756
|
+
case " ": {
|
|
757
|
+
if (ctx.typeahead.buffer.length > 0 && ctx.now - ctx.typeahead.at <= TYPEAHEAD_RESET_MS) return typeahead(ctx, " ");
|
|
758
|
+
if (id === void 0) return null;
|
|
759
|
+
if (ctx.selection === "none") return null;
|
|
760
|
+
if (ctx.selection === "single") return { kind: "activate", id };
|
|
761
|
+
return { kind: "toggleSelect", id, additive: true };
|
|
762
|
+
}
|
|
763
|
+
case "*": {
|
|
764
|
+
return id === void 0 ? null : { kind: "expandSiblings", id };
|
|
765
|
+
}
|
|
766
|
+
case "Escape": {
|
|
767
|
+
ctx.typeahead.buffer = "";
|
|
768
|
+
return ctx.selection === "multiple" && ctx.hasSelection ? { kind: "clearSelection" } : null;
|
|
769
|
+
}
|
|
770
|
+
default: {
|
|
771
|
+
if (key.length === 1 && key !== " ") return typeahead(ctx, key);
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
var TREE_INDENT = 20;
|
|
777
|
+
var HALF_GLYPH = { md: 8, lg: 10 };
|
|
778
|
+
var ROW_PX = { md: 6, lg: 8 };
|
|
779
|
+
var AXIS = { md: ROW_PX.md + HALF_GLYPH.md, lg: ROW_PX.lg + HALF_GLYPH.lg };
|
|
780
|
+
var ELBOW = { md: TREE_INDENT - HALF_GLYPH.md, lg: TREE_INDENT - HALF_GLYPH.lg };
|
|
781
|
+
var GAP_ROW = "mb-0.5";
|
|
782
|
+
var GAP_BLEED = "-bottom-0.5";
|
|
783
|
+
var GAP_LINE = { before: "-top-0.5", after: "-bottom-0.5" };
|
|
784
|
+
var ROW_H = { md: 32, lg: 36 };
|
|
785
|
+
var GLYPH_TO_EDGE = { md: ROW_H.md / 2 - HALF_GLYPH.md, lg: ROW_H.lg / 2 - HALF_GLYPH.lg };
|
|
786
|
+
var STUB_TOP = {
|
|
787
|
+
md: ROW_H.md - GLYPH_TO_EDGE.md,
|
|
788
|
+
lg: ROW_H.lg - GLYPH_TO_EDGE.lg
|
|
789
|
+
};
|
|
790
|
+
function contentLeft(size, depth) {
|
|
791
|
+
return ROW_PX[size] + depth * TREE_INDENT;
|
|
792
|
+
}
|
|
793
|
+
var ROW_GAP_X = { md: 6, lg: 8 };
|
|
794
|
+
function messageLeft(size, depth) {
|
|
795
|
+
return contentLeft(size, depth) + HALF_GLYPH[size] * 2 + ROW_GAP_X[size];
|
|
796
|
+
}
|
|
797
|
+
var HOVER_OPEN_MS = 600;
|
|
798
|
+
var ANNOUNCE_DEBOUNCE_MS = 300;
|
|
799
|
+
var GUIDE_RULE = `pointer-events-none absolute top-0 w-px bg-border-primary ${GAP_BLEED}`;
|
|
800
|
+
var GUIDE_ELBOW = "pointer-events-none absolute top-0 h-1/2 rounded-bl-md border-b border-l border-primary";
|
|
801
|
+
var GUIDE_STUB = `pointer-events-none absolute w-px bg-border-primary ${GAP_BLEED}`;
|
|
802
|
+
var GUIDE_DOT = "size-1 rounded-full bg-border-primary";
|
|
803
|
+
function GuideRules({ size, depth, lastChain }) {
|
|
804
|
+
if (depth === 0) return null;
|
|
805
|
+
const rules = [];
|
|
806
|
+
for (let k = 0; k < depth; k++) {
|
|
807
|
+
const left = AXIS[size] + k * TREE_INDENT;
|
|
808
|
+
const isLast = lastChain[k + 1] === true;
|
|
809
|
+
if (!isLast) rules.push(/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: GUIDE_RULE, style: { left } }, k));
|
|
810
|
+
else if (k === depth - 1) rules.push(/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: GUIDE_ELBOW, style: { left, width: ELBOW[size] } }, k));
|
|
811
|
+
}
|
|
812
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rules });
|
|
813
|
+
}
|
|
814
|
+
var ROW_BASE = "relative flex min-w-0 cursor-pointer items-center rounded-lg text-left select-none transition-colors duration-100 ease-linear";
|
|
815
|
+
var ROW_FOCUS_RING = "outline-none [&:focus-visible>[data-tree-row]]:outline-2 [&:focus-visible>[data-tree-row]]:-outline-offset-2 [&:focus-visible>[data-tree-row]]:outline-focus-ring";
|
|
816
|
+
var ROW_SIZE = {
|
|
817
|
+
md: "h-8 gap-1.5 px-1.5 text-sm",
|
|
818
|
+
lg: "h-9 gap-2 px-2 text-sm"
|
|
819
|
+
};
|
|
820
|
+
var ROW_IDLE = "text-primary hover:bg-ghost-hover";
|
|
821
|
+
var ROW_SELECTED = "bg-selected text-primary hover:bg-selected-hover";
|
|
822
|
+
var ROW_DISABLED = "cursor-not-allowed opacity-50";
|
|
823
|
+
var CHEVRON = "grid shrink-0 place-items-center text-border-primary transition-[transform,rotate,color] duration-200 ease-out group-hover/row:text-primary";
|
|
824
|
+
var GLYPH_SIZE = {
|
|
825
|
+
md: "size-4 [&>svg]:size-4",
|
|
826
|
+
lg: "size-5 [&>svg]:size-5"
|
|
827
|
+
};
|
|
828
|
+
var MARKER_BASE = "relative inline-flex shrink-0 items-center justify-center ring-1 ring-inset text-fg-white transition-colors duration-100 ease-linear";
|
|
829
|
+
var MARKER_SIZE = {
|
|
830
|
+
md: "size-4 rounded-sm",
|
|
831
|
+
lg: "size-4 rounded-sm"
|
|
832
|
+
};
|
|
833
|
+
var MARKER_STATE = {
|
|
834
|
+
checked: "bg-brand-solid ring-brand-solid",
|
|
835
|
+
mixed: "bg-brand-solid ring-brand-solid",
|
|
836
|
+
unchecked: "ring-primary"
|
|
837
|
+
};
|
|
838
|
+
function MarkerGlyphs({ state }) {
|
|
839
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
840
|
+
/* @__PURE__ */ jsx(CheckIcon, { className: cn(MARKER_GLYPH, state === "checked" && "opacity-100") }),
|
|
841
|
+
/* @__PURE__ */ jsx(MinusIcon, { className: cn(MARKER_GLYPH, state === "mixed" && "opacity-100") })
|
|
842
|
+
] });
|
|
843
|
+
}
|
|
844
|
+
var MARKER_GLYPH = "pointer-events-none absolute size-3.5 opacity-0 transition-opacity duration-100 ease-linear";
|
|
845
|
+
var SKELETON_ROW = { md: "h-3", lg: "h-3.5" };
|
|
846
|
+
var RETRY_BUTTON = "cursor-pointer rounded-md font-medium text-brand-secondary underline decoration-transparent underline-offset-2 outline-focus-ring transition-[color,text-decoration-color] duration-100 ease-linear hover:decoration-current focus-visible:outline-2 focus-visible:outline-offset-2";
|
|
847
|
+
var EMPTY_ROW = {
|
|
848
|
+
md: `relative px-1.5 py-1 text-sm text-fg-quaternary ${GAP_ROW}`,
|
|
849
|
+
lg: `relative px-2 py-1.5 text-sm text-fg-quaternary ${GAP_ROW}`
|
|
850
|
+
};
|
|
851
|
+
var DRAG_SOURCE = "opacity-50";
|
|
852
|
+
var DRAG_PREVIEW = "pointer-events-none fixed z-50 max-w-64 truncate rounded-lg bg-primary_alt px-2 py-1 text-sm text-primary shadow-md ring-1 ring-secondary ring-inset";
|
|
853
|
+
var DROP_LINE = "pointer-events-none absolute right-0 h-0.5 rounded-full bg-brand-solid";
|
|
854
|
+
var DROP_INTO = "ring-2 ring-focus-ring ring-inset";
|
|
855
|
+
var GRIP = "shrink-0 cursor-grab text-quaternary active:cursor-grabbing";
|
|
856
|
+
var ROW_GRAB = "cursor-grab active:cursor-grabbing";
|
|
857
|
+
function highlight(label, query) {
|
|
858
|
+
if (typeof label !== "string" || query === "") return label;
|
|
859
|
+
const needle = query.trim().toLowerCase();
|
|
860
|
+
if (needle === "") return label;
|
|
861
|
+
const parts = [];
|
|
862
|
+
const haystack = label.toLowerCase();
|
|
863
|
+
let cursor = 0;
|
|
864
|
+
for (let at = haystack.indexOf(needle, cursor); at !== -1; at = haystack.indexOf(needle, cursor)) {
|
|
865
|
+
if (at > cursor) parts.push(label.slice(cursor, at));
|
|
866
|
+
parts.push(
|
|
867
|
+
/* @__PURE__ */ jsx("mark", { className: "rounded-md bg-warning-primary px-0.5 text-primary", children: label.slice(at, at + needle.length) }, at)
|
|
868
|
+
);
|
|
869
|
+
cursor = at + needle.length;
|
|
870
|
+
}
|
|
871
|
+
if (parts.length === 0) return label;
|
|
872
|
+
if (cursor < label.length) parts.push(label.slice(cursor));
|
|
873
|
+
return parts;
|
|
874
|
+
}
|
|
875
|
+
function resolveSlot(slot, state) {
|
|
876
|
+
return typeof slot === "function" ? slot(state) : slot;
|
|
877
|
+
}
|
|
878
|
+
function TreeRow({
|
|
879
|
+
node,
|
|
880
|
+
depth,
|
|
881
|
+
ctx,
|
|
882
|
+
reserve,
|
|
883
|
+
rowId,
|
|
884
|
+
open,
|
|
885
|
+
lastChain
|
|
886
|
+
}) {
|
|
887
|
+
const { tree, size, guide } = ctx;
|
|
888
|
+
const branch = isBranch(node);
|
|
889
|
+
const disabled = tree.isDisabled(node.id);
|
|
890
|
+
const selected = tree.checkedState(node.id) === "checked";
|
|
891
|
+
const isLoading = tree.loading.has(node.id);
|
|
892
|
+
const hasFailed = tree.failed.has(node.id);
|
|
893
|
+
const groupVisible = branch && open && (node.children != null || isLoading || hasFailed);
|
|
894
|
+
const state = { expanded: open, selected, depth, isBranch: branch, loading: isLoading };
|
|
895
|
+
const checked = tree.checkedState(node.id);
|
|
896
|
+
const dropPosition = ctx.drag !== null && ctx.drag.targetId === node.id ? ctx.drag.position : null;
|
|
897
|
+
const leading = resolveSlot(node.leading, state);
|
|
898
|
+
const trailing = resolveSlot(node.trailing, state);
|
|
899
|
+
return /* @__PURE__ */ jsxs(
|
|
900
|
+
"div",
|
|
901
|
+
{
|
|
902
|
+
id: rowId,
|
|
903
|
+
"data-tree-row": "",
|
|
904
|
+
style: { paddingLeft: contentLeft(size, depth) },
|
|
905
|
+
className: cn(
|
|
906
|
+
"group/row",
|
|
907
|
+
ROW_BASE,
|
|
908
|
+
GAP_ROW,
|
|
909
|
+
ROW_SIZE[size],
|
|
910
|
+
selected ? ROW_SELECTED : ROW_IDLE,
|
|
911
|
+
/* The grab cursor IS the `handle: "row"` affordance, so it goes on before the states that can
|
|
912
|
+
* override it: a disabled row says `not-allowed` and a refused drop target does too, and both
|
|
913
|
+
* of those are later in this list on purpose. */
|
|
914
|
+
ctx.tree.reorderEnabled && ctx.tree.reorderHandle === "row" && !disabled && ROW_GRAB,
|
|
915
|
+
disabled && ROW_DISABLED,
|
|
916
|
+
ctx.drag?.id === node.id && DRAG_SOURCE,
|
|
917
|
+
dropPosition === "child" && DROP_INTO,
|
|
918
|
+
// A refused drop reads as a wall rather than an error: no indicator, and the cursor says so.
|
|
919
|
+
ctx.drag !== null && ctx.drag.targetId === node.id && ctx.drag.position === null && "cursor-not-allowed",
|
|
920
|
+
node.className
|
|
921
|
+
),
|
|
922
|
+
onClick: disabled ? void 0 : (event) => ctx.onRowClick(node.id, event),
|
|
923
|
+
onDoubleClick: disabled ? void 0 : () => ctx.onRowDoubleClick(node.id),
|
|
924
|
+
onMouseDown: disabled ? (event) => event.preventDefault() : ctx.tree.reorderHandle === "row" ? (event) => {
|
|
925
|
+
ctx.dragHandlers.onMouseDown(event);
|
|
926
|
+
} : void 0,
|
|
927
|
+
onTouchStart: disabled || ctx.tree.reorderHandle !== "row" ? void 0 : ctx.dragHandlers.onTouchStart,
|
|
928
|
+
children: [
|
|
929
|
+
guide === "line" ? /* @__PURE__ */ jsx(GuideRules, { size, depth, lastChain }) : null,
|
|
930
|
+
guide === "line" && groupVisible ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", "data-tree-stub": "", className: GUIDE_STUB, style: { left: AXIS[size] + depth * TREE_INDENT, top: STUB_TOP[size] } }) : null,
|
|
931
|
+
dropPosition === "before" ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(DROP_LINE, GAP_LINE.before), style: { left: contentLeft(size, depth) } }) : null,
|
|
932
|
+
dropPosition === "after" ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(DROP_LINE, GAP_LINE.after), style: { left: contentLeft(size, depth) } }) : null,
|
|
933
|
+
branch ? /* @__PURE__ */ jsx(
|
|
934
|
+
"span",
|
|
935
|
+
{
|
|
936
|
+
"aria-hidden": "true",
|
|
937
|
+
"data-tree-chevron": "",
|
|
938
|
+
className: cn(CHEVRON, GLYPH_SIZE[size], hasFailed && "text-error-primary"),
|
|
939
|
+
onClick: (event) => {
|
|
940
|
+
event.stopPropagation();
|
|
941
|
+
if (!disabled) tree.toggleExpanded(node.id);
|
|
942
|
+
},
|
|
943
|
+
children: isLoading ? /* @__PURE__ */ jsx(LoaderCircleIcon, { className: "size-4 animate-spin" }) : hasFailed ? /* @__PURE__ */ jsx(CircleAlertIcon, { className: "size-4", strokeWidth: 2.5 }) : /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-4 transition-[transform,rotate] duration-200 ease-out", open && "rotate-90"), strokeWidth: 2.5 })
|
|
944
|
+
}
|
|
945
|
+
) : (
|
|
946
|
+
/* A leaf still reserves the chevron column, or its label sits 20px left of its siblings' —
|
|
947
|
+
and under `guide="dot"` that reserved column is exactly where the mark belongs. Which is
|
|
948
|
+
also the whole reason a branch never shows one: the column already holds its chevron. */
|
|
949
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("grid shrink-0 place-items-center", GLYPH_SIZE[size]), children: guide === "dot" && depth > 0 ? /* @__PURE__ */ jsx("span", { className: GUIDE_DOT }) : null })
|
|
950
|
+
),
|
|
951
|
+
ctx.showMarkers ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn(MARKER_BASE, MARKER_SIZE[size], MARKER_STATE[checked]), children: /* @__PURE__ */ jsx(MarkerGlyphs, { state: checked }) }) : null,
|
|
952
|
+
leading == null ? reserve ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cn("shrink-0", GLYPH_SIZE[size]) }) : null : /* @__PURE__ */ jsx(Slot, { className: GLYPH_SIZE[size], children: leading }),
|
|
953
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: tree.matches.has(node.id) ? highlight(node.label, tree.query) : node.label }),
|
|
954
|
+
trailing == null ? null : /* @__PURE__ */ jsx(Slot, { className: "ml-1", children: trailing }),
|
|
955
|
+
ctx.tree.reorderEnabled && ctx.tree.reorderHandle === "grip" && !disabled ? /* @__PURE__ */ jsx(
|
|
956
|
+
"span",
|
|
957
|
+
{
|
|
958
|
+
"data-tree-grip": "",
|
|
959
|
+
"aria-hidden": "true",
|
|
960
|
+
className: cn(GRIP, "ml-auto", GLYPH_SIZE[size]),
|
|
961
|
+
onMouseDown: ctx.dragHandlers.onMouseDown,
|
|
962
|
+
onTouchStart: ctx.dragHandlers.onTouchStart,
|
|
963
|
+
children: /* @__PURE__ */ jsx(GripVerticalIcon, {})
|
|
964
|
+
}
|
|
965
|
+
) : null
|
|
966
|
+
]
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
function TreeItem({
|
|
971
|
+
node,
|
|
972
|
+
depth,
|
|
973
|
+
ctx,
|
|
974
|
+
reserve,
|
|
975
|
+
lastChain
|
|
976
|
+
}) {
|
|
977
|
+
const { tree, size, guide, emptyMessage } = ctx;
|
|
978
|
+
const rowId = React.useId();
|
|
979
|
+
const branch = isBranch(node);
|
|
980
|
+
const children = node.children;
|
|
981
|
+
const open = branch && (ctx.keptIds === null ? tree.expanded.has(node.id) : children?.some((child) => ctx.keptIds.has(child.id)) ?? false);
|
|
982
|
+
const isLoading = tree.loading.has(node.id);
|
|
983
|
+
const hasFailed = tree.failed.has(node.id);
|
|
984
|
+
const groupDepth = depth + 1;
|
|
985
|
+
const groupRowStyle = { paddingLeft: messageLeft(size, groupDepth) };
|
|
986
|
+
const groupRules = guide === "line" ? /* @__PURE__ */ jsx(GuideRules, { size, depth: groupDepth, lastChain: [...lastChain, true] }) : null;
|
|
987
|
+
return /* @__PURE__ */ jsxs(
|
|
988
|
+
"li",
|
|
989
|
+
{
|
|
990
|
+
role: "treeitem",
|
|
991
|
+
"aria-label": node.ariaLabel,
|
|
992
|
+
"aria-labelledby": node.ariaLabel == null ? rowId : void 0,
|
|
993
|
+
"aria-expanded": branch ? open : void 0,
|
|
994
|
+
"aria-selected": tree.selection !== "none" && !ctx.showMarkers ? tree.checkedState(node.id) === "checked" : void 0,
|
|
995
|
+
"aria-checked": ctx.showMarkers ? tree.checkedState(node.id) === "mixed" ? "mixed" : tree.checkedState(node.id) === "checked" : void 0,
|
|
996
|
+
"aria-disabled": tree.isDisabled(node.id) || void 0,
|
|
997
|
+
"aria-busy": open && isLoading || void 0,
|
|
998
|
+
tabIndex: ctx.focusedId === node.id ? 0 : -1,
|
|
999
|
+
"data-tree-id": node.id,
|
|
1000
|
+
onFocus: (event) => {
|
|
1001
|
+
if (event.target === event.currentTarget) ctx.onRowFocus(node.id);
|
|
1002
|
+
},
|
|
1003
|
+
className: ROW_FOCUS_RING,
|
|
1004
|
+
children: [
|
|
1005
|
+
/* @__PURE__ */ jsx(TreeRow, { node, depth, ctx, reserve, rowId, open, lastChain }),
|
|
1006
|
+
branch && children == null && open && (isLoading || hasFailed) ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("ul", { role: "group", children: isLoading ? (
|
|
1007
|
+
/* TWO bars, not one: a single bar reads as a real row that failed to render. Always
|
|
1008
|
+
`aria-hidden` — `aria-busy` on the treeitem is what announces the state. */
|
|
1009
|
+
/* @__PURE__ */ jsxs("li", { role: "none", className: cn("flex flex-col gap-1.5", EMPTY_ROW[size]), style: groupRowStyle, children: [
|
|
1010
|
+
groupRules,
|
|
1011
|
+
/* @__PURE__ */ jsx(SkeletonBar, { className: cn(SKELETON_ROW[size], "w-3/5") }),
|
|
1012
|
+
/* @__PURE__ */ jsx(SkeletonBar, { className: cn(SKELETON_ROW[size], "w-4/5") })
|
|
1013
|
+
] })
|
|
1014
|
+
) : (
|
|
1015
|
+
/* The ONE genuinely focusable control inside a tree, and it needs the care: a `<button>`
|
|
1016
|
+
in `<li role="none">` — a SIBLING of the treeitems, never inside one, so it never
|
|
1017
|
+
joins a row's accessible name. It is a real second tab stop, which APG allows for
|
|
1018
|
+
interactive content in a tree, and it is NOT in `tree.visible`, so ↑↓ skip it. */
|
|
1019
|
+
/* @__PURE__ */ jsxs("li", { role: "none", className: cn("flex items-center gap-2", EMPTY_ROW[size]), style: groupRowStyle, children: [
|
|
1020
|
+
groupRules,
|
|
1021
|
+
/* @__PURE__ */ jsx("span", { className: "text-error-primary", children: "Couldn\u2019t load" }),
|
|
1022
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => tree.retryLoad(node.id), className: RETRY_BUTTON, children: "Retry" })
|
|
1023
|
+
] })
|
|
1024
|
+
) }) }) : null,
|
|
1025
|
+
branch && children != null ? /* @__PURE__ */ jsx(
|
|
1026
|
+
"div",
|
|
1027
|
+
{
|
|
1028
|
+
className: cn(
|
|
1029
|
+
"grid transition-[grid-template-rows,visibility] duration-200 ease-out",
|
|
1030
|
+
open ? "visible grid-rows-[1fr]" : "invisible grid-rows-[0fr]"
|
|
1031
|
+
),
|
|
1032
|
+
children: /* @__PURE__ */ jsx("div", { className: "overflow-hidden", children: /* @__PURE__ */ jsx("ul", { role: "group", children: children.length > 0 ? /* @__PURE__ */ jsx(TreeRows, { nodes: children, depth: depth + 1, ctx, parentChain: lastChain }) : (
|
|
1033
|
+
/* The third empty state, and the one that gets forgotten: an EXPANDED EMPTY BRANCH.
|
|
1034
|
+
`children: []` is a branch (`nodes.ts`), so it keeps its chevron and opens to this
|
|
1035
|
+
instead of silently reading as a leaf. `role="group"` has no required owned
|
|
1036
|
+
elements, so a bare `<li role="none">` is legal here. */
|
|
1037
|
+
/* @__PURE__ */ jsxs("li", { role: "none", className: EMPTY_ROW[size], style: groupRowStyle, children: [
|
|
1038
|
+
groupRules,
|
|
1039
|
+
emptyMessage
|
|
1040
|
+
] })
|
|
1041
|
+
) }) })
|
|
1042
|
+
}
|
|
1043
|
+
) : null
|
|
1044
|
+
]
|
|
1045
|
+
}
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
function TreeRows({
|
|
1049
|
+
nodes,
|
|
1050
|
+
depth,
|
|
1051
|
+
ctx,
|
|
1052
|
+
parentChain
|
|
1053
|
+
}) {
|
|
1054
|
+
const rows = ctx.keptIds === null ? nodes : nodes.filter((node) => ctx.keptIds.has(node.id));
|
|
1055
|
+
const reserve = rows.some((node) => node.leading != null);
|
|
1056
|
+
return /* @__PURE__ */ jsx(Fragment, { children: rows.map((node, index) => (
|
|
1057
|
+
/* "Last" is decided over the RENDERED rows, so a filter that drops the real last child
|
|
1058
|
+
* promotes the new one and the elbow follows it instead of hanging off a row that is gone. */
|
|
1059
|
+
/* @__PURE__ */ jsx(TreeItem, { node, depth, ctx, reserve, lastChain: [...parentChain, index === rows.length - 1] }, node.id)
|
|
1060
|
+
)) });
|
|
1061
|
+
}
|
|
1062
|
+
function Tree(props) {
|
|
1063
|
+
const { tree, size = "md", guide = "line", emptyMessage = "Nothing here", render, className, ...rest } = props;
|
|
1064
|
+
warnNeedsName("Tree", rest["aria-label"] != null || rest["aria-labelledby"] != null, "`aria-label` or `aria-labelledby`");
|
|
1065
|
+
const rootRef = React.useRef(null);
|
|
1066
|
+
const [focusedId, setFocusedId] = React.useState(null);
|
|
1067
|
+
const typeahead2 = React.useRef({ buffer: "", at: 0 });
|
|
1068
|
+
const anchorRef = React.useRef(null);
|
|
1069
|
+
const pendingFocus = React.useRef(null);
|
|
1070
|
+
const resolvedFocus = React.useMemo(() => {
|
|
1071
|
+
const landable2 = tree.visible.filter((v) => !tree.isDisabled(v.node.id));
|
|
1072
|
+
if (landable2.length === 0) return null;
|
|
1073
|
+
if (focusedId !== null && tree.visible.some((v) => v.node.id === focusedId)) return focusedId;
|
|
1074
|
+
if (focusedId !== null) {
|
|
1075
|
+
for (const ancestor of ancestorIds(tree.nodes, focusedId)) {
|
|
1076
|
+
if (tree.visible.some((v) => v.node.id === ancestor) && !tree.isDisabled(ancestor)) return ancestor;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
const selected = landable2.find((v) => tree.selected.has(v.node.id));
|
|
1080
|
+
return selected?.node.id ?? landable2[0].node.id;
|
|
1081
|
+
}, [focusedId, tree]);
|
|
1082
|
+
const moveFocus = React.useCallback((id) => {
|
|
1083
|
+
pendingFocus.current = id;
|
|
1084
|
+
setFocusedId(id);
|
|
1085
|
+
}, []);
|
|
1086
|
+
const hadFocus = React.useRef(false);
|
|
1087
|
+
const prevFocus = React.useRef(null);
|
|
1088
|
+
useIsomorphicLayoutEffect(() => {
|
|
1089
|
+
const root = rootRef.current;
|
|
1090
|
+
const explicit = pendingFocus.current !== null && pendingFocus.current === resolvedFocus;
|
|
1091
|
+
pendingFocus.current = null;
|
|
1092
|
+
const previous = prevFocus.current;
|
|
1093
|
+
prevFocus.current = resolvedFocus;
|
|
1094
|
+
if (!root || resolvedFocus === null) return;
|
|
1095
|
+
const rowFor = (id) => [...root.querySelectorAll('[role="treeitem"]')].find((el) => el.dataset.treeId === id);
|
|
1096
|
+
const active = document.activeElement;
|
|
1097
|
+
const treeHasFocus = active instanceof HTMLElement && root.contains(active);
|
|
1098
|
+
const vanished = hadFocus.current && !treeHasFocus && previous !== null && previous !== resolvedFocus && rowFor(previous) === void 0;
|
|
1099
|
+
if (!explicit && !vanished) return;
|
|
1100
|
+
const row = rowFor(resolvedFocus);
|
|
1101
|
+
row?.focus();
|
|
1102
|
+
row?.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
1103
|
+
}, [resolvedFocus]);
|
|
1104
|
+
const onRowFocus = React.useCallback((id) => {
|
|
1105
|
+
hadFocus.current = true;
|
|
1106
|
+
setFocusedId(id);
|
|
1107
|
+
}, []);
|
|
1108
|
+
const [announcement, setAnnouncement] = React.useState("");
|
|
1109
|
+
const announceTimer = React.useRef(null);
|
|
1110
|
+
React.useEffect(() => () => clearTimeout(announceTimer.current ?? void 0), []);
|
|
1111
|
+
const announce = React.useCallback(
|
|
1112
|
+
(committed) => {
|
|
1113
|
+
const moved = tree.nodeById(committed.id);
|
|
1114
|
+
const target = tree.nodeById(committed.target);
|
|
1115
|
+
const name = typeof moved?.label === "string" ? moved.label : "Item";
|
|
1116
|
+
const into = typeof target?.label === "string" ? target.label : "";
|
|
1117
|
+
const verb = committed.position === "child" ? "into" : committed.position;
|
|
1118
|
+
clearTimeout(announceTimer.current ?? void 0);
|
|
1119
|
+
announceTimer.current = setTimeout(() => setAnnouncement(into ? `${name} moved ${verb} ${into}` : `${name} moved`), ANNOUNCE_DEBOUNCE_MS);
|
|
1120
|
+
},
|
|
1121
|
+
[tree]
|
|
1122
|
+
);
|
|
1123
|
+
const onRowClick = React.useCallback(
|
|
1124
|
+
(id, event) => {
|
|
1125
|
+
const node = tree.nodeById(id);
|
|
1126
|
+
if (!node) return;
|
|
1127
|
+
if (tree.selection === "none") {
|
|
1128
|
+
tree.onActivate?.(node);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
if (tree.selection === "single" && tree.checkedState(id) === "checked") {
|
|
1132
|
+
tree.onActivate?.(node);
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
tree.toggleSelected(id, { range: event.shiftKey, additive: event.ctrlKey || event.metaKey });
|
|
1136
|
+
},
|
|
1137
|
+
[tree]
|
|
1138
|
+
);
|
|
1139
|
+
const onRowDoubleClick = React.useCallback(
|
|
1140
|
+
(id) => {
|
|
1141
|
+
const node = tree.nodeById(id);
|
|
1142
|
+
if (node) tree.onActivate?.(node);
|
|
1143
|
+
},
|
|
1144
|
+
[tree]
|
|
1145
|
+
);
|
|
1146
|
+
const showMarkers = tree.selection === "multiple" && tree.checkboxes;
|
|
1147
|
+
const rowUnder = React.useCallback((pt) => {
|
|
1148
|
+
const root = rootRef.current;
|
|
1149
|
+
if (!root) return null;
|
|
1150
|
+
for (const item of root.querySelectorAll('[role="treeitem"]')) {
|
|
1151
|
+
const box = item.firstElementChild;
|
|
1152
|
+
if (!box) continue;
|
|
1153
|
+
const rect = box.getBoundingClientRect();
|
|
1154
|
+
if (pt.y < rect.top || pt.y > rect.bottom) continue;
|
|
1155
|
+
const id = item.dataset.treeId;
|
|
1156
|
+
if (id === void 0) return null;
|
|
1157
|
+
return { id, rect: { top: rect.top, bottom: rect.bottom, left: rect.left, height: rect.height } };
|
|
1158
|
+
}
|
|
1159
|
+
return null;
|
|
1160
|
+
}, []);
|
|
1161
|
+
const ancestorAt = React.useCallback(
|
|
1162
|
+
(id, up) => {
|
|
1163
|
+
const trail = ancestorIds(tree.nodes, id);
|
|
1164
|
+
return trail[trail.length - up] ?? null;
|
|
1165
|
+
},
|
|
1166
|
+
[tree.nodes]
|
|
1167
|
+
);
|
|
1168
|
+
const resolveDrop = React.useCallback(
|
|
1169
|
+
(draggedId, pt) => {
|
|
1170
|
+
const hit = rowUnder(pt);
|
|
1171
|
+
if (!hit) return { targetId: null, position: null, move: null };
|
|
1172
|
+
const row = tree.visible.find((v) => v.node.id === hit.id);
|
|
1173
|
+
const ctxHit = { indent: TREE_INDENT, depth: row?.depth ?? 0, canHaveChildren: tree.isBranch(hit.id) && !tree.failed.has(hit.id) };
|
|
1174
|
+
const position = rowHitbox(pt, hit.rect, ctxHit);
|
|
1175
|
+
if (position === null) return { targetId: hit.id, position: null, move: null };
|
|
1176
|
+
const candidate = toMove(draggedId, hit.id, position, outdentSteps(pt, hit.rect, ctxHit), ancestorAt);
|
|
1177
|
+
if (candidate === null || !tree.canMove(candidate)) return { targetId: hit.id, position: null, move: null };
|
|
1178
|
+
return { targetId: hit.id, position, move: candidate };
|
|
1179
|
+
},
|
|
1180
|
+
[ancestorAt, rowUnder, tree]
|
|
1181
|
+
);
|
|
1182
|
+
const hoverOpen = React.useRef(null);
|
|
1183
|
+
const cancelHoverOpen = React.useCallback(() => {
|
|
1184
|
+
if (hoverOpen.current) clearTimeout(hoverOpen.current.timer);
|
|
1185
|
+
hoverOpen.current = null;
|
|
1186
|
+
}, []);
|
|
1187
|
+
const autoScroll = useAutoScroll(rootRef);
|
|
1188
|
+
const { handlers: dragHandlers, draft: drag } = useDrag({
|
|
1189
|
+
onStart: (pt) => {
|
|
1190
|
+
if (!tree.reorderEnabled) return null;
|
|
1191
|
+
const hit = rowUnder(pt);
|
|
1192
|
+
if (!hit || tree.isDisabled(hit.id)) return null;
|
|
1193
|
+
const node = tree.nodeById(hit.id);
|
|
1194
|
+
if (!node) return null;
|
|
1195
|
+
autoScroll.arm();
|
|
1196
|
+
return { id: hit.id, targetId: null, position: null, point: pt, label: node.label };
|
|
1197
|
+
},
|
|
1198
|
+
onMove: (draft, pt) => {
|
|
1199
|
+
const { targetId, position } = resolveDrop(draft.id, pt);
|
|
1200
|
+
if (targetId !== null && position === "child" && tree.isBranch(targetId) && !tree.expanded.has(targetId)) {
|
|
1201
|
+
if (hoverOpen.current?.id !== targetId) {
|
|
1202
|
+
cancelHoverOpen();
|
|
1203
|
+
hoverOpen.current = { id: targetId, timer: setTimeout(() => tree.expand(targetId), HOVER_OPEN_MS) };
|
|
1204
|
+
}
|
|
1205
|
+
} else {
|
|
1206
|
+
cancelHoverOpen();
|
|
1207
|
+
}
|
|
1208
|
+
return { ...draft, targetId, position, point: pt };
|
|
1209
|
+
},
|
|
1210
|
+
onEnd: (draft) => {
|
|
1211
|
+
cancelHoverOpen();
|
|
1212
|
+
autoScroll.disarm();
|
|
1213
|
+
const { move: committed } = resolveDrop(draft.id, draft.point);
|
|
1214
|
+
if (committed) {
|
|
1215
|
+
tree.move(committed);
|
|
1216
|
+
announce(committed);
|
|
1217
|
+
moveFocus(committed.id);
|
|
1218
|
+
}
|
|
1219
|
+
},
|
|
1220
|
+
onCancel: () => {
|
|
1221
|
+
cancelHoverOpen();
|
|
1222
|
+
autoScroll.disarm();
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
const keptIds = React.useMemo(
|
|
1226
|
+
() => tree.isFiltering ? new Set(tree.visible.map((v) => v.node.id)) : null,
|
|
1227
|
+
[tree.isFiltering, tree.visible]
|
|
1228
|
+
);
|
|
1229
|
+
const handleBlur = React.useCallback((event) => {
|
|
1230
|
+
const next = event.relatedTarget;
|
|
1231
|
+
const leaving = next !== null && !event.currentTarget.contains(next);
|
|
1232
|
+
if (leaving || next === null && event.target instanceof HTMLElement && event.target.isConnected) {
|
|
1233
|
+
hadFocus.current = false;
|
|
1234
|
+
}
|
|
1235
|
+
}, []);
|
|
1236
|
+
const handleKeyDown = React.useCallback(
|
|
1237
|
+
(event) => {
|
|
1238
|
+
const target = event.target;
|
|
1239
|
+
if (target && target !== event.currentTarget && target.closest("input, textarea, select, [contenteditable='true']")) return;
|
|
1240
|
+
const intent = treeKeydown(event.nativeEvent, {
|
|
1241
|
+
visible: tree.visible,
|
|
1242
|
+
expanded: tree.expanded,
|
|
1243
|
+
focusedId: resolvedFocus,
|
|
1244
|
+
selection: tree.selection,
|
|
1245
|
+
reorderEnabled: tree.reorderEnabled,
|
|
1246
|
+
isDisabled: tree.isDisabled,
|
|
1247
|
+
isBranch: tree.isBranch,
|
|
1248
|
+
hasSelection: tree.selected.size > 0,
|
|
1249
|
+
typeahead: typeahead2.current,
|
|
1250
|
+
now: Date.now()
|
|
1251
|
+
});
|
|
1252
|
+
if (intent === null) return;
|
|
1253
|
+
event.preventDefault();
|
|
1254
|
+
switch (intent.kind) {
|
|
1255
|
+
case "focus": {
|
|
1256
|
+
moveFocus(intent.id);
|
|
1257
|
+
if (intent.extend) tree.toggleSelected(intent.id, { range: true });
|
|
1258
|
+
else anchorRef.current = intent.id;
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
case "expand": {
|
|
1262
|
+
tree.expand(intent.id);
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
case "collapse": {
|
|
1266
|
+
tree.collapse(intent.id);
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
case "expandSiblings": {
|
|
1270
|
+
tree.expandSiblings(intent.id);
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
case "activate": {
|
|
1274
|
+
const node = tree.nodeById(intent.id);
|
|
1275
|
+
if (!node) return;
|
|
1276
|
+
if (tree.selection === "single") tree.toggleSelected(intent.id);
|
|
1277
|
+
tree.onActivate?.(node);
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
case "toggleSelect": {
|
|
1281
|
+
tree.toggleSelected(intent.id, { range: intent.range, additive: intent.additive });
|
|
1282
|
+
anchorRef.current = intent.id;
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
case "clearSelection": {
|
|
1286
|
+
tree.clearSelected();
|
|
1287
|
+
anchorRef.current = null;
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
case "move": {
|
|
1291
|
+
if (!tree.canMove(intent.move)) return;
|
|
1292
|
+
tree.move(intent.move);
|
|
1293
|
+
announce(intent.move);
|
|
1294
|
+
moveFocus(intent.move.id);
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1299
|
+
[announce, moveFocus, resolvedFocus, tree]
|
|
1300
|
+
);
|
|
1301
|
+
const ctx = React.useMemo(
|
|
1302
|
+
() => ({ tree, size, guide, emptyMessage, focusedId: resolvedFocus, onRowFocus, showMarkers, keptIds, onRowClick, onRowDoubleClick, drag, dragHandlers }),
|
|
1303
|
+
[tree, size, guide, emptyMessage, resolvedFocus, onRowFocus, showMarkers, keptIds, onRowClick, onRowDoubleClick, drag, dragHandlers]
|
|
1304
|
+
);
|
|
1305
|
+
const empty = tree.visible.length === 0;
|
|
1306
|
+
const element = useRender({
|
|
1307
|
+
defaultTagName: "ul",
|
|
1308
|
+
render,
|
|
1309
|
+
props: mergeProps(
|
|
1310
|
+
{
|
|
1311
|
+
// Dropped when there is nothing to render, deliberately. `role="tree"` REQUIRES owned
|
|
1312
|
+
// `treeitem`/`group` children, so an empty one is an aria-required-children violation — and
|
|
1313
|
+
// an empty tree is not a tree. Without the role it is an honest one-item list saying so.
|
|
1314
|
+
role: empty ? void 0 : "tree",
|
|
1315
|
+
// Announced on the ROOT, so AT describes the widget before the user reaches a row.
|
|
1316
|
+
"aria-multiselectable": tree.selection === "multiple" ? true : void 0,
|
|
1317
|
+
ref: rootRef,
|
|
1318
|
+
onKeyDown: handleKeyDown,
|
|
1319
|
+
onBlur: handleBlur,
|
|
1320
|
+
className: cn("", className),
|
|
1321
|
+
children: empty ? /* @__PURE__ */ jsx("li", { role: "none", className: EMPTY_ROW[size], children: tree.isFiltering ? `No matches for \u201C${tree.query}\u201D` : emptyMessage }) : /* @__PURE__ */ jsx(TreeRows, { nodes: tree.nodes, depth: 0, ctx, parentChain: [] })
|
|
1322
|
+
},
|
|
1323
|
+
rest
|
|
1324
|
+
)
|
|
1325
|
+
});
|
|
1326
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1327
|
+
element,
|
|
1328
|
+
/* @__PURE__ */ jsx("div", { role: "status", className: "sr-only", children: announcement }),
|
|
1329
|
+
drag !== null ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: DRAG_PREVIEW, style: { top: drag.point.y + 8, left: drag.point.x + 8 }, children: drag.label }) : null
|
|
1330
|
+
] });
|
|
1331
|
+
}
|
|
1332
|
+
Tree.displayName = "Tree";
|
|
1333
|
+
|
|
1334
|
+
export { Tree, ancestorIds, applyTreeMove, attachChildren, isBranch, isDescendant, useTree, walkTree };
|
|
1335
|
+
//# sourceMappingURL=chunk-7EWQKTNQ.js.map
|
|
1336
|
+
//# sourceMappingURL=chunk-7EWQKTNQ.js.map
|