@asup/tree-of-nodes 2.0.5 → 3.0.0

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 CHANGED
@@ -1,3 +1,16 @@
1
+ :root {
2
+ --ton-transition-time: .3s;
3
+ --ton-long-transition-time: .6s;
4
+ }
5
+
6
+ .tree-of-nodes {
7
+ flex-direction: column;
8
+ gap: 1px;
9
+ width: 100%;
10
+ max-width: 100%;
11
+ display: flex;
12
+ }
13
+
1
14
  .ton-checkbox {
2
15
  margin-top: 3px;
3
16
  margin-right: 3px;
@@ -12,18 +25,26 @@
12
25
  align-items: center;
13
26
  width: 100%;
14
27
  max-width: 100%;
15
- height: 34px;
28
+ height: 30px;
16
29
  display: flex;
17
30
  }
18
31
 
19
32
  .ton-label {
20
- height: 34px;
33
+ height: 26px;
21
34
  }
22
35
 
23
36
  .ton-label-span {
37
+ box-sizing: border-box;
38
+ font-family: inherit;
39
+ font-size: inherit;
40
+ font-weight: inherit;
24
41
  text-overflow: ellipsis;
25
42
  white-space: nowrap;
43
+ border: 1px solid #0000;
44
+ border-radius: 3px;
26
45
  width: 100%;
46
+ padding: 1px 3px;
47
+ line-height: 24px;
27
48
  display: inline-block;
28
49
  overflow: hidden;
29
50
  }
@@ -33,16 +54,27 @@
33
54
  }
34
55
 
35
56
  .ton-rename {
57
+ box-sizing: border-box;
58
+ font-family: inherit;
59
+ font-size: inherit;
60
+ font-weight: inherit;
36
61
  border: 1px dotted #000;
62
+ border-radius: 3px;
37
63
  width: 100%;
38
64
  min-width: 0;
39
- line-height: .75rem;
65
+ padding: 1px 3px;
66
+ line-height: 24px;
67
+ }
68
+
69
+ .ton-rename:focus {
70
+ box-shadow: none;
71
+ outline: none;
40
72
  }
41
73
 
42
74
  .ton-child {
43
75
  opacity: 1;
76
+ transition: opacity var(--ton-long-transition-time) linear;
44
77
  margin-left: 16px;
45
- transition: opacity .6s linear;
46
78
  display: block;
47
79
  }
48
80
 
@@ -55,29 +87,33 @@
55
87
 
56
88
  .ton-collapsible-wrapper:after {
57
89
  content: "";
58
- height: 20px;
90
+ height: 1px;
91
+ transition: height var(--ton-transition-time) linear, max-height 0s var(--ton-transition-time) linear;
59
92
  max-height: 0;
60
- transition: height .3s linear, max-height 0s linear .3s;
61
93
  }
62
94
 
63
95
  .ton-collapsible {
96
+ transition: margin-bottom var(--ton-transition-time) cubic-bezier(0, 0, 0, 1);
97
+ flex-direction: column;
98
+ gap: 1px;
64
99
  width: 100%;
65
100
  max-height: 10000px;
66
- margin-bottom: 0;
67
- transition: margin-bottom .3s cubic-bezier(0, 0, 0, 1);
101
+ margin-top: 1px;
102
+ margin-bottom: 1px;
103
+ display: flex;
68
104
  }
69
105
 
70
106
  .ton-collapsible-wrapper.collapsed > .ton-collapsible {
107
+ transition: margin-bottom var(--ton-transition-time) cubic-bezier(1, 0, 1, 1), visibility 0s var(--ton-transition-time), max-height 0s var(--ton-transition-time);
71
108
  visibility: hidden;
72
109
  max-height: 0;
73
110
  margin-bottom: -2000px;
74
- transition: margin-bottom .3s cubic-bezier(1, 0, 1, 1), visibility 0s .3s, max-height 0s .3s;
75
111
  }
76
112
 
77
113
  .ton-collapsible-wrapper.collapsed:after {
78
114
  height: 0;
115
+ transition: height var(--ton-transition-time) linear;
79
116
  max-height: 20px;
80
- transition: height .3s linear;
81
117
  }
82
118
 
