mn-angular-lib 2.0.34 → 2.0.36

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 (52) hide show
  1. package/fesm2022/mn-angular-lib-alert.mjs +515 -527
  2. package/fesm2022/mn-angular-lib-alert.mjs.map +1 -1
  3. package/fesm2022/mn-angular-lib-bottom-sheet.mjs +264 -357
  4. package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -1
  5. package/fesm2022/mn-angular-lib-button.mjs +819 -382
  6. package/fesm2022/mn-angular-lib-button.mjs.map +1 -1
  7. package/fesm2022/mn-angular-lib-calendar-core.mjs +240 -365
  8. package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -1
  9. package/fesm2022/mn-angular-lib-calendar.mjs +1691 -1545
  10. package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -1
  11. package/fesm2022/mn-angular-lib-collection.mjs +2367 -2796
  12. package/fesm2022/mn-angular-lib-collection.mjs.map +1 -1
  13. package/fesm2022/mn-angular-lib-core.mjs +693 -1241
  14. package/fesm2022/mn-angular-lib-core.mjs.map +1 -1
  15. package/fesm2022/mn-angular-lib-display.mjs +679 -712
  16. package/fesm2022/mn-angular-lib-display.mjs.map +1 -1
  17. package/fesm2022/mn-angular-lib-forms.mjs +3671 -4647
  18. package/fesm2022/mn-angular-lib-forms.mjs.map +1 -1
  19. package/fesm2022/mn-angular-lib-keyboard.mjs +221 -190
  20. package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -1
  21. package/fesm2022/mn-angular-lib-modal-core.mjs +711 -896
  22. package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -1
  23. package/fesm2022/mn-angular-lib-modal-ui.mjs +2089 -2035
  24. package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -1
  25. package/fesm2022/mn-angular-lib-modal.mjs +76 -121
  26. package/fesm2022/mn-angular-lib-modal.mjs.map +1 -1
  27. package/fesm2022/mn-angular-lib-rich-text-editor.mjs +289 -277
  28. package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -1
  29. package/fesm2022/mn-angular-lib-segmented.mjs +189 -241
  30. package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -1
  31. package/fesm2022/mn-angular-lib-tab.mjs +409 -642
  32. package/fesm2022/mn-angular-lib-tab.mjs.map +1 -1
  33. package/fesm2022/mn-angular-lib.mjs +16 -29
  34. package/package.json +1 -1
  35. package/types/mn-angular-lib-alert.d.ts +239 -241
  36. package/types/mn-angular-lib-bottom-sheet.d.ts +190 -150
  37. package/types/mn-angular-lib-button.d.ts +319 -317
  38. package/types/mn-angular-lib-calendar-core.d.ts +199 -209
  39. package/types/mn-angular-lib-calendar.d.ts +656 -511
  40. package/types/mn-angular-lib-collection.d.ts +1649 -1585
  41. package/types/mn-angular-lib-core.d.ts +524 -535
  42. package/types/mn-angular-lib-display.d.ts +946 -886
  43. package/types/mn-angular-lib-forms.d.ts +3012 -3013
  44. package/types/mn-angular-lib-keyboard.d.ts +125 -85
  45. package/types/mn-angular-lib-modal-core.d.ts +978 -994
  46. package/types/mn-angular-lib-modal-ui.d.ts +541 -493
  47. package/types/mn-angular-lib-modal.d.ts +24 -27
  48. package/types/mn-angular-lib-rich-text-editor.d.ts +131 -98
  49. package/types/mn-angular-lib-segmented.d.ts +354 -341
  50. package/types/mn-angular-lib-tab.d.ts +345 -336
  51. package/types/mn-angular-lib.d.ts +16 -16
  52. package/fesm2022/mn-angular-lib.mjs.map +0 -1
@@ -1,126 +1,81 @@
1
- import * as i0 from '@angular/core';
2
- import { inject, ApplicationRef, EnvironmentInjector, createComponent, Injectable } from '@angular/core';
3
- import { MnModalRef, ModalCloseReason } from 'mn-angular-lib/modal-core';
4
-
5
- /** The loaded modal components, shared by every service instance. */
1
+ import * as i0 from "@angular/core";
2
+ import { ApplicationRef, EnvironmentInjector, Injectable, createComponent, inject } from "@angular/core";
3
+ import { MnModalRef, ModalCloseReason } from "mn-angular-lib/modal-core";
6
4
  let modalUi = null;
