mn-angular-lib 1.0.178 → 1.0.180

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 (66) hide show
  1. package/fesm2022/mn-angular-lib-alert.mjs +535 -0
  2. package/fesm2022/mn-angular-lib-alert.mjs.map +1 -0
  3. package/fesm2022/mn-angular-lib-bottom-sheet.mjs +356 -0
  4. package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -0
  5. package/fesm2022/mn-angular-lib-button.mjs +382 -0
  6. package/fesm2022/mn-angular-lib-button.mjs.map +1 -0
  7. package/fesm2022/mn-angular-lib-calendar-core.mjs +377 -0
  8. package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -0
  9. package/fesm2022/mn-angular-lib-calendar.mjs +1513 -0
  10. package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -0
  11. package/fesm2022/mn-angular-lib-collection.mjs +2277 -0
  12. package/fesm2022/mn-angular-lib-collection.mjs.map +1 -0
  13. package/fesm2022/mn-angular-lib-core.mjs +1232 -0
  14. package/fesm2022/mn-angular-lib-core.mjs.map +1 -0
  15. package/fesm2022/mn-angular-lib-display.mjs +763 -0
  16. package/fesm2022/mn-angular-lib-display.mjs.map +1 -0
  17. package/fesm2022/mn-angular-lib-forms.mjs +4260 -0
  18. package/fesm2022/mn-angular-lib-forms.mjs.map +1 -0
  19. package/fesm2022/mn-angular-lib-keyboard.mjs +195 -0
  20. package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -0
  21. package/fesm2022/mn-angular-lib-modal-core.mjs +945 -0
  22. package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -0
  23. package/fesm2022/mn-angular-lib-modal-ui.mjs +2016 -0
  24. package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -0
  25. package/fesm2022/mn-angular-lib-modal.mjs +126 -0
  26. package/fesm2022/mn-angular-lib-modal.mjs.map +1 -0
  27. package/fesm2022/mn-angular-lib-rich-text-editor.mjs +275 -0
  28. package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -0
  29. package/fesm2022/mn-angular-lib-segmented.mjs +246 -0
  30. package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -0
  31. package/fesm2022/mn-angular-lib-tab.mjs +573 -0
  32. package/fesm2022/mn-angular-lib-tab.mjs.map +1 -0
  33. package/fesm2022/mn-angular-lib.mjs +21 -15517
  34. package/fesm2022/mn-angular-lib.mjs.map +1 -1
  35. package/package.json +66 -1
  36. package/src/lib/styles/index.css +2 -2
  37. package/types/mn-angular-lib-alert.d.ts +258 -0
  38. package/types/mn-angular-lib-bottom-sheet.d.ts +173 -0
  39. package/types/mn-angular-lib-button.d.ts +318 -0
  40. package/types/mn-angular-lib-calendar-core.d.ts +378 -0
  41. package/types/mn-angular-lib-calendar.d.ts +636 -0
  42. package/types/mn-angular-lib-collection.d.ts +1550 -0
  43. package/types/mn-angular-lib-core.d.ts +756 -0
  44. package/types/mn-angular-lib-display.d.ts +1147 -0
  45. package/types/mn-angular-lib-forms.d.ts +3235 -0
  46. package/types/mn-angular-lib-keyboard.d.ts +128 -0
  47. package/types/mn-angular-lib-modal-core.d.ts +1130 -0
  48. package/types/mn-angular-lib-modal-ui.d.ts +492 -0
  49. package/types/mn-angular-lib-modal.d.ts +27 -0
  50. package/types/mn-angular-lib-rich-text-editor.d.ts +157 -0
  51. package/types/mn-angular-lib-segmented.d.ts +395 -0
  52. package/types/mn-angular-lib-tab.d.ts +313 -0
  53. package/types/mn-angular-lib.d.ts +16 -10822
  54. /package/{src/lib/features → alert/src}/mn-alert/mn-alert-outlet/mn-alert-outlet.css +0 -0
  55. /package/{src/lib/features → bottom-sheet/src}/mn-bottom-sheet/mn-bottom-sheet.component.css +0 -0
  56. /package/{src/lib/features → button/src}/mn-skeleton/mn-skeleton.css +0 -0
  57. /package/{src/lib/features → collection/src}/mn-list/mn-list.component.css +0 -0
  58. /package/{src/lib/features → forms/src}/mn-checkbox/mn-checkbox.css +0 -0
  59. /package/{src/lib/features → forms/src}/mn-dropdown/mn-dropdown.css +0 -0
  60. /package/{src/lib/features → forms/src}/mn-multi-select/mn-multi-select.css +0 -0
  61. /package/{src/lib/features → keyboard/src}/mn-keyboard/mn-keyboard.component.css +0 -0
  62. /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-confirmation-body/mn-confirmation-body.component.css +0 -0
  63. /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-form-body/mn-form-body.component.css +0 -0
  64. /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-modal-shell/mn-modal-shell.component.css +0 -0
  65. /package/{src/lib/features → modal-ui/src}/mn-modal/components/mn-wizard-body/mn-wizard-body.component.css +0 -0
  66. /package/{src/lib/features → rich-text-editor/src}/mn-rich-text-editor/mn-rich-text-editor.component.css +0 -0