83
119
  .ton-collapsible-wrapper.collapsed {
@@ -86,6 +122,6 @@
86
122
 
87
123
  .ton-collapsible-wrapper.collapsed .ton-child {
88
124
  opacity: 0;
89
- transition: opacity .6s linear;
125
+ transition: opacity var(--ton-long-transition-time) linear;
90
126
  }
91
127
  /*# sourceMappingURL=main.css.map */
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;AAKA;;;;AAIA;;;;;;;;;AASA;;;;AAIA;;;;;;;;AAQA;;;;AAIA;;;;;;;AAOA;;;;;;;AAOA;;;;;;;AAMA;;;;;;;AAQA;;;;;;;AAMA;;;;;;;AASA;;;;;;AAKA;;;;AAGA","sources":["src/components/TreeNode.css"],"sourcesContent":[".ton-checkbox {\n margin-right: 3px;\n margin-top: 3px;\n}\n\n.ton-expander {\n margin: 0;\n}\n\n.ton-node {\n display: flex;\n align-items: center;\n cursor: pointer;\n width: 100%;\n max-width: 100%;\n height: 34px;\n}\n\n.ton-label {\n height: 34px;\n}\n\n.ton-label-span {\n display: inline-block;\n width: 100%;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.ton-rename-holder {\n width: 100%;\n}\n\n.ton-rename {\n line-height: 0.75rem;\n border: 1px dotted black;\n width: 100%;\n min-width: 0;\n}\n\n.ton-child {\n margin-left: 16px;\n display: block;\n opacity: 1;\n transition: opacity 0.6s linear;\n}\n\n.ton-collapsible-wrapper {\n display: flex;\n overflow: hidden;\n width: 100%;\n max-width: 100%;\n}\n.ton-collapsible-wrapper:after {\n content: \"\";\n height: 20px;\n transition:\n height 0.3s linear,\n max-height 0s 0.3s linear;\n max-height: 0px;\n}\n.ton-collapsible {\n transition: margin-bottom 0.3s cubic-bezier(0, 0, 0, 1);\n margin-bottom: 0;\n max-height: 10000px;\n width: 100%;\n}\n.ton-collapsible-wrapper.collapsed > .ton-collapsible {\n margin-bottom: -2000px;\n transition:\n margin-bottom 0.3s cubic-bezier(1, 0, 1, 1),\n visibility 0s 0.3s,\n max-height 0s 0.3s;\n visibility: hidden;\n max-height: 0;\n}\n.ton-collapsible-wrapper.collapsed:after {\n height: 0;\n transition: height 0.3s linear;\n max-height: 20px;\n}\n.ton-collapsible-wrapper.collapsed {\n visibility: hidden;\n}\n.ton-collapsible-wrapper.collapsed .ton-child {\n opacity: 0;\n transition: opacity 0.6s linear;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
1
+ {"mappings":"AAAA;;;;;AAKA;;;;;;;;AAQA;;;;;AAKA;;;;AAIA;;;;;;;;;AASA;;;;AAIA;;;;;;;;;;;;;;;;AAgBA;;;;AAIA;;;;;;;;;;;;;AAaA;;;;;AAKA;;;;;;;AAOA;;;;;;;AAMA;;;;;;;AAQA;;;;;;;;;;;AAUA;;;;;;;AASA;;;;;;AAKA;;;;AAGA","sources":["src/components/TreeNode.css"],"sourcesContent":[":root {\n --ton-transition-time: 0.3s;\n --ton-long-transition-time: 0.6s;\n}\n\n.tree-of-nodes {\n display: flex;\n flex-direction: column;\n width: 100%;\n max-width: 100%;\n gap: 1px;\n}\n\n.ton-checkbox {\n margin-right: 3px;\n margin-top: 3px;\n}\n\n.ton-expander {\n margin: 0;\n}\n\n.ton-node {\n display: flex;\n align-items: center;\n cursor: pointer;\n width: 100%;\n max-width: 100%;\n height: 30px;\n}\n\n.ton-label {\n height: 26px;\n}\n\n.ton-label-span {\n border-radius: 3px;\n border: 1px solid transparent;\n box-sizing: border-box;\n display: inline-block;\n font-family: inherit;\n font-size: inherit;\n font-weight: inherit;\n line-height: 24px;\n overflow: hidden;\n padding: 1px 3px;\n text-overflow: ellipsis;\n white-space: nowrap;\n width: 100%;\n}\n\n.ton-rename-holder {\n width: 100%;\n}\n\n.ton-rename {\n border-radius: 3px;\n border: 1px dotted black;\n box-sizing: border-box;\n font-family: inherit;\n font-size: inherit;\n font-weight: inherit;\n line-height: 24px;\n min-width: 0;\n padding: 1px 3px;\n width: 100%;\n}\n\n.ton-rename:focus {\n outline: none;\n box-shadow: none;\n}\n\n.ton-child {\n margin-left: 16px;\n display: block;\n opacity: 1;\n transition: opacity var(--ton-long-transition-time) linear;\n}\n\n.ton-collapsible-wrapper {\n display: flex;\n overflow: hidden;\n width: 100%;\n max-width: 100%;\n}\n.ton-collapsible-wrapper:after {\n content: \"\";\n height: 1px;\n transition:\n height var(--ton-transition-time) linear,\n max-height 0s var(--ton-transition-time) linear;\n max-height: 0px;\n}\n.ton-collapsible {\n display: flex;\n flex-direction: column;\n gap: 1px;\n transition: margin-bottom var(--ton-transition-time) cubic-bezier(0, 0, 0, 1);\n margin-top: 1px;\n margin-bottom: 1px;\n max-height: 10000px;\n width: 100%;\n}\n.ton-collapsible-wrapper.collapsed > .ton-collapsible {\n margin-bottom: -2000px;\n transition:\n margin-bottom var(--ton-transition-time) cubic-bezier(1, 0, 1, 1),\n visibility 0s var(--ton-transition-time),\n max-height 0s var(--ton-transition-time);\n visibility: hidden;\n max-height: 0;\n}\n.ton-collapsible-wrapper.collapsed:after {\n height: 0;\n transition: height var(--ton-transition-time) linear;\n max-height: 20px;\n}\n.ton-collapsible-wrapper.collapsed {\n visibility: hidden;\n}\n.ton-collapsible-wrapper.collapsed .ton-child {\n opacity: 0;\n transition: opacity var(--ton-long-transition-time) linear;\n}\n"],"names":[],"version":3,"file":"main.css.map"}
package/dist/cjs/main.js CHANGED
@@ -3,7 +3,6 @@ var $gTuX4$reactjsxruntime = require("react/jsx-runtime");
3
3
  var $gTuX4$asupcontextmenu = require("@asup/context-menu");
4
4
  var $gTuX4$react = require("react");
5
5
  var $gTuX4$reactbootstrapicons = require("react-bootstrap-icons");
6
- var $gTuX4$swchelperscjs_object_spreadcjs = require("@swc/helpers/cjs/_object_spread.cjs");
7
6
  var $gTuX4$reactbootstrap = require("react-bootstrap");
8
7
 
9
8
 
@@ -27,10 +26,6 @@ function $parcel$exportWildcard(dest, source) {
27
26
  function $parcel$export(e, n, v, s) {
28
27
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
29
28
  }
30
-
31
- function $parcel$interopDefault(a) {
32
- return a && a.__esModule ? a.default : a;
33
- }
34
29
  var $a68bd8a6c0fd98c2$exports = {};
35
30
 
36
31
  $parcel$export($a68bd8a6c0fd98c2$exports, "TreeNode", function () { return $a56aac35d4408806$export$2eba8ec3a333fdbb; });
@@ -75,54 +70,48 @@ const $ff9cca1fe8f6b24e$export$29ec378200e05207 = (0, $gTuX4$react.createContext
75
70
 
76
71
 
77
72
 
78
-
79
- const $176d21a51def1fce$export$14f190ac910bde69 = /*#__PURE__*/ (0, ($parcel$interopDefault($gTuX4$react))).forwardRef(({ id: id, value: value, editing: editing, saving: saving, setValue: setValue, sendEscape: sendEscape, style: style, spellCheck: spellCheck = "true" }, ref)=>{
80
- $176d21a51def1fce$export$14f190ac910bde69.displayName = "WordEntry";
81
- const currentStyle = (0, $gTuX4$react.useMemo)(()=>{
82
- return (0, $gTuX4$swchelperscjs_object_spreadcjs._)({
83
- display: "inline-block",
84
- padding: "1px",
85
- paddingLeft: "3px",
86
- paddingRight: "3px",
87
- border: "1px",
88
- borderRadius: "3px"
89
- }, style);
90
- }, [
91
- style
92
- ]);
73
+ const $176d21a51def1fce$export$14f190ac910bde69 = /*#__PURE__*/ (0, $gTuX4$react.forwardRef)(({ id: id, className: className, value: value, editing: editing, saving: saving, setValue: setValue, sendEscape: sendEscape, style: style, spellCheck: spellCheck = "true" }, ref)=>{
93
74
  const [currentValue, setCurrentValue] = (0, $gTuX4$react.useState)(value !== null && value !== void 0 ? value : "");
94
75
  (0, $gTuX4$react.useEffect)(()=>{
95
76
  setCurrentValue(value !== null && value !== void 0 ? value : "");
96
77
  }, [
97
78
  value
98
79
  ]);
99
- const returnData = (0, $gTuX4$react.useCallback)(()=>{
100
- setValue === null || setValue === void 0 ? void 0 : setValue(currentValue);
101
- }, [
102
- currentValue,
103
- setValue
104
- ]);
105
- const keyPress = (0, $gTuX4$react.useCallback)((e)=>{
80
+ const keyPress = (e)=>{
106
81
  if (e.code === "Escape") {
107
82
  setCurrentValue(value !== null && value !== void 0 ? value : "");
108
83
  sendEscape === null || sendEscape === void 0 ? void 0 : sendEscape();
109
- } else if (e.code === "Enter") returnData();
84
+ } else if (e.code === "Enter") setValue === null || setValue === void 0 ? void 0 : setValue(currentValue);
85
+ };
86
+ // Add window onMouseDown event to stop events when editing
87
+ (0, $gTuX4$react.useEffect)(()=>{
88
+ const handleMouseDown = (e)=>{
89
+ const target = e.target;
90
+ if (editing && target.id !== `${id}` && target.id !== `${id}-holder` && target.id !== `${id}-spinner` && target.className !== "ton-rename") {
91
+ e.preventDefault();
92
+ e.stopPropagation();
93
+ setValue === null || setValue === void 0 ? void 0 : setValue(currentValue);
94
+ }
95
+ };
96
+ window.addEventListener("mousedown", handleMouseDown);
97
+ return ()=>{
98
+ window.removeEventListener("mousedown", handleMouseDown);
99
+ };
110
100
  }, [
111
- returnData,
112
- sendEscape,
113
- value
101
+ currentValue,
102
+ editing,
103
+ id,
104
+ setValue
114
105
  ]);
115
- // Simple if not editing
116
- if (!editing) return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
106
+ return !editing ? /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
117
107
  className: "ton-label-span",
118
- style: currentStyle,
108
+ style: style,
119
109
  id: `${id}`,
120
110
  children: value ? value : /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $gTuX4$reactjsxruntime.Fragment), {
121
111
  children: "\xa0"
122
112
  })
123
- });
124
- return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
125
- style: currentStyle,
113
+ }) : /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)("div", {
114
+ style: style,
126
115
  id: `${id}-holder`,
127
116
  className: "ton-rename-holder",
128
117
  children: [
@@ -137,47 +126,35 @@ const $176d21a51def1fce$export$14f190ac910bde69 = /*#__PURE__*/ (0, ($parcel$int
137
126
  id: String(id),
138
127
  ref: ref,
139
128
  type: "text",
140
- className: "ton-rename",
129
+ className: [
130
+ "ton-rename",
131
+ className
132
+ ].filter(Boolean).join(" "),
141
133
  value: currentValue,
142
134
  disabled: saving,
143
135
  onChange: (e)=>setCurrentValue(e.currentTarget.value),
144
- onBlur: returnData,
136
+ onBlur: (e)=>setValue === null || setValue === void 0 ? void 0 : setValue(e.currentTarget.value),
145
137
  onKeyDownCapture: keyPress
146
138
  })
147
139
  ]
148
140
  });
149
141
  });
142
+ $176d21a51def1fce$export$14f190ac910bde69.displayName = "WordEntry";
150
143
 
151
144
 
152
145
  const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemove, canRename: canRename, canAddChildren: canAddChildren, canRemoveChildren: canRemoveChildren, canRenameChildren: canRenameChildren })=>{
153
146
  // Contexts
154
147
  const treeContext = (0, $gTuX4$react.useContext)((0, $ff9cca1fe8f6b24e$export$29ec378200e05207));
155
148
  // Node information
156
- const thisNode = (0, $gTuX4$react.useMemo)(()=>treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.find((n)=>n.id === id), [
157
- id,
158
- treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
159
- ]);
160
- const childNodes = (0, $gTuX4$react.useMemo)(()=>treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.filter((n)=>n.parentId === id), [
161
- id,
162
- treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList
163
- ]);
164
- const descendents = (0, $gTuX4$react.useMemo)(()=>{
165
- var _treeContext_nodeList;
166
- return (0, $a19ef65643ae39e0$export$bd923365b402cb04)(id, (_treeContext_nodeList = treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList) !== null && _treeContext_nodeList !== void 0 ? _treeContext_nodeList : []);
167
- }, [
168
- id,
169
- treeContext
170
- ]);
149
+ const thisNode = treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.find((n)=>n.id === id);
150
+ const childNodes = treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList.filter((n)=>n.parentId === id);
151
+ var _treeContext_nodeList;
152
+ const descendents = (0, $a19ef65643ae39e0$export$bd923365b402cb04)(id, (_treeContext_nodeList = treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList) !== null && _treeContext_nodeList !== void 0 ? _treeContext_nodeList : []);
171
153
  // State
172
154
  const [error, setError] = (0, $gTuX4$react.useState)(false);
173
- const [errorText, setErrotText] = (0, $gTuX4$react.useState)("");
174
- const expanded = (0, $gTuX4$react.useMemo)(()=>{
175
- var _treeContext_expandedNodes_findIndex;
176
- 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;
177
- }, [
178
- id,
179
- treeContext === null || treeContext === void 0 ? void 0 : treeContext.expandedNodes
180
- ]);
155
+ const [errorText, setErrorText] = (0, $gTuX4$react.useState)("");
156
+ var _treeContext_expandedNodes_findIndex;
157
+ const expanded = ((_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;
181
158
  // Checkbox
182
159
  const checkRef = (0, $gTuX4$react.useRef)(null);
183
160
  (0, $gTuX4$react.useEffect)(()=>{
@@ -199,13 +176,8 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
199
176
  treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected
200
177
  ]);
201
178
  // Apply selected border
202
- const currentBorder = (0, $gTuX4$react.useMemo)(()=>{
203
- return (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected.includes(id)) ? "1px solid black" : "";
204
- }, [
205
- id,
206
- treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected
207
- ]);
208
- const nodeColour = (0, $gTuX4$react.useMemo)(()=>{
179
+ const currentBorder = (treeContext === null || treeContext === void 0 ? void 0 : treeContext.selected.includes(id)) ? "1px solid black" : "";
180
+ const nodeColour = (()=>{
209
181
  if (treeContext && treeContext.selected) {
210
182
  const anc = (0, $580f9b3e262282c9$export$c6fd3ab3f44300d0)(treeContext.selected, [], treeContext === null || treeContext === void 0 ? void 0 : treeContext.nodeList).map((n)=>n.id);
211
183
  if ([
@@ -214,10 +186,7 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
214
186
  ].includes(id)) return treeContext.nodeHighlight;
215
187
  }
216
188
  return;
217
- }, [
218
- id,
219
- treeContext
220
- ]);
189
+ })();
221
190
  // New node parameters
222
191
  const newNameRef = (0, $gTuX4$react.useRef)(null);
223
192
  const [showNewNode, setShowNewNode] = (0, $gTuX4$react.useState)(false);
@@ -227,95 +196,66 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
227
196
  const [renaming, setRenaming] = (0, $gTuX4$react.useState)(false);
228
197
  const [updatingNode, setUpdatingNode] = (0, $gTuX4$react.useState)(false);
229
198
  // Context functions
230
- const handleReturn = (0, $gTuX4$react.useCallback)((ret)=>{
199
+ const handleReturn = (ret)=>{
231
200
  if (!ret.success) {
232
201
  setError(true);
233
202
  var _ret_ErrorText;
234
- setErrotText((_ret_ErrorText = ret.ErrorText) !== null && _ret_ErrorText !== void 0 ? _ret_ErrorText : "An unknown error has occured");
203
+ setErrorText((_ret_ErrorText = ret.ErrorText) !== null && _ret_ErrorText !== void 0 ? _ret_ErrorText : "An unknown error has occured");
235
204
  } else {
236
205
  setError(false);
237
- setErrotText("");
206
+ setErrorText("");
238
207
  }
239
- }, []);
240
- const confirmNewNode = (0, $gTuX4$react.useCallback)(async (label)=>{
208
+ };
209
+ const confirmNewNode = async (label)=>{
241
210
  setSavingNewNode(true);
242
211
  if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onAddChild) handleReturn(await treeContext.onAddChild(id, label));
243
212
  setSavingNewNode(false);
244
213
  setShowNewNode(false);
245
- }, [
246
- handleReturn,
247
- id,
248
- treeContext
249
- ]);
250
- const renameNode = (0, $gTuX4$react.useCallback)(async (newLabel)=>{
214
+ };
215
+ const renameNode = async (newLabel)=>{
251
216
  setRenaming(false);
252
217
  if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRename) {
253
218
  setUpdatingNode(true);
254
219
  handleReturn(await treeContext.onRename(id, newLabel));
255
220
  setUpdatingNode(false);
256
221
  }
257
- }, [
258
- handleReturn,
259
- id,
260
- treeContext
261
- ]);
262
- const deleteThis = (0, $gTuX4$react.useCallback)(async ()=>{
222
+ };
223
+ const deleteThis = async ()=>{
263
224
  if (treeContext === null || treeContext === void 0 ? void 0 : treeContext.onRemove) {
264
225
  setUpdatingNode(true);
265
226
  handleReturn(await treeContext.onRemove(id));
266
227
  setUpdatingNode(false);
267
228
  }
268
- }, [
269
- handleReturn,
270
- id,
271
- treeContext
272
- ]);
229
+ };
273
230
  // Context actions
274
- const addChild = (0, $gTuX4$react.useCallback)(()=>{
231
+ const addChild = ()=>{
275
232
  var _treeContext_handleExpandClick;
276
233
  setShowNewNode(true);
277
234
  treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleExpandClick = treeContext.handleExpandClick) === null || _treeContext_handleExpandClick === void 0 ? void 0 : _treeContext_handleExpandClick.call(treeContext, id, true);
278
- }, [
279
- id,
280
- treeContext
281
- ]);
282
- (0, $gTuX4$react.useEffect)(()=>{
283
- if (showNewNode === true && newNameRef.current) newNameRef.current.focus();
284
- }, [
285
- showNewNode
286
- ]);
287
- const renameThis = (0, $gTuX4$react.useCallback)(()=>{
235
+ };
236
+ const renameThis = ()=>{
288
237
  var _treeContext_handleSelect;
289
238
  setRenaming(true);
290
239
  treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
291
- }, [
292
- id,
293
- treeContext
294
- ]);
240
+ };
295
241
  // Context menu