7
- /** The in-flight or settled load of the modal components. */
8
5
  let modalUiLoad = null;
9
- /**
10
- * Loads `mn-angular-lib/modal-ui` once. The shell and its bodies render every form field and
11
- * the table, so importing them statically put most of the library into each consumer's
12
- * startup bundle just because a service injects `MnModalService`.
13
- * @returns The loaded entry point.
14
- */
15
6
  function loadModalUi() {
16
- modalUiLoad ??= import('mn-angular-lib/modal-ui').then((ui) => (modalUi = ui));
17
- return modalUiLoad;
18
- }
19
- class MnModalService {
20
- appRef = inject(ApplicationRef);
21
- injector = inject(EnvironmentInjector);
22
- modalStack = [];
23
- constructor() {
24
- // Fetch the modal components once the app is idle, so the first modal opens without a
25
- // network round trip while startup never waits for them.
26
- if (typeof window !== 'undefined') {
27
- const whenIdle = window.requestIdleCallback ?? ((callback) => setTimeout(callback, 2000));
28
- whenIdle(() => void this.preload().catch(() => undefined));
29
- }
30
- }
31
- /**
32
- * Loads the modal components ahead of the first `open()`. After it resolves, `open()` renders
33
- * synchronously; tests await it before asserting on the DOM.
34
- * @returns Resolves once the components are loaded.
35
- */
36
- preload() {
37
- return loadModalUi().then(() => undefined);
38
- }
39
- open(config) {
40
- // Work off a mutable shallow copy of the (frozen) builder config, shared by
41
- // both the shell and the ref. `ModalBuilder.build()` returns a frozen object;
42
- // `MnModalRef.update()` mutates the config in place (so the shell, which holds
43
- // the same reference, sees the change), which would throw on a frozen object.
44
- // Cloning here keeps the caller's built config immutable while giving the
45
- // runtime an extensible object to update (e.g. footer actions set at runtime).
46
- const workingConfig = { ...config };
47
- // The ref exists straight away so callers can subscribe and close as before; the shell
48
- // attaches to it as soon as the modal components are available (immediately once loaded).
49
- const modalRef = new MnModalRef(null, workingConfig);
50
- if (modalUi) {
51
- this.render(modalUi, modalRef, workingConfig);
52
- }
53
- else {
54
- loadModalUi().then((ui) => {
55
- if (!modalRef.isCloseRequested)
56
- this.render(ui, modalRef, workingConfig);
57
- }, (error) => {
58
- console.error('[MnModal] Failed to load the modal components', error);
59
- modalRef.dismiss(ModalCloseReason.PROGRAMMATIC);
60
- });
61
- }
62
- return modalRef;
63
- }
64
- /**
65
- * Creates the shell for a modal, stacks it on top of any open modal and attaches it to the app.
66
- * @param ui The loaded modal components.
67
- * @param modalRef The ref returned from `open()`.
68
- * @param workingConfig The mutable config shared by the ref and the shell.
69
- */
70
- render(ui, modalRef, workingConfig) {
71
- const componentRef = createComponent(ui.MnModalShellComponent, {
72
- environmentInjector: this.injector,
73
- });
74
- // TModel is erased at the shell boundary — the shell only needs TResult
75
- componentRef.instance.config = workingConfig;
76
- componentRef.instance.modalRef = modalRef;
77
- modalRef.attach(componentRef);
78
- // Update stack and dim previous modal
79
- if (this.modalStack.length > 0) {
80
- const prevModal = this.modalStack[this.modalStack.length - 1];
81
- prevModal.component.isStacked.set(true);
82
- }
83
- this.modalStack.push(modalRef);
84
- // Attach to application
85
- this.appRef.attachView(componentRef.hostView);
86
- const domElem = componentRef.location.nativeElement;
87
- document.body.appendChild(domElem);
88
- // Clean up on close
89
- modalRef.afterClosed$.subscribe(() => {
90
- this.appRef.detachView(componentRef.hostView);
91
- domElem.remove();
92
- // Update stack
93
- const index = this.modalStack.indexOf(modalRef);
94
- if (index > -1) {
95
- this.modalStack.splice(index, 1);
96
- if (this.modalStack.length > 0) {
97
- const topModal = this.modalStack[this.modalStack.length - 1];
98
- topModal.component.isStacked.set(false);
99
- }
100
- }
101
- });
102
- }
103
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnModalService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
104
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnModalService, providedIn: 'root' });
7
+ modalUiLoad ??= import("mn-angular-lib/modal-ui").then((ui) => modalUi = ui);
8
+ return modalUiLoad;
105
9
  }
