@molecule/app-ui-angular 1.4.1 → 1.5.1

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 (138) hide show
  1. package/README.md +989 -1103
  2. package/dist/components/alert.component.d.ts +11 -16
  3. package/dist/components/alert.component.d.ts.map +1 -1
  4. package/dist/components/alert.component.js +22 -51
  5. package/dist/components/alert.component.js.map +1 -1
  6. package/dist/components/auth-guard.component.d.ts +36 -28
  7. package/dist/components/auth-guard.component.d.ts.map +1 -1
  8. package/dist/components/auth-guard.component.js +59 -67
  9. package/dist/components/auth-guard.component.js.map +1 -1
  10. package/dist/components/avatar.component.d.ts +13 -10
  11. package/dist/components/avatar.component.d.ts.map +1 -1
  12. package/dist/components/avatar.component.js +27 -25
  13. package/dist/components/avatar.component.js.map +1 -1
  14. package/dist/components/button.component.d.ts +26 -30
  15. package/dist/components/button.component.d.ts.map +1 -1
  16. package/dist/components/button.component.js +41 -75
  17. package/dist/components/button.component.js.map +1 -1
  18. package/dist/components/checkbox.component.d.ts +5 -4
  19. package/dist/components/checkbox.component.d.ts.map +1 -1
  20. package/dist/components/checkbox.component.js +14 -9
  21. package/dist/components/checkbox.component.js.map +1 -1
  22. package/dist/components/confirm-button.component.d.ts +11 -28
  23. package/dist/components/confirm-button.component.d.ts.map +1 -1
  24. package/dist/components/confirm-button.component.js +31 -63
  25. package/dist/components/confirm-button.component.js.map +1 -1
  26. package/dist/components/confirm-dialog.component.d.ts +28 -17
  27. package/dist/components/confirm-dialog.component.d.ts.map +1 -1
  28. package/dist/components/confirm-dialog.component.js +98 -69
  29. package/dist/components/confirm-dialog.component.js.map +1 -1
  30. package/dist/components/dropdown.component.d.ts +29 -16
  31. package/dist/components/dropdown.component.d.ts.map +1 -1
  32. package/dist/components/dropdown.component.js +134 -105
  33. package/dist/components/dropdown.component.js.map +1 -1
  34. package/dist/components/empty-state.component.d.ts +10 -15
  35. package/dist/components/empty-state.component.d.ts.map +1 -1
  36. package/dist/components/empty-state.component.js +23 -27
  37. package/dist/components/empty-state.component.js.map +1 -1
  38. package/dist/components/form-field.component.d.ts +26 -11
  39. package/dist/components/form-field.component.d.ts.map +1 -1
  40. package/dist/components/form-field.component.js +86 -25
  41. package/dist/components/form-field.component.js.map +1 -1
  42. package/dist/components/input.component.d.ts +20 -23
  43. package/dist/components/input.component.d.ts.map +1 -1
  44. package/dist/components/input.component.js +45 -54
  45. package/dist/components/input.component.js.map +1 -1
  46. package/dist/components/language-picker.component.d.ts +15 -18
  47. package/dist/components/language-picker.component.d.ts.map +1 -1
  48. package/dist/components/language-picker.component.js +25 -35
  49. package/dist/components/language-picker.component.js.map +1 -1
  50. package/dist/components/load-error-banner.component.d.ts +14 -26
  51. package/dist/components/load-error-banner.component.d.ts.map +1 -1
  52. package/dist/components/load-error-banner.component.js +28 -62
  53. package/dist/components/load-error-banner.component.js.map +1 -1
  54. package/dist/components/modal.component.d.ts +25 -21
  55. package/dist/components/modal.component.d.ts.map +1 -1
  56. package/dist/components/modal.component.js +42 -78
  57. package/dist/components/modal.component.js.map +1 -1
  58. package/dist/components/molecule/button.component.d.ts +13 -2
  59. package/dist/components/molecule/button.component.d.ts.map +1 -1
  60. package/dist/components/molecule/button.component.js +45 -15
  61. package/dist/components/molecule/button.component.js.map +1 -1
  62. package/dist/components/molecule/toast.component.d.ts +2 -1
  63. package/dist/components/molecule/toast.component.d.ts.map +1 -1
  64. package/dist/components/molecule/toast.component.js +9 -7
  65. package/dist/components/molecule/toast.component.js.map +1 -1
  66. package/dist/components/molecule/tooltip.component.d.ts +4 -2
  67. package/dist/components/molecule/tooltip.component.d.ts.map +1 -1
  68. package/dist/components/molecule/tooltip.component.js +19 -14
  69. package/dist/components/molecule/tooltip.component.js.map +1 -1
  70. package/dist/components/optimistic-toggle-button.component.d.ts +13 -25
  71. package/dist/components/optimistic-toggle-button.component.d.ts.map +1 -1
  72. package/dist/components/optimistic-toggle-button.component.js +33 -63
  73. package/dist/components/optimistic-toggle-button.component.js.map +1 -1
  74. package/dist/components/page-header.component.d.ts +8 -13
  75. package/dist/components/page-header.component.d.ts.map +1 -1
  76. package/dist/components/page-header.component.js +16 -24
  77. package/dist/components/page-header.component.js.map +1 -1
  78. package/dist/components/page-shell.component.d.ts +8 -14
  79. package/dist/components/page-shell.component.d.ts.map +1 -1
  80. package/dist/components/page-shell.component.js +18 -28
  81. package/dist/components/page-shell.component.js.map +1 -1
  82. package/dist/components/panel-close.component.d.ts +14 -8
  83. package/dist/components/panel-close.component.d.ts.map +1 -1
  84. package/dist/components/panel-close.component.js +28 -17
  85. package/dist/components/panel-close.component.js.map +1 -1
  86. package/dist/components/prompt-dialog.component.d.ts +32 -10
  87. package/dist/components/prompt-dialog.component.d.ts.map +1 -1
  88. package/dist/components/prompt-dialog.component.js +110 -73
  89. package/dist/components/prompt-dialog.component.js.map +1 -1
  90. package/dist/components/responsive-app-shell.component.d.ts +38 -57
  91. package/dist/components/responsive-app-shell.component.d.ts.map +1 -1
  92. package/dist/components/responsive-app-shell.component.js +138 -213
  93. package/dist/components/responsive-app-shell.component.js.map +1 -1
  94. package/dist/components/sidebar-user-card.component.d.ts +8 -12
  95. package/dist/components/sidebar-user-card.component.d.ts.map +1 -1
  96. package/dist/components/sidebar-user-card.component.js +19 -35
  97. package/dist/components/sidebar-user-card.component.js.map +1 -1
  98. package/dist/components/switch.component.d.ts +13 -8
  99. package/dist/components/switch.component.d.ts.map +1 -1
  100. package/dist/components/switch.component.js +29 -20
  101. package/dist/components/switch.component.js.map +1 -1
  102. package/dist/components/table.component.d.ts +22 -14
  103. package/dist/components/table.component.d.ts.map +1 -1
  104. package/dist/components/table.component.js +34 -32
  105. package/dist/components/table.component.js.map +1 -1
  106. package/dist/components/toast.component.d.ts +34 -37
  107. package/dist/components/toast.component.d.ts.map +1 -1
  108. package/dist/components/toast.component.js +76 -112
  109. package/dist/components/toast.component.js.map +1 -1
  110. package/dist/components/tooltip.component.d.ts +14 -11
  111. package/dist/components/tooltip.component.d.ts.map +1 -1
  112. package/dist/components/tooltip.component.js +47 -47
  113. package/dist/components/tooltip.component.js.map +1 -1
  114. package/dist/components/user-menu-popover.component.d.ts +6 -12
  115. package/dist/components/user-menu-popover.component.d.ts.map +1 -1
  116. package/dist/components/user-menu-popover.component.js +40 -77
  117. package/dist/components/user-menu-popover.component.js.map +1 -1
  118. package/dist/components/user-menu.component.d.ts +8 -11
  119. package/dist/components/user-menu.component.d.ts.map +1 -1
  120. package/dist/components/user-menu.component.js +19 -27
  121. package/dist/components/user-menu.component.js.map +1 -1
  122. package/dist/index.d.ts +5 -5
  123. package/dist/index.js +5 -5
  124. package/dist/utilities/dom-context.d.ts +62 -15
  125. package/dist/utilities/dom-context.d.ts.map +1 -1
  126. package/dist/utilities/dom-context.js +79 -34
  127. package/dist/utilities/dom-context.js.map +1 -1
  128. package/dist/utilities/form-field-context.d.ts +2 -0
  129. package/dist/utilities/form-field-context.d.ts.map +1 -1
  130. package/dist/utilities/form-field-context.js +4 -2
  131. package/dist/utilities/form-field-context.js.map +1 -1
  132. package/dist/utilities/node-value.d.ts +8 -0
  133. package/dist/utilities/node-value.d.ts.map +1 -1
  134. package/dist/utilities/node-value.js +10 -0
  135. package/dist/utilities/node-value.js.map +1 -1
  136. package/dist/utilities/rest-attrs.d.ts +2 -2
  137. package/dist/utilities/rest-attrs.js +1 -1
  138. package/package.json +3 -3
