@dxos/react-ui-list 0.7.4 → 0.7.5-labs.35b4b42
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 +145 -217
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +153 -221
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +145 -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.map +1 -1
- package/dist/types/src/components/List/ListItem.d.ts +3 -6
- 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 +5 -3
- 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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -48,73 +48,35 @@ var import_react_dom = require("react-dom");
|
|
|
48
48
|
var import_invariant = require("@dxos/invariant");
|
|
49
49
|
var import_react_ui = require("@dxos/react-ui");
|
|
50
50
|
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
51
|
-
var import_react2 = __toESM(require("react"));
|
|
52
|
-
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
53
51
|
var import_adapter2 = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
54
52
|
var import_closest_edge2 = require("@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge");
|
|
55
53
|
var import_get_reorder_destination_index = require("@atlaskit/pragmatic-drag-and-drop-hitbox/util/get-reorder-destination-index");
|
|
56
54
|
var import_react_context2 = require("@radix-ui/react-context");
|
|
55
|
+
var import_react2 = __toESM(require("react"));
|
|
57
56
|
var import_react3 = __toESM(require("react"));
|
|
58
|
-
var import_react4 = __toESM(require("react"));
|
|
59
57
|
var import_react_ui2 = require("@dxos/react-ui");
|
|
60
|
-
var
|
|
58
|
+
var import_react4 = require("react");
|
|
61
59
|
var import_debug = require("@dxos/debug");
|
|
62
60
|
var import_combine2 = require("@atlaskit/pragmatic-drag-and-drop/combine");
|
|
63
61
|
var import_adapter3 = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
64
62
|
var import_tree_item = require("@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item");
|
|
65
|
-
var
|
|
63
|
+
var import_react5 = __toESM(require("react"));
|
|
66
64
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
67
65
|
var import_invariant2 = require("@dxos/invariant");
|
|
68
66
|
var import_react_ui3 = require("@dxos/react-ui");
|
|
69
|
-
var
|
|
70
|
-
var
|
|
71
|
-
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
72
|
-
var import_react8 = __toESM(require("react"));
|
|
67
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
68
|
+
var import_react6 = __toESM(require("react"));
|
|
73
69
|
var import_react_ui4 = require("@dxos/react-ui");
|
|
74
70
|
var import_react_ui_text_tooltip = require("@dxos/react-ui-text-tooltip");
|
|
75
|
-
var
|
|
76
|
-
var
|
|
71
|
+
var import_react_ui_theme3 = require("@dxos/react-ui-theme");
|
|
72
|
+
var import_react7 = __toESM(require("react"));
|
|
77
73
|
var import_react_ui5 = require("@dxos/react-ui");
|
|
78
|
-
var
|
|
79
|
-
var edgeToOrientationMap = {
|
|
80
|
-
top: "horizontal",
|
|
81
|
-
bottom: "horizontal",
|
|
82
|
-
left: "vertical",
|
|
83
|
-
right: "vertical"
|
|
84
|
-
};
|
|
85
|
-
var orientationStyles = {
|
|
86
|
-
horizontal: "h-[--line-thickness] left-[--terminal-radius] right-0 before:left-[--negative-terminal-size]",
|
|
87
|
-
vertical: "w-[--line-thickness] top-[--terminal-radius] bottom-0 before:top-[--negative-terminal-size]"
|
|
88
|
-
};
|
|
89
|
-
var edgeStyles = {
|
|
90
|
-
top: "top-[--line-offset] before:top-[--offset-terminal]",
|
|
91
|
-
right: "right-[--line-offset] before:right-[--offset-terminal]",
|
|
92
|
-
bottom: "bottom-[--line-offset] before:bottom-[--offset-terminal]",
|
|
93
|
-
left: "left-[--line-offset] before:left-[--offset-terminal]"
|
|
94
|
-
};
|
|
95
|
-
var strokeSize = 2;
|
|
96
|
-
var terminalSize = 8;
|
|
97
|
-
var offsetToAlignTerminalWithLine = (strokeSize - terminalSize) / 2;
|
|
98
|
-
var DropIndicator = ({ edge, gap = 0 }) => {
|
|
99
|
-
const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize}px))`;
|
|
100
|
-
const orientation = edgeToOrientationMap[edge];
|
|
101
|
-
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
102
|
-
style: {
|
|
103
|
-
"--line-thickness": `${strokeSize}px`,
|
|
104
|
-
"--line-offset": `${lineOffset}`,
|
|
105
|
-
"--terminal-size": `${terminalSize}px`,
|
|
106
|
-
"--terminal-radius": `${terminalSize / 2}px`,
|
|
107
|
-
"--negative-terminal-size": `-${terminalSize}px`,
|
|
108
|
-
"--offset-terminal": `${offsetToAlignTerminalWithLine}px`
|
|
109
|
-
},
|
|
110
|
-
className: (0, import_react_ui_theme2.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])
|
|
111
|
-
});
|
|
112
|
-
};
|
|
74
|
+
var import_react_ui_theme4 = require("@dxos/react-ui-theme");
|
|
113
75
|
var LIST_NAME = "List";
|
|
114
76
|
var [ListProvider, useListContext] = (0, import_react_context2.createContext)(LIST_NAME);
|
|
115
77
|
var defaultGetId = (item) => item?.id;
|
|
116
78
|
var ListRoot = ({ classNames, children, items, isItem, getId = defaultGetId, onMove, ...props }) => {
|
|
117
|
-
const isEqual = (0,
|
|
79
|
+
const isEqual = (0, import_react2.useCallback)((a, b) => {
|
|
118
80
|
const idA = getId?.(a);
|
|
119
81
|
const idB = getId?.(b);
|
|
120
82
|
if (idA !== void 0 && idB !== void 0) {
|
|
@@ -125,8 +87,8 @@ var ListRoot = ({ classNames, children, items, isItem, getId = defaultGetId, onM
|
|
|
125
87
|
}, [
|
|
126
88
|
getId
|
|
127
89
|
]);
|
|
128
|
-
const [state, setState] = (0,
|
|
129
|
-
(0,
|
|
90
|
+
const [state, setState] = (0, import_react2.useState)(idle);
|
|
91
|
+
(0, import_react2.useEffect)(() => {
|
|
130
92
|
if (!items) {
|
|
131
93
|
return;
|
|
132
94
|
}
|
|
@@ -162,7 +124,7 @@ var ListRoot = ({ classNames, children, items, isItem, getId = defaultGetId, onM
|
|
|
162
124
|
isEqual,
|
|
163
125
|
onMove
|
|
164
126
|
]);
|
|
165
|
-
return /* @__PURE__ */
|
|
127
|
+
return /* @__PURE__ */ import_react2.default.createElement(ListProvider, {
|
|
166
128
|
isItem,
|
|
167
129
|
state,
|
|
168
130
|
setState,
|
|
@@ -191,7 +153,7 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
191
153
|
const element = ref.current;
|
|
192
154
|
(0, import_invariant.invariant)(element, void 0, {
|
|
193
155
|
F: __dxlog_file,
|
|
194
|
-
L:
|
|
156
|
+
L: 90,
|
|
195
157
|
S: void 0,
|
|
196
158
|
A: [
|
|
197
159
|
"element",
|
|
@@ -228,6 +190,8 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
228
190
|
container,
|
|
229
191
|
item
|
|
230
192
|
});
|
|
193
|
+
return () => {
|
|
194
|
+
};
|
|
231
195
|
}
|
|
232
196
|
});
|
|
233
197
|
} : void 0,
|
|
@@ -303,7 +267,7 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
303
267
|
ref,
|
|
304
268
|
role: "listitem",
|
|
305
269
|
className: (0, import_react_ui_theme.mx)("flex overflow-hidden", classNames, stateStyles[state.type])
|
|
306
|
-
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ import_react.default.createElement(DropIndicator, {
|
|
270
|
+
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ import_react.default.createElement(import_react_ui.ListItem.DropIndicator, {
|
|
307
271
|
edge: state.closestEdge
|
|
308
272
|
})));
|
|
309
273
|
};
|
|
@@ -361,59 +325,17 @@ var List = {
|
|
|
361
325
|
ItemTitle: ListItemTitle,
|
|
362
326
|
IconButton
|
|
363
327
|
};
|
|
364
|
-
var TreeContext = /* @__PURE__ */ (0,
|
|
365
|
-
var useTree = () => (0,
|
|
328
|
+
var TreeContext = /* @__PURE__ */ (0, import_react4.createContext)(null);
|
|
329
|
+
var useTree = () => (0, import_react4.useContext)(TreeContext) ?? (0, import_debug.raise)(new Error("TreeContext not found"));
|
|
366
330
|
var TreeProvider = TreeContext.Provider;
|
|
367
|
-
var
|
|
368
|
-
"reorder-above": "sibling",
|
|
369
|
-
"reorder-below": "sibling",
|
|
370
|
-
"make-child": "child",
|
|
371
|
-
reparent: "child"
|
|
372
|
-
};
|
|
373
|
-
var orientationStyles2 = {
|
|
374
|
-
// TODO(wittjosiah): Stop using left/right here.
|
|
375
|
-
sibling: "bs-[--line-thickness] left-[--horizontal-indent] right-0 bg-accentSurface before:left-[--negative-terminal-size]",
|
|
376
|
-
child: "is-full block-start-0 block-end-0 border-[length:--line-thickness] before:invisible"
|
|
377
|
-
};
|
|
378
|
-
var instructionStyles = {
|
|
379
|
-
"reorder-above": "block-start-[--line-offset] before:block-start-[--offset-terminal]",
|
|
380
|
-
"reorder-below": "block-end-[--line-offset] before:block-end-[--offset-terminal]",
|
|
381
|
-
"make-child": "border-accentSurface",
|
|
382
|
-
// TODO(wittjosiah): This is not occurring in the current implementation.
|
|
383
|
-
reparent: ""
|
|
384
|
-
};
|
|
385
|
-
var strokeSize2 = 2;
|
|
386
|
-
var terminalSize2 = 8;
|
|
387
|
-
var offsetToAlignTerminalWithLine2 = (strokeSize2 - terminalSize2) / 2;
|
|
388
|
-
var DropIndicator2 = ({ instruction, gap = 0 }) => {
|
|
389
|
-
const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize2}px))`;
|
|
390
|
-
const isBlocked = instruction.type === "instruction-blocked";
|
|
391
|
-
const desiredInstruction = isBlocked ? instruction.desired : instruction;
|
|
392
|
-
const orientation = edgeToOrientationMap2[desiredInstruction.type];
|
|
393
|
-
if (isBlocked) {
|
|
394
|
-
return null;
|
|
395
|
-
}
|
|
396
|
-
return /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
397
|
-
style: {
|
|
398
|
-
"--line-thickness": `${strokeSize2}px`,
|
|
399
|
-
"--line-offset": `${lineOffset}`,
|
|
400
|
-
"--terminal-size": `${terminalSize2}px`,
|
|
401
|
-
"--terminal-radius": `${terminalSize2 / 2}px`,
|
|
402
|
-
"--negative-terminal-size": `-${terminalSize2}px`,
|
|
403
|
-
"--offset-terminal": `${offsetToAlignTerminalWithLine2}px`,
|
|
404
|
-
"--horizontal-indent": `${desiredInstruction.currentLevel * desiredInstruction.indentPerLevel + 4}px`
|
|
405
|
-
},
|
|
406
|
-
className: (0, import_react_ui_theme4.mx)("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])
|
|
407
|
-
});
|
|
408
|
-
};
|
|
409
|
-
var TreeItemHeading = /* @__PURE__ */ (0, import_react8.memo)(/* @__PURE__ */ (0, import_react8.forwardRef)(({ label, icon, className, disabled, current, onSelect }, forwardedRef) => {
|
|
331
|
+
var TreeItemHeading = /* @__PURE__ */ (0, import_react6.memo)(/* @__PURE__ */ (0, import_react6.forwardRef)(({ label, icon, className, disabled, current, onSelect }, forwardedRef) => {
|
|
410
332
|
const { t } = (0, import_react_ui4.useTranslation)();
|
|
411
|
-
const handleSelect = (0,
|
|
333
|
+
const handleSelect = (0, import_react6.useCallback)((event) => {
|
|
412
334
|
onSelect?.(event.altKey);
|
|
413
335
|
}, [
|
|
414
336
|
onSelect
|
|
415
337
|
]);
|
|
416
|
-
const handleButtonKeydown = (0,
|
|
338
|
+
const handleButtonKeydown = (0, import_react6.useCallback)((event) => {
|
|
417
339
|
if (event.key === " " || event.key === "Enter") {
|
|
418
340
|
event.preventDefault();
|
|
419
341
|
event.stopPropagation();
|
|
@@ -422,50 +344,50 @@ var TreeItemHeading = /* @__PURE__ */ (0, import_react8.memo)(/* @__PURE__ */ (0
|
|
|
422
344
|
}, [
|
|
423
345
|
onSelect
|
|
424
346
|
]);
|
|
425
|
-
return /* @__PURE__ */
|
|
347
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui_text_tooltip.TextTooltip, {
|
|
426
348
|
text: (0, import_react_ui4.toLocalizedString)(label, t),
|
|
427
349
|
side: "bottom",
|
|
428
350
|
truncateQuery: "span[data-tooltip]",
|
|
429
351
|
onlyWhenTruncating: true,
|
|
430
352
|
asChild: true,
|
|
431
353
|
ref: forwardedRef
|
|
432
|
-
}, /* @__PURE__ */
|
|
354
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Button, {
|
|
433
355
|
"data-testid": "treeItem.heading",
|
|
434
356
|
variant: "ghost",
|
|
435
357
|
density: "fine",
|
|
436
|
-
classNames: (0,
|
|
358
|
+
classNames: (0, import_react_ui_theme3.mx)("grow gap-2 pis-0.5 hover:bg-transparent dark:hover:bg-transparent", "disabled:cursor-default disabled:opacity-100", className),
|
|
437
359
|
disabled,
|
|
438
360
|
onClick: handleSelect,
|
|
439
361
|
onKeyDown: handleButtonKeydown,
|
|
440
362
|
...current && {
|
|
441
363
|
"aria-current": "location"
|
|
442
364
|
}
|
|
443
|
-
}, icon && /* @__PURE__ */
|
|
365
|
+
}, icon && /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Icon, {
|
|
444
366
|
icon: icon ?? "ph--placeholder--regular",
|
|
445
367
|
size: 4,
|
|
446
368
|
classNames: "is-[1em] bs-[1em] mlb-1"
|
|
447
|
-
}), /* @__PURE__ */
|
|
369
|
+
}), /* @__PURE__ */ import_react6.default.createElement("span", {
|
|
448
370
|
className: "flex-1 is-0 truncate text-start text-sm font-normal",
|
|
449
371
|
"data-tooltip": true
|
|
450
372
|
}, (0, import_react_ui4.toLocalizedString)(label, t))));
|
|
451
373
|
}));
|
|
452
|
-
var TreeItemToggle = /* @__PURE__ */ (0,
|
|
453
|
-
return /* @__PURE__ */
|
|
374
|
+
var TreeItemToggle = /* @__PURE__ */ (0, import_react7.memo)(/* @__PURE__ */ (0, import_react7.forwardRef)(({ open, isBranch, hidden, onToggle }, forwardedRef) => {
|
|
375
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Button, {
|
|
454
376
|
ref: forwardedRef,
|
|
455
377
|
"data-testid": "treeItem.toggle",
|
|
456
378
|
"aria-expanded": open,
|
|
457
379
|
variant: "ghost",
|
|
458
380
|
density: "fine",
|
|
459
|
-
classNames: (0,
|
|
381
|
+
classNames: (0, import_react_ui_theme4.mx)("is-4 dx-focus-ring-inset pli-0", hidden ? "hidden" : !isBranch && "invisible"),
|
|
460
382
|
onClick: onToggle
|
|
461
|
-
}, /* @__PURE__ */
|
|
383
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
462
384
|
icon: "ph--caret-right--regular",
|
|
463
385
|
size: 3,
|
|
464
|
-
classNames: (0,
|
|
386
|
+
classNames: (0, import_react_ui_theme4.mx)("transition duration-200", open && "rotate-90")
|
|
465
387
|
}));
|
|
466
388
|
}));
|
|
467
389
|
var DEFAULT_INDENTATION = 8;
|
|
468
|
-
var
|
|
390
|
+
var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
|
|
469
391
|
paddingInlineStart: `${(level - 1) * indentation}px`
|
|
470
392
|
});
|
|
471
393
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-list/src/components/Tree/TreeItem.tsx";
|
|
@@ -476,11 +398,11 @@ var TreeDataSchema = import_echo_schema.S.Struct({
|
|
|
476
398
|
item: import_echo_schema.S.Any
|
|
477
399
|
});
|
|
478
400
|
var isTreeData = (data) => import_echo_schema.S.is(TreeDataSchema)(data);
|
|
479
|
-
var RawTreeItem = ({ item, path: _path, last, draggable:
|
|
401
|
+
var RawTreeItem = ({ item, path: _path, last, draggable: _draggable, renderColumns: Columns, canDrop, onOpenChange, onSelect, levelOffset = 2 }) => {
|
|
480
402
|
const { getItems, getProps, isOpen, isCurrent } = useTree();
|
|
481
403
|
const items = getItems(item);
|
|
482
404
|
const { id, label, parentOf, icon, disabled, className, headingClassName, testId } = getProps(item, _path);
|
|
483
|
-
const path = (0,
|
|
405
|
+
const path = (0, import_react5.useMemo)(() => [
|
|
484
406
|
..._path,
|
|
485
407
|
id
|
|
486
408
|
], [
|
|
@@ -489,10 +411,10 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
489
411
|
]);
|
|
490
412
|
const open = isOpen(path, item);
|
|
491
413
|
const current = isCurrent(path, item);
|
|
492
|
-
const level = path.length -
|
|
414
|
+
const level = path.length - levelOffset;
|
|
493
415
|
const isBranch = !!parentOf;
|
|
494
416
|
const mode = last ? "last-in-group" : open ? "expanded" : "standard";
|
|
495
|
-
const data = (0,
|
|
417
|
+
const data = (0, import_react5.useMemo)(() => ({
|
|
496
418
|
id,
|
|
497
419
|
path,
|
|
498
420
|
item
|
|
@@ -501,108 +423,112 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
501
423
|
path,
|
|
502
424
|
item
|
|
503
425
|
]);
|
|
504
|
-
const rowRef = (0,
|
|
505
|
-
const buttonRef = (0,
|
|
506
|
-
const openRef = (0,
|
|
507
|
-
const cancelExpandRef = (0,
|
|
508
|
-
const [_state, setState] = (0,
|
|
509
|
-
const [instruction, setInstruction] = (0,
|
|
510
|
-
const [menuOpen, setMenuOpen] = (0,
|
|
511
|
-
const cancelExpand = (0,
|
|
426
|
+
const rowRef = (0, import_react5.useRef)(null);
|
|
427
|
+
const buttonRef = (0, import_react5.useRef)(null);
|
|
428
|
+
const openRef = (0, import_react5.useRef)(false);
|
|
429
|
+
const cancelExpandRef = (0, import_react5.useRef)(null);
|
|
430
|
+
const [_state, setState] = (0, import_react5.useState)("idle");
|
|
431
|
+
const [instruction, setInstruction] = (0, import_react5.useState)(null);
|
|
432
|
+
const [menuOpen, setMenuOpen] = (0, import_react5.useState)(false);
|
|
433
|
+
const cancelExpand = (0, import_react5.useCallback)(() => {
|
|
512
434
|
if (cancelExpandRef.current) {
|
|
513
435
|
clearTimeout(cancelExpandRef.current);
|
|
514
436
|
cancelExpandRef.current = null;
|
|
515
437
|
}
|
|
516
438
|
}, []);
|
|
517
|
-
(0,
|
|
518
|
-
if (!
|
|
439
|
+
(0, import_react5.useEffect)(() => {
|
|
440
|
+
if (!_draggable) {
|
|
519
441
|
return;
|
|
520
442
|
}
|
|
521
443
|
(0, import_invariant2.invariant)(buttonRef.current, void 0, {
|
|
522
444
|
F: __dxlog_file2,
|
|
523
|
-
L:
|
|
445
|
+
L: 106,
|
|
524
446
|
S: void 0,
|
|
525
447
|
A: [
|
|
526
448
|
"buttonRef.current",
|
|
527
449
|
""
|
|
528
450
|
]
|
|
529
451
|
});
|
|
530
|
-
return (0, import_combine2.combine)(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
452
|
+
return (0, import_combine2.combine)(
|
|
453
|
+
(0, import_adapter3.draggable)({
|
|
454
|
+
element: buttonRef.current,
|
|
455
|
+
getInitialData: () => data,
|
|
456
|
+
onDragStart: () => {
|
|
457
|
+
setState("dragging");
|
|
458
|
+
if (open) {
|
|
459
|
+
openRef.current = true;
|
|
460
|
+
onOpenChange?.({
|
|
461
|
+
item,
|
|
462
|
+
path,
|
|
463
|
+
open: false
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
onDrop: () => {
|
|
468
|
+
setState("idle");
|
|
469
|
+
if (openRef.current) {
|
|
470
|
+
onOpenChange?.({
|
|
471
|
+
item,
|
|
472
|
+
path,
|
|
473
|
+
open: true
|
|
474
|
+
});
|
|
475
|
+
}
|
|
542
476
|
}
|
|
543
|
-
},
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
477
|
+
}),
|
|
478
|
+
// https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
|
|
479
|
+
(0, import_adapter3.dropTargetForElements)({
|
|
480
|
+
element: buttonRef.current,
|
|
481
|
+
getData: ({ input, element }) => {
|
|
482
|
+
return (0, import_tree_item.attachInstruction)(data, {
|
|
483
|
+
input,
|
|
484
|
+
element,
|
|
485
|
+
indentPerLevel: DEFAULT_INDENTATION,
|
|
486
|
+
currentLevel: level,
|
|
487
|
+
mode,
|
|
488
|
+
block: isBranch ? [] : [
|
|
489
|
+
"make-child"
|
|
490
|
+
]
|
|
551
491
|
});
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
onOpenChange?.({
|
|
579
|
-
item,
|
|
580
|
-
path,
|
|
581
|
-
open: true
|
|
582
|
-
});
|
|
583
|
-
}, 500);
|
|
584
|
-
}
|
|
585
|
-
if (instruction2?.type !== "make-child") {
|
|
586
|
-
cancelExpand();
|
|
492
|
+
},
|
|
493
|
+
canDrop: ({ source }) => {
|
|
494
|
+
const _canDrop = canDrop ?? (() => true);
|
|
495
|
+
return source.element !== buttonRef.current && _canDrop(source.data, data);
|
|
496
|
+
},
|
|
497
|
+
getIsSticky: () => true,
|
|
498
|
+
onDrag: ({ self, source }) => {
|
|
499
|
+
const instruction2 = (0, import_tree_item.extractInstruction)(self.data);
|
|
500
|
+
if (source.data.id !== id) {
|
|
501
|
+
if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
|
|
502
|
+
cancelExpandRef.current = setTimeout(() => {
|
|
503
|
+
onOpenChange?.({
|
|
504
|
+
item,
|
|
505
|
+
path,
|
|
506
|
+
open: true
|
|
507
|
+
});
|
|
508
|
+
}, 500);
|
|
509
|
+
}
|
|
510
|
+
if (instruction2?.type !== "make-child") {
|
|
511
|
+
cancelExpand();
|
|
512
|
+
}
|
|
513
|
+
setInstruction(instruction2);
|
|
514
|
+
} else if (instruction2?.type === "reparent") {
|
|
515
|
+
setInstruction(instruction2);
|
|
516
|
+
} else {
|
|
517
|
+
setInstruction(null);
|
|
587
518
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
519
|
+
},
|
|
520
|
+
onDragLeave: () => {
|
|
521
|
+
cancelExpand();
|
|
522
|
+
setInstruction(null);
|
|
523
|
+
},
|
|
524
|
+
onDrop: () => {
|
|
525
|
+
cancelExpand();
|
|
592
526
|
setInstruction(null);
|
|
593
527
|
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
cancelExpand();
|
|
597
|
-
setInstruction(null);
|
|
598
|
-
},
|
|
599
|
-
onDrop: () => {
|
|
600
|
-
cancelExpand();
|
|
601
|
-
setInstruction(null);
|
|
602
|
-
}
|
|
603
|
-
}));
|
|
528
|
+
})
|
|
529
|
+
);
|
|
604
530
|
}, [
|
|
605
|
-
|
|
531
|
+
_draggable,
|
|
606
532
|
item,
|
|
607
533
|
id,
|
|
608
534
|
mode,
|
|
@@ -610,10 +536,10 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
610
536
|
open,
|
|
611
537
|
canDrop
|
|
612
538
|
]);
|
|
613
|
-
(0,
|
|
539
|
+
(0, import_react5.useEffect)(() => () => cancelExpand(), [
|
|
614
540
|
cancelExpand
|
|
615
541
|
]);
|
|
616
|
-
const handleOpenChange = (0,
|
|
542
|
+
const handleOpenChange = (0, import_react5.useCallback)(() => onOpenChange?.({
|
|
617
543
|
item,
|
|
618
544
|
path,
|
|
619
545
|
open: !open
|
|
@@ -623,7 +549,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
623
549
|
path,
|
|
624
550
|
open
|
|
625
551
|
]);
|
|
626
|
-
const handleSelect = (0,
|
|
552
|
+
const handleSelect = (0, import_react5.useCallback)((option = false) => {
|
|
627
553
|
rowRef.current?.focus();
|
|
628
554
|
onSelect?.({
|
|
629
555
|
item,
|
|
@@ -637,7 +563,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
637
563
|
path,
|
|
638
564
|
current
|
|
639
565
|
]);
|
|
640
|
-
const handleKeyDown = (0,
|
|
566
|
+
const handleKeyDown = (0, import_react5.useCallback)((event) => {
|
|
641
567
|
switch (event.key) {
|
|
642
568
|
case "ArrowRight":
|
|
643
569
|
isBranch && !open && handleOpenChange();
|
|
@@ -655,13 +581,13 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
655
581
|
handleOpenChange,
|
|
656
582
|
handleSelect
|
|
657
583
|
]);
|
|
658
|
-
return /* @__PURE__ */
|
|
584
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Treegrid.Row, {
|
|
659
585
|
ref: rowRef,
|
|
660
586
|
key: id,
|
|
661
587
|
id,
|
|
662
588
|
"aria-labelledby": `${id}__label`,
|
|
663
589
|
parentOf: parentOf?.join(import_react_ui3.Treegrid.PARENT_OF_SEPARATOR),
|
|
664
|
-
classNames: (0,
|
|
590
|
+
classNames: (0, import_react_ui_theme2.mx)("grid grid-cols-subgrid col-[tree-row] mbs-0.5 aria-[current]:bg-input", import_react_ui_theme2.hoverableControls, import_react_ui_theme2.hoverableFocusedKeyboardControls, import_react_ui_theme2.hoverableFocusedWithinControls, hoverableDescriptionIcons, import_react_ui_theme2.ghostHover, className),
|
|
665
591
|
"data-itemid": id,
|
|
666
592
|
"data-testid": testId,
|
|
667
593
|
// NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
|
|
@@ -673,18 +599,18 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
673
599
|
event.preventDefault();
|
|
674
600
|
setMenuOpen(true);
|
|
675
601
|
}
|
|
676
|
-
}, /* @__PURE__ */
|
|
602
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Treegrid.Cell, {
|
|
677
603
|
indent: true,
|
|
678
604
|
classNames: "relative grid grid-cols-subgrid col-[tree-row]",
|
|
679
|
-
style:
|
|
680
|
-
}, /* @__PURE__ */
|
|
605
|
+
style: paddingIndentation(level)
|
|
606
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
681
607
|
role: "none",
|
|
682
608
|
className: "flex items-center"
|
|
683
|
-
}, /* @__PURE__ */
|
|
609
|
+
}, /* @__PURE__ */ import_react5.default.createElement(TreeItemToggle, {
|
|
684
610
|
open,
|
|
685
611
|
isBranch,
|
|
686
612
|
onToggle: handleOpenChange
|
|
687
|
-
}), /* @__PURE__ */
|
|
613
|
+
}), /* @__PURE__ */ import_react5.default.createElement(TreeItemHeading, {
|
|
688
614
|
ref: buttonRef,
|
|
689
615
|
label,
|
|
690
616
|
icon,
|
|
@@ -692,29 +618,30 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
692
618
|
disabled,
|
|
693
619
|
current,
|
|
694
620
|
onSelect: handleSelect
|
|
695
|
-
})), Columns && /* @__PURE__ */
|
|
621
|
+
})), Columns && /* @__PURE__ */ import_react5.default.createElement(Columns, {
|
|
696
622
|
item,
|
|
697
623
|
path,
|
|
624
|
+
open,
|
|
698
625
|
menuOpen,
|
|
699
626
|
setMenuOpen
|
|
700
|
-
}), instruction && /* @__PURE__ */
|
|
627
|
+
}), instruction && /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.TreeItem.DropIndicator, {
|
|
701
628
|
instruction,
|
|
702
629
|
gap: 2
|
|
703
|
-
}))), open && items.map((item2, index) => /* @__PURE__ */
|
|
630
|
+
}))), open && items.map((item2, index) => /* @__PURE__ */ import_react5.default.createElement(TreeItem, {
|
|
704
631
|
key: item2.id,
|
|
705
632
|
item: item2,
|
|
706
633
|
path,
|
|
707
634
|
last: index === items.length - 1,
|
|
708
|
-
draggable:
|
|
635
|
+
draggable: _draggable,
|
|
709
636
|
renderColumns: Columns,
|
|
710
637
|
canDrop,
|
|
711
638
|
onOpenChange,
|
|
712
639
|
onSelect
|
|
713
640
|
})));
|
|
714
641
|
};
|
|
715
|
-
var TreeItem = /* @__PURE__ */ (0,
|
|
716
|
-
var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable:
|
|
717
|
-
const context = (0,
|
|
642
|
+
var TreeItem = /* @__PURE__ */ (0, import_react5.memo)(RawTreeItem);
|
|
643
|
+
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 }) => {
|
|
644
|
+
const context = (0, import_react3.useMemo)(() => ({
|
|
718
645
|
getItems,
|
|
719
646
|
getProps,
|
|
720
647
|
isOpen,
|
|
@@ -725,23 +652,28 @@ var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable: draggable2 =
|
|
|
725
652
|
isOpen,
|
|
726
653
|
isCurrent
|
|
727
654
|
]);
|
|
728
|
-
const items = getItems();
|
|
729
|
-
const
|
|
655
|
+
const items = getItems(root);
|
|
656
|
+
const treePath = (0, import_react3.useMemo)(() => path ? [
|
|
657
|
+
...path,
|
|
730
658
|
id
|
|
731
|
-
]
|
|
659
|
+
] : [
|
|
732
660
|
id
|
|
661
|
+
], [
|
|
662
|
+
id,
|
|
663
|
+
path
|
|
733
664
|
]);
|
|
734
|
-
return /* @__PURE__ */
|
|
665
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.Treegrid.Root, {
|
|
735
666
|
gridTemplateColumns,
|
|
736
667
|
classNames
|
|
737
|
-
}, /* @__PURE__ */
|
|
668
|
+
}, /* @__PURE__ */ import_react3.default.createElement(TreeProvider, {
|
|
738
669
|
value: context
|
|
739
|
-
}, items.map((item, index) => /* @__PURE__ */
|
|
670
|
+
}, items.map((item, index) => /* @__PURE__ */ import_react3.default.createElement(TreeItem, {
|
|
740
671
|
key: item.id,
|
|
741
672
|
item,
|
|
742
673
|
last: index === items.length - 1,
|
|
743
|
-
path,
|
|
744
|
-
|
|
674
|
+
path: treePath,
|
|
675
|
+
levelOffset,
|
|
676
|
+
draggable: draggable3,
|
|
745
677
|
renderColumns,
|
|
746
678
|
canDrop,
|
|
747
679
|
onOpenChange,
|