296
- const menuItems = (0, $gTuX4$react.useMemo)(()=>{
297
- const menuItems = [];
298
- if (canAddChildren) menuItems.push({
299
- label: "Add",
300
- action: addChild
301
- });
302
- if (canRename) menuItems.push({
303
- label: "Rename",
304
- action: renameThis
305
- });
306
- if (canRemove && (childNodes === undefined || childNodes.length === 0)) menuItems.push({
307
- label: "Delete",
308
- action: deleteThis
309
- });
310
- return menuItems;
242
+ const menuItems = [];
243
+ if (canAddChildren) menuItems.push({
244
+ label: "Add",
245
+ action: addChild
246
+ });
247
+ if (canRename) menuItems.push({
248
+ label: "Rename",
249
+ action: renameThis
250
+ });
251
+ if (canRemove && (childNodes === undefined || childNodes.length === 0)) menuItems.push({
252
+ label: "Delete",
253
+ action: deleteThis
254
+ });
255
+ (0, $gTuX4$react.useEffect)(()=>{
256
+ if (showNewNode === true && newNameRef.current) newNameRef.current.focus();
311
257
  }, [
312
- addChild,
313
- canAddChildren,
314
- canRemove,
315
- canRename,
316
- childNodes,
317
- deleteThis,
318
- renameThis
258
+ showNewNode
319
259
  ]);
320
260
  // Return node
321
261
  return !treeContext ? null : /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsxs)((0, $gTuX4$reactjsxruntime.Fragment), {
@@ -348,10 +288,10 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
348
288
  id: `${treeContext.id}-treenode-checkbox-${id}`,
349
289
  onClick: ()=>{
350
290
  var _treeContext_handleSelect;
351
- return treeContext === null || treeContext === void 0 ? void 0 : (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, descendents);
291
+ return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, descendents);
352
292
  }
353
293
  }),