106
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnModalService, decorators: [{
107
- type: Injectable,
108
- args: [{
109
- providedIn: 'root',
110
- }]
111
- }], ctorParameters: () => [] });
112
-
113
- /**
114
- * Public API of the `mn-angular-lib/modal` entry point: the modal service.
115
- *
116
- * Each entry point is its own module in the published package, so a consumer's bundler
117
- * splits it into the chunk that uses it instead of loading the whole library at startup.
118
- * The root `mn-angular-lib` entry re-exports every entry point.
119
- */
120
-
121
- /**
122
- * Generated bundle index. Do not edit.
123
- */
124
-
10
+ var MnModalService = class MnModalService {
11
+ appRef = inject(ApplicationRef);
12
+ injector = inject(EnvironmentInjector);
13
+ modalStack = [];
14
+ constructor() {
15
+ if (typeof window !== "undefined") (window.requestIdleCallback ?? ((callback) => setTimeout(callback, 2e3)))(() => void this.preload().catch(() => void 0));
16
+ }
17
+ preload() {
18
+ return loadModalUi().then(() => void 0);
19
+ }
20
+ open(config) {
21
+ const workingConfig = { ...config };
22
+ const modalRef = new MnModalRef(null, workingConfig);
23
+ if (modalUi) this.render(modalUi, modalRef, workingConfig);
24
+ else loadModalUi().then((ui) => {
25
+ if (!modalRef.isCloseRequested) this.render(ui, modalRef, workingConfig);
26
+ }, (error) => {
27
+ console.error("[MnModal] Failed to load the modal components", error);
28
+ modalRef.dismiss(ModalCloseReason.PROGRAMMATIC);
29
+ });
30
+ return modalRef;
31
+ }
32
+ render(ui, modalRef, workingConfig) {
33
+ const componentRef = createComponent(ui.MnModalShellComponent, { environmentInjector: this.injector });
34
+ componentRef.instance.config = workingConfig;
35
+ componentRef.instance.modalRef = modalRef;
36
+ modalRef.attach(componentRef);
37
+ if (this.modalStack.length > 0) this.modalStack[this.modalStack.length - 1].component.isStacked.set(true);
38
+ this.modalStack.push(modalRef);
39
+ this.appRef.attachView(componentRef.hostView);
40
+ const domElem = componentRef.location.nativeElement;
41
+ document.body.appendChild(domElem);
42
+ modalRef.afterClosed$.subscribe(() => {
43
+ this.appRef.detachView(componentRef.hostView);
44
+ domElem.remove();
45
+ const index = this.modalStack.indexOf(modalRef);
46
+ if (index > -1) {
47
+ this.modalStack.splice(index, 1);
48
+ if (this.modalStack.length > 0) this.modalStack[this.modalStack.length - 1].component.isStacked.set(false);
49
+ }
50
+ });
51
+ }
52
+ static ɵfac = i0.ɵɵngDeclareFactory({
53
+ minVersion: "12.0.0",
54
+ version: "22.2.2",
55
+ ngImport: i0,
56
+ type: MnModalService,
57
+ deps: [],
58
+ target: i0.ɵɵFactoryTarget.Injectable
59
+ });
60
+ static ɵprov = i0.ɵɵngDeclareInjectable({
61
+ minVersion: "12.0.0",
62
+ version: "22.2.2",
63
+ ngImport: i0,
64
+ type: MnModalService,
65
+ providedIn: "root"
66
+ });
67
+ };
68
+ i0.ɵɵngDeclareClassMetadata({
69
+ minVersion: "12.0.0",
70
+ version: "22.2.2",
71
+ ngImport: i0,
72
+ type: MnModalService,
73
+ decorators: [{
74
+ type: Injectable,
75
+ args: [{ providedIn: "root" }]
76
+ }],
77
+ ctorParameters: () => []
78
+ });
125
79
  export { MnModalService };
