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