@nanahoshi/mona-ui 0.24.6 → 0.24.8

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 (78) hide show
  1. package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
  2. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +14 -4
  3. package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
  4. package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +1 -1
  5. package/fesm2022/nanahoshi-mona-ui-filter.mjs +233 -231
  6. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-CD_ODHpU.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DdyHnUIr.mjs} +24 -12
  7. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-B6gq7Hu3.mjs +208 -0
  8. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-DdUY3I7P.mjs +1100 -0
  9. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-Sa1aAtJ-.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-DG8Bu4Dy.mjs} +34 -21
  10. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BvUM9nPt.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CVqpbMcb.mjs} +2565 -928
  11. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  12. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +79 -11
  13. package/fesm2022/nanahoshi-mona-ui-internal-filter-input.mjs +20 -4
  14. package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +335 -45
  15. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +565 -197
  16. package/fesm2022/nanahoshi-mona-ui-internal.mjs +28 -2
  17. package/fesm2022/nanahoshi-mona-ui-list-box.mjs +598 -208
  18. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +193 -74
  19. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +58 -11
  20. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +62 -11
  21. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +62 -11
  22. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +69 -11
  23. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +58 -11
  24. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +62 -11
  25. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +58 -11
  26. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +58 -11
  27. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +62 -11
  28. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +78 -11
  29. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +58 -11
  30. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +58 -11
  31. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +58 -11
  32. package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +1 -1
  33. package/fesm2022/nanahoshi-mona-ui-pager.mjs +367 -463
  34. package/fesm2022/nanahoshi-mona-ui-query.mjs +317 -122
  35. package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +205 -140
  36. package/i18n/catalogs/en-US.messages.json +64 -17
  37. package/locales/ar-sa/ar-sa.messages.json +58 -11
  38. package/locales/de-de/de-de.messages.json +58 -11
  39. package/locales/es-es/es-es.messages.json +58 -11
  40. package/locales/fr-fr/fr-fr.messages.json +58 -11
  41. package/locales/id-id/id-id.messages.json +58 -11
  42. package/locales/it-it/it-it.messages.json +58 -11
  43. package/locales/ja-jp/ja-jp.messages.json +58 -11
  44. package/locales/ko-kr/ko-kr.messages.json +58 -11
  45. package/locales/pt-br/pt-br.messages.json +58 -11
  46. package/locales/ru-ru/ru-ru.messages.json +58 -11
  47. package/locales/tr-tr/tr-tr.messages.json +58 -11
  48. package/locales/zh-cn/zh-cn.messages.json +58 -11
  49. package/locales/zh-tw/zh-tw.messages.json +58 -11
  50. package/package.json +1 -1
  51. package/types/nanahoshi-mona-ui-check-box.d.ts +11 -1
  52. package/types/nanahoshi-mona-ui-filter.d.ts +54 -32
  53. package/types/nanahoshi-mona-ui-grid.d.ts +359 -110
  54. package/types/nanahoshi-mona-ui-i18n.d.ts +97 -6
  55. package/types/nanahoshi-mona-ui-internal-filter-input.d.ts +14 -2
  56. package/types/nanahoshi-mona-ui-internal-list.d.ts +89 -10
  57. package/types/nanahoshi-mona-ui-internal-tree.d.ts +155 -40
  58. package/types/nanahoshi-mona-ui-internal.d.ts +10 -2
  59. package/types/nanahoshi-mona-ui-list-box.d.ts +148 -47
  60. package/types/nanahoshi-mona-ui-list-view.d.ts +111 -21
  61. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +53 -6
  62. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +53 -6
  63. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +53 -6
  64. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +53 -6
  65. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +53 -6
  66. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +53 -6
  67. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +53 -6
  68. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +53 -6
  69. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +53 -6
  70. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +53 -6
  71. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +53 -6
  72. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +53 -6
  73. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +53 -6
  74. package/types/nanahoshi-mona-ui-pager.d.ts +159 -76
  75. package/types/nanahoshi-mona-ui-query.d.ts +45 -14
  76. package/types/nanahoshi-mona-ui-tree-view.d.ts +84 -40
  77. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-0jN7I1jo.mjs +0 -176
  78. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-BI_iE7pl.mjs +0 -946
@@ -1,15 +1,16 @@
1
+ import { LiveAnnouncer } from '@angular/cdk/a11y';
1
2
  import { NgTemplateOutlet } from '@angular/common';
2
3
  import * as i0 from '@angular/core';
3
- import { Directive, inject, DestroyRef, ElementRef, computed, contentChild, TemplateRef, output, input, signal, effect, untracked, afterNextRender, Component } from '@angular/core';
4
- import { toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
+ import { Directive, input, booleanAttribute, inject, ElementRef, Injector, computed, signal, contentChild, TemplateRef, output, effect, untracked, afterNextRender, Component } from '@angular/core';
5
+ import { toObservable } from '@angular/core/rxjs-interop';
5
6
  import { LucideChevronUp, LucideChevronDown, LucideChevronLeft, LucideChevronRight, LucideChevronsLeft, LucideChevronsRight, LucideX, LucideTrash2 } from '@lucide/angular';
7
+ import { ImmutableList } from '@mirei/ts-collections';
6
8
  import { ButtonDirective } from '@nanahoshi/mona-ui/button';
7
- import { PreventableEvent, ContainsPipe } from '@nanahoshi/mona-ui/common';
8
- import { ListService } from '@nanahoshi/mona-ui/internal/list';
9
+ import { formatNumber, injectComponentDirection, MonaI18nService } from '@nanahoshi/mona-ui/i18n';
10
+ import { injectLabelledByText } from '@nanahoshi/mona-ui/internal';
11
+ import { ListService, LIST_VIEW_HOST_LIST_SERVICE } from '@nanahoshi/mona-ui/internal/list';
9
12
  import { ListViewComponent, ListViewSelectableDirective, ListViewItemTemplateDirective, ListViewNavigableDirective, ListViewNoDataTemplateDirective, ListViewFooterTemplateDirective, ListViewHeaderTemplateDirective } from '@nanahoshi/mona-ui/list-view';
10
- import { ImmutableList } from '@mirei/ts-collections';
11
- import { Subject, ReplaySubject, sample, delay, filter, tap, scan, startWith, switchMap } from 'rxjs';
12
- import { MonaI18nService } from '@nanahoshi/mona-ui/i18n';
13
+ import { PreventableEvent } from '@nanahoshi/mona-ui/common';
13
14
  import { cva } from 'class-variance-authority';
14
15
 
15
16
  class ListBoxFooterTemplateDirective {
@@ -34,16 +35,33 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
34
35
  }]
35
36
  }] });
36
37
 
38
+ /**
39
+ * Template for each item of a list box. The data item is the template's implicit value (`let-item`). Bind the list
40
+ * box's items to `monaListBoxItemTemplateOf` to type it; without it, the item is `any` in templates.
41
+ */
42
+ // `any` by default: a template without `monaListBoxItemTemplateOf` keeps an untyped item, as before the guard existed.
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
44
  class ListBoxItemTemplateDirective {
45
+ constructor() {
46
+ /**
47
+ * @description The list box's items, used only to type the template's item. Optional.
48
+ * @default null
49
+ */
50
+ this.monaListBoxItemTemplateOf = input(null, /* @ts-ignore */
51
+ ...(ngDevMode ? [{ debugName: "monaListBoxItemTemplateOf" }] : /* istanbul ignore next */ []));
52
+ }
53
+ static ngTemplateContextGuard(_directive, _context) {
54
+ return true;
55
+ }
38
56
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ListBoxItemTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
39
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: ListBoxItemTemplateDirective, isStandalone: true, selector: "ng-template[monaListBoxItemTemplate]", ngImport: i0 }); }
57
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.0.6", type: ListBoxItemTemplateDirective, isStandalone: true, selector: "ng-template[monaListBoxItemTemplate]", inputs: { monaListBoxItemTemplateOf: { classPropertyName: "monaListBoxItemTemplateOf", publicName: "monaListBoxItemTemplateOf", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 }); }
40
58
  }
41
59
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ListBoxItemTemplateDirective, decorators: [{
42
60
  type: Directive,
43
61
  args: [{
44
62
  selector: "ng-template[monaListBoxItemTemplate]"
45
63
  }]
46
- }] });
64
+ }], propDecorators: { monaListBoxItemTemplateOf: [{ type: i0.Input, args: [{ isSignal: true, alias: "monaListBoxItemTemplateOf", required: false }] }] } });
47
65
 