354
- childNodes !== undefined && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $gTuX4$reactbootstrapicons.CaretRightFill), {
294
+ childNodes && childNodes.length > 0 ? !expanded ? /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $gTuX4$reactbootstrapicons.CaretRightFill), {
355
295
  id: `${treeContext.id}-treenode-caret-${id}`,
356
296
  style: {
357
297
  width: "16px",
@@ -394,7 +334,8 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
394
334
  },
395
335
  onClickCapture: ()=>{
396
336
  var _treeContext_handleSelect;
397
- return (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
337
+ if (!treeContext.expandedNodes.includes(id)) treeContext.handleExpandClick(id);
338
+ (_treeContext_handleSelect = treeContext.handleSelect) === null || _treeContext_handleSelect === void 0 ? void 0 : _treeContext_handleSelect.call(treeContext, id);
398
339
  },
399
340
  onFocusCapture: ()=>{
400
341
  var _treeContext_handleSelect;
@@ -402,6 +343,7 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
402
343
  },
403
344
  children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $176d21a51def1fce$export$14f190ac910bde69), {
404
345
  id: `${treeContext.id}-treenode-entry-${id}`,
346
+ className: currentBorder ? "selected" : "",
405
347
  ref: currentNameRef,
406
348
  value: thisNode.label,
407
349
  editing: renaming,
@@ -420,21 +362,9 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
420
362
  })
