@dxos/react-ui-list 0.8.4-main.406dc2a → 0.8.4-main.4a85c3132b

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 (47) hide show
  1. package/dist/lib/browser/index.mjs +657 -712
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +657 -712
  5. package/dist/lib/node-esm/index.mjs.map +3 -3
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Accordion/Accordion.stories.d.ts +0 -3
  8. package/dist/types/src/components/Accordion/Accordion.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/List/List.d.ts +2 -2
  10. package/dist/types/src/components/List/List.d.ts.map +1 -1
  11. package/dist/types/src/components/List/List.stories.d.ts +2 -2
  12. package/dist/types/src/components/List/List.stories.d.ts.map +1 -1
  13. package/dist/types/src/components/List/ListItem.d.ts +2 -2
  14. package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
  15. package/dist/types/src/components/List/ListRoot.d.ts +2 -2
  16. package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
  17. package/dist/types/src/components/Tree/Tree.d.ts +10 -6
  18. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
  19. package/dist/types/src/components/Tree/Tree.stories.d.ts +9 -28
  20. package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Tree/TreeContext.d.ts +18 -9
  22. package/dist/types/src/components/Tree/TreeContext.d.ts.map +1 -1
  23. package/dist/types/src/components/Tree/TreeItem.d.ts +20 -3
  24. package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
  25. package/dist/types/src/components/Tree/TreeItemHeading.d.ts +1 -1
  26. package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
  27. package/dist/types/src/components/Tree/index.d.ts +2 -0
  28. package/dist/types/src/components/Tree/index.d.ts.map +1 -1
  29. package/dist/types/src/components/Tree/testing.d.ts +2 -2
  30. package/dist/types/src/components/Tree/testing.d.ts.map +1 -1
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +30 -28
  33. package/src/components/Accordion/Accordion.stories.tsx +2 -5
  34. package/src/components/Accordion/AccordionItem.tsx +3 -3
  35. package/src/components/Accordion/AccordionRoot.tsx +1 -1
  36. package/src/components/List/List.stories.tsx +29 -17
  37. package/src/components/List/ListItem.tsx +13 -13
  38. package/src/components/List/ListRoot.tsx +2 -2
  39. package/src/components/List/testing.ts +2 -2
  40. package/src/components/Tree/Tree.stories.tsx +150 -60
  41. package/src/components/Tree/Tree.tsx +39 -41
  42. package/src/components/Tree/TreeContext.tsx +15 -8
  43. package/src/components/Tree/TreeItem.tsx +99 -51
  44. package/src/components/Tree/TreeItemHeading.tsx +9 -5
  45. package/src/components/Tree/TreeItemToggle.tsx +1 -1
  46. package/src/components/Tree/index.ts +2 -0
  47. package/src/components/Tree/testing.ts +4 -3
@@ -1,85 +1,63 @@
1
1
  // src/components/Accordion/AccordionItem.tsx
2
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
3
2
  import * as AccordionPrimitive2 from "@radix-ui/react-accordion";
4
3
  import { createContext as createContext2 } from "@radix-ui/react-context";
5
4
  import React2 from "react";
6
5
  import { Icon } from "@dxos/react-ui";
7
- import { mx as mx2 } from "@dxos/react-ui-theme";
6
+ import { mx as mx2 } from "@dxos/ui-theme";
8
7
 
9
8
  // src/components/Accordion/AccordionRoot.tsx
10
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
11
9
  import * as AccordionPrimitive from "@radix-ui/react-accordion";
12
10
  import { createContext } from "@radix-ui/react-context";
13
11
  import React from "react";
14
- import { mx } from "@dxos/react-ui-theme";
12
+ import { mx } from "@dxos/ui-theme";
15
13
  var ACCORDION_NAME = "Accordion";
16
14
  var [AccordionProvider, useAccordionContext] = createContext(ACCORDION_NAME);
17
15
  var defaultGetId = (item) => item?.id;
18
16
  var AccordionRoot = ({ classNames, items, getId = defaultGetId, children, value, defaultValue, onValueChange }) => {
19
- var _effect = _useSignals();
20
- try {
21
- return /* @__PURE__ */ React.createElement(AccordionProvider, {
22
- getId
23
- }, /* @__PURE__ */ React.createElement(AccordionPrimitive.Root, {
24
- type: "multiple",
25
- value,
26
- defaultValue,
27
- onValueChange,
28
- className: mx(classNames)
29
- }, children?.({
30
- items: items ?? []
31
- })));
32
- } finally {
33
- _effect.f();
34
- }
17
+ return /* @__PURE__ */ React.createElement(AccordionProvider, {
18
+ getId
19
+ }, /* @__PURE__ */ React.createElement(AccordionPrimitive.Root, {
20
+ type: "multiple",
21
+ value,
22
+ defaultValue,
23
+ onValueChange,
24
+ className: mx(classNames)
25
+ }, children?.({
26
+ items: items ?? []
27
+ })));
35
28
  };
36
29
 
37
30
  // src/components/Accordion/AccordionItem.tsx
38
31
  var ACCORDION_ITEM_NAME = "AccordionItem";
39
32
  var [AccordionItemProvider, useDxAccordionItemContext] = createContext2(ACCORDION_ITEM_NAME);
40
33
  var AccordionItem = ({ children, classNames, item }) => {
41
- var _effect = _useSignals2();
42
- try {
43
- const { getId } = useAccordionContext(ACCORDION_ITEM_NAME);
44
- return /* @__PURE__ */ React2.createElement(AccordionItemProvider, {
45
- item
46
- }, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Item, {
47
- value: getId(item),
48
- className: mx2("overflow-hidden", classNames)
49
- }, children));
50
- } finally {
51
- _effect.f();
52
- }
34
+ const { getId } = useAccordionContext(ACCORDION_ITEM_NAME);
35
+ return /* @__PURE__ */ React2.createElement(AccordionItemProvider, {
36
+ item
37
+ }, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Item, {
38
+ value: getId(item),
39
+ className: mx2("overflow-hidden", classNames)
40
+ }, children));
53
41
  };
54
42
  var AccordionItemHeader = ({ classNames, children, ...props }) => {
55
- var _effect = _useSignals2();
56
- try {
57
- return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Header, {
58
- ...props,
59
- className: mx2(classNames)
60
- }, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Trigger, {
61
- className: "group flex items-center p-2 dx-focus-ring-inset is-full text-start"
62
- }, children, /* @__PURE__ */ React2.createElement(Icon, {
63
- icon: "ph--caret-right--regular",
64
- size: 4,
65
- classNames: "transition-transform duration-200 group-data-[state=open]:rotate-90"
66
- })));
67
- } finally {
68
- _effect.f();
69
- }
43
+ return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Header, {
44
+ ...props,
45
+ className: mx2(classNames)
46
+ }, /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Trigger, {
47
+ className: "group flex items-center p-2 dx-focus-ring-inset w-full text-start"
48
+ }, children, /* @__PURE__ */ React2.createElement(Icon, {
49
+ icon: "ph--caret-right--regular",
50
+ size: 4,
51
+ classNames: "transition-transform duration-200 group-data-[state=open]:rotate-90"
52
+ })));
70
53
  };
