@dxos/react-ui-list 0.7.4 → 0.7.5-labs.071a3e2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +147 -217
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +156 -222
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +147 -217
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/List/List.d.ts +1 -1
- package/dist/types/src/components/List/List.d.ts.map +1 -1
- package/dist/types/src/components/List/ListItem.d.ts +6 -9
- package/dist/types/src/components/List/ListItem.d.ts.map +1 -1
- package/dist/types/src/components/List/ListRoot.d.ts +3 -6
- package/dist/types/src/components/List/ListRoot.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.d.ts +4 -2
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItem.d.ts +3 -1
- package/dist/types/src/components/Tree/TreeItem.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItemHeading.d.ts.map +1 -1
- package/dist/types/src/components/Tree/TreeItemToggle.d.ts +1 -0
- package/dist/types/src/components/Tree/TreeItemToggle.d.ts.map +1 -1
- package/dist/types/src/components/Tree/helpers.d.ts +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +20 -20
- package/src/components/List/ListItem.tsx +15 -7
- package/src/components/Tree/Tree.tsx +9 -5
- package/src/components/Tree/TreeItem.tsx +23 -21
- package/src/components/Tree/TreeItemHeading.tsx +2 -3
- package/src/components/Tree/TreeItemToggle.tsx +3 -2
- package/src/components/Tree/helpers.ts +1 -1
- package/dist/types/src/components/List/DropIndicator.d.ts +0 -11
- package/dist/types/src/components/List/DropIndicator.d.ts.map +0 -1
- package/dist/types/src/components/Tree/DropIndicator.d.ts +0 -8
- package/dist/types/src/components/Tree/DropIndicator.d.ts.map +0 -1
- package/src/components/List/DropIndicator.tsx +0 -69
- package/src/components/Tree/DropIndicator.tsx +0 -78
|
@@ -6,56 +6,18 @@ import { draggable, dropTargetForElements } from "@atlaskit/pragmatic-drag-and-d
|
|
|
6
6
|
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
7
7
|
import { attachClosestEdge, extractClosestEdge as extractClosestEdge2 } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
8
8
|
import { createContext as createContext2 } from "@radix-ui/react-context";
|
|
9
|
-
import
|
|
9
|
+
import React2, { forwardRef, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
11
|
import { invariant } from "@dxos/invariant";
|
|
12
|
-
import { Icon } from "@dxos/react-ui";
|
|
13
|
-
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
14
|
-
|
|
15
|
-
// packages/ui/react-ui-list/src/components/List/DropIndicator.tsx
|
|
16
|
-
import React from "react";
|
|
12
|
+
import { Icon, ListItem as NaturalListItem } from "@dxos/react-ui";
|
|
17
13
|
import { mx } from "@dxos/react-ui-theme";
|
|
18
|
-
var edgeToOrientationMap = {
|
|
19
|
-
top: "horizontal",
|
|
20
|
-
bottom: "horizontal",
|
|
21
|
-
left: "vertical",
|
|
22
|
-
right: "vertical"
|
|
23
|
-
};
|
|
24
|
-
var orientationStyles = {
|
|
25
|
-
horizontal: "h-[--line-thickness] left-[--terminal-radius] right-0 before:left-[--negative-terminal-size]",
|
|
26
|
-
vertical: "w-[--line-thickness] top-[--terminal-radius] bottom-0 before:top-[--negative-terminal-size]"
|
|
27
|
-
};
|
|
28
|
-
var edgeStyles = {
|
|
29
|
-
top: "top-[--line-offset] before:top-[--offset-terminal]",
|
|
30
|
-
right: "right-[--line-offset] before:right-[--offset-terminal]",
|
|
31
|
-
bottom: "bottom-[--line-offset] before:bottom-[--offset-terminal]",
|
|
32
|
-
left: "left-[--line-offset] before:left-[--offset-terminal]"
|
|
33
|
-
};
|
|
34
|
-
var strokeSize = 2;
|
|
35
|
-
var terminalSize = 8;
|
|
36
|
-
var offsetToAlignTerminalWithLine = (strokeSize - terminalSize) / 2;
|
|
37
|
-
var DropIndicator = ({ edge, gap = 0 }) => {
|
|
38
|
-
const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize}px))`;
|
|
39
|
-
const orientation = edgeToOrientationMap[edge];
|
|
40
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
41
|
-
style: {
|
|
42
|
-
"--line-thickness": `${strokeSize}px`,
|
|
43
|
-
"--line-offset": `${lineOffset}`,
|
|
44
|
-
"--terminal-size": `${terminalSize}px`,
|
|
45
|
-
"--terminal-radius": `${terminalSize / 2}px`,
|
|
46
|
-
"--negative-terminal-size": `-${terminalSize}px`,
|
|
47
|
-
"--offset-terminal": `${offsetToAlignTerminalWithLine}px`
|
|
48
|
-
},
|
|
49
|
-
className: mx("absolute z-10 pointer-events-none bg-blue-700", "before:content-[''] before:w-[--terminal-size] before:h-[--terminal-size] box-border before:absolute", "before:border-[length:--line-thickness] before:border-solid before:border-blue-700 before:rounded-full", orientationStyles[orientation], edgeStyles[edge])
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
14
|
|
|
53
15
|
// packages/ui/react-ui-list/src/components/List/ListRoot.tsx
|
|
54
16
|
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
55
17
|
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
56
18
|
import { getReorderDestinationIndex } from "@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index";
|
|
57
19
|
import { createContext } from "@radix-ui/react-context";
|
|
58
|
-
import
|
|
20
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
59
21
|
var LIST_NAME = "List";
|
|
60
22
|
var [ListProvider, useListContext] = createContext(LIST_NAME);
|
|
61
23
|
var defaultGetId = (item) => item?.id;
|
|
@@ -108,7 +70,7 @@ var ListRoot = ({ classNames, children, items, isItem, getId = defaultGetId, onM
|
|
|
108
70
|
isEqual,
|
|
109
71
|
onMove
|
|
110
72
|
]);
|
|
111
|
-
return /* @__PURE__ */
|
|
73
|
+
return /* @__PURE__ */ React.createElement(ListProvider, {
|
|
112
74
|
isItem,
|
|
113
75
|
state,
|
|
114
76
|
setState,
|
|
@@ -130,7 +92,7 @@ var stateStyles = {
|
|
|
130
92
|
var defaultContext = {};
|
|
131
93
|
var LIST_ITEM_NAME = "ListItem";
|
|
132
94
|
var [ListItemProvider, useListItemContext] = createContext2(LIST_ITEM_NAME, defaultContext);
|
|
133
|
-
var ListItem = ({ children, classNames, item }) => {
|
|
95
|
+
var ListItem = ({ children, classNames, item, ...props }) => {
|
|
134
96
|
const { isItem, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
|
|
135
97
|
const ref = useRef(null);
|
|
136
98
|
const dragHandleRef = useRef(null);
|
|
@@ -176,6 +138,8 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
176
138
|
container,
|
|
177
139
|
item
|
|
178
140
|
});
|
|
141
|
+
return () => {
|
|
142
|
+
};
|
|
179
143
|
}
|
|
180
144
|
});
|
|
181
145
|
} : void 0,
|
|
@@ -242,25 +206,27 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
242
206
|
}, [
|
|
243
207
|
item
|
|
244
208
|
]);
|
|
245
|
-
return /* @__PURE__ */
|
|
209
|
+
return /* @__PURE__ */ React2.createElement(ListItemProvider, {
|
|
246
210
|
item,
|
|
247
211
|
dragHandleRef
|
|
248
|
-
}, /* @__PURE__ */
|
|
212
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
213
|
+
role: "none",
|
|
249
214
|
className: "relative"
|
|
250
|
-
}, /* @__PURE__ */
|
|
215
|
+
}, /* @__PURE__ */ React2.createElement("div", {
|
|
251
216
|
ref,
|
|
252
217
|
role: "listitem",
|
|
253
|
-
className:
|
|
254
|
-
|
|
218
|
+
className: mx("flex overflow-hidden", classNames, stateStyles[state.type]),
|
|
219
|
+
...props
|
|
220
|
+
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ React2.createElement(NaturalListItem.DropIndicator, {
|
|
255
221
|
edge: state.closestEdge
|
|
256
222
|
})));
|
|
257
223
|
};
|
|
258
224
|
var IconButton = /* @__PURE__ */ forwardRef(({ classNames, icon, ...props }, forwardedRef) => {
|
|
259
|
-
return /* @__PURE__ */
|
|
225
|
+
return /* @__PURE__ */ React2.createElement("button", {
|
|
260
226
|
ref: forwardedRef,
|
|
261
|
-
className:
|
|
227
|
+
className: mx("flex items-center justify-center", classNames),
|
|
262
228
|
...props
|
|
263
|
-
}, /* @__PURE__ */
|
|
229
|
+
}, /* @__PURE__ */ React2.createElement(Icon, {
|
|
264
230
|
icon,
|
|
265
231
|
classNames: "cursor-pointer",
|
|
266
232
|
size: 4
|
|
@@ -269,7 +235,7 @@ var IconButton = /* @__PURE__ */ forwardRef(({ classNames, icon, ...props }, for
|
|
|
269
235
|
var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, ...props }) => {
|
|
270
236
|
const { state } = useListContext("DELETE_BUTTON");
|
|
271
237
|
const isDisabled = state.type !== "idle" || disabled;
|
|
272
|
-
return /* @__PURE__ */
|
|
238
|
+
return /* @__PURE__ */ React2.createElement(IconButton, {
|
|
273
239
|
icon: "ph--x--regular",
|
|
274
240
|
disabled: isDisabled,
|
|
275
241
|
classNames: [
|
|
@@ -281,7 +247,7 @@ var ListItemDeleteButton = ({ autoHide = true, classNames, disabled, ...props })
|
|
|
281
247
|
};
|
|
282
248
|
var ListItemDragHandle = () => {
|
|
283
249
|
const { dragHandleRef } = useListItemContext("DRAG_HANDLE");
|
|
284
|
-
return /* @__PURE__ */
|
|
250
|
+
return /* @__PURE__ */ React2.createElement(IconButton, {
|
|
285
251
|
ref: dragHandleRef,
|
|
286
252
|
icon: "ph--dots-six-vertical--regular"
|
|
287
253
|
});
|
|
@@ -292,11 +258,11 @@ var ListItemDragPreview = ({ children }) => {
|
|
|
292
258
|
item: state.item
|
|
293
259
|
}), state.container) : null;
|
|
294
260
|
};
|
|
295
|
-
var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */
|
|
296
|
-
className:
|
|
261
|
+
var ListItemWrapper = ({ classNames, children }) => /* @__PURE__ */ React2.createElement("div", {
|
|
262
|
+
className: mx("flex is-full gap-2", classNames)
|
|
297
263
|
}, children);
|
|
298
|
-
var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */
|
|
299
|
-
className:
|
|
264
|
+
var ListItemTitle = ({ classNames, children, ...props }) => /* @__PURE__ */ React2.createElement("div", {
|
|
265
|
+
className: mx("flex grow items-center truncate", classNames),
|
|
300
266
|
...props
|
|
301
267
|
}, children);
|
|
302
268
|
|
|
@@ -313,7 +279,7 @@ var List = {
|
|
|
313
279
|
};
|
|
314
280
|
|
|
315
281
|
// packages/ui/react-ui-list/src/components/Tree/Tree.tsx
|
|
316
|
-
import
|
|
282
|
+
import React6, { useMemo as useMemo2 } from "react";
|
|
317
283
|
import { Treegrid as Treegrid2 } from "@dxos/react-ui";
|
|
318
284
|
|
|
319
285
|
// packages/ui/react-ui-list/src/components/Tree/TreeContext.tsx
|
|
@@ -325,65 +291,19 @@ var TreeProvider = TreeContext.Provider;
|
|
|
325
291
|
|
|
326
292
|
// packages/ui/react-ui-list/src/components/Tree/TreeItem.tsx
|
|
327
293
|
import { combine as combine2 } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
328
|
-
import { draggable as
|
|
294
|
+
import { draggable as draggable2, dropTargetForElements as dropTargetForElements2 } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
329
295
|
import { attachInstruction, extractInstruction } from "@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item";
|
|
330
|
-
import
|
|
296
|
+
import React5, { memo as memo3, useCallback as useCallback3, useEffect as useEffect3, useMemo, useRef as useRef2, useState as useState3 } from "react";
|
|
331
297
|
import { S } from "@dxos/echo-schema";
|
|
332
298
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
333
|
-
import { Treegrid } from "@dxos/react-ui";
|
|
334
|
-
import {
|
|
335
|
-
|
|
336
|
-
// packages/ui/react-ui-list/src/components/Tree/DropIndicator.tsx
|
|
337
|
-
import React4 from "react";
|
|
338
|
-
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
339
|
-
var edgeToOrientationMap2 = {
|
|
340
|
-
"reorder-above": "sibling",
|
|
341
|
-
"reorder-below": "sibling",
|
|
342
|
-
"make-child": "child",
|
|
343
|
-
reparent: "child"
|
|
344
|
-
};
|
|
345
|
-
var orientationStyles2 = {
|
|
346
|
-
// TODO(wittjosiah): Stop using left/right here.
|
|
347
|
-
sibling: "bs-[--line-thickness] left-[--horizontal-indent] right-0 bg-accentSurface before:left-[--negative-terminal-size]",
|
|
348
|
-
child: "is-full block-start-0 block-end-0 border-[length:--line-thickness] before:invisible"
|
|
349
|
-
};
|
|
350
|
-
var instructionStyles = {
|
|
351
|
-
"reorder-above": "block-start-[--line-offset] before:block-start-[--offset-terminal]",
|
|
352
|
-
"reorder-below": "block-end-[--line-offset] before:block-end-[--offset-terminal]",
|
|
353
|
-
"make-child": "border-accentSurface",
|
|
354
|
-
// TODO(wittjosiah): This is not occurring in the current implementation.
|
|
355
|
-
reparent: ""
|
|
356
|
-
};
|
|
357
|
-
var strokeSize2 = 2;
|
|
358
|
-
var terminalSize2 = 8;
|
|
359
|
-
var offsetToAlignTerminalWithLine2 = (strokeSize2 - terminalSize2) / 2;
|
|
360
|
-
var DropIndicator2 = ({ instruction, gap = 0 }) => {
|
|
361
|
-
const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize2}px))`;
|
|
362
|
-
const isBlocked = instruction.type === "instruction-blocked";
|
|
363
|
-
const desiredInstruction = isBlocked ? instruction.desired : instruction;
|
|
364
|
-
const orientation = edgeToOrientationMap2[desiredInstruction.type];
|
|
365
|
-
if (isBlocked) {
|
|
366
|
-
return null;
|
|
367
|
-
}
|
|
368
|
-
return /* @__PURE__ */ React4.createElement("div", {
|
|
369
|
-
style: {
|
|
370
|
-
"--line-thickness": `${strokeSize2}px`,
|
|
371
|
-
"--line-offset": `${lineOffset}`,
|
|
372
|
-
"--terminal-size": `${terminalSize2}px`,
|
|
373
|
-
"--terminal-radius": `${terminalSize2 / 2}px`,
|
|
374
|
-
"--negative-terminal-size": `-${terminalSize2}px`,
|
|
375
|
-
"--offset-terminal": `${offsetToAlignTerminalWithLine2}px`,
|
|
376
|
-
"--horizontal-indent": `${desiredInstruction.currentLevel * desiredInstruction.indentPerLevel + 4}px`
|
|
377
|
-
},
|
|
378
|
-
className: mx3("absolute z-10 pointer-events-none", "before:is-[--terminal-size] before:bs-[--terminal-size] box-border before:absolute", "before:border-[length:--line-thickness] before:border-solid before:border-accentSurface before:rounded-full", orientationStyles2[orientation], instructionStyles[desiredInstruction.type])
|
|
379
|
-
});
|
|
380
|
-
};
|
|
299
|
+
import { Treegrid, TreeItem as NaturalTreeItem } from "@dxos/react-ui";
|
|
300
|
+
import { ghostHover, hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, mx as mx4 } from "@dxos/react-ui-theme";
|
|
381
301
|
|
|
382
302
|
// packages/ui/react-ui-list/src/components/Tree/TreeItemHeading.tsx
|
|
383
|
-
import
|
|
303
|
+
import React3, { forwardRef as forwardRef2, memo, useCallback as useCallback2 } from "react";
|
|
384
304
|
import { Button, Icon as Icon2, toLocalizedString, useTranslation } from "@dxos/react-ui";
|
|
385
305
|
import { TextTooltip } from "@dxos/react-ui-text-tooltip";
|
|
386
|
-
import { mx as
|
|
306
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
387
307
|
var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef2(({ label, icon, className, disabled, current, onSelect }, forwardedRef) => {
|
|
388
308
|
const { t } = useTranslation();
|
|
389
309
|
const handleSelect = useCallback2((event) => {
|
|
@@ -400,57 +320,57 @@ var TreeItemHeading = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef2(({ label,
|
|
|
400
320
|
}, [
|
|
401
321
|
onSelect
|
|
402
322
|
]);
|
|
403
|
-
return /* @__PURE__ */
|
|
323
|
+
return /* @__PURE__ */ React3.createElement(TextTooltip, {
|
|
404
324
|
text: toLocalizedString(label, t),
|
|
405
325
|
side: "bottom",
|
|
406
326
|
truncateQuery: "span[data-tooltip]",
|
|
407
327
|
onlyWhenTruncating: true,
|
|
408
328
|
asChild: true,
|
|
409
329
|
ref: forwardedRef
|
|
410
|
-
}, /* @__PURE__ */
|
|
330
|
+
}, /* @__PURE__ */ React3.createElement(Button, {
|
|
411
331
|
"data-testid": "treeItem.heading",
|
|
412
332
|
variant: "ghost",
|
|
413
333
|
density: "fine",
|
|
414
|
-
classNames:
|
|
334
|
+
classNames: mx2("grow gap-2 pis-0.5 hover:bg-transparent dark:hover:bg-transparent", "disabled:cursor-default disabled:opacity-100", className),
|
|
415
335
|
disabled,
|
|
416
336
|
onClick: handleSelect,
|
|
417
337
|
onKeyDown: handleButtonKeydown,
|
|
418
338
|
...current && {
|
|
419
339
|
"aria-current": "location"
|
|
420
340
|
}
|
|
421
|
-
}, icon && /* @__PURE__ */
|
|
341
|
+
}, icon && /* @__PURE__ */ React3.createElement(Icon2, {
|
|
422
342
|
icon: icon ?? "ph--placeholder--regular",
|
|
423
343
|
size: 4,
|
|
424
344
|
classNames: "is-[1em] bs-[1em] mlb-1"
|
|
425
|
-
}), /* @__PURE__ */
|
|
345
|
+
}), /* @__PURE__ */ React3.createElement("span", {
|
|
426
346
|
className: "flex-1 is-0 truncate text-start text-sm font-normal",
|
|
427
347
|
"data-tooltip": true
|
|
428
348
|
}, toLocalizedString(label, t))));
|
|
429
349
|
}));
|
|
430
350
|
|
|
431
351
|
// packages/ui/react-ui-list/src/components/Tree/TreeItemToggle.tsx
|
|
432
|
-
import
|
|
352
|
+
import React4, { forwardRef as forwardRef3, memo as memo2 } from "react";
|
|
433
353
|
import { Button as Button2, Icon as Icon3 } from "@dxos/react-ui";
|
|
434
|
-
import { mx as
|
|
435
|
-
var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef3(({ open, isBranch, onToggle }, forwardedRef) => {
|
|
436
|
-
return /* @__PURE__ */
|
|
354
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
355
|
+
var TreeItemToggle = /* @__PURE__ */ memo2(/* @__PURE__ */ forwardRef3(({ open, isBranch, hidden, onToggle }, forwardedRef) => {
|
|
356
|
+
return /* @__PURE__ */ React4.createElement(Button2, {
|
|
437
357
|
ref: forwardedRef,
|
|
438
358
|
"data-testid": "treeItem.toggle",
|
|
439
359
|
"aria-expanded": open,
|
|
440
360
|
variant: "ghost",
|
|
441
361
|
density: "fine",
|
|
442
|
-
classNames:
|
|
362
|
+
classNames: mx3("is-4 dx-focus-ring-inset pli-0", hidden ? "hidden" : !isBranch && "invisible"),
|
|
443
363
|
onClick: onToggle
|
|
444
|
-
}, /* @__PURE__ */
|
|
364
|
+
}, /* @__PURE__ */ React4.createElement(Icon3, {
|
|
445
365
|
icon: "ph--caret-right--regular",
|
|
446
366
|
size: 3,
|
|
447
|
-
classNames:
|
|
367
|
+
classNames: mx3("transition duration-200", open && "rotate-90")
|
|
448
368
|
}));
|
|
449
369
|
}));
|
|
450
370
|
|
|
451
371
|
// packages/ui/react-ui-list/src/components/Tree/helpers.ts
|
|
452
372
|
var DEFAULT_INDENTATION = 8;
|
|
453
|
-
var
|
|
373
|
+
var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
|
|
454
374
|
paddingInlineStart: `${(level - 1) * indentation}px`
|
|
455
375
|
});
|
|
456
376
|
|
|
@@ -463,7 +383,7 @@ var TreeDataSchema = S.Struct({
|
|
|
463
383
|
item: S.Any
|
|
464
384
|
});
|
|
465
385
|
var isTreeData = (data) => S.is(TreeDataSchema)(data);
|
|
466
|
-
var RawTreeItem = ({ item, path: _path, last, draggable:
|
|
386
|
+
var RawTreeItem = ({ item, path: _path, last, draggable: _draggable, renderColumns: Columns, canDrop, onOpenChange, onSelect, levelOffset = 2 }) => {
|
|
467
387
|
const { getItems, getProps, isOpen, isCurrent } = useTree();
|
|
468
388
|
const items = getItems(item);
|
|
469
389
|
const { id, label, parentOf, icon, disabled, className, headingClassName, testId } = getProps(item, _path);
|
|
@@ -476,7 +396,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
476
396
|
]);
|
|
477
397
|
const open = isOpen(path, item);
|
|
478
398
|
const current = isCurrent(path, item);
|
|
479
|
-
const level = path.length -
|
|
399
|
+
const level = path.length - levelOffset;
|
|
480
400
|
const isBranch = !!parentOf;
|
|
481
401
|
const mode = last ? "last-in-group" : open ? "expanded" : "standard";
|
|
482
402
|
const data = useMemo(() => ({
|
|
@@ -502,94 +422,98 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
502
422
|
}
|
|
503
423
|
}, []);
|
|
504
424
|
useEffect3(() => {
|
|
505
|
-
if (!
|
|
425
|
+
if (!_draggable) {
|
|
506
426
|
return;
|
|
507
427
|
}
|
|
508
428
|
invariant2(buttonRef.current, void 0, {
|
|
509
429
|
F: __dxlog_file2,
|
|
510
|
-
L:
|
|
430
|
+
L: 106,
|
|
511
431
|
S: void 0,
|
|
512
432
|
A: [
|
|
513
433
|
"buttonRef.current",
|
|
514
434
|
""
|
|
515
435
|
]
|
|
516
436
|
});
|
|
517
|
-
return combine2(
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
437
|
+
return combine2(
|
|
438
|
+
draggable2({
|
|
439
|
+
element: buttonRef.current,
|
|
440
|
+
getInitialData: () => data,
|
|
441
|
+
onDragStart: () => {
|
|
442
|
+
setState("dragging");
|
|
443
|
+
if (open) {
|
|
444
|
+
openRef.current = true;
|
|
445
|
+
onOpenChange?.({
|
|
446
|
+
item,
|
|
447
|
+
path,
|
|
448
|
+
open: false
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
onDrop: () => {
|
|
453
|
+
setState("idle");
|
|
454
|
+
if (openRef.current) {
|
|
455
|
+
onOpenChange?.({
|
|
456
|
+
item,
|
|
457
|
+
path,
|
|
458
|
+
open: true
|
|
459
|
+
});
|
|
460
|
+
}
|
|
529
461
|
}
|
|
530
|
-
},
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
462
|
+
}),
|
|
463
|
+
// https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
|
|
464
|
+
dropTargetForElements2({
|
|
465
|
+
element: buttonRef.current,
|
|
466
|
+
getData: ({ input, element }) => {
|
|
467
|
+
return attachInstruction(data, {
|
|
468
|
+
input,
|
|
469
|
+
element,
|
|
470
|
+
indentPerLevel: DEFAULT_INDENTATION,
|
|
471
|
+
currentLevel: level,
|
|
472
|
+
mode,
|
|
473
|
+
block: isBranch ? [] : [
|
|
474
|
+
"make-child"
|
|
475
|
+
]
|
|
538
476
|
});
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
onOpenChange?.({
|
|
566
|
-
item,
|
|
567
|
-
path,
|
|
568
|
-
open: true
|
|
569
|
-
});
|
|
570
|
-
}, 500);
|
|
571
|
-
}
|
|
572
|
-
if (instruction2?.type !== "make-child") {
|
|
573
|
-
cancelExpand();
|
|
477
|
+
},
|
|
478
|
+
canDrop: ({ source }) => {
|
|
479
|
+
const _canDrop = canDrop ?? (() => true);
|
|
480
|
+
return source.element !== buttonRef.current && _canDrop(source.data, data);
|
|
481
|
+
},
|
|
482
|
+
getIsSticky: () => true,
|
|
483
|
+
onDrag: ({ self, source }) => {
|
|
484
|
+
const instruction2 = extractInstruction(self.data);
|
|
485
|
+
if (source.data.id !== id) {
|
|
486
|
+
if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
|
|
487
|
+
cancelExpandRef.current = setTimeout(() => {
|
|
488
|
+
onOpenChange?.({
|
|
489
|
+
item,
|
|
490
|
+
path,
|
|
491
|
+
open: true
|
|
492
|
+
});
|
|
493
|
+
}, 500);
|
|
494
|
+
}
|
|
495
|
+
if (instruction2?.type !== "make-child") {
|
|
496
|
+
cancelExpand();
|
|
497
|
+
}
|
|
498
|
+
setInstruction(instruction2);
|
|
499
|
+
} else if (instruction2?.type === "reparent") {
|
|
500
|
+
setInstruction(instruction2);
|
|
501
|
+
} else {
|
|
502
|
+
setInstruction(null);
|
|
574
503
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
504
|
+
},
|
|
505
|
+
onDragLeave: () => {
|
|
506
|
+
cancelExpand();
|
|
507
|
+
setInstruction(null);
|
|
508
|
+
},
|
|
509
|
+
onDrop: () => {
|
|
510
|
+
cancelExpand();
|
|
579
511
|
setInstruction(null);
|
|
580
512
|
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
cancelExpand();
|
|
584
|
-
setInstruction(null);
|
|
585
|
-
},
|
|
586
|
-
onDrop: () => {
|
|
587
|
-
cancelExpand();
|
|
588
|
-
setInstruction(null);
|
|
589
|
-
}
|
|
590
|
-
}));
|
|
513
|
+
})
|
|
514
|
+
);
|
|
591
515
|
}, [
|
|
592
|
-
|
|
516
|
+
_draggable,
|
|
593
517
|
item,
|
|
594
518
|
id,
|
|
595
519
|
mode,
|
|
@@ -642,13 +566,13 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
642
566
|
handleOpenChange,
|
|
643
567
|
handleSelect
|
|
644
568
|
]);
|
|
645
|
-
return /* @__PURE__ */
|
|
569
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(Treegrid.Row, {
|
|
646
570
|
ref: rowRef,
|
|
647
571
|
key: id,
|
|
648
572
|
id,
|
|
649
573
|
"aria-labelledby": `${id}__label`,
|
|
650
574
|
parentOf: parentOf?.join(Treegrid.PARENT_OF_SEPARATOR),
|
|
651
|
-
classNames:
|
|
575
|
+
classNames: mx4("grid grid-cols-subgrid col-[tree-row] mbs-0.5 aria-[current]:bg-input", hoverableControls, hoverableFocusedKeyboardControls, hoverableFocusedWithinControls, hoverableDescriptionIcons, ghostHover, className),
|
|
652
576
|
"data-itemid": id,
|
|
653
577
|
"data-testid": testId,
|
|
654
578
|
// NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
|
|
@@ -660,18 +584,18 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
660
584
|
event.preventDefault();
|
|
661
585
|
setMenuOpen(true);
|
|
662
586
|
}
|
|
663
|
-
}, /* @__PURE__ */
|
|
587
|
+
}, /* @__PURE__ */ React5.createElement(Treegrid.Cell, {
|
|
664
588
|
indent: true,
|
|
665
589
|
classNames: "relative grid grid-cols-subgrid col-[tree-row]",
|
|
666
|
-
style:
|
|
667
|
-
}, /* @__PURE__ */
|
|
590
|
+
style: paddingIndentation(level)
|
|
591
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
668
592
|
role: "none",
|
|
669
593
|
className: "flex items-center"
|
|
670
|
-
}, /* @__PURE__ */
|
|
594
|
+
}, /* @__PURE__ */ React5.createElement(TreeItemToggle, {
|
|
671
595
|
open,
|
|
672
596
|
isBranch,
|
|
673
597
|
onToggle: handleOpenChange
|
|
674
|
-
}), /* @__PURE__ */
|
|
598
|
+
}), /* @__PURE__ */ React5.createElement(TreeItemHeading, {
|
|
675
599
|
ref: buttonRef,
|
|
676
600
|
label,
|
|
677
601
|
icon,
|
|
@@ -679,20 +603,21 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
679
603
|
disabled,
|
|
680
604
|
current,
|
|
681
605
|
onSelect: handleSelect
|
|
682
|
-
})), Columns && /* @__PURE__ */
|
|
606
|
+
})), Columns && /* @__PURE__ */ React5.createElement(Columns, {
|
|
683
607
|
item,
|
|
684
608
|
path,
|
|
609
|
+
open,
|
|
685
610
|
menuOpen,
|
|
686
611
|
setMenuOpen
|
|
687
|
-
}), instruction && /* @__PURE__ */
|
|
612
|
+
}), instruction && /* @__PURE__ */ React5.createElement(NaturalTreeItem.DropIndicator, {
|
|
688
613
|
instruction,
|
|
689
614
|
gap: 2
|
|
690
|
-
}))), open && items.map((item2, index) => /* @__PURE__ */
|
|
615
|
+
}))), open && items.map((item2, index) => /* @__PURE__ */ React5.createElement(TreeItem, {
|
|
691
616
|
key: item2.id,
|
|
692
617
|
item: item2,
|
|
693
618
|
path,
|
|
694
619
|
last: index === items.length - 1,
|
|
695
|
-
draggable:
|
|
620
|
+
draggable: _draggable,
|
|
696
621
|
renderColumns: Columns,
|
|
697
622
|
canDrop,
|
|
698
623
|
onOpenChange,
|
|
@@ -702,7 +627,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
702
627
|
var TreeItem = /* @__PURE__ */ memo3(RawTreeItem);
|
|
703
628
|
|
|
704
629
|
// packages/ui/react-ui-list/src/components/Tree/Tree.tsx
|
|
705
|
-
var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable:
|
|
630
|
+
var Tree = ({ root, path, id, getItems, getProps, isOpen, isCurrent, draggable: draggable3 = false, gridTemplateColumns = "[tree-row-start] 1fr min-content [tree-row-end]", classNames, renderColumns, canDrop, onOpenChange, onSelect, levelOffset }) => {
|
|
706
631
|
const context = useMemo2(() => ({
|
|
707
632
|
getItems,
|
|
708
633
|
getProps,
|
|
@@ -714,23 +639,28 @@ var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable: draggable2 =
|
|
|
714
639
|
isOpen,
|
|
715
640
|
isCurrent
|
|
716
641
|
]);
|
|
717
|
-
const items = getItems();
|
|
718
|
-
const
|
|
642
|
+
const items = getItems(root);
|
|
643
|
+
const treePath = useMemo2(() => path ? [
|
|
644
|
+
...path,
|
|
719
645
|
id
|
|
720
|
-
]
|
|
646
|
+
] : [
|
|
721
647
|
id
|
|
648
|
+
], [
|
|
649
|
+
id,
|
|
650
|
+
path
|
|
722
651
|
]);
|
|
723
|
-
return /* @__PURE__ */
|
|
652
|
+
return /* @__PURE__ */ React6.createElement(Treegrid2.Root, {
|
|
724
653
|
gridTemplateColumns,
|
|
725
654
|
classNames
|
|
726
|
-
}, /* @__PURE__ */
|
|
655
|
+
}, /* @__PURE__ */ React6.createElement(TreeProvider, {
|
|
727
656
|
value: context
|
|
728
|
-
}, items.map((item, index) => /* @__PURE__ */
|
|
657
|
+
}, items.map((item, index) => /* @__PURE__ */ React6.createElement(TreeItem, {
|
|
729
658
|
key: item.id,
|
|
730
659
|
item,
|
|
731
660
|
last: index === items.length - 1,
|
|
732
|
-
path,
|
|
733
|
-
|
|
661
|
+
path: treePath,
|
|
662
|
+
levelOffset,
|
|
663
|
+
draggable: draggable3,
|
|
734
664
|
renderColumns,
|
|
735
665
|
canDrop,
|
|
736
666
|
onOpenChange,
|