@asup/tree-of-nodes 1.0.4 → 1.0.6

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/main.js CHANGED
@@ -1,118 +1,37 @@
1
- import "./main.css";
2
- import {jsx as $duWW8$jsx, jsxs as $duWW8$jsxs, Fragment as $duWW8$Fragment} from "react/jsx-runtime";
3
- import $duWW8$react, {useRef as $duWW8$useRef, useState as $duWW8$useState, useCallback as $duWW8$useCallback, useEffect as $duWW8$useEffect, useContext as $duWW8$useContext, useMemo as $duWW8$useMemo, createContext as $duWW8$createContext} from "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
18
 
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
- });
19
+ const $6303f0814ed0ce8b$export$c6fd3ab3f44300d0 = (id, included, hierarchyNodes)=>{
20
+ // Get current node
21
+ const current = hierarchyNodes.find((h)=>h.id === id);
22
+ if (current === undefined) return [];
23
+ // Get parent node
24
+ const parent = hierarchyNodes.find((h)=>h.id === current.parentId);
25
+ // Stop if no more parents
26
+ return parent === undefined ? included : $6303f0814ed0ce8b$export$c6fd3ab3f44300d0(parent.id, [
27
+ ...included.filter((i)=>i.id !== parent.id),
28
+ parent
29
+ ], hierarchyNodes);
103
30
  };
104
31
 
105
32
 
106
33
 
107
-
108
-
109
-
110
-
111
-
112
- const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)({
113
- id: "tree-of-nodes",
114
- nodeList: []
115
- });
34
+ const $886f402bccb0fd30$export$29ec378200e05207 = (0, $duWW8$createContext)(undefined);
116
35
 
117
36
 
118
37
 
@@ -171,6 +90,7 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
171
90
  animation: "border"
172
91
  }),
