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