@@ -4,19 +4,19 @@
4
4
  *
5
5
  * @module
6
6
  */
7
- import { afterNextRender, Component, effect, ElementRef, EnvironmentInjector, inject, Injector, Renderer2, signal, ViewChild, } from '@angular/core';
8
- import { useRouter, useTranslation } from '@molecule/app-angular';
7
+ import { afterNextRender, Component, effect, ElementRef, EnvironmentInjector, inject, Injector, signal, ViewChild, } from '@angular/core';
8
+ import { MolPlacement, placeElement, setElementPresent, useHostPresence, usePlacement, useRouter, useTranslation, } from '@molecule/app-angular';
9
9
  import { getClassMap } from '@molecule/app-ui';
10
10
  import { useIsDesktop } from '../hooks/use-is-desktop.js';
11
- import { findDomContext, provideDomContext, removeDomContext } from '../utilities/dom-context.js';
11
+ import { createDomContext } from '../utilities/dom-context.js';
12
12
  import { createScrollLock, getFocusableElements } from '../utilities/focus.js';
13
13
  import { nextInstanceId } from '../utilities/ids.js';
14
14
  import { asTemplate, isGiven, nodeText } from '../utilities/node-value.js';
15
15
  import { MolIconSvg, resolveIcon } from '../utilities/render-icon.js';
16
16
  import { styleText } from '../utilities/style.js';
17
- import { hasNodes, SlotWrapper } from './button.component.js';
18
17
  import { MolTemplateOutlet } from './template-outlet.directive.js';
19
18
  import * as i0 from "@angular/core";
19
+ import * as i1 from "@molecule/app-angular";
20
20
  const _c0 = ["*"];
21
21
  const _c1 = ["brandSlot"];
22
22
  const _c2 = ["actionsSlot"];
@@ -125,7 +125,7 @@ export class ResponsiveAppShell {
125
125
  ...(ngDevMode ? [{ debugName: "desktopEffect" }] : /* istanbul ignore next */ []));
126
126
  /** Registers the shell context on the host before any projected child resolves it. */
127
127
  constructor() {
128
- provideDomContext(this.host.nativeElement, new ShellContextValueImpl(this));
128
+ ShellDomContext.provide(this.host.nativeElement, new ShellContextValueImpl(this));
129
129
  }
130
130
  /**
131
131
  * The current class map.
@@ -154,7 +154,7 @@ export class ResponsiveAppShell {
154
154
  }
155
155
  /** Removes the context registration (unmount). */
