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