@nanahoshi/mona-ui 0.24.7 → 0.24.9

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 (97) hide show
  1. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
  2. package/fesm2022/nanahoshi-mona-ui-button-group.mjs +37 -9
  3. package/fesm2022/nanahoshi-mona-ui-button.mjs +8 -2
  4. package/fesm2022/nanahoshi-mona-ui-color-gradient.mjs +4 -3
  5. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
  6. package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +101 -47
  7. package/fesm2022/nanahoshi-mona-ui-dialog.mjs +339 -101
  8. package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +119 -69
  9. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1 -1
  10. package/fesm2022/nanahoshi-mona-ui-editor.mjs +2 -2
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DhKLnW06.mjs} +2 -2
  12. package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs → nanahoshi-mona-ui-grid-grid-list.component-voGbKOiB.mjs} +4 -4
  13. package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs → nanahoshi-mona-ui-grid-grid-row.component-HQ1Kv6R9.mjs} +2 -3
  14. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-PNLJFcuH.mjs} +4 -4
  15. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BO19AVwC.mjs} +10 -10
  16. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  17. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +44 -3
  18. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +20 -4
  19. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +335 -45
  20. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +565 -197
  21. package/fesm2022/nanahoshi-mona-ui-internal.mjs +465 -23
  22. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +598 -208
  23. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +193 -71
  24. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +29 -3
  25. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -3
  26. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -3
  27. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +40 -3
  28. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +29 -3
  29. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -3
  30. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +29 -3
  31. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +29 -3
  32. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -3
  33. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +49 -3
  34. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +29 -3
  35. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +29 -3
  36. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +29 -3
  37. package/fesm2022/nanahoshi-mona-ui-menubar.mjs +127 -133
  38. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1 -1
  39. package/fesm2022/nanahoshi-mona-ui-notification.mjs +473 -240
  40. package/fesm2022/nanahoshi-mona-ui-popover.mjs +202 -90
  41. package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +609 -256
  42. package/fesm2022/nanahoshi-mona-ui-popup.mjs +2 -0
  43. package/fesm2022/nanahoshi-mona-ui-sheet.mjs +45 -10
  44. package/fesm2022/nanahoshi-mona-ui-split-button.mjs +102 -58
  45. package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +286 -443
  46. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +205 -140
  47. package/fesm2022/nanahoshi-mona-ui-window.mjs +591 -310
  48. package/i18n/catalogs/en-US.messages.json +32 -6
  49. package/locales/ar-sa/ar-sa.messages.json +29 -3
  50. package/locales/de-de/de-de.messages.json +29 -3
  51. package/locales/es-es/es-es.messages.json +29 -3
  52. package/locales/fr-fr/fr-fr.messages.json +29 -3
  53. package/locales/id-id/id-id.messages.json +29 -3
  54. package/locales/it-it/it-it.messages.json +29 -3
  55. package/locales/ja-jp/ja-jp.messages.json +29 -3
  56. package/locales/ko-kr/ko-kr.messages.json +29 -3
  57. package/locales/pt-br/pt-br.messages.json +29 -3
  58. package/locales/ru-ru/ru-ru.messages.json +29 -3
  59. package/locales/tr-tr/tr-tr.messages.json +29 -3
  60. package/locales/zh-cn/zh-cn.messages.json +29 -3
  61. package/locales/zh-tw/zh-tw.messages.json +29 -3
  62. package/package.json +1 -1
  63. package/types/nanahoshi-mona-ui-button-group.d.ts +13 -3
  64. package/types/nanahoshi-mona-ui-button.d.ts +20 -3
  65. package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -6
  66. package/types/nanahoshi-mona-ui-dialog.d.ts +131 -20
  67. package/types/nanahoshi-mona-ui-dropdown-button.d.ts +75 -56
  68. package/types/nanahoshi-mona-ui-i18n.d.ts +69 -0
  69. package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +14 -2
  70. package/types/nanahoshi-mona-ui-internal-list.d.ts +89 -10
  71. package/types/nanahoshi-mona-ui-internal-tree.d.ts +155 -40
  72. package/types/nanahoshi-mona-ui-internal.d.ts +128 -16
  73. package/types/nanahoshi-mona-ui-list-box.d.ts +148 -47
  74. package/types/nanahoshi-mona-ui-list-view.d.ts +112 -21
  75. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +26 -0
  76. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +26 -0
  77. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +26 -0
  78. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +26 -0
  79. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +26 -0
  80. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +26 -0
  81. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +26 -0
  82. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +26 -0
  83. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +26 -0
  84. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +26 -0
  85. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +26 -0
  86. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +26 -0
  87. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +26 -0
  88. package/types/nanahoshi-mona-ui-menubar.d.ts +65 -62
  89. package/types/nanahoshi-mona-ui-notification.d.ts +76 -16
  90. package/types/nanahoshi-mona-ui-popover.d.ts +44 -17
  91. package/types/nanahoshi-mona-ui-popup-menu.d.ts +110 -32
  92. package/types/nanahoshi-mona-ui-popup.d.ts +2 -0
  93. package/types/nanahoshi-mona-ui-sheet.d.ts +16 -5
  94. package/types/nanahoshi-mona-ui-split-button.d.ts +29 -7
  95. package/types/nanahoshi-mona-ui-tooltip.d.ts +43 -20
  96. package/types/nanahoshi-mona-ui-tree-view.d.ts +84 -40
  97. package/types/nanahoshi-mona-ui-window.d.ts +103 -14
@@ -1,16 +1,16 @@
1
- import { FocusMonitor } from '@angular/cdk/a11y';
1
+ import { LiveAnnouncer, FocusMonitor } from '@angular/cdk/a11y';
2
2
  import * as i0 from '@angular/core';
3
- import { Directive, signal, computed, inject, DestroyRef, effect, untracked, Injectable, Pipe, input, ChangeDetectionStrategy, Component, DOCUMENT, NgZone, ElementRef, afterRenderEffect, contentChild, TemplateRef, afterNextRender } from '@angular/core';
3
+ import { Directive, signal, computed, inject, DestroyRef, effect, untracked, Injectable, Pipe, input, Component, DOCUMENT, NgZone, ElementRef, afterRenderEffect, Injector, contentChild, TemplateRef, afterNextRender } from '@angular/core';
4
4
  import { toObservable, toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
- import { MonaI18nService, injectComponentDirection } from '@nanahoshi/mona-ui/i18n';
5
+ import { formatNumber, MonaI18nService, injectComponentDirection } from '@nanahoshi/mona-ui/i18n';
6
6
  import { themeOverlaySurfaceClasses, isTypeaheadKey, setupTypeahead } from '@nanahoshi/mona-ui/internal';
7
- import { Subject, BehaviorSubject, ReplaySubject, switchMap, debounceTime, distinctUntilChanged, Observable, take, filter, tap, map, asapScheduler, fromEvent, takeWhile } from 'rxjs';
7
+ import { Subject, BehaviorSubject, ReplaySubject, distinctUntilChanged, Observable, take, filter, tap, map, asapScheduler, fromEvent, switchMap, merge, takeWhile } from 'rxjs';
8
8
  import { PreventableEvent } from '@nanahoshi/mona-ui/common';
9
9
  import { ImmutableSet, List, from, sequenceEqual, EnumerableSet, forEach } from '@mirei/ts-collections';
10
10
  import { v4 } from 'uuid';
11
11
  import { cva } from 'class-variance-authority';
12
12
  import { CdkDropList, CdkDrag, CdkDragPreview } from '@angular/cdk/drag-drop';
13
- import { LucideArrowDown, LucideArrowUp, LucideBan, LucideChevronDown, LucideChevronRight, LucideLoaderCircle, LucidePlus } from '@lucide/angular';
13
+ import { LucideArrowDown, LucideArrowUp, LucideBan, LucideChevronDown, LucideChevronRight, LucideCircleAlert, LucideLoaderCircle, LucidePlus } from '@lucide/angular';
14
14
  import * as i1 from '@angular/forms';
15
15
  import { FormsModule } from '@angular/forms';
16
16
  import { CheckBoxComponent } from '@nanahoshi/mona-ui/check-box';
@@ -27,6 +27,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
27
27
  }]
28
28
  }] });
29
29
 
