@edux-design/tree-select 0.2.4 → 0.2.5
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/README.md +24 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +68 -24
- package/dist/index.mjs +68 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -179,6 +179,29 @@ import { MenuList, MenuItem } from "@edux-design/menus";
|
|
|
179
179
|
/>;
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
+
### `renderLabel` (function)
|
|
183
|
+
Renders custom inline content where the label normally appears. This is the supported way to compose metadata like `Tag` elements next to the item title.
|
|
184
|
+
|
|
185
|
+
```jsx
|
|
186
|
+
import { Tag } from "@edux-design/tags";
|
|
187
|
+
|
|
188
|
+
<TreeSelect
|
|
189
|
+
data={data}
|
|
190
|
+
renderLabel={({ id, node, hasChildren }) => (
|
|
191
|
+
<>
|
|
192
|
+
<span>{node.label ?? id}</span>
|
|
193
|
+
<Tag
|
|
194
|
+
size="small"
|
|
195
|
+
tone="subtle"
|
|
196
|
+
variant={hasChildren ? "information" : "neutral"}
|
|
197
|
+
>
|
|
198
|
+
{hasChildren ? "Group" : "Leaf"}
|
|
199
|
+
</Tag>
|
|
200
|
+
</>
|
|
201
|
+
)}
|
|
202
|
+
/>;
|
|
203
|
+
```
|
|
204
|
+
|
|
182
205
|
### `maxLabelLength` (number)
|
|
183
206
|
Limits label width by character count and truncates with an ellipsis when exceeded.
|
|
184
207
|
|
|
@@ -244,6 +267,7 @@ levelConfig={{
|
|
|
244
267
|
- `levelConfig` can override editability, actions, and tooltips per depth.
|
|
245
268
|
- Drag-and-drop supports reordering within a level and moving items between levels.
|
|
246
269
|
- Drag handle alignment is set so child handles align under the parent toggle.
|
|
270
|
+
- `renderLabel` customizes both the row content and the single-item drag overlay.
|
|
247
271
|
|
|
248
272
|
---
|
|
249
273
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, allowDelete, useChevron, actionButtonsPosition, maxLabelLength, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, onLabelChange, levelConfig, defaultExpanded, expanded, onExpandedChange, renderAdditionalActionsMenu, }: {
|
|
3
|
+
declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, allowDelete, useChevron, actionButtonsPosition, maxLabelLength, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, onLabelChange, levelConfig, defaultExpanded, expanded, onExpandedChange, renderAdditionalActionsMenu, renderLabel, }: {
|
|
4
4
|
data: any;
|
|
5
5
|
onDataChange: any;
|
|
6
6
|
allowDragAndDrop?: boolean;
|
|
@@ -20,6 +20,7 @@ declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDr
|
|
|
20
20
|
expanded: any;
|
|
21
21
|
onExpandedChange: any;
|
|
22
22
|
renderAdditionalActionsMenu: any;
|
|
23
|
+
renderLabel: any;
|
|
23
24
|
}): react_jsx_runtime.JSX.Element;
|
|
24
25
|
|
|
25
26
|
export { TreeSelect };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, allowDelete, useChevron, actionButtonsPosition, maxLabelLength, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, onLabelChange, levelConfig, defaultExpanded, expanded, onExpandedChange, renderAdditionalActionsMenu, }: {
|
|
3
|
+
declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDrag, isEditable, allowDelete, useChevron, actionButtonsPosition, maxLabelLength, maxDepth, addChildTooltip, addSiblingTooltip, deleteTooltip, onLabelChange, levelConfig, defaultExpanded, expanded, onExpandedChange, renderAdditionalActionsMenu, renderLabel, }: {
|
|
4
4
|
data: any;
|
|
5
5
|
onDataChange: any;
|
|
6
6
|
allowDragAndDrop?: boolean;
|
|
@@ -20,6 +20,7 @@ declare function TreeSelect({ data, onDataChange, allowDragAndDrop, allowMultiDr
|
|
|
20
20
|
expanded: any;
|
|
21
21
|
onExpandedChange: any;
|
|
22
22
|
renderAdditionalActionsMenu: any;
|
|
23
|
+
renderLabel: any;
|
|
23
24
|
}): react_jsx_runtime.JSX.Element;
|
|
24
25
|
|
|
25
26
|
export { TreeSelect };
|
package/dist/index.js
CHANGED
|
@@ -87,10 +87,19 @@ var TreeRow = ({
|
|
|
87
87
|
canDelete,
|
|
88
88
|
onDelete,
|
|
89
89
|
deleteTooltip,
|
|
90
|
-
additionalActionsMenu
|
|
90
|
+
additionalActionsMenu,
|
|
91
|
+
renderLabel
|
|
91
92
|
}) => {
|
|
92
93
|
const toggleLabel = isExpanded ? "Collapse item" : "Expand item";
|
|
93
94
|
const label = item.node.label ?? item.node.id;
|
|
95
|
+
const labelContent = renderLabel ? renderLabel({
|
|
96
|
+
id: item.id,
|
|
97
|
+
node: item.node,
|
|
98
|
+
depth,
|
|
99
|
+
parentId: item.parentId,
|
|
100
|
+
hasChildren: item.hasChildren,
|
|
101
|
+
isExpanded
|
|
102
|
+
}) : label;
|
|
94
103
|
const showToggle = item.hasChildren;
|
|
95
104
|
const [additionalMenuOpen, setAdditionalMenuOpen] = import_react.default.useState(false);
|
|
96
105
|
const rowBackground = isDragging ? "rgba(0, 0, 0, 0.04)" : isSelected ? "rgba(15, 98, 254, 0.08)" : void 0;
|
|
@@ -217,9 +226,13 @@ var TreeRow = ({
|
|
|
217
226
|
style: {
|
|
218
227
|
fontSize: 14,
|
|
219
228
|
cursor: isEditable ? "pointer" : "default",
|
|
220
|
-
...
|
|
229
|
+
...renderLabel ? {
|
|
230
|
+
display: "inline-flex",
|
|
231
|
+
alignItems: "center",
|
|
232
|
+
gap: 6
|
|
233
|
+
} : labelStyle
|
|
221
234
|
},
|
|
222
|
-
children:
|
|
235
|
+
children: labelContent
|
|
223
236
|
}
|
|
224
237
|
),
|
|
225
238
|
showActions ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
@@ -326,7 +339,8 @@ var TreeSortableRow = ({
|
|
|
326
339
|
canDelete,
|
|
327
340
|
onDelete,
|
|
328
341
|
deleteTooltip,
|
|
329
|
-
additionalActionsMenu
|
|
342
|
+
additionalActionsMenu,
|
|
343
|
+
renderLabel
|
|
330
344
|
}) => {
|
|
331
345
|
const {
|
|
332
346
|
attributes,
|
|
@@ -390,7 +404,8 @@ var TreeSortableRow = ({
|
|
|
390
404
|
canDelete,
|
|
391
405
|
onDelete,
|
|
392
406
|
deleteTooltip,
|
|
393
|
-
additionalActionsMenu
|
|
407
|
+
additionalActionsMenu,
|
|
408
|
+
renderLabel
|
|
394
409
|
}
|
|
395
410
|
);
|
|
396
411
|
};
|
|
@@ -765,9 +780,9 @@ function TreeSelect({
|
|
|
765
780
|
defaultExpanded,
|
|
766
781
|
expanded,
|
|
767
782
|
onExpandedChange,
|
|
768
|
-
renderAdditionalActionsMenu
|
|
783
|
+
renderAdditionalActionsMenu,
|
|
784
|
+
renderLabel
|
|
769
785
|
}) {
|
|
770
|
-
var _a, _b;
|
|
771
786
|
const [uncontrolledExpandedIds, setExpandedIds] = (0, import_react3.useState)(
|
|
772
787
|
() => getExpandedIds(data ?? [], defaultExpanded)
|
|
773
788
|
);
|
|
@@ -806,12 +821,12 @@ function TreeSelect({
|
|
|
806
821
|
}, [maxDepth]);
|
|
807
822
|
const resolvedLevelConfig = (0, import_react3.useCallback)(
|
|
808
823
|
(depth) => {
|
|
809
|
-
var
|
|
824
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
810
825
|
const defaults = (levelConfig == null ? void 0 : levelConfig.default) ?? {};
|
|
811
|
-
const perLevel = ((
|
|
826
|
+
const perLevel = ((_a = levelConfig == null ? void 0 : levelConfig.levels) == null ? void 0 : _a[depth]) ?? {};
|
|
812
827
|
const editable = perLevel.editable ?? defaults.editable ?? isEditable;
|
|
813
828
|
const actions = {
|
|
814
|
-
addChild: ((
|
|
829
|
+
addChild: ((_b = perLevel.actions) == null ? void 0 : _b.addChild) ?? ((_c = defaults.actions) == null ? void 0 : _c.addChild) ?? editable,
|
|
815
830
|
addSibling: ((_d = perLevel.actions) == null ? void 0 : _d.addSibling) ?? ((_e = defaults.actions) == null ? void 0 : _e.addSibling) ?? editable,
|
|
816
831
|
delete: ((_f = perLevel.actions) == null ? void 0 : _f.delete) ?? ((_g = defaults.actions) == null ? void 0 : _g.delete) ?? (editable && allowDelete)
|
|
817
832
|
};
|
|
@@ -863,15 +878,15 @@ function TreeSelect({
|
|
|
863
878
|
}, [updateExpandedIds]);
|
|
864
879
|
const handleRowClick = (0, import_react3.useCallback)(
|
|
865
880
|
(event, id) => {
|
|
866
|
-
var
|
|
881
|
+
var _a, _b;
|
|
867
882
|
if (!allowMultiDrag) return;
|
|
868
883
|
const hasMultiKey = event.metaKey || event.ctrlKey;
|
|
869
|
-
const parentId = ((
|
|
884
|
+
const parentId = ((_a = itemById.get(id)) == null ? void 0 : _a.parentId) ?? null;
|
|
870
885
|
const siblingOrder = siblingOrderMap.get(parentId) ?? [];
|
|
871
886
|
if (event.shiftKey) {
|
|
872
887
|
const anchorIndex = siblingOrder.indexOf(lastSelectedId);
|
|
873
888
|
const targetIndex = siblingOrder.indexOf(id);
|
|
874
|
-
if (anchorIndex < 0 || targetIndex < 0 || (((
|
|
889
|
+
if (anchorIndex < 0 || targetIndex < 0 || (((_b = itemById.get(lastSelectedId ?? "")) == null ? void 0 : _b.parentId) ?? null) !== parentId) {
|
|
875
890
|
setSelectedIds(/* @__PURE__ */ new Set([id]));
|
|
876
891
|
setLastSelectedId(id);
|
|
877
892
|
return;
|
|
@@ -893,10 +908,10 @@ function TreeSelect({
|
|
|
893
908
|
return;
|
|
894
909
|
}
|
|
895
910
|
setSelectedIds((prev) => {
|
|
896
|
-
var
|
|
911
|
+
var _a2;
|
|
897
912
|
if (prev.size) {
|
|
898
913
|
const firstSelected = prev.values().next().value;
|
|
899
|
-
const selectedParent = ((
|
|
914
|
+
const selectedParent = ((_a2 = itemById.get(firstSelected)) == null ? void 0 : _a2.parentId) ?? null;
|
|
900
915
|
if (selectedParent !== parentId) {
|
|
901
916
|
return /* @__PURE__ */ new Set([id]);
|
|
902
917
|
}
|
|
@@ -954,13 +969,13 @@ function TreeSelect({
|
|
|
954
969
|
setHorizontalOffset(event.delta.x);
|
|
955
970
|
}, []);
|
|
956
971
|
const handleDragOver = (0, import_react3.useCallback)((event) => {
|
|
957
|
-
var
|
|
958
|
-
if ((
|
|
972
|
+
var _a;
|
|
973
|
+
if ((_a = event.over) == null ? void 0 : _a.id) {
|
|
959
974
|
setOverId(normaliseId(event.over.id));
|
|
960
975
|
}
|
|
961
976
|
}, []);
|
|
962
977
|
const handleDragEnd = (0, import_react3.useCallback)(() => {
|
|
963
|
-
var
|
|
978
|
+
var _a;
|
|
964
979
|
const projection = getDropProjection({
|
|
965
980
|
items: visibleItems,
|
|
966
981
|
activeId,
|
|
@@ -976,7 +991,7 @@ function TreeSelect({
|
|
|
976
991
|
return;
|
|
977
992
|
}
|
|
978
993
|
const { parentId, siblingIndex, projectedDepth } = projection;
|
|
979
|
-
const sourceParentId = ((
|
|
994
|
+
const sourceParentId = ((_a = itemById.get(draggedRootIds[0] ?? activeId)) == null ? void 0 : _a.parentId) ?? null;
|
|
980
995
|
const { nextNodes, removedNodes } = removeNodes(treeData, draggedRootIds);
|
|
981
996
|
if (!removedNodes.length) {
|
|
982
997
|
setActiveId(null);
|
|
@@ -1089,8 +1104,8 @@ function TreeSelect({
|
|
|
1089
1104
|
);
|
|
1090
1105
|
const startEdit = (0, import_react3.useCallback)(
|
|
1091
1106
|
(id) => {
|
|
1092
|
-
var
|
|
1093
|
-
const currentLabel = ((
|
|
1107
|
+
var _a, _b, _c, _d;
|
|
1108
|
+
const currentLabel = ((_b = (_a = itemById.get(id)) == null ? void 0 : _a.node) == null ? void 0 : _b.label) ?? ((_d = (_c = itemById.get(id)) == null ? void 0 : _c.node) == null ? void 0 : _d.id) ?? "";
|
|
1094
1109
|
setEditingId(id);
|
|
1095
1110
|
setDraftLabel(String(currentLabel));
|
|
1096
1111
|
},
|
|
@@ -1118,6 +1133,21 @@ function TreeSelect({
|
|
|
1118
1133
|
const cancelEdit = (0, import_react3.useCallback)(() => {
|
|
1119
1134
|
setEditingId(null);
|
|
1120
1135
|
}, []);
|
|
1136
|
+
const renderLabelContent = (0, import_react3.useCallback)(
|
|
1137
|
+
(item) => {
|
|
1138
|
+
if (!item) return null;
|
|
1139
|
+
if (!renderLabel) return item.node.label ?? item.id;
|
|
1140
|
+
return renderLabel({
|
|
1141
|
+
id: item.id,
|
|
1142
|
+
node: item.node,
|
|
1143
|
+
depth: item.depth,
|
|
1144
|
+
parentId: item.parentId,
|
|
1145
|
+
hasChildren: item.hasChildren,
|
|
1146
|
+
isExpanded: expandedIds.has(item.id)
|
|
1147
|
+
});
|
|
1148
|
+
},
|
|
1149
|
+
[expandedIds, renderLabel]
|
|
1150
|
+
);
|
|
1121
1151
|
const indicator = (0, import_react3.useMemo)(() => {
|
|
1122
1152
|
if (!allowDragAndDrop) return null;
|
|
1123
1153
|
return getDropIndicator({
|
|
@@ -1206,7 +1236,8 @@ function TreeSelect({
|
|
|
1206
1236
|
canDelete: levelSettings.actions.delete,
|
|
1207
1237
|
onDelete: handleDelete,
|
|
1208
1238
|
deleteTooltip: levelSettings.tooltips.delete,
|
|
1209
|
-
additionalActionsMenu
|
|
1239
|
+
additionalActionsMenu,
|
|
1240
|
+
renderLabel
|
|
1210
1241
|
},
|
|
1211
1242
|
item.id
|
|
1212
1243
|
);
|
|
@@ -1221,7 +1252,19 @@ function TreeSelect({
|
|
|
1221
1252
|
borderRadius: 6,
|
|
1222
1253
|
boxShadow: "0 8px 24px rgba(0, 0, 0, 0.12)"
|
|
1223
1254
|
},
|
|
1224
|
-
children: draggedRootIds.length > 1 ? `${draggedRootIds.length} items` :
|
|
1255
|
+
children: draggedRootIds.length > 1 ? `${draggedRootIds.length} items` : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1256
|
+
"span",
|
|
1257
|
+
{
|
|
1258
|
+
style: {
|
|
1259
|
+
display: "inline-flex",
|
|
1260
|
+
alignItems: "center",
|
|
1261
|
+
gap: 6
|
|
1262
|
+
},
|
|
1263
|
+
children: renderLabelContent(
|
|
1264
|
+
visibleItems.find((item) => item.id === activeId)
|
|
1265
|
+
) ?? activeId
|
|
1266
|
+
}
|
|
1267
|
+
)
|
|
1225
1268
|
}
|
|
1226
1269
|
) : null })
|
|
1227
1270
|
]
|
|
@@ -1266,7 +1309,8 @@ function TreeSelect({
|
|
|
1266
1309
|
canDelete: levelSettings.actions.delete,
|
|
1267
1310
|
onDelete: handleDelete,
|
|
1268
1311
|
deleteTooltip: levelSettings.tooltips.delete,
|
|
1269
|
-
additionalActionsMenu
|
|
1312
|
+
additionalActionsMenu,
|
|
1313
|
+
renderLabel
|
|
1270
1314
|
},
|
|
1271
1315
|
item.id
|
|
1272
1316
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -70,10 +70,19 @@ var TreeRow = ({
|
|
|
70
70
|
canDelete,
|
|
71
71
|
onDelete,
|
|
72
72
|
deleteTooltip,
|
|
73
|
-
additionalActionsMenu
|
|
73
|
+
additionalActionsMenu,
|
|
74
|
+
renderLabel
|
|
74
75
|
}) => {
|
|
75
76
|
const toggleLabel = isExpanded ? "Collapse item" : "Expand item";
|
|
76
77
|
const label = item.node.label ?? item.node.id;
|
|
78
|
+
const labelContent = renderLabel ? renderLabel({
|
|
79
|
+
id: item.id,
|
|
80
|
+
node: item.node,
|
|
81
|
+
depth,
|
|
82
|
+
parentId: item.parentId,
|
|
83
|
+
hasChildren: item.hasChildren,
|
|
84
|
+
isExpanded
|
|
85
|
+
}) : label;
|
|
77
86
|
const showToggle = item.hasChildren;
|
|
78
87
|
const [additionalMenuOpen, setAdditionalMenuOpen] = React.useState(false);
|
|
79
88
|
const rowBackground = isDragging ? "rgba(0, 0, 0, 0.04)" : isSelected ? "rgba(15, 98, 254, 0.08)" : void 0;
|
|
@@ -200,9 +209,13 @@ var TreeRow = ({
|
|
|
200
209
|
style: {
|
|
201
210
|
fontSize: 14,
|
|
202
211
|
cursor: isEditable ? "pointer" : "default",
|
|
203
|
-
...
|
|
212
|
+
...renderLabel ? {
|
|
213
|
+
display: "inline-flex",
|
|
214
|
+
alignItems: "center",
|
|
215
|
+
gap: 6
|
|
216
|
+
} : labelStyle
|
|
204
217
|
},
|
|
205
|
-
children:
|
|
218
|
+
children: labelContent
|
|
206
219
|
}
|
|
207
220
|
),
|
|
208
221
|
showActions ? /* @__PURE__ */ jsxs(
|
|
@@ -309,7 +322,8 @@ var TreeSortableRow = ({
|
|
|
309
322
|
canDelete,
|
|
310
323
|
onDelete,
|
|
311
324
|
deleteTooltip,
|
|
312
|
-
additionalActionsMenu
|
|
325
|
+
additionalActionsMenu,
|
|
326
|
+
renderLabel
|
|
313
327
|
}) => {
|
|
314
328
|
const {
|
|
315
329
|
attributes,
|
|
@@ -373,7 +387,8 @@ var TreeSortableRow = ({
|
|
|
373
387
|
canDelete,
|
|
374
388
|
onDelete,
|
|
375
389
|
deleteTooltip,
|
|
376
|
-
additionalActionsMenu
|
|
390
|
+
additionalActionsMenu,
|
|
391
|
+
renderLabel
|
|
377
392
|
}
|
|
378
393
|
);
|
|
379
394
|
};
|
|
@@ -748,9 +763,9 @@ function TreeSelect({
|
|
|
748
763
|
defaultExpanded,
|
|
749
764
|
expanded,
|
|
750
765
|
onExpandedChange,
|
|
751
|
-
renderAdditionalActionsMenu
|
|
766
|
+
renderAdditionalActionsMenu,
|
|
767
|
+
renderLabel
|
|
752
768
|
}) {
|
|
753
|
-
var _a, _b;
|
|
754
769
|
const [uncontrolledExpandedIds, setExpandedIds] = useState(
|
|
755
770
|
() => getExpandedIds(data ?? [], defaultExpanded)
|
|
756
771
|
);
|
|
@@ -789,12 +804,12 @@ function TreeSelect({
|
|
|
789
804
|
}, [maxDepth]);
|
|
790
805
|
const resolvedLevelConfig = useCallback2(
|
|
791
806
|
(depth) => {
|
|
792
|
-
var
|
|
807
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
793
808
|
const defaults = (levelConfig == null ? void 0 : levelConfig.default) ?? {};
|
|
794
|
-
const perLevel = ((
|
|
809
|
+
const perLevel = ((_a = levelConfig == null ? void 0 : levelConfig.levels) == null ? void 0 : _a[depth]) ?? {};
|
|
795
810
|
const editable = perLevel.editable ?? defaults.editable ?? isEditable;
|
|
796
811
|
const actions = {
|
|
797
|
-
addChild: ((
|
|
812
|
+
addChild: ((_b = perLevel.actions) == null ? void 0 : _b.addChild) ?? ((_c = defaults.actions) == null ? void 0 : _c.addChild) ?? editable,
|
|
798
813
|
addSibling: ((_d = perLevel.actions) == null ? void 0 : _d.addSibling) ?? ((_e = defaults.actions) == null ? void 0 : _e.addSibling) ?? editable,
|
|
799
814
|
delete: ((_f = perLevel.actions) == null ? void 0 : _f.delete) ?? ((_g = defaults.actions) == null ? void 0 : _g.delete) ?? (editable && allowDelete)
|
|
800
815
|
};
|
|
@@ -846,15 +861,15 @@ function TreeSelect({
|
|
|
846
861
|
}, [updateExpandedIds]);
|
|
847
862
|
const handleRowClick = useCallback2(
|
|
848
863
|
(event, id) => {
|
|
849
|
-
var
|
|
864
|
+
var _a, _b;
|
|
850
865
|
if (!allowMultiDrag) return;
|
|
851
866
|
const hasMultiKey = event.metaKey || event.ctrlKey;
|
|
852
|
-
const parentId = ((
|
|
867
|
+
const parentId = ((_a = itemById.get(id)) == null ? void 0 : _a.parentId) ?? null;
|
|
853
868
|
const siblingOrder = siblingOrderMap.get(parentId) ?? [];
|
|
854
869
|
if (event.shiftKey) {
|
|
855
870
|
const anchorIndex = siblingOrder.indexOf(lastSelectedId);
|
|
856
871
|
const targetIndex = siblingOrder.indexOf(id);
|
|
857
|
-
if (anchorIndex < 0 || targetIndex < 0 || (((
|
|
872
|
+
if (anchorIndex < 0 || targetIndex < 0 || (((_b = itemById.get(lastSelectedId ?? "")) == null ? void 0 : _b.parentId) ?? null) !== parentId) {
|
|
858
873
|
setSelectedIds(/* @__PURE__ */ new Set([id]));
|
|
859
874
|
setLastSelectedId(id);
|
|
860
875
|
return;
|
|
@@ -876,10 +891,10 @@ function TreeSelect({
|
|
|
876
891
|
return;
|
|
877
892
|
}
|
|
878
893
|
setSelectedIds((prev) => {
|
|
879
|
-
var
|
|
894
|
+
var _a2;
|
|
880
895
|
if (prev.size) {
|
|
881
896
|
const firstSelected = prev.values().next().value;
|
|
882
|
-
const selectedParent = ((
|
|
897
|
+
const selectedParent = ((_a2 = itemById.get(firstSelected)) == null ? void 0 : _a2.parentId) ?? null;
|
|
883
898
|
if (selectedParent !== parentId) {
|
|
884
899
|
return /* @__PURE__ */ new Set([id]);
|
|
885
900
|
}
|
|
@@ -937,13 +952,13 @@ function TreeSelect({
|
|
|
937
952
|
setHorizontalOffset(event.delta.x);
|
|
938
953
|
}, []);
|
|
939
954
|
const handleDragOver = useCallback2((event) => {
|
|
940
|
-
var
|
|
941
|
-
if ((
|
|
955
|
+
var _a;
|
|
956
|
+
if ((_a = event.over) == null ? void 0 : _a.id) {
|
|
942
957
|
setOverId(normaliseId(event.over.id));
|
|
943
958
|
}
|
|
944
959
|
}, []);
|
|
945
960
|
const handleDragEnd = useCallback2(() => {
|
|
946
|
-
var
|
|
961
|
+
var _a;
|
|
947
962
|
const projection = getDropProjection({
|
|
948
963
|
items: visibleItems,
|
|
949
964
|
activeId,
|
|
@@ -959,7 +974,7 @@ function TreeSelect({
|
|
|
959
974
|
return;
|
|
960
975
|
}
|
|
961
976
|
const { parentId, siblingIndex, projectedDepth } = projection;
|
|
962
|
-
const sourceParentId = ((
|
|
977
|
+
const sourceParentId = ((_a = itemById.get(draggedRootIds[0] ?? activeId)) == null ? void 0 : _a.parentId) ?? null;
|
|
963
978
|
const { nextNodes, removedNodes } = removeNodes(treeData, draggedRootIds);
|
|
964
979
|
if (!removedNodes.length) {
|
|
965
980
|
setActiveId(null);
|
|
@@ -1072,8 +1087,8 @@ function TreeSelect({
|
|
|
1072
1087
|
);
|
|
1073
1088
|
const startEdit = useCallback2(
|
|
1074
1089
|
(id) => {
|
|
1075
|
-
var
|
|
1076
|
-
const currentLabel = ((
|
|
1090
|
+
var _a, _b, _c, _d;
|
|
1091
|
+
const currentLabel = ((_b = (_a = itemById.get(id)) == null ? void 0 : _a.node) == null ? void 0 : _b.label) ?? ((_d = (_c = itemById.get(id)) == null ? void 0 : _c.node) == null ? void 0 : _d.id) ?? "";
|
|
1077
1092
|
setEditingId(id);
|
|
1078
1093
|
setDraftLabel(String(currentLabel));
|
|
1079
1094
|
},
|
|
@@ -1101,6 +1116,21 @@ function TreeSelect({
|
|
|
1101
1116
|
const cancelEdit = useCallback2(() => {
|
|
1102
1117
|
setEditingId(null);
|
|
1103
1118
|
}, []);
|
|
1119
|
+
const renderLabelContent = useCallback2(
|
|
1120
|
+
(item) => {
|
|
1121
|
+
if (!item) return null;
|
|
1122
|
+
if (!renderLabel) return item.node.label ?? item.id;
|
|
1123
|
+
return renderLabel({
|
|
1124
|
+
id: item.id,
|
|
1125
|
+
node: item.node,
|
|
1126
|
+
depth: item.depth,
|
|
1127
|
+
parentId: item.parentId,
|
|
1128
|
+
hasChildren: item.hasChildren,
|
|
1129
|
+
isExpanded: expandedIds.has(item.id)
|
|
1130
|
+
});
|
|
1131
|
+
},
|
|
1132
|
+
[expandedIds, renderLabel]
|
|
1133
|
+
);
|
|
1104
1134
|
const indicator = useMemo2(() => {
|
|
1105
1135
|
if (!allowDragAndDrop) return null;
|
|
1106
1136
|
return getDropIndicator({
|
|
@@ -1189,7 +1219,8 @@ function TreeSelect({
|
|
|
1189
1219
|
canDelete: levelSettings.actions.delete,
|
|
1190
1220
|
onDelete: handleDelete,
|
|
1191
1221
|
deleteTooltip: levelSettings.tooltips.delete,
|
|
1192
|
-
additionalActionsMenu
|
|
1222
|
+
additionalActionsMenu,
|
|
1223
|
+
renderLabel
|
|
1193
1224
|
},
|
|
1194
1225
|
item.id
|
|
1195
1226
|
);
|
|
@@ -1204,7 +1235,19 @@ function TreeSelect({
|
|
|
1204
1235
|
borderRadius: 6,
|
|
1205
1236
|
boxShadow: "0 8px 24px rgba(0, 0, 0, 0.12)"
|
|
1206
1237
|
},
|
|
1207
|
-
children: draggedRootIds.length > 1 ? `${draggedRootIds.length} items` :
|
|
1238
|
+
children: draggedRootIds.length > 1 ? `${draggedRootIds.length} items` : /* @__PURE__ */ jsx3(
|
|
1239
|
+
"span",
|
|
1240
|
+
{
|
|
1241
|
+
style: {
|
|
1242
|
+
display: "inline-flex",
|
|
1243
|
+
alignItems: "center",
|
|
1244
|
+
gap: 6
|
|
1245
|
+
},
|
|
1246
|
+
children: renderLabelContent(
|
|
1247
|
+
visibleItems.find((item) => item.id === activeId)
|
|
1248
|
+
) ?? activeId
|
|
1249
|
+
}
|
|
1250
|
+
)
|
|
1208
1251
|
}
|
|
1209
1252
|
) : null })
|
|
1210
1253
|
]
|
|
@@ -1249,7 +1292,8 @@ function TreeSelect({
|
|
|
1249
1292
|
canDelete: levelSettings.actions.delete,
|
|
1250
1293
|
onDelete: handleDelete,
|
|
1251
1294
|
deleteTooltip: levelSettings.tooltips.delete,
|
|
1252
|
-
additionalActionsMenu
|
|
1295
|
+
additionalActionsMenu,
|
|
1296
|
+
renderLabel
|
|
1253
1297
|
},
|
|
1254
1298
|
item.id
|
|
1255
1299
|
);
|