156
156
  ngOnDestroy() {
157
- removeDomContext(this.host.nativeElement);
157
+ ShellDomContext.remove(this.host.nativeElement);
158
158
  }
159
159
  static ɵfac = function ResponsiveAppShell_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ResponsiveAppShell)(); };
160
160
  static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ResponsiveAppShell, selectors: [["div", "mol-responsive-app-shell", ""]], hostVars: 5, hostBindings: function ResponsiveAppShell_HostBindings(rf, ctx) { if (rf & 2) {
@@ -180,7 +180,7 @@ export class ResponsiveAppShell {
180
180
  template: `<ng-content></ng-content>`,
181
181
  }]
182
182
  }], () => [], null); })();
183
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShell, { className: "ResponsiveAppShell", filePath: "components/responsive-app-shell.component.ts", lineNumber: 193 }); })();
183
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShell, { className: "ResponsiveAppShell", filePath: "components/responsive-app-shell.component.ts", lineNumber: 200 }); })();
184
184
  /** The shell context a `ResponsiveAppShell` root registers. */
185
185
  class ShellContextValueImpl {
186
186
  root;
@@ -260,26 +260,35 @@ export class ResponsiveAppShellTopBar {
260
260
  * does not).
261
261
  */
262
262
  i18n = useTranslation();
263
- renderer = inject(Renderer2);
264
- sync = new SlotWrapper(this.host, this.renderer);
265
- brandParent = null;
266
- actionsParent = null;
267
263
  hasBrand = false;
268
264
  hasActions = false;
269
- detachedParent = null;
270
- detachedAnchor = null;
265
+ /** Prepares the header's mount condition (React's `mobileOnly`). */
266
+ constructor() {
267
+ usePlacement((hasContent) => {
268
+ // Resolve the shell context while the host is still in the page: a mobileOnly header
269
+ // leaves it on desktop, and its ancestors are the only way to the shell root.
270
+ void this.shell();
271
+ this.syncWrappers(hasContent);
272
+ });
273
+ // Leaves no element in the page while the bar is hidden on desktop (React renders null).
274
+ useHostPresence(() => !(this.mobileOnly && this.shell().isDesktop));
275
+ }
271
276
  /**
272
277
  * The nearest shell context.
273
- * @returns The context (null outside the shell).
278
+ * @returns The context (its defaults outside the shell).
274
279
  */
275
280
  shell() {
276
281
  // Cached: a detached (mobileOnly) header loses its DOM ancestors, so the
277
282
  // lookup must not be repeated after the element leaves the tree.
278
- this.context ??= contextOrDefault(this.host.nativeElement);
279
- return this.context;
283
+ return this.readContext() ?? contextOrDefault(null);
284
+ }
285
+ /**
286
+ * Reads the shell context from the host's place in the rendered tree.
287
+ * @returns The context, or null outside the shell.
288
+ */
289
+ readContext() {
290
+ return ShellDomContext.find(this.host.nativeElement) ?? null;
280
291
  }
281
- /** The resolved shell context. */
282
- context = null;
283
292
  /**
284
293
  * The current class map.
285
294
  * @returns The UIClassMap.
@@ -330,60 +339,14 @@ export class ResponsiveAppShellTopBar {
330
339
  * Refuses to render outside a shell (React's `useShellContext` throws).
331
340
  */
332
341
  ngOnInit() {
333
- requireShell(this.host.nativeElement, 'ResponsiveAppShell.TopBar');
334
- }
335
- /** Reads slot presence and applies the `mobileOnly` mount condition. */
336
- ngAfterViewInit() {
337
- this.brandParent = this.brandSlot?.nativeElement.parentElement ?? null;
338
- this.actionsParent = this.actionsSlot?.nativeElement.parentElement ?? null;
339
- this.hasBrand = isGiven(this.brand) || hasNodes(this.brandSlot?.nativeElement);
340
- this.hasActions = isGiven(this.actions) || hasNodes(this.actionsSlot?.nativeElement);
341
- this.syncWrappers();
342
- this.syncVisibility();
343
- }
344
- /** Re-reconciles the wrappers and the mount condition. */
345
- ngDoCheck() {
346
- this.hasBrand = isGiven(this.brand) || hasNodes(this.brandSlot?.nativeElement);
347
- this.hasActions = isGiven(this.actions) || hasNodes(this.actionsSlot?.nativeElement);
348
- this.syncWrappers();
349
- this.syncVisibility();
350
- }
351
- /** Restores a detached header (unmount). */
352
- ngOnDestroy() {
353
- this.reattach();
354
- }
355
- /** Applies React's `{mobileOnly && isDesktop ? null : <header>}`. */
356
- syncVisibility() {
357
- const hidden = this.mobileOnly && this.shell().isDesktop;
358
- const host = this.host.nativeElement;
359
- if (hidden && host.isConnected) {
360
- this.detachedParent = host.parentNode;
361
- this.detachedAnchor = host.nextSibling;
362
- host.parentNode?.removeChild(host);
363
- }
364
- else if (!hidden && !host.isConnected && this.detachedParent) {
365
- this.detachedParent.insertBefore(host, this.detachedAnchor);
366
- this.detachedParent = null;
367
- this.detachedAnchor = null;
368
- }
369
- }
370
- /** Restores the header into its parent (Angular's removal needs it there). */
371
- reattach() {
372
- const host = this.host.nativeElement;
373
- if (!host.isConnected && this.detachedParent) {
374
- this.detachedParent.insertBefore(host, this.detachedAnchor);
375
- this.detachedParent = null;
376
- this.detachedAnchor = null;
377
- }
342
+ requireShell(this.readContext(), 'ResponsiveAppShell.TopBar');
378
343
  }
379
344
  /** Applies React's conditional brand/actions wrappers. */
380
- syncWrappers() {
381
- // While the header is detached (mobileOnly on desktop) every node reads as
382
- // disconnected; attempting a re-attach would append it in the wrong place.
383
- if (!this.host.nativeElement.isConnected)
384
- return;
385
- this.sync.sync(this.brandSlot?.nativeElement, this.hasBrand, this.brandParent ?? undefined);
386
- this.sync.sync(this.actionsSlot?.nativeElement, this.hasActions, this.actionsParent ?? undefined);
345
+ syncWrappers(hasContent) {
346
+ this.hasBrand = isGiven(this.brand) || hasContent(this.brandSlot?.nativeElement);
347
+ this.hasActions = isGiven(this.actions) || hasContent(this.actionsSlot?.nativeElement);
348
+ setElementPresent(this.brandSlot?.nativeElement, this.hasBrand);
349
+ setElementPresent(this.actionsSlot?.nativeElement, this.hasActions);
387
350
  }
388
351
  static ɵfac = function ResponsiveAppShellTopBar_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ResponsiveAppShellTopBar)(); };
