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