tsgrid-ui 2.7.1 → 2.9.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.
Files changed (68) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/dist/base.d.ts +148 -0
  3. package/dist/base.es6.js +11 -0
  4. package/dist/base.es6.js.map +1 -0
  5. package/dist/chunks/chunk-26XP2XU3.js +1795 -0
  6. package/dist/chunks/chunk-26XP2XU3.js.map +1 -0
  7. package/dist/chunks/chunk-3NYH6545.js +2423 -0
  8. package/dist/chunks/chunk-3NYH6545.js.map +1 -0
  9. package/dist/chunks/chunk-BIB3X2TW.js +1638 -0
  10. package/dist/chunks/chunk-BIB3X2TW.js.map +1 -0
  11. package/dist/chunks/chunk-DXZJHS4M.js +1283 -0
  12. package/dist/chunks/chunk-DXZJHS4M.js.map +1 -0
  13. package/dist/chunks/chunk-EVZMMVXO.js +1212 -0
  14. package/dist/chunks/chunk-EVZMMVXO.js.map +1 -0
  15. package/dist/chunks/chunk-GJD5NFWQ.js +2305 -0
  16. package/dist/chunks/chunk-GJD5NFWQ.js.map +1 -0
  17. package/dist/chunks/chunk-IYF3Q7GX.js +127 -0
  18. package/dist/chunks/chunk-IYF3Q7GX.js.map +1 -0
  19. package/dist/chunks/chunk-OFASTA2A.js +2980 -0
  20. package/dist/chunks/chunk-OFASTA2A.js.map +1 -0
  21. package/dist/chunks/chunk-OMLGN735.js +677 -0
  22. package/dist/chunks/chunk-OMLGN735.js.map +1 -0
  23. package/dist/chunks/chunk-WKSLGUB3.js +1127 -0
  24. package/dist/chunks/chunk-WKSLGUB3.js.map +1 -0
  25. package/dist/chunks/chunk-YBY52G2U.js +849 -0
  26. package/dist/chunks/chunk-YBY52G2U.js.map +1 -0
  27. package/dist/field.d.ts +329 -0
  28. package/dist/field.es6.js +11 -0
  29. package/dist/field.es6.js.map +1 -0
  30. package/dist/form.d.ts +162 -0
  31. package/dist/form.es6.js +14 -0
  32. package/dist/form.es6.js.map +1 -0
  33. package/dist/layout.d.ts +108 -0
  34. package/dist/layout.es6.js +13 -0
  35. package/dist/layout.es6.js.map +1 -0
  36. package/dist/locale.d.ts +30 -0
  37. package/dist/locale.es6.js +7 -0
  38. package/dist/locale.es6.js.map +1 -0
  39. package/dist/metafile-esm.json +1 -0
  40. package/dist/popup.d.ts +92 -0
  41. package/dist/popup.es6.js +18 -0
  42. package/dist/popup.es6.js.map +1 -0
  43. package/dist/query-CKGg5Ugv.d.ts +81 -0
  44. package/dist/sidebar.d.ts +138 -0
  45. package/dist/sidebar.es6.js +11 -0
  46. package/dist/sidebar.es6.js.map +1 -0
  47. package/dist/tabs.d.ts +63 -0
  48. package/dist/tabs.es6.js +11 -0
  49. package/dist/tabs.es6.js.map +1 -0
  50. package/dist/toolbar.d.ts +97 -0
  51. package/dist/toolbar.es6.js +11 -0
  52. package/dist/toolbar.es6.js.map +1 -0
  53. package/dist/tooltip.d.ts +322 -0
  54. package/dist/tooltip.es6.js +18 -0
  55. package/dist/tooltip.es6.js.map +1 -0
  56. package/dist/tsgrid-ui.css +2 -2
  57. package/dist/tsgrid-ui.d.ts +16 -2004
  58. package/dist/tsgrid-ui.es6.js +7750 -23830
  59. package/dist/tsgrid-ui.es6.js.map +1 -1
  60. package/dist/tsgrid-ui.es6.min.js +28 -28
  61. package/dist/tsgrid-ui.js +96 -17
  62. package/dist/tsgrid-ui.min.css +2 -2
  63. package/dist/tsgrid-ui.min.js +24 -24
  64. package/dist/tsutils-message-CogFtVtO.d.ts +82 -0
  65. package/dist/utils.d.ts +418 -0
  66. package/dist/utils.es6.js +14 -0
  67. package/dist/utils.es6.js.map +1 -0
  68. package/package.json +26 -5