389
352
  static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ResponsiveAppShellTopBar, selectors: [["header", "mol-responsive-app-shell-topbar", ""]], viewQuery: function ResponsiveAppShellTopBar_Query(rf, ctx) { if (rf & 1) {
@@ -396,7 +359,7 @@ export class ResponsiveAppShellTopBar {
396
359
  i0.ɵɵattribute("data-mol-id", ctx.dataMolId)("data-testid", ctx.testId);
397
360
  i0.ɵɵstyleMap(ctx.hostStyle());
398
361
  i0.ɵɵclassMap(ctx.classes());
399
- } }, inputs: { brand: "brand", actions: "actions", mobileOnly: "mobileOnly", className: "className", dataMolId: "dataMolId", testId: "testId" }, ngContentSelectors: _c4, decls: 12, vars: 15, consts: [["brandSlot", ""], ["actionsSlot", ""], ["type", "button", "data-mol-id", "shell-drawer-open", 3, "class", "style"], [3, "molTemplateOutlet"], ["type", "button", "data-mol-id", "shell-drawer-open", 3, "click"], ["mol-icon", "", 3, "data"]], template: function ResponsiveAppShellTopBar_Template(rf, ctx) { if (rf & 1) {
362
+ } }, inputs: { brand: "brand", actions: "actions", mobileOnly: "mobileOnly", className: "className", dataMolId: "dataMolId", testId: "testId" }, features: [i0.ɵɵHostDirectivesFeature([i1.MolPlacement])], ngContentSelectors: _c4, decls: 12, vars: 15, consts: [["brandSlot", ""], ["actionsSlot", ""], ["type", "button", "data-mol-id", "shell-drawer-open", 3, "class", "style"], [3, "molTemplateOutlet"], ["type", "button", "data-mol-id", "shell-drawer-open", 3, "click"], ["mol-icon", "", 3, "data"]], template: function ResponsiveAppShellTopBar_Template(rf, ctx) { if (rf & 1) {
400
363
  i0.ɵɵprojectionDef(_c3);
401
364
  i0.ɵɵelementStart(0, "div");
402
365
  i0.ɵɵconditionalCreate(1, ResponsiveAppShellTopBar_Conditional_1_Template, 2, 8, "button", 2);
@@ -434,6 +397,7 @@ export class ResponsiveAppShellTopBar {
434
397
  args: [{
435
398
  selector: 'header[mol-responsive-app-shell-topbar]',
436
399
  standalone: true,
400
+ hostDirectives: [MolPlacement],
437
401
  imports: [MolIconSvg, MolTemplateOutlet],
438
402
  inputs: ['brand', 'actions', 'mobileOnly', 'className', 'dataMolId', 'testId'],
439
403
  host: {
@@ -471,14 +435,14 @@ export class ResponsiveAppShellTopBar {
471
435
  >{{ nodeText(actions) }}
472
436
  </div>`,
473
437
  }]
474
- }], null, { brandSlot: [{
438
+ }], () => [], { brandSlot: [{
475
439
  type: ViewChild,
476
440
  args: ['brandSlot']
477
441
  }], actionsSlot: [{
478
442
  type: ViewChild,
479
443
  args: ['actionsSlot']
480
444
  }] }); })();
481
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellTopBar, { className: "ResponsiveAppShellTopBar", filePath: "components/responsive-app-shell.component.ts", lineNumber: 368 }); })();
445
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellTopBar, { className: "ResponsiveAppShellTopBar", filePath: "components/responsive-app-shell.component.ts", lineNumber: 376 }); })();
482
446
  /**
483
447
  * The desktop sidebar (`<aside>` + `<nav>` landmarks); renders nothing below
484
448
  * the breakpoint (the Drawer carries the nav there).
@@ -507,23 +471,33 @@ export class ResponsiveAppShellSidebar {
507
471
  * does not).
508
472
  */
509
473
  i18n = useTranslation();
510
- renderer = inject(Renderer2);
511
- sync = new SlotWrapper(this.host, this.renderer);
512
- footerParent = null;
513
474
  hasFooter = false;
514
- detachedParent = null;
515
- detachedAnchor = null;
475
+ /** Prepares the aside's mount condition (React's breakpoint check). */
476
+ constructor() {
477
+ usePlacement((hasContent) => {
478
+ // Resolve the shell context while the host is still in the page: below the breakpoint
479
+ // it leaves the page, and its ancestors are the only way to the shell root.
480
+ void this.shell();
481
+ this.syncWrapper(hasContent);
482
+ });
483
+ // Leaves no element in the page below the breakpoint (React renders null).
484
+ useHostPresence(() => this.shell().isDesktop);
485
+ }
516
486
  /**
517
487
  * The nearest shell context.
518
- * @returns The context (defaults outside the shell).
488
+ * @returns The context (its defaults outside the shell).
519
489
  */
520
490
  shell() {
521
491
  // Cached: a detached (mobile) sidebar loses its DOM ancestors.
522
- this.context ??= contextOrDefault(this.host.nativeElement);
523
- return this.context;
492
+ return this.readContext() ?? contextOrDefault(null);
493
+ }
494
+ /**
495
+ * Reads the shell context from the host's place in the rendered tree.
496
+ * @returns The context, or null outside the shell.
497
+ */
498
+ readContext() {
499
+ return ShellDomContext.find(this.host.nativeElement) ?? null;
524
500
  }
525
- /** The resolved shell context. */
526
- context = null;
527
501
  /**
528
502
  * The current class map.
529
503
  * @returns The UIClassMap.
@@ -557,55 +531,12 @@ export class ResponsiveAppShellSidebar {
557
531
  * Refuses to render outside a shell (React's `useShellContext` throws).
558
532
  */
559
533
  ngOnInit() {
560
- requireShell(this.host.nativeElement, 'ResponsiveAppShell.Sidebar');
561
- }
562
- /** Applies the initial mount condition and footer presence. */
563
- ngAfterViewInit() {
564
- this.footerParent = this.footerSlot?.nativeElement.parentElement ?? null;
565
- this.hasFooter = isGiven(this.footer) || hasNodes(this.footerSlot?.nativeElement);
566
- this.syncWrapper();
567
- this.syncVisibility();
568
- }
569
- /** Re-reconciles the mount condition and the footer wrapper. */
570
- ngDoCheck() {
571
- this.hasFooter = isGiven(this.footer) || hasNodes(this.footerSlot?.nativeElement);
572
- this.syncWrapper();
573
- this.syncVisibility();
574
- }
575
- /** Restores a detached aside (unmount). */
576
- ngOnDestroy() {
577
- this.reattach();
578
- }
579
- /** Applies React's `{!isDesktop ? null : <aside>}`. */
580
- syncVisibility() {
581
- const hidden = !this.shell().isDesktop;
582
- const host = this.host.nativeElement;
583
- if (hidden && host.isConnected) {
584
- this.detachedParent = host.parentNode;
585
- this.detachedAnchor = host.nextSibling;
586
- host.parentNode?.removeChild(host);
587
- }
588
- else if (!hidden && !host.isConnected && this.detachedParent) {
589
- this.detachedParent.insertBefore(host, this.detachedAnchor);
590
- this.detachedParent = null;
591
- this.detachedAnchor = null;
592
- }
593
- }
594
- /** Restores the aside into its parent. */
595
- reattach() {
596
- const host = this.host.nativeElement;
597
- if (!host.isConnected && this.detachedParent) {
598
- this.detachedParent.insertBefore(host, this.detachedAnchor);
599
- this.detachedParent = null;
600
- this.detachedAnchor = null;
601
- }
534
+ requireShell(this.readContext(), 'ResponsiveAppShell.Sidebar');
602
535
  }
603
536
  /** Applies React's conditional footer wrapper. */
604
- syncWrapper() {
605
- // While the aside is detached (mobile) every node reads as disconnected.
606
- if (!this.host.nativeElement.isConnected)
607
- return;
608
- this.sync.sync(this.footerSlot?.nativeElement, this.hasFooter, this.footerParent ?? undefined);
537
+ syncWrapper(hasContent) {
538
+ this.hasFooter = isGiven(this.footer) || hasContent(this.footerSlot?.nativeElement);
539
+ setElementPresent(this.footerSlot?.nativeElement, this.hasFooter);
609
540
  }
610
541
  static ɵfac = function ResponsiveAppShellSidebar_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ResponsiveAppShellSidebar)(); };
611
542
  static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ResponsiveAppShellSidebar, selectors: [["aside", "mol-responsive-app-shell-sidebar", ""]], viewQuery: function ResponsiveAppShellSidebar_Query(rf, ctx) { if (rf & 1) {
@@ -617,7 +548,7 @@ export class ResponsiveAppShellSidebar {
617
548
  i0.ɵɵattribute("data-mol-id", ctx.dataMolId)("data-testid", ctx.testId);
618
549
  i0.ɵɵstyleMap(ctx.hostStyle());
619
550
  i0.ɵɵclassMap(ctx.classes());
620
- } }, inputs: { navLabel: "navLabel", footer: "footer", className: "className", dataMolId: "dataMolId", testId: "testId" }, ngContentSelectors: _c8, decls: 7, vars: 8, consts: [["footerSlot", ""], [3, "molTemplateOutlet"]], template: function ResponsiveAppShellSidebar_Template(rf, ctx) { if (rf & 1) {
551
+ } }, inputs: { navLabel: "navLabel", footer: "footer", className: "className", dataMolId: "dataMolId", testId: "testId" }, features: [i0.ɵɵHostDirectivesFeature([i1.MolPlacement])], ngContentSelectors: _c8, decls: 7, vars: 8, consts: [["footerSlot", ""], [3, "molTemplateOutlet"]], template: function ResponsiveAppShellSidebar_Template(rf, ctx) { if (rf & 1) {
621
552
  i0.ɵɵprojectionDef(_c7);
622
553
  i0.ɵɵelementStart(0, "nav");
623
554
  i0.ɵɵprojection(1);
@@ -643,6 +574,7 @@ export class ResponsiveAppShellSidebar {
643
574
  args: [{
644
575
  selector: 'aside[mol-responsive-app-shell-sidebar]',
645
576
  standalone: true,
577
+ hostDirectives: [MolPlacement],
646
578
  imports: [MolTemplateOutlet],
647
579
  inputs: ['navLabel', 'footer', 'className', 'dataMolId', 'testId'],
648
580
  host: {
@@ -669,11 +601,11 @@ export class ResponsiveAppShellSidebar {
669
601
  ><ng-container [molTemplateOutlet]="asTemplate(footer)"></ng-container>{{ nodeText(footer) }}
670
602
  </div>`,
671
603
  }]
672
- }], null, { footerSlot: [{
604
+ }], () => [], { footerSlot: [{
673
605
  type: ViewChild,
674
606
  args: ['footerSlot']
675
607
  }] }); })();
676
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellSidebar, { className: "ResponsiveAppShellSidebar", filePath: "components/responsive-app-shell.component.ts", lineNumber: 592 }); })();
608
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellSidebar, { className: "ResponsiveAppShellSidebar", filePath: "components/responsive-app-shell.component.ts", lineNumber: 558 }); })();
677
609
  /**
678
610
  * The mobile nav drawer (<768px): a left-anchored dialog panel over a
679
611
  * backdrop, portaled into `document.body`.
@@ -721,32 +653,43 @@ export class ResponsiveAppShellDrawer {
721
653
  * does not).
722
654
  */