@@ -0,0 +1,2277 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, ChangeDetectorRef, afterEveryRender, TemplateRef, Input, Directive, EventEmitter, Output, ChangeDetectionStrategy, Component, ElementRef, Renderer2, DestroyRef, afterNextRender, HostListener, ViewChild } from '@angular/core';
3
+ import { Subject, skip, debounceTime } from 'rxjs';
4
+ import { lucideIcons, MnLanguageService } from 'mn-angular-lib/core';
5
+ import * as lucide from 'lucide';
6
+ import * as i1 from '@angular/forms';
7
+ import { FormsModule } from '@angular/forms';
8
+ import { MnButton, MnSkeleton } from 'mn-angular-lib/button';
9
+ import { MnSelect, MnCheckbox, MnInputField, MnMultiSelect, MnDropdown } from 'mn-angular-lib/forms';
10
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
11
+ import { NgClass, NgTemplateOutlet } from '@angular/common';
12
+ import { MnBottomSheet } from 'mn-angular-lib/bottom-sheet';
13
+ import { LucideDynamicIcon } from '@lucide/angular';
14
+
15
+ // ── Data lifecycle state ──
16
+ /**
17
+ * Lifecycle state of a collection's data, driving which chrome the component
18
+ * renders: skeleton placeholders ({@link LOADING}), the rows or empty state
19
+ * ({@link RETRIEVED}), or an error placeholder ({@link ERROR}).
20
+ *
21
+ * Because the components are zoneless and OnPush, a consumer that flips `state`
22
+ * to `ERROR` (or `RETRIEVED`) must also emit on `dataRows` (e.g. `dataRows.next([])`)
23
+ * so the component runs change detection and re-reads the new state.
24
+ */
25
+ var MnCollectionState;
26
+ (function (MnCollectionState) {
27
+ /** Data is being (re)loaded; skeleton placeholders are shown. */
28
+ MnCollectionState["LOADING"] = "LOADING";
29
+ /** Data has loaded (possibly empty); rows or the empty state are shown. */
30
+ MnCollectionState["RETRIEVED"] = "RETRIEVED";
31
+ /** Loading failed; the error placeholder is shown. */
32
+ MnCollectionState["ERROR"] = "ERROR";
33
+ })(MnCollectionState || (MnCollectionState = {}));
34
+
35
+ /** Lucide icons this file renders. */
36
+ const ICONS$1 = lucideIcons({ Inbox: lucide.Inbox });
37
+ /**
38
+ * Shared chrome for MnLib collection components (table, list, grid):
39
+ * data subscription, client/server search, every pagination mode, load-more,
40
+ * skeleton-row count, empty-state plumbing, common i18n key resolution and
41
+ * toolbar change-detection.
42
+ *
43
+ * Concrete components extend this (or {@link MnSelectableCollectionBase}) and
44
+ * implement only their rendering. The class is decorated `@Directive()` so it can
45
+ * declare `@Input`s and use `inject()` while remaining abstract.
46
+ *
47
+ * Init runs in a fixed order (see {@link ngOnInit}); subclasses hook in via the
48
+ * `protected` template methods rather than overriding `ngOnInit`.
49
+ */
50
+ class MnCollectionBase {
51
+ dataSource;
52
+ /** Row count at which the search box auto-enables when `canSearch` is unset. */
53
+ static DEFAULT_SEARCH_THRESHOLD = 8;
54
+ filteredItems = [];
55
+ paginatedItems = [];
56
+ searchValue = '';
57
+ loadingMoreRows = false;
58
+ /** Fallback empty-state icon used when a data source doesn't set `emptyIcon`. */
59
+ defaultEmptyIcon = ICONS$1.Inbox;
60
+ currentPage = 1;
61
+ pageSize = 10;
62
+ /**
63
+ * Measured pixel height of the body container, applied as a `min-height` floor
64
+ * while a server reload is in flight so the container can't collapse when the
65
+ * data rows are swapped for skeletons. Released in {@link ngDoCheck} the moment
66
+ * the loading state clears. `0` means no lock.
67
+ */
68
+ lockedMinHeight = 0;
69
+ /**
70
+ * Measured pixel height of one full page, applied as a persistent `min-height` floor
71
+ * while paginated so a short page (the last page, or after a row is removed/filtered)
72
+ * can't collapse the body and jump the layout below it. Blank space fills the remaindernpm
73
+ * at the bottom. Captured once a full page is actually on screen; `0` means unmeasured.
74
+ * Distinct from the transient {@link lockedMinHeight} reload lock — both combine in
75
+ * {@link bodyMinHeight} via `Math.max`.
76
+ */
77
+ fullPageHeight = 0;
78
+ /** Write-once guard so {@link fullPageHeight} is measured once per pageSize. */
79
+ pageHeightMeasured = false;
80
+ cdr = inject(ChangeDetectorRef);
81
+ lang = inject(MnLanguageService);
82
+ /** Prefix used in validation error messages, e.g. `MnList`. Overridden by subclasses. */
83
+ componentName = 'MnCollection';
84
+ dataSubscription;
85
+ searchSubject = new Subject();
86
+ searchSubscription;
87
+ langSubscription;
88
+ /** Tracks the previous toolbar template reference for change detection. */
89
+ previousToolbarTemplate;
90
+ constructor() {
91
+ // Measure the body's height once a full page is on screen and cache it as the persistent
92
+ // {@link fullPageHeight} floor. Runs after every render (outside change detection, so
93
+ // writing the bound field can't trigger `ExpressionChangedAfterItHasBeenChecked`); the
94
+ // {@link pageHeightMeasured} guard limits the actual measurement to once per pageSize.
95
+ afterEveryRender(() => {
96
+ if (this.pageHeightMeasured || !this.isPaginated || this.isLoadingState)
97
+ return;
98
+ if (this.paginatedItems.length !== this.pageSize)
99
+ return;
100
+ const el = this.collectionBody?.nativeElement;
101
+ if (!el)
102
+ return;
103
+ this.fullPageHeight = el.offsetHeight;
104
+ this.pageHeightMeasured = true;
105
+ this.cdr.markForCheck();
106
+ });
107
+ }
108
+ // ── Data lifecycle state ──
109
+ /**
110
+ * Single source of truth for the data lifecycle: the explicit
111
+ * {@link MnCollectionDataSource.state}, defaulting to RETRIEVED when unset.
112
+ * Every internal loading check routes through this.
113
+ */
114
+ get collectionState() {
115
+ return this.dataSource.state ?? MnCollectionState.RETRIEVED;
116
+ }
117
+ /** Whether the collection is currently loading (skeleton placeholders shown). */
118
+ get isLoadingState() {
119
+ return this.collectionState === MnCollectionState.LOADING;
120
+ }
121
+ /** Accessible name for the loading placeholder, and the text the status region announces. */
122
+ get loadingLabel() {
123
+ return this.resolveLabel(undefined, 'mnCollection.loading', 'Loading');
124
+ }
125
+ /** Whether loading failed (the error placeholder is shown instead of rows/empty). */
126
+ get isErrorState() {
127
+ return this.collectionState === MnCollectionState.ERROR;
128
+ }
129
+ // ── Template-method hooks ──
130
+ /** Whether the component delegates search to the consumer (server-side). */
131
+ get isServerSearched() {
132
+ return !!this.dataSource.onServerSearch;
133
+ }
134
+ /**
135
+ * Whether the search box is shown: the explicit `canSearch` when set, otherwise
136
+ * auto-enabled once the row count reaches `searchThreshold` and the source can actually
137
+ * search (a client predicate or a server callback — a box that filters nothing is noise).
138
+ * A non-empty term keeps the box even when the (server-)filtered result drops below the
139
+ * threshold, so the user can always clear what they typed.
140
+ */
141
+ get isSearchable() {
142
+ if (this.dataSource.canSearch !== undefined)
143
+ return this.dataSource.canSearch;
144
+ if (!this.dataSource.isInSearch && !this.isServerSearched)
145
+ return false;
146
+ if (this.searchValue.length > 0)
147
+ return true;
148
+ const threshold = this.dataSource.searchThreshold ?? MnCollectionBase.DEFAULT_SEARCH_THRESHOLD;
149
+ const rowCount = this.isServerPaginated && this.dataSource.totalItems != null
150
+ ? this.dataSource.totalItems
151
+ : (this.dataSource.dataRows.value ?? []).length;
152
+ return rowCount >= threshold;
153
+ }
154
+ get isPaginated() {
155
+ const mode = this.dataSource.paginationMode;
156
+ return mode === 'paginated' || mode === 'client-side-pagination';
157
+ }
158
+ /** Whether the component delegates pagination to the consumer (server-side). */
159
+ get isServerPaginated() {
160
+ const mode = this.dataSource.paginationMode ?? 'load-more';
161
+ return mode === 'paginated' || mode === 'load-more';
162
+ }
163
+ get showLoadMore() {
164
+ const mode = this.dataSource.paginationMode ?? 'load-more';
165
+ // Server-side load-more: check if there are more items to load.
166
+ if (this.dataSource.onLoadMore) {
167
+ const totalItems = this.dataSource.totalItems ?? 0;
168
+ return mode === 'load-more' && this.filteredItems.length < totalItems;
169
+ }
170
+ const strategy = this.dataSource.paginationStrategy;
171
+ const hasMore = strategy ? strategy.hasMoreRows : !!this.dataSource.loadAdditionalRows;
172
+ return mode === 'load-more' && hasMore;
173
+ }
174
+ // ── Height stabilization ──
175
+ /**
176
+ * The measured full-page {@link fullPageHeight} floor, but only while it should apply:
177
+ * paginated, not loading, with rows present. Keeps a short page from collapsing the body.
178
+ */
179
+ get reservedPageHeight() {
180
+ if (this.isPaginated && !this.isLoadingState && this.filteredItems.length > 0) {
181
+ return this.fullPageHeight;
182
+ }
183
+ return 0;
184
+ }
185
+ /**
186
+ * `min-height` (px) applied to the body: the larger of the transient reload lock and the
187
+ * persistent full-page floor, so neither can shrink the body below the other. `null` clears it.
188
+ */
189
+ get bodyMinHeight() {
190
+ return Math.max(this.lockedMinHeight, this.reservedPageHeight) || null;
191
+ }
192
+ // ── Lifecycle ──
193
+ /** Total number of items, accounting for server-side pagination. */
194
+ get totalItemCount() {
195
+ if (this.isServerPaginated && this.dataSource.totalItems != null) {
196
+ return this.dataSource.totalItems;
197
+ }
198
+ return this.filteredItems.length;
199
+ }
200
+ get totalPages() {
201
+ return Math.max(1, Math.ceil(this.totalItemCount / this.pageSize));
202
+ }
203
+ get resolvedPageSizeOptions() {
204
+ return this.dataSource.pageSizeOptions ?? [5, 10, 25, 50];
205
+ }
206
+ // ── Search ──
207
+ /** Page-size options formatted for mn-select. */
208
+ get pageSizeSelectOptions() {
209
+ return this.resolvedPageSizeOptions.map(opt => ({ label: String(opt), value: opt }));
210
+ }
211
+ get visiblePages() {
212
+ const total = this.totalPages;
213
+ const current = this.currentPage;
214
+ const maxVisible = 3;
215
+ let start = Math.max(1, current - Math.floor(maxVisible / 2));
216
+ let end = start + maxVisible - 1;
217
+ if (end > total) {
218
+ end = total;
219
+ start = Math.max(1, end - maxVisible + 1);
220
+ }
221
+ const pages = [];
222
+ for (let i = start; i <= end; i++) {
223
+ pages.push(i);
224
+ }
225
+ return pages;
226
+ }
227
+ get skeletonRows() {
228
+ // Explicit override wins; otherwise match the rows currently on screen so the
229
+ // skeleton fills the same space on a reload; fall back to 5 on the first load.
230
+ const count = this.dataSource.skeletonRowCount ?? (this.paginatedItems.length || 5);
231
+ return Array.from({ length: count });
232
+ }
233
+ ngOnInit() {
234
+ this.normalizeDataSource();
235
+ this.resolveTranslationKeys();
236
+ this.pageSize = this.dataSource.pageSize ?? 10;
237
+ this.beforeInitialFilter();
238
+ this.applyFilter(false);
239
+ // Skip the initial BehaviorSubject emission (already handled above).
240
+ this.dataSubscription = this.dataSource.dataRows.pipe(skip(1)).subscribe(() => {
241
+ this.applyFilter(false);
242
+ this.onRowsChanged();
243
+ this.cdr.markForCheck();
244
+ });
245
+ this.searchSubscription = this.searchSubject
246
+ .pipe(debounceTime(300))
247
+ .subscribe(value => {
248
+ this.searchValue = value;
249
+ this.applyFilter(true);
250
+ this.cdr.markForCheck();
251
+ });
252
+ // Re-resolve translation keys whenever the locale changes.
253
+ this.langSubscription = this.lang.locale$.pipe(skip(1)).subscribe(() => {
254
+ this.resolveTranslationKeys();
255
+ this.cdr.markForCheck();
256
+ });
257
+ }
258
+ ngDoCheck() {
259
+ // Release the height lock as soon as loading ends — same CD cycle that clears
260
+ // the skeleton, so the lock can never outlive the skeleton it protects.
261
+ if (this.lockedMinHeight && !this.isLoadingState) {
262
+ this.lockedMinHeight = 0;
263
+ }
264
+ const currentTemplate = this.trackedToolbarTemplate;
265
+ if (currentTemplate !== this.previousToolbarTemplate) {
266
+ this.previousToolbarTemplate = currentTemplate;
267
+ this.cdr.markForCheck();
268
+ }
269
+ }
270
+ ngOnDestroy() {
271
+ this.dataSubscription?.unsubscribe();
272
+ this.searchSubscription?.unsubscribe();
273
+ this.langSubscription?.unsubscribe();
274
+ }
275
+ onSearch(searchString) {
276
+ this.currentPage = 1;
277
+ if (this.isServerSearched) {
278
+ this.lockBodyHeight();
279
+ this.searchValue = searchString;
280
+ this.dataSource.onServerSearch?.(searchString);
281
+ this.cdr.markForCheck();
282
+ }
283
+ else {
284
+ this.searchSubject.next(searchString);
285
+ }
286
+ }
287
+ goToPage(page) {
288
+ if (page < 1 || page > this.totalPages)
289
+ return;
290
+ this.currentPage = page;
291
+ if (this.dataSource.paginationMode === 'client-side-pagination') {
292
+ this.applyPagination();
293
+ }
294
+ else {
295
+ this.lockBodyHeight();
296
+ this.dataSource.onPageChange?.(page);
297
+ }
298
+ this.cdr.markForCheck();
299
+ }
300
+ onPageSizeChange(newSize) {
301
+ this.invalidatePageHeight();
302
+ this.pageSize = newSize;
303
+ this.currentPage = 1;
304
+ if (this.dataSource.paginationMode === 'client-side-pagination') {
305
+ this.applyPagination();
306
+ }
307
+ else {
308
+ this.lockBodyHeight();
309
+ this.dataSource.onPageSizeChange?.(newSize);
310
+ }
311
+ this.cdr.markForCheck();
312
+ }
313
+ loadMoreRows() {
314
+ // Server-side infinite scroll: delegate to consumer callback.
315
+ if (this.dataSource.onLoadMore) {
316
+ this.dataSource.onLoadMore();
317
+ return;
318
+ }
319
+ if (!this.dataSource.loadAdditionalRows || this.loadingMoreRows)
320
+ return;
321
+ this.loadingMoreRows = true;
322
+ const promise = (this.searchValue && this.searchValue.length > 0 && this.dataSource.searchForAdditionalItems)
323
+ ? this.dataSource.searchForAdditionalItems(this.searchValue)
324
+ : this.dataSource.loadAdditionalRows();
325
+ promise
326
+ .then(rows => this.processLoadedRows(rows))
327
+ .catch(() => this.loadingMoreRows = false);
328
+ }
329
+ isTemplateRef(value) {
330
+ return value instanceof TemplateRef;
331
+ }
332
+ trackByID = (_index, item) => {
333
+ return this.dataSource.getID(item);
334
+ };
335
+ // ── Template helpers ──
336
+ /** Runs after pageSize is set but before the first {@link applyFilter}. */
337
+ beforeInitialFilter() {
338
+ // no-op by default
339
+ }
340
+ /**
341
+ * Runs after a fresh batch of rows has been filtered in, for work that needs the
342
+ * rows to exist. Subclasses override to react to data arriving late; call `super`
343
+ * to keep the default (currently nothing).
344
+ */
345
+ onRowsChanged() {
346
+ // no-op by default
347
+ }
348
+ /**
349
+ * Resolves a label three ways, in order: the consumer's explicit key, a
350
+ * conventional `mnCollection.*` key when the app defines one, and finally a
351
+ * readable English default.
352
+ *
353
+ * The middle step is what makes the components translatable out of the box: an
354
+ * app that adds the `mnCollection` namespace to its locale files gets every
355
+ * table, list and grid translated at once, with no per-call-site wiring across
356
+ * dozens of data sources. An app that does not keeps today's English text rather
357
+ * than leaking raw keys into the UI.
358
+ *
359
+ * @param consumerKey The data source's own translation key, if it set one.
360
+ * @param defaultKey The conventional key this label falls back to.
361
+ * @param fallback The English text used when neither key resolves.
362
+ * @param params Optional interpolation values.
363
+ * @returns The resolved label.
364
+ */
365
+ resolveLabel(consumerKey, defaultKey, fallback, params) {
366
+ if (consumerKey)
367
+ return this.lang.t(consumerKey, params);
368
+ return this.lang.translateIfPresent(defaultKey, params) ?? fallback;
369
+ }
370
+ /**
371
+ * Resolves translation keys to display strings via {@link MnLanguageService}.
372
+ * Subclasses override to resolve their own keys; call `super` to keep these.
373
+ */
374
+ resolveTranslationKeys() {
375
+ if (this.dataSource.emptyMessageKey) {
376
+ this.dataSource.emptyMessage = this.lang.t(this.dataSource.emptyMessageKey);
377
+ }
378
+ if (this.dataSource.errorMessageKey) {
379
+ this.dataSource.errorMessage = this.lang.t(this.dataSource.errorMessageKey);
380
+ }
381
+ if (this.dataSource.searchPlaceholderKey) {
382
+ this.dataSource.searchPlaceholder = this.lang.t(this.dataSource.searchPlaceholderKey);
383
+ }
384
+ if (this.dataSource.labels) {
385
+ if (this.dataSource.labels.loadMoreKey) {
386
+ this.dataSource.labels.loadMore = this.lang.t(this.dataSource.labels.loadMoreKey);
387
+ }
388
+ if (this.dataSource.labels.rowsPerPageKey) {
389
+ this.dataSource.labels.rowsPerPage = this.lang.t(this.dataSource.labels.rowsPerPageKey);
390
+ }
391
+ // Resolved without params so the `{{current}}` / `{{start}}` placeholders
392
+ // survive; MnCollectionPagination fills them in per render.
393
+ if (this.dataSource.labels.pageIndicatorKey) {
394
+ this.dataSource.labels.pageIndicator = this.lang.t(this.dataSource.labels.pageIndicatorKey);
395
+ }
396
+ if (this.dataSource.labels.itemRangeKey) {
397
+ this.dataSource.labels.itemRange = this.lang.t(this.dataSource.labels.itemRangeKey);
398
+ }
399
+ }
400
+ }
401
+ // ── Shared internals ──
402
+ /**
403
+ * Captures the body container's current height into {@link lockedMinHeight} so it
404
+ * holds while a server reload swaps the data rows for skeletons. Must be called
405
+ * while the old rows are still rendered (before delegating to the consumer), and
406
+ * only locks when rows are present — the first load has nothing to preserve.
407
+ */
408
+ lockBodyHeight() {
409
+ const el = this.collectionBody?.nativeElement;
410
+ if (el && this.paginatedItems.length > 0) {
411
+ this.lockedMinHeight = el.offsetHeight;
412
+ }
413
+ }
414
+ /**
415
+ * Drops the cached {@link fullPageHeight} floor so it is re-measured on the next full page.
416
+ * Must run whenever the page size changes (the old floor is for a different row count).
417
+ */
418
+ invalidatePageHeight() {
419
+ this.fullPageHeight = 0;
420
+ this.pageHeightMeasured = false;
421
+ }
422
+ applyPagination() {
423
+ if (this.dataSource.paginationMode === 'client-side-pagination') {
424
+ const start = (this.currentPage - 1) * this.pageSize;
425
+ this.paginatedItems = this.filteredItems.slice(start, start + this.pageSize);
426
+ }
427
+ else {
428
+ // Server always provides the correct page/slice — no client-side slicing.
429
+ this.paginatedItems = this.filteredItems;
430
+ }
431
+ }
432
+ /** Client-side search filtering shared by list and grid. */
433
+ applySearchFilter(items) {
434
+ if (!this.isServerSearched && this.dataSource.isInSearch && this.isSearchable && this.searchValue && this.searchValue.length > 0) {
435
+ const term = this.searchValue.toLowerCase();
436
+ return items.filter(row => this.dataSource.isInSearch(row, term));
437
+ }
438
+ return items;
439
+ }
440
+ processLoadedRows(rows) {
441
+ const merged = [...new Map([...this.dataSource.dataRows.value, ...rows].map(item => [this.dataSource.getID(item), item])).values()];
442
+ this.dataSource.dataRows.next(merged);
443
+ this.loadingMoreRows = false;
444
+ this.applyFilter(false);
445
+ }
446
+ /**
447
+ * Reports every misconfigured pagination setting and repairs it in place.
448
+ *
449
+ * This deliberately does **not** throw. It runs first in {@link ngOnInit}, and a
450
+ * throw there aborts the rest of init — the data subscription is never made and
451
+ * {@link applyFilter} never runs, so the component renders a permanently empty
452
+ * body that only "heals" once some later interaction happens to call
453
+ * {@link applyFilter}. That failure mode reads as "the table is broken" rather
454
+ * than "the data source is misconfigured", and inside a modal the thrown error
455
+ * is easy to miss entirely. Logging loudly and degrading to the nearest working
456
+ * mode keeps the misconfiguration visible while still rendering the rows.
457
+ */
458
+ normalizeDataSource() {
459
+ const mode = this.dataSource.paginationMode;
460
+ // Server-side pagination without the server half of the contract: there is no
461
+ // way to fetch another page, so paginate the rows we were handed instead.
462
+ if (mode === 'paginated') {
463
+ const missing = [];
464
+ if (!this.dataSource.onPageChange)
465
+ missing.push('onPageChange');
466
+ if (this.dataSource.totalItems == null)
467
+ missing.push('totalItems');
468
+ if (missing.length > 0) {
469
+ this.reportConfigError(`paginationMode is 'paginated' but ${missing.join(' and ')} ${missing.length === 1 ? 'is' : 'are'} missing. ` +
470
+ `Server-side pagination requires both; falling back to 'client-side-pagination'.`);
471
+ this.dataSource.paginationMode = 'client-side-pagination';
472
+ }
473
+ }
474
+ if (mode === 'load-more' || mode === 'infinite-scroll') {
475
+ if (!this.dataSource.onLoadMore && !this.dataSource.loadAdditionalRows && !this.dataSource.paginationStrategy) {
476
+ this.reportConfigError(`paginationMode is '${mode}' but no load-more mechanism is provided. ` +
477
+ `Provide 'onLoadMore', 'loadAdditionalRows', or 'paginationStrategy'; falling back to 'none'.`);
478
+ this.dataSource.paginationMode = 'none';
479
+ }
480
+ }
481
+ // A pageSize outside the selector's options would leave the dropdown with no
482
+ // matching entry; widen the options rather than override the consumer's size.
483
+ if (this.dataSource.paginationMode && this.dataSource.paginationMode !== 'none') {
484
+ const options = this.resolvedPageSizeOptions;
485
+ const size = this.dataSource.pageSize ?? 10;
486
+ if (!options.includes(size)) {
487
+ this.reportConfigError(`pageSize '${size}' is not one of pageSizeOptions [${options.join(', ')}]. ` +
488
+ `Adding it so the rows-per-page selector can show it.`);
489
+ this.dataSource.pageSizeOptions = [...options, size].sort((a, b) => a - b);
490
+ }
491
+ }
492
+ }
493
+ /**
494
+ * Logs a data-source configuration problem, prefixed with the component name.
495
+ * @param message What is wrong and how it was compensated for.
496
+ */
497
+ reportConfigError(message) {
498
+ console.error(`[${this.componentName}] ${message}`);
499
+ }
500
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCollectionBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
501
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: MnCollectionBase, isStandalone: true, inputs: { dataSource: "dataSource" }, ngImport: i0 });
502
+ }
503
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCollectionBase, decorators: [{
504
+ type: Directive
505
+ }], ctorParameters: () => [], propDecorators: { dataSource: [{
506
+ type: Input
507
+ }] } });
508
+
509
+ /**
510
+ * Extends {@link MnCollectionBase} with single/multi row selection, shared by
511
+ * components that support it (table, list). Grid extends the plain base instead.
512
+ */
513
+ class MnSelectableCollectionBase extends MnCollectionBase {
514
+ selectionChange = new EventEmitter();
515
+ selectedIds = new Set();
516
+ /** Whether the summary is currently showing every tag rather than the first few. */
517
+ selectionSummaryExpanded = false;
518
+ get allSelected() {
519
+ return this.filteredItems.length > 0 && this.selectedIds.size === this.filteredItems.length;
520
+ }
521
+ /**
522
+ * The row behind every selected id, kept so the selection survives the rows
523
+ * themselves going away.
524
+ *
525
+ * {@link selectedIds} alone is enough to tick a checkbox, because that only ever
526
+ * asks about a row already on screen. The summary asks the opposite question —
527
+ * "what is selected, including what isn't on this page?" — and a server-paginated
528
+ * collection has long since discarded those rows. Rows are captured as they are
529
+ * selected and backfilled from {@link MnSelectableCollectionDataSource.initialSelectedRows}
530
+ * and from each batch that loads.
531
+ */
532
+ selectedRowsById = new Map();
533
+ /**
534
+ * Whether a seeded initial selection still has to be announced, because none of
535
+ * its ids matched a loaded row yet. See {@link beforeInitialFilter}.
536
+ */
537
+ pendingInitialEmit = false;
538
+ /**
539
+ * Every selected row, in selection order, for the summary. Ids whose row was
540
+ * never seen are skipped rather than rendered as a bare id.
541
+ */
542
+ get selectedSummaryRows() {
543
+ const rows = [];
544
+ for (const id of this.selectedIds) {
545
+ const row = this.selectedRowsById.get(id);
546
+ if (row !== undefined)
547
+ rows.push(row);
548
+ }
549
+ return rows;
550
+ }
551
+ /** Whether the selection summary should render. */
552
+ get showSelectionSummary() {
553
+ return !!this.dataSource.selectionSummary && this.hasSelection && this.selectedIds.size > 0;
554
+ }
555
+ /** How many tags to show before collapsing the remainder. */
556
+ get selectionSummaryLimit() {
557
+ return this.dataSource.selectionSummaryLimit ?? this.defaultSelectionSummaryLimit;
558
+ }
559
+ /**
560
+ * Tag count the summary collapses at when the data source names no limit.
561
+ *
562
+ * Subclasses that know their own width narrow this: the same eight tags that
563
+ * read as a compact header on a wide table become seven stacked lines in a phone
564
+ * sheet, pushing the rows they describe off screen. Overridden by
565
+ * {@link MnCollectionDataSource.selectionSummaryLimit}.
566
+ */
567
+ // Deliberately an accessor, not a readonly field: MnTable overrides it with a
568
+ // width-dependent getter, and TypeScript cannot override a property with one.
569
+ // eslint-disable-next-line @typescript-eslint/class-literal-property-style
570
+ get defaultSelectionSummaryLimit() {
571
+ return 8;
572
+ }
573
+ /**
574
+ * The tags to render: the first {@link selectionSummaryLimit} rows, or all of them
575
+ * once expanded. Keeps a large selection from turning the header into the page.
576
+ */
577
+ get visibleSelectionRows() {
578
+ const rows = this.selectedSummaryRows;
579
+ return this.selectionSummaryExpanded ? rows : rows.slice(0, this.selectionSummaryLimit);
580
+ }
581
+ /** How many selected rows are collapsed out of view; 0 when all are shown. */
582
+ get hiddenSelectionCount() {
583
+ if (this.selectionSummaryExpanded)
584
+ return 0;
585
+ return Math.max(0, this.selectedSummaryRows.length - this.selectionSummaryLimit);
586
+ }
587
+ /** Expands or re-collapses the summary's tag list. */
588
+ toggleSelectionSummary() {
589
+ this.selectionSummaryExpanded = !this.selectionSummaryExpanded;
590
+ this.cdr.markForCheck();
591
+ }
592
+ /**
593
+ * The label for a row in the summary: the consumer's {@link
594
+ * MnSelectableCollectionDataSource.selectionLabel}, else the first column that
595
+ * renders a plain string, else the row's id.
596
+ * @param row The selected row.
597
+ * @returns The text to show on the row's tag.
598
+ */
599
+ selectionLabelFor(row) {
600
+ const custom = this.dataSource.selectionLabel;
601
+ if (custom)
602
+ return custom(row);
603
+ return this.defaultSelectionLabel(row) ?? this.dataSource.getID(row);
604
+ }
605
+ /** Removes one row from the selection, from its tag in the summary. */
606
+ removeSelection(row) {
607
+ const id = this.dataSource.getID(row);
608
+ if (!this.selectedIds.delete(id))
609
+ return;
610
+ this.selectedRowsById.delete(id);
611
+ this.emitSelection();
612
+ this.cdr.markForCheck();
613
+ }
614
+ get hasSelection() {
615
+ return (this.dataSource.selectionMode ?? 'none') !== 'none';
616
+ }
617
+ get isMultiSelect() {
618
+ return this.dataSource.selectionMode === 'multi';
619
+ }
620
+ isSelected(item) {
621
+ return this.selectedIds.has(this.dataSource.getID(item));
622
+ }
623
+ /** Clears the whole selection, from the summary's clear-all action. */
624
+ clearSelection() {
625
+ if (this.selectedIds.size === 0)
626
+ return;
627
+ this.selectedIds.clear();
628
+ this.selectedRowsById.clear();
629
+ this.emitSelection();
630
+ this.cdr.markForCheck();
631
+ }
632
+ toggle(item) {
633
+ const id = this.dataSource.getID(item);
634
+ const mode = this.dataSource.selectionMode ?? 'none';
635
+ if (mode === 'single') {
636
+ this.selectedIds.clear();
637
+ this.selectedRowsById.clear();
638
+ this.selectedIds.add(id);
639
+ this.selectedRowsById.set(id, item);
640
+ }
641
+ else if (mode === 'multi') {
642
+ if (this.selectedIds.has(id)) {
643
+ this.selectedIds.delete(id);
644
+ this.selectedRowsById.delete(id);
645
+ }
646
+ else {
647
+ this.selectedIds.add(id);
648
+ this.selectedRowsById.set(id, item);
649
+ }
650
+ }
651
+ this.emitSelection();
652
+ }
653
+ toggleAll() {
654
+ if (this.selectedIds.size === this.filteredItems.length) {
655
+ this.selectedIds.clear();
656
+ this.selectedRowsById.clear();
657
+ }
658
+ else {
659
+ this.filteredItems.forEach(item => {
660
+ const id = this.dataSource.getID(item);
661
+ this.selectedIds.add(id);
662
+ this.selectedRowsById.set(id, item);
663
+ });
664
+ }
665
+ this.emitSelection();
666
+ }
667
+ /**
668
+ * Fallback label used when the data source declares no `selectionLabel`.
669
+ * Subclasses that know how to render a row as text (a table knows its columns)
670
+ * override this; the base has nothing to go on.
671
+ * @returns The label, or null when none can be derived.
672
+ */
673
+ defaultSelectionLabel(_row) {
674
+ return null;
675
+ }
676
+ /** Seeds selection from `initialSelectedIds` before the first filter pass. */
677
+ beforeInitialFilter() {
678
+ super.beforeInitialFilter();
679
+ if (!this.dataSource.initialSelectedIds?.length)
680
+ return;
681
+ for (const id of this.dataSource.initialSelectedIds) {
682
+ this.selectedIds.add(id);
683
+ }
684
+ for (const row of this.dataSource.initialSelectedRows ?? []) {
685
+ this.selectedRowsById.set(this.dataSource.getID(row), row);
686
+ }
687
+ this.captureSelectedRows();
688
+ // The rows are commonly still in flight at this point (any server fetch), and
689
+ // then no id resolves to a row yet. Emitting that would announce "nothing is
690
+ // selected" and let the consumer — a form control bound to this table, say —
691
+ // overwrite the very value it just seeded us with. Defer instead, and announce
692
+ // it from {@link onRowsChanged} once the rows actually arrive.
693
+ if (this.resolveSelectedRows().length === 0) {
694
+ this.pendingInitialEmit = true;
695
+ return;
696
+ }
697
+ this.emitSelection();
698
+ }
699
+ /** Announces a deferred initial selection as soon as its rows are loaded. */
700
+ onRowsChanged() {
701
+ super.onRowsChanged();
702
+ // A newly loaded page may hold rows for ids selected before it arrived.
703
+ this.captureSelectedRows();
704
+ if (!this.pendingInitialEmit || this.resolveSelectedRows().length === 0)
705
+ return;
706
+ this.pendingInitialEmit = false;
707
+ this.emitSelection();
708
+ }
709
+ emitSelection() {
710
+ // A real user interaction supersedes any deferred initial announcement.
711
+ this.pendingInitialEmit = false;
712
+ const rows = this.resolveSelectedRows();
713
+ this.dataSource.selectedRows?.next(rows);
714
+ this.selectionChange.emit(rows);
715
+ }
716
+ /** Records the row object for every loaded row that is currently selected. */
717
+ captureSelectedRows() {
718
+ for (const row of this.dataSource.dataRows.value ?? []) {
719
+ const id = this.dataSource.getID(row);
720
+ if (this.selectedIds.has(id))
721
+ this.selectedRowsById.set(id, row);
722
+ }
723
+ }
724
+ /** The currently loaded rows whose id is selected. */
725
+ resolveSelectedRows() {
726
+ return (this.dataSource.dataRows.value ?? [])
727
+ .filter(r => this.selectedIds.has(this.dataSource.getID(r)));
728
+ }
729
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnSelectableCollectionBase, deps: null, target: i0.ɵɵFactoryTarget.Directive });
730
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: MnSelectableCollectionBase, isStandalone: true, outputs: { selectionChange: "selectionChange" }, usesInheritance: true, ngImport: i0 });
731
+ }
732
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnSelectableCollectionBase, decorators: [{
733
+ type: Directive
734
+ }], propDecorators: { selectionChange: [{
735
+ type: Output
736
+ }] } });
737
+
738
+ /**
739
+ * Presentational pagination footer shared by every MnLib collection component
740
+ * (table, list, grid): the load-more button, the page-size selector and the
741
+ * page navigator. It holds no state — the host component owns pagination state
742
+ * (via {@link import('./mn-collection-base.directive').MnCollectionBase}) and
743
+ * reacts to the outputs.
744
+ */
745
+ class MnCollectionPagination {
746
+ lang = inject(MnLanguageService);
747
+ /** Prefix for the page-size select's id, keeping it unique per host. */
748
+ idPrefix = 'mn-collection';
749
+ isPaginated = false;
750
+ isServerPaginated = false;
751
+ showLoadMore = false;
752
+ loadingMoreRows = false;
753
+ currentPage = 1;
754
+ pageSize = 10;
755
+ totalPages = 1;
756
+ totalItemCount = 0;
757
+ visiblePages = [];
758
+ pageSizeSelectOptions = [];
759
+ labels;
760
+ loadMore = new EventEmitter();
761
+ pageChange = new EventEmitter();
762
+ pageSizeChange = new EventEmitter();
763
+ get showPagination() {
764
+ return this.isPaginated && (this.totalPages > 1 || this.isServerPaginated);
765
+ }
766
+ /** First item number on the current page, 1-based. Zero when there is no data. */
767
+ get rangeStart() {
768
+ return this.totalItemCount === 0 ? 0 : (this.currentPage - 1) * this.pageSize + 1;
769
+ }
770
+ /** Last item number on the current page, clamped to the total. */
771
+ get rangeEnd() {
772
+ return Math.min(this.currentPage * this.pageSize, this.totalItemCount);
773
+ }
774
+ /**
775
+ * {@link visiblePages} anchored with the first and last page, so the total page
776
+ * count is on screen at md+ without consulting the readout.
777
+ *
778
+ * e.g. page 5 of 50 → `1 … 4 5 6 … 50`
779
+ */
780
+ get pageSlots() {
781
+ const pages = this.visiblePages;
782
+ if (pages.length === 0)
783
+ return [];
784
+ const first = pages[0];
785
+ const last = pages[pages.length - 1];
786
+ const slots = pages.map(page => ({ page, anchor: false }));
787
+ if (first > 1) {
788
+ // Only insert a gap when the anchor isn't already adjacent to the window.
789
+ if (first > 2)
790
+ slots.unshift({ page: null, anchor: true });
791
+ slots.unshift({ page: 1, anchor: true });
792
+ }
793
+ if (last < this.totalPages) {
794
+ if (last < this.totalPages - 1)
795
+ slots.push({ page: null, anchor: true });
796
+ slots.push({ page: this.totalPages, anchor: true });
797
+ }
798
+ return slots;
799
+ }
800
+ /** e.g. `Page 5 of 50`. */
801
+ get pageIndicatorLabel() {
802
+ return this.fill(this.label(this.labels?.pageIndicator, 'mnCollection.pageIndicator', 'Page {{current}} of {{total}}'), {
803
+ current: this.currentPage,
804
+ total: this.totalPages,
805
+ });
806
+ }
807
+ /** e.g. `41–50 of 250`. */
808
+ get itemRangeLabel() {
809
+ return this.fill(this.label(this.labels?.itemRange, 'mnCollection.itemRange', '{{start}}–{{end}} of {{total}}'), {
810
+ start: this.rangeStart,
811
+ end: this.rangeEnd,
812
+ total: this.totalItemCount,
813
+ });
814
+ }
815
+ /** "Items per page" label beside the page-size selector. */
816
+ get rowsPerPageLabel() {
817
+ return this.label(this.labels?.rowsPerPage, 'mnCollection.rowsPerPage', 'Items per page:');
818
+ }
819
+ /**
820
+ * Substitutes `{{name}}` placeholders, matching the interpolation syntax used
821
+ * by MnLanguageService so the same translation strings work either way.
822
+ */
823
+ fill(template, params) {
824
+ return Object.entries(params).reduce((result, [key, value]) => result.replace(new RegExp(`\\{\\{${key}\\}\\}`, 'g'), String(value)), template);
825
+ }
826
+ /** Label for the load-more button. */
827
+ get loadMoreLabel() {
828
+ return this.label(this.labels?.loadMore, 'mnCollection.loadMore', 'Load more');
829
+ }
830
+ /** Accessible label for the first-page control. */
831
+ get firstPageLabel() {
832
+ return this.label(undefined, 'mnCollection.firstPage', 'First page');
833
+ }
834
+ /** Accessible label for the previous-page control. */
835
+ get previousPageLabel() {
836
+ return this.label(undefined, 'mnCollection.previousPage', 'Previous page');
837
+ }
838
+ /** Accessible label for the next-page control. */
839
+ get nextPageLabel() {
840
+ return this.label(undefined, 'mnCollection.nextPage', 'Next page');
841
+ }
842
+ /** Accessible label for the last-page control. */
843
+ get lastPageLabel() {
844
+ return this.label(undefined, 'mnCollection.lastPage', 'Last page');
845
+ }
846
+ /**
847
+ * Wrapper classes for one slot in the page strip, shrinking it in two steps as
848
+ * the footer narrows. Container queries, so the measurement is the footer's own
849
+ * width — the same strip is wide on a page and cramped in a modal.
850
+ *
851
+ * The first/last anchors and their gaps drop below 640px, where « and » already
852
+ * jump to either end. Below 380px every number except the current one drops too:
853
+ * the strip would otherwise wrap onto a second line and push the footer over the
854
+ * table, and the "Page 3 of 9" readout beside it already says where the user is.
855
+ * The arrows survive both steps, so navigation never depends on a number.
856
+ */
857
+ slotVisibility(slot) {
858
+ if (slot.anchor)
859
+ return 'hidden @min-[640px]:inline-flex';
860
+ return slot.page === this.currentPage ? 'inline-flex' : 'hidden @min-[380px]:inline-flex';
861
+ }
862
+ /**
863
+ * Accessible label for a page-number button.
864
+ * @param page The page the button jumps to.
865
+ * @returns The label, naming the page.
866
+ */
867
+ pageLabel(page) {
868
+ const template = this.label(undefined, 'mnCollection.page', 'Page {{page}}');
869
+ return template.replace('{{page}}', String(page));
870
+ }
871
+ /**
872
+ * Resolves a label three ways, in order: the consumer's explicit text, the
873
+ * conventional `mnCollection.*` key when the app defines one, and finally a
874
+ * readable English default.
875
+ *
876
+ * Mirrors `MnCollectionBase.resolveLabel`; this component is presentational and
877
+ * does not extend that base, but its chrome must be just as translatable — the
878
+ * page-size label and the item-range readout are on screen for every paged
879
+ * collection in the app.
880
+ *
881
+ * @param explicit The label the host passed in, if any.
882
+ * @param key The conventional translation key to try.
883
+ * @param fallback The English text used when neither resolves.
884
+ * @returns The resolved label.
885
+ */
886
+ label(explicit, key, fallback) {
887
+ return explicit ?? this.lang.translateIfPresent(key) ?? fallback;
888
+ }
889
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCollectionPagination, deps: [], target: i0.ɵɵFactoryTarget.Component });
890
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnCollectionPagination, isStandalone: true, selector: "mn-collection-pagination", inputs: { idPrefix: "idPrefix", isPaginated: "isPaginated", isServerPaginated: "isServerPaginated", showLoadMore: "showLoadMore", loadingMoreRows: "loadingMoreRows", currentPage: "currentPage", pageSize: "pageSize", totalPages: "totalPages", totalItemCount: "totalItemCount", visiblePages: "visiblePages", pageSizeSelectOptions: "pageSizeSelectOptions", labels: "labels" }, outputs: { loadMore: "loadMore", pageChange: "pageChange", pageSizeChange: "pageSizeChange" }, ngImport: i0, template: "<!-- Load more button -->\n@if (showLoadMore) {\n <div class=\"flex justify-center py-4\">\n <button\n (click)=\"loadMore.emit()\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'primary' }\"\n [disabled]=\"loadingMoreRows\"\n class=\"px-4 py-1.5 text-sm rounded border border-primary-500 text-primary-500 hover:bg-primary-100 transition-colors disabled:opacity-50\"\n mnButton\n type=\"button\"\n >\n @if (loadingMoreRows) {\n <span\n class=\"inline-block w-3 h-3 border-2 border-primary-500 border-t-transparent rounded-full animate-spin mr-2\"></span>\n }\n {{ loadMoreLabel }}\n </button>\n </div>\n}\n\n<!-- Pagination controls -->\n@if (showPagination) {\n <div class=\"@container flex items-center justify-between gap-2 px-2 py-3 text-sm text-base-content\">\n @if (pageSizeSelectOptions.length > 1) {\n <div class=\"hidden @min-[640px]:flex items-center gap-2\">\n <span>{{ rowsPerPageLabel }}</span>\n <mn-lib-select\n (ngModelChange)=\"pageSizeChange.emit($event)\"\n [ngModel]=\"pageSize\"\n [props]=\"{\n id: idPrefix + '-page-size',\n ariaLabel: rowsPerPageLabel,\n options: pageSizeSelectOptions,\n size: 'sm'\n }\"\n ></mn-lib-select>\n </div>\n } @else {\n <div class=\"hidden @min-[640px]:block\"></div>\n }\n\n <!-- Narrow viewports state the page position outright: the strip's last-page\n anchor only appears once the window stops reaching the end, so it can't\n be relied on to carry the total. -->\n <span aria-live=\"polite\"\n class=\"@min-[640px]:hidden text-xs opacity-70 whitespace-nowrap\">{{ pageIndicatorLabel }}</span>\n\n <div class=\"flex flex-wrap items-center justify-center gap-0.5 @min-[640px]:gap-1\">\n <span class=\"text-xs mr-2 hidden @min-[640px]:inline\">{{ itemRangeLabel }}</span>\n\n <button\n (click)=\"pageChange.emit(1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === 1 }\"\n [disabled]=\"currentPage === 1\"\n [attr.aria-label]=\"firstPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u00AB\n </button>\n\n <button\n (click)=\"pageChange.emit(currentPage - 1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === 1 }\"\n [disabled]=\"currentPage === 1\"\n [attr.aria-label]=\"previousPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u2039\n </button>\n\n @for (slot of pageSlots; track $index) {\n <span [class]=\"slotVisibility(slot)\">\n @if (slot.page !== null) {\n <button\n (click)=\"pageChange.emit(slot.page)\"\n [attr.aria-current]=\"slot.page === currentPage ? 'page' : null\"\n [attr.aria-label]=\"pageLabel(slot.page)\"\n [data]=\"{ size: 'sm', variant: 'text', color: slot.page === currentPage ? 'primary' : 'gray' }\"\n class=\"px-1.5 @min-[640px]:px-2.5 py-1 rounded underline underline-offset-2 transition-colors text-xs\"\n mnButton\n type=\"button\"\n >{{ slot.page }}\n </button>\n } @else {\n <span aria-hidden=\"true\" class=\"px-0.5 text-xs opacity-50 select-none\">\u2026</span>\n }\n </span>\n }\n\n <button\n (click)=\"pageChange.emit(currentPage + 1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === totalPages }\"\n [disabled]=\"currentPage === totalPages\"\n [attr.aria-label]=\"nextPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u203A\n </button>\n\n <button\n (click)=\"pageChange.emit(totalPages)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === totalPages }\"\n [disabled]=\"currentPage === totalPages\"\n [attr.aria-label]=\"lastPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u00BB\n </button>\n </div>\n </div>\n}\n", dependencies: [{ kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }, { kind: "component", type: MnSelect, selector: "mn-lib-select", inputs: ["props"] }, { 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"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
891
+ }
892
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnCollectionPagination, decorators: [{
893
+ type: Component,
894
+ args: [{ selector: 'mn-collection-pagination', standalone: true, imports: [MnButton, MnSelect, FormsModule], changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- Load more button -->\n@if (showLoadMore) {\n <div class=\"flex justify-center py-4\">\n <button\n (click)=\"loadMore.emit()\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'primary' }\"\n [disabled]=\"loadingMoreRows\"\n class=\"px-4 py-1.5 text-sm rounded border border-primary-500 text-primary-500 hover:bg-primary-100 transition-colors disabled:opacity-50\"\n mnButton\n type=\"button\"\n >\n @if (loadingMoreRows) {\n <span\n class=\"inline-block w-3 h-3 border-2 border-primary-500 border-t-transparent rounded-full animate-spin mr-2\"></span>\n }\n {{ loadMoreLabel }}\n </button>\n </div>\n}\n\n<!-- Pagination controls -->\n@if (showPagination) {\n <div class=\"@container flex items-center justify-between gap-2 px-2 py-3 text-sm text-base-content\">\n @if (pageSizeSelectOptions.length > 1) {\n <div class=\"hidden @min-[640px]:flex items-center gap-2\">\n <span>{{ rowsPerPageLabel }}</span>\n <mn-lib-select\n (ngModelChange)=\"pageSizeChange.emit($event)\"\n [ngModel]=\"pageSize\"\n [props]=\"{\n id: idPrefix + '-page-size',\n ariaLabel: rowsPerPageLabel,\n options: pageSizeSelectOptions,\n size: 'sm'\n }\"\n ></mn-lib-select>\n </div>\n } @else {\n <div class=\"hidden @min-[640px]:block\"></div>\n }\n\n <!-- Narrow viewports state the page position outright: the strip's last-page\n anchor only appears once the window stops reaching the end, so it can't\n be relied on to carry the total. -->\n <span aria-live=\"polite\"\n class=\"@min-[640px]:hidden text-xs opacity-70 whitespace-nowrap\">{{ pageIndicatorLabel }}</span>\n\n <div class=\"flex flex-wrap items-center justify-center gap-0.5 @min-[640px]:gap-1\">\n <span class=\"text-xs mr-2 hidden @min-[640px]:inline\">{{ itemRangeLabel }}</span>\n\n <button\n (click)=\"pageChange.emit(1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === 1 }\"\n [disabled]=\"currentPage === 1\"\n [attr.aria-label]=\"firstPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u00AB\n </button>\n\n <button\n (click)=\"pageChange.emit(currentPage - 1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === 1 }\"\n [disabled]=\"currentPage === 1\"\n [attr.aria-label]=\"previousPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u2039\n </button>\n\n @for (slot of pageSlots; track $index) {\n <span [class]=\"slotVisibility(slot)\">\n @if (slot.page !== null) {\n <button\n (click)=\"pageChange.emit(slot.page)\"\n [attr.aria-current]=\"slot.page === currentPage ? 'page' : null\"\n [attr.aria-label]=\"pageLabel(slot.page)\"\n [data]=\"{ size: 'sm', variant: 'text', color: slot.page === currentPage ? 'primary' : 'gray' }\"\n class=\"px-1.5 @min-[640px]:px-2.5 py-1 rounded underline underline-offset-2 transition-colors text-xs\"\n mnButton\n type=\"button\"\n >{{ slot.page }}\n </button>\n } @else {\n <span aria-hidden=\"true\" class=\"px-0.5 text-xs opacity-50 select-none\">\u2026</span>\n }\n </span>\n }\n\n <button\n (click)=\"pageChange.emit(currentPage + 1)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === totalPages }\"\n [disabled]=\"currentPage === totalPages\"\n [attr.aria-label]=\"nextPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u203A\n </button>\n\n <button\n (click)=\"pageChange.emit(totalPages)\"\n [data]=\"{ size: 'sm', variant: 'outline', color: 'secondary', disabled: currentPage === totalPages }\"\n [disabled]=\"currentPage === totalPages\"\n [attr.aria-label]=\"lastPageLabel\"\n class=\"px-2 py-1 rounded border border-base-300 hover:bg-base-200 transition-colors disabled:opacity-40 disabled:cursor-not-allowed aspect-square leading-none\"\n mnButton\n type=\"button\"\n >\u00BB\n </button>\n </div>\n </div>\n}\n" }]
895
+ }], propDecorators: { idPrefix: [{
896
+ type: Input
897
+ }], isPaginated: [{
898
+ type: Input
899
+ }], isServerPaginated: [{
900
+ type: Input
901
+ }], showLoadMore: [{
902
+ type: Input
903
+ }], loadingMoreRows: [{
904
+ type: Input
905
+ }], currentPage: [{
906
+ type: Input
907
+ }], pageSize: [{
908
+ type: Input
909
+ }], totalPages: [{
910
+ type: Input
911
+ }], totalItemCount: [{
912
+ type: Input
913
+ }], visiblePages: [{
914
+ type: Input
915
+ }], pageSizeSelectOptions: [{
916
+ type: Input
917
+ }], labels: [{
918
+ type: Input
919
+ }], loadMore: [{
920
+ type: Output
921
+ }], pageChange: [{
922
+ type: Output
923
+ }], pageSizeChange: [{
924
+ type: Output
925
+ }] } });
926
+
927
+ // ── Column Sort Type ──
928
+ var ColumnSortType;
929
+ (function (ColumnSortType) {
930
+ ColumnSortType["ALPHABETICAL"] = "ALPHABETICAL";
931
+ ColumnSortType["NUMERICAL"] = "NUMERICAL";
932
+ ColumnSortType["DATE"] = "DATE";
933
+ ColumnSortType["NONE"] = "NONE";
934
+ })(ColumnSortType || (ColumnSortType = {}));
935
+
936
+ /**
937
+ * Pure helpers backing mn-table's per-column filters: the empty value and
938
+ * "is it set?" test for each filter type, and the default client-side predicate
939
+ * applied when a column supplies no `filterFn`.
940
+ *
941
+ * Kept free of Angular so the filter semantics can be unit-tested directly.
942
+ */
943
+ /** The reset/unset value for a filter type. */
944
+ function emptyFilterValue(type) {
945
+ switch (type) {
946
+ case 'multi-select':
947
+ return [];
948
+ case 'boolean':
949
+ case 'text':
950
+ case 'select':
951
+ default:
952
+ return '';
953
+ }
954
+ }
955
+ /**
956
+ * Whether a filter value should actually narrow the rows. Empty strings and
957
+ * empty arrays are inactive; `false` on a boolean filter is active (it means
958
+ * "show only the false rows"), which is why a plain truthiness check is not
959
+ * enough.
960
+ */
961
+ function isFilterValueActive(value) {
962
+ if (value === undefined || value === null)
963
+ return false;
964
+ if (typeof value === 'boolean')
965
+ return true;
966
+ if (typeof value === 'string')
967
+ return value.trim().length > 0;
968
+ return Array.isArray(value) && value.length > 0;
969
+ }
970
+ /**
971
+ * The value a filter compares against for a row: the column's
972
+ * `getRawValueToSort` when present (the only option for template cells, which
973
+ * have no string to read), otherwise the rendered cell string.
974
+ */
975
+ function resolveFilterableValue(column, row) {
976
+ if (column.getRawValueToSort)
977
+ return column.getRawValueToSort(row);
978
+ if (typeof column.cell === 'function')
979
+ return column.cell(row);
980
+ return '';
981
+ }
982
+ /**
983
+ * The default predicate for a filter type, used when the column supplies no
984
+ * `filterFn`. Semantics per type:
985
+ * - `text` — case-insensitive substring match
986
+ * - `select` — exact string equality
987
+ * - `multi-select` — equality against any selected value (OR)
988
+ * - `boolean` — truthiness of the raw value equals the chosen state
989
+ */
990
+ function defaultFilterPredicate(type, raw, value) {
991
+ switch (type) {
992
+ case 'select':
993
+ return String(raw ?? '') === String(value);
994
+ case 'multi-select': {
995
+ const selected = value;
996
+ return selected.some(option => String(raw ?? '') === option);
997
+ }
998
+ case 'boolean':
999
+ return Boolean(raw) === value;
1000
+ case 'text':
1001
+ default:
1002
+ return String(raw ?? '')
1003
+ .toLowerCase()
1004
+ .includes(String(value).trim().toLowerCase());
1005
+ }
1006
+ }
1007
+ /**
1008
+ * Whether a row passes a column's active filter — the column's own `filterFn`
1009
+ * when it has one, otherwise {@link defaultFilterPredicate}.
1010
+ *
1011
+ * `filterFn` is declared per filter type on {@link ColumnDefinition}, so at this
1012
+ * generic call site the union of signatures is not callable and the value shape
1013
+ * is widened once here. Consumers keep the precise per-type signature where they
1014
+ * declare the column, which is where it matters.
1015
+ */
1016
+ function matchesColumnFilter(column, row, value) {
1017
+ const filterFn = column.filterFn;
1018
+ if (filterFn)
1019
+ return filterFn(row, value);
1020
+ return defaultFilterPredicate(column.filterType ?? 'text', resolveFilterableValue(column, row), value);
1021
+ }
1022
+
1023
+ /**
1024
+ * Attribute directive that applies responsive-hiding classes to table cells/headers.
1025
+ * Hides the element by default and shows it as `table-cell` at the specified breakpoint.
1026
+ *
1027
+ * The breakpoints are **container** queries against the table's own width, not the
1028
+ * viewport: a table inside a modal (or any narrow column) is far narrower than the
1029
+ * window, so viewport breakpoints would reveal columns the table has no room for.
1030
+ * mn-table marks its chrome `@container` for exactly this.
1031
+ *
1032
+ * Because of that, `sm`/`md`/`lg` mean "the table is at least this wide", and the
1033
+ * thresholds are **not** the viewport values of the same names — see {@link classMap}.
1034
+ *
1035
+ * Uses a static class map so Tailwind CSS can detect the full class names at build time.
1036
+ *
1037
+ * Usage: `<td [mnHiddenBelow]="column.hiddenBelow">`
1038
+ */
1039
+ class MnHiddenBelowDirective {
1040
+ /** The breakpoint below which the element is hidden. */
1041
+ mnHiddenBelow;
1042
+ el = inject(ElementRef);
1043
+ renderer = inject(Renderer2);
1044
+ appliedClasses = [];
1045
+ /**
1046
+ * Static mapping of breakpoints to their full Tailwind class names, so Tailwind
1047
+ * can detect them at build time.
1048
+ *
1049
+ * These are **container** widths, deliberately lower than the viewport
1050
+ * breakpoints they are named after. A table almost never gets the whole window:
1051
+ * a page table sits inside a docked sidebar plus page padding, which on a
1052
+ * 1280px screen leaves it under 900px. Reusing 1024px for `lg` would demand a
1053
+ * ~1400px window before an `lg` column ever appeared — hiding columns on the
1054
+ * most ordinary laptop. These values instead express how much room the column
1055
+ * itself needs, which is what a container query should measure.
1056
+ */
1057
+ classMap = {
1058
+ sm: ['hidden', '@min-[480px]:table-cell'],
1059
+ md: ['hidden', '@min-[640px]:table-cell'],
1060
+ lg: ['hidden', '@min-[800px]:table-cell'],
1061
+ };
1062
+ ngOnChanges() {
1063
+ // Remove previously applied classes
1064
+ for (const cls of this.appliedClasses) {
1065
+ this.renderer.removeClass(this.el.nativeElement, cls);
1066
+ }
1067
+ this.appliedClasses = [];
1068
+ if (this.mnHiddenBelow && this.classMap[this.mnHiddenBelow]) {
1069
+ const classes = this.classMap[this.mnHiddenBelow];
1070
+ for (const cls of classes) {
1071
+ this.renderer.addClass(this.el.nativeElement, cls);
1072
+ }
1073
+ this.appliedClasses = classes;
1074
+ }
1075
+ }
1076
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnHiddenBelowDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1077
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: MnHiddenBelowDirective, isStandalone: true, selector: "[mnHiddenBelow]", inputs: { mnHiddenBelow: "mnHiddenBelow" }, usesOnChanges: true, ngImport: i0 });
1078
+ }
1079
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnHiddenBelowDirective, decorators: [{
1080
+ type: Directive,
1081
+ args: [{
1082
+ selector: '[mnHiddenBelow]',
1083
+ standalone: true,
1084
+ }]
1085
+ }], propDecorators: { mnHiddenBelow: [{
1086
+ type: Input
1087
+ }] } });
1088
+
1089
+ /**
1090
+ * Attribute directive that hides an element below the given breakpoint and shows it at/above.
1091
+ * Uses `hidden` + `{bp}:inline` so the element is invisible on small screens.
1092
+ *
1093
+ * Usage: `<span [mnShowAbove]="'sm'">`
1094
+ */
1095
+ class MnShowAboveDirective {
1096
+ /** The breakpoint at/above which the element becomes visible. */
1097
+ mnShowAbove;
1098
+ el = inject(ElementRef);
1099
+ renderer = inject(Renderer2);
1100
+ appliedClasses = [];
1101
+ /** Static mapping of breakpoints to their full Tailwind class names. */
1102
+ classMap = {
1103
+ sm: ['hidden', '@min-[480px]:inline'],
1104
+ md: ['hidden', '@min-[640px]:inline'],
1105
+ lg: ['hidden', '@min-[800px]:inline'],
1106
+ };
1107
+ ngOnChanges() {
1108
+ for (const cls of this.appliedClasses) {
1109
+ this.renderer.removeClass(this.el.nativeElement, cls);
1110
+ }
1111
+ this.appliedClasses = [];
1112
+ if (this.mnShowAbove && this.classMap[this.mnShowAbove]) {
1113
+ const classes = this.classMap[this.mnShowAbove];
1114
+ for (const cls of classes) {
1115
+ this.renderer.addClass(this.el.nativeElement, cls);
1116
+ }
1117
+ this.appliedClasses = classes;
1118
+ }
1119
+ }
1120
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnShowAboveDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1121
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: MnShowAboveDirective, isStandalone: true, selector: "[mnShowAbove]", inputs: { mnShowAbove: "mnShowAbove" }, usesOnChanges: true, ngImport: i0 });
1122
+ }
1123
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnShowAboveDirective, decorators: [{
1124
+ type: Directive,
1125
+ args: [{
1126
+ selector: '[mnShowAbove]',
1127
+ standalone: true,
1128
+ }]
1129
+ }], propDecorators: { mnShowAbove: [{
1130
+ type: Input
1131
+ }] } });
1132
+
1133
+ /**
1134
+ * Attribute directive that shows an element below the given breakpoint and hides it at/above.
1135
+ * Uses `inline` by default + `{bp}:hidden` so the element is only visible on small screens.
1136
+ *
1137
+ * Usage: `<span [mnShowBelow]="'sm'">`
1138
+ */
1139
+ class MnShowBelowDirective {
1140
+ /** The breakpoint below which the element is visible. */
1141
+ mnShowBelow;
1142
+ el = inject(ElementRef);
1143
+ renderer = inject(Renderer2);
1144
+ appliedClasses = [];
1145
+ /** Static mapping of breakpoints to their full Tailwind class names. */
1146
+ classMap = {
1147
+ sm: ['inline', '@min-[480px]:hidden'],
1148
+ md: ['inline', '@min-[640px]:hidden'],
1149
+ lg: ['inline', '@min-[800px]:hidden'],
1150
+ };
1151
+ ngOnChanges() {
1152
+ for (const cls of this.appliedClasses) {
1153
+ this.renderer.removeClass(this.el.nativeElement, cls);
1154
+ }
1155
+ this.appliedClasses = [];
1156
+ if (this.mnShowBelow && this.classMap[this.mnShowBelow]) {
1157
+ const classes = this.classMap[this.mnShowBelow];
1158
+ for (const cls of classes) {
1159
+ this.renderer.addClass(this.el.nativeElement, cls);
1160
+ }
1161
+ this.appliedClasses = classes;
1162
+ }
1163
+ }
1164
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnShowBelowDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1165
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.3", type: MnShowBelowDirective, isStandalone: true, selector: "[mnShowBelow]", inputs: { mnShowBelow: "mnShowBelow" }, usesOnChanges: true, ngImport: i0 });
1166
+ }
1167
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnShowBelowDirective, decorators: [{
1168
+ type: Directive,
1169
+ args: [{
1170
+ selector: '[mnShowBelow]',
1171
+ standalone: true,
1172
+ }]
1173
+ }], propDecorators: { mnShowBelow: [{
1174
+ type: Input
1175
+ }] } });
1176
+
1177
+ /** Lucide icons this file renders. */
1178
+ const ICONS = lucideIcons({ Funnel: lucide.Funnel, X: lucide.X });
1179
+ class MnTable extends MnSelectableCollectionBase {
1180
+ /** Lucide icons the template renders. */
1181
+ icons = ICONS;
1182
+ sortChange = new EventEmitter();
1183
+ rowClick = new EventEmitter();
1184
+ currentSort = null;
1185
+ /** Per-column filter values keyed by column key. */
1186
+ columnFilters = {};
1187
+ /** Viewport width (px) below which the inline filter row collapses into a panel. */
1188
+ static FILTER_COLLAPSE_WIDTH = 640;
1189
+ /**
1190
+ * True when the viewport is narrow enough that the per-column filter inputs no
1191
+ * longer fit under their headers; the inline row is then replaced by a toggle
1192
+ * button and a stacked filter panel.
1193
+ */
1194
+ filtersCollapsed = false;
1195
+ /** Whether the small-screen filter bottom sheet is currently open. */
1196
+ filtersPanelOpen = false;
1197
+ /** Small-screen filter sheet, held so the close button can play its exit. */
1198
+ filtersSheet;
1199
+ componentName = 'MnTable';
1200
+ get trackedToolbarTemplate() {
1201
+ return this.dataSource?.toolbarLeftTemplate;
1202
+ }
1203
+ collectionBody;
1204
+ // ── Column Filters ──
1205
+ /** Debounces server-side text filters so typing doesn't fire a request per keystroke. */
1206
+ filterDebounce = new Subject();
1207
+ /**
1208
+ * Most rows shown per page on mobile (< md). A **cap**, not an override: a data
1209
+ * source asking for fewer rows keeps its own size. Raising a small page size on
1210
+ * a phone is the opposite of what it is for — it pushes the paginator below the
1211
+ * fold, which is most damaging inside a modal, where the sheet is already short
1212
+ * and its footer is pinned over the bottom of the table.
1213
+ */
1214
+ static MOBILE_PAGE_SIZE = 10;
1215
+ /**
1216
+ * The component's own element, measured for every responsive decision. Typed via
1217
+ * the annotation, not `inject(ElementRef<HTMLElement>)` — that form is a generic
1218
+ * call on the token and leaves `nativeElement` untyped.
1219
+ */
1220
+ host = inject(ElementRef);
1221
+ /** Whether the consumer owns filtering (server-side), mirroring {@link isServerSearched}. */
1222
+ get isServerFiltered() {
1223
+ return !!this.dataSource.onColumnFilterChange;
1224
+ }
1225
+ /** Every column filter that is actually set, in column order. */
1226
+ get activeColumnFilters() {
1227
+ return this.dataSource.columns
1228
+ .filter(col => col.filterable && isFilterValueActive(this.columnFilters[col.key]))
1229
+ .map(col => ({
1230
+ key: col.key,
1231
+ type: this.filterTypeOf(col),
1232
+ value: this.columnFilters[col.key],
1233
+ }));
1234
+ }
1235
+ /** Whether at least one column filter is active. */
1236
+ get hasActiveFilters() {
1237
+ return this.dataSource.columns.some(col => col.filterable && isFilterValueActive(this.columnFilters[col.key]));
1238
+ }
1239
+ /**
1240
+ * Updates a column filter value and either re-filters locally or hands the
1241
+ * active filters to the consumer. Server-side text filters are debounced;
1242
+ * every other type commits immediately.
1243
+ */
1244
+ onColumnFilter(column, value) {
1245
+ this.columnFilters[column.key] = value;
1246
+ this.currentPage = 1;
1247
+ if (this.isServerFiltered) {
1248
+ if (this.filterTypeOf(column) === 'text') {
1249
+ this.filterDebounce.next();
1250
+ }
1251
+ else {
1252
+ this.emitServerFilters();
1253
+ }
1254
+ }
1255
+ else {
1256
+ this.applyFilter(false);
1257
+ }
1258
+ this.cdr.markForCheck();
1259
+ }
1260
+ /** Updates a tri-state boolean filter from its select ('' = any). */
1261
+ onBooleanFilter(column, raw) {
1262
+ this.onColumnFilter(column, raw === '' ? '' : raw === 'true');
1263
+ }
1264
+ /** The effective filter type of a column, defaulting to text. */
1265
+ filterTypeOf(column) {
1266
+ return column.filterType ?? 'text';
1267
+ }
1268
+ /** Whether a specific column's filter currently narrows the rows. */
1269
+ isColumnFilterActive(column) {
1270
+ return isFilterValueActive(this.columnFilters[column.key]);
1271
+ }
1272
+ /** Filter options formatted for mn-multi-select for a given column. */
1273
+ getFilterMultiSelectOptions(column) {
1274
+ return (column.filterOptions ?? []).map(opt => ({ label: opt.label, value: String(opt.value) }));
1275
+ }
1276
+ /** Label for the small-screen filters toggle button. */
1277
+ get filtersButtonLabel() {
1278
+ return this.resolveLabel(this.dataSource.filtersLabelKey, 'mnCollection.filters', this.dataSource.filtersLabel ?? 'Filters');
1279
+ }
1280
+ /**
1281
+ * Summary a multi-select filter collapses to once more than one option is picked.
1282
+ * Resolved with the `{count}` token intact for mn-multi-select to fill in.
1283
+ */
1284
+ get filterSelectedLabel() {
1285
+ return this.resolveLabel(this.dataSource.filterLabels?.selectedKey, 'mnCollection.filterSelected', this.dataSource.filterLabels?.selected ?? '{count} selected');
1286
+ }
1287
+ /** Current text/select filter value for a column. */
1288
+ textFilterValue(column) {
1289
+ const value = this.columnFilters[column.key];
1290
+ return typeof value === 'string' ? value : '';
1291
+ }
1292
+ /** Current multi-select filter value for a column. */
1293
+ multiFilterValue(column) {
1294
+ const value = this.columnFilters[column.key];
1295
+ return Array.isArray(value) ? value : [];
1296
+ }
1297
+ /** Current boolean filter value for a column, as the select's string value. */
1298
+ booleanFilterValue(column) {
1299
+ const value = this.columnFilters[column.key];
1300
+ return typeof value === 'boolean' ? String(value) : '';
1301
+ }
1302
+ /** Resets every column filter and re-applies (or re-requests) filtering. */
1303
+ clearAllFilters() {
1304
+ this.seedFilterValues();
1305
+ this.currentPage = 1;
1306
+ if (this.isServerFiltered) {
1307
+ this.emitServerFilters();
1308
+ }
1309
+ else {
1310
+ this.applyFilter(false);
1311
+ }
1312
+ this.cdr.markForCheck();
1313
+ }
1314
+ /** Whether any column has filtering enabled. */
1315
+ get hasColumnFilters() {
1316
+ return this.dataSource.columns.some(c => c.filterable);
1317
+ }
1318
+ /** Label for the "clear all filters" action in the small-screen panel. */
1319
+ get clearFiltersButtonLabel() {
1320
+ return this.resolveLabel(this.dataSource.clearFiltersLabelKey, 'mnCollection.clearAll', this.dataSource.clearFiltersLabel ?? 'Clear all');
1321
+ }
1322
+ /** Accessible label for the filter sheet's close button. */
1323
+ get filtersCloseLabel() {
1324
+ return this.resolveLabel(undefined, 'mnCollection.close', 'Close');
1325
+ }
1326
+ /** Heading for the selection summary, with the count filled in. */
1327
+ get selectionSummaryTitle() {
1328
+ const labels = this.dataSource.selectionSummaryLabels;
1329
+ const template = this.resolveLabel(labels?.titleKey, 'mnCollection.selectedCount', labels?.title ?? 'Selected ({{count}})');
1330
+ return template.replace('{{count}}', String(this.selectedIds.size));
1331
+ }
1332
+ /** Label for the summary's clear-everything action. */
1333
+ get selectionClearAllLabel() {
1334
+ const labels = this.dataSource.selectionSummaryLabels;
1335
+ return this.resolveLabel(labels?.clearAllKey, 'mnCollection.clearAll', labels?.clearAll ?? 'Clear all');
1336
+ }
1337
+ /** Opens the small-screen filter bottom sheet. */
1338
+ openFiltersPanel() {
1339
+ this.filtersPanelOpen = true;
1340
+ }
1341
+ /** Plays the sheet's slide-down exit, then unmounts it. */
1342
+ async closeFiltersPanel() {
1343
+ await this.filtersSheet?.startClosing();
1344
+ this.filtersPanelOpen = false;
1345
+ this.cdr.markForCheck();
1346
+ }
1347
+ baseTableClasses = 'w-full border-collapse overflow-y-hidden';
1348
+ /**
1349
+ * Column widths measured from the automatic layout and pinned, keyed by column
1350
+ * key, for `stable`. Empty until the first render that has real rows on screen,
1351
+ * and cleared whenever the table is resized so the next render re-measures.
1352
+ */
1353
+ pinnedWidths = new Map();
1354
+ /** Sets sort/filter state seeded from the data source before the first filter pass. */
1355
+ beforeInitialFilter() {
1356
+ super.beforeInitialFilter();
1357
+ // Force the mobile row count below `md`; use the consumer's pageSize (or 10) above it.
1358
+ this.desktopPageSize = this.dataSource.pageSize ?? 10;
1359
+ this.applyResponsivePageSize(false);
1360
+ // Seed the filter layout for the initial viewport (no markForCheck pre-render).
1361
+ this.updateFilterLayout(false);
1362
+ this.currentSort = this.dataSource.defaultSort ?? null;
1363
+ this.seedFilterValues();
1364
+ }
1365
+ /**
1366
+ * Whether {@link pinColumnWidths} has run. Tracked separately from
1367
+ * {@link pinnedWidths} being non-empty, because the widest column is deliberately
1368
+ * left unpinned and a table with a single flexible column therefore pins nothing.
1369
+ */
1370
+ widthsPinned = false;
1371
+ /**
1372
+ * Recomputes whether the inline filter row should collapse into the panel.
1373
+ * Closes the panel when returning to the wide layout so reopened state never
1374
+ * leaks across the breakpoint. Marks for check only when the layout flips.
1375
+ */
1376
+ updateFilterLayout(reflow) {
1377
+ const collapsed = this.isFilterViewport();
1378
+ if (collapsed === this.filtersCollapsed)
1379
+ return;
1380
+ this.filtersCollapsed = collapsed;
1381
+ if (!collapsed)
1382
+ this.filtersPanelOpen = false;
1383
+ if (reflow)
1384
+ this.cdr.markForCheck();
1385
+ }
1386
+ sort(column) {
1387
+ if (!column.sortType || column.sortType === ColumnSortType.NONE)
1388
+ return;
1389
+ if (this.currentSort?.columnKey === column.key) {
1390
+ this.currentSort = this.currentSort.direction === 'asc'
1391
+ ? { columnKey: column.key, direction: 'desc' }
1392
+ : null;
1393
+ }
1394
+ else {
1395
+ this.currentSort = { columnKey: column.key, direction: 'asc' };
1396
+ }
1397
+ this.sortChange.emit(this.currentSort);
1398
+ this.applyFilter(false);
1399
+ }
1400
+ onRowClick(row) {
1401
+ if (this.hasSelection) {
1402
+ this.toggle(row);
1403
+ }
1404
+ this.dataSource.onRowClick?.(row);
1405
+ this.rowClick.emit(row);
1406
+ }
1407
+ // ── Sorting ──
1408
+ /**
1409
+ * Resolves the skeleton placeholder config for a column's cells.
1410
+ * Falls back to a text-shaped bar at 75% width (the previous default); any
1411
+ * fields the column provides override that default.
1412
+ */
1413
+ getColumnSkeletonData(column) {
1414
+ const skeleton = column.skeleton;
1415
+ const overrides = skeleton && !this.isTemplateRef(skeleton) ? skeleton : {};
1416
+ return { shape: 'text', width: '75%', ...overrides };
1417
+ }
1418
+ getSortIcon(column) {
1419
+ if (!this.currentSort || this.currentSort.columnKey !== column.key)
1420
+ return '';
1421
+ return this.currentSort.direction === 'asc' ? '▲' : '▼';
1422
+ }
1423
+ /**
1424
+ * Accessible name for a column's inline filter control: the header text, or the column key when
1425
+ * the header is a template.
1426
+ * @param column - The filtered column.
1427
+ */
1428
+ filterLabel(column) {
1429
+ return typeof column.header === 'string' ? this.headerText(column) : column.key;
1430
+ }
1431
+ /**
1432
+ * A string column's header text. `headerKey` is translated here, at render time, rather than
1433
+ * only in `resolveTranslationKeys`: that runs on init and on a locale change, so a column a
1434
+ * consumer adds afterwards (a permission-gated actions or image column) kept an empty header,
1435
+ * which a screen reader announces as a nameless column.
1436
+ * @param column - The column whose header is shown.
1437
+ * @returns The translated key when the column has one, otherwise its literal header, or an
1438
+ * empty string for a template header (rendered through its own outlet instead).
1439
+ */
1440
+ headerText(column) {
1441
+ if (column.headerKey) {
1442
+ return this.lang.t(column.headerKey);
1443
+ }
1444
+ return typeof column.header === 'string' ? column.header : '';
1445
+ }
1446
+ isSortable(column) {
1447
+ return !!column.sortType && column.sortType !== ColumnSortType.NONE;
1448
+ }
1449
+ // ── Row interaction ──
1450
+ constructor() {
1451
+ super();
1452
+ // Server-side text filtering only: client-side filtering stays instant per keystroke.
1453
+ this.filterDebounce
1454
+ .pipe(debounceTime(300), takeUntilDestroyed())
1455
+ .subscribe(() => {
1456
+ this.emitServerFilters();
1457
+ this.cdr.markForCheck();
1458
+ });
1459
+ // Watch the table's own box rather than the window: inside a modal, a sidebar
1460
+ // or a narrow grid cell the table resizes without the window ever changing,
1461
+ // and the window resizes without the table's share of it changing.
1462
+ if (typeof ResizeObserver !== 'undefined') {
1463
+ const observer = new ResizeObserver(() => this.onHostResize());
1464
+ observer.observe(this.host.nativeElement);
1465
+ inject(DestroyRef).onDestroy(() => observer.disconnect());
1466
+ }
1467
+ // `beforeInitialFilter` runs while the host may not be attached or laid out
1468
+ // yet, so its width reads 0 and {@link measuredWidth} has to guess from the
1469
+ // window — the one guess that is wrong for a table in a modal. Re-evaluate
1470
+ // once after the first render, when the real width is available.
1471
+ afterNextRender(() => this.onHostResize());
1472
+ // The `stable` layout has to let the browser lay the table out automatically
1473
+ // once before it can capture the result. This runs after every render because
1474
+ // the first render usually has no rows yet (a server fetch is still in flight);
1475
+ // the guards below make it a no-op until real rows are on screen, and the
1476
+ // pinned widths then stop it from measuring again.
1477
+ afterEveryRender(() => {
1478
+ if (this.layoutMode !== 'stable')
1479
+ return;
1480
+ if (this.widthsPinned || this.isLoadingState)
1481
+ return;
1482
+ if (this.paginatedItems.length === 0)
1483
+ return;
1484
+ this.pinColumnWidths();
1485
+ });
1486
+ }
1487
+ /**
1488
+ * Classes for the `<table>` element. `table-fixed` is added once column widths
1489
+ * are no longer allowed to follow the content: always for the `fixed` layout, and
1490
+ * for `stable` from the moment its widths have been measured and pinned.
1491
+ */
1492
+ get tableClasses() {
1493
+ return this.widthsArePinned ? `${this.baseTableClasses} table-fixed` : this.baseTableClasses;
1494
+ }
1495
+ /** Page size to use at/above the `md` breakpoint (consumer's pageSize, or the user's selection). */
1496
+ desktopPageSize = 10;
1497
+ /** Label for the summary's expand/collapse control. */
1498
+ get selectionSummaryToggleLabel() {
1499
+ const labels = this.dataSource.selectionSummaryLabels;
1500
+ if (this.selectionSummaryExpanded) {
1501
+ return this.resolveLabel(labels?.showLessKey, 'mnCollection.showLess', labels?.showLess ?? 'Show less');
1502
+ }
1503
+ const template = this.resolveLabel(labels?.showMoreKey, 'mnCollection.showMore', labels?.showMore ?? '+{{count}} more');
1504
+ return template.replace('{{count}}', String(this.hiddenSelectionCount));
1505
+ }
1506
+ /** Placeholder and accessible name for the search box. */
1507
+ get searchPlaceholderLabel() {
1508
+ return this.resolveLabel(this.dataSource.searchPlaceholderKey, 'mnCollection.search', this.dataSource.searchPlaceholder ?? 'Search...');
1509
+ }
1510
+ /** Screen-reader-only header text of the selection column, so that column is never nameless. */
1511
+ get selectionColumnLabel() {
1512
+ return this.resolveLabel(undefined, 'mnCollection.selectionColumn', 'Selection');
1513
+ }
1514
+ /** Accessible name for the scrollable table region. */
1515
+ get tableRegionLabel() {
1516
+ return this.resolveLabel(this.dataSource.ariaLabel, 'mnCollection.dataTable', 'Data table');
1517
+ }
1518
+ /**
1519
+ * Fewer tags once the table is narrow. A tag holding a person's full name takes
1520
+ * a whole line at phone width, so the eight that read as a compact header on a
1521
+ * wide table become eight stacked lines in a modal sheet — the summary then
1522
+ * occupies more of the screen than the rows it is summarising.
1523
+ *
1524
+ * Reuses {@link filtersCollapsed} rather than measuring again: it is already
1525
+ * maintained on every resize and means exactly "this table is under 640px".
1526
+ * The heading still states the true total, so the hidden tags cost no information.
1527
+ */
1528
+ get defaultSelectionSummaryLimit() {
1529
+ return this.filtersCollapsed ? 5 : 8;
1530
+ }
1531
+ /** Tracks the desktop page size when the user picks one (selector only shows at >= md). */
1532
+ onPageSizeChange(newSize) {
1533
+ this.desktopPageSize = newSize;
1534
+ super.onPageSizeChange(newSize);
1535
+ }
1536
+ /** The effective column-width strategy, defaulting to `stable`. */
1537
+ get layoutMode() {
1538
+ return this.dataSource.appearance?.layout ?? 'stable';
1539
+ }
1540
+ /**
1541
+ * Whether column widths have stopped following the cell content — `fixed` always,
1542
+ * `stable` once {@link pinColumnWidths} has captured them. Drives `table-fixed`
1543
+ * and the cell truncation together, so a cell is never clipped while the column
1544
+ * it sits in could still have grown to fit it.
1545
+ */
1546
+ get widthsArePinned() {
1547
+ return this.layoutMode === 'fixed' || (this.layoutMode === 'stable' && this.widthsPinned);
1548
+ }
1549
+ /** Any / Yes / No options for a boolean column filter. */
1550
+ getBooleanFilterOptions(column) {
1551
+ const labels = this.dataSource.filterLabels;
1552
+ return [
1553
+ {
1554
+ label: column.filterPlaceholder ?? this.resolveLabel(labels?.anyKey, 'mnCollection.filterAny', labels?.any ?? 'Any'),
1555
+ value: ''
1556
+ },
1557
+ { label: this.resolveLabel(labels?.yesKey, 'mnCollection.filterYes', labels?.yes ?? 'Yes'), value: 'true' },
1558
+ { label: this.resolveLabel(labels?.noKey, 'mnCollection.filterNo', labels?.no ?? 'No'), value: 'false' },
1559
+ ];
1560
+ }
1561
+ /**
1562
+ * The width to render for a column: the consumer's own declared width always
1563
+ * wins, then a width pinned by the `stable` layout, otherwise none.
1564
+ * @param column The column being rendered.
1565
+ * @returns A CSS width, or `null` to leave it to the layout algorithm.
1566
+ */
1567
+ columnWidth(column) {
1568
+ return column.width ?? this.pinnedWidths.get(column.key) ?? null;
1569
+ }
1570
+ /**
1571
+ * The `title` tooltip for a cell, so text truncated by a pinned column stays
1572
+ * readable. Only string cells have text to expose; template cells render their
1573
+ * own markup and are left alone.
1574
+ * @param column The column being rendered.
1575
+ * @param row The row being rendered.
1576
+ * @returns The full cell text, or `null` when there is nothing to expose.
1577
+ */
1578
+ cellTitle(column, row) {
1579
+ if (!this.widthsArePinned || typeof column.cell !== 'function')
1580
+ return null;
1581
+ return column.cell(row) || null;
1582
+ }
1583
+ /**
1584
+ * Falls back to the first column that renders a plain string, which is almost
1585
+ * always the name-like column a person would use to identify the row. Template
1586
+ * columns are skipped: they render markup this cannot flatten to a tag label.
1587
+ * @param row The selected row.
1588
+ * @returns The label, or null when every column renders a template.
1589
+ */
1590
+ defaultSelectionLabel(row) {
1591
+ for (const column of this.dataSource.columns) {
1592
+ if (typeof column.cell !== 'function')
1593
+ continue;
1594
+ const value = column.cell(row);
1595
+ if (value)
1596
+ return value;
1597
+ }
1598
+ return null;
1599
+ }
1600
+ /**
1601
+ * Resolves table-specific translation keys (column headers/filters) plus the
1602
+ * shared keys handled by the base.
1603
+ */
1604
+ resolveTranslationKeys() {
1605
+ super.resolveTranslationKeys();
1606
+ for (const col of this.dataSource.columns) {
1607
+ if (col.headerKey) {
1608
+ col.header = this.lang.t(col.headerKey);
1609
+ }
1610
+ if (col.filterPlaceholderKey) {
1611
+ col.filterPlaceholder = this.lang.t(col.filterPlaceholderKey);
1612
+ }
1613
+ // Row actions are deliberately not pre-resolved here: `rowActionLabel` translates
1614
+ // at render time (a locale change calls markForCheck, so the next pass picks the
1615
+ // new text up), which keeps a per-row `label`/`labelKey` accessor intact instead
1616
+ // of being flattened to one string for every row.
1617
+ }
1618
+ if (this.dataSource.filtersLabelKey) {
1619
+ this.dataSource.filtersLabel = this.lang.t(this.dataSource.filtersLabelKey);
1620
+ }
1621
+ if (this.dataSource.clearFiltersLabelKey) {
1622
+ this.dataSource.clearFiltersLabel = this.lang.t(this.dataSource.clearFiltersLabelKey);
1623
+ }
1624
+ this.resolveFilterLabelKeys();
1625
+ this.resolveSelectionSummaryKeys();
1626
+ }
1627
+ applyFilter(searchForItems) {
1628
+ let items = this.applySearchFilter(this.dataSource.dataRows.value ?? []);
1629
+ // Per-column filters. Skipped entirely when the consumer owns filtering: the
1630
+ // rows already are the filtered set, and re-filtering them locally would
1631
+ // narrow the current page a second time.
1632
+ if (!this.isServerFiltered) {
1633
+ for (const col of this.dataSource.columns) {
1634
+ const filterValue = this.columnFilters[col.key];
1635
+ if (!col.filterable || !isFilterValueActive(filterValue))
1636
+ continue;
1637
+ items = items.filter(row => matchesColumnFilter(col, row, filterValue));
1638
+ }
1639
+ }
1640
+ items = this.applySorting(items);
1641
+ this.filteredItems = items;
1642
+ this.applyPagination();
1643
+ if (searchForItems) {
1644
+ this.loadMoreRows();
1645
+ }
1646
+ }
1647
+ /**
1648
+ * Re-evaluate on a window resize too. The ResizeObserver covers every change to
1649
+ * the table's own box, but {@link isMobileViewport} reads the window, which can
1650
+ * change without the table's width following it (a fixed-width table, a modal
1651
+ * pinned to a max width).
1652
+ */
1653
+ onWindowResize() {
1654
+ this.onHostResize();
1655
+ }
1656
+ /** Re-evaluate responsive page size and filter layout when the table is resized. */
1657
+ onHostResize() {
1658
+ // Pixel widths captured for the old box are meaningless in the new one.
1659
+ this.unpinColumnWidths();
1660
+ this.applyResponsivePageSize(true);
1661
+ this.updateFilterLayout(true);
1662
+ }
1663
+ /**
1664
+ * Captures the current, automatically-derived width of every visible column and
1665
+ * pins it, which flips the table to `table-fixed` on the next render.
1666
+ *
1667
+ * Runs only with real rows on screen: measuring the loading skeletons would pin
1668
+ * the placeholder bars' widths rather than the data's. Hidden columns
1669
+ * ({@link ColumnBase.hiddenBelow}) measure 0 and are skipped, so they are free to
1670
+ * size themselves if a resize later reveals them.
1671
+ *
1672
+ * The **widest** column is measured but deliberately left unpinned, so it absorbs
1673
+ * whatever space the pinned ones leave over. Pinning every column instead makes the
1674
+ * widths sum to slightly more than the container — `border-collapse` shares borders
1675
+ * between neighbours, so rounding each cell's measured width over-counts them — and
1676
+ * the table then overflows into a spurious horizontal scrollbar. Leaving one column
1677
+ * elastic also means a later resize squeezes the widest column first instead of
1678
+ * clipping every column equally.
1679
+ */
1680
+ pinColumnWidths() {
1681
+ const headerCells = this.host.nativeElement.querySelectorAll('thead tr:first-child th[data-column-key]');
1682
+ const measured = [];
1683
+ for (const cell of Array.from(headerCells)) {
1684
+ const key = cell.dataset['columnKey'];
1685
+ const width = cell.getBoundingClientRect().width;
1686
+ // A width of 0 means the column is hidden at this container width.
1687
+ if (!key || width <= 0)
1688
+ continue;
1689
+ measured.push({ key, width });
1690
+ }
1691
+ if (measured.length === 0)
1692
+ return;
1693
+ const widest = measured.reduce((a, b) => (b.width > a.width ? b : a));
1694
+ const pinned = new Map();
1695
+ for (const { key, width } of measured) {
1696
+ if (key === widest.key)
1697
+ continue;
1698
+ pinned.set(key, `${Math.round(width)}px`);
1699
+ }
1700
+ this.pinnedWidths = pinned;
1701
+ this.widthsPinned = true;
1702
+ // Pinning changes row heights: cells stop wrapping and start truncating, so a
1703
+ // full page becomes shorter than it was during the automatic pass. The reserved
1704
+ // full-page floor was measured against those taller rows and would otherwise
1705
+ // hold the body open, leaving dead space between the last row and the paginator.
1706
+ this.invalidatePageHeight();
1707
+ this.cdr.markForCheck();
1708
+ }
1709
+ /**
1710
+ * Drops the pinned widths so the next render with rows re-measures them. Called
1711
+ * when the table is resized: the old pixel widths were shares of a box that no
1712
+ * longer exists, and a resize is also what makes `hiddenBelow` columns come and
1713
+ * go, changing which columns need a share at all.
1714
+ */
1715
+ unpinColumnWidths() {
1716
+ if (!this.widthsPinned)
1717
+ return;
1718
+ this.pinnedWidths = new Map();
1719
+ this.widthsPinned = false;
1720
+ // Row heights are about to change back; the floor measured for the pinned
1721
+ // layout does not describe the automatic one.
1722
+ this.invalidatePageHeight();
1723
+ }
1724
+ // ── Template helpers ──
1725
+ getCellValue(column, row) {
1726
+ if (typeof column.cell === 'function')
1727
+ return column.cell(row);
1728
+ return '';
1729
+ }
1730
+ /** Returns the small-screen cell value for a column with cellSm defined. */
1731
+ getCellSmValue(column, row) {
1732
+ if (column.cellSm && typeof column.cellSm.cell === 'function')
1733
+ return column.cellSm.cell(row);
1734
+ return '';
1735
+ }
1736
+ // ── Row actions ──
1737
+ /** The actions visible for a given row — those whose `hidden(row)` is not true. */
1738
+ visibleRowActions(column, row) {
1739
+ return (column.actions ?? []).filter(action => !(action.hidden?.(row) ?? false));
1740
+ }
1741
+ /** Whether a row has any visible actions at all; when false its cell is left empty. */
1742
+ hasRowActions(column, row) {
1743
+ return this.visibleRowActions(column, row).length > 0;
1744
+ }
1745
+ /**
1746
+ * Whether a row's actions fold into the ⋯ menu below 450px. They do unless the row has
1747
+ * exactly one visible action that renders as a bare icon: that button is narrower than the
1748
+ * ⋯ trigger it would hide behind, so collapsing it only puts a second tap in front of the
1749
+ * one command the row has.
1750
+ */
1751
+ collapsesRowActions(column, row) {
1752
+ const visible = this.visibleRowActions(column, row);
1753
+ if (visible.length !== 1)
1754
+ return true;
1755
+ const [only] = visible;
1756
+ return this.showActionLabel(column, only, row);
1757
+ }
1758
+ /**
1759
+ * Resolves a {@link MnRowValue}: either the fixed value, or the accessor applied to
1760
+ * the row. Every per-row presentation field goes through here so the fixed and derived
1761
+ * forms can never drift apart.
1762
+ */
1763
+ resolveRowValue(value, row) {
1764
+ return typeof value === 'function' ? value(row) : value;
1765
+ }
1766
+ /** The resolved label for an inline action button (translation key wins once resolved). */
1767
+ rowActionLabel(action, row) {
1768
+ const labelKey = this.resolveRowValue(action.labelKey, row);
1769
+ if (labelKey)
1770
+ return this.lang.t(labelKey);
1771
+ return this.resolveRowValue(action.label, row) ?? '';
1772
+ }
1773
+ /** The resolved leading icon for an action on a given row, if it has one. */
1774
+ rowActionIcon(action, row) {
1775
+ return this.resolveRowValue(action.icon, row);
1776
+ }
1777
+ /** Whether an inline action button should render its icon. */
1778
+ showActionIcon(column, action, row) {
1779
+ return (column.actionsInline ?? 'both') !== 'label' && !!this.rowActionIcon(action, row);
1780
+ }
1781
+ /**
1782
+ * Whether an inline action button should render its text label. In `'icon'` mode the
1783
+ * label is hidden — unless the action has no icon, in which case it is shown anyway so
1784
+ * the button is never blank.
1785
+ */
1786
+ showActionLabel(column, action, row) {
1787
+ if ((column.actionsInline ?? 'both') === 'icon')
1788
+ return !this.rowActionIcon(action, row);
1789
+ return true;
1790
+ }
1791
+ /** Whether an action is disabled for the given row. */
1792
+ isRowActionDisabled(action, row) {
1793
+ return action.disabled ? action.disabled(row) : false;
1794
+ }
1795
+ /**
1796
+ * The effective colour for an action, used identically by the inline button and the
1797
+ * collapsed ⋯-menu item so the two never diverge: an explicit `color`, else `'danger'`
1798
+ * for a destructive action, else the default `'primary'`.
1799
+ */
1800
+ rowActionColor(action, row) {
1801
+ return this.resolveRowValue(action.color, row) ?? (action.danger ? 'danger' : 'primary');
1802
+ }
1803
+ /** Invokes an action for a row. */
1804
+ runRowAction(action, row) {
1805
+ action.run(row);
1806
+ }
1807
+ /** A stable, unique element id for a row's actions dropdown (aria wiring). */
1808
+ actionsDropdownId(column, row) {
1809
+ return `mn-table-actions-${column.key}-${this.dataSource.getID(row)}`;
1810
+ }
1811
+ /** Maps a row's visible actions to mn-dropdown commands, binding the row into each. */
1812
+ rowDropdownActions(column, row) {
1813
+ return this.visibleRowActions(column, row).map(action => ({
1814
+ // Per-row values are resolved here, but `labelKey` stays a *key* so the dropdown
1815
+ // keeps re-translating it on a locale change rather than freezing today's text.
1816
+ label: this.resolveRowValue(action.label, row),
1817
+ labelKey: this.resolveRowValue(action.labelKey, row),
1818
+ icon: this.rowActionIcon(action, row),
1819
+ color: this.rowActionColor(action, row),
1820
+ danger: action.danger,
1821
+ disabled: this.isRowActionDisabled(action, row),
1822
+ run: () => action.run(row),
1823
+ }));
1824
+ }
1825
+ trackByKey = (_index, column) => {
1826
+ return column.key;
1827
+ };
1828
+ // ── Table CSS classes ──
1829
+ /** True when the table is narrower than the filter-collapse breakpoint. */
1830
+ isFilterViewport() {
1831
+ return this.measuredWidth() < MnTable.FILTER_COLLAPSE_WIDTH;
1832
+ }
1833
+ /**
1834
+ * True when the **window** is below the `md` (768px) breakpoint.
1835
+ *
1836
+ * Deliberately viewport-based, unlike {@link isFilterViewport}: the forced
1837
+ * mobile page size exists to keep a phone screen scrollable, and it is paired
1838
+ * with the rows-per-page selector that mn-collection-pagination hides at the
1839
+ * same viewport breakpoint. Measuring the table's own width instead would let
1840
+ * the two disagree — a 700px table on a desktop would be pinned to the mobile
1841
+ * row count while still offering the selector that overrides it.
1842
+ */
1843
+ isMobileViewport() {
1844
+ return typeof window !== 'undefined' && window.innerWidth < 768;
1845
+ }
1846
+ /**
1847
+ * The table's own rendered width, which every responsive decision is made
1848
+ * against — the same width the `@container` queries in the template use, so
1849
+ * the TS and CSS halves of the responsive layout can never disagree.
1850
+ *
1851
+ * Falls back to the window width before the host has been laid out (and in
1852
+ * SSR), which is the closest available approximation at that point.
1853
+ * @returns The width in CSS pixels.
1854
+ */
1855
+ measuredWidth() {
1856
+ const width = this.host.nativeElement.getBoundingClientRect().width;
1857
+ if (width > 0)
1858
+ return width;
1859
+ return typeof window === 'undefined' ? Number.MAX_SAFE_INTEGER : window.innerWidth;
1860
+ }
1861
+ /**
1862
+ * Applies the breakpoint-appropriate page size: capped at {@link MOBILE_PAGE_SIZE}
1863
+ * below `md`, the desktop size at/above it. When the size actually changes, client-side tables
1864
+ * re-slice locally and server-side tables ask the consumer to refetch, so the
1865
+ * rendered rows update in every pagination mode (used at init and on window resize).
1866
+ */
1867
+ applyResponsivePageSize(reflow) {
1868
+ const target = this.isMobileViewport()
1869
+ ? Math.min(this.desktopPageSize, MnTable.MOBILE_PAGE_SIZE)
1870
+ : this.desktopPageSize;
1871
+ if (target === this.pageSize)
1872
+ return;
1873
+ this.invalidatePageHeight();
1874
+ this.pageSize = target;
1875
+ this.currentPage = 1;
1876
+ if (this.dataSource.paginationMode === 'client-side-pagination') {
1877
+ this.applyPagination();
1878
+ }
1879
+ else if (this.isServerPaginated) {
1880
+ // Server owns the slice — tell the consumer to refetch with the new size.
1881
+ this.dataSource.onPageSizeChange?.(target);
1882
+ }
1883
+ if (reflow)
1884
+ this.cdr.markForCheck();
1885
+ }
1886
+ get totalColumnCount() {
1887
+ let count = this.dataSource.columns.length;
1888
+ if (this.hasSelection)
1889
+ count++;
1890
+ return count;
1891
+ }
1892
+ // ── Skeleton ──
1893
+ /**
1894
+ * Hands the active filters to the consumer. Locks the body height first so the
1895
+ * skeleton swap during the refetch can't collapse the layout, matching
1896
+ * {@link goToPage} and {@link onSearch}.
1897
+ */
1898
+ emitServerFilters() {
1899
+ this.lockBodyHeight();
1900
+ this.dataSource.onColumnFilterChange?.(this.activeColumnFilters);
1901
+ }
1902
+ /** Resets every filterable column to its type's empty value. */
1903
+ seedFilterValues() {
1904
+ for (const col of this.dataSource.columns) {
1905
+ if (col.filterable) {
1906
+ this.columnFilters[col.key] = emptyFilterValue(this.filterTypeOf(col));
1907
+ }
1908
+ }
1909
+ }
1910
+ // ── Filtering & sorting ──
1911
+ /**
1912
+ * Resolves the selection-summary labels from their translation keys. Resolved
1913
+ * without params so the `{{count}}` / `{{label}}` placeholders survive for the
1914
+ * getters to fill in per render.
1915
+ */
1916
+ resolveSelectionSummaryKeys() {
1917
+ const labels = this.dataSource.selectionSummaryLabels;
1918
+ if (!labels)
1919
+ return;
1920
+ if (labels.titleKey)
1921
+ labels.title = this.lang.t(labels.titleKey);
1922
+ if (labels.clearAllKey)
1923
+ labels.clearAll = this.lang.t(labels.clearAllKey);
1924
+ if (labels.removeKey)
1925
+ labels.remove = this.lang.t(labels.removeKey);
1926
+ if (labels.showMoreKey)
1927
+ labels.showMore = this.lang.t(labels.showMoreKey);
1928
+ if (labels.showLessKey)
1929
+ labels.showLess = this.lang.t(labels.showLessKey);
1930
+ }
1931
+ /** Resolves the range / boolean filter control labels from their translation keys. */
1932
+ resolveFilterLabelKeys() {
1933
+ const labels = this.dataSource.filterLabels;
1934
+ if (!labels)
1935
+ return;
1936
+ const pairs = [
1937
+ ['anyKey', 'any'], ['yesKey', 'yes'], ['noKey', 'no'], ['selectedKey', 'selected'],
1938
+ ];
1939
+ for (const [keyProp, labelProp] of pairs) {
1940
+ const key = labels[keyProp];
1941
+ if (key)
1942
+ labels[labelProp] = this.lang.t(key);
1943
+ }
1944
+ }
1945
+ applySorting(items) {
1946
+ if (!this.currentSort)
1947
+ return items;
1948
+ const column = this.dataSource.columns.find(c => c.key === this.currentSort.columnKey);
1949
+ if (!column || !column.sortType || column.sortType === ColumnSortType.NONE)
1950
+ return items;
1951
+ const getValue = column.getRawValueToSort ?? ((row) => {
1952
+ if (typeof column.cell === 'function')
1953
+ return column.cell(row);
1954
+ return '';
1955
+ });
1956
+ const dir = this.currentSort.direction === 'asc' ? 1 : -1;
1957
+ return [...items].sort((a, b) => {
1958
+ const va = getValue(a);
1959
+ const vb = getValue(b);
1960
+ if (va == null && vb == null)
1961
+ return 0;
1962
+ if (va == null)
1963
+ return 1;
1964
+ if (vb == null)
1965
+ return -1;
1966
+ switch (column.sortType) {
1967
+ case ColumnSortType.ALPHABETICAL:
1968
+ return String(va).localeCompare(String(vb)) * dir;
1969
+ case ColumnSortType.NUMERICAL:
1970
+ return (Number(va) - Number(vb)) * dir;
1971
+ case ColumnSortType.DATE:
1972
+ return (new Date(va).getTime() - new Date(vb).getTime()) * dir;
1973
+ default:
1974
+ return 0;
1975
+ }
1976
+ });
1977
+ }
1978
+ /** Filter options formatted for mn-select for a given column. */
1979
+ getFilterSelectOptions(column) {
1980
+ const placeholder = column.filterPlaceholder ?? this.resolveLabel(undefined, 'mnCollection.filterAll', 'All');
1981
+ return [
1982
+ { label: placeholder, value: '' },
1983
+ ...(column.filterOptions ?? []).map(opt => ({ label: opt.label, value: String(opt.value) })),
1984
+ ];
1985
+ }
1986
+ /**
1987
+ * Accessible label for a tag's remove button.
1988
+ * @param row The row the tag stands for.
1989
+ * @returns The label, naming the row so screen readers announce which one goes.
1990
+ */
1991
+ selectionRemoveLabel(row) {
1992
+ const labels = this.dataSource.selectionSummaryLabels;
1993
+ const template = this.resolveLabel(labels?.removeKey, 'mnCollection.removeSelected', labels?.remove ?? 'Remove {{label}}');
1994
+ return template.replace('{{label}}', this.selectionLabelFor(row));
1995
+ }
1996
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTable, deps: [], target: i0.ɵɵFactoryTarget.Component });
1997
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnTable, isStandalone: true, selector: "mn-table", outputs: { sortChange: "sortChange", rowClick: "rowClick" }, host: { listeners: { "window:resize": "onWindowResize()" }, classAttribute: "block" }, viewQueries: [{ propertyName: "filtersSheet", first: true, predicate: ["filtersSheet"], descendants: true }, { propertyName: "collectionBody", first: true, predicate: ["collectionBody"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<!-- Everything that reflows lives inside a @container, so the breakpoints below\n measure the table's own width rather than the window's. A table in a modal,\n a sidebar or a narrow grid cell is far narrower than the viewport, and\n viewport breakpoints would hand it a desktop layout it has no room for. -->\n<div class=\"@container\">\n <!-- Selection summary: the whole selection, never paged, filtered or sorted. The\n table below answers \"what could I pick?\", which is why it is searched and paged;\n this answers \"what did I pick?\", which a paginated list cannot without hiding\n most of the answer on some other page. -->\n @if (showSelectionSummary) {\n <div class=\"flex flex-col gap-2 rounded-md border border-base-300 bg-base-200/50 p-3 mb-3\">\n <div class=\"flex items-center justify-between gap-2\">\n <span class=\"text-sm font-medium text-base-content\">{{ selectionSummaryTitle }}</span>\n <button\n (click)=\"clearSelection()\"\n [data]=\"{ variant: 'text', color: 'gray', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"gap-1 shrink-0\"\n mnButton\n type=\"button\"\n >\n <svg [size]=\"14\" [lucideIcon]=\"icons.X\"></svg>\n <span>{{ selectionClearAllLabel }}</span>\n </button>\n </div>\n <!-- Only the first few tags render; the rest collapse behind a \"+N more\" control.\n The heading's count always states the true total, so this hides tags, never\n information. Expanded, the list is height-capped and scrolls, so even a\n selection of hundreds cannot push the table off screen. -->\n <ul\n [class.max-h-28]=\"selectionSummaryExpanded\"\n [class.overflow-y-auto]=\"selectionSummaryExpanded\"\n class=\"flex flex-wrap gap-1.5 list-none m-0 p-0\"\n >\n @for (row of visibleSelectionRows; track dataSource.getID(row)) {\n <li\n class=\"inline-flex items-center gap-1 rounded-full bg-base-100 border border-base-300 pl-2.5 pr-1 py-0.5 text-xs text-base-content max-w-full\">\n <span [attr.title]=\"selectionLabelFor(row)\" class=\"truncate\">{{ selectionLabelFor(row) }}</span>\n <button\n (click)=\"removeSelection(row)\"\n [attr.aria-label]=\"selectionRemoveLabel(row)\"\n class=\"shrink-0 rounded-full p-0.5 hover:bg-base-300 transition-colors cursor-pointer\"\n type=\"button\"\n >\n <svg [size]=\"12\" [lucideIcon]=\"icons.X\"></svg>\n </button>\n </li>\n }\n @if (hiddenSelectionCount > 0 || selectionSummaryExpanded) {\n <li>\n <button\n (click)=\"toggleSelectionSummary()\"\n [attr.aria-expanded]=\"selectionSummaryExpanded\"\n [data]=\"{ variant: 'text', color: 'primary', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"text-xs\"\n mnButton\n type=\"button\"\n >\n {{ selectionSummaryToggleLabel }}\n </button>\n </li>\n }\n </ul>\n </div>\n }\n\n <!-- Toolbar: custom toolbar template + search. Only rendered when it has content,\n so an unsearchable table without toolbar templates emits no empty spacer. -->\n@if (isSearchable || dataSource.toolbarLeftTemplate || dataSource.toolbarRightTemplate || (hasColumnFilters && filtersCollapsed)) {\n <div class=\"flex flex-col @min-[420px]:flex-row @min-[420px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full @min-[420px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full @min-[420px]:w-auto @min-[420px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col @min-[420px]:flex-row @min-[420px]:items-center gap-2 w-full @min-[420px]:flex-1 @min-[560px]:flex-none @min-[560px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box belongs to the\n table's chrome, not to whatever form the table happens to sit in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n class=\"w-full @min-[420px]:flex-1 @min-[560px]:max-w-64\"\n [props]=\"{\n id: 'mn-table-search',\n type: 'search',\n label: '',\n ariaLabel: searchPlaceholderLabel,\n placeholder: searchPlaceholderLabel,\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n [ngModel]=\"searchValue\"\n (ngModelChange)=\"onSearch($event)\"\n ></mn-lib-input-field>\n }\n @if (dataSource.toolbarRightTemplate) {\n <div class=\"flex flex-col w-full @min-[420px]:w-auto @min-[420px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarRightTemplate\"></ng-container>\n </div>\n }\n <!-- Small-screen filter toggle: replaces the inline per-column filter row below 640px -->\n @if (hasColumnFilters && filtersCollapsed) {\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'outline', color: 'primary', size: 'md', borderRadius: 'md', hover: true }\"\n class=\"w-full @min-[420px]:w-auto gap-1.5\"\n [attr.aria-expanded]=\"filtersPanelOpen\"\n aria-controls=\"mn-table-filters-panel\"\n (click)=\"openFiltersPanel()\"\n >\n <svg [lucideIcon]=\"icons.Funnel\" [size]=\"15\"></svg>\n <span>{{ filtersButtonLabel }}</span>\n </button>\n }\n </div>\n</div>\n}\n\n<!-- Small-screen filters: full-width fields decoupled from column widths, presented\n as a bottom sheet so they overlay rather than push the table down. -->\n@if (hasColumnFilters && filtersCollapsed && filtersPanelOpen) {\n <mn-bottom-sheet\n #filtersSheet\n (dismiss)=\"filtersPanelOpen = false\"\n [ariaLabel]=\"filtersButtonLabel\"\n [growWithKeyboard]=\"true\"\n [maxHeightVh]=\"80\"\n >\n <div id=\"mn-table-filters-panel\" class=\"flex flex-col gap-3 px-4 pb-4\">\n <span class=\"text-base font-semibold text-base-content\">{{ filtersButtonLabel }}</span>\n @for (column of dataSource.columns; track column.key) {\n @if (column.filterable) {\n <div class=\"flex flex-col gap-1\">\n <label\n class=\"text-xs font-medium text-base-content/70\"\n [attr.for]=\"'mn-table-filter-panel-' + column.key\"\n >\n @if (isTemplateRef(column.header)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.header)\"></ng-container>\n } @else {\n {{ headerText(column) }}\n }\n </label>\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: column, idScope: 'panel' }\"\n [ngTemplateOutlet]=\"filterField\"\n ></ng-container>\n </div>\n }\n }\n @if (hasActiveFilters) {\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'text', color: 'gray', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"self-start gap-1\"\n (click)=\"clearAllFilters()\"\n >\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n <span>{{ clearFiltersButtonLabel }}</span>\n </button>\n }\n <div class=\"mt-1 flex min-[400px]:justify-end\">\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'fill', color: 'primary', size: 'md', borderRadius: 'md', hover: true }\"\n class=\"w-full min-[400px]:w-auto\"\n (click)=\"closeFiltersPanel()\"\n >\n <span>{{ filtersCloseLabel }}</span>\n </button>\n </div>\n </div>\n </mn-bottom-sheet>\n}\n\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<!-- Table wrapper with horizontal scroll -->\n <div #collectionBody [attr.aria-busy]=\"isLoadingState || null\" [attr.aria-label]=\"tableRegionLabel\" [style.min-height.px]=\"bodyMinHeight\"\n class=\"overflow-x-auto\"\n role=\"region\">\n <table [class]=\"tableClasses\">\n <thead>\n <tr class=\"bg-base-100\">\n <!-- Selection column header. It always carries a screen-reader-only name: a single-select\n table has nothing else in this cell, and a multi-select one only a checkbox, so\n without it the column is announced as a nameless header (axe empty-table-header). -->\n @if (hasSelection) {\n <th class=\"w-10 text-center text-sm px-2 py-2\">\n <span class=\"sr-only\">{{ selectionColumnLabel }}</span>\n @if (isMultiSelect) {\n <mn-lib-checkbox\n (checkedChange)=\"toggleAll()\"\n [checked]=\"allSelected\"\n [props]=\"{ id: 'mn-table-select-all', size: 'sm' }\"\n ></mn-lib-checkbox>\n }\n </th>\n }\n\n <!-- Data columns -->\n @for (column of dataSource.columns; track column.key) {\n <th\n [attr.data-column-key]=\"column.key\"\n [class.truncate]=\"widthsArePinned\"\n [class.cursor-pointer]=\"isSortable(column)\"\n [class.select-none]=\"isSortable(column)\"\n [class.hover:bg-base-200]=\"isSortable(column)\"\n [class.text-left]=\"(column.align ?? 'left') === 'left'\"\n [class.text-center]=\"column.align === 'center'\"\n [class.text-right]=\"column.align === 'right'\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n [attr.aria-sort]=\"currentSort?.columnKey === column.key ? (currentSort!.direction === 'asc' ? 'ascending' : 'descending') : null\"\n class=\"text-sm px-2 py-1 @min-[640px]:px-4 @min-[640px]:py-2 whitespace-nowrap\"\n (click)=\"sort(column)\"\n >\n <!-- The header content is declared once; a sortable column wraps it in a real button so\n the sort is reachable by keyboard. The button's click stops there, so the th's own\n click (which keeps the cell padding clickable) does not sort a second time. -->\n <ng-template #headerContent>\n @if (isTemplateRef(column.header)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.header)\"></ng-container>\n } @else {\n <span>{{ headerText(column) }}</span>\n }\n @if (isSortable(column)) {\n <span class=\"text-[0.65rem] opacity-70 min-w-3 inline-block\" aria-hidden=\"true\">{{ getSortIcon(column) }}</span>\n }\n </ng-template>\n @if (isSortable(column)) {\n <button type=\"button\" class=\"inline-flex items-center gap-1 cursor-pointer\" (click)=\"$event.stopPropagation(); sort(column)\">\n <ng-container [ngTemplateOutlet]=\"headerContent\"></ng-container>\n </button>\n } @else {\n <span class=\"inline-flex items-center gap-1\">\n <ng-container [ngTemplateOutlet]=\"headerContent\"></ng-container>\n </span>\n }\n </th>\n }\n\n </tr>\n\n <!-- Per-column filter row (wide screens only; collapses into a panel below 640px).\n The cells are `td`, not `th`: they hold form controls, not headings, and a\n column without a filter would otherwise be an empty header, which assistive tech\n announces as a nameless column (axe `empty-table-header`). `font-normal` stays\n so a consumer's thead styling cannot make the controls bold. -->\n @if (hasColumnFilters && !filtersCollapsed) {\n <tr class=\"bg-base-100 border-b border-base-300 font-normal\">\n @if (hasSelection) {\n <td class=\"px-2 py-1 font-normal\"></td>\n }\n @for (column of dataSource.columns; track column.key) {\n <td\n class=\"px-4 py-2 font-normal\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n >\n @if (column.filterable) {\n <!-- Every filter renders as an ordinary control right under its\n header. The rich types used to hide behind a button that opened\n a floating panel, which cost a click to discover, a click to\n apply, and hid whether a column was even filterable. -->\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: column, idScope: 'inline' }\"\n [ngTemplateOutlet]=\"filterField\"\n ></ng-container>\n }\n </td>\n }\n </tr>\n }\n </thead>\n\n <tbody>\n <!-- Loading state -->\n @if (isLoadingState) {\n @for (_ of skeletonRows; track $index) {\n <tr>\n @if (hasSelection) {\n <td class=\"px-2 py-3\">\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '1rem', height: '1rem' }\"></mn-skeleton>\n </td>\n }\n @for (column of dataSource.columns; track column.key) {\n <td class=\"px-4 py-3\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n >\n @if (isTemplateRef(column.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.skeleton)\"></ng-container>\n } @else {\n <mn-skeleton [data]=\"getColumnSkeletonData(column)\"></mn-skeleton>\n }\n </td>\n }\n </tr>\n }\n } @else if (isErrorState) {\n <!-- Error state -->\n <tr class=\"bg-base-100\">\n <td [attr.colspan]=\"totalColumnCount\" class=\"text-center text-xs py-8\">\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-error\">\n <p class=\"text-sm\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n </td>\n </tr>\n } @else {\n <!-- Empty state -->\n @if (filteredItems.length === 0) {\n <tr class=\"bg-base-100\">\n <td [attr.colspan]=\"totalColumnCount\" class=\"text-center text-xs py-8\">\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-base-content/50\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n </td>\n </tr>\n }\n\n <!-- Data rows -->\n @for (row of paginatedItems; track trackByID($index, row); let odd = $odd; let last = $last) {\n <tr\n class=\"bg-base-100 transition-colors duration-150 hover:cursor-pointer\"\n [ngClass]=\"{'bg-primary/10': isSelected(row)}\"\n [class.bg-base-200]=\"!isSelected(row) && odd && dataSource.appearance?.striped\"\n [class.hover:bg-base-200]=\"dataSource.appearance?.hover !== false\"\n [class.cursor-pointer]=\"!!dataSource.onRowClick\"\n [class.border-b]=\"!last\"\n [class.border-base-300]=\"!last\"\n [class.border-b-1]=\"last\"\n [class.border-black]=\"last\"\n [class.shadow-3xl]=\"last\"\n (click)=\"onRowClick(row)\"\n >\n <!-- Selection checkbox -->\n @if (hasSelection) {\n <td (click)=\"$event.stopPropagation()\" class=\"w-10 text-center px-2 py-2\">\n <mn-lib-checkbox\n (checkedChange)=\"toggle(row)\"\n [checked]=\"isSelected(row)\"\n [props]=\"{ id: 'mn-table-row-' + $index, size: 'sm' }\"\n ></mn-lib-checkbox>\n </td>\n }\n\n <!-- Data cells -->\n @for (column of dataSource.columns; track column.key) {\n <td\n [attr.title]=\"cellTitle(column, row)\"\n [class.text-left]=\"(column.align ?? 'left') === 'left'\"\n [class.text-center]=\"column.align === 'center'\"\n [class.text-right]=\"column.align === 'right'\"\n [class.truncate]=\"widthsArePinned\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n class=\"text-xs px-2 py-1 @min-[640px]:px-4 @min-[640px]:py-2\"\n >\n @if (column.actions) {\n <!-- Actions column: inline command buttons that collapse into a \u22EF menu\n once the table is narrower than 450px (container query), for every\n row with actions. A row with no visible actions renders nothing.\n A row with a single icon-only action never collapses: one icon button\n is narrower than the \u22EF trigger it would hide behind, so folding it\n only costs a tap. -->\n @if (hasRowActions(column, row)) {\n <div class=\"inline-flex items-center gap-1\"\n [class.justify-end]=\"(column.align ?? 'left') === 'right'\">\n @if (collapsesRowActions(column, row)) {\n <span class=\"hidden items-center gap-1 @min-[450px]:inline-flex\">\n <ng-container [ngTemplateOutletContext]=\"{ column: column, row: row }\"\n [ngTemplateOutlet]=\"actionButtons\"></ng-container>\n </span>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <span class=\"@min-[450px]:hidden\" (click)=\"$event.stopPropagation()\">\n <mn-lib-dropdown [datasource]=\"{\n id: actionsDropdownId(column, row),\n actions: rowDropdownActions(column, row),\n menuLabel: headerText(column),\n size: 'sm'\n }\"></mn-lib-dropdown>\n </span>\n } @else {\n <span class=\"inline-flex items-center gap-1\">\n <ng-container [ngTemplateOutletContext]=\"{ column: column, row: row }\"\n [ngTemplateOutlet]=\"actionButtons\"></ng-container>\n </span>\n }\n </div>\n }\n } @else if (column.cellSm) {\n <!-- Default cell: hidden below the cellSm breakpoint -->\n <span [mnShowAbove]=\"column.cellSm.below\">\n @if (isTemplateRef(column.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cell)\"></ng-container>\n } @else {\n {{ getCellValue(column, row) }}\n }\n </span>\n <!-- Small cell: shown only below the cellSm breakpoint -->\n <span [mnShowBelow]=\"column.cellSm.below\">\n @if (isTemplateRef(column.cellSm.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cellSm.cell)\"></ng-container>\n } @else {\n {{ getCellSmValue(column, row) }}\n }\n </span>\n } @else {\n @if (isTemplateRef(column.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cell)\"></ng-container>\n } @else {\n {{ getCellValue(column, row) }}\n }\n }\n </td>\n }\n\n </tr>\n }\n }\n </tbody>\n </table>\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-table\"\n></mn-collection-pagination>\n</div>\n\n<!-- Single source of truth for every filter control, reused by the inline header\n row and the small-screen panel. `idScope` keeps element ids unique across\n both placements. -->\n<ng-template #filterField let-column let-idScope=\"idScope\">\n @switch (filterTypeOf(column)) {\n @case ('select') {\n <mn-lib-select\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"textFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getFilterSelectOptions(column),\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-select>\n }\n @case ('multi-select') {\n <mn-lib-multi-select\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"multiFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getFilterMultiSelectOptions(column),\n placeholder: column.filterPlaceholder ?? '',\n collapsePlaceholder: filterSelectedLabel,\n collapseThreshold: 1,\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-multi-select>\n }\n @case ('boolean') {\n <mn-lib-select\n (ngModelChange)=\"onBooleanFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"booleanFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getBooleanFilterOptions(column),\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-select>\n }\n @default {\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"textFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n type: 'text',\n label: '',\n placeholder: column.filterPlaceholder ?? '',\n ariaLabel: column.filterPlaceholder ?? '',\n autocomplete: column.filterAutocomplete ?? undefined,\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true,\n hover: true\n }\"\n ></mn-lib-input-field>\n }\n }\n</ng-template>\n\n<!-- Inline action buttons for an actions column, shared by the wide-table layout and\n (implicitly) mirrored by the \u22EF menu below 450px. -->\n<ng-template #actionButtons let-column=\"column\" let-row=\"row\">\n @for (action of visibleRowActions(column, row); track $index) {\n <button\n mnButton\n type=\"button\"\n [data]=\"{\n size: 'sm',\n variant: 'text',\n color: rowActionColor(action, row),\n disabled: isRowActionDisabled(action, row)\n }\"\n class=\"cursor-pointer\"\n (click)=\"$event.stopPropagation(); runRowAction(action, row)\"\n [attr.aria-label]=\"rowActionLabel(action, row)\"\n [attr.title]=\"showActionLabel(column, action, row) ? null : rowActionLabel(action, row)\"\n >\n @if (showActionIcon(column, action, row)) {\n <span class=\"inline-flex items-center shrink-0\">\n @let icon = rowActionIcon(action, row);\n @if (isTemplateRef(icon)) {\n <ng-container [ngTemplateOutlet]=\"icon\"></ng-container>\n } @else {\n <!-- Data icon: sized here to match the sm button's text, so a caller can\n declare the action in TypeScript without owning a template. -->\n <svg [lucideIcon]=\"$any(icon)\" [size]=\"17\"></svg>\n }\n </span>\n }\n @if (showActionLabel(column, action, row)) {\n <span>{{ rowActionLabel(action, row) }}</span>\n }\n </button>\n }\n</ng-template>\n", dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: MnCheckbox, selector: "mn-lib-checkbox", inputs: ["props", "checked"], outputs: ["checkedChange"] }, { kind: "directive", type: MnHiddenBelowDirective, selector: "[mnHiddenBelow]", inputs: ["mnHiddenBelow"] }, { kind: "directive", type: MnShowAboveDirective, selector: "[mnShowAbove]", inputs: ["mnShowAbove"] }, { kind: "directive", type: MnShowBelowDirective, selector: "[mnShowBelow]", inputs: ["mnShowBelow"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: MnSelect, selector: "mn-lib-select", inputs: ["props"] }, { kind: "component", type: MnMultiSelect, selector: "mn-lib-multi-select", inputs: ["props"] }, { kind: "component", type: MnDropdown, selector: "mn-lib-dropdown", inputs: ["datasource"] }, { kind: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { 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: "component", type: MnCollectionPagination, selector: "mn-collection-pagination", inputs: ["idPrefix", "isPaginated", "isServerPaginated", "showLoadMore", "loadingMoreRows", "currentPage", "pageSize", "totalPages", "totalItemCount", "visiblePages", "pageSizeSelectOptions", "labels"], outputs: ["loadMore", "pageChange", "pageSizeChange"] }, { kind: "component", type: MnButton, selector: "button[mnButton], a[mnButton]", inputs: ["data"] }, { kind: "component", type: MnBottomSheet, selector: "mn-bottom-sheet", inputs: ["showBackdrop", "showGrabber", "dismissible", "minHeightPx", "maxHeightVh", "containerClass", "ariaLabel", "ariaLabelledby", "growWithKeyboard", "dismissGuard"], outputs: ["dismiss"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1998
+ }
1999
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTable, decorators: [{
2000
+ type: Component,
2001
+ args: [{ selector: 'mn-table', standalone: true, imports: [NgClass, NgTemplateOutlet, MnCheckbox, MnHiddenBelowDirective, MnShowAboveDirective, MnShowBelowDirective, MnInputField, MnSelect, MnMultiSelect, MnDropdown, MnSkeleton, FormsModule, MnCollectionPagination, MnButton, MnBottomSheet, LucideDynamicIcon], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'block' }, template: "<!-- Everything that reflows lives inside a @container, so the breakpoints below\n measure the table's own width rather than the window's. A table in a modal,\n a sidebar or a narrow grid cell is far narrower than the viewport, and\n viewport breakpoints would hand it a desktop layout it has no room for. -->\n<div class=\"@container\">\n <!-- Selection summary: the whole selection, never paged, filtered or sorted. The\n table below answers \"what could I pick?\", which is why it is searched and paged;\n this answers \"what did I pick?\", which a paginated list cannot without hiding\n most of the answer on some other page. -->\n @if (showSelectionSummary) {\n <div class=\"flex flex-col gap-2 rounded-md border border-base-300 bg-base-200/50 p-3 mb-3\">\n <div class=\"flex items-center justify-between gap-2\">\n <span class=\"text-sm font-medium text-base-content\">{{ selectionSummaryTitle }}</span>\n <button\n (click)=\"clearSelection()\"\n [data]=\"{ variant: 'text', color: 'gray', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"gap-1 shrink-0\"\n mnButton\n type=\"button\"\n >\n <svg [size]=\"14\" [lucideIcon]=\"icons.X\"></svg>\n <span>{{ selectionClearAllLabel }}</span>\n </button>\n </div>\n <!-- Only the first few tags render; the rest collapse behind a \"+N more\" control.\n The heading's count always states the true total, so this hides tags, never\n information. Expanded, the list is height-capped and scrolls, so even a\n selection of hundreds cannot push the table off screen. -->\n <ul\n [class.max-h-28]=\"selectionSummaryExpanded\"\n [class.overflow-y-auto]=\"selectionSummaryExpanded\"\n class=\"flex flex-wrap gap-1.5 list-none m-0 p-0\"\n >\n @for (row of visibleSelectionRows; track dataSource.getID(row)) {\n <li\n class=\"inline-flex items-center gap-1 rounded-full bg-base-100 border border-base-300 pl-2.5 pr-1 py-0.5 text-xs text-base-content max-w-full\">\n <span [attr.title]=\"selectionLabelFor(row)\" class=\"truncate\">{{ selectionLabelFor(row) }}</span>\n <button\n (click)=\"removeSelection(row)\"\n [attr.aria-label]=\"selectionRemoveLabel(row)\"\n class=\"shrink-0 rounded-full p-0.5 hover:bg-base-300 transition-colors cursor-pointer\"\n type=\"button\"\n >\n <svg [size]=\"12\" [lucideIcon]=\"icons.X\"></svg>\n </button>\n </li>\n }\n @if (hiddenSelectionCount > 0 || selectionSummaryExpanded) {\n <li>\n <button\n (click)=\"toggleSelectionSummary()\"\n [attr.aria-expanded]=\"selectionSummaryExpanded\"\n [data]=\"{ variant: 'text', color: 'primary', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"text-xs\"\n mnButton\n type=\"button\"\n >\n {{ selectionSummaryToggleLabel }}\n </button>\n </li>\n }\n </ul>\n </div>\n }\n\n <!-- Toolbar: custom toolbar template + search. Only rendered when it has content,\n so an unsearchable table without toolbar templates emits no empty spacer. -->\n@if (isSearchable || dataSource.toolbarLeftTemplate || dataSource.toolbarRightTemplate || (hasColumnFilters && filtersCollapsed)) {\n <div class=\"flex flex-col @min-[420px]:flex-row @min-[420px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full @min-[420px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full @min-[420px]:w-auto @min-[420px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col @min-[420px]:flex-row @min-[420px]:items-center gap-2 w-full @min-[420px]:flex-1 @min-[560px]:flex-none @min-[560px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box belongs to the\n table's chrome, not to whatever form the table happens to sit in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n class=\"w-full @min-[420px]:flex-1 @min-[560px]:max-w-64\"\n [props]=\"{\n id: 'mn-table-search',\n type: 'search',\n label: '',\n ariaLabel: searchPlaceholderLabel,\n placeholder: searchPlaceholderLabel,\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n [ngModel]=\"searchValue\"\n (ngModelChange)=\"onSearch($event)\"\n ></mn-lib-input-field>\n }\n @if (dataSource.toolbarRightTemplate) {\n <div class=\"flex flex-col w-full @min-[420px]:w-auto @min-[420px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarRightTemplate\"></ng-container>\n </div>\n }\n <!-- Small-screen filter toggle: replaces the inline per-column filter row below 640px -->\n @if (hasColumnFilters && filtersCollapsed) {\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'outline', color: 'primary', size: 'md', borderRadius: 'md', hover: true }\"\n class=\"w-full @min-[420px]:w-auto gap-1.5\"\n [attr.aria-expanded]=\"filtersPanelOpen\"\n aria-controls=\"mn-table-filters-panel\"\n (click)=\"openFiltersPanel()\"\n >\n <svg [lucideIcon]=\"icons.Funnel\" [size]=\"15\"></svg>\n <span>{{ filtersButtonLabel }}</span>\n </button>\n }\n </div>\n</div>\n}\n\n<!-- Small-screen filters: full-width fields decoupled from column widths, presented\n as a bottom sheet so they overlay rather than push the table down. -->\n@if (hasColumnFilters && filtersCollapsed && filtersPanelOpen) {\n <mn-bottom-sheet\n #filtersSheet\n (dismiss)=\"filtersPanelOpen = false\"\n [ariaLabel]=\"filtersButtonLabel\"\n [growWithKeyboard]=\"true\"\n [maxHeightVh]=\"80\"\n >\n <div id=\"mn-table-filters-panel\" class=\"flex flex-col gap-3 px-4 pb-4\">\n <span class=\"text-base font-semibold text-base-content\">{{ filtersButtonLabel }}</span>\n @for (column of dataSource.columns; track column.key) {\n @if (column.filterable) {\n <div class=\"flex flex-col gap-1\">\n <label\n class=\"text-xs font-medium text-base-content/70\"\n [attr.for]=\"'mn-table-filter-panel-' + column.key\"\n >\n @if (isTemplateRef(column.header)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.header)\"></ng-container>\n } @else {\n {{ headerText(column) }}\n }\n </label>\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: column, idScope: 'panel' }\"\n [ngTemplateOutlet]=\"filterField\"\n ></ng-container>\n </div>\n }\n }\n @if (hasActiveFilters) {\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'text', color: 'gray', size: 'sm', borderRadius: 'md', hover: true }\"\n class=\"self-start gap-1\"\n (click)=\"clearAllFilters()\"\n >\n <svg [lucideIcon]=\"icons.X\" [size]=\"14\"></svg>\n <span>{{ clearFiltersButtonLabel }}</span>\n </button>\n }\n <div class=\"mt-1 flex min-[400px]:justify-end\">\n <button\n type=\"button\"\n mnButton\n [data]=\"{ variant: 'fill', color: 'primary', size: 'md', borderRadius: 'md', hover: true }\"\n class=\"w-full min-[400px]:w-auto\"\n (click)=\"closeFiltersPanel()\"\n >\n <span>{{ filtersCloseLabel }}</span>\n </button>\n </div>\n </div>\n </mn-bottom-sheet>\n}\n\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<!-- Table wrapper with horizontal scroll -->\n <div #collectionBody [attr.aria-busy]=\"isLoadingState || null\" [attr.aria-label]=\"tableRegionLabel\" [style.min-height.px]=\"bodyMinHeight\"\n class=\"overflow-x-auto\"\n role=\"region\">\n <table [class]=\"tableClasses\">\n <thead>\n <tr class=\"bg-base-100\">\n <!-- Selection column header. It always carries a screen-reader-only name: a single-select\n table has nothing else in this cell, and a multi-select one only a checkbox, so\n without it the column is announced as a nameless header (axe empty-table-header). -->\n @if (hasSelection) {\n <th class=\"w-10 text-center text-sm px-2 py-2\">\n <span class=\"sr-only\">{{ selectionColumnLabel }}</span>\n @if (isMultiSelect) {\n <mn-lib-checkbox\n (checkedChange)=\"toggleAll()\"\n [checked]=\"allSelected\"\n [props]=\"{ id: 'mn-table-select-all', size: 'sm' }\"\n ></mn-lib-checkbox>\n }\n </th>\n }\n\n <!-- Data columns -->\n @for (column of dataSource.columns; track column.key) {\n <th\n [attr.data-column-key]=\"column.key\"\n [class.truncate]=\"widthsArePinned\"\n [class.cursor-pointer]=\"isSortable(column)\"\n [class.select-none]=\"isSortable(column)\"\n [class.hover:bg-base-200]=\"isSortable(column)\"\n [class.text-left]=\"(column.align ?? 'left') === 'left'\"\n [class.text-center]=\"column.align === 'center'\"\n [class.text-right]=\"column.align === 'right'\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n [attr.aria-sort]=\"currentSort?.columnKey === column.key ? (currentSort!.direction === 'asc' ? 'ascending' : 'descending') : null\"\n class=\"text-sm px-2 py-1 @min-[640px]:px-4 @min-[640px]:py-2 whitespace-nowrap\"\n (click)=\"sort(column)\"\n >\n <!-- The header content is declared once; a sortable column wraps it in a real button so\n the sort is reachable by keyboard. The button's click stops there, so the th's own\n click (which keeps the cell padding clickable) does not sort a second time. -->\n <ng-template #headerContent>\n @if (isTemplateRef(column.header)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.header)\"></ng-container>\n } @else {\n <span>{{ headerText(column) }}</span>\n }\n @if (isSortable(column)) {\n <span class=\"text-[0.65rem] opacity-70 min-w-3 inline-block\" aria-hidden=\"true\">{{ getSortIcon(column) }}</span>\n }\n </ng-template>\n @if (isSortable(column)) {\n <button type=\"button\" class=\"inline-flex items-center gap-1 cursor-pointer\" (click)=\"$event.stopPropagation(); sort(column)\">\n <ng-container [ngTemplateOutlet]=\"headerContent\"></ng-container>\n </button>\n } @else {\n <span class=\"inline-flex items-center gap-1\">\n <ng-container [ngTemplateOutlet]=\"headerContent\"></ng-container>\n </span>\n }\n </th>\n }\n\n </tr>\n\n <!-- Per-column filter row (wide screens only; collapses into a panel below 640px).\n The cells are `td`, not `th`: they hold form controls, not headings, and a\n column without a filter would otherwise be an empty header, which assistive tech\n announces as a nameless column (axe `empty-table-header`). `font-normal` stays\n so a consumer's thead styling cannot make the controls bold. -->\n @if (hasColumnFilters && !filtersCollapsed) {\n <tr class=\"bg-base-100 border-b border-base-300 font-normal\">\n @if (hasSelection) {\n <td class=\"px-2 py-1 font-normal\"></td>\n }\n @for (column of dataSource.columns; track column.key) {\n <td\n class=\"px-4 py-2 font-normal\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n >\n @if (column.filterable) {\n <!-- Every filter renders as an ordinary control right under its\n header. The rich types used to hide behind a button that opened\n a floating panel, which cost a click to discover, a click to\n apply, and hid whether a column was even filterable. -->\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: column, idScope: 'inline' }\"\n [ngTemplateOutlet]=\"filterField\"\n ></ng-container>\n }\n </td>\n }\n </tr>\n }\n </thead>\n\n <tbody>\n <!-- Loading state -->\n @if (isLoadingState) {\n @for (_ of skeletonRows; track $index) {\n <tr>\n @if (hasSelection) {\n <td class=\"px-2 py-3\">\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '1rem', height: '1rem' }\"></mn-skeleton>\n </td>\n }\n @for (column of dataSource.columns; track column.key) {\n <td class=\"px-4 py-3\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n >\n @if (isTemplateRef(column.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(column.skeleton)\"></ng-container>\n } @else {\n <mn-skeleton [data]=\"getColumnSkeletonData(column)\"></mn-skeleton>\n }\n </td>\n }\n </tr>\n }\n } @else if (isErrorState) {\n <!-- Error state -->\n <tr class=\"bg-base-100\">\n <td [attr.colspan]=\"totalColumnCount\" class=\"text-center text-xs py-8\">\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-error\">\n <p class=\"text-sm\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n </td>\n </tr>\n } @else {\n <!-- Empty state -->\n @if (filteredItems.length === 0) {\n <tr class=\"bg-base-100\">\n <td [attr.colspan]=\"totalColumnCount\" class=\"text-center text-xs py-8\">\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-base-content/50\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n </td>\n </tr>\n }\n\n <!-- Data rows -->\n @for (row of paginatedItems; track trackByID($index, row); let odd = $odd; let last = $last) {\n <tr\n class=\"bg-base-100 transition-colors duration-150 hover:cursor-pointer\"\n [ngClass]=\"{'bg-primary/10': isSelected(row)}\"\n [class.bg-base-200]=\"!isSelected(row) && odd && dataSource.appearance?.striped\"\n [class.hover:bg-base-200]=\"dataSource.appearance?.hover !== false\"\n [class.cursor-pointer]=\"!!dataSource.onRowClick\"\n [class.border-b]=\"!last\"\n [class.border-base-300]=\"!last\"\n [class.border-b-1]=\"last\"\n [class.border-black]=\"last\"\n [class.shadow-3xl]=\"last\"\n (click)=\"onRowClick(row)\"\n >\n <!-- Selection checkbox -->\n @if (hasSelection) {\n <td (click)=\"$event.stopPropagation()\" class=\"w-10 text-center px-2 py-2\">\n <mn-lib-checkbox\n (checkedChange)=\"toggle(row)\"\n [checked]=\"isSelected(row)\"\n [props]=\"{ id: 'mn-table-row-' + $index, size: 'sm' }\"\n ></mn-lib-checkbox>\n </td>\n }\n\n <!-- Data cells -->\n @for (column of dataSource.columns; track column.key) {\n <td\n [attr.title]=\"cellTitle(column, row)\"\n [class.text-left]=\"(column.align ?? 'left') === 'left'\"\n [class.text-center]=\"column.align === 'center'\"\n [class.text-right]=\"column.align === 'right'\"\n [class.truncate]=\"widthsArePinned\"\n [mnHiddenBelow]=\"column.hiddenBelow\"\n [style.width]=\"columnWidth(column)\"\n class=\"text-xs px-2 py-1 @min-[640px]:px-4 @min-[640px]:py-2\"\n >\n @if (column.actions) {\n <!-- Actions column: inline command buttons that collapse into a \u22EF menu\n once the table is narrower than 450px (container query), for every\n row with actions. A row with no visible actions renders nothing.\n A row with a single icon-only action never collapses: one icon button\n is narrower than the \u22EF trigger it would hide behind, so folding it\n only costs a tap. -->\n @if (hasRowActions(column, row)) {\n <div class=\"inline-flex items-center gap-1\"\n [class.justify-end]=\"(column.align ?? 'left') === 'right'\">\n @if (collapsesRowActions(column, row)) {\n <span class=\"hidden items-center gap-1 @min-[450px]:inline-flex\">\n <ng-container [ngTemplateOutletContext]=\"{ column: column, row: row }\"\n [ngTemplateOutlet]=\"actionButtons\"></ng-container>\n </span>\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <span class=\"@min-[450px]:hidden\" (click)=\"$event.stopPropagation()\">\n <mn-lib-dropdown [datasource]=\"{\n id: actionsDropdownId(column, row),\n actions: rowDropdownActions(column, row),\n menuLabel: headerText(column),\n size: 'sm'\n }\"></mn-lib-dropdown>\n </span>\n } @else {\n <span class=\"inline-flex items-center gap-1\">\n <ng-container [ngTemplateOutletContext]=\"{ column: column, row: row }\"\n [ngTemplateOutlet]=\"actionButtons\"></ng-container>\n </span>\n }\n </div>\n }\n } @else if (column.cellSm) {\n <!-- Default cell: hidden below the cellSm breakpoint -->\n <span [mnShowAbove]=\"column.cellSm.below\">\n @if (isTemplateRef(column.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cell)\"></ng-container>\n } @else {\n {{ getCellValue(column, row) }}\n }\n </span>\n <!-- Small cell: shown only below the cellSm breakpoint -->\n <span [mnShowBelow]=\"column.cellSm.below\">\n @if (isTemplateRef(column.cellSm.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cellSm.cell)\"></ng-container>\n } @else {\n {{ getCellSmValue(column, row) }}\n }\n </span>\n } @else {\n @if (isTemplateRef(column.cell)) {\n <ng-container [ngTemplateOutletContext]=\"{ $implicit: row, data: row }\"\n [ngTemplateOutlet]=\"$any(column.cell)\"></ng-container>\n } @else {\n {{ getCellValue(column, row) }}\n }\n }\n </td>\n }\n\n </tr>\n }\n }\n </tbody>\n </table>\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-table\"\n></mn-collection-pagination>\n</div>\n\n<!-- Single source of truth for every filter control, reused by the inline header\n row and the small-screen panel. `idScope` keeps element ids unique across\n both placements. -->\n<ng-template #filterField let-column let-idScope=\"idScope\">\n @switch (filterTypeOf(column)) {\n @case ('select') {\n <mn-lib-select\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"textFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getFilterSelectOptions(column),\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-select>\n }\n @case ('multi-select') {\n <mn-lib-multi-select\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"multiFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getFilterMultiSelectOptions(column),\n placeholder: column.filterPlaceholder ?? '',\n collapsePlaceholder: filterSelectedLabel,\n collapseThreshold: 1,\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-multi-select>\n }\n @case ('boolean') {\n <mn-lib-select\n (ngModelChange)=\"onBooleanFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"booleanFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n ariaLabel: filterLabel(column),\n options: getBooleanFilterOptions(column),\n size: 'sm',\n fullWidth: true\n }\"\n ></mn-lib-select>\n }\n @default {\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onColumnFilter(column, $event)\"\n [disabled]=\"column.filterDisabled ?? false\"\n [ngModel]=\"textFilterValue(column)\"\n [props]=\"{\n id: 'mn-table-filter-' + idScope + '-' + column.key,\n type: 'text',\n label: '',\n placeholder: column.filterPlaceholder ?? '',\n ariaLabel: column.filterPlaceholder ?? '',\n autocomplete: column.filterAutocomplete ?? undefined,\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true,\n hover: true\n }\"\n ></mn-lib-input-field>\n }\n }\n</ng-template>\n\n<!-- Inline action buttons for an actions column, shared by the wide-table layout and\n (implicitly) mirrored by the \u22EF menu below 450px. -->\n<ng-template #actionButtons let-column=\"column\" let-row=\"row\">\n @for (action of visibleRowActions(column, row); track $index) {\n <button\n mnButton\n type=\"button\"\n [data]=\"{\n size: 'sm',\n variant: 'text',\n color: rowActionColor(action, row),\n disabled: isRowActionDisabled(action, row)\n }\"\n class=\"cursor-pointer\"\n (click)=\"$event.stopPropagation(); runRowAction(action, row)\"\n [attr.aria-label]=\"rowActionLabel(action, row)\"\n [attr.title]=\"showActionLabel(column, action, row) ? null : rowActionLabel(action, row)\"\n >\n @if (showActionIcon(column, action, row)) {\n <span class=\"inline-flex items-center shrink-0\">\n @let icon = rowActionIcon(action, row);\n @if (isTemplateRef(icon)) {\n <ng-container [ngTemplateOutlet]=\"icon\"></ng-container>\n } @else {\n <!-- Data icon: sized here to match the sm button's text, so a caller can\n declare the action in TypeScript without owning a template. -->\n <svg [lucideIcon]=\"$any(icon)\" [size]=\"17\"></svg>\n }\n </span>\n }\n @if (showActionLabel(column, action, row)) {\n <span>{{ rowActionLabel(action, row) }}</span>\n }\n </button>\n }\n</ng-template>\n" }]
2002
+ }], ctorParameters: () => [], propDecorators: { sortChange: [{
2003
+ type: Output
2004
+ }], rowClick: [{
2005
+ type: Output
2006
+ }], filtersSheet: [{
2007
+ type: ViewChild,
2008
+ args: ['filtersSheet']
2009
+ }], collectionBody: [{
2010
+ type: ViewChild,
2011
+ args: ['collectionBody']
2012
+ }], onWindowResize: [{
2013
+ type: HostListener,
2014
+ args: ['window:resize']
2015
+ }] } });
2016
+
2017
+ /** Default skeleton lines reproducing the previous two-bar placeholder. */
2018
+ const DEFAULT_LIST_SKELETON_LINES = [
2019
+ { shape: 'text', width: '75%' },
2020
+ { shape: 'text', width: '50%', height: '0.75rem' },
2021
+ ];
2022
+ class MnList extends MnSelectableCollectionBase {
2023
+ itemClick = new EventEmitter();
2024
+ componentName = 'MnList';
2025
+ /** Skeleton lines rendered for each placeholder item, falling back to the default two-bar layout. */
2026
+ get skeletonLines() {
2027
+ const skeleton = this.dataSource.skeleton;
2028
+ if (skeleton && !this.isTemplateRef(skeleton)) {
2029
+ return skeleton.lines;
2030
+ }
2031
+ return DEFAULT_LIST_SKELETON_LINES;
2032
+ }
2033
+ // ── Item interaction ──
2034
+ onItemClick(item) {
2035
+ this.dataSource.onItemClick?.(item);
2036
+ this.itemClick.emit(item);
2037
+ }
2038
+ /**
2039
+ * Keyboard activation of a clickable item: Enter and Space open it, as they would a button.
2040
+ * Handled on keydown so Space does not scroll the page first, and only when the item itself has
2041
+ * focus, so a checkbox or button inside the item keeps its own keys.
2042
+ * @param event - The keydown on the item.
2043
+ * @param item - The item the key was pressed on.
2044
+ */
2045
+ onItemKeydown(event, item) {
2046
+ if (!this.dataSource.onItemClick || event.target !== event.currentTarget)
2047
+ return;
2048
+ if (event.key !== 'Enter' && event.key !== ' ')
2049
+ return;
2050
+ event.preventDefault();
2051
+ this.onItemClick(item);
2052
+ }
2053
+ // ── Skeleton ──
2054
+ /**
2055
+ * The toolbar template the base class watches for identity changes. Prefers the
2056
+ * left slot, then the right, then the deprecated `toolbarTemplate`, so a list
2057
+ * using any single slot still re-renders when that template is swapped.
2058
+ */
2059
+ get trackedToolbarTemplate() {
2060
+ return (this.dataSource?.toolbarLeftTemplate ??
2061
+ this.dataSource?.toolbarRightTemplate ??
2062
+ this.dataSource?.toolbarTemplate);
2063
+ }
2064
+ collectionBody;
2065
+ // ── Filtering ──
2066
+ applyFilter(searchForItems) {
2067
+ this.filteredItems = this.applySearchFilter(this.dataSource.dataRows.value);
2068
+ this.applyPagination();
2069
+ if (searchForItems) {
2070
+ this.loadMoreRows();
2071
+ }
2072
+ }
2073
+ /** Accessible name for the scrollable list region. */
2074
+ get listRegionLabel() {
2075
+ return this.resolveLabel(undefined, 'mnCollection.dataList', 'Data list');
2076
+ }
2077
+ /** Label on the header checkbox that selects or clears every visible row. */
2078
+ get selectAllLabel() {
2079
+ return this.resolveLabel(undefined, 'mnCollection.selectAll', 'Select all');
2080
+ }
2081
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnList, deps: null, target: i0.ɵɵFactoryTarget.Component });
2082
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnList, isStandalone: true, selector: "mn-list", outputs: { itemClick: "itemClick" }, viewQueries: [{ propertyName: "collectionBody", first: true, predicate: ["collectionBody"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<!-- Toolbar: left template, then search + right template. Below 375px each group\n takes its own full-width row; from 375px up the left group sits at the start\n and the search group at the end. Structure and classes mirror mn-table so all\n collections behave identically at every width. -->\n@if (\n isSearchable ||\n dataSource.toolbarLeftTemplate ||\n dataSource.toolbarRightTemplate ||\n dataSource.toolbarTemplate\n) {\n <div class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full min-[375px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center gap-2 w-full min-[375px]:flex-1 min-[480px]:flex-none min-[480px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box is the\n collection's own chrome, not a field of whatever form it sits in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onSearch($event)\"\n [ngModel]=\"searchValue\"\n [props]=\"{\n id: 'mn-list-search',\n type: 'search',\n label: '',\n ariaLabel: dataSource.searchPlaceholder ?? 'Search...',\n placeholder: dataSource.searchPlaceholder ?? 'Search...',\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n class=\"w-full min-[375px]:flex-1 min-[480px]:max-w-64\"\n ></mn-lib-input-field>\n }\n <!-- `toolbarTemplate` is the deprecated name for this slot; honouring it here\n keeps existing callers rendering exactly where they used to. -->\n @if (dataSource.toolbarRightTemplate ?? dataSource.toolbarTemplate; as rightTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"rightTemplate\"></ng-container>\n </div>\n }\n </div>\n </div>\n}\n\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<!-- List wrapper -->\n<div\n #collectionBody\n [attr.aria-busy]=\"isLoadingState || null\"\n [style.min-height.px]=\"bodyMinHeight\"\n class=\"w-full\"\n [class.border]=\"dataSource.appearance?.bordered\"\n [class.border-base-300]=\"dataSource.appearance?.bordered\"\n [class.rounded]=\"dataSource.appearance?.bordered\"\n role=\"list\"\n [attr.aria-label]=\"listRegionLabel\"\n>\n <!-- Loading state -->\n @if (isLoadingState) {\n @for (_ of skeletonRows; track $index) {\n <div [class.py-2]=\"dataSource.appearance?.compact\" class=\"px-4 py-3\" role=\"listitem\">\n @if (isTemplateRef(dataSource.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(dataSource.skeleton)\"></ng-container>\n } @else {\n <div class=\"flex flex-col gap-1\">\n @for (line of skeletonLines; track $index) {\n <mn-skeleton [data]=\"line\"></mn-skeleton>\n }\n </div>\n }\n </div>\n @if (!$last && (dataSource.appearance?.dividers !== false)) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n } @else if (isErrorState) {\n <!-- Error state -->\n <div class=\"text-center text-xs py-8\" role=\"listitem\">\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-error\">\n <p class=\"text-sm\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n </div>\n } @else {\n <!-- Empty state -->\n @if (filteredItems.length === 0) {\n <div class=\"text-center text-xs py-8\" role=\"listitem\">\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-base-content/50\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n </div>\n }\n\n <!-- Select all (multi-select) -->\n @if (isMultiSelect && filteredItems.length > 0) {\n <div class=\"flex items-center gap-2 px-4 py-2 bg-base-200 text-sm\">\n <mn-lib-checkbox\n (checkedChange)=\"toggleAll()\"\n [checked]=\"allSelected\"\n [props]=\"{ id: 'mn-list-select-all', label: selectAllLabel, size: 'sm' }\"\n ></mn-lib-checkbox>\n </div>\n @if (dataSource.appearance?.dividers !== false) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n\n <!-- Data items -->\n @for (item of paginatedItems; track trackByID($index, item); let odd = $odd; let last = $last) {\n <div\n class=\"flex items-center gap-2 bg-base-100 transition-colors duration-150\"\n [ngClass]=\"{'bg-primary/10': isSelected(item)}\"\n [class.bg-base-200]=\"!isSelected(item) && odd && dataSource.appearance?.dividers !== false\"\n [class.hover:bg-base-200]=\"dataSource.appearance?.hover !== false\"\n [class.cursor-pointer]=\"!!dataSource.onItemClick\"\n [class.px-4]=\"true\"\n [class.py-3]=\"!dataSource.appearance?.compact\"\n [class.py-2]=\"dataSource.appearance?.compact\"\n role=\"listitem\"\n (keydown)=\"onItemKeydown($event, item)\"\n (click)=\"onItemClick(item)\"\n [attr.tabindex]=\"dataSource.onItemClick ? 0 : null\"\n >\n <!-- Selection checkbox -->\n @if (hasSelection) {\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div (click)=\"$event.stopPropagation()\" class=\"shrink-0\">\n <mn-lib-checkbox\n (checkedChange)=\"toggle(item)\"\n [checked]=\"isSelected(item)\"\n [props]=\"{ id: 'mn-list-item-' + $index, size: 'sm' }\"\n ></mn-lib-checkbox>\n </div>\n }\n\n <!-- Item content via template -->\n <div class=\"flex-1 min-w-0\">\n <ng-container\n [ngTemplateOutlet]=\"dataSource.itemTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: item, data: item }\"\n ></ng-container>\n </div>\n </div>\n @if (!last && (dataSource.appearance?.dividers !== false)) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n }\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-list\"\n></mn-collection-pagination>\n", styles: [""], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { 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: "component", type: MnCheckbox, selector: "mn-lib-checkbox", inputs: ["props", "checked"], outputs: ["checkedChange"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { kind: "component", type: MnCollectionPagination, selector: "mn-collection-pagination", inputs: ["idPrefix", "isPaginated", "isServerPaginated", "showLoadMore", "loadingMoreRows", "currentPage", "pageSize", "totalPages", "totalItemCount", "visiblePages", "pageSizeSelectOptions", "labels"], outputs: ["loadMore", "pageChange", "pageSizeChange"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2083
+ }
2084
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnList, decorators: [{
2085
+ type: Component,
2086
+ args: [{ selector: 'mn-list', standalone: true, imports: [NgClass, NgTemplateOutlet, FormsModule, MnCheckbox, MnInputField, MnSkeleton, MnCollectionPagination, LucideDynamicIcon], changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- Toolbar: left template, then search + right template. Below 375px each group\n takes its own full-width row; from 375px up the left group sits at the start\n and the search group at the end. Structure and classes mirror mn-table so all\n collections behave identically at every width. -->\n@if (\n isSearchable ||\n dataSource.toolbarLeftTemplate ||\n dataSource.toolbarRightTemplate ||\n dataSource.toolbarTemplate\n) {\n <div class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full min-[375px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center gap-2 w-full min-[375px]:flex-1 min-[480px]:flex-none min-[480px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box is the\n collection's own chrome, not a field of whatever form it sits in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onSearch($event)\"\n [ngModel]=\"searchValue\"\n [props]=\"{\n id: 'mn-list-search',\n type: 'search',\n label: '',\n ariaLabel: dataSource.searchPlaceholder ?? 'Search...',\n placeholder: dataSource.searchPlaceholder ?? 'Search...',\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n class=\"w-full min-[375px]:flex-1 min-[480px]:max-w-64\"\n ></mn-lib-input-field>\n }\n <!-- `toolbarTemplate` is the deprecated name for this slot; honouring it here\n keeps existing callers rendering exactly where they used to. -->\n @if (dataSource.toolbarRightTemplate ?? dataSource.toolbarTemplate; as rightTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"rightTemplate\"></ng-container>\n </div>\n }\n </div>\n </div>\n}\n\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<!-- List wrapper -->\n<div\n #collectionBody\n [attr.aria-busy]=\"isLoadingState || null\"\n [style.min-height.px]=\"bodyMinHeight\"\n class=\"w-full\"\n [class.border]=\"dataSource.appearance?.bordered\"\n [class.border-base-300]=\"dataSource.appearance?.bordered\"\n [class.rounded]=\"dataSource.appearance?.bordered\"\n role=\"list\"\n [attr.aria-label]=\"listRegionLabel\"\n>\n <!-- Loading state -->\n @if (isLoadingState) {\n @for (_ of skeletonRows; track $index) {\n <div [class.py-2]=\"dataSource.appearance?.compact\" class=\"px-4 py-3\" role=\"listitem\">\n @if (isTemplateRef(dataSource.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(dataSource.skeleton)\"></ng-container>\n } @else {\n <div class=\"flex flex-col gap-1\">\n @for (line of skeletonLines; track $index) {\n <mn-skeleton [data]=\"line\"></mn-skeleton>\n }\n </div>\n }\n </div>\n @if (!$last && (dataSource.appearance?.dividers !== false)) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n } @else if (isErrorState) {\n <!-- Error state -->\n <div class=\"text-center text-xs py-8\" role=\"listitem\">\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-error\">\n <p class=\"text-sm\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n </div>\n } @else {\n <!-- Empty state -->\n @if (filteredItems.length === 0) {\n <div class=\"text-center text-xs py-8\" role=\"listitem\">\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div class=\"flex flex-col items-center gap-2 text-base-content/50\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n </div>\n }\n\n <!-- Select all (multi-select) -->\n @if (isMultiSelect && filteredItems.length > 0) {\n <div class=\"flex items-center gap-2 px-4 py-2 bg-base-200 text-sm\">\n <mn-lib-checkbox\n (checkedChange)=\"toggleAll()\"\n [checked]=\"allSelected\"\n [props]=\"{ id: 'mn-list-select-all', label: selectAllLabel, size: 'sm' }\"\n ></mn-lib-checkbox>\n </div>\n @if (dataSource.appearance?.dividers !== false) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n\n <!-- Data items -->\n @for (item of paginatedItems; track trackByID($index, item); let odd = $odd; let last = $last) {\n <div\n class=\"flex items-center gap-2 bg-base-100 transition-colors duration-150\"\n [ngClass]=\"{'bg-primary/10': isSelected(item)}\"\n [class.bg-base-200]=\"!isSelected(item) && odd && dataSource.appearance?.dividers !== false\"\n [class.hover:bg-base-200]=\"dataSource.appearance?.hover !== false\"\n [class.cursor-pointer]=\"!!dataSource.onItemClick\"\n [class.px-4]=\"true\"\n [class.py-3]=\"!dataSource.appearance?.compact\"\n [class.py-2]=\"dataSource.appearance?.compact\"\n role=\"listitem\"\n (keydown)=\"onItemKeydown($event, item)\"\n (click)=\"onItemClick(item)\"\n [attr.tabindex]=\"dataSource.onItemClick ? 0 : null\"\n >\n <!-- Selection checkbox -->\n @if (hasSelection) {\n <!-- eslint-disable-next-line @angular-eslint/template/click-events-have-key-events,@angular-eslint/template/interactive-supports-focus -->\n <div (click)=\"$event.stopPropagation()\" class=\"shrink-0\">\n <mn-lib-checkbox\n (checkedChange)=\"toggle(item)\"\n [checked]=\"isSelected(item)\"\n [props]=\"{ id: 'mn-list-item-' + $index, size: 'sm' }\"\n ></mn-lib-checkbox>\n </div>\n }\n\n <!-- Item content via template -->\n <div class=\"flex-1 min-w-0\">\n <ng-container\n [ngTemplateOutlet]=\"dataSource.itemTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: item, data: item }\"\n ></ng-container>\n </div>\n </div>\n @if (!last && (dataSource.appearance?.dividers !== false)) {\n <div class=\"border-b border-base-300\"></div>\n }\n }\n }\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-list\"\n></mn-collection-pagination>\n" }]
2087
+ }], propDecorators: { itemClick: [{
2088
+ type: Output
2089
+ }], collectionBody: [{
2090
+ type: ViewChild,
2091
+ args: ['collectionBody']
2092
+ }] } });
2093
+
2094
+ /** Default card skeleton: an image block plus two text bars. */
2095
+ const DEFAULT_GRID_SKELETON_LINES = [
2096
+ { shape: 'rectangle', width: '100%', height: '8rem' },
2097
+ { shape: 'text', width: '75%' },
2098
+ { shape: 'text', width: '50%', height: '0.75rem' },
2099
+ ];
2100
+ /** Breakpoints a `cols` map may address, ordered small → large. */
2101
+ const GRID_BREAKPOINTS = ['base', 'sm', 'md', 'lg', 'xl'];
2102
+ /** Highest column count with a pre-generated class; larger requests clamp to it. */
2103
+ const MAX_GRID_COLS = 12;
2104
+ /**
2105
+ * Column utilities per breakpoint, indexed by `columns - 1`.
2106
+ *
2107
+ * Spelled out as literals on purpose: the consuming app's Tailwind scanner reads
2108
+ * the shipped bundle, so a name assembled at runtime (`sm:grid-cols-${n}`) would
2109
+ * never be generated. Breakpoints are Tailwind's defaults (sm 640, md 768,
2110
+ * lg 1024, xl 1280), and each unset one simply inherits the next-smaller class.
2111
+ */
2112
+ const GRID_COL_CLASSES = {
2113
+ base: [
2114
+ 'grid-cols-1', 'grid-cols-2', 'grid-cols-3', 'grid-cols-4', 'grid-cols-5', 'grid-cols-6',
2115
+ 'grid-cols-7', 'grid-cols-8', 'grid-cols-9', 'grid-cols-10', 'grid-cols-11', 'grid-cols-12',
2116
+ ],
2117
+ sm: [
2118
+ 'sm:grid-cols-1', 'sm:grid-cols-2', 'sm:grid-cols-3', 'sm:grid-cols-4', 'sm:grid-cols-5', 'sm:grid-cols-6',
2119
+ 'sm:grid-cols-7', 'sm:grid-cols-8', 'sm:grid-cols-9', 'sm:grid-cols-10', 'sm:grid-cols-11', 'sm:grid-cols-12',
2120
+ ],
2121
+ md: [
2122
+ 'md:grid-cols-1', 'md:grid-cols-2', 'md:grid-cols-3', 'md:grid-cols-4', 'md:grid-cols-5', 'md:grid-cols-6',
2123
+ 'md:grid-cols-7', 'md:grid-cols-8', 'md:grid-cols-9', 'md:grid-cols-10', 'md:grid-cols-11', 'md:grid-cols-12',
2124
+ ],
2125
+ lg: [
2126
+ 'lg:grid-cols-1', 'lg:grid-cols-2', 'lg:grid-cols-3', 'lg:grid-cols-4', 'lg:grid-cols-5', 'lg:grid-cols-6',
2127
+ 'lg:grid-cols-7', 'lg:grid-cols-8', 'lg:grid-cols-9', 'lg:grid-cols-10', 'lg:grid-cols-11', 'lg:grid-cols-12',
2128
+ ],
2129
+ xl: [
2130
+ 'xl:grid-cols-1', 'xl:grid-cols-2', 'xl:grid-cols-3', 'xl:grid-cols-4', 'xl:grid-cols-5', 'xl:grid-cols-6',
2131
+ 'xl:grid-cols-7', 'xl:grid-cols-8', 'xl:grid-cols-9', 'xl:grid-cols-10', 'xl:grid-cols-11', 'xl:grid-cols-12',
2132
+ ],
2133
+ };
2134
+ /**
2135
+ * Picks the column utility for a breakpoint, clamped to the range that has one.
2136
+ * @param breakpoint Breakpoint the class applies from.
2137
+ * @param columns Requested column count.
2138
+ * @returns The Tailwind class name.
2139
+ */
2140
+ function gridColClass(breakpoint, columns) {
2141
+ const index = Math.min(Math.max(Math.round(columns), 1), MAX_GRID_COLS) - 1;
2142
+ return GRID_COL_CLASSES[breakpoint][index];
2143
+ }
2144
+ /**
2145
+ * Responsive card-grid component. Shares the collection chrome (search, every
2146
+ * pagination mode, loading skeleton, empty state, toolbar, i18n) with
2147
+ * {@link import('../mn-list').MnList} and {@link import('../mn-table').MnTable}
2148
+ * via {@link MnCollectionBase}, and lays items out as cards instead of rows.
2149
+ * Selection is intentionally not supported.
2150
+ */
2151
+ class MnGrid extends MnCollectionBase {
2152
+ itemClick = new EventEmitter();
2153
+ componentName = 'MnGrid';
2154
+ /** Whether the grid uses auto-fit (minCardWidth) instead of explicit columns. */
2155
+ get isAutoLayout() {
2156
+ return !!this.dataSource.layout?.minCardWidth;
2157
+ }
2158
+ // ── Layout ──
2159
+ /**
2160
+ * Classes for the card container: `grid` plus one column utility per
2161
+ * breakpoint the consumer configured. Omitted for the auto-fit layout, whose
2162
+ * columns come from {@link autoTemplateColumns} instead.
2163
+ */
2164
+ get gridClasses() {
2165
+ if (this.isAutoLayout) {
2166
+ return 'grid';
2167
+ }
2168
+ const cols = this.dataSource.layout?.cols;
2169
+ const classes = ['grid', gridColClass('base', cols?.base ?? 1)];
2170
+ for (const breakpoint of GRID_BREAKPOINTS) {
2171
+ if (breakpoint === 'base')
2172
+ continue;
2173
+ const columns = cols?.[breakpoint];
2174
+ if (columns != null) {
2175
+ classes.push(gridColClass(breakpoint, columns));
2176
+ }
2177
+ }
2178
+ return classes.join(' ');
2179
+ }
2180
+ /** Gap between cards. */
2181
+ get gridGap() {
2182
+ return this.dataSource.layout?.gap ?? '1rem';
2183
+ }
2184
+ /**
2185
+ * Inline `grid-template-columns` for the auto-fit layout, or null when explicit
2186
+ * `cols` are used (the utilities in {@link gridClasses} then own the columns).
2187
+ * `minCardWidth` is a free-form CSS length, so it can only be expressed inline.
2188
+ */
2189
+ get autoTemplateColumns() {
2190
+ const minCardWidth = this.dataSource.layout?.minCardWidth;
2191
+ return minCardWidth ? `repeat(auto-fit, minmax(${minCardWidth}, 1fr))` : null;
2192
+ }
2193
+ /** Skeleton lines for the default/lines placeholder; null when a custom template is used. */
2194
+ get skeletonLines() {
2195
+ const skeleton = this.dataSource.skeleton;
2196
+ if (skeleton && !this.isTemplateRef(skeleton)) {
2197
+ return skeleton.lines;
2198
+ }
2199
+ return DEFAULT_GRID_SKELETON_LINES;
2200
+ }
2201
+ // ── Item interaction ──
2202
+ /**
2203
+ * The toolbar template the base class watches for identity changes. Prefers the
2204
+ * left slot, then the right, then the deprecated `toolbarTemplate`, so a grid
2205
+ * using any single slot still re-renders when that template is swapped.
2206
+ */
2207
+ get trackedToolbarTemplate() {
2208
+ return (this.dataSource?.toolbarLeftTemplate ??
2209
+ this.dataSource?.toolbarRightTemplate ??
2210
+ this.dataSource?.toolbarTemplate);
2211
+ }
2212
+ collectionBody;
2213
+ // ── Skeleton ──
2214
+ onItemClick(item) {
2215
+ this.dataSource.onItemClick?.(item);
2216
+ this.itemClick.emit(item);
2217
+ }
2218
+ /**
2219
+ * Keyboard activation of a clickable item: Enter and Space open it, as they would a button.
2220
+ * Handled on keydown so Space does not scroll the page first, and only when the item itself has
2221
+ * focus, so a checkbox or button inside the item keeps its own keys.
2222
+ * @param event - The keydown on the item.
2223
+ * @param item - The item the key was pressed on.
2224
+ */
2225
+ onItemKeydown(event, item) {
2226
+ if (!this.dataSource.onItemClick || event.target !== event.currentTarget)
2227
+ return;
2228
+ if (event.key !== 'Enter' && event.key !== ' ')
2229
+ return;
2230
+ event.preventDefault();
2231
+ this.onItemClick(item);
2232
+ }
2233
+ // ── Filtering ──
2234
+ applyFilter(searchForItems) {
2235
+ let items = this.applySearchFilter(this.dataSource.dataRows.value ?? []);
2236
+ // Preview cap: show only the first `maxItems` cards (pager stays hidden).
2237
+ const maxItems = this.dataSource.layout?.maxItems;
2238
+ if (maxItems != null) {
2239
+ items = items.slice(0, maxItems);
2240
+ }
2241
+ this.filteredItems = items;
2242
+ this.applyPagination();
2243
+ if (searchForItems) {
2244
+ this.loadMoreRows();
2245
+ }
2246
+ }
2247
+ /** Accessible name for the scrollable grid region. */
2248
+ get gridRegionLabel() {
2249
+ return this.resolveLabel(undefined, 'mnCollection.cardGrid', 'Card grid');
2250
+ }
2251
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnGrid, deps: null, target: i0.ɵɵFactoryTarget.Component });
2252
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnGrid, isStandalone: true, selector: "mn-grid", outputs: { itemClick: "itemClick" }, host: { classAttribute: "block" }, viewQueries: [{ propertyName: "collectionBody", first: true, predicate: ["collectionBody"], descendants: true }], usesInheritance: true, ngImport: i0, template: "<!-- Toolbar: left template, then search + right template. Below 375px each group\n takes its own full-width row; from 375px up the left group sits at the start\n and the search group at the end. Structure and classes mirror mn-table so all\n collections behave identically at every width. -->\n@if (\n isSearchable ||\n dataSource.toolbarLeftTemplate ||\n dataSource.toolbarRightTemplate ||\n dataSource.toolbarTemplate\n) {\n <div class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full min-[375px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center gap-2 w-full min-[375px]:flex-1 min-[480px]:flex-none min-[480px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box is the\n collection's own chrome, not a field of whatever form it sits in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onSearch($event)\"\n [ngModel]=\"searchValue\"\n [props]=\"{\n id: 'mn-grid-search',\n type: 'search',\n label: '',\n ariaLabel: dataSource.searchPlaceholder ?? 'Search...',\n placeholder: dataSource.searchPlaceholder ?? 'Search...',\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n class=\"w-full min-[375px]:flex-1 min-[480px]:max-w-64\"\n ></mn-lib-input-field>\n }\n <!-- `toolbarTemplate` is the deprecated name for this slot; honouring it here\n keeps existing callers rendering exactly where they used to. -->\n @if (dataSource.toolbarRightTemplate ?? dataSource.toolbarTemplate; as rightTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"rightTemplate\"></ng-container>\n </div>\n }\n </div>\n </div>\n}\n\n<!-- Body: skeleton/data swap region. Wrapper holds its height during a server reload. -->\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<div #collectionBody [style.min-height.px]=\"bodyMinHeight\">\n<!-- Loading state -->\n @if (isLoadingState) {\n <div\n [class]=\"gridClasses\"\n [style.gap]=\"gridGap\"\n [style.grid-template-columns]=\"autoTemplateColumns\"\n aria-busy=\"true\"\n [attr.aria-label]=\"loadingLabel\"\n role=\"list\"\n >\n @for (_ of skeletonRows; track $index) {\n <div role=\"listitem\">\n @if (isTemplateRef(dataSource.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(dataSource.skeleton)\"></ng-container>\n } @else {\n <div class=\"flex flex-col gap-2 p-4 border border-base-300 rounded-lg\">\n @for (line of skeletonLines; track $index) {\n <mn-skeleton [data]=\"line\"></mn-skeleton>\n }\n </div>\n }\n </div>\n }\n </div>\n } @else if (isErrorState) {\n <!-- Error state -->\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div\n class=\"flex items-center justify-center min-h-[6rem] py-8 rounded-xl border border-dashed border-error/30 bg-base-100\">\n <p class=\"text-sm text-error\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n} @else {\n <!-- Empty state: a caller-provided template/component (rendered unwrapped, full\n control over its own layout) or, when none is given, the default text. -->\n @if (filteredItems.length === 0) {\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div\n class=\"flex flex-col items-center justify-center gap-2 min-h-[6rem] py-8 rounded-xl border border-dashed border-base-content/15 bg-base-100 text-base-content/40\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n } @else {\n <!-- Card grid -->\n <div\n [class]=\"gridClasses\"\n [style.gap]=\"gridGap\"\n [style.grid-template-columns]=\"autoTemplateColumns\"\n [attr.aria-label]=\"gridRegionLabel\"\n role=\"list\"\n >\n @for (item of paginatedItems; track trackByID($index, item)) {\n <div\n (click)=\"onItemClick(item)\"\n (keydown)=\"onItemKeydown($event, item)\"\n [attr.tabindex]=\"dataSource.onItemClick ? 0 : null\"\n [class.cursor-pointer]=\"!!dataSource.onItemClick\"\n class=\"transition-colors duration-150\"\n role=\"listitem\"\n >\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: item, data: item }\"\n [ngTemplateOutlet]=\"dataSource.cardTemplate\"\n ></ng-container>\n </div>\n }\n </div>\n }\n}\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-grid\"\n></mn-collection-pagination>\n", dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { 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: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { kind: "component", type: MnInputField, selector: "mn-lib-input-field", inputs: ["props"] }, { kind: "component", type: MnCollectionPagination, selector: "mn-collection-pagination", inputs: ["idPrefix", "isPaginated", "isServerPaginated", "showLoadMore", "loadingMoreRows", "currentPage", "pageSize", "totalPages", "totalItemCount", "visiblePages", "pageSizeSelectOptions", "labels"], outputs: ["loadMore", "pageChange", "pageSizeChange"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2253
+ }
2254
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnGrid, decorators: [{
2255
+ type: Component,
2256
+ args: [{ selector: 'mn-grid', standalone: true, imports: [NgTemplateOutlet, FormsModule, MnSkeleton, MnInputField, MnCollectionPagination, LucideDynamicIcon], host: { class: 'block' }, changeDetection: ChangeDetectionStrategy.OnPush, template: "<!-- Toolbar: left template, then search + right template. Below 375px each group\n takes its own full-width row; from 375px up the left group sits at the start\n and the search group at the end. Structure and classes mirror mn-table so all\n collections behave identically at every width. -->\n@if (\n isSearchable ||\n dataSource.toolbarLeftTemplate ||\n dataSource.toolbarRightTemplate ||\n dataSource.toolbarTemplate\n) {\n <div class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center justify-between gap-2 mb-3\">\n <div class=\"flex items-center gap-2 w-full min-[375px]:w-auto\">\n @if (dataSource.toolbarLeftTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"dataSource.toolbarLeftTemplate\"></ng-container>\n </div>\n }\n </div>\n <div\n class=\"flex flex-col min-[375px]:flex-row min-[375px]:items-center gap-2 w-full min-[375px]:flex-1 min-[480px]:flex-none min-[480px]:w-auto\">\n @if (isSearchable) {\n <!-- Enter must not submit a surrounding form: the search box is the\n collection's own chrome, not a field of whatever form it sits in. -->\n <mn-lib-input-field\n (keydown.enter)=\"$event.preventDefault()\"\n (ngModelChange)=\"onSearch($event)\"\n [ngModel]=\"searchValue\"\n [props]=\"{\n id: 'mn-grid-search',\n type: 'search',\n label: '',\n ariaLabel: dataSource.searchPlaceholder ?? 'Search...',\n placeholder: dataSource.searchPlaceholder ?? 'Search...',\n size: 'sm',\n borderRadius: 'md',\n fullWidth: true\n }\"\n class=\"w-full min-[375px]:flex-1 min-[480px]:max-w-64\"\n ></mn-lib-input-field>\n }\n <!-- `toolbarTemplate` is the deprecated name for this slot; honouring it here\n keeps existing callers rendering exactly where they used to. -->\n @if (dataSource.toolbarRightTemplate ?? dataSource.toolbarTemplate; as rightTemplate) {\n <div class=\"flex flex-col w-full min-[375px]:w-auto min-[375px]:flex-row\">\n <ng-container [ngTemplateOutlet]=\"rightTemplate\"></ng-container>\n </div>\n }\n </div>\n </div>\n}\n\n<!-- Body: skeleton/data swap region. Wrapper holds its height during a server reload. -->\n<!-- Announces loading. The skeletons are aria-hidden, so without this a screen reader hears\n nothing while rows load. The region stays in the DOM and only its text changes, which is\n what makes assistive tech read it; one inserted with its text already set is often missed. -->\n<span class=\"sr-only\" role=\"status\">{{ isLoadingState ? loadingLabel : '' }}</span>\n\n<div #collectionBody [style.min-height.px]=\"bodyMinHeight\">\n<!-- Loading state -->\n @if (isLoadingState) {\n <div\n [class]=\"gridClasses\"\n [style.gap]=\"gridGap\"\n [style.grid-template-columns]=\"autoTemplateColumns\"\n aria-busy=\"true\"\n [attr.aria-label]=\"loadingLabel\"\n role=\"list\"\n >\n @for (_ of skeletonRows; track $index) {\n <div role=\"listitem\">\n @if (isTemplateRef(dataSource.skeleton)) {\n <ng-container [ngTemplateOutlet]=\"$any(dataSource.skeleton)\"></ng-container>\n } @else {\n <div class=\"flex flex-col gap-2 p-4 border border-base-300 rounded-lg\">\n @for (line of skeletonLines; track $index) {\n <mn-skeleton [data]=\"line\"></mn-skeleton>\n }\n </div>\n }\n </div>\n }\n </div>\n } @else if (isErrorState) {\n <!-- Error state -->\n @if (dataSource.errorTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.errorTemplate\"></ng-container>\n } @else {\n <div\n class=\"flex items-center justify-center min-h-[6rem] py-8 rounded-xl border border-dashed border-error/30 bg-base-100\">\n <p class=\"text-sm text-error\">{{ dataSource.errorMessage }}</p>\n </div>\n }\n} @else {\n <!-- Empty state: a caller-provided template/component (rendered unwrapped, full\n control over its own layout) or, when none is given, the default text. -->\n @if (filteredItems.length === 0) {\n @if (dataSource.emptyTemplate) {\n <ng-container [ngTemplateOutlet]=\"dataSource.emptyTemplate\"></ng-container>\n } @else {\n <div\n class=\"flex flex-col items-center justify-center gap-2 min-h-[6rem] py-8 rounded-xl border border-dashed border-base-content/15 bg-base-100 text-base-content/40\">\n @if (dataSource.emptyIcon !== null) {\n <svg [lucideIcon]=\"dataSource.emptyIcon ?? defaultEmptyIcon\" [size]=\"32\" [strokeWidth]=\"1.5\"></svg>\n }\n <p class=\"text-sm\">{{ dataSource.emptyMessage }}</p>\n </div>\n }\n } @else {\n <!-- Card grid -->\n <div\n [class]=\"gridClasses\"\n [style.gap]=\"gridGap\"\n [style.grid-template-columns]=\"autoTemplateColumns\"\n [attr.aria-label]=\"gridRegionLabel\"\n role=\"list\"\n >\n @for (item of paginatedItems; track trackByID($index, item)) {\n <div\n (click)=\"onItemClick(item)\"\n (keydown)=\"onItemKeydown($event, item)\"\n [attr.tabindex]=\"dataSource.onItemClick ? 0 : null\"\n [class.cursor-pointer]=\"!!dataSource.onItemClick\"\n class=\"transition-colors duration-150\"\n role=\"listitem\"\n >\n <ng-container\n [ngTemplateOutletContext]=\"{ $implicit: item, data: item }\"\n [ngTemplateOutlet]=\"dataSource.cardTemplate\"\n ></ng-container>\n </div>\n }\n </div>\n }\n}\n</div>\n\n<!-- Load more + pagination -->\n<mn-collection-pagination\n (loadMore)=\"loadMoreRows()\"\n (pageChange)=\"goToPage($event)\"\n (pageSizeChange)=\"onPageSizeChange($event)\"\n [currentPage]=\"currentPage\"\n [isPaginated]=\"isPaginated\"\n [isServerPaginated]=\"isServerPaginated\"\n [labels]=\"dataSource.labels\"\n [loadingMoreRows]=\"loadingMoreRows\"\n [pageSizeSelectOptions]=\"pageSizeSelectOptions\"\n [pageSize]=\"pageSize\"\n [showLoadMore]=\"showLoadMore\"\n [totalItemCount]=\"totalItemCount\"\n [totalPages]=\"totalPages\"\n [visiblePages]=\"visiblePages\"\n idPrefix=\"mn-grid\"\n></mn-collection-pagination>\n" }]
2257
+ }], propDecorators: { itemClick: [{
2258
+ type: Output
2259
+ }], collectionBody: [{
2260
+ type: ViewChild,
2261
+ args: ['collectionBody']
2262
+ }] } });
2263
+
2264
+ /**
2265
+ * Public API of the `mn-angular-lib/collection` entry point: collections (table, list, grid, pagination).
2266
+ *
2267
+ * Each entry point is its own module in the published package, so a consumer's bundler
2268
+ * splits it into the chunk that uses it instead of loading the whole library at startup.
2269
+ * The root `mn-angular-lib` entry re-exports every entry point.
2270
+ */
2271
+
2272
+ /**
2273
+ * Generated bundle index. Do not edit.
2274
+ */
2275
+
2276
+ export { ColumnSortType, MnCollectionBase, MnCollectionPagination, MnCollectionState, MnGrid, MnHiddenBelowDirective, MnList, MnSelectableCollectionBase, MnShowAboveDirective, MnShowBelowDirective, MnTable, defaultFilterPredicate, emptyFilterValue, isFilterValueActive, matchesColumnFilter, resolveFilterableValue };
2277
+ //# sourceMappingURL=mn-angular-lib-collection.mjs.map