@molecule/app-angular 3.13.0 → 3.16.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-23T13:31:45.205Z
6
+ Generated: 2026-11-25T04:39:22.950Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-angular
@@ -1640,12 +1640,18 @@ interface SlotReader {
1640
1640
  /**
1641
1641
  * The slot's React children (`React.Children.toArray(slot)`): its elements
1642
1642
  * and its text that is not template indentation, in order, wherever
1643
- * {@link placeContent} rendered them.
1643
+ * {@link placeContent} rendered them. A `*molLazy` slot is one child, its
1644
+ * anchor comment, whether or not its content is stamped: hide that node to
1645
+ * hide the child, and its content is destroyed until it shows again.
1646
+ *
1647
+ * The same array comes back while the children are the same nodes, so it can be kept in a
1648
+ * signal (`children.set(hasContent.nodes(capture))`) and passed to a binding: the placement
1649
+ * function runs after every render, and a new array each time would render again forever.
1644
1650
  *
1645
1651
  * @param capture - The element Angular projected the content into.
1646
1652
  * @returns The children.
1647
1653
  */
1648
- nodes(capture: Node | null | undefined): Node[]
1654
+ nodes(capture: Node | null | undefined): readonly Node[]
1649
1655
  }
1650
1656
  ```
1651
1657
 
@@ -3625,6 +3631,71 @@ export class MolWrapEachChild {
3625
3631
  }
3626
3632
  ```
3627
3633
 
