@asup/tree-of-nodes 1.0.3 → 1.0.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/dist/cjs/main.js +167 -311
- package/dist/cjs/main.js.map +1 -1
- package/dist/main.js +157 -286
- package/dist/main.js.map +1 -1
- package/dist/tree-of-nodes.d.ts +0 -27
- package/dist/tree-of-nodes.d.ts.map +1 -1
- package/package.json +5 -1
package/dist/main.js
CHANGED
|
@@ -1,118 +1,23 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
3
|
-
import $duWW8$react, {
|
|
4
|
-
import {Spinner as $duWW8$Spinner} from "react-bootstrap";
|
|
1
|
+
import {jsx as $duWW8$jsx, Fragment as $duWW8$Fragment, jsxs as $duWW8$jsxs} from "react/jsx-runtime";
|
|
2
|
+
import {ContextMenuHandler as $duWW8$ContextMenuHandler} from "@asup/context-menu";
|
|
3
|
+
import $duWW8$react, {useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, useState as $duWW8$useState, useRef as $duWW8$useRef, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, createContext as $duWW8$createContext} from "react";
|
|
5
4
|
import {ExclamationCircleFill as $duWW8$ExclamationCircleFill, CaretRightFill as $duWW8$CaretRightFill, CaretDownFill as $duWW8$CaretDownFill, CaretRight as $duWW8$CaretRight} from "react-bootstrap-icons";
|
|
5
|
+
import {Spinner as $duWW8$Spinner} from "react-bootstrap";
|
|
6
6
|
|
|
7
7
|
function $parcel$export(e, n, v, s) {
|
|
8
8
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
9
|
}
|
|
10
10
|
var $b65191f6d0a0a991$exports = {};
|
|
11
11
|
|
|
12
|
-
$parcel$export($b65191f6d0a0a991$exports, "ContextMenu", function () { return $567ed433af94513f$export$8dc6765e8be191c7; });
|
|
13
|
-
$parcel$export($b65191f6d0a0a991$exports, "ContextMenuProvider", function () { return $9c3c2ad4d66e1cfe$export$434a17f82a8154e4; });
|
|
14
12
|
$parcel$export($b65191f6d0a0a991$exports, "TreeNode", function () { return $47c36cf4281201f5$export$2eba8ec3a333fdbb; });
|
|
15
13
|
$parcel$export($b65191f6d0a0a991$exports, "TreeOfNodes", function () { return $ba47aaf387735a90$export$5580fff3e08a8be5; });
|
|
16
14
|
$parcel$export($b65191f6d0a0a991$exports, "WordEntry", function () { return $84765747a8c6bfe2$export$14f190ac910bde69; });
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
const $567ed433af94513f$export$8dc6765e8be191c7 = /*#__PURE__*/ (0, $duWW8$react).forwardRef(({ entries: entries , visible: visible , xPos: xPos , yPos: yPos }, ref)=>{
|
|
21
|
-
$567ed433af94513f$export$8dc6765e8be191c7.displayName = "ContextMenu";
|
|
22
|
-
var _e_label;
|
|
23
|
-
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
24
|
-
ref: ref,
|
|
25
|
-
className: `context-menu ${visible ? "visible" : ""}`,
|
|
26
|
-
style: {
|
|
27
|
-
top: `${yPos}px`,
|
|
28
|
-
left: `${xPos}px`
|
|
29
|
-
},
|
|
30
|
-
children: entries.map((e, i)=>/*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
31
|
-
className: "context-menu-item",
|
|
32
|
-
onClick: ()=>{
|
|
33
|
-
e.action && e.action();
|
|
34
|
-
},
|
|
35
|
-
children: (_e_label = e.label) !== null && _e_label !== void 0 ? _e_label : ""
|
|
36
|
-
}, i))
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const $9c3c2ad4d66e1cfe$export$c7e742effb1c51e2 = /*#__PURE__*/ (0, $duWW8$react).createContext({});
|
|
45
|
-
const $9c3c2ad4d66e1cfe$export$434a17f82a8154e4 = ({ children: children })=>{
|
|
46
|
-
// Menu resources
|
|
47
|
-
const divRef = (0, $duWW8$useRef)(null);
|
|
48
|
-
const menuRef = (0, $duWW8$useRef)(null);
|
|
49
|
-
const [menuXPos, setMenuXPos] = (0, $duWW8$useState)(0);
|
|
50
|
-
const [menuYPos, setMenuYPos] = (0, $duWW8$useState)(0);
|
|
51
|
-
const [menuVisible, setMenuVisible] = (0, $duWW8$useState)(false);
|
|
52
|
-
const [menuItems, setMenuItems] = (0, $duWW8$useState)([]);
|
|
53
|
-
// Update menu items
|
|
54
|
-
const updateMenu = (0, $duWW8$useCallback)((ret)=>{
|
|
55
|
-
if (divRef.current) {
|
|
56
|
-
if (ret.visible !== undefined) setMenuVisible(ret.visible);
|
|
57
|
-
if (ret.x) setMenuXPos(ret.x - window.scrollX - divRef.current.getBoundingClientRect().x);
|
|
58
|
-
if (ret.y) setMenuYPos(ret.y - window.scrollX - divRef.current.getBoundingClientRect().y);
|
|
59
|
-
if (ret.menuItems !== undefined) setMenuItems(ret.menuItems);
|
|
60
|
-
}
|
|
61
|
-
}, []);
|
|
62
|
-
// Handle click off the menu
|
|
63
|
-
const handleClick = (0, $duWW8$useCallback)((e)=>{
|
|
64
|
-
var _menuRef_current;
|
|
65
|
-
if (menuRef.current && (e.target instanceof Element && !((_menuRef_current = menuRef.current) === null || _menuRef_current === void 0 ? void 0 : _menuRef_current.contains(e.target)) || !(e.target instanceof Element))) setMenuVisible(false);
|
|
66
|
-
}, []);
|
|
67
|
-
// Update the document click handler
|
|
68
|
-
(0, $duWW8$useEffect)(()=>{
|
|
69
|
-
if (menuVisible) document.addEventListener("mousedown", handleClick);
|
|
70
|
-
else document.removeEventListener("mousedown", handleClick);
|
|
71
|
-
return ()=>{
|
|
72
|
-
document.removeEventListener("mousedown", handleClick);
|
|
73
|
-
};
|
|
74
|
-
}, [
|
|
75
|
-
handleClick,
|
|
76
|
-
menuVisible
|
|
77
|
-
]);
|
|
78
|
-
return /*#__PURE__*/ (0, $duWW8$jsx)($9c3c2ad4d66e1cfe$export$c7e742effb1c51e2.Provider, {
|
|
79
|
-
value: {
|
|
80
|
-
visible: menuVisible,
|
|
81
|
-
x: menuXPos,
|
|
82
|
-
y: menuYPos,
|
|
83
|
-
set: updateMenu
|
|
84
|
-
},
|
|
85
|
-
children: /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
86
|
-
className: "menu-context-provider",
|
|
87
|
-
style: {
|
|
88
|
-
position: "relative"
|
|
89
|
-
},
|
|
90
|
-
ref: divRef,
|
|
91
|
-
children: [
|
|
92
|
-
children,
|
|
93
|
-
/*#__PURE__*/ (0, $duWW8$jsx)((0, $567ed433af94513f$export$8dc6765e8be191c7), {
|
|
94
|
-
ref: menuRef,
|
|
95
|
-
entries: menuItems,
|
|
96
|
-
visible: menuVisible,
|
|
97
|
-
xPos: menuXPos,
|
|
98
|
-
yPos: menuYPos
|
|
99
|
-
})
|
|
100
|
-
]
|
|
101
|
-
})
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
18
|
|
|
105
19
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)({
|
|
113
|
-
id: "tree-of-nodes",
|
|
114
|
-
nodeList: []
|
|
115
|
-
});
|
|
20
|
+
const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)(undefined);
|
|
116
21
|
|
|
117
22
|
|
|
118
23
|
|
|
@@ -194,37 +99,35 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
194
99
|
const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemove , canRename: canRename , canAddChildren: canAddChildren , canRemoveChildren: canRemoveChildren , canRenameChildren: canRenameChildren })=>{
|
|
195
100
|
// Contexts
|
|
196
101
|
const treeContext = (0, $duWW8$useContext)((0, $886f402bccb0fd30$export$29ec378200e05207));
|
|
197
|
-
const menuContext = (0, $duWW8$useContext)((0, $9c3c2ad4d66e1cfe$export$c7e742effb1c51e2));
|
|
198
102
|
// Node information
|
|
199
|
-
const thisNode = (0, $duWW8$useMemo)(()=>
|
|
103
|
+
const thisNode = (0, $duWW8$useMemo)(()=>{
|
|
104
|
+
return treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.find((n)=>n.id === id);
|
|
105
|
+
}, [
|
|
200
106
|
id,
|
|
201
|
-
treeContext.nodeList
|
|
107
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
|
|
202
108
|
]);
|
|
203
|
-
const childNodes = (0, $duWW8$useMemo)(()=>
|
|
109
|
+
const childNodes = (0, $duWW8$useMemo)(()=>{
|
|
110
|
+
return treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.filter((n)=>n.parentId === id);
|
|
111
|
+
}, [
|
|
204
112
|
id,
|
|
205
|
-
treeContext.nodeList
|
|
113
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
|
|
206
114
|
]);
|
|
207
115
|
// State
|
|
208
|
-
const loading = (0, $duWW8$useMemo)(()=>treeContext.nodeList.findIndex((n)=>n.id === id) === -1, [
|
|
209
|
-
id,
|
|
210
|
-
treeContext.nodeList
|
|
211
|
-
]);
|
|
212
116
|
const [error, setError] = (0, $duWW8$useState)(false);
|
|
213
117
|
const [errorText, setErrotText] = (0, $duWW8$useState)(null);
|
|
214
118
|
const expanded = (0, $duWW8$useMemo)(()=>{
|
|
215
|
-
var _treeContext_expandedNodes;
|
|
216
119
|
var _treeContext_expandedNodes_findIndex;
|
|
217
|
-
return ((_treeContext_expandedNodes_findIndex =
|
|
120
|
+
return ((_treeContext_expandedNodes_findIndex = treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes.findIndex((e)=>e === id)) !== null && _treeContext_expandedNodes_findIndex !== void 0 ? _treeContext_expandedNodes_findIndex : -1) > -1;
|
|
218
121
|
}, [
|
|
219
122
|
id,
|
|
220
|
-
treeContext.expandedNodes
|
|
123
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes
|
|
221
124
|
]);
|
|
222
125
|
// // Apply selected borer
|
|
223
126
|
const currentBorder = (0, $duWW8$useMemo)(()=>{
|
|
224
|
-
return id === treeContext.selectedId ? "1px solid black" : "";
|
|
127
|
+
return id === (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selectedId) ? "1px solid black" : "";
|
|
225
128
|
}, [
|
|
226
129
|
id,
|
|
227
|
-
treeContext.selectedId
|
|
130
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.selectedId
|
|
228
131
|
]);
|
|
229
132
|
// New node parameters
|
|
230
133
|
const newNameRef = (0, $duWW8$useRef)(null);
|
|
@@ -247,7 +150,7 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
|
|
|
247
150
|
}, []);
|
|
248
151
|
const confirmNewNode = (0, $duWW8$useCallback)(async (label)=>{
|
|
249
152
|
setSavingNewNode(true);
|
|
250
|
-
if (treeContext.onAddChild) handleReturn(await treeContext.onAddChild(id, label));
|
|
153
|
+
if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onAddChild) handleReturn(await treeContext.onAddChild(id, label));
|
|
251
154
|
setSavingNewNode(false);
|
|
252
155
|
setShowNewNode(false);
|
|
253
156
|
}, [
|
|
@@ -257,18 +160,22 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
|
|
|
257
160
|
]);
|
|
258
161
|
const renameNode = (0, $duWW8$useCallback)(async (newLabel)=>{
|
|
259
162
|
setRenaming(false);
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
163
|
+
if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRename) {
|
|
164
|
+
setUpdatingNode(true);
|
|
165
|
+
handleReturn(await treeContext.onRename(id, newLabel));
|
|
166
|
+
setUpdatingNode(false);
|
|
167
|
+
}
|
|
263
168
|
}, [
|
|
264
169
|
handleReturn,
|
|
265
170
|
id,
|
|
266
171
|
treeContext
|
|
267
172
|
]);
|
|
268
173
|
const deleteThis = (0, $duWW8$useCallback)(async ()=>{
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
174
|
+
if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRemove) {
|
|
175
|
+
setUpdatingNode(true);
|
|
176
|
+
handleReturn(await treeContext.onRemove(id));
|
|
177
|
+
setUpdatingNode(false);
|
|
178
|
+
}
|
|
272
179
|
}, [
|
|
273
180
|
handleReturn,
|
|
274
181
|
id,
|
|
@@ -276,16 +183,10 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
|
|
|
276
183
|
]);
|
|
277
184
|
// Context actions
|
|
278
185
|
const addChild = (0, $duWW8$useCallback)(()=>{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
visible: false
|
|
282
|
-
});
|
|
283
|
-
setShowNewNode(true);
|
|
284
|
-
treeContext.handleExpandClick && treeContext.handleExpandClick(id, true);
|
|
285
|
-
}
|
|
186
|
+
setShowNewNode(true);
|
|
187
|
+
treeContext && treeContext.handleExpandClick(id, true);
|
|
286
188
|
}, [
|
|
287
189
|
id,
|
|
288
|
-
menuContext,
|
|
289
190
|
treeContext
|
|
290
191
|
]);
|
|
291
192
|
(0, $duWW8$useEffect)(()=>{
|
|
@@ -294,35 +195,14 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
|
|
|
294
195
|
showNewNode
|
|
295
196
|
]);
|
|
296
197
|
const renameThis = (0, $duWW8$useCallback)(()=>{
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
visible: false
|
|
300
|
-
});
|
|
301
|
-
setRenaming(true);
|
|
302
|
-
}
|
|
303
|
-
}, [
|
|
304
|
-
menuContext
|
|
305
|
-
]);
|
|
306
|
-
(0, $duWW8$useEffect)(()=>{
|
|
307
|
-
if (renaming === true && currentNameRef.current) currentNameRef.current.focus();
|
|
198
|
+
setRenaming(true);
|
|
199
|
+
treeContext === null || treeContext === void 0 ? void 0 : treeContext.handleSelect(id);
|
|
308
200
|
}, [
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const removeThis = (0, $duWW8$useCallback)(()=>{
|
|
312
|
-
if (menuContext.set) {
|
|
313
|
-
menuContext.set({
|
|
314
|
-
visible: false
|
|
315
|
-
});
|
|
316
|
-
deleteThis();
|
|
317
|
-
}
|
|
318
|
-
}, [
|
|
319
|
-
menuContext,
|
|
320
|
-
deleteThis
|
|
201
|
+
id,
|
|
202
|
+
treeContext
|
|
321
203
|
]);
|
|
322
204
|
// Context menu
|
|
323
|
-
const
|
|
324
|
-
e.preventDefault();
|
|
325
|
-
e.stopPropagation();
|
|
205
|
+
const menuItems = (0, $duWW8$useMemo)(()=>{
|
|
326
206
|
const menuItems = [];
|
|
327
207
|
if (canAddChildren) menuItems.push({
|
|
328
208
|
label: "Add",
|
|
@@ -334,122 +214,110 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
|
|
|
334
214
|
});
|
|
335
215
|
if (canRemove && (childNodes === undefined || childNodes.length === 0)) menuItems.push({
|
|
336
216
|
label: "Delete",
|
|
337
|
-
action:
|
|
338
|
-
});
|
|
339
|
-
if (typeof menuContext.set === "function") menuContext.set({
|
|
340
|
-
visible: true,
|
|
341
|
-
y: e.pageY,
|
|
342
|
-
x: e.pageX,
|
|
343
|
-
menuItems: menuItems
|
|
217
|
+
action: deleteThis
|
|
344
218
|
});
|
|
219
|
+
return menuItems;
|
|
345
220
|
}, [
|
|
346
221
|
addChild,
|
|
347
222
|
canAddChildren,
|
|
348
223
|
canRemove,
|
|
349
224
|
canRename,
|
|
350
225
|
childNodes,
|
|
351
|
-
|
|
352
|
-
removeThis,
|
|
226
|
+
deleteThis,
|
|
353
227
|
renameThis
|
|
354
228
|
]);
|
|
355
229
|
// Return node
|
|
356
|
-
return /*#__PURE__*/ (0, $duWW8$
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
230
|
+
if (!treeContext) return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {});
|
|
231
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ContextMenuHandler), {
|
|
232
|
+
menuItems: menuItems,
|
|
233
|
+
children: /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
234
|
+
id: `${treeContext.id}-treenode-${id}`,
|
|
235
|
+
className: "treenode",
|
|
236
|
+
onClickCapture: ()=>treeContext.handleSelect(id),
|
|
237
|
+
onContextMenuCapture: ()=>treeContext.handleSelect(id),
|
|
238
|
+
onFocusCapture: ()=>treeContext.handleSelect(id),
|
|
239
|
+
children: [
|
|
240
|
+
error ? /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
|
|
241
|
+
children: [
|
|
242
|
+
/*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ExclamationCircleFill), {
|
|
243
|
+
color: "var(--bs-danger)"
|
|
244
|
+
}),
|
|
245
|
+
" ",
|
|
246
|
+
errorText && errorText !== "" ? errorText : "An unknown error has occured"
|
|
247
|
+
]
|
|
248
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
|
|
249
|
+
children: [
|
|
250
|
+
childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRightFill), {
|
|
251
|
+
role: "button",
|
|
252
|
+
"aria-expanded": false,
|
|
253
|
+
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
254
|
+
onClick: ()=>treeContext.handleExpandClick(id)
|
|
255
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
|
|
256
|
+
role: "button",
|
|
257
|
+
"aria-expanded": true,
|
|
258
|
+
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
259
|
+
onClick: ()=>treeContext.handleExpandClick(id)
|
|
260
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
|
|
261
|
+
role: "button",
|
|
262
|
+
"aria-expanded": false,
|
|
263
|
+
"aria-disabled": true
|
|
264
|
+
}),
|
|
265
|
+
thisNode && /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
266
|
+
id: `${treeContext.id}-treenode-entry-${id}`,
|
|
267
|
+
ref: currentNameRef,
|
|
268
|
+
value: thisNode.label,
|
|
269
|
+
editing: renaming,
|
|
270
|
+
saving: updatingNode,
|
|
271
|
+
setValue: (ret)=>renameNode(ret),
|
|
272
|
+
sendEscape: ()=>setRenaming(false),
|
|
273
|
+
style: {
|
|
274
|
+
border: currentBorder,
|
|
275
|
+
margin: currentBorder === "" ? "1px" : "",
|
|
276
|
+
backgroundColor: currentBorder === "" ? "" : "lightgrey"
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}),
|
|
281
|
+
childNodes !== undefined && childNodes.map((h)=>/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
282
|
+
id: `${treeContext.id}-treenode-child-${h.id}`,
|
|
283
|
+
style: {
|
|
284
|
+
marginLeft: "16px",
|
|
285
|
+
display: "block",
|
|
286
|
+
maxHeight: expanded ? "99999px" : "0px",
|
|
287
|
+
height: expanded ? "auto" : "0px",
|
|
288
|
+
overflowY: "hidden",
|
|
289
|
+
visibility: expanded ? "inherit" : "hidden",
|
|
290
|
+
opacity: expanded ? 1 : 0,
|
|
291
|
+
transition: "visibility .3s, opacity .3s ease-in-out, max-height 0.3s ease-in-out"
|
|
292
|
+
},
|
|
293
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)($47c36cf4281201f5$export$2eba8ec3a333fdbb, {
|
|
294
|
+
id: h.id,
|
|
295
|
+
canRemove: canRemoveChildren,
|
|
296
|
+
canRename: canRenameChildren,
|
|
297
|
+
canAddChildren: canAddChildren,
|
|
298
|
+
canRemoveChildren: canRemoveChildren,
|
|
299
|
+
canRenameChildren: canRenameChildren
|
|
300
|
+
})
|
|
301
|
+
}, h.id)),
|
|
302
|
+
showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
303
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
406
304
|
style: {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
305
|
+
marginLeft: "14px"
|
|
306
|
+
},
|
|
307
|
+
id: `treenode-new-${id}`,
|
|
308
|
+
ref: newNameRef,
|
|
309
|
+
editing: true,
|
|
310
|
+
setValue: (ret)=>{
|
|
311
|
+
confirmNewNode(ret);
|
|
312
|
+
},
|
|
313
|
+
saving: savingNewNode,
|
|
314
|
+
sendEscape: ()=>{
|
|
315
|
+
setShowNewNode(false);
|
|
410
316
|
}
|
|
411
317
|
})
|
|
412
|
-
]
|
|
413
|
-
}),
|
|
414
|
-
childNodes !== undefined && childNodes.map((h, i)=>/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
415
|
-
id: `${treeContext.id}-treenode-child-${h.id}`,
|
|
416
|
-
style: {
|
|
417
|
-
marginLeft: "16px",
|
|
418
|
-
display: "block",
|
|
419
|
-
maxHeight: expanded ? "99999px" : "0px",
|
|
420
|
-
height: expanded ? "auto" : "0px",
|
|
421
|
-
overflowY: "hidden",
|
|
422
|
-
visibility: expanded ? "inherit" : "hidden",
|
|
423
|
-
opacity: expanded ? 1 : 0,
|
|
424
|
-
transition: "visibility .3s, opacity .3s ease-in-out, max-height 0.3s ease-in-out"
|
|
425
|
-
},
|
|
426
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)($47c36cf4281201f5$export$2eba8ec3a333fdbb, {
|
|
427
|
-
id: h.id,
|
|
428
|
-
canRemove: canRemoveChildren,
|
|
429
|
-
canRename: canRenameChildren,
|
|
430
|
-
canAddChildren: canAddChildren,
|
|
431
|
-
canRemoveChildren: canRemoveChildren,
|
|
432
|
-
canRenameChildren: canRenameChildren
|
|
433
|
-
})
|
|
434
|
-
}, h.id)),
|
|
435
|
-
showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
436
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
437
|
-
style: {
|
|
438
|
-
marginLeft: "14px"
|
|
439
|
-
},
|
|
440
|
-
id: `treenode-new-${id}`,
|
|
441
|
-
ref: newNameRef,
|
|
442
|
-
editing: true,
|
|
443
|
-
setValue: (ret)=>{
|
|
444
|
-
confirmNewNode(ret);
|
|
445
|
-
},
|
|
446
|
-
saving: savingNewNode,
|
|
447
|
-
sendEscape: ()=>{
|
|
448
|
-
setShowNewNode(false);
|
|
449
|
-
}
|
|
450
318
|
})
|
|
451
|
-
|
|
452
|
-
|
|
319
|
+
]
|
|
320
|
+
})
|
|
453
321
|
});
|
|
454
322
|
};
|
|
455
323
|
|
|
@@ -475,26 +343,31 @@ const $03b5c1380eb9c122$export$85488b7eb1e4976f = (id, included, hierarchyNodes)
|
|
|
475
343
|
|
|
476
344
|
|
|
477
345
|
const $c7008d808d3e1c7a$export$40c47a7ac5f85aba = (nodeList, selectedId, expandedNodes)=>{
|
|
478
|
-
|
|
346
|
+
return [
|
|
479
347
|
...expandedNodes,
|
|
480
348
|
...(0, $03b5c1380eb9c122$export$85488b7eb1e4976f)(selectedId, [], nodeList).map((n)=>n.id).filter((k)=>!expandedNodes.includes(k))
|
|
481
349
|
].sort((a, b)=>`${a}`.localeCompare(`${b}`));
|
|
482
|
-
console.log(`checkExpandedNodes: ${k.join(",")}`);
|
|
483
|
-
return k;
|
|
484
350
|
};
|
|
485
351
|
|
|
486
352
|
|
|
487
353
|
|
|
488
354
|
|
|
489
|
-
|
|
490
355
|
const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id , nodeList: nodeList , roots: roots , canRemoveRoot: // canAddRoot = false,
|
|
491
356
|
canRemoveRoot = false , canRenameRoot: canRenameRoot = false , canAddChildren: canAddChildren = false , canRemoveChildren: canRemoveChildren = false , canRenameChildren: canRenameChildren = false , selectedId: selectedId , handleSelect: handleSelect = ()=>{
|
|
492
357
|
return;
|
|
493
358
|
} , onAdd: onAdd , onRename: onRename , onRemove: onRemove })=>{
|
|
494
359
|
const [expandedNodes, setExpandedNodes] = (0, $duWW8$useState)([]);
|
|
495
360
|
(0, $duWW8$useEffect)(()=>{
|
|
496
|
-
|
|
497
|
-
|
|
361
|
+
if (selectedId) {
|
|
362
|
+
// Check all nodes are showing that should be
|
|
363
|
+
const shouldExpand = (0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList, selectedId, expandedNodes);
|
|
364
|
+
shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0 && setExpandedNodes(shouldExpand);
|
|
365
|
+
}
|
|
366
|
+
}, [
|
|
367
|
+
expandedNodes,
|
|
368
|
+
nodeList,
|
|
369
|
+
selectedId
|
|
370
|
+
]);
|
|
498
371
|
// Change expansion and update context
|
|
499
372
|
const changeExpand = (0, $duWW8$useCallback)((eKey, force)=>{
|
|
500
373
|
const newExpandedNodes = [
|
|
@@ -507,28 +380,26 @@ canRemoveRoot = false , canRenameRoot: canRenameRoot = false , canAddChildren: c
|
|
|
507
380
|
}, [
|
|
508
381
|
expandedNodes
|
|
509
382
|
]);
|
|
510
|
-
return /*#__PURE__*/ (0, $duWW8$jsx)((0, $
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}, r))
|
|
531
|
-
})
|
|
383
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)((0, $886f402bccb0fd30$export$29ec378200e05207).Provider, {
|
|
384
|
+
value: {
|
|
385
|
+
id: id,
|
|
386
|
+
nodeList: nodeList,
|
|
387
|
+
selectedId: selectedId,
|
|
388
|
+
handleSelect: handleSelect,
|
|
389
|
+
expandedNodes: expandedNodes,
|
|
390
|
+
handleExpandClick: (r, f)=>changeExpand(r, f),
|
|
391
|
+
onAddChild: onAdd,
|
|
392
|
+
onRename: onRename,
|
|
393
|
+
onRemove: onRemove
|
|
394
|
+
},
|
|
395
|
+
children: roots.map((r)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $47c36cf4281201f5$export$2eba8ec3a333fdbb), {
|
|
396
|
+
id: r,
|
|
397
|
+
canRemove: canRemoveRoot,
|
|
398
|
+
canAddChildren: canAddChildren,
|
|
399
|
+
canRename: canRenameRoot,
|
|
400
|
+
canRemoveChildren: canRemoveChildren,
|
|
401
|
+
canRenameChildren: canRenameChildren
|
|
402
|
+
}, r))
|
|
532
403
|
});
|
|
533
404
|
};
|
|
534
405
|
|
|
@@ -544,5 +415,5 @@ $parcel$export($3d005c8713d7dfb7$exports, "getParents", function () { return $03
|
|
|
544
415
|
|
|
545
416
|
|
|
546
417
|
|
|
547
|
-
export {$
|
|
418
|
+
export {$47c36cf4281201f5$export$2eba8ec3a333fdbb as TreeNode, $ba47aaf387735a90$export$5580fff3e08a8be5 as TreeOfNodes, $84765747a8c6bfe2$export$14f190ac910bde69 as WordEntry, $03b5c1380eb9c122$export$85488b7eb1e4976f as getParents};
|
|
548
419
|
//# sourceMappingURL=main.js.map
|