421
363
  })
422
364
  }),
423
- showNewNode && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $176d21a51def1fce$export$14f190ac910bde69), {
424
- style: {
425
- marginLeft: "14px"
426
- },
427
- id: `treenode-new-${id}`,
428
- ref: newNameRef,
429
- editing: true,
430
- setValue: (ret)=>confirmNewNode(ret),
431
- saving: savingNewNode,
432
- sendEscape: ()=>setShowNewNode(false),
433
- spellCheck: treeContext.spellCheck
434
- }),
435
- childNodes !== undefined && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
436
- className: `ton-collapsible-wrapper ${expanded ? "" : "collapsed"}`,
437
- children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
365
+ childNodes && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
366
+ className: `ton-collapsible-wrapper ${expanded && childNodes.length > 0 ? "" : "collapsed"}`,
367
+ children: childNodes.length > 0 && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
438
368
  className: "ton-collapsible",
439
369
  children: childNodes.map((h)=>/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("span", {
440
370
  id: `${treeContext.id}-treenode-child-${h.id}`,
@@ -449,6 +379,18 @@ const $a56aac35d4408806$export$2eba8ec3a333fdbb = ({ id: id, canRemove: canRemov
449
379
  })
450
380
  }, h.id))
451
381
  })
382
+ }),
383
+ showNewNode && /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $176d21a51def1fce$export$14f190ac910bde69), {
384
+ style: {
385
+ marginLeft: "14px"
386
+ },
387
+ id: `treenode-new-${id}`,
388
+ ref: newNameRef,
389
+ editing: true,
390
+ setValue: (ret)=>confirmNewNode(ret),
391
+ saving: savingNewNode,
392
+ sendEscape: ()=>setShowNewNode(false),
393
+ spellCheck: treeContext.spellCheck
452
394
  })
