@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
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,
|
|
@@ -182,7 +144,7 @@ var stateStyles = {
|
|
|
182
144
|
var defaultContext = {};
|
|
183
145
|
var LIST_ITEM_NAME = "ListItem";
|
|
184
146
|
var [ListItemProvider, useListItemContext] = (0, import_react_context.createContext)(LIST_ITEM_NAME, defaultContext);
|
|
185
|
-
var ListItem = ({ children, classNames, item }) => {
|
|
147
|
+
var ListItem = ({ children, classNames, item, ...props }) => {
|
|
186
148
|
const { isItem, dragPreview, setState: setRootState } = useListContext(LIST_ITEM_NAME);
|
|
187
149
|
const ref = (0, import_react.useRef)(null);
|
|
188
150
|
const dragHandleRef = (0, import_react.useRef)(null);
|
|
@@ -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,
|
|
@@ -298,12 +262,14 @@ var ListItem = ({ children, classNames, item }) => {
|
|
|
298
262
|
item,
|
|
299
263
|
dragHandleRef
|
|
300
264
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
265
|
+
role: "none",
|
|
301
266
|
className: "relative"
|
|
302
267
|
}, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
303
268
|
ref,
|
|
304
269
|
role: "listitem",
|
|
305
|
-
className: (0, import_react_ui_theme.mx)("flex overflow-hidden", classNames, stateStyles[state.type])
|
|
306
|
-
|
|
270
|
+
className: (0, import_react_ui_theme.mx)("flex overflow-hidden", classNames, stateStyles[state.type]),
|
|
271
|
+
...props
|
|
272
|
+
}, children), state.type === "is-dragging-over" && state.closestEdge && /* @__PURE__ */ import_react.default.createElement(import_react_ui.ListItem.DropIndicator, {
|
|
307
273
|
edge: state.closestEdge
|
|
308
274
|
})));
|
|
309
275
|
};
|
|
@@ -361,59 +327,17 @@ var List = {
|
|
|
361
327
|
ItemTitle: ListItemTitle,
|
|
362
328
|
IconButton
|
|
363
329
|
};
|
|
364
|
-
var TreeContext = /* @__PURE__ */ (0,
|
|
365
|
-
var useTree = () => (0,
|
|
330
|
+
var TreeContext = /* @__PURE__ */ (0, import_react4.createContext)(null);
|
|
331
|
+
var useTree = () => (0, import_react4.useContext)(TreeContext) ?? (0, import_debug.raise)(new Error("TreeContext not found"));
|
|
366
332
|
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) => {
|
|
333
|
+
var TreeItemHeading = /* @__PURE__ */ (0, import_react6.memo)(/* @__PURE__ */ (0, import_react6.forwardRef)(({ label, icon, className, disabled, current, onSelect }, forwardedRef) => {
|
|
410
334
|
const { t } = (0, import_react_ui4.useTranslation)();
|
|
411
|
-
const handleSelect = (0,
|
|
335
|
+
const handleSelect = (0, import_react6.useCallback)((event) => {
|
|
412
336
|
onSelect?.(event.altKey);
|
|
413
337
|
}, [
|
|
414
338
|
onSelect
|
|
415
339
|
]);
|
|
416
|
-
const handleButtonKeydown = (0,
|
|
340
|
+
const handleButtonKeydown = (0, import_react6.useCallback)((event) => {
|
|
417
341
|
if (event.key === " " || event.key === "Enter") {
|
|
418
342
|
event.preventDefault();
|
|
419
343
|
event.stopPropagation();
|
|
@@ -422,50 +346,50 @@ var TreeItemHeading = /* @__PURE__ */ (0, import_react8.memo)(/* @__PURE__ */ (0
|
|
|
422
346
|
}, [
|
|
423
347
|
onSelect
|
|
424
348
|
]);
|
|
425
|
-
return /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_ui_text_tooltip.TextTooltip, {
|
|
426
350
|
text: (0, import_react_ui4.toLocalizedString)(label, t),
|
|
427
351
|
side: "bottom",
|
|
428
352
|
truncateQuery: "span[data-tooltip]",
|
|
429
353
|
onlyWhenTruncating: true,
|
|
430
354
|
asChild: true,
|
|
431
355
|
ref: forwardedRef
|
|
432
|
-
}, /* @__PURE__ */
|
|
356
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Button, {
|
|
433
357
|
"data-testid": "treeItem.heading",
|
|
434
358
|
variant: "ghost",
|
|
435
359
|
density: "fine",
|
|
436
|
-
classNames: (0,
|
|
360
|
+
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
361
|
disabled,
|
|
438
362
|
onClick: handleSelect,
|
|
439
363
|
onKeyDown: handleButtonKeydown,
|
|
440
364
|
...current && {
|
|
441
365
|
"aria-current": "location"
|
|
442
366
|
}
|
|
443
|
-
}, icon && /* @__PURE__ */
|
|
367
|
+
}, icon && /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Icon, {
|
|
444
368
|
icon: icon ?? "ph--placeholder--regular",
|
|
445
369
|
size: 4,
|
|
446
370
|
classNames: "is-[1em] bs-[1em] mlb-1"
|
|
447
|
-
}), /* @__PURE__ */
|
|
371
|
+
}), /* @__PURE__ */ import_react6.default.createElement("span", {
|
|
448
372
|
className: "flex-1 is-0 truncate text-start text-sm font-normal",
|
|
449
373
|
"data-tooltip": true
|
|
450
374
|
}, (0, import_react_ui4.toLocalizedString)(label, t))));
|
|
451
375
|
}));
|
|
452
|
-
var TreeItemToggle = /* @__PURE__ */ (0,
|
|
453
|
-
return /* @__PURE__ */
|
|
376
|
+
var TreeItemToggle = /* @__PURE__ */ (0, import_react7.memo)(/* @__PURE__ */ (0, import_react7.forwardRef)(({ open, isBranch, hidden, onToggle }, forwardedRef) => {
|
|
377
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Button, {
|
|
454
378
|
ref: forwardedRef,
|
|
455
379
|
"data-testid": "treeItem.toggle",
|
|
456
380
|
"aria-expanded": open,
|
|
457
381
|
variant: "ghost",
|
|
458
382
|
density: "fine",
|
|
459
|
-
classNames: (0,
|
|
383
|
+
classNames: (0, import_react_ui_theme4.mx)("is-4 dx-focus-ring-inset pli-0", hidden ? "hidden" : !isBranch && "invisible"),
|
|
460
384
|
onClick: onToggle
|
|
461
|
-
}, /* @__PURE__ */
|
|
385
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
462
386
|
icon: "ph--caret-right--regular",
|
|
463
387
|
size: 3,
|
|
464
|
-
classNames: (0,
|
|
388
|
+
classNames: (0, import_react_ui_theme4.mx)("transition duration-200", open && "rotate-90")
|
|
465
389
|
}));
|
|
466
390
|
}));
|
|
467
391
|
var DEFAULT_INDENTATION = 8;
|
|
468
|
-
var
|
|
392
|
+
var paddingIndentation = (level, indentation = DEFAULT_INDENTATION) => ({
|
|
469
393
|
paddingInlineStart: `${(level - 1) * indentation}px`
|
|
470
394
|
});
|
|
471
395
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-list/src/components/Tree/TreeItem.tsx";
|
|
@@ -476,11 +400,11 @@ var TreeDataSchema = import_echo_schema.S.Struct({
|
|
|
476
400
|
item: import_echo_schema.S.Any
|
|
477
401
|
});
|
|
478
402
|
var isTreeData = (data) => import_echo_schema.S.is(TreeDataSchema)(data);
|
|
479
|
-
var RawTreeItem = ({ item, path: _path, last, draggable:
|
|
403
|
+
var RawTreeItem = ({ item, path: _path, last, draggable: _draggable, renderColumns: Columns, canDrop, onOpenChange, onSelect, levelOffset = 2 }) => {
|
|
480
404
|
const { getItems, getProps, isOpen, isCurrent } = useTree();
|
|
481
405
|
const items = getItems(item);
|
|
482
406
|
const { id, label, parentOf, icon, disabled, className, headingClassName, testId } = getProps(item, _path);
|
|
483
|
-
const path = (0,
|
|
407
|
+
const path = (0, import_react5.useMemo)(() => [
|
|
484
408
|
..._path,
|
|
485
409
|
id
|
|
486
410
|
], [
|
|
@@ -489,10 +413,10 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
489
413
|
]);
|
|
490
414
|
const open = isOpen(path, item);
|
|
491
415
|
const current = isCurrent(path, item);
|
|
492
|
-
const level = path.length -
|
|
416
|
+
const level = path.length - levelOffset;
|
|
493
417
|
const isBranch = !!parentOf;
|
|
494
418
|
const mode = last ? "last-in-group" : open ? "expanded" : "standard";
|
|
495
|
-
const data = (0,
|
|
419
|
+
const data = (0, import_react5.useMemo)(() => ({
|
|
496
420
|
id,
|
|
497
421
|
path,
|
|
498
422
|
item
|
|
@@ -501,108 +425,112 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
501
425
|
path,
|
|
502
426
|
item
|
|
503
427
|
]);
|
|
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,
|
|
428
|
+
const rowRef = (0, import_react5.useRef)(null);
|
|
429
|
+
const buttonRef = (0, import_react5.useRef)(null);
|
|
430
|
+
const openRef = (0, import_react5.useRef)(false);
|
|
431
|
+
const cancelExpandRef = (0, import_react5.useRef)(null);
|
|
432
|
+
const [_state, setState] = (0, import_react5.useState)("idle");
|
|
433
|
+
const [instruction, setInstruction] = (0, import_react5.useState)(null);
|
|
434
|
+
const [menuOpen, setMenuOpen] = (0, import_react5.useState)(false);
|
|
435
|
+
const cancelExpand = (0, import_react5.useCallback)(() => {
|
|
512
436
|
if (cancelExpandRef.current) {
|
|
513
437
|
clearTimeout(cancelExpandRef.current);
|
|
514
438
|
cancelExpandRef.current = null;
|
|
515
439
|
}
|
|
516
440
|
}, []);
|
|
517
|
-
(0,
|
|
518
|
-
if (!
|
|
441
|
+
(0, import_react5.useEffect)(() => {
|
|
442
|
+
if (!_draggable) {
|
|
519
443
|
return;
|
|
520
444
|
}
|
|
521
445
|
(0, import_invariant2.invariant)(buttonRef.current, void 0, {
|
|
522
446
|
F: __dxlog_file2,
|
|
523
|
-
L:
|
|
447
|
+
L: 106,
|
|
524
448
|
S: void 0,
|
|
525
449
|
A: [
|
|
526
450
|
"buttonRef.current",
|
|
527
451
|
""
|
|
528
452
|
]
|
|
529
453
|
});
|
|
530
|
-
return (0, import_combine2.combine)(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
454
|
+
return (0, import_combine2.combine)(
|
|
455
|
+
(0, import_adapter3.draggable)({
|
|
456
|
+
element: buttonRef.current,
|
|
457
|
+
getInitialData: () => data,
|
|
458
|
+
onDragStart: () => {
|
|
459
|
+
setState("dragging");
|
|
460
|
+
if (open) {
|
|
461
|
+
openRef.current = true;
|
|
462
|
+
onOpenChange?.({
|
|
463
|
+
item,
|
|
464
|
+
path,
|
|
465
|
+
open: false
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
onDrop: () => {
|
|
470
|
+
setState("idle");
|
|
471
|
+
if (openRef.current) {
|
|
472
|
+
onOpenChange?.({
|
|
473
|
+
item,
|
|
474
|
+
path,
|
|
475
|
+
open: true
|
|
476
|
+
});
|
|
477
|
+
}
|
|
542
478
|
}
|
|
543
|
-
},
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
479
|
+
}),
|
|
480
|
+
// https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
|
|
481
|
+
(0, import_adapter3.dropTargetForElements)({
|
|
482
|
+
element: buttonRef.current,
|
|
483
|
+
getData: ({ input, element }) => {
|
|
484
|
+
return (0, import_tree_item.attachInstruction)(data, {
|
|
485
|
+
input,
|
|
486
|
+
element,
|
|
487
|
+
indentPerLevel: DEFAULT_INDENTATION,
|
|
488
|
+
currentLevel: level,
|
|
489
|
+
mode,
|
|
490
|
+
block: isBranch ? [] : [
|
|
491
|
+
"make-child"
|
|
492
|
+
]
|
|
551
493
|
});
|
|
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();
|
|
494
|
+
},
|
|
495
|
+
canDrop: ({ source }) => {
|
|
496
|
+
const _canDrop = canDrop ?? (() => true);
|
|
497
|
+
return source.element !== buttonRef.current && _canDrop(source.data, data);
|
|
498
|
+
},
|
|
499
|
+
getIsSticky: () => true,
|
|
500
|
+
onDrag: ({ self, source }) => {
|
|
501
|
+
const instruction2 = (0, import_tree_item.extractInstruction)(self.data);
|
|
502
|
+
if (source.data.id !== id) {
|
|
503
|
+
if (instruction2?.type === "make-child" && isBranch && !open && !cancelExpandRef.current) {
|
|
504
|
+
cancelExpandRef.current = setTimeout(() => {
|
|
505
|
+
onOpenChange?.({
|
|
506
|
+
item,
|
|
507
|
+
path,
|
|
508
|
+
open: true
|
|
509
|
+
});
|
|
510
|
+
}, 500);
|
|
511
|
+
}
|
|
512
|
+
if (instruction2?.type !== "make-child") {
|
|
513
|
+
cancelExpand();
|
|
514
|
+
}
|
|
515
|
+
setInstruction(instruction2);
|
|
516
|
+
} else if (instruction2?.type === "reparent") {
|
|
517
|
+
setInstruction(instruction2);
|
|
518
|
+
} else {
|
|
519
|
+
setInstruction(null);
|
|
587
520
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
521
|
+
},
|
|
522
|
+
onDragLeave: () => {
|
|
523
|
+
cancelExpand();
|
|
524
|
+
setInstruction(null);
|
|
525
|
+
},
|
|
526
|
+
onDrop: () => {
|
|
527
|
+
cancelExpand();
|
|
592
528
|
setInstruction(null);
|
|
593
529
|
}
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
cancelExpand();
|
|
597
|
-
setInstruction(null);
|
|
598
|
-
},
|
|
599
|
-
onDrop: () => {
|
|
600
|
-
cancelExpand();
|
|
601
|
-
setInstruction(null);
|
|
602
|
-
}
|
|
603
|
-
}));
|
|
530
|
+
})
|
|
531
|
+
);
|
|
604
532
|
}, [
|
|
605
|
-
|
|
533
|
+
_draggable,
|
|
606
534
|
item,
|
|
607
535
|
id,
|
|
608
536
|
mode,
|
|
@@ -610,10 +538,10 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
610
538
|
open,
|
|
611
539
|
canDrop
|
|
612
540
|
]);
|
|
613
|
-
(0,
|
|
541
|
+
(0, import_react5.useEffect)(() => () => cancelExpand(), [
|
|
614
542
|
cancelExpand
|
|
615
543
|
]);
|
|
616
|
-
const handleOpenChange = (0,
|
|
544
|
+
const handleOpenChange = (0, import_react5.useCallback)(() => onOpenChange?.({
|
|
617
545
|
item,
|
|
618
546
|
path,
|
|
619
547
|
open: !open
|
|
@@ -623,7 +551,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
623
551
|
path,
|
|
624
552
|
open
|
|
625
553
|
]);
|
|
626
|
-
const handleSelect = (0,
|
|
554
|
+
const handleSelect = (0, import_react5.useCallback)((option = false) => {
|
|
627
555
|
rowRef.current?.focus();
|
|
628
556
|
onSelect?.({
|
|
629
557
|
item,
|
|
@@ -637,7 +565,7 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
637
565
|
path,
|
|
638
566
|
current
|
|
639
567
|
]);
|
|
640
|
-
const handleKeyDown = (0,
|
|
568
|
+
const handleKeyDown = (0, import_react5.useCallback)((event) => {
|
|
641
569
|
switch (event.key) {
|
|
642
570
|
case "ArrowRight":
|
|
643
571
|
isBranch && !open && handleOpenChange();
|
|
@@ -655,13 +583,13 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
655
583
|
handleOpenChange,
|
|
656
584
|
handleSelect
|
|
657
585
|
]);
|
|
658
|
-
return /* @__PURE__ */
|
|
586
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Treegrid.Row, {
|
|
659
587
|
ref: rowRef,
|
|
660
588
|
key: id,
|
|
661
589
|
id,
|
|
662
590
|
"aria-labelledby": `${id}__label`,
|
|
663
591
|
parentOf: parentOf?.join(import_react_ui3.Treegrid.PARENT_OF_SEPARATOR),
|
|
664
|
-
classNames: (0,
|
|
592
|
+
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
593
|
"data-itemid": id,
|
|
666
594
|
"data-testid": testId,
|
|
667
595
|
// NOTE(thure): This is intentionally an empty string to for descendents to select by in the CSS
|
|
@@ -673,18 +601,18 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
673
601
|
event.preventDefault();
|
|
674
602
|
setMenuOpen(true);
|
|
675
603
|
}
|
|
676
|
-
}, /* @__PURE__ */
|
|
604
|
+
}, /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.Treegrid.Cell, {
|
|
677
605
|
indent: true,
|
|
678
606
|
classNames: "relative grid grid-cols-subgrid col-[tree-row]",
|
|
679
|
-
style:
|
|
680
|
-
}, /* @__PURE__ */
|
|
607
|
+
style: paddingIndentation(level)
|
|
608
|
+
}, /* @__PURE__ */ import_react5.default.createElement("div", {
|
|
681
609
|
role: "none",
|
|
682
610
|
className: "flex items-center"
|
|
683
|
-
}, /* @__PURE__ */
|
|
611
|
+
}, /* @__PURE__ */ import_react5.default.createElement(TreeItemToggle, {
|
|
684
612
|
open,
|
|
685
613
|
isBranch,
|
|
686
614
|
onToggle: handleOpenChange
|
|
687
|
-
}), /* @__PURE__ */
|
|
615
|
+
}), /* @__PURE__ */ import_react5.default.createElement(TreeItemHeading, {
|
|
688
616
|
ref: buttonRef,
|
|
689
617
|
label,
|
|
690
618
|
icon,
|
|
@@ -692,29 +620,30 @@ var RawTreeItem = ({ item, path: _path, last, draggable: draggable2, renderColum
|
|
|
692
620
|
disabled,
|
|
693
621
|
current,
|
|
694
622
|
onSelect: handleSelect
|
|
695
|
-
})), Columns && /* @__PURE__ */
|
|
623
|
+
})), Columns && /* @__PURE__ */ import_react5.default.createElement(Columns, {
|
|
696
624
|
item,
|
|
697
625
|
path,
|
|
626
|
+
open,
|
|
698
627
|
menuOpen,
|
|
699
628
|
setMenuOpen
|
|
700
|
-
}), instruction && /* @__PURE__ */
|
|
629
|
+
}), instruction && /* @__PURE__ */ import_react5.default.createElement(import_react_ui3.TreeItem.DropIndicator, {
|
|
701
630
|
instruction,
|
|
702
631
|
gap: 2
|
|
703
|
-
}))), open && items.map((item2, index) => /* @__PURE__ */
|
|
632
|
+
}))), open && items.map((item2, index) => /* @__PURE__ */ import_react5.default.createElement(TreeItem, {
|
|
704
633
|
key: item2.id,
|
|
705
634
|
item: item2,
|
|
706
635
|
path,
|
|
707
636
|
last: index === items.length - 1,
|
|
708
|
-
draggable:
|
|
637
|
+
draggable: _draggable,
|
|
709
638
|
renderColumns: Columns,
|
|
710
639
|
canDrop,
|
|
711
640
|
onOpenChange,
|
|
712
641
|
onSelect
|
|
713
642
|
})));
|
|
714
643
|
};
|
|
715
|
-
var TreeItem = /* @__PURE__ */ (0,
|
|
716
|
-
var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable:
|
|
717
|
-
const context = (0,
|
|
644
|
+
var TreeItem = /* @__PURE__ */ (0, import_react5.memo)(RawTreeItem);
|
|
645
|
+
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 }) => {
|
|
646
|
+
const context = (0, import_react3.useMemo)(() => ({
|
|
718
647
|
getItems,
|
|
719
648
|
getProps,
|
|
720
649
|
isOpen,
|
|
@@ -725,23 +654,28 @@ var Tree = ({ id, getItems, getProps, isOpen, isCurrent, draggable: draggable2 =
|
|
|
725
654
|
isOpen,
|
|
726
655
|
isCurrent
|
|
727
656
|
]);
|
|
728
|
-
const items = getItems();
|
|
729
|
-
const
|
|
657
|
+
const items = getItems(root);
|
|
658
|
+
const treePath = (0, import_react3.useMemo)(() => path ? [
|
|
659
|
+
...path,
|
|
730
660
|
id
|
|
731
|
-
]
|
|
661
|
+
] : [
|
|
732
662
|
id
|
|
663
|
+
], [
|
|
664
|
+
id,
|
|
665
|
+
path
|
|
733
666
|
]);
|
|
734
|
-
return /* @__PURE__ */
|
|
667
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.Treegrid.Root, {
|
|
735
668
|
gridTemplateColumns,
|
|
736
669
|
classNames
|
|
737
|
-
}, /* @__PURE__ */
|
|
670
|
+
}, /* @__PURE__ */ import_react3.default.createElement(TreeProvider, {
|
|
738
671
|
value: context
|
|
739
|
-
}, items.map((item, index) => /* @__PURE__ */
|
|
672
|
+
}, items.map((item, index) => /* @__PURE__ */ import_react3.default.createElement(TreeItem, {
|
|
740
673
|
key: item.id,
|
|
741
674
|
item,
|
|
742
675
|
last: index === items.length - 1,
|
|
743
|
-
path,
|
|
744
|
-
|
|
676
|
+
path: treePath,
|
|
677
|
+
levelOffset,
|
|
678
|
+
draggable: draggable3,
|
|
745
679
|
renderColumns,
|
|
746
680
|
canDrop,
|
|
747
681
|
onOpenChange,
|