@asup/tree-of-nodes 2.0.3 → 2.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.css +36 -2
- package/dist/cjs/main.css.map +1 -1
- package/dist/cjs/main.js +171 -152
- package/dist/cjs/main.js.map +1 -1
- package/dist/main.css +36 -2
- package/dist/main.css.map +1 -1
- package/dist/main.js +172 -153
- package/dist/main.js.map +1 -1
- package/dist/tree-of-nodes.d.ts +4 -3
- package/dist/tree-of-nodes.d.ts.map +1 -1
- package/package.json +23 -16
package/dist/main.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "./main.css";
|
|
2
|
-
import {
|
|
2
|
+
import {jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment, jsx as $duWW8$jsx} from "react/jsx-runtime";
|
|
3
3
|
import {ContextMenuHandler as $duWW8$ContextMenuHandler} from "@asup/context-menu";
|
|
4
4
|
import $duWW8$react, {useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, useState as $duWW8$useState, useRef as $duWW8$useRef, useEffect as $duWW8$useEffect, useCallback as $duWW8$useCallback, createContext as $duWW8$createContext} from "react";
|
|
5
5
|
import {ExclamationCircleFill as $duWW8$ExclamationCircleFill, CaretRightFill as $duWW8$CaretRightFill, CaretDownFill as $duWW8$CaretDownFill, CaretRight as $duWW8$CaretRight} from "react-bootstrap-icons";
|
|
6
|
+
import {_ as $duWW8$_} from "@swc/helpers/_/_object_spread";
|
|
6
7
|
import {Spinner as $duWW8$Spinner} from "react-bootstrap";
|
|
7
8
|
|
|
8
9
|
|
|
@@ -53,18 +54,18 @@ const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)(unde
|
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
|
|
56
58
|
const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react).forwardRef(({ id: id, value: value, editing: editing, saving: saving, setValue: setValue, sendEscape: sendEscape, style: style, spellCheck: spellCheck = "true" }, ref)=>{
|
|
57
59
|
$84765747a8c6bfe2$export$14f190ac910bde69.displayName = "WordEntry";
|
|
58
60
|
const currentStyle = (0, $duWW8$useMemo)(()=>{
|
|
59
|
-
return {
|
|
61
|
+
return (0, $duWW8$_)({
|
|
60
62
|
display: "inline-block",
|
|
61
63
|
padding: "1px",
|
|
62
64
|
paddingLeft: "3px",
|
|
63
65
|
paddingRight: "3px",
|
|
64
66
|
border: "1px",
|
|
65
|
-
borderRadius: "3px"
|
|
66
|
-
|
|
67
|
-
};
|
|
67
|
+
borderRadius: "3px"
|
|
68
|
+
}, style);
|
|
68
69
|
}, [
|
|
69
70
|
style
|
|
70
71
|
]);
|
|
@@ -75,7 +76,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
75
76
|
value
|
|
76
77
|
]);
|
|
77
78
|
const returnData = (0, $duWW8$useCallback)(()=>{
|
|
78
|
-
setValue
|
|
79
|
+
setValue === null || setValue === void 0 ? void 0 : setValue(currentValue);
|
|
79
80
|
}, [
|
|
80
81
|
currentValue,
|
|
81
82
|
setValue
|
|
@@ -83,7 +84,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
83
84
|
const keyPress = (0, $duWW8$useCallback)((e)=>{
|
|
84
85
|
if (e.code === "Escape") {
|
|
85
86
|
setCurrentValue(value !== null && value !== void 0 ? value : "");
|
|
86
|
-
sendEscape
|
|
87
|
+
sendEscape === null || sendEscape === void 0 ? void 0 : sendEscape();
|
|
87
88
|
} else if (e.code === "Enter") returnData();
|
|
88
89
|
}, [
|
|
89
90
|
returnData,
|
|
@@ -92,6 +93,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
92
93
|
]);
|
|
93
94
|
// Simple if not editing
|
|
94
95
|
if (!editing) return /*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
96
|
+
className: "ton-label-span",
|
|
95
97
|
style: currentStyle,
|
|
96
98
|
id: `${id}`,
|
|
97
99
|
children: value ? value : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {
|
|
@@ -101,6 +103,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
101
103
|
return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
102
104
|
style: currentStyle,
|
|
103
105
|
id: `${id}-holder`,
|
|
106
|
+
className: "ton-rename-holder",
|
|
104
107
|
children: [
|
|
105
108
|
saving && /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Spinner), {
|
|
106
109
|
id: `${id}-spinner`,
|
|
@@ -113,12 +116,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
|
|
|
113
116
|
id: String(id),
|
|
114
117
|
ref: ref,
|
|
115
118
|
type: "text",
|
|
116
|
-
|
|
117
|
-
lineHeight: "0.75rem",
|
|
118
|
-
border: "1px dotted black",
|
|
119
|
-
width: "auto",
|
|
120
|
-
minWidth: "0"
|
|
121
|
-
},
|
|
119
|
+
className: "ton-rename",
|
|
122
120
|
value: currentValue,
|
|
123
121
|
disabled: saving,
|
|
124
122
|
onChange: (e)=>setCurrentValue(e.currentTarget.value),
|
|
@@ -253,8 +251,9 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
253
251
|
]);
|
|
254
252
|
// Context actions
|
|
255
253
|
const addChild = (0, $duWW8$useCallback)(()=>{
|
|
254
|
+
var _treeContext_handleExpandClick;
|
|
256
255
|
setShowNewNode(true);
|
|
257
|
-
treeContext
|
|
256
|
+
treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleExpandClick = treeContext.handleExpandClick) === null || _treeContext_handleExpandClick === void 0 ? void 0 : _treeContext_handleExpandClick.call(treeContext, id, true);
|
|
258
257
|
}, [
|
|
259
258
|
id,
|
|
260
259
|
treeContext
|
|
@@ -265,8 +264,9 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
265
264
|
showNewNode
|
|
266
265
|
]);
|
|
267
266
|
const renameThis = (0, $duWW8$useCallback)(()=>{
|
|
267
|
+
var _treeContext_handleSelect;
|
|
268
268
|
setRenaming(true);
|
|
269
|
-
treeContext
|
|
269
|
+
treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
|
|
270
270
|
}, [
|
|
271
271
|
id,
|
|
272
272
|
treeContext
|
|
@@ -297,124 +297,139 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
|
|
|
297
297
|
renameThis
|
|
298
298
|
]);
|
|
299
299
|
// Return node
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
onClick: ()=>treeContext.handleExpandClick(id)
|
|
336
|
-
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
|
|
337
|
-
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
338
|
-
className: "ton-expander",
|
|
339
|
-
role: "button",
|
|
340
|
-
"aria-expanded": true,
|
|
341
|
-
"aria-label": "Expander",
|
|
342
|
-
color: nodeColour,
|
|
343
|
-
onClick: ()=>{
|
|
344
|
-
treeContext.handleExpandClick(id);
|
|
345
|
-
}
|
|
346
|
-
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
|
|
347
|
-
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
348
|
-
className: "ton-expander",
|
|
349
|
-
role: "button",
|
|
350
|
-
color: nodeColour,
|
|
351
|
-
"aria-expanded": false,
|
|
352
|
-
"aria-label": "Disabled expander",
|
|
353
|
-
onClick: ()=>treeContext.handleSelect && treeContext.handleSelect(id)
|
|
354
|
-
}),
|
|
355
|
-
thisNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
356
|
-
style: {
|
|
357
|
-
display: "inline-block"
|
|
358
|
-
},
|
|
359
|
-
onContextMenuCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
|
|
360
|
-
onClickCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
|
|
361
|
-
onFocusCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
|
|
362
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
363
|
-
id: `${treeContext.id}-treenode-entry-${id}`,
|
|
364
|
-
ref: currentNameRef,
|
|
365
|
-
value: thisNode.label,
|
|
366
|
-
editing: renaming,
|
|
367
|
-
saving: updatingNode,
|
|
368
|
-
setValue: (ret)=>renameNode(ret),
|
|
369
|
-
sendEscape: ()=>setRenaming(false),
|
|
300
|
+
return !treeContext ? null : /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
|
|
301
|
+
children: [
|
|
302
|
+
/*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ContextMenuHandler), {
|
|
303
|
+
menuItems: menuItems,
|
|
304
|
+
style: {
|
|
305
|
+
display: "inline-block",
|
|
306
|
+
width: "100%"
|
|
307
|
+
},
|
|
308
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
309
|
+
id: `${treeContext.id}-treenode-${id}`,
|
|
310
|
+
className: "treenode",
|
|
311
|
+
children: error ? /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
|
|
312
|
+
children: [
|
|
313
|
+
/*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ExclamationCircleFill), {
|
|
314
|
+
color: "var(--bs-danger)"
|
|
315
|
+
}),
|
|
316
|
+
" ",
|
|
317
|
+
errorText
|
|
318
|
+
]
|
|
319
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
|
|
320
|
+
className: "ton-node",
|
|
321
|
+
children: [
|
|
322
|
+
treeContext.showCheckBox && /*#__PURE__*/ (0, $duWW8$jsx)("input", {
|
|
323
|
+
ref: checkRef,
|
|
324
|
+
type: "checkbox",
|
|
325
|
+
role: "checkbox",
|
|
326
|
+
className: "ton-checkbox",
|
|
327
|
+
id: `${treeContext.id}-treenode-checkbox-${id}`,
|
|
328
|
+
onClick: ()=>{
|
|
329
|
+
var _treeContext_handleSelect;
|
|
330
|
+
return treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, descendents);
|
|
331
|
+
}
|
|
332
|
+
}),
|
|
333
|
+
childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRightFill), {
|
|
334
|
+
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
370
335
|
style: {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
backgroundColor: currentBorder === "" ? "" : treeContext.textHighlight
|
|
336
|
+
width: "16px",
|
|
337
|
+
height: "16px"
|
|
374
338
|
},
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
339
|
+
className: "ton-expander",
|
|
340
|
+
role: "button",
|
|
341
|
+
color: nodeColour,
|
|
342
|
+
"aria-expanded": false,
|
|
343
|
+
"aria-label": "Expander",
|
|
344
|
+
onClick: ()=>treeContext.handleExpandClick(id)
|
|
345
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
|
|
346
|
+
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
347
|
+
className: "ton-expander",
|
|
348
|
+
role: "button",
|
|
349
|
+
"aria-expanded": true,
|
|
350
|
+
"aria-label": "Expander",
|
|
351
|
+
color: nodeColour,
|
|
352
|
+
onClick: ()=>treeContext.handleExpandClick(id)
|
|
353
|
+
}) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
|
|
354
|
+
id: `${treeContext.id}-treenode-caret-${id}`,
|
|
355
|
+
className: "ton-expander",
|
|
356
|
+
role: "button",
|
|
357
|
+
color: nodeColour,
|
|
358
|
+
"aria-expanded": false,
|
|
359
|
+
"aria-label": "Disabled expander",
|
|
360
|
+
onClick: ()=>{
|
|
361
|
+
var _treeContext_handleSelect;
|
|
362
|
+
return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
|
|
363
|
+
}
|
|
364
|
+
}),
|
|
365
|
+
thisNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
366
|
+
className: "ton-label",
|
|
367
|
+
style: {
|
|
368
|
+
width: `calc(100% - ${treeContext.showCheckBox ? "32px" : "16px"})`
|
|
369
|
+
},
|
|
370
|
+
onContextMenuCapture: ()=>{
|
|
371
|
+
var _treeContext_handleSelect;
|
|
372
|
+
return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
|
|
373
|
+
},
|
|
374
|
+
onClickCapture: ()=>{
|
|
375
|
+
var _treeContext_handleSelect;
|
|
376
|
+
return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
|
|
377
|
+
},
|
|
378
|
+
onFocusCapture: ()=>{
|
|
379
|
+
var _treeContext_handleSelect;
|
|
380
|
+
return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
|
|
381
|
+
},
|
|
382
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
383
|
+
id: `${treeContext.id}-treenode-entry-${id}`,
|
|
384
|
+
ref: currentNameRef,
|
|
385
|
+
value: thisNode.label,
|
|
386
|
+
editing: renaming,
|
|
387
|
+
saving: updatingNode,
|
|
388
|
+
setValue: (ret)=>renameNode(ret),
|
|
389
|
+
sendEscape: ()=>setRenaming(false),
|
|
390
|
+
style: {
|
|
391
|
+
border: currentBorder,
|
|
392
|
+
margin: currentBorder === "" ? "1px" : "",
|
|
393
|
+
backgroundColor: currentBorder === "" ? "" : treeContext.textHighlight
|
|
394
|
+
},
|
|
395
|
+
spellCheck: treeContext.spellCheck
|
|
394
396
|
})
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
}),
|
|
398
|
-
showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
399
|
-
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
400
|
-
style: {
|
|
401
|
-
marginLeft: "14px"
|
|
402
|
-
},
|
|
403
|
-
id: `treenode-new-${id}`,
|
|
404
|
-
ref: newNameRef,
|
|
405
|
-
editing: true,
|
|
406
|
-
setValue: (ret)=>{
|
|
407
|
-
confirmNewNode(ret);
|
|
408
|
-
},
|
|
409
|
-
saving: savingNewNode,
|
|
410
|
-
sendEscape: ()=>{
|
|
411
|
-
setShowNewNode(false);
|
|
412
|
-
},
|
|
413
|
-
spellCheck: treeContext.spellCheck
|
|
397
|
+
})
|
|
398
|
+
]
|
|
414
399
|
})
|
|
415
400
|
})
|
|
416
|
-
|
|
417
|
-
|
|
401
|
+
}),
|
|
402
|
+
showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
|
|
403
|
+
style: {
|
|
404
|
+
marginLeft: "14px"
|
|
405
|
+
},
|
|
406
|
+
id: `treenode-new-${id}`,
|
|
407
|
+
ref: newNameRef,
|
|
408
|
+
editing: true,
|
|
409
|
+
setValue: (ret)=>confirmNewNode(ret),
|
|
410
|
+
saving: savingNewNode,
|
|
411
|
+
sendEscape: ()=>setShowNewNode(false),
|
|
412
|
+
spellCheck: treeContext.spellCheck
|
|
413
|
+
}),
|
|
414
|
+
childNodes !== undefined && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
415
|
+
className: `ton-collapsible-wrapper ${expanded ? "" : "collapsed"}`,
|
|
416
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
417
|
+
className: "ton-collapsible",
|
|
418
|
+
children: childNodes.map((h)=>/*#__PURE__*/ (0, $duWW8$jsx)("span", {
|
|
419
|
+
id: `${treeContext.id}-treenode-child-${h.id}`,
|
|
420
|
+
className: "ton-child",
|
|
421
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)($47c36cf4281201f5$export$2eba8ec3a333fdbb, {
|
|
422
|
+
id: h.id,
|
|
423
|
+
canRemove: canRemoveChildren,
|
|
424
|
+
canRename: canRenameChildren,
|
|
425
|
+
canAddChildren: canAddChildren,
|
|
426
|
+
canRemoveChildren: canRemoveChildren,
|
|
427
|
+
canRenameChildren: canRenameChildren
|
|
428
|
+
})
|
|
429
|
+
}, h.id))
|
|
430
|
+
})
|
|
431
|
+
})
|
|
432
|
+
]
|
|
418
433
|
});
|
|
419
434
|
};
|
|
420
435
|
$47c36cf4281201f5$export$2eba8ec3a333fdbb.displayName = "TreeNode";
|
|
@@ -444,7 +459,7 @@ const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList,
|
|
|
444
459
|
if (selectedArray.length > 0) {
|
|
445
460
|
// Check all nodes are showing that should be
|
|
446
461
|
const shouldExpand = (0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList, selectedArray, expandedNodes);
|
|
447
|
-
shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0
|
|
462
|
+
if (shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0) setExpandedNodes(shouldExpand);
|
|
448
463
|
}
|
|
449
464
|
}, [
|
|
450
465
|
expandedNodes,
|
|
@@ -463,30 +478,34 @@ const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList,
|
|
|
463
478
|
}, [
|
|
464
479
|
expandedNodes
|
|
465
480
|
]);
|
|
466
|
-
return /*#__PURE__*/ (0, $duWW8$jsx)(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
481
|
+
return /*#__PURE__*/ (0, $duWW8$jsx)("div", {
|
|
482
|
+
id: id,
|
|
483
|
+
className: "tree-of-nodes",
|
|
484
|
+
children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $886f402bccb0fd30$export$29ec378200e05207).Provider, {
|
|
485
|
+
value: {
|
|
486
|
+
id: id,
|
|
487
|
+
nodeList: nodeList,
|
|
488
|
+
selected: selectedArray,
|
|
489
|
+
showCheckBox: showCheckBox,
|
|
490
|
+
handleSelect: handleSelect,
|
|
491
|
+
expandedNodes: expandedNodes,
|
|
492
|
+
handleExpandClick: (r, f)=>changeExpand(r, f),
|
|
493
|
+
onAddChild: onAdd,
|
|
494
|
+
onRename: onRename,
|
|
495
|
+
onRemove: onRemove,
|
|
496
|
+
nodeHighlight: nodeHighlight,
|
|
497
|
+
textHighlight: textHighlight,
|
|
498
|
+
spellCheck: spellCheck
|
|
499
|
+
},
|
|
500
|
+
children: roots.map((r)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $47c36cf4281201f5$export$2eba8ec3a333fdbb), {
|
|
501
|
+
id: r,
|
|
502
|
+
canRemove: canRemoveRoot,
|
|
503
|
+
canAddChildren: canAddChildren,
|
|
504
|
+
canRename: canRenameRoot,
|
|
505
|
+
canRemoveChildren: canRemoveChildren,
|
|
506
|
+
canRenameChildren: canRenameChildren
|
|
507
|
+
}, r))
|
|
508
|
+
})
|
|
490
509
|
});
|
|
491
510
|
};
|
|
492
511
|
$ba47aaf387735a90$export$5580fff3e08a8be5.displayName = "TreeOfNodes";
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;AGGO,MAAM,4CAAe,CAC1B,IACA,UACA;IAEA,MAAM,aAAa,MAAM,OAAO,CAAC,MAAM,KAAK;QAAC;KAAG;IAEhD,MAAM,UAAU,WACb,GAAG,CAAC,CAAC,IAAM,eAAe,IAAI,CAAC,CAAC,IAAM,EAAE,EAAE,KAAK,IAC/C,MAAM,CAAC,CAAC,IAAM,MAAM;IACvB,IAAI,QAAQ,MAAM,KAAK,GAAG,OAAO;IAEjC,MAAM,UAAU,AACd,QACG,GAAG,CAAC,CAAC,IAAM,EAAE,QAAQ,EACrB,GAAG,CAAC,CAAC,MAAQ,eAAe,IAAI,CAAC,CAAC,IAAM,QAAQ,EAAE,EA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AAM,CAAC,cAAc,QAAQ,CAAC,IAAI,MAAM,GAAG,KAC9D,iBAAiB;QACrB;IACF,GAAG;QAAC;QAAe;QAAU;KAAc;IAE3C,uCAAuC;IACvC,MAAM,eAAe,CAAA,GAAA,kBAAU,EAC7B,CAAC,MAAW;QACV,MAAM,mBAAmB;eAAI;SAAc;QAC3C,MAAM,KAAK,iBAAiB,SAAS,CAAC,CAAC,OAAS,SAAS;QACzD,IAAI,AAAC,OAAO,MAAM,UAAU,aAAc,UAAU,MAAM,iBAAiB,IAAI,CAAC;aAC3E,iBAAiB,MAAM,CAAC,IAAI;QACjC,iBAAiB;IACnB,GACA;QAAC;KAAc;IAGjB,qBACE,gBAAC,CAAA,GAAA,yCAAiB,EAAE,QAAQ;QAC1B,OAAO;YACL,IAAI;sBACJ;YACA,UAAU;0BACV;0BACA;2BACA;YACA,mBAAmB,CAAC,GAAG,IAAM,aAAa,GAAG;YAC7C,YAAY;sBACZ;sBACA;2BACA;2BACA;wBACA;QACF;kBAEC,MAAM,GAAG,CAAC,CAAC,kBACV,gBAAC,CAAA,GAAA,yCAAO;gBAEN,IAAI;gBACJ,WAAW;gBACX,gBAAgB;gBAChB,WAAW;gBACX,mBAAmB;gBACnB,mBAAmB;eANd;;AAWf;AAEA,0CAAY,WAAW,GAAG;;;;;;;;;;;","sources":["src/main.ts","src/components/index.ts","src/components/TreeNode.tsx","src/functions/getAncestors.tsx","src/functions/getDescendentIds.ts","src/components/TreeOfNodesContext.ts","src/components/WordEntry.tsx","src/components/TreeOfNodes.tsx","src/functions/checkExpandedNodes.ts","src/functions/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./functions\";\n","import { TreeNode } from \"./TreeNode\";\nimport { TreeOfNodes } from \"./TreeOfNodes\";\nimport { iNodeUpdate, TreeNodeBase, TreeNodeData } from \"./interface\";\nimport { WordEntry } from \"./WordEntry\";\n\nexport { TreeNode, TreeOfNodes, WordEntry };\nexport type { TreeNodeBase, TreeNodeData, iNodeUpdate };\n","import { ContextMenuHandler, iMenuItem } from \"@asup/context-menu\";\nimport { Key, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n CaretDownFill,\n CaretRight,\n CaretRightFill,\n ExclamationCircleFill,\n} from \"react-bootstrap-icons\";\nimport { getAncestors } from \"../functions/getAncestors\";\nimport { getDescendentIds } from \"../functions/getDescendentIds\";\nimport \"./TreeNode.css\";\nimport { TreeOfNodesContext } from \"./TreeOfNodesContext\";\nimport { WordEntry } from \"./WordEntry\";\nimport { iNodeUpdate } from \"./interface\";\n\ninterface TreeNodeProps {\n id: Key;\n indentLevel?: number;\n canRemove?: boolean;\n canRename?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n refresh?: () => void;\n}\n\nexport const TreeNode = ({\n id,\n canRemove,\n canRename,\n canAddChildren,\n canRemoveChildren,\n canRenameChildren,\n}: TreeNodeProps): JSX.Element => {\n // Contexts\n const treeContext = useContext(TreeOfNodesContext);\n\n // Node information\n const thisNode = useMemo(\n () => treeContext?.nodeList.find((n) => n.id === id),\n [id, treeContext?.nodeList],\n );\n const childNodes = useMemo(\n () => treeContext?.nodeList.filter((n) => n.parentId === id),\n [id, treeContext?.nodeList],\n );\n const descendents = useMemo(\n () => getDescendentIds(id, treeContext?.nodeList ?? []),\n [id, treeContext],\n );\n\n // State\n const [error, setError] = useState<boolean>(false);\n const [errorText, setErrotText] = useState<string>(\"\");\n const expanded = useMemo(() => {\n return (treeContext?.expandedNodes.findIndex((e) => e === id) ?? -1) > -1;\n }, [id, treeContext?.expandedNodes]);\n\n // Checkbox\n const checkRef = useRef<HTMLInputElement | null>(null);\n useEffect(() => {\n if (checkRef.current) {\n if (treeContext?.selected.includes(id)) {\n checkRef.current.checked = true;\n checkRef.current.indeterminate = false;\n } else if (descendents.some((d) => treeContext?.selected.includes(d))) {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = true;\n } else {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = false;\n }\n }\n }, [descendents, id, treeContext?.selected]);\n\n // Apply selected border\n const currentBorder = useMemo<string>(() => {\n return treeContext?.selected.includes(id) ? \"1px solid black\" : \"\";\n }, [id, treeContext?.selected]);\n const nodeColour = useMemo<string | undefined>(() => {\n if (treeContext && treeContext.selected) {\n const anc = getAncestors(treeContext.selected, [], treeContext?.nodeList).map((n) => n.id);\n if ([...anc, treeContext.selected].includes(id)) return treeContext.nodeHighlight;\n }\n return;\n }, [id, treeContext]);\n\n // New node parameters\n const newNameRef = useRef<HTMLInputElement | null>(null);\n const [showNewNode, setShowNewNode] = useState<boolean>(false);\n const [savingNewNode, setSavingNewNode] = useState<boolean>(false);\n\n // Rename parameters\n const currentNameRef = useRef<HTMLInputElement | null>(null);\n const [renaming, setRenaming] = useState<boolean>(false);\n const [updatingNode, setUpdatingNode] = useState<boolean>(false);\n\n // Context functions\n const handleReturn = useCallback((ret: iNodeUpdate) => {\n if (!ret.success) {\n setError(true);\n setErrotText(ret.ErrorText ?? \"An unknown error has occured\");\n } else {\n setError(false);\n setErrotText(\"\");\n }\n }, []);\n\n const confirmNewNode = useCallback(\n async (label: string) => {\n setSavingNewNode(true);\n if (treeContext?.onAddChild) {\n handleReturn(await treeContext.onAddChild(id, label));\n }\n setSavingNewNode(false);\n setShowNewNode(false);\n },\n [handleReturn, id, treeContext],\n );\n\n const renameNode = useCallback(\n async (newLabel: string) => {\n setRenaming(false);\n if (treeContext?.onRename) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRename(id, newLabel));\n setUpdatingNode(false);\n }\n },\n [handleReturn, id, treeContext],\n );\n\n const deleteThis = useCallback(async () => {\n if (treeContext?.onRemove) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRemove(id));\n setUpdatingNode(false);\n }\n }, [handleReturn, id, treeContext]);\n\n // Context actions\n const addChild = useCallback(() => {\n setShowNewNode(true);\n treeContext && treeContext.handleExpandClick(id, true);\n }, [id, treeContext]);\n useEffect(() => {\n if (showNewNode === true && newNameRef.current) newNameRef.current.focus();\n }, [showNewNode]);\n const renameThis = useCallback(() => {\n setRenaming(true);\n treeContext && treeContext.handleSelect && treeContext.handleSelect(id);\n }, [id, treeContext]);\n\n // Context menu\n const menuItems = useMemo(() => {\n const menuItems: iMenuItem[] = [];\n if (canAddChildren) {\n menuItems.push({ label: \"Add\", action: addChild });\n }\n if (canRename) {\n menuItems.push({ label: \"Rename\", action: renameThis });\n }\n if (canRemove && (childNodes === undefined || childNodes.length === 0)) {\n menuItems.push({ label: \"Delete\", action: deleteThis });\n }\n return menuItems;\n }, [addChild, canAddChildren, canRemove, canRename, childNodes, deleteThis, renameThis]);\n\n // Return node\n if (!treeContext) return <></>;\n return (\n <ContextMenuHandler menuItems={menuItems}>\n <div\n id={`${treeContext.id}-treenode-${id}`}\n className=\"treenode\"\n >\n {error ? (\n <>\n <ExclamationCircleFill color=\"var(--bs-danger)\" /> {errorText}\n </>\n ) : (\n <div className=\"ton-node\">\n {treeContext.showCheckBox && (\n <input\n ref={checkRef}\n type=\"checkbox\"\n role=\"checkbox\"\n className=\"ton-checkbox\"\n id={`${treeContext.id}-treenode-checkbox-${id}`}\n onClick={() => {\n treeContext.handleSelect && treeContext.handleSelect(descendents);\n }}\n />\n )}\n {childNodes !== undefined && childNodes.length > 0 ? (\n !expanded ? (\n <CaretRightFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n className=\"ton-expander\"\n role=\"button\"\n color={nodeColour}\n aria-expanded={false}\n aria-label=\"Expander\"\n onClick={() => treeContext.handleExpandClick(id)}\n />\n ) : (\n <CaretDownFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n className=\"ton-expander\"\n role=\"button\"\n aria-expanded={true}\n aria-label=\"Expander\"\n color={nodeColour}\n onClick={() => {\n treeContext.handleExpandClick(id);\n }}\n />\n )\n ) : (\n <CaretRight\n id={`${treeContext.id}-treenode-caret-${id}`}\n className=\"ton-expander\"\n role=\"button\"\n color={nodeColour}\n aria-expanded={false}\n aria-label=\"Disabled expander\"\n onClick={() => treeContext.handleSelect && treeContext.handleSelect(id)}\n />\n )}\n {thisNode && (\n <div\n style={{ display: \"inline-block\" }}\n onContextMenuCapture={() =>\n treeContext.handleSelect && treeContext.handleSelect(id)\n }\n onClickCapture={() => treeContext.handleSelect && treeContext.handleSelect(id)}\n onFocusCapture={() => treeContext.handleSelect && treeContext.handleSelect(id)}\n >\n <WordEntry\n id={`${treeContext.id}-treenode-entry-${id}`}\n ref={currentNameRef}\n value={thisNode.label}\n editing={renaming}\n saving={updatingNode}\n setValue={(ret) => renameNode(ret)}\n sendEscape={() => setRenaming(false)}\n style={{\n border: currentBorder,\n margin: currentBorder === \"\" ? \"1px\" : \"\",\n backgroundColor: currentBorder === \"\" ? \"\" : treeContext.textHighlight,\n }}\n spellCheck={treeContext.spellCheck}\n />\n </div>\n )}\n </div>\n )}\n {childNodes !== undefined && (\n <div className={`ton-collapsible-wrapper ${expanded ? \"\" : \"collapsed\"}`}>\n <div className=\"ton-collapsible\">\n {childNodes.map((h) => (\n <span\n key={h.id}\n id={`${treeContext.id}-treenode-child-${h.id}`}\n className=\"ton-child\"\n >\n <TreeNode\n id={h.id}\n canRemove={canRemoveChildren}\n canRename={canRenameChildren}\n canAddChildren={canAddChildren}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n </span>\n ))}\n </div>\n </div>\n )}\n {showNewNode && (\n <div>\n <WordEntry\n style={{ marginLeft: \"14px\" }}\n id={`treenode-new-${id}`}\n ref={newNameRef}\n editing={true}\n setValue={(ret) => {\n confirmNewNode(ret);\n }}\n saving={savingNewNode}\n sendEscape={() => {\n setShowNewNode(false);\n }}\n spellCheck={treeContext.spellCheck}\n />\n </div>\n )}\n </div>\n </ContextMenuHandler>\n );\n};\n\nTreeNode.displayName = \"TreeNode\";\n","import { Key } from \"react\";\nimport { TreeNodeBase } from \"../components/interface\";\n\nexport const getAncestors = (\n id: Key | Key[],\n included: TreeNodeBase[],\n hierarchyNodes: TreeNodeBase[],\n): TreeNodeBase[] => {\n const processIds = Array.isArray(id) ? id : [id];\n\n const current = processIds\n .map((i) => hierarchyNodes.find((h) => h.id === i))\n .filter((h) => h !== undefined) as TreeNodeBase[];\n if (current.length === 0) return included;\n\n const parents = (\n current\n .map((h) => h.parentId)\n .map((pid) => hierarchyNodes.find((h) => pid === h.id)) as TreeNodeBase[]\n ).filter((p) => p !== undefined) as TreeNodeBase[];\n if (parents.length === 0) return included;\n else\n return getAncestors(\n parents.map((p) => p.id),\n [...included, ...parents.filter((p) => !included.includes(p))],\n hierarchyNodes,\n );\n};\n","import { Key } from \"react\";\nimport { TreeNodeBase } from \"../components/interface\";\n\nexport const getDescendentIds = (id: Key | Key[], hierarchyNodes: TreeNodeBase[]): Key[] => {\n const processIds = Array.isArray(id) ? id : [id];\n const newChildren = hierarchyNodes\n .filter(\n (h) =>\n h.parentId !== undefined && processIds.includes(h.parentId) && !processIds.includes(h.id),\n )\n .map((h) => h.id);\n return newChildren.length === 0\n ? processIds\n : getDescendentIds([...processIds, ...newChildren], hierarchyNodes);\n};\n","import { createContext, Key } from \"react\";\nimport { iNodeUpdate, TreeNodeData } from \"./interface\";\n\nexport interface TreeOfNodesContextProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n selected: Key[];\n showCheckBox: boolean;\n handleSelect?: (ret: Key | Key[]) => void;\n expandedNodes: Key[];\n handleExpandClick: (ret: Key, force?: boolean) => void;\n onAddChild?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (id: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (id: Key) => Promise<iNodeUpdate>;\n nodeHighlight: string;\n textHighlight: string;\n spellCheck?: \"true\" | \"false\";\n}\n\nexport const TreeOfNodesContext = createContext<TreeOfNodesContextProps<unknown> | undefined>(\n undefined,\n);\n","import React, { Key, useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Spinner } from \"react-bootstrap\";\n\ninterface WordEntryProps {\n id: Key;\n value?: string;\n editing?: boolean;\n saving?: boolean;\n setValue?: (ret: string) => void;\n sendEscape?: () => void;\n style?: React.CSSProperties;\n spellCheck?: \"true\" | \"false\";\n}\n\nexport const WordEntry = React.forwardRef<HTMLInputElement, WordEntryProps>(\n (\n { id, value, editing, saving, setValue, sendEscape, style, spellCheck = \"true\" },\n ref,\n ): JSX.Element => {\n WordEntry.displayName = \"WordEntry\";\n const currentStyle = useMemo<React.CSSProperties>(() => {\n return {\n display: \"inline-block\",\n padding: \"1px\",\n paddingLeft: \"3px\",\n paddingRight: \"3px\",\n border: \"1px\",\n borderRadius: \"3px\",\n ...style,\n };\n }, [style]);\n\n const [currentValue, setCurrentValue] = useState<string>(value ?? \"\");\n useEffect(() => {\n setCurrentValue(value ?? \"\");\n }, [value]);\n\n const returnData = useCallback(() => {\n setValue && setValue(currentValue);\n }, [currentValue, setValue]);\n\n const keyPress = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.code === \"Escape\") {\n setCurrentValue(value ?? \"\");\n sendEscape && sendEscape();\n } else if (e.code === \"Enter\") {\n returnData();\n }\n },\n [returnData, sendEscape, value],\n );\n\n // Simple if not editing\n if (!editing) {\n return (\n <span\n style={currentStyle}\n id={`${id}`}\n >\n {value ? value : <> </>}\n </span>\n );\n }\n\n return (\n <div\n style={currentStyle}\n id={`${id}-holder`}\n >\n {saving && (\n <Spinner\n id={`${id}-spinner`}\n size=\"sm\"\n animation=\"border\"\n />\n )}\n <input\n autoFocus\n spellCheck={spellCheck}\n id={String(id)}\n ref={ref}\n type=\"text\"\n style={{\n lineHeight: \"0.75rem\",\n border: \"1px dotted black\",\n width: \"auto\",\n minWidth: \"0\",\n }}\n value={currentValue}\n disabled={saving}\n onChange={(e) => setCurrentValue(e.currentTarget.value)}\n onBlur={returnData}\n onKeyDownCapture={keyPress}\n />\n </div>\n );\n },\n);\n","import { Key, useCallback, useEffect, useMemo, useState } from \"react\";\nimport { checkExpandedNodes } from \"../functions/checkExpandedNodes\";\nimport { iNodeUpdate, TreeNodeData } from \"./interface\";\nimport { TreeNode } from \"./TreeNode\";\nimport { TreeOfNodesContext } from \"./TreeOfNodesContext\";\n\ninterface TreeOfNodesProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n roots: Key[];\n showCheckBox?: boolean;\n selected?: Key | Key[];\n handleSelect?: (ret: Key | Key[]) => void;\n onAdd?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (childId: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (childId: Key) => Promise<iNodeUpdate>;\n canRemoveRoot?: boolean;\n canRenameRoot?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n nodeHighlight?: string;\n textHighlight?: string;\n spellCheck?: \"true\" | \"false\";\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\nexport const TreeOfNodes = <T extends unknown>({\n id,\n nodeList,\n roots,\n selected = [],\n showCheckBox = false,\n handleSelect,\n onAdd,\n onRename,\n onRemove,\n canRemoveRoot = false,\n canRenameRoot = false,\n canAddChildren = false,\n canRemoveChildren = false,\n canRenameChildren = false,\n nodeHighlight = \"red\",\n textHighlight = \"rgba(255, 0, 0, 0.2)\",\n spellCheck = \"true\",\n}: TreeOfNodesProps<T>) => {\n const [expandedNodes, setExpandedNodes] = useState<Key[]>([]);\n const selectedArray = useMemo(\n () => (Array.isArray(selected) ? selected : [selected]),\n [selected],\n );\n useEffect(() => {\n if (selectedArray.length > 0) {\n // Check all nodes are showing that should be\n const shouldExpand = checkExpandedNodes(nodeList, selectedArray, expandedNodes);\n shouldExpand.filter((n) => !expandedNodes.includes(n)).length > 0 &&\n setExpandedNodes(shouldExpand);\n }\n }, [expandedNodes, nodeList, selectedArray]);\n\n // Change expansion and update contexts\n const changeExpand = useCallback(\n (eKey: Key, force?: boolean) => {\n const newExpandedNodes = [...expandedNodes];\n const ix = newExpandedNodes.findIndex((nKey) => nKey === eKey);\n if ((ix === -1 && force === undefined) || force === true) newExpandedNodes.push(eKey);\n else newExpandedNodes.splice(ix, 1);\n setExpandedNodes(newExpandedNodes);\n },\n [expandedNodes],\n );\n\n return (\n <TreeOfNodesContext.Provider\n value={{\n id: id,\n nodeList,\n selected: selectedArray,\n showCheckBox,\n handleSelect,\n expandedNodes,\n handleExpandClick: (r, f) => changeExpand(r, f),\n onAddChild: onAdd,\n onRename,\n onRemove,\n nodeHighlight,\n textHighlight,\n spellCheck,\n }}\n >\n {roots.map((r) => (\n <TreeNode\n key={r}\n id={r}\n canRemove={canRemoveRoot}\n canAddChildren={canAddChildren}\n canRename={canRenameRoot}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n ))}\n </TreeOfNodesContext.Provider>\n );\n};\n\nTreeOfNodes.displayName = \"TreeOfNodes\";\n","import { TreeNodeBase } from \"components\";\nimport { Key } from \"react\";\nimport { getAncestors } from \"./getAncestors\";\n\nexport const checkExpandedNodes = (\n nodeList: TreeNodeBase[],\n selected: Key | Key[],\n expandedNodes: Key[],\n): Key[] => {\n return [\n ...expandedNodes,\n ...getAncestors(selected, [], nodeList)\n .map((n) => n.id)\n .filter((k) => !expandedNodes.includes(k)),\n ].sort((a, b) => `${a}`.localeCompare(`${b}`));\n};\n","import { getAncestors } from \"./getAncestors\";\n\nexport { getAncestors as getParents };\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AGGO,MAAM,4CAAe,CAC1B,IACA,UACA;IAEA,MAAM,aAAa,MAAM,OAAO,CAAC,MAAM,KAAK;QAAC;KAAG;IAEhD,MAAM,UAAU,WACb,GAAG,CAAC,CAAC,IAAM,eAAe,IAAI,CAAC,CAAC,IAAM,EAAE,EAAE,KAAK,IAC/C,MAAM,CAAC,CAAC,IAAM,MAAM;IACvB,IAAI,QAAQ,MAAM,KAAK,GAAG,OAAO;IAEjC,MAAM,UAAU,AACd,QACG,GAAG,CAAC,CAAC,IAAM,EAAE,QAAQ,EACrB,GAAG,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EACtD;QAAC;KAAS;IAEZ,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,cAAc,MAAM,GAAG,GAAG;YAC5B,6CAA6C;YAC7C,MAAM,eAAe,CAAA,GAAA,yCAAiB,EAAE,UAAU,eAAe;YACjE,IAAI,aAAa,MAAM,CAAC,CAAC,IAAM,CAAC,cAAc,QAAQ,CAAC,IAAI,MAAM,GAAG,GAClE,iBAAiB;QAErB;IACF,GAAG;QAAC;QAAe;QAAU;KAAc;IAE3C,uCAAuC;IACvC,MAAM,eAAe,CAAA,GAAA,kBAAU,EAC7B,CAAC,MAAW;QACV,MAAM,mBAAmB;eAAI;SAAc;QAC3C,MAAM,KAAK,iBAAiB,SAAS,CAAC,CAAC,OAAS,SAAS;QACzD,IAAI,AAAC,OAAO,MAAM,UAAU,aAAc,UAAU,MAAM,iBAAiB,IAAI,CAAC;aAC3E,iBAAiB,MAAM,CAAC,IAAI;QACjC,iBAAiB;IACnB,GACA;QAAC;KAAc;IAGjB,qBACE,gBAAC;QACC,IAAI;QACJ,WAAU;kBAEV,cAAA,gBAAC,CAAA,GAAA,yCAAiB,EAAE,QAAQ;YAC1B,OAAO;gBACL,IAAI;0BACJ;gBACA,UAAU;8BACV;8BACA;+BACA;gBACA,mBAAmB,CAAC,GAAG,IAAM,aAAa,GAAG;gBAC7C,YAAY;0BACZ;0BACA;+BACA;+BACA;4BACA;YACF;sBAEC,MAAM,GAAG,CAAC,CAAC,kBACV,gBAAC,CAAA,GAAA,yCAAO;oBAEN,IAAI;oBACJ,WAAW;oBACX,gBAAgB;oBAChB,WAAW;oBACX,mBAAmB;oBACnB,mBAAmB;mBANd;;;AAYjB;AAEA,0CAAY,WAAW,GAAG;;;;;;;;;;;","sources":["src/main.ts","src/components/index.ts","src/components/TreeNode.tsx","src/functions/getAncestors.tsx","src/functions/getDescendentIds.ts","src/components/TreeOfNodesContext.ts","src/components/WordEntry.tsx","src/components/TreeOfNodes.tsx","src/functions/checkExpandedNodes.ts","src/functions/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./functions\";\n","import { TreeNode } from \"./TreeNode\";\nimport { TreeOfNodes } from \"./TreeOfNodes\";\nimport { iNodeUpdate, TreeNodeBase, TreeNodeData } from \"./interface\";\nimport { WordEntry } from \"./WordEntry\";\n\nexport { TreeNode, TreeOfNodes, WordEntry };\nexport type { TreeNodeBase, TreeNodeData, iNodeUpdate };\n","import { ContextMenuHandler, MenuItem } from \"@asup/context-menu\";\nimport {\n Key,\n ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n CaretDownFill,\n CaretRight,\n CaretRightFill,\n ExclamationCircleFill,\n} from \"react-bootstrap-icons\";\nimport { getAncestors } from \"../functions/getAncestors\";\nimport { getDescendentIds } from \"../functions/getDescendentIds\";\nimport \"./TreeNode.css\";\nimport { TreeOfNodesContext } from \"./TreeOfNodesContext\";\nimport { WordEntry } from \"./WordEntry\";\nimport { iNodeUpdate } from \"./interface\";\n\ninterface TreeNodeProps {\n id: Key;\n indentLevel?: number;\n canRemove?: boolean;\n canRename?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n refresh?: () => void;\n}\n\nexport const TreeNode = ({\n id,\n canRemove,\n canRename,\n canAddChildren,\n canRemoveChildren,\n canRenameChildren,\n}: TreeNodeProps): ReactNode => {\n // Contexts\n const treeContext = useContext(TreeOfNodesContext);\n\n // Node information\n const thisNode = useMemo(\n () => treeContext?.nodeList.find((n) => n.id === id),\n [id, treeContext?.nodeList],\n );\n const childNodes = useMemo(\n () => treeContext?.nodeList.filter((n) => n.parentId === id),\n [id, treeContext?.nodeList],\n );\n const descendents = useMemo(\n () => getDescendentIds(id, treeContext?.nodeList ?? []),\n [id, treeContext],\n );\n\n // State\n const [error, setError] = useState<boolean>(false);\n const [errorText, setErrotText] = useState<string>(\"\");\n const expanded = useMemo(() => {\n return (treeContext?.expandedNodes.findIndex((e) => e === id) ?? -1) > -1;\n }, [id, treeContext?.expandedNodes]);\n\n // Checkbox\n const checkRef = useRef<HTMLInputElement | null>(null);\n useEffect(() => {\n if (checkRef.current) {\n if (treeContext?.selected.includes(id)) {\n checkRef.current.checked = true;\n checkRef.current.indeterminate = false;\n } else if (descendents.some((d) => treeContext?.selected.includes(d))) {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = true;\n } else {\n checkRef.current.checked = false;\n checkRef.current.indeterminate = false;\n }\n }\n }, [descendents, id, treeContext?.selected]);\n\n // Apply selected border\n const currentBorder = useMemo<string>(() => {\n return treeContext?.selected.includes(id) ? \"1px solid black\" : \"\";\n }, [id, treeContext?.selected]);\n const nodeColour = useMemo<string | undefined>(() => {\n if (treeContext && treeContext.selected) {\n const anc = getAncestors(treeContext.selected, [], treeContext?.nodeList).map((n) => n.id);\n if ([...anc, treeContext.selected].includes(id)) return treeContext.nodeHighlight;\n }\n return;\n }, [id, treeContext]);\n\n // New node parameters\n const newNameRef = useRef<HTMLInputElement | null>(null);\n const [showNewNode, setShowNewNode] = useState<boolean>(false);\n const [savingNewNode, setSavingNewNode] = useState<boolean>(false);\n\n // Rename parameters\n const currentNameRef = useRef<HTMLInputElement | null>(null);\n const [renaming, setRenaming] = useState<boolean>(false);\n const [updatingNode, setUpdatingNode] = useState<boolean>(false);\n\n // Context functions\n const handleReturn = useCallback((ret: iNodeUpdate) => {\n if (!ret.success) {\n setError(true);\n setErrotText(ret.ErrorText ?? \"An unknown error has occured\");\n } else {\n setError(false);\n setErrotText(\"\");\n }\n }, []);\n\n const confirmNewNode = useCallback(\n async (label: string) => {\n setSavingNewNode(true);\n if (treeContext?.onAddChild) {\n handleReturn(await treeContext.onAddChild(id, label));\n }\n setSavingNewNode(false);\n setShowNewNode(false);\n },\n [handleReturn, id, treeContext],\n );\n\n const renameNode = useCallback(\n async (newLabel: string) => {\n setRenaming(false);\n if (treeContext?.onRename) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRename(id, newLabel));\n setUpdatingNode(false);\n }\n },\n [handleReturn, id, treeContext],\n );\n\n const deleteThis = useCallback(async () => {\n if (treeContext?.onRemove) {\n setUpdatingNode(true);\n handleReturn(await treeContext.onRemove(id));\n setUpdatingNode(false);\n }\n }, [handleReturn, id, treeContext]);\n\n // Context actions\n const addChild = useCallback(() => {\n setShowNewNode(true);\n treeContext?.handleExpandClick?.(id, true);\n }, [id, treeContext]);\n useEffect(() => {\n if (showNewNode === true && newNameRef.current) newNameRef.current.focus();\n }, [showNewNode]);\n const renameThis = useCallback(() => {\n setRenaming(true);\n treeContext?.handleSelect?.(id);\n }, [id, treeContext]);\n\n // Context menu\n const menuItems = useMemo(() => {\n const menuItems: MenuItem[] = [];\n if (canAddChildren) {\n menuItems.push({ label: \"Add\", action: addChild });\n }\n if (canRename) {\n menuItems.push({ label: \"Rename\", action: renameThis });\n }\n if (canRemove && (childNodes === undefined || childNodes.length === 0)) {\n menuItems.push({ label: \"Delete\", action: deleteThis });\n }\n return menuItems;\n }, [addChild, canAddChildren, canRemove, canRename, childNodes, deleteThis, renameThis]);\n\n // Return node\n return !treeContext ? null : (\n <>\n <ContextMenuHandler\n menuItems={menuItems}\n style={{ display: \"inline-block\", width: \"100%\" }}\n >\n <div\n id={`${treeContext.id}-treenode-${id}`}\n className=\"treenode\"\n >\n {error ? (\n <>\n <ExclamationCircleFill color=\"var(--bs-danger)\" /> {errorText}\n </>\n ) : (\n <div className=\"ton-node\">\n {treeContext.showCheckBox && (\n <input\n ref={checkRef}\n type=\"checkbox\"\n role=\"checkbox\"\n className=\"ton-checkbox\"\n id={`${treeContext.id}-treenode-checkbox-${id}`}\n onClick={() => treeContext?.handleSelect?.(descendents)}\n />\n )}\n {childNodes !== undefined && childNodes.length > 0 ? (\n !expanded ? (\n <CaretRightFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n style={{ width: \"16px\", height: \"16px\" }}\n className=\"ton-expander\"\n role=\"button\"\n color={nodeColour}\n aria-expanded={false}\n aria-label=\"Expander\"\n onClick={() => treeContext.handleExpandClick(id)}\n />\n ) : (\n <CaretDownFill\n id={`${treeContext.id}-treenode-caret-${id}`}\n className=\"ton-expander\"\n role=\"button\"\n aria-expanded={true}\n aria-label=\"Expander\"\n color={nodeColour}\n onClick={() => treeContext.handleExpandClick(id)}\n />\n )\n ) : (\n <CaretRight\n id={`${treeContext.id}-treenode-caret-${id}`}\n className=\"ton-expander\"\n role=\"button\"\n color={nodeColour}\n aria-expanded={false}\n aria-label=\"Disabled expander\"\n onClick={() => treeContext.handleSelect?.(id)}\n />\n )}\n {thisNode && (\n <div\n className=\"ton-label\"\n style={{ width: `calc(100% - ${treeContext.showCheckBox ? \"32px\" : \"16px\"})` }}\n onContextMenuCapture={() => treeContext.handleSelect?.(id)}\n onClickCapture={() => treeContext.handleSelect?.(id)}\n onFocusCapture={() => treeContext.handleSelect?.(id)}\n >\n <WordEntry\n id={`${treeContext.id}-treenode-entry-${id}`}\n ref={currentNameRef}\n value={thisNode.label}\n editing={renaming}\n saving={updatingNode}\n setValue={(ret) => renameNode(ret)}\n sendEscape={() => setRenaming(false)}\n style={{\n border: currentBorder,\n margin: currentBorder === \"\" ? \"1px\" : \"\",\n backgroundColor: currentBorder === \"\" ? \"\" : treeContext.textHighlight,\n }}\n spellCheck={treeContext.spellCheck}\n />\n </div>\n )}\n </div>\n )}\n </div>\n </ContextMenuHandler>\n {showNewNode && (\n <WordEntry\n style={{ marginLeft: \"14px\" }}\n id={`treenode-new-${id}`}\n ref={newNameRef}\n editing={true}\n setValue={(ret) => confirmNewNode(ret)}\n saving={savingNewNode}\n sendEscape={() => setShowNewNode(false)}\n spellCheck={treeContext.spellCheck}\n />\n )}\n {childNodes !== undefined && (\n <div className={`ton-collapsible-wrapper ${expanded ? \"\" : \"collapsed\"}`}>\n <div className=\"ton-collapsible\">\n {childNodes.map((h) => (\n <span\n key={h.id}\n id={`${treeContext.id}-treenode-child-${h.id}`}\n className=\"ton-child\"\n >\n <TreeNode\n id={h.id}\n canRemove={canRemoveChildren}\n canRename={canRenameChildren}\n canAddChildren={canAddChildren}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n </span>\n ))}\n </div>\n </div>\n )}\n </>\n );\n};\n\nTreeNode.displayName = \"TreeNode\";\n","import { Key } from \"react\";\nimport { TreeNodeBase } from \"../components/interface\";\n\nexport const getAncestors = (\n id: Key | Key[],\n included: TreeNodeBase[],\n hierarchyNodes: TreeNodeBase[],\n): TreeNodeBase[] => {\n const processIds = Array.isArray(id) ? id : [id];\n\n const current = processIds\n .map((i) => hierarchyNodes.find((h) => h.id === i))\n .filter((h) => h !== undefined) as TreeNodeBase[];\n if (current.length === 0) return included;\n\n const parents = (\n current\n .map((h) => h.parentId)\n .map((pid) => hierarchyNodes.find((h) => pid === h.id)) as TreeNodeBase[]\n ).filter((p) => p !== undefined) as TreeNodeBase[];\n if (parents.length === 0) return included;\n else\n return getAncestors(\n parents.map((p) => p.id),\n [...included, ...parents.filter((p) => !included.includes(p))],\n hierarchyNodes,\n );\n};\n","import { Key } from \"react\";\nimport { TreeNodeBase } from \"../components/interface\";\n\nexport const getDescendentIds = (id: Key | Key[], hierarchyNodes: TreeNodeBase[]): Key[] => {\n const processIds = Array.isArray(id) ? id : [id];\n const newChildren = hierarchyNodes\n .filter(\n (h) =>\n h.parentId !== undefined && processIds.includes(h.parentId) && !processIds.includes(h.id),\n )\n .map((h) => h.id);\n return newChildren.length === 0\n ? processIds\n : getDescendentIds([...processIds, ...newChildren], hierarchyNodes);\n};\n","import { createContext, Key } from \"react\";\nimport { iNodeUpdate, TreeNodeData } from \"./interface\";\n\nexport interface TreeOfNodesContextProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n selected: Key[];\n showCheckBox: boolean;\n handleSelect?: (ret: Key | Key[]) => void;\n expandedNodes: Key[];\n handleExpandClick: (ret: Key, force?: boolean) => void;\n onAddChild?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (id: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (id: Key) => Promise<iNodeUpdate>;\n nodeHighlight: string;\n textHighlight: string;\n spellCheck?: \"true\" | \"false\";\n}\n\nexport const TreeOfNodesContext = createContext<TreeOfNodesContextProps<unknown> | undefined>(\n undefined,\n);\n","import React, { Key, useCallback, useEffect, useMemo, useState } from \"react\";\nimport { Spinner } from \"react-bootstrap\";\n\ninterface WordEntryProps {\n id: Key;\n value?: string;\n editing?: boolean;\n saving?: boolean;\n setValue?: (ret: string) => void;\n sendEscape?: () => void;\n style?: React.CSSProperties;\n spellCheck?: \"true\" | \"false\";\n}\n\nexport const WordEntry = React.forwardRef<HTMLInputElement, WordEntryProps>(\n (\n { id, value, editing, saving, setValue, sendEscape, style, spellCheck = \"true\" },\n ref,\n ): JSX.Element => {\n WordEntry.displayName = \"WordEntry\";\n const currentStyle = useMemo<React.CSSProperties>(() => {\n return {\n display: \"inline-block\",\n padding: \"1px\",\n paddingLeft: \"3px\",\n paddingRight: \"3px\",\n border: \"1px\",\n borderRadius: \"3px\",\n ...style,\n };\n }, [style]);\n\n const [currentValue, setCurrentValue] = useState<string>(value ?? \"\");\n useEffect(() => {\n setCurrentValue(value ?? \"\");\n }, [value]);\n\n const returnData = useCallback(() => {\n setValue?.(currentValue);\n }, [currentValue, setValue]);\n\n const keyPress = useCallback(\n (e: React.KeyboardEvent) => {\n if (e.code === \"Escape\") {\n setCurrentValue(value ?? \"\");\n sendEscape?.();\n } else if (e.code === \"Enter\") {\n returnData();\n }\n },\n [returnData, sendEscape, value],\n );\n\n // Simple if not editing\n if (!editing) {\n return (\n <span\n className=\"ton-label-span\"\n style={currentStyle}\n id={`${id}`}\n >\n {value ? value : <> </>}\n </span>\n );\n }\n\n return (\n <div\n style={currentStyle}\n id={`${id}-holder`}\n className=\"ton-rename-holder\"\n >\n {saving && (\n <Spinner\n id={`${id}-spinner`}\n size=\"sm\"\n animation=\"border\"\n />\n )}\n <input\n autoFocus\n spellCheck={spellCheck}\n id={String(id)}\n ref={ref}\n type=\"text\"\n className=\"ton-rename\"\n value={currentValue}\n disabled={saving}\n onChange={(e) => setCurrentValue(e.currentTarget.value)}\n onBlur={returnData}\n onKeyDownCapture={keyPress}\n />\n </div>\n );\n },\n);\n","import { Key, useCallback, useEffect, useMemo, useState } from \"react\";\nimport { checkExpandedNodes } from \"../functions/checkExpandedNodes\";\nimport { iNodeUpdate, TreeNodeData } from \"./interface\";\nimport { TreeNode } from \"./TreeNode\";\nimport { TreeOfNodesContext } from \"./TreeOfNodesContext\";\n\ninterface TreeOfNodesProps<T> {\n id: string;\n nodeList: TreeNodeData<T>[];\n roots: Key[];\n showCheckBox?: boolean;\n selected?: Key | Key[];\n handleSelect?: (ret: Key | Key[]) => void;\n onAdd?: (parentId: Key, newName: string) => Promise<iNodeUpdate>;\n onRename?: (childId: Key, newName: string) => Promise<iNodeUpdate>;\n onRemove?: (childId: Key) => Promise<iNodeUpdate>;\n canRemoveRoot?: boolean;\n canRenameRoot?: boolean;\n canAddChildren?: boolean;\n canRemoveChildren?: boolean;\n canRenameChildren?: boolean;\n nodeHighlight?: string;\n textHighlight?: string;\n spellCheck?: \"true\" | \"false\";\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint\nexport const TreeOfNodes = <T extends unknown>({\n id,\n nodeList,\n roots,\n selected = [],\n showCheckBox = false,\n handleSelect,\n onAdd,\n onRename,\n onRemove,\n canRemoveRoot = false,\n canRenameRoot = false,\n canAddChildren = false,\n canRemoveChildren = false,\n canRenameChildren = false,\n nodeHighlight = \"red\",\n textHighlight = \"rgba(255, 0, 0, 0.2)\",\n spellCheck = \"true\",\n}: TreeOfNodesProps<T>) => {\n const [expandedNodes, setExpandedNodes] = useState<Key[]>([]);\n const selectedArray = useMemo(\n () => (Array.isArray(selected) ? selected : [selected]),\n [selected],\n );\n useEffect(() => {\n if (selectedArray.length > 0) {\n // Check all nodes are showing that should be\n const shouldExpand = checkExpandedNodes(nodeList, selectedArray, expandedNodes);\n if (shouldExpand.filter((n) => !expandedNodes.includes(n)).length > 0) {\n setExpandedNodes(shouldExpand);\n }\n }\n }, [expandedNodes, nodeList, selectedArray]);\n\n // Change expansion and update contexts\n const changeExpand = useCallback(\n (eKey: Key, force?: boolean) => {\n const newExpandedNodes = [...expandedNodes];\n const ix = newExpandedNodes.findIndex((nKey) => nKey === eKey);\n if ((ix === -1 && force === undefined) || force === true) newExpandedNodes.push(eKey);\n else newExpandedNodes.splice(ix, 1);\n setExpandedNodes(newExpandedNodes);\n },\n [expandedNodes],\n );\n\n return (\n <div\n id={id}\n className=\"tree-of-nodes\"\n >\n <TreeOfNodesContext.Provider\n value={{\n id: id,\n nodeList,\n selected: selectedArray,\n showCheckBox,\n handleSelect,\n expandedNodes,\n handleExpandClick: (r, f) => changeExpand(r, f),\n onAddChild: onAdd,\n onRename,\n onRemove,\n nodeHighlight,\n textHighlight,\n spellCheck,\n }}\n >\n {roots.map((r) => (\n <TreeNode\n key={r}\n id={r}\n canRemove={canRemoveRoot}\n canAddChildren={canAddChildren}\n canRename={canRenameRoot}\n canRemoveChildren={canRemoveChildren}\n canRenameChildren={canRenameChildren}\n />\n ))}\n </TreeOfNodesContext.Provider>\n </div>\n );\n};\n\nTreeOfNodes.displayName = \"TreeOfNodes\";\n","import { TreeNodeBase } from \"components\";\nimport { Key } from \"react\";\nimport { getAncestors } from \"./getAncestors\";\n\nexport const checkExpandedNodes = (\n nodeList: TreeNodeBase[],\n selected: Key | Key[],\n expandedNodes: Key[],\n): Key[] => {\n return [\n ...expandedNodes,\n ...getAncestors(selected, [], nodeList)\n .map((n) => n.id)\n .filter((k) => !expandedNodes.includes(k)),\n ].sort((a, b) => `${a}`.localeCompare(`${b}`));\n};\n","import { getAncestors } from \"./getAncestors\";\n\nexport { getAncestors as getParents };\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/tree-of-nodes.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React, { Key } from "react";
|
|
1
|
+
import React, { Key, ReactNode } from "react";
|
|
2
|
+
import { JSX } from "react/jsx-runtime";
|
|
2
3
|
export interface iNodeUpdate {
|
|
3
4
|
success: boolean;
|
|
4
5
|
ErrorText?: string;
|
|
@@ -34,7 +35,7 @@ interface TreeNodeProps {
|
|
|
34
35
|
refresh?: () => void;
|
|
35
36
|
}
|
|
36
37
|
export const TreeNode: {
|
|
37
|
-
({ id, canRemove, canRename, canAddChildren, canRemoveChildren, canRenameChildren, }: TreeNodeProps):
|
|
38
|
+
({ id, canRemove, canRename, canAddChildren, canRemoveChildren, canRenameChildren, }: TreeNodeProps): ReactNode;
|
|
38
39
|
displayName: string;
|
|
39
40
|
};
|
|
40
41
|
interface TreeOfNodesProps<T> {
|
|
@@ -57,7 +58,7 @@ interface TreeOfNodesProps<T> {
|
|
|
57
58
|
spellCheck?: "true" | "false";
|
|
58
59
|
}
|
|
59
60
|
export const TreeOfNodes: {
|
|
60
|
-
<T extends unknown>({ id, nodeList, roots, selected, showCheckBox, handleSelect, onAdd, onRename, onRemove, canRemoveRoot, canRenameRoot, canAddChildren, canRemoveChildren, canRenameChildren, nodeHighlight, textHighlight, spellCheck, }: TreeOfNodesProps<T>):
|
|
61
|
+
<T extends unknown>({ id, nodeList, roots, selected, showCheckBox, handleSelect, onAdd, onRename, onRemove, canRemoveRoot, canRenameRoot, canAddChildren, canRemoveChildren, canRenameChildren, nodeHighlight, textHighlight, spellCheck, }: TreeOfNodesProps<T>): JSX.Element;
|
|
61
62
|
displayName: string;
|
|
62
63
|
};
|
|
63
64
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;AAEA;IACE,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;IACE,EAAE,EAAE,GAAG,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,8BAA8B,CAAC,CAAE,SAAQ,YAAY;IACn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K,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACjE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IACnE,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B;AAGD,OAAO,MAAM;KAAe,CAAC,SAAS,OAAO,2NAkB1C,iBAAiB,CAAC,CAAC;;CAgErB,CAAC","sources":["src/src/components/interface.ts","src/src/functions/getAncestors.tsx","src/src/functions/getDescendentIds.ts","src/src/components/TreeOfNodesContext.ts","src/src/components/WordEntry.tsx","src/src/components/TreeNode.tsx","src/src/functions/checkExpandedNodes.ts","src/src/components/TreeOfNodes.tsx","src/src/components/index.ts","src/src/functions/index.ts","src/src/main.ts","src/main.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,"export * from \"./components\";\nexport * from \"./functions\";\n"],"names":[],"version":3,"file":"tree-of-nodes.d.ts.map"}
|