71
54
  var AccordionItemBody = ({ children, classNames }) => {
72
- var _effect = _useSignals2();
73
- try {
74
- return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Content, {
75
- className: "overflow-hidden data-[state=closed]:animate-slideUp data-[state=open]:animate-slideDown"
76
- }, /* @__PURE__ */ React2.createElement("div", {
77
- role: "none",
78
- className: mx2("p-2", classNames)
79
- }, children));
80
- } finally {
81
- _effect.f();
82
- }
55
+ return /* @__PURE__ */ React2.createElement(AccordionPrimitive2.Content, {
56
+ className: "overflow-hidden data-[state=closed]:animate-slide-up data-[state=open]:animate-slide-down"
57
+ }, /* @__PURE__ */ React2.createElement("div", {
58
+ role: "none",
59
+ className: mx2("p-2", classNames)
60
+ }, children));
83
61
  };
84
62
 
85
63
  // src/components/Accordion/Accordion.tsx
@@ -91,7 +69,6 @@ var Accordion = {
91
69
  };
92
70
 
93
71
  // src/components/List/ListItem.tsx
94
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
95
72
  import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
96
73
  import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
97
74
  import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
@@ -101,10 +78,9 @@ import React4, { useEffect as useEffect2, useRef, useState as useState2 } from "
101
78
  import { createPortal } from "react-dom";
102
79
  import { invariant } from "@dxos/invariant";
103
80
  import { IconButton, ListItem as NaturalListItem, useTranslation } from "@dxos/react-ui";
104
- import { mx as mx3 } from "@dxos/react-ui-theme";
81
+ import { mx as mx3, osTranslations } from "@dxos/ui-theme";
105
82
 
106
83
  // src/components/List/ListRoot.tsx
107
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
108
84
  import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
109
85
  import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
110
86
  import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
@@ -114,68 +90,63 @@ var LIST_NAME = "List";
114
90
  var [ListProvider, useListContext] = createContext3(LIST_NAME);
115
91
  var defaultGetId2 = (item) => item?.id;