723
655
  i18n = useTranslation();
724
- renderer = inject(Renderer2);
725
656
  /** Schedules the deferred focus moves from the change-detection hooks. */
726
657
  injector = inject(Injector);
727
658
  /** Schedules the focus restore of a destroyed open drawer (the component's own injector is gone). */
728
659
  environmentInjector = inject(EnvironmentInjector);
729
- sync = new SlotWrapper(this.host, this.renderer);
730
660
  scrollLock = createScrollLock();
731
661
  hasFooter = false;
732
- footerParent = null;
733
- headerParent = null;
734
- headerRowParent = null;
735
- attached = false;
736
662
  locked = false;
737
663
  lastOpen = false;
738
664
  previouslyFocused = null;
739
665
  listeners = [];
666
+ /** Applies React's conditional header/footer wrappers, and takes the host out of the page. */
667
+ constructor() {
668
+ usePlacement((hasContent) => {
669
+ // Resolve the shell context while the host is still in the page: it leaves the page
670
+ // below, and its ancestors are the only way to the shell root.
671
+ void this.shell();
672
+ this.syncWrappers(hasContent);
673
+ // Read through the placement function so the drawer's portal follows the shell's open
674
+ // state: the state is a signal on the shell root, and only a read here (or in the
675
+ // template) marks this component for a check.
676
+ this.syncOpen();
677
+ });
678
+ }
740
679
  /**
741
680
  * The nearest shell context.
742
- * @returns The context (defaults outside the shell).
681
+ * @returns The context (its defaults outside the shell).
743
682
  */
