@dxos/react-ui-list 0.9.0 → 0.9.1-main.c7dcc2e112
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/lib/browser/index.mjs +993 -521
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +993 -521
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/aspects/index.d.ts +6 -0
- package/dist/types/src/aspects/index.d.ts.map +1 -0
- package/dist/types/src/aspects/useListDisclosure.d.ts +60 -0
- package/dist/types/src/aspects/useListDisclosure.d.ts.map +1 -0
- package/dist/types/src/aspects/useListDisclosure.test.d.ts +2 -0
- package/dist/types/src/aspects/useListDisclosure.test.d.ts.map +1 -0
- package/dist/types/src/aspects/useListGrid.d.ts +30 -0
- package/dist/types/src/aspects/useListGrid.d.ts.map +1 -0
- package/dist/types/src/aspects/useListGrid.test.d.ts +2 -0
- package/dist/types/src/aspects/useListGrid.test.d.ts.map +1 -0
- package/dist/types/src/aspects/useListNavigation.d.ts +68 -0
- package/dist/types/src/aspects/useListNavigation.d.ts.map +1 -0
- package/dist/types/src/aspects/useListNavigation.test.d.ts +2 -0
- package/dist/types/src/aspects/useListNavigation.test.d.ts.map +1 -0
- package/dist/types/src/aspects/useListSelection.d.ts +48 -0
- package/dist/types/src/aspects/useListSelection.d.ts.map +1 -0
- package/dist/types/src/aspects/useListSelection.test.d.ts +2 -0
- package/dist/types/src/aspects/useListSelection.test.d.ts.map +1 -0
- package/dist/types/src/aspects/useReorder.d.ts +103 -0
- package/dist/types/src/aspects/useReorder.d.ts.map +1 -0
- package/dist/types/src/components/Accordion/Accordion.d.ts +1 -1
- package/dist/types/src/components/Accordion/AccordionItem.d.ts +5 -3
- package/dist/types/src/components/Accordion/AccordionItem.d.ts.map +1 -1
- package/dist/types/src/components/Accordion/AccordionRoot.d.ts +1 -1
- package/dist/types/src/components/Accordion/AccordionRoot.d.ts.map +1 -1
- package/dist/types/src/components/Listbox/Listbox.d.ts +60 -20
- package/dist/types/src/components/Listbox/Listbox.d.ts.map +1 -1
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts +27 -3
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts.map +1 -1
- package/dist/types/src/components/OrderedList/OrderedList.d.ts +49 -0
- package/dist/types/src/components/OrderedList/OrderedList.d.ts.map +1 -0
- package/dist/types/src/components/OrderedList/OrderedList.stories.d.ts +11 -0
- package/dist/types/src/components/OrderedList/OrderedList.stories.d.ts.map +1 -0
- package/dist/types/src/components/OrderedList/OrderedList.test.d.ts +2 -0
- package/dist/types/src/components/OrderedList/OrderedList.test.d.ts.map +1 -0
- package/dist/types/src/components/OrderedList/OrderedListItem.d.ts +94 -0
- package/dist/types/src/components/OrderedList/OrderedListItem.d.ts.map +1 -0
- package/dist/types/src/components/OrderedList/OrderedListRoot.d.ts +73 -0
- package/dist/types/src/components/OrderedList/OrderedListRoot.d.ts.map +1 -0
- package/dist/types/src/components/OrderedList/index.d.ts +2 -0
- package/dist/types/src/components/OrderedList/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/vitest-setup.d.ts +2 -0
- package/dist/types/src/vitest-setup.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -15
- package/src/aspects/index.ts +9 -0
- package/src/aspects/useListDisclosure.test.ts +72 -0
- package/src/aspects/useListDisclosure.ts +160 -0
- package/src/aspects/useListGrid.test.ts +41 -0
- package/src/aspects/useListGrid.ts +61 -0
- package/src/aspects/useListNavigation.test.ts +44 -0
- package/src/aspects/useListNavigation.ts +160 -0
- package/src/aspects/useListSelection.test.ts +101 -0
- package/src/aspects/useListSelection.ts +162 -0
- package/src/aspects/useReorder.ts +370 -0
- package/src/components/Accordion/Accordion.stories.tsx +1 -1
- package/src/components/Accordion/AccordionItem.tsx +11 -6
- package/src/components/Accordion/AccordionRoot.tsx +4 -1
- package/src/components/Listbox/Listbox.stories.tsx +171 -21
- package/src/components/Listbox/Listbox.tsx +302 -145
- package/src/components/OrderedList/OrderedList.stories.tsx +379 -0
- package/src/components/OrderedList/OrderedList.test.tsx +59 -0
- package/src/components/OrderedList/OrderedList.tsx +63 -0
- package/src/components/OrderedList/OrderedListItem.tsx +348 -0
- package/src/components/OrderedList/OrderedListRoot.tsx +173 -0
- package/src/components/OrderedList/index.ts +5 -0
- package/src/components/Tree/TreeItem.tsx +2 -0
- package/src/components/Tree/TreeItemHeading.tsx +1 -2
- package/src/components/index.ts +1 -2
- package/src/index.ts +1 -0
- package/src/vitest-setup.ts +11 -0
- package/dist/types/src/components/List/List.d.ts +0 -40
- package/dist/types/src/components/List/List.d.ts.map +0 -1
- package/dist/types/src/components/List/List.stories.d.ts +0 -18
- package/dist/types/src/components/List/List.stories.d.ts.map +0 -1
- package/dist/types/src/components/List/ListItem.d.ts +0 -49
- package/dist/types/src/components/List/ListItem.d.ts.map +0 -1
- package/dist/types/src/components/List/ListRoot.d.ts +0 -29
- package/dist/types/src/components/List/ListRoot.d.ts.map +0 -1
- package/dist/types/src/components/List/index.d.ts +0 -2
- package/dist/types/src/components/List/index.d.ts.map +0 -1
- package/dist/types/src/components/List/testing.d.ts +0 -15
- package/dist/types/src/components/List/testing.d.ts.map +0 -1
- package/dist/types/src/components/RowList/RowList.d.ts +0 -61
- package/dist/types/src/components/RowList/RowList.d.ts.map +0 -1
- package/dist/types/src/components/RowList/RowList.stories.d.ts +0 -35
- package/dist/types/src/components/RowList/RowList.stories.d.ts.map +0 -1
- package/dist/types/src/components/RowList/index.d.ts +0 -3
- package/dist/types/src/components/RowList/index.d.ts.map +0 -1
- package/src/components/List/List.stories.tsx +0 -129
- package/src/components/List/List.tsx +0 -47
- package/src/components/List/ListItem.tsx +0 -287
- package/src/components/List/ListRoot.tsx +0 -106
- package/src/components/List/index.ts +0 -5
- package/src/components/List/testing.ts +0 -31
- package/src/components/RowList/RowList.stories.tsx +0 -163
- package/src/components/RowList/RowList.tsx +0 -350
- package/src/components/RowList/index.ts +0 -6
|
@@ -1,5 +1,582 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
|
+
// src/aspects/useListDisclosure.ts
|
|
4
|
+
import { useCallback, useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
var isMulti = (value) => value instanceof Set;
|
|
6
|
+
var useListDisclosure = (opts) => {
|
|
7
|
+
const { mode, value, defaultValue, onValueChange } = opts;
|
|
8
|
+
const idPrefix = useId();
|
|
9
|
+
const wasControlledRef = useRef(Object.prototype.hasOwnProperty.call(opts, "value"));
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(opts, "value")) {
|
|
11
|
+
wasControlledRef.current = true;
|
|
12
|
+
}
|
|
13
|
+
const isControlled = wasControlledRef.current;
|
|
14
|
+
const [internalValue, setInternalValue] = useState(() => defaultValue);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (isControlled) {
|
|
17
|
+
setInternalValue(value);
|
|
18
|
+
}
|
|
19
|
+
}, [
|
|
20
|
+
isControlled,
|
|
21
|
+
value
|
|
22
|
+
]);
|
|
23
|
+
const resolvedValue = isControlled ? value : internalValue;
|
|
24
|
+
const isExpanded = useCallback((id) => {
|
|
25
|
+
if (mode === "multi") {
|
|
26
|
+
return isMulti(resolvedValue) && resolvedValue.has(id);
|
|
27
|
+
}
|
|
28
|
+
return resolvedValue === id;
|
|
29
|
+
}, [
|
|
30
|
+
mode,
|
|
31
|
+
resolvedValue
|
|
32
|
+
]);
|
|
33
|
+
const setExpanded = useCallback((id, expanded) => {
|
|
34
|
+
const computeNext = () => {
|
|
35
|
+
if (mode === "multi") {
|
|
36
|
+
const current = isMulti(resolvedValue) ? resolvedValue : /* @__PURE__ */ new Set();
|
|
37
|
+
const next2 = new Set(current);
|
|
38
|
+
if (expanded) {
|
|
39
|
+
next2.add(id);
|
|
40
|
+
} else {
|
|
41
|
+
next2.delete(id);
|
|
42
|
+
}
|
|
43
|
+
return next2;
|
|
44
|
+
}
|
|
45
|
+
return expanded ? id : void 0;
|
|
46
|
+
};
|
|
47
|
+
const next = computeNext();
|
|
48
|
+
if (!isControlled) {
|
|
49
|
+
setInternalValue(next);
|
|
50
|
+
}
|
|
51
|
+
onValueChange?.(next);
|
|
52
|
+
}, [
|
|
53
|
+
mode,
|
|
54
|
+
resolvedValue,
|
|
55
|
+
isControlled,
|
|
56
|
+
onValueChange
|
|
57
|
+
]);
|
|
58
|
+
const bind = useCallback((id) => {
|
|
59
|
+
const expanded = isExpanded(id);
|
|
60
|
+
const triggerId = `${idPrefix}-${id}-trigger`;
|
|
61
|
+
const panelId = `${idPrefix}-${id}-panel`;
|
|
62
|
+
return {
|
|
63
|
+
expanded,
|
|
64
|
+
toggle: () => setExpanded(id, !expanded),
|
|
65
|
+
triggerId,
|
|
66
|
+
panelId,
|
|
67
|
+
triggerProps: {
|
|
68
|
+
id: triggerId,
|
|
69
|
+
"aria-expanded": expanded,
|
|
70
|
+
"aria-controls": panelId,
|
|
71
|
+
onClick: () => setExpanded(id, !expanded)
|
|
72
|
+
},
|
|
73
|
+
panelProps: {
|
|
74
|
+
id: panelId,
|
|
75
|
+
role: "region",
|
|
76
|
+
"aria-labelledby": triggerId
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}, [
|
|
80
|
+
idPrefix,
|
|
81
|
+
isExpanded,
|
|
82
|
+
setExpanded
|
|
83
|
+
]);
|
|
84
|
+
return {
|
|
85
|
+
bind
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// src/aspects/useListGrid.ts
|
|
90
|
+
import { useMemo } from "react";
|
|
91
|
+
var useListGrid = ({ actionSlots = 0, expandable = false, trailing = false } = {}) => {
|
|
92
|
+
const gridTemplateColumns = useMemo(() => {
|
|
93
|
+
const tracks = [
|
|
94
|
+
"var(--dx-rail-item)",
|
|
95
|
+
"1fr"
|
|
96
|
+
];
|
|
97
|
+
for (let index = 0; index < actionSlots; index++) {
|
|
98
|
+
tracks.push("var(--dx-rail-item)");
|
|
99
|
+
}
|
|
100
|
+
if (expandable) {
|
|
101
|
+
tracks.push("var(--dx-rail-item)");
|
|
102
|
+
}
|
|
103
|
+
if (trailing) {
|
|
104
|
+
tracks.push("var(--dx-rail-item)");
|
|
105
|
+
}
|
|
106
|
+
return tracks.join(" ");
|
|
107
|
+
}, [
|
|
108
|
+
actionSlots,
|
|
109
|
+
expandable,
|
|
110
|
+
trailing
|
|
111
|
+
]);
|
|
112
|
+
return {
|
|
113
|
+
rowProps: {
|
|
114
|
+
className: "grid items-start gap-1",
|
|
115
|
+
style: {
|
|
116
|
+
gridTemplateColumns
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/aspects/useListNavigation.ts
|
|
123
|
+
import { useArrowNavigationGroup } from "@fluentui/react-tabster";
|
|
124
|
+
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
125
|
+
var containerRoleByMode = {
|
|
126
|
+
list: "list",
|
|
127
|
+
listbox: "listbox",
|
|
128
|
+
grid: "grid"
|
|
129
|
+
};
|
|
130
|
+
var itemRoleByMode = {
|
|
131
|
+
list: "listitem",
|
|
132
|
+
listbox: "option",
|
|
133
|
+
grid: "row"
|
|
134
|
+
};
|
|
135
|
+
var defaultAxisByMode = {
|
|
136
|
+
list: "vertical",
|
|
137
|
+
listbox: "vertical",
|
|
138
|
+
grid: "grid"
|
|
139
|
+
};
|
|
140
|
+
var findListboxEntryTarget = (container) => {
|
|
141
|
+
return container.querySelector('[role="option"][aria-selected="true"]:not([aria-disabled="true"])') ?? container.querySelector('[role="option"]:not([aria-disabled="true"])');
|
|
142
|
+
};
|
|
143
|
+
var useListNavigation = ({ mode, axis, memorizeCurrent = true }) => {
|
|
144
|
+
const tabsterAttrs = useArrowNavigationGroup({
|
|
145
|
+
axis: axis ?? defaultAxisByMode[mode],
|
|
146
|
+
memorizeCurrent
|
|
147
|
+
});
|
|
148
|
+
const handleFocus = useCallback2((event) => {
|
|
149
|
+
if (event.target !== event.currentTarget) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (mode !== "listbox") {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const target = findListboxEntryTarget(event.currentTarget);
|
|
156
|
+
target?.focus();
|
|
157
|
+
}, [
|
|
158
|
+
mode
|
|
159
|
+
]);
|
|
160
|
+
const orientation = mode === "grid" ? void 0 : axis === "horizontal" ? "horizontal" : "vertical";
|
|
161
|
+
const containerProps = useMemo2(() => ({
|
|
162
|
+
role: containerRoleByMode[mode],
|
|
163
|
+
...orientation && {
|
|
164
|
+
"aria-orientation": orientation
|
|
165
|
+
},
|
|
166
|
+
...tabsterAttrs,
|
|
167
|
+
onFocus: handleFocus
|
|
168
|
+
}), [
|
|
169
|
+
mode,
|
|
170
|
+
orientation,
|
|
171
|
+
tabsterAttrs,
|
|
172
|
+
handleFocus
|
|
173
|
+
]);
|
|
174
|
+
const itemRole = itemRoleByMode[mode];
|
|
175
|
+
const itemTabIndex = mode === "listbox" ? 0 : -1;
|
|
176
|
+
const itemProps = useCallback2(({ disabled } = {}) => ({
|
|
177
|
+
role: itemRole,
|
|
178
|
+
tabIndex: itemTabIndex,
|
|
179
|
+
...disabled && {
|
|
180
|
+
"aria-disabled": true
|
|
181
|
+
}
|
|
182
|
+
}), [
|
|
183
|
+
itemRole,
|
|
184
|
+
itemTabIndex
|
|
185
|
+
]);
|
|
186
|
+
return {
|
|
187
|
+
containerProps,
|
|
188
|
+
itemProps
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/aspects/useListSelection.ts
|
|
193
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
194
|
+
var isMulti2 = (value) => value instanceof Set;
|
|
195
|
+
var useListSelection = (opts) => {
|
|
196
|
+
const { mode, value, defaultValue, onValueChange, followsFocus } = opts;
|
|
197
|
+
const wasControlledRef = useRef2(Object.prototype.hasOwnProperty.call(opts, "value"));
|
|
198
|
+
if (Object.prototype.hasOwnProperty.call(opts, "value")) {
|
|
199
|
+
wasControlledRef.current = true;
|
|
200
|
+
}
|
|
201
|
+
const isControlled = wasControlledRef.current;
|
|
202
|
+
const [internalValue, setInternalValue] = useState2(() => defaultValue);
|
|
203
|
+
useEffect2(() => {
|
|
204
|
+
if (isControlled) {
|
|
205
|
+
setInternalValue(value);
|
|
206
|
+
}
|
|
207
|
+
}, [
|
|
208
|
+
isControlled,
|
|
209
|
+
value
|
|
210
|
+
]);
|
|
211
|
+
const resolvedValue = isControlled ? value : internalValue;
|
|
212
|
+
const setResolvedValue = useCallback3((next) => {
|
|
213
|
+
if (!isControlled) {
|
|
214
|
+
setInternalValue(next);
|
|
215
|
+
}
|
|
216
|
+
onValueChange?.(next);
|
|
217
|
+
}, [
|
|
218
|
+
isControlled,
|
|
219
|
+
onValueChange,
|
|
220
|
+
mode
|
|
221
|
+
]);
|
|
222
|
+
const isSelected = useCallback3((id) => {
|
|
223
|
+
if (mode === "multi") {
|
|
224
|
+
return isMulti2(resolvedValue) && resolvedValue.has(id);
|
|
225
|
+
}
|
|
226
|
+
return resolvedValue === id;
|
|
227
|
+
}, [
|
|
228
|
+
mode,
|
|
229
|
+
resolvedValue
|
|
230
|
+
]);
|
|
231
|
+
const setSelected = useCallback3((id, selected) => {
|
|
232
|
+
if (mode === "multi") {
|
|
233
|
+
const current = isMulti2(resolvedValue) ? resolvedValue : /* @__PURE__ */ new Set();
|
|
234
|
+
const next = new Set(current);
|
|
235
|
+
if (selected) {
|
|
236
|
+
next.add(id);
|
|
237
|
+
} else {
|
|
238
|
+
next.delete(id);
|
|
239
|
+
}
|
|
240
|
+
setResolvedValue(next);
|
|
241
|
+
} else {
|
|
242
|
+
setResolvedValue(selected ? id : void 0);
|
|
243
|
+
}
|
|
244
|
+
}, [
|
|
245
|
+
mode,
|
|
246
|
+
resolvedValue,
|
|
247
|
+
setResolvedValue
|
|
248
|
+
]);
|
|
249
|
+
const followFocusDefault = mode === "single";
|
|
250
|
+
const trackFocus = followsFocus ?? followFocusDefault;
|
|
251
|
+
const bind = useCallback3((id, { disabled } = {}) => {
|
|
252
|
+
const selected = isSelected(id);
|
|
253
|
+
return {
|
|
254
|
+
selected,
|
|
255
|
+
toggle: () => {
|
|
256
|
+
if (!disabled) {
|
|
257
|
+
setSelected(id, mode === "multi" ? !selected : true);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
rowProps: {
|
|
261
|
+
"aria-selected": selected,
|
|
262
|
+
onClick: () => {
|
|
263
|
+
if (disabled) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
setSelected(id, mode === "multi" ? !selected : true);
|
|
267
|
+
},
|
|
268
|
+
...trackFocus && {
|
|
269
|
+
onFocus: (event) => {
|
|
270
|
+
if (disabled || selected) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const container = event.currentTarget?.closest?.('[role="listbox"],[role="list"],[role="grid"]');
|
|
274
|
+
if (container && !container.contains(event.relatedTarget)) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
setSelected(id, true);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
}, [
|
|
283
|
+
isSelected,
|
|
284
|
+
mode,
|
|
285
|
+
setSelected,
|
|
286
|
+
trackFocus
|
|
287
|
+
]);
|
|
288
|
+
return {
|
|
289
|
+
bind
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// src/aspects/useReorder.ts
|
|
294
|
+
import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element";
|
|
295
|
+
import { attachClosestEdge, extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
296
|
+
import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
|
|
297
|
+
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
298
|
+
import { draggable, dropTargetForElements, monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
299
|
+
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
300
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
301
|
+
var REORDER_LIST_KEY = "__dxosReorderListId";
|
|
302
|
+
var reorderListIdCounter = 0;
|
|
303
|
+
var allocateReorderListId = () => `reorder-${++reorderListIdCounter}`;
|
|
304
|
+
var IDLE = {
|
|
305
|
+
type: "idle"
|
|
306
|
+
};
|
|
307
|
+
var useReorderList = ({ items, getId, onMove, axis = "vertical", readonly = false, getInitialData, canDrop, getDragPreview }) => {
|
|
308
|
+
const listIdRef = useRef3(null);
|
|
309
|
+
if (!listIdRef.current) {
|
|
310
|
+
listIdRef.current = allocateReorderListId();
|
|
311
|
+
}
|
|
312
|
+
const listId = listIdRef.current;
|
|
313
|
+
const itemsRef = useRef3(items);
|
|
314
|
+
itemsRef.current = items;
|
|
315
|
+
const getIdRef = useRef3(getId);
|
|
316
|
+
getIdRef.current = getId;
|
|
317
|
+
const onMoveRef = useRef3(onMove);
|
|
318
|
+
onMoveRef.current = onMove;
|
|
319
|
+
const canDropRef = useRef3(canDrop);
|
|
320
|
+
canDropRef.current = canDrop;
|
|
321
|
+
const getInitialDataRef = useRef3(getInitialData);
|
|
322
|
+
getInitialDataRef.current = getInitialData;
|
|
323
|
+
const getDragPreviewRef = useRef3(getDragPreview);
|
|
324
|
+
getDragPreviewRef.current = getDragPreview;
|
|
325
|
+
const readonlyRef = useRef3(readonly);
|
|
326
|
+
readonlyRef.current = readonly;
|
|
327
|
+
const [active, setActive] = useState3(null);
|
|
328
|
+
const findIndex = useCallback4((id) => {
|
|
329
|
+
return itemsRef.current.findIndex((item) => getIdRef.current(item) === id);
|
|
330
|
+
}, []);
|
|
331
|
+
const findIndexFromPayload = useCallback4((data) => {
|
|
332
|
+
if (!data || data[REORDER_LIST_KEY] !== listId) {
|
|
333
|
+
return -1;
|
|
334
|
+
}
|
|
335
|
+
const id = data.id;
|
|
336
|
+
return id ? findIndex(id) : -1;
|
|
337
|
+
}, [
|
|
338
|
+
listId,
|
|
339
|
+
findIndex
|
|
340
|
+
]);
|
|
341
|
+
useEffect3(() => {
|
|
342
|
+
return monitorForElements({
|
|
343
|
+
canMonitor: ({ source }) => {
|
|
344
|
+
if (canDropRef.current) {
|
|
345
|
+
return canDropRef.current({
|
|
346
|
+
source
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return source.data[REORDER_LIST_KEY] === listId;
|
|
350
|
+
},
|
|
351
|
+
onDrop: ({ location, source }) => {
|
|
352
|
+
const target = location.current.dropTargets[0];
|
|
353
|
+
if (!target) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const sourceIdx = findIndexFromPayload(source.data);
|
|
357
|
+
const targetIdx = findIndexFromPayload(target.data);
|
|
358
|
+
if (sourceIdx < 0 || targetIdx < 0) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const destinationIndex = getReorderDestinationIndex({
|
|
362
|
+
closestEdgeOfTarget: extractClosestEdge(target.data),
|
|
363
|
+
startIndex: sourceIdx,
|
|
364
|
+
indexOfTarget: targetIdx,
|
|
365
|
+
axis
|
|
366
|
+
});
|
|
367
|
+
onMoveRef.current(sourceIdx, destinationIndex);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}, [
|
|
371
|
+
listId,
|
|
372
|
+
axis,
|
|
373
|
+
findIndexFromPayload
|
|
374
|
+
]);
|
|
375
|
+
const controller = useMemo3(() => ({
|
|
376
|
+
listId,
|
|
377
|
+
getItem: (id) => {
|
|
378
|
+
const index = findIndex(id);
|
|
379
|
+
if (index < 0) {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
item: itemsRef.current[index],
|
|
384
|
+
index
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
bindItem: (id, refs, onItemState) => {
|
|
388
|
+
const lookup = () => {
|
|
389
|
+
const index2 = findIndex(id);
|
|
390
|
+
return {
|
|
391
|
+
item: itemsRef.current[index2],
|
|
392
|
+
index: index2
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
const { item, index } = lookup();
|
|
396
|
+
if (!item && index < 0) {
|
|
397
|
+
return () => {
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
const allowedEdges = axis === "vertical" ? [
|
|
401
|
+
"top",
|
|
402
|
+
"bottom"
|
|
403
|
+
] : [
|
|
404
|
+
"left",
|
|
405
|
+
"right"
|
|
406
|
+
];
|
|
407
|
+
return combine(draggable({
|
|
408
|
+
element: refs.row,
|
|
409
|
+
dragHandle: refs.handle,
|
|
410
|
+
canDrag: () => !readonlyRef.current,
|
|
411
|
+
getInitialData: () => {
|
|
412
|
+
const current = lookup();
|
|
413
|
+
return {
|
|
414
|
+
[REORDER_LIST_KEY]: listId,
|
|
415
|
+
id,
|
|
416
|
+
...getInitialDataRef.current?.(current.item, current.index) ?? {}
|
|
417
|
+
};
|
|
418
|
+
},
|
|
419
|
+
onGenerateDragPreview: getDragPreviewRef.current ? ({ nativeSetDragImage, source }) => {
|
|
420
|
+
const rect = source.element.getBoundingClientRect();
|
|
421
|
+
setCustomNativeDragPreview({
|
|
422
|
+
nativeSetDragImage,
|
|
423
|
+
getOffset: ({ container }) => ({
|
|
424
|
+
x: 20,
|
|
425
|
+
y: container.getBoundingClientRect().height / 2
|
|
426
|
+
}),
|
|
427
|
+
render: ({ container }) => {
|
|
428
|
+
container.style.width = `${rect.width}px`;
|
|
429
|
+
onItemState({
|
|
430
|
+
type: "preview",
|
|
431
|
+
container
|
|
432
|
+
});
|
|
433
|
+
const current = lookup();
|
|
434
|
+
setActive({
|
|
435
|
+
id,
|
|
436
|
+
item: current.item,
|
|
437
|
+
container
|
|
438
|
+
});
|
|
439
|
+
return () => {
|
|
440
|
+
onItemState(IDLE);
|
|
441
|
+
setActive(null);
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
} : void 0,
|
|
446
|
+
onDragStart: () => {
|
|
447
|
+
onItemState({
|
|
448
|
+
type: "dragging"
|
|
449
|
+
});
|
|
450
|
+
const current = lookup();
|
|
451
|
+
setActive({
|
|
452
|
+
id,
|
|
453
|
+
item: current.item,
|
|
454
|
+
container: refs.row
|
|
455
|
+
});
|
|
456
|
+
},
|
|
457
|
+
onDrop: () => {
|
|
458
|
+
onItemState(IDLE);
|
|
459
|
+
setActive(null);
|
|
460
|
+
}
|
|
461
|
+
}), dropTargetForElements({
|
|
462
|
+
element: refs.row,
|
|
463
|
+
canDrop: ({ source }) => {
|
|
464
|
+
if (source.element === refs.row) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
if (canDropRef.current) {
|
|
468
|
+
return canDropRef.current({
|
|
469
|
+
source
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
return source.data[REORDER_LIST_KEY] === listId;
|
|
473
|
+
},
|
|
474
|
+
getData: ({ input }) => attachClosestEdge({
|
|
475
|
+
[REORDER_LIST_KEY]: listId,
|
|
476
|
+
id
|
|
477
|
+
}, {
|
|
478
|
+
element: refs.row,
|
|
479
|
+
input,
|
|
480
|
+
allowedEdges
|
|
481
|
+
}),
|
|
482
|
+
getIsSticky: () => true,
|
|
483
|
+
onDragEnter: ({ self }) => {
|
|
484
|
+
onItemState({
|
|
485
|
+
type: "dragging-over",
|
|
486
|
+
closestEdge: extractClosestEdge(self.data)
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
onDrag: ({ self }) => {
|
|
490
|
+
onItemState({
|
|
491
|
+
type: "dragging-over",
|
|
492
|
+
closestEdge: extractClosestEdge(self.data)
|
|
493
|
+
});
|
|
494
|
+
},
|
|
495
|
+
onDragLeave: () => onItemState(IDLE),
|
|
496
|
+
onDrop: () => onItemState(IDLE)
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
}), [
|
|
500
|
+
listId,
|
|
501
|
+
axis,
|
|
502
|
+
findIndex
|
|
503
|
+
]);
|
|
504
|
+
return {
|
|
505
|
+
controller,
|
|
506
|
+
active,
|
|
507
|
+
listId
|
|
508
|
+
};
|
|
509
|
+
};
|
|
510
|
+
var useReorderItem = (controller, id) => {
|
|
511
|
+
const [state, setState] = useState3(IDLE);
|
|
512
|
+
const rowElement = useRef3(null);
|
|
513
|
+
const handleElement = useRef3(null);
|
|
514
|
+
const cleanupRef = useRef3(null);
|
|
515
|
+
const tryRegister = useCallback4(() => {
|
|
516
|
+
if (!rowElement.current || !handleElement.current) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
cleanupRef.current?.();
|
|
520
|
+
cleanupRef.current = controller.bindItem(id, {
|
|
521
|
+
row: rowElement.current,
|
|
522
|
+
handle: handleElement.current
|
|
523
|
+
}, setState);
|
|
524
|
+
}, [
|
|
525
|
+
controller,
|
|
526
|
+
id
|
|
527
|
+
]);
|
|
528
|
+
const teardown = useCallback4(() => {
|
|
529
|
+
cleanupRef.current?.();
|
|
530
|
+
cleanupRef.current = null;
|
|
531
|
+
setState(IDLE);
|
|
532
|
+
}, []);
|
|
533
|
+
useEffect3(() => {
|
|
534
|
+
tryRegister();
|
|
535
|
+
return teardown;
|
|
536
|
+
}, [
|
|
537
|
+
tryRegister,
|
|
538
|
+
teardown
|
|
539
|
+
]);
|
|
540
|
+
const rowRef = useCallback4((node) => {
|
|
541
|
+
rowElement.current = node;
|
|
542
|
+
if (node) {
|
|
543
|
+
tryRegister();
|
|
544
|
+
} else {
|
|
545
|
+
teardown();
|
|
546
|
+
}
|
|
547
|
+
}, [
|
|
548
|
+
tryRegister,
|
|
549
|
+
teardown
|
|
550
|
+
]);
|
|
551
|
+
const handleRef = useCallback4((node) => {
|
|
552
|
+
handleElement.current = node;
|
|
553
|
+
if (node && rowElement.current) {
|
|
554
|
+
tryRegister();
|
|
555
|
+
} else if (!node) {
|
|
556
|
+
teardown();
|
|
557
|
+
}
|
|
558
|
+
}, [
|
|
559
|
+
tryRegister,
|
|
560
|
+
teardown
|
|
561
|
+
]);
|
|
562
|
+
return {
|
|
563
|
+
rowRef,
|
|
564
|
+
handleRef,
|
|
565
|
+
state,
|
|
566
|
+
isDragging: state.type === "dragging",
|
|
567
|
+
closestEdge: state.type === "dragging-over" ? state.closestEdge : null
|
|
568
|
+
};
|
|
569
|
+
};
|
|
570
|
+
var useReorderAutoScroll = () => {
|
|
571
|
+
const cleanupRef = useRef3(null);
|
|
572
|
+
return useCallback4((node) => {
|
|
573
|
+
cleanupRef.current?.();
|
|
574
|
+
cleanupRef.current = node ? autoScrollForElements({
|
|
575
|
+
element: node
|
|
576
|
+
}) : null;
|
|
577
|
+
}, []);
|
|
578
|
+
};
|
|
579
|
+
|
|
3
580
|
// src/components/Accordion/AccordionItem.tsx
|
|
4
581
|
import * as AccordionPrimitive2 from "@radix-ui/react-accordion";
|
|
5
582
|
import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
@@ -41,16 +618,21 @@ var AccordionItem = ({ children, classNames, item }) => {
|
|
|
41
618
|
className: mx2("overflow-hidden", classNames)
|
|
42
619
|
}, children));
|
|
43
620
|
};
|
|
44
|
-
var AccordionItemHeader = ({ classNames, children, ...props }) => {
|
|
621
|
+
var AccordionItemHeader = ({ classNames, children, icon, ...props }) => {
|
|
45
622
|
return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Header, {
|
|
46
623
|
...props,
|
|
47
624
|
className: mx2(classNames)
|
|
48
625
|
}, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Trigger, {
|
|
49
|
-
className: "group flex items-center p-2 dx-focus-ring-inset w-full text-start"
|
|
50
|
-
},
|
|
626
|
+
className: "group flex items-center justify-between gap-2 p-2 dx-focus-ring-inset w-full text-start"
|
|
627
|
+
}, icon && /* @__PURE__ */ React2.createElement(Icon, {
|
|
628
|
+
icon,
|
|
629
|
+
size: 4
|
|
630
|
+
}), /* @__PURE__ */ React2.createElement("span", {
|
|
631
|
+
className: "min-w-0 flex-1 truncate"
|
|
632
|
+
}, children), /* @__PURE__ */ React2.createElement(Icon, {
|
|
51
633
|
icon: "ph--caret-right--regular",
|
|
52
634
|
size: 4,
|
|
53
|
-
classNames: "transition-transform duration-200 group-data-[state=open]:rotate-90"
|
|
635
|
+
classNames: "shrink-0 transition-transform duration-200 group-data-[state=open]:rotate-90"
|
|
54
636
|
})));
|
|
55
637
|
};
|
|
56
638
|
var AccordionItemBody = ({ children, classNames }) => {
|
|
@@ -72,14 +654,14 @@ var Accordion = {
|
|
|
72
654
|
// src/components/Combobox/Combobox.tsx
|
|
73
655
|
import { createContext as createContext4 } from "@radix-ui/react-context";
|
|
74
656
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
75
|
-
import React4, { forwardRef as forwardRef2, useCallback as
|
|
76
|
-
import { Button, Icon as Icon2, Popover, ScrollArea, useId } from "@dxos/react-ui";
|
|
657
|
+
import React4, { forwardRef as forwardRef2, useCallback as useCallback6 } from "react";
|
|
658
|
+
import { Button, Icon as Icon2, Popover, ScrollArea, useId as useId2 } from "@dxos/react-ui";
|
|
77
659
|
import { composable, composableProps } from "@dxos/react-ui";
|
|
78
660
|
import { mx as mx4 } from "@dxos/ui-theme";
|
|
79
661
|
|
|
80
662
|
// src/components/Picker/Picker.tsx
|
|
81
663
|
import { Slot } from "@radix-ui/react-slot";
|
|
82
|
-
import React3, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
664
|
+
import React3, { forwardRef, useCallback as useCallback5, useEffect as useEffect4, useMemo as useMemo4, useRef as useRef4, useState as useState4 } from "react";
|
|
83
665
|
import { Input, useThemeContext } from "@dxos/react-ui";
|
|
84
666
|
import { mx as mx3 } from "@dxos/ui-theme";
|
|
85
667
|
|
|
@@ -90,10 +672,10 @@ var [PickerInputContextProvider, usePickerInputContext] = createContext3("Picker
|
|
|
90
672
|
|
|
91
673
|
// src/components/Picker/Picker.tsx
|
|
92
674
|
var PickerRoot = ({ children }) => {
|
|
93
|
-
const [selectedValue, setSelectedValue] =
|
|
94
|
-
const itemsRef =
|
|
95
|
-
const [itemVersion, setItemVersion] =
|
|
96
|
-
|
|
675
|
+
const [selectedValue, setSelectedValue] = useState4(void 0);
|
|
676
|
+
const itemsRef = useRef4(/* @__PURE__ */ new Map());
|
|
677
|
+
const [itemVersion, setItemVersion] = useState4(0);
|
|
678
|
+
useEffect4(() => {
|
|
97
679
|
const current = selectedValue !== void 0 ? itemsRef.current.get(selectedValue) : void 0;
|
|
98
680
|
const isValid = current !== void 0 && !current.disabled;
|
|
99
681
|
if (!isValid && itemsRef.current.size > 0) {
|
|
@@ -121,7 +703,7 @@ var PickerRoot = ({ children }) => {
|
|
|
121
703
|
itemVersion,
|
|
122
704
|
selectedValue
|
|
123
705
|
]);
|
|
124
|
-
const registerItem =
|
|
706
|
+
const registerItem = useCallback5((value, element, onSelect, disabled) => {
|
|
125
707
|
if (element) {
|
|
126
708
|
itemsRef.current.set(value, {
|
|
127
709
|
element,
|
|
@@ -131,17 +713,17 @@ var PickerRoot = ({ children }) => {
|
|
|
131
713
|
setItemVersion((v) => v + 1);
|
|
132
714
|
}
|
|
133
715
|
}, []);
|
|
134
|
-
const unregisterItem =
|
|
716
|
+
const unregisterItem = useCallback5((value) => {
|
|
135
717
|
itemsRef.current.delete(value);
|
|
136
718
|
setItemVersion((v) => v + 1);
|
|
137
719
|
}, []);
|
|
138
|
-
const getItemValues =
|
|
720
|
+
const getItemValues = useCallback5(() => {
|
|
139
721
|
return Array.from(itemsRef.current.entries()).filter(([, data]) => !data.disabled).sort(([, a], [, b]) => {
|
|
140
722
|
const position = a.element.compareDocumentPosition(b.element);
|
|
141
723
|
return position & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : position & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0;
|
|
142
724
|
}).map(([value]) => value);
|
|
143
725
|
}, []);
|
|
144
|
-
const triggerSelect =
|
|
726
|
+
const triggerSelect = useCallback5(() => {
|
|
145
727
|
if (selectedValue !== void 0) {
|
|
146
728
|
const item = itemsRef.current.get(selectedValue);
|
|
147
729
|
item?.onSelect?.();
|
|
@@ -149,7 +731,7 @@ var PickerRoot = ({ children }) => {
|
|
|
149
731
|
}, [
|
|
150
732
|
selectedValue
|
|
151
733
|
]);
|
|
152
|
-
const itemContextValue =
|
|
734
|
+
const itemContextValue = useMemo4(() => ({
|
|
153
735
|
selectedValue,
|
|
154
736
|
onSelectedValueChange: setSelectedValue,
|
|
155
737
|
registerItem,
|
|
@@ -159,7 +741,7 @@ var PickerRoot = ({ children }) => {
|
|
|
159
741
|
registerItem,
|
|
160
742
|
unregisterItem
|
|
161
743
|
]);
|
|
162
|
-
const inputContextValue =
|
|
744
|
+
const inputContextValue = useMemo4(() => ({
|
|
163
745
|
selectedValue,
|
|
164
746
|
onSelectedValueChange: setSelectedValue,
|
|
165
747
|
getItemValues,
|
|
@@ -175,14 +757,14 @@ PickerRoot.displayName = "Picker.Root";
|
|
|
175
757
|
var PickerInput = /* @__PURE__ */ forwardRef(({ value, onValueChange, onChange, onKeyDown, autoFocus, ...props }, forwardedRef) => {
|
|
176
758
|
const { hasIosKeyboard } = useThemeContext();
|
|
177
759
|
const { selectedValue, onSelectedValueChange, getItemValues, triggerSelect } = usePickerInputContext("Picker.Input");
|
|
178
|
-
const handleChange =
|
|
760
|
+
const handleChange = useCallback5((event) => {
|
|
179
761
|
onValueChange?.(event.target.value);
|
|
180
762
|
onChange?.(event);
|
|
181
763
|
}, [
|
|
182
764
|
onValueChange,
|
|
183
765
|
onChange
|
|
184
766
|
]);
|
|
185
|
-
const handleKeyDown =
|
|
767
|
+
const handleKeyDown = useCallback5((event) => {
|
|
186
768
|
onKeyDown?.(event);
|
|
187
769
|
if (event.defaultPrevented) {
|
|
188
770
|
return;
|
|
@@ -269,9 +851,9 @@ var PickerInput = /* @__PURE__ */ forwardRef(({ value, onValueChange, onChange,
|
|
|
269
851
|
PickerInput.displayName = "Picker.Input";
|
|
270
852
|
var PickerItem = /* @__PURE__ */ forwardRef(({ classNames, value, onSelect, disabled, asChild, children, ...props }, forwardedRef) => {
|
|
271
853
|
const { selectedValue, onSelectedValueChange, registerItem, unregisterItem } = usePickerItemContext("Picker.Item");
|
|
272
|
-
const internalRef =
|
|
854
|
+
const internalRef = useRef4(null);
|
|
273
855
|
const isSelected = selectedValue === value && !disabled;
|
|
274
|
-
|
|
856
|
+
useEffect4(() => {
|
|
275
857
|
const element = internalRef.current;
|
|
276
858
|
if (element) {
|
|
277
859
|
registerItem(value, element, onSelect, disabled);
|
|
@@ -284,7 +866,7 @@ var PickerItem = /* @__PURE__ */ forwardRef(({ classNames, value, onSelect, disa
|
|
|
284
866
|
registerItem,
|
|
285
867
|
unregisterItem
|
|
286
868
|
]);
|
|
287
|
-
|
|
869
|
+
useEffect4(() => {
|
|
288
870
|
if (isSelected && internalRef.current) {
|
|
289
871
|
internalRef.current.scrollIntoView({
|
|
290
872
|
block: "nearest",
|
|
@@ -294,7 +876,7 @@ var PickerItem = /* @__PURE__ */ forwardRef(({ classNames, value, onSelect, disa
|
|
|
294
876
|
}, [
|
|
295
877
|
isSelected
|
|
296
878
|
]);
|
|
297
|
-
const handleClick =
|
|
879
|
+
const handleClick = useCallback5(() => {
|
|
298
880
|
if (disabled) {
|
|
299
881
|
return;
|
|
300
882
|
}
|
|
@@ -306,7 +888,7 @@ var PickerItem = /* @__PURE__ */ forwardRef(({ classNames, value, onSelect, disa
|
|
|
306
888
|
onSelectedValueChange,
|
|
307
889
|
onSelect
|
|
308
890
|
]);
|
|
309
|
-
const handleMouseDown =
|
|
891
|
+
const handleMouseDown = useCallback5((event) => {
|
|
310
892
|
event.preventDefault();
|
|
311
893
|
}, []);
|
|
312
894
|
const Comp = asChild ? Slot : "div";
|
|
@@ -347,7 +929,7 @@ var COMBOBOX_ITEM_NAME = "ComboboxItem";
|
|
|
347
929
|
var COMBOBOX_TRIGGER_NAME = "ComboboxTrigger";
|
|
348
930
|
var [ComboboxProvider, useComboboxContext] = createContext4(COMBOBOX_NAME, {});
|
|
349
931
|
var ComboboxRoot = ({ children, modal, modalId: modalIdProp, open: openProp, defaultOpen, onOpenChange: propsOnOpenChange, value: valueProp, defaultValue, onValueChange: propsOnValueChange, placeholder }) => {
|
|
350
|
-
const modalId =
|
|
932
|
+
const modalId = useId2(COMBOBOX_NAME, modalIdProp);
|
|
351
933
|
const [open = false, onOpenChange] = useControllableState({
|
|
352
934
|
prop: openProp,
|
|
353
935
|
defaultProp: defaultOpen,
|
|
@@ -386,7 +968,7 @@ var ComboboxContent = composable(({ children, ...props }, forwardedRef) => {
|
|
|
386
968
|
ComboboxContent.displayName = COMBOBOX_CONTENT_NAME;
|
|
387
969
|
var ComboboxTrigger = /* @__PURE__ */ forwardRef2(({ children, onClick, ...props }, forwardedRef) => {
|
|
388
970
|
const { modalId, open, onOpenChange, placeholder, value } = useComboboxContext(COMBOBOX_TRIGGER_NAME);
|
|
389
|
-
const handleClick =
|
|
971
|
+
const handleClick = useCallback6((event) => {
|
|
390
972
|
onClick?.(event);
|
|
391
973
|
onOpenChange?.(true);
|
|
392
974
|
}, [
|
|
@@ -441,7 +1023,7 @@ var ComboboxList = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props
|
|
|
441
1023
|
ComboboxList.displayName = "Combobox.List";
|
|
442
1024
|
var ComboboxItem = /* @__PURE__ */ forwardRef2(({ classNames, onSelect, value, label, icon, iconClassNames, checked, suffix, disabled, closeOnSelect = true, children }, forwardedRef) => {
|
|
443
1025
|
const { onValueChange, onOpenChange } = useComboboxContext(COMBOBOX_ITEM_NAME);
|
|
444
|
-
const handleSelect =
|
|
1026
|
+
const handleSelect = useCallback6(() => {
|
|
445
1027
|
onSelect?.();
|
|
446
1028
|
if (value !== void 0) {
|
|
447
1029
|
onValueChange?.(value);
|
|
@@ -506,333 +1088,43 @@ var Combobox = {
|
|
|
506
1088
|
Empty: ComboboxEmpty
|
|
507
1089
|
};
|
|
508
1090
|
|
|
509
|
-
// src/components/List/ListItem.tsx
|
|
510
|
-
import { attachClosestEdge, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
511
|
-
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
512
|
-
import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
513
|
-
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
514
|
-
import { createContext as createContext6 } from "@radix-ui/react-context";
|
|
515
|
-
import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
516
|
-
import React6, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
517
|
-
import { createPortal } from "react-dom";
|
|
518
|
-
import { invariant } from "@dxos/invariant";
|
|
519
|
-
import { IconButton, ListItem as NaturalListItem, useTranslation } from "@dxos/react-ui";
|
|
520
|
-
import { mx as mx5, osTranslations } from "@dxos/ui-theme";
|
|
521
|
-
|
|
522
|
-
// src/components/List/ListRoot.tsx
|
|
523
|
-
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
524
|
-
import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
|
|
525
|
-
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
526
|
-
import { createContext as createContext5 } from "@radix-ui/react-context";
|
|
527
|
-
import React5, { useCallback as useCallback3, useEffect as useEffect2, useState as useState2 } from "react";
|
|
528
|
-
var LIST_NAME = "List";
|
|
529
|
-
var [ListProvider, useListContext] = createContext5(LIST_NAME);
|
|
530
|
-
var defaultGetId2 = (item) => item?.id;
|
|
531
|
-
var ListRoot = ({ children, items, isItem, getId = defaultGetId2, onMove, ...props }) => {
|
|
532
|
-
const isEqual = useCallback3((a, b) => {
|
|
533
|
-
const idA = getId?.(a);
|
|
534
|
-
const idB = getId?.(b);
|
|
535
|
-
if (idA !== void 0 && idB !== void 0) {
|
|
536
|
-
return idA === idB;
|
|
537
|
-
} else {
|
|
538
|
-
return a === b;
|
|
539
|
-
}
|
|
540
|
-
}, [
|
|
541
|
-
getId
|
|
542
|
-
]);
|
|
543
|
-
const [state, setState] = useState2(idle);
|
|
544
|
-
useEffect2(() => {
|
|
545
|
-
if (!items) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
return monitorForElements({
|
|
549
|
-
canMonitor: ({ source }) => isItem?.(source.data) ?? false,
|
|
550
|
-
onDrop: ({ location, source }) => {
|
|
551
|
-
const target = location.current.dropTargets[0];
|
|
552
|
-
if (!target) {
|
|
553
|
-
return;
|
|
554
|
-
}
|
|
555
|
-
const sourceData = source.data;
|
|
556
|
-
const targetData = target.data;
|
|
557
|
-
if (!isItem?.(sourceData) || !isItem?.(targetData)) {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
const sourceIdx = items.findIndex((item) => isEqual(item, sourceData));
|
|
561
|
-
const targetIdx = items.findIndex((item) => isEqual(item, targetData));
|
|
562
|
-
if (targetIdx < 0 || sourceIdx < 0) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
const closestEdgeOfTarget = extractClosestEdge(targetData);
|
|
566
|
-
const destinationIndex = getReorderDestinationIndex({
|
|
567
|
-
closestEdgeOfTarget,
|
|
568
|
-
startIndex: sourceIdx,
|
|
569
|
-
indexOfTarget: targetIdx,
|
|
570
|
-
axis: "vertical"
|
|
571
|
-
});
|
|
572
|
-
onMove?.(sourceIdx, destinationIndex);
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
}, [
|
|
576
|
-
items,
|
|
577
|
-
isEqual,
|
|
578
|
-
onMove
|
|
579
|
-
]);
|
|
580
|
-
return /* @__PURE__ */ React5.createElement(ListProvider, {
|
|
581
|
-
state,
|
|
582
|
-
setState,
|
|
583
|
-
isItem,
|
|
584
|
-
...props
|
|
585
|
-
}, children?.({
|
|
586
|
-
state,
|
|
587
|
-
items: items ?? []
|
|
588
|
-
}));
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// src/components/List/ListItem.tsx
|
|
592
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-list/src/components/List/ListItem.tsx";
|
|
593
|
-
var idle = {
|
|
594
|
-
type: "idle"
|
|
595
|
-
};
|
|
596
|
-
var stateStyles = {
|
|
597
|
-
"is-dragging": "opacity-50"
|
|
598
|
-
};
|
|
599
|
-
var defaultContext = {};
|
|
600
|
-
var LIST_ITEM_NAME = "ListItem";
|
|
601
|
-
var [ListItemProvider, useListItemContext] = createContext6(LIST_ITEM_NAME, defaultContext);
|
|
602
|
-
var ListItem = ({ children, classNames, item, asChild, selected, ...props }) => {
|
|
603
|
-
const Comp = asChild ? Slot2 : "div";
|
|
604
|
-
const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
|
|
605
|
-
const rootRef = useRef2(null);
|
|
606
|
-
const dragHandleRef = useRef2(null);
|
|
607
|
-
const [state, setState] = useState3(idle);
|
|
608
|
-
useEffect3(() => {
|
|
609
|
-
const element = rootRef.current;
|
|
610
|
-
invariant(element, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 37, S: void 0, A: ["element", ""] });
|
|
611
|
-
return combine(
|
|
612
|
-
//
|
|
613
|
-
// https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#draggable
|
|
614
|
-
//
|
|
615
|
-
draggable({
|
|
616
|
-
element,
|
|
617
|
-
dragHandle: dragHandleRef.current,
|
|
618
|
-
canDrag: () => !readonly,
|
|
619
|
-
getInitialData: () => item,
|
|
620
|
-
onGenerateDragPreview: dragPreview ? ({ nativeSetDragImage, source }) => {
|
|
621
|
-
const rect = source.element.getBoundingClientRect();
|
|
622
|
-
setCustomNativeDragPreview({
|
|
623
|
-
nativeSetDragImage,
|
|
624
|
-
getOffset: ({ container }) => {
|
|
625
|
-
const { height } = container.getBoundingClientRect();
|
|
626
|
-
return {
|
|
627
|
-
x: 20,
|
|
628
|
-
y: height / 2
|
|
629
|
-
};
|
|
630
|
-
},
|
|
631
|
-
render: ({ container }) => {
|
|
632
|
-
container.style.width = rect.width + "px";
|
|
633
|
-
setState({
|
|
634
|
-
type: "preview",
|
|
635
|
-
container
|
|
636
|
-
});
|
|
637
|
-
setRootState({
|
|
638
|
-
type: "preview",
|
|
639
|
-
container,
|
|
640
|
-
item
|
|
641
|
-
});
|
|
642
|
-
return () => {
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
} : void 0,
|
|
647
|
-
onDragStart: () => {
|
|
648
|
-
setState({
|
|
649
|
-
type: "is-dragging"
|
|
650
|
-
});
|
|
651
|
-
setRootState({
|
|
652
|
-
type: "is-dragging",
|
|
653
|
-
item
|
|
654
|
-
});
|
|
655
|
-
},
|
|
656
|
-
onDrop: () => {
|
|
657
|
-
setState(idle);
|
|
658
|
-
setRootState(idle);
|
|
659
|
-
}
|
|
660
|
-
}),
|
|
661
|
-
//
|
|
662
|
-
// https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#drop-target-for-elements
|
|
663
|
-
//
|
|
664
|
-
dropTargetForElements({
|
|
665
|
-
element,
|
|
666
|
-
canDrop: ({ source }) => {
|
|
667
|
-
return (source.element !== element && isItem?.(source.data)) ?? false;
|
|
668
|
-
},
|
|
669
|
-
getData: ({ input }) => {
|
|
670
|
-
return attachClosestEdge(item, {
|
|
671
|
-
element,
|
|
672
|
-
input,
|
|
673
|
-
allowedEdges: [
|
|
674
|
-
"top",
|
|
675
|
-
"bottom"
|
|
676
|
-
]
|
|
677
|
-
});
|
|
678
|
-
},
|
|
679
|
-
getIsSticky: () => true,
|
|
680
|
-
onDragEnter: ({ self }) => {
|
|
681
|
-
const closestEdge = extractClosestEdge2(self.data);
|
|
682
|
-
setState({
|
|
683
|
-
type: "is-dragging-over",
|
|
684
|
-
closestEdge
|
|
685
|
-
});
|
|
686
|
-
},
|
|
687
|
-
onDragLeave: () => {
|
|
688
|
-
setState(idle);
|
|
689
|
-
},
|
|
690
|
-
onDrag: ({ self }) => {
|
|
691
|
-
const closestEdge = extractClosestEdge2(self.data);
|
|
692
|
-
setState((current) => {
|
|
693
|
-
if (current.type === "is-dragging-over" && current.closestEdge === closestEdge) {
|
|
694
|
-
return current;
|
|
695
|
-
}
|
|
696
|
-
return {
|
|
697
|
-
type: "is-dragging-over",
|
|
698
|
-
closestEdge
|
|
699
|
-
};
|
|
700
|
-
});
|
|
701
|
-
},
|
|
702
|
-
onDrop: () => {
|
|
703
|
-
setState(idle);
|
|
704
|
-
}
|
|
705
|
-
})
|
|
706
|
-
);
|
|
707
|
-
}, [
|
|
708
|
-
item
|
|
709
|
-
]);
|
|
710
|
-
return /* @__PURE__ */ React6.createElement(ListItemProvider, {
|
|
711
|
-
item,
|
|
712
|
-
dragHandleRef
|
|
713
|
-
}, /* @__PURE__ */ React6.createElement(Comp, {
|
|
714
|
-
...props,
|
|
715
|
-
role: "listitem",
|
|
716
|
-
"aria-selected": selected,
|
|
717
|
-
className: mx5("relative p-1 dx-selected dx-hover", classNames, stateStyles[state.type]),
|
|
718
|
-
ref: rootRef
|
|
719
|
-
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React6.createElement(NaturalListItem.DropIndicator, {
|
|
720
|
-
edge: state.closestEdge
|
|
721
|
-
}));
|
|
722
|
-
};
|
|
723
|
-
var ListItemIconButton = ({ autoHide = true, iconOnly = true, variant = "ghost", classNames, disabled, ...props }) => {
|
|
724
|
-
const { state } = useListContext("ITEM_BUTTON");
|
|
725
|
-
const isDisabled = state.type !== "idle" || disabled;
|
|
726
|
-
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
727
|
-
...props,
|
|
728
|
-
disabled: isDisabled,
|
|
729
|
-
iconOnly,
|
|
730
|
-
variant,
|
|
731
|
-
classNames: [
|
|
732
|
-
classNames,
|
|
733
|
-
autoHide && disabled && "hidden"
|
|
734
|
-
]
|
|
735
|
-
});
|
|
736
|
-
};
|
|
737
|
-
var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, icon = "ph--x--regular", label, ...props }) => {
|
|
738
|
-
const { state } = useListContext("DELETE_BUTTON");
|
|
739
|
-
const isDisabled = state.type !== "idle" || disabled;
|
|
740
|
-
const { t } = useTranslation(osTranslations);
|
|
741
|
-
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
742
|
-
...props,
|
|
743
|
-
variant: "ghost",
|
|
744
|
-
disabled: isDisabled,
|
|
745
|
-
icon,
|
|
746
|
-
iconOnly: true,
|
|
747
|
-
label: label ?? t("delete.label"),
|
|
748
|
-
classNames: [
|
|
749
|
-
classNames,
|
|
750
|
-
autoHide && disabled && "hidden"
|
|
751
|
-
]
|
|
752
|
-
});
|
|
753
|
-
};
|
|
754
|
-
var ListItemDragHandle = ({ disabled }) => {
|
|
755
|
-
const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
|
|
756
|
-
const { t } = useTranslation(osTranslations);
|
|
757
|
-
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
758
|
-
variant: "ghost",
|
|
759
|
-
disabled,
|
|
760
|
-
icon: "ph--dots-six-vertical--regular",
|
|
761
|
-
iconOnly: true,
|
|
762
|
-
label: t("drag-handle.label"),
|
|
763
|
-
ref: dragHandleRef
|
|
764
|
-
});
|
|
765
|
-
};
|
|
766
|
-
var ListItemDragPreview = ({ children }) => {
|
|
767
|
-
const { state } = useListContext("DRAG_PREVIEW");
|
|
768
|
-
return state?.type === "preview" ? /* @__PURE__ */ createPortal(children({
|
|
769
|
-
item: state.item
|
|
770
|
-
}), state.container) : null;
|
|
771
|
-
};
|
|
772
|
-
var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React6.createElement("div", {
|
|
773
|
-
className: mx5("flex w-full gap-2", classNames)
|
|
774
|
-
}, children);
|
|
775
|
-
var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React6.createElement("div", {
|
|
776
|
-
className: mx5("flex grow items-center truncate", classNames),
|
|
777
|
-
...props
|
|
778
|
-
}, children);
|
|
779
|
-
|
|
780
|
-
// src/components/List/List.tsx
|
|
781
|
-
var List = {
|
|
782
|
-
Root: ListRoot,
|
|
783
|
-
Item: ListItem,
|
|
784
|
-
ItemDragPreview: ListItemDragPreview,
|
|
785
|
-
ItemWrapper: ListItemWrapper,
|
|
786
|
-
ItemDragHandle: ListItemDragHandle,
|
|
787
|
-
ItemIconButton: ListItemIconButton,
|
|
788
|
-
ItemDeleteButton: ListItemDeleteButton,
|
|
789
|
-
ItemTitle: ListItemTitle
|
|
790
|
-
};
|
|
791
|
-
|
|
792
1091
|
// src/components/Listbox/Listbox.tsx
|
|
793
|
-
import {
|
|
794
|
-
import
|
|
795
|
-
import {
|
|
796
|
-
import {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
var
|
|
807
|
-
var
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
var Root2 = ({ selectedId, defaultSelectedId, onSelectChange, children }) => {
|
|
814
|
-
const [resolved, setResolved] = useControllableState2({
|
|
815
|
-
prop: selectedId,
|
|
816
|
-
defaultProp: defaultSelectedId,
|
|
817
|
-
onChange: (next) => {
|
|
1092
|
+
import { createContext as createContext5 } from "@radix-ui/react-context";
|
|
1093
|
+
import React5, { forwardRef as forwardRef3, useCallback as useCallback7, useMemo as useMemo5 } from "react";
|
|
1094
|
+
import { List, ListItem } from "@dxos/react-list";
|
|
1095
|
+
import { Icon as Icon3, ScrollArea as ScrollArea2, composable as composable2, composableProps as composableProps2 } from "@dxos/react-ui";
|
|
1096
|
+
import { mx as mx5 } from "@dxos/ui-theme";
|
|
1097
|
+
var LISTBOX_NAME = "Listbox";
|
|
1098
|
+
var LISTBOX_ROOT_NAME = "Listbox.Root";
|
|
1099
|
+
var LISTBOX_VIEWPORT_NAME = "Listbox.Viewport";
|
|
1100
|
+
var LISTBOX_CONTENT_NAME = "Listbox.Content";
|
|
1101
|
+
var LISTBOX_ITEM_NAME = "Listbox.Item";
|
|
1102
|
+
var LISTBOX_ITEM_LABEL_NAME = "Listbox.ItemLabel";
|
|
1103
|
+
var LISTBOX_INDICATOR_NAME = "Listbox.Indicator";
|
|
1104
|
+
var [ListboxProvider, useListboxContext] = createContext5(LISTBOX_NAME);
|
|
1105
|
+
var [ListboxItemProvider, useListboxItemContext] = createContext5(LISTBOX_ITEM_NAME);
|
|
1106
|
+
var Root2 = ({ value, defaultValue, onValueChange, autoFocus: _autoFocus, children }) => {
|
|
1107
|
+
const selection = useListSelection({
|
|
1108
|
+
mode: "single",
|
|
1109
|
+
value,
|
|
1110
|
+
defaultValue,
|
|
1111
|
+
onValueChange: (next) => {
|
|
818
1112
|
if (next !== void 0) {
|
|
819
|
-
|
|
1113
|
+
onValueChange?.(next);
|
|
820
1114
|
}
|
|
821
1115
|
}
|
|
822
1116
|
});
|
|
823
|
-
const
|
|
824
|
-
|
|
1117
|
+
const context = useMemo5(() => ({
|
|
1118
|
+
selection
|
|
1119
|
+
}), [
|
|
1120
|
+
selection
|
|
825
1121
|
]);
|
|
826
|
-
return /* @__PURE__ */
|
|
827
|
-
scope: void 0,
|
|
828
|
-
selectedId: resolved,
|
|
829
|
-
setSelected
|
|
830
|
-
}, children);
|
|
1122
|
+
return /* @__PURE__ */ React5.createElement(ListboxProvider, context, children);
|
|
831
1123
|
};
|
|
832
|
-
Root2.displayName =
|
|
1124
|
+
Root2.displayName = LISTBOX_ROOT_NAME;
|
|
833
1125
|
var Viewport = composable2((props, forwardedRef) => {
|
|
834
1126
|
const { thin, padding, centered, children, ...rest } = props;
|
|
835
|
-
return /* @__PURE__ */
|
|
1127
|
+
return /* @__PURE__ */ React5.createElement(ScrollArea2.Root, {
|
|
836
1128
|
...composableProps2(rest, {
|
|
837
1129
|
classNames: "dx-container"
|
|
838
1130
|
}),
|
|
@@ -841,181 +1133,348 @@ var Viewport = composable2((props, forwardedRef) => {
|
|
|
841
1133
|
centered,
|
|
842
1134
|
orientation: "vertical",
|
|
843
1135
|
ref: forwardedRef
|
|
844
|
-
}, /* @__PURE__ */
|
|
1136
|
+
}, /* @__PURE__ */ React5.createElement(ScrollArea2.Viewport, null, children));
|
|
845
1137
|
});
|
|
846
|
-
Viewport.displayName =
|
|
847
|
-
var firstEnabledOption = (ul) => {
|
|
848
|
-
if (!ul) {
|
|
849
|
-
return null;
|
|
850
|
-
}
|
|
851
|
-
return ul.querySelector('[role="option"]:not([aria-disabled="true"])');
|
|
852
|
-
};
|
|
1138
|
+
Viewport.displayName = LISTBOX_VIEWPORT_NAME;
|
|
853
1139
|
var Content2 = composable2((props, forwardedRef) => {
|
|
854
|
-
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
memorizeCurrent: true
|
|
1140
|
+
useListboxContext(LISTBOX_CONTENT_NAME);
|
|
1141
|
+
const navigation = useListNavigation({
|
|
1142
|
+
mode: "listbox"
|
|
858
1143
|
});
|
|
859
1144
|
const { children, ...rest } = props;
|
|
860
|
-
const handleFocus = useCallback4((event) => {
|
|
861
|
-
if (event.target !== event.currentTarget) {
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
const ul = event.currentTarget;
|
|
865
|
-
const selected = ul.querySelector('[role="option"][aria-selected="true"]:not([aria-disabled="true"])');
|
|
866
|
-
const target = selected ?? firstEnabledOption(ul);
|
|
867
|
-
target?.focus();
|
|
868
|
-
}, []);
|
|
869
1145
|
const composed = composableProps2(rest, {
|
|
870
1146
|
classNames: "flex flex-col"
|
|
871
1147
|
});
|
|
872
|
-
return /* @__PURE__ */
|
|
1148
|
+
return /* @__PURE__ */ React5.createElement(List, {
|
|
873
1149
|
variant: "unordered",
|
|
874
1150
|
...composed,
|
|
875
|
-
...
|
|
876
|
-
role: "listbox",
|
|
877
|
-
onFocus: handleFocus,
|
|
1151
|
+
...navigation.containerProps,
|
|
878
1152
|
ref: forwardedRef
|
|
879
1153
|
}, children);
|
|
880
1154
|
});
|
|
881
|
-
Content2.displayName =
|
|
882
|
-
var
|
|
883
|
-
var
|
|
1155
|
+
Content2.displayName = LISTBOX_CONTENT_NAME;
|
|
1156
|
+
var ITEM_BASE = "flex items-center dx-hover dx-selected px-3 py-2 cursor-pointer outline-none";
|
|
1157
|
+
var Item2 = composable2((props, forwardedRef) => {
|
|
884
1158
|
const { id, disabled, onClick, onFocus, children, ...rest } = props;
|
|
885
|
-
const {
|
|
886
|
-
const
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1159
|
+
const { selection } = useListboxContext(LISTBOX_ITEM_NAME);
|
|
1160
|
+
const binding = selection.bind(id, {
|
|
1161
|
+
disabled
|
|
1162
|
+
});
|
|
1163
|
+
const handleClick = useCallback7((event) => {
|
|
1164
|
+
binding.rowProps.onClick(event);
|
|
1165
|
+
if (!disabled) {
|
|
1166
|
+
onClick?.(event);
|
|
890
1167
|
}
|
|
891
|
-
setSelected(id);
|
|
892
|
-
onClick?.(event);
|
|
893
1168
|
}, [
|
|
1169
|
+
binding,
|
|
894
1170
|
disabled,
|
|
895
|
-
id,
|
|
896
|
-
setSelected,
|
|
897
1171
|
onClick
|
|
898
1172
|
]);
|
|
899
|
-
const handleFocus =
|
|
900
|
-
|
|
901
|
-
setSelected(id);
|
|
902
|
-
}
|
|
1173
|
+
const handleFocus = useCallback7((event) => {
|
|
1174
|
+
binding.rowProps.onFocus?.(event);
|
|
903
1175
|
onFocus?.(event);
|
|
904
1176
|
}, [
|
|
905
|
-
|
|
906
|
-
selectedId,
|
|
907
|
-
id,
|
|
908
|
-
setSelected,
|
|
1177
|
+
binding,
|
|
909
1178
|
onFocus
|
|
910
1179
|
]);
|
|
911
1180
|
const composed = composableProps2(rest, {
|
|
912
1181
|
classNames: [
|
|
913
|
-
|
|
1182
|
+
ITEM_BASE,
|
|
914
1183
|
disabled && "opacity-50 cursor-not-allowed"
|
|
915
1184
|
]
|
|
916
1185
|
});
|
|
917
|
-
return /* @__PURE__ */
|
|
1186
|
+
return /* @__PURE__ */ React5.createElement(ListItemProviderHost, {
|
|
1187
|
+
id,
|
|
1188
|
+
selected: binding.selected
|
|
1189
|
+
}, /* @__PURE__ */ React5.createElement(ListItem, {
|
|
918
1190
|
...composed,
|
|
919
1191
|
role: "option",
|
|
920
1192
|
tabIndex: 0,
|
|
921
|
-
"aria-selected":
|
|
1193
|
+
"aria-selected": binding.selected,
|
|
922
1194
|
"aria-disabled": disabled || void 0,
|
|
923
1195
|
onClick: handleClick,
|
|
924
1196
|
onFocus: handleFocus,
|
|
925
1197
|
ref: forwardedRef
|
|
926
|
-
}, children);
|
|
1198
|
+
}, children));
|
|
927
1199
|
});
|
|
928
|
-
|
|
929
|
-
var
|
|
930
|
-
|
|
931
|
-
|
|
1200
|
+
Item2.displayName = LISTBOX_ITEM_NAME;
|
|
1201
|
+
var ListItemProviderHost = ({ id, selected, children }) => /* @__PURE__ */ React5.createElement(ListboxItemProvider, {
|
|
1202
|
+
id,
|
|
1203
|
+
selected
|
|
1204
|
+
}, children);
|
|
1205
|
+
var ItemLabel = /* @__PURE__ */ forwardRef3(({ classNames, children, ...rest }, forwardedRef) => /* @__PURE__ */ React5.createElement("span", {
|
|
1206
|
+
...rest,
|
|
1207
|
+
className: mx5("grow truncate", classNames),
|
|
1208
|
+
ref: forwardedRef
|
|
1209
|
+
}, children));
|
|
1210
|
+
ItemLabel.displayName = LISTBOX_ITEM_LABEL_NAME;
|
|
1211
|
+
var Indicator = /* @__PURE__ */ forwardRef3(({ classNames, ...rootProps }, forwardedRef) => {
|
|
1212
|
+
const { selected } = useListboxItemContext(LISTBOX_INDICATOR_NAME);
|
|
1213
|
+
return /* @__PURE__ */ React5.createElement(Icon3, {
|
|
1214
|
+
icon: "ph--check--regular",
|
|
1215
|
+
...rootProps,
|
|
1216
|
+
classNames: mx5(!selected && "invisible", classNames),
|
|
1217
|
+
ref: forwardedRef
|
|
1218
|
+
});
|
|
1219
|
+
});
|
|
1220
|
+
Indicator.displayName = LISTBOX_INDICATOR_NAME;
|
|
1221
|
+
var useListboxSelection = (id) => {
|
|
1222
|
+
const { selection } = useListboxContext("useListboxSelection");
|
|
1223
|
+
return selection.bind(id).selected;
|
|
932
1224
|
};
|
|
933
|
-
var
|
|
1225
|
+
var Listbox = {
|
|
934
1226
|
Root: Root2,
|
|
935
1227
|
Viewport,
|
|
936
|
-
Content: Content2
|
|
1228
|
+
Content: Content2,
|
|
1229
|
+
Item: Item2,
|
|
1230
|
+
ItemLabel,
|
|
1231
|
+
Indicator
|
|
937
1232
|
};
|
|
938
1233
|
|
|
939
|
-
// src/components/
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
var
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1234
|
+
// src/components/OrderedList/OrderedListItem.tsx
|
|
1235
|
+
import { createContext as createContext7 } from "@radix-ui/react-context";
|
|
1236
|
+
import React7, { useCallback as useCallback8 } from "react";
|
|
1237
|
+
import { IconBlock, IconButton, ListItem as NaturalListItem, ToggleIconButton, useTranslation } from "@dxos/react-ui";
|
|
1238
|
+
import { mx as mx7, osTranslations } from "@dxos/ui-theme";
|
|
1239
|
+
|
|
1240
|
+
// src/components/OrderedList/OrderedListRoot.tsx
|
|
1241
|
+
import { createContext as createContext6 } from "@radix-ui/react-context";
|
|
1242
|
+
import React6, { useMemo as useMemo6 } from "react";
|
|
1243
|
+
import { ScrollArea as ScrollArea3, composable as composable3, composableProps as composableProps3 } from "@dxos/react-ui";
|
|
1244
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
1245
|
+
var ORDERED_LIST_NAME = "OrderedList";
|
|
1246
|
+
var [OrderedListProvider, useOrderedListContext] = createContext6(ORDERED_LIST_NAME);
|
|
1247
|
+
var defaultGetId2 = (item) => item?.id;
|
|
1248
|
+
var noopMove = () => {
|
|
1249
|
+
};
|
|
1250
|
+
var OrderedListRoot = ({ items, getId = defaultGetId2, onMove = noopMove, readonly, expandedId, defaultExpandedId, onExpandedChange, children }) => {
|
|
1251
|
+
const { controller, active } = useReorderList({
|
|
1252
|
+
items,
|
|
1253
|
+
getId,
|
|
1254
|
+
onMove,
|
|
1255
|
+
readonly
|
|
1256
|
+
});
|
|
1257
|
+
const disclosure = useListDisclosure({
|
|
1258
|
+
mode: "single",
|
|
1259
|
+
value: expandedId,
|
|
1260
|
+
defaultValue: defaultExpandedId,
|
|
1261
|
+
onValueChange: (next) => onExpandedChange?.(next)
|
|
1262
|
+
});
|
|
1263
|
+
const navigation = useListNavigation({
|
|
1264
|
+
mode: "list"
|
|
1265
|
+
});
|
|
1266
|
+
const context = useMemo6(() => ({
|
|
1267
|
+
reorder: controller,
|
|
1268
|
+
disclosure,
|
|
1269
|
+
navigation,
|
|
1270
|
+
readonly,
|
|
1271
|
+
active,
|
|
1272
|
+
getId
|
|
1273
|
+
}), [
|
|
1274
|
+
controller,
|
|
1275
|
+
disclosure,
|
|
1276
|
+
navigation,
|
|
1277
|
+
readonly,
|
|
1278
|
+
active,
|
|
1279
|
+
getId
|
|
1280
|
+
]);
|
|
1281
|
+
return /* @__PURE__ */ React6.createElement(OrderedListProvider, context, children({
|
|
1282
|
+
items
|
|
1283
|
+
}));
|
|
1284
|
+
};
|
|
1285
|
+
var OrderedListContent = ({ classNames, children }) => {
|
|
1286
|
+
const { navigation } = useOrderedListContext("OrderedList.Content");
|
|
1287
|
+
return /* @__PURE__ */ React6.createElement("div", {
|
|
1288
|
+
...navigation.containerProps,
|
|
1289
|
+
className: mx6("flex flex-col", classNames)
|
|
1290
|
+
}, children);
|
|
1291
|
+
};
|
|
1292
|
+
var OrderedListViewport = composable3((props, forwardedRef) => {
|
|
1293
|
+
const { thin, padding, centered, children, ...rest } = props;
|
|
1294
|
+
const autoScrollRef = useReorderAutoScroll();
|
|
1295
|
+
return /* @__PURE__ */ React6.createElement(ScrollArea3.Root, {
|
|
1296
|
+
...composableProps3(rest, {
|
|
1297
|
+
classNames: "dx-container"
|
|
1298
|
+
}),
|
|
1299
|
+
thin,
|
|
1300
|
+
padding,
|
|
1301
|
+
centered,
|
|
1302
|
+
orientation: "vertical",
|
|
970
1303
|
ref: forwardedRef
|
|
971
|
-
}, /* @__PURE__ */
|
|
972
|
-
|
|
1304
|
+
}, /* @__PURE__ */ React6.createElement(ScrollArea3.Viewport, {
|
|
1305
|
+
ref: autoScrollRef
|
|
973
1306
|
}, children));
|
|
974
1307
|
});
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
},
|
|
1308
|
+
OrderedListViewport.displayName = "OrderedList.Viewport";
|
|
1309
|
+
|
|
1310
|
+
// src/components/OrderedList/OrderedListItem.tsx
|
|
1311
|
+
var ORDERED_LIST_ITEM_NAME = "OrderedListItem";
|
|
1312
|
+
var [OrderedListItemProvider, useOrderedListItemContext] = createContext7(ORDERED_LIST_ITEM_NAME);
|
|
1313
|
+
var OrderedListItem = ({ id, canDrag = true, hover = false, selected, onClick, classNames, style, children }) => {
|
|
1314
|
+
const { reorder, disclosure, navigation } = useOrderedListContext(ORDERED_LIST_ITEM_NAME);
|
|
1315
|
+
const { rowRef, handleRef, closestEdge, state } = useReorderItem(reorder, id);
|
|
1316
|
+
const { expanded, toggle, triggerProps, panelProps } = disclosure.bind(id);
|
|
1317
|
+
return /* @__PURE__ */ React7.createElement(OrderedListItemProvider, {
|
|
1318
|
+
id,
|
|
1319
|
+
expanded,
|
|
1320
|
+
toggle,
|
|
1321
|
+
canDrag,
|
|
1322
|
+
handleRef,
|
|
1323
|
+
triggerProps,
|
|
1324
|
+
panelProps
|
|
1325
|
+
}, /* @__PURE__ */ React7.createElement("div", {
|
|
1326
|
+
ref: rowRef,
|
|
1327
|
+
...navigation.itemProps(),
|
|
1328
|
+
style,
|
|
1329
|
+
"aria-current": selected || void 0,
|
|
1330
|
+
onClick,
|
|
1331
|
+
className: mx7("relative dx-current", hover && "dx-hover", state.type === "dragging" && "opacity-50", classNames)
|
|
1332
|
+
}, children, closestEdge && /* @__PURE__ */ React7.createElement(NaturalListItem.DropIndicator, {
|
|
1333
|
+
edge: closestEdge
|
|
1334
|
+
})));
|
|
983
1335
|
};
|
|
984
|
-
var
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1336
|
+
var OrderedListDragHandle = () => {
|
|
1337
|
+
const { readonly } = useOrderedListContext("OrderedListDragHandle");
|
|
1338
|
+
const { canDrag, handleRef } = useOrderedListItemContext("OrderedListDragHandle");
|
|
1339
|
+
const { t } = useTranslation(osTranslations);
|
|
1340
|
+
const disabled = readonly || !canDrag;
|
|
1341
|
+
return /* @__PURE__ */ React7.createElement(IconButton, {
|
|
1342
|
+
variant: "ghost",
|
|
1343
|
+
disabled,
|
|
1344
|
+
noTooltip: true,
|
|
1345
|
+
icon: "ph--dots-six-vertical--regular",
|
|
1346
|
+
iconOnly: true,
|
|
1347
|
+
label: t("drag-handle.label"),
|
|
1348
|
+
ref: handleRef
|
|
1349
|
+
});
|
|
1350
|
+
};
|
|
1351
|
+
var OrderedListTitle = ({ classNames, children, onClick, ...props }) => {
|
|
1352
|
+
const { triggerProps } = useOrderedListItemContext("OrderedListTitle");
|
|
1353
|
+
const handleClick = useCallback8((event) => {
|
|
1354
|
+
onClick?.(event);
|
|
1355
|
+
triggerProps.onClick(event);
|
|
1356
|
+
}, [
|
|
1357
|
+
onClick,
|
|
1358
|
+
triggerProps
|
|
1359
|
+
]);
|
|
1360
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1361
|
+
...props,
|
|
1362
|
+
// The title row is also the disclosure trigger, so it carries the trigger's
|
|
1363
|
+
// `id` + `aria-expanded` + `aria-controls` for assistive tech.
|
|
1364
|
+
id: triggerProps.id,
|
|
1365
|
+
"aria-expanded": triggerProps["aria-expanded"],
|
|
1366
|
+
"aria-controls": triggerProps["aria-controls"],
|
|
1367
|
+
className: mx7("flex grow items-center truncate cursor-pointer", classNames),
|
|
1368
|
+
onClick: handleClick
|
|
989
1369
|
}, children);
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1370
|
+
};
|
|
1371
|
+
var OrderedListIconButton = ({ autoHide = false, disabled, classNames, ...props }) => /* @__PURE__ */ React7.createElement(IconBlock, null, /* @__PURE__ */ React7.createElement(IconButton, {
|
|
1372
|
+
...props,
|
|
1373
|
+
variant: "ghost",
|
|
1374
|
+
iconOnly: true,
|
|
1375
|
+
disabled,
|
|
1376
|
+
classNames: [
|
|
1377
|
+
classNames,
|
|
1378
|
+
autoHide && disabled && "hidden"
|
|
1379
|
+
]
|
|
1380
|
+
}));
|
|
1381
|
+
var OrderedListDeleteButton = ({ autoHide = false, icon = "ph--x--regular", label, disabled, classNames, ...props }) => {
|
|
1382
|
+
const { t } = useTranslation(osTranslations);
|
|
1383
|
+
return /* @__PURE__ */ React7.createElement(OrderedListIconButton, {
|
|
1384
|
+
...props,
|
|
1385
|
+
autoHide,
|
|
1386
|
+
disabled,
|
|
1387
|
+
icon,
|
|
1388
|
+
label: label ?? t("delete.label"),
|
|
1389
|
+
classNames
|
|
1000
1390
|
});
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1391
|
+
};
|
|
1392
|
+
var OrderedListExpandCaret = ({ onClick, ...props }) => {
|
|
1393
|
+
const { t } = useTranslation(osTranslations);
|
|
1394
|
+
const { expanded, toggle, triggerProps } = useOrderedListItemContext("OrderedListExpandCaret");
|
|
1395
|
+
const handleClick = useCallback8((event) => {
|
|
1396
|
+
toggle();
|
|
1397
|
+
onClick?.(event);
|
|
1398
|
+
}, [
|
|
1399
|
+
toggle,
|
|
1400
|
+
onClick
|
|
1401
|
+
]);
|
|
1402
|
+
return /* @__PURE__ */ React7.createElement(ToggleIconButton, {
|
|
1403
|
+
iconOnly: true,
|
|
1404
|
+
variant: "ghost",
|
|
1405
|
+
active: expanded,
|
|
1406
|
+
icon: "ph--caret-right--regular",
|
|
1407
|
+
label: t("toggle-expand.label"),
|
|
1408
|
+
// Disclosure semantics are carried here for AT users that interact with the caret
|
|
1409
|
+
// rather than the title.
|
|
1410
|
+
"aria-expanded": triggerProps["aria-expanded"],
|
|
1411
|
+
"aria-controls": triggerProps["aria-controls"],
|
|
1412
|
+
onClick: handleClick,
|
|
1413
|
+
...props
|
|
1414
|
+
});
|
|
1415
|
+
};
|
|
1416
|
+
var OrderedListDetailItem = ({ id, item, canDrag, title, titleClassNames, actions, trailing, expandable = true, classNames, children }) => {
|
|
1417
|
+
const grid = useListGrid({
|
|
1418
|
+
trailing: !!trailing
|
|
1419
|
+
});
|
|
1420
|
+
return /* @__PURE__ */ React7.createElement(OrderedListItem, {
|
|
1421
|
+
id,
|
|
1422
|
+
item,
|
|
1423
|
+
canDrag,
|
|
1424
|
+
// The grid template is inline so the row's three slots (handle / card / trailing)
|
|
1425
|
+
// land in fixed-width tracks that share a baseline with the title row inside the card.
|
|
1426
|
+
// See useListGrid for the rationale.
|
|
1427
|
+
style: grid.rowProps.style,
|
|
1428
|
+
classNames: mx7(grid.rowProps.className, "pb-1", classNames)
|
|
1429
|
+
}, /* @__PURE__ */ React7.createElement(OrderedListDragHandle, null), /* @__PURE__ */ React7.createElement("div", {
|
|
1430
|
+
className: "flex flex-col ring-1 ring-subdued-separator rounded-sm overflow-hidden"
|
|
1431
|
+
}, /* @__PURE__ */ React7.createElement("div", {
|
|
1432
|
+
className: "flex items-center min-h-[var(--dx-rail-item)]"
|
|
1433
|
+
}, expandable ? /* @__PURE__ */ React7.createElement(OrderedListTitle, {
|
|
1434
|
+
classNames: mx7("px-2", titleClassNames)
|
|
1435
|
+
}, title) : (
|
|
1436
|
+
// When the row is not expandable, render a plain (non-toggling) title so a click
|
|
1437
|
+
// doesn't mutate hidden disclosure state. Mirrors `OrderedListTitle`'s structure
|
|
1438
|
+
// minus the trigger plumbing.
|
|
1439
|
+
/* @__PURE__ */ React7.createElement("div", {
|
|
1440
|
+
className: mx7("flex grow items-center truncate px-2", titleClassNames)
|
|
1441
|
+
}, title)
|
|
1442
|
+
), actions, expandable && /* @__PURE__ */ React7.createElement(OrderedListExpandCaret, null)), expandable && /* @__PURE__ */ React7.createElement(DetailPanel, null, children)), trailing);
|
|
1443
|
+
};
|
|
1444
|
+
var DetailPanel = ({ children }) => {
|
|
1445
|
+
const { expanded, panelProps } = useOrderedListItemContext("OrderedListDetailItem.Panel");
|
|
1446
|
+
if (!expanded || !children) {
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1450
|
+
...panelProps,
|
|
1451
|
+
className: "px-2 pb-2"
|
|
1452
|
+
}, children);
|
|
1453
|
+
};
|
|
1454
|
+
|
|
1455
|
+
// src/components/OrderedList/OrderedList.tsx
|
|
1456
|
+
var OrderedList = {
|
|
1457
|
+
Root: OrderedListRoot,
|
|
1458
|
+
Viewport: OrderedListViewport,
|
|
1459
|
+
Content: OrderedListContent,
|
|
1460
|
+
Item: OrderedListItem,
|
|
1461
|
+
DetailItem: OrderedListDetailItem,
|
|
1462
|
+
DragHandle: OrderedListDragHandle,
|
|
1463
|
+
Title: OrderedListTitle,
|
|
1464
|
+
IconButton: OrderedListIconButton,
|
|
1465
|
+
DeleteButton: OrderedListDeleteButton,
|
|
1466
|
+
ExpandCaret: OrderedListExpandCaret
|
|
1008
1467
|
};
|
|
1009
1468
|
|
|
1010
1469
|
// src/components/Tree/Tree.tsx
|
|
1011
1470
|
import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
|
|
1012
|
-
import
|
|
1471
|
+
import React11, { useMemo as useMemo8 } from "react";
|
|
1013
1472
|
import { Treegrid as Treegrid2 } from "@dxos/react-ui";
|
|
1014
1473
|
|
|
1015
1474
|
// src/components/Tree/TreeContext.tsx
|
|
1016
|
-
import { createContext as
|
|
1475
|
+
import { createContext as createContext8, useContext } from "react";
|
|
1017
1476
|
import { raise } from "@dxos/debug";
|
|
1018
|
-
var TreeContext = /* @__PURE__ */
|
|
1477
|
+
var TreeContext = /* @__PURE__ */ createContext8(null);
|
|
1019
1478
|
var TreeProvider = TreeContext.Provider;
|
|
1020
1479
|
var useTree = () => useContext(TreeContext) ?? raise(new Error("TreeContext not found"));
|
|
1021
1480
|
|
|
@@ -1025,10 +1484,10 @@ import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
|
1025
1484
|
import { draggable as draggable2, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
1026
1485
|
import { useAtomValue } from "@effect-atom/atom-react";
|
|
1027
1486
|
import * as Schema from "effect/Schema";
|
|
1028
|
-
import
|
|
1029
|
-
import { invariant
|
|
1487
|
+
import React10, { memo as memo3, useCallback as useCallback10, useEffect as useEffect5, useMemo as useMemo7, useRef as useRef5, useState as useState5 } from "react";
|
|
1488
|
+
import { invariant } from "@dxos/invariant";
|
|
1030
1489
|
import { TreeItem as NaturalTreeItem, Treegrid, TREEGRID_PARENT_OF_SEPARATOR } from "@dxos/react-ui";
|
|
1031
|
-
import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as
|
|
1490
|
+
import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx8 } from "@dxos/ui-theme";
|
|
1032
1491
|
|
|
1033
1492
|
// src/components/Tree/helpers.ts
|
|
1034
1493
|
var DEFAULT_INDENTATION = 8;
|
|
@@ -1037,19 +1496,18 @@ var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
|
|
|
1037
1496
|
});
|
|
1038
1497
|
|
|
1039
1498
|
// src/components/Tree/TreeItemHeading.tsx
|
|
1040
|
-
import
|
|
1041
|
-
import { Button as Button2, Icon as Icon4, Tag, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
1042
|
-
import { TextTooltip } from "@dxos/react-ui-text-tooltip";
|
|
1499
|
+
import React8, { forwardRef as forwardRef4, memo, useCallback as useCallback9 } from "react";
|
|
1500
|
+
import { Button as Button2, Icon as Icon4, Tag, TextTooltip, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
1043
1501
|
import { getStyles } from "@dxos/ui-theme";
|
|
1044
1502
|
var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef4(({ label, className, icon, iconHue, disabled, current, count, modifiedCount, onSelect }, forwardedRef) => {
|
|
1045
1503
|
const { t } = useTranslation2();
|
|
1046
1504
|
const styles = iconHue ? getStyles(iconHue) : void 0;
|
|
1047
|
-
const handleSelect =
|
|
1505
|
+
const handleSelect = useCallback9((event) => {
|
|
1048
1506
|
onSelect?.(event.altKey);
|
|
1049
1507
|
}, [
|
|
1050
1508
|
onSelect
|
|
1051
1509
|
]);
|
|
1052
|
-
const handleButtonKeydown =
|
|
1510
|
+
const handleButtonKeydown = useCallback9((event) => {
|
|
1053
1511
|
if (event.key === " " || event.key === "Enter") {
|
|
1054
1512
|
event.preventDefault();
|
|
1055
1513
|
event.stopPropagation();
|
|
@@ -1058,14 +1516,14 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef4(({ label,
|
|
|
1058
1516
|
}, [
|
|
1059
1517
|
onSelect
|
|
1060
1518
|
]);
|
|
1061
|
-
return /* @__PURE__ */
|
|
1519
|
+
return /* @__PURE__ */ React8.createElement(TextTooltip, {
|
|
1062
1520
|
text: toLocalizedString(label, t),
|
|
1063
1521
|
side: "bottom",
|
|
1064
1522
|
truncateQuery: "span[data-tooltip]",
|
|
1065
1523
|
onlyWhenTruncating: true,
|
|
1066
1524
|
asChild: true,
|
|
1067
1525
|
ref: forwardedRef
|
|
1068
|
-
}, /* @__PURE__ */
|
|
1526
|
+
}, /* @__PURE__ */ React8.createElement(Button2, {
|
|
1069
1527
|
"data-testid": "treeItem.heading",
|
|
1070
1528
|
variant: "ghost",
|
|
1071
1529
|
classNames: [
|
|
@@ -1079,30 +1537,30 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef4(({ label,
|
|
|
1079
1537
|
...current && {
|
|
1080
1538
|
"aria-current": "location"
|
|
1081
1539
|
}
|
|
1082
|
-
}, icon && /* @__PURE__ */
|
|
1540
|
+
}, icon && /* @__PURE__ */ React8.createElement(Icon4, {
|
|
1083
1541
|
size: 5,
|
|
1084
1542
|
icon: icon ?? "ph--circle-dashed--regular",
|
|
1085
1543
|
classNames: [
|
|
1086
1544
|
"my-1",
|
|
1087
1545
|
styles?.text
|
|
1088
1546
|
]
|
|
1089
|
-
}), /* @__PURE__ */
|
|
1547
|
+
}), /* @__PURE__ */ React8.createElement("span", {
|
|
1090
1548
|
className: "min-w-0 truncate text-start font-normal",
|
|
1091
1549
|
"data-tooltip": true
|
|
1092
|
-
}, toLocalizedString(label, t)), /* @__PURE__ */
|
|
1550
|
+
}, toLocalizedString(label, t)), /* @__PURE__ */ React8.createElement(CountBadge, {
|
|
1093
1551
|
count,
|
|
1094
1552
|
modifiedCount
|
|
1095
1553
|
})));
|
|
1096
1554
|
}));
|
|
1097
1555
|
var CountBadge = ({ count, modifiedCount }) => {
|
|
1098
1556
|
if (typeof modifiedCount === "number" && modifiedCount > 0) {
|
|
1099
|
-
return /* @__PURE__ */
|
|
1557
|
+
return /* @__PURE__ */ React8.createElement(Tag, {
|
|
1100
1558
|
palette: "rose",
|
|
1101
1559
|
classNames: "shrink-0 text-center [min-inline-size:1.5rem] tabular-nums"
|
|
1102
1560
|
}, modifiedCount);
|
|
1103
1561
|
}
|
|
1104
1562
|
if (typeof count === "number") {
|
|
1105
|
-
return /* @__PURE__ */
|
|
1563
|
+
return /* @__PURE__ */ React8.createElement(Tag, {
|
|
1106
1564
|
palette: "neutral",
|
|
1107
1565
|
classNames: "shrink-0 text-center [min-inline-size:1.5rem] tabular-nums"
|
|
1108
1566
|
}, count);
|
|
@@ -1111,10 +1569,10 @@ var CountBadge = ({ count, modifiedCount }) => {
|
|
|
1111
1569
|
};
|
|
1112
1570
|
|
|
1113
1571
|
// src/components/Tree/TreeItemToggle.tsx
|
|
1114
|
-
import
|
|
1572
|
+
import React9, { forwardRef as forwardRef5, memo as memo2 } from "react";
|
|
1115
1573
|
import { IconButton as IconButton2 } from "@dxos/react-ui";
|
|
1116
1574
|
var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef5(({ classNames, open, isBranch, hidden, ...props }, forwardedRef) => {
|
|
1117
|
-
return /* @__PURE__ */
|
|
1575
|
+
return /* @__PURE__ */ React9.createElement(IconButton2, {
|
|
1118
1576
|
ref: forwardedRef,
|
|
1119
1577
|
"data-testid": "treeItem.toggle",
|
|
1120
1578
|
"aria-expanded": open,
|
|
@@ -1138,7 +1596,7 @@ var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef5(({ classN
|
|
|
1138
1596
|
}));
|
|
1139
1597
|
|
|
1140
1598
|
// src/components/Tree/TreeItem.tsx
|
|
1141
|
-
var
|
|
1599
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-list/src/components/Tree/TreeItem.tsx";
|
|
1142
1600
|
var hoverableDescriptionIcons = "[--icons-color:inherit] hover-hover:[--icons-color:var(--description-text)] hover-hover:hover:[--icons-color:inherit] focus-within:[--icons-color:inherit]";
|
|
1143
1601
|
var TreeDataSchema = Schema.Struct({
|
|
1144
1602
|
id: Schema.String,
|
|
@@ -1147,15 +1605,15 @@ var TreeDataSchema = Schema.Struct({
|
|
|
1147
1605
|
});
|
|
1148
1606
|
var isTreeData = (data) => Schema.is(TreeDataSchema)(data);
|
|
1149
1607
|
var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: draggableProp, renderColumns: Columns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
|
|
1150
|
-
const rowRef =
|
|
1151
|
-
const buttonRef =
|
|
1152
|
-
const openRef =
|
|
1153
|
-
const cancelExpandRef =
|
|
1154
|
-
const [_state, setState] =
|
|
1155
|
-
const [instruction, setInstruction] =
|
|
1156
|
-
const [menuOpen, setMenuOpen] =
|
|
1608
|
+
const rowRef = useRef5(null);
|
|
1609
|
+
const buttonRef = useRef5(null);
|
|
1610
|
+
const openRef = useRef5(false);
|
|
1611
|
+
const cancelExpandRef = useRef5(null);
|
|
1612
|
+
const [_state, setState] = useState5("idle");
|
|
1613
|
+
const [instruction, setInstruction] = useState5(null);
|
|
1614
|
+
const [menuOpen, setMenuOpen] = useState5(false);
|
|
1157
1615
|
const { itemProps: itemPropsAtom, childIds: childIdsAtom, itemOpen: itemOpenAtom, itemCurrent: itemCurrentAtom } = useTree();
|
|
1158
|
-
const path =
|
|
1616
|
+
const path = useMemo7(() => [
|
|
1159
1617
|
...pathProp,
|
|
1160
1618
|
item.id
|
|
1161
1619
|
], [
|
|
@@ -1179,7 +1637,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1179
1637
|
item
|
|
1180
1638
|
};
|
|
1181
1639
|
const shouldSeedNativeDragData = typeof document !== "undefined" && document.body.hasAttribute("data-platform");
|
|
1182
|
-
const cancelExpand =
|
|
1640
|
+
const cancelExpand = useCallback10(() => {
|
|
1183
1641
|
if (cancelExpandRef.current) {
|
|
1184
1642
|
clearTimeout(cancelExpandRef.current);
|
|
1185
1643
|
cancelExpandRef.current = null;
|
|
@@ -1188,11 +1646,11 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1188
1646
|
const isItemDraggable = draggableProp && itemDraggable !== false;
|
|
1189
1647
|
const isItemDroppable = itemDroppable !== false;
|
|
1190
1648
|
const nativeDragText = id;
|
|
1191
|
-
|
|
1649
|
+
useEffect5(() => {
|
|
1192
1650
|
if (!draggableProp) {
|
|
1193
1651
|
return;
|
|
1194
1652
|
}
|
|
1195
|
-
|
|
1653
|
+
invariant(buttonRef.current, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 70, S: void 0, A: ["buttonRef.current", ""] });
|
|
1196
1654
|
const makeDraggable = () => draggable2({
|
|
1197
1655
|
element: buttonRef.current,
|
|
1198
1656
|
getInitialData: () => data,
|
|
@@ -1307,10 +1765,10 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1307
1765
|
blockInstruction,
|
|
1308
1766
|
canDrop
|
|
1309
1767
|
]);
|
|
1310
|
-
|
|
1768
|
+
useEffect5(() => () => cancelExpand(), [
|
|
1311
1769
|
cancelExpand
|
|
1312
1770
|
]);
|
|
1313
|
-
const handleOpenToggle =
|
|
1771
|
+
const handleOpenToggle = useCallback10(() => onOpenChange?.({
|
|
1314
1772
|
item,
|
|
1315
1773
|
path,
|
|
1316
1774
|
open: !open
|
|
@@ -1320,7 +1778,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1320
1778
|
path,
|
|
1321
1779
|
open
|
|
1322
1780
|
]);
|
|
1323
|
-
const handleSelect =
|
|
1781
|
+
const handleSelect = useCallback10((option = false) => {
|
|
1324
1782
|
if (isBranch && (option || current)) {
|
|
1325
1783
|
handleOpenToggle();
|
|
1326
1784
|
} else if (canSelectItem) {
|
|
@@ -1345,7 +1803,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1345
1803
|
handleOpenToggle,
|
|
1346
1804
|
onSelect
|
|
1347
1805
|
]);
|
|
1348
|
-
const handleKeyDown =
|
|
1806
|
+
const handleKeyDown = useCallback10((event) => {
|
|
1349
1807
|
switch (event.key) {
|
|
1350
1808
|
case "ArrowRight":
|
|
1351
1809
|
case "ArrowLeft":
|
|
@@ -1358,7 +1816,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1358
1816
|
handleOpenToggle,
|
|
1359
1817
|
handleSelect
|
|
1360
1818
|
]);
|
|
1361
|
-
const handleItemHover =
|
|
1819
|
+
const handleItemHover = useCallback10(() => {
|
|
1362
1820
|
onItemHover?.({
|
|
1363
1821
|
item
|
|
1364
1822
|
});
|
|
@@ -1366,7 +1824,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1366
1824
|
onItemHover,
|
|
1367
1825
|
item
|
|
1368
1826
|
]);
|
|
1369
|
-
const handleContextMenu =
|
|
1827
|
+
const handleContextMenu = useCallback10((event) => {
|
|
1370
1828
|
event.preventDefault();
|
|
1371
1829
|
setMenuOpen(true);
|
|
1372
1830
|
}, [
|
|
@@ -1382,7 +1840,7 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1382
1840
|
onOpenChange,
|
|
1383
1841
|
onSelect
|
|
1384
1842
|
};
|
|
1385
|
-
return /* @__PURE__ */
|
|
1843
|
+
return /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement(Treegrid.Row, {
|
|
1386
1844
|
ref: rowRef,
|
|
1387
1845
|
key: id,
|
|
1388
1846
|
id,
|
|
@@ -1394,20 +1852,31 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1394
1852
|
// without alerting the user (except for in the correct link element). See also:
|
|
1395
1853
|
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current#description
|
|
1396
1854
|
"aria-current": current ? "" : void 0,
|
|
1397
|
-
classNames:
|
|
1855
|
+
classNames: mx8(
|
|
1856
|
+
"grid grid-cols-subgrid col-[tree-row] mt-0.5 is-current:bg-current-surface",
|
|
1857
|
+
// Highlight the row while a descendant marks an open popover anchor (e.g. inline rename).
|
|
1858
|
+
"has-[[data-popover-anchor]]:bg-current-surface",
|
|
1859
|
+
hoverableControls,
|
|
1860
|
+
hoverableFocusedKeyboardControls,
|
|
1861
|
+
hoverableFocusedWithinControls,
|
|
1862
|
+
hoverableDescriptionIcons,
|
|
1863
|
+
ghostFocusWithin,
|
|
1864
|
+
ghostHover,
|
|
1865
|
+
className
|
|
1866
|
+
),
|
|
1398
1867
|
onKeyDown: handleKeyDown,
|
|
1399
1868
|
onMouseEnter: handleItemHover,
|
|
1400
1869
|
onContextMenu: handleContextMenu
|
|
1401
|
-
}, /* @__PURE__ */
|
|
1870
|
+
}, /* @__PURE__ */ React10.createElement("div", {
|
|
1402
1871
|
className: "indent relative grid grid-cols-subgrid col-[tree-row]",
|
|
1403
1872
|
style: paddingIndentation(level)
|
|
1404
|
-
}, /* @__PURE__ */
|
|
1873
|
+
}, /* @__PURE__ */ React10.createElement(Treegrid.Cell, {
|
|
1405
1874
|
classNames: "flex items-center"
|
|
1406
|
-
}, /* @__PURE__ */
|
|
1875
|
+
}, /* @__PURE__ */ React10.createElement(TreeItemToggle, {
|
|
1407
1876
|
isBranch,
|
|
1408
1877
|
open,
|
|
1409
1878
|
onClick: handleOpenToggle
|
|
1410
|
-
}), /* @__PURE__ */
|
|
1879
|
+
}), /* @__PURE__ */ React10.createElement(TreeItemHeading, {
|
|
1411
1880
|
disabled,
|
|
1412
1881
|
current,
|
|
1413
1882
|
label,
|
|
@@ -1418,16 +1887,16 @@ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: dra
|
|
|
1418
1887
|
modifiedCount,
|
|
1419
1888
|
onSelect: handleSelect,
|
|
1420
1889
|
ref: buttonRef
|
|
1421
|
-
})), Columns && /* @__PURE__ */
|
|
1890
|
+
})), Columns && /* @__PURE__ */ React10.createElement(Columns, {
|
|
1422
1891
|
item,
|
|
1423
1892
|
path,
|
|
1424
1893
|
open,
|
|
1425
1894
|
menuOpen,
|
|
1426
1895
|
setMenuOpen
|
|
1427
|
-
}), instruction && /* @__PURE__ */
|
|
1896
|
+
}), instruction && /* @__PURE__ */ React10.createElement(NaturalTreeItem.DropIndicator, {
|
|
1428
1897
|
instruction,
|
|
1429
1898
|
gap: 2
|
|
1430
|
-
}))), open && childIds.map((childId, index) => /* @__PURE__ */
|
|
1899
|
+
}))), open && childIds.map((childId, index) => /* @__PURE__ */ React10.createElement(TreeItemById, {
|
|
1431
1900
|
key: childId,
|
|
1432
1901
|
id: childId,
|
|
1433
1902
|
path,
|
|
@@ -1442,7 +1911,7 @@ var RawTreeItemById = ({ id, ...props }) => {
|
|
|
1442
1911
|
if (!item) {
|
|
1443
1912
|
return null;
|
|
1444
1913
|
}
|
|
1445
|
-
return /* @__PURE__ */
|
|
1914
|
+
return /* @__PURE__ */ React10.createElement(TreeItem, {
|
|
1446
1915
|
item,
|
|
1447
1916
|
...props
|
|
1448
1917
|
});
|
|
@@ -1452,7 +1921,7 @@ var TreeItemById = /* @__PURE__ */ memo3(RawTreeItemById);
|
|
|
1452
1921
|
// src/components/Tree/Tree.tsx
|
|
1453
1922
|
var Tree = ({ classNames, model, rootId, path, id, draggable: draggable3 = false, gridTemplateColumns = "[tree-row-start] minmax(0, 1fr) min-content [tree-row-end]", levelOffset, renderColumns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
|
|
1454
1923
|
const childIds = useAtomValue2(model.childIds(rootId));
|
|
1455
|
-
const treePath =
|
|
1924
|
+
const treePath = useMemo8(() => path ? [
|
|
1456
1925
|
...path,
|
|
1457
1926
|
id
|
|
1458
1927
|
] : [
|
|
@@ -1473,12 +1942,12 @@ var Tree = ({ classNames, model, rootId, path, id, draggable: draggable3 = false
|
|
|
1473
1942
|
onSelect,
|
|
1474
1943
|
onItemHover
|
|
1475
1944
|
};
|
|
1476
|
-
return /* @__PURE__ */
|
|
1945
|
+
return /* @__PURE__ */ React11.createElement(Treegrid2.Root, {
|
|
1477
1946
|
gridTemplateColumns,
|
|
1478
1947
|
classNames
|
|
1479
|
-
}, /* @__PURE__ */
|
|
1948
|
+
}, /* @__PURE__ */ React11.createElement(TreeProvider, {
|
|
1480
1949
|
value: model
|
|
1481
|
-
}, childIds.map((childId, index) => /* @__PURE__ */
|
|
1950
|
+
}, childIds.map((childId, index) => /* @__PURE__ */ React11.createElement(TreeItemById, {
|
|
1482
1951
|
key: childId,
|
|
1483
1952
|
id: childId,
|
|
1484
1953
|
last: index === childIds.length - 1,
|
|
@@ -1505,25 +1974,28 @@ export {
|
|
|
1505
1974
|
Accordion,
|
|
1506
1975
|
Combobox,
|
|
1507
1976
|
DEFAULT_INDENTATION,
|
|
1508
|
-
List,
|
|
1509
1977
|
Listbox,
|
|
1978
|
+
OrderedList,
|
|
1510
1979
|
Path,
|
|
1511
1980
|
Picker,
|
|
1512
|
-
Row,
|
|
1513
|
-
RowList,
|
|
1514
1981
|
Tree,
|
|
1515
1982
|
TreeDataSchema,
|
|
1516
1983
|
TreeItem,
|
|
1517
1984
|
TreeItemById,
|
|
1518
1985
|
TreeItemToggle,
|
|
1519
1986
|
TreeProvider,
|
|
1520
|
-
createListboxScope,
|
|
1521
|
-
createRowListScope,
|
|
1522
1987
|
isTreeData,
|
|
1523
1988
|
paddingIndentation,
|
|
1989
|
+
useListDisclosure,
|
|
1990
|
+
useListGrid,
|
|
1991
|
+
useListNavigation,
|
|
1992
|
+
useListSelection,
|
|
1993
|
+
useListboxSelection,
|
|
1524
1994
|
usePickerInputContext,
|
|
1525
1995
|
usePickerItemContext,
|
|
1526
|
-
|
|
1996
|
+
useReorderAutoScroll,
|
|
1997
|
+
useReorderItem,
|
|
1998
|
+
useReorderList,
|
|
1527
1999
|
useTree
|
|
1528
2000
|
};
|
|
1529
2001
|
//# sourceMappingURL=index.mjs.map
|