@nanahoshi/mona-ui 0.1.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 (134) hide show
  1. package/README.md +25 -0
  2. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +590 -0
  3. package/fesm2022/nanahoshi-mona-ui-avatar.mjs +168 -0
  4. package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +220 -0
  5. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +225 -0
  6. package/fesm2022/nanahoshi-mona-ui-button.mjs +497 -0
  7. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +1569 -0
  8. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +339 -0
  9. package/fesm2022/nanahoshi-mona-ui-chip.mjs +453 -0
  10. package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +200 -0
  11. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +853 -0
  12. package/fesm2022/nanahoshi-mona-ui-color-palette.mjs +923 -0
  13. package/fesm2022/nanahoshi-mona-ui-color-picker.mjs +495 -0
  14. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +686 -0
  15. package/fesm2022/nanahoshi-mona-ui-common.mjs +642 -0
  16. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +485 -0
  17. package/fesm2022/nanahoshi-mona-ui-date-input.mjs +132 -0
  18. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +460 -0
  19. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +659 -0
  20. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +828 -0
  21. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +523 -0
  22. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +615 -0
  23. package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +701 -0
  24. package/fesm2022/nanahoshi-mona-ui-editor.mjs +1400 -0
  25. package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +245 -0
  26. package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +170 -0
  27. package/fesm2022/nanahoshi-mona-ui-filter.mjs +680 -0
  28. package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-cell.component-B9SQH5N-.mjs +105 -0
  29. package/fesm2022/nanahoshi-mona-ui-grid-grid-footer-table-cell.directive-DlLwcCFT.mjs +42 -0
  30. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-Dgea-O0X.mjs +130 -0
  31. package/fesm2022/nanahoshi-mona-ui-grid-grid-toggle.component-DIUutx9s.mjs +773 -0
  32. package/fesm2022/nanahoshi-mona-ui-grid-grid-virtual-list.component-DRHycGIh.mjs +240 -0
  33. package/fesm2022/nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-C3eZIaJK.mjs +5374 -0
  34. package/fesm2022/nanahoshi-mona-ui-grid.mjs +2 -0
  35. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +87 -0
  36. package/fesm2022/nanahoshi-mona-ui-internal-indicator-icon.mjs +154 -0
  37. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1356 -0
  38. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +2263 -0
  39. package/fesm2022/nanahoshi-mona-ui-internal.mjs +379 -0
  40. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +630 -0
  41. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +527 -0
  42. package/fesm2022/nanahoshi-mona-ui-list.mjs +4 -0
  43. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +966 -0
  44. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +641 -0
  45. package/fesm2022/nanahoshi-mona-ui-notification.mjs +536 -0
  46. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +597 -0
  47. package/fesm2022/nanahoshi-mona-ui-pager.mjs +790 -0
  48. package/fesm2022/nanahoshi-mona-ui-placeholder.mjs +83 -0
  49. package/fesm2022/nanahoshi-mona-ui-popover.mjs +325 -0
  50. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +1559 -0
  51. package/fesm2022/nanahoshi-mona-ui-popup.mjs +1321 -0
  52. package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +294 -0
  53. package/fesm2022/nanahoshi-mona-ui-query.mjs +175 -0
  54. package/fesm2022/nanahoshi-mona-ui-radio-button.mjs +339 -0
  55. package/fesm2022/nanahoshi-mona-ui-scroll-view.mjs +565 -0
  56. package/fesm2022/nanahoshi-mona-ui-slider.mjs +1049 -0
  57. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +636 -0
  58. package/fesm2022/nanahoshi-mona-ui-splitter.mjs +843 -0
  59. package/fesm2022/nanahoshi-mona-ui-stepper.mjs +537 -0
  60. package/fesm2022/nanahoshi-mona-ui-switch.mjs +308 -0
  61. package/fesm2022/nanahoshi-mona-ui-tabs.mjs +664 -0
  62. package/fesm2022/nanahoshi-mona-ui-text-area.mjs +111 -0
  63. package/fesm2022/nanahoshi-mona-ui-text-box.mjs +369 -0
  64. package/fesm2022/nanahoshi-mona-ui-theme.mjs +314 -0
  65. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +450 -0
  66. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +723 -0
  67. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +716 -0
  68. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +733 -0
  69. package/fesm2022/nanahoshi-mona-ui-window.mjs +1329 -0
  70. package/fesm2022/nanahoshi-mona-ui.mjs +9 -0
  71. package/package.json +289 -0
  72. package/types/nanahoshi-mona-ui-auto-complete.d.ts +223 -0
  73. package/types/nanahoshi-mona-ui-avatar.d.ts +642 -0
  74. package/types/nanahoshi-mona-ui-breadcrumb.d.ts +70 -0
  75. package/types/nanahoshi-mona-ui-button-group.d.ts +77 -0
  76. package/types/nanahoshi-mona-ui-button.d.ts +111 -0
  77. package/types/nanahoshi-mona-ui-calendar.d.ts +262 -0
  78. package/types/nanahoshi-mona-ui-check-box.d.ts +133 -0
  79. package/types/nanahoshi-mona-ui-chip.d.ts +130 -0
  80. package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +113 -0
  81. package/types/nanahoshi-mona-ui-color-gradient.d.ts +201 -0
  82. package/types/nanahoshi-mona-ui-color-palette.d.ts +102 -0
  83. package/types/nanahoshi-mona-ui-color-picker.d.ts +156 -0
  84. package/types/nanahoshi-mona-ui-combo-box.d.ts +232 -0
  85. package/types/nanahoshi-mona-ui-common.d.ts +386 -0
  86. package/types/nanahoshi-mona-ui-contextmenu.d.ts +129 -0
  87. package/types/nanahoshi-mona-ui-date-input.d.ts +60 -0
  88. package/types/nanahoshi-mona-ui-date-picker.d.ts +177 -0
  89. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +199 -0
  90. package/types/nanahoshi-mona-ui-dialog.d.ts +261 -0
  91. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +159 -0
  92. package/types/nanahoshi-mona-ui-dropdown-list.d.ts +219 -0
  93. package/types/nanahoshi-mona-ui-dropdowns.d.ts +176 -0
  94. package/types/nanahoshi-mona-ui-editor.d.ts +113 -0
  95. package/types/nanahoshi-mona-ui-expansion-panel.d.ts +87 -0
  96. package/types/nanahoshi-mona-ui-fieldset.d.ts +68 -0
  97. package/types/nanahoshi-mona-ui-filter.d.ts +115 -0
  98. package/types/nanahoshi-mona-ui-grid.d.ts +1114 -0
  99. package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +25 -0
  100. package/types/nanahoshi-mona-ui-internal-indicator-icon.d.ts +28 -0
  101. package/types/nanahoshi-mona-ui-internal-list.d.ts +269 -0
  102. package/types/nanahoshi-mona-ui-internal-tree.d.ts +391 -0
  103. package/types/nanahoshi-mona-ui-internal.d.ts +136 -0
  104. package/types/nanahoshi-mona-ui-list-box.d.ts +225 -0
  105. package/types/nanahoshi-mona-ui-list-view.d.ts +188 -0
  106. package/types/nanahoshi-mona-ui-list.d.ts +1 -0
  107. package/types/nanahoshi-mona-ui-menubar.d.ts +198 -0
  108. package/types/nanahoshi-mona-ui-multi-select.d.ts +247 -0
  109. package/types/nanahoshi-mona-ui-notification.d.ts +106 -0
  110. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +161 -0
  111. package/types/nanahoshi-mona-ui-pager.d.ts +238 -0
  112. package/types/nanahoshi-mona-ui-placeholder.d.ts +35 -0
  113. package/types/nanahoshi-mona-ui-popover.d.ts +130 -0
  114. package/types/nanahoshi-mona-ui-popup-menu.d.ts +412 -0
  115. package/types/nanahoshi-mona-ui-popup.d.ts +485 -0
  116. package/types/nanahoshi-mona-ui-progress-bar.d.ts +139 -0
  117. package/types/nanahoshi-mona-ui-query.d.ts +89 -0
  118. package/types/nanahoshi-mona-ui-radio-button.d.ts +128 -0
  119. package/types/nanahoshi-mona-ui-scroll-view.d.ts +166 -0
  120. package/types/nanahoshi-mona-ui-slider.d.ts +305 -0
  121. package/types/nanahoshi-mona-ui-split-button.d.ts +182 -0
  122. package/types/nanahoshi-mona-ui-splitter.d.ts +70 -0
  123. package/types/nanahoshi-mona-ui-stepper.d.ts +173 -0
  124. package/types/nanahoshi-mona-ui-switch.d.ts +125 -0
  125. package/types/nanahoshi-mona-ui-tabs.d.ts +158 -0
  126. package/types/nanahoshi-mona-ui-text-area.d.ts +42 -0
  127. package/types/nanahoshi-mona-ui-text-box.d.ts +164 -0
  128. package/types/nanahoshi-mona-ui-theme.d.ts +23 -0
  129. package/types/nanahoshi-mona-ui-time-picker.d.ts +184 -0
  130. package/types/nanahoshi-mona-ui-time-selector.d.ts +143 -0
  131. package/types/nanahoshi-mona-ui-tooltip.d.ts +130 -0
  132. package/types/nanahoshi-mona-ui-tree-view.d.ts +274 -0
  133. package/types/nanahoshi-mona-ui-window.d.ts +295 -0
  134. package/types/nanahoshi-mona-ui.d.ts +2 -0
