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