tree-element 0.2.0 → 0.3.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 (121) hide show
  1. package/README.md +12 -4
  2. package/lib/animation.d.ts +2 -2
  3. package/lib/animation.d.ts.map +1 -1
  4. package/lib/animation.js +13 -9
  5. package/lib/animation.js.map +1 -1
  6. package/lib/dataLoader.d.ts +1 -0
  7. package/lib/dataLoader.d.ts.map +1 -1
  8. package/lib/dataLoader.js +8 -0
  9. package/lib/dataLoader.js.map +1 -1
  10. package/lib/dragAndDropHandler/dragElement.d.ts.map +1 -1
  11. package/lib/dragAndDropHandler/dragElement.js +2 -1
  12. package/lib/dragAndDropHandler/dragElement.js.map +1 -1
  13. package/lib/dragAndDropHandler/index.d.ts.map +1 -1
  14. package/lib/dragAndDropHandler/index.js +56 -65
  15. package/lib/dragAndDropHandler/index.js.map +1 -1
  16. package/lib/dragAndDropHandler/iterateVisibleNodes.d.ts.map +1 -1
  17. package/lib/dragAndDropHandler/iterateVisibleNodes.js +16 -15
  18. package/lib/dragAndDropHandler/iterateVisibleNodes.js.map +1 -1
  19. package/lib/elementsRenderer.d.ts +5 -1
  20. package/lib/elementsRenderer.d.ts.map +1 -1
  21. package/lib/elementsRenderer.js +62 -39
  22. package/lib/elementsRenderer.js.map +1 -1
  23. package/lib/events.d.ts +44 -11
  24. package/lib/events.d.ts.map +1 -1
  25. package/lib/index.d.ts +31 -8
  26. package/lib/index.d.ts.map +1 -1
  27. package/lib/index.js +162 -122
  28. package/lib/index.js.map +1 -1
  29. package/lib/keyHandler.d.ts +11 -5
  30. package/lib/keyHandler.d.ts.map +1 -1
  31. package/lib/keyHandler.js +87 -33
  32. package/lib/keyHandler.js.map +1 -1
  33. package/lib/methodTypes.d.ts +2 -2
  34. package/lib/methodTypes.d.ts.map +1 -1
  35. package/lib/mouseHandler.d.ts +1 -1
  36. package/lib/mouseHandler.d.ts.map +1 -1
  37. package/lib/mouseHandler.js +10 -7
  38. package/lib/mouseHandler.js.map +1 -1
  39. package/lib/node.d.ts +45 -15
  40. package/lib/node.d.ts.map +1 -1
  41. package/lib/node.js +136 -139
  42. package/lib/node.js.map +1 -1
  43. package/lib/nodeElement/folderElement.d.ts +1 -1
  44. package/lib/nodeElement/folderElement.d.ts.map +1 -1
  45. package/lib/nodeElement/folderElement.js +46 -57
  46. package/lib/nodeElement/folderElement.js.map +1 -1
  47. package/lib/nodeElement/ghostDropHint.d.ts.map +1 -1
  48. package/lib/nodeElement/ghostDropHint.js +8 -4
  49. package/lib/nodeElement/ghostDropHint.js.map +1 -1
  50. package/lib/nodeElement/index.d.ts.map +1 -1
  51. package/lib/nodeElement/index.js +6 -6
  52. package/lib/nodeElement/index.js.map +1 -1
  53. package/lib/nodeUtils.d.ts.map +1 -1
  54. package/lib/nodeUtils.js +1 -1
  55. package/lib/nodeUtils.js.map +1 -1
  56. package/lib/options.d.ts +19 -3
  57. package/lib/options.d.ts.map +1 -1
  58. package/lib/requestUrl.d.ts.map +1 -1
  59. package/lib/requestUrl.js +2 -11
  60. package/lib/requestUrl.js.map +1 -1
  61. package/lib/saveStateHandler.d.ts.map +1 -1
  62. package/lib/saveStateHandler.js +21 -41
  63. package/lib/saveStateHandler.js.map +1 -1
  64. package/lib/scrollHandler/containerScrollParent.d.ts.map +1 -1
  65. package/lib/scrollHandler/containerScrollParent.js +3 -8
  66. package/lib/scrollHandler/containerScrollParent.js.map +1 -1
  67. package/lib/scrollHandler/createScrollParent.d.ts.map +1 -1
  68. package/lib/scrollHandler/createScrollParent.js +4 -5
  69. package/lib/scrollHandler/createScrollParent.js.map +1 -1
  70. package/lib/scrollHandler/documentScrollParent.d.ts.map +1 -1
  71. package/lib/scrollHandler/documentScrollParent.js +3 -9
  72. package/lib/scrollHandler/documentScrollParent.js.map +1 -1
  73. package/lib/scrollHandler/scrollParent.d.ts.map +1 -1
  74. package/lib/scrollHandler/scrollParent.js +19 -17
  75. package/lib/scrollHandler/scrollParent.js.map +1 -1
  76. package/lib/selectNodeHandler.d.ts +3 -1
  77. package/lib/selectNodeHandler.d.ts.map +1 -1
  78. package/lib/selectNodeHandler.js +27 -37
  79. package/lib/selectNodeHandler.js.map +1 -1
  80. package/lib/setDefaultOptions.d.ts.map +1 -1
  81. package/lib/setDefaultOptions.js +11 -10
  82. package/lib/setDefaultOptions.js.map +1 -1
  83. package/lib/util.d.ts.map +1 -1
  84. package/lib/util.js +1 -1
  85. package/lib/util.js.map +1 -1
  86. package/lib/version.d.ts +1 -1
  87. package/lib/version.js +1 -1
  88. package/lib/version.js.map +1 -1
  89. package/package.json +42 -33
  90. package/src/animation.ts +13 -11
  91. package/src/dataLoader.ts +11 -0
  92. package/src/dragAndDropHandler/dragElement.ts +2 -1
  93. package/src/dragAndDropHandler/index.ts +70 -75
  94. package/src/dragAndDropHandler/iterateVisibleNodes.ts +18 -16
  95. package/src/elementsRenderer.ts +76 -46
  96. package/src/events.ts +44 -11
  97. package/src/index.ts +210 -150
  98. package/src/keyHandler.ts +95 -41
  99. package/src/methodTypes.ts +3 -3
  100. package/src/mouseHandler.ts +10 -7
  101. package/src/node.ts +155 -148
  102. package/src/nodeElement/folderElement.ts +54 -63
  103. package/src/nodeElement/ghostDropHint.ts +4 -2
  104. package/src/nodeElement/index.ts +9 -15
  105. package/src/nodeUtils.ts +1 -1
  106. package/src/options.ts +19 -3
  107. package/src/requestUrl.ts +4 -11
  108. package/src/saveStateHandler.ts +29 -43
  109. package/src/scrollHandler/containerScrollParent.ts +3 -9
  110. package/src/scrollHandler/createScrollParent.ts +1 -2
  111. package/src/scrollHandler/documentScrollParent.ts +5 -11
  112. package/src/scrollHandler/scrollParent.ts +29 -25
  113. package/src/selectNodeHandler.ts +34 -38
  114. package/src/setDefaultOptions.ts +19 -10
  115. package/src/util.ts +1 -2
  116. package/src/version.ts +1 -1
  117. package/tree_element.css +87 -69
  118. package/tree_element.debug.js +706 -639
  119. package/tree_element.debug.js.map +1 -1
  120. package/tree_element.js +2 -2
  121. package/tree_element.js.map +1 -1