126
- //# sourceMappingURL=mn-angular-lib-modal.mjs.map
80
+
81
+ //# sourceMappingURL=mn-angular-lib-modal.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mn-angular-lib-modal.mjs","sources":["../../../projects/mn-angular-lib/modal/src/mn-modal/mn-modal.service.ts","../../../projects/mn-angular-lib/modal/public-api.ts","../../../projects/mn-angular-lib/modal/mn-angular-lib-modal.ts"],"sourcesContent":["import {ApplicationRef, ComponentRef, createComponent, EnvironmentInjector, inject, Injectable, Type,} from '@angular/core';\nimport {MnModalRef, ModalCloseReason, ModalConfig} from 'mn-angular-lib/modal-core';\nimport type {MnModalShellComponent} from 'mn-angular-lib/modal-ui';\n\n/** The modal components entry point, once loaded. */\ntype ModalUi = { MnModalShellComponent: Type<MnModalShellComponent<unknown>> };\n\n/** The loaded modal components, shared by every service instance. */\nlet modalUi: ModalUi | null = null;\n\n/** The in-flight or settled load of the modal components. */\nlet modalUiLoad: Promise<ModalUi> | null = null;\n\n/**\n * Loads `mn-angular-lib/modal-ui` once. The shell and its bodies render every form field and\n * the table, so importing them statically put most of the library into each consumer's\n * startup bundle just because a service injects `MnModalService`.\n * @returns The loaded entry point.\n */\nfunction loadModalUi(): Promise<ModalUi> {\n modalUiLoad ??= import('mn-angular-lib/modal-ui').then((ui) => (modalUi = ui));\n return modalUiLoad;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class MnModalService {\n private readonly appRef = inject(ApplicationRef);\n private readonly injector = inject(EnvironmentInjector);\n private readonly modalStack: MnModalRef<unknown>[] = [];\n\n constructor() {\n // Fetch the modal components once the app is idle, so the first modal opens without a\n // network round trip while startup never waits for them.\n if (typeof window !== 'undefined') {\n const whenIdle = window.requestIdleCallback ?? ((callback: () => void) => setTimeout(callback, 2000));\n whenIdle(() => void this.preload().catch(() => undefined));\n }\n }\n\n /**\n * Loads the modal components ahead of the first `open()`. After it resolves, `open()` renders\n * synchronously; tests await it before asserting on the DOM.\n * @returns Resolves once the components are loaded.\n */\n preload(): Promise<void> {\n return loadModalUi().then(() => undefined);\n }\n\n open<TResult = unknown, TModel = unknown>(config: ModalConfig<TResult, TModel>): MnModalRef<TResult> {\n // Work off a mutable shallow copy of the (frozen) builder config, shared by\n // both the shell and the ref. `ModalBuilder.build()` returns a frozen object;\n // `MnModalRef.update()` mutates the config in place (so the shell, which holds\n // the same reference, sees the change), which would throw on a frozen object.\n // Cloning here keeps the caller's built config immutable while giving the\n // runtime an extensible object to update (e.g. footer actions set at runtime).\n const workingConfig = {...(config as ModalConfig<TResult>)};\n\n // The ref exists straight away so callers can subscribe and close as before; the shell\n // attaches to it as soon as the modal components are available (immediately once loaded).\n const modalRef = new MnModalRef<TResult>(null, workingConfig);\n\n if (modalUi) {\n this.render(modalUi, modalRef, workingConfig);\n } else {\n loadModalUi().then(\n (ui) => {\n if (!modalRef.isCloseRequested) this.render(ui, modalRef, workingConfig);\n },\n (error: unknown) => {\n console.error('[MnModal] Failed to load the modal components', error);\n modalRef.dismiss(ModalCloseReason.PROGRAMMATIC);\n },\n );\n }\n\n return modalRef;\n }\n\n /**\n * Creates the shell for a modal, stacks it on top of any open modal and attaches it to the app.\n * @param ui The loaded modal components.\n * @param modalRef The ref returned from `open()`.\n * @param workingConfig The mutable config shared by the ref and the shell.\n */\n private render<TResult>(ui: ModalUi, modalRef: MnModalRef<TResult>, workingConfig: ModalConfig<TResult>): void {\n const componentRef = createComponent(ui.MnModalShellComponent, {\n environmentInjector: this.injector,\n }) as unknown as ComponentRef<MnModalShellComponent<TResult>>;\n\n // TModel is erased at the shell boundary — the shell only needs TResult\n componentRef.instance.config = workingConfig;\n componentRef.instance.modalRef = modalRef;\n modalRef.attach(componentRef);\n\n // Update stack and dim previous modal\n if (this.modalStack.length > 0) {\n const prevModal = this.modalStack[this.modalStack.length - 1];\n (prevModal.component as MnModalShellComponent<unknown>).isStacked.set(true);\n }\n this.modalStack.push(modalRef as unknown as MnModalRef<unknown>);\n\n // Attach to application\n this.appRef.attachView(componentRef.hostView);\n const domElem = componentRef.location.nativeElement;\n document.body.appendChild(domElem);\n\n // Clean up on close\n modalRef.afterClosed$.subscribe(() => {\n this.appRef.detachView(componentRef.hostView);\n domElem.remove();\n\n // Update stack\n const index = this.modalStack.indexOf(modalRef as unknown as MnModalRef<unknown>);\n if (index > -1) {\n this.modalStack.splice(index, 1);\n if (this.modalStack.length > 0) {\n const topModal = this.modalStack[this.modalStack.length - 1];\n (topModal.component as MnModalShellComponent<unknown>).isStacked.set(false);\n }\n }\n });\n }\n}\n","/**\n * Public API of the `mn-angular-lib/modal` entry point: the modal service.\n *\n * Each entry point is its own module in the published package, so a consumer's bundler\n * splits it into the chunk that uses it instead of loading the whole library at startup.\n * The root `mn-angular-lib` entry re-exports every entry point.\n */\nexport { MnModalService } from './src/mn-modal/mn-modal.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAOA;AACA,IAAI,OAAO,GAAmB,IAAI;AAElC;AACA,IAAI,WAAW,GAA4B,IAAI;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AAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAA0C,CAAC;AACjF,YAAA,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;gBACd,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;gBAChC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;AAC9B,oBAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;oBAC3D,QAAQ,CAAC,SAA4C,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;gBAC7E;YACF;AACF,QAAA,CAAC,CAAC;IACJ;uGAhGW,cAAc,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAd,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,cAAc,cAFb,MAAM,EAAA,CAAA;;2FAEP,cAAc,EAAA,UAAA,EAAA,CAAA;kBAH1B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;AC1BD;;;;;;AAMG;;ACNH;;AAEG;;"}
1
+ {"version":3,"file":"mn-angular-lib-modal.mjs","names":[],"sources":["../../../projects/mn-angular-lib/modal/src/mn-modal/mn-modal.service.ts"],"sourcesContent":["import {ApplicationRef, ComponentRef, createComponent, EnvironmentInjector, inject, Injectable, Type,} from '@angular/core';\nimport {MnModalRef, ModalCloseReason, ModalConfig} from 'mn-angular-lib/modal-core';\nimport type {MnModalShellComponent} from 'mn-angular-lib/modal-ui';\n\n/** The modal components entry point, once loaded. */\ntype ModalUi = { MnModalShellComponent: Type<MnModalShellComponent<unknown>> };\n\n/** The loaded modal components, shared by every service instance. */\nlet modalUi: ModalUi | null = null;\n\n/** The in-flight or settled load of the modal components. */\nlet modalUiLoad: Promise<ModalUi> | null = null;\n\n/**\n * Loads `mn-angular-lib/modal-ui` once. The shell and its bodies render every form field and\n * the table, so importing them statically put most of the library into each consumer's\n * startup bundle just because a service injects `MnModalService`.\n * @returns The loaded entry point.\n */\nfunction loadModalUi(): Promise<ModalUi> {\n modalUiLoad ??= import('mn-angular-lib/modal-ui').then((ui) => (modalUi = ui));\n return modalUiLoad;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class MnModalService {\n private readonly appRef = inject(ApplicationRef);\n private readonly injector = inject(EnvironmentInjector);\n private readonly modalStack: MnModalRef<unknown>[] = [];\n\n constructor() {\n // Fetch the modal components once the app is idle, so the first modal opens without a\n // network round trip while startup never waits for them.\n if (typeof window !== 'undefined') {\n const whenIdle = window.requestIdleCallback ?? ((callback: () => void) => setTimeout(callback, 2000));\n whenIdle(() => void this.preload().catch(() => undefined));\n }\n }\n\n /**\n * Loads the modal components ahead of the first `open()`. After it resolves, `open()` renders\n * synchronously; tests await it before asserting on the DOM.\n * @returns Resolves once the components are loaded.\n */\n preload(): Promise<void> {\n return loadModalUi().then(() => undefined);\n }\n\n open<TResult = unknown, TModel = unknown>(config: ModalConfig<TResult, TModel>): MnModalRef<TResult> {\n // Work off a mutable shallow copy of the (frozen) builder config, shared by\n // both the shell and the ref. `ModalBuilder.build()` returns a frozen object;\n // `MnModalRef.update()` mutates the config in place (so the shell, which holds\n // the same reference, sees the change), which would throw on a frozen object.\n // Cloning here keeps the caller's built config immutable while giving the\n // runtime an extensible object to update (e.g. footer actions set at runtime).\n const workingConfig = {...(config as ModalConfig<TResult>)};\n\n // The ref exists straight away so callers can subscribe and close as before; the shell\n // attaches to it as soon as the modal components are available (immediately once loaded).\n const modalRef = new MnModalRef<TResult>(null, workingConfig);\n\n if (modalUi) {\n this.render(modalUi, modalRef, workingConfig);\n } else {\n loadModalUi().then(\n (ui) => {\n if (!modalRef.isCloseRequested) this.render(ui, modalRef, workingConfig);\n },\n (error: unknown) => {\n console.error('[MnModal] Failed to load the modal components', error);\n modalRef.dismiss(ModalCloseReason.PROGRAMMATIC);\n },\n );\n }\n\n return modalRef;\n }\n\n /**\n * Creates the shell for a modal, stacks it on top of any open modal and attaches it to the app.\n * @param ui The loaded modal components.\n * @param modalRef The ref returned from `open()`.\n * @param workingConfig The mutable config shared by the ref and the shell.\n */\n private render<TResult>(ui: ModalUi, modalRef: MnModalRef<TResult>, workingConfig: ModalConfig<TResult>): void {\n const componentRef = createComponent(ui.MnModalShellComponent, {\n environmentInjector: this.injector,\n }) as unknown as ComponentRef<MnModalShellComponent<TResult>>;\n\n // TModel is erased at the shell boundary — the shell only needs TResult\n componentRef.instance.config = workingConfig;\n componentRef.instance.modalRef = modalRef;\n modalRef.attach(componentRef);\n\n // Update stack and dim previous modal\n if (this.modalStack.length > 0) {\n const prevModal = this.modalStack[this.modalStack.length - 1];\n (prevModal.component as MnModalShellComponent<unknown>).isStacked.set(true);\n }\n this.modalStack.push(modalRef as unknown as MnModalRef<unknown>);\n\n // Attach to application\n this.appRef.attachView(componentRef.hostView);\n const domElem = componentRef.location.nativeElement;\n document.body.appendChild(domElem);\n\n // Clean up on close\n modalRef.afterClosed$.subscribe(() => {\n this.appRef.detachView(componentRef.hostView);\n domElem.remove();\n\n // Update stack\n const index = this.modalStack.indexOf(modalRef as unknown as MnModalRef<unknown>);\n if (index > -1) {\n this.modalStack.splice(index, 1);\n if (this.modalStack.length > 0) {\n const topModal = this.modalStack[this.modalStack.length - 1];\n (topModal.component as MnModalShellComponent<unknown>).isStacked.set(false);\n }\n }\n });\n }\n}\n"],"mappings":";;;AAQA,IAAI,UAA0B;AAG9B,IAAI,cAAuC;AAQ3C,SAAS,cAAW;CAClB,gBAAgB,OAAO,0BAA0B,CAAC,MAAM,OAAQ,UAAU,EAAG;CAC7E,OAAO;AACT;AAKA,IAAa,iBAAb,MAAa,eAAc;CACR,SAAS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