3634
+ #### `MolLazy`
3635
+
3636
+ Stamps projected content in its own place, and keeps it exactly while that place is in the
3637
+ page: created when the component that received it shows it, destroyed when the component
3638
+ hides it, created again when it shows it again, as React mounts a slot. A place that moves to
3639
+ another parent (a sidebar rendered on the other side) is a new place: React never moves a
3640
+ mounted node to another parent, so the content is created again there. Write it as `*molLazy`
3641
+ on the slot's element, or as `molLazy` on an `<ng-template>` (with `ngProjectAs` for a named
3642
+ slot):
3643
+
3644
+ ```html
3645
+ <mol-modal [open]="open" (close)="open = false">
3646
+ <form *molLazy>…</form>
3647
+ <div slot="footer" *molLazy><button molButton>Save</button></div>
3648
+ <ng-template molLazy ngProjectAs="[slot=footer]">…</ng-template>
3649
+ </mol-modal>
3650
+ ```
3651
+
3652
+ Plain projected content is created with the consumer's view and kept for its whole life,
3653
+ which is right for static content (a closed dialog's footer buttons). Use `*molLazy` for
3654
+ content with state, effects or a fetch, which must not run while hidden and must start fresh
3655
+ each time it shows. It works on every component that hides a slot by taking its place out of
3656
+ the page, through `@if` or the `@molecule/app-angular` DOM placement, and on content that a
3657
+ wrapper component projects on.
3658
+
3659
+ The decision runs after every render, once every component has placed its slots: a component
3660
+ that attaches or detaches a region does it in a render's `write` phase or earlier, and this
3661
+ directive reads the result in the `mixedReadWrite` phase of the same render. It does not run on
3662
+ the server, where a lazy slot renders nothing.
3663
+
3664
+ ```typescript
3665
+ @Directive({ selector: '[molLazy]', standalone: true })
3666
+ export class MolLazy {
3667
+ constructor() {
3668
+ const template = inject(TemplateRef, { optional: true })
3669
+ if (template === null) {
3670
+ throw new Error('molLazy goes on an <ng-template>, or as *molLazy on an element.')
3671
+ }
3672
+ const views = inject(ViewContainerRef)
3673
+ const anchor = inject(ElementRef).nativeElement as Comment
3674
+ lazyAnchors.set(anchor, template)
3675
+ /** The parent the content was stamped in. */
3676
+ let stampedIn: Node | null = null
3677
+ afterEveryRender({
3678
+ // After every component's placement (`write`), so a closed dialog's footer is already out
3679
+ // of the page; outside change detection, so no view is edited while Angular walks it.
3680
+ mixedReadWrite: () => {
3681
+ const shown = anchor.isConnected
3682
+ if (views.length > 0 && (!shown || anchor.parentNode !== stampedIn)) {
3683
+ stampedRoots.delete(anchor)
3684
+ views.clear()
3685
+ }
3686
+ if (shown && views.length === 0) {
3687
+ stampedIn = anchor.parentNode
3688
+ const view = views.createEmbeddedView(template)
3689
+ for (const node of view.rootNodes as Node[]) lazyContent.add(node)
3690
+ stampedRoots.set(anchor, view.rootNodes as Node[])
3691
+ view.detectChanges()
3692
+ }
3693
+ },
3694
+ })
3695
+ }
3696
+ }
3697
+ ```
3698
+
3628
3699
  #### `Link`
3629
3700
 
3630
3701
  `<a molLink="/settings">`: sets the anchor's `href` and navigates in-app
@@ -3634,6 +3705,13 @@ navigates without a page load; a ctrl/cmd, shift or alt click, a `target`
3634
3705
  other than `_self`, a click the template's own `(click)` handler prevented,
3635
3706
  and a URL on another origin are left to the browser.
3636
3707
 
3708
+ A link to a URL outside the app (another origin, `mailto:`, `//host`) needs
3709
+ no router: the browser, or on a device the URL handler, opens it. It renders
3710
+ with no router registered, the URL as its `href`, and a click is left to the
3711
+ browser (the template's own `(click)` handler still runs). A link to an app
3712
+ path needs a router, and fails without one with the error `useRouterInstance`
3713
+ throws.
3714
+
3637
3715
  Inputs: `molLink` (the destination: an app path or a URL), `replace` (replace
3638
3716
  the current history entry; when unset, a link to the location already shown
3639
3717
  replaces it and any other link pushes, as with react-router's `<Link>`), and
@@ -3653,7 +3731,8 @@ that calls `navigate()`. Needs the router from `provideMolecule({ router })`.
3653
3731
  export class Link implements OnInit, LinkProps {
3654
3732
  /**
3655
3733
  * The destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is
3656
- * the one the router writes for it (`routerLinkHref`), base path included.
3734
+ * the one the router writes for it (`routerLinkHref`), base path included; a URL's is the URL as
3735
+ * written.
3657
3736
  */
3658
3737
  molLink = ''
3659
3738
  /** Replace the current history entry instead of pushing one. */
@@ -3661,11 +3740,22 @@ export class Link implements OnInit, LinkProps {
3661
3740
  /** State stored with the new history entry. */
3662
3741
  state?: unknown
3663
3742
 
3664
- private readonly router = useRouterInstance()
3743
+ /**
3744
+ * Reads the registered router once, here in the field initializer's injection context, and
3745
+ * answers for each destination this link shows: an app path fails with the no-router error
3746
+ * when none is registered. It takes the hook's function form because `molLink` is not set
3747
+ * when a field initializer runs.
3748
+ */
3749
+ private readonly linkRouter = useLinkRouter()
3665
3750
 
3666
- /** The anchor's `href`: the one the router writes for an app path, base path included. */
3751
+ /**
3752
+ * The anchor's `href`: the URL as written for a URL outside the app with no router registered,
3753
+ * else the one the router writes for an app path, base path included. An app path with no
3754
+ * router fails here with the no-router error.
3755
+ */
3667
3756
  get href(): string {
3668
- return routerLinkHref(this.molLink, this.router)
3757
+ const router = this.linkRouter(this.molLink)
3758
+ return router === null ? this.molLink : routerLinkHref(this.molLink, router)
3669
3759
  }
3670
3760
  private readonly element = inject<ElementRef<HTMLAnchorElement>>(ElementRef)
3671
3761
  private readonly renderer = inject(Renderer2)
@@ -3674,14 +3764,18 @@ export class Link implements OnInit, LinkProps {
3674
3764
  /**
3675
3765
  * Starts handling clicks. The listener is added here, after the template
3676
3766
  * created this anchor's own `(click)` listeners, so those run first and can
3677
- * prevent the navigation (react-router calls `onClick` first too).
3767
+ * prevent the navigation (react-router calls `onClick` first too). With no
3768
+ * router (a URL outside the app) the browser follows the anchor instead.
3678
3769
  */
3679
3770
  ngOnInit(): void {
3680
3771
  const stop = this.renderer.listen(this.element.nativeElement, 'click', (event: MouseEvent) => {
3681
- followRouterLink(event, this.molLink, this.router, {
3682
- replace: this.replace,
3683
- state: this.state,
3684
- })
3772
+ const router = this.linkRouter(this.molLink)
3773
+ if (router !== null) {
3774
+ followRouterLink(event, this.molLink, router, {
3775
+ replace: this.replace,
3776
+ state: this.state,
3777
+ })
3778
+ }
3685
3779
  })
3686
3780
  this.destroyRef.onDestroy(stop)
3687
3781
  }
@@ -4988,6 +5082,50 @@ export class SessionReady {
4988
5082
  }
4989
5083
  ```
4990
5084
 
5085
+ #### `MolSlotCopy`
5086
+
5087
+ Renders a slot's children here, as React renders `{children}` inside each row, node or gap:
5088
+ every place shows its own copy. Give it the slot's children (`SlotReader.nodes` of
5089
+ `usePlacement`) and keep the slot itself out of the page (`setElementPresent(capture,
5090
+ false)`), so the slot shows no copy of its own.
5091
+
5092
+ A `*molLazy` child is stamped here from its template: a live instance per place, created with
5093
+ this copy and destroyed with it or when the child leaves the slot, as each of React's is. Any
5094
+ other child is copied as DOM (`cloneNode`), which has no listeners and no components, so
5095
+ content with either is written with `*molLazy` (`MolLazy`). A child that stays in the
5096
+ slot keeps its copy here when other children come and go.
5097
+
5098
+ ````html
5099
+ ```typescript @Directive({ selector: '[molSlotCopy]', standalone: true }) export class MolSlotCopy
5100
+ implements OnDestroy { /** The slot's children to render here, in order. */ @Input({ required: true
5101
+ }) molSlotCopy: readonly Node[] = [] /** Where the stamped instances go. */ private readonly views =
5102
+ inject(ViewContainerRef) /** The directive's own place: the copies sit right before it. */ private
5103
+ readonly anchor = inject(ElementRef).nativeElement as Comment /** The copies, in render order. */
5104
+ private copies: Copy[] = [] /** The children the copies were last rendered from. */ private
5105
+ rendered: readonly Node[] = [] constructor() { // In the same phase as `MolLazy`, after it: a slot's
5106
+ own lazy children are stamped first, // in the order React mounts them (the original before its
5107
+ copies). afterEveryRender({ mixedReadWrite: () => this.render() }) } /** Destroys every instance it
5108
+ stamped. */ ngOnDestroy(): void { for (const copy of this.copies) this.destroy(copy) this.copies =
5109
+ [] } /** Renders the children it is given, keeping the copy of each child it already shows. */
5110
+ private render(): void { // `SlotReader.nodes` returns the same array while the children are the
5111
+ same. if (this.molSlotCopy === this.rendered) return this.rendered = this.molSlotCopy const kept =
5112
+ new Map(this.copies.map((copy) => [copy.source, copy])) const next = this.molSlotCopy.map((source)
5113
+ => { const copy = kept.get(source) if (copy === undefined) return this.create(source)
5114
+ kept.delete(source) return copy }) for (const gone of kept.values()) this.destroy(gone) // The
5115
+ stamped instances in their order, so Angular inserts each next to the right neighbour. let index = 0
5116
+ for (const copy of next) if (copy.view !== null) this.views.move(copy.view, index++) // Then every
5117
+ copy, back to front, right before the one that follows it. let ref: ChildNode = this.anchor for
5118
+ (const copy of [...next].reverse()) { const nodes = nodesOf(copy) as ChildNode[] const first =
5119
+ nodes[0] if (first === undefined) continue if (nodes[nodes.length - 1]?.nextSibling !== ref)
5120
+ ref.before(...nodes) ref = first } this.copies = next } /** * Renders one child here. * * @param
5121
+ source - The slot's child. * @returns Its copy. */ private create(source: Node): Copy { const
5122
+ template = lazySlotTemplate(source) if (template === undefined) return { source, view: null, node:
5123
+ source.cloneNode(true) } const view = this.views.createEmbeddedView(template) view.detectChanges()
5124
+ return { source, view, node: null } } /** * Takes one copy out of the page, destroying its instance.
5125
+ * * @param copy - The copy. */ private destroy(copy: Copy): void { if (copy.view !== null)
5126
+ copy.view.destroy() else (copy.node as ChildNode).remove() } }
5127
+ ````
5128
+
4991
5129
  ### Functions
4992
5130
 
4993
5131
  #### `useChatProvider()`
@@ -5995,6 +6133,29 @@ function useRouterInstance(): Router
5995
6133
 
5996
6134
  **Returns:** The router instance.
5997
6135
 
6136
+ #### `useLinkRouter(to)`
6137
+
6138
+ The router a link navigates through, React's `useLinkRouter` in Angular's
6139
+ idiom: the registered router, or `null` for a URL outside the app when none
6140
+ is. The browser, or on a device the URL handler, opens such a URL, so a link
6141
+ to it renders in an app with no router (a widget, a static page). A link to
6142
+ an app path still fails without one: that is how an app that forgot to
6143
+ register its router finds out.
6144
+
6145
+ The `Link` directive uses it. With a destination it answers for that one and
6146
+ follows it while the injector's host lives. Without one (a directive's input
6147
+ is not set when its field initializers run) it returns a function to call
6148
+ with the destination wherever it is known. Call it in an injection context
6149
+ (a constructor or a field initializer), which reads the injector once.
6150
+
6151
+ ```typescript
6152
+ function useLinkRouter(to: MaybeSignal<string>): Signal<Router | null>
6153
+ ```
6154
+
6155
+ - `to` — The link's destination: an app path or a URL, or a signal of one.
6156
+
6157
+ **Returns:** A signal of the router the link navigates through, or `null` for a URL outside the app with no router registered.
6158
+
5998
6159
  #### `useRouter()`
5999
6160
 
6000
6161
  Routing state and actions. Call it in an injection context (a component
@@ -6331,6 +6492,17 @@ function useThemeColors(): Signal<Theme['colors']>
6331
6492
 
6332
6493
  **Returns:** A signal of the current theme's colors.
6333
6494
 
6495
+ #### `useRichTranslation()`
6496
+
6497
+ Reads rich catalog messages from the active provider. Call the returned
6498
+ translation function in render so it follows locale and catalog changes.
6499
+
6500
+ ```typescript
6501
+ function useRichTranslation(): RichTranslateFunction
6502
+ ```
6503
+
6504
+ **Returns:** The locale-reactive rich translation function.
6505
+
6334
6506
  #### `useI18nProvider()`
6335
6507
 
6336
6508
  The i18n provider registered by `provideMolecule({ i18n })` or
@@ -6496,6 +6668,83 @@ function t(key: string, values?: InterpolationValues, options?: TranslateOptions
6496
6668
 
6497
6669
  **Returns:** Translated string
6498
6670
 
6671
+ #### `isLazySlotAnchor(node)`
6672
+
6673
+ Whether a node is the anchor of a {@link MolLazy} slot. A lazy slot is one child of the
6674
+ component it is passed to, stamped or not (React's `children` holds the element either way):
6675
+ a slot reader counts its anchor as content and as the child, so the wrapper that holds it is in
6676
+ the page, and a component that hides a child takes the anchor out of the page, which destroys
6677
+ the content.
6678
+
6679
+ ```typescript
6680
+ function isLazySlotAnchor(node: Node): boolean
6681
+ ```
6682
+
6683
+ - `node` — A node of a slot.
6684
+
6685
+ **Returns:** Whether it is a lazy slot's anchor.
6686
+
6687
+ #### `isElementChild(node)`
6688
+
6689
+ Whether a slot's child is an element, as React's `isValidElement(child)` tells an element from
6690
+ text: an element, or a {@link MolLazy} slot, which stands for the element it stamps whether or
6691
+ not it is stamped yet. Use it to pick a slot's elements out of `SlotReader.nodes`; a component
6692
+ that then moves the child (`placeElement`) moves the lazy slot, which stamps its content in the
6693
+ new place.
6694
+
6695
+ ```typescript
6696
+ function isElementChild(node: Node): boolean
6697
+ ```
6698
+
6699
+ - `node` — A child of a slot (`SlotReader.nodes`).
6700
+
6701
+ **Returns:** Whether it is an element child.
6702
+
6703
+ #### `slotElement(node)`
6704
+
6705
+ The element a slot's child is, for a component that works the child itself (React's
6706
+ `cloneElement(child, …)`: a trigger that gets the listeners and `aria-*`, an anchor a popup is
6707
+ positioned against): the child when it is an element, the element a {@link MolLazy} child stamped
6708
+ once it is stamped, else `null`. A lazy child is stamped after the placement that put it in the
6709
+ page, and stamping it runs that placement again, which then finds the element; decide the
6710
+ layout from {@link isElementChild} meanwhile, so the child is not given a wrapper it then leaves.
6711
+
6712
+ ```typescript
6713
+ function slotElement(node: Node): Element | null
6714
+ ```
6715
+
6716
+ - `node` — A child of a slot (`SlotReader.nodes`).
6717
+
6718
+ **Returns:** The element, or `null`.
6719
+
6720
+ #### `lazySlotTemplate(node)`
6721
+
6722
+ The template of a {@link MolLazy} slot, which a component that renders a slot's children in more
6723
+ than one place stamps in each of them (`MolSlotCopy` does this): each copy is then a live
6724
+ instance, as each of React's is. Plain projected content exists once in Angular; a copy of it
6725
+ (`cloneNode`) has no listeners or components.
6726
+
6727
+ ```typescript
6728
+ function lazySlotTemplate(node: Node): TemplateRef<unknown> | undefined
6729
+ ```
6730
+
6731
+ - `node` — A child of a slot (`SlotReader.nodes`).
6732
+
6733
+ **Returns:** The lazy slot's template, or `undefined` when the node is not a lazy slot's anchor.
6734
+
6735
+ #### `isLazySlotContent(node)`
6736
+
6737
+ Whether a node is a root node of a {@link MolLazy} slot's stamped content: part of the child
6738
+ its anchor stands for ({@link isLazySlotAnchor}), not a child of its own.
6739
+
6740
+ ```typescript
6741
+ function isLazySlotContent(node: Node): boolean
6742
+ ```
6743
+
6744
+ - `node` — A node of a slot.
6745
+
6746
+ **Returns:** Whether it is stamped lazy content.
6747
+
6499
6748
  #### `readMaybeSignal(value)`
6500
6749
 
6501
6750
  Reads a hook argument's current value. Inside a `computed` or `effect` this
@@ -6510,6 +6759,23 @@ function readMaybeSignal<T>(value: MaybeSignal<T>): T
6510
6759
 
6511
6760
  **Returns:** The argument's current value.
6512
6761
 
6762
+ #### `rendersNode(node)`
6763
+
6764
+ Whether a node input renders anything: not `null`, `undefined`, a boolean or `''`, and not
6765
+ a list holding only those. React's `slot(node)` from `@molecule/app-react/render` decides the
6766
+ same way, so a component that renders a wrapper, a default or an `aria-*` reference only
6767
+ while a node prop has something to show reads the same in both: `title=""` renders no heading,
6768
+ like an omitted `title`. Projected content is read with the `SlotReader` of
6769
+ {@link usePlacement} instead, which already counts only what renders.
6770
+
6771
+ ```typescript
6772
+ function rendersNode(node: unknown): boolean
6773
+ ```
6774
+
6775
+ - `node` — The input's value.
6776
+
6777
+ **Returns:** True when it renders something.
6778
+
6513
6779
  #### `provideState(provider)`
6514
6780
 
6515
6781
  Provide state management.
@@ -6997,8 +7263,8 @@ Peer dependencies:
6997
7263
  - `@molecule/app-device` ^1.0.1
6998
7264
  - `@molecule/app-forms` ^2.4.0
6999
7265
  - `@molecule/app-http` ^1.0.1
7000
- - `@molecule/app-i18n` ^1.0.1
7001
- - `@molecule/app-ide` ^1.0.1 _(optional)_
7266
+ - `@molecule/app-i18n` ^1.3.0
7267
+ - `@molecule/app-ide` ^1.1.0 _(optional)_
7002
7268
  - `@molecule/app-live-preview` ^1.0.1 _(optional)_
7003
7269
  - `@molecule/app-logger` ^1.0.1
7004
7270
  - `@molecule/app-platform` ^1.0.1
@@ -7007,7 +7273,7 @@ Peer dependencies:
7007
7273
  - `@molecule/app-routing-angular-router` >=1.4.0 _(optional)_
7008
7274
  - `@molecule/app-state` ^1.2.0
7009
7275
  - `@molecule/app-storage` ^1.1.1
7010
- - `@molecule/app-theme` ^1.0.1
7276
+ - `@molecule/app-theme` ^1.0.2
7011
7277
  - `@molecule/app-ui` ^1.0.1
7012
7278
  - `@molecule/app-utilities` ^1.0.1
7013
7279
  - `@molecule/app-version` ^1.0.1
@@ -244,12 +244,18 @@ export interface SlotReader {
244
244
  /**
245
245
  * The slot's React children (`React.Children.toArray(slot)`): its elements
246
246
  * and its text that is not template indentation, in order, wherever
247
- * {@link placeContent} rendered them.
247
+ * {@link placeContent} rendered them. A `*molLazy` slot is one child, its
248
+ * anchor comment, whether or not its content is stamped: hide that node to
249
+ * hide the child, and its content is destroyed until it shows again.
250
+ *
251
+ * The same array comes back while the children are the same nodes, so it can be kept in a
252
+ * signal (`children.set(hasContent.nodes(capture))`) and passed to a binding: the placement
253
+ * function runs after every render, and a new array each time would render again forever.
248
254
  *
249
255
  * @param capture - The element Angular projected the content into.
250
256
  * @returns The children.
251
257
  */
252
- nodes(capture: Node | null | undefined): Node[];
258
+ nodes(capture: Node | null | undefined): readonly Node[];
253
259
  }
254
260
  /**
255
261
  * Gives {@link usePlacement} the component's own moments. A component that
@@ -1 +1 @@
1
- {"version":3,"file":"dom-placement.d.ts","sourceRoot":"","sources":["../src/dom-placement.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAEL,KAAK,aAAa,EAIlB,KAAK,OAAO,EAGZ,KAAK,oBAAoB,EAUzB,KAAK,MAAM,EAIZ,MAAM,eAAe,CAAA;;AAqRtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC3C,IAAI,CASN;AA2VD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,IAAI,oBAAoB,CAkB1D;AAkBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAsB1F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAI3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAgBxF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,w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QAAQ,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,WAAW,GAAG,IAAI;IAI3D;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAQjC;;;;;OAKG;IACH,aAAa,IAAI,WAAW;IAM5B;;;;OAIG;IACH,OAAO,IAAI,IAAI;yCAtDJ,eAAe;;CAmE3B;AAED;;;;GAIG;AACH,qBACa,gBAAgB;;yCAAhB,gBAAgB;2CAAhB,gBAAgB;CAM5B"}
@@ -37,6 +37,7 @@
37
37
  * @module
38
38
  */
39
39
  import { afterEveryRender, ChangeDetectorRef, DestroyRef, Directive, effect, ElementRef, inject, Injectable, InjectionToken, isDevMode, makeEnvironmentProviders, provideEnvironmentInitializer, reflectComponentType, RendererFactory2, signal, untracked, } from '@angular/core';
40
+ import { isLazySlotAnchor, isLazySlotContent } from './lazy-slot.js';
40
41
  import * as i0 from "@angular/core";
41
42
  /** Set once {@link provideDomPlacement} decorated the application's renderer factory. */
42
43
  const DOM_PLACEMENT = new InjectionToken('@molecule/app-angular DOM placement');
@@ -339,11 +340,19 @@ function contentChanged(parent) {
339
340
  * and fills it in the same pass, so an empty text node is a child; comments are
340
341
  * Angular's own block anchors.
341
342
  *
343
+ * Whitespace-only text is indentation, on one line too: Angular collapses a
344
+ * template's line breaks around an interpolation into spaces in the same text
345
+ * node (`\n {{ x }}\n` renders `' '` while `x` is empty), the
346
+ * formatting JSX drops when it compiles. A consumer's deliberate `{{ ' ' }}`
347
+ * renders the same DOM, so it reads as no content here, where React's
348
+ * `slot(' ')` counts it; nothing in the page tells the two apart.
349
+ *
342
350
  * @param node - The node Angular is placing.
343
351
  * @returns Whether the node gets its own wrapper.
344
352
  */
345
353
  function isChild(node) {
346
- if (node.nodeType === 1)
354
+ // A lazy slot is one child, stamped or not; its content is stamped inside the anchor's wrapper.
355
+ if (node.nodeType === 1 || isLazySlotAnchor(node))
347
356
  return true;
348
357
  if (node.nodeType !== 3)
349
358
  return false;
@@ -502,7 +511,11 @@ function takeAlong(node) {
502
511
  function restoreAbsentHostOf(parent) {
503
512
  if (parent.isConnected)
504
513
  return;
505
- absentHosts.get(parent.getRootNode())?.();
514
+ // Angular's server DOM does not implement getRootNode().
515
+ let root = parent;
516
+ while (root.parentNode)
517
+ root = root.parentNode;
518
+ absentHosts.get(root)?.();
506
519
  }
507
520
  /**
508
521
  * Wraps one of Angular's renderers so the placement rules apply to every node
@@ -525,7 +538,12 @@ function withPlacement(renderer) {
525
538
  }
526
539
  dropPlaceholder(child);
527
540
  const from = child.parentNode;
528
- const before = ref === null ? null : placeOf(ref, parent);
541
+ // A lazy slot's content goes right before its anchor, wherever a component placed the anchor
542
+ // (placeElement): Angular names the slot's own parent, where the anchor no longer is.
543
+ const lazyAnchor = ref !== null && isLazySlotAnchor(ref) && ref.parentNode !== null;
544
+ if (lazyAnchor)
545
+ parent = ref.parentNode;
546
+ const before = ref === null ? null : lazyAnchor ? ref : placeOf(ref, parent);
529
547
  const owner = wrappingParents.get(parent);
530
548
  let node = child;
531
549
  if (owner !== undefined && isChild(child)) {
@@ -1021,7 +1039,8 @@ export function placeContentBefore(capture, sibling) {
1021
1039
  * content: an element, or text that is not template indentation. It reads the
1022
1040
  * content wherever {@link placeContent} rendered it, so a component that moved
1023
1041
  * its slot elsewhere still sees it. Comments (Angular's anchors) are not
1024
- * content.
1042
+ * content, except the anchor of a `*molLazy` slot ({@link isLazySlotAnchor}),
1043
+ * stamped or not: its wrapper must be in the page for it to be stamped.
1025
1044
  *
1026
1045
  * @param capture - The element Angular projected the content into.
1027
1046
  * @param ownLeadingNodes - How many of the capture's first child nodes the
@@ -1036,7 +1055,8 @@ function contentOf(capture, ownLeadingNodes = 0) {
1036
1055
  * A slot's React children, wherever {@link placeContent} rendered them: its
1037
1056
  * elements and its text that is not template indentation, in order. A
1038
1057
  * projected component that renders nothing counts as the placeholder that
1039
- * holds its place.
1058
+ * holds its place, and a `*molLazy` slot as its anchor comment, stamped or
1059
+ * not ({@link isLazySlotAnchor}).
1040
1060
  *
1041
1061
  * @param capture - The element Angular projected the content into.
1042
1062
  * @param firstOnly - Stop at the first child.
@@ -1062,8 +1082,11 @@ function childrenOf(capture, firstOnly, ownLeadingNodes = 0) {
1062
1082
  const isContent = node.nodeType === 1 ||
1063
1083
  (node.nodeType === 3 && node.data.trim() !== '') ||
1064
1084
  // A projected component that renders nothing is still a child React was given.
1065
- heldPlaces.has(node);
1066
- if (!isContent)
1085
+ heldPlaces.has(node) ||
1086
+ // A lazy slot is one child, its anchor, whether or not its content is stamped (React's
1087
+ // `children` holds the element either way); its stamped nodes are that child, not others.
1088
+ isLazySlotAnchor(node);
1089
+ if (!isContent || isLazySlotContent(node))
1067
1090
  continue;
1068
1091
  children.push(node);
1069
1092
  if (firstOnly)
@@ -1166,9 +1189,21 @@ export function usePlacement(place) {
1166
1189
  inRun();
1167
1190
  return contentOf(capture, ownLeadingNodes);
1168
1191
  });
1192
+ /** The last children read from each capture, returned again while they are the same nodes. */
1193
+ const lastNodes = new WeakMap();
1169
1194
  hasContent.nodes = (capture) => {
1170
1195
  inRun();
1171
- return childrenOf(capture, false);
1196
+ const nodes = childrenOf(capture, false);
1197
+ if (!capture)
1198
+ return nodes;
1199
+ const last = lastNodes.get(capture);
1200
+ if (last !== undefined &&
1201
+ last.length === nodes.length &&
1202
+ last.every((n, i) => n === nodes[i])) {
1203
+ return last;
1204
+ }
1205
+ lastNodes.set(capture, nodes);
1206
+ return nodes;
1172
1207
  };
1173
1208
  const host = inject(ElementRef).nativeElement;
1174
1209
  // Absent when a test calls usePlacement outside a component.