mn-angular-lib 1.0.177 → 1.0.179

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 +728 -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 -15509
  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 +1075 -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 -10816
  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,573 @@
1
+ import * as i0 from '@angular/core';
2
+ import { inject, EventEmitter, isSignal, Output, Input, ViewChild, Component } from '@angular/core';
3
+ import { Router, ActivatedRoute } from '@angular/router';
4
+ import { MnTranslatePipe } from 'mn-angular-lib/core';
5
+ import { MnCollectionState } from 'mn-angular-lib/collection';
6
+ import { CommonModule } from '@angular/common';
7
+ import { MnBadge, MnSkeleton } from 'mn-angular-lib/button';
8
+
9
+ /** Fallback number of skeleton tabs when no items are known and no count is given. */
10
+ const DEFAULT_SKELETON_TAB_COUNT = 3;
11
+ /** Query parameter the active tab is mirrored in unless the data source names another. */
12
+ const DEFAULT_TAB_URL_PARAM = 'tab';
13
+ /** Key used for a label that slugs to nothing (e.g. punctuation only). */
14
+ const FALLBACK_TAB_URL_KEY = 'tab';
15
+ /**
16
+ * Slugs a tab label into the value it takes in the URL: the last segment of a
17
+ * translation key, kebab-cased. `matches.hub.tab.entrants` → `entrants`,
18
+ * `members.tabMembers` → `tab-members`.
19
+ * @param label - The tab's label or translation key.
20
+ */
21
+ function tabUrlKey(label) {
22
+ const segment = label.split('.').pop() ?? label;
23
+ const slug = segment
24
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
25
+ .replace(/[^a-zA-Z0-9]+/g, '-')
26
+ .replace(/^-+|-+$/g, '')
27
+ .toLowerCase();
28
+ return slug || FALLBACK_TAB_URL_KEY;
29
+ }
30
+ /**
31
+ * Tab component that renders a horizontal tab bar.
32
+ * Supports translation keys for labels via MnTranslatePipe.
33
+ *
34
+ * The active tab is mirrored in the URL query string by default, so a reload,
35
+ * a back button or a shared link lands on the same tab; see
36
+ * {@link MnTabDataSource.urlParam} to rename that parameter or switch it off.
37
+ */
38
+ class MnTabComponent {
39
+ /**
40
+ * Router the active tab is written to. Optional: a tab bar used outside a
41
+ * routed application still works, it just has no URL to mirror into.
42
+ */
43
+ router = inject(Router, { optional: true });
44
+ /** Route the tab value is read back from; absent for the same reason as {@link router}. */
45
+ route = inject(ActivatedRoute, { optional: true });
46
+ /** Watches the URL so a deep link, a back button or an in-app link moves the tab bar. */
47
+ queryParamsSub;
48
+ /**
49
+ * URL keys of the current items, memoised on the items array so a slug is
50
+ * computed once per tab set rather than on every change-detection pass.
51
+ */
52
+ urlKeyCache;
53
+ /** URL key of {@link currentActive}, so a rebuilt tab set can be recognised as the same tab. */
54
+ currentKey;
55
+ /**
56
+ * Key of a selection whose URL write has not landed yet. Navigation is
57
+ * asynchronous, so a consumer that rebuilds its tabs in response to the click
58
+ * can be resolved against a URL that still names the previous tab; until the
59
+ * write completes, this is the truth about what the user picked.
60
+ */
61
+ pendingKey;
62
+ /** Set on destroy so a deferred restore can't announce a tab nobody is showing. */
63
+ destroyed = false;
64
+ /** The horizontally-scrolling wrapper the edge fade is painted onto. */
65
+ scrollContainer;
66
+ /** The tab row; queried for the active tab so the indicator can measure it. */
67
+ tabList;
68
+ /** The shared underline that slides to the active tab. */
69
+ indicator;
70
+ /** Pending indicator remeasure, cancelled on destroy so a post-destroy frame can't read a detached ref. */
71
+ indicatorFrame;
72
+ /**
73
+ * True while a click-initiated slide is animating. The active tab's
74
+ * `font-bold` widens the row, which fires {@link resizeObserver}; without
75
+ * this guard the observer's snap ({@link updateIndicator} with `animate:
76
+ * false`) would land the indicator at its target the same frame the slide
77
+ * starts, so the transition never paints. Set synchronously in
78
+ * {@link setActive} — before the frame runs — so the guard doesn't depend on
79
+ * rAF-vs-ResizeObserver callback ordering.
80
+ */
81
+ sliding = false;
82
+ /** Clears {@link sliding} after the slide finishes; re-armed per click, cancelled on destroy. */
83
+ slidingTimer;
84
+ /** Slide duration in ms; matches the indicator's `duration-300` transition. */
85
+ static SLIDE_MS = 300;
86
+ /** How far the fade reaches in from each overflowing edge. */
87
+ static FADE = '2rem';
88
+ /** Data source containing tab items and default active index. */
89
+ dataSource;
90
+ /**
91
+ * Whether to enable horizontal scrolling when items overflow.
92
+ * When true, tabs scroll horizontally instead of overflowing their container.
93
+ *
94
+ * Defaults to `true`: the tab bar never wraps (`flex-nowrap`), so without
95
+ * scrolling an overflowing bar would clip its last tabs or push the page width
96
+ * on narrow screens. When the tabs already fit, `overflow-x-auto` is a no-op,
97
+ * so this default only ever changes behaviour for the overflow case it fixes.
98
+ */
99
+ scrollable = true;
100
+ /**
101
+ * Whether tabs should stretch to fill the available width.
102
+ * Defaults to false, so tabs only take as much space as their content.
103
+ */
104
+ justified = false;
105
+ /** Emits the newly activated tab item whenever the active tab changes. */
106
+ activeChange = new EventEmitter();
107
+ /** The currently active tab item. */
108
+ currentActive;
109
+ /** Watches the wrapper and the tab row so the fade re-evaluates on width or content changes. */
110
+ resizeObserver;
111
+ /**
112
+ * Whether the tab bar is loading and should render skeleton tabs, from
113
+ * {@link MnTabDataSource.state}.
114
+ */
115
+ get isLoadingState() {
116
+ return this.dataSource.state === MnCollectionState.LOADING;
117
+ }
118
+ /**
119
+ * Index array sizing the loading skeleton: `skeletonCount` when provided,
120
+ * otherwise the number of known items, falling back to a default when none.
121
+ */
122
+ get skeletonTabs() {
123
+ const count = this.dataSource.skeletonCount ??
124
+ (this.dataSource.items.length || DEFAULT_SKELETON_TAB_COUNT);
125
+ return Array.from({ length: count }, (_, index) => index);
126
+ }
127
+ constructor() {
128
+ // The URL is a second source of truth for the selection: a deep link, an
129
+ // in-app link into another tab of the page already on screen, or the back
130
+ // button all change it without a click landing on this component.
131
+ this.queryParamsSub = this.route?.queryParamMap.subscribe((params) => {
132
+ const param = this.urlParam();
133
+ if (param)
134
+ this.activateUrlKey(params.get(param));
135
+ });
136
+ }
137
+ /**
138
+ * Re-resolves the active tab on every change-detection pass.
139
+ *
140
+ * The data source is often populated or rebuilt asynchronously (tabs that
141
+ * depend on fetched data or permissions). Resolving the active tab only once
142
+ * at init would leave {@link currentActive} pointing at a stale item — the
143
+ * tab bar would then highlight nothing and swallow the first click — so the
144
+ * selection is kept in sync with whatever the data source currently holds.
145
+ */
146
+ ngDoCheck() {
147
+ this.syncActiveTab();
148
+ }
149
+ /**
150
+ * Starts watching the scroll wrapper so the edge fade stays honest. A scroll
151
+ * moves the fade to whichever side now hides tabs; a resize (viewport change)
152
+ * or a change to the tab row's width (tabs added, relabelled, skeleton →
153
+ * loaded) re-checks whether either edge overflows at all.
154
+ */
155
+ ngAfterViewInit() {
156
+ const el = this.scrollContainer?.nativeElement;
157
+ if (!el)
158
+ return;
159
+ this.resizeObserver = new ResizeObserver(() => {
160
+ this.updateEdgeFades();
161
+ // Tabs may have reflowed (viewport change, justified widths); snap the
162
+ // indicator to the new geometry — animating a resize tick reads as jank.
163
+ // But skip the snap mid-slide: a click's own `font-bold` resizes the row
164
+ // and fires this observer, and snapping there kills the slide it triggered.
165
+ if (!this.sliding)
166
+ this.updateIndicator(false);
167
+ });
168
+ this.resizeObserver.observe(el);
169
+ if (el.firstElementChild)
170
+ this.resizeObserver.observe(el.firstElementChild);
171
+ this.updateEdgeFades();
172
+ // Place the indicator on the default tab without a slide-in from zero.
173
+ this.updateIndicator(false);
174
+ }
175
+ /** Wrapper geometry (`scrollWidth:clientWidth`) at the last fade evaluation. */
176
+ lastFadeGeometry = '';
177
+ /**
178
+ * Re-evaluates the edge fade when the wrapper's scrollable extent changes without its box
179
+ * changing. {@link resizeObserver} only sees border-box changes, and the tab row is a
180
+ * block-level flex container that keeps its parent's width while its tabs overflow inside it,
181
+ * so tabs that arrive after init (permission-gated tabs, badge counts, skeleton → loaded) grow
182
+ * `scrollWidth` without firing it; until a resize or scroll the fade stayed off. Two property
183
+ * reads per pass; the repaint only runs when they moved.
184
+ */
185
+ ngAfterViewChecked() {
186
+ const el = this.scrollContainer?.nativeElement;
187
+ if (!el)
188
+ return;
189
+ const geometry = `${el.scrollWidth}:${el.clientWidth}`;
190
+ if (geometry === this.lastFadeGeometry)
191
+ return;
192
+ this.lastFadeGeometry = geometry;
193
+ this.updateEdgeFades();
194
+ }
195
+ ngOnDestroy() {
196
+ this.destroyed = true;
197
+ this.queryParamsSub?.unsubscribe();
198
+ this.resizeObserver?.disconnect();
199
+ if (this.indicatorFrame !== undefined)
200
+ cancelAnimationFrame(this.indicatorFrame);
201
+ if (this.slidingTimer !== undefined)
202
+ clearTimeout(this.slidingTimer);
203
+ }
204
+ /**
205
+ * Paints a fade over whichever edge has tabs scrolled out of view — a soft
206
+ * dissolve that reads as "more this way", the affordance a hidden scrollbar
207
+ * otherwise costs us. Uses a mask (content → transparent) rather than a
208
+ * background-coloured overlay, so it needs no knowledge of the theme.
209
+ */
210
+ updateEdgeFades() {
211
+ const el = this.scrollContainer?.nativeElement;
212
+ if (!el)
213
+ return;
214
+ const fadeStart = el.scrollLeft > 1;
215
+ const fadeEnd = el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
216
+ const f = MnTabComponent.FADE;
217
+ let mask = '';
218
+ if (this.scrollable && fadeStart && fadeEnd) {
219
+ mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 calc(100% - ${f}), transparent 100%)`;
220
+ }
221
+ else if (this.scrollable && fadeStart) {
222
+ mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 100%)`;
223
+ }
224
+ else if (this.scrollable && fadeEnd) {
225
+ mask = `linear-gradient(to right, #000 0, #000 calc(100% - ${f}), transparent 100%)`;
226
+ }
227
+ el.style.maskImage = mask;
228
+ el.style.setProperty('-webkit-mask-image', mask);
229
+ }
230
+ /**
231
+ * Sets the given tab item as active, invoking deactivate/activate callbacks,
232
+ * and records the selection in the URL so it survives a reload or a share.
233
+ * @param item - The tab item to activate.
234
+ */
235
+ setActive(item) {
236
+ if (this.currentActive === item) {
237
+ return;
238
+ }
239
+ this.activate(item);
240
+ this.writeUrl(item);
241
+ }
242
+ /**
243
+ * Whether a tab is the bar's single Tab stop: the active tab, or the first tab while none is
244
+ * active yet. Every other tab is reached with the arrow keys, so Tab leaves the bar in one press.
245
+ * @param item - The tab to check.
246
+ * @returns True for the one tab that keeps `tabindex="0"`.
247
+ */
248
+ isTabStop(item) {
249
+ return this.currentActive ? this.currentActive === item : this.dataSource?.items[0] === item;
250
+ }
251
+ /**
252
+ * Keyboard handling on a tab. Left and Right move to the previous or next tab and wrap at the
253
+ * ends, Home and End jump to the first and last; the tab moved to is activated at once
254
+ * (automatic activation) and receives focus. Enter and Space activate the focused tab, handled
255
+ * on keydown so Space does not scroll the page first. Other keys are left alone.
256
+ * @param event - The keydown on a tab.
257
+ * @param item - The tab the key was pressed on.
258
+ */
259
+ onTabKeydown(event, item) {
260
+ const items = this.dataSource?.items ?? [];
261
+ const index = items.indexOf(item);
262
+ if (index < 0)
263
+ return;
264
+ let target;
265
+ switch (event.key) {
266
+ case 'ArrowRight':
267
+ target = (index + 1) % items.length;
268
+ break;
269
+ case 'ArrowLeft':
270
+ target = (index - 1 + items.length) % items.length;
271
+ break;
272
+ case 'Home':
273
+ target = 0;
274
+ break;
275
+ case 'End':
276
+ target = items.length - 1;
277
+ break;
278
+ case 'Enter':
279
+ case ' ':
280
+ event.preventDefault();
281
+ this.setActive(item);
282
+ return;
283
+ default:
284
+ return;
285
+ }
286
+ event.preventDefault();
287
+ this.setActive(items[target]);
288
+ this.focusTab(target);
289
+ }
290
+ /**
291
+ * Moves focus to the tab at `index` and scrolls it into view inside a scrollable bar. Focusing
292
+ * works before change detection has moved `tabindex="0"` onto it, because a script may focus an
293
+ * element with `tabindex="-1"`.
294
+ * @param index - Position of the tab in the data source's items.
295
+ */
296
+ focusTab(index) {
297
+ const tabs = this.tabList?.nativeElement.querySelectorAll('[role="tab"]');
298
+ const tab = tabs?.[index];
299
+ if (!tab)
300
+ return;
301
+ tab.focus();
302
+ tab.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
303
+ }
304
+ /**
305
+ * Moves the selection to `item` and tells the consumer about it: the
306
+ * deactivate/activate/emit sequence a click produces, shared by the click
307
+ * path and the URL-driven ones (deep link, back button), which owe the
308
+ * consumer the same notifications.
309
+ * @param item - The tab item to activate.
310
+ */
311
+ activate(item) {
312
+ this.currentActive?.onDeactivate?.();
313
+ item.onClick?.();
314
+ this.select(item);
315
+ this.activeChange.emit(item);
316
+ // Slide the underline to the new tab. Measure on the next frame, after
317
+ // change detection has applied the active tab's `font-bold` (which widens
318
+ // it) so the indicator lands on the final, bolded geometry. Guard the slide
319
+ // against the resize snap the same `font-bold` triggers (see {@link sliding}).
320
+ this.beginSlide();
321
+ this.scheduleIndicator(true);
322
+ }
323
+ /**
324
+ * Marks a click-driven slide as in progress and schedules the guard to lift
325
+ * once the transition has finished. A timeout (not `transitionend`) so the
326
+ * flag still clears under `motion-reduce`, where no transition event fires.
327
+ */
328
+ beginSlide() {
329
+ this.sliding = true;
330
+ if (this.slidingTimer !== undefined)
331
+ clearTimeout(this.slidingTimer);
332
+ this.slidingTimer = setTimeout(() => {
333
+ this.slidingTimer = undefined;
334
+ this.sliding = false;
335
+ }, MnTabComponent.SLIDE_MS);
336
+ }
337
+ /**
338
+ * Moves the shared underline to the active tab. When `animate` is false the
339
+ * move is snapped (no slide) by disabling the transition for one reflow —
340
+ * used on init, async selection and resize, where a slide would read as jank.
341
+ * @param animate - Whether the move should slide (true) or snap (false).
342
+ */
343
+ updateIndicator(animate) {
344
+ const bar = this.indicator?.nativeElement;
345
+ const list = this.tabList?.nativeElement;
346
+ if (!bar || !list)
347
+ return;
348
+ const active = list.querySelector('[role="tab"][aria-selected="true"]');
349
+ if (!active) {
350
+ bar.style.opacity = '0';
351
+ return;
352
+ }
353
+ if (!animate)
354
+ bar.style.transition = 'none';
355
+ bar.style.opacity = '1';
356
+ bar.style.width = `${active.offsetWidth}px`;
357
+ bar.style.transform = `translateX(${active.offsetLeft}px)`;
358
+ if (!animate) {
359
+ // Force a reflow so the snapped values apply before the transition is
360
+ // restored, then hand animation back to the CSS class.
361
+ void bar.offsetWidth;
362
+ bar.style.transition = '';
363
+ }
364
+ }
365
+ /**
366
+ * Remeasures the indicator on the next animation frame, so the read happens
367
+ * after layout reflects the latest active-tab classes. Coalesces bursts and
368
+ * is cancellable on destroy.
369
+ * @param animate - Whether the resulting move should slide.
370
+ */
371
+ scheduleIndicator(animate) {
372
+ if (this.indicatorFrame !== undefined)
373
+ cancelAnimationFrame(this.indicatorFrame);
374
+ this.indicatorFrame = requestAnimationFrame(() => {
375
+ this.indicatorFrame = undefined;
376
+ this.updateIndicator(animate);
377
+ });
378
+ }
379
+ /**
380
+ * Returns the resolved badge value for a tab item, supporting both plain numbers and Signal<number>.
381
+ * @param item - The tab item whose badge to resolve.
382
+ */
383
+ getBadge(item) {
384
+ if (isSignal(item.badge))
385
+ return item.badge();
386
+ return item.badge;
387
+ }
388
+ /**
389
+ * Ensures {@link currentActive} references a tab that still exists in the data
390
+ * source, preferring the tab named in the URL and falling back to the
391
+ * configured default tab when the current selection is missing or stale
392
+ * (e.g. after the items array is replaced).
393
+ */
394
+ syncActiveTab() {
395
+ const items = this.dataSource?.items;
396
+ if (!items || items.length === 0) {
397
+ if (this.currentActive !== undefined) {
398
+ this.currentActive = undefined;
399
+ this.currentKey = undefined;
400
+ this.scheduleIndicator(false);
401
+ }
402
+ return;
403
+ }
404
+ if (this.currentActive && items.includes(this.currentActive)) {
405
+ return;
406
+ }
407
+ const defaultIndex = this.dataSource.defaultActive;
408
+ const index = defaultIndex >= 0 && defaultIndex < items.length ? defaultIndex : 0;
409
+ const fallback = items[index];
410
+ const restored = this.itemFromUrl(items);
411
+ const previousKey = this.currentKey;
412
+ this.select(restored ?? fallback);
413
+ // Selection resolved from data (not a user click): snap, don't slide.
414
+ this.scheduleIndicator(false);
415
+ if (restored && restored !== fallback && this.currentKey !== previousKey) {
416
+ // The URL asks for a tab the consumer has not rendered, so this selection
417
+ // has to be announced like a click's would be — but only the first time,
418
+ // or a consumer that rebuilds its items array would re-run the tab's
419
+ // callbacks on every rebuild. Deferred out of the change-detection pass
420
+ // that resolved it: the consumer will flip its own state in response, and
421
+ // doing that mid-pass writes to bindings that have already been checked.
422
+ queueMicrotask(() => this.announceRestored(restored));
423
+ }
424
+ }
425
+ /**
426
+ * Records `item` as the selection, remembering its URL key so the same tab is
427
+ * recognised after the consumer rebuilds the items array.
428
+ * @param item - The newly selected tab.
429
+ */
430
+ select(item) {
431
+ const items = this.dataSource.items;
432
+ this.currentActive = item;
433
+ this.currentKey = this.urlKeys(items)[items.indexOf(item)];
434
+ }
435
+ /**
436
+ * Runs the restored tab's callbacks a change-detection pass later, unless the
437
+ * selection moved on in the meantime (a click, or another tab set arriving).
438
+ * @param item - The tab restored from the URL.
439
+ */
440
+ announceRestored(item) {
441
+ if (this.destroyed || this.currentActive !== item)
442
+ return;
443
+ item.onClick?.();
444
+ this.activeChange.emit(item);
445
+ }
446
+ /**
447
+ * Activates the tab a URL value names, when it is not the tab already on
448
+ * screen. Values naming no known tab are ignored: another tab bar on the page
449
+ * may own that parameter, and a stale link should leave the default standing.
450
+ * @param key - The value read from the query parameter, if any.
451
+ */
452
+ activateUrlKey(key) {
453
+ const items = this.dataSource?.items;
454
+ if (!key || !items?.length)
455
+ return;
456
+ const item = items[this.urlKeys(items).indexOf(key)];
457
+ if (!item || item === this.currentActive)
458
+ return;
459
+ this.activate(item);
460
+ }
461
+ /**
462
+ * The query parameter this tab bar mirrors into, or undefined when there is
463
+ * nothing to mirror into (no router) or the consumer switched it off.
464
+ */
465
+ urlParam() {
466
+ if (!this.router || !this.route)
467
+ return undefined;
468
+ const param = this.dataSource?.urlParam ?? DEFAULT_TAB_URL_PARAM;
469
+ return param === false || param === '' ? undefined : param;
470
+ }
471
+ /**
472
+ * The tab the current URL asks for, if it names one of `items`.
473
+ * @param items - The tab set to resolve the URL value against.
474
+ */
475
+ itemFromUrl(items) {
476
+ const param = this.urlParam();
477
+ if (!param)
478
+ return undefined;
479
+ const key = this.pendingKey ?? this.route?.snapshot.queryParamMap.get(param);
480
+ if (!key)
481
+ return undefined;
482
+ const index = this.urlKeys(items).indexOf(key);
483
+ return index === -1 ? undefined : items[index];
484
+ }
485
+ /**
486
+ * Records the active tab in the query string, replacing the current history
487
+ * entry: switching tabs is not a navigation to walk back through, and back
488
+ * should leave the page rather than retrace its tabs.
489
+ * @param item - The tab that just became active.
490
+ */
491
+ writeUrl(item) {
492
+ const param = this.urlParam();
493
+ if (!param || !this.router)
494
+ return;
495
+ const items = this.dataSource.items;
496
+ const key = this.urlKeys(items)[items.indexOf(item)];
497
+ if (!key)
498
+ return;
499
+ this.pendingKey = key;
500
+ // No path commands and no `relativeTo`, so only the query string changes.
501
+ // That holds wherever the tab bar sits, including a modal body, which has
502
+ // no route of its own to be relative to.
503
+ void this.router
504
+ .navigate([], {
505
+ queryParams: { [param]: key },
506
+ queryParamsHandling: 'merge',
507
+ replaceUrl: true,
508
+ })
509
+ .catch(() => undefined)
510
+ .then(() => {
511
+ // Only clear our own write; a later click already owns the pending key.
512
+ if (this.pendingKey === key)
513
+ this.pendingKey = undefined;
514
+ });
515
+ }
516
+ /**
517
+ * The URL key of every tab, in item order: the item's `id`, else a slug of
518
+ * its label. Repeats are numbered so each tab still round-trips through the
519
+ * URL; give such tabs an explicit `id` to choose the value yourself.
520
+ * @param items - The tab set to key.
521
+ */
522
+ urlKeys(items) {
523
+ if (this.urlKeyCache?.items === items)
524
+ return this.urlKeyCache.keys;
525
+ const used = new Map();
526
+ const keys = items.map((item) => {
527
+ const base = item.id ?? tabUrlKey(item.label);
528
+ const taken = used.get(base) ?? 0;
529
+ used.set(base, taken + 1);
530
+ return taken === 0 ? base : `${base}-${taken + 1}`;
531
+ });
532
+ this.urlKeyCache = { items, keys };
533
+ return keys;
534
+ }
535
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTabComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
536
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.3", type: MnTabComponent, isStandalone: true, selector: "mn-tab", inputs: { dataSource: "dataSource", scrollable: "scrollable", justified: "justified" }, outputs: { activeChange: "activeChange" }, viewQueries: [{ propertyName: "scrollContainer", first: true, predicate: ["scrollContainer"], descendants: true }, { propertyName: "tabList", first: true, predicate: ["tabList"], descendants: true }, { propertyName: "indicator", first: true, predicate: ["indicator"], descendants: true }], ngImport: i0, template: "<div class=\"mb-10\">\n <div\n #scrollContainer\n (scroll)=\"updateEdgeFades()\"\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n #tabList\n role=\"tablist\"\n class=\"tabs relative flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n <!--\n Shared sliding indicator: a single underline that travels to the active\n tab, rather than each tab flipping its own border on/off (which snaps).\n Pinned to left-0/top-auto so offsetLeft maps 1:1 regardless of the\n flex justify-content or the justified full-width layout; position and\n width are measured and set from TS. Sits on the same baseline as the\n hover ::after so hover \u2192 select reads as one continuous underline.\n -->\n <div\n #indicator\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute left-0 top-auto bottom-0 h-[2px] w-0 bg-primary opacity-0 transition-[transform,width] duration-300 ease-out motion-reduce:transition-none\"\n ></div>\n @if (isLoadingState) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <!-- One Tab stop per bar (the active tab); the arrow keys, Home and End move between\n tabs and activate them, the WAI-ARIA tabs pattern. Every tab used to be its own\n Tab stop with no arrow keys, so crossing an eight-tab bar took eight presses. -->\n <div\n (click)=\"setActive(item)\"\n (keydown)=\"onTabKeydown($event, item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [attr.tabindex]=\"isTabStop(item) ? 0 : -1\"\n [class.hover:after:scale-x-100]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab relative px-4 py-2 border-b-2 border-transparent cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2 after:content-[''] after:absolute after:inset-x-0 after:-bottom-[2px] after:h-[2px] after:bg-primary/60 after:origin-center after:scale-x-0 after:transition-transform after:duration-300 after:ease-out\"\n role=\"tab\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: MnBadge, selector: "span[mnBadge]", inputs: ["data"] }, { kind: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { kind: "pipe", type: MnTranslatePipe, name: "mnTranslate" }] });
537
+ }
538
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.3", ngImport: i0, type: MnTabComponent, decorators: [{
539
+ type: Component,
540
+ args: [{ selector: 'mn-tab', standalone: true, imports: [MnTranslatePipe, CommonModule, MnBadge, MnSkeleton], template: "<div class=\"mb-10\">\n <div\n #scrollContainer\n (scroll)=\"updateEdgeFades()\"\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n #tabList\n role=\"tablist\"\n class=\"tabs relative flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n <!--\n Shared sliding indicator: a single underline that travels to the active\n tab, rather than each tab flipping its own border on/off (which snaps).\n Pinned to left-0/top-auto so offsetLeft maps 1:1 regardless of the\n flex justify-content or the justified full-width layout; position and\n width are measured and set from TS. Sits on the same baseline as the\n hover ::after so hover \u2192 select reads as one continuous underline.\n -->\n <div\n #indicator\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute left-0 top-auto bottom-0 h-[2px] w-0 bg-primary opacity-0 transition-[transform,width] duration-300 ease-out motion-reduce:transition-none\"\n ></div>\n @if (isLoadingState) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <!-- One Tab stop per bar (the active tab); the arrow keys, Home and End move between\n tabs and activate them, the WAI-ARIA tabs pattern. Every tab used to be its own\n Tab stop with no arrow keys, so crossing an eight-tab bar took eight presses. -->\n <div\n (click)=\"setActive(item)\"\n (keydown)=\"onTabKeydown($event, item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [attr.tabindex]=\"isTabStop(item) ? 0 : -1\"\n [class.hover:after:scale-x-100]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab relative px-4 py-2 border-b-2 border-transparent cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2 after:content-[''] after:absolute after:inset-x-0 after:-bottom-[2px] after:h-[2px] after:bg-primary/60 after:origin-center after:scale-x-0 after:transition-transform after:duration-300 after:ease-out\"\n role=\"tab\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n" }]
541
+ }], ctorParameters: () => [], propDecorators: { scrollContainer: [{
542
+ type: ViewChild,
543
+ args: ['scrollContainer']
544
+ }], tabList: [{
545
+ type: ViewChild,
546
+ args: ['tabList']
547
+ }], indicator: [{
548
+ type: ViewChild,
549
+ args: ['indicator']
550
+ }], dataSource: [{
551
+ type: Input
552
+ }], scrollable: [{
553
+ type: Input
554
+ }], justified: [{
555
+ type: Input
556
+ }], activeChange: [{
557
+ type: Output
558
+ }] } });
559
+
560
+ /**
561
+ * Public API of the `mn-angular-lib/tab` entry point: tabs.
562
+ *
563
+ * Each entry point is its own module in the published package, so a consumer's bundler
564
+ * splits it into the chunk that uses it instead of loading the whole library at startup.
565
+ * The root `mn-angular-lib` entry re-exports every entry point.
566
+ */
567
+
568
+ /**
569
+ * Generated bundle index. Do not edit.
570
+ */
571
+
572
+ export { MnTabComponent };
573
+ //# sourceMappingURL=mn-angular-lib-tab.mjs.map