173
92
  /*#__PURE__*/ (0, $duWW8$jsx)("input", {
93
+ autoFocus: true,
174
94
  id: String(id),
175
95
  ref: ref,
176
96
  type: "text",
@@ -194,37 +114,48 @@ const $84765747a8c6bfe2$export$14f190ac910bde69 = /*#__PURE__*/ (0, $duWW8$react
194
114
  const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemove , canRename: canRename , canAddChildren: canAddChildren , canRemoveChildren: canRemoveChildren , canRenameChildren: canRenameChildren })=>{
195
115
  // Contexts
196
116
  const treeContext = (0, $duWW8$useContext)((0, $886f402bccb0fd30$export$29ec378200e05207));
197
- const menuContext = (0, $duWW8$useContext)((0, $9c3c2ad4d66e1cfe$export$c7e742effb1c51e2));
198
117
  // Node information
199
- const thisNode = (0, $duWW8$useMemo)(()=>treeContext.nodeList.find((n)=>n.id === id), [
118
+ const thisNode = (0, $duWW8$useMemo)(()=>{
119
+ return treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.find((n)=>n.id === id);
120
+ }, [
200
121
  id,
201
- treeContext.nodeList
122
+ treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
202
123
  ]);
203
- const childNodes = (0, $duWW8$useMemo)(()=>treeContext.nodeList.filter((n)=>n.parentId === id), [
124
+ const childNodes = (0, $duWW8$useMemo)(()=>{
125
+ return treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.filter((n)=>n.parentId === id);
126
+ }, [
204
127
  id,
205
- treeContext.nodeList
128
+ treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
206
129
  ]);
207
130
  // State
208
- const loading = (0, $duWW8$useMemo)(()=>treeContext.nodeList.findIndex((n)=>n.id === id) === -1, [
209
- id,
210
- treeContext.nodeList
211
- ]);
212
131
  const [error, setError] = (0, $duWW8$useState)(false);
213
132
  const [errorText, setErrotText] = (0, $duWW8$useState)(null);
214
133
  const expanded = (0, $duWW8$useMemo)(()=>{
215
- var _treeContext_expandedNodes;
216
134
  var _treeContext_expandedNodes_findIndex;
217
- return ((_treeContext_expandedNodes_findIndex = (_treeContext_expandedNodes = treeContext.expandedNodes) === null || _treeContext_expandedNodes === void 0 ? void 0 : _treeContext_expandedNodes.findIndex((e)=>e === id)) !== null && _treeContext_expandedNodes_findIndex !== void 0 ? _treeContext_expandedNodes_findIndex : -1) > -1;
135
+ 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
136
  }, [
219
137
  id,
220
- treeContext.expandedNodes
138
+ treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes
221
139
  ]);
222
140
  // // Apply selected borer
223
141
  const currentBorder = (0, $duWW8$useMemo)(()=>{
224
- return id === treeContext.selectedId ? "1px solid black" : "";
142
+ return id === (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selectedId) ? "1px solid black" : "";
143
+ }, [
144
+ id,
145
+ treeContext === null || treeContext === void 0 ? void 0 : treeContext.selectedId
146
+ ]);
147
+ const nodeColour = (0, $duWW8$useMemo)(()=>{
148
+ if (treeContext && treeContext.selectedId) {
149
+ const anc = (0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(treeContext.selectedId, [], treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList).map((n)=>n.id);
150
+ if ([
151
+ ...anc,
152
+ treeContext.selectedId
153
+ ].includes(id)) return treeContext.nodeHighlight;
154
+ }
155
+ return;
225
156
  }, [
226
157
  id,
227
- treeContext.selectedId
158
+ treeContext
228
159
  ]);
229
160
  // New node parameters
230
161
  const newNameRef = (0, $duWW8$useRef)(null);
@@ -247,7 +178,7 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
247
178
  }, []);
248
179
  const confirmNewNode = (0, $duWW8$useCallback)(async (label)=>{
249
180
  setSavingNewNode(true);
250
- if (treeContext.onAddChild) handleReturn(await treeContext.onAddChild(id, label));
181
+ if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onAddChild) handleReturn(await treeContext.onAddChild(id, label));
251
182
  setSavingNewNode(false);
252
183
  setShowNewNode(false);
253
184
  }, [
@@ -257,18 +188,22 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
257
188
  ]);
258
189
  const renameNode = (0, $duWW8$useCallback)(async (newLabel)=>{
259
190
  setRenaming(false);
260
- setUpdatingNode(true);
261
- if (treeContext.onRename) handleReturn(await treeContext.onRename(id, newLabel));
262
- setUpdatingNode(false);
191
+ if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRename) {
192
+ setUpdatingNode(true);
193
+ handleReturn(await treeContext.onRename(id, newLabel));
194
+ setUpdatingNode(false);
195
+ }
263
196
  }, [
264
197
  handleReturn,
265
198
  id,
266
199
  treeContext
267
200
  ]);
268
201
  const deleteThis = (0, $duWW8$useCallback)(async ()=>{
269
- setUpdatingNode(true);
270
- if (treeContext.onRemove) handleReturn(await treeContext.onRemove(id));
271
- setUpdatingNode(false);
202
+ if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRemove) {
203
+ setUpdatingNode(true);
204
+ handleReturn(await treeContext.onRemove(id));
205
+ setUpdatingNode(false);
206
+ }
272
207
  }, [
273
208
  handleReturn,
274
209
  id,
@@ -276,16 +211,10 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
276
211
  ]);
277
212
  // Context actions
278
213
  const addChild = (0, $duWW8$useCallback)(()=>{
279
- if (menuContext.set) {
280
- menuContext.set({
281
- visible: false
282
- });
283
- setShowNewNode(true);
284
- treeContext.handleExpandClick && treeContext.handleExpandClick(id, true);
285
- }
214
+ setShowNewNode(true);
215
+ treeContext && treeContext.handleExpandClick(id, true);
286
216
  }, [
287
217
  id,
288
- menuContext,
289
218
  treeContext
290
219
  ]);
291
220
  (0, $duWW8$useEffect)(()=>{
@@ -294,35 +223,14 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
294
223
  showNewNode
295
224
  ]);
296
225
  const renameThis = (0, $duWW8$useCallback)(()=>{
297
- if (menuContext.set) {
298
- menuContext.set({
299
- visible: false
300
- });
301
- setRenaming(true);
302
- }
226
+ setRenaming(true);
227
+ treeContext === null || treeContext === void 0 ? void 0 : treeContext.handleSelect(id);
303
228
  }, [
304
- menuContext
305
- ]);
306
- (0, $duWW8$useEffect)(()=>{
307
- if (renaming === true && currentNameRef.current) currentNameRef.current.focus();
308
- }, [
309
- renaming
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
229
+ id,
230
+ treeContext
321
231
  ]);
322
232
  // Context menu
323
- const showMenu = (0, $duWW8$useCallback)((e)=>{
324
- e.preventDefault();
325
- e.stopPropagation();
233
+ const menuItems = (0, $duWW8$useMemo)(()=>{
326
234
  const menuItems = [];
327
235
  if (canAddChildren) menuItems.push({
328
236
  label: "Add",
@@ -334,167 +242,155 @@ const $47c36cf4281201f5$export$2eba8ec3a333fdbb = ({ id: id , canRemove: canRemo
334
242
  });
335
243
  if (canRemove && (childNodes === undefined || childNodes.length === 0)) menuItems.push({
336
244
  label: "Delete",
337
- action: removeThis
338
- });
339
- if (typeof menuContext.set === "function") menuContext.set({
340
- visible: true,
341
- y: e.pageY,
342
- x: e.pageX,
343
- menuItems: menuItems
245
+ action: deleteThis
344
246
  });
247
+ return menuItems;
345
248
  }, [
346
249
  addChild,
347
250
  canAddChildren,
348
251
  canRemove,
349
252
  canRename,
350
253
  childNodes,
351
- menuContext,
352
- removeThis,
254
+ deleteThis,
353
255
  renameThis
354
256
  ]);
355
257
  // Return node
356
- return /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
357
- id: `${treeContext.id}-treenode-${id}`,
358
- className: "treenode",
359
- onClickCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
360
- onContextMenuCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
361
- onFocusCapture: ()=>treeContext.handleSelect && treeContext.handleSelect(id),
362
- children: [
363
- error ? /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
364
- children: [
365
- /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ExclamationCircleFill), {
366
- color: "var(--bs-danger)"
367
- }),
368
- " ",
369
- errorText && errorText !== "" ? errorText : "An unknown error has occured"
370
- ]
371
- }) : loading ? /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
372
- children: [
373
- /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Spinner), {
374
- size: "sm",
375
- animation: "border"
376
- }),
377
- " ",
378
- "Loading..."
379
- ]
380
- }) : /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
381
- onContextMenu: showMenu,
382
- children: [
383
- childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRightFill), {
384
- role: "button",
385
- "aria-expanded": false,
386
- id: `${treeContext.id}-treenode-caret-${id}`,
387
- onClick: ()=>treeContext.handleExpandClick && treeContext.handleExpandClick(id)
388
- }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
389
- role: "button",
390
- "aria-expanded": true,
391
- id: `${treeContext.id}-treenode-caret-${id}`,
392
- onClick: ()=>treeContext.handleExpandClick && treeContext.handleExpandClick(id)
393
- }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
394
- role: "button",
395
- "aria-expanded": false,
396
- "aria-disabled": true
397
- }),
398
- thisNode && /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
399
- id: `${treeContext.id}-treenode-entry-${id}`,
400
- ref: currentNameRef,
401
- value: thisNode.label,
402
- editing: renaming,
403
- saving: updatingNode,
404
- setValue: (ret)=>renameNode(ret),
405
- sendEscape: ()=>setRenaming(false),
258
+ if (!treeContext) return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$Fragment), {});
259
+ return /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ContextMenuHandler), {
260
+ menuItems: menuItems,
261
+ children: /*#__PURE__*/ (0, $duWW8$jsxs)("div", {
262
+ id: `${treeContext.id}-treenode-${id}`,
263
+ className: "treenode",
264
+ children: [
265
+ error ? /*#__PURE__*/ (0, $duWW8$jsxs)((0, $duWW8$Fragment), {
266
+ children: [
267
+ /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$ExclamationCircleFill), {
268
+ color: "var(--bs-danger)"
269
+ }),
270
+ " ",
271
+ errorText && errorText !== "" ? errorText : "An unknown error has occured"
272
+ ]
273
+ }) : /*#__PURE__*/ (0, $duWW8$jsxs)("span", {
274
+ children: [
275
+ childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRightFill), {
276
+ id: `${treeContext.id}-treenode-caret-${id}`,
277
+ role: "button",
278
+ color: nodeColour,
279
+ "aria-expanded": false,
280
+ onClick: ()=>treeContext.handleExpandClick(id)
281
+ }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretDownFill), {
282
+ id: `${treeContext.id}-treenode-caret-${id}`,
283
+ role: "button",
284
+ "aria-expanded": true,
285
+ color: nodeColour,
286
+ onClick: ()=>{
287
+ treeContext.handleExpandClick(id);
288
+ }
289
+ }) : /*#__PURE__*/ (0, $duWW8$jsx)((0, $duWW8$CaretRight), {
290
+ id: `${treeContext.id}-treenode-caret-${id}`,
291
+ role: "button",
292
+ color: nodeColour,
293
+ "aria-expanded": false,
294
+ "aria-disabled": true
295
+ }),
296
+ thisNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
297
+ style: {
298
+ display: "inline-block"
299
+ },
300
+ onContextMenuCapture: ()=>treeContext.handleSelect(id),
301
+ onClickCapture: ()=>treeContext.handleSelect(id),
302
+ onFocusCapture: ()=>treeContext.handleSelect(id),
303
+ children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
304
+ id: `${treeContext.id}-treenode-entry-${id}`,
305
+ ref: currentNameRef,
306
+ value: thisNode.label,
307
+ editing: renaming,
308
+ saving: updatingNode,
309
+ setValue: (ret)=>renameNode(ret),
310
+ sendEscape: ()=>setRenaming(false),
311
+ style: {
312
+ border: currentBorder,
313
+ margin: currentBorder === "" ? "1px" : "",
314
+ backgroundColor: currentBorder === "" ? "" : treeContext.textHighlight
315
+ }
316
+ })
317
+ })
318
+ ]
319
+ }),
320
+ childNodes !== undefined && childNodes.map((h)=>/*#__PURE__*/ (0, $duWW8$jsx)("span", {
321
+ id: `${treeContext.id}-treenode-child-${h.id}`,
322
+ style: {
323
+ marginLeft: "16px",
324
+ display: "block",
325
+ maxHeight: expanded ? "99999px" : "0px",
326
+ height: expanded ? "auto" : "0px",
327
+ overflowY: "hidden",
328
+ visibility: expanded ? "inherit" : "hidden",
329
+ opacity: expanded ? 1 : 0,
330
+ transition: "visibility .3s, opacity .3s ease-in-out, max-height 0.3s ease-in-out"
331
+ },
332
+ children: /*#__PURE__*/ (0, $duWW8$jsx)($47c36cf4281201f5$export$2eba8ec3a333fdbb, {
333
+ id: h.id,
334
+ canRemove: canRemoveChildren,
335
+ canRename: canRenameChildren,
336
+ canAddChildren: canAddChildren,
337
+ canRemoveChildren: canRemoveChildren,
338
+ canRenameChildren: canRenameChildren
339
+ })
340
+ }, h.id)),
341
+ showNewNode && /*#__PURE__*/ (0, $duWW8$jsx)("div", {
342
+ children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $84765747a8c6bfe2$export$14f190ac910bde69), {
406
343
  style: {
407
- border: currentBorder,
408
- margin: currentBorder === "" ? "1px" : "",
409
- backgroundColor: currentBorder === "" ? "" : "lightgrey"
344
+ marginLeft: "14px"
345
+ },
346
+ id: `treenode-new-${id}`,
347
+ ref: newNameRef,
348
+ editing: true,
349
+ setValue: (ret)=>{
350
+ confirmNewNode(ret);
351
+ },
352
+ saving: savingNewNode,
353
+ sendEscape: ()=>{
354
+ setShowNewNode(false);
410
355
  }
411
356
  })
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
357
  })