@@ -0,0 +1,1638 @@
1
+ import {
2
+ TsMenu,
3
+ TsTooltip
4
+ } from "./chunk-OFASTA2A.js";
5
+ import {
6
+ TsUtils
7
+ } from "./chunk-3NYH6545.js";
8
+ import {
9
+ TsBase,
10
+ TsUi,
11
+ query
12
+ } from "./chunk-DXZJHS4M.js";
13
+
14
+ // src/tssidebar.ts
15
+ var query2 = query;
16
+ var TsSidebar = class extends TsBase {
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ nodes;
19
+ // any: sidebar node tree has dynamic shape
20
+ // any: targeted-any per typing_policy; TsSidebar node tree shape is user-defined at runtime
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ selected;
23
+ // any: targeted-any per typing_policy; TsSidebar node tree shape is user-defined at runtime
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ img;
26
+ // any: targeted-any per typing_policy; TsSidebar node tree shape is user-defined at runtime
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ icon;
29
+ style;
30
+ hasFocus;
31
+ flat;
32
+ flatButton;
33
+ keyboard;
34
+ editable;
35
+ reorder;
36
+ tabIndex;
37
+ routeData;
38
+ multi;
39
+ skipRefresh;
40
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
41
+ last;
42
+ // any: accumulates move, renaming, observeResize
43
+ node_template;
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ constructor(options) {
46
+ super(options.name);
47
+ this.name = "";
48
+ this.box = null;
49
+ this["sidebar"] = null;
50
+ this["parent"] = null;
51
+ this.nodes = [];
52
+ this["menu"] = [];
53
+ this.routeData = {};
54
+ this.selected = null;
55
+ this.icon = null;
56
+ this.style = "";
57
+ this["topHTML"] = "";
58
+ this["bottomHTML"] = "";
59
+ this.multi = false;
60
+ this.editable = false;
61
+ this.reorder = false;
62
+ this.flatButton = false;
63
+ this.keyboard = true;
64
+ this.flat = false;
65
+ this.hasFocus = false;
66
+ this["levelPadding"] = 12;
67
+ this["toggleAlign"] = "right";
68
+ this.skipRefresh = false;
69
+ this.tabIndex = null;
70
+ this["handle"] = { width: 0, style: "", text: "", tooltip: "" };
71
+ this["badge"] = null;
72
+ this["onClick"] = null;
73
+ this["onSelect"] = null;
74
+ this["onUnselect"] = null;
75
+ this["onDblClick"] = null;
76
+ this["onMouseEnter"] = null;
77
+ this["onMouseLeave"] = null;
78
+ this["onContextMenu"] = null;
79
+ this["onMenuClick"] = null;
80
+ this["onExpand"] = null;
81
+ this["onCollapse"] = null;
82
+ this["onKeydown"] = null;
83
+ this["onRender"] = null;
84
+ this["onRefresh"] = null;
85
+ this["onResize"] = null;
86
+ this["onDestroy"] = null;
87
+ this["onFocus"] = null;
88
+ this["onBlur"] = null;
89
+ this["onFlat"] = null;
90
+ this["onEdit"] = null;
91
+ this["onRename"] = null;
92
+ this["onReorder"] = null;
93
+ this["onDragStart"] = null;
94
+ this["onDragOver"] = null;
95
+ this.node_template = {
96
+ id: null,
97
+ text: "",
98
+ order: null,
99
+ count: null,
100
+ icon: null,
101
+ nodes: [],
102
+ style: "",
103
+ // additional style for subitems
104
+ route: null,
105
+ selected: false,
106
+ expanded: false,
107
+ hidden: false,
108
+ disabled: false,
109
+ group: false,
110
+ // if true, it will build as a group
111
+ groupShowHide: true,
112
+ collapsible: false,
113
+ plus: false,
114
+ // if true, plus will be shown even if there is no sub nodes
115
+ childOffset: 0,
116
+ // events
117
+ onClick: null,
118
+ onDblClick: null,
119
+ onContextMenu: null,
120
+ onExpand: null,
121
+ onCollapse: null,
122
+ // internal
123
+ parent: null,
124
+ // node object
125
+ sidebar: null
126
+ };
127
+ this.last = {
128
+ badge: {},
129
+ renaming: false,
130
+ move: null
131
+ // object, move details
132
+ };
133
+ const nodes = options.nodes;
134
+ delete options.nodes;
135
+ Object.assign(this, options);
136
+ if (Array.isArray(nodes)) this.add(nodes);
137
+ options.nodes = nodes;
138
+ if (typeof this.box == "string") this.box = query2(this.box).get(0);
139
+ if (this.box) this.render(this.box);
140
+ }
141
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
142
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
+ add(parent, nodes) {
144
+ if (nodes === void 0) {
145
+ nodes = parent;
146
+ parent = this;
147
+ }
148
+ if (typeof parent == "string") parent = this.get(parent);
149
+ if (parent == null || parent == "") parent = this;
150
+ return this.insert(parent, null, nodes);
151
+ }
152
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
153
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
+ insert(parent, before, nodes) {
155
+ let txt, ind, tmp, node, nd;
156
+ if (nodes === void 0 && typeof parent == "string") {
157
+ nodes = before;
158
+ before = parent;
159
+ if (before != null) {
160
+ ind = this.get(before);
161
+ if (ind == null) {
162
+ if (!Array.isArray(nodes)) nodes = [nodes];
163
+ if (nodes[0].caption != null && nodes[0].text == null) {
164
+ console.log("NOTICE: sidebar node.caption property is deprecated, please use node.text. Node -> ", nodes[0]);
165
+ nodes[0].text = nodes[0].caption;
166
+ }
167
+ txt = nodes[0].text;
168
+ console.log('ERROR: Cannot insert node "' + txt + '" because cannot find node "' + before + '" to insert before.');
169
+ return null;
170
+ }
171
+ parent = this.get(before).parent;
172
+ } else {
173
+ parent = this;
174
+ }
175
+ }
176
+ if (typeof parent == "string") parent = this.get(parent);
177
+ if (parent == null || parent == "") parent = this;
178
+ if (!Array.isArray(nodes)) nodes = [nodes];
179
+ for (let o = 0; o < nodes.length; o++) {
180
+ node = nodes[o];
181
+ if (node.caption != null && node.text == null) {
182
+ console.log("NOTICE: sidebar node.caption property is deprecated, please use node.text");
183
+ node.text = node.caption;
184
+ }
185
+ if (typeof node.id == null) {
186
+ txt = node.text;
187
+ console.log('ERROR: Cannot insert node "' + txt + '" because it has no id.');
188
+ continue;
189
+ }
190
+ if (this.get(this, node.id) != null) {
191
+ console.log("ERROR: Cannot insert node with id=" + node.id + " (text: " + node.text + ") because another node with the same id already exists.");
192
+ continue;
193
+ }
194
+ tmp = Object.assign({}, this.node_template, node);
195
+ tmp.sidebar = this;
196
+ tmp.parent = parent;
197
+ nd = tmp.nodes || [];
198
+ tmp.nodes = [];
199
+ if (before == null) {
200
+ parent.nodes.push(tmp);
201
+ } else {
202
+ ind = this.get(parent, before, true);
203
+ if (ind == null) {
204
+ console.log('ERROR: Cannot insert node "' + node.text + '" because cannot find node "' + before + '" to insert before.');
205
+ return null;
206
+ }
207
+ parent.nodes.splice(ind, 0, tmp);
208
+ }
209
+ if (nd.length > 0) {
210
+ this.insert(tmp, null, nd);
211
+ }
212
+ }
213
+ if (!this.skipRefresh) this.refresh(parent.id);
214
+ return tmp;
215
+ }
216
+ // any: array of heterogeneous runtime values; TsSidebar node tree shape is user-defined at runtime
217
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
+ remove(...args) {
219
+ let effected = 0;
220
+ let lastNode = null;
221
+ args.forEach((arg) => {
222
+ const node = this.get(arg);
223
+ if (node == null) return;
224
+ if (this.selected != null) {
225
+ if (Array.isArray(this.selected)) {
226
+ this.selected.splice(this.selected.indexOf(node.id), 1);
227
+ } else if (this.selected === node.id) {
228
+ this.selected = null;
229
+ }
230
+ }
231
+ const ind = this.get(node.parent, arg, true);
232
+ if (ind == null) return;
233
+ if (node.parent.nodes[ind].selected) node["sidebar"].unselect(node.id);
234
+ node.parent.nodes.splice(ind, 1);
235
+ node.parent.collapsible = node.parent.nodes.length > 0;
236
+ lastNode = node;
237
+ effected++;
238
+ });
239
+ if (!this.skipRefresh) {
240
+ if (effected > 0 && arguments.length == 1 && lastNode != null) this.refresh(lastNode.parent.id);
241
+ else this.refresh();
242
+ }
243
+ return effected;
244
+ }
245
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
246
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
247
+ set(parent, id, node) {
248
+ if (node === void 0) {
249
+ node = id;
250
+ id = parent;
251
+ parent = this;
252
+ }
253
+ if (typeof parent == "string") parent = this.get(parent);
254
+ if (parent.nodes == null) return null;
255
+ for (let i = 0; i < parent.nodes.length; i++) {
256
+ if (parent.nodes[i].id === id) {
257
+ const res = this.update(id, node);
258
+ if (Object.keys(res).length != 0) {
259
+ const nodes = node.nodes;
260
+ TsUtils.extend(parent.nodes[i], node, nodes != null ? { nodes: [] } : {});
261
+ if (nodes != null) {
262
+ this.add(parent.nodes[i], nodes);
263
+ }
264
+ if (!this.skipRefresh) this.refresh(id);
265
+ }
266
+ return true;
267
+ } else {
268
+ const rv = this.set(parent.nodes[i], id, node);
269
+ if (rv) return true;
270
+ }
271
+ }
272
+ return false;
273
+ }
274
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
275
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
276
+ get(parent, id, returnIndex) {
277
+ if (arguments.length === 0) {
278
+ const all = [];
279
+ const tmp = this.find({});
280
+ for (let t = 0; t < tmp.length; t++) {
281
+ if (tmp[t].id != null) all.push(tmp[t].id);
282
+ }
283
+ return all;
284
+ } else {
285
+ if (arguments.length == 1 || arguments.length == 2 && id === true) {
286
+ returnIndex = id;
287
+ id = parent;
288
+ parent = this;
289
+ }
290
+ if (typeof parent == "string") parent = this.get(parent);
291
+ if (parent.nodes == null) return null;
292
+ for (let i = 0; i < parent.nodes.length; i++) {
293
+ if (parent.nodes[i].id == id) {
294
+ if (returnIndex === true) return i;
295
+ else return parent.nodes[i];
296
+ } else {
297
+ const rv = this.get(parent.nodes[i], id, returnIndex);
298
+ if (rv || rv === 0) return rv;
299
+ }
300
+ }
301
+ return null;
302
+ }
303
+ }
304
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
+ setCount(id, count, options = {}) {
306
+ const node = this.get(id);
307
+ if (node.group) {
308
+ console.log(`Node "${id}" is a group and groups cannot have counts or badges.`);
309
+ return;
310
+ }
311
+ this.last.badge[id] = {
312
+ className: options.className ?? "",
313
+ style: options.style ?? ""
314
+ };
315
+ const btn = query2(this.box).find(`#node_${TsUtils.escapeId(id)} .tsg-node-badge`);
316
+ if (btn.length > 0) {
317
+ const $cnt = btn.removeClass(null).addClass(`tsg-node-badge ${options.className ?? "tsg-node-count"}`).text(count);
318
+ $cnt.get(0).style.cssText = options.style || "";
319
+ const item = this.get(id);
320
+ item.count = count;
321
+ } else if (!options.noRepeat) {
322
+ this.set(id, { count });
323
+ options.noRepeat = true;
324
+ queueMicrotask(() => this.setCount(id, count, options));
325
+ }
326
+ }
327
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
328
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
329
+ find(parent, params, results) {
330
+ if (arguments.length == 1) {
331
+ params = parent;
332
+ parent = this;
333
+ }
334
+ if (!results) results = [];
335
+ if (typeof parent == "string") parent = this.get(parent);
336
+ if (parent.nodes == null) return results;
337
+ for (let i = 0; i < parent.nodes.length; i++) {
338
+ let match = true;
339
+ for (const prop in params) {
340
+ if (parent.nodes[i][prop] != params[prop]) match = false;
341
+ }
342
+ if (match) results.push(parent.nodes[i]);
343
+ if (parent.nodes[i].nodes.length > 0) results = this.find(parent.nodes[i], params, results);
344
+ }
345
+ return results;
346
+ }
347
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
+ sort(options, nodes) {
349
+ if (!options || typeof options != "object") options = {};
350
+ if (options.foldersFirst == null) options.foldersFirst = true;
351
+ if (options.caseSensitive == null) options.caseSensitive = false;
352
+ if (options.reverse == null) options.reverse = false;
353
+ if (nodes == null) {
354
+ nodes = this.nodes;
355
+ }
356
+ nodes.sort((a, b) => {
357
+ const isAfolder = a.nodes && a.nodes.length > 0;
358
+ const isBfolder = b.nodes && b.nodes.length > 0;
359
+ if (options.foldersFirst === false || !isAfolder && !isBfolder || isAfolder && isBfolder) {
360
+ let aText = a.text;
361
+ let bText = b.text;
362
+ if (a.order != null) aText = a.order;
363
+ if (b.order != null) bText = b.order;
364
+ if (!options.caseSensitive) {
365
+ aText = aText.toLowerCase();
366
+ bText = bText.toLowerCase();
367
+ }
368
+ const cmp = TsUtils.naturalCompare(aText, bText);
369
+ return (cmp === 1 || cmp === -1) & (options.reverse ? 1 : 0) ? -cmp : cmp;
370
+ }
371
+ if (isAfolder && !isBfolder) {
372
+ return !options.reverse ? -1 : 1;
373
+ }
374
+ if (!isAfolder && isBfolder) {
375
+ return !options.reverse ? 1 : -1;
376
+ }
377
+ });
378
+ nodes.forEach((node) => {
379
+ if (node.nodes && node.nodes.length > 0) {
380
+ this.sort(options, node.nodes);
381
+ }
382
+ });
383
+ }
384
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
385
+ each(fn, nodes) {
386
+ if (nodes == null) nodes = this.nodes;
387
+ nodes.forEach((node) => {
388
+ fn.call(this, node);
389
+ if (node.nodes && node.nodes.length > 0) {
390
+ this.each(fn, node.nodes);
391
+ }
392
+ });
393
+ }
394
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+ search(str, compare = null) {
396
+ let count = 0;
397
+ const str2 = str.toLowerCase();
398
+ this.each((node) => {
399
+ let match = false;
400
+ if (typeof compare == "function") {
401
+ match = compare(str, node);
402
+ } else {
403
+ match = !(node.text.toLowerCase().indexOf(str2) === -1);
404
+ }
405
+ if (match) {
406
+ count++;
407
+ showParents(node);
408
+ node.hidden = false;
409
+ } else {
410
+ node.hidden = true;
411
+ }
412
+ });
413
+ this.refresh();
414
+ return count;
415
+ function showParents(node) {
416
+ if (node.parent) {
417
+ node.parent.hidden = false;
418
+ showParents(node.parent);
419
+ }
420
+ }
421
+ }
422
+ // any: array of heterogeneous runtime values; TsSidebar node tree shape is user-defined at runtime
423
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
424
+ show(...args) {
425
+ const effected = [];
426
+ args.forEach((it) => {
427
+ const node = this.get(it);
428
+ if (node == null || node.hidden === false) return;
429
+ node.hidden = false;
430
+ effected.push(node.id);
431
+ });
432
+ if (effected.length > 0) {
433
+ if (args.length == 1) this.refresh(args[0]);
434
+ else this.refresh();
435
+ }
436
+ return effected;
437
+ }
438
+ // any: array of heterogeneous runtime values; TsSidebar node tree shape is user-defined at runtime
439
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
440
+ hide(...args) {
441
+ const effected = [];
442
+ args.forEach((it) => {
443
+ const node = this.get(it);
444
+ if (node == null || node.hidden === true) return;
445
+ node.hidden = true;
446
+ effected.push(node.id);
447
+ });
448
+ if (effected.length > 0) {
449
+ if (args.length == 1) this.refresh(args[0]);
450
+ else this.refresh();
451
+ }
452
+ return effected;
453
+ }
454
+ // any: array of heterogeneous runtime values; TsSidebar node tree shape is user-defined at runtime
455
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
456
+ enable(...args) {
457
+ const effected = [];
458
+ args.forEach((it) => {
459
+ const node = this.get(it);
460
+ if (node == null || node.disabled === false) return;
461
+ node.disabled = false;
462
+ effected.push(node.id);
463
+ });
464
+ if (effected.length > 0) {
465
+ if (args.length == 1) this.refresh(args[0]);
466
+ else this.refresh();
467
+ }
468
+ return effected;
469
+ }
470
+ // any: array of heterogeneous runtime values; TsSidebar node tree shape is user-defined at runtime
471
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
472
+ disable(...args) {
473
+ const effected = [];
474
+ args.forEach((it) => {
475
+ const node = this.get(it);
476
+ if (node == null || node.disabled === true) return;
477
+ node.disabled = true;
478
+ if (node.selected) this.unselect(node.id);
479
+ effected.push(node.id);
480
+ });
481
+ if (effected.length > 0) {
482
+ if (args.length == 1) this.refresh(args[0]);
483
+ else this.refresh();
484
+ }
485
+ return effected;
486
+ }
487
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
488
+ select(id) {
489
+ if (Array.isArray(id)) {
490
+ [...id].forEach((id2) => this.select(id2));
491
+ return;
492
+ }
493
+ const new_node = this.get(id);
494
+ if (!new_node) return false;
495
+ const edata = this.trigger("select", { target: id, id, node: new_node });
496
+ if (edata.isCancelled === true) {
497
+ return true;
498
+ }
499
+ if (!this.multi && this.selected == id && new_node.selected) {
500
+ return false;
501
+ } else {
502
+ this.find({ selected: true }).forEach((nd) => nd.selected = false);
503
+ }
504
+ const $el = query2(this.box).find("#node_" + TsUtils.escapeId(id));
505
+ $el.addClass("tsg-selected").find(".tsg-icon").addClass("tsg-icon-selected");
506
+ if ($el.length > 0) {
507
+ if (!this.inView(id)) this.scrollIntoView(id);
508
+ }
509
+ new_node.selected = true;
510
+ if (this.multi) {
511
+ if (!Array.isArray(this.selected)) {
512
+ this.selected = this.selected ? [this.selected] : [];
513
+ }
514
+ this.selected.push(id);
515
+ } else {
516
+ this.selected = this.multi ? [id] : id;
517
+ }
518
+ edata.finish();
519
+ return true;
520
+ }
521
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
522
+ unselect(id) {
523
+ if (arguments.length === 0) {
524
+ id = this.selected;
525
+ }
526
+ if (Array.isArray(id)) {
527
+ [...id].forEach((id2) => this.unselect(id2));
528
+ return;
529
+ }
530
+ const current = this.get(id);
531
+ if (!current) return false;
532
+ const edata = this.trigger("unselect", { target: id, id, node: current });
533
+ if (edata.isCancelled === true) {
534
+ return true;
535
+ }
536
+ current.selected = false;
537
+ query2(this.box).find("#node_" + TsUtils.escapeId(id)).removeClass("tsg-selected").find(".tsg-icon").removeClass("tsg-icon-selected");
538
+ if (typeof this.selected == "string" && this.selected == id) {
539
+ this.selected = null;
540
+ }
541
+ if (this.multi && Array.isArray(this.selected)) {
542
+ const ind = this.selected.indexOf(id);
543
+ if (ind != -1) this.selected.splice(ind, 1);
544
+ }
545
+ edata.finish();
546
+ return true;
547
+ }
548
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
549
+ toggle(id) {
550
+ const nd = this.get(id);
551
+ if (nd == null) return false;
552
+ if (nd.plus) {
553
+ this.set(id, { plus: false });
554
+ this.expand(id);
555
+ this.refresh(id);
556
+ return;
557
+ }
558
+ if (nd.nodes.length === 0) return false;
559
+ if (!nd.collapsible) return false;
560
+ if (this.get(id).expanded) return this.collapse(id);
561
+ else return this.expand(id);
562
+ }
563
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
564
+ collapse(id) {
565
+ const nd = this.get(id);
566
+ if (nd == null) return false;
567
+ const edata = this.trigger("collapse", { target: id, object: nd, node: nd });
568
+ if (edata.isCancelled === true) return;
569
+ query2(this.box).find("#node_" + TsUtils.escapeId(id) + "_sub").hide();
570
+ query2(this.box).find("#node_" + TsUtils.escapeId(id) + " .tsg-expanded").removeClass("tsg-expanded").addClass("tsg-collapsed");
571
+ nd.expanded = false;
572
+ edata.finish();
573
+ this.refresh(id);
574
+ return true;
575
+ }
576
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
577
+ expand(id) {
578
+ const nd = this.get(id);
579
+ const edata = this.trigger("expand", { target: id, object: nd, node: nd });
580
+ if (edata.isCancelled === true) return;
581
+ query2(this.box).find("#node_" + TsUtils.escapeId(id) + "_sub").show();
582
+ query2(this.box).find("#node_" + TsUtils.escapeId(id) + " .tsg-collapsed").removeClass("tsg-collapsed").addClass("tsg-expanded");
583
+ nd.expanded = true;
584
+ edata.finish();
585
+ this.refresh(id);
586
+ return true;
587
+ }
588
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
589
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
590
+ collapseAll(parent) {
591
+ if (parent == null) parent = this;
592
+ if (typeof parent == "string") parent = this.get(parent);
593
+ if (parent.nodes == null) return false;
594
+ for (let i = 0; i < parent.nodes.length; i++) {
595
+ if (parent.nodes[i].expanded === true) parent.nodes[i].expanded = false;
596
+ if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.collapseAll(parent.nodes[i]);
597
+ }
598
+ this.refresh(parent.id);
599
+ return true;
600
+ }
601
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
602
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
603
+ expandAll(parent) {
604
+ if (parent == null) parent = this;
605
+ if (typeof parent == "string") parent = this.get(parent);
606
+ if (parent.nodes == null) return false;
607
+ for (let i = 0; i < parent.nodes.length; i++) {
608
+ if (parent.nodes[i].expanded === false) parent.nodes[i].expanded = true;
609
+ if (parent.nodes[i].nodes && parent.nodes[i].nodes.length > 0) this.expandAll(parent.nodes[i]);
610
+ }
611
+ this.refresh(parent.id);
612
+ }
613
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
614
+ expandParents(id) {
615
+ const node = this.get(id);
616
+ if (node == null) return false;
617
+ if (node.parent) {
618
+ if (!node.parent.expanded) {
619
+ node.parent.expanded = true;
620
+ this.refresh(node.parent.id);
621
+ }
622
+ this.expandParents(node.parent.id);
623
+ }
624
+ return true;
625
+ }
626
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
627
+ click(id, event) {
628
+ const nd = this.get(id);
629
+ if (nd == null) return;
630
+ if (nd.disabled || nd.group) {
631
+ const edata = this.trigger("click", { target: id, originalEvent: event, node: nd, object: nd });
632
+ edata.finish();
633
+ return;
634
+ }
635
+ const newNode = query2(this.box).find("#node_" + TsUtils.escapeId(id));
636
+ newNode.addClass("tsg-selected").find(".tsg-icon").addClass("tsg-icon-selected");
637
+ setTimeout(() => {
638
+ const edata = this.trigger("click", { target: id, originalEvent: event, node: nd, object: nd });
639
+ if (edata.isCancelled === true) {
640
+ newNode.removeClass("tsg-selected").find(".tsg-icon").removeClass("tsg-icon-selected");
641
+ return;
642
+ }
643
+ if (this.multi) {
644
+ const mev = event;
645
+ const isShift = mev?.shiftKey ?? false;
646
+ const isCtrl = (mev?.ctrlKey || mev?.metaKey) ?? false;
647
+ if (typeof this.selected == "string") {
648
+ this.selected = [this.selected];
649
+ }
650
+ if (isCtrl && !isShift) {
651
+ if (this.selected?.includes(id)) {
652
+ this.unselect(id);
653
+ return;
654
+ } else {
655
+ this.select(id);
656
+ }
657
+ } else if (!isCtrl && isShift) {
658
+ const chain = this.getChain();
659
+ const ind1 = Math.min(this.selected.map((sel) => chain.indexOf(sel)));
660
+ const ind2 = chain.indexOf(id);
661
+ for (let i = Math.min(ind1, ind2); i < chain.length && i <= Math.max(ind1, ind2); i++) {
662
+ const node = this.get(chain[i]);
663
+ if (!this.selected.includes(chain[i]) && node.hidden != true) {
664
+ this.select(chain[i]);
665
+ }
666
+ }
667
+ } else {
668
+ const ids = this.selected?.filter((sid) => sid != id && this.selected.includes(sid));
669
+ this.unselect(ids);
670
+ if (!this.selected?.includes(id)) {
671
+ this.select(id);
672
+ }
673
+ }
674
+ } else if (this.selected !== id) {
675
+ if (this.selected != null) this.unselect(this.selected);
676
+ this.select(id);
677
+ if (typeof nd.route == "string") {
678
+ let route = nd.route !== "" ? String("/" + nd.route).replace(/\/{2,}/g, "/") : "";
679
+ const info = TsUtils.parseRoute(route);
680
+ if (info.keys.length > 0) {
681
+ for (let k = 0; k < info.keys.length; k++) {
682
+ const routeKey = info.keys[k];
683
+ if (routeKey == null) continue;
684
+ if (this.routeData[routeKey.name] == null) continue;
685
+ route = route.replace(new RegExp(":" + routeKey.name, "g"), this.routeData[routeKey.name]);
686
+ }
687
+ }
688
+ setTimeout(() => {
689
+ window.location.hash = route;
690
+ }, 1);
691
+ }
692
+ if (this.flat) {
693
+ let _getItems2 = function(nodes) {
694
+ const items2 = nodes.map((it) => {
695
+ const items3 = it.nodes.length > 0 ? _getItems2(it.nodes) : null;
696
+ return { id: it.id, text: it.text, icon: it.icon, items: items3 };
697
+ });
698
+ return items2;
699
+ };
700
+ var _getItems = _getItems2;
701
+ const items = _getItems2(nd.nodes);
702
+ if (items.length > 0) {
703
+ this.flatMenu(newNode, items);
704
+ }
705
+ }
706
+ }
707
+ edata.finish();
708
+ }, 1);
709
+ }
710
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
711
+ flatMenu(el, items) {
712
+ const self = this;
713
+ const $el = query2(el).find(".tsg-node-data");
714
+ TsMenu.show({
715
+ // any: query().get(0) returns Node|Node[]; anchor is always HTMLElement in flat menu context
716
+ anchor: $el.get(0),
717
+ name: this.name + "_flat-menu",
718
+ items,
719
+ // class: 'tsg-dark',
720
+ position: "right|left",
721
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
722
+ onSelect(event) {
723
+ self.unselect();
724
+ self.click(event.detail.item.id, event.detail.originalEvent);
725
+ },
726
+ onHide(_event) {
727
+ self.unselect();
728
+ }
729
+ });
730
+ TsTooltip.hide(this.name + "_tooltip");
731
+ }
732
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
733
+ focus(event) {
734
+ const edata = this.trigger("focus", { target: this.name, originalEvent: event });
735
+ if (edata.isCancelled === true) return false;
736
+ this.hasFocus = true;
737
+ query2(this.box).find(".tsg-sidebar-body").addClass("tsg-focus");
738
+ setTimeout(() => {
739
+ const input = query2(this.box).find("#sidebar_" + this.name + "_focus").get(0);
740
+ if (document.activeElement != input) input.focus();
741
+ }, 10);
742
+ edata.finish();
743
+ }
744
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
745
+ blur(event) {
746
+ const edata = this.trigger("blur", { target: this.name, originalEvent: event });
747
+ if (edata.isCancelled === true) return false;
748
+ this.hasFocus = false;
749
+ query2(this.box).find(".tsg-sidebar-body").removeClass("tsg-focus");
750
+ edata.finish();
751
+ }
752
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
753
+ next(node, noSubs) {
754
+ if (node == null) return null;
755
+ const parent = node.parent;
756
+ const ind = this.get(node.id, true);
757
+ let nextNode = null;
758
+ if (node.expanded && node.nodes.length > 0 && noSubs !== true) {
759
+ const nd = node.nodes[0] ?? null;
760
+ if (nd == null) {
761
+ nextNode = null;
762
+ } else if (nd.hidden || nd.disabled || nd.group) {
763
+ nextNode = this.next(nd);
764
+ } else {
765
+ nextNode = nd;
766
+ }
767
+ } else {
768
+ if (parent && ind + 1 < parent.nodes.length) {
769
+ nextNode = parent.nodes[ind + 1] ?? null;
770
+ } else {
771
+ nextNode = this.next(parent, true);
772
+ }
773
+ }
774
+ if (nextNode != null && (nextNode.hidden || nextNode.disabled || nextNode.group)) nextNode = this.next(nextNode);
775
+ return nextNode;
776
+ }
777
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
778
+ prev(node) {
779
+ if (node == null) return null;
780
+ const parent = node.parent;
781
+ const ind = this.get(node.id, true);
782
+ const lastChild = (node2) => {
783
+ if (node2.expanded && node2.nodes.length > 0) {
784
+ const nd = node2.nodes[node2.nodes.length - 1] ?? null;
785
+ if (nd == null) return node2;
786
+ if (nd.hidden || nd.disabled || nd.group) return this.prev(nd);
787
+ else return lastChild(nd);
788
+ }
789
+ return node2;
790
+ };
791
+ const prevNodeSource = ind > 0 ? parent.nodes[ind - 1] : null;
792
+ let prevNode = ind > 0 && prevNodeSource != null ? lastChild(prevNodeSource) : parent;
793
+ if (prevNode != null && (prevNode.hidden || prevNode.disabled || prevNode.group)) prevNode = this.prev(prevNode);
794
+ return prevNode;
795
+ }
796
+ // returns ids of expanded elements as a flat array
797
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
798
+ getChain(nodes, options = {}) {
799
+ options.returnDisabled ??= false;
800
+ options.returnGroups ??= false;
801
+ const ids = [];
802
+ if (nodes == null) nodes = this.nodes;
803
+ nodes.forEach((node) => {
804
+ if (!node.disabled && !node.group || node.disabled && options.returnDisabled || node.group && options.returnGroups) {
805
+ ids.push(node.id);
806
+ }
807
+ if (Array.isArray(node.nodes) && node.expanded) {
808
+ ids.push(...this.getChain(node.nodes, options));
809
+ }
810
+ });
811
+ return ids;
812
+ }
813
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
814
+ keydown(event) {
815
+ const self = this;
816
+ const first = Array.isArray(this.selected) ? this.selected[0] : this.selected;
817
+ let nd = this.get(first);
818
+ if (this.keyboard !== true) return;
819
+ if (!nd) nd = this.nodes[0] ?? null;
820
+ if (event.keyCode == 27) {
821
+ const mv = this.last.move;
822
+ if (mv?.reorder && mv?.moved) {
823
+ mv.restore();
824
+ return;
825
+ }
826
+ }
827
+ const edata = this.trigger("keydown", { target: this.name, originalEvent: event });
828
+ if (edata.isCancelled === true) return;
829
+ if (event.keyCode == 13 || event.keyCode == 32) {
830
+ if (event.keyCode == 13 && this.editable && !event.ctrlKey && !event.metaKey) {
831
+ this.edit(first);
832
+ } else {
833
+ if (nd.nodes.length > 0) {
834
+ this.toggle(first);
835
+ }
836
+ }
837
+ }
838
+ if (event.keyCode == 37) {
839
+ if (nd.nodes.length > 0 && nd.expanded) {
840
+ this.collapse(first);
841
+ } else {
842
+ selectNode(nd.parent);
843
+ if (!nd.parent.group) this.collapse(nd.parent.id);
844
+ }
845
+ }
846
+ if (event.keyCode == 39) {
847
+ if ((nd.nodes.length > 0 || nd.plus) && !nd.expanded) this.expand(first);
848
+ }
849
+ if (event.keyCode == 38) {
850
+ if (this.get(first) == null) {
851
+ selectNode(this.nodes[0] || null);
852
+ } else {
853
+ selectNode(neighbor(nd, this.prev));
854
+ }
855
+ }
856
+ if (event.keyCode == 40) {
857
+ if (this.get(first) == null) {
858
+ selectNode(this.nodes[0] || null);
859
+ } else {
860
+ selectNode(neighbor(nd, this.next));
861
+ }
862
+ }
863
+ if ([13, 32, 37, 38, 39, 40].includes(event.keyCode)) {
864
+ if (event.preventDefault) event.preventDefault();
865
+ if (event.stopPropagation) event.stopPropagation();
866
+ }
867
+ edata.finish();
868
+ function selectNode(node, event2) {
869
+ if (node != null && !node.hidden && !node.disabled && !node.group) {
870
+ self.click(node.id, event2);
871
+ if (!self.inView(node.id)) self.scrollIntoView(node.id);
872
+ }
873
+ }
874
+ function neighbor(node, neighborFunc) {
875
+ node = neighborFunc.call(self, node);
876
+ while (node != null && (node.hidden || node.disabled)) {
877
+ if (node.group) break;
878
+ else node = neighborFunc(node);
879
+ }
880
+ return node;
881
+ }
882
+ }
883
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
884
+ inView(id) {
885
+ const item = query2(this.box).find("#node_" + TsUtils.escapeId(id)).get(0);
886
+ if (!item) {
887
+ return false;
888
+ }
889
+ const div = query2(this.box).find(".tsg-sidebar-body").get(0);
890
+ if (!div) return false;
891
+ if (item.offsetTop < div.scrollTop || item.offsetTop + item.clientHeight > div.clientHeight + div.scrollTop) {
892
+ return false;
893
+ }
894
+ return true;
895
+ }
896
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
897
+ scrollIntoView(id, instant) {
898
+ return new Promise((resolve) => {
899
+ if (id == null) id = Array.isArray(this.selected) ? this.selected[0] : this.selected;
900
+ const nd = this.get(id);
901
+ if (nd == null) return;
902
+ const item = query2(this.box).find("#node_" + TsUtils.escapeId(id)).get(0);
903
+ if (item) item.scrollIntoView({ block: "center", inline: "center", behavior: instant ? "auto" : "smooth" });
904
+ setTimeout(() => {
905
+ this.resize();
906
+ resolve();
907
+ }, instant ? 0 : 500);
908
+ });
909
+ }
910
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
911
+ dblClick(id, event) {
912
+ const nd = this.get(id);
913
+ const edata = this.trigger("dblClick", { target: id, originalEvent: event, object: nd });
914
+ if (edata.isCancelled === true) return;
915
+ if (this.editable) {
916
+ this.edit(id);
917
+ } else if (!this.flat) {
918
+ this.toggle(id);
919
+ }
920
+ edata.finish();
921
+ }
922
+ /**
923
+ * This is needed for not reorder
924
+ */
925
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
926
+ mouseDown(id, event) {
927
+ const self = this;
928
+ if (this.reorder) {
929
+ this.last.move = {
930
+ x: event.screenX,
931
+ y: event.screenY,
932
+ divX: 0,
933
+ divY: 0,
934
+ reorder: true,
935
+ moved: false
936
+ };
937
+ const mv = this.last.move;
938
+ const body = query2(this.box).find(".tsg-sidebar-body");
939
+ if (!mv.ghost) {
940
+ const node = query2(this.box).find(`#node_${TsUtils.escapeId(id)}`);
941
+ mv.offsetY = event.offsetY;
942
+ mv.target = id;
943
+ const nodeEl = node.get(0);
944
+ mv.pos = { top: nodeEl.offsetTop - 1, left: nodeEl.offsetLeft };
945
+ const clone = query2(node.find(".tsg-node-data").get(0).cloneNode(true));
946
+ mv.node = node;
947
+ mv.nodeSub = node.next();
948
+ body.append('<div id="sidebar_' + this.name + '_ghost" class="tsg-node tsg-ghost"></div>');
949
+ query2(this.box).find("#sidebar_" + this.name + "_ghost").append(clone);
950
+ mv.ghost = query2(this.box).find("#sidebar_" + this.name + "_ghost");
951
+ mv.ghost.css({ display: "none" });
952
+ mv.restore = () => {
953
+ mv.resetReorder();
954
+ this.refresh();
955
+ };
956
+ mv.resetReorder = () => {
957
+ this.last.move = null;
958
+ query2(this.box).find(`#sidebar_${this.name}_ghost`).remove();
959
+ query2(document).off(`.tsg-${this.name}-reorder`);
960
+ };
961
+ }
962
+ query2(document).on(`mousemove.tsg-${this.name}-reorder`, _mouseMove).on(`mouseup.tsg-${this.name}-reorder`, _mouseStop);
963
+ }
964
+ function _mouseMove(event2) {
965
+ if (!event2.target.tagName) {
966
+ return;
967
+ }
968
+ const mv = self.last.move;
969
+ mv.divX = event2.screenX - mv.x;
970
+ mv.divY = event2.screenY - mv.y;
971
+ if (Math.abs(mv.divX) <= 1 && Math.abs(mv.divY) <= 1) return;
972
+ if (self.reorder == true && mv.reorder && !mv.moved) {
973
+ const edata = self.trigger("dragStart", { target: mv.target, moved: true, node: self.get(mv.target), mv, originalEvent: event2 });
974
+ if (edata.isCancelled === true) {
975
+ mv.restore();
976
+ return;
977
+ }
978
+ const rect = mv.node.get(0).getBoundingClientRect();
979
+ mv.moved = true;
980
+ mv.node.html("").removeAttr("id", "data-id").addClass("tsg-reorder-empty").css({ height: rect.height + "px" });
981
+ if (mv.node.next().css("display") !== "none") {
982
+ const rect2 = mv.node.next().get(0).getBoundingClientRect();
983
+ mv.node.next().html('<div class="tsg-reorder-empty-sub"></div>').css({ height: rect2.height + "px" });
984
+ }
985
+ mv.ghost.css({ display: "block" });
986
+ edata.finish();
987
+ }
988
+ mv.ghost.css({
989
+ top: mv.pos.top + mv.divY + "px",
990
+ left: 0
991
+ });
992
+ const over = query2(event2.target).closest(".tsg-node, .tsg-node-group");
993
+ const id2 = over.attr("data-id");
994
+ if (query2(event2.target).hasClass("tsg-sidebar-body") && event2.layerY > 5 && !mv.append) {
995
+ const edata = self.trigger("dragOver", { target: mv.target, append: true, mv, originalEvent: event2 });
996
+ if (edata.isCancelled === true) {
997
+ return;
998
+ }
999
+ mv.ghost.before(mv.node);
1000
+ mv.ghost.before(mv.nodeSub);
1001
+ mv.append = true;
1002
+ mv.moveBefore = null;
1003
+ edata.finish();
1004
+ } else if (id2 != null && id2 != mv.moveBefore) {
1005
+ mv.append = false;
1006
+ mv.moveBefore = id2;
1007
+ const edata = self.trigger("dragOver", { target: mv.target, moveBefore: id2, mv, originalEvent: event2 });
1008
+ if (edata.isCancelled === true) {
1009
+ return;
1010
+ }
1011
+ const el = query2(self.box).find(`#node_${TsUtils.escapeId(id2)}`);
1012
+ el.before(mv.node);
1013
+ el.before(mv.nodeSub);
1014
+ edata.finish();
1015
+ }
1016
+ }
1017
+ function _mouseStop(event2) {
1018
+ const mv = self.last.move;
1019
+ mv.resetReorder();
1020
+ if (mv.moved) {
1021
+ if (mv.moveBefore != null && mv.target != mv.moveBefore || mv.append) {
1022
+ const edata = self.trigger("reorder", { target: mv.target, moveBefore: mv.moveBefore, append: mv.append, originalEvent: event2 });
1023
+ if (edata.isCancelled === true) {
1024
+ self.refresh();
1025
+ return;
1026
+ }
1027
+ const target = self.get(mv.target);
1028
+ const targetInd = target.parent.nodes.indexOf(target);
1029
+ const cut = target.parent.nodes.splice(targetInd, 1);
1030
+ if (mv.append) {
1031
+ self.nodes.push(...cut);
1032
+ cut.forEach((nd) => nd.parent = self);
1033
+ } else {
1034
+ const before = self.get(mv.moveBefore);
1035
+ const beforeInd = before.parent.nodes.indexOf(before);
1036
+ cut.forEach((nd) => nd.parent = before.parent);
1037
+ before.parent.nodes.splice(beforeInd, 0, ...cut);
1038
+ }
1039
+ self.refresh();
1040
+ edata.finish();
1041
+ } else {
1042
+ self.refresh();
1043
+ }
1044
+ }
1045
+ }
1046
+ }
1047
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1048
+ edit(id) {
1049
+ const self = this;
1050
+ const node = query2(this.box).find("#node_" + TsUtils.escapeId(id));
1051
+ const text = node.find(".tsg-node-text");
1052
+ const edata = this.trigger("edit", { target: id, el: node, textEl: text });
1053
+ if (edata.isCancelled === true) {
1054
+ return;
1055
+ }
1056
+ this.last.renaming = true;
1057
+ node.addClass("tsg-editing");
1058
+ text.addClass("tsg-focus").css("pointer-events", "all").attr("contenteditable", TsUtils.isFirefox ? "true" : "plaintext-only").on("blur.node-editing", (_event) => {
1059
+ setTimeout(_rename, 0);
1060
+ }).on("keydown.node-editing", (event) => {
1061
+ const kbdEvent = event;
1062
+ if (kbdEvent.keyCode == 13) _rename(kbdEvent);
1063
+ if (kbdEvent.keyCode == 27) _rename(kbdEvent, true);
1064
+ });
1065
+ text.get(0).focus();
1066
+ const original = text.text();
1067
+ TsUtils.setCursorPosition(text[0], 0, text.text().length);
1068
+ edata.finish();
1069
+ return text.get(0);
1070
+ function _rename(event, cancel) {
1071
+ const renameTo = text.text();
1072
+ node.removeClass("tsg-editing");
1073
+ text.removeClass("tsg-focus").css("pointer-events", "none").removeAttr("contenteditable").off(".node-editing");
1074
+ if (!cancel && self.last.renaming && original !== renameTo) {
1075
+ const edata2 = self.trigger("rename", { target: id, text_previous: original, text_new: renameTo, originalEvent: event });
1076
+ if (edata2.isCancelled === true) {
1077
+ text.text(original);
1078
+ self.last.renaming = false;
1079
+ self.focus();
1080
+ return;
1081
+ }
1082
+ self.set(id, { text: renameTo });
1083
+ edata2.finish();
1084
+ }
1085
+ if (cancel) {
1086
+ self.set(id, { text: original });
1087
+ }
1088
+ self.last.renaming = false;
1089
+ self.focus();
1090
+ }
1091
+ }
1092
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1093
+ contextMenu(id, event) {
1094
+ const nd = this.get(id);
1095
+ if (Array.isArray(this.selected)) {
1096
+ if (!this.selected.includes(id)) this.click(id);
1097
+ } else {
1098
+ if (id != this.selected) this.click(id);
1099
+ }
1100
+ const edata = this.trigger("contextMenu", { target: id, originalEvent: event, object: nd, allowOnDisabled: false });
1101
+ if (edata.isCancelled === true) return;
1102
+ if (nd.disabled && !edata.detail["allowOnDisabled"]) return;
1103
+ if (this["menu"].length > 0) {
1104
+ TsMenu.hide(this.name + "_menu");
1105
+ const menuAttach = TsMenu.show({
1106
+ name: this.name + "_menu",
1107
+ anchor: document.body,
1108
+ contextMenu: true,
1109
+ items: this["menu"],
1110
+ originalEvent: event
1111
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1112
+ });
1113
+ menuAttach?.select?.((evt) => {
1114
+ this.menuClick(id, evt.detail);
1115
+ });
1116
+ }
1117
+ if (event.preventDefault) event.preventDefault();
1118
+ edata.finish();
1119
+ }
1120
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1121
+ menuClick(itemId, detail = {}) {
1122
+ const edata = this.trigger("menuClick", { target: itemId, ...detail });
1123
+ if (edata.isCancelled === true) return;
1124
+ edata.finish();
1125
+ }
1126
+ goFlat() {
1127
+ const edata = this.trigger("flat", { goFlat: !this.flat });
1128
+ if (edata.isCancelled === true) return;
1129
+ this.flat = !this.flat;
1130
+ this.refresh();
1131
+ if (this.flat) {
1132
+ this.nodes.forEach((node) => {
1133
+ if (!node.group) {
1134
+ this.collapse(node.id);
1135
+ this.collapseAll(node.id);
1136
+ }
1137
+ });
1138
+ this.unselect();
1139
+ } else {
1140
+ this.nodes.forEach((node) => {
1141
+ if (!node.group) {
1142
+ this.expand(node.id);
1143
+ this.expandAll(node.id);
1144
+ }
1145
+ });
1146
+ }
1147
+ edata.finish();
1148
+ }
1149
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1150
+ render(box) {
1151
+ const time = Date.now();
1152
+ const obj = this;
1153
+ if (typeof box == "string") box = query2(box).get(0);
1154
+ const edata = this.trigger("render", { target: this.name, box: box ?? this.box });
1155
+ if (edata.isCancelled === true) return;
1156
+ if (box != null) {
1157
+ this.unmount();
1158
+ this.box = box;
1159
+ }
1160
+ if (!this.box) return;
1161
+ query2(this.box).attr("name", this.name).addClass("tsg-reset tsg-sidebar").html(`<div>
1162
+ <div class="tsg-sidebar-top"></div>
1163
+ <input id="sidebar_${this.name}_focus" ${this.tabIndex ? 'tabindex="' + this.tabIndex + '"' : ""}
1164
+ style="position: absolute; top: 0; right: 1px; width: 1px; z-index: -1; opacity: 0"
1165
+ ${TsUtils.isMobile ? "readonly" : ""}/>
1166
+ <div class="tsg-sidebar-body"></div>
1167
+ <div class="tsg-sidebar-bottom"></div>
1168
+ </div>`);
1169
+ const boxEl3 = query2(this.box).get(0);
1170
+ const rect = boxEl3.getBoundingClientRect();
1171
+ query2(this.box).find(":scope > div").css({
1172
+ width: rect.width + "px",
1173
+ height: rect.height + "px"
1174
+ });
1175
+ boxEl3.style.cssText += this.style;
1176
+ let kbd_timer;
1177
+ query2(this.box).find("#sidebar_" + this.name + "_focus").on("focus", function(event) {
1178
+ clearTimeout(kbd_timer);
1179
+ if (!obj.hasFocus) obj.focus(event);
1180
+ }).on("blur", function(event) {
1181
+ kbd_timer = setTimeout(() => {
1182
+ if (obj.hasFocus) {
1183
+ obj.blur(event);
1184
+ }
1185
+ }, 100);
1186
+ }).on("keydown", function(event) {
1187
+ const w2obj = TsUi[obj.name];
1188
+ w2obj?.keydown?.call(w2obj, event);
1189
+ });
1190
+ query2(this.box).off("mousedown").on("mousedown", function(event) {
1191
+ setTimeout(() => {
1192
+ if (["INPUT", "TEXTAREA", "SELECT"].indexOf(event.target?.tagName?.toUpperCase()) == -1) {
1193
+ const $input = query2(obj.box).find("#sidebar_" + obj.name + "_focus");
1194
+ const inputEl = $input.get(0);
1195
+ if (document.activeElement != inputEl && $input.length > 0) {
1196
+ inputEl?.focus();
1197
+ }
1198
+ }
1199
+ }, 1);
1200
+ });
1201
+ const flatHTML = `<div class="tsg-flat tsg-flat-${this.flat ? "right" : "left"}" ${this.flatButton == false ? 'style="display: none"' : ""}></div>`;
1202
+ if (this["topHTML"] !== "" || flatHTML !== "") {
1203
+ query2(this.box).find(".tsg-sidebar-top").html(this["topHTML"] + flatHTML);
1204
+ query2(this.box).find(".tsg-sidebar-body").css("top", query2(this.box).find(".tsg-sidebar-top").get(0)?.clientHeight + "px");
1205
+ query2(this.box).find(".tsg-flat").off("click").on("click", (_event) => {
1206
+ this.goFlat();
1207
+ });
1208
+ }
1209
+ if (this["bottomHTML"] !== "") {
1210
+ query2(this.box).find(".tsg-sidebar-bottom").html(this["bottomHTML"]);
1211
+ query2(this.box).find(".tsg-sidebar-body").css("bottom", query2(this.box).find(".tsg-sidebar-bottom").get(0)?.clientHeight + "px");
1212
+ }
1213
+ this.last.observeResize = new ResizeObserver(() => {
1214
+ this.resize();
1215
+ });
1216
+ this.last.observeResize.observe(this.box);
1217
+ edata.finish();
1218
+ this.refresh();
1219
+ return Date.now() - time;
1220
+ }
1221
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1222
+ update(id, options = {}) {
1223
+ const nd = this.get(id);
1224
+ let level;
1225
+ if (nd) {
1226
+ const $el = query2(this.box).find("#node_" + TsUtils.escapeId(nd.id));
1227
+ if (nd.group) {
1228
+ if (options.text) {
1229
+ nd.text = options.text;
1230
+ $el.find(".tsg-group-text").replace(typeof nd.text == "function" ? nd.text.call(this, nd) : '<span class="tsg-group-text">' + nd.text + "</span>");
1231
+ delete options.text;
1232
+ }
1233
+ if (options.class) {
1234
+ nd.class = options.class;
1235
+ level = $el.data("level");
1236
+ $el.get(0).className = "tsg-node-group tsg-level-" + level + (nd.class ? " " + nd.class : "");
1237
+ delete options.class;
1238
+ }
1239
+ if (options.style) {
1240
+ nd.style = options.style;
1241
+ const nextEl = $el.get(0).nextElementSibling;
1242
+ if (nextEl) nextEl.setAttribute("style", nd.style + ";" + (!nd.hidden && nd.expanded ? "" : "display: none;"));
1243
+ delete options.style;
1244
+ }
1245
+ } else {
1246
+ if (options.icon) {
1247
+ const $icon = $el.find(".tsg-node-image > span");
1248
+ if ($icon.length > 0) {
1249
+ nd.icon = options.icon;
1250
+ $icon[0].className = typeof nd.icon == "function" ? nd.icon.call(this, nd) : nd.icon;
1251
+ delete options.icon;
1252
+ }
1253
+ }
1254
+ if (options.count != null) {
1255
+ nd.count = options.count;
1256
+ let txt = nd.count ?? this["badge"]?.text;
1257
+ const style = this["badge"]?.style;
1258
+ const last = this.last.badge[nd.id];
1259
+ if (typeof txt == "function") txt = txt.call(this, nd, level);
1260
+ $el.find(".tsg-node-badge").html(txt).attr("style", `${style}; ${last?.style ?? ""}`);
1261
+ if ($el.find(".tsg-node-badge").length > 0) delete options.count;
1262
+ }
1263
+ if (options.class && $el.length > 0) {
1264
+ nd.class = options.class;
1265
+ level = $el.data("level");
1266
+ $el[0].className = "tsg-node tsg-level-" + level + (nd.selected ? " tsg-selected" : "") + (nd.disabled ? " tsg-disabled" : "") + (nd.class ? " " + nd.class : "");
1267
+ delete options.class;
1268
+ }
1269
+ if (options.text != null) {
1270
+ nd.text = options.text;
1271
+ $el.find(".tsg-node-text").html(typeof nd.text == "function" ? nd.text.call(this, nd) : nd.text);
1272
+ delete options.text;
1273
+ }
1274
+ if (options.style && $el.length > 0) {
1275
+ const $txt = $el.find(".tsg-node-text");
1276
+ nd.style = options.style;
1277
+ $txt[0].setAttribute("style", nd.style);
1278
+ delete options.style;
1279
+ }
1280
+ }
1281
+ }
1282
+ return options;
1283
+ }
1284
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1285
+ refresh(id, options = {}) {
1286
+ if (this.box == null) return;
1287
+ const body = query2(this.box).find(":scope > div > .tsg-sidebar-body").get(0);
1288
+ const { scrollTop, scrollLeft } = body ?? {};
1289
+ const time = Date.now();
1290
+ const edata = this.trigger("refresh", {
1291
+ target: id != null ? id : this.name,
1292
+ nodeId: id != null ? id : null,
1293
+ fullRefresh: id != null ? false : true
1294
+ });
1295
+ if (edata.isCancelled === true) return;
1296
+ if (this.flatButton == true) {
1297
+ query2(this.box).find(".tsg-sidebar-top .tsg-flat").show().removeClass("tsg-flat-left tsg-flat-right").addClass(` tsg-flat-${this.flat ? "right" : "left"}`);
1298
+ } else {
1299
+ query2(this.box).find(".tsg-sidebar-top .tsg-flat").hide();
1300
+ }
1301
+ const boxEl2 = query2(this.box).get(0);
1302
+ query2(this.box).find(":scope > div").removeClass("tsg-sidebar-flat").addClass(this.flat ? "tsg-sidebar-flat" : "").css({
1303
+ width: (boxEl2?.clientWidth ?? 0) + "px",
1304
+ height: (boxEl2?.clientHeight ?? 0) + "px"
1305
+ });
1306
+ if (this.nodes.length > 0 && this.nodes[0].parent == null) {
1307
+ const tmp = this.nodes;
1308
+ this.nodes = [];
1309
+ this.add(this, tmp);
1310
+ }
1311
+ const obj = this;
1312
+ let node;
1313
+ let nodeSubId;
1314
+ if (id == null) {
1315
+ node = this;
1316
+ nodeSubId = ".tsg-sidebar-body";
1317
+ } else {
1318
+ node = this.get(id);
1319
+ if (node == null) return;
1320
+ nodeSubId = "#node_" + TsUtils.escapeId(node.id) + "_sub";
1321
+ }
1322
+ const nodeId = "#node_" + TsUtils.escapeId(node.id);
1323
+ let nodeHTML;
1324
+ if (node !== this) {
1325
+ nodeHTML = getNodeHTML(node);
1326
+ query2(this.box).find(nodeId).before('<div id="sidebar_' + this.name + '_tmp"></div>');
1327
+ query2(this.box).find(nodeId).remove();
1328
+ query2(this.box).find(nodeSubId).remove();
1329
+ query2(this.box).find("#sidebar_" + this.name + "_tmp").before(nodeHTML);
1330
+ query2(this.box).find("#sidebar_" + this.name + "_tmp").remove();
1331
+ }
1332
+ const div = query2(this.box).find(":scope > div").get(0);
1333
+ const scroll = {
1334
+ top: div?.scrollTop,
1335
+ left: div?.scrollLeft
1336
+ };
1337
+ const cnt = node == this ? query2(this.box).find(":scope > div > .tsg-sidebar-body") : query2(body).find(nodeSubId);
1338
+ cnt.html("");
1339
+ for (let i = 0; i < node.nodes.length; i++) {
1340
+ const subNode = node.nodes[i];
1341
+ nodeHTML = getNodeHTML(subNode);
1342
+ cnt.append(nodeHTML);
1343
+ if (subNode.nodes.length !== 0) {
1344
+ this.refresh(subNode.id, { recursive: true });
1345
+ } else {
1346
+ const edata2 = this.trigger("refresh", { target: subNode.id });
1347
+ if (edata2.isCancelled === true) return;
1348
+ edata2.finish();
1349
+ }
1350
+ }
1351
+ if (div) {
1352
+ div.scrollTop = scroll.top ?? 0;
1353
+ div.scrollLeft = scroll.left ?? 0;
1354
+ }
1355
+ if (!options.recursive) {
1356
+ const els = query2(this.box).find(`${nodeId}, ${nodeId} .tsg-eaction, ${nodeSubId} .tsg-eaction`);
1357
+ TsUtils.bindEvents(els, this);
1358
+ query2(body).prop({ scrollLeft, scrollTop });
1359
+ }
1360
+ edata.finish();
1361
+ return Date.now() - time;
1362
+ function getNodeHTML(nd) {
1363
+ let html = "";
1364
+ let icon = nd.icon;
1365
+ if (icon == null) icon = obj.icon;
1366
+ let tmp = nd.parent;
1367
+ let level = 0;
1368
+ while (tmp && tmp.parent != null) {
1369
+ tmp = tmp.parent;
1370
+ level++;
1371
+ }
1372
+ if (nd.caption != null && nd.text == null) nd.text = nd.caption;
1373
+ if (nd.caption != null) {
1374
+ console.log("NOTICE: sidebar node.caption property is deprecated, please use node.text. Node -> ", nd);
1375
+ nd.text = nd.caption;
1376
+ }
1377
+ if (Array.isArray(nd.nodes) && nd.nodes.length > 0) nd.collapsible = true;
1378
+ if (nd.group) {
1379
+ let text = TsUtils.lang(typeof nd.text == "function" ? nd.text.call(obj, nd, level) : nd.text);
1380
+ if (String(text).substr(0, 5) != "<span") {
1381
+ text = `<span class="tsg-group-text">${text}</span>`;
1382
+ }
1383
+ html = `
1384
+ <div id="node_${nd.id}" data-id="${nd.id}" data-level="${level}" style="${nd.hidden ? "display: none" : ""}"
1385
+ class="tsg-node-group tsg-level-${level} ${nd.class ? nd.class : ""} tsg-eaction"
1386
+ data-click="toggle|${nd.id}"
1387
+ data-contextmenu="contextMenu|${nd.id}|event"
1388
+ data-mouseenter="showPlus|this|inherit"
1389
+ data-mouseleave="showPlus|this|transparent">
1390
+ ${nd.groupShowHide && nd.collapsible ? `<span>${!nd.hidden && nd.expanded ? TsUtils.lang("Hide") : TsUtils.lang("Show")}</span>` : "<span></span>"} ${text}
1391
+ </div>
1392
+ <div class="tsg-node-sub" id="node_${nd.id}_sub" style="${nd.style}; ${!nd.hidden && nd.expanded ? "" : "display: none;"}">
1393
+ </div>`;
1394
+ if (obj.flat) {
1395
+ html = `
1396
+ <div class="tsg-node-group" id="node_${nd.id}" data-id="${nd.id}"><span>&#160;</span></div>
1397
+ <div id="node_${nd.id}_sub" style="${nd.style}; ${!nd.hidden && nd.expanded ? "" : "display: none;"}"></div>`;
1398
+ }
1399
+ } else {
1400
+ if (nd.selected && !nd.disabled) {
1401
+ if (obj.multi) {
1402
+ obj.selected ??= [];
1403
+ if (!obj.selected.includes(nd.id)) {
1404
+ obj.selected.push(nd.id);
1405
+ }
1406
+ } else {
1407
+ obj.selected = nd.id;
1408
+ }
1409
+ }
1410
+ let image = "";
1411
+ if (icon) {
1412
+ if (icon instanceof Object) {
1413
+ const text2 = typeof icon.text == "function" ? icon.text.call(obj, nd, level) ?? "" : icon.text;
1414
+ image = `
1415
+ <div class="tsg-node-image tsg-eaction" style="${obj.icon.style ?? ""}; pointer-events: all"
1416
+ data-mouseEnter="mouseAction|Enter|this|${nd.id}|event|icon"
1417
+ data-mouseLeave="mouseAction|Leave|this|${nd.id}|event|icon"
1418
+ data-click="mouseAction|click|this|${nd.id}|event|icon">
1419
+ ${text2}
1420
+ </div>
1421
+ `;
1422
+ } else {
1423
+ image = `
1424
+ <div class="tsg-node-image">
1425
+ <span class="${typeof icon == "function" ? icon.call(obj, nd, level) : icon}"></span>
1426
+ </div>`;
1427
+ }
1428
+ }
1429
+ let expand = "";
1430
+ let counts = "";
1431
+ if (obj["badge"] != null || nd.count != null) {
1432
+ let txt = nd.count ?? obj["badge"]?.text;
1433
+ const style = obj["badge"]?.style;
1434
+ const last = obj.last.badge[nd.id];
1435
+ if (typeof txt == "function") txt = txt.call(obj, nd, level);
1436
+ if (txt || txt === 0) {
1437
+ counts = `
1438
+ <div class="tsg-node-badge tsg-eaction ${nd.count != null ? "tsg-node-count" : ""} ${last?.className ?? ""}"
1439
+ style="${style ?? ""};${last?.style ?? ""}"
1440
+ data-mouseEnter="mouseAction|Enter|this|${nd.id}|event|badge"
1441
+ data-mouseLeave="mouseAction|Leave|this|${nd.id}|event|badge"
1442
+ data-click="mouseAction|click|this|${nd.id}|event|badge"
1443
+ >
1444
+ ${txt}
1445
+ </div>`;
1446
+ }
1447
+ }
1448
+ const classes = ["tsg-node", `tsg-level-${level}`, "tsg-eaction"];
1449
+ if (nd.selected) classes.push("tsg-selected");
1450
+ if (nd.disabled) classes.push("tsg-disabled");
1451
+ if (nd.class) classes.push(nd.class);
1452
+ if (nd.collapsible === true) {
1453
+ const toggleClasses = ["tsg-sb-toggle", "tsg-eaction", nd.expanded ? "tsg-expanded" : "tsg-collapsed"];
1454
+ if (obj["toggleAlign"] == "left") toggleClasses.push("tsg-left-toggle");
1455
+ expand = `<div class="${toggleClasses.join(" ")}" data-click="toggle|${nd.id}"><span></span></div>`;
1456
+ classes.push("tsg-has-children");
1457
+ }
1458
+ const text = TsUtils.lang(typeof nd.text == "function" ? nd.text.call(obj, nd, level) : nd.text);
1459
+ let nodeOffset = nd.parent?.childOffset ?? 0;
1460
+ if (level === 0 && nd.collapsible === true && obj["toggleAlign"] == "left") {
1461
+ nodeOffset += 12;
1462
+ }
1463
+ html = `
1464
+ <div id="node_${nd.id}" class="${classes.join(" ")}" data-id="${nd.id}" data-level="${level}"
1465
+ style="${nd.hidden ? "display: none;" : ""}"
1466
+ data-click="click|${nd.id}|event"
1467
+ data-dblclick="dblClick|${nd.id}|event"
1468
+ data-mouseDown="mouseDown|${nd.id}|event"
1469
+ data-contextmenu="contextMenu|${nd.id}|event"
1470
+ data-mouseEnter="mouseAction|Enter|this|${nd.id}|event"
1471
+ data-mouseLeave="mouseAction|Leave|this|${nd.id}|event"
1472
+ >
1473
+ ${obj["handle"].text ? `<div class="tsg-node-handle tsg-eaction" style="width: ${obj["handle"].width}px; ${obj["handle"].style}"
1474
+ data-mouseEnter="mouseAction|Enter|this|${nd.id}|event|handle"
1475
+ data-mouseLeave="mouseAction|Leave|this|${nd.id}|event|handle"
1476
+ data-click="mouseAction|click|this|${nd.id}|event|handle"
1477
+ >
1478
+ ${typeof obj["handle"].text == "function" ? obj["handle"].text.call(obj, nd, level) ?? "" : obj["handle"].text}
1479
+ </div>` : ""}
1480
+ <div class="tsg-node-data" style="margin-left: ${level * obj["levelPadding"] + nodeOffset + obj["handle"].width}px">
1481
+ ${expand} ${image} ${counts}
1482
+ <div class="tsg-node-text ${!image ? "no-icon" : ""}" style="${nd.style || ""}">${text}</div>
1483
+ </div>
1484
+ </div>
1485
+ <div class="tsg-node-sub" id="node_${nd.id}_sub" style="${nd.style}; ${!nd.hidden && nd.expanded ? "" : "display: none;"}"></div>`;
1486
+ if (obj.flat) {
1487
+ html = `
1488
+ <div id="node_${nd.id}" class="${classes.join(" ")} tsg-node-flat" data-id="${nd.id}" style="${nd.hidden ? "display: none;" : ""}"
1489
+ data-click="click|${nd.id}|event"
1490
+ data-dblclick="dblClick|${nd.id}|event"
1491
+ data-contextmenu="contextMenu|${nd.id}|event"
1492
+ data-mouseEnter="mouseAction|Enter|this|${nd.id}|event|tooltip"
1493
+ data-mouseLeave="mouseAction|Leave|this|${nd.id}|event|tooltip"
1494
+ >
1495
+ <div class="tsg-node-data">${image}</div>
1496
+ </div>
1497
+ <div class="tsg-node-sub" id="node_${nd.id}_sub" style="${nd.style}; ${!nd.hidden && nd.expanded ? "" : "display: none;"}"></div>`;
1498
+ }
1499
+ }
1500
+ return html;
1501
+ }
1502
+ }
1503
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1504
+ mouseAction(action, anchor, nodeId, event, type) {
1505
+ let edata;
1506
+ const node = this.get(nodeId);
1507
+ if (type == null) {
1508
+ edata = this.trigger("mouse" + action, { target: node.id, node, originalEvent: event });
1509
+ }
1510
+ if (type == "tooltip") {
1511
+ const text = TsUtils.lang(typeof node.text == "function" ? node.text.call(this, node) : node.text);
1512
+ let tooltip = text + (node.count != null ? ' - <span class="tsg-node-badge tsg-node-count">' + node.count + "</span>" : "");
1513
+ if (action == "Leave" || this.selected == node.id) tooltip = "";
1514
+ this.tooltip(anchor, tooltip);
1515
+ }
1516
+ if (type == "handle") {
1517
+ if (action == "click") {
1518
+ const onClick = this["handle"].onClick;
1519
+ if (typeof onClick == "function") {
1520
+ onClick.call(this, node, event);
1521
+ }
1522
+ } else {
1523
+ let tooltip = this["handle"].tooltip;
1524
+ if (typeof tooltip == "function") {
1525
+ tooltip = tooltip.call(this, node, event);
1526
+ }
1527
+ if (action == "Leave") tooltip = "";
1528
+ this.otherTooltip(anchor, tooltip);
1529
+ }
1530
+ }
1531
+ if (type == "icon") {
1532
+ if (action == "click") {
1533
+ const onClick = this.icon.onClick;
1534
+ if (typeof onClick == "function") {
1535
+ onClick.call(this, node, event);
1536
+ }
1537
+ } else {
1538
+ let tooltip = this.icon.tooltip;
1539
+ if (typeof tooltip == "function") {
1540
+ tooltip = tooltip.call(this, node, event);
1541
+ }
1542
+ if (action == "Leave") tooltip = "";
1543
+ this.otherTooltip(anchor, tooltip);
1544
+ }
1545
+ }
1546
+ if (type == "badge") {
1547
+ if (action == "click") {
1548
+ const onClick = this["badge"]?.onClick;
1549
+ if (typeof onClick == "function") {
1550
+ onClick.call(this, node, event);
1551
+ }
1552
+ } else {
1553
+ let tooltip = this["badge"]?.tooltip;
1554
+ if (typeof tooltip == "function") {
1555
+ tooltip = tooltip.call(this, node, event);
1556
+ }
1557
+ if (action == "Leave") tooltip = "";
1558
+ this.otherTooltip(anchor, tooltip);
1559
+ }
1560
+ }
1561
+ edata?.finish();
1562
+ }
1563
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1564
+ tooltip(el, text) {
1565
+ const $el = query2(el).find(".tsg-node-data");
1566
+ if (text !== "") {
1567
+ TsTooltip.show({
1568
+ // any: query().get(0) returns Node|Node[]; sidebar node-data element is always HTMLElement
1569
+ anchor: $el.get(0),
1570
+ name: this.name + "_tooltip",
1571
+ html: text,
1572
+ position: "right|left"
1573
+ });
1574
+ } else {
1575
+ TsTooltip.hide(this.name + "_tooltip");
1576
+ }
1577
+ }
1578
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1579
+ otherTooltip(el, text) {
1580
+ if (text !== "") {
1581
+ TsTooltip.show({
1582
+ anchor: el,
1583
+ name: this.name + "_tooltip",
1584
+ html: text,
1585
+ position: "top|bottom"
1586
+ });
1587
+ } else {
1588
+ TsTooltip.hide(this.name + "_tooltip");
1589
+ }
1590
+ }
1591
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1592
+ showPlus(el, color) {
1593
+ query2(el).find("span:nth-child(1)").css("color", color);
1594
+ }
1595
+ resize() {
1596
+ const time = Date.now();
1597
+ const edata = this.trigger("resize", { target: this.name });
1598
+ if (edata.isCancelled === true) return;
1599
+ if (this.box != null) {
1600
+ const boxEl = query2(this.box).get(0);
1601
+ const rect = boxEl.getBoundingClientRect();
1602
+ query2(this.box).css("overflow", "hidden");
1603
+ query2(this.box).find(":scope > div").css({
1604
+ width: rect.width + "px",
1605
+ height: rect.height + "px"
1606
+ });
1607
+ }
1608
+ edata.finish();
1609
+ return Date.now() - time;
1610
+ }
1611
+ destroy() {
1612
+ const edata = this.trigger("destroy", { target: this.name });
1613
+ if (edata.isCancelled === true) return;
1614
+ if (query2(this.box).find(".tsg-sidebar-body").length > 0) {
1615
+ this.unmount();
1616
+ }
1617
+ delete TsUi[this.name];
1618
+ edata.finish();
1619
+ }
1620
+ unmount() {
1621
+ super.unmount();
1622
+ this.last.observeResize?.disconnect();
1623
+ }
1624
+ // any: callback parameter — caller signature varies; TsSidebar node tree shape is user-defined at runtime
1625
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1626
+ lock(msg, showSpinner) {
1627
+ TsUtils.lock(this.box, msg, showSpinner);
1628
+ }
1629
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1630
+ unlock(speed) {
1631
+ TsUtils.unlock(this.box, speed);
1632
+ }
1633
+ };
1634
+
1635
+ export {
1636
+ TsSidebar
1637
+ };
1638
+ //# sourceMappingURL=chunk-BIB3X2TW.js.map