@dxos/react-ui-list 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +955 -270
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +955 -270
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Accordion/Accordion.d.ts +1 -1
- package/dist/types/src/components/Accordion/Accordion.d.ts.map +1 -1
- package/dist/types/src/components/Accordion/Accordion.stories.d.ts.map +1 -1
- 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/Combobox/Combobox.d.ts +105 -0
- package/dist/types/src/components/Combobox/Combobox.d.ts.map +1 -0
- package/dist/types/src/components/Combobox/Combobox.stories.d.ts +12 -0
- package/dist/types/src/components/Combobox/Combobox.stories.d.ts.map +1 -0
- package/dist/types/src/components/Combobox/index.d.ts +2 -0
- package/dist/types/src/components/Combobox/index.d.ts.map +1 -0
- package/dist/types/src/components/List/List.d.ts +18 -7
- package/dist/types/src/components/List/List.d.ts.map +1 -1
- package/dist/types/src/components/List/List.stories.d.ts +2 -2
- package/dist/types/src/components/List/List.stories.d.ts.map +1 -1
- package/dist/types/src/components/List/ListItem.d.ts +10 -8
- package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
- package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
- package/dist/types/src/components/List/testing.d.ts.map +1 -1
- package/dist/types/src/components/Listbox/Listbox.d.ts +27 -0
- package/dist/types/src/components/Listbox/Listbox.d.ts.map +1 -0
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts +12 -0
- package/dist/types/src/components/Listbox/Listbox.stories.d.ts.map +1 -0
- package/dist/types/src/components/Listbox/index.d.ts +2 -0
- package/dist/types/src/components/Listbox/index.d.ts.map +1 -0
- package/dist/types/src/components/Picker/Picker.d.ts +49 -0
- package/dist/types/src/components/Picker/Picker.d.ts.map +1 -0
- package/dist/types/src/components/Picker/Picker.stories.d.ts +28 -0
- package/dist/types/src/components/Picker/Picker.stories.d.ts.map +1 -0
- package/dist/types/src/components/Picker/context.d.ts +29 -0
- package/dist/types/src/components/Picker/context.d.ts.map +1 -0
- package/dist/types/src/components/Picker/index.d.ts +3 -0
- package/dist/types/src/components/Picker/index.d.ts.map +1 -0
- package/dist/types/src/components/RowList/RowList.d.ts +61 -0
- package/dist/types/src/components/RowList/RowList.d.ts.map +1 -0
- package/dist/types/src/components/RowList/RowList.stories.d.ts +35 -0
- package/dist/types/src/components/RowList/RowList.stories.d.ts.map +1 -0
- package/dist/types/src/components/RowList/index.d.ts +3 -0
- package/dist/types/src/components/RowList/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/Tree.d.ts +6 -5
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeContext.d.ts +21 -10
- package/dist/types/src/components/Tree/TreeContext.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItem.d.ts +8 -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/Tree/helpers.d.ts.map +1 -1
- package/dist/types/src/components/Tree/index.d.ts +2 -0
- package/dist/types/src/components/Tree/index.d.ts.map +1 -1
- package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/util/path.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -21
- package/src/components/Accordion/Accordion.stories.tsx +5 -5
- package/src/components/Accordion/AccordionItem.tsx +2 -5
- package/src/components/Combobox/Combobox.stories.tsx +60 -0
- package/src/components/Combobox/Combobox.tsx +387 -0
- package/src/components/Combobox/index.ts +5 -0
- package/src/components/List/List.stories.tsx +12 -12
- package/src/components/List/List.tsx +14 -10
- package/src/components/List/ListItem.tsx +55 -37
- package/src/components/List/ListRoot.tsx +1 -1
- package/src/components/List/testing.ts +4 -4
- package/src/components/Listbox/Listbox.stories.tsx +48 -0
- package/src/components/Listbox/Listbox.tsx +201 -0
- package/src/components/Listbox/index.ts +5 -0
- package/src/components/Picker/Picker.stories.tsx +131 -0
- package/src/components/Picker/Picker.tsx +368 -0
- package/src/components/Picker/context.ts +43 -0
- package/src/components/Picker/index.ts +6 -0
- package/src/components/RowList/RowList.stories.tsx +163 -0
- package/src/components/RowList/RowList.tsx +350 -0
- package/src/components/RowList/index.ts +6 -0
- package/src/components/Tree/Tree.stories.tsx +105 -30
- package/src/components/Tree/Tree.tsx +31 -41
- package/src/components/Tree/TreeContext.tsx +18 -9
- package/src/components/Tree/TreeItem.tsx +179 -108
- package/src/components/Tree/TreeItemHeading.tsx +5 -4
- package/src/components/Tree/TreeItemToggle.tsx +4 -4
- package/src/components/Tree/index.ts +2 -0
- package/src/components/Tree/testing.ts +5 -5
- package/src/components/index.ts +4 -0
|
@@ -44,7 +44,7 @@ var AccordionItemHeader = ({ classNames, children, ...props }) => {
|
|
|
44
44
|
...props,
|
|
45
45
|
className: mx2(classNames)
|
|
46
46
|
}, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Trigger, {
|
|
47
|
-
className: "group flex items-center p-2 dx-focus-ring-inset
|
|
47
|
+
className: "group flex items-center p-2 dx-focus-ring-inset w-full text-start"
|
|
48
48
|
}, children, /* @__PURE__ */ React2.createElement(Icon, {
|
|
49
49
|
icon: "ph--caret-right--regular",
|
|
50
50
|
size: 4,
|
|
@@ -55,7 +55,6 @@ var AccordionItemBody = ({ children, classNames }) => {
|
|
|
55
55
|
return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Content, {
|
|
56
56
|
className: "overflow-hidden data-[state=closed]:animate-slide-up data-[state=open]:animate-slide-down"
|
|
57
57
|
}, /* @__PURE__ */ React2.createElement("div", {
|
|
58
|
-
role: "none",
|
|
59
58
|
className: mx2("p-2", classNames)
|
|
60
59
|
}, children));
|
|
61
60
|
};
|
|
@@ -68,29 +67,466 @@ var Accordion = {
|
|
|
68
67
|
ItemBody: AccordionItemBody
|
|
69
68
|
};
|
|
70
69
|
|
|
70
|
+
// src/components/Combobox/Combobox.tsx
|
|
71
|
+
import { createContext as createContext4 } from "@radix-ui/react-context";
|
|
72
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
73
|
+
import React4, { forwardRef as forwardRef2, useCallback as useCallback2 } from "react";
|
|
74
|
+
import { Button, Icon as Icon2, Popover, ScrollArea, useId } from "@dxos/react-ui";
|
|
75
|
+
import { composable, composableProps, mx as mx4 } from "@dxos/ui-theme";
|
|
76
|
+
|
|
77
|
+
// src/components/Picker/Picker.tsx
|
|
78
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
79
|
+
import React3, { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
80
|
+
import { Input, useThemeContext } from "@dxos/react-ui";
|
|
81
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
82
|
+
|
|
83
|
+
// src/components/Picker/context.ts
|
|
84
|
+
import { createContext as createContext3 } from "@radix-ui/react-context";
|
|
85
|
+
var [PickerItemContextProvider, usePickerItemContext] = createContext3("PickerItem");
|
|
86
|
+
var [PickerInputContextProvider, usePickerInputContext] = createContext3("PickerInput");
|
|
87
|
+
|
|
88
|
+
// src/components/Picker/Picker.tsx
|
|
89
|
+
var PickerRoot = ({ children }) => {
|
|
90
|
+
const [selectedValue, setSelectedValue] = useState(void 0);
|
|
91
|
+
const itemsRef = useRef(/* @__PURE__ */ new Map());
|
|
92
|
+
const [itemVersion, setItemVersion] = useState(0);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const current = selectedValue !== void 0 ? itemsRef.current.get(selectedValue) : void 0;
|
|
95
|
+
const isValid = current !== void 0 && !current.disabled;
|
|
96
|
+
if (!isValid && itemsRef.current.size > 0) {
|
|
97
|
+
const entries = Array.from(itemsRef.current.entries()).filter(([, data]) => !data.disabled);
|
|
98
|
+
if (entries.length > 0) {
|
|
99
|
+
entries.sort(([, a], [, b]) => {
|
|
100
|
+
const position = a.element.compareDocumentPosition(b.element);
|
|
101
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
102
|
+
return -1;
|
|
103
|
+
}
|
|
104
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
return 0;
|
|
108
|
+
});
|
|
109
|
+
const firstValue = entries[0]?.[0];
|
|
110
|
+
if (firstValue !== void 0 && firstValue !== selectedValue) {
|
|
111
|
+
setSelectedValue(firstValue);
|
|
112
|
+
}
|
|
113
|
+
} else if (selectedValue !== void 0) {
|
|
114
|
+
setSelectedValue(void 0);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, [
|
|
118
|
+
itemVersion,
|
|
119
|
+
selectedValue
|
|
120
|
+
]);
|
|
121
|
+
const registerItem = useCallback((value, element, onSelect, disabled) => {
|
|
122
|
+
if (element) {
|
|
123
|
+
itemsRef.current.set(value, {
|
|
124
|
+
element,
|
|
125
|
+
onSelect,
|
|
126
|
+
disabled
|
|
127
|
+
});
|
|
128
|
+
setItemVersion((v) => v + 1);
|
|
129
|
+
}
|
|
130
|
+
}, []);
|
|
131
|
+
const unregisterItem = useCallback((value) => {
|
|
132
|
+
itemsRef.current.delete(value);
|
|
133
|
+
setItemVersion((v) => v + 1);
|
|
134
|
+
}, []);
|
|
135
|
+
const getItemValues = useCallback(() => {
|
|
136
|
+
return Array.from(itemsRef.current.entries()).filter(([, data]) => !data.disabled).sort(([, a], [, b]) => {
|
|
137
|
+
const position = a.element.compareDocumentPosition(b.element);
|
|
138
|
+
return position & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : position & Node.DOCUMENT_POSITION_PRECEDING ? 1 : 0;
|
|
139
|
+
}).map(([value]) => value);
|
|
140
|
+
}, []);
|
|
141
|
+
const triggerSelect = useCallback(() => {
|
|
142
|
+
if (selectedValue !== void 0) {
|
|
143
|
+
const item = itemsRef.current.get(selectedValue);
|
|
144
|
+
item?.onSelect?.();
|
|
145
|
+
}
|
|
146
|
+
}, [
|
|
147
|
+
selectedValue
|
|
148
|
+
]);
|
|
149
|
+
const itemContextValue = useMemo(() => ({
|
|
150
|
+
selectedValue,
|
|
151
|
+
onSelectedValueChange: setSelectedValue,
|
|
152
|
+
registerItem,
|
|
153
|
+
unregisterItem
|
|
154
|
+
}), [
|
|
155
|
+
selectedValue,
|
|
156
|
+
registerItem,
|
|
157
|
+
unregisterItem
|
|
158
|
+
]);
|
|
159
|
+
const inputContextValue = useMemo(() => ({
|
|
160
|
+
selectedValue,
|
|
161
|
+
onSelectedValueChange: setSelectedValue,
|
|
162
|
+
getItemValues,
|
|
163
|
+
triggerSelect
|
|
164
|
+
}), [
|
|
165
|
+
selectedValue,
|
|
166
|
+
getItemValues,
|
|
167
|
+
triggerSelect
|
|
168
|
+
]);
|
|
169
|
+
return /* @__PURE__ */ React3.createElement(PickerInputContextProvider, inputContextValue, /* @__PURE__ */ React3.createElement(PickerItemContextProvider, itemContextValue, children));
|
|
170
|
+
};
|
|
171
|
+
PickerRoot.displayName = "Picker.Root";
|
|
172
|
+
var PickerInput = /* @__PURE__ */ forwardRef(({ value, onValueChange, onChange, onKeyDown, autoFocus, ...props }, forwardedRef) => {
|
|
173
|
+
const { hasIosKeyboard } = useThemeContext();
|
|
174
|
+
const { selectedValue, onSelectedValueChange, getItemValues, triggerSelect } = usePickerInputContext("Picker.Input");
|
|
175
|
+
const handleChange = useCallback((event) => {
|
|
176
|
+
onValueChange?.(event.target.value);
|
|
177
|
+
onChange?.(event);
|
|
178
|
+
}, [
|
|
179
|
+
onValueChange,
|
|
180
|
+
onChange
|
|
181
|
+
]);
|
|
182
|
+
const handleKeyDown = useCallback((event) => {
|
|
183
|
+
onKeyDown?.(event);
|
|
184
|
+
if (event.defaultPrevented) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const values = getItemValues();
|
|
188
|
+
if (values.length === 0) {
|
|
189
|
+
if (event.key === "Escape") {
|
|
190
|
+
onValueChange?.("");
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const currentIndex = selectedValue !== void 0 ? values.indexOf(selectedValue) : -1;
|
|
195
|
+
switch (event.key) {
|
|
196
|
+
case "ArrowDown": {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
const nextIndex = currentIndex === -1 ? 0 : Math.min(currentIndex + 1, values.length - 1);
|
|
199
|
+
const nextValue = values[nextIndex];
|
|
200
|
+
if (nextValue !== void 0) {
|
|
201
|
+
onSelectedValueChange(nextValue);
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "ArrowUp": {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
const prevIndex = currentIndex === -1 ? values.length - 1 : Math.max(currentIndex - 1, 0);
|
|
208
|
+
const prevValue = values[prevIndex];
|
|
209
|
+
if (prevValue !== void 0) {
|
|
210
|
+
onSelectedValueChange(prevValue);
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "Enter": {
|
|
215
|
+
if (selectedValue !== void 0) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
triggerSelect();
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case "Home": {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
const firstValue = values[0];
|
|
224
|
+
if (firstValue !== void 0) {
|
|
225
|
+
onSelectedValueChange(firstValue);
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case "End": {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
const lastValue = values[values.length - 1];
|
|
232
|
+
if (lastValue !== void 0) {
|
|
233
|
+
onSelectedValueChange(lastValue);
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "Escape": {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
if (selectedValue !== void 0) {
|
|
240
|
+
onSelectedValueChange(void 0);
|
|
241
|
+
} else {
|
|
242
|
+
onValueChange?.("");
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}, [
|
|
248
|
+
selectedValue,
|
|
249
|
+
onSelectedValueChange,
|
|
250
|
+
getItemValues,
|
|
251
|
+
triggerSelect,
|
|
252
|
+
onValueChange,
|
|
253
|
+
onKeyDown
|
|
254
|
+
]);
|
|
255
|
+
return /* @__PURE__ */ React3.createElement(Input.Root, null, /* @__PURE__ */ React3.createElement(Input.TextInput, {
|
|
256
|
+
...props,
|
|
257
|
+
autoFocus: autoFocus && !hasIosKeyboard,
|
|
258
|
+
...value !== void 0 && {
|
|
259
|
+
value
|
|
260
|
+
},
|
|
261
|
+
onChange: handleChange,
|
|
262
|
+
onKeyDown: handleKeyDown,
|
|
263
|
+
ref: forwardedRef
|
|
264
|
+
}));
|
|
265
|
+
});
|
|
266
|
+
PickerInput.displayName = "Picker.Input";
|
|
267
|
+
var PickerItem = /* @__PURE__ */ forwardRef(({ classNames, value, onSelect, disabled, asChild, children, ...props }, forwardedRef) => {
|
|
268
|
+
const { selectedValue, onSelectedValueChange, registerItem, unregisterItem } = usePickerItemContext("Picker.Item");
|
|
269
|
+
const internalRef = useRef(null);
|
|
270
|
+
const isSelected = selectedValue === value && !disabled;
|
|
271
|
+
useEffect(() => {
|
|
272
|
+
const element = internalRef.current;
|
|
273
|
+
if (element) {
|
|
274
|
+
registerItem(value, element, onSelect, disabled);
|
|
275
|
+
}
|
|
276
|
+
return () => unregisterItem(value);
|
|
277
|
+
}, [
|
|
278
|
+
value,
|
|
279
|
+
onSelect,
|
|
280
|
+
disabled,
|
|
281
|
+
registerItem,
|
|
282
|
+
unregisterItem
|
|
283
|
+
]);
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (isSelected && internalRef.current) {
|
|
286
|
+
internalRef.current.scrollIntoView({
|
|
287
|
+
block: "nearest",
|
|
288
|
+
behavior: "smooth"
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}, [
|
|
292
|
+
isSelected
|
|
293
|
+
]);
|
|
294
|
+
const handleClick = useCallback(() => {
|
|
295
|
+
if (disabled) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
onSelectedValueChange(value);
|
|
299
|
+
onSelect?.();
|
|
300
|
+
}, [
|
|
301
|
+
disabled,
|
|
302
|
+
value,
|
|
303
|
+
onSelectedValueChange,
|
|
304
|
+
onSelect
|
|
305
|
+
]);
|
|
306
|
+
const handleMouseDown = useCallback((event) => {
|
|
307
|
+
event.preventDefault();
|
|
308
|
+
}, []);
|
|
309
|
+
const Comp = asChild ? Slot : "div";
|
|
310
|
+
return /* @__PURE__ */ React3.createElement(Comp, {
|
|
311
|
+
...props,
|
|
312
|
+
ref: (node) => {
|
|
313
|
+
internalRef.current = node;
|
|
314
|
+
if (typeof forwardedRef === "function") {
|
|
315
|
+
forwardedRef(node);
|
|
316
|
+
} else if (forwardedRef) {
|
|
317
|
+
forwardedRef.current = node;
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
role: "option",
|
|
321
|
+
"aria-selected": isSelected,
|
|
322
|
+
"aria-disabled": disabled,
|
|
323
|
+
"data-selected": isSelected,
|
|
324
|
+
"data-disabled": disabled,
|
|
325
|
+
"data-value": value,
|
|
326
|
+
// Browser focus stays on the input; highlight is via `aria-selected`.
|
|
327
|
+
tabIndex: -1,
|
|
328
|
+
className: mx3("dx-hover dx-selected px-[var(--gutter,0.75rem)] py-1 cursor-pointer select-none", disabled && "opacity-50 cursor-not-allowed", classNames),
|
|
329
|
+
onMouseDown: handleMouseDown,
|
|
330
|
+
onClick: handleClick
|
|
331
|
+
}, children);
|
|
332
|
+
});
|
|
333
|
+
PickerItem.displayName = "Picker.Item";
|
|
334
|
+
var Picker = {
|
|
335
|
+
Root: PickerRoot,
|
|
336
|
+
Input: PickerInput,
|
|
337
|
+
Item: PickerItem
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// src/components/Combobox/Combobox.tsx
|
|
341
|
+
var COMBOBOX_NAME = "Combobox";
|
|
342
|
+
var COMBOBOX_CONTENT_NAME = "ComboboxContent";
|
|
343
|
+
var COMBOBOX_ITEM_NAME = "ComboboxItem";
|
|
344
|
+
var COMBOBOX_TRIGGER_NAME = "ComboboxTrigger";
|
|
345
|
+
var [ComboboxProvider, useComboboxContext] = createContext4(COMBOBOX_NAME, {});
|
|
346
|
+
var ComboboxRoot = ({ children, modal, modalId: modalIdProp, open: openProp, defaultOpen, onOpenChange: propsOnOpenChange, value: valueProp, defaultValue, onValueChange: propsOnValueChange, placeholder }) => {
|
|
347
|
+
const modalId = useId(COMBOBOX_NAME, modalIdProp);
|
|
348
|
+
const [open = false, onOpenChange] = useControllableState({
|
|
349
|
+
prop: openProp,
|
|
350
|
+
defaultProp: defaultOpen,
|
|
351
|
+
onChange: propsOnOpenChange
|
|
352
|
+
});
|
|
353
|
+
const [value = "", onValueChange] = useControllableState({
|
|
354
|
+
prop: valueProp,
|
|
355
|
+
defaultProp: defaultValue,
|
|
356
|
+
onChange: propsOnValueChange
|
|
357
|
+
});
|
|
358
|
+
return /* @__PURE__ */ React4.createElement(Popover.Root, {
|
|
359
|
+
open,
|
|
360
|
+
onOpenChange,
|
|
361
|
+
modal
|
|
362
|
+
}, /* @__PURE__ */ React4.createElement(ComboboxProvider, {
|
|
363
|
+
isCombobox: true,
|
|
364
|
+
modalId,
|
|
365
|
+
placeholder,
|
|
366
|
+
open,
|
|
367
|
+
onOpenChange,
|
|
368
|
+
value,
|
|
369
|
+
onValueChange
|
|
370
|
+
}, children));
|
|
371
|
+
};
|
|
372
|
+
var ComboboxContent = composable(({ children, ...props }, forwardedRef) => {
|
|
373
|
+
const { modalId } = useComboboxContext(COMBOBOX_CONTENT_NAME);
|
|
374
|
+
return /* @__PURE__ */ React4.createElement(Popover.Content, {
|
|
375
|
+
...composableProps(props, {
|
|
376
|
+
id: modalId
|
|
377
|
+
}),
|
|
378
|
+
ref: forwardedRef
|
|
379
|
+
}, /* @__PURE__ */ React4.createElement(Popover.Viewport, {
|
|
380
|
+
classNames: "w-(--radix-popover-trigger-width)"
|
|
381
|
+
}, /* @__PURE__ */ React4.createElement(Picker.Root, null, children)));
|
|
382
|
+
});
|
|
383
|
+
ComboboxContent.displayName = COMBOBOX_CONTENT_NAME;
|
|
384
|
+
var ComboboxTrigger = /* @__PURE__ */ forwardRef2(({ children, onClick, ...props }, forwardedRef) => {
|
|
385
|
+
const { modalId, open, onOpenChange, placeholder, value } = useComboboxContext(COMBOBOX_TRIGGER_NAME);
|
|
386
|
+
const handleClick = useCallback2((event) => {
|
|
387
|
+
onClick?.(event);
|
|
388
|
+
onOpenChange?.(true);
|
|
389
|
+
}, [
|
|
390
|
+
onClick,
|
|
391
|
+
onOpenChange
|
|
392
|
+
]);
|
|
393
|
+
return /* @__PURE__ */ React4.createElement(Popover.Trigger, {
|
|
394
|
+
asChild: true
|
|
395
|
+
}, /* @__PURE__ */ React4.createElement(Button, {
|
|
396
|
+
...props,
|
|
397
|
+
role: "combobox",
|
|
398
|
+
"aria-expanded": open,
|
|
399
|
+
"aria-controls": modalId,
|
|
400
|
+
"aria-haspopup": "dialog",
|
|
401
|
+
onClick: handleClick,
|
|
402
|
+
ref: forwardedRef
|
|
403
|
+
}, children ?? /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("span", {
|
|
404
|
+
className: mx4("font-normal text-start flex-1 min-w-0 truncate me-2", !value && "text-subdued")
|
|
405
|
+
}, value || placeholder), /* @__PURE__ */ React4.createElement(Icon2, {
|
|
406
|
+
icon: "ph--caret-down--bold",
|
|
407
|
+
size: 3
|
|
408
|
+
}))));
|
|
409
|
+
});
|
|
410
|
+
ComboboxTrigger.displayName = COMBOBOX_TRIGGER_NAME;
|
|
411
|
+
var ComboboxVirtualTrigger = Popover.VirtualTrigger;
|
|
412
|
+
var ComboboxInput = /* @__PURE__ */ forwardRef2(({ classNames, ...props }, forwardedRef) => {
|
|
413
|
+
return /* @__PURE__ */ React4.createElement(Picker.Input, {
|
|
414
|
+
...props,
|
|
415
|
+
classNames: [
|
|
416
|
+
"m-form-chrome mb-0 w-[calc(100%-2*var(--spacing-form-chrome))]",
|
|
417
|
+
classNames
|
|
418
|
+
],
|
|
419
|
+
ref: forwardedRef
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
ComboboxInput.displayName = "Combobox.Input";
|
|
423
|
+
var ComboboxList = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, forwardedRef) => {
|
|
424
|
+
return /* @__PURE__ */ React4.createElement(ScrollArea.Root, {
|
|
425
|
+
...composableProps(props, {
|
|
426
|
+
classNames: [
|
|
427
|
+
"py-form-chrome",
|
|
428
|
+
classNames
|
|
429
|
+
]
|
|
430
|
+
}),
|
|
431
|
+
role: "listbox",
|
|
432
|
+
centered: true,
|
|
433
|
+
padding: true,
|
|
434
|
+
thin: true,
|
|
435
|
+
ref: forwardedRef
|
|
436
|
+
}, /* @__PURE__ */ React4.createElement(ScrollArea.Viewport, null, children));
|
|
437
|
+
});
|
|
438
|
+
ComboboxList.displayName = "Combobox.List";
|
|
439
|
+
var ComboboxItem = /* @__PURE__ */ forwardRef2(({ classNames, onSelect, value, label, icon, iconClassNames, checked, suffix, disabled, closeOnSelect = true, children }, forwardedRef) => {
|
|
440
|
+
const { onValueChange, onOpenChange } = useComboboxContext(COMBOBOX_ITEM_NAME);
|
|
441
|
+
const handleSelect = useCallback2(() => {
|
|
442
|
+
onSelect?.();
|
|
443
|
+
if (value !== void 0) {
|
|
444
|
+
onValueChange?.(value);
|
|
445
|
+
}
|
|
446
|
+
if (closeOnSelect) {
|
|
447
|
+
onOpenChange?.(false);
|
|
448
|
+
}
|
|
449
|
+
}, [
|
|
450
|
+
onSelect,
|
|
451
|
+
onValueChange,
|
|
452
|
+
onOpenChange,
|
|
453
|
+
value,
|
|
454
|
+
closeOnSelect
|
|
455
|
+
]);
|
|
456
|
+
return /* @__PURE__ */ React4.createElement(Picker.Item, {
|
|
457
|
+
value,
|
|
458
|
+
disabled,
|
|
459
|
+
onSelect: handleSelect,
|
|
460
|
+
ref: forwardedRef,
|
|
461
|
+
classNames: [
|
|
462
|
+
// Full width inside the viewport (no horizontal margin).
|
|
463
|
+
// `px-3 py-1`, `cursor-pointer`, `select-none` and the
|
|
464
|
+
// `dx-hover` / `dx-selected` pairing come from `Picker.Item`'s
|
|
465
|
+
// defaults; we only add the row-shape (flex / icons + label)
|
|
466
|
+
// and the disabled overrides on top.
|
|
467
|
+
"flex w-full gap-2 items-center",
|
|
468
|
+
disabled && "hover:bg-transparent data-[selected=true]:bg-transparent",
|
|
469
|
+
classNames
|
|
470
|
+
]
|
|
471
|
+
}, children ?? /* @__PURE__ */ React4.createElement(React4.Fragment, null, icon && /* @__PURE__ */ React4.createElement(Icon2, {
|
|
472
|
+
icon,
|
|
473
|
+
classNames: iconClassNames
|
|
474
|
+
}), /* @__PURE__ */ React4.createElement("span", {
|
|
475
|
+
className: "w-0 grow truncate"
|
|
476
|
+
}, label), suffix && /* @__PURE__ */ React4.createElement("span", {
|
|
477
|
+
className: "shrink-0 text-description"
|
|
478
|
+
}, suffix), checked && /* @__PURE__ */ React4.createElement(Icon2, {
|
|
479
|
+
icon: "ph--check--regular"
|
|
480
|
+
})));
|
|
481
|
+
});
|
|
482
|
+
ComboboxItem.displayName = COMBOBOX_ITEM_NAME;
|
|
483
|
+
var ComboboxArrow = Popover.Arrow;
|
|
484
|
+
var ComboboxEmpty = /* @__PURE__ */ forwardRef2(({ classNames, children }, forwardedRef) => {
|
|
485
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
486
|
+
ref: forwardedRef,
|
|
487
|
+
role: "status",
|
|
488
|
+
className: mx4(classNames)
|
|
489
|
+
}, children);
|
|
490
|
+
});
|
|
491
|
+
ComboboxEmpty.displayName = "Combobox.Empty";
|
|
492
|
+
var ComboboxPortal = Popover.Portal;
|
|
493
|
+
var Combobox = {
|
|
494
|
+
Root: ComboboxRoot,
|
|
495
|
+
Portal: ComboboxPortal,
|
|
496
|
+
Content: ComboboxContent,
|
|
497
|
+
Trigger: ComboboxTrigger,
|
|
498
|
+
VirtualTrigger: ComboboxVirtualTrigger,
|
|
499
|
+
Input: ComboboxInput,
|
|
500
|
+
List: ComboboxList,
|
|
501
|
+
Item: ComboboxItem,
|
|
502
|
+
Arrow: ComboboxArrow,
|
|
503
|
+
Empty: ComboboxEmpty
|
|
504
|
+
};
|
|
505
|
+
|
|
71
506
|
// src/components/List/ListItem.tsx
|
|
507
|
+
import { attachClosestEdge, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
72
508
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
73
509
|
import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
74
510
|
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
75
|
-
import {
|
|
76
|
-
import {
|
|
77
|
-
import
|
|
511
|
+
import { createContext as createContext6 } from "@radix-ui/react-context";
|
|
512
|
+
import { Slot as Slot2 } from "@radix-ui/react-slot";
|
|
513
|
+
import React6, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
78
514
|
import { createPortal } from "react-dom";
|
|
79
515
|
import { invariant } from "@dxos/invariant";
|
|
80
516
|
import { IconButton, ListItem as NaturalListItem, useTranslation } from "@dxos/react-ui";
|
|
81
|
-
import { mx as
|
|
517
|
+
import { mx as mx5, osTranslations } from "@dxos/ui-theme";
|
|
82
518
|
|
|
83
519
|
// src/components/List/ListRoot.tsx
|
|
84
|
-
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
85
520
|
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
86
521
|
import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
|
|
87
|
-
import {
|
|
88
|
-
import
|
|
522
|
+
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
523
|
+
import { createContext as createContext5 } from "@radix-ui/react-context";
|
|
524
|
+
import React5, { useCallback as useCallback3, useEffect as useEffect2, useState as useState2 } from "react";
|
|
89
525
|
var LIST_NAME = "List";
|
|
90
|
-
var [ListProvider, useListContext] =
|
|
526
|
+
var [ListProvider, useListContext] = createContext5(LIST_NAME);
|
|
91
527
|
var defaultGetId2 = (item) => item?.id;
|
|
92
528
|
var ListRoot = ({ children, items, isItem, getId = defaultGetId2, onMove, ...props }) => {
|
|
93
|
-
const isEqual =
|
|
529
|
+
const isEqual = useCallback3((a, b) => {
|
|
94
530
|
const idA = getId?.(a);
|
|
95
531
|
const idB = getId?.(b);
|
|
96
532
|
if (idA !== void 0 && idB !== void 0) {
|
|
@@ -101,8 +537,8 @@ var ListRoot = ({ children, items, isItem, getId = defaultGetId2, onMove, ...pro
|
|
|
101
537
|
}, [
|
|
102
538
|
getId
|
|
103
539
|
]);
|
|
104
|
-
const [state, setState] =
|
|
105
|
-
|
|
540
|
+
const [state, setState] = useState2(idle);
|
|
541
|
+
useEffect2(() => {
|
|
106
542
|
if (!items) {
|
|
107
543
|
return;
|
|
108
544
|
}
|
|
@@ -138,7 +574,7 @@ var ListRoot = ({ children, items, isItem, getId = defaultGetId2, onMove, ...pro
|
|
|
138
574
|
isEqual,
|
|
139
575
|
onMove
|
|
140
576
|
]);
|
|
141
|
-
return /* @__PURE__ */
|
|
577
|
+
return /* @__PURE__ */ React5.createElement(ListProvider, {
|
|
142
578
|
state,
|
|
143
579
|
setState,
|
|
144
580
|
isItem,
|
|
@@ -159,23 +595,16 @@ var stateStyles = {
|
|
|
159
595
|
};
|
|
160
596
|
var defaultContext = {};
|
|
161
597
|
var LIST_ITEM_NAME = "ListItem";
|
|
162
|
-
var [ListItemProvider, useListItemContext] =
|
|
163
|
-
var ListItem = ({ children, classNames, item, ...props }) => {
|
|
598
|
+
var [ListItemProvider, useListItemContext] = createContext6(LIST_ITEM_NAME, defaultContext);
|
|
599
|
+
var ListItem = ({ children, classNames, item, asChild, selected, ...props }) => {
|
|
600
|
+
const Comp = asChild ? Slot2 : "div";
|
|
164
601
|
const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
|
|
165
|
-
const
|
|
166
|
-
const dragHandleRef =
|
|
167
|
-
const [state, setState] =
|
|
168
|
-
|
|
169
|
-
const element =
|
|
170
|
-
invariant(element, void 0, {
|
|
171
|
-
F: __dxlog_file,
|
|
172
|
-
L: 98,
|
|
173
|
-
S: void 0,
|
|
174
|
-
A: [
|
|
175
|
-
"element",
|
|
176
|
-
""
|
|
177
|
-
]
|
|
178
|
-
});
|
|
602
|
+
const rootRef = useRef2(null);
|
|
603
|
+
const dragHandleRef = useRef2(null);
|
|
604
|
+
const [state, setState] = useState3(idle);
|
|
605
|
+
useEffect3(() => {
|
|
606
|
+
const element = rootRef.current;
|
|
607
|
+
invariant(element, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 37, S: void 0, A: ["element", ""] });
|
|
179
608
|
return combine(
|
|
180
609
|
//
|
|
181
610
|
// https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#draggable
|
|
@@ -275,43 +704,44 @@ var ListItem = ({ children, classNames, item, ...props }) => {
|
|
|
275
704
|
}, [
|
|
276
705
|
item
|
|
277
706
|
]);
|
|
278
|
-
return /* @__PURE__ */
|
|
707
|
+
return /* @__PURE__ */ React6.createElement(ListItemProvider, {
|
|
279
708
|
item,
|
|
280
709
|
dragHandleRef
|
|
281
|
-
}, /* @__PURE__ */
|
|
282
|
-
|
|
710
|
+
}, /* @__PURE__ */ React6.createElement(Comp, {
|
|
711
|
+
...props,
|
|
283
712
|
role: "listitem",
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
713
|
+
"aria-selected": selected,
|
|
714
|
+
className: mx5("relative p-1 dx-selected dx-hover", classNames, stateStyles[state.type]),
|
|
715
|
+
ref: rootRef
|
|
716
|
+
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React6.createElement(NaturalListItem.DropIndicator, {
|
|
287
717
|
edge: state.closestEdge
|
|
288
|
-
}))
|
|
718
|
+
}));
|
|
289
719
|
};
|
|
290
|
-
var
|
|
291
|
-
const { state } = useListContext("
|
|
720
|
+
var ListItemIconButton = ({ autoHide = true, iconOnly = true, variant = "ghost", classNames, disabled, ...props }) => {
|
|
721
|
+
const { state } = useListContext("ITEM_BUTTON");
|
|
292
722
|
const isDisabled = state.type !== "idle" || disabled;
|
|
293
|
-
|
|
294
|
-
return /* @__PURE__ */ React4.createElement(IconButton, {
|
|
295
|
-
iconOnly: true,
|
|
296
|
-
variant: "ghost",
|
|
723
|
+
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
297
724
|
...props,
|
|
298
|
-
icon,
|
|
299
725
|
disabled: isDisabled,
|
|
300
|
-
|
|
726
|
+
iconOnly,
|
|
727
|
+
variant,
|
|
301
728
|
classNames: [
|
|
302
729
|
classNames,
|
|
303
730
|
autoHide && disabled && "hidden"
|
|
304
731
|
]
|
|
305
732
|
});
|
|
306
733
|
};
|
|
307
|
-
var
|
|
308
|
-
const { state } = useListContext("
|
|
734
|
+
var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, icon = "ph--x--regular", label, ...props }) => {
|
|
735
|
+
const { state } = useListContext("DELETE_BUTTON");
|
|
309
736
|
const isDisabled = state.type !== "idle" || disabled;
|
|
310
|
-
|
|
737
|
+
const { t } = useTranslation(osTranslations);
|
|
738
|
+
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
311
739
|
...props,
|
|
740
|
+
variant: "ghost",
|
|
312
741
|
disabled: isDisabled,
|
|
313
|
-
|
|
314
|
-
|
|
742
|
+
icon,
|
|
743
|
+
iconOnly: true,
|
|
744
|
+
label: label ?? t("delete.label"),
|
|
315
745
|
classNames: [
|
|
316
746
|
classNames,
|
|
317
747
|
autoHide && disabled && "hidden"
|
|
@@ -321,13 +751,13 @@ var ListItemButton = ({ autoHide = true, iconOnly = true, variant = "ghost", cla
|
|
|
321
751
|
var ListItemDragHandle = ({ disabled }) => {
|
|
322
752
|
const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
|
|
323
753
|
const { t } = useTranslation(osTranslations);
|
|
324
|
-
return /* @__PURE__ */
|
|
325
|
-
iconOnly: true,
|
|
754
|
+
return /* @__PURE__ */ React6.createElement(IconButton, {
|
|
326
755
|
variant: "ghost",
|
|
327
|
-
|
|
328
|
-
ref: dragHandleRef,
|
|
756
|
+
disabled,
|
|
329
757
|
icon: "ph--dots-six-vertical--regular",
|
|
330
|
-
|
|
758
|
+
iconOnly: true,
|
|
759
|
+
label: t("drag-handle.label"),
|
|
760
|
+
ref: dragHandleRef
|
|
331
761
|
});
|
|
332
762
|
};
|
|
333
763
|
var ListItemDragPreview = ({ children }) => {
|
|
@@ -336,11 +766,11 @@ var ListItemDragPreview = ({ children }) => {
|
|
|
336
766
|
item: state.item
|
|
337
767
|
}), state.container) : null;
|
|
338
768
|
};
|
|
339
|
-
var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */
|
|
340
|
-
className:
|
|
769
|
+
var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React6.createElement("div", {
|
|
770
|
+
className: mx5("flex w-full gap-2", classNames)
|
|
341
771
|
}, children);
|
|
342
|
-
var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */
|
|
343
|
-
className:
|
|
772
|
+
var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React6.createElement("div", {
|
|
773
|
+
className: mx5("flex grow items-center truncate", classNames),
|
|
344
774
|
...props
|
|
345
775
|
}, children);
|
|
346
776
|
|
|
@@ -351,31 +781,252 @@ var List = {
|
|
|
351
781
|
ItemDragPreview: ListItemDragPreview,
|
|
352
782
|
ItemWrapper: ListItemWrapper,
|
|
353
783
|
ItemDragHandle: ListItemDragHandle,
|
|
784
|
+
ItemIconButton: ListItemIconButton,
|
|
354
785
|
ItemDeleteButton: ListItemDeleteButton,
|
|
355
|
-
ItemButton: ListItemButton,
|
|
356
786
|
ItemTitle: ListItemTitle
|
|
357
787
|
};
|
|
358
788
|
|
|
789
|
+
// src/components/Listbox/Listbox.tsx
|
|
790
|
+
import { createContextScope as createContextScope2 } from "@radix-ui/react-context";
|
|
791
|
+
import React8, { forwardRef as forwardRef3 } from "react";
|
|
792
|
+
import { Icon as Icon3 } from "@dxos/react-ui";
|
|
793
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
794
|
+
|
|
795
|
+
// src/components/RowList/RowList.tsx
|
|
796
|
+
import { useArrowNavigationGroup } from "@fluentui/react-tabster";
|
|
797
|
+
import { createContextScope } from "@radix-ui/react-context";
|
|
798
|
+
import { useControllableState as useControllableState2 } from "@radix-ui/react-use-controllable-state";
|
|
799
|
+
import React7, { useCallback as useCallback4 } from "react";
|
|
800
|
+
import { List as List2, ListItem as ListItem2 } from "@dxos/react-list";
|
|
801
|
+
import { ScrollArea as ScrollArea2 } from "@dxos/react-ui";
|
|
802
|
+
import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
|
|
803
|
+
var ROW_LIST_NAME = "RowList";
|
|
804
|
+
var ROW_LIST_ROOT_NAME = "RowList.Root";
|
|
805
|
+
var ROW_LIST_VIEWPORT_NAME = "RowList.Viewport";
|
|
806
|
+
var ROW_LIST_CONTENT_NAME = "RowList.Content";
|
|
807
|
+
var ROW_NAME = "List.Row";
|
|
808
|
+
var [createRowListContext, createRowListScope] = createContextScope(ROW_LIST_NAME, []);
|
|
809
|
+
var [RowListProvider, useRowListContext] = createRowListContext(ROW_LIST_NAME);
|
|
810
|
+
var Root2 = ({ selectedId, defaultSelectedId, onSelectChange, children }) => {
|
|
811
|
+
const [resolved, setResolved] = useControllableState2({
|
|
812
|
+
prop: selectedId,
|
|
813
|
+
defaultProp: defaultSelectedId,
|
|
814
|
+
onChange: (next) => {
|
|
815
|
+
if (next !== void 0) {
|
|
816
|
+
onSelectChange?.(next);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
const setSelected = useCallback4((id) => setResolved(id), [
|
|
821
|
+
setResolved
|
|
822
|
+
]);
|
|
823
|
+
return /* @__PURE__ */ React7.createElement(RowListProvider, {
|
|
824
|
+
scope: void 0,
|
|
825
|
+
selectedId: resolved,
|
|
826
|
+
setSelected
|
|
827
|
+
}, children);
|
|
828
|
+
};
|
|
829
|
+
Root2.displayName = ROW_LIST_ROOT_NAME;
|
|
830
|
+
var Viewport = composable2((props, forwardedRef) => {
|
|
831
|
+
const { thin, padding, centered, children, ...rest } = props;
|
|
832
|
+
return /* @__PURE__ */ React7.createElement(ScrollArea2.Root, {
|
|
833
|
+
...composableProps2(rest, {
|
|
834
|
+
classNames: "dx-container"
|
|
835
|
+
}),
|
|
836
|
+
thin,
|
|
837
|
+
padding,
|
|
838
|
+
centered,
|
|
839
|
+
orientation: "vertical",
|
|
840
|
+
ref: forwardedRef
|
|
841
|
+
}, /* @__PURE__ */ React7.createElement(ScrollArea2.Viewport, null, children));
|
|
842
|
+
});
|
|
843
|
+
Viewport.displayName = ROW_LIST_VIEWPORT_NAME;
|
|
844
|
+
var firstEnabledOption = (ul) => {
|
|
845
|
+
if (!ul) {
|
|
846
|
+
return null;
|
|
847
|
+
}
|
|
848
|
+
return ul.querySelector('[role="option"]:not([aria-disabled="true"])');
|
|
849
|
+
};
|
|
850
|
+
var Content2 = composable2((props, forwardedRef) => {
|
|
851
|
+
useRowListContext(ROW_LIST_CONTENT_NAME, void 0);
|
|
852
|
+
const arrowGroup = useArrowNavigationGroup({
|
|
853
|
+
axis: "vertical",
|
|
854
|
+
memorizeCurrent: true
|
|
855
|
+
});
|
|
856
|
+
const { children, ...rest } = props;
|
|
857
|
+
const handleFocus = useCallback4((event) => {
|
|
858
|
+
if (event.target !== event.currentTarget) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const ul = event.currentTarget;
|
|
862
|
+
const selected = ul.querySelector('[role="option"][aria-selected="true"]:not([aria-disabled="true"])');
|
|
863
|
+
const target = selected ?? firstEnabledOption(ul);
|
|
864
|
+
target?.focus();
|
|
865
|
+
}, []);
|
|
866
|
+
const composed = composableProps2(rest, {
|
|
867
|
+
classNames: "flex flex-col"
|
|
868
|
+
});
|
|
869
|
+
return /* @__PURE__ */ React7.createElement(List2, {
|
|
870
|
+
variant: "unordered",
|
|
871
|
+
...composed,
|
|
872
|
+
...arrowGroup,
|
|
873
|
+
role: "listbox",
|
|
874
|
+
onFocus: handleFocus,
|
|
875
|
+
ref: forwardedRef
|
|
876
|
+
}, children);
|
|
877
|
+
});
|
|
878
|
+
Content2.displayName = ROW_LIST_CONTENT_NAME;
|
|
879
|
+
var ROW_BASE = "dx-hover dx-selected px-3 py-2 cursor-pointer outline-none";
|
|
880
|
+
var Row = composable2((props, forwardedRef) => {
|
|
881
|
+
const { id, disabled, onClick, onFocus, children, ...rest } = props;
|
|
882
|
+
const { selectedId, setSelected } = useRowListContext(ROW_NAME, void 0);
|
|
883
|
+
const isSelected = selectedId === id;
|
|
884
|
+
const handleClick = useCallback4((event) => {
|
|
885
|
+
if (disabled) {
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
888
|
+
setSelected(id);
|
|
889
|
+
onClick?.(event);
|
|
890
|
+
}, [
|
|
891
|
+
disabled,
|
|
892
|
+
id,
|
|
893
|
+
setSelected,
|
|
894
|
+
onClick
|
|
895
|
+
]);
|
|
896
|
+
const handleFocus = useCallback4((event) => {
|
|
897
|
+
if (!disabled && selectedId !== id) {
|
|
898
|
+
setSelected(id);
|
|
899
|
+
}
|
|
900
|
+
onFocus?.(event);
|
|
901
|
+
}, [
|
|
902
|
+
disabled,
|
|
903
|
+
selectedId,
|
|
904
|
+
id,
|
|
905
|
+
setSelected,
|
|
906
|
+
onFocus
|
|
907
|
+
]);
|
|
908
|
+
const composed = composableProps2(rest, {
|
|
909
|
+
classNames: [
|
|
910
|
+
ROW_BASE,
|
|
911
|
+
disabled && "opacity-50 cursor-not-allowed"
|
|
912
|
+
]
|
|
913
|
+
});
|
|
914
|
+
return /* @__PURE__ */ React7.createElement(ListItem2, {
|
|
915
|
+
...composed,
|
|
916
|
+
role: "option",
|
|
917
|
+
tabIndex: 0,
|
|
918
|
+
"aria-selected": isSelected,
|
|
919
|
+
"aria-disabled": disabled || void 0,
|
|
920
|
+
onClick: handleClick,
|
|
921
|
+
onFocus: handleFocus,
|
|
922
|
+
ref: forwardedRef
|
|
923
|
+
}, children);
|
|
924
|
+
});
|
|
925
|
+
Row.displayName = ROW_NAME;
|
|
926
|
+
var useRowListSelection = (id) => {
|
|
927
|
+
const { selectedId } = useRowListContext("useRowListSelection", void 0);
|
|
928
|
+
return selectedId === id;
|
|
929
|
+
};
|
|
930
|
+
var RowList = {
|
|
931
|
+
Root: Root2,
|
|
932
|
+
Viewport,
|
|
933
|
+
Content: Content2
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
// src/components/Listbox/Listbox.tsx
|
|
937
|
+
var commandItem = "flex items-center overflow-hidden";
|
|
938
|
+
var LISTBOX_NAME = "Listbox";
|
|
939
|
+
var LISTBOX_OPTION_NAME = "ListboxOption";
|
|
940
|
+
var LISTBOX_OPTION_LABEL_NAME = "ListboxOptionLabel";
|
|
941
|
+
var LISTBOX_OPTION_INDICATOR_NAME = "ListboxOptionIndicator";
|
|
942
|
+
var [createListboxContext, createListboxScope] = createContextScope2(LISTBOX_NAME, [
|
|
943
|
+
createRowListScope
|
|
944
|
+
]);
|
|
945
|
+
var [createListboxOptionContext, createListboxOptionScope] = createContextScope2(LISTBOX_OPTION_NAME, [
|
|
946
|
+
createListboxScope
|
|
947
|
+
]);
|
|
948
|
+
var [ListboxOptionProvider, useListboxOptionContext] = createListboxOptionContext(LISTBOX_OPTION_NAME);
|
|
949
|
+
var ListboxRoot = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
|
|
950
|
+
const { __listboxScope: _scope, children, classNames, value, defaultValue, onValueChange, autoFocus: _autoFocus, ...rootProps } = props;
|
|
951
|
+
return /* @__PURE__ */ React8.createElement(RowList.Root, {
|
|
952
|
+
selectedId: value,
|
|
953
|
+
defaultSelectedId: defaultValue,
|
|
954
|
+
onSelectChange: onValueChange
|
|
955
|
+
}, /* @__PURE__ */ React8.createElement(RowList.Content, {
|
|
956
|
+
...rootProps,
|
|
957
|
+
classNames: mx6("w-full", classNames),
|
|
958
|
+
ref: forwardedRef
|
|
959
|
+
}, children));
|
|
960
|
+
});
|
|
961
|
+
ListboxRoot.displayName = LISTBOX_NAME;
|
|
962
|
+
var ListboxOption = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
|
|
963
|
+
const { __listboxScope, children, classNames, value, ...rootProps } = props;
|
|
964
|
+
return /* @__PURE__ */ React8.createElement(Row, {
|
|
965
|
+
id: value,
|
|
966
|
+
...rootProps,
|
|
967
|
+
classNames: mx6("dx-focus-ring rounded-xs", commandItem, classNames),
|
|
968
|
+
ref: forwardedRef
|
|
969
|
+
}, /* @__PURE__ */ React8.createElement(ListboxOptionProviderHost, {
|
|
970
|
+
value
|
|
971
|
+
}, children));
|
|
972
|
+
});
|
|
973
|
+
ListboxOption.displayName = LISTBOX_OPTION_NAME;
|
|
974
|
+
var ListboxOptionProviderHost = ({ value, children }) => {
|
|
975
|
+
const isSelected = useRowListSelection(value);
|
|
976
|
+
return /* @__PURE__ */ React8.createElement(ListboxOptionProvider, {
|
|
977
|
+
scope: void 0,
|
|
978
|
+
value,
|
|
979
|
+
isSelected
|
|
980
|
+
}, children);
|
|
981
|
+
};
|
|
982
|
+
var ListboxOptionLabel = /* @__PURE__ */ forwardRef3(({ children, classNames, ...rootProps }, forwardedRef) => {
|
|
983
|
+
return /* @__PURE__ */ React8.createElement("span", {
|
|
984
|
+
...rootProps,
|
|
985
|
+
className: mx6("grow truncate", classNames),
|
|
986
|
+
ref: forwardedRef
|
|
987
|
+
}, children);
|
|
988
|
+
});
|
|
989
|
+
ListboxOptionLabel.displayName = LISTBOX_OPTION_LABEL_NAME;
|
|
990
|
+
var ListboxOptionIndicator = /* @__PURE__ */ forwardRef3((props, forwardedRef) => {
|
|
991
|
+
const { __listboxOptionScope, classNames, ...rootProps } = props;
|
|
992
|
+
const { isSelected } = useListboxOptionContext(LISTBOX_OPTION_INDICATOR_NAME, __listboxOptionScope);
|
|
993
|
+
return /* @__PURE__ */ React8.createElement(Icon3, {
|
|
994
|
+
icon: "ph--check--regular",
|
|
995
|
+
...rootProps,
|
|
996
|
+
classNames: mx6(!isSelected && "invisible", classNames),
|
|
997
|
+
ref: forwardedRef
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
ListboxOptionIndicator.displayName = LISTBOX_OPTION_INDICATOR_NAME;
|
|
1001
|
+
var Listbox = {
|
|
1002
|
+
Root: ListboxRoot,
|
|
1003
|
+
Option: ListboxOption,
|
|
1004
|
+
OptionLabel: ListboxOptionLabel,
|
|
1005
|
+
OptionIndicator: ListboxOptionIndicator
|
|
1006
|
+
};
|
|
1007
|
+
|
|
359
1008
|
// src/components/Tree/Tree.tsx
|
|
360
|
-
import
|
|
1009
|
+
import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
|
|
1010
|
+
import React12, { useMemo as useMemo3 } from "react";
|
|
361
1011
|
import { Treegrid as Treegrid2 } from "@dxos/react-ui";
|
|
362
1012
|
|
|
363
1013
|
// src/components/Tree/TreeContext.tsx
|
|
364
|
-
import { createContext as
|
|
1014
|
+
import { createContext as createContext7, useContext } from "react";
|
|
365
1015
|
import { raise } from "@dxos/debug";
|
|
366
|
-
var TreeContext = /* @__PURE__ */
|
|
1016
|
+
var TreeContext = /* @__PURE__ */ createContext7(null);
|
|
367
1017
|
var TreeProvider = TreeContext.Provider;
|
|
368
1018
|
var useTree = () => useContext(TreeContext) ?? raise(new Error("TreeContext not found"));
|
|
369
1019
|
|
|
370
1020
|
// src/components/Tree/TreeItem.tsx
|
|
1021
|
+
import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
|
|
371
1022
|
import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
372
1023
|
import { draggable as draggable2, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
373
|
-
import {
|
|
1024
|
+
import { useAtomValue } from "@effect-atom/atom-react";
|
|
374
1025
|
import * as Schema from "effect/Schema";
|
|
375
|
-
import
|
|
1026
|
+
import React11, { memo as memo3, useCallback as useCallback6, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
|
|
376
1027
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
377
|
-
import { TreeItem as NaturalTreeItem, Treegrid } from "@dxos/react-ui";
|
|
378
|
-
import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls } from "@dxos/ui-theme";
|
|
1028
|
+
import { TreeItem as NaturalTreeItem, Treegrid, TREEGRID_PARENT_OF_SEPARATOR } from "@dxos/react-ui";
|
|
1029
|
+
import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx7 } from "@dxos/ui-theme";
|
|
379
1030
|
|
|
380
1031
|
// src/components/Tree/helpers.ts
|
|
381
1032
|
var DEFAULT_INDENTATION = 8;
|
|
@@ -384,19 +1035,19 @@ var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
|
|
|
384
1035
|
});
|
|
385
1036
|
|
|
386
1037
|
// src/components/Tree/TreeItemHeading.tsx
|
|
387
|
-
import
|
|
388
|
-
import { Button, Icon as
|
|
1038
|
+
import React9, { forwardRef as forwardRef4, memo, useCallback as useCallback5 } from "react";
|
|
1039
|
+
import { Button as Button2, Icon as Icon4, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
389
1040
|
import { TextTooltip } from "@dxos/react-ui-text-tooltip";
|
|
390
1041
|
import { getStyles } from "@dxos/ui-theme";
|
|
391
|
-
var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */
|
|
1042
|
+
var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef4(({ label, className, icon, iconHue, disabled, current, onSelect }, forwardedRef) => {
|
|
392
1043
|
const { t } = useTranslation2();
|
|
393
1044
|
const styles = iconHue ? getStyles(iconHue) : void 0;
|
|
394
|
-
const handleSelect =
|
|
1045
|
+
const handleSelect = useCallback5((event) => {
|
|
395
1046
|
onSelect?.(event.altKey);
|
|
396
1047
|
}, [
|
|
397
1048
|
onSelect
|
|
398
1049
|
]);
|
|
399
|
-
const handleButtonKeydown =
|
|
1050
|
+
const handleButtonKeydown = useCallback5((event) => {
|
|
400
1051
|
if (event.key === " " || event.key === "Enter") {
|
|
401
1052
|
event.preventDefault();
|
|
402
1053
|
event.stopPropagation();
|
|
@@ -405,19 +1056,18 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ label,
|
|
|
405
1056
|
}, [
|
|
406
1057
|
onSelect
|
|
407
1058
|
]);
|
|
408
|
-
return /* @__PURE__ */
|
|
1059
|
+
return /* @__PURE__ */ React9.createElement(TextTooltip, {
|
|
409
1060
|
text: toLocalizedString(label, t),
|
|
410
1061
|
side: "bottom",
|
|
411
1062
|
truncateQuery: "span[data-tooltip]",
|
|
412
1063
|
onlyWhenTruncating: true,
|
|
413
1064
|
asChild: true,
|
|
414
1065
|
ref: forwardedRef
|
|
415
|
-
}, /* @__PURE__ */
|
|
1066
|
+
}, /* @__PURE__ */ React9.createElement(Button2, {
|
|
416
1067
|
"data-testid": "treeItem.heading",
|
|
417
1068
|
variant: "ghost",
|
|
418
|
-
density: "fine",
|
|
419
1069
|
classNames: [
|
|
420
|
-
"grow gap-2
|
|
1070
|
+
"grow gap-2 ps-0.5 hover:bg-transparent dark:hover:bg-transparent",
|
|
421
1071
|
"disabled:cursor-default disabled:opacity-100",
|
|
422
1072
|
className
|
|
423
1073
|
],
|
|
@@ -427,33 +1077,33 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ label,
|
|
|
427
1077
|
...current && {
|
|
428
1078
|
"aria-current": "location"
|
|
429
1079
|
}
|
|
430
|
-
}, icon && /* @__PURE__ */
|
|
431
|
-
icon: icon ?? "ph--placeholder--regular",
|
|
1080
|
+
}, icon && /* @__PURE__ */ React9.createElement(Icon4, {
|
|
432
1081
|
size: 5,
|
|
1082
|
+
icon: icon ?? "ph--placeholder--regular",
|
|
433
1083
|
classNames: [
|
|
434
|
-
"
|
|
435
|
-
styles?.
|
|
1084
|
+
"my-1",
|
|
1085
|
+
styles?.foreground
|
|
436
1086
|
]
|
|
437
|
-
}), /* @__PURE__ */
|
|
438
|
-
className: "flex-1
|
|
1087
|
+
}), /* @__PURE__ */ React9.createElement("span", {
|
|
1088
|
+
className: "flex-1 w-0 truncate text-start font-normal",
|
|
439
1089
|
"data-tooltip": true
|
|
440
1090
|
}, toLocalizedString(label, t))));
|
|
441
1091
|
}));
|
|
442
1092
|
|
|
443
1093
|
// src/components/Tree/TreeItemToggle.tsx
|
|
444
|
-
import
|
|
1094
|
+
import React10, { forwardRef as forwardRef5, memo as memo2 } from "react";
|
|
445
1095
|
import { IconButton as IconButton2 } from "@dxos/react-ui";
|
|
446
|
-
var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */
|
|
447
|
-
return /* @__PURE__ */
|
|
1096
|
+
var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef5(({ classNames, open, isBranch, hidden, ...props }, forwardedRef) => {
|
|
1097
|
+
return /* @__PURE__ */ React10.createElement(IconButton2, {
|
|
448
1098
|
ref: forwardedRef,
|
|
449
1099
|
"data-testid": "treeItem.toggle",
|
|
450
1100
|
"aria-expanded": open,
|
|
451
1101
|
variant: "ghost",
|
|
452
1102
|
density: "fine",
|
|
453
1103
|
classNames: [
|
|
454
|
-
"
|
|
455
|
-
"[&_svg]:transition-
|
|
456
|
-
open
|
|
1104
|
+
"h-full w-6 px-0",
|
|
1105
|
+
"[&_svg]:transition-transform [&_svg]:duration-200",
|
|
1106
|
+
open ? "[&_svg]:rotate-90" : "[&_svg]:rotate-0",
|
|
457
1107
|
hidden ? "hidden" : !isBranch && "invisible",
|
|
458
1108
|
classNames
|
|
459
1109
|
],
|
|
@@ -476,26 +1126,26 @@ var TreeDataSchema = Schema.Struct({
|
|
|
476
1126
|
item: Schema.Any
|
|
477
1127
|
});
|
|
478
1128
|
var isTreeData = (data) => Schema.is(TreeDataSchema)(data);
|
|
479
|
-
var RawTreeItem = ({ item, path:
|
|
480
|
-
const rowRef =
|
|
481
|
-
const buttonRef =
|
|
482
|
-
const openRef =
|
|
483
|
-
const cancelExpandRef =
|
|
484
|
-
const [_state, setState] =
|
|
485
|
-
const [instruction, setInstruction] =
|
|
486
|
-
const [menuOpen, setMenuOpen] =
|
|
487
|
-
const {
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
..._path,
|
|
492
|
-
id
|
|
1129
|
+
var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: draggableProp, renderColumns: Columns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
|
|
1130
|
+
const rowRef = useRef3(null);
|
|
1131
|
+
const buttonRef = useRef3(null);
|
|
1132
|
+
const openRef = useRef3(false);
|
|
1133
|
+
const cancelExpandRef = useRef3(null);
|
|
1134
|
+
const [_state, setState] = useState4("idle");
|
|
1135
|
+
const [instruction, setInstruction] = useState4(null);
|
|
1136
|
+
const [menuOpen, setMenuOpen] = useState4(false);
|
|
1137
|
+
const { itemProps: itemPropsAtom, childIds: childIdsAtom, itemOpen: itemOpenAtom, itemCurrent: itemCurrentAtom } = useTree();
|
|
1138
|
+
const path = useMemo2(() => [
|
|
1139
|
+
...pathProp,
|
|
1140
|
+
item.id
|
|
493
1141
|
], [
|
|
494
|
-
|
|
495
|
-
id
|
|
1142
|
+
pathProp,
|
|
1143
|
+
item.id
|
|
496
1144
|
]);
|
|
497
|
-
const
|
|
498
|
-
const
|
|
1145
|
+
const { id, parentOf, draggable: itemDraggable, droppable: itemDroppable, label, className, headingClassName, icon, iconHue, disabled, testId } = useAtomValue(itemPropsAtom(path));
|
|
1146
|
+
const childIds = useAtomValue(childIdsAtom(item.id));
|
|
1147
|
+
const open = useAtomValue(itemOpenAtom(path));
|
|
1148
|
+
const current = useAtomValue(itemCurrentAtom(path));
|
|
499
1149
|
const level = path.length - levelOffset;
|
|
500
1150
|
const isBranch = !!parentOf;
|
|
501
1151
|
const mode = last ? "last-in-group" : open ? "expanded" : "standard";
|
|
@@ -503,122 +1153,132 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
503
1153
|
item,
|
|
504
1154
|
path
|
|
505
1155
|
}) ?? true;
|
|
506
|
-
const
|
|
1156
|
+
const data = {
|
|
1157
|
+
id,
|
|
1158
|
+
path,
|
|
1159
|
+
item
|
|
1160
|
+
};
|
|
1161
|
+
const shouldSeedNativeDragData = typeof document !== "undefined" && document.body.hasAttribute("data-platform");
|
|
1162
|
+
const cancelExpand = useCallback6(() => {
|
|
507
1163
|
if (cancelExpandRef.current) {
|
|
508
1164
|
clearTimeout(cancelExpandRef.current);
|
|
509
1165
|
cancelExpandRef.current = null;
|
|
510
1166
|
}
|
|
511
1167
|
}, []);
|
|
512
|
-
|
|
513
|
-
|
|
1168
|
+
const isItemDraggable = draggableProp && itemDraggable !== false;
|
|
1169
|
+
const isItemDroppable = itemDroppable !== false;
|
|
1170
|
+
const nativeDragText = id;
|
|
1171
|
+
useEffect4(() => {
|
|
1172
|
+
if (!draggableProp) {
|
|
514
1173
|
return;
|
|
515
1174
|
}
|
|
516
|
-
invariant2(buttonRef.current, void 0, {
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
]
|
|
524
|
-
});
|
|
525
|
-
const data = {
|
|
526
|
-
id,
|
|
527
|
-
path,
|
|
528
|
-
item
|
|
529
|
-
};
|
|
530
|
-
return combine2(
|
|
531
|
-
draggable2({
|
|
532
|
-
element: buttonRef.current,
|
|
533
|
-
getInitialData: () => data,
|
|
534
|
-
onDragStart: () => {
|
|
535
|
-
setState("dragging");
|
|
536
|
-
if (open) {
|
|
537
|
-
openRef.current = true;
|
|
538
|
-
onOpenChange?.({
|
|
539
|
-
item,
|
|
540
|
-
path,
|
|
541
|
-
open: false
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
},
|
|
545
|
-
onDrop: () => {
|
|
546
|
-
setState("idle");
|
|
547
|
-
if (openRef.current) {
|
|
548
|
-
onOpenChange?.({
|
|
549
|
-
item,
|
|
550
|
-
path,
|
|
551
|
-
open: true
|
|
552
|
-
});
|
|
553
|
-
}
|
|
1175
|
+
invariant2(buttonRef.current, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 70, S: void 0, A: ["buttonRef.current", ""] });
|
|
1176
|
+
const makeDraggable = () => draggable2({
|
|
1177
|
+
element: buttonRef.current,
|
|
1178
|
+
getInitialData: () => data,
|
|
1179
|
+
getInitialDataForExternal: () => {
|
|
1180
|
+
if (!shouldSeedNativeDragData) {
|
|
1181
|
+
return {};
|
|
554
1182
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
"make-child"
|
|
568
|
-
]
|
|
569
|
-
});
|
|
570
|
-
},
|
|
571
|
-
canDrop: ({ source }) => {
|
|
572
|
-
const _canDrop = canDrop ?? (() => true);
|
|
573
|
-
return source.element !== buttonRef.current && _canDrop({
|
|
574
|
-
source: source.data,
|
|
575
|
-
target: data
|
|
1183
|
+
return {
|
|
1184
|
+
"text/plain": nativeDragText
|
|
1185
|
+
};
|
|
1186
|
+
},
|
|
1187
|
+
onDragStart: () => {
|
|
1188
|
+
setState("dragging");
|
|
1189
|
+
if (open) {
|
|
1190
|
+
openRef.current = true;
|
|
1191
|
+
onOpenChange?.({
|
|
1192
|
+
item,
|
|
1193
|
+
path,
|
|
1194
|
+
open: false
|
|
576
1195
|
});
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
onDrop: () => {
|
|
1199
|
+
setState("idle");
|
|
1200
|
+
if (openRef.current) {
|
|
1201
|
+
onOpenChange?.({
|
|
1202
|
+
item,
|
|
1203
|
+
path,
|
|
1204
|
+
open: true
|
|
585
1205
|
});
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
});
|
|
1209
|
+
if (!isItemDroppable) {
|
|
1210
|
+
return isItemDraggable ? makeDraggable() : void 0;
|
|
1211
|
+
}
|
|
1212
|
+
const dropTarget = dropTargetForElements2({
|
|
1213
|
+
element: buttonRef.current,
|
|
1214
|
+
getData: ({ input, element }) => {
|
|
1215
|
+
return attachInstruction(data, {
|
|
1216
|
+
input,
|
|
1217
|
+
element,
|
|
1218
|
+
indentPerLevel: DEFAULT_INDENTATION,
|
|
1219
|
+
currentLevel: level,
|
|
1220
|
+
mode,
|
|
1221
|
+
block: isBranch ? [] : [
|
|
1222
|
+
"make-child"
|
|
1223
|
+
]
|
|
1224
|
+
});
|
|
1225
|
+
},
|
|
1226
|
+
canDrop: ({ source }) => {
|
|
1227
|
+
const _canDrop = canDrop ?? (() => true);
|
|
1228
|
+
return source.element !== buttonRef.current && _canDrop({
|
|
1229
|
+
source: source.data,
|
|
1230
|
+
target: data
|
|
1231
|
+
});
|
|
1232
|
+
},
|
|
1233
|
+
getIsSticky: () => true,
|
|
1234
|
+
onDrag: ({ self, source }) => {
|
|
1235
|
+
const desired = extractInstruction(self.data);
|
|
1236
|
+
const block = desired && blockInstruction?.({
|
|
1237
|
+
instruction: desired,
|
|
1238
|
+
source: source.data,
|
|
1239
|
+
target: data
|
|
1240
|
+
});
|
|
1241
|
+
const instruction2 = block && desired.type !== "instruction-blocked" ? {
|
|
1242
|
+
type: "instruction-blocked",
|
|
1243
|
+
desired
|
|
1244
|
+
} : desired;
|
|
1245
|
+
if (source.data.id !== id) {
|
|
1246
|
+
if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
|
|
1247
|
+
cancelExpandRef.current = setTimeout(() => {
|
|
1248
|
+
onOpenChange?.({
|
|
1249
|
+
item,
|
|
1250
|
+
path,
|
|
1251
|
+
open: true
|
|
1252
|
+
});
|
|
1253
|
+
}, 500);
|
|
608
1254
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
setInstruction(
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
|
|
1255
|
+
if (instruction2?.type !== "make-child") {
|
|
1256
|
+
cancelExpand();
|
|
1257
|
+
}
|
|
1258
|
+
setInstruction(instruction2);
|
|
1259
|
+
} else if (instruction2?.type === "reparent") {
|
|
1260
|
+
setInstruction(instruction2);
|
|
1261
|
+
} else {
|
|
616
1262
|
setInstruction(null);
|
|
617
1263
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
1264
|
+
},
|
|
1265
|
+
onDragLeave: () => {
|
|
1266
|
+
cancelExpand();
|
|
1267
|
+
setInstruction(null);
|
|
1268
|
+
},
|
|
1269
|
+
onDrop: () => {
|
|
1270
|
+
cancelExpand();
|
|
1271
|
+
setInstruction(null);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
if (!isItemDraggable) {
|
|
1275
|
+
return dropTarget;
|
|
1276
|
+
}
|
|
1277
|
+
return combine2(makeDraggable(), dropTarget);
|
|
620
1278
|
}, [
|
|
621
|
-
|
|
1279
|
+
draggableProp,
|
|
1280
|
+
isItemDraggable,
|
|
1281
|
+
isItemDroppable,
|
|
622
1282
|
item,
|
|
623
1283
|
id,
|
|
624
1284
|
mode,
|
|
@@ -627,10 +1287,10 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
627
1287
|
blockInstruction,
|
|
628
1288
|
canDrop
|
|
629
1289
|
]);
|
|
630
|
-
|
|
1290
|
+
useEffect4(() => () => cancelExpand(), [
|
|
631
1291
|
cancelExpand
|
|
632
1292
|
]);
|
|
633
|
-
const handleOpenToggle =
|
|
1293
|
+
const handleOpenToggle = useCallback6(() => onOpenChange?.({
|
|
634
1294
|
item,
|
|
635
1295
|
path,
|
|
636
1296
|
open: !open
|
|
@@ -640,7 +1300,7 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
640
1300
|
path,
|
|
641
1301
|
open
|
|
642
1302
|
]);
|
|
643
|
-
const handleSelect =
|
|
1303
|
+
const handleSelect = useCallback6((option = false) => {
|
|
644
1304
|
if (isBranch && (option || current)) {
|
|
645
1305
|
handleOpenToggle();
|
|
646
1306
|
} else if (canSelectItem) {
|
|
@@ -665,7 +1325,7 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
665
1325
|
handleOpenToggle,
|
|
666
1326
|
onSelect
|
|
667
1327
|
]);
|
|
668
|
-
const handleKeyDown =
|
|
1328
|
+
const handleKeyDown = useCallback6((event) => {
|
|
669
1329
|
switch (event.key) {
|
|
670
1330
|
case "ArrowRight":
|
|
671
1331
|
case "ArrowLeft":
|
|
@@ -678,44 +1338,56 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
678
1338
|
handleOpenToggle,
|
|
679
1339
|
handleSelect
|
|
680
1340
|
]);
|
|
681
|
-
|
|
1341
|
+
const handleItemHover = useCallback6(() => {
|
|
1342
|
+
onItemHover?.({
|
|
1343
|
+
item
|
|
1344
|
+
});
|
|
1345
|
+
}, [
|
|
1346
|
+
onItemHover,
|
|
1347
|
+
item
|
|
1348
|
+
]);
|
|
1349
|
+
const handleContextMenu = useCallback6((event) => {
|
|
1350
|
+
event.preventDefault();
|
|
1351
|
+
setMenuOpen(true);
|
|
1352
|
+
}, [
|
|
1353
|
+
setMenuOpen
|
|
1354
|
+
]);
|
|
1355
|
+
const childProps = {
|
|
1356
|
+
draggable: draggableProp,
|
|
1357
|
+
renderColumns: Columns,
|
|
1358
|
+
blockInstruction,
|
|
1359
|
+
canDrop,
|
|
1360
|
+
canSelect,
|
|
1361
|
+
onItemHover,
|
|
1362
|
+
onOpenChange,
|
|
1363
|
+
onSelect
|
|
1364
|
+
};
|
|
1365
|
+
return /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement(Treegrid.Row, {
|
|
682
1366
|
ref: rowRef,
|
|
683
1367
|
key: id,
|
|
684
1368
|
id,
|
|
685
1369
|
"aria-labelledby": `${id}__label`,
|
|
686
|
-
parentOf: parentOf?.join(
|
|
687
|
-
classNames: [
|
|
688
|
-
"grid grid-cols-subgrid col-[tree-row] mbs-0.5 aria-[current]:bg-activeSurface",
|
|
689
|
-
hoverableControls,
|
|
690
|
-
hoverableFocusedKeyboardControls,
|
|
691
|
-
hoverableFocusedWithinControls,
|
|
692
|
-
hoverableDescriptionIcons,
|
|
693
|
-
ghostHover,
|
|
694
|
-
ghostFocusWithin,
|
|
695
|
-
className
|
|
696
|
-
],
|
|
1370
|
+
parentOf: parentOf?.join(TREEGRID_PARENT_OF_SEPARATOR),
|
|
697
1371
|
"data-object-id": id,
|
|
698
1372
|
"data-testid": testId,
|
|
699
1373
|
// NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
|
|
700
1374
|
// without alerting the user (except for in the correct link element). See also:
|
|
701
1375
|
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current#description
|
|
702
1376
|
"aria-current": current ? "" : void 0,
|
|
1377
|
+
classNames: mx7("grid grid-cols-subgrid col-[tree-row] mt-0.5 is-current:bg-current-surface", hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableDescriptionIcons, ghostFocusWithin, ghostHover, className),
|
|
703
1378
|
onKeyDown: handleKeyDown,
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
}, /* @__PURE__ */ React7.createElement("div", {
|
|
709
|
-
role: "none",
|
|
1379
|
+
onMouseEnter: handleItemHover,
|
|
1380
|
+
onContextMenu: handleContextMenu
|
|
1381
|
+
}, /* @__PURE__ */ React11.createElement("div", {
|
|
710
1382
|
className: "indent relative grid grid-cols-subgrid col-[tree-row]",
|
|
711
1383
|
style: paddingIndentation(level)
|
|
712
|
-
}, /* @__PURE__ */
|
|
1384
|
+
}, /* @__PURE__ */ React11.createElement(Treegrid.Cell, {
|
|
713
1385
|
classNames: "flex items-center"
|
|
714
|
-
}, /* @__PURE__ */
|
|
1386
|
+
}, /* @__PURE__ */ React11.createElement(TreeItemToggle, {
|
|
715
1387
|
isBranch,
|
|
716
1388
|
open,
|
|
717
1389
|
onClick: handleOpenToggle
|
|
718
|
-
}), /* @__PURE__ */
|
|
1390
|
+
}), /* @__PURE__ */ React11.createElement(TreeItemHeading, {
|
|
719
1391
|
disabled,
|
|
720
1392
|
current,
|
|
721
1393
|
label,
|
|
@@ -724,46 +1396,41 @@ var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _dragg
|
|
|
724
1396
|
iconHue,
|
|
725
1397
|
onSelect: handleSelect,
|
|
726
1398
|
ref: buttonRef
|
|
727
|
-
})), Columns && /* @__PURE__ */
|
|
1399
|
+
})), Columns && /* @__PURE__ */ React11.createElement(Columns, {
|
|
728
1400
|
item,
|
|
729
1401
|
path,
|
|
730
1402
|
open,
|
|
731
1403
|
menuOpen,
|
|
732
1404
|
setMenuOpen
|
|
733
|
-
}), instruction && /* @__PURE__ */
|
|
1405
|
+
}), instruction && /* @__PURE__ */ React11.createElement(NaturalTreeItem.DropIndicator, {
|
|
734
1406
|
instruction,
|
|
735
1407
|
gap: 2
|
|
736
|
-
}))), open &&
|
|
737
|
-
key:
|
|
738
|
-
|
|
1408
|
+
}))), open && childIds.map((childId, index) => /* @__PURE__ */ React11.createElement(TreeItemById, {
|
|
1409
|
+
key: childId,
|
|
1410
|
+
id: childId,
|
|
739
1411
|
path,
|
|
740
|
-
last: index ===
|
|
741
|
-
|
|
742
|
-
renderColumns: Columns,
|
|
743
|
-
blockInstruction,
|
|
744
|
-
canDrop,
|
|
745
|
-
canSelect,
|
|
746
|
-
onOpenChange,
|
|
747
|
-
onSelect
|
|
1412
|
+
last: index === childIds.length - 1,
|
|
1413
|
+
...childProps
|
|
748
1414
|
})));
|
|
749
1415
|
};
|
|
750
1416
|
var TreeItem = /* @__PURE__ */ memo3(RawTreeItem);
|
|
1417
|
+
var RawTreeItemById = ({ id, ...props }) => {
|
|
1418
|
+
const { item: itemAtom } = useTree();
|
|
1419
|
+
const item = useAtomValue(itemAtom(id));
|
|
1420
|
+
if (!item) {
|
|
1421
|
+
return null;
|
|
1422
|
+
}
|
|
1423
|
+
return /* @__PURE__ */ React11.createElement(TreeItem, {
|
|
1424
|
+
item,
|
|
1425
|
+
...props
|
|
1426
|
+
});
|
|
1427
|
+
};
|
|
1428
|
+
var TreeItemById = /* @__PURE__ */ memo3(RawTreeItemById);
|
|
751
1429
|
|
|
752
1430
|
// src/components/Tree/Tree.tsx
|
|
753
|
-
var Tree = ({
|
|
754
|
-
const
|
|
755
|
-
|
|
756
|
-
getProps,
|
|
757
|
-
useIsOpen,
|
|
758
|
-
useIsCurrent
|
|
759
|
-
}), [
|
|
760
|
-
useItems,
|
|
761
|
-
getProps,
|
|
762
|
-
useIsOpen,
|
|
763
|
-
useIsCurrent
|
|
764
|
-
]);
|
|
765
|
-
const items = useItems(root);
|
|
766
|
-
const treePath = useMemo2(() => path ? [
|
|
1431
|
+
var Tree = ({ classNames, model, rootId, path, id, draggable: draggable3 = false, gridTemplateColumns = "[tree-row-start] 1fr min-content [tree-row-end]", levelOffset, renderColumns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
|
|
1432
|
+
const childIds = useAtomValue2(model.childIds(rootId));
|
|
1433
|
+
const treePath = useMemo3(() => path ? [
|
|
767
1434
|
...path,
|
|
768
1435
|
id
|
|
769
1436
|
] : [
|
|
@@ -772,15 +1439,7 @@ var Tree = ({ root, path, id, useItems, getProps, useIsOpen, useIsCurrent, dragg
|
|
|
772
1439
|
id,
|
|
773
1440
|
path
|
|
774
1441
|
]);
|
|
775
|
-
|
|
776
|
-
gridTemplateColumns,
|
|
777
|
-
classNames
|
|
778
|
-
}, /* @__PURE__ */ React8.createElement(TreeProvider, {
|
|
779
|
-
value: context
|
|
780
|
-
}, items.map((item, index) => /* @__PURE__ */ React8.createElement(TreeItem, {
|
|
781
|
-
key: item.id,
|
|
782
|
-
item,
|
|
783
|
-
last: index === items.length - 1,
|
|
1442
|
+
const childProps = {
|
|
784
1443
|
path: treePath,
|
|
785
1444
|
levelOffset,
|
|
786
1445
|
draggable: draggable3,
|
|
@@ -789,7 +1448,19 @@ var Tree = ({ root, path, id, useItems, getProps, useIsOpen, useIsCurrent, dragg
|
|
|
789
1448
|
canDrop,
|
|
790
1449
|
canSelect,
|
|
791
1450
|
onOpenChange,
|
|
792
|
-
onSelect
|
|
1451
|
+
onSelect,
|
|
1452
|
+
onItemHover
|
|
1453
|
+
};
|
|
1454
|
+
return /* @__PURE__ */ React12.createElement(Treegrid2.Root, {
|
|
1455
|
+
gridTemplateColumns,
|
|
1456
|
+
classNames
|
|
1457
|
+
}, /* @__PURE__ */ React12.createElement(TreeProvider, {
|
|
1458
|
+
value: model
|
|
1459
|
+
}, childIds.map((childId, index) => /* @__PURE__ */ React12.createElement(TreeItemById, {
|
|
1460
|
+
key: childId,
|
|
1461
|
+
id: childId,
|
|
1462
|
+
last: index === childIds.length - 1,
|
|
1463
|
+
...childProps
|
|
793
1464
|
}))));
|
|
794
1465
|
};
|
|
795
1466
|
|
|
@@ -810,13 +1481,27 @@ var Path = {
|
|
|
810
1481
|
};
|
|
811
1482
|
export {
|
|
812
1483
|
Accordion,
|
|
1484
|
+
Combobox,
|
|
1485
|
+
DEFAULT_INDENTATION,
|
|
813
1486
|
List,
|
|
1487
|
+
Listbox,
|
|
814
1488
|
Path,
|
|
1489
|
+
Picker,
|
|
1490
|
+
Row,
|
|
1491
|
+
RowList,
|
|
815
1492
|
Tree,
|
|
816
1493
|
TreeDataSchema,
|
|
817
1494
|
TreeItem,
|
|
1495
|
+
TreeItemById,
|
|
1496
|
+
TreeItemToggle,
|
|
818
1497
|
TreeProvider,
|
|
1498
|
+
createListboxScope,
|
|
1499
|
+
createRowListScope,
|
|
819
1500
|
isTreeData,
|
|
1501
|
+
paddingIndentation,
|
|
1502
|
+
usePickerInputContext,
|
|
1503
|
+
usePickerItemContext,
|
|
1504
|
+
useRowListSelection,
|
|
820
1505
|
useTree
|
|
821
1506
|
};
|
|
822
1507
|
//# sourceMappingURL=index.mjs.map
|