451
- })
452
- ]
358
+ ]
359
+ })
453
360
  });
454
361
  };
455
362
 
456
363
 
457
364
 
458
365
 
459
- const $03b5c1380eb9c122$export$85488b7eb1e4976f = (id, included, hierarchyNodes)=>{
460
- // Get current node
461
- const current = hierarchyNodes.find((h)=>h.id === id);
462
- if (current === undefined) return [];
463
- // Set return as children, current node or parent's return
464
- const ret = current.parentId === undefined || current.parentId === null || hierarchyNodes.findIndex((h)=>{
465
- return h.id === (current === null || current === void 0 ? void 0 : current.parentId);
466
- }) === -1 ? [
467
- ...included,
468
- current
469
- ] : $03b5c1380eb9c122$export$85488b7eb1e4976f(current.parentId, [
470
- ...included.filter((c)=>c.id !== current.parentId && c.id !== current.id),
471
- current
472
- ], hierarchyNodes);
473
- return ret;
474
- };
475
-
476
366
 
477
367
  const $c7008d808d3e1c7a$export$40c47a7ac5f85aba = (nodeList, selectedId, expandedNodes)=>{
478
- const k = [
368
+ return [
479
369
  ...expandedNodes,
480
- ...(0, $03b5c1380eb9c122$export$85488b7eb1e4976f)(selectedId, [], nodeList).map((n)=>n.id).filter((k)=>!expandedNodes.includes(k))
370
+ ...(0, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0)(selectedId, [], nodeList).map((n)=>n.id).filter((k)=>!expandedNodes.includes(k))
481
371
  ].sort((a, b)=>`${a}`.localeCompare(`${b}`));
482
- return k;
483
372
  };
484
373
 
485
374
 
486
375
 
487
376
 
488
-
489
377
  const $ba47aaf387735a90$export$5580fff3e08a8be5 = ({ id: id , nodeList: nodeList , roots: roots , canRemoveRoot: // canAddRoot = false,
490
378
  canRemoveRoot = false , canRenameRoot: canRenameRoot = false , canAddChildren: canAddChildren = false , canRemoveChildren: canRemoveChildren = false , canRenameChildren: canRenameChildren = false , selectedId: selectedId , handleSelect: handleSelect = ()=>{
491
379
  return;
492
- } , onAdd: onAdd , onRename: onRename , onRemove: onRemove })=>{
380
+ } , onAdd: onAdd , onRename: onRename , onRemove: onRemove , nodeHighlight: nodeHighlight = "red" , textHighlight: textHighlight = "rgba(255, 0, 0, 0.2)" })=>{
493
381
  const [expandedNodes, setExpandedNodes] = (0, $duWW8$useState)([]);
494
382
  (0, $duWW8$useEffect)(()=>{
495
- selectedId !== undefined && setExpandedNodes((0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList, selectedId, expandedNodes));
496
- }, []);
497
- // Change expansion and update context
383
+ if (selectedId) {
384
+ // Check all nodes are showing that should be
385
+ const shouldExpand = (0, $c7008d808d3e1c7a$export$40c47a7ac5f85aba)(nodeList, selectedId, expandedNodes);
386
+ shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0 && setExpandedNodes(shouldExpand);
387
+ }
388
+ }, [
389
+ expandedNodes,
390
+ nodeList,
391
+ selectedId
392
+ ]);
393
+ // Change expansion and update contexts
498
394
  const changeExpand = (0, $duWW8$useCallback)((eKey, force)=>{
499
395
  const newExpandedNodes = [
500
396
  ...expandedNodes
@@ -506,28 +402,28 @@ canRemoveRoot = false , canRenameRoot: canRenameRoot = false , canAddChildren: c
506
402
  }, [
507
403
  expandedNodes
508
404
  ]);
509
- return /*#__PURE__*/ (0, $duWW8$jsx)((0, $9c3c2ad4d66e1cfe$export$434a17f82a8154e4), {
510
- children: /*#__PURE__*/ (0, $duWW8$jsx)((0, $886f402bccb0fd30$export$29ec378200e05207).Provider, {
511
- value: {
512
- id: id,
513
- nodeList: nodeList,
514
- selectedId: selectedId,
515
- handleSelect: handleSelect,
516
- expandedNodes: expandedNodes,
517
- handleExpandClick: (r, f)=>changeExpand(r, f),
518
- onAddChild: onAdd,
519
- onRename: onRename,
520
- onRemove: onRemove
521
- },
522
- children: roots.map((r)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $47c36cf4281201f5$export$2eba8ec3a333fdbb), {
523
- id: r,
524
- canRemove: canRemoveRoot,
525
- canAddChildren: canAddChildren,
526
- canRename: canRenameRoot,
527
- canRemoveChildren: canRemoveChildren,
528
- canRenameChildren: canRenameChildren
529
- }, r))
530
- })
405
+ return /*#__PURE__*/ (0, $duWW8$jsx)((0, $886f402bccb0fd30$export$29ec378200e05207).Provider, {
406
+ value: {
407
+ id: id,
408
+ nodeList: nodeList,
409
+ selectedId: selectedId,
410
+ handleSelect: handleSelect,
411
+ expandedNodes: expandedNodes,
412
+ handleExpandClick: (r, f)=>changeExpand(r, f),
413
+ onAddChild: onAdd,
414
+ onRename: onRename,
415
+ onRemove: onRemove,
416
+ nodeHighlight: nodeHighlight,
417
+ textHighlight: textHighlight
418
+ },
419
+ children: roots.map((r)=>/*#__PURE__*/ (0, $duWW8$jsx)((0, $47c36cf4281201f5$export$2eba8ec3a333fdbb), {
420
+ id: r,
421
+ canRemove: canRemoveRoot,
422
+ canAddChildren: canAddChildren,
423
+ canRename: canRenameRoot,
424
+ canRemoveChildren: canRemoveChildren,
425
+ canRenameChildren: canRenameChildren
426
+ }, r))
531
427
  });
532
428
  };