744
683
  shell() {
745
- this.context ??= contextOrDefault(this.host.nativeElement);
746
- return this.context;
684
+ return this.readContext() ?? contextOrDefault(null);
685
+ }
686
+ /**
687
+ * Reads the shell context from the host's place in the rendered tree.
688
+ * @returns The context, or null outside the shell.
689
+ */
690
+ readContext() {
691
+ return ShellDomContext.find(this.host.nativeElement) ?? null;
747
692
  }
748
- /** The resolved shell context. */
749
- context = null;
750
693
  /**
751
694
  * The current class map.
752
695
  * @returns The UIClassMap.
@@ -820,20 +763,16 @@ export class ResponsiveAppShellDrawer {
820
763
  this.shell().closeDrawer();
821
764
  }
822
765
  /**
823
- * Refuses to render outside a shell (React's `useShellContext` throws).
766
+ * Refuses to render outside a shell (React's `useShellContext` throws). The
767
+ * host may already have left the page (the placement function runs first), so
768
+ * the context resolved there is the one to check.
824
769
  */
825
770
  ngOnInit() {
826
- requireShell(this.host.nativeElement, 'ResponsiveAppShell.Drawer');
771
+ requireShell(this.readContext(), 'ResponsiveAppShell.Drawer');
827
772
  }
828
773
  /** Registers the drawer, reads slots and applies the initial open state. */