453
395
  ]
454
396
  });
@@ -469,26 +411,28 @@ const $f31429c9cc6d3bce$export$40c47a7ac5f85aba = (nodeList, selected, expandedN
469
411
 
470
412
 
471
413
 
472
- const $9becaaec3a803ae7$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList, roots: roots, selected: selected = [], showCheckBox: showCheckBox = false, handleSelect: handleSelect, onAdd: onAdd, onRename: onRename, onRemove: onRemove, canRemoveRoot: canRemoveRoot = false, canRenameRoot: canRenameRoot = false, canAddChildren: canAddChildren = false, canRemoveChildren: canRemoveChildren = false, canRenameChildren: canRenameChildren = false, nodeHighlight: nodeHighlight = "red", textHighlight: textHighlight = "rgba(255, 0, 0, 0.2)", spellCheck: spellCheck = "true" })=>{
414
+ const $9becaaec3a803ae7$export$5580fff3e08a8be5 = ({ alwaysShowSelected: alwaysShowSelected = "first", canAddChildren: canAddChildren = false, canRemoveChildren: canRemoveChildren = false, canRemoveRoot: canRemoveRoot = false, canRenameChildren: canRenameChildren = false, canRenameRoot: canRenameRoot = false, handleSelect: handleSelect, id: id, nodeHighlight: nodeHighlight = "red", nodeList: nodeList, onAdd: onAdd, onRemove: onRemove, onRename: onRename, roots: roots, selected: selected = [], showCheckBox: showCheckBox = false, spellCheck: spellCheck = "true", textHighlight: textHighlight = "rgba(255, 0, 0, 0.2)" })=>{
415
+ const [firstRender, setFirstRender] = (0, $gTuX4$react.useState)(alwaysShowSelected === "first");
473
416
  const [expandedNodes, setExpandedNodes] = (0, $gTuX4$react.useState)([]);
474
- const selectedArray = (0, $gTuX4$react.useMemo)(()=>Array.isArray(selected) ? selected : [
475
- selected
476
- ], [
477
- selected
478
- ]);
479
417
  (0, $gTuX4$react.useEffect)(()=>{
480
- if (selectedArray.length > 0) {
418
+ const selectedArray = Array.isArray(selected) ? selected : [
419
+ selected
420
+ ];
421
+ if ((alwaysShowSelected === "always" || firstRender) && selectedArray.length > 0) {
481
422
  // Check all nodes are showing that should be
482
423
  const shouldExpand = (0, $f31429c9cc6d3bce$export$40c47a7ac5f85aba)(nodeList, selectedArray, expandedNodes);
483
424
  if (shouldExpand.filter((n)=>!expandedNodes.includes(n)).length > 0) setExpandedNodes(shouldExpand);
425
+ setFirstRender(false);
484
426
  }
485
427
  }, [
428
+ alwaysShowSelected,
429
+ firstRender,
486
430
  expandedNodes,
487
431
  nodeList,
488
- selectedArray
432
+ selected
489
433
  ]);
490
434
  // Change expansion and update contexts
491
- const changeExpand = (0, $gTuX4$react.useCallback)((eKey, force)=>{
435
+ const changeExpand = (eKey, force)=>{
492
436
  const newExpandedNodes = [
493
437
  ...expandedNodes
494
438
  ];
@@ -496,27 +440,27 @@ const $9becaaec3a803ae7$export$5580fff3e08a8be5 = ({ id: id, nodeList: nodeList,
496
440
  if (ix === -1 && force === undefined || force === true) newExpandedNodes.push(eKey);
497
441
  else newExpandedNodes.splice(ix, 1);
498
442
  setExpandedNodes(newExpandedNodes);
499
- }, [
500
- expandedNodes
501
- ]);
443
+ };
502
444
  return /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)("div", {
503
445
  id: id,
504
446
  className: "tree-of-nodes",
505
447
  children: /*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $ff9cca1fe8f6b24e$export$29ec378200e05207).Provider, {
506
448
  value: {
507
449
  id: id,
508
- nodeList: nodeList,
509
- selected: selectedArray,
510
- showCheckBox: showCheckBox,
511
- handleSelect: handleSelect,
512
450
  expandedNodes: expandedNodes,
513
451
  handleExpandClick: (r, f)=>changeExpand(r, f),
452
+ handleSelect: handleSelect,
453
+ nodeHighlight: nodeHighlight,
454
+ nodeList: nodeList,
514
455
  onAddChild: onAdd,
515
- onRename: onRename,
516
456
  onRemove: onRemove,
517
- nodeHighlight: nodeHighlight,
518
- textHighlight: textHighlight,
519
- spellCheck: spellCheck
457
+ onRename: onRename,
458
+ selected: Array.isArray(selected) ? selected : [
459
+ selected
460
+ ],
461
+ showCheckBox: showCheckBox,
462
+ spellCheck: spellCheck,
463
+ textHighlight: textHighlight
520
464
  },
521
465
  children: roots.map((r)=>/*#__PURE__*/ (0, $gTuX4$reactjsxruntime.jsx)((0, $a56aac35d4408806$export$2eba8ec3a333fdbb), {
522
466
  id: r,