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

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