package/src/node.ts CHANGED
@@ -40,44 +40,67 @@ type IterateCallback = (node: Node, level: number) => boolean;
40
40
  * :::
41
41
  */
42
42
  export class Node {
43
- /** @hidden */
43
+ /**
44
+ @hidden
45
+ */
44
46
  [key: string]: unknown;
45
47
 
46
- /** The child nodes. */
48
+ /**
49
+ The child nodes.
50
+ */
47
51
  public children: Node[];
48
52
  /** The `li` element, once the node is rendered. Nodes inside a closed
49
53
  * folder are rendered when the folder is opened. */
50
54
  public element?: HTMLElement;
51
- /** The id from the node data. */
55
+ /**
56
+ The id from the node data.
57
+ */
52
58
  public id?: NodeId;
53
- /** @hidden */
59
+ /**
60
+ @hidden
61
+ */
54
62
  public idMapping?: Map<NodeId, Node>;
55
- /** Whether the node's children are being fetched. */
63
+ /**
64
+ Whether the node's children are being fetched.
65
+ */
56
66
  public is_loading?: boolean;
57
- /** Whether the folder is open. */
67
+ /**
68
+ Whether the folder is open.
69
+ */
58
70
  public is_open?: boolean;
59
- /** Whether the node data had an empty `children` array. */
71
+ /**
72
+ Whether the node data had an empty `children` array.
73
+ */
60
74
  public isEmptyFolder: boolean;
61
- /** Whether the children still have to be fetched. */
62
- public load_on_demand: boolean;
63
- /** The label. Also settable from the `label` key in node data. */
64
- public name: string;
65
- /** @hidden */
75
+ /**
76
+ Whether the children still have to be fetched.
77
+ */
78
+ public load_on_demand = false;
79
+ /**
80
+ The label. Also settable from the `label` key in node data.
81
+ */
82
+ public name = "";
83
+ /**
84
+ @hidden
85
+ */
66
86
  public nodeClass?: typeof Node;
67
- /** The parent; `null` for the root node. */
87
+ /**
88
+ The parent; `null` for the root node.
89
+ */
68
90
  public parent: Node | null;
69
- /** The root node. */
91
+ /**
92
+ The root node.
93
+ */
70
94
  public tree?: Node;
71
95
 
72
- /** @hidden */
96
+ /**
97
+ @hidden
98
+ */
73
99
  constructor(
74
100
  nodeData: NodeData | null = null,
75
101
  isRoot = false,
76
102
  nodeClass = Node,
77
103
  ) {
78
- this.name = "";
79
- this.load_on_demand = false;
80
-
81
104
  this.isEmptyFolder =
82
105
  nodeData != null &&
83
106
  isNodeRecordWithChildren(nodeData) &&
@@ -106,9 +129,7 @@ export class Node {
106
129
  * @group Changing the tree
107
130
  */
108
131
  public addAfter(nodeInfo: NodeData): Node | null {
109
- if (!this.parent) {
110
- return null;
111
- } else {
132
+ if (this.parent) {
112
133
  const node = this.createNode(nodeInfo);
113
134
 
114
135
  const childIndex = this.parent.getChildIndex(this);
@@ -117,6 +138,7 @@ export class Node {
117
138
  node.loadChildrenFromData(nodeInfo);
118
139
  return node;
119
140
  }
141
+ return null;
120
142
  }
121
143
 
122
144
  /**
@@ -126,9 +148,7 @@ export class Node {
126
148
  * @group Changing the tree
127
149
  */
128
150
  public addBefore(nodeInfo: NodeData): Node | null {
129
- if (!this.parent) {
130
- return null;
131
- } else {
151
+ if (this.parent) {
132
152
  const node = this.createNode(nodeInfo);
133
153
 
134
154
  const childIndex = this.parent.getChildIndex(this);
@@ -137,6 +157,7 @@ export class Node {
137
157
  node.loadChildrenFromData(nodeInfo);
138
158
  return node;
139
159
  }
160
+ return null;
140
161
  }
141
162
 
142
163
  /**
@@ -160,7 +181,9 @@ export class Node {
160
181
  node.setParent(this);
161
182
  }
162
183
 
163
- /** @hidden */
184
+ /**
185
+ @hidden
186
+ */
164
187
  public addNodeToIndex(node: Node): void {
165
188
  if (node.id != null) {
166
189
  this.idMapping?.set(node.id, node);
@@ -174,9 +197,7 @@ export class Node {
174
197
  * @group Changing the tree
175
198
  */
176
199
  public addParent(nodeInfo: NodeData): Node | null {
177
- if (!this.parent) {
178
- return null;
179
- } else {
200
+ if (this.parent) {
180
201
  const newParent = this.createNode(nodeInfo);
181
202
 
182
203
  if (this.tree) {
@@ -192,6 +213,7 @@ export class Node {
192
213
  originalParent.addChild(newParent);
193
214
  return newParent;
194
215
  }
216
+ return null;
195
217
  }
196
218
 
197
219
  /**
@@ -265,20 +287,22 @@ export class Node {
265
287
  for (const k in node) {
266
288
  if (
267
289
  [
268
- "parent",
269
290
  "children",
270
291
  "element",
271
292
  "idMapping",
293
+ "isEmptyFolder",
272
294
  "load_on_demand",
273
295
  "nodeClass",
296
+ "parent",
274
297
  "tree",
275
- "isEmptyFolder",
276
- ].indexOf(k) === -1 &&
277
- Object.prototype.hasOwnProperty.call(node, k)
298
+ ].includes(k) ||
299
+ !Object.prototype.hasOwnProperty.call(node, k)
278
300
  ) {
279
- const v = node[k];
280
- tmpNode[k] = v;
301
+ continue;
281
302
  }
303
+
304
+ const v = node[k];
305
+ tmpNode[k] = v;
282
306
  }
283
307
 
284
308
  if (node.hasChildren()) {
@@ -289,11 +313,7 @@ export class Node {
289
313
  });
290
314
  };
291
315
 
292
- if (includeParent) {
293
- return getDataFromNodes([this]);
294
- } else {
295
- return getDataFromNodes(this.children);
296
- }
316
+ return getDataFromNodes(includeParent ? [this] : this.children);
297
317
  }
298
318
 
299
319
  /**
@@ -303,17 +323,14 @@ export class Node {
303
323
  * @group Moving around the tree
304
324
  */
305
325
  public getLastChild(): Node | null {
306
- if (!this.hasChildren()) {
307
- return null;
308
- } else {
326
+ if (this.hasChildren()) {
309
327
  const lastChild = this.children[this.children.length - 1] as Node;
310
328
 
311
- if (!(lastChild.hasChildren() && lastChild.is_open)) {
312
- return lastChild;
313
- } else {
314
- return lastChild.getLastChild();
315
- }
329
+ return lastChild.hasChildren() && lastChild.is_open
330
+ ? lastChild.getLastChild()
331
+ : lastChild;
316
332
  }
333
+ return null;
317
334
  }
318
335
 
319
336
  /**
@@ -323,7 +340,7 @@ export class Node {
323
340
  */
324
341
  public getLevel(): number {
325
342
  let level = 0;
326
- let node: Node = this; // eslint-disable-line @typescript-eslint/no-this-alias
343
+ let node: Node = this; // eslint-disable-line @typescript-eslint/no-this-alias, unicorn/no-this-assignment
327
344
 
328
345
  while (node.parent) {
329
346
  level += 1;
@@ -342,17 +359,13 @@ export class Node {
342
359
  public getNextNode(includeChildren = true): Node | null {
343
360
  if (includeChildren && this.hasChildren()) {
344
361
  return this.children[0] ?? null;
345
- } else if (!this.parent) {
346
- return null;
347
- } else {
362
+ }
363
+ if (this.parent) {
348
364
  const nextSibling = this.getNextSibling();
349
365
 
350
- if (nextSibling) {
351
- return nextSibling;
352
- } else {
353
- return this.parent.getNextNode(false);
354
- }
366
+ return nextSibling ?? this.parent.getNextNode(false);
355
367
  }
368
+ return null;
356
369
  }
357
370
 
358
371
  /**
@@ -361,16 +374,13 @@ export class Node {
361
374
  * @group Moving around the tree
362
375
  */
363
376
  public getNextSibling(): Node | null {
364
- if (!this.parent) {
365
- return null;
366
- } else {
377
+ if (this.parent) {
367
378
  const nextIndex = this.parent.getChildIndex(this) + 1;
368
- if (nextIndex < this.parent.children.length) {
369
- return this.parent.children[nextIndex] ?? null;
370
- } else {
371
- return null;
372
- }
379
+ return nextIndex < this.parent.children.length
380
+ ? (this.parent.children[nextIndex] ?? null)
381
+ : null;
373
382
  }
383
+ return null;
374
384
  }
375
385
 
376
386
  /**
@@ -383,20 +393,17 @@ export class Node {
383
393
  if (this.hasChildren() && this.is_open) {
384
394
  // First child
385
395
  return this.children[0] ?? null;
386
- } else {
387
- if (!this.parent) {
388
- return null;
389
- } else {
390
- const nextSibling = this.getNextSibling();
391
- if (nextSibling) {
392
- // Next sibling
393
- return nextSibling;
394
- } else {
395
- // Next node of parent
396
- return this.parent.getNextNode(false);
397
- }
396
+ }
397
+ if (this.parent) {
398
+ const nextSibling = this.getNextSibling();
399
+ if (nextSibling) {
400
+ // Next sibling
401
+ return nextSibling;
398
402
  }
403
+ // Next node of parent
404
+ return this.parent.getNextNode(false);
399
405
  }
406
+ return null;
400
407
  }
401
408
 
402
409
  /**
@@ -410,12 +417,12 @@ export class Node {
410
417
  this.iterate((node: Node) => {
411
418
  if (result) {
412
419
  return false;
413
- } else if (callback(node)) {
420
+ }
421
+ if (callback(node)) {
414
422
  result = node;
415
423
  return false;
416
- } else {
417
- return true;
418
424
  }
425
+ return true;
419
426
  });
420
427
 
421
428
  return result;
@@ -474,12 +481,12 @@ export class Node {
474
481
  // Return parent except if it is the root node
475
482
  if (!this.parent) {
476
483
  return null;
477
- } else if (!this.parent.parent) {
478
- // Root node -> null
479
- return null;
480
- } else {
484
+ }
485
+ if (this.parent.parent) {
481
486
  return this.parent;
482
487
  }
488
+ // Root node -> null
489
+ return null;
483
490
  }
484
491
 
485
492
  /**
@@ -489,19 +496,17 @@ export class Node {
489
496
  * @group Moving around the tree
490
497
  */
491
498
  public getPreviousNode(): Node | null {
492
- if (!this.parent) {
493
- return null;
494
- } else {
499
+ if (this.parent) {
495
500
  const previousSibling = this.getPreviousSibling();
496
501
 
497
502
  if (!previousSibling) {
498
503
  return this.getParent();
499
- } else if (previousSibling.hasChildren()) {
500
- return previousSibling.getLastChild();
501
- } else {
502
- return previousSibling;
503
504
  }
505
+ return previousSibling.hasChildren()
506
+ ? previousSibling.getLastChild()
507
+ : previousSibling;
504
508
  }
509
+ return null;
505
510
  }
506
511
 
507
512
  /**
@@ -510,16 +515,13 @@ export class Node {
510
515
  * @group Moving around the tree
511
516
  */
512
517
  public getPreviousSibling(): Node | null {
513
- if (!this.parent) {
514
- return null;
515
- } else {
518
+ if (this.parent) {
516
519
  const previousIndex = this.parent.getChildIndex(this) - 1;
517
- if (previousIndex >= 0) {
518
- return this.parent.children[previousIndex] ?? null;
519
- } else {
520
- return null;
521
- }
520
+ return previousIndex >= 0
521
+ ? (this.parent.children[previousIndex] ?? null)
522
+ : null;
522
523
  }
524
+ return null;
523
525
  }
524
526
 
525
527
  /**
@@ -529,21 +531,20 @@ export class Node {
529
531
  * @group Moving around the tree
530
532
  */
531
533
  public getPreviousVisibleNode(): Node | null {
532
- if (!this.parent) {
533
- return null;
534
- } else {
534
+ if (this.parent) {
535
535
  const previousSibling = this.getPreviousSibling();
536
536
 
537
537
  if (!previousSibling) {
538
538
  return this.getParent();
539
- } else if (!previousSibling.hasChildren() || !previousSibling.is_open) {
539
+ }
540
+ if (!previousSibling.hasChildren() || !previousSibling.is_open) {
540
541
  // Previous sibling
541
542
  return previousSibling;
542
- } else {
543
- // Last child of previous sibling
544
- return previousSibling.getLastChild();
545
543
  }
544
+ // Last child of previous sibling
545
+ return previousSibling.getLastChild();
546
546
  }
547
+ return null;
547
548
  }
548
549
 
549
550
  /**
@@ -672,37 +673,36 @@ export class Node {
672
673
  // - Node is parent of target node
673
674
  // - Or, parent is empty
674
675
  return false;
675
- } else {
676
- movedNode.parent.doRemoveChild(movedNode);
677
-
678
- switch (position) {
679
- case "after": {
680
- if (targetNode.parent) {
681
- targetNode.parent.addChildAtPosition(
682
- movedNode,
683
- targetNode.parent.getChildIndex(targetNode) + 1,
684
- );
685
- return true;
686
- }
687
- return false;
688
- }
689
-
690
- case "before": {
691
- if (targetNode.parent) {
692
- targetNode.parent.addChildAtPosition(
693
- movedNode,
694
- targetNode.parent.getChildIndex(targetNode),
695
- );
696
- return true;
697
- }
698
- return false;
676
+ }
677
+ movedNode.parent.doRemoveChild(movedNode);
678
+
679
+ switch (position) {
680
+ case "after": {
681
+ if (targetNode.parent) {
682
+ targetNode.parent.addChildAtPosition(
683
+ movedNode,
684
+ targetNode.parent.getChildIndex(targetNode) + 1,
685
+ );
686
+ return true;
699
687
  }
688
+ return false;
689
+ }
700
690
 
701
- case "inside": {
702
- // move inside as first child
703
- targetNode.addChildAtPosition(movedNode, 0);
691
+ case "before": {
692
+ if (targetNode.parent) {
693
+ targetNode.parent.addChildAtPosition(
694
+ movedNode,
695
+ targetNode.parent.getChildIndex(targetNode),
696
+ );
704
697
  return true;
705
698
  }
699
+ return false;
700
+ }
701
+
702
+ case "inside": {
703
+ // move inside as first child
704
+ targetNode.addChildAtPosition(movedNode, 0);
705
+ return true;
706
706
  }
707
707
  }
708
708
  }
@@ -727,10 +727,12 @@ export class Node {
727
727
  * @group Changing the tree
728
728
  */
729
729
  public remove(): void {
730
- if (this.parent) {
731
- this.parent.removeChild(this);
732
- this.parent = null;
730
+ if (!this.parent) {
731
+ return;
733
732
  }
733
+
734
+ this.parent.removeChild(this);
735
+ this.parent = null;
734
736
  }
735
737
 
736
738
  /**
@@ -759,7 +761,9 @@ export class Node {
759
761
  this.children = [];
760
762
  }
761
763
 
762
- /** @hidden */
764
+ /**
765
+ @hidden
766
+ */
763
767
  public removeNodeFromIndex(node: Node): void {
764
768
  if (node.id != null) {
765
769
  this.idMapping?.delete(node.id);
@@ -776,22 +780,25 @@ export class Node {
776
780
  public setData(o: NodeData | null): void {
777
781
  if (!o) {
778
782
  return;
779
- } else if (typeof o === "string") {
783
+ }
784
+ if (typeof o === "string") {
780
785
  this.name = o;
781
786
  } else if (typeof o === "object") {
782
787
  for (const key in o) {
783
- if (Object.prototype.hasOwnProperty.call(o, key)) {
784
- const value = o[key];
785
-
786
- if (key === "label" || key === "name") {
787
- // You can use the 'label' key instead of 'name'; this is a legacy feature
788
- if (typeof value === "string") {
789
- this.name = value;
790
- }
791
- } else if (key !== "children" && key !== "parent") {
792
- // You can't update the children or the parent using this function
793
- this[key] = value;
788
+ if (!Object.prototype.hasOwnProperty.call(o, key)) {
789
+ continue;
790
+ }
791
+
792
+ const value = o[key];
793
+
794
+ if (key === "label" || key === "name") {
795
+ // You can use the 'label' key instead of 'name'; this is a legacy feature
796
+ if (typeof value === "string") {
797
+ this.name = value;
794
798
  }
799
+ } else if (key !== "children" && key !== "parent") {
800
+ // You can't update the children or the parent using this function
801
+ this[key] = value;
795
802
  }
796
803
  }
797
804
  }
@@ -46,7 +46,10 @@ class FolderElement extends NodeElement {
46
46
  this.triggerEvent = triggerEvent;
47
47
  }
48
48
 
49
- public close(slide: boolean, animationSpeed: AnimationSpeed): void {
49
+ public async close(
50
+ slide: boolean,
51
+ animationSpeed: AnimationSpeed,
52
+ ): Promise<void> {
50
53
  if (!this.node.is_open) {
51
54
  return;
52
55
  }
@@ -60,92 +63,80 @@ class FolderElement extends NodeElement {
60
63
 
61
64
  const button = this.getButton();
62
65
  button.classList.add(this.classNames.closed);
63
- button.innerHTML = "";
66
+ button.replaceChildren();
64
67
 
65
68
  const closedIconElement = this.closedIconElement;
66
69
 
67
70
  if (closedIconElement) {
68
71
  const icon = closedIconElement.cloneNode(true);
69
- button.appendChild(icon);
72
+ button.append(icon);
70
73
  }
71
74
 
72
- const doClose = (): void => {
73
- this.element.classList.add(this.classNames.closed);
75
+ const ul = this.getUl();
74
76
 
75
- const titleSpan = this.getTitleSpan();
76
- titleSpan.setAttribute("aria-expanded", "false");
77
+ if (ul) {
78
+ if (slide) {
79
+ await slideUp(ul, animationSpeed);
80
+ } else {
81
+ ul.style.display = "none";
82
+ }
83
+ }
77
84
 
78
- this.triggerEvent("tree.close", {
79
- node: this.node,
80
- });
81
- };
85
+ this.element.classList.add(this.classNames.closed);
82
86
 
83
- const ul = this.getUl();
87
+ const titleSpan = this.getTitleSpan();
88
+ titleSpan.setAttribute("aria-expanded", "false");
84
89
 
85
- if (!ul) {
86
- doClose();
87
- } else if (slide) {
88
- slideUp(ul, animationSpeed, doClose);
89
- } else {
90
- ul.style.display = "none";
91
- doClose();
92
- }
90
+ this.triggerEvent("tree.close", {
91
+ node: this.node,
92
+ });
93
93
  }
94
94
 
95
95
  public async open(
96
96
  slide: boolean,
97
97
  animationSpeed: AnimationSpeed,
98
98
  ): Promise<void> {
99
- return new Promise((resolve) => {
100
- if (this.node.is_open) {
101
- resolve();
102
- return;
103
- }
104
-
105
- this.node.is_open = true;
106
-
107
- if (!this.isRendered()) {
108
- // The folder is rendered open when its parent is opened
109
- this.triggerEvent("tree.open", { node: this.node });
110
- resolve();
111
- return;
112
- }
113
-
114
- const button = this.getButton();
115
- button.classList.remove(this.classNames.closed);
116
- button.innerHTML = "";
99
+ if (this.node.is_open) {
100
+ return;
101
+ }
117
102
 
118
- const openedIconElement = this.openedIconElement;
103
+ this.node.is_open = true;
119
104
 
120
- if (openedIconElement) {
121
- const icon = openedIconElement.cloneNode(true);
122
- button.appendChild(icon);
123
- }
124
-
125
- const doOpen = (): void => {
126
- this.element.classList.remove(this.classNames.closed);
105
+ if (!this.isRendered()) {
106
+ // The folder is rendered open when its parent is opened
107
+ this.triggerEvent("tree.open", { node: this.node });
108
+ return;
109
+ }
127
110
 
128
- const titleSpan = this.getTitleSpan();
129
- titleSpan.setAttribute("aria-expanded", "true");
111
+ const button = this.getButton();
112
+ button.classList.remove(this.classNames.closed);
113
+ button.replaceChildren();
130
114
 
131
- this.triggerEvent("tree.open", {
132
- node: this.node,
133
- });
115
+ const openedIconElement = this.openedIconElement;
134
116
 
135
- resolve();
136
- };
117
+ if (openedIconElement) {
118
+ const icon = openedIconElement.cloneNode(true);
119
+ button.append(icon);
120
+ }
137
121
 
138
- // The children are rendered the first time the folder is opened
139
- const ul = this.getUl() ?? this.renderChildren(this.node);
122
+ // The children are rendered the first time the folder is opened
123
+ const ul = this.getUl() ?? this.renderChildren(this.node);
140
124
 
141
- if (!ul) {
142
- doOpen();
143
- } else if (slide) {
144
- slideDown(ul, animationSpeed, doOpen);
125
+ if (ul) {
126
+ if (slide) {
127
+ await slideDown(ul, animationSpeed);
145
128
  } else {
146
129
  ul.style.display = "block";
147
- doOpen();
148
130
  }
131
+ }
132
+
133
+ this.element.classList.remove(this.classNames.closed);
134
+
135
+ const titleSpan = this.getTitleSpan();
136
+ titleSpan.setAttribute("aria-expanded", "true");
137
+
138
+ this.triggerEvent("tree.open", {
139
+ node: this.node,
149
140
  });
150
141
  }
151
142
 
@@ -153,10 +144,10 @@ class FolderElement extends NodeElement {
153
144
  return !this.node.is_open && position === "inside";
154
145
  }
155
146
 
156
- private getButton(): HTMLLinkElement {
147
+ private getButton(): HTMLElement {
157
148
  return this.element.querySelector(
158
- `:scope > .${this.classNames.element} > a.${this.classNames.toggler}`,
159
- ) as HTMLLinkElement;
149
+ `:scope > .${this.classNames.element} > .${this.classNames.toggler}`,
150
+ ) as HTMLElement;
160
151
  }
161
152
  }
162
153