829
774
  ngAfterViewInit() {
830
775
  this.shell().registerDrawer(true);
831
- this.headerParent = this.headerSlot?.nativeElement.parentElement ?? null;
832
- this.headerRowParent = this.headerRow?.nativeElement.parentElement ?? null;
833
- this.footerParent = this.footerSlot?.nativeElement.parentElement ?? null;
834
- this.headerPresent.set(isGiven(this.header) || hasNodes(this.headerSlot?.nativeElement));
835
- this.hasFooter = isGiven(this.footer) || hasNodes(this.footerSlot?.nativeElement);
836
- this.syncWrappers();
837
776
  const open = this.shell().drawerOpen && !this.shell().isDesktop;
838
777
  this.lastOpen = open;
839
778
  if (open)
@@ -841,16 +780,13 @@ export class ResponsiveAppShellDrawer {
841
780
  else
842
781
  this.detachPortal();
843
782
  }
844
- /** Reconciles the open state, the wrappers and the drawer registration. */
783
+ /** Reconciles the open state and the drawer registration. */
845
784
  ngDoCheck() {
846
- this.headerPresent.set(isGiven(this.header) || hasNodes(this.headerSlot?.nativeElement));
847
- this.hasFooter = isGiven(this.footer) || hasNodes(this.footerSlot?.nativeElement);
848
- this.syncWrappers();
849
785
  this.syncOpen();
850
786
  }
851
787
  /**
852
- * Unregisters the drawer, unlocks scroll, restores the portal nodes and, when it was open, puts
853
- * focus back on whatever opened it (React's effect cleanup does on unmount).
788
+ * Unregisters the drawer, unlocks scroll and, when it was open, puts focus back on whatever
789
+ * opened it (React's effect cleanup does on unmount).
854
790
  */
855
791
  ngOnDestroy() {
856
792
  this.shell().registerDrawer(false);
@@ -868,26 +804,17 @@ export class ResponsiveAppShellDrawer {
868
804
  this.scrollLock.unlock();
869
805
  this.locked = false;
870
806
  }
871
- const host = this.host.nativeElement;
872
- if (this.attached) {
873
- const overlay = this.overlay?.nativeElement;
874
- const wrapper = this.wrapper?.nativeElement;
875
- if (overlay?.parentNode === document.body)
876
- host.appendChild(overlay);
877
- if (wrapper?.parentNode === document.body)
878
- host.appendChild(wrapper);
879
- this.attached = false;
880
- }
881
807
  }
882
- /** Applies React's conditional header/footer wrappers. */
883
- syncWrappers() {
884
- // The whole panel lives in a detached portal while the drawer is closed;
885
- // a "re-attach" there would append the wrapper at the panel's end.
886
- if (!this.attached)
887
- return;
888
- this.sync.sync(this.headerRow?.nativeElement, this.headerPresent() || (this.showCloseButton ?? true), this.headerRowParent ?? undefined);
889
- this.sync.sync(this.headerSlot?.nativeElement, this.headerPresent(), this.headerParent ?? undefined);
890
- this.sync.sync(this.footerSlot?.nativeElement, this.hasFooter, this.footerParent ?? undefined);
808
+ /** Applies React's conditional header/footer wrappers, and takes the host out of the page. */
809
+ syncWrappers(hasContent) {
810
+ this.headerPresent.set(isGiven(this.header) || hasContent(this.headerSlot?.nativeElement));
811
+ this.hasFooter = isGiven(this.footer) || hasContent(this.footerSlot?.nativeElement);
812
+ setElementPresent(this.headerRow?.nativeElement, this.headerPresent() || (this.showCloseButton ?? true));
813
+ setElementPresent(this.headerSlot?.nativeElement, this.headerPresent());
814
+ setElementPresent(this.footerSlot?.nativeElement, this.hasFooter);
815
+ // React renders the drawer's portal in `document.body` while open and nothing while closed:
816
+ // no element at the sub-component's place either way.
817
+ setElementPresent(this.host.nativeElement, false);
891
818
  }
892
819
  /** Applies the open transition (portal mounting, focus, scroll lock). */
893
820
  syncOpen() {
@@ -919,9 +846,6 @@ export class ResponsiveAppShellDrawer {
919
846
  openPanel() {
920
847
  this.previouslyFocused = document.activeElement ?? null;
921
848
  this.attachPortal();
922
- // The wrappers could not be reconciled while the portal was detached
923
- // (every node read as disconnected); apply them now that it is mounted.
924
- this.syncWrappers();
925
849
  // After the render, so the panel's `focusin` listeners settle after the
926
850
  // view check (a state change made during it is never rendered).
927
851
  afterNextRender(() => {
@@ -935,21 +859,23 @@ export class ResponsiveAppShellDrawer {
935
859
  this.locked = true;
936
860
  this.addListeners();
937
861
  }
938
- /** Moves the portal nodes into `document.body`. */
862
+ /** Renders the portal nodes in `document.body`. */
939
863
  attachPortal() {
940
864
  const overlay = this.overlay?.nativeElement;
941
865
  const wrapper = this.wrapper?.nativeElement;
942
866
  if (!overlay || !wrapper)
943
867
  return;
944
- document.body.appendChild(overlay);
945
- document.body.appendChild(wrapper);
946
- this.attached = true;
868
+ placeElement(overlay, document.body);
869
+ placeElement(wrapper, document.body);
947
870
  }
948
871
  /** Removes the portal nodes (React renders null). */
949
872
  detachPortal() {
950
- this.overlay?.nativeElement.remove();
951
- this.wrapper?.nativeElement.remove();
952
- this.attached = false;
873
+ const overlay = this.overlay?.nativeElement;
874
+ const wrapper = this.wrapper?.nativeElement;
875
+ placeElement(overlay, null);
876
+ setElementPresent(overlay, false);
877
+ placeElement(wrapper, null);
878
+ setElementPresent(wrapper, false);
953
879
  }
954
880
  /** Adds Escape and the Tab focus trap while open. */
955
881
  addListeners() {
@@ -1010,9 +936,7 @@ export class ResponsiveAppShellDrawer {
1010
936
  i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.headerRow = _t.first);
1011
937
  i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.headerSlot = _t.first);
1012
938
  i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.footerSlot = _t.first);
1013
- } }, hostAttrs: ["data-parity-unwrap", "", 2, "display", "contents"], hostVars: 1, hostBindings: function ResponsiveAppShellDrawer_HostBindings(rf, ctx) { if (rf & 2) {
1014
- i0.ɵɵattribute("data-open", ctx.shell().drawerOpen ? "true" : null);
1015
- } }, inputs: { header: "header", navLabel: "navLabel", footer: "footer", showCloseButton: "showCloseButton", className: "className", dataMolId: "dataMolId", closeDataMolId: "closeDataMolId", testId: "testId" }, ngContentSelectors: _c16, decls: 22, vars: 31, consts: [["overlay", ""], ["wrapper", ""], ["panel", ""], ["headerRow", ""], ["headerSlot", ""], ["footerSlot", ""], ["aria-hidden", "true"], ["role", "presentation", 3, "click"], ["role", "dialog", "aria-modal", "true", "tabindex", "-1", 3, "id"], [3, "molTemplateOutlet"], ["type", "button", 3, "class"], ["type", "button", 3, "click"], ["mol-icon", "", 3, "data"]], template: function ResponsiveAppShellDrawer_Template(rf, ctx) { if (rf & 1) {
939
+ } }, inputs: { header: "header", navLabel: "navLabel", footer: "footer", showCloseButton: "showCloseButton", className: "className", dataMolId: "dataMolId", closeDataMolId: "closeDataMolId", testId: "testId" }, features: [i0.ɵɵHostDirectivesFeature([i1.MolPlacement])], ngContentSelectors: _c16, decls: 22, vars: 31, consts: [["overlay", ""], ["wrapper", ""], ["panel", ""], ["headerRow", ""], ["headerSlot", ""], ["footerSlot", ""], ["aria-hidden", "true"], ["role", "presentation", 3, "click"], ["role", "dialog", "aria-modal", "true", "tabindex", "-1", 3, "id"], [3, "molTemplateOutlet"], ["type", "button", 3, "class"], ["type", "button", 3, "click"], ["mol-icon", "", 3, "data"]], template: function ResponsiveAppShellDrawer_Template(rf, ctx) { if (rf & 1) {
1016
940
  i0.ɵɵprojectionDef(_c15);
1017
941
  i0.ɵɵelement(0, "div", 6, 0);
1018
942
  i0.ɵɵelementStart(2, "div", 7, 1);
@@ -1071,6 +995,7 @@ export class ResponsiveAppShellDrawer {
1071
995
  args: [{
1072
996
  selector: 'mol-responsive-app-shell-drawer',
1073
997
  standalone: true,
998
+ hostDirectives: [MolPlacement],
1074
999
  imports: [MolIconSvg, MolTemplateOutlet],
1075
1000
  inputs: [
1076
1001
  'header',
@@ -1082,11 +1007,6 @@ export class ResponsiveAppShellDrawer {
1082
1007
  'closeDataMolId',
1083
1008
  'testId',
1084
1009
  ],
1085
- host: {
1086
- 'data-parity-unwrap': '',
1087
- style: 'display: contents',
1088
- '[attr.data-open]': 'shell().drawerOpen ? "true" : null',
1089
- },
1090
1010
  template: `<div #overlay [class]="cm().overlay" aria-hidden="true"></div>
1091
1011
  <div
1092
1012
  #wrapper
@@ -1158,7 +1078,7 @@ export class ResponsiveAppShellDrawer {
1158
1078
  </div>
1159
1079
  </div>`,
1160
1080
  }]
1161
- }], null, { overlay: [{
1081
+ }], () => [], { overlay: [{
1162
1082
  type: ViewChild,
1163
1083
  args: ['overlay']
1164
1084
  }], wrapper: [{
@@ -1177,7 +1097,7 @@ export class ResponsiveAppShellDrawer {
1177
1097
  type: ViewChild,
1178
1098
  args: ['footerSlot']
1179
1099
  }] }); })();
1180
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellDrawer, { className: "ResponsiveAppShellDrawer", filePath: "components/responsive-app-shell.component.ts", lineNumber: 838 }); })();
1100
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellDrawer, { className: "ResponsiveAppShellDrawer", filePath: "components/responsive-app-shell.component.ts", lineNumber: 765 }); })();
1181
1101
  /**
1182
1102
  * The shell's `<main>` landmark.
1183
1103
  */