@@ -0,0 +1,2263 @@
1
+ import { FocusMonitor } from '@angular/cdk/a11y';
2
+ import * as i0 from '@angular/core';
3
+ import { Directive, signal, computed, untracked, effect, Injectable, Pipe, inject, DestroyRef, input, ChangeDetectionStrategy, Component, DOCUMENT, NgZone, ElementRef, afterRenderEffect, contentChild, TemplateRef, afterNextRender } from '@angular/core';
4
+ import { toObservable, toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
+ import { ThemeService } from '@nanahoshi/mona-ui/theme';
6
+ import { Subject, BehaviorSubject, ReplaySubject, switchMap, debounceTime, distinctUntilChanged, Observable, take, filter, tap, map, asapScheduler, fromEvent, takeWhile } from 'rxjs';
7
+ import { PreventableEvent } from '@nanahoshi/mona-ui/common';
8
+ import { ImmutableSet, List, from, sequenceEqual, contains, EnumerableSet, forEach } from '@mirei/ts-collections';
9
+ import { v4 } from 'uuid';
10
+ import { cva } from 'class-variance-authority';
11
+ import { CdkDropList, CdkDrag, CdkDragPreview } from '@angular/cdk/drag-drop';
12
+ import * as i1 from '@angular/forms';
13
+ import { FormsModule } from '@angular/forms';
14
+ import { CheckBoxComponent } from '@nanahoshi/mona-ui/check-box';
15
+ import { NgTemplateOutlet } from '@angular/common';
16
+ import { twMerge } from 'tailwind-merge';
17
+
18
+ class TreeNodeTemplateDirective {
19
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
20
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: TreeNodeTemplateDirective, isStandalone: true, selector: "ng-template[monaTreeNodeTemplate]", ngImport: i0 }); }
21
+ }
22
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeTemplateDirective, decorators: [{
23
+ type: Directive,
24
+ args: [{
25
+ selector: "ng-template[monaTreeNodeTemplate]"
26
+ }]
27
+ }] });
28
+
29
+ class NodeCheckEvent extends PreventableEvent {
30
+ #node;
31
+ constructor(node, event) {
32
+ super("nodeCheck", event);
33
+ this.#node = node;
34
+ }
35
+ get nodeItem() {
36
+ return {
37
+ data: this.#node.data,
38
+ hasChildren: this.#node.children().length > 0,
39
+ uid: this.#node.uid
40
+ };
41
+ }
42
+ }
43
+
44
+ class NodeSelectEvent extends PreventableEvent {
45
+ #node;
46
+ constructor(node, event) {
47
+ super("nodeSelect", event);
48
+ this.#node = node;
49
+ }
50
+ get nodeItem() {
51
+ return {
52
+ data: this.#node.data,
53
+ hasChildren: this.#node.children().length > 0,
54
+ uid: this.#node.uid
55
+ };
56
+ }
57
+ }
58
+
59
+ class TreeNode {
60
+ constructor(data) {
61
+ this.checked = signal(false, /* @ts-ignore */
62
+ ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
63
+ this.children = signal(ImmutableSet.create(), /* @ts-ignore */
64
+ ...(ngDevMode ? [{ debugName: "children" }] : /* istanbul ignore next */ []));
65
+ this.loading = signal(false, /* @ts-ignore */
66
+ ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
67
+ this.uid = v4();
68
+ this.index = "";
69
+ this.parent = null;
70
+ this.data = data;
71
+ }
72
+ clone() {
73
+ const node = new TreeNode(this.data);
74
+ node.index = this.index;
75
+ node.children.set(ImmutableSet.create(this.children().select(c => c.clone())));
76
+ node.parent = this.parent;
77
+ return node;
78
+ }
79
+ isDescendantOf(node) {
80
+ let parent = this.parent;
81
+ while (parent != null) {
82
+ if (parent === node) {
83
+ return true;
84
+ }
85
+ parent = parent.parent;
86
+ }
87
+ return false;
88
+ }
89
+ get nodeItem() {
90
+ return {
91
+ data: this.data,
92
+ hasChildren: this.children().length > 0,
93
+ uid: this.uid
94
+ };
95
+ }
96
+ }
97
+
98
+ function getTreeNodeElementId(uid) {
99
+ return `mona-tree-node-${uid}`;
100
+ }
101
+
102
+ var _a;
103
+ class TreeService {
104
+ #checkedKeys;
105
+ #data;
106
+ #filteredExpandedKeys;
107
+ #flatIdField;
108
+ #flatParentIdField;
109
+ #hasCheckboxPredicate;
110
+ #hasChildrenPredicate;
111
+ #navigableNodes;
112
+ #nodeDictionary;
113
+ #structure;
114
+ #unfilteredExpandedKeys;
115
+ #visibleUids;
116
+ constructor() {
117
+ this.#checkedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
118
+ ...(ngDevMode ? [{ debugName: "#checkedKeys" }] : /* istanbul ignore next */ []));
119
+ this.#data = signal(ImmutableSet.create(), /* @ts-ignore */
120
+ ...(ngDevMode ? [{ debugName: "#data" }] : /* istanbul ignore next */ []));
121
+ this.#filteredExpandedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
122
+ ...(ngDevMode ? [{ debugName: "#filteredExpandedKeys" }] : /* istanbul ignore next */ []));
123
+ this.#flatIdField = signal("", /* @ts-ignore */
124
+ ...(ngDevMode ? [{ debugName: "#flatIdField" }] : /* istanbul ignore next */ []));
125
+ this.#flatParentIdField = signal("", /* @ts-ignore */
126
+ ...(ngDevMode ? [{ debugName: "#flatParentIdField" }] : /* istanbul ignore next */ []));
127
+ this.#hasCheckboxPredicate = signal(null, /* @ts-ignore */
128
+ ...(ngDevMode ? [{ debugName: "#hasCheckboxPredicate" }] : /* istanbul ignore next */ []));
129
+ this.#hasChildrenPredicate = signal(null, /* @ts-ignore */
130
+ ...(ngDevMode ? [{ debugName: "#hasChildrenPredicate" }] : /* istanbul ignore next */ []));
131
+ this.#navigableNodes = computed(() => {
132
+ const visibleUids = this.#visibleUids();
133
+ const allFlatNodes = _a.flatten(this.nodeSet());
134
+ if (visibleUids === null) {
135
+ return allFlatNodes
136
+ .where(n => n.parent === null || !this.isAnyParentCollapsed(n))
137
+ .orderBy(n => n.index)
138
+ .toImmutableSet();
139
+ }
140
+ return allFlatNodes
141
+ .where(n => visibleUids.has(n.uid) && (n.parent === null || !this.isAnyParentCollapsed(n)))
142
+ .orderBy(n => n.index)
143
+ .toImmutableSet();
144
+ }, /* @ts-ignore */
145
+ ...(ngDevMode ? [{ debugName: "#navigableNodes" }] : /* istanbul ignore next */ []));
146
+ this.#nodeDictionary = computed(() => {
147
+ const nodes = this.nodeSet();
148
+ return this.createNodeDictionary(nodes);
149
+ }, /* @ts-ignore */
150
+ ...(ngDevMode ? [{ debugName: "#nodeDictionary" }] : /* istanbul ignore next */ []));
151
+ this.#structure = signal("hierarchical", /* @ts-ignore */
152
+ ...(ngDevMode ? [{ debugName: "#structure" }] : /* istanbul ignore next */ []));
153
+ this.#unfilteredExpandedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
154
+ ...(ngDevMode ? [{ debugName: "#unfilteredExpandedKeys" }] : /* istanbul ignore next */ []));
155
+ this.#visibleUids = computed(() => {
156
+ const filterText = this.filterText();
157
+ if (!filterText) {
158
+ return null;
159
+ }
160
+ const nodeSet = this.nodeSet();
161
+ return untracked(() => this.computeVisibleUids(nodeSet, filterText));
162
+ }, /* @ts-ignore */
163
+ ...(ngDevMode ? [{ debugName: "#visibleUids" }] : /* istanbul ignore next */ []));
164
+ this.animationTemporarilyDisabled = signal(false, /* @ts-ignore */
165
+ ...(ngDevMode ? [{ debugName: "animationTemporarilyDisabled" }] : /* istanbul ignore next */ []));
166
+ this.animationEnabled = signal(true, /* @ts-ignore */
167
+ ...(ngDevMode ? [{ debugName: "animationEnabled" }] : /* istanbul ignore next */ []));
168
+ this.blur$ = new Subject();
169
+ this.checkBy = signal(null, /* @ts-ignore */
170
+ ...(ngDevMode ? [{ debugName: "checkBy" }] : /* istanbul ignore next */ []));
171
+ this.checkableOptions = signal({
172
+ checkChildren: true,
173
+ checkDisabledChildren: false,
174
+ checkParents: true,
175
+ childrenOnly: false,
176
+ enabled: false,
177
+ mode: "multiple"
178
+ }, /* @ts-ignore */
179
+ ...(ngDevMode ? [{ debugName: "checkableOptions" }] : /* istanbul ignore next */ []));
180
+ this.checkedKeys$ = toObservable(this.#checkedKeys);
181
+ this.children = signal("", /* @ts-ignore */
182
+ ...(ngDevMode ? [{ debugName: "children" }] : /* istanbul ignore next */ []));
183
+ this.disableBy = signal(null, /* @ts-ignore */
184
+ ...(ngDevMode ? [{ debugName: "disableBy" }] : /* istanbul ignore next */ []));
185
+ this.disableOptions = signal({
186
+ disableChildren: true,
187
+ enabled: false
188
+ }, /* @ts-ignore */
189
+ ...(ngDevMode ? [{ debugName: "disableOptions" }] : /* istanbul ignore next */ []));
190
+ this.disabledKeys = signal(ImmutableSet.create(), /* @ts-ignore */
191
+ ...(ngDevMode ? [{ debugName: "disabledKeys" }] : /* istanbul ignore next */ []));
192
+ this.draggableOptions = signal({ enabled: false }, /* @ts-ignore */
193
+ ...(ngDevMode ? [{ debugName: "draggableOptions" }] : /* istanbul ignore next */ []));
194
+ this.dragging = signal(false, /* @ts-ignore */
195
+ ...(ngDevMode ? [{ debugName: "dragging" }] : /* istanbul ignore next */ []));
196
+ this.dragging$ = toObservable(this.dragging);
197
+ this.dropAllowed = signal(false, /* @ts-ignore */
198
+ ...(ngDevMode ? [{ debugName: "dropAllowed" }] : /* istanbul ignore next */ []));
199
+ this.dropPositionChange$ = new BehaviorSubject(null);
200
+ this.dropPositionSignal = toSignal(this.dropPositionChange$, { initialValue: null });
201
+ this.expandBy = signal(null, /* @ts-ignore */
202
+ ...(ngDevMode ? [{ debugName: "expandBy" }] : /* istanbul ignore next */ []));
203
+ this.expandableOptions = signal({ enabled: false }, /* @ts-ignore */
204
+ ...(ngDevMode ? [{ debugName: "expandableOptions" }] : /* istanbul ignore next */ []));
205
+ this.expandedKeys = computed(() => {
206
+ const filterText = this.filterText();
207
+ if (filterText) {
208
+ return this.#filteredExpandedKeys();
209
+ }
210
+ return this.#unfilteredExpandedKeys();
211
+ }, /* @ts-ignore */
212
+ ...(ngDevMode ? [{ debugName: "expandedKeys" }] : /* istanbul ignore next */ []));
213
+ this.expandedKeys$ = toObservable(this.expandedKeys);
214
+ this.filterableOptions = signal({
215
+ enabled: false,
216
+ debounce: 0,
217
+ caseSensitive: false,
218
+ operator: "contains"
219
+ }, /* @ts-ignore */
220
+ ...(ngDevMode ? [{ debugName: "filterableOptions" }] : /* istanbul ignore next */ []));
221
+ this.filter$ = new ReplaySubject(1);
222
+ this.filterChange$ = new Subject();
223
+ this.filterPlaceholder = signal("", /* @ts-ignore */
224
+ ...(ngDevMode ? [{ debugName: "filterPlaceholder" }] : /* istanbul ignore next */ []));
225
+ this.filterText = toSignal(toObservable(this.filterableOptions).pipe(switchMap(opts => this.filter$.pipe(debounceTime(opts.debounce), distinctUntilChanged()))), { initialValue: "" });
226
+ this.focus$ = new Subject();
227
+ this.navigatedNode = signal(null, /* @ts-ignore */
228
+ ...(ngDevMode ? [{ debugName: "navigatedNode" }] : /* istanbul ignore next */ []));
229
+ this.nodeCheck$ = new Subject();
230
+ this.nodeCheckChange$ = new Subject();
231
+ this.nodeClick$ = new Subject();
232
+ this.nodeDrag$ = new Subject();
233
+ this.nodeDragEnd$ = new Subject();
234
+ this.nodeDragStart$ = new Subject();
235
+ this.nodeDrop$ = new Subject();
236
+ this.nodeExpand$ = new Subject();
237
+ this.nodeSelect$ = new Subject();
238
+ this.nodeSelectChange$ = new Subject();
239
+ this.nodeSet = signal(ImmutableSet.create(), /* @ts-ignore */
240
+ ...(ngDevMode ? [{ debugName: "nodeSet" }] : /* istanbul ignore next */ []));
241
+ this.nodeTemplate = signal(null, /* @ts-ignore */
242
+ ...(ngDevMode ? [{ debugName: "nodeTemplate" }] : /* istanbul ignore next */ []));
243
+ this.selectBy = signal(null, /* @ts-ignore */
244
+ ...(ngDevMode ? [{ debugName: "selectBy" }] : /* istanbul ignore next */ []));
245
+ this.selectableOptions = signal({
246
+ childrenOnly: false,
247
+ enabled: false,
248
+ mode: "single",
249
+ toggleable: false
250
+ }, /* @ts-ignore */
251
+ ...(ngDevMode ? [{ debugName: "selectableOptions" }] : /* istanbul ignore next */ []));
252
+ this.selectedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
253
+ ...(ngDevMode ? [{ debugName: "selectedKeys" }] : /* istanbul ignore next */ []));
254
+ this.selectedKeys$ = toObservable(this.selectedKeys);
255
+ this.selectedNodes = computed(() => {
256
+ const selectedKeys = this.selectedKeys();
257
+ const nodeDictionary = this.#nodeDictionary();
258
+ return selectedKeys
259
+ .select(k => {
260
+ return nodeDictionary.values().firstOrDefault(n => {
261
+ const key = this.getSelectKey(n);
262
+ return key === k;
263
+ });
264
+ })
265
+ .where(n => n != null)
266
+ .cast()
267
+ .toImmutableSet();
268
+ }, /* @ts-ignore */
269
+ ...(ngDevMode ? [{ debugName: "selectedNodes" }] : /* istanbul ignore next */ []));
270
+ this.selectionChange$ = new Subject();
271
+ this.textField = signal("", /* @ts-ignore */
272
+ ...(ngDevMode ? [{ debugName: "textField" }] : /* istanbul ignore next */ []));
273
+ this.viewNodeSet = computed(() => {
274
+ const visibleUids = this.#visibleUids();
275
+ if (visibleUids === null) {
276
+ return this.nodeSet();
277
+ }
278
+ return this.nodeSet()
279
+ .where(n => visibleUids.has(n.uid))
280
+ .toImmutableSet();
281
+ }, /* @ts-ignore */
282
+ ...(ngDevMode ? [{ debugName: "viewNodeSet" }] : /* istanbul ignore next */ []));
283
+ effect(() => {
284
+ const visibleUids = this.#visibleUids();
285
+ untracked(() => {
286
+ if (visibleUids === null) {
287
+ return;
288
+ }
289
+ const expandedKeys = _a.flatten(this.nodeSet())
290
+ .where(n => visibleUids.has(n.uid) && !n.children().isEmpty())
291
+ .select(n => this.getExpandKey(n))
292
+ .toImmutableSet();
293
+ this.#filteredExpandedKeys.set(expandedKeys);
294
+ });
295
+ });
296
+ }
297
+ static flatten(nodes) {
298
+ const flattenedNodes = new List();
299
+ for (const node of nodes) {
300
+ flattenedNodes.add(node);
301
+ if (!node.children().isEmpty()) {
302
+ flattenedNodes.addAll(_a.flatten(node.children()));
303
+ }
304
+ }
305
+ return flattenedNodes;
306
+ }
307
+ clearFilter() {
308
+ this.filter$.next("");
309
+ }
310
+ detachNode(node) {
311
+ if (node.parent) {
312
+ node.parent.children.update(list => {
313
+ const parent = node.parent;
314
+ return list.clear().addAll(parent.children().where(n => n !== node));
315
+ });
316
+ node.parent = null;
317
+ }
318
+ else {
319
+ this.nodeSet.update(nodes => nodes.remove(node));
320
+ }
321
+ this.updateNodeIndices();
322
+ }
323
+ getNodeByUid(uid) {
324
+ const nodeDictionary = this.#nodeDictionary();
325
+ return nodeDictionary.get(uid) ?? null;
326
+ }
327
+ getNodeElementId(uid) {
328
+ return getTreeNodeElementId(uid);
329
+ }
330
+ getNodeText(node) {
331
+ const textField = this.textField();
332
+ if (!textField) {
333
+ return String(node.data) || "";
334
+ }
335
+ if (typeof textField === "string") {
336
+ return node.data[textField];
337
+ }
338
+ return textField(node.data);
339
+ }
340
+ hasChildren(node) {
341
+ if (node === null) {
342
+ return false;
343
+ }
344
+ const hasChildrenPredicate = this.#hasChildrenPredicate();
345
+ if (hasChildrenPredicate) {
346
+ return hasChildrenPredicate(node.data);
347
+ }
348
+ return !node.children().isEmpty();
349
+ }
350
+ insertNodeAtIndex(node, parentUid, index) {
351
+ if (parentUid !== null) {
352
+ const parent = this.getNodeByUid(parentUid);
353
+ if (!parent || node.isDescendantOf(parent)) {
354
+ return;
355
+ }
356
+ parent.children.update(set => {
357
+ const tempList = set.toList();
358
+ tempList.addAt(node, index);
359
+ return tempList.toImmutableSet();
360
+ });
361
+ node.parent = parent;
362
+ }
363
+ else {
364
+ this.nodeSet.update(nodes => {
365
+ const tempList = nodes.toList();
366
+ tempList.addAt(node, index);
367
+ return tempList.toImmutableSet();
368
+ });
369
+ node.parent = null;
370
+ }
371
+ this.updateNodeIndices();
372
+ }
373
+ isCheckable(node) {
374
+ const checkableOptions = this.checkableOptions();
375
+ if (!checkableOptions.enabled) {
376
+ return false;
377
+ }
378
+ const hasCheckbox = this.#hasCheckboxPredicate();
379
+ if (hasCheckbox !== null && !hasCheckbox(node.data, node.uid)) {
380
+ return false;
381
+ }
382
+ return !(checkableOptions.childrenOnly && !node.children().isEmpty());
383
+ }
384
+ isChecked(node) {
385
+ return node.checked();
386
+ }
387
+ isDisabled(node) {
388
+ const disableOptions = this.disableOptions();
389
+ const disabledKeys = this.disabledKeys();
390
+ if (!disableOptions.enabled) {
391
+ return false;
392
+ }
393
+ const key = this.getDisableKey(node);
394
+ const disabled = disabledKeys.contains(key);
395
+ if (!disableOptions.disableChildren) {
396
+ return disabled;
397
+ }
398
+ const anyParentDisabled = this.isAnyParentDisabled(node);
399
+ return disabled || (disableOptions.disableChildren && anyParentDisabled);
400
+ }
401
+ isExpanded(node) {
402
+ const expandableOptions = this.expandableOptions();
403
+ const expandedKeys = this.expandedKeys();
404
+ if (!expandableOptions.enabled) {
405
+ return true;
406
+ }
407
+ if (node.children().isEmpty()) {
408
+ return false;
409
+ }
410
+ const key = this.getExpandKey(node);
411
+ return expandedKeys.contains(key);
412
+ }
413
+ isIndeterminate(node) {
414
+ const checkableOptions = this.checkableOptions();
415
+ if (!checkableOptions.enabled || !checkableOptions.checkParents || checkableOptions.mode === "single") {
416
+ return false;
417
+ }
418
+ if (node.children().isEmpty()) {
419
+ return false;
420
+ }
421
+ const hasCheckbox = this.#hasCheckboxPredicate();
422
+ const childNodes = hasCheckbox !== null ? node.children().where(n => hasCheckbox(n.data, n.uid)) : node.children();
423
+ if (childNodes.none()) {
424
+ return false;
425
+ }
426
+ const checkedCount = childNodes.where(n => this.isChecked(n)).count();
427
+ const indeterminateCount = childNodes.where(n => this.isIndeterminate(n)).count();
428
+ const childCount = childNodes.count();
429
+ return (checkedCount > 0 && checkedCount < childCount) || indeterminateCount > 0;
430
+ }
431
+ isNavigated(node) {
432
+ const navigatedNode = this.navigatedNode();
433
+ return navigatedNode === node;
434
+ }
435
+ isSelected(node) {
436
+ const selectableOptions = this.selectableOptions();
437
+ const selectedKeys = this.selectedKeys();
438
+ if (!selectableOptions.enabled) {
439
+ return false;
440
+ }
441
+ const key = this.getSelectKey(node);
442
+ return selectedKeys.contains(key);
443
+ }
444
+ isTreeFiltered() {
445
+ return this.filterText() !== "";
446
+ }
447
+ isVisible(node) {
448
+ const visibleUids = this.#visibleUids();
449
+ if (visibleUids === null) {
450
+ return true;
451
+ }
452
+ return visibleUids.has(node.uid);
453
+ }
454
+ loadNodeChildren(node) {
455
+ const childrenSelector = this.children();
456
+ if (typeof childrenSelector !== "function") {
457
+ return;
458
+ }
459
+ const children = childrenSelector(node.data);
460
+ if (!(children instanceof Observable)) {
461
+ return;
462
+ }
463
+ node.children.set(ImmutableSet.create());
464
+ node.loading.set(true);
465
+ children.pipe(take(1)).subscribe({
466
+ next: c => {
467
+ const childNodes = new List();
468
+ for (const child of c) {
469
+ const childNode = new TreeNode(child);
470
+ childNode.parent = node;
471
+ childNodes.add(childNode);
472
+ }
473
+ this.loadCheckedKeysForChildren(node, childNodes);
474
+ node.children.update(list => list.clear().addAll(childNodes));
475
+ node.loading.set(false);
476
+ this.restoreExpandedChildren(childNodes);
477
+ },
478
+ error: () => {
479
+ node.loading.set(false);
480
+ }
481
+ });
482
+ }
483
+ moveNode(sourceNode, targetNode, position) {
484
+ const oldParent = sourceNode.parent;
485
+ switch (position) {
486
+ case "inside":
487
+ this.moveNodeInside(sourceNode, targetNode);
488
+ break;
489
+ case "before":
490
+ this.moveNodeBefore(sourceNode, targetNode);
491
+ break;
492
+ case "after":
493
+ this.moveNodeAfter(sourceNode, targetNode);
494
+ break;
495
+ }
496
+ this.updateNodeIndices();
497
+ this.recalculateCheckedAncestors(oldParent, sourceNode.parent);
498
+ }
499
+ navigate(direction) {
500
+ const navigableNodes = this.#navigableNodes();
501
+ const navigatedNode = this.navigatedNode();
502
+ if (navigableNodes.isEmpty()) {
503
+ return null;
504
+ }
505
+ if (direction === "first") {
506
+ const first = navigableNodes.first();
507
+ this.navigatedNode.set(first);
508
+ return first;
509
+ }
510
+ if (direction === "last") {
511
+ const last = navigableNodes.last();
512
+ this.navigatedNode.set(last);
513
+ return last;
514
+ }
515
+ const firstNode = navigableNodes.first();
516
+ if (navigatedNode === null) {
517
+ this.navigatedNode.set(firstNode);
518
+ return firstNode;
519
+ }
520
+ if (direction === "next") {
521
+ return this.navigateToNextNode();
522
+ }
523
+ if (direction === "previous") {
524
+ return this.navigateToPreviousNode();
525
+ }
526
+ return null;
527
+ }
528
+ notifySelectionChange(node) {
529
+ this.selectionChange$.next(node.nodeItem);
530
+ }
531
+ setAnimationEnabled(enabled) {
532
+ this.animationEnabled.set(enabled);
533
+ }
534
+ setChildrenSelector(selector) {
535
+ if (this.children() === selector) {
536
+ return;
537
+ }
538
+ this.children.set(selector);
539
+ this.nodeSet.set(this.createNodes(this.#data()));
540
+ this.updateNodeIndices();
541
+ }
542
+ setCheckBy(selector) {
543
+ this.checkBy.set(selector);
544
+ }
545
+ setCheckableOptions(options) {
546
+ this.checkableOptions.update(o => ({ ...o, ...options }));
547
+ }
548
+ setCheckedKeys(keys) {
549
+ const checkedKeys = this.#checkedKeys().orderBy(k => k);
550
+ const orderedKeys = from(keys).orderBy(k => k);
551
+ if (sequenceEqual(checkedKeys, orderedKeys)) {
552
+ return;
553
+ }
554
+ const checkedKeysSet = this.#nodeDictionary()
555
+ .values()
556
+ .where(n => contains(keys, this.getCheckKey(n)))
557
+ .toEnumerableSet();
558
+ this.#nodeDictionary().forEach(n => {
559
+ n.value.checked.set(checkedKeysSet.contains(n.value));
560
+ });
561
+ this.#checkedKeys.set(ImmutableSet.create(keys));
562
+ }
563
+ setData(data) {
564
+ this.#data.set(ImmutableSet.create(data));
565
+ this.nodeSet.set(this.createNodes(data));
566
+ this.updateNodeIndices();
567
+ this.applyCheckedKeysToNodes();
568
+ }
569
+ setDataStructure(structure) {
570
+ this.#structure.set(structure);
571
+ }
572
+ setDisableBy(selector) {
573
+ this.disableBy.set(selector);
574
+ }
575
+ setDisableOptions(options) {
576
+ this.disableOptions.update(o => ({ ...o, ...options }));
577
+ }
578
+ setDisabledKeys(keys) {
579
+ const disabledKeys = this.disabledKeys().orderBy(k => k);
580
+ const orderedKeys = from(keys).orderBy(k => k);
581
+ if (sequenceEqual(disabledKeys, orderedKeys)) {
582
+ return;
583
+ }
584
+ this.disabledKeys.set(ImmutableSet.create(keys));
585
+ }
586
+ setDraggableOptions(options) {
587
+ this.draggableOptions.update(o => ({ ...o, ...options }));
588
+ }
589
+ setExpandBy(selector) {
590
+ this.expandBy.set(selector);
591
+ }
592
+ setExpandableOptions(options) {
593
+ this.expandableOptions.update(o => ({ ...o, ...options }));
594
+ }
595
+ setExpandedKeys(keys) {
596
+ const unfilteredKeys = this.#unfilteredExpandedKeys().orderBy(k => k);
597
+ const orderedKeys = from(keys).orderBy(k => k);
598
+ if (sequenceEqual(unfilteredKeys, orderedKeys)) {
599
+ return;
600
+ }
601
+ this.#unfilteredExpandedKeys.set(ImmutableSet.create(keys));
602
+ }
603
+ setFilterableOptions(options) {
604
+ this.filterableOptions.update(o => ({ ...o, ...options }));
605
+ }
606
+ setFlatIdField(field) {
607
+ this.#flatIdField.set(field);
608
+ }
609
+ setFlatParentIdField(field) {
610
+ this.#flatParentIdField.set(field);
611
+ }
612
+ setHasCheckboxPredicate(fn) {
613
+ this.#hasCheckboxPredicate.set(fn);
614
+ }
615
+ setHasChildrenPredicate(predicate) {
616
+ this.#hasChildrenPredicate.set(predicate);
617
+ }
618
+ setNodeCheck(node, checked) {
619
+ const checkableOptions = this.checkableOptions();
620
+ if (!checkableOptions.enabled) {
621
+ return;
622
+ }
623
+ const checkParents = checkableOptions.checkParents;
624
+ const checkChildren = checkableOptions.checkChildren;
625
+ const childrenOnly = checkableOptions.childrenOnly;
626
+ const checkDisabledChildren = checkableOptions.checkDisabledChildren;
627
+ const mode = checkableOptions.mode;
628
+ const key = this.getCheckKey(node);
629
+ const checkedKeys = this.#checkedKeys().toEnumerableSet();
630
+ const nodeDictionary = this.#nodeDictionary();
631
+ if (mode === "single") {
632
+ nodeDictionary
633
+ .values()
634
+ .where(n => n !== node)
635
+ .forEach(n => n.checked.set(false));
636
+ checkedKeys.clear();
637
+ if (checked) {
638
+ checkedKeys.add(key);
639
+ }
640
+ }
641
+ else if (checked) {
642
+ checkedKeys.add(key);
643
+ }
644
+ else {
645
+ checkedKeys.remove(key);
646
+ }
647
+ node.checked.set(checked);
648
+ if (mode !== "single" && checkChildren) {
649
+ const hasCheckbox = this.#hasCheckboxPredicate();
650
+ const childNodes = this.getChildNodes(node);
651
+ childNodes.forEach(n => {
652
+ if (hasCheckbox !== null && !hasCheckbox(n.data, n.uid)) {
653
+ return;
654
+ }
655
+ if (checkDisabledChildren || !this.isDisabled(n)) {
656
+ const childKey = this.getCheckKey(n);
657
+ if (checked) {
658
+ checkedKeys.add(childKey);
659
+ }
660
+ else {
661
+ checkedKeys.remove(childKey);
662
+ }
663
+ n.checked.set(checked);
664
+ }
665
+ });
666
+ }
667
+ if (mode !== "single" && checkParents && !childrenOnly) {
668
+ const hasCheckbox = this.#hasCheckboxPredicate();
669
+ const parentNodes = this.getParentNodes(node);
670
+ parentNodes.forEach(n => {
671
+ const siblings = hasCheckbox !== null ? n.children().where(c => hasCheckbox(c.data, c.uid)) : n.children();
672
+ const allChecked = siblings.all(c => c.checked());
673
+ const parentKey = this.getCheckKey(n);
674
+ if (allChecked) {
675
+ checkedKeys.add(parentKey);
676
+ }
677
+ else {
678
+ checkedKeys.remove(parentKey);
679
+ }
680
+ n.checked.set(allChecked);
681
+ });
682
+ }
683
+ this.#checkedKeys.set(checkedKeys.toImmutableSet());
684
+ }
685
+ setNodeExpand(node, expanded) {
686
+ const key = this.getExpandKey(node);
687
+ const expandedKeysSignal = this.isTreeFiltered() ? this.#filteredExpandedKeys : this.#unfilteredExpandedKeys;
688
+ expandedKeysSignal.update(keys => {
689
+ if (expanded) {
690
+ return keys.add(key);
691
+ }
692
+ return keys.remove(key);
693
+ });
694
+ this.navigatedNode.set(node);
695
+ }
696
+ setNodeSelect(node, selected) {
697
+ const selectableOptions = this.selectableOptions();
698
+ if (!selectableOptions.enabled) {
699
+ return;
700
+ }
701
+ const childrenOnly = selectableOptions.childrenOnly;
702
+ if (childrenOnly && this.hasChildren(node)) {
703
+ return;
704
+ }
705
+ const key = this.getSelectKey(node);
706
+ const mode = selectableOptions.mode;
707
+ this.selectedKeys.update(keys => {
708
+ if (mode === "single") {
709
+ const toggleable = selectableOptions.toggleable;
710
+ if (toggleable && keys.contains(key)) {
711
+ return keys.remove(key);
712
+ }
713
+ else {
714
+ return keys.clear().add(key);
715
+ }
716
+ }
717
+ if (selected) {
718
+ return keys.add(key);
719
+ }
720
+ return keys.remove(key);
721
+ });
722
+ this.navigatedNode.set(node);
723
+ }
724
+ setSelectBy(selector) {
725
+ this.selectBy.set(selector);
726
+ }
727
+ setSelectableOptions(options) {
728
+ this.selectableOptions.update(o => ({ ...o, ...options }));
729
+ }
730
+ setSelectedDataItems(dataItems) {
731
+ const selectBy = this.selectBy();
732
+ if (!selectBy) {
733
+ this.selectedKeys.update(set => set.clear().addAll(dataItems));
734
+ }
735
+ else {
736
+ const selectedKeys = from(dataItems).select(d => this.getDataItemSelectKey(d));
737
+ this.selectedKeys.update(set => set.clear().addAll(selectedKeys));
738
+ }
739
+ }
740
+ setSelectedKeys(keys) {
741
+ const selectedKeys = this.selectedKeys().orderBy(k => k);
742
+ const orderedKeys = from(keys).orderBy(k => k);
743
+ if (sequenceEqual(selectedKeys, orderedKeys)) {
744
+ return;
745
+ }
746
+ this.selectedKeys.set(ImmutableSet.create(keys));
747
+ }
748
+ setTextField(selector) {
749
+ this.textField.set(selector);
750
+ }
751
+ getCheckKey(node) {
752
+ const checkBy = this.checkBy();
753
+ if (!checkBy) {
754
+ return node.data;
755
+ }
756
+ if (typeof checkBy === "string") {
757
+ return node.data[checkBy];
758
+ }
759
+ return checkBy(node.data);
760
+ }
761
+ getDisableKey(node) {
762
+ const disableBy = this.disableBy();
763
+ if (!disableBy) {
764
+ return node.data;
765
+ }
766
+ if (typeof disableBy === "string") {
767
+ return node.data[disableBy];
768
+ }
769
+ return disableBy(node.data);
770
+ }
771
+ applyCheckedKeysToNodes() {
772
+ const checkableOptions = this.checkableOptions();
773
+ const checkedKeys = this.#checkedKeys();
774
+ if (checkedKeys.isEmpty()) {
775
+ return;
776
+ }
777
+ this.#nodeDictionary().forEach(entry => {
778
+ const node = entry.value;
779
+ const key = this.getCheckKey(node);
780
+ node.checked.set(checkedKeys.contains(key));
781
+ });
782
+ if (checkableOptions.enabled && checkableOptions.checkParents && checkableOptions.mode !== "single") {
783
+ const allNodes = _a.flatten(this.nodeSet());
784
+ const updatedCheckedKeys = this.#checkedKeys().toEnumerableSet();
785
+ let changed = false;
786
+ allNodes.reverse().forEach(node => {
787
+ const childNodes = node.children();
788
+ if (!childNodes.isEmpty()) {
789
+ const allChildrenChecked = childNodes.all(c => c.checked());
790
+ const key = this.getCheckKey(node);
791
+ if (allChildrenChecked !== node.checked()) {
792
+ node.checked.set(allChildrenChecked);
793
+ changed = true;
794
+ }
795
+ if (allChildrenChecked && !updatedCheckedKeys.contains(key)) {
796
+ updatedCheckedKeys.add(key);
797
+ changed = true;
798
+ }
799
+ else if (!allChildrenChecked && updatedCheckedKeys.contains(key)) {
800
+ updatedCheckedKeys.remove(key);
801
+ changed = true;
802
+ }
803
+ }
804
+ });
805
+ if (changed) {
806
+ this.#checkedKeys.set(updatedCheckedKeys.toImmutableSet());
807
+ }
808
+ }
809
+ }
810
+ computeVisibleUids(nodes, filterText) {
811
+ const visible = new Set();
812
+ for (const node of nodes) {
813
+ const childVisible = this.computeVisibleUids(node.children(), filterText);
814
+ for (const uid of childVisible) {
815
+ visible.add(uid);
816
+ }
817
+ if (childVisible.size > 0 || this.isFiltered(this.getNodeText(node), filterText)) {
818
+ visible.add(node.uid);
819
+ }
820
+ }
821
+ return visible;
822
+ }
823
+ createFlatNodes(data, parentId) {
824
+ const flatIdField = this.#flatIdField();
825
+ const flatParentIdField = this.#flatParentIdField();
826
+ const childrenByParentId = new Map();
827
+ for (const item of data) {
828
+ const dataItem = item;
829
+ const pid = dataItem[flatParentIdField] ?? null;
830
+ if (!childrenByParentId.has(pid)) {
831
+ childrenByParentId.set(pid, []);
832
+ }
833
+ childrenByParentId.get(pid).push(item);
834
+ }
835
+ const buildNodes = (pid, parent) => {
836
+ const items = childrenByParentId.get(pid) ?? [];
837
+ const nodes = new List();
838
+ for (const item of items) {
839
+ const dataItem = item;
840
+ const node = new TreeNode(item);
841
+ node.parent = parent;
842
+ node.children.set(buildNodes(dataItem[flatIdField], node));
843
+ nodes.add(node);
844
+ }
845
+ return nodes.toImmutableSet();
846
+ };
847
+ return buildNodes(parentId, null);
848
+ }
849
+ createHierarchicalNodes(root, parent, nodeDict) {
850
+ const rootList = new List(root);
851
+ const children = this.children();
852
+ if (rootList.isEmpty() || !children) {
853
+ return null;
854
+ }
855
+ const nodes = new EnumerableSet();
856
+ for (const dataItem of rootList) {
857
+ const existingNode = nodeDict.firstOrDefault(n => n.value.data === dataItem);
858
+ let node;
859
+ if (existingNode) {
860
+ node = existingNode.value;
861
+ node.parent = parent;
862
+ }
863
+ else {
864
+ node = new TreeNode(dataItem);
865
+ node.parent = parent;
866
+ }
867
+ if (typeof children === "string") {
868
+ const subNodes = dataItem[children];
869
+ if (subNodes) {
870
+ const childNodes = this.createHierarchicalNodes(subNodes, node, nodeDict);
871
+ node.children.update(list => list.clear().addAll(childNodes ?? []));
872
+ }
873
+ }
874
+ else {
875
+ const result = children(dataItem);
876
+ if (!(result instanceof Observable)) {
877
+ const childNodes = this.createHierarchicalNodes(result, node, nodeDict);
878
+ node.children.update(list => list.clear().addAll(childNodes ?? []));
879
+ }
880
+ }
881
+ nodes.add(node);
882
+ }
883
+ return nodes.toImmutableSet();
884
+ }
885
+ createNodeDictionary(nodes) {
886
+ const flattenedNodes = _a.flatten(nodes);
887
+ return flattenedNodes.toImmutableDictionary(n => n.uid, n => n);
888
+ }
889
+ createNodes(data) {
890
+ const structure = this.#structure();
891
+ if (structure === "flat") {
892
+ return this.createFlatNodes(data, null).toImmutableSet();
893
+ }
894
+ const nodeDictionary = this.#nodeDictionary();
895
+ return this.createHierarchicalNodes(data, null, nodeDictionary) ?? ImmutableSet.create();
896
+ }
897
+ getExpandKey(node) {
898
+ const expandBy = this.expandBy();
899
+ if (!expandBy) {
900
+ return node.data;
901
+ }
902
+ if (typeof expandBy === "string") {
903
+ return node.data[expandBy];
904
+ }
905
+ return expandBy(node.data);
906
+ }
907
+ getChildNodes(node) {
908
+ const nodes = _a.flatten([node]);
909
+ return nodes.where(n => n !== node).toImmutableSet();
910
+ }
911
+ getDataItemSelectKey(dataItem) {
912
+ const selectBy = this.selectBy();
913
+ if (!selectBy) {
914
+ return dataItem;
915
+ }
916
+ if (typeof selectBy === "string") {
917
+ return dataItem[selectBy] ?? dataItem;
918
+ }
919
+ return selectBy(dataItem);
920
+ }
921
+ getParentNodes(node) {
922
+ const nodes = new List();
923
+ let current = node.parent;
924
+ while (current !== null) {
925
+ nodes.add(current);
926
+ current = current.parent;
927
+ }
928
+ return nodes.toImmutableSet();
929
+ }
930
+ getSelectKey(node) {
931
+ const selectBy = this.selectBy();
932
+ if (!selectBy) {
933
+ return node.data;
934
+ }
935
+ if (typeof selectBy === "string") {
936
+ return node.data[selectBy];
937
+ }
938
+ return selectBy(node.data);
939
+ }
940
+ isAnyParentCollapsed(node) {
941
+ if (node.parent) {
942
+ return !this.isExpanded(node.parent) || this.isAnyParentCollapsed(node.parent);
943
+ }
944
+ return false;
945
+ }
946
+ isAnyParentDisabled(node) {
947
+ if (node.parent) {
948
+ return this.isDisabled(node.parent) || this.isAnyParentDisabled(node.parent);
949
+ }
950
+ return false;
951
+ }
952
+ isFiltered(nodeText, filterText) {
953
+ const text = this.filterableOptions().caseSensitive ? nodeText : nodeText.toLowerCase();
954
+ const filter = this.filterableOptions().caseSensitive ? filterText : filterText.toLowerCase();
955
+ const operator = this.filterableOptions().operator;
956
+ if (typeof operator === "function") {
957
+ return operator(text, filter);
958
+ }
959
+ if (operator === "contains") {
960
+ return text.indexOf(filter) >= 0;
961
+ }
962
+ if (operator === "endsWith") {
963
+ return text.endsWith(filter);
964
+ }
965
+ if (operator === "startsWith") {
966
+ return text.startsWith(filter);
967
+ }
968
+ return text.indexOf(filter) >= 0;
969
+ }
970
+ loadCheckedKeysForChildren(node, childNodes) {
971
+ const checkedKeys = this.#checkedKeys();
972
+ if (node.checked() && this.checkableOptions().checkChildren) {
973
+ const checkDisabledChildren = this.checkableOptions().checkDisabledChildren;
974
+ const childKeys = new EnumerableSet();
975
+ forEach(childNodes, n => {
976
+ if (checkDisabledChildren || !this.isDisabled(n)) {
977
+ const childKey = this.getCheckKey(n);
978
+ childKeys.add(childKey);
979
+ n.checked.set(true);
980
+ }
981
+ });
982
+ this.#checkedKeys.set(checkedKeys.addAll(childKeys));
983
+ }
984
+ else {
985
+ forEach(childNodes, n => {
986
+ const childKey = this.getCheckKey(n);
987
+ if (checkedKeys.contains(childKey)) {
988
+ n.checked.set(true);
989
+ }
990
+ });
991
+ }
992
+ }
993
+ moveNodeAfter(sourceNode, targetNode) {
994
+ if (sourceNode.parent) {
995
+ sourceNode.parent.children.update(list => {
996
+ const sourceNodeParent = sourceNode.parent;
997
+ return list.clear().addAll(sourceNodeParent.children().where(n => n !== sourceNode));
998
+ });
999
+ }
1000
+ if (targetNode.parent) {
1001
+ const index = targetNode.parent.children().toImmutableList().indexOf(targetNode);
1002
+ if (index === -1) {
1003
+ return;
1004
+ }
1005
+ targetNode.parent.children.update(set => {
1006
+ const tempList = set.toList();
1007
+ tempList.addAt(sourceNode, index + 1);
1008
+ return tempList.toImmutableSet();
1009
+ });
1010
+ if (!sourceNode.parent) {
1011
+ this.nodeSet.update(nodes => nodes.remove(sourceNode));
1012
+ }
1013
+ sourceNode.parent = targetNode.parent;
1014
+ }
1015
+ else {
1016
+ const index = this.nodeSet()
1017
+ .where(n => n !== sourceNode)
1018
+ .toList()
1019
+ .indexOf(targetNode);
1020
+ if (index === -1) {
1021
+ return;
1022
+ }
1023
+ this.nodeSet.update(nodes => {
1024
+ const newNodes = nodes.where(n => n !== sourceNode).toList();
1025
+ newNodes.addAt(sourceNode, index + 1);
1026
+ return newNodes.toImmutableSet();
1027
+ });
1028
+ sourceNode.parent = null;
1029
+ }
1030
+ }
1031
+ moveNodeBefore(sourceNode, targetNode) {
1032
+ if (sourceNode.parent) {
1033
+ sourceNode.parent.children.update(list => {
1034
+ const sourceNodeParent = sourceNode.parent;
1035
+ return list.clear().addAll(sourceNodeParent.children().where(n => n !== sourceNode));
1036
+ });
1037
+ }
1038
+ if (targetNode.parent) {
1039
+ const index = targetNode.parent.children().toImmutableList().indexOf(targetNode);
1040
+ if (index === -1) {
1041
+ return;
1042
+ }
1043
+ targetNode.parent.children.update(set => {
1044
+ const tempList = set.toList();
1045
+ tempList.addAt(sourceNode, index);
1046
+ return tempList.toImmutableSet();
1047
+ });
1048
+ if (!sourceNode.parent) {
1049
+ this.nodeSet.update(nodes => nodes.remove(sourceNode));
1050
+ }
1051
+ sourceNode.parent = targetNode.parent;
1052
+ }
1053
+ else {
1054
+ const index = this.nodeSet()
1055
+ .where(n => n !== sourceNode)
1056
+ .toList()
1057
+ .indexOf(targetNode);
1058
+ if (index === -1) {
1059
+ return;
1060
+ }
1061
+ this.nodeSet.update(nodes => {
1062
+ const newNodes = nodes.where(n => n !== sourceNode).toList();
1063
+ newNodes.addAt(sourceNode, index);
1064
+ return newNodes.toImmutableSet();
1065
+ });
1066
+ sourceNode.parent = null;
1067
+ }
1068
+ }
1069
+ moveNodeInside(sourceNode, targetNode) {
1070
+ if (sourceNode.parent === targetNode || this.isDisabled(targetNode)) {
1071
+ return;
1072
+ }
1073
+ if (sourceNode.parent) {
1074
+ sourceNode.parent.children.update(list => {
1075
+ const sourceNodeParent = sourceNode.parent;
1076
+ return list.clear().addAll(sourceNodeParent.children().where(n => n !== sourceNode));
1077
+ });
1078
+ }
1079
+ else {
1080
+ this.nodeSet.update(nodes => nodes.remove(sourceNode));
1081
+ }
1082
+ targetNode.children.update(list => list.add(sourceNode));
1083
+ sourceNode.parent = targetNode;
1084
+ this.nodeSet.update(n => n.toImmutableSet());
1085
+ }
1086
+ navigateToNextNode() {
1087
+ const navigableNodes = this.#navigableNodes();
1088
+ const navigatedNode = this.navigatedNode();
1089
+ const firstNode = navigableNodes.first();
1090
+ let nextNode = navigableNodes
1091
+ .skipWhile(n => n !== navigatedNode)
1092
+ .skip(1)
1093
+ .firstOrDefault();
1094
+ if (nextNode === null) {
1095
+ this.navigatedNode.set(firstNode);
1096
+ return firstNode;
1097
+ }
1098
+ else {
1099
+ this.navigatedNode.set(nextNode);
1100
+ return nextNode;
1101
+ }
1102
+ }
1103
+ navigateToPreviousNode() {
1104
+ const navigableNodes = this.#navigableNodes();
1105
+ const navigatedNode = this.navigatedNode();
1106
+ let previousNode = navigableNodes.takeWhile(n => n !== navigatedNode).lastOrDefault();
1107
+ if (previousNode === null) {
1108
+ this.navigatedNode.set(navigableNodes.last());
1109
+ return navigableNodes.last();
1110
+ }
1111
+ else {
1112
+ this.navigatedNode.set(previousNode);
1113
+ return previousNode;
1114
+ }
1115
+ }
1116
+ recalculateCheckedAncestors(oldParent, newParent) {
1117
+ const checkableOptions = this.checkableOptions();
1118
+ if (!checkableOptions.enabled || !checkableOptions.checkParents || checkableOptions.mode === "single") {
1119
+ return;
1120
+ }
1121
+ const checkedKeys = this.#checkedKeys().toEnumerableSet();
1122
+ let changed = false;
1123
+ const recalculateNodeChain = (start) => {
1124
+ let current = start;
1125
+ while (current !== null) {
1126
+ const childNodes = current.children();
1127
+ if (childNodes.isEmpty()) {
1128
+ current = current.parent;
1129
+ continue;
1130
+ }
1131
+ const allChecked = childNodes.all(c => c.checked());
1132
+ const key = this.getCheckKey(current);
1133
+ if (allChecked !== current.checked()) {
1134
+ current.checked.set(allChecked);
1135
+ changed = true;
1136
+ }
1137
+ if (allChecked && !checkedKeys.contains(key)) {
1138
+ checkedKeys.add(key);
1139
+ changed = true;
1140
+ }
1141
+ else if (!allChecked && checkedKeys.contains(key)) {
1142
+ checkedKeys.remove(key);
1143
+ changed = true;
1144
+ }
1145
+ current = current.parent;
1146
+ }
1147
+ };
1148
+ recalculateNodeChain(oldParent);
1149
+ if (newParent !== oldParent) {
1150
+ recalculateNodeChain(newParent);
1151
+ }
1152
+ if (changed) {
1153
+ this.#checkedKeys.set(checkedKeys.toImmutableSet());
1154
+ }
1155
+ }
1156
+ restoreExpandedChildren(childNodes) {
1157
+ const expandedKeys = this.expandedKeys();
1158
+ for (const childNode of childNodes) {
1159
+ const key = this.getExpandKey(childNode);
1160
+ if (expandedKeys.contains(key)) {
1161
+ this.loadNodeChildren(childNode);
1162
+ }
1163
+ }
1164
+ }
1165
+ updateNodeIndices() {
1166
+ const updateRecursively = (nodes, parent) => {
1167
+ let index = 0;
1168
+ for (const node of nodes) {
1169
+ node.index = parent == null ? String(index++) : `${parent.index}.${index++}`;
1170
+ updateRecursively(node.children(), node);
1171
+ }
1172
+ };
1173
+ updateRecursively(this.nodeSet(), null);
1174
+ }
1175
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1176
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeService }); }
1177
+ }
1178
+ _a = TreeService;
1179
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeService, decorators: [{
1180
+ type: Injectable
1181
+ }], ctorParameters: () => [] });
1182
+
1183
+ const subTreeListVariants = cva(`
1184
+ list-none flex flex-col
1185
+ `);
1186
+ const subTreeListItemVariants = cva(`
1187
+ relative overflow-hidden outline-none
1188
+ ps-6
1189
+ `);
1190
+ const treeBaseVariants = cva(`
1191
+ relative outline-none select-none
1192
+ text-md
1193
+ `);
1194
+ const treeDropHintBaseVariants = cva(`
1195
+ fixed z-1 w-10 h-0.5
1196
+ bg-primary opacity-80
1197
+ pointer-events-none
1198
+ `);
1199
+ const treeDropHintIconVariants = cva(`
1200
+ absolute flex items-center justify-center
1201
+ -top-3.25 -left-3.5 text-xl
1202
+ `);
1203
+ const treeNodeBaseVariants = cva(`
1204
+ px-2 py-1 cursor-default
1205
+ `, {
1206
+ variants: {
1207
+ disabled: {
1208
+ true: "pointer-events-none opacity-50 cursor-default",
1209
+ false: ""
1210
+ },
1211
+ highlighted: {
1212
+ true: "inset-ring-1 inset-ring-gray-400/70",
1213
+ false: ""
1214
+ },
1215
+ selected: {
1216
+ true: "bg-primary text-primary-foreground",
1217
+ false: ""
1218
+ }
1219
+ },
1220
+ compoundVariants: [
1221
+ {
1222
+ disabled: false,
1223
+ selected: false,
1224
+ class: "hover:bg-hover active:bg-active"
1225
+ },
1226
+ {
1227
+ disabled: false,
1228
+ selected: true,
1229
+ class: "hover:bg-primary-hover"
1230
+ }
1231
+ ]
1232
+ });
1233
+ const treeNodeContainerVariants = cva(`
1234
+ flex items-center
1235
+ `);
1236
+ const treeNodeDraggingVariants = cva(`
1237
+ flex items-center justify-center
1238
+ px-2! py-1! top-3!
1239
+ bg-background! text-foreground!
1240
+ border! border-border!
1241
+ shadow-md
1242
+ `);
1243
+ const treeNodeExpanderVariants = cva(`
1244
+ min-w-6 h-full -ms-6
1245
+ flex items-center justify-center
1246
+ cursor-pointer text-sm text-foreground
1247
+ `);
1248
+
1249
+ const subTreeListThemeVariants = (theme) => {
1250
+ switch (theme) {
1251
+ case "mona":
1252
+ return subTreeListVariants;
1253
+ default:
1254
+ return subTreeListVariants;
1255
+ }
1256
+ };
1257
+ const subTreeListItemThemeVariants = (theme) => {
1258
+ switch (theme) {
1259
+ case "mona":
1260
+ return subTreeListItemVariants;
1261
+ default:
1262
+ return subTreeListItemVariants;
1263
+ }
1264
+ };
1265
+ const treeBaseThemeVariants = (theme) => {
1266
+ switch (theme) {
1267
+ case "mona":
1268
+ return treeBaseVariants;
1269
+ default:
1270
+ return treeBaseVariants;
1271
+ }
1272
+ };
1273
+ const treeDropHintBaseThemeVariants = (theme) => {
1274
+ switch (theme) {
1275
+ case "mona":
1276
+ return treeDropHintBaseVariants;
1277
+ default:
1278
+ return treeDropHintBaseVariants;
1279
+ }
1280
+ };
1281
+ const treeDropHintIconThemeVariants = (theme) => {
1282
+ switch (theme) {
1283
+ case "mona":
1284
+ return treeDropHintIconVariants;
1285
+ default:
1286
+ return treeDropHintIconVariants;
1287
+ }
1288
+ };
1289
+ const treeNodeBaseThemeVariants = (theme) => {
1290
+ switch (theme) {
1291
+ case "mona":
1292
+ return treeNodeBaseVariants;
1293
+ default:
1294
+ return treeNodeBaseVariants;
1295
+ }
1296
+ };
1297
+ const treeNodeContainerThemeVariants = (theme) => {
1298
+ switch (theme) {
1299
+ case "mona":
1300
+ return treeNodeContainerVariants;
1301
+ default:
1302
+ return treeNodeContainerVariants;
1303
+ }
1304
+ };
1305
+ const treeNodeDraggingThemeVariants = (theme) => {
1306
+ switch (theme) {
1307
+ case "mona":
1308
+ return treeNodeDraggingVariants;
1309
+ default:
1310
+ return treeNodeDraggingVariants;
1311
+ }
1312
+ };
1313
+ const treeNodeExpanderThemeVariants = (theme) => {
1314
+ switch (theme) {
1315
+ case "mona":
1316
+ return treeNodeExpanderVariants;
1317
+ default:
1318
+ return treeNodeExpanderVariants;
1319
+ }
1320
+ };
1321
+
1322
+ class NodeEvent extends PreventableEvent {
1323
+ #node;
1324
+ constructor(type, node, event) {
1325
+ super(type, event);
1326
+ this.#node = node;
1327
+ }
1328
+ get nodeItem() {
1329
+ return {
1330
+ data: this.#node.data,
1331
+ hasChildren: this.#node.children().length > 0,
1332
+ uid: this.#node.uid
1333
+ };
1334
+ }
1335
+ }
1336
+
1337
+ class NodeDragEndEvent extends NodeEvent {
1338
+ constructor(node, event) {
1339
+ super("nodeDragEnd", node, event);
1340
+ }
1341
+ }
1342
+
1343
+ class NodeDragEvent {
1344
+ #event;
1345
+ #node;
1346
+ #targetNode;
1347
+ #type = "nodeDrag";
1348
+ constructor(node, targetNode, event) {
1349
+ this.#node = node;
1350
+ this.#event = event;
1351
+ this.#targetNode = targetNode;
1352
+ }
1353
+ get nodeItem() {
1354
+ return this.#node.nodeItem;
1355
+ }
1356
+ get originalEvent() {
1357
+ return this.#event;
1358
+ }
1359
+ get targetNodeItem() {
1360
+ return this.#targetNode?.nodeItem ?? null;
1361
+ }
1362
+ get type() {
1363
+ return this.#type;
1364
+ }
1365
+ }
1366
+ class InternalNodeDragEvent {
1367
+ #dragEvent;
1368
+ #dropAllowed;
1369
+ constructor(dragEvent, dropAllowed) {
1370
+ this.#dragEvent = dragEvent;
1371
+ this.#dropAllowed = dropAllowed;
1372
+ }
1373
+ get dragEvent() {
1374
+ return this.#dragEvent;
1375
+ }
1376
+ get dropAllowed() {
1377
+ return this.#dropAllowed;
1378
+ }
1379
+ }
1380
+
1381
+ class NodeDragStartEvent extends NodeEvent {
1382
+ constructor(node, event) {
1383
+ super("nodeDragStart", node, event);
1384
+ }
1385
+ }
1386
+
1387
+ class NodeDropEvent extends NodeEvent {
1388
+ #params;
1389
+ constructor(params) {
1390
+ super("nodeDrop", params.sourceNode, params.event);
1391
+ this.#params = params;
1392
+ }
1393
+ get position() {
1394
+ return this.#params.position;
1395
+ }
1396
+ get sourceNode() {
1397
+ return this.#params.sourceNode.nodeItem;
1398
+ }
1399
+ get targetNode() {
1400
+ return this.#params.targetNode.nodeItem;
1401
+ }
1402
+ get treeView() {
1403
+ return this.#params.treeView;
1404
+ }
1405
+ }
1406
+ class NodeDropEventSansTree extends NodeEvent {
1407
+ #params;
1408
+ constructor(params) {
1409
+ super("nodeDropSansTree", params.sourceNode, params.event);
1410
+ this.#params = params;
1411
+ }
1412
+ get event() {
1413
+ return this.#params.event;
1414
+ }
1415
+ get position() {
1416
+ return this.#params.position;
1417
+ }
1418
+ get sourceNode() {
1419
+ return this.#params.sourceNode;
1420
+ }
1421
+ get targetNode() {
1422
+ return this.#params.targetNode;
1423
+ }
1424
+ }
1425
+
1426
+ class TreeNodeElementIdPipe {
1427
+ transform(uid) {
1428
+ return getTreeNodeElementId(uid);
1429
+ }
1430
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeElementIdPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
1431
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeElementIdPipe, isStandalone: true, name: "treeNodeElementId" }); }
1432
+ }
1433
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeElementIdPipe, decorators: [{
1434
+ type: Pipe,
1435
+ args: [{
1436
+ name: "treeNodeElementId"
1437
+ }]
1438
+ }] });
1439
+
1440
+ class NodeClickEvent extends PreventableEvent {
1441
+ #node;
1442
+ constructor(node, event) {
1443
+ super("nodeClick", event);
1444
+ this.#node = node;
1445
+ }
1446
+ get nodeItem() {
1447
+ return {
1448
+ data: this.#node.data,
1449
+ hasChildren: this.#node.children().length > 0,
1450
+ uid: this.#node.uid
1451
+ };
1452
+ }
1453
+ }
1454
+
1455
+ class TreeNodeComponent {
1456
+ #destroyRef;
1457
+ #themeService;
1458
+ #dragging;
1459
+ constructor() {
1460
+ this.#destroyRef = inject(DestroyRef);
1461
+ this.#themeService = inject(ThemeService);
1462
+ this.treeService = inject((TreeService));
1463
+ this.#dragging = toSignal(this.treeService.dragging$, {
1464
+ initialValue: false
1465
+ });
1466
+ this.baseClass = computed(() => {
1467
+ const theme = this.#themeService.theme();
1468
+ const disabled = this.disabled();
1469
+ const highlighted = this.navigated();
1470
+ const selected = this.selected();
1471
+ return treeNodeBaseThemeVariants(theme)({ disabled, highlighted, selected });
1472
+ }, /* @ts-ignore */
1473
+ ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
1474
+ this.checkable = computed(() => {
1475
+ const node = this.node();
1476
+ if (node === null) {
1477
+ return false;
1478
+ }
1479
+ return this.treeService.isCheckable(node);
1480
+ }, /* @ts-ignore */
1481
+ ...(ngDevMode ? [{ debugName: "checkable" }] : /* istanbul ignore next */ []));
1482
+ this.checkboxCheck$ = new Subject();
1483
+ this.checkboxClick$ = new Subject();
1484
+ this.checked = computed(() => {
1485
+ const node = this.node();
1486
+ this.#dragging();
1487
+ if (node === null) {
1488
+ return false;
1489
+ }
1490
+ return this.treeService.isChecked(node);
1491
+ }, /* @ts-ignore */
1492
+ ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
1493
+ this.disabled = computed(() => {
1494
+ const node = this.node();
1495
+ if (node === null) {
1496
+ return false;
1497
+ }
1498
+ return this.treeService.isDisabled(node);
1499
+ }, /* @ts-ignore */
1500
+ ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
1501
+ this.expandable = computed(() => {
1502
+ const node = this.node();
1503
+ const expandableOptions = this.treeService.expandableOptions();
1504
+ const childrenSelector = this.treeService.children();
1505
+ const children = node?.children() ?? [];
1506
+ if (node === null) {
1507
+ return false;
1508
+ }
1509
+ if (!expandableOptions.enabled) {
1510
+ return false;
1511
+ }
1512
+ if (typeof childrenSelector === "function") {
1513
+ return this.treeService.hasChildren(node);
1514
+ }
1515
+ return children.length > 0;
1516
+ }, /* @ts-ignore */
1517
+ ...(ngDevMode ? [{ debugName: "expandable" }] : /* istanbul ignore next */ []));
1518
+ this.expanded = computed(() => {
1519
+ const node = this.node();
1520
+ if (node === null) {
1521
+ return true;
1522
+ }
1523
+ return this.treeService.isExpanded(node);
1524
+ }, /* @ts-ignore */
1525
+ ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
1526
+ this.indeterminate = computed(() => {
1527
+ const node = this.node();
1528
+ this.#dragging();
1529
+ if (node === null) {
1530
+ return false;
1531
+ }
1532
+ return this.treeService.isIndeterminate(node);
1533
+ }, /* @ts-ignore */
1534
+ ...(ngDevMode ? [{ debugName: "indeterminate" }] : /* istanbul ignore next */ []));
1535
+ this.navigated = computed(() => {
1536
+ const node = this.node();
1537
+ if (node === null) {
1538
+ return false;
1539
+ }
1540
+ return this.treeService.isNavigated(node);
1541
+ }, /* @ts-ignore */
1542
+ ...(ngDevMode ? [{ debugName: "navigated" }] : /* istanbul ignore next */ []));
1543
+ this.nodeText = computed(() => {
1544
+ const node = this.node();
1545
+ if (node === null) {
1546
+ return "";
1547
+ }
1548
+ return this.treeService.getNodeText(node);
1549
+ }, /* @ts-ignore */
1550
+ ...(ngDevMode ? [{ debugName: "nodeText" }] : /* istanbul ignore next */ []));
1551
+ this.selected = computed(() => {
1552
+ const node = this.node();
1553
+ if (node === null) {
1554
+ return false;
1555
+ }
1556
+ return this.treeService.isSelected(node);
1557
+ }, /* @ts-ignore */
1558
+ ...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
1559
+ this.depth = input(0, /* @ts-ignore */
1560
+ ...(ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []));
1561
+ this.node = input(null, /* @ts-ignore */
1562
+ ...(ngDevMode ? [{ debugName: "node" }] : /* istanbul ignore next */ []));
1563
+ this.setCheckboxClickSubscription();
1564
+ }
1565
+ onNodeClick(event) {
1566
+ const node = this.node();
1567
+ if (node === null) {
1568
+ return;
1569
+ }
1570
+ if (this.treeService.isDisabled(node)) {
1571
+ return;
1572
+ }
1573
+ if (event.type === "contextmenu") {
1574
+ event.preventDefault();
1575
+ return;
1576
+ }
1577
+ const nodeClickEvent = this.notifyNodeClick(event);
1578
+ if (nodeClickEvent.isDefaultPrevented()) {
1579
+ return;
1580
+ }
1581
+ this.treeService.navigatedNode.set(node);
1582
+ const selectableOptions = this.treeService.selectableOptions();
1583
+ if (!selectableOptions.enabled) {
1584
+ return;
1585
+ }
1586
+ if (selectableOptions.childrenOnly && this.treeService.hasChildren(node)) {
1587
+ return;
1588
+ }
1589
+ const nodeSelectEvent = new NodeSelectEvent(node, event);
1590
+ this.treeService.nodeSelect$.next(nodeSelectEvent);
1591
+ if (nodeSelectEvent.isDefaultPrevented()) {
1592
+ return;
1593
+ }
1594
+ const newSelected = !this.selected();
1595
+ this.treeService.setNodeSelect(node, newSelected);
1596
+ this.treeService.nodeSelectChange$.next({ node, selected: newSelected });
1597
+ this.treeService.notifySelectionChange(node);
1598
+ }
1599
+ onNodeContextMenu(event) {
1600
+ const node = this.node();
1601
+ if (node === null) {
1602
+ return;
1603
+ }
1604
+ if (this.treeService.isDisabled(node)) {
1605
+ return;
1606
+ }
1607
+ this.treeService.navigatedNode.set(node);
1608
+ }
1609
+ notifyNodeClick(event) {
1610
+ const node = this.node();
1611
+ const nodeClickEvent = new NodeClickEvent(node, event);
1612
+ this.treeService.nodeClick$.next(nodeClickEvent);
1613
+ return nodeClickEvent;
1614
+ }
1615
+ setCheckboxClickSubscription() {
1616
+ this.checkboxClick$
1617
+ .pipe(takeUntilDestroyed(this.#destroyRef), filter(() => this.checkable() && !this.disabled()), tap(e => {
1618
+ e.preventDefault();
1619
+ e.stopPropagation();
1620
+ }), map(event => {
1621
+ const node = this.node();
1622
+ const nodeCheckEvent = new NodeCheckEvent(node, event);
1623
+ this.treeService.nodeCheck$.next(nodeCheckEvent);
1624
+ return nodeCheckEvent;
1625
+ }))
1626
+ .subscribe(event => {
1627
+ const node = this.node();
1628
+ if (event.isDefaultPrevented()) {
1629
+ event.originalEvent?.preventDefault();
1630
+ return;
1631
+ }
1632
+ const checked = this.treeService.isChecked(node);
1633
+ this.treeService.setNodeCheck(node, !checked);
1634
+ this.treeService.nodeCheckChange$.next({ node, checked: !checked });
1635
+ });
1636
+ }
1637
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1638
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TreeNodeComponent, isStandalone: true, selector: "mona-tree-node", inputs: { depth: { classPropertyName: "depth", publicName: "depth", isSignal: true, isRequired: false, transformFunction: null }, node: { classPropertyName: "node", publicName: "node", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<div [class]=\"baseClass()\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeContextMenu($event)\" #element>\r\n @if (treeService.nodeTemplate()) {\r\n <ng-container\r\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\r\n [ngTemplateOutletContext]=\"{\r\n $implicit: node()?.data,\r\n element: element.parentElement\r\n }\"></ng-container>\r\n } @else {\r\n <span class=\"truncate\">{{ nodeText() }}</span>\r\n }\r\n</div>\r\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1639
+ }
1640
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeComponent, decorators: [{
1641
+ type: Component,
1642
+ args: [{ selector: "mona-tree-node", changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgTemplateOutlet], template: "<div [class]=\"baseClass()\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeContextMenu($event)\" #element>\r\n @if (treeService.nodeTemplate()) {\r\n <ng-container\r\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\r\n [ngTemplateOutletContext]=\"{\r\n $implicit: node()?.data,\r\n element: element.parentElement\r\n }\"></ng-container>\r\n } @else {\r\n <span class=\"truncate\">{{ nodeText() }}</span>\r\n }\r\n</div>\r\n" }]
1643
+ }], ctorParameters: () => [], propDecorators: { depth: [{ type: i0.Input, args: [{ isSignal: true, alias: "depth", required: false }] }], node: [{ type: i0.Input, args: [{ isSignal: true, alias: "node", required: false }] }] } });
1644
+
1645
+ class SubTreeComponent {
1646
+ constructor() {
1647
+ this.#document = inject(DOCUMENT);
1648
+ this.#themeService = inject(ThemeService);
1649
+ this.#zone = inject(NgZone);
1650
+ this.listClass = computed(() => {
1651
+ const theme = this.#themeService.theme();
1652
+ return subTreeListThemeVariants(theme)();
1653
+ }, /* @ts-ignore */
1654
+ ...(ngDevMode ? [{ debugName: "listClass" }] : /* istanbul ignore next */ []));
1655
+ this.listItemClass = computed(() => {
1656
+ const theme = this.#themeService.theme();
1657
+ return subTreeListItemThemeVariants(theme)();
1658
+ }, /* @ts-ignore */
1659
+ ...(ngDevMode ? [{ debugName: "listItemClass" }] : /* istanbul ignore next */ []));
1660
+ this.nodeContainerClass = computed(() => {
1661
+ const theme = this.#themeService.theme();
1662
+ return treeNodeContainerThemeVariants(theme)();
1663
+ }, /* @ts-ignore */
1664
+ ...(ngDevMode ? [{ debugName: "nodeContainerClass" }] : /* istanbul ignore next */ []));
1665
+ this.nodeDraggingClass = computed(() => {
1666
+ const theme = this.#themeService.theme();
1667
+ return treeNodeDraggingThemeVariants(theme)();
1668
+ }, /* @ts-ignore */
1669
+ ...(ngDevMode ? [{ debugName: "nodeDraggingClass" }] : /* istanbul ignore next */ []));
1670
+ this.nodeExpandEnterClass = computed(() => this.nodeAnimationDisabled() ? "" : "mona-tree-node-expand-enter", /* @ts-ignore */
1671
+ ...(ngDevMode ? [{ debugName: "nodeExpandEnterClass" }] : /* istanbul ignore next */ []));
1672
+ this.nodeExpandLeaveClass = computed(() => this.nodeAnimationDisabled() ? "" : "mona-tree-node-expand-leave", /* @ts-ignore */
1673
+ ...(ngDevMode ? [{ debugName: "nodeExpandLeaveClass" }] : /* istanbul ignore next */ []));
1674
+ this.nodeExpanderClass = computed(() => {
1675
+ const theme = this.#themeService.theme();
1676
+ return treeNodeExpanderThemeVariants(theme)();
1677
+ }, /* @ts-ignore */
1678
+ ...(ngDevMode ? [{ debugName: "nodeExpanderClass" }] : /* istanbul ignore next */ []));
1679
+ this.treeService = inject(TreeService);
1680
+ this.visibleNodes = computed(() => {
1681
+ return this.nodes()
1682
+ .where(n => this.treeService.isVisible(n))
1683
+ .toImmutableSet();
1684
+ }, /* @ts-ignore */
1685
+ ...(ngDevMode ? [{ debugName: "visibleNodes" }] : /* istanbul ignore next */ []));
1686
+ this.depth = input.required(/* @ts-ignore */
1687
+ ...(ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []));
1688
+ this.nodes = input.required({ ...(ngDevMode ? { debugName: "nodes" } : /* istanbul ignore next */ {}), transform: value => ImmutableSet.create(value) });
1689
+ this.parent = input.required(/* @ts-ignore */
1690
+ ...(ngDevMode ? [{ debugName: "parent" }] : /* istanbul ignore next */ []));
1691
+ }
1692
+ #document;
1693
+ #themeService;
1694
+ #zone;
1695
+ nodeAnimationDisabled() {
1696
+ return (!this.treeService.animationEnabled() ||
1697
+ this.treeService.animationTemporarilyDisabled() ||
1698
+ this.treeService.filterText().length !== 0);
1699
+ }
1700
+ onExpandStateChange(node) {
1701
+ const expanded = this.treeService.isExpanded(node);
1702
+ if (!expanded) {
1703
+ this.treeService.loadNodeChildren(node);
1704
+ }
1705
+ this.treeService.setNodeExpand(node, !expanded);
1706
+ this.treeService.nodeExpand$.next({ node, expanded: !expanded });
1707
+ }
1708
+ onNodeDragEnd(event) {
1709
+ const nodeDragEndEvent = new NodeDragEndEvent(event.source.data, event.event);
1710
+ this.treeService.nodeDragEnd$.next(nodeDragEndEvent);
1711
+ if (nodeDragEndEvent.isDefaultPrevented()) {
1712
+ return;
1713
+ }
1714
+ this.treeService.dropAllowed.set(false);
1715
+ this.treeService.dragging.set(false);
1716
+ }
1717
+ onNodeDragMove(event, node) {
1718
+ this.treeService.dropPositionChange$.pipe(take(1)).subscribe(e => {
1719
+ if (e == null) {
1720
+ return;
1721
+ }
1722
+ const nodeDragEvent = new NodeDragEvent(node, e.targetNode, event.event);
1723
+ const dropAllowed = e.position !== "outside" &&
1724
+ e.targetNode != null &&
1725
+ e.targetNode !== node &&
1726
+ !e.targetNode.isDescendantOf(node);
1727
+ const internalNodeDragEvent = new InternalNodeDragEvent(nodeDragEvent, dropAllowed);
1728
+ this.treeService.dropAllowed.set(dropAllowed);
1729
+ this.treeService.nodeDrag$.next(internalNodeDragEvent);
1730
+ });
1731
+ }
1732
+ onNodeDragStart(event) {
1733
+ const node = event.source.data;
1734
+ if (this.treeService.isDisabled(node)) {
1735
+ event.event.stopPropagation();
1736
+ return;
1737
+ }
1738
+ const nodeDragStartEvent = new NodeDragStartEvent(node, event.event);
1739
+ this.treeService.nodeDragStart$.next(nodeDragStartEvent);
1740
+ if (nodeDragStartEvent.isDefaultPrevented()) {
1741
+ return;
1742
+ }
1743
+ this.treeService.dragging.set(true);
1744
+ }
1745
+ onNodeDrop(event) {
1746
+ this.treeService.dropPositionChange$.pipe(take(1)).subscribe(e => {
1747
+ if (e == null) {
1748
+ return;
1749
+ }
1750
+ const sourceNode = event.item.data;
1751
+ const targetNode = e.targetNode;
1752
+ if (targetNode === null ||
1753
+ sourceNode === targetNode ||
1754
+ targetNode.isDescendantOf(sourceNode) ||
1755
+ e.position === "outside") {
1756
+ return;
1757
+ }
1758
+ this.treeService.animationTemporarilyDisabled.set(true);
1759
+ const nodeDropEvent = new NodeDropEventSansTree({
1760
+ event: event.event,
1761
+ sourceNode,
1762
+ targetNode,
1763
+ position: e.position
1764
+ });
1765
+ this.treeService.nodeDrop$.next(nodeDropEvent);
1766
+ if (nodeDropEvent.isDefaultPrevented()) {
1767
+ this.treeService.animationTemporarilyDisabled.set(false);
1768
+ return;
1769
+ }
1770
+ this.treeService.dropPositionChange$.next(null);
1771
+ this.focusNode(sourceNode);
1772
+ this.#zone.runOutsideAngular(() => asapScheduler.schedule(() => this.treeService.animationTemporarilyDisabled.set(false)));
1773
+ });
1774
+ }
1775
+ focusNode(node) {
1776
+ this.treeService.navigatedNode.set(node);
1777
+ const element = this.#document
1778
+ .querySelector(`li[data-uid="${node.uid}"]`)
1779
+ ?.closest(".mona-tree");
1780
+ if (element == null) {
1781
+ return;
1782
+ }
1783
+ element.focus();
1784
+ }
1785
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SubTreeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1786
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: SubTreeComponent, isStandalone: true, selector: "mona-sub-tree", inputs: { depth: { classPropertyName: "depth", publicName: "depth", isSignal: true, isRequired: true, transformFunction: null }, nodes: { classPropertyName: "nodes", publicName: "nodes", isSignal: true, isRequired: true, transformFunction: null }, parent: { classPropertyName: "parent", publicName: "parent", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<ul\r\n [class]=\"listClass()\"\r\n [attr.role]=\"parent() ? 'group' : null\"\r\n cdkDropList\r\n [cdkDropListSortingDisabled]=\"true\"\r\n (cdkDropListDropped)=\"onNodeDrop($event)\">\r\n @for (node of visibleNodes(); track node.uid) {\r\n <li\r\n [attr.id]=\"node.uid | treeNodeElementId\"\r\n [attr.data-uid]=\"node.uid\"\r\n [class]=\"listItemClass()\"\r\n [tabindex]=\"-1\"\r\n role=\"treeitem\"\r\n [attr.aria-level]=\"depth() + 1\"\r\n [attr.aria-setsize]=\"visibleNodes().length\"\r\n [attr.aria-posinset]=\"$index + 1\"\r\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\r\n [attr.aria-selected]=\"treeService.selectableOptions().enabled ? nodeComponent.selected() : null\"\r\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\r\n [attr.aria-checked]=\"\r\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\r\n \"\r\n (focus)=\"treeService.navigatedNode.set(node)\"\r\n cdkDrag\r\n [cdkDragData]=\"node\"\r\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\r\n (cdkDragStarted)=\"onNodeDragStart($event)\"\r\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\r\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\r\n <div [class]=\"nodeContainerClass()\">\r\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\r\n <button\r\n type=\"button\"\r\n tabindex=\"-1\"\r\n [class]=\"nodeExpanderClass()\"\r\n [class.mona-disabled]=\"nodeComponent.disabled()\"\r\n [attr.aria-label]=\"\r\n (nodeComponent.expanded() ? 'Collapse' : 'Expand') + ' ' + nodeComponent.nodeText()\r\n \"\r\n (click)=\"onExpandStateChange(node)\">\r\n @if (node.loading()) {\r\n <i class=\"ri-loader-2-line\"></i>\r\n } @else if (nodeComponent.expanded()) {\r\n <i class=\"ri-arrow-down-s-fill\"></i>\r\n } @else {\r\n <i class=\"ri-arrow-right-s-fill\"></i>\r\n }\r\n </button>\r\n }\r\n @if (nodeComponent.checkable()) {\r\n <mona-check-box\r\n aria-hidden=\"true\"\r\n [tabIndex]=\"-1\"\r\n [disabled]=\"nodeComponent.disabled()\"\r\n [indeterminate]=\"nodeComponent.indeterminate()\"\r\n [ngModel]=\"nodeComponent.checked()\"\r\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\r\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\r\n }\r\n <mona-tree-node [node]=\"node\" [depth]=\"depth()\" #nodeComponent></mona-tree-node>\r\n </div>\r\n @if (node.children().length > 0 && nodeComponent.expanded()) {\r\n <div\r\n class=\"grid overflow-hidden\"\r\n [animate.enter]=\"nodeExpandEnterClass()\"\r\n [animate.leave]=\"nodeExpandLeaveClass()\">\r\n <div class=\"min-h-0 overflow-hidden\">\r\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\r\n </div>\r\n </div>\r\n }\r\n @if (!nodeComponent.disabled()) {\r\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\r\n <span>\r\n @switch (treeService.dropPositionSignal()?.position) {\r\n @case (\"before\") {\r\n @if (treeService.dropAllowed()) {\r\n <i class=\"ri-arrow-up-line\"></i>\r\n } @else {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n @case (\"after\") {\r\n @if (treeService.dropAllowed()) {\r\n <i class=\"ri-arrow-down-line\"></i>\r\n } @else {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n @case (\"inside\") {\r\n <i class=\"ri-add-line\"></i>\r\n }\r\n @default {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n </span>\r\n <span>{{ nodeComponent.nodeText() }}</span>\r\n </div>\r\n } @else {\r\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\r\n }\r\n </li>\r\n }\r\n</ul>\r\n", styles: [".mona-tree-node-expand-enter{animation:mona-tree-node-expand-in .15s ease-out}.mona-tree-node-expand-leave{animation:mona-tree-node-expand-out .15s ease-out}@keyframes mona-tree-node-expand-in{0%{grid-template-rows:0fr;opacity:0}to{grid-template-rows:1fr;opacity:1}}@keyframes mona-tree-node-expand-out{0%{grid-template-rows:1fr;opacity:1}to{grid-template-rows:0fr;opacity:0}}@media(prefers-reduced-motion:reduce){.mona-tree-node-expand-enter,.mona-tree-node-expand-leave{animation-duration:1ms}}\n"], dependencies: [{ kind: "component", type: SubTreeComponent, selector: "mona-sub-tree", inputs: ["depth", "nodes", "parent"] }, { kind: "component", type: TreeNodeComponent, selector: "mona-tree-node", inputs: ["depth", "node"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: CdkDropList, selector: "[cdkDropList], cdk-drop-list", inputs: ["cdkDropListConnectedTo", "cdkDropListData", "cdkDropListOrientation", "id", "cdkDropListLockAxis", "cdkDropListDisabled", "cdkDropListSortingDisabled", "cdkDropListEnterPredicate", "cdkDropListSortPredicate", "cdkDropListAutoScrollDisabled", "cdkDropListAutoScrollStep", "cdkDropListElementContainer", "cdkDropListHasAnchor"], outputs: ["cdkDropListDropped", "cdkDropListEntered", "cdkDropListExited", "cdkDropListSorted"], exportAs: ["cdkDropList"] }, { kind: "directive", type: CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragData", "cdkDragLockAxis", "cdkDragRootElement", "cdkDragBoundary", "cdkDragStartDelay", "cdkDragFreeDragPosition", "cdkDragDisabled", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragPreviewContainer", "cdkDragScale"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { kind: "directive", type: CdkDragPreview, selector: "ng-template[cdkDragPreview]", inputs: ["data", "matchSize"] }, { kind: "component", type: CheckBoxComponent, selector: "mona-check-box", inputs: ["checked", "disabled", "indeterminate", "invalid", "label", "labelPosition", "labelSize", "required", "rounded", "tabIndex", "touched", "class"], outputs: ["checkedChange", "inputBlur", "inputChange", "inputFocus", "touch"] }, { kind: "pipe", type: TreeNodeElementIdPipe, name: "treeNodeElementId" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1787
+ }
1788
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SubTreeComponent, decorators: [{
1789
+ type: Component,
1790
+ args: [{ selector: "mona-sub-tree", changeDetection: ChangeDetectionStrategy.OnPush, imports: [
1791
+ TreeNodeComponent,
1792
+ FormsModule,
1793
+ CdkDropList,
1794
+ CdkDrag,
1795
+ CdkDragPreview,
1796
+ CheckBoxComponent,
1797
+ TreeNodeElementIdPipe
1798
+ ], template: "<ul\r\n [class]=\"listClass()\"\r\n [attr.role]=\"parent() ? 'group' : null\"\r\n cdkDropList\r\n [cdkDropListSortingDisabled]=\"true\"\r\n (cdkDropListDropped)=\"onNodeDrop($event)\">\r\n @for (node of visibleNodes(); track node.uid) {\r\n <li\r\n [attr.id]=\"node.uid | treeNodeElementId\"\r\n [attr.data-uid]=\"node.uid\"\r\n [class]=\"listItemClass()\"\r\n [tabindex]=\"-1\"\r\n role=\"treeitem\"\r\n [attr.aria-level]=\"depth() + 1\"\r\n [attr.aria-setsize]=\"visibleNodes().length\"\r\n [attr.aria-posinset]=\"$index + 1\"\r\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\r\n [attr.aria-selected]=\"treeService.selectableOptions().enabled ? nodeComponent.selected() : null\"\r\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\r\n [attr.aria-checked]=\"\r\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\r\n \"\r\n (focus)=\"treeService.navigatedNode.set(node)\"\r\n cdkDrag\r\n [cdkDragData]=\"node\"\r\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\r\n (cdkDragStarted)=\"onNodeDragStart($event)\"\r\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\r\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\r\n <div [class]=\"nodeContainerClass()\">\r\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\r\n <button\r\n type=\"button\"\r\n tabindex=\"-1\"\r\n [class]=\"nodeExpanderClass()\"\r\n [class.mona-disabled]=\"nodeComponent.disabled()\"\r\n [attr.aria-label]=\"\r\n (nodeComponent.expanded() ? 'Collapse' : 'Expand') + ' ' + nodeComponent.nodeText()\r\n \"\r\n (click)=\"onExpandStateChange(node)\">\r\n @if (node.loading()) {\r\n <i class=\"ri-loader-2-line\"></i>\r\n } @else if (nodeComponent.expanded()) {\r\n <i class=\"ri-arrow-down-s-fill\"></i>\r\n } @else {\r\n <i class=\"ri-arrow-right-s-fill\"></i>\r\n }\r\n </button>\r\n }\r\n @if (nodeComponent.checkable()) {\r\n <mona-check-box\r\n aria-hidden=\"true\"\r\n [tabIndex]=\"-1\"\r\n [disabled]=\"nodeComponent.disabled()\"\r\n [indeterminate]=\"nodeComponent.indeterminate()\"\r\n [ngModel]=\"nodeComponent.checked()\"\r\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\r\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\r\n }\r\n <mona-tree-node [node]=\"node\" [depth]=\"depth()\" #nodeComponent></mona-tree-node>\r\n </div>\r\n @if (node.children().length > 0 && nodeComponent.expanded()) {\r\n <div\r\n class=\"grid overflow-hidden\"\r\n [animate.enter]=\"nodeExpandEnterClass()\"\r\n [animate.leave]=\"nodeExpandLeaveClass()\">\r\n <div class=\"min-h-0 overflow-hidden\">\r\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\r\n </div>\r\n </div>\r\n }\r\n @if (!nodeComponent.disabled()) {\r\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\r\n <span>\r\n @switch (treeService.dropPositionSignal()?.position) {\r\n @case (\"before\") {\r\n @if (treeService.dropAllowed()) {\r\n <i class=\"ri-arrow-up-line\"></i>\r\n } @else {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n @case (\"after\") {\r\n @if (treeService.dropAllowed()) {\r\n <i class=\"ri-arrow-down-line\"></i>\r\n } @else {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n @case (\"inside\") {\r\n <i class=\"ri-add-line\"></i>\r\n }\r\n @default {\r\n <i class=\"ri-prohibited-2-line\"></i>\r\n }\r\n }\r\n </span>\r\n <span>{{ nodeComponent.nodeText() }}</span>\r\n </div>\r\n } @else {\r\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\r\n }\r\n </li>\r\n }\r\n</ul>\r\n", styles: [".mona-tree-node-expand-enter{animation:mona-tree-node-expand-in .15s ease-out}.mona-tree-node-expand-leave{animation:mona-tree-node-expand-out .15s ease-out}@keyframes mona-tree-node-expand-in{0%{grid-template-rows:0fr;opacity:0}to{grid-template-rows:1fr;opacity:1}}@keyframes mona-tree-node-expand-out{0%{grid-template-rows:1fr;opacity:1}to{grid-template-rows:0fr;opacity:0}}@media(prefers-reduced-motion:reduce){.mona-tree-node-expand-enter,.mona-tree-node-expand-leave{animation-duration:1ms}}\n"] }]
1799
+ }], propDecorators: { depth: [{ type: i0.Input, args: [{ isSignal: true, alias: "depth", required: true }] }], nodes: [{ type: i0.Input, args: [{ isSignal: true, alias: "nodes", required: true }] }], parent: [{ type: i0.Input, args: [{ isSignal: true, alias: "parent", required: true }] }] } });
1800
+
1801
+ class TreeDropHintComponent {
1802
+ #dropPositionChange;
1803
+ #hostElementRef;
1804
+ #themeService;
1805
+ constructor() {
1806
+ this.#dropPositionChange = toSignal(inject(TreeService).dropPositionChange$, {
1807
+ initialValue: null
1808
+ });
1809
+ this.#hostElementRef = inject(ElementRef);
1810
+ this.#themeService = inject(ThemeService);
1811
+ this.baseClass = computed(() => {
1812
+ const theme = this.#themeService.theme();
1813
+ return treeDropHintBaseThemeVariants(theme)();
1814
+ }, /* @ts-ignore */
1815
+ ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
1816
+ this.dropHintStyles = computed(() => {
1817
+ const dropPositionData = this.#dropPositionChange();
1818
+ if (!dropPositionData) {
1819
+ return { display: "none" };
1820
+ }
1821
+ const node = dropPositionData.targetNode;
1822
+ if (!node) {
1823
+ return { display: "none" };
1824
+ }
1825
+ const nodeElement = this.#hostElementRef.nativeElement.parentElement?.querySelector(`[data-uid="${node.uid}"] > div`);
1826
+ if (!nodeElement) {
1827
+ return { display: "none" };
1828
+ }
1829
+ const rect = nodeElement.getBoundingClientRect();
1830
+ const position = dropPositionData.position;
1831
+ const leftOffset = 0;
1832
+ if (position === "before") {
1833
+ return {
1834
+ display: "flex",
1835
+ top: `${rect.top}px`,
1836
+ left: `${rect.left + leftOffset}px`
1837
+ };
1838
+ }
1839
+ else if (position === "after") {
1840
+ return {
1841
+ display: "flex",
1842
+ top: `${rect.bottom}px`,
1843
+ left: `${rect.left + leftOffset}px`
1844
+ };
1845
+ }
1846
+ else {
1847
+ return { display: "none" };
1848
+ }
1849
+ }, /* @ts-ignore */
1850
+ ...(ngDevMode ? [{ debugName: "dropHintStyles" }] : /* istanbul ignore next */ []));
1851
+ this.iconClass = computed(() => {
1852
+ const theme = this.#themeService.theme();
1853
+ const icon = "ri-arrow-right-s-fill";
1854
+ const variantClass = treeDropHintIconThemeVariants(theme)();
1855
+ return twMerge(icon, variantClass);
1856
+ }, /* @ts-ignore */
1857
+ ...(ngDevMode ? [{ debugName: "iconClass" }] : /* istanbul ignore next */ []));
1858
+ afterRenderEffect({
1859
+ write: () => {
1860
+ const styles = this.dropHintStyles();
1861
+ Object.assign(this.#hostElementRef.nativeElement.style, styles);
1862
+ }
1863
+ });
1864
+ }
1865
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeDropHintComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1866
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.6", type: TreeDropHintComponent, isStandalone: true, selector: "mona-tree-drop-hint", host: { properties: { "class": "baseClass()" } }, ngImport: i0, template: "<i [class]=\"iconClass()\"></i>\r\n", changeDetection: i0.ChangeDetectionStrategy.Eager }); }
1867
+ }
1868
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeDropHintComponent, decorators: [{
1869
+ type: Component,
1870
+ args: [{ selector: "mona-tree-drop-hint", changeDetection: ChangeDetectionStrategy.Eager, host: {
1871
+ "[class]": "baseClass()"
1872
+ }, template: "<i [class]=\"iconClass()\"></i>\r\n" }]
1873
+ }], ctorParameters: () => [] });
1874
+
1875
+ class TreeComponent {
1876
+ #destroyRef;
1877
+ #focusMonitor;
1878
+ #hostElementRef;
1879
+ #themeService;
1880
+ #zone;
1881
+ #lastNavigatedNode;
1882
+ constructor() {
1883
+ this.#destroyRef = inject(DestroyRef);
1884
+ this.#focusMonitor = inject(FocusMonitor);
1885
+ this.#hostElementRef = inject(ElementRef);
1886
+ this.#themeService = inject(ThemeService);
1887
+ this.#zone = inject(NgZone);
1888
+ this.#lastNavigatedNode = null;
1889
+ this.activeDescendantId = computed(() => {
1890
+ const node = this.treeService.navigatedNode();
1891
+ return node === null ? null : this.treeService.getNodeElementId(node.uid);
1892
+ }, /* @ts-ignore */
1893
+ ...(ngDevMode ? [{ debugName: "activeDescendantId" }] : /* istanbul ignore next */ []));
1894
+ this.baseClass = computed(() => {
1895
+ const theme = this.#themeService.theme();
1896
+ return treeBaseThemeVariants(theme)();
1897
+ }, /* @ts-ignore */
1898
+ ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
1899
+ this.ariaLabel = input("", /* @ts-ignore */
1900
+ ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
1901
+ this.treeService = inject(TreeService);
1902
+ this.nodeTemplate = contentChild(TreeNodeTemplateDirective, { ...(ngDevMode ? { debugName: "nodeTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
1903
+ this.data = input(/* @ts-ignore */
1904
+ ...(ngDevMode ? [undefined, { debugName: "data" }] : /* istanbul ignore next */ []));
1905
+ effect(() => {
1906
+ const node = this.treeService.navigatedNode();
1907
+ untracked(() => {
1908
+ if (node !== null) {
1909
+ this.#lastNavigatedNode = node;
1910
+ }
1911
+ });
1912
+ });
1913
+ effect(() => {
1914
+ const nodeTemplate = this.nodeTemplate() ?? null;
1915
+ untracked(() => {
1916
+ this.treeService.nodeTemplate.set(nodeTemplate);
1917
+ });
1918
+ });
1919
+ effect(() => {
1920
+ const data = this.data();
1921
+ untracked(() => {
1922
+ if (data != null) {
1923
+ this.treeService.setData(data);
1924
+ }
1925
+ });
1926
+ });
1927
+ afterNextRender({
1928
+ read: () => this.setSubscriptions()
1929
+ });
1930
+ }
1931
+ handleMouseMoveWhileDragging(event) {
1932
+ if (this.isMouseOutsideTree(event)) {
1933
+ this.treeService.dropPositionChange$.next({
1934
+ targetNode: null,
1935
+ position: "outside"
1936
+ });
1937
+ return;
1938
+ }
1939
+ const element = event.target;
1940
+ const closest = element.closest("li");
1941
+ if (!closest) {
1942
+ return;
1943
+ }
1944
+ const nodeUid = closest.getAttribute("data-uid");
1945
+ if (!nodeUid) {
1946
+ return;
1947
+ }
1948
+ const node = this.treeService.getNodeByUid(nodeUid);
1949
+ if (!node) {
1950
+ return;
1951
+ }
1952
+ const nodeElement = closest.querySelector("mona-tree-node");
1953
+ if (!nodeElement) {
1954
+ return;
1955
+ }
1956
+ this.notifyDropPositionChange(event, nodeElement, node);
1957
+ }
1958
+ isMouseOutsideTree(event) {
1959
+ const rect = this.#hostElementRef.nativeElement.getBoundingClientRect();
1960
+ return event.clientY < rect.top || event.clientY > rect.bottom;
1961
+ }
1962
+ notifyDropPositionChange(event, nodeElement, node) {
1963
+ const rect = nodeElement.getBoundingClientRect();
1964
+ if (event.clientY > rect.top && event.clientY - rect.top <= 8) {
1965
+ this.treeService.dropPositionChange$.next({
1966
+ targetNode: node,
1967
+ position: "before"
1968
+ });
1969
+ }
1970
+ else if (event.clientY < rect.bottom && rect.bottom - event.clientY <= 8) {
1971
+ this.treeService.dropPositionChange$.next({
1972
+ targetNode: node,
1973
+ position: "after"
1974
+ });
1975
+ }
1976
+ else if (event.clientY < rect.top || event.clientY > rect.bottom) {
1977
+ this.treeService.dropPositionChange$.next({
1978
+ targetNode: null,
1979
+ position: "outside"
1980
+ });
1981
+ }
1982
+ else {
1983
+ this.treeService.dropPositionChange$.next({
1984
+ targetNode: node,
1985
+ position: "inside"
1986
+ });
1987
+ }
1988
+ }
1989
+ setFocusSubscription() {
1990
+ this.#focusMonitor
1991
+ .monitor(this.#hostElementRef.nativeElement, true)
1992
+ .pipe(takeUntilDestroyed(this.#destroyRef))
1993
+ .subscribe(origin => {
1994
+ if (origin) {
1995
+ asapScheduler.schedule(() => {
1996
+ if (this.treeService.navigatedNode() === null) {
1997
+ if (this.#lastNavigatedNode !== null) {
1998
+ this.treeService.navigatedNode.set(this.#lastNavigatedNode);
1999
+ }
2000
+ else {
2001
+ this.treeService.navigate("next");
2002
+ }
2003
+ }
2004
+ });
2005
+ return;
2006
+ }
2007
+ asapScheduler.schedule(() => {
2008
+ this.treeService.navigatedNode.set(null);
2009
+ });
2010
+ });
2011
+ fromEvent(this.#hostElementRef.nativeElement, "focusin")
2012
+ .pipe(filter(e => !this.#hostElementRef.nativeElement.contains(e.relatedTarget)), takeUntilDestroyed(this.#destroyRef))
2013
+ .subscribe(e => this.treeService.focus$.next(e));
2014
+ fromEvent(this.#hostElementRef.nativeElement, "focusout")
2015
+ .pipe(filter(e => !this.#hostElementRef.nativeElement.contains(e.relatedTarget)), takeUntilDestroyed(this.#destroyRef))
2016
+ .subscribe(e => this.treeService.blur$.next(e));
2017
+ }
2018
+ setKeydownSubscription() {
2019
+ fromEvent(this.#hostElementRef.nativeElement, "keydown")
2020
+ .pipe(takeUntilDestroyed(this.#destroyRef))
2021
+ .subscribe(event => {
2022
+ const navigatedNode = this.treeService.navigatedNode();
2023
+ if (event.key === "ArrowUp") {
2024
+ event.preventDefault();
2025
+ this.treeService.navigate("previous");
2026
+ }
2027
+ else if (event.key === "ArrowDown") {
2028
+ event.preventDefault();
2029
+ this.treeService.navigate("next");
2030
+ }
2031
+ else if (event.key === "ArrowLeft") {
2032
+ event.preventDefault();
2033
+ if (!navigatedNode || !navigatedNode.nodeItem.hasChildren) {
2034
+ return;
2035
+ }
2036
+ const expanded = this.treeService.isExpanded(navigatedNode);
2037
+ const disabled = this.treeService.isDisabled(navigatedNode);
2038
+ if (!disabled && expanded) {
2039
+ this.treeService.setNodeExpand(navigatedNode, false);
2040
+ }
2041
+ this.treeService.navigatedNode.set(navigatedNode);
2042
+ }
2043
+ else if (event.key === "ArrowRight") {
2044
+ event.preventDefault();
2045
+ if (!navigatedNode || !navigatedNode.nodeItem.hasChildren) {
2046
+ return;
2047
+ }
2048
+ const expanded = this.treeService.isExpanded(navigatedNode);
2049
+ const disabled = this.treeService.isDisabled(navigatedNode);
2050
+ if (!disabled && !expanded) {
2051
+ this.treeService.setNodeExpand(navigatedNode, true);
2052
+ }
2053
+ }
2054
+ else if (event.key === " ") {
2055
+ event.preventDefault();
2056
+ if (!navigatedNode || this.treeService.isDisabled(navigatedNode)) {
2057
+ return;
2058
+ }
2059
+ if (!this.treeService.isCheckable(navigatedNode)) {
2060
+ return;
2061
+ }
2062
+ const nodeCheckEvent = new NodeCheckEvent(navigatedNode, event);
2063
+ this.treeService.nodeCheck$.next(nodeCheckEvent);
2064
+ if (!nodeCheckEvent.isDefaultPrevented()) {
2065
+ const newCheckState = !this.treeService.isChecked(navigatedNode);
2066
+ this.treeService.setNodeCheck(navigatedNode, newCheckState);
2067
+ this.treeService.nodeCheckChange$.next({
2068
+ node: navigatedNode,
2069
+ checked: newCheckState
2070
+ });
2071
+ }
2072
+ }
2073
+ else if (event.key === "Home") {
2074
+ event.preventDefault();
2075
+ this.treeService.navigate("first");
2076
+ }
2077
+ else if (event.key === "End") {
2078
+ event.preventDefault();
2079
+ this.treeService.navigate("last");
2080
+ }
2081
+ else if (event.key === "Enter") {
2082
+ event.preventDefault();
2083
+ if (!navigatedNode || this.treeService.isDisabled(navigatedNode)) {
2084
+ return;
2085
+ }
2086
+ const selectableOptions = this.treeService.selectableOptions();
2087
+ if (!selectableOptions.enabled) {
2088
+ return;
2089
+ }
2090
+ if (selectableOptions.childrenOnly && this.treeService.hasChildren(navigatedNode)) {
2091
+ return;
2092
+ }
2093
+ const nodeSelectEvent = new NodeSelectEvent(navigatedNode, event);
2094
+ this.treeService.nodeSelect$.next(nodeSelectEvent);
2095
+ if (!nodeSelectEvent.isDefaultPrevented()) {
2096
+ const newSelected = !this.treeService.isSelected(navigatedNode);
2097
+ this.treeService.setNodeSelect(navigatedNode, newSelected);
2098
+ this.treeService.nodeSelectChange$.next({
2099
+ node: navigatedNode,
2100
+ selected: newSelected
2101
+ });
2102
+ this.treeService.notifySelectionChange(navigatedNode);
2103
+ }
2104
+ }
2105
+ });
2106
+ }
2107
+ setNodeDragHandlerSubscription() {
2108
+ this.#zone.runOutsideAngular(() => {
2109
+ this.treeService.dragging$
2110
+ .pipe(takeUntilDestroyed(this.#destroyRef), switchMap(dragging => dragging
2111
+ ? fromEvent(document, "mousemove").pipe(takeWhile(() => this.treeService.dragging()))
2112
+ : []))
2113
+ .subscribe(event => this.handleMouseMoveWhileDragging(event));
2114
+ });
2115
+ }
2116
+ setSubscriptions() {
2117
+ this.setFocusSubscription();
2118
+ this.setKeydownSubscription();
2119
+ this.setNodeDragHandlerSubscription();
2120
+ }
2121
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2122
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TreeComponent, isStandalone: true, selector: "mona-tree", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class": "baseClass()", "attr.role": "'tree'", "attr.tabindex": "0", "attr.aria-label": "ariaLabel() || null", "attr.aria-multiselectable": "treeService.selectableOptions().mode === 'multiple' || null", "attr.aria-activedescendant": "activeDescendantId()" } }, queries: [{ propertyName: "nodeTemplate", first: true, predicate: TreeNodeTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<mona-sub-tree [nodes]=\"treeService.viewNodeSet()\" [parent]=\"null\" [depth]=\"0\"></mona-sub-tree>\n@if (treeService.dragging() && treeService.dropAllowed()) {\n <mona-tree-drop-hint></mona-tree-drop-hint>\n}\n", dependencies: [{ kind: "component", type: SubTreeComponent, selector: "mona-sub-tree", inputs: ["depth", "nodes", "parent"] }, { kind: "component", type: TreeDropHintComponent, selector: "mona-tree-drop-hint" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
2123
+ }
2124
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeComponent, decorators: [{
2125
+ type: Component,
2126
+ args: [{ selector: "mona-tree", imports: [SubTreeComponent, TreeDropHintComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: {
2127
+ "[class]": "baseClass()",
2128
+ "[attr.role]": "'tree'",
2129
+ "[attr.tabindex]": "0",
2130
+ "[attr.aria-label]": "ariaLabel() || null",
2131
+ "[attr.aria-multiselectable]": "treeService.selectableOptions().mode === 'multiple' || null",
2132
+ "[attr.aria-activedescendant]": "activeDescendantId()"
2133
+ }, template: "<mona-sub-tree [nodes]=\"treeService.viewNodeSet()\" [parent]=\"null\" [depth]=\"0\"></mona-sub-tree>\n@if (treeService.dragging() && treeService.dropAllowed()) {\n <mona-tree-drop-hint></mona-tree-drop-hint>\n}\n" }]
2134
+ }], ctorParameters: () => [], propDecorators: { ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], nodeTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TreeNodeTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }] } });
2135
+
2136
+ /**
2137
+ * Moves a node within a generic flat tree structure that uses parentId references.
2138
+ * @param treeData - The flat array of tree nodes.
2139
+ * @param event - The drag-and-drop event payload.
2140
+ * @param idKey - The property key used to uniquely identify each node (e.g., 'id').
2141
+ * @param parentIdKey - The property key holding the parent node's id, or null for roots (e.g., 'parentId').
2142
+ * @returns A new array representing the updated flat tree, with the moved node's parentIdKey updated.
2143
+ */
2144
+ function moveFlatTreeNode(treeData, event, idKey, parentIdKey) {
2145
+ const workingArray = [...treeData];
2146
+ const draggedId = event.nodeItem.data[idKey];
2147
+ const targetId = event.targetNode.data[idKey];
2148
+ const position = event.position;
2149
+ if (position === "outside") {
2150
+ return workingArray;
2151
+ }
2152
+ const draggedIndex = workingArray.findIndex(item => item[idKey] === draggedId);
2153
+ if (draggedIndex === -1) {
2154
+ return workingArray;
2155
+ }
2156
+ const [draggedNode] = workingArray.splice(draggedIndex, 1);
2157
+ const targetIndex = workingArray.findIndex(item => item[idKey] === targetId);
2158
+ if (targetIndex === -1) {
2159
+ workingArray.splice(draggedIndex, 0, draggedNode);
2160
+ return workingArray;
2161
+ }
2162
+ const targetNode = workingArray[targetIndex];
2163
+ if (position === "before") {
2164
+ const updatedNode = { ...draggedNode, [parentIdKey]: targetNode[parentIdKey] };
2165
+ workingArray.splice(targetIndex, 0, updatedNode);
2166
+ }
2167
+ else if (position === "after") {
2168
+ const updatedNode = { ...draggedNode, [parentIdKey]: targetNode[parentIdKey] };
2169
+ workingArray.splice(targetIndex + 1, 0, updatedNode);
2170
+ }
2171
+ else if (position === "inside") {
2172
+ const updatedNode = { ...draggedNode, [parentIdKey]: targetNode[idKey] };
2173
+ function findLastDescendantIndex(anchorId) {
2174
+ let lastIndex = workingArray.findIndex(item => item[idKey] === anchorId);
2175
+ for (let i = 0; i < workingArray.length; i++) {
2176
+ if (workingArray[i][parentIdKey] === anchorId) {
2177
+ const childLastIndex = findLastDescendantIndex(workingArray[i][idKey]);
2178
+ if (childLastIndex > lastIndex) {
2179
+ lastIndex = childLastIndex;
2180
+ }
2181
+ }
2182
+ }
2183
+ return lastIndex;
2184
+ }
2185
+ const insertAfterIndex = findLastDescendantIndex(targetId);
2186
+ workingArray.splice(insertAfterIndex + 1, 0, updatedNode);
2187
+ }
2188
+ return workingArray;
2189
+ }
2190
+
2191
+ /**
2192
+ * Moves a node within a generic hierarchical tree structure.
2193
+ * @param treeData - The array of tree nodes.
2194
+ * @param event - The drag-and-drop event payload.
2195
+ * @param idKey - The property key used to identify nodes (e.g., 'id').
2196
+ * @param childrenKey - The property key containing the nested items (e.g., 'items').
2197
+ * @returns A new array representing the updated tree structure.
2198
+ */
2199
+ function moveTreeNode(treeData, event, idKey, childrenKey) {
2200
+ const updatedTree = [...treeData];
2201
+ const draggedId = event.nodeItem.data[idKey];
2202
+ const targetId = event.targetNode.data[idKey];
2203
+ const position = event.position;
2204
+ let draggedNode = null;
2205
+ function extractNode(nodes) {
2206
+ for (let i = 0; i < nodes.length; i++) {
2207
+ if (nodes[i][idKey] === draggedId) {
2208
+ draggedNode = nodes.splice(i, 1)[0];
2209
+ return true;
2210
+ }
2211
+ const children = nodes[i][childrenKey];
2212
+ if (children && Array.isArray(children)) {
2213
+ if (extractNode(children)) {
2214
+ return true;
2215
+ }
2216
+ }
2217
+ }
2218
+ return false;
2219
+ }
2220
+ function insertNode(nodes) {
2221
+ for (let i = 0; i < nodes.length; i++) {
2222
+ if (nodes[i][idKey] === targetId) {
2223
+ if (position === "inside") {
2224
+ if (!nodes[i][childrenKey]) {
2225
+ nodes[i][childrenKey] = [];
2226
+ }
2227
+ const children = nodes[i][childrenKey];
2228
+ children.push(draggedNode);
2229
+ }
2230
+ else if (position === "before") {
2231
+ nodes.splice(i, 0, draggedNode);
2232
+ }
2233
+ else if (position === "after") {
2234
+ nodes.splice(i + 1, 0, draggedNode);
2235
+ }
2236
+ return true;
2237
+ }
2238
+ const children = nodes[i][childrenKey];
2239
+ if (children && Array.isArray(children)) {
2240
+ if (insertNode(children)) {
2241
+ return true;
2242
+ }
2243
+ }
2244
+ }
2245
+ return false;
2246
+ }
2247
+ extractNode(updatedTree);
2248
+ if (draggedNode) {
2249
+ insertNode(updatedTree);
2250
+ }
2251
+ return updatedTree;
2252
+ }
2253
+
2254
+ /*
2255
+ * Public API Surface of @nanahoshi/mona-ui/tree
2256
+ */
2257
+
2258
+ /**
2259
+ * Generated bundle index. Do not edit.
2260
+ */
2261
+
2262
+ export { InternalNodeDragEvent, NodeCheckEvent, NodeClickEvent, NodeDragEndEvent, NodeDragEvent, NodeDragStartEvent, NodeDropEvent, NodeDropEventSansTree, NodeEvent, NodeSelectEvent, TreeComponent, TreeNode, TreeNodeTemplateDirective, TreeService, moveFlatTreeNode, moveTreeNode };
2263
+ //# sourceMappingURL=nanahoshi-mona-ui-internal-tree.mjs.map