48
66
  class ListBoxNoDataTemplateDirective {
49
67
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ListBoxNoDataTemplateDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
@@ -58,17 +76,36 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
58
76
 
59
77
  // Generated from i18n/catalogs/en-US.messages.json by scripts/generate-locale-catalogs.ts. Do not edit.
60
78
  // Edit the JSON file and run `npm run generate:locale-catalogs`.
79
+ function localizeNumber(value, options) {
80
+ return formatNumber(value, "en-US", options);
81
+ }
61
82
  const LIST_BOX_DEFAULT_MESSAGES = {
62
83
  clearSelection: "Clear Selection",
84
+ itemsMoved: (position, total) => `Moved to position ${localizeNumber(position)} of ${localizeNumber(total)}`,
85
+ itemsRemoved: (count) => count === 1 ? `${localizeNumber(count)} item removed` : `${localizeNumber(count)} items removed`,
86
+ itemsTransferred: (count, list) => count === 1
87
+ ? `${localizeNumber(count)} item moved to ${list}`
88
+ : `${localizeNumber(count)} items moved to ${list}`,
89
+ itemsTransferredToOtherList: (count) => count === 1
90
+ ? `${localizeNumber(count)} item moved to the other list`
91
+ : `${localizeNumber(count)} items moved to the other list`,
63
92
  moveDown: "Move Down",
64
93
  moveUp: "Move Up",
65
94
  remove: "Remove",
66
- transferAllFrom: "Transfer All From",
67
- transferAllTo: "Transfer All To",
68
- transferFrom: "Transfer From",
69
- transferTo: "Transfer To"
95
+ selectionCleared: "Selection cleared",
96
+ toolbarLabel: (list) => `${list} actions`,
97
+ transferAllFrom: "Transfer all from the other list",
98
+ transferAllFromList: (list) => `Transfer all from ${list}`,
99
+ transferAllTo: "Transfer all to the other list",
100
+ transferAllToList: (list) => `Transfer all to ${list}`,
101
+ transferFrom: "Transfer from the other list",
102
+ transferFromList: (list) => `Transfer from ${list}`,
103
+ transferTo: "Transfer to the other list",
104
+ transferToList: (list) => `Transfer to ${list}`
70
105
  };
71
106
 
107
+ // `any` by default, so an event annotated without a type argument keeps untyped items.
108
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
109
  class ListBoxClearEvent extends PreventableEvent {
73
110
  #action = "clear";
74
111
  #selectedItems;
@@ -84,6 +121,8 @@ class ListBoxClearEvent extends PreventableEvent {
84
121
  }
85
122
  }
86
123
 
124
+ // `any` by default, so an event annotated without a type argument keeps untyped items.
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
126
  class ListBoxMoveEvent extends PreventableEvent {
88
127
  #action;
89
128
  #newIndex;
@@ -115,6 +154,8 @@ class ListBoxMoveEvent extends PreventableEvent {
115
154
  }
116
155
  }
117
156
 
157
+ // `any` by default, so an event annotated without a type argument keeps untyped items.
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
159
  class ListBoxRemoveEvent extends PreventableEvent {
119
160
  #action = "remove";
120
161
  #selectedItems;
@@ -130,6 +171,8 @@ class ListBoxRemoveEvent extends PreventableEvent {
130
171
  }
131
172
  }
132
173
 
174
+ // `any` by default, so an event annotated without a type argument keeps untyped items.
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
176
  class ListBoxTransferEvent extends PreventableEvent {
134
177
  #action;
135
178
  #selectedItems;
@@ -196,37 +239,91 @@ const listBoxToolbarThemeVariants = cva(`
196
239
  }
197
240
  });
198
241
 
242
+ const DEFAULT_ACTIONS = [
243
+ "clear",
244
+ "moveDown",
245
+ "moveUp",
246
+ "remove",
247
+ "transferAllFrom",
248
+ "transferAllTo",
249
+ "transferFrom",
250
+ "transferTo"
251
+ ];
252
+ /** The order the toolbar shows its buttons in, whatever order `actions` lists them in. */
253
+ const TOOLBAR_ORDER = [
254
+ "moveUp",
255
+ "moveDown",
256
+ "transferFrom",
257
+ "transferTo",
258
+ "transferAllFrom",
259
+ "transferAllTo",
260
+ "clear",
261
+ "remove"
262
+ ];
263
+ const TRANSFER_ACTIONS = new Set([
264
+ "transferAllFrom",
265
+ "transferAllTo",
266
+ "transferFrom",
267
+ "transferTo"
268
+ ]);
269
+ /** Accepts the bare `toolbar` attribute and `"true"`/`"false"`, as well as a boolean or an options object. */
270
+ function toToolbarSetting(value) {
271
+ if (value == null) {
272
+ return true;
273
+ }
274
+ if (typeof value === "boolean" || typeof value === "object") {
275
+ return value;
276
+ }
277
+ return booleanAttribute(value);
278
+ }
199
279
  class ListBoxComponent {
200
- #dataStateChange$;
201
- #destroyRef;
280
+ #direction;
202
281
  #hostElementRef;
203
282
  #i18n;
283
+ #injector;
284
+ /** The first index of each item, so positions are looked up once per action instead of with `indexOf`. */
285
+ #itemIndexes;
286
+ #labelledByText;
204
287
  #listService;
205
- #notifySelectionChange$;
288
+ #liveAnnouncer;
289
+ /** The list box's name as text: its `aria-label`, else the text of its `aria-labelledby` elements. */
290
+ #name;
291
+ /** The list box whose `connectedList` is this one, if any: its toolbar transfers items to and from this one. */
292
+ #owner;
293
+ /** The toolbar button that last had focus, which keeps the toolbar's Tab stop. */
294
+ #toolbarFocus;
295
+ /** The selection keys last reported through `selectionChange`, with their items. */
296
+ #reported;
206
297
  constructor() {
207
- this.#dataStateChange$ = new Subject();
208
- this.#destroyRef = inject(DestroyRef);
298
+ this.#direction = injectComponentDirection();
209
299
  this.#hostElementRef = inject(ElementRef);
210
300
  this.#i18n = inject(MonaI18nService);
211
- this.#listService = inject(ListService);
212
- this.#notifySelectionChange$ = new ReplaySubject(1);
213
- /**
214
- * The list box (`this` or the connected list box) that currently holds the selection; falling back to `this`
215
- * when neither side has a selection. Used by actions that make sense to run on `this` even with no selection
216
- * (e.g., "transfer all"). For actions that require a real selection to proceed, use {@link getSelectedListBox} instead.
217
- */
218
- this.activeListBox = computed(() => {
219
- const selectedItems = this.selectedItems();
220
- if (selectedItems.any()) {
221
- return this;
222
- }
223
- const connectedList = this.connectedList();
224
- if (connectedList?.selectedItems().any()) {
225
- return connectedList;
226
- }
227
- return this;
301
+ this.#injector = inject(Injector);
302
+ /** The first index of each item, so positions are looked up once per action instead of with `indexOf`. */
303
+ this.#itemIndexes = computed(() => {
304
+ const indexes = new Map();
305
+ this.listBoxItems().forEach((item, index) => {
306
+ if (!indexes.has(item)) {
307
+ indexes.set(item, index);
308
+ }
309
+ });
310
+ return indexes;
228
311
  }, /* @ts-ignore */
229
- ...(ngDevMode ? [{ debugName: "activeListBox" }] : /* istanbul ignore next */ []));
312
+ ...(ngDevMode ? [{ debugName: "#itemIndexes" }] : /* istanbul ignore next */ []));
313
+ this.#labelledByText = injectLabelledByText(() => this.ariaLabelledBy());
314
+ this.#listService = inject(ListService);
315
+ this.#liveAnnouncer = inject(LiveAnnouncer);
316
+ /** The list box's name as text: its `aria-label`, else the text of its `aria-labelledby` elements. */
317
+ this.#name = computed(() => this.ariaLabel().trim() || this.#labelledByText(), /* @ts-ignore */
318
+ ...(ngDevMode ? [{ debugName: "#name" }] : /* istanbul ignore next */ []));
319
+ /** The list box whose `connectedList` is this one, if any: its toolbar transfers items to and from this one. */
320
+ this.#owner = signal(null, /* @ts-ignore */
321
+ ...(ngDevMode ? [{ debugName: "#owner" }] : /* istanbul ignore next */ []));
322
+ /** The toolbar button that last had focus, which keeps the toolbar's Tab stop. */
323
+ this.#toolbarFocus = signal(null, /* @ts-ignore */
324
+ ...(ngDevMode ? [{ debugName: "#toolbarFocus" }] : /* istanbul ignore next */ []));
325
+ /** The selection keys last reported through `selectionChange`, with their items. */
326
+ this.#reported = new Map();
230
327
  this.baseClasses = computed(() => {
231
328
  const rounded = this.rounded();
232
329
  const size = this.size();
@@ -237,6 +334,24 @@ class ListBoxComponent {
237
334
  return listBoxBaseThemeVariants({ direction, reversed, rounded, size });
238
335
  }, /* @ts-ignore */
239
336
  ...(ngDevMode ? [{ debugName: "baseClasses" }] : /* istanbul ignore next */ []));
337
+ /** Whether the selection (in this list box or the connected one) can move down: it doesn't touch the end. */
338
+ this.canMoveDown = computed(() => {
339
+ const source = this.selectionHolder();
340
+ const indices = source?.selectedIndices() ?? [];
341
+ return source != null && indices.length > 0 && indices[indices.length - 1] < source.listBoxItems().length - 1;
342
+ }, /* @ts-ignore */
343
+ ...(ngDevMode ? [{ debugName: "canMoveDown" }] : /* istanbul ignore next */ []));
344
+ /** Whether the selection (in this list box or the connected one) can move up: it doesn't touch the start. */
345
+ this.canMoveUp = computed(() => {
346
+ const indices = this.selectionHolder()?.selectedIndices() ?? [];
347
+ return indices.length > 0 && indices[0] > 0;
348
+ }, /* @ts-ignore */
349
+ ...(ngDevMode ? [{ debugName: "canMoveUp" }] : /* istanbul ignore next */ []));
350
+ /** The items that aren't disabled by `disabledBy`, which are the ones the "All" transfers carry. */
351
+ this.enabledItems = computed(() => this.listBoxItems()
352
+ .where(item => !this.#listService.isDataItemDisabled(item))
353
+ .toArray(), /* @ts-ignore */
354
+ ...(ngDevMode ? [{ debugName: "enabledItems" }] : /* istanbul ignore next */ []));
240
355
  this.footerTemplate = contentChild(ListBoxFooterTemplateDirective, { ...(ngDevMode ? { debugName: "footerTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
241
356
  this.headerTemplate = contentChild(ListBoxHeaderTemplateDirective, { ...(ngDevMode ? { debugName: "headerTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
242
357
  this.itemTemplate = contentChild(ListBoxItemTemplateDirective, { ...(ngDevMode ? { debugName: "itemTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
@@ -252,6 +367,20 @@ class ListBoxComponent {
252
367
  ...(ngDevMode ? [{ debugName: "listWidth" }] : /* istanbul ignore next */ []));
253
368
  this.messages = this.#i18n.componentMessages("listBox", LIST_BOX_DEFAULT_MESSAGES);
254
369
  this.noDataTemplate = contentChild(ListBoxNoDataTemplateDirective, { ...(ngDevMode ? { debugName: "noDataTemplate" } : /* istanbul ignore next */ {}), read: TemplateRef });
370
+ /**
371
+ * The selected items in list order (not the order they were selected in), with their indices. Disabled items
372
+ * are left out, so no action carries them.
373
+ */
374
+ this.orderedSelection = computed(() => {
375
+ const indexes = this.#itemIndexes();
376
+ return this.selectedItems()
377
+ .toArray()
378
+ .filter(item => !this.#listService.isDataItemDisabled(item))
379
+ .map(item => ({ index: indexes.get(item) ?? -1, item }))
380
+ .filter(entry => entry.index >= 0)
381
+ .sort((a, b) => a.index - b.index);
382
+ }, /* @ts-ignore */
383
+ ...(ngDevMode ? [{ debugName: "orderedSelection" }] : /* istanbul ignore next */ []));
255
384
  this.selectableOptions = computed(() => {
256
385
  const enabled = true;
257
386
  const mode = this.selectionMode();
@@ -261,37 +390,123 @@ class ListBoxComponent {
261
390
  return { enabled, mode, toggleable: this.singleSelectionToggleable() };
262
391
  }, /* @ts-ignore */
263
392
  ...(ngDevMode ? [{ debugName: "selectableOptions" }] : /* istanbul ignore next */ []));
393
+ /** Indices of the selected items, in list order. */
394
+ this.selectedIndices = computed(() => this.orderedSelection().map(entry => entry.index), /* @ts-ignore */
395
+ ...(ngDevMode ? [{ debugName: "selectedIndices" }] : /* istanbul ignore next */ []));
396
+ /** The list box that holds the selection: this one, else the connected one, else none. */
397
+ this.selectionHolder = computed(() => {
398
+ if (this.orderedSelection().length > 0) {
399
+ return this;
400
+ }
401
+ const connectedList = this.connectedList();
402
+ return connectedList && connectedList.orderedSelection().length > 0 ? connectedList : null;
403
+ }, /* @ts-ignore */
404
+ ...(ngDevMode ? [{ debugName: "selectionHolder" }] : /* istanbul ignore next */ []));
405
+ /**
406
+ * The toolbar's buttons, in toolbar order. The transfer actions need a connected list box; the others work on a
407
+ * list box of its own.
408
+ */
409
+ this.toolbarButtons = computed(() => {
410
+ const options = this.toolbarOptions();
411
+ if (!options) {
412
+ return [];
413
+ }
414
+ const connectedList = this.connectedList();
415
+ const messages = this.messages();
416
+ const holder = this.selectionHolder();
417
+ const target = connectedList ? connectedList.#name() : "";
418
+ const enabled = {
419
+ clear: holder != null,
420
+ moveDown: this.canMoveDown(),
421
+ moveUp: this.canMoveUp(),
422
+ remove: holder != null,
423
+ transferAllFrom: (connectedList?.enabledItems().length ?? 0) > 0,
424
+ transferAllTo: this.enabledItems().length > 0,
425
+ transferFrom: (connectedList?.orderedSelection().length ?? 0) > 0,
426
+ transferTo: this.orderedSelection().length > 0
427
+ };
428
+ const labels = {
429
+ clear: messages.clearSelection,
430
+ moveDown: messages.moveDown,
431
+ moveUp: messages.moveUp,
432
+ remove: messages.remove,
433
+ transferAllFrom: target ? messages.transferAllFromList(target) : messages.transferAllFrom,
434
+ transferAllTo: target ? messages.transferAllToList(target) : messages.transferAllTo,
435
+ transferFrom: target ? messages.transferFromList(target) : messages.transferFrom,
436
+ transferTo: target ? messages.transferToList(target) : messages.transferTo
437
+ };
438
+ return TOOLBAR_ORDER.filter(action => options.actions.includes(action) && (connectedList != null || !TRANSFER_ACTIONS.has(action))).map(action => ({ action, enabled: enabled[action], label: labels[action] }));
439
+ }, /* @ts-ignore */
440
+ ...(ngDevMode ? [{ debugName: "toolbarButtons" }] : /* istanbul ignore next */ []));
264
441
  this.toolbarClasses = computed(() => {
265
- const toolbarOptions = this.toolbarOptions();
266
- const position = toolbarOptions?.position ?? "right";
267
- const direction = position === "left" || position === "right" ? "vertical" : "horizontal";
442
+ const direction = this.toolbarOrientation();
268
443
  return listBoxToolbarThemeVariants({ direction });
269
444
  }, /* @ts-ignore */
270
445
  ...(ngDevMode ? [{ debugName: "toolbarClasses" }] : /* istanbul ignore next */ []));
446
+ /** The toolbar's name: `toolbarAriaLabel`, else one built from the list box's name. */
447
+ this.toolbarLabel = computed(() => {
448
+ const label = this.toolbarAriaLabel().trim();
449
+ if (label) {
450
+ return label;
451
+ }
452
+ const list = this.#name();
453
+ return list ? this.messages().toolbarLabel(list) : null;
454
+ }, /* @ts-ignore */
455
+ ...(ngDevMode ? [{ debugName: "toolbarLabel" }] : /* istanbul ignore next */ []));
271
456
  this.toolbarOptions = computed(() => {
272
457
  const toolbar = this.toolbar();
273
458
  if (typeof toolbar === "boolean") {
274
- return toolbar ? this.getDefaultToolbarOptions() : null;
459
+ return toolbar ? { actions: [...DEFAULT_ACTIONS], position: "right" } : null;
275
460
  }
276
- return this.updateToolbarOptions(toolbar);
461
+ return {
462
+ actions: toolbar.actions ? [...toolbar.actions] : [...DEFAULT_ACTIONS],
463
+ position: toolbar.position ?? "right"
464
+ };
277
465
  }, /* @ts-ignore */
278
466
  ...(ngDevMode ? [{ debugName: "toolbarOptions" }] : /* istanbul ignore next */ []));
467
+ /** A toolbar beside the list stacks its buttons; one above or below lines them up. */
468
+ this.toolbarOrientation = computed(() => {
469
+ const position = this.toolbarOptions()?.position ?? "right";
470
+ return position === "left" || position === "right" ? "vertical" : "horizontal";
471
+ }, /* @ts-ignore */
472
+ ...(ngDevMode ? [{ debugName: "toolbarOrientation" }] : /* istanbul ignore next */ []));
473
+ /** The one enabled toolbar button in the Tab order; the arrow keys move between the others. */
474
+ this.toolbarTabStop = computed(() => {
475
+ const enabled = this.toolbarButtons().filter(button => button.enabled);
476
+ const focused = this.#toolbarFocus();
477
+ return (enabled.find(button => button.action === focused) ?? enabled[0])?.action ?? null;
478
+ }, /* @ts-ignore */
479
+ ...(ngDevMode ? [{ debugName: "toolbarTabStop" }] : /* istanbul ignore next */ []));
279
480
  /**
280
481
  * @description Emitted when a toolbar action button is clicked, carrying the action's details.
281
482
  */
282
483
  this.actionClick = output();
283
484
  /**
284
485
  * @description Accessible name for the list box's `listbox` element. Describe what the list represents,
285
- * which matters in particular when connecting two list boxes.
486
+ * which matters in particular when connecting two list boxes: the toolbar's name and the transfer buttons'
487
+ * labels are built from it.
286
488
  * @default ""
287
489
  */
288
490
  this.ariaLabel = input("", { ...(ngDevMode ? { debugName: "ariaLabel" } : /* istanbul ignore next */ {}), alias: "aria-label" });
491
+ /**
492
+ * @description Id of the element that names the list box, as an alternative to `aria-label`. Without an
493
+ * `aria-label`, the toolbar's name and the transfer buttons' labels are built from that element's text.
494
+ * @default ""
495
+ */
496
+ this.ariaLabelledBy = input("", { ...(ngDevMode ? { debugName: "ariaLabelledBy" } : /* istanbul ignore next */ {}), alias: "aria-labelledby" });
289
497
  /**
290
498
  * @description The other list box to transfer items to and from using the toolbar actions.
291
499
  * @default null
292
500
  */
293
501
  this.connectedList = input(null, /* @ts-ignore */
294
502
  ...(ngDevMode ? [{ debugName: "connectedList" }] : /* istanbul ignore next */ []));
503
+ /**
504
+ * @description Property name or predicate that marks items as disabled. Disabled items can't be selected, and no
505
+ * action (including the "All" transfers) carries them.
506
+ * @default ""
507
+ */
508
+ this.disabledBy = input("", /* @ts-ignore */
509
+ ...(ngDevMode ? [{ debugName: "disabledBy" }] : /* istanbul ignore next */ []));
295
510
  /**
296
511
  * @description Sets the height of the component.
297
512
  * @default 100%
@@ -304,7 +519,8 @@ class ListBoxComponent {
304
519
  */
305
520
  this.items = input([], /* @ts-ignore */
306
521
  ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
307
- this.listBoxItems = signal(ImmutableList.create(), /* @ts-ignore */
522
+ /** The items, as rendered. Read-only: change `items` to change them. */
523
+ this.listBoxItems = computed(() => ImmutableList.create(this.items()), /* @ts-ignore */
308
524
  ...(ngDevMode ? [{ debugName: "listBoxItems" }] : /* istanbul ignore next */ []));
309
525
  /**
310
526
  * @description Border-radius preset applied to the component.
@@ -318,11 +534,13 @@ class ListBoxComponent {
318
534
  */
319
535
  this.selectBy = input("", /* @ts-ignore */
320
536
  ...(ngDevMode ? [{ debugName: "selectBy" }] : /* istanbul ignore next */ []));
537
+ /** The selected items, read-only. */
321
538
  this.selectedItems = computed(() => {
322
539
  const listItems = this.#listService.selectedListItems();
323
540
  return listItems.select(item => item.data).toImmutableSet();
324
541
  }, /* @ts-ignore */
325
542
  ...(ngDevMode ? [{ debugName: "selectedItems" }] : /* istanbul ignore next */ []));
543
+ /** @deprecated Use the `selectedItems` signal or the `selectionChange` output. */
326
544
  this.selectedItems$ = toObservable(this.selectedItems);
327
545
  /**
328
546
  * @description Keys of the currently selected items.
@@ -331,11 +549,13 @@ class ListBoxComponent {
331
549
  this.selectedKeys = input([], /* @ts-ignore */
332
550
  ...(ngDevMode ? [{ debugName: "selectedKeys" }] : /* istanbul ignore next */ []));
333
551
  /**
334
- * @description Emitted with the updated keys whenever the selection changes.
552
+ * @description Emitted with the updated keys whenever the user changes the selection, including when an
553
+ * action (transfer, clear, remove) or a selection in the connected list box changes it.
335
554
  */
336
555
  this.selectedKeysChange = output();
337
556
  /**
338
- * @description Emitted with the selected and deselected items whenever the selection changes.
557
+ * @description Emitted with the selected and deselected items whenever the user changes the selection, including
558
+ * when an action (transfer, clear, remove) or a selection in the connected list box changes it.
339
559
  */
340
560
  this.selectionChange = output();
341
561
  /**
@@ -346,11 +566,10 @@ class ListBoxComponent {
346
566
  ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
347
567
  /**
348
568
  * @description Allows an already-selected item to be deselected by clicking it again while `selectionMode`
349
- * is `"single"`. Has no effect when `selectionMode` is `"multiple"`.
569
+ * is `"single"`. Has no effect when `selectionMode` is `"multiple"`. Accepts the bare attribute form.
350
570
  * @default true
351
571
  */
352
- this.singleSelectionToggleable = input(true, /* @ts-ignore */
353
- ...(ngDevMode ? [{ debugName: "singleSelectionToggleable" }] : /* istanbul ignore next */ []));
572
+ this.singleSelectionToggleable = input(true, { ...(ngDevMode ? { debugName: "singleSelectionToggleable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
354
573
  /**
355
574
  * @description Size preset controlling the component's dimensions.
356
575
  * @default medium
@@ -365,11 +584,19 @@ class ListBoxComponent {
365
584
  ...(ngDevMode ? [{ debugName: "textField" }] : /* istanbul ignore next */ []));
366
585
  /**
367
586
  * @description Shows the action toolbar. Pass `false` to hide it entirely, or an options object to customize
368
- * which actions are shown and where the toolbar is positioned.
587
+ * which actions are shown and where the toolbar is positioned. The transfer actions appear only with a
588
+ * `connectedList`; the move, clear and remove actions work on a list box of its own. Accepts the bare attribute
589
+ * form.
369
590
  * @default true
370
591
  */
371
- this.toolbar = input(true, /* @ts-ignore */
372
- ...(ngDevMode ? [{ debugName: "toolbar" }] : /* istanbul ignore next */ []));
592
+ this.toolbar = input(true, { ...(ngDevMode ? { debugName: "toolbar" } : /* istanbul ignore next */ {}), transform: toToolbarSetting });
593
+ /**
594
+ * @description Accessible name for the toolbar. By default it is built from the list box's name
595
+ * ("Available foods actions").
596
+ * @default ""
597
+ */
598
+ this.toolbarAriaLabel = input("", /* @ts-ignore */
599
+ ...(ngDevMode ? [{ debugName: "toolbarAriaLabel" }] : /* istanbul ignore next */ []));
373
600
  /**
374
601
  * @description Sets the width of the component.
375
602
  * @default 100%
@@ -377,223 +604,383 @@ class ListBoxComponent {
377
604
  this.width = input("100%", /* @ts-ignore */
378
605
  ...(ngDevMode ? [{ debugName: "width" }] : /* istanbul ignore next */ []));
379
606
  effect(() => {
380
- const items = this.items();
381
- untracked(() => this.listBoxItems.set(ImmutableList.create(items)));
607
+ const selectBy = this.selectBy();
608
+ const keys = this.selectedKeys();
609
+ untracked(() => {
610
+ // Keys set from code are the new baseline; they aren't reported back as a user change.
611
+ this.#listService.setValueField(selectBy ?? "");
612
+ this.#listService.setSelectedKeys(keys ?? []);
613
+ this.#reported = new Map(Array.from(keys ?? [], key => [key, undefined]));
614
+ });
382
615
  });
383
616
  effect(onCleanup => {
384
617
  const connectedList = this.connectedList();
385
618
  if (!connectedList) {
386
619
  return;
387
620
  }
388
- const subscription = connectedList.selectionChange.subscribe(() => {
389
- untracked(() => this.clearSelections());
621
+ // The connected list box learns which list box transfers to it, for the shortcuts used in it.
622
+ untracked(() => connectedList.#owner.set(this));
623
+ onCleanup(() => {
624
+ if (untracked(connectedList.#owner) === this) {
625
+ connectedList.#owner.set(null);
626
+ }
390
627
  });
391
- onCleanup(() => subscription.unsubscribe());
392
- });
393
- afterNextRender({
394
- read: () => this.setSubscriptions()
395
628
  });
396
629
  }
397
630
  /**
398
- * @description Clears the current selection without emitting `selectionChange`. Call {@link notifySelectionChange}
399
- * afterward if the resulting selection change should be emitted.
631
+ * @description Clears the selection and reports the change through `selectionChange` and `selectedKeysChange`.
400
632
  */
401
633
  clearSelections() {
402
634
  this.#listService.clearSelections();
635
+ this.reportSelection();
403
636
  }
404
637
  /**
405
- * @description Emits `selectionChange` for any selection changes made since the last notification
406
- * (e.g., after programmatically calling {@link clearSelections}).
638
+ * @deprecated `clearSelections()` and the actions report selection changes themselves.
407
639
  */
408
640
  notifySelectionChange() {
409
- this.#notifySelectionChange$.next(true);
641
+ this.reportSelection();
642
+ }
643
+ onActionClick(action, event) {
644
+ const button = event.currentTarget instanceof HTMLButtonElement ? event.currentTarget : null;
645
+ this.runAction(action, event, button);
410
646
  }
411
- onClearClick(event) {
412
- const listBox = this.activeListBox();
413
- if (!listBox) {
647
+ /**
648
+ * Keyboard shortcuts on an option: Alt+ArrowUp and Alt+ArrowDown move the selection, Delete removes it, and
649
+ * Alt+ArrowRight and Alt+ArrowLeft (mirrored in RTL) transfer it to and from the connected list box. Each runs
650
+ * only when the toolbar offers that action and the selection is in this list box.
651
+ */
652
+ onHostKeydown(event) {
653
+ if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.shiftKey || !this.isOwnOption(event)) {
414
654
  return;
415
655
  }
416
- const selectedItems = listBox.selectedItems();
417
- if (selectedItems.none()) {
656
+ const shortcut = this.resolveShortcut(event);
657
+ if (!shortcut) {
418
658
  return;
419
659
  }
420
- const clearEvent = new ListBoxClearEvent(selectedItems, event);
421
- listBox.actionClick.emit(clearEvent);
422
- if (!clearEvent.isDefaultPrevented()) {
423
- listBox.clearSelections();
424
- listBox.notifySelectionChange();
425
- this.connectedList()?.clearSelections();
426
- this.connectedList()?.notifySelectionChange();
660
+ const { action, controller } = shortcut;
661
+ const button = controller.toolbarButtons().find(candidate => candidate.action === action);
662
+ if (!button?.enabled || controller.selectionHolder() !== this) {
663
+ return;
664
+ }
665
+ event.preventDefault();
666
+ controller.runAction(action, event, null);
667
+ }
668
+ onSelectedKeysChange() {
669
+ this.reportSelection();
670
+ }
671
+ onToolbarFocusIn(event) {
672
+ const action = this.toolbarActionOf(event.target);
673
+ if (action) {
674
+ this.#toolbarFocus.set(action);
427
675
  }
428
676
  }
429
- onMoveClick(direction, event) {
430
- const activeListBox = this.getSelectedListBox();
431
- if (!activeListBox) {
677
+ /** Arrow keys move between the toolbar's enabled buttons (wrapping), Home and End go to the first and last. */
678
+ onToolbarKeydown(event) {
679
+ if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
432
680
  return;
433
681
  }
434
- const selectedItems = activeListBox.selectedItems();
435
- if (selectedItems.none()) {
436
- const moveEvent = new ListBoxMoveEvent(direction, [], [], -1, -1, event);
437
- activeListBox.actionClick.emit(moveEvent);
682
+ const buttons = this.toolbarButtons().filter(button => button.enabled);
683
+ if (buttons.length === 0) {
438
684
  return;
439
685
  }
440
- const listBoxItems = activeListBox.listBoxItems();
441
- const startIndex = listBoxItems.indexOf(selectedItems.elementAt(0));
442
- const endIndex = listBoxItems.indexOf(selectedItems.elementAt(selectedItems.length - 1));
443
- let newMoveIndex;
444
- if (direction === "moveDown") {
445
- if (endIndex >= listBoxItems.length - 1) {
446
- return;
447
- }
448
- newMoveIndex = endIndex + 1;
686
+ const vertical = this.toolbarOrientation() === "vertical";
687
+ const rtl = this.#direction() === "rtl";
688
+ const nextKey = vertical ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
689
+ const previousKey = vertical ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
690
+ const current = Math.max(0, buttons.findIndex(button => button.action === this.toolbarTabStop()));
691
+ let index;
692
+ if (event.key === nextKey) {
693
+ index = (current + 1) % buttons.length;
694
+ }
695
+ else if (event.key === previousKey) {
696
+ index = (current - 1 + buttons.length) % buttons.length;
697
+ }
698
+ else if (event.key === "Home") {
699
+ index = 0;
700
+ }
701
+ else if (event.key === "End") {
702
+ index = buttons.length - 1;
449
703
  }
450
704
  else {
451
- if (startIndex <= 0) {
452
- return;
705
+ return;
706
+ }
707
+ event.preventDefault();
708
+ this.focusToolbarButton(buttons[index].action);
709
+ }
710
+ /**
711
+ * Runs once the consumer's data change has rendered: announces the result and moves focus to what the action
712
+ * acted on when a shortcut ran it, or when its button is now disabled (focus would otherwise drop to the page).
713
+ */
714
+ afterActionRender(button, outcome) {
715
+ afterNextRender({
716
+ write: () => {
717
+ const { announcement, focus } = outcome();
718
+ if (announcement) {
719
+ void this.#liveAnnouncer.announce(announcement, "polite");
720
+ }
721
+ const active = this.#hostElementRef.nativeElement.ownerDocument.activeElement;
722
+ const focusLost = active == null || active === active.ownerDocument.body;
723
+ if (button == null || button.disabled || focusLost) {
724
+ focus();
725
+ }
453
726
  }
454
- newMoveIndex = startIndex - 1;
727
+ }, { injector: this.#injector });
728
+ }
729
+ clear(event, button) {
730
+ const holder = this.selectionHolder();
731
+ if (!holder) {
732
+ return;
455
733
  }
456
- const selectedIndices = selectedItems.select(item => listBoxItems.indexOf(item)).toArray();
457
- const moveEvent = new ListBoxMoveEvent(direction, selectedItems, selectedIndices, startIndex, newMoveIndex, event);
458
- activeListBox.actionClick.emit(moveEvent);
459
- if (!moveEvent.isDefaultPrevented()) {
460
- activeListBox.scrollToSelectedItem();
734
+ const selection = holder.orderedSelection();
735
+ const clearEvent = new ListBoxClearEvent(selection.map(entry => entry.item), event);
736
+ holder.actionClick.emit(clearEvent);
737
+ if (clearEvent.isDefaultPrevented()) {
738
+ return;
461
739
  }
740
+ this.clearSelections();
741
+ this.connectedList()?.clearSelections();
742
+ this.afterActionRender(button, () => ({
743
+ announcement: this.messages().selectionCleared,
744
+ focus: () => holder.revealItem(selection[0]?.item, true)
745
+ }));
746
+ }
747
+ findItemByKey(key) {
748
+ return (this.listBoxItems().firstOrDefault(item => this.#listService.getDataItemValue(item) === key) ?? undefined);
749
+ }
750
+ focusToolbarButton(action) {
751
+ this.#toolbarFocus.set(action);
752
+ const button = this.#hostElementRef.nativeElement.querySelector(`[role='toolbar'] button[data-action='${action}']`);
753
+ button?.focus();
462
754
  }
463
- onRemoveClick(event) {
464
- const listBox = this.activeListBox();
465
- if (!listBox) {
755
+ /** Whether a key event comes from one of this list box's own options (not a control in a template). */
756
+ isOwnOption(event) {
757
+ const target = event.target;
758
+ return (target instanceof HTMLElement &&
759
+ target.hasAttribute("data-uid") &&
760
+ target.closest("mona-list-box") === this.#hostElementRef.nativeElement);
761
+ }
762
+ move(direction, event, button) {
763
+ const holder = this.selectionHolder();
764
+ if (!holder || (direction === "moveUp" ? !this.canMoveUp() : !this.canMoveDown())) {
466
765
  return;
467
766
  }
468
- const selectedItems = listBox.selectedItems();
469
- if (selectedItems.none()) {
767
+ const selection = holder.orderedSelection();
768
+ const indices = selection.map(entry => entry.index);
769
+ const startIndex = indices[0];
770
+ const newIndex = direction === "moveDown" ? indices[indices.length - 1] + 1 : startIndex - 1;
771
+ const items = selection.map(entry => entry.item);
772
+ // A shortcut keeps focus on the option it was pressed on; a button moves it to the first moved item.
773
+ const highlighted = holder.#listService.highlightedItem()?.data;
774
+ const focusItem = highlighted !== undefined && items.includes(highlighted) ? highlighted : items[0];
775
+ const moveEvent = new ListBoxMoveEvent(direction, items, indices, startIndex, newIndex, event);
776
+ holder.actionClick.emit(moveEvent);
777
+ if (moveEvent.isDefaultPrevented()) {
470
778
  return;
471
779
  }
472
- const removeEvent = new ListBoxRemoveEvent(selectedItems, event);
473
- listBox.actionClick.emit(removeEvent);
474
- if (!removeEvent.isDefaultPrevented()) {
475
- listBox.scrollToSelectedItem();
476
- this.#dataStateChange$.next();
780
+ this.afterActionRender(button, () => {
781
+ const first = holder.selectedIndices()[0];
782
+ holder.revealItem(holder.orderedSelection()[0]?.item, false);
783
+ return {
784
+ announcement: first !== undefined && first !== startIndex
785
+ ? this.messages().itemsMoved(first + 1, holder.listBoxItems().size())
786
+ : null,
787
+ focus: () => holder.revealItem(focusItem, true)
788
+ };
789
+ });
790
+ }
791
+ remove(event, button) {
792
+ const holder = this.selectionHolder();
793
+ if (!holder) {
794
+ return;
477
795
  }
796
+ const selection = holder.orderedSelection();
797
+ const removeEvent = new ListBoxRemoveEvent(selection.map(entry => entry.item), event);
798
+ holder.actionClick.emit(removeEvent);
799
+ if (removeEvent.isDefaultPrevented()) {
800
+ return;
801
+ }
802
+ const keys = selection.map(entry => holder.#listService.getDataItemValue(entry.item));
803
+ const firstIndex = selection[0].index;
804
+ holder.clearSelections();
805
+ this.afterActionRender(button, () => {
806
+ const remaining = new Set(holder.listBoxItems().select(item => holder.#listService.getDataItemValue(item)));
807
+ const removed = keys.filter(key => !remaining.has(key)).length;
808
+ const enabledItems = holder.enabledItems();
809
+ // The item now at the first removed one's position, or the last one.
810
+ const neighbour = enabledItems.find(item => (holder.#itemIndexes().get(item) ?? -1) >= firstIndex);
811
+ return {
812
+ announcement: removed > 0 ? this.messages().itemsRemoved(removed) : null,
813
+ focus: () => holder.revealItem(neighbour ?? enabledItems[enabledItems.length - 1], true)
814
+ };
815
+ });
478
816
  }
479
- onSelectedKeysChange(keys) {
817
+ /**
818
+ * Emits `selectionChange` and `selectedKeysChange` when the selected keys differ from the ones last reported. A
819
+ * new selection clears the connected list box's, as only one side holds a selection.
820
+ */
821
+ reportSelection() {
822
+ const keys = this.#listService.selectedKeys().toArray();
823
+ const current = new Map();
824
+ for (const listItem of this.#listService.selectedListItems()) {
825
+ current.set(this.#listService.getDataItemValue(listItem.data), listItem.data);
826
+ }
827
+ for (const key of keys) {
828
+ if (!current.has(key)) {
829
+ current.set(key, undefined);
830
+ }
831
+ }
832
+ const previous = this.#reported;
833
+ const selectedItems = [...current]
834
+ .filter(([key]) => !previous.has(key))
835
+ .map(([, item]) => item)
836
+ .filter((item) => item !== undefined);
837
+ const deselectedItems = [...previous]
838
+ .filter(([key]) => !current.has(key))
839
+ .map(([key, item]) => item ?? this.findItemByKey(key))
840
+ .filter((item) => item !== undefined);
841
+ const changed = keys.length !== previous.size || keys.some(key => !previous.has(key));
842
+ this.#reported = current;
843
+ if (!changed) {
844
+ return;
845
+ }
846
+ this.selectionChange.emit({ deselectedItems, selectedItems });
480
847
  this.selectedKeysChange.emit(keys);
481
- this.connectedList()?.clearSelections();
482
- this.#notifySelectionChange$.next(true);
848
+ if (selectedItems.length > 0) {
849
+ this.connectedList()?.clearSelections();
850
+ this.#owner()?.clearSelections();
851
+ }
483
852
  }
484
- onTransferClick(action, event) {
485
- const connectedList = this.connectedList();
486
- if (!connectedList) {
487
- return;
853
+ /**
854
+ * The action a shortcut runs and the list box whose toolbar runs it. Transfers go towards the connected list
855
+ * box, which follows this one in reading order: Alt+ArrowRight (Alt+ArrowLeft in RTL) from this list box,
856
+ * Alt+ArrowLeft (Alt+ArrowRight in RTL) back from the connected one.
857
+ */
858
+ resolveShortcut(event) {
859
+ const toolbarHolder = this.toolbarOptions() ? this : this.#owner();
860
+ if (event.key === "Delete" && !event.altKey) {
861
+ return toolbarHolder ? { action: "remove", controller: toolbarHolder } : null;
488
862
  }
489
- const sourceList = this.activeListBox();
490
- const targetList = this.activeListBox() === connectedList ? this : connectedList;
491
- if (!sourceList || !targetList) {
492
- return;
863
+ if (!event.altKey) {
864
+ return null;
493
865
  }
494
- const selectedItems = sourceList.selectedItems();
495
- const transferEvent = new ListBoxTransferEvent(action, selectedItems, event);
496
- if (action === "transferFrom" || action === "transferAllFrom") {
497
- connectedList.actionClick.emit(transferEvent);
866
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") {
867
+ const action = event.key === "ArrowUp" ? "moveUp" : "moveDown";
868
+ return toolbarHolder ? { action, controller: toolbarHolder } : null;
498
869
  }
499
- else {
500
- sourceList.actionClick.emit(transferEvent);
870
+ if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") {
871
+ return null;
501
872
  }
502
- if (!transferEvent.isDefaultPrevented()) {
503
- sourceList.clearSelections();
504
- targetList.clearSelections();
505
- targetList.scrollToSelectedItem();
506
- this.#dataStateChange$.next();
873
+ const forward = (event.key === "ArrowRight") !== (this.#direction() === "rtl");
874
+ if (forward) {
875
+ return this.connectedList() ? { action: "transferTo", controller: this } : null;
507
876
  }
877
+ const owner = this.#owner();
878
+ return owner ? { action: "transferFrom", controller: owner } : null;
508
879
  }
509
- createSelectedChangeNotifier() {
510
- return this.selectedItems$.pipe(sample(this.#notifySelectionChange$.pipe(delay(0), filter(e => e), tap(() => this.#notifySelectionChange$.next(false)))), scan((previous, current) => {
511
- const selectedItems = current.where(i => !previous.contains(i)).toArray();
512
- const deselectedItems = previous.where(i => !current.contains(i)).toArray();
513
- if (selectedItems.length > 0 || deselectedItems.length > 0) {
514
- this.activeListBox()?.selectionChange.emit({ selectedItems, deselectedItems });
880
+ /** Scrolls an item into view, and focuses it, or the list when the item isn't there. */
881
+ revealItem(dataItem, focus) {
882
+ const key = dataItem === undefined ? undefined : this.#listService.getDataItemValue(dataItem);
883
+ const listItem = dataItem === undefined
884
+ ? null
885
+ : this.#listService
886
+ .viewItems()
887
+ .firstOrDefault(item => !item.isHeader && this.#listService.getDataItemValue(item.data) === key);
888
+ if (listItem) {
889
+ if (focus) {
890
+ this.#listService.highlightedItem.set(listItem);
515
891
  }
516
- return current;
517
- }, this.selectedItems()));
892
+ this.#listService.scrollToItem(listItem, focus);
893
+ }
894
+ else if (focus) {
895
+ this.#listService.focus$.next();
896
+ }
897
+ }
898
+ runAction(action, event, button) {
899
+ switch (action) {
900
+ case "clear":
901
+ this.clear(event, button);
902
+ break;
903
+ case "moveDown":
904
+ case "moveUp":
905
+ this.move(action, event, button);
906
+ break;
907
+ case "remove":
908
+ this.remove(event, button);
909
+ break;
910
+ default:
911
+ this.transfer(action, event, button);
912
+ }
913
+ }
914
+ /** Selects the items a transfer brought into this list box: all of them, or the first in single mode. */
915
+ selectTransferredItems(items) {
916
+ const selected = this.selectionMode() === "multiple" ? items : items.slice(0, 1);
917
+ this.#listService.setSelectedKeys(selected.map(item => this.#listService.getDataItemValue(item)));
918
+ this.reportSelection();
919
+ }
920
+ toolbarActionOf(target) {
921
+ if (!(target instanceof HTMLElement)) {
922
+ return null;
923
+ }
924
+ const action = target.closest("button[data-action]")?.getAttribute("data-action");
925
+ return TOOLBAR_ORDER.find(candidate => candidate === action) ?? null;
518
926
  }
519
927
  /**
520
- * The list box (`this` or the connected list box, recursively) that currently has a real selection
521
- * or `null` if neither side has one. Unlike {@link activeListBox}, this does not fall back to `this`,
522
- * since move actions need to know an actual selected index to operate on.
928
+ * "To" actions move items from this list box to the connected one, "From" actions from the connected one to
929
+ * this one. The event fires on the source list box and carries the items to move: the selection, or every enabled
930
+ * item for the "All" actions. Once the consumer has moved them, they are selected in the target.
523
931
  */
524
- getDefaultToolbarOptions() {
525
- return {
526
- actions: [
527
- "clear",
528
- "moveDown",
529
- "moveUp",
530
- "remove",
531
- "transferAllFrom",
532
- "transferAllTo",
533
- "transferFrom",
534
- "transferTo"
535
- ],
536
- position: "right"
537
- };
538
- }
539
- getSelectedListBox() {
540
- if (this.selectedItems().any()) {
541
- return this;
542
- }
543
- if (this.connectedList() != null) {
544
- return this.connectedList().getSelectedListBox();
545
- }
546
- return null;
547
- }
548
- scrollToSelectedItem() {
549
- const selectedItemElement = this.#hostElementRef.nativeElement.querySelector("[data-selected='true']");
550
- if (selectedItemElement) {
551
- selectedItemElement.scrollIntoView({ behavior: "auto", block: "center" });
552
- }
553
- }
554
- setSubscriptions() {
555
- this.#dataStateChange$
556
- .pipe(takeUntilDestroyed(this.#destroyRef), startWith(null), switchMap(() => this.createSelectedChangeNotifier()))
557
- .subscribe();
558
- }
559
- updateToolbarOptions(options) {
560
- if (typeof options === "boolean") {
561
- return options ? this.getDefaultToolbarOptions() : null;
562
- }
563
- const position = options.position ?? "right";
564
- let actions;
565
- if (options.actions && options.actions.length > 0) {
566
- actions = options.actions;
567
- }
568
- else if (options.actions && options.actions.length === 0) {
569
- actions = [];
932
+ transfer(action, event, button) {
933
+ const connectedList = this.connectedList();
934
+ if (!connectedList) {
935
+ return;
570
936
  }
571
- else {
572
- actions = [
573
- "clear",
574
- "moveDown",
575
- "moveUp",
576
- "remove",
577
- "transferAllFrom",
578
- "transferAllTo",
579
- "transferFrom",
580
- "transferTo"
581
- ];
582
- }
583
- return { actions, position };
937
+ const toConnected = action === "transferTo" || action === "transferAllTo";
938
+ const source = toConnected ? this : connectedList;
939
+ const target = toConnected ? connectedList : this;
940
+ const all = action === "transferAllTo" || action === "transferAllFrom";
941
+ const items = all ? source.enabledItems() : source.orderedSelection().map(entry => entry.item);
942
+ if (items.length === 0) {
943
+ return;
944
+ }
945
+ const transferEvent = new ListBoxTransferEvent(action, items, event);
946
+ source.actionClick.emit(transferEvent);
947
+ if (transferEvent.isDefaultPrevented()) {
948
+ return;
949
+ }
950
+ source.clearSelections();
951
+ target.clearSelections();
952
+ const keys = new Set(items.map(item => target.#listService.getDataItemValue(item)));
953
+ this.afterActionRender(button, () => {
954
+ const arrived = target
955
+ .listBoxItems()
956
+ .where(item => keys.has(target.#listService.getDataItemValue(item)))
957
+ .toArray();
958
+ if (arrived.length > 0) {
959
+ target.selectTransferredItems(arrived);
960
+ target.revealItem(arrived[0], false);
961
+ }
962
+ const name = target.#name();
963
+ const messages = this.messages();
964
+ let announcement = null;
965
+ if (arrived.length > 0) {
966
+ announcement = name
967
+ ? messages.itemsTransferred(arrived.length, name)
968
+ : messages.itemsTransferredToOtherList(arrived.length);
969
+ }
970
+ return { announcement, focus: () => target.revealItem(arrived[0], true) };
971
+ });
584
972
  }
585
973
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ListBoxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
586
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: ListBoxComponent, isStandalone: true, selector: "mona-list-box", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, connectedList: { classPropertyName: "connectedList", publicName: "connectedList", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selectBy: { classPropertyName: "selectBy", publicName: "selectBy", isSignal: true, isRequired: false, transformFunction: null }, selectedKeys: { classPropertyName: "selectedKeys", publicName: "selectedKeys", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, singleSelectionToggleable: { classPropertyName: "singleSelectionToggleable", publicName: "singleSelectionToggleable", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, textField: { classPropertyName: "textField", publicName: "textField", isSignal: true, isRequired: false, transformFunction: null }, toolbar: { classPropertyName: "toolbar", publicName: "toolbar", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { actionClick: "actionClick", selectedKeysChange: "selectedKeysChange", selectionChange: "selectionChange" }, host: { properties: { "class": "baseClasses()", "style.height": "listHeight()", "style.width": "listWidth()" } }, providers: [ListService], queries: [{ propertyName: "footerTemplate", first: true, predicate: ListBoxFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "headerTemplate", first: true, predicate: ListBoxHeaderTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "itemTemplate", first: true, predicate: ListBoxItemTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "noDataTemplate", first: true, predicate: ListBoxNoDataTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<mona-list-view\n [ariaLabel]=\"ariaLabel()\"\n [items]=\"listBoxItems()\"\n [height]=\"'100%'\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [textField]=\"textField()\"\n [width]=\"'100%'\"\n [monaListViewNavigable]=\"{ enabled: true, mode: 'select' }\"\n [monaListViewSelectable]=\"selectableOptions()\"\n [selectBy]=\"selectBy()\"\n [selectedKeys]=\"selectedKeys()\"\n (selectedKeysChange)=\"onSelectedKeysChange($event)\">\n @if (footerTemplate()) {\n <ng-template monaListViewFooterTemplate>\n <ng-container [ngTemplateOutlet]=\"footerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (headerTemplate()) {\n <ng-template monaListViewHeaderTemplate>\n <ng-container [ngTemplateOutlet]=\"headerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (itemTemplate()) {\n <ng-template monaListViewItemTemplate let-dataItem>\n <ng-container\n [ngTemplateOutlet]=\"itemTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: dataItem }\"></ng-container>\n </ng-template>\n }\n @if (noDataTemplate()) {\n <ng-template monaListViewNoDataTemplate>\n <ng-container [ngTemplateOutlet]=\"noDataTemplate()\"></ng-container>\n </ng-template>\n }\n</mona-list-view>\n\n@let options = toolbarOptions() ?? null;\n@let connectedListBox = connectedList();\n@let hasSelectedItems = selectedItems().length > 0;\n@let connectedListHasSelectedItems = connectedListBox && connectedListBox.selectedItems().length > 0;\n@let connectedListItems = connectedListBox?.listBoxItems() ?? [];\n@if (options !== null && connectedListBox !== null) {\n <div [class]=\"toolbarClasses()\">\n @if (options.actions | monaContains: \"moveUp\") {\n <button\n monaButton\n (click)=\"onMoveClick('moveUp', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().moveUp\"\n [attr.aria-label]=\"messages().moveUp\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideChevronUp [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"moveDown\") {\n <button\n monaButton\n (click)=\"onMoveClick('moveDown', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().moveDown\"\n [attr.aria-label]=\"messages().moveDown\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideChevronDown [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferFrom\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferFrom', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferFrom\"\n [attr.aria-label]=\"messages().transferFrom\"\n [disabled]=\"!connectedListHasSelectedItems\">\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferTo\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferTo', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferTo\"\n [attr.aria-label]=\"messages().transferTo\"\n [disabled]=\"!hasSelectedItems\">\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferAllFrom\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferAllFrom', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferAllFrom\"\n [attr.aria-label]=\"messages().transferAllFrom\"\n [disabled]=\"!connectedListBox || connectedListItems.length === 0\">\n <svg lucideChevronsLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferAllTo\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferAllTo', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferAllTo\"\n [attr.aria-label]=\"messages().transferAllTo\"\n [disabled]=\"listBoxItems().length === 0\">\n <svg lucideChevronsRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"clear\") {\n <button\n monaButton\n (click)=\"onClearClick($event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().clearSelection\"\n [attr.aria-label]=\"messages().clearSelection\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"remove\") {\n <button\n monaButton\n (click)=\"onRemoveClick($event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().remove\"\n [attr.aria-label]=\"messages().remove\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideTrash2 [size]=\"14\"></svg>\n </button>\n }\n </div>\n}\n", dependencies: [{ kind: "component", type: ListViewComponent, selector: "mona-list-view", inputs: ["aria-label", "height", "items", "listClass", "listItemClass", "listItemStyle", "listStyle", "maxHeight", "maxWidth", "rounded", "size", "textField", "class", "width"], outputs: ["scrollBottom"] }, { kind: "directive", type: ListViewSelectableDirective, selector: "mona-list-view[monaListViewSelectable]", inputs: ["monaListViewSelectable", "selectBy", "selectedKeys"], outputs: ["selectedKeysChange"] }, { kind: "directive", type: ListViewItemTemplateDirective, selector: "ng-template[monaListViewItemTemplate]" }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: ListViewNavigableDirective, selector: "mona-list-view[monaListViewNavigable]", inputs: ["monaListViewNavigable"] }, { kind: "directive", type: ListViewNoDataTemplateDirective, selector: "ng-template[monaListViewNoDataTemplate]" }, { kind: "directive", type: ListViewFooterTemplateDirective, selector: "ng-template[monaListViewFooterTemplate]" }, { kind: "directive", type: ListViewHeaderTemplateDirective, selector: "ng-template[monaListViewHeaderTemplate]" }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronLeft, selector: "svg[lucideChevronLeft]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideChevronsLeft, selector: "svg[lucideChevronsLeft]" }, { kind: "component", type: LucideChevronsRight, selector: "svg[lucideChevronsRight]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }, { kind: "component", type: LucideTrash2, selector: "svg[lucideTrash2]" }, { kind: "pipe", type: ContainsPipe, name: "monaContains" }] }); }
974
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: ListBoxComponent, isStandalone: true, selector: "mona-list-box", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "aria-label", isSignal: true, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "aria-labelledby", isSignal: true, isRequired: false, transformFunction: null }, connectedList: { classPropertyName: "connectedList", publicName: "connectedList", isSignal: true, isRequired: false, transformFunction: null }, disabledBy: { classPropertyName: "disabledBy", publicName: "disabledBy", isSignal: true, isRequired: false, transformFunction: null }, height: { classPropertyName: "height", publicName: "height", isSignal: true, isRequired: false, transformFunction: null }, items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, rounded: { classPropertyName: "rounded", publicName: "rounded", isSignal: true, isRequired: false, transformFunction: null }, selectBy: { classPropertyName: "selectBy", publicName: "selectBy", isSignal: true, isRequired: false, transformFunction: null }, selectedKeys: { classPropertyName: "selectedKeys", publicName: "selectedKeys", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, singleSelectionToggleable: { classPropertyName: "singleSelectionToggleable", publicName: "singleSelectionToggleable", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, textField: { classPropertyName: "textField", publicName: "textField", isSignal: true, isRequired: false, transformFunction: null }, toolbar: { classPropertyName: "toolbar", publicName: "toolbar", isSignal: true, isRequired: false, transformFunction: null }, toolbarAriaLabel: { classPropertyName: "toolbarAriaLabel", publicName: "toolbarAriaLabel", isSignal: true, isRequired: false, transformFunction: null }, width: { classPropertyName: "width", publicName: "width", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { actionClick: "actionClick", selectedKeysChange: "selectedKeysChange", selectionChange: "selectionChange" }, host: { listeners: { "keydown": "onHostKeydown($event)" }, properties: { "attr.aria-label": "null", "class": "baseClasses()", "style.height": "listHeight()", "style.width": "listWidth()" } }, providers: [ListService], queries: [{ propertyName: "footerTemplate", first: true, predicate: ListBoxFooterTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "headerTemplate", first: true, predicate: ListBoxHeaderTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "itemTemplate", first: true, predicate: ListBoxItemTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }, { propertyName: "noDataTemplate", first: true, predicate: ListBoxNoDataTemplateDirective, descendants: true, read: TemplateRef, isSignal: true }], ngImport: i0, template: "<mona-list-view\n [aria-label]=\"ariaLabel()\"\n [aria-labelledby]=\"ariaLabelledBy()\"\n [items]=\"listBoxItems()\"\n [height]=\"'100%'\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [textField]=\"textField()\"\n [width]=\"'100%'\"\n [disabledBy]=\"disabledBy()\"\n [monaListViewNavigable]=\"{ enabled: true, mode: 'select' }\"\n [monaListViewSelectable]=\"selectableOptions()\"\n [selectBy]=\"selectBy()\"\n [selectedKeys]=\"selectedKeys()\"\n (selectedKeysChange)=\"onSelectedKeysChange()\">\n @if (footerTemplate()) {\n <ng-template monaListViewFooterTemplate>\n <ng-container [ngTemplateOutlet]=\"footerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (headerTemplate()) {\n <ng-template monaListViewHeaderTemplate>\n <ng-container [ngTemplateOutlet]=\"headerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (itemTemplate()) {\n <ng-template monaListViewItemTemplate let-dataItem>\n <ng-container\n [ngTemplateOutlet]=\"itemTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: dataItem }\"></ng-container>\n </ng-template>\n }\n @if (noDataTemplate()) {\n <ng-template monaListViewNoDataTemplate>\n <ng-container [ngTemplateOutlet]=\"noDataTemplate()\"></ng-container>\n </ng-template>\n }\n</mona-list-view>\n\n@let buttons = toolbarButtons();\n@if (buttons.length > 0) {\n @let tabStop = toolbarTabStop();\n <div\n role=\"toolbar\"\n [attr.aria-label]=\"toolbarLabel()\"\n [attr.aria-orientation]=\"toolbarOrientation()\"\n [class]=\"toolbarClasses()\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\">\n @for (button of buttons; track button.action) {\n <button\n monaButton\n type=\"button\"\n [attr.data-action]=\"button.action\"\n (click)=\"onActionClick(button.action, $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"button.label\"\n [attr.aria-label]=\"button.label\"\n [disabled]=\"!button.enabled\"\n [tabindex]=\"tabStop === button.action ? 0 : -1\">\n @switch (button.action) {\n @case (\"moveUp\") {\n <svg lucideChevronUp [size]=\"16\"></svg>\n }\n @case (\"moveDown\") {\n <svg lucideChevronDown [size]=\"16\"></svg>\n }\n @case (\"transferFrom\") {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferTo\") {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferAllFrom\") {\n <svg lucideChevronsLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferAllTo\") {\n <svg lucideChevronsRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"clear\") {\n <svg lucideX [size]=\"16\"></svg>\n }\n @case (\"remove\") {\n <svg lucideTrash2 [size]=\"14\"></svg>\n }\n }\n </button>\n }\n </div>\n}\n", dependencies: [{ kind: "component", type: ListViewComponent, selector: "mona-list-view", inputs: ["aria-label", "aria-labelledby", "disabledBy", "height", "items", "listClass", "listItemClass", "listItemStyle", "listStyle", "loading", "maxHeight", "maxWidth", "pagerAriaLabel", "rounded", "size", "textField", "class", "width"], outputs: ["itemActivate", "scrollBottom"] }, { kind: "directive", type: ListViewSelectableDirective, selector: "mona-list-view[monaListViewSelectable]", inputs: ["monaListViewSelectable", "selectBy", "selectedKeys"], outputs: ["selectedKeysChange"] }, { kind: "directive", type: ListViewItemTemplateDirective, selector: "ng-template[monaListViewItemTemplate]", inputs: ["monaListViewItemTemplateOf"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: ButtonDirective, selector: "button[monaButton]", inputs: ["aria-haspopup", "disabled", "iconOnly", "loading", "look", "rounded", "selected", "size", "tabindex", "toggleable", "type", "class"], outputs: ["lookChange", "selectedChange"] }, { kind: "directive", type: ListViewNavigableDirective, selector: "mona-list-view[monaListViewNavigable]", inputs: ["monaListViewNavigable"] }, { kind: "directive", type: ListViewNoDataTemplateDirective, selector: "ng-template[monaListViewNoDataTemplate]" }, { kind: "directive", type: ListViewFooterTemplateDirective, selector: "ng-template[monaListViewFooterTemplate]" }, { kind: "directive", type: ListViewHeaderTemplateDirective, selector: "ng-template[monaListViewHeaderTemplate]" }, { kind: "component", type: LucideChevronUp, selector: "svg[lucideChevronUp]" }, { kind: "component", type: LucideChevronDown, selector: "svg[lucideChevronDown]" }, { kind: "component", type: LucideChevronLeft, selector: "svg[lucideChevronLeft]" }, { kind: "component", type: LucideChevronRight, selector: "svg[lucideChevronRight]" }, { kind: "component", type: LucideChevronsLeft, selector: "svg[lucideChevronsLeft]" }, { kind: "component", type: LucideChevronsRight, selector: "svg[lucideChevronsRight]" }, { kind: "component", type: LucideX, selector: "svg[lucideX]" }, { kind: "component", type: LucideTrash2, selector: "svg[lucideTrash2]" }], viewProviders: [{ provide: LIST_VIEW_HOST_LIST_SERVICE, useExisting: ListService }] }); }
587
975
  }
588
976
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: ListBoxComponent, decorators: [{
589
977
  type: Component,
590
- args: [{ selector: "mona-list-box", providers: [ListService], imports: [
978
+ args: [{ selector: "mona-list-box", providers: [ListService], viewProviders: [{ provide: LIST_VIEW_HOST_LIST_SERVICE, useExisting: ListService }], imports: [
591
979
  ListViewComponent,
592
980
  ListViewSelectableDirective,
593
981
  ListViewItemTemplateDirective,
594
982
  NgTemplateOutlet,
595
983
  ButtonDirective,
596
- ContainsPipe,
597
984
  ListViewNavigableDirective,
598
985
  ListViewNoDataTemplateDirective,
599
986
  ListViewFooterTemplateDirective,
@@ -607,11 +994,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImpor
607
994
  LucideX,
608
995
  LucideTrash2
609
996
  ], host: {
997
+ // The name belongs to the listbox inside; on the host it would be a name on a generic element.
998
+ "[attr.aria-label]": "null",
610
999
  "[class]": "baseClasses()",
611
1000
  "[style.height]": "listHeight()",
612
- "[style.width]": "listWidth()"
613
- }, template: "<mona-list-view\n [ariaLabel]=\"ariaLabel()\"\n [items]=\"listBoxItems()\"\n [height]=\"'100%'\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [textField]=\"textField()\"\n [width]=\"'100%'\"\n [monaListViewNavigable]=\"{ enabled: true, mode: 'select' }\"\n [monaListViewSelectable]=\"selectableOptions()\"\n [selectBy]=\"selectBy()\"\n [selectedKeys]=\"selectedKeys()\"\n (selectedKeysChange)=\"onSelectedKeysChange($event)\">\n @if (footerTemplate()) {\n <ng-template monaListViewFooterTemplate>\n <ng-container [ngTemplateOutlet]=\"footerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (headerTemplate()) {\n <ng-template monaListViewHeaderTemplate>\n <ng-container [ngTemplateOutlet]=\"headerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (itemTemplate()) {\n <ng-template monaListViewItemTemplate let-dataItem>\n <ng-container\n [ngTemplateOutlet]=\"itemTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: dataItem }\"></ng-container>\n </ng-template>\n }\n @if (noDataTemplate()) {\n <ng-template monaListViewNoDataTemplate>\n <ng-container [ngTemplateOutlet]=\"noDataTemplate()\"></ng-container>\n </ng-template>\n }\n</mona-list-view>\n\n@let options = toolbarOptions() ?? null;\n@let connectedListBox = connectedList();\n@let hasSelectedItems = selectedItems().length > 0;\n@let connectedListHasSelectedItems = connectedListBox && connectedListBox.selectedItems().length > 0;\n@let connectedListItems = connectedListBox?.listBoxItems() ?? [];\n@if (options !== null && connectedListBox !== null) {\n <div [class]=\"toolbarClasses()\">\n @if (options.actions | monaContains: \"moveUp\") {\n <button\n monaButton\n (click)=\"onMoveClick('moveUp', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().moveUp\"\n [attr.aria-label]=\"messages().moveUp\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideChevronUp [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"moveDown\") {\n <button\n monaButton\n (click)=\"onMoveClick('moveDown', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().moveDown\"\n [attr.aria-label]=\"messages().moveDown\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideChevronDown [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferFrom\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferFrom', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferFrom\"\n [attr.aria-label]=\"messages().transferFrom\"\n [disabled]=\"!connectedListHasSelectedItems\">\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferTo\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferTo', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferTo\"\n [attr.aria-label]=\"messages().transferTo\"\n [disabled]=\"!hasSelectedItems\">\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferAllFrom\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferAllFrom', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferAllFrom\"\n [attr.aria-label]=\"messages().transferAllFrom\"\n [disabled]=\"!connectedListBox || connectedListItems.length === 0\">\n <svg lucideChevronsLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"transferAllTo\") {\n <button\n monaButton\n (click)=\"onTransferClick('transferAllTo', $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().transferAllTo\"\n [attr.aria-label]=\"messages().transferAllTo\"\n [disabled]=\"listBoxItems().length === 0\">\n <svg lucideChevronsRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"clear\") {\n <button\n monaButton\n (click)=\"onClearClick($event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().clearSelection\"\n [attr.aria-label]=\"messages().clearSelection\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideX [size]=\"16\"></svg>\n </button>\n }\n @if (options.actions | monaContains: \"remove\") {\n <button\n monaButton\n (click)=\"onRemoveClick($event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"messages().remove\"\n [attr.aria-label]=\"messages().remove\"\n [disabled]=\"!hasSelectedItems && !connectedListHasSelectedItems\">\n <svg lucideTrash2 [size]=\"14\"></svg>\n </button>\n }\n </div>\n}\n" }]
614
- }], ctorParameters: () => [], propDecorators: { footerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], headerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxHeaderTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], itemTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxItemTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], noDataTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxNoDataTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], actionClick: [{ type: i0.Output, args: ["actionClick"] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], connectedList: [{ type: i0.Input, args: [{ isSignal: true, alias: "connectedList", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], selectBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectBy", required: false }] }], selectedKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedKeys", required: false }] }], selectedKeysChange: [{ type: i0.Output, args: ["selectedKeysChange"] }], selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], singleSelectionToggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "singleSelectionToggleable", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], textField: [{ type: i0.Input, args: [{ isSignal: true, alias: "textField", required: false }] }], toolbar: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolbar", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }] } });
1001
+ "[style.width]": "listWidth()",
1002
+ "(keydown)": "onHostKeydown($event)"
1003
+ }, template: "<mona-list-view\n [aria-label]=\"ariaLabel()\"\n [aria-labelledby]=\"ariaLabelledBy()\"\n [items]=\"listBoxItems()\"\n [height]=\"'100%'\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [textField]=\"textField()\"\n [width]=\"'100%'\"\n [disabledBy]=\"disabledBy()\"\n [monaListViewNavigable]=\"{ enabled: true, mode: 'select' }\"\n [monaListViewSelectable]=\"selectableOptions()\"\n [selectBy]=\"selectBy()\"\n [selectedKeys]=\"selectedKeys()\"\n (selectedKeysChange)=\"onSelectedKeysChange()\">\n @if (footerTemplate()) {\n <ng-template monaListViewFooterTemplate>\n <ng-container [ngTemplateOutlet]=\"footerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (headerTemplate()) {\n <ng-template monaListViewHeaderTemplate>\n <ng-container [ngTemplateOutlet]=\"headerTemplate()\"></ng-container>\n </ng-template>\n }\n @if (itemTemplate()) {\n <ng-template monaListViewItemTemplate let-dataItem>\n <ng-container\n [ngTemplateOutlet]=\"itemTemplate()\"\n [ngTemplateOutletContext]=\"{ $implicit: dataItem }\"></ng-container>\n </ng-template>\n }\n @if (noDataTemplate()) {\n <ng-template monaListViewNoDataTemplate>\n <ng-container [ngTemplateOutlet]=\"noDataTemplate()\"></ng-container>\n </ng-template>\n }\n</mona-list-view>\n\n@let buttons = toolbarButtons();\n@if (buttons.length > 0) {\n @let tabStop = toolbarTabStop();\n <div\n role=\"toolbar\"\n [attr.aria-label]=\"toolbarLabel()\"\n [attr.aria-orientation]=\"toolbarOrientation()\"\n [class]=\"toolbarClasses()\"\n (focusin)=\"onToolbarFocusIn($event)\"\n (keydown)=\"onToolbarKeydown($event)\">\n @for (button of buttons; track button.action) {\n <button\n monaButton\n type=\"button\"\n [attr.data-action]=\"button.action\"\n (click)=\"onActionClick(button.action, $event)\"\n [iconOnly]=\"true\"\n [rounded]=\"rounded()\"\n [size]=\"size()\"\n [title]=\"button.label\"\n [attr.aria-label]=\"button.label\"\n [disabled]=\"!button.enabled\"\n [tabindex]=\"tabStop === button.action ? 0 : -1\">\n @switch (button.action) {\n @case (\"moveUp\") {\n <svg lucideChevronUp [size]=\"16\"></svg>\n }\n @case (\"moveDown\") {\n <svg lucideChevronDown [size]=\"16\"></svg>\n }\n @case (\"transferFrom\") {\n <svg lucideChevronLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferTo\") {\n <svg lucideChevronRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferAllFrom\") {\n <svg lucideChevronsLeft [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"transferAllTo\") {\n <svg lucideChevronsRight [size]=\"16\" class=\"rtl:rotate-180\"></svg>\n }\n @case (\"clear\") {\n <svg lucideX [size]=\"16\"></svg>\n }\n @case (\"remove\") {\n <svg lucideTrash2 [size]=\"14\"></svg>\n }\n }\n </button>\n }\n </div>\n}\n" }]
1004
+ }], ctorParameters: () => [], propDecorators: { footerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxFooterTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], headerTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxHeaderTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], itemTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxItemTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], noDataTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => ListBoxNoDataTemplateDirective), { ...{ read: TemplateRef }, isSignal: true }] }], actionClick: [{ type: i0.Output, args: ["actionClick"] }], ariaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-label", required: false }] }], ariaLabelledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "aria-labelledby", required: false }] }], connectedList: [{ type: i0.Input, args: [{ isSignal: true, alias: "connectedList", required: false }] }], disabledBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabledBy", required: false }] }], height: [{ type: i0.Input, args: [{ isSignal: true, alias: "height", required: false }] }], items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], rounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "rounded", required: false }] }], selectBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectBy", required: false }] }], selectedKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedKeys", required: false }] }], selectedKeysChange: [{ type: i0.Output, args: ["selectedKeysChange"] }], selectionChange: [{ type: i0.Output, args: ["selectionChange"] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], singleSelectionToggleable: [{ type: i0.Input, args: [{ isSignal: true, alias: "singleSelectionToggleable", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], textField: [{ type: i0.Input, args: [{ isSignal: true, alias: "textField", required: false }] }], toolbar: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolbar", required: false }] }], toolbarAriaLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "toolbarAriaLabel", required: false }] }], width: [{ type: i0.Input, args: [{ isSignal: true, alias: "width", required: false }] }] } });
615
1005
 
616
1006
  /*
617
1007
  * Public API Surface of @nanahoshi/mona-ui/list-box