533
429
 
@@ -537,11 +433,11 @@ canRemoveRoot = false , canRenameRoot: canRenameRoot = false , canAddChildren: c
537
433
 
538
434
  var $3d005c8713d7dfb7$exports = {};
539
435
 
540
- $parcel$export($3d005c8713d7dfb7$exports, "getParents", function () { return $03b5c1380eb9c122$export$85488b7eb1e4976f; });
436
+ $parcel$export($3d005c8713d7dfb7$exports, "getParents", function () { return $6303f0814ed0ce8b$export$c6fd3ab3f44300d0; });
541
437
 
542
438
 
543
439
 
544
440
 
545
441
 
546
- export {$567ed433af94513f$export$8dc6765e8be191c7 as ContextMenu, $9c3c2ad4d66e1cfe$export$434a17f82a8154e4 as ContextMenuProvider, $47c36cf4281201f5$export$2eba8ec3a333fdbb as TreeNode, $ba47aaf387735a90$export$5580fff3e08a8be5 as TreeOfNodes, $84765747a8c6bfe2$export$14f190ac910bde69 as WordEntry, $03b5c1380eb9c122$export$85488b7eb1e4976f as getParents};
442
+ export {$47c36cf4281201f5$export$2eba8ec3a333fdbb as TreeNode, $ba47aaf387735a90$export$5580fff3e08a8be5 as TreeOfNodes, $84765747a8c6bfe2$export$14f190ac910bde69 as WordEntry, $6303f0814ed0ce8b$export$c6fd3ab3f44300d0 as getAncestors};
547
443
  //# sourceMappingURL=main.js.map