30
+ // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
31
+ // Edit the JSON file and run `npm run generate:locale-catalogs`.
32
+ function localizeNumber(value, options) {
33
+ return formatNumber(value, "en-US", options);
34
+ }
35
+ const TREE_DEFAULT_MESSAGES = {
36
+ collapse: "Collapse",
37
+ expand: "Expand",
38
+ filter: "Filter",
39
+ filterLabel: (tree) => `Filter ${tree}`,
40
+ filterTree: "Filter tree",
41
+ loadError: (node) => `Couldn't load the items in ${node}`,
42
+ loadingNode: (node) => `Loading ${node}`,
43
+ movedAfter: (node, target) => `${node} moved after ${target}`,
44
+ movedBefore: (node, target) => `${node} moved before ${target}`,
45
+ movedInto: (node, target) => `${node} moved into ${target}`,
46
+ noData: "No data",
47
+ noMatches: "No matching items",
48
+ results: (count) => (count === 1 ? `${localizeNumber(count)} result` : `${localizeNumber(count)} results`),
49
+ retryLoading: (node) => `Retry loading ${node}`
50
+ };
51
+
30
52
  class NodeCheckEvent extends PreventableEvent {
31
53
  #node;
32
54
  constructor(node, event) {
@@ -42,6 +64,64 @@ class NodeCheckEvent extends PreventableEvent {
42
64
  }
43
65
  }
44
66
 
67
+ class NodeEvent extends PreventableEvent {
68
+ #node;
69
+ constructor(type, node, event) {
70
+ super(type, event);
71
+ this.#node = node;
72
+ }
73
+ get nodeItem() {
74
+ return {
75
+ data: this.#node.data,
76
+ hasChildren: this.#node.children().length > 0,
77
+ uid: this.#node.uid
78
+ };
79
+ }
80
+ }
81
+
82
+ /**
83
+ * A request to move a node: a drop, or a keyboard move (Ctrl+Shift+Arrow), whose original event is then the
84
+ * `KeyboardEvent`.
85
+ */
86
+ class NodeDropEvent extends NodeEvent {
87
+ #params;
88
+ constructor(params) {
89
+ super("nodeDrop", params.sourceNode, params.event);
90
+ this.#params = params;
91
+ }
92
+ get position() {
93
+ return this.#params.position;
94
+ }
95
+ get sourceNode() {
96
+ return this.#params.sourceNode.nodeItem;
97
+ }
98
+ get targetNode() {
99
+ return this.#params.targetNode.nodeItem;
100
+ }
101
+ get treeView() {
102
+ return this.#params.treeView;
103
+ }
104
+ }
105
+ class NodeDropEventSansTree extends NodeEvent {
106
+ #params;
107
+ constructor(params) {
108
+ super("nodeDropSansTree", params.sourceNode, params.event);
109
+ this.#params = params;
110
+ }
111
+ get event() {
112
+ return this.#params.event;
113
+ }
114
+ get position() {
115
+ return this.#params.position;
116
+ }
117
+ get sourceNode() {
118
+ return this.#params.sourceNode;
119
+ }
120
+ get targetNode() {
121
+ return this.#params.targetNode;
122
+ }
123
+ }
124
+
45
125
  class NodeSelectEvent extends PreventableEvent {
46
126
  #node;
47
127
  constructor(node, event) {
@@ -63,6 +143,9 @@ class TreeNode {
63
143
  ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
64
144
  this.children = signal(ImmutableSet.create(), /* @ts-ignore */
65
145
  ...(ngDevMode ? [{ debugName: "children" }] : /* istanbul ignore next */ []));
146
+ /** Whether the last load of this node's children from an asynchronous children selector failed. */
147
+ this.loadFailed = signal(false, /* @ts-ignore */
148
+ ...(ngDevMode ? [{ debugName: "loadFailed" }] : /* istanbul ignore next */ []));
66
149
  this.loading = signal(false, /* @ts-ignore */
67
150
  ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
68
151
  this.uid = v4();
@@ -113,6 +196,8 @@ class TreeService {
113
196
  */
114
197
  #childLoads;
115
198
  #data;
199
+ /** Private so that `filterText`, declared before the public `filterableOptions`, can read it. */
200
+ #filterableOptions;
116
201
  #filteredExpandedKeys;
117
202
  #flatIdField;
118
203
  #flatParentIdField;
@@ -132,6 +217,14 @@ class TreeService {
132
217
  this.#childLoads = new Map();
133
218
  this.#data = signal(ImmutableSet.create(), /* @ts-ignore */
134
219
  ...(ngDevMode ? [{ debugName: "#data" }] : /* istanbul ignore next */ []));
220
+ /** Private so that `filterText`, declared before the public `filterableOptions`, can read it. */
221
+ this.#filterableOptions = signal({
222
+ enabled: false,
223
+ debounce: 0,
224
+ caseSensitive: false,
225
+ operator: "contains"
226
+ }, /* @ts-ignore */
227
+ ...(ngDevMode ? [{ debugName: "#filterableOptions" }] : /* istanbul ignore next */ []));
135
228
  this.#filteredExpandedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
136
229
  ...(ngDevMode ? [{ debugName: "#filteredExpandedKeys" }] : /* istanbul ignore next */ []));
137
230
  this.#flatIdField = signal("", /* @ts-ignore */
@@ -172,10 +265,10 @@ class TreeService {
172
265
  return this.computeVisibleUids(this.nodeSet(), filterText);
173
266
  }, /* @ts-ignore */
174
267
  ...(ngDevMode ? [{ debugName: "#visibleUids" }] : /* istanbul ignore next */ []));
175
- this.animationTemporarilyDisabled = signal(false, /* @ts-ignore */
176
- ...(ngDevMode ? [{ debugName: "animationTemporarilyDisabled" }] : /* istanbul ignore next */ []));
177
268
  this.animationEnabled = signal(true, /* @ts-ignore */
178
269
  ...(ngDevMode ? [{ debugName: "animationEnabled" }] : /* istanbul ignore next */ []));
270
+ this.animationTemporarilyDisabled = signal(false, /* @ts-ignore */
271
+ ...(ngDevMode ? [{ debugName: "animationTemporarilyDisabled" }] : /* istanbul ignore next */ []));
179
272
  this.blur$ = new Subject();
180
273
  this.checkBy = signal(null, /* @ts-ignore */
181
274
  ...(ngDevMode ? [{ debugName: "checkBy" }] : /* istanbul ignore next */ []));
@@ -188,9 +281,21 @@ class TreeService {
188
281
  mode: "multiple"
189
282
  }, /* @ts-ignore */
190
283
  ...(ngDevMode ? [{ debugName: "checkableOptions" }] : /* istanbul ignore next */ []));
191
- this.checkedKeys$ = toObservable(this.#checkedKeys);
284
+ /**
285
+ * The checked keys after the user checks or unchecks a node. Keys set from code, and keys the tree derives on its
286
+ * own (parents with `checkParents`, lazily loaded children of a checked node, ancestors after a move), aren't
287
+ * reported here.
288
+ */
289
+ this.checkedKeysChange$ = new Subject();
192
290
  this.children = signal("", /* @ts-ignore */
193
291
  ...(ngDevMode ? [{ debugName: "children" }] : /* istanbul ignore next */ []));
292
+ /**
293
+ * A node's children failed to load from an asynchronous children selector. The node is collapsed again (not
294
+ * reported through `expandedKeysChange$`), and expanding it retries the load.
295
+ */
296
+ this.childrenLoadError$ = new Subject();
297
+ /** A node started loading its children from an asynchronous children selector. */
298
+ this.childrenLoadStart$ = new Subject();
194
299
  this.disableBy = signal(null, /* @ts-ignore */
195
300
  ...(ngDevMode ? [{ debugName: "disableBy" }] : /* istanbul ignore next */ []));
196
301
  this.disableOptions = signal({
@@ -221,20 +326,28 @@ class TreeService {
221
326
  return this.#unfilteredExpandedKeys();
222
327
  }, /* @ts-ignore */
223
328
  ...(ngDevMode ? [{ debugName: "expandedKeys" }] : /* istanbul ignore next */ []));
224
- this.expandedKeys$ = toObservable(this.expandedKeys);
225
- this.filterableOptions = signal({
226
- enabled: false,
227
- debounce: 0,
228
- caseSensitive: false,
229
- operator: "contains"
230
- }, /* @ts-ignore */
231
- ...(ngDevMode ? [{ debugName: "filterableOptions" }] : /* istanbul ignore next */ []));
329
+ /**
330
+ * The expanded keys after the user expands or collapses a node outside filtering. The expansion a filter applies,
331
+ * and the user's changes to it while filtering, are view state and aren't reported.
332
+ */
333
+ this.expandedKeysChange$ = new Subject();
232
334
  this.filter$ = new ReplaySubject(1);
233
335
  this.filterChange$ = new Subject();
234
336
  this.filterPlaceholder = signal("", /* @ts-ignore */
235
337
  ...(ngDevMode ? [{ debugName: "filterPlaceholder" }] : /* istanbul ignore next */ []));
236
- this.filterText = toSignal(toObservable(this.filterableOptions).pipe(switchMap(opts => this.filter$.pipe(debounceTime(opts.debounce), distinctUntilChanged()))), { initialValue: "" });
338
+ /** The applied filter. Typing is debounced by the filter input; a filter set from code applies at once. */
339
+ this.filterText = toSignal(this.filter$.pipe(distinctUntilChanged()), { initialValue: "" });
340
+ this.filterableOptions = this.#filterableOptions.asReadonly();
237
341
  this.focus$ = new Subject();
342
+ /** The number of nodes whose text matches the filter (their ancestors, shown for context, aren't counted). */
343
+ this.matchCount = computed(() => {
344
+ const filterText = this.filterText();
345
+ if (!filterText) {
346
+ return 0;
347
+ }
348
+ return _a.flatten(this.nodeSet()).count(node => this.isFiltered(this.getNodeText(node), filterText));
349
+ }, /* @ts-ignore */
350
+ ...(ngDevMode ? [{ debugName: "matchCount" }] : /* istanbul ignore next */ []));
238
351
  this.navigatedNode = signal(null, /* @ts-ignore */
239
352
  ...(ngDevMode ? [{ debugName: "navigatedNode" }] : /* istanbul ignore next */ []));
240
353
  this.nodeCheck$ = new Subject();
@@ -262,7 +375,8 @@ class TreeService {
262
375
  ...(ngDevMode ? [{ debugName: "selectableOptions" }] : /* istanbul ignore next */ []));
263
376
  this.selectedKeys = signal(ImmutableSet.create(), /* @ts-ignore */
264
377
  ...(ngDevMode ? [{ debugName: "selectedKeys" }] : /* istanbul ignore next */ []));
265
- this.selectedKeys$ = toObservable(this.selectedKeys);
378
+ /** The selected keys after the user selects or deselects a node. Keys set from code aren't reported. */
379
+ this.selectedKeysChange$ = new Subject();
266
380
  this.selectedNodes = computed(() => {
267
381
  const selectedKeys = this.selectedKeys();
268
382
  const nodeDictionary = this.#nodeDictionary();
@@ -308,6 +422,33 @@ class TreeService {
308
422
  this.#filteredExpandedKeys.set(expandedKeys);
309
423
  });
310
424
  });
425
+ effect(() => {
426
+ const navigableNodes = this.#navigableNodes();
427
+ const navigatedNode = this.navigatedNode();
428
+ untracked(() => this.keepNavigatedNodeVisible(navigableNodes, navigatedNode));
429
+ });
430
+ // An expanded node whose children come from an observable loads them, including nodes expanded from the
431
+ // start through `expandedKeys`, and not just nodes the user expands.
432
+ effect(() => {
433
+ const expandedKeys = this.#unfilteredExpandedKeys();
434
+ const nodes = this.nodeSet();
435
+ const enabled = this.expandableOptions().enabled;
436
+ const children = this.children();
437
+ this.expandBy();
438
+ untracked(() => {
439
+ if (enabled && typeof children === "function") {
440
+ this.loadExpandedNodes(nodes, expandedKeys);
441
+ }
442
+ });
443
+ });
444
+ }
445
+ /** Whether two key sets hold the same keys, in any order. */
446
+ /** Reads a field of a data item by name (for the string forms of the key, id and children selectors). */
447
+ static readField(item, field) {
448
+ return item == null ? undefined : item[field];
449
+ }
450
+ static sameKeys(a, b) {
451
+ return a.size() === b.size() && a.all(key => b.contains(key));
311
452
  }
312
453
  static flatten(nodes) {
313
454
  const flattenedNodes = new List();
@@ -347,15 +488,29 @@ class TreeService {
347
488
  }
348
489
  }
349
490
  /**
350
- * Finds the next visible node, after the navigated node and wrapping around, whose text starts with `prefix`
351
- * (case-insensitive). Used for typeahead.
491
+ * The node of the current nodes that stands for `node`: the node itself, or after a data refresh rebuilt the
492
+ * nodes, the node of the same data item (or, for flat data, of the same id).
493
+ */
494
+ findCounterpart(node) {
495
+ const sameNode = this.getNodeByUid(node.uid);
496
+ if (sameNode) {
497
+ return sameNode;
498
+ }
499
+ const identity = this.getNodeIdentity(node);
500
+ return (_a.flatten(this.nodeSet()).firstOrDefault(candidate => candidate.data === node.data || this.getNodeIdentity(candidate) === identity) ?? null);
501
+ }
502
+ /**
503
+ * Finds the next visible node whose text starts with `prefix` (case-insensitive), wrapping around. Used for
504
+ * typeahead: a first character searches after the navigated node, and each further character keeps the
505
+ * navigated node while it still matches.
352
506
  */
353
507
  findNodeByText(prefix) {
354
508
  const normalizedPrefix = prefix.toLowerCase();
355
509
  const nodes = this.#navigableNodes().toArray();
356
510
  const navigatedNode = this.navigatedNode();
357
511
  const start = navigatedNode ? nodes.indexOf(navigatedNode) : -1;
358
- for (let offset = 1; offset <= nodes.length; offset++) {
512
+ const first = normalizedPrefix.length > 1 && start !== -1 ? 0 : 1;
513
+ for (let offset = first; offset <= nodes.length; offset++) {
359
514
  const node = nodes[(start + offset) % nodes.length];
360
515
  if (this.getNodeText(node).toLowerCase().startsWith(normalizedPrefix)) {
361
516
  return node;
@@ -363,6 +518,53 @@ class TreeService {
363
518
  }
364
519
  return null;
365
520
  }
521
+ getCheckKey(node) {
522
+ const checkBy = this.checkBy();
523
+ if (!checkBy) {
524
+ return node.data;
525
+ }
526
+ if (typeof checkBy === "string") {
527
+ return _a.readField(node.data, checkBy);
528
+ }
529
+ return checkBy(node.data);
530
+ }
531
+ getDisableKey(node) {
532
+ const disableBy = this.disableBy();
533
+ if (!disableBy) {
534
+ return node.data;
535
+ }
536
+ if (typeof disableBy === "string") {
537
+ return _a.readField(node.data, disableBy);
538
+ }
539
+ return disableBy(node.data);
540
+ }
541
+ /**
542
+ * Where a keyboard move takes a node: before its previous or after its next visible sibling (`"up"`, `"down"`),
543
+ * inside its previous visible sibling as the last child (`"in"`), or after its parent (`"out"`). `null` when the
544
+ * node can't move that way or is disabled.
545
+ */
546
+ getKeyboardMove(node, direction) {
547
+ if (this.isDisabled(node)) {
548
+ return null;
549
+ }
550
+ if (direction === "out") {
551
+ return node.parent ? { position: "after", targetNode: node.parent } : null;
552
+ }
553
+ const siblings = (node.parent ? node.parent.children() : this.nodeSet())
554
+ .where(sibling => this.isVisible(sibling))
555
+ .toArray();
556
+ const index = siblings.indexOf(node);
557
+ const previous = index > 0 ? siblings[index - 1] : null;
558
+ const next = index !== -1 && index < siblings.length - 1 ? siblings[index + 1] : null;
559
+ switch (direction) {
560
+ case "up":
561
+ return previous ? { position: "before", targetNode: previous } : null;
562
+ case "down":
563
+ return next ? { position: "after", targetNode: next } : null;
564
+ case "in":
565
+ return previous && !this.isDisabled(previous) ? { position: "inside", targetNode: previous } : null;
566
+ }
567
+ }
366
568
  getNodeByUid(uid) {
367
569
  const nodeDictionary = this.#nodeDictionary();
368
570
  return nodeDictionary.get(uid) ?? null;
@@ -370,6 +572,11 @@ class TreeService {
370
572
  getNodeElementId(uid) {
371
573
  return getTreeNodeElementId(uid);
372
574
  }
575
+ /** What identifies a node's data item across data refreshes: its id for flat data, else the item itself. */
576
+ getNodeIdentity(node) {
577
+ const idField = this.#flatIdField();
578
+ return this.#structure() === "flat" && idField ? _a.readField(node.data, idField) : node.data;
579
+ }
373
580
  getNodeText(node) {
374
581
  const textField = this.textField();
375
582
  let text;
@@ -457,7 +664,8 @@ class TreeService {
457
664
  if (!expandableOptions.enabled) {
458
665
  return true;
459
666
  }
460
- if (node.children().isEmpty()) {
667
+ // A node whose children are still loading is open, so it reads as expanded (and busy) until they arrive.
668
+ if (node.children().isEmpty() && !node.loading()) {
461
669
  return false;
462
670
  }
463
671
  const key = this.getExpandKey(node);
@@ -520,7 +728,9 @@ class TreeService {
520
728
  return;
521
729
  }
522
730
  this.#childLoads.get(node.uid)?.unsubscribe();
731
+ node.loadFailed.set(false);
523
732
  node.loading.set(true);
733
+ this.childrenLoadStart$.next(node);
524
734
  const subscription = children.pipe(take(1)).subscribe({
525
735
  next: c => {
526
736
  const childNodes = new List();
@@ -537,9 +747,15 @@ class TreeService {
537
747
  this.#childLoads.delete(node.uid);
538
748
  this.restoreExpandedChildren(childNodes);
539
749
  },
540
- error: () => {
750
+ error: (error) => {
541
751
  node.loading.set(false);
752
+ node.loadFailed.set(true);
542
753
  this.#childLoads.delete(node.uid);
754
+ // Collapsed again, so expanding the node retries the load.
755
+ const key = this.getExpandKey(node);
756
+ const expandedKeys = this.isTreeFiltered() ? this.#filteredExpandedKeys : this.#unfilteredExpandedKeys;
757
+ expandedKeys.update(keys => keys.remove(key));
758
+ this.childrenLoadError$.next({ error, node });
543
759
  },
544
760
  complete: () => {
545
761
  if (node.loading()) {
@@ -554,11 +770,16 @@ class TreeService {
554
770
  }
555
771
  /**
556
772
  * Moves a node relative to a target node. Moving a node onto itself or into its own subtree is ignored,
557
- * because it would detach the subtree and create a parent cycle.
773
+ * because it would detach the subtree and create a parent cycle, and so is moving it inside its own parent or
774
+ * a disabled node, or `"outside"`.
775
+ * @returns whether the node moved.
558
776
  */
559
777
  moveNode(sourceNode, targetNode, position) {
560
- if (sourceNode === targetNode || targetNode.isDescendantOf(sourceNode)) {
561
- return;
778
+ if (sourceNode === targetNode || targetNode.isDescendantOf(sourceNode) || position === "outside") {
779
+ return false;
780
+ }
781
+ if (position === "inside" && (sourceNode.parent === targetNode || this.isDisabled(targetNode))) {
782
+ return false;
562
783
  }
563
784
  const oldParent = sourceNode.parent;
564
785
  switch (position) {
@@ -574,6 +795,7 @@ class TreeService {
574
795
  }
575
796
  this.updateNodeIndices();
576
797
  this.recalculateCheckedAncestors(oldParent, sourceNode.parent);
798
+ return true;
577
799
  }
578
800
  navigate(direction) {
579
801
  const navigableNodes = this.#navigableNodes();
@@ -607,17 +829,17 @@ class TreeService {
607
829
  notifySelectionChange(node) {
608
830
  this.selectionChange$.next(node.nodeItem);
609
831
  }
832
+ /**
833
+ * Whether selecting `node` the way the user does (a click, or Enter) changes the selection. It doesn't for the
834
+ * selected node of a single selection that can't be toggled off.
835
+ */
836
+ selectionWouldChange(node) {
837
+ const options = this.selectableOptions();
838
+ return !(options.mode === "single" && !options.toggleable && this.isSelected(node));
839
+ }
610
840
  setAnimationEnabled(enabled) {
611
841
  this.animationEnabled.set(enabled);
612
842
  }
613
- setChildrenSelector(selector) {
614
- if (this.children() === selector) {
615
- return;
616
- }
617
- this.children.set(selector);
618
- this.nodeSet.set(this.createNodes(this.#data()));
619
- this.updateNodeIndices();
620
- }
621
843
  setCheckBy(selector) {
622
844
  this.checkBy.set(selector);
623
845
  }
@@ -638,6 +860,14 @@ class TreeService {
638
860
  this.#checkedKeys.set(ImmutableSet.create(keyList));
639
861
  this.applyCheckedKeysToNodes();
640
862
  }
863
+ setChildrenSelector(selector) {
864
+ if (this.children() === selector) {
865
+ return;
866
+ }
867
+ this.children.set(selector);
868
+ this.nodeSet.set(this.createNodes(this.#data()));
869
+ this.updateNodeIndices();
870
+ }
641
871
  setData(data) {
642
872
  this.#data.set(ImmutableSet.create(data));
643
873
  this.nodeSet.set(this.createNodes(data));
@@ -645,8 +875,9 @@ class TreeService {
645
875
  this.applyCheckedKeysToNodes();
646
876
  const navigatedNode = this.navigatedNode();
647
877
  if (navigatedNode && this.#nodeDictionary().get(navigatedNode.uid) == null) {
648
- // The node was removed: drop it so aria-activedescendant never points at a missing element.
649
- this.navigatedNode.set(null);
878
+ // Rebuilt nodes (flat data always is) keep the active node; a removed node is dropped, so
879
+ // aria-activedescendant never points at a missing element.
880
+ this.navigatedNode.set(this.findCounterpart(navigatedNode));
650
881
  }
651
882
  }
652
883
  setDataStructure(structure) {
@@ -684,7 +915,7 @@ class TreeService {
684
915
  this.#unfilteredExpandedKeys.set(ImmutableSet.create(keys));
685
916
  }
686
917
  setFilterableOptions(options) {
687
- this.filterableOptions.update(o => ({ ...o, ...options }));
918
+ this.#filterableOptions.update(o => ({ ...o, ...options }));
688
919
  }
689
920
  setFlatIdField(field) {
690
921
  this.#flatIdField.set(field);
@@ -764,7 +995,12 @@ class TreeService {
764
995
  n.checked.set(allChecked);
765
996
  });
766
997
  }
767
- this.#checkedKeys.set(checkedKeys.toImmutableSet());
998
+ const previousKeys = this.#checkedKeys();
999
+ const nextKeys = checkedKeys.toImmutableSet();
1000
+ this.#checkedKeys.set(nextKeys);
1001
+ if (!_a.sameKeys(previousKeys, nextKeys)) {
1002
+ this.checkedKeysChange$.next(nextKeys);
1003
+ }
768
1004
  }
769
1005
  setNodeExpand(node, expanded) {
770
1006
  const key = this.getExpandKey(node);
@@ -777,17 +1013,19 @@ class TreeService {
777
1013
  });
778
1014
  this.navigatedNode.set(node);
779
1015
  }
1016
+ /** @returns whether the selection changed. */
780
1017
  setNodeSelect(node, selected) {
781
1018
  const selectableOptions = this.selectableOptions();
782
1019
  if (!selectableOptions.enabled) {
783
- return;
1020
+ return false;
784
1021
  }
785
1022
  const childrenOnly = selectableOptions.childrenOnly;
786
1023
  if (childrenOnly && this.hasChildren(node)) {
787
- return;
1024
+ return false;
788
1025
  }
789
1026
  const key = this.getSelectKey(node);
790
1027
  const mode = selectableOptions.mode;
1028
+ const previousKeys = this.selectedKeys();
791
1029
  this.selectedKeys.update(keys => {
792
1030
  if (mode === "single") {
793
1031
  const toggleable = selectableOptions.toggleable;
@@ -804,6 +1042,12 @@ class TreeService {
804
1042
  return keys.remove(key);
805
1043
  });
806
1044
  this.navigatedNode.set(node);
1045
+ const nextKeys = this.selectedKeys();
1046
+ if (_a.sameKeys(previousKeys, nextKeys)) {
1047
+ return false;
1048
+ }
1049
+ this.selectedKeysChange$.next(nextKeys);
1050
+ return true;
807
1051
  }
808
1052
  setSelectBy(selector) {
809
1053
  this.selectBy.set(selector);
@@ -834,11 +1078,12 @@ class TreeService {
834
1078
  }
835
1079
  /**
836
1080
  * Expands or collapses a node the way user interaction does: disabled nodes are left alone, children of an
837
- * asynchronous children selector are loaded on first expand, and `nodeExpand$` is notified.
1081
+ * asynchronous children selector are loaded on first expand, and `nodeExpand$` is notified. Without expanding
1082
+ * (every node is then open), nothing changes.
838
1083
  * @returns whether the expand state changed.
839
1084
  */
840
1085
  toggleNodeExpand(node, expanded) {
841
- if (this.isDisabled(node) || this.isExpanded(node) === expanded) {
1086
+ if (!this.expandableOptions().enabled || this.isDisabled(node) || this.isExpanded(node) === expanded) {
842
1087
  return false;
843
1088
  }
844
1089
  if (expanded) {
@@ -846,27 +1091,10 @@ class TreeService {
846
1091
  }
847
1092
  this.setNodeExpand(node, expanded);
848
1093
  this.nodeExpand$.next({ node, expanded });
849
- return true;
850
- }
851
- getCheckKey(node) {
852
- const checkBy = this.checkBy();
853
- if (!checkBy) {
854
- return node.data;
855
- }
856
- if (typeof checkBy === "string") {
857
- return node.data[checkBy];
858
- }
859
- return checkBy(node.data);
860
- }
861
- getDisableKey(node) {
862
- const disableBy = this.disableBy();
863
- if (!disableBy) {
864
- return node.data;
1094
+ if (!this.isTreeFiltered()) {
1095
+ this.expandedKeysChange$.next(this.#unfilteredExpandedKeys());
865
1096
  }
866
- if (typeof disableBy === "string") {
867
- return node.data[disableBy];
868
- }
869
- return disableBy(node.data);
1097
+ return true;
870
1098
  }
871
1099
  applyCheckedKeysToNodes() {
872
1100
  const checkableOptions = this.checkableOptions();
@@ -916,8 +1144,7 @@ class TreeService {
916
1144
  const flatParentIdField = this.#flatParentIdField();
917
1145
  const childrenByParentId = new Map();
918
1146
  for (const item of data) {
919
- const dataItem = item;
920
- const pid = dataItem[flatParentIdField] ?? null;
1147
+ const pid = _a.readField(item, flatParentIdField) ?? null;
921
1148
  if (!childrenByParentId.has(pid)) {
922
1149
  childrenByParentId.set(pid, []);
923
1150
  }
@@ -927,10 +1154,9 @@ class TreeService {
927
1154
  const items = childrenByParentId.get(pid) ?? [];
928
1155
  const nodes = new List();
929
1156
  for (const item of items) {
930
- const dataItem = item;
931
1157
  const node = new TreeNode(item);
932
1158
  node.parent = parent;
933
- node.children.set(buildNodes(dataItem[flatIdField], node));
1159
+ node.children.set(buildNodes(_a.readField(item, flatIdField), node));
934
1160
  nodes.add(node);
935
1161
  }
936
1162
  return nodes.toImmutableSet();
@@ -954,7 +1180,7 @@ class TreeService {
954
1180
  node.parent = parent;
955
1181
  usedNodes.add(node);
956
1182
  if (typeof children === "string") {
957
- const subNodes = dataItem[children];
1183
+ const subNodes = _a.readField(dataItem, children);
958
1184
  if (subNodes) {
959
1185
  const childNodes = this.createHierarchicalNodes(subNodes, node, existingNodes, usedNodes);
960
1186
  node.children.update(list => list.clear().addAll(childNodes ?? []));
@@ -1008,16 +1234,6 @@ class TreeService {
1008
1234
  .where(c => (hasCheckbox === null || hasCheckbox(c.data, c.uid)) &&
1009
1235
  (checkDisabledChildren || !this.isDisabled(c)));
1010
1236
  }
1011
- getExpandKey(node) {
1012
- const expandBy = this.expandBy();
1013
- if (!expandBy) {
1014
- return node.data;
1015
- }
1016
- if (typeof expandBy === "string") {
1017
- return node.data[expandBy];
1018
- }
1019
- return expandBy(node.data);
1020
- }
1021
1237
  getChildNodes(node) {
1022
1238
  const nodes = _a.flatten([node]);
1023
1239
  return nodes.where(n => n !== node).toImmutableSet();
@@ -1028,10 +1244,20 @@ class TreeService {
1028
1244
  return dataItem;
1029
1245
  }
1030
1246
  if (typeof selectBy === "string") {
1031
- return dataItem[selectBy] ?? dataItem;
1247
+ return _a.readField(dataItem, selectBy) ?? dataItem;
1032
1248
  }
1033
1249
  return selectBy(dataItem);
1034
1250
  }
1251
+ getExpandKey(node) {
1252
+ const expandBy = this.expandBy();
1253
+ if (!expandBy) {
1254
+ return node.data;
1255
+ }
1256
+ if (typeof expandBy === "string") {
1257
+ return _a.readField(node.data, expandBy);
1258
+ }
1259
+ return expandBy(node.data);
1260
+ }
1035
1261
  getParentNodes(node) {
1036
1262
  const nodes = new List();
1037
1263
  let current = node.parent;
@@ -1047,7 +1273,7 @@ class TreeService {
1047
1273
  return node.data;
1048
1274
  }
1049
1275
  if (typeof selectBy === "string") {
1050
- return node.data[selectBy];
1276
+ return _a.readField(node.data, selectBy);
1051
1277
  }
1052
1278
  return selectBy(node.data);
1053
1279
  }
@@ -1075,6 +1301,27 @@ class TreeService {
1075
1301
  }
1076
1302
  return text.indexOf(filter) >= 0;
1077
1303
  }
1304
+ /**
1305
+ * Keeps `aria-activedescendant` on a rendered node: when the active node is hidden by a collapse or a filter, the
1306
+ * nearest visible ancestor takes over (else the first visible node); a node re-created by new data with the same
1307
+ * uid is swapped in.
1308
+ */
1309
+ keepNavigatedNodeVisible(navigableNodes, navigatedNode) {
1310
+ // A node that isn't in the tree is left to setData, which drops removed nodes.
1311
+ if (navigatedNode === null || this.#nodeDictionary().get(navigatedNode.uid) == null) {
1312
+ return;
1313
+ }
1314
+ const byUid = new Map();
1315
+ navigableNodes.forEach(node => byUid.set(node.uid, node));
1316
+ let candidate = navigatedNode;
1317
+ while (candidate !== null && !byUid.has(candidate.uid)) {
1318
+ candidate = candidate.parent;
1319
+ }
1320
+ const next = candidate === null ? (navigableNodes.firstOrDefault() ?? null) : (byUid.get(candidate.uid) ?? null);
1321
+ if (next !== navigatedNode) {
1322
+ this.navigatedNode.set(next);
1323
+ }
1324
+ }
1078
1325
  loadCheckedKeysForChildren(node, childNodes) {
1079
1326
  const checkedKeys = this.#checkedKeys();
1080
1327
  if (node.checked() && this.checkableOptions().checkChildren) {
@@ -1098,6 +1345,19 @@ class TreeService {
1098
1345
  });
1099
1346
  }
1100
1347
  }
1348
+ /** Loads the children of the expanded, shown nodes whose children come from an observable and aren't loaded. */
1349
+ loadExpandedNodes(nodes, expandedKeys) {
1350
+ for (const node of _a.flatten(nodes)) {
1351
+ if (node.childrenLoaded || node.loading() || node.loadFailed() || !node.children().isEmpty()) {
1352
+ continue;
1353
+ }
1354
+ if (expandedKeys.contains(this.getExpandKey(node)) &&
1355
+ this.hasChildren(node) &&
1356
+ !this.isAnyParentCollapsed(node)) {
1357
+ this.loadNodeChildren(node);
1358
+ }
1359
+ }
1360
+ }
1101
1361
  moveNodeAfter(sourceNode, targetNode) {
1102
1362
  if (sourceNode.parent) {
1103
1363
  sourceNode.parent.children.update(list => {
@@ -1297,7 +1557,15 @@ const subTreeListItemThemeVariants = cva(`
1297
1557
  const treeBaseThemeVariants = cva(`
1298
1558
  relative outline-none select-none
1299
1559
  text-base
1300
- `);
1560
+ `, {
1561
+ variants: {
1562
+ // An empty tree has no active node to draw the ring on, so the tree draws it.
1563
+ empty: {
1564
+ true: "block min-h-full focus-visible:inset-ring-2 focus-visible:inset-ring-focus-indicator",
1565
+ false: ""
1566
+ }
1567
+ }
1568
+ });
1301
1569
  const treeDropHintBaseThemeVariants = cva(`
1302
1570
  fixed z-1 h-0.5 w-10
1303
1571
  pointer-events-none
@@ -1316,7 +1584,7 @@ const treeNodeBaseThemeVariants = cva(`
1316
1584
  false: ""
1317
1585
  },
1318
1586
  highlighted: {
1319
- true: "inset-ring-1 inset-ring-focus-indicator/35",
1587
+ true: "inset-ring-2 inset-ring-focus-indicator",
1320
1588
  false: ""
1321
1589
  },
1322
1590
  selected: {
@@ -1352,30 +1620,6 @@ const treeNodeExpanderThemeVariants = cva(`
1352
1620
  cursor-pointer text-sm text-foreground
1353
1621
  `);
1354
1622
 
1355
- // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
1356
- // Edit the JSON file and run `npm run generate:locale-catalogs`.
1357
- const TREE_DEFAULT_MESSAGES = {
1358
- collapse: "Collapse",
1359
- expand: "Expand",
1360
- filter: "Filter",
1361
- filterTree: "Filter tree"
1362
- };
1363
-
1364
- class NodeEvent extends PreventableEvent {
1365
- #node;
1366
- constructor(type, node, event) {
1367
- super(type, event);
1368
- this.#node = node;
1369
- }
1370
- get nodeItem() {
1371
- return {
1372
- data: this.#node.data,
1373
- hasChildren: this.#node.children().length > 0,
1374
- uid: this.#node.uid
1375
- };
1376
- }
1377
- }
1378
-
1379
1623
  class NodeDragEndEvent extends NodeEvent {
1380
1624
  constructor(node, event) {
1381
1625
  super("nodeDragEnd", node, event);
@@ -1426,45 +1670,6 @@ class NodeDragStartEvent extends NodeEvent {
1426
1670
  }
1427
1671
  }
1428
1672
 
1429
- class NodeDropEvent extends NodeEvent {
1430
- #params;
1431
- constructor(params) {
1432
- super("nodeDrop", params.sourceNode, params.event);
1433
- this.#params = params;
1434
- }
1435
- get position() {
1436
- return this.#params.position;
1437
- }
1438
- get sourceNode() {
1439
- return this.#params.sourceNode.nodeItem;
1440
- }
1441
- get targetNode() {
1442
- return this.#params.targetNode.nodeItem;
1443
- }
1444
- get treeView() {
1445
- return this.#params.treeView;
1446
- }
1447
- }
1448
- class NodeDropEventSansTree extends NodeEvent {
1449
- #params;
1450
- constructor(params) {
1451
- super("nodeDropSansTree", params.sourceNode, params.event);
1452
- this.#params = params;
1453
- }
1454
- get event() {
1455
- return this.#params.event;
1456
- }
1457
- get position() {
1458
- return this.#params.position;
1459
- }
1460
- get sourceNode() {
1461
- return this.#params.sourceNode;
1462
- }
1463
- get targetNode() {
1464
- return this.#params.targetNode;
1465
- }
1466
- }
1467
-
1468
1673
  class TreeNodeElementIdPipe {
1469
1674
  transform(uid) {
1470
1675
  return getTreeNodeElementId(uid);
@@ -1499,8 +1704,7 @@ class TreeNodeComponent {
1499
1704
  #dragging;
1500
1705
  constructor() {
1501
1706
  this.#destroyRef = inject(DestroyRef);
1502
- this.treeService = inject((TreeService));
1503
- this.#dragging = toSignal(this.treeService.dragging$, {
1707
+ this.#dragging = toSignal(inject((TreeService)).dragging$, {
1504
1708
  initialValue: false
1505
1709
  });
1506
1710
  this.baseClass = computed(() => {
@@ -1510,6 +1714,7 @@ class TreeNodeComponent {
1510
1714
  return treeNodeBaseThemeVariants({ disabled, highlighted, selected });
1511
1715
  }, /* @ts-ignore */
1512
1716
  ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
1717
+ this.treeService = inject((TreeService));
1513
1718
  this.checkable = computed(() => {
1514
1719
  const node = this.node();
1515
1720
  if (node === null) {
@@ -1529,6 +1734,8 @@ class TreeNodeComponent {
1529
1734
  return this.treeService.isChecked(node);
1530
1735
  }, /* @ts-ignore */
1531
1736
  ...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
1737
+ this.depth = input(0, /* @ts-ignore */
1738
+ ...(ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []));
1532
1739
  this.disabled = computed(() => {
1533
1740
  const node = this.node();
1534
1741
  if (node === null) {
@@ -1579,6 +1786,8 @@ class TreeNodeComponent {
1579
1786
  return this.treeService.isNavigated(node);
1580
1787
  }, /* @ts-ignore */
1581
1788
  ...(ngDevMode ? [{ debugName: "navigated" }] : /* istanbul ignore next */ []));
1789
+ this.node = input(null, /* @ts-ignore */
1790
+ ...(ngDevMode ? [{ debugName: "node" }] : /* istanbul ignore next */ []));
1582
1791
  this.nodeText = computed(() => {
1583
1792
  const node = this.node();
1584
1793
  if (node === null) {
@@ -1595,10 +1804,6 @@ class TreeNodeComponent {
1595
1804
  return this.treeService.isSelected(node);
1596
1805
  }, /* @ts-ignore */
1597
1806
  ...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
1598
- this.depth = input(0, /* @ts-ignore */
1599
- ...(ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []));
1600
- this.node = input(null, /* @ts-ignore */
1601
- ...(ngDevMode ? [{ debugName: "node" }] : /* istanbul ignore next */ []));
1602
1807
  this.setCheckboxClickSubscription();
1603
1808
  }
1604
1809
  onNodeClick(event) {
@@ -1625,17 +1830,20 @@ class TreeNodeComponent {
1625
1830
  if (selectableOptions.childrenOnly && this.treeService.hasChildren(node)) {
1626
1831
  return;
1627
1832
  }
1833
+ if (!this.treeService.selectionWouldChange(node)) {
1834
+ return;
1835
+ }
1628
1836
  const nodeSelectEvent = new NodeSelectEvent(node, event);
1629
1837
  this.treeService.nodeSelect$.next(nodeSelectEvent);
1630
1838
  if (nodeSelectEvent.isDefaultPrevented()) {
1631
1839
  return;
1632
1840
  }
1633
- const newSelected = !this.selected();
1634
- this.treeService.setNodeSelect(node, newSelected);
1635
- this.treeService.nodeSelectChange$.next({ node, selected: newSelected });
1636
- this.treeService.notifySelectionChange(node);
1841
+ if (this.treeService.setNodeSelect(node, !this.selected())) {
1842
+ this.treeService.nodeSelectChange$.next({ node, selected: this.treeService.isSelected(node) });
1843
+ this.treeService.notifySelectionChange(node);
1844
+ }
1637
1845
  }
1638
- onNodeContextMenu(event) {
1846
+ onNodeContextMenu() {
1639
1847
  const node = this.node();
1640
1848
  if (node === null) {
1641
1849
  return;
@@ -1674,11 +1882,11 @@ class TreeNodeComponent {
1674
1882
  });
1675
1883
  }
1676
1884
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1677
- 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>\n @if (treeService.nodeTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\n [ngTemplateOutletContext]=\"{\n $implicit: node()?.data,\n element: element.parentElement\n }\"></ng-container>\n } @else {\n <span class=\"truncate\">{{ nodeText() }}</span>\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1885
+ 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()\" #element>\n @if (treeService.nodeTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\n [ngTemplateOutletContext]=\"{\n $implicit: node()?.data,\n element: element.parentElement\n }\"></ng-container>\n } @else {\n <span class=\"truncate\">{{ nodeText() }}</span>\n }\n</div>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] }); }
1678
1886
  }
1679
1887
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeNodeComponent, decorators: [{
1680
1888
  type: Component,
1681
- args: [{ selector: "mona-tree-node", changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgTemplateOutlet], template: "<div [class]=\"baseClass()\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeContextMenu($event)\" #element>\n @if (treeService.nodeTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\n [ngTemplateOutletContext]=\"{\n $implicit: node()?.data,\n element: element.parentElement\n }\"></ng-container>\n } @else {\n <span class=\"truncate\">{{ nodeText() }}</span>\n }\n</div>\n" }]
1889
+ args: [{ selector: "mona-tree-node", imports: [NgTemplateOutlet], template: "<div [class]=\"baseClass()\" (click)=\"onNodeClick($event)\" (contextmenu)=\"onNodeContextMenu()\" #element>\n @if (treeService.nodeTemplate()) {\n <ng-container\n [ngTemplateOutlet]=\"treeService.nodeTemplate()\"\n [ngTemplateOutletContext]=\"{\n $implicit: node()?.data,\n element: element.parentElement\n }\"></ng-container>\n } @else {\n <span class=\"truncate\">{{ nodeText() }}</span>\n }\n</div>\n" }]
1682
1890
  }], ctorParameters: () => [], propDecorators: { depth: [{ type: i0.Input, args: [{ isSignal: true, alias: "depth", required: false }] }], node: [{ type: i0.Input, args: [{ isSignal: true, alias: "node", required: false }] }] } });
1683
1891
 
1684
1892
  class SubTreeComponent {
@@ -1711,6 +1919,12 @@ class SubTreeComponent {
1711
1919
  return treeNodeExpanderThemeVariants();
1712
1920
  }, /* @ts-ignore */
1713
1921
  ...(ngDevMode ? [{ debugName: "nodeExpanderClass" }] : /* istanbul ignore next */ []));
1922
+ /**
1923
+ * With checkboxes, a node reports whether it is checked (`aria-checked`); reporting selection as well would give
1924
+ * it two conflicting states, so selection is then shown but not reported.
1925
+ */
1926
+ this.selectionReported = computed(() => this.treeService.selectableOptions().enabled && !this.treeService.checkableOptions().enabled, /* @ts-ignore */
1927
+ ...(ngDevMode ? [{ debugName: "selectionReported" }] : /* istanbul ignore next */ []));
1714
1928
  this.treeService = inject(TreeService);
1715
1929
  this.visibleNodes = computed(() => {
1716
1930
  return this.nodes()
@@ -1730,14 +1944,11 @@ class SubTreeComponent {
1730
1944
  onExpandStateChange(node) {
1731
1945
  this.treeService.toggleNodeExpand(node, !this.treeService.isExpanded(node));
1732
1946
  }
1947
+ /** The drag is over whatever a `nodeDragEnd` handler does, so it can't be kept going with `preventDefault()`. */
1733
1948
  onNodeDragEnd(event) {
1734
- const nodeDragEndEvent = new NodeDragEndEvent(event.source.data, event.event);
1735
- this.treeService.nodeDragEnd$.next(nodeDragEndEvent);
1736
- if (nodeDragEndEvent.isDefaultPrevented()) {
1737
- return;
1738
- }
1739
1949
  this.treeService.dropAllowed.set(false);
1740
1950
  this.treeService.dragging.set(false);
1951
+ this.treeService.nodeDragEnd$.next(new NodeDragEndEvent(event.source.data, event.event));
1741
1952
  }
1742
1953
  onNodeDragMove(event, node) {
1743
1954
  this.treeService.dropPositionChange$.pipe(take(1)).subscribe(e => {
@@ -1797,6 +2008,16 @@ class SubTreeComponent {
1797
2008
  this.#zone.runOutsideAngular(() => asapScheduler.schedule(() => this.treeService.animationTemporarilyDisabled.set(false)));
1798
2009
  });
1799
2010
  }
2011
+ expanderLabel(node, expanded, text) {
2012
+ const messages = this.messages();
2013
+ if (node.loading()) {
2014
+ return messages.loadingNode(text);
2015
+ }
2016
+ if (node.loadFailed()) {
2017
+ return messages.retryLoading(text);
2018
+ }
2019
+ return `${expanded ? messages.collapse : messages.expand} ${text}`;
2020
+ }
1800
2021
  nodeAnimationDisabled() {
1801
2022
  return (!this.treeService.animationEnabled() ||
1802
2023
  this.treeService.animationTemporarilyDisabled() ||
@@ -1813,16 +2034,17 @@ class SubTreeComponent {
1813
2034
  element.focus();
1814
2035
  }
1815
2036
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SubTreeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
1816
- 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\n [class]=\"listClass()\"\n [attr.role]=\"parent() ? 'group' : 'none'\"\n cdkDropList\n [cdkDropListSortingDisabled]=\"true\"\n (cdkDropListDropped)=\"onNodeDrop($event)\">\n @for (node of visibleNodes(); track node.uid) {\n <li\n [attr.id]=\"node.uid | treeNodeElementId\"\n [attr.data-uid]=\"node.uid\"\n [class]=\"listItemClass()\"\n [tabindex]=\"-1\"\n role=\"treeitem\"\n [attr.aria-level]=\"depth() + 1\"\n [attr.aria-setsize]=\"visibleNodes().length\"\n [attr.aria-posinset]=\"$index + 1\"\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\n [attr.aria-selected]=\"treeService.selectableOptions().enabled ? nodeComponent.selected() : null\"\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\n [attr.aria-checked]=\"\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\n \"\n (focus)=\"treeService.navigatedNode.set(node)\"\n cdkDrag\n [cdkDragData]=\"node\"\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\n (cdkDragStarted)=\"onNodeDragStart($event)\"\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\n <div [class]=\"nodeContainerClass()\">\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [class]=\"nodeExpanderClass()\"\n [class.mona-disabled]=\"nodeComponent.disabled()\"\n [disabled]=\"nodeComponent.disabled()\"\n [attr.aria-label]=\"\n (nodeComponent.expanded() ? messages().collapse : messages().expand) +\n ' ' +\n nodeComponent.nodeText()\n \"\n (click)=\"onExpandStateChange(node)\">\n @if (node.loading()) {\n <svg lucideLoaderCircle [size]=\"16\" aria-hidden=\"true\" class=\"animate-spin\"></svg>\n } @else if (nodeComponent.expanded()) {\n <svg lucideChevronDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" aria-hidden=\"true\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n }\n @if (nodeComponent.checkable()) {\n <mona-check-box\n aria-hidden=\"true\"\n [tabIndex]=\"-1\"\n [disabled]=\"nodeComponent.disabled()\"\n [indeterminate]=\"nodeComponent.indeterminate()\"\n [ngModel]=\"nodeComponent.checked()\"\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\n }\n <mona-tree-node [node]=\"node\" [depth]=\"depth()\" #nodeComponent></mona-tree-node>\n </div>\n @if (node.children().length > 0 && nodeComponent.expanded()) {\n <div\n class=\"grid overflow-hidden\"\n [animate.enter]=\"nodeExpandEnterClass()\"\n [animate.leave]=\"nodeExpandLeaveClass()\">\n <div class=\"min-h-0 overflow-hidden\">\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\n </div>\n </div>\n }\n @if (!nodeComponent.disabled()) {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\n <span>\n @switch (treeService.dropPositionSignal()?.position) {\n @case (\"before\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowUp [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"after\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"inside\") {\n <svg lucidePlus [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n @default {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n </span>\n <span>{{ nodeComponent.nodeText() }}</span>\n </div>\n } @else {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\n }\n </li>\n }\n</ul>\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: LucideArrowDown, selector: "svg[lucideArrowDown]" }, { kind: "component", type: LucideArrowUp, selector: "svg[lucideArrowUp]" }, { kind: "component", type: LucideBan, selector: "svg[lucideBan]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideLoaderCircle, selector: "svg[lucideLoaderCircle], svg[lucideLoader2]" }, { kind: "component", type: LucidePlus, selector: "svg[lucidePlus]" }, { 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: ["aria-describedby", "aria-label", "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 }); }
2037
+ 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\n [class]=\"listClass()\"\n [attr.role]=\"parent() ? 'group' : 'none'\"\n cdkDropList\n [cdkDropListSortingDisabled]=\"true\"\n (cdkDropListDropped)=\"onNodeDrop($event)\">\n @for (node of visibleNodes(); track node.uid) {\n <li\n [attr.id]=\"node.uid | treeNodeElementId\"\n [attr.data-uid]=\"node.uid\"\n [class]=\"listItemClass()\"\n [tabindex]=\"-1\"\n role=\"treeitem\"\n [attr.aria-level]=\"depth() + 1\"\n [attr.aria-setsize]=\"visibleNodes().length\"\n [attr.aria-posinset]=\"$index + 1\"\n [attr.aria-labelledby]=\"(node.uid | treeNodeElementId) + '-label'\"\n [attr.aria-describedby]=\"node.loadFailed() ? (node.uid | treeNodeElementId) + '-error' : null\"\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\n [attr.aria-busy]=\"node.loading() || null\"\n [attr.aria-selected]=\"selectionReported() ? nodeComponent.selected() : null\"\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\n [attr.aria-checked]=\"\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\n \"\n (focus)=\"treeService.navigatedNode.set(node)\"\n cdkDrag\n [cdkDragData]=\"node\"\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\n (cdkDragStarted)=\"onNodeDragStart($event)\"\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\n <div [class]=\"nodeContainerClass()\">\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [class]=\"nodeExpanderClass()\"\n [class.mona-disabled]=\"nodeComponent.disabled()\"\n [disabled]=\"nodeComponent.disabled()\"\n [attr.aria-label]=\"expanderLabel(node, nodeComponent.expanded(), nodeComponent.nodeText())\"\n (click)=\"onExpandStateChange(node)\">\n @if (node.loading()) {\n <svg lucideLoaderCircle [size]=\"16\" aria-hidden=\"true\" class=\"animate-spin\"></svg>\n } @else if (node.loadFailed()) {\n <svg lucideCircleAlert [size]=\"16\" aria-hidden=\"true\" class=\"text-error\"></svg>\n } @else if (nodeComponent.expanded()) {\n <svg lucideChevronDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" aria-hidden=\"true\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n }\n @if (nodeComponent.checkable()) {\n <mona-check-box\n aria-hidden=\"true\"\n [tabIndex]=\"-1\"\n [disabled]=\"nodeComponent.disabled()\"\n [indeterminate]=\"nodeComponent.indeterminate()\"\n [ngModel]=\"nodeComponent.checked()\"\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\n }\n <mona-tree-node\n [id]=\"(node.uid | treeNodeElementId) + '-label'\"\n [node]=\"node\"\n [depth]=\"depth()\"\n #nodeComponent></mona-tree-node>\n @if (node.loadFailed()) {\n <span [id]=\"(node.uid | treeNodeElementId) + '-error'\" class=\"sr-only\">{{\n messages().loadError(nodeComponent.nodeText())\n }}</span>\n }\n </div>\n @if (node.children().length > 0 && nodeComponent.expanded()) {\n <div\n class=\"grid overflow-hidden\"\n [animate.enter]=\"nodeExpandEnterClass()\"\n [animate.leave]=\"nodeExpandLeaveClass()\">\n <div class=\"min-h-0 overflow-hidden\">\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\n </div>\n </div>\n }\n @if (!nodeComponent.disabled()) {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\n <span>\n @switch (treeService.dropPositionSignal()?.position) {\n @case (\"before\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowUp [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"after\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"inside\") {\n <svg lucidePlus [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n @default {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n </span>\n <span>{{ nodeComponent.nodeText() }}</span>\n </div>\n } @else {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\n }\n </li>\n }\n</ul>\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: LucideArrowDown, selector: "svg[lucideArrowDown]" }, { kind: "component", type: LucideArrowUp, selector: "svg[lucideArrowUp]" }, { kind: "component", type: LucideBan, selector: "svg[lucideBan]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideCircleAlert, selector: "svg[lucideCircleAlert], svg[lucideAlertCircle]" }, { kind: "component", type: LucideLoaderCircle, selector: "svg[lucideLoaderCircle], svg[lucideLoader2]" }, { kind: "component", type: LucidePlus, selector: "svg[lucidePlus]" }, { 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: ["aria-describedby", "aria-label", "checked", "disabled", "indeterminate", "invalid", "label", "labelPosition", "labelSize", "required", "rounded", "tabIndex", "touched", "class"], outputs: ["checkedChange", "inputBlur", "inputChange", "inputFocus", "touch"] }, { kind: "pipe", type: TreeNodeElementIdPipe, name: "treeNodeElementId" }] }); }
1817
2038
  }
1818
2039
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: SubTreeComponent, decorators: [{
1819
2040
  type: Component,
1820
- args: [{ selector: "mona-sub-tree", changeDetection: ChangeDetectionStrategy.OnPush, imports: [
2041
+ args: [{ selector: "mona-sub-tree", imports: [
1821
2042
  LucideArrowDown,
1822
2043
  LucideArrowUp,
1823
2044
  LucideBan,
1824
2045
  LucideChevronDown,
1825
2046
  LucideChevronRight,
2047
+ LucideCircleAlert,
1826
2048
  LucideLoaderCircle,
1827
2049
  LucidePlus,
1828
2050
  TreeNodeComponent,
@@ -1832,7 +2054,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
1832
2054
  CdkDragPreview,
1833
2055
  CheckBoxComponent,
1834
2056
  TreeNodeElementIdPipe
1835
- ], template: "<ul\n [class]=\"listClass()\"\n [attr.role]=\"parent() ? 'group' : 'none'\"\n cdkDropList\n [cdkDropListSortingDisabled]=\"true\"\n (cdkDropListDropped)=\"onNodeDrop($event)\">\n @for (node of visibleNodes(); track node.uid) {\n <li\n [attr.id]=\"node.uid | treeNodeElementId\"\n [attr.data-uid]=\"node.uid\"\n [class]=\"listItemClass()\"\n [tabindex]=\"-1\"\n role=\"treeitem\"\n [attr.aria-level]=\"depth() + 1\"\n [attr.aria-setsize]=\"visibleNodes().length\"\n [attr.aria-posinset]=\"$index + 1\"\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\n [attr.aria-selected]=\"treeService.selectableOptions().enabled ? nodeComponent.selected() : null\"\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\n [attr.aria-checked]=\"\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\n \"\n (focus)=\"treeService.navigatedNode.set(node)\"\n cdkDrag\n [cdkDragData]=\"node\"\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\n (cdkDragStarted)=\"onNodeDragStart($event)\"\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\n <div [class]=\"nodeContainerClass()\">\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [class]=\"nodeExpanderClass()\"\n [class.mona-disabled]=\"nodeComponent.disabled()\"\n [disabled]=\"nodeComponent.disabled()\"\n [attr.aria-label]=\"\n (nodeComponent.expanded() ? messages().collapse : messages().expand) +\n ' ' +\n nodeComponent.nodeText()\n \"\n (click)=\"onExpandStateChange(node)\">\n @if (node.loading()) {\n <svg lucideLoaderCircle [size]=\"16\" aria-hidden=\"true\" class=\"animate-spin\"></svg>\n } @else if (nodeComponent.expanded()) {\n <svg lucideChevronDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" aria-hidden=\"true\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n }\n @if (nodeComponent.checkable()) {\n <mona-check-box\n aria-hidden=\"true\"\n [tabIndex]=\"-1\"\n [disabled]=\"nodeComponent.disabled()\"\n [indeterminate]=\"nodeComponent.indeterminate()\"\n [ngModel]=\"nodeComponent.checked()\"\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\n }\n <mona-tree-node [node]=\"node\" [depth]=\"depth()\" #nodeComponent></mona-tree-node>\n </div>\n @if (node.children().length > 0 && nodeComponent.expanded()) {\n <div\n class=\"grid overflow-hidden\"\n [animate.enter]=\"nodeExpandEnterClass()\"\n [animate.leave]=\"nodeExpandLeaveClass()\">\n <div class=\"min-h-0 overflow-hidden\">\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\n </div>\n </div>\n }\n @if (!nodeComponent.disabled()) {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\n <span>\n @switch (treeService.dropPositionSignal()?.position) {\n @case (\"before\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowUp [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"after\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"inside\") {\n <svg lucidePlus [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n @default {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n </span>\n <span>{{ nodeComponent.nodeText() }}</span>\n </div>\n } @else {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\n }\n </li>\n }\n</ul>\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"] }]
2057
+ ], template: "<ul\n [class]=\"listClass()\"\n [attr.role]=\"parent() ? 'group' : 'none'\"\n cdkDropList\n [cdkDropListSortingDisabled]=\"true\"\n (cdkDropListDropped)=\"onNodeDrop($event)\">\n @for (node of visibleNodes(); track node.uid) {\n <li\n [attr.id]=\"node.uid | treeNodeElementId\"\n [attr.data-uid]=\"node.uid\"\n [class]=\"listItemClass()\"\n [tabindex]=\"-1\"\n role=\"treeitem\"\n [attr.aria-level]=\"depth() + 1\"\n [attr.aria-setsize]=\"visibleNodes().length\"\n [attr.aria-posinset]=\"$index + 1\"\n [attr.aria-labelledby]=\"(node.uid | treeNodeElementId) + '-label'\"\n [attr.aria-describedby]=\"node.loadFailed() ? (node.uid | treeNodeElementId) + '-error' : null\"\n [attr.aria-expanded]=\"nodeComponent.expandable() ? nodeComponent.expanded() : null\"\n [attr.aria-busy]=\"node.loading() || null\"\n [attr.aria-selected]=\"selectionReported() ? nodeComponent.selected() : null\"\n [attr.aria-disabled]=\"nodeComponent.disabled() ? true : null\"\n [attr.aria-checked]=\"\n nodeComponent.checkable() ? (nodeComponent.indeterminate() ? 'mixed' : nodeComponent.checked()) : null\n \"\n (focus)=\"treeService.navigatedNode.set(node)\"\n cdkDrag\n [cdkDragData]=\"node\"\n [cdkDragDisabled]=\"!treeService.draggableOptions().enabled\"\n (cdkDragStarted)=\"onNodeDragStart($event)\"\n (cdkDragEnded)=\"onNodeDragEnd($event)\"\n (cdkDragMoved)=\"onNodeDragMove($event, node)\">\n <div [class]=\"nodeContainerClass()\">\n @if (treeService.expandableOptions().enabled && nodeComponent.expandable()) {\n <button\n type=\"button\"\n tabindex=\"-1\"\n [class]=\"nodeExpanderClass()\"\n [class.mona-disabled]=\"nodeComponent.disabled()\"\n [disabled]=\"nodeComponent.disabled()\"\n [attr.aria-label]=\"expanderLabel(node, nodeComponent.expanded(), nodeComponent.nodeText())\"\n (click)=\"onExpandStateChange(node)\">\n @if (node.loading()) {\n <svg lucideLoaderCircle [size]=\"16\" aria-hidden=\"true\" class=\"animate-spin\"></svg>\n } @else if (node.loadFailed()) {\n <svg lucideCircleAlert [size]=\"16\" aria-hidden=\"true\" class=\"text-error\"></svg>\n } @else if (nodeComponent.expanded()) {\n <svg lucideChevronDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideChevronRight [size]=\"16\" aria-hidden=\"true\" class=\"rtl:rotate-180\"></svg>\n }\n </button>\n }\n @if (nodeComponent.checkable()) {\n <mona-check-box\n aria-hidden=\"true\"\n [tabIndex]=\"-1\"\n [disabled]=\"nodeComponent.disabled()\"\n [indeterminate]=\"nodeComponent.indeterminate()\"\n [ngModel]=\"nodeComponent.checked()\"\n (click)=\"nodeComponent.checkboxClick$.next($event)\"\n (ngModelChange)=\"nodeComponent.checkboxCheck$.next($event)\"></mona-check-box>\n }\n <mona-tree-node\n [id]=\"(node.uid | treeNodeElementId) + '-label'\"\n [node]=\"node\"\n [depth]=\"depth()\"\n #nodeComponent></mona-tree-node>\n @if (node.loadFailed()) {\n <span [id]=\"(node.uid | treeNodeElementId) + '-error'\" class=\"sr-only\">{{\n messages().loadError(nodeComponent.nodeText())\n }}</span>\n }\n </div>\n @if (node.children().length > 0 && nodeComponent.expanded()) {\n <div\n class=\"grid overflow-hidden\"\n [animate.enter]=\"nodeExpandEnterClass()\"\n [animate.leave]=\"nodeExpandLeaveClass()\">\n <div class=\"min-h-0 overflow-hidden\">\n <mona-sub-tree [nodes]=\"node.children()\" [depth]=\"depth() + 1\" [parent]=\"node\"></mona-sub-tree>\n </div>\n </div>\n }\n @if (!nodeComponent.disabled()) {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\">\n <span>\n @switch (treeService.dropPositionSignal()?.position) {\n @case (\"before\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowUp [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"after\") {\n @if (treeService.dropAllowed()) {\n <svg lucideArrowDown [size]=\"16\" aria-hidden=\"true\"></svg>\n } @else {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n @case (\"inside\") {\n <svg lucidePlus [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n @default {\n <svg lucideBan [size]=\"16\" aria-hidden=\"true\"></svg>\n }\n }\n </span>\n <span>{{ nodeComponent.nodeText() }}</span>\n </div>\n } @else {\n <div *cdkDragPreview [class]=\"nodeDraggingClass()\"></div>\n }\n </li>\n }\n</ul>\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"] }]
1836
2058
  }], 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 }] }] } });
1837
2059
 
1838
2060
  class TreeDropHintComponent {
@@ -1908,37 +2130,62 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
1908
2130
  }, template: "<svg lucideChevronRight [size]=\"20\" [class]=\"iconClass()\" aria-hidden=\"true\"></svg>\n" }]
1909
2131
  }], ctorParameters: () => [] });
1910
2132
 
2133
+ /** The keyboard equivalents of dragging, listed on the tree while dragging is on. */
2134
+ const MOVE_KEY_SHORTCUTS = "Control+Shift+ArrowUp Control+Shift+ArrowDown Control+Shift+ArrowLeft Control+Shift+ArrowRight";
1911
2135
  class TreeComponent {
2136
+ #announcer;
1912
2137
  #destroyRef;
1913
2138
  #direction;
2139
+ #document;
1914
2140
  #focusMonitor;
1915
2141
  #hostElementRef;
1916
2142
  #i18n;
2143
+ #injector;
1917
2144
  #typeaheadKey$;
1918
2145
  #zone;
1919
2146
  #lastNavigatedNode;
1920
2147
  constructor() {
2148
+ this.#announcer = inject(LiveAnnouncer);
1921
2149
  this.#destroyRef = inject(DestroyRef);
1922
2150
  this.#direction = injectComponentDirection();
2151
+ this.#document = inject(DOCUMENT);
1923
2152
  this.#focusMonitor = inject(FocusMonitor);
1924
2153
  this.#hostElementRef = inject(ElementRef);
1925
2154
  this.#i18n = inject(MonaI18nService);
2155
+ this.#injector = inject(Injector);
1926
2156
  this.#typeaheadKey$ = new Subject();
1927
2157
  this.#zone = inject(NgZone);
1928
2158
  this.#lastNavigatedNode = null;
1929
- this.isRtl = computed(() => this.#direction() === "rtl", /* @ts-ignore */
1930
- ...(ngDevMode ? [{ debugName: "isRtl" }] : /* istanbul ignore next */ []));
1931
2159
  this.activeDescendantId = computed(() => {
1932
2160
  const node = this.treeService.navigatedNode();
1933
2161
  return node === null ? null : this.treeService.getNodeElementId(node.uid);
1934
2162
  }, /* @ts-ignore */
1935
2163
  ...(ngDevMode ? [{ debugName: "activeDescendantId" }] : /* istanbul ignore next */ []));
1936
2164
  this.baseClass = computed(() => {
1937
- return treeBaseThemeVariants();
2165
+ return treeBaseThemeVariants({ empty: this.treeService.viewNodeSet().isEmpty() });
1938
2166
  }, /* @ts-ignore */
1939
2167
  ...(ngDevMode ? [{ debugName: "baseClass" }] : /* istanbul ignore next */ []));
2168
+ this.isRtl = computed(() => this.#direction() === "rtl", /* @ts-ignore */
2169
+ ...(ngDevMode ? [{ debugName: "isRtl" }] : /* istanbul ignore next */ []));
2170
+ this.keyShortcuts = computed(() => this.treeService.draggableOptions().enabled ? MOVE_KEY_SHORTCUTS : null, /* @ts-ignore */
2171
+ ...(ngDevMode ? [{ debugName: "keyShortcuts" }] : /* istanbul ignore next */ []));
2172
+ this.messages = this.#i18n.componentMessages("treeView", TREE_DEFAULT_MESSAGES);
2173
+ /**
2174
+ * With checkboxes, nodes report `aria-checked` and not `aria-selected`, so the tree isn't multiselectable in the
2175
+ * `aria-selected` sense.
2176
+ */
2177
+ this.multiselectable = computed(() => {
2178
+ const selectable = this.treeService.selectableOptions();
2179
+ const checkable = this.treeService.checkableOptions().enabled;
2180
+ return (!checkable && selectable.enabled && selectable.mode === "multiple") || null;
2181
+ }, /* @ts-ignore */
2182
+ ...(ngDevMode ? [{ debugName: "multiselectable" }] : /* istanbul ignore next */ []));
2183
+ this.ariaDescribedBy = input("", /* @ts-ignore */
2184
+ ...(ngDevMode ? [{ debugName: "ariaDescribedBy" }] : /* istanbul ignore next */ []));
1940
2185
  this.ariaLabel = input("", /* @ts-ignore */
1941
2186
  ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
2187
+ this.ariaLabelledBy = input("", /* @ts-ignore */
2188
+ ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
1942
2189
  this.data = input(/* @ts-ignore */
1943
2190
  ...(ngDevMode ? [undefined, { debugName: "data" }] : /* istanbul ignore next */ []));
1944
2191
  this.nodeTemplate = contentChild(TreeNodeTemplateDirective, { ...(ngDevMode ? { debugName: "nodeTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
@@ -1969,16 +2216,70 @@ class TreeComponent {
1969
2216
  read: () => this.setSubscriptions()
1970
2217
  });
1971
2218
  }
1972
- handleMouseMoveWhileDragging(event) {
1973
- if (this.isMouseOutsideTree(event)) {
2219
+ /**
2220
+ * Once the tree has rendered after a keyboard move, finds out whether the `nodeDrop` handler applied it (through
2221
+ * `data` or `moveNode`). A move that was applied keeps the node active, opens the node it went into, and is
2222
+ * announced.
2223
+ */
2224
+ afterKeyboardMove(node, move, before) {
2225
+ const movedNode = this.treeService.findCounterpart(node);
2226
+ if (!movedNode) {
2227
+ return;
2228
+ }
2229
+ const after = this.locationOf(movedNode);
2230
+ if (after.parent === before.parent && after.index === before.index) {
2231
+ return;
2232
+ }
2233
+ const targetNode = this.treeService.findCounterpart(move.targetNode);
2234
+ if (move.position === "inside" && targetNode) {
2235
+ this.treeService.toggleNodeExpand(targetNode, true);
2236
+ }
2237
+ this.treeService.navigatedNode.set(movedNode);
2238
+ const messages = this.messages();
2239
+ const text = this.treeService.getNodeText(movedNode);
2240
+ const target = targetNode ? this.treeService.getNodeText(targetNode) : "";
2241
+ const announcement = move.position === "inside"
2242
+ ? messages.movedInto(text, target)
2243
+ : move.position === "before"
2244
+ ? messages.movedBefore(text, target)
2245
+ : messages.movedAfter(text, target);
2246
+ this.#announcer.announce(announcement, "polite");
2247
+ }
2248
+ /** Ctrl+Shift+Arrow (Cmd+Shift+Arrow on macOS) moves the active node while dragging is on. */
2249
+ handleMoveKey(event) {
2250
+ if (!this.treeService.draggableOptions().enabled) {
2251
+ return false;
2252
+ }
2253
+ if (!(event.ctrlKey || event.metaKey) || !event.shiftKey || event.altKey) {
2254
+ return false;
2255
+ }
2256
+ const direction = this.moveDirection(event.key);
2257
+ if (direction === null) {
2258
+ return false;
2259
+ }
2260
+ event.preventDefault();
2261
+ const node = this.treeService.navigatedNode();
2262
+ const move = node ? this.treeService.getKeyboardMove(node, direction) : null;
2263
+ if (node && move) {
2264
+ this.moveWithKeyboard(event, node, move);
2265
+ }
2266
+ return true;
2267
+ }
2268
+ handlePointerMoveWhileDragging(event) {
2269
+ const point = "touches" in event ? (event.touches[0] ?? event.changedTouches[0]) : event;
2270
+ if (!point) {
2271
+ return;
2272
+ }
2273
+ if (this.isPointerOutsideTree(point.clientY)) {
1974
2274
  this.treeService.dropPositionChange$.next({
1975
2275
  targetNode: null,
1976
2276
  position: "outside"
1977
2277
  });
1978
2278
  return;
1979
2279
  }
1980
- const element = event.target;
1981
- const closest = element.closest("li");
2280
+ // A touch keeps targeting the element it started on, so the element under the finger is looked up.
2281
+ const element = "touches" in event ? this.#document.elementFromPoint(point.clientX, point.clientY) : event.target;
2282
+ const closest = element instanceof Element ? element.closest("li") : null;
1982
2283
  if (!closest) {
1983
2284
  return;
1984
2285
  }
@@ -1994,27 +2295,80 @@ class TreeComponent {
1994
2295
  if (!nodeElement) {
1995
2296
  return;
1996
2297
  }
1997
- this.notifyDropPositionChange(event, nodeElement, node);
2298
+ this.notifyDropPositionChange(point.clientY, nodeElement, node);
1998
2299
  }
1999
- isMouseOutsideTree(event) {
2300
+ isPointerOutsideTree(clientY) {
2000
2301
  const rect = this.#hostElementRef.nativeElement.getBoundingClientRect();
2001
- return event.clientY < rect.top || event.clientY > rect.bottom;
2302
+ return clientY < rect.top || clientY > rect.bottom;
2303
+ }
2304
+ /**
2305
+ * Whether a key event is meant for the tree: from the tree itself or one of its nodes. Keys pressed in controls
2306
+ * of a node template (or in a tree nested in one) are left to those controls.
2307
+ */
2308
+ isTreeKeyTarget(event) {
2309
+ const host = this.#hostElementRef.nativeElement;
2310
+ const target = event.target;
2311
+ if (!(target instanceof HTMLElement) || target === host) {
2312
+ return true;
2313
+ }
2314
+ const nodeContent = target.closest("mona-tree-node");
2315
+ return nodeContent === null && target.closest("mona-tree") === host;
2316
+ }
2317
+ locationOf(node) {
2318
+ const siblings = node.parent ? node.parent.children() : this.treeService.nodeSet();
2319
+ return {
2320
+ index: siblings.toArray().indexOf(node),
2321
+ parent: node.parent ? this.treeService.getNodeIdentity(node.parent) : null
2322
+ };
2323
+ }
2324
+ moveDirection(key) {
2325
+ const isRtl = this.isRtl();
2326
+ switch (key) {
2327
+ case "ArrowUp":
2328
+ return "up";
2329
+ case "ArrowDown":
2330
+ return "down";
2331
+ case "ArrowRight":
2332
+ return isRtl ? "out" : "in";
2333
+ case "ArrowLeft":
2334
+ return isRtl ? "in" : "out";
2335
+ default:
2336
+ return null;
2337
+ }
2338
+ }
2339
+ /**
2340
+ * Asks for a keyboard move the way a drop does: `nodeDrop` is emitted, and its handler applies the move. The
2341
+ * keyboard event is the drop event's original event.
2342
+ */
2343
+ moveWithKeyboard(event, node, move) {
2344
+ const before = this.locationOf(node);
2345
+ const dropEvent = new NodeDropEventSansTree({
2346
+ event,
2347
+ position: move.position,
2348
+ sourceNode: node,
2349
+ targetNode: move.targetNode
2350
+ });
2351
+ this.treeService.nodeDrop$.next(dropEvent);
2352
+ if (dropEvent.isDefaultPrevented()) {
2353
+ return;
2354
+ }
2355
+ afterNextRender(() => this.afterKeyboardMove(node, move, before), { injector: this.#injector });
2002
2356
  }
2003
- notifyDropPositionChange(event, nodeElement, node) {
2357
+ notifyDropPositionChange(clientY, nodeElement, node) {
2004
2358
  const rect = nodeElement.getBoundingClientRect();
2005
- if (event.clientY > rect.top && event.clientY - rect.top <= 8) {
2359
+ if (clientY > rect.top && clientY - rect.top <= 8) {
2006
2360
  this.treeService.dropPositionChange$.next({
2007
2361
  targetNode: node,
2008
2362
  position: "before"
2009
2363
  });
2010
2364
  }
2011
- else if (event.clientY < rect.bottom && rect.bottom - event.clientY <= 8) {
2365
+ else if (clientY < rect.bottom && rect.bottom - clientY <= 8) {
2012
2366
  this.treeService.dropPositionChange$.next({
2013
2367
  targetNode: node,
2014
2368
  position: "after"
2015
2369
  });
2016
2370
  }
2017
- else if (event.clientY < rect.top || event.clientY > rect.bottom) {
2371
+ else if (clientY < rect.top || clientY > rect.bottom) {
2018
2372
  this.treeService.dropPositionChange$.next({
2019
2373
  targetNode: null,
2020
2374
  position: "outside"
@@ -2036,9 +2390,9 @@ class TreeComponent {
2036
2390
  asapScheduler.schedule(() => {
2037
2391
  if (this.treeService.navigatedNode() === null) {
2038
2392
  if (this.#lastNavigatedNode !== null) {
2039
- this.treeService.navigatedNode.set(this.#lastNavigatedNode);
2393
+ this.treeService.navigatedNode.set(this.treeService.findCounterpart(this.#lastNavigatedNode));
2040
2394
  }
2041
- else {
2395
+ if (this.treeService.navigatedNode() === null) {
2042
2396
  this.treeService.navigate("next");
2043
2397
  }
2044
2398
  }
@@ -2058,8 +2412,15 @@ class TreeComponent {
2058
2412
  }
2059
2413
  setKeydownSubscription() {
2060
2414
  fromEvent(this.#hostElementRef.nativeElement, "keydown")
2061
- .pipe(takeUntilDestroyed(this.#destroyRef))
2415
+ .pipe(filter(event => !event.isComposing && this.isTreeKeyTarget(event)), takeUntilDestroyed(this.#destroyRef))
2062
2416
  .subscribe(event => {
2417
+ if (this.handleMoveKey(event)) {
2418
+ return;
2419
+ }
2420
+ // Keys with Ctrl, Alt or Meta are shortcuts, left to the page and the browser.
2421
+ if (event.ctrlKey || event.metaKey || event.altKey) {
2422
+ return;
2423
+ }
2063
2424
  const navigatedNode = this.treeService.navigatedNode();
2064
2425
  const isRtl = this.isRtl();
2065
2426
  const collapseKey = isRtl ? "ArrowRight" : "ArrowLeft";
@@ -2073,16 +2434,16 @@ class TreeComponent {
2073
2434
  this.treeService.navigate("next");
2074
2435
  }
2075
2436
  else if (event.key === collapseKey) {
2076
- // WAI-ARIA tree: collapse an open node, otherwise move to the parent.
2437
+ // WAI-ARIA tree: collapse an open node, otherwise (closed, an end node, a node that can't be
2438
+ // collapsed) move to the parent.
2077
2439
  event.preventDefault();
2078
2440
  if (!navigatedNode) {
2079
2441
  return;
2080
2442
  }
2081
- const collapsible = this.treeService.hasChildren(navigatedNode) && this.treeService.isExpanded(navigatedNode);
2082
- if (collapsible && this.treeService.toggleNodeExpand(navigatedNode, false)) {
2443
+ if (this.treeService.toggleNodeExpand(navigatedNode, false)) {
2083
2444
  return;
2084
2445
  }
2085
- if (!collapsible && navigatedNode.parent) {
2446
+ if (navigatedNode.parent) {
2086
2447
  this.treeService.navigatedNode.set(navigatedNode.parent);
2087
2448
  }
2088
2449
  }
@@ -2148,14 +2509,18 @@ class TreeComponent {
2148
2509
  if (selectableOptions.childrenOnly && this.treeService.hasChildren(navigatedNode)) {
2149
2510
  return;
2150
2511
  }
2512
+ if (!this.treeService.selectionWouldChange(navigatedNode)) {
2513
+ return;
2514
+ }
2151
2515
  const nodeSelectEvent = new NodeSelectEvent(navigatedNode, event);
2152
2516
  this.treeService.nodeSelect$.next(nodeSelectEvent);
2153
- if (!nodeSelectEvent.isDefaultPrevented()) {
2154
- const newSelected = !this.treeService.isSelected(navigatedNode);
2155
- this.treeService.setNodeSelect(navigatedNode, newSelected);
2517
+ if (nodeSelectEvent.isDefaultPrevented()) {
2518
+ return;
2519
+ }
2520
+ if (this.treeService.setNodeSelect(navigatedNode, !this.treeService.isSelected(navigatedNode))) {
2156
2521
  this.treeService.nodeSelectChange$.next({
2157
2522
  node: navigatedNode,
2158
- selected: newSelected
2523
+ selected: this.treeService.isSelected(navigatedNode)
2159
2524
  });
2160
2525
  this.treeService.notifySelectionChange(navigatedNode);
2161
2526
  }
@@ -2166,9 +2531,9 @@ class TreeComponent {
2166
2531
  this.#zone.runOutsideAngular(() => {
2167
2532
  this.treeService.dragging$
2168
2533
  .pipe(takeUntilDestroyed(this.#destroyRef), switchMap(dragging => dragging
2169
- ? fromEvent(document, "mousemove").pipe(takeWhile(() => this.treeService.dragging()))
2534
+ ? merge(fromEvent(this.#document, "mousemove"), fromEvent(this.#document, "touchmove", { passive: true })).pipe(takeWhile(() => this.treeService.dragging()))
2170
2535
  : []))
2171
- .subscribe(event => this.handleMouseMoveWhileDragging(event));
2536
+ .subscribe(event => this.handlePointerMoveWhileDragging(event));
2172
2537
  });
2173
2538
  }
2174
2539
  setSubscriptions() {
@@ -2188,19 +2553,22 @@ class TreeComponent {
2188
2553
  });
2189
2554
  }
2190
2555
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2191
- 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 }); }
2556
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: TreeComponent, isStandalone: true, selector: "mona-tree", inputs: { ariaDescribedBy: { classPropertyName: "ariaDescribedBy", publicName: "ariaDescribedBy", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "ariaLabelledBy", 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-labelledby": "ariaLabelledBy() || null", "attr.aria-describedby": "ariaDescribedBy() || null", "attr.aria-multiselectable": "multiselectable()", "attr.aria-activedescendant": "activeDescendantId()", "attr.aria-keyshortcuts": "keyShortcuts()" } }, 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" }] }); }
2192
2557
  }
2193
2558
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: TreeComponent, decorators: [{
2194
2559
  type: Component,
2195
- args: [{ selector: "mona-tree", imports: [SubTreeComponent, TreeDropHintComponent], changeDetection: ChangeDetectionStrategy.OnPush, host: {
2560
+ args: [{ selector: "mona-tree", imports: [SubTreeComponent, TreeDropHintComponent], host: {
2196
2561
  "[class]": "baseClass()",
2197
2562
  "[attr.role]": "'tree'",
2198
2563
  "[attr.tabindex]": "0",
2199
2564
  "[attr.aria-label]": "ariaLabel() || null",
2200
- "[attr.aria-multiselectable]": "treeService.selectableOptions().mode === 'multiple' || null",
2201
- "[attr.aria-activedescendant]": "activeDescendantId()"
2565
+ "[attr.aria-labelledby]": "ariaLabelledBy() || null",
2566
+ "[attr.aria-describedby]": "ariaDescribedBy() || null",
2567
+ "[attr.aria-multiselectable]": "multiselectable()",
2568
+ "[attr.aria-activedescendant]": "activeDescendantId()",
2569
+ "[attr.aria-keyshortcuts]": "keyShortcuts()"
2202
2570
  }, 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" }]
2203
- }], ctorParameters: () => [], propDecorators: { ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], nodeTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TreeNodeTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }] } });
2571
+ }], ctorParameters: () => [], propDecorators: { ariaDescribedBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaDescribedBy", required: false }] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabel", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelledBy", required: false }] }], data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], nodeTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TreeNodeTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }] } });
2204
2572
 
2205
2573
  /**
2206
2574
  * Moves a node within a generic flat tree structure that uses parentId references.