@dxos/react-ui-list 0.8.4-main.ead640a → 0.8.4-main.effb148878

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