116
92
  var ListRoot = ({ children, items, isItem, getId = defaultGetId2, onMove, ...props }) => {
117
- var _effect = _useSignals3();
118
- try {
119
- const isEqual = useCallback((a, b) => {
120
- const idA = getId?.(a);
121
- const idB = getId?.(b);
122
- if (idA !== void 0 && idB !== void 0) {
123
- return idA === idB;
124
- } else {
125
- return a === b;
126
- }
127
- }, [
128
- getId
129
- ]);
130
- const [state, setState] = useState(idle);
131
- useEffect(() => {
132
- if (!items) {
133
- return;
134
- }
135
- return monitorForElements({
136
- canMonitor: ({ source }) => isItem?.(source.data) ?? false,
137
- onDrop: ({ location, source }) => {
138
- const target = location.current.dropTargets[0];
139
- if (!target) {
140
- return;
141
- }
142
- const sourceData = source.data;
143
- const targetData = target.data;
144
- if (!isItem?.(sourceData) || !isItem?.(targetData)) {
145
- return;
146
- }
147
- const sourceIdx = items.findIndex((item) => isEqual(item, sourceData));
148
- const targetIdx = items.findIndex((item) => isEqual(item, targetData));
149
- if (targetIdx < 0 || sourceIdx < 0) {
150
- return;
151
- }
152
- const closestEdgeOfTarget = extractClosestEdge(targetData);
153
- const destinationIndex = getReorderDestinationIndex({
154
- closestEdgeOfTarget,
155
- startIndex: sourceIdx,
156
- indexOfTarget: targetIdx,
157
- axis: "vertical"
158
- });
159
- onMove?.(sourceIdx, destinationIndex);
93
+ const isEqual = useCallback((a, b) => {
94
+ const idA = getId?.(a);
95
+ const idB = getId?.(b);
96
+ if (idA !== void 0 && idB !== void 0) {
97
+ return idA === idB;
98
+ } else {
99
+ return a === b;
100
+ }
101
+ }, [
102
+ getId
103
+ ]);
104
+ const [state, setState] = useState(idle);
105
+ useEffect(() => {
106
+ if (!items) {
107
+ return;
108
+ }
109
+ return monitorForElements({
110
+ canMonitor: ({ source }) => isItem?.(source.data) ?? false,
111
+ onDrop: ({ location, source }) => {
112
+ const target = location.current.dropTargets[0];
113
+ if (!target) {
114
+ return;
160
115
  }
161
- });
162
- }, [
163
- items,
164
- isEqual,
165
- onMove
166
- ]);
167
- return /* @__PURE__ */ React3.createElement(ListProvider, {
168
- state,
169
- setState,
170
- isItem,
171
- ...props
172
- }, children?.({
173
- state,
174
- items: items ?? []
175
- }));
176
- } finally {
177
- _effect.f();
178
- }
116
+ const sourceData = source.data;
117
+ const targetData = target.data;
118
+ if (!isItem?.(sourceData) || !isItem?.(targetData)) {
119
+ return;
120
+ }
121
+ const sourceIdx = items.findIndex((item) => isEqual(item, sourceData));
122
+ const targetIdx = items.findIndex((item) => isEqual(item, targetData));
123
+ if (targetIdx < 0 || sourceIdx < 0) {
124
+ return;
125
+ }
126
+ const closestEdgeOfTarget = extractClosestEdge(targetData);
127
+ const destinationIndex = getReorderDestinationIndex({
128
+ closestEdgeOfTarget,
129
+ startIndex: sourceIdx,
130
+ indexOfTarget: targetIdx,
131
+ axis: "vertical"
132
+ });
133
+ onMove?.(sourceIdx, destinationIndex);
134
+ }
135
+ });
136
+ }, [
137
+ items,
138
+ isEqual,
139
+ onMove
140
+ ]);
141
+ return /* @__PURE__ */ React3.createElement(ListProvider, {
142
+ state,
143
+ setState,
144
+ isItem,
145
+ ...props
146
+ }, children?.({
147
+ state,
148
+ items: items ?? []
149
+ }));
179
150
  };
180
151
 
181
152
  // src/components/List/ListItem.tsx
@@ -184,200 +155,180 @@ var idle = {
184
155
  type: "idle"
185
156
  };
186
157
  var stateStyles = {
187
- "is-dragging": "opacity-50"
158
+ "w-dragging": "opacity-50"
188
159
  };
189
160
  var defaultContext = {};
190
161
  var LIST_ITEM_NAME = "ListItem";
191
162
  var [ListItemProvider, useListItemContext] = createContext4(LIST_ITEM_NAME, defaultContext);
192
163
  var ListItem = ({ children, classNames, item, ...props }) => {
193
- var _effect = _useSignals4();
194
- try {
195
- const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
196
- const ref = useRef(null);
197
- const dragHandleRef = useRef(null);
198
- const [state, setState] = useState2(idle);
199
- useEffect2(() => {
200
- const element = ref.current;
201
- invariant(element, void 0, {
202
- F: __dxlog_file,
203
- L: 98,
204
- S: void 0,
205
- A: [
206
- "element",
207
- ""
208
- ]
209
- });
210
- return combine(
211
- //
212
- // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#draggable
213
- //
214
- draggable({
215
- element,
216
- dragHandle: dragHandleRef.current,
217
- canDrag: () => !readonly,
218
- getInitialData: () => item,
219
- onGenerateDragPreview: dragPreview ? ({ nativeSetDragImage, source }) => {
220
- const rect = source.element.getBoundingClientRect();
221
- setCustomNativeDragPreview({
222
- nativeSetDragImage,
223
- getOffset: ({ container }) => {
224
- const { height } = container.getBoundingClientRect();
225
- return {
226
- x: 20,
227
- y: height / 2
228
- };
229
- },
230
- render: ({ container }) => {
231
- container.style.width = rect.width + "px";
232
- setState({
233
- type: "preview",
234
- container
235
- });
236
- setRootState({
237
- type: "preview",
238
- container,
239
- item
240
- });
241
- return () => {
242
- };
243
- }
244
- });
245
- } : void 0,
246
- onDragStart: () => {
247
- setState({
248
- type: "is-dragging"
249
- });
250
- setRootState({
251
- type: "is-dragging",
252
- item
253
- });
254
- },
255
- onDrop: () => {
256
- setState(idle);
257
- setRootState(idle);
258
- }
259
- }),
260
- //
261
- // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#drop-target-for-elements
262
- //
263
- dropTargetForElements({
264
- element,
265
- canDrop: ({ source }) => {
266
- return (source.element !== element && isItem?.(source.data)) ?? false;
267
- },
268
- getData: ({ input }) => {
269
- return attachClosestEdge(item, {
270
- element,
271
- input,
272
- allowedEdges: [
273
- "top",
274
- "bottom"
275
- ]
276
- });
277
- },
278
- getIsSticky: () => true,
279
- onDragEnter: ({ self }) => {
280
- const closestEdge = extractClosestEdge2(self.data);
281
- setState({
282
- type: "is-dragging-over",
283
- closestEdge
284
- });
285
- },
286
- onDragLeave: () => {
287
- setState(idle);
288
- },
289
- onDrag: ({ self }) => {
290
- const closestEdge = extractClosestEdge2(self.data);
291
- setState((current) => {
292
- if (current.type === "is-dragging-over" && current.closestEdge === closestEdge) {
293
- return current;
294
- }
164
+ const { isItem, readonly, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
165
+ const ref = useRef(null);
166
+ const dragHandleRef = useRef(null);
167
+ const [state, setState] = useState2(idle);
168
+ useEffect2(() => {
169
+ const element = ref.current;
170
+ invariant(element, void 0, {
171
+ F: __dxlog_file,
172
+ L: 98,
173
+ S: void 0,
174
+ A: [
175
+ "element",
176
+ ""
177
+ ]
178
+ });
179
+ return combine(
180
+ //
181
+ // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#draggable
182
+ //
183
+ draggable({
184
+ element,
185
+ dragHandle: dragHandleRef.current,
186
+ canDrag: () => !readonly,
187
+ getInitialData: () => item,
188
+ onGenerateDragPreview: dragPreview ? ({ nativeSetDragImage, source }) => {
189
+ const rect = source.element.getBoundingClientRect();
190
+ setCustomNativeDragPreview({
191
+ nativeSetDragImage,
192
+ getOffset: ({ container }) => {
193
+ const { height } = container.getBoundingClientRect();
295
194
  return {
296
- type: "is-dragging-over",
297
- closestEdge
195
+ x: 20,
196
+ y: height / 2
298
197
  };
299
- });
300
- },
301
- onDrop: () => {
302
- setState(idle);
303
- }
304
- })
305
- );
306
- }, [
307
- item
308
- ]);
309
- return /* @__PURE__ */ React4.createElement(ListItemProvider, {
310
- item,
311
- dragHandleRef
312
- }, /* @__PURE__ */ React4.createElement("div", {
313
- ref,
314
- role: "listitem",
315
- className: mx3("flex relative", classNames, stateStyles[state.type]),
316
- ...props
317
- }, children, state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React4.createElement(NaturalListItem.DropIndicator, {
318
- edge: state.closestEdge
319
- })));
320
- } finally {
321
- _effect.f();
322
- }
198
+ },
199
+ render: ({ container }) => {
200
+ container.style.width = rect.width + "px";
201
+ setState({
202
+ type: "preview",
203
+ container
204
+ });
205
+ setRootState({
206
+ type: "preview",
207
+ container,
208
+ item
209
+ });
210
+ return () => {
211
+ };
212
+ }
213
+ });
214
+ } : void 0,
215
+ onDragStart: () => {
216
+ setState({
217
+ type: "w-dragging"
218
+ });
219
+ setRootState({
220
+ type: "w-dragging",
221
+ item
222
+ });
223
+ },
224
+ onDrop: () => {
225
+ setState(idle);
226
+ setRootState(idle);
227
+ }
228
+ }),
229
+ //
230
+ // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about#drop-target-for-elements
231
+ //
232
+ dropTargetForElements({
233
+ element,
234
+ canDrop: ({ source }) => {
235
+ return (source.element !== element && isItem?.(source.data)) ?? false;
236
+ },
237
+ getData: ({ input }) => {
238
+ return attachClosestEdge(item, {
239
+ element,
240
+ input,
241
+ allowedEdges: [
242
+ "top",
243
+ "bottom"
244
+ ]
245
+ });
246
+ },
247
+ getIsSticky: () => true,
248
+ onDragEnter: ({ self }) => {
249
+ const closestEdge = extractClosestEdge2(self.data);
250
+ setState({
251
+ type: "w-dragging-over",
252
+ closestEdge
253
+ });
254
+ },
255
+ onDragLeave: () => {
256
+ setState(idle);
257
+ },
258
+ onDrag: ({ self }) => {
259
+ const closestEdge = extractClosestEdge2(self.data);
260
+ setState((current) => {
261
+ if (current.type === "w-dragging-over" && current.closestEdge === closestEdge) {
262
+ return current;
263
+ }
264
+ return {
265
+ type: "w-dragging-over",
266
+ closestEdge
267
+ };
268
+ });
269
+ },
270
+ onDrop: () => {
271
+ setState(idle);
272
+ }
273
+ })
274
+ );
275
+ }, [
276
+ item
277
+ ]);
278
+ return /* @__PURE__ */ React4.createElement(ListItemProvider, {
279
+ item,
280
+ dragHandleRef
281
+ }, /* @__PURE__ */ React4.createElement("div", {
282
+ ref,
283
+ role: "listitem",
284
+ className: mx3("flex relative", classNames, stateStyles[state.type]),
285
+ ...props
286
+ }, children, state.type === "w-dragging-over" && state.closestEdge && /* @__PURE__ */ React4.createElement(NaturalListItem.DropIndicator, {
287
+ edge: state.closestEdge
288
+ })));
323
289
  };
324
290
  var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, icon = "ph--x--regular", label, ...props }) => {
325
- var _effect = _useSignals4();
326
- try {
327
- const { state } = useListContext("DELETE_BUTTON");
328
- const isDisabled = state.type !== "idle" || disabled;
329
- const { t } = useTranslation("os");
330
- return /* @__PURE__ */ React4.createElement(IconButton, {
331
- iconOnly: true,
332
- variant: "ghost",
333
- ...props,
334
- icon,
335
- disabled: isDisabled,
336
- label: label ?? t("delete label"),
337
- classNames: [
338
- classNames,
339
- autoHide && disabled && "hidden"
340
- ]
341
- });
342
- } finally {
343
- _effect.f();
344
- }
291
+ const { state } = useListContext("DELETE_BUTTON");
292
+ const isDisabled = state.type !== "idle" || disabled;
293
+ const { t } = useTranslation(osTranslations);
294
+ return /* @__PURE__ */ React4.createElement(IconButton, {
295
+ iconOnly: true,
296
+ variant: "ghost",
297
+ ...props,
298
+ icon,
299
+ disabled: isDisabled,
300
+ label: label ?? t("delete label"),
301
+ classNames: [
302
+ classNames,
303
+ autoHide && disabled && "hidden"
304
+ ]
305
+ });
345
306
  };