@@ -1236,38 +1156,43 @@ export class ResponsiveAppShellContent {
1236
1156
  template: `<ng-content></ng-content>`,
1237
1157
  }]
1238
1158
  }], null, null); })();
1239
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellContent, { className: "ResponsiveAppShellContent", filePath: "components/responsive-app-shell.component.ts", lineNumber: 1216 }); })();
1159
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ResponsiveAppShellContent, { className: "ResponsiveAppShellContent", filePath: "components/responsive-app-shell.component.ts", lineNumber: 1136 }); })();
1160
+ /** The safe default a sub-component reads outside a shell (one object, so a spy sees its methods). */
1161
+ const NO_SHELL_CONTEXT = {
1162
+ isDesktop: false,
1163
+ sidebarWidthPx: SIDEBAR_WIDTH_PX.md,
1164
+ drawerOpen: false,
1165
+ openDrawer: () => undefined,
1166
+ closeDrawer: () => undefined,
1167
+ drawerId: '',
1168
+ hasDrawer: false,
1169
+ registerDrawer: () => undefined,
1170
+ };
1240
1171
  /**
1241
1172
  * The nearest shell context, or a safe default outside the shell.
1242
1173
  *
1243
- * @param element - The reading element.
1174
+ * @param element - The reading element, or null.
1244
1175
  * @returns The context.
1245
1176
  */
1246
1177
  function contextOrDefault(element) {
1247
- return (findDomContext(element) ?? {
1248
- isDesktop: false,
1249
- sidebarWidthPx: SIDEBAR_WIDTH_PX.md,
1250
- drawerOpen: false,
1251
- openDrawer: () => undefined,
1252
- closeDrawer: () => undefined,
1253
- drawerId: '',
1254
- hasDrawer: false,
1255
- registerDrawer: () => undefined,
1256
- });
1178
+ return ShellDomContext.find(element) ?? NO_SHELL_CONTEXT;
1257
1179
  }
1258
1180
  /**
1259
1181
  * Refuses to render a sub-component that has no enclosing shell — React's
1260
1182
  * `useShellContext`, which throws `<…> must be rendered inside
1261
1183
  * <ResponsiveAppShell>`. Angular has no context consumer to throw from during
1262
1184
  * render, so the same refusal happens in the component's `ngOnInit` (its
1263
- * first render pass).
1185
+ * first render pass), from the context the sub-component read while its host
1186
+ * was still in the page.
1264
1187
  *
1265
- * @param element - The sub-component's host element.
1188
+ * @param context - The sub-component's shell context, or null outside a shell.
1266
1189
  * @param name - The React component name the error names.
1267
1190
  */
1268
- function requireShell(element, name) {
1269
- if (!findDomContext(element)) {
1191
+ function requireShell(context, name) {
1192
+ if (context === null) {
1270
1193
  throw new Error(`<${name}> must be rendered inside <ResponsiveAppShell>`);
1271
1194
  }
1272
1195
  }
1196
+ /** The context a provider registers and its consumers find. */
1197
+ const ShellDomContext = createDomContext('ShellDomContext');
1273
1198
  //# sourceMappingURL=responsive-app-shell.component.js.map