@dxos/react-ui-list 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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