346
307
  var ListItemButton = ({ autoHide = true, iconOnly = true, variant = "ghost", classNames, disabled, ...props }) => {
347
- var _effect = _useSignals4();
348
- try {
349
- const { state } = useListContext("ITEM_BUTTON");
350
- const isDisabled = state.type !== "idle" || disabled;
351
- return /* @__PURE__ */ React4.createElement(IconButton, {
352
- ...props,
353
- disabled: isDisabled,
354
- iconOnly,
355
- variant,
356
- classNames: [
357
- classNames,
358
- autoHide && disabled && "hidden"
359
- ]
360
- });
361
- } finally {
362
- _effect.f();
363
- }
308
+ const { state } = useListContext("ITEM_BUTTON");
309
+ const isDisabled = state.type !== "idle" || disabled;
310
+ return /* @__PURE__ */ React4.createElement(IconButton, {
311
+ ...props,
312
+ disabled: isDisabled,
313
+ iconOnly,
314
+ variant,
315
+ classNames: [
316
+ classNames,
317
+ autoHide && disabled && "hidden"
318
+ ]
319
+ });
364
320
  };
365
321
  var ListItemDragHandle = ({ disabled }) => {
366
- var _effect = _useSignals4();
367
- try {
368
- const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
369
- const { t } = useTranslation("os");
370
- return /* @__PURE__ */ React4.createElement(IconButton, {
371
- iconOnly: true,
372
- variant: "ghost",
373
- label: t("drag handle label"),
374
- ref: dragHandleRef,
375
- icon: "ph--dots-six-vertical--regular",
376
- disabled
377
- });
378
- } finally {
379
- _effect.f();
380
- }
322
+ const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
323
+ const { t } = useTranslation(osTranslations);
324
+ return /* @__PURE__ */ React4.createElement(IconButton, {
325
+ iconOnly: true,
326
+ variant: "ghost",
327
+ label: t("drag handle label"),
328
+ ref: dragHandleRef,
329
+ icon: "ph--dots-six-vertical--regular",
330
+ disabled
331
+ });
381
332
  };
382
333
  var ListItemDragPreview = ({ children }) => {
383
334
  const { state } = useListContext("DRAG_PREVIEW");
@@ -385,27 +336,13 @@ var ListItemDragPreview = ({ children }) => {
385
336
  item: state.item
386
337
  }), state.container) : null;
387
338
  };
388
- var ListItemWrapper = ({ classNames, children }) => {
389
- var _effect = _useSignals4();
390
- try {
391
- return /* @__PURE__ */ React4.createElement("div", {
392
- className: mx3("flex is-full gap-2", classNames)
393
- }, children);
394
- } finally {
395
- _effect.f();
396
- }
397
- };
398
- var ListItemTitle = ({ classNames, children, ...props }) => {
399
- var _effect = _useSignals4();
400
- try {
401
- return /* @__PURE__ */ React4.createElement("div", {
402
- className: mx3("flex grow items-center truncate", classNames),
403
- ...props
404
- }, children);
405
- } finally {
406
- _effect.f();
407
- }
408
- };
339
+ var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React4.createElement("div", {
340
+ className: mx3("flex w-full gap-2", classNames)
341
+ }, children);
342
+ var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React4.createElement("div", {
343
+ className: mx3("flex grow items-center truncate", classNames),
344
+ ...props
345
+ }, children);
409
346
 
410
347
  // src/components/List/List.tsx
411
348
  var List = {
@@ -420,7 +357,7 @@ var List = {
420
357
  };
421
358
 
422
359
  // src/components/Tree/Tree.tsx
423
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
360
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
424
361
  import React8, { useMemo as useMemo2 } from "react";
425
362
  import { Treegrid as Treegrid2 } from "@dxos/react-ui";
426
363
 
@@ -432,15 +369,15 @@ var TreeProvider = TreeContext.Provider;
432
369
  var useTree = () => useContext(TreeContext) ?? raise(new Error("TreeContext not found"));
433
370
 
434
371
  // src/components/Tree/TreeItem.tsx
435
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
436
372
  import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
437
373
  import { draggable as draggable2, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
438
374
  import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
375
+ import { useAtomValue } from "@effect-atom/atom-react";
439
376
  import * as Schema from "effect/Schema";
440
377
  import React7, { memo as memo3, useCallback as useCallback3, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState3 } from "react";
441
378
  import { invariant as invariant2 } from "@dxos/invariant";
442
379
  import { TreeItem as NaturalTreeItem, Treegrid } from "@dxos/react-ui";
443
- import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls } from "@dxos/react-ui-theme";
380
+ import { ghostFocusWithin, ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx4 } from "@dxos/ui-theme";
444
381
 
445
382
  // src/components/Tree/helpers.ts
446
383
  var DEFAULT_INDENTATION = 8;
@@ -449,97 +386,87 @@ var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
449
386
  });
450
387
 
451
388
  // src/components/Tree/TreeItemHeading.tsx
452
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
453
389
  import React5, { forwardRef, memo, useCallback as useCallback2 } from "react";
454
390
  import { Button, Icon as Icon2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
455
391
  import { TextTooltip } from "@dxos/react-ui-text-tooltip";
456
- var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ label, className, icon, iconClassName, disabled, current, onSelect }, forwardedRef) => {
457
- var _effect = _useSignals5();
458
- try {
459
- const { t } = useTranslation2();
460
- const handleSelect = useCallback2((event) => {
392
+ import { getStyles } from "@dxos/ui-theme";
393
+ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef(({ label, className, icon, iconHue, disabled, current, onSelect }, forwardedRef) => {
394
+ const { t } = useTranslation2();
395
+ const styles = iconHue ? getStyles(iconHue) : void 0;
396
+ const handleSelect = useCallback2((event) => {
397
+ onSelect?.(event.altKey);
398
+ }, [
399
+ onSelect
400
+ ]);
401
+ const handleButtonKeydown = useCallback2((event) => {
402
+ if (event.key === " " || event.key === "Enter") {
403
+ event.preventDefault();
404
+ event.stopPropagation();
461
405
  onSelect?.(event.altKey);
462
- }, [
463
- onSelect
464
- ]);
465
- const handleButtonKeydown = useCallback2((event) => {
466
- if (event.key === " " || event.key === "Enter") {
467
- event.preventDefault();
468
- event.stopPropagation();
469
- onSelect?.(event.altKey);
470
- }
471
- }, [
472
- onSelect
473
- ]);
474
- return /* @__PURE__ */ React5.createElement(TextTooltip, {
475
- text: toLocalizedString(label, t),
476
- side: "bottom",
477
- truncateQuery: "span[data-tooltip]",
478
- onlyWhenTruncating: true,
479
- asChild: true,
480
- ref: forwardedRef
481
- }, /* @__PURE__ */ React5.createElement(Button, {
482
- "data-testid": "treeItem.heading",
483
- variant: "ghost",
484
- density: "fine",
485
- classNames: [
486
- "grow gap-2 pis-0.5 hover:bg-transparent dark:hover:bg-transparent",
487
- "disabled:cursor-default disabled:opacity-100",
488
- className
489
- ],
490
- disabled,
491
- onClick: handleSelect,
492
- onKeyDown: handleButtonKeydown,
493
- ...current && {
494
- "aria-current": "location"
495
- }
496
- }, icon && /* @__PURE__ */ React5.createElement(Icon2, {
497
- icon: icon ?? "ph--placeholder--regular",
498
- size: 5,
499
- classNames: [
500
- "mlb-1",
501
- iconClassName
502
- ]
503
- }), /* @__PURE__ */ React5.createElement("span", {
504
- className: "flex-1 is-0 truncate text-start text-sm font-normal",
505
- "data-tooltip": true
506
- }, toLocalizedString(label, t))));
507
- } finally {
508
- _effect.f();
509
- }
406
+ }
407
+ }, [
408
+ onSelect
409
+ ]);
410
+ return /* @__PURE__ */ React5.createElement(TextTooltip, {
411
+ text: toLocalizedString(label, t),
412
+ side: "bottom",
413
+ truncateQuery: "span[data-tooltip]",
414
+ onlyWhenTruncating: true,
415
+ asChild: true,
416
+ ref: forwardedRef
417
+ }, /* @__PURE__ */ React5.createElement(Button, {
418
+ "data-testid": "treeItem.heading",
419
+ variant: "ghost",
420
+ density: "fine",
421
+ classNames: [
422
+ "grow gap-2 ps-0.5 hover:bg-transparent dark:hover:bg-transparent",
423
+ "disabled:cursor-default disabled:opacity-100",
424
+ className
425
+ ],
426
+ disabled,
427
+ onClick: handleSelect,
428
+ onKeyDown: handleButtonKeydown,
429
+ ...current && {
430
+ "aria-current": "location"
431
+ }
432
+ }, icon && /* @__PURE__ */ React5.createElement(Icon2, {
433
+ icon: icon ?? "ph--placeholder--regular",
434
+ size: 5,
435
+ classNames: [
436
+ "my-1",
437
+ styles?.surfaceText
438
+ ]
439
+ }), /* @__PURE__ */ React5.createElement("span", {
440
+ className: "flex-1 w-0 truncate text-start font-normal",
441
+ "data-tooltip": true
442
+ }, toLocalizedString(label, t))));
510
443
  }));
511
444
 
512
445
  // src/components/Tree/TreeItemToggle.tsx
513
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
514
446
  import React6, { forwardRef as forwardRef2, memo as memo2 } from "react";
515
447
  import { IconButton as IconButton2 } from "@dxos/react-ui";
516
448
  var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef2(({ open, isBranch, hidden, classNames, ...props }, forwardedRef) => {
517
- var _effect = _useSignals6();
518
- try {
519
- return /* @__PURE__ */ React6.createElement(IconButton2, {
520
- ref: forwardedRef,
521
- "data-testid": "treeItem.toggle",
522
- "aria-expanded": open,
523
- variant: "ghost",
524
- density: "fine",
525
- classNames: [
526
- "bs-full is-6 pli-0",
527
- "[&_svg]:transition-[transform] [&_svg]:duration-200",
528
- open && "[&_svg]:rotate-90",
529
- hidden ? "hidden" : !isBranch && "invisible",
530
- classNames
531
- ],
532
- size: 3,
533
- icon: "ph--caret-right--bold",
534
- iconOnly: true,
535
- noTooltip: true,
536
- label: open ? "Click to close" : "Click to open",
537
- tabIndex: -1,
538
- ...props
539
- });
540
- } finally {
541
- _effect.f();
542
- }
449
+ return /* @__PURE__ */ React6.createElement(IconButton2, {
450
+ ref: forwardedRef,
451
+ "data-testid": "treeItem.toggle",
452
+ "aria-expanded": open,
453
+ variant: "ghost",
454
+ density: "fine",
455
+ classNames: [
456
+ "h-full w-6 px-0",
457
+ "[&_svg]:transition-[transform] [&_svg]:duration-200",
458
+ open && "[&_svg]:rotate-90",
459
+ hidden ? "hidden" : !isBranch && "invisible",
460
+ classNames
461
+ ],
462
+ size: 3,
463
+ icon: "ph--caret-right--bold",
464
+ iconOnly: true,
465
+ noTooltip: true,
466
+ label: open ? "Click to close" : "Click to open",
467
+ tabIndex: -1,
468
+ ...props
469
+ });
543
470
  }));
544
471
 
545
472
  // src/components/Tree/TreeItem.tsx
@@ -551,319 +478,333 @@ var TreeDataSchema = Schema.Struct({
551
478
  item: Schema.Any
552
479
  });
553
480
  var isTreeData = (data) => Schema.is(TreeDataSchema)(data);
554
- var RawTreeItem = ({ item, path: _path, levelOffset = 2, last, draggable: _draggable, renderColumns: Columns, canDrop, canSelect, onOpenChange, onSelect }) => {
555
- var _effect = _useSignals7();
556
- try {
557
- const rowRef = useRef2(null);
558
- const buttonRef = useRef2(null);
559
- const openRef = useRef2(false);
560
- const cancelExpandRef = useRef2(null);
561
- const [_state, setState] = useState3("idle");
562
- const [instruction, setInstruction] = useState3(null);
563
- const [menuOpen, setMenuOpen] = useState3(false);
564
- const { useItems, getProps, isOpen, isCurrent } = useTree();
565
- const items = useItems(item);
566
- const { id, parentOf, label, className, headingClassName, icon, iconClassName, disabled, testId } = getProps(item, _path);
567
- const path = useMemo(() => [
568
- ..._path,
569
- id
570
- ], [
571
- _path,
572
- id
573
- ]);
574
- const open = isOpen(path, item);
575
- const current = isCurrent(path, item);
576
- const level = path.length - levelOffset;
577
- const isBranch = !!parentOf;
578
- const mode = last ? "last-in-group" : open ? "expanded" : "standard";
579
- const canSelectItem = canSelect?.({
580
- item,
581
- path
582
- }) ?? true;
583
- const cancelExpand = useCallback3(() => {
584
- if (cancelExpandRef.current) {
585
- clearTimeout(cancelExpandRef.current);
586
- cancelExpandRef.current = null;
587
- }
588
- }, []);
589
- useEffect3(() => {
590
- if (!_draggable) {
591
- return;
592
- }
593
- invariant2(buttonRef.current, void 0, {
594
- F: __dxlog_file2,
595
- L: 113,
596
- S: void 0,
597
- A: [
598
- "buttonRef.current",
599
- ""
600
- ]
601
- });
602
- const data = {
603
- id,
604
- path,
605
- item
606
- };
607
- return combine2(
608
- draggable2({
609
- element: buttonRef.current,
610
- getInitialData: () => data,
611
- onDragStart: () => {
612
- setState("dragging");
613
- if (open) {
614
- openRef.current = true;
615
- onOpenChange?.({
616
- item,
617
- path,
618
- open: false
619
- });
620
- }
621
- },
622
- onDrop: () => {
623
- setState("idle");
624
- if (openRef.current) {
625
- onOpenChange?.({
626
- item,
627
- path,
628
- open: true
629
- });
630
- }
631
- }
632
- }),
633
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
634
- dropTargetForElements2({
635
- element: buttonRef.current,
636
- getData: ({ input, element }) => {
637
- return attachInstruction(data, {
638
- input,
639
- element,
640
- indentPerLevel: DEFAULT_INDENTATION,
641
- currentLevel: level,
642
- mode,
643
- block: isBranch ? [] : [
644
- "make-child"
645
- ]
481
+ var RawTreeItem = ({ item, path: pathProp, levelOffset = 2, last, draggable: draggableProp, renderColumns: Columns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
482
+ const rowRef = useRef2(null);
483
+ const buttonRef = useRef2(null);
484
+ const openRef = useRef2(false);
485
+ const cancelExpandRef = useRef2(null);
486
+ const [_state, setState] = useState3("idle");
487
+ const [instruction, setInstruction] = useState3(null);
488
+ const [menuOpen, setMenuOpen] = useState3(false);
489
+ const { itemProps: itemPropsAtom, childIds: childIdsAtom, itemOpen: itemOpenAtom, itemCurrent: itemCurrentAtom } = useTree();
490
+ const path = useMemo(() => [
491
+ ...pathProp,
492
+ item.id
493
+ ], [
494
+ pathProp,
495
+ item.id
496
+ ]);
497
+ const { id, parentOf, label, className, headingClassName, icon, iconHue, disabled, testId } = useAtomValue(itemPropsAtom(path));
498
+ const childIds = useAtomValue(childIdsAtom(item.id));
499
+ const open = useAtomValue(itemOpenAtom(path));
500
+ const current = useAtomValue(itemCurrentAtom(path));
501
+ const level = path.length - levelOffset;
502
+ const isBranch = !!parentOf;
503
+ const mode = last ? "last-in-group" : open ? "expanded" : "standard";
504
+ const canSelectItem = canSelect?.({
505
+ item,
506
+ path
507
+ }) ?? true;
508
+ const data = {
509
+ id,
510
+ path,
511
+ item
512
+ };
513
+ const cancelExpand = useCallback3(() => {
514
+ if (cancelExpandRef.current) {
515
+ clearTimeout(cancelExpandRef.current);
516
+ cancelExpandRef.current = null;
517
+ }
518
+ }, []);
519
+ useEffect3(() => {
520
+ if (!draggableProp) {
521
+ return;
522
+ }
523
+ invariant2(buttonRef.current, void 0, {
524
+ F: __dxlog_file2,
525
+ L: 135,
526
+ S: void 0,
527
+ A: [
528
+ "buttonRef.current",
529
+ ""
530
+ ]
531
+ });
532
+ return combine2(
533
+ draggable2({
534
+ element: buttonRef.current,
535
+ getInitialData: () => data,
536
+ onDragStart: () => {
537
+ setState("dragging");
538
+ if (open) {
539
+ openRef.current = true;
540
+ onOpenChange?.({
541
+ item,
542
+ path,
543
+ open: false
646
544
  });
647
- },
648
- canDrop: ({ source }) => {
649
- const _canDrop = canDrop ?? (() => true);
650
- return source.element !== buttonRef.current && _canDrop({
651
- source: source.data,
652
- target: data
545
+ }
546
+ },
547
+ onDrop: () => {
548
+ setState("idle");
549
+ if (openRef.current) {
550
+ onOpenChange?.({
551
+ item,
552
+ path,
553
+ open: true
653
554
  });
654
- },
655
- getIsSticky: () => true,
656
- onDrag: ({ self, source }) => {
657
- const instruction2 = extractInstruction(self.data);
658
- if (source.data.id !== id) {
659
- if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
660
- cancelExpandRef.current = setTimeout(() => {
661
- onOpenChange?.({
662
- item,
663
- path,
664
- open: true
665
- });
666
- }, 500);
667
- }
668
- if (instruction2?.type !== "make-child") {
669
- cancelExpand();
670
- }
671
- setInstruction(instruction2);
672
- } else if (instruction2?.type === "reparent") {
673
- setInstruction(instruction2);
674
- } else {
675
- setInstruction(null);
555
+ }
556
+ }
557
+ }),
558
+ // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
559
+ dropTargetForElements2({
560
+ element: buttonRef.current,
561
+ getData: ({ input, element }) => {
562
+ return attachInstruction(data, {
563
+ input,
564
+ element,
565
+ indentPerLevel: DEFAULT_INDENTATION,
566
+ currentLevel: level,
567
+ mode,
568
+ block: isBranch ? [] : [
569
+ "make-child"
570
+ ]
571
+ });
572
+ },
573
+ canDrop: ({ source }) => {
574
+ const _canDrop = canDrop ?? (() => true);
575
+ return source.element !== buttonRef.current && _canDrop({
576
+ source: source.data,
577
+ target: data
578
+ });
579
+ },
580
+ getIsSticky: () => true,
581
+ onDrag: ({ self, source }) => {
582
+ const desired = extractInstruction(self.data);
583
+ const block = desired && blockInstruction?.({
584
+ instruction: desired,
585
+ source: source.data,
586
+ target: data
587
+ });
588
+ const instruction2 = block && desired.type !== "instruction-blocked" ? {
589
+ type: "instruction-blocked",
590
+ desired
591
+ } : desired;
592
+ if (source.data.id !== id) {
593
+ if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
594
+ cancelExpandRef.current = setTimeout(() => {
595
+ onOpenChange?.({
596
+ item,
597
+ path,
598
+ open: true
599
+ });
600
+ }, 500);
676
601
  }
677
- },
678
- onDragLeave: () => {
679
- cancelExpand();
680
- setInstruction(null);
681
- },
682
- onDrop: () => {
683
- cancelExpand();
602
+ if (instruction2?.type !== "make-child") {
603
+ cancelExpand();
604
+ }
605
+ setInstruction(instruction2);
606
+ } else if (instruction2?.type === "reparent") {
607
+ setInstruction(instruction2);
608
+ } else {
684
609
  setInstruction(null);
685
610
  }
686
- })
687
- );
688
- }, [
689
- _draggable,
690
- item,
691
- id,
692
- mode,
693
- path,
694
- open,
695
- canDrop
696
- ]);
697
- useEffect3(() => () => cancelExpand(), [
698
- cancelExpand
699
- ]);
700
- const handleOpenToggle = useCallback3(() => onOpenChange?.({
701
- item,
702
- path,
703
- open: !open
704
- }), [
705
- onOpenChange,
706
- item,
707
- path,
708
- open
709
- ]);
710
- const handleSelect = useCallback3((option = false) => {
711
- if (isBranch && (option || current)) {
712
- handleOpenToggle();
713
- } else if (canSelectItem) {
714
- canSelect?.({
715
- item,
716
- path
717
- });
718
- rowRef.current?.focus();
719
- onSelect?.({
720
- item,
721
- path,
722
- current: !current,
723
- option
724
- });
725
- }
726
- }, [
727
- item,
728
- path,
729
- current,
730
- isBranch,
731
- canSelectItem,
732
- handleOpenToggle,
733
- onSelect
734
- ]);
735
- const handleKeyDown = useCallback3((event) => {
736
- switch (event.key) {
737
- case "ArrowRight":
738
- case "ArrowLeft":
739
- isBranch && handleOpenToggle();
740
- break;
741
- }
742
- }, [
743
- isBranch,
744
- open,
745
- handleOpenToggle,
746
- handleSelect
747
- ]);
748
- return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Treegrid.Row, {
749
- ref: rowRef,
750
- key: id,
751
- id,
752
- "aria-labelledby": `${id}__label`,
753
- parentOf: parentOf?.join(Treegrid.PARENT_OF_SEPARATOR),
754
- classNames: [
755
- "grid grid-cols-subgrid col-[tree-row] mbs-0.5 aria-[current]:bg-activeSurface",
756
- hoverableControls,
757
- hoverableFocusedKeyboardControls,
758
- hoverableFocusedWithinControls,
759
- hoverableDescriptionIcons,
760
- ghostHover,
761
- ghostFocusWithin,
762
- className
763
- ],
764
- "data-itemid": id,
765
- "data-testid": testId,
766
- // NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
767
- // without alerting the user (except for in the correct link element). See also:
768
- // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current#description
769
- "aria-current": current ? "" : void 0,
770
- onKeyDown: handleKeyDown,
771
- onContextMenu: (event) => {
772
- event.preventDefault();
773
- setMenuOpen(true);
774
- }
775
- }, /* @__PURE__ */ React7.createElement("div", {
776
- role: "none",
777
- className: "indent relative grid grid-cols-subgrid col-[tree-row]",
778
- style: paddingIndentation(level)
779
- }, /* @__PURE__ */ React7.createElement(Treegrid.Cell, {
780
- classNames: "flex items-center"
781
- }, /* @__PURE__ */ React7.createElement(TreeItemToggle, {
782
- isBranch,
783
- open,
784
- onClick: handleOpenToggle
785
- }), /* @__PURE__ */ React7.createElement(TreeItemHeading, {
786
- disabled,
787
- current,
788
- label,
789
- className: headingClassName,
790
- icon,
791
- iconClassName,
792
- onSelect: handleSelect,
793
- ref: buttonRef
794
- })), Columns && /* @__PURE__ */ React7.createElement(Columns, {
795
- item,
796
- path,
797
- open,
798
- menuOpen,
799
- setMenuOpen
800
- }), instruction && /* @__PURE__ */ React7.createElement(NaturalTreeItem.DropIndicator, {
801
- instruction,
802
- gap: 2
803
- }))), open && items.map((item2, index) => /* @__PURE__ */ React7.createElement(TreeItem, {
804
- key: item2.id,
805
- item: item2,
806
- path,
807
- last: index === items.length - 1,
808
- draggable: _draggable,
809
- renderColumns: Columns,
810
- canDrop,
811
- canSelect,
812
- onOpenChange,
813
- onSelect
814
- })));
815
- } finally {
816
- _effect.f();
817
- }
611
+ },
612
+ onDragLeave: () => {
613
+ cancelExpand();
614
+ setInstruction(null);
615
+ },
616
+ onDrop: () => {
617
+ cancelExpand();
618
+ setInstruction(null);
619
+ }
620
+ })
621
+ );
622
+ }, [
623
+ draggableProp,
624
+ item,
625
+ id,
626
+ mode,
627
+ path,
628
+ open,
629
+ blockInstruction,
630
+ canDrop
631
+ ]);
632
+ useEffect3(() => () => cancelExpand(), [
633
+ cancelExpand
634
+ ]);
635
+ const handleOpenToggle = useCallback3(() => onOpenChange?.({
636
+ item,
637
+ path,
638
+ open: !open
639
+ }), [
640
+ onOpenChange,
641
+ item,
642
+ path,
643
+ open
644
+ ]);
645
+ const handleSelect = useCallback3((option = false) => {
646
+ if (isBranch && (option || current)) {
647
+ handleOpenToggle();
648
+ } else if (canSelectItem) {
649
+ canSelect?.({
650
+ item,
651
+ path
652
+ });
653
+ rowRef.current?.focus();
654
+ onSelect?.({
655
+ item,
656
+ path,
657
+ current: !current,
658
+ option
659
+ });
660
+ }
661
+ }, [
662
+ item,
663
+ path,
664
+ current,
665
+ isBranch,
666
+ canSelectItem,
667
+ handleOpenToggle,
668
+ onSelect
669
+ ]);
670
+ const handleKeyDown = useCallback3((event) => {
671
+ switch (event.key) {
672
+ case "ArrowRight":
673
+ case "ArrowLeft":
674
+ isBranch && handleOpenToggle();
675
+ break;
676
+ }
677
+ }, [
678
+ isBranch,
679
+ open,
680
+ handleOpenToggle,
681
+ handleSelect
682
+ ]);
683
+ const handleItemHover = useCallback3(() => {
684
+ onItemHover?.({
685
+ item
686
+ });
687
+ }, [
688
+ onItemHover,
689
+ item
690
+ ]);
691
+ const handleContextMenu = useCallback3((event) => {
692
+ event.preventDefault();
693
+ setMenuOpen(true);
694
+ }, [
695
+ setMenuOpen
696
+ ]);
697
+ const childProps = {
698
+ draggable: draggableProp,
699
+ renderColumns: Columns,
700
+ blockInstruction,
701
+ canDrop,
702
+ canSelect,
703
+ onItemHover,
704
+ onOpenChange,
705
+ onSelect
706
+ };
707
+ return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Treegrid.Row, {
708
+ ref: rowRef,
709
+ key: id,
710
+ id,
711
+ "aria-labelledby": `${id}__label`,
712
+ parentOf: parentOf?.join(Treegrid.PARENT_OF_SEPARATOR),
713
+ "data-object-id": id,
714
+ "data-testid": testId,
715
+ // NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
716
+ // without alerting the user (except for in the correct link element). See also:
717
+ // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current#description
718
+ "aria-current": current ? "" : void 0,
719
+ classNames: mx4("grid grid-cols-subgrid col-[tree-row] mt-0.5 is-current:bg-active-surface", hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableDescriptionIcons, ghostFocusWithin, ghostHover, className),
720
+ onKeyDown: handleKeyDown,
721
+ onMouseEnter: handleItemHover,
722
+ onContextMenu: handleContextMenu
723
+ }, /* @__PURE__ */ React7.createElement("div", {
724
+ role: "none",
725
+ className: "indent relative grid grid-cols-subgrid col-[tree-row]",
726
+ style: paddingIndentation(level)
727
+ }, /* @__PURE__ */ React7.createElement(Treegrid.Cell, {
728
+ classNames: "flex items-center"
729
+ }, /* @__PURE__ */ React7.createElement(TreeItemToggle, {
730
+ isBranch,
731
+ open,
732
+ onClick: handleOpenToggle
733
+ }), /* @__PURE__ */ React7.createElement(TreeItemHeading, {
734
+ disabled,
735
+ current,
736
+ label,
737
+ className: headingClassName,
738
+ icon,
739
+ iconHue,
740
+ onSelect: handleSelect,
741
+ ref: buttonRef
742
+ })), Columns && /* @__PURE__ */ React7.createElement(Columns, {
743
+ item,
744
+ path,
745
+ open,
746
+ menuOpen,
747
+ setMenuOpen
748
+ }), instruction && /* @__PURE__ */ React7.createElement(NaturalTreeItem.DropIndicator, {
749
+ instruction,
750
+ gap: 2
751
+ }))), open && childIds.map((childId, index) => /* @__PURE__ */ React7.createElement(TreeItemById, {
752
+ key: childId,
753
+ id: childId,
754
+ path,
755
+ last: index === childIds.length - 1,
756
+ ...childProps
757
+ })));
818
758
  };
819
759
  var TreeItem = /* @__PURE__ */ memo3(RawTreeItem);
760
+ var RawTreeItemById = ({ id, ...props }) => {
761
+ const { item: itemAtom } = useTree();
762
+ const item = useAtomValue(itemAtom(id));
763
+ if (!item) {
764
+ return null;
765
+ }
766
+ return /* @__PURE__ */ React7.createElement(TreeItem, {
767
+ item,
768
+ ...props
769
+ });
770
+ };
771
+ var TreeItemById = /* @__PURE__ */ memo3(RawTreeItemById);
820
772
 
821
773
  // src/components/Tree/Tree.tsx
822
- 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 }) => {
823
- var _effect = _useSignals8();
824
- try {
825
- const context = useMemo2(() => ({
826
- useItems,
827
- getProps,
828
- isOpen,
829
- isCurrent
830
- }), [
831
- useItems,
832
- getProps,
833
- isOpen,
834
- isCurrent
835
- ]);
836
- const items = useItems(root);
837
- const treePath = useMemo2(() => path ? [
838
- ...path,
839
- id
840
- ] : [
841
- id
842
- ], [
843
- id,
844
- path
845
- ]);
846
- return /* @__PURE__ */ React8.createElement(Treegrid2.Root, {
847
- gridTemplateColumns,
848
- classNames
849
- }, /* @__PURE__ */ React8.createElement(TreeProvider, {
850
- value: context
851
- }, items.map((item, index) => /* @__PURE__ */ React8.createElement(TreeItem, {
852
- key: item.id,
853
- item,
854
- last: index === items.length - 1,
855
- path: treePath,
856
- levelOffset,
857
- draggable: draggable3,
858
- renderColumns,
859
- canDrop,
860
- canSelect,
861
- onOpenChange,
862
- onSelect
863
- }))));
864
- } finally {
865
- _effect.f();
866
- }
774
+ var Tree = ({ model, rootId, path, id, draggable: draggable3 = false, gridTemplateColumns = "[tree-row-start] 1fr min-content [tree-row-end]", classNames, levelOffset, renderColumns, blockInstruction, canDrop, canSelect, onOpenChange, onSelect, onItemHover }) => {
775
+ const childIds = useAtomValue2(model.childIds(rootId));
776
+ const treePath = useMemo2(() => path ? [
777
+ ...path,
778
+ id
779
+ ] : [
780
+ id
781
+ ], [
782
+ id,
783
+ path
784
+ ]);
785
+ const childProps = {
786
+ path: treePath,
787
+ levelOffset,
788
+ draggable: draggable3,
789
+ renderColumns,
790
+ blockInstruction,
791
+ canDrop,
792
+ canSelect,
793
+ onOpenChange,
794
+ onSelect,
795
+ onItemHover
796
+ };
797
+ return /* @__PURE__ */ React8.createElement(Treegrid2.Root, {
798
+ gridTemplateColumns,
799
+ classNames
800
+ }, /* @__PURE__ */ React8.createElement(TreeProvider, {
801
+ value: model
802
+ }, childIds.map((childId, index) => /* @__PURE__ */ React8.createElement(TreeItemById, {
803
+ key: childId,
804
+ id: childId,
805
+ last: index === childIds.length - 1,
806
+ ...childProps
807
+ }))));
867
808
  };
868
809
 
869
810
  // src/util/path.ts
@@ -883,13 +824,17 @@ var Path = {
883
824
  };
884
825
  export {
885
826
  Accordion,
827
+ DEFAULT_INDENTATION,
886
828
  List,
887
829
  Path,
888
830
  Tree,
889
831
  TreeDataSchema,
890
832
  TreeItem,
833
+ TreeItemById,
834
+ TreeItemToggle,
891
835
  TreeProvider,
892
836
  isTreeData,
837
+ paddingIndentation,
893
838
  useTree
894
839
  };
895
840
  //# sourceMappingURL=index.mjs.map