@molecule/app-angular 3.12.1 → 3.13.0

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-23T06:34:57.062Z
6
+ Generated: 2026-11-23T13:31:45.205Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-angular
@@ -1357,8 +1357,8 @@ interface Router {
1357
1357
  * link, the back button, `navigate`), with the new location and the navigation action.
1358
1358
  * A router calls it before the browser paints the new page, so a component that renders
1359
1359
  * from a listener (the framework bindings' `useLocation` and `useParams` do) shows the new
1360
- * location in the same paint as the new page. The router conformance cases of
1361
- * `@molecule/app-framework-conformance/routing` check that at every paint.
1360
+ * location in the same paint as the new page. Molecule's router conformance tests check
1361
+ * that at every paint.
1362
1362
  *
1363
1363
  * @param listener - Called with the new location and the navigation action.
1364
1364
  * @returns Stops calling `listener`.
@@ -1627,6 +1627,33 @@ interface Theme {
1627
1627
  }
1628
1628
  ```
1629
1629
 
1630
+ #### `SlotReader`
1631
+
1632
+ Reads whether a slot renders anything; see {@link usePlacement}. A capture
1633
+ that also holds the port's own text before the slot (`<span #c>{{ label
1634
+ }}<ng-content /></span>`) passes how many leading child nodes are the
1635
+ port's: one per interpolation or static text before the `<ng-content>`.
1636
+
1637
+ ```typescript
1638
+ interface SlotReader {
1639
+ (capture: Node | null | undefined, ownLeadingNodes?: number): boolean
1640
+ /**
1641
+ * The slot's React children (`React.Children.toArray(slot)`): its elements
1642
+ * and its text that is not template indentation, in order, wherever
1643
+ * {@link placeContent} rendered them.
1644
+ *
1645
+ * @param capture - The element Angular projected the content into.
1646
+ * @returns The children.
1647
+ */
1648
+ nodes(capture: Node | null | undefined): Node[]
1649
+ }
1650
+ ```
1651
+
1652
+ - `capture` — The element Angular projected the content into.
1653
+ - `ownLeadingNodes` — How many of the capture's first child nodes the port renders itself (default 0).
1654
+
1655
+ **Returns:** Whether the slot has content.
1656
+
1630
1657
  #### `UseAIModelsResult`
1631
1658
 
1632
1659
  Result returned by {@link useAIModels}: every field as a signal.
@@ -3461,6 +3488,41 @@ type MaybeSignal<T> = T | Signal<T>
3461
3488
 
3462
3489
  ### Classes
3463
3490
 
3491
+ #### `MolPlacement`
3492
+
3493
+ Gives {@link usePlacement} the component's own moments. A component that
3494
+ calls `usePlacement` lists it in `hostDirectives`; `usePlacement` throws
3495
+ without it. Its hooks fire exactly when the component's own would: after the
3496
+ component's view was first rendered (its view queries are set), and each
3497
+ time the parent checks the component (its inputs are set).
3498
+
3499
+ ```typescript
3500
+ @Directive({ standalone: true })
3501
+ export class MolPlacement implements AfterViewInit, DoCheck {
3502
+ private readonly runs: (() => void)[] = []
3503
+
3504
+ /**
3505
+ * Adds a placement function to run at the component's moments.
3506
+ *
3507
+ * @param run - Runs it.
3508
+ * @internal
3509
+ */
3510
+ add(run: () => void): void {
3511
+ this.runs.push(run)
3512
+ }
3513
+
3514
+ /** The component's view exists and its view queries are set. */
3515
+ ngAfterViewInit(): void {
3516
+ for (const run of this.runs) run()
3517
+ }
3518
+
3519
+ /** The parent set the component's inputs. */
3520
+ ngDoCheck(): void {
3521
+ for (const run of this.runs) run()
3522
+ }
3523
+ }
3524
+ ```
3525
+
3464
3526
  #### `WrappedChildren`
3465
3527
 
3466
3528
  The wrappers around a component's projected children: React's
@@ -3631,7 +3693,8 @@ export class Link implements OnInit, LinkProps {
3631
3693
  Renders the matched child route, through whichever routing bond the app wired (an outlet
3632
3694
  component under the angular-router bond). A layout or guard renders it where its page goes
3633
3695
  when it was given no projected content, so the component imports no router library. The page
3634
- renders inside this element, whose box the page takes (`display: contents`).
3696
+ renders where this element stands, and the element itself is not in the page: React's
3697
+ `RoutedView` renders only the page.
3635
3698
 
3636
3699
  Throws an `I18nError` (`angular.error.noRoutedView`) when it is created and the routing bond
3637
3700
  has no routed view: project the page instead. Rendering nothing there would show a blank page
@@ -3641,14 +3704,12 @@ with no error.
3641
3704
  @Component({
3642
3705
  selector: 'mol-routed-view',
3643
3706
  standalone: true,
3707
+ hostDirectives: [MolPlacement],
3644
3708
  template: '<ng-container #outlet />',
3645
- host: {
3646
- 'data-parity-unwrap': '',
3647
- style: 'display: contents',
3648
- },
3649
3709
  })
3650
3710
  export class RoutedView implements OnInit {
3651
3711
  private readonly view = routedViewOrThrow()
3712
+ private readonly host = inject(ElementRef).nativeElement as HTMLElement
3652
3713
  /**
3653
3714
  * An anchor of its own template: a RoutedView created outside any template (a test mounting it
3654
3715
  * alone) has no parent element for its host's container, so a page placed there never shows. A
@@ -3657,6 +3718,14 @@ export class RoutedView implements OnInit {
3657
3718
  */
3658
3719
  @ViewChild('outlet', { read: ViewContainerRef, static: true }) outlet?: ViewContainerRef
3659
3720
 
3721
+ constructor() {
3722
+ // Alone (no parent element), the host keeps the page: placeContentBefore needs a place.
3723
+ usePlacement(() => {
3724
+ placeContentBefore(this.host, this.host)
3725
+ setElementPresent(this.host, false)
3726
+ })
3727
+ }
3728
+
3660
3729
  /** Creates the routed view's component at this element's anchor. */
3661
3730
  ngOnInit(): void {
3662
3731
  this.outlet?.createComponent(this.view)
@@ -4950,6 +5019,43 @@ function useChat(options: UseChatOptions | Signal<UseChatOptions>): UseChatResul
4950
5019
 
4951
5020
  **Returns:** Each state field as a signal, and the chat controls.
4952
5021
 
5022
+ #### `setHostRoot(host, root, options)`
5023
+
5024
+ Names the element that stands for the calling component's host: React's
5025
+ `{...rest}` target. Call it in the component's {@link usePlacement}
5026
+ function, for a component whose host is out of the page.
5027
+
5028
+ An Angular consumer binds on the component's tag: `<mol-switch
5029
+ (keydown)="…" class="…" data-testid="…" [attr.aria-label]="…">`. With the
5030
+ host out of the page those would do nothing. Instead, while the host is
5031
+ absent:
5032
+
5033
+ - native listeners are attached to the root (`$event.currentTarget` is the
5034
+ root, as it is in React);
5035
+ - attributes, class names and styles the consumer writes on the tag are
5036
+ written on the root, in the same instruction, and the ones already on the
5037
+ host are moved there.
5038
+
5039
+ A component that calls nothing gets the common case for free: with one
5040
+ element in its place (`placeElementBefore(root, host)`) that element is the
5041
+ root; with several elements or projected content in its place, listeners go
5042
+ to each of them (the events that used to bubble to the host) and attributes
5043
+ stay on the host. A component with nothing in its place (a portal) names its
5044
+ root, or a listener on its tag throws in dev mode: it could never fire.
5045
+
5046
+ ```typescript
5047
+ function setHostRoot(
5048
+ host: Element,
5049
+ root: Element | null | undefined,
5050
+ options?: { except?: readonly string[] },
5051
+ ): void
5052
+ ```
5053
+
5054
+ - `host` — The component's host element.
5055
+ - `root` — The element that stands for it, or `null` while React renders none.
5056
+ - `options` — `except`: attribute names the component reads off its host itself (it merges them with its own), which stay on the host.
5057
+ - `options.except` — Those attribute names.
5058
+
4953
5059
  #### `provideDomPlacement()`
4954
5060
 
4955
5061
  Installs the placement rules in the application's renderer. `provideMolecule`
@@ -4971,6 +5077,8 @@ in the same place once it is true: Angular's equivalent of React's
4971
5077
  holds an `<ng-content>`). "Attached" means the element has a parent, not
4972
5078
  that it is in the document, so it also works inside a host that is itself
4973
5079
  absent. An element that was never taken out is left where Angular put it.
5080
+ An element rendered elsewhere ({@link placeElement}, {@link placeElementBefore})
5081
+ leaves that parent too, and `true` puts it back in its own place.
4974
5082
  Angular may remove or move the element while it is absent; its placeholder
4975
5083
  goes then.
4976
5084
 
@@ -4981,6 +5089,22 @@ function setElementPresent(element: Node | null | undefined, present: boolean):
4981
5089
  - `element` — The element (nothing happens without one).
4982
5090
  - `present` — Whether React would render it now.
4983
5091
 
5092
+ #### `heldElement(node)`
5093
+
5094
+ The element a placeholder stands in for while the element is out of its own
5095
+ place ({@link setElementPresent}, {@link placeElement},
5096
+ {@link placeElementBefore}). A slot's children ({@link SlotReader.nodes})
5097
+ list such an element as its placeholder; a component that took one of its
5098
+ slot's children out of the page finds that child again with this.
5099
+
5100
+ ```typescript
5101
+ function heldElement(node: Node | null | undefined): Node | undefined
5102
+ ```
5103
+
5104
+ - `node` — A node of the rendered tree.
5105
+
5106
+ **Returns:** The element whose place the node holds, or `undefined` when the node is not a current placeholder.
5107
+
4984
5108
  #### `placeElement(element, target)`
4985
5109
 
4986
5110
  Renders an element in another parent while it keeps its place in Angular's
@@ -4996,8 +5120,68 @@ removed from the other parent too, as React unmounts a portal.
4996
5120
  function placeElement(element: Node | null | undefined, target: Node | null): void
4997
5121
  ```
4998
5122
 
5123
+ #### `placeElementBefore(element, sibling)`
5124
+
5125
+ Renders an element of the component's template immediately in front of
5126
+ another node, as its sibling: Angular's equivalent of a React component whose
5127
+ root is a fragment, `<><div>{children}</div>{portal}</>`, where the node is
5128
+ the component's host (kept in the DOM with `display: contents`).
5129
+
5130
+ The element then belongs to the node's place. Angular inserts a new sibling
5131
+ before the element, not between the two; when Angular moves the node (a
5132
+ consumer `@for` reorders), the element moves with it; when Angular removes
5133
+ the node, the element goes back to its own place inside it and leaves the
5134
+ page with it. Several elements placed before the same node stand in the
5135
+ order they were placed. Calling it again moves nothing while the element
5136
+ already stands there.
5137
+
5138
+ "In front of the node" means in front of the node's place. A host that is
5139
+ absent (`setElementPresent(host, false)`) holds its place with a comment, and
5140
+ the element stands in front of that: this is how a fragment root renders
5141
+ React's exact DOM, with no host element among the siblings at all. A node
5142
+ another component rendered elsewhere ({@link placeElement}) is likewise
5143
+ led at its place, not where it was rendered.
5144
+
5145
+ Nothing happens while the node has no parent; call it
5146
+ from the component's {@link usePlacement} function, which runs again.
5147
+ `placeElement(element, null)` puts the element back in its own place.
5148
+
5149
+ ```typescript
5150
+ function placeElementBefore(
5151
+ element: Node | null | undefined,
5152
+ sibling: Node | null | undefined,
5153
+ ): void
5154
+ ```
5155
+
4999
5156
  - `element` — The element (nothing happens without one).
5000
- - `target` — The parent to render it in, or `null` for its own place.
5157
+ - `sibling` — The node it stands in front of, usually the host.
5158
+
5159
+ #### `renderedParent(node)`
5160
+
5161
+ A node's parent in the rendered tree: the parent React context follows.
5162
+ It is the DOM parent, except where this module placed the node:
5163
+
5164
+ - an element that is absent, or rendered in another parent
5165
+ ({@link setElementPresent}, {@link placeElement},
5166
+ {@link placeElementBefore}), belongs where its placeholder is, the place
5167
+ the template gave it. A portal's content therefore has the component that
5168
+ declared it as an ancestor, not `document.body`, as in React.
5169
+ - a top-level node of a capture's content that renders outside the capture
5170
+ ({@link placeContent}, {@link placeContentBefore}) belongs to the capture.
5171
+ With `placeContentBefore(host, host)` that is the host: what a provider
5172
+ renders in its own place is the provider's child, and a sibling that merely
5173
+ shares the DOM parent is not.
5174
+
5175
+ So a component looks its context up from its own host and registers one on
5176
+ its own host, whether or not the host is in the page.
5177
+
5178
+ ```typescript
5179
+ function renderedParent(node: Node | null | undefined): Element | null
5180
+ ```
5181
+
5182
+ - `node` — The node.
5183
+
5184
+ **Returns:** Its parent in the rendered tree, or `null` at the top (or for a node that has no place: never inserted, or removed).
5001
5185
 
5002
5186
  #### `placeContent(capture, target, before)`
5003
5187
 
@@ -5011,7 +5195,8 @@ consumer's `@for` and `@if` keep working at the new place: Angular inserts a
5011
5195
  view under the parent of its anchor, before a node of the same run. Never
5012
5196
  move a filtered or remembered list of nodes instead; the anchors or the
5013
5197
  nodes Angular adds later stay behind (NG05106). Calling it again with the
5014
- same target moves nothing.
5198
+ same target moves nothing. When Angular removes the capture (its view went),
5199
+ the content goes back inside it and leaves the page with it.
5015
5200
 
5016
5201
  ```typescript
5017
5202
  function placeContent(
@@ -5025,22 +5210,86 @@ function placeContent(
5025
5210
  - `target` — The parent to render the content in, or `null` to put it back inside `capture`.
5026
5211
  - `before` — The child of `target` to place the content before (default: at the end).
5027
5212
 
5028
- #### `hasContent(capture)`
5213
+ #### `placeContentBefore(capture, sibling)`
5214
+
5215
+ Renders a capture's content immediately in front of another node, as its
5216
+ siblings, with no element around it: Angular's equivalent of a React
5217
+ component whose root is a fragment of what it was given, `<>{children}</>`
5218
+ (a provider or a gate that renders no DOM of its own). The node is usually
5219
+ the component's host, and the capture may be the host itself:
5220
+ `placeContentBefore(host, host)` renders everything the host holds in front
5221
+ of it and leaves the host empty.
5222
+
5223
+ The content then belongs to the node's place, as an element does with
5224
+ {@link placeElementBefore}: Angular inserts a new sibling before the content,
5225
+ the content moves with the node, and it goes back inside the capture when
5226
+ Angular removes the node. Angular's block anchors move with the content, so
5227
+ an `@if` in the component's own template around `<ng-content>` and the
5228
+ consumer's blocks render at the new place from the first node on. Nothing
5229
+ happens while the node has no parent; call it from the component's
5230
+ {@link usePlacement} function. `placeContent(capture, null)` puts the
5231
+ content back.
5232
+
5233
+ ```typescript
5234
+ function placeContentBefore(
5235
+ capture: Element | null | undefined,
5236
+ sibling: Node | null | undefined,
5237
+ ): void
5238
+ ```
5239
+
5240
+ - `capture` — The element that holds the content (nothing happens without one).
5241
+ - `sibling` — The node the content stands in front of, usually the host.
5242
+
5243
+ #### `hasContent(capture)` _(deprecated)_
5244
+
5245
+ > **Deprecated:** Use the reader {@link usePlacement} passes.
5029
5246
 
5030
- Whether a slot renders anything, React's `{slot && …}` for projected
5031
- content: an element, or text that is not template indentation. It reads the
5032
- content wherever {@link placeContent} rendered it, so a component that moved
5033
- its slot elsewhere still sees it. Comments (Angular's anchors) are not
5034
- content.
5247
+ Reads a slot from a lifecycle hook, which can lag the content: a hook runs
5248
+ before the consumer's `@if` adds its node, and no hook runs at all when the
5249
+ content comes through an `OnPush` component in between. Read slots in the
5250
+ function passed to {@link usePlacement} instead; this export goes in the
5251
+ next major version.
5035
5252
 
5036
5253
  ```typescript
5037
5254
  function hasContent(capture: Node | null | undefined): boolean
5038
5255
  ```
5039
5256
 
5040
- - `capture` — The element Angular projected the content into.
5257
+ - `capture` — The capture.
5041
5258
 
5042
5259
  **Returns:** Whether the slot has content.
5043
5260
 
5261
+ #### `usePlacement(place)`
5262
+
5263
+ Registers the calling component's placement function: the one place where
5264
+ it decides, from its inputs and its projected content, which of its template
5265
+ elements are present ({@link setElementPresent}) and where its slots render
5266
+ ({@link placeContent}, {@link placeElement}). Call it in the constructor.
5267
+
5268
+ The component writes no lifecycle hook for this. The function runs:
5269
+
5270
+ - right after Angular adds, removes or changes a node of a slot the function
5271
+ read, in the same instruction — in whatever pass and from whatever
5272
+ template the node came, so the decision never lags the content and the new
5273
+ content is in the page before its own `ngAfterViewInit`;
5274
+ - when a signal it read changed (an effect);
5275
+ - when the component's view was first rendered and each time its parent
5276
+ checks it ({@link MolPlacement}, which the component lists in
5277
+ `hostDirectives`), so a plain input is followed in any kind of change
5278
+ detection, a bare `detectChanges()` included;
5279
+ - after every render.
5280
+
5281
+ `hasContent` is the only way to ask whether a slot has content, and it works
5282
+ only while the function runs: a lifecycle hook cannot read a slot, because
5283
+ no hook runs at a moment when the slot is known to be current
5284
+ (`ngDoCheck` runs before the consumer's `@if` adds its node; no hook at all
5285
+ runs when the content comes through an `OnPush` component in between).
5286
+
5287
+ ```typescript
5288
+ function usePlacement(place: (hasContent: SlotReader) => void): void
5289
+ ```
5290
+
5291
+ - `place` — The placement function. It gets `hasContent`.
5292
+
5044
5293
  #### `useHostPresence(isPresent)`
5045
5294
 
5046
5295
  Keeps the calling component's host element out of the DOM while
@@ -6312,7 +6561,7 @@ function provideRouter(
6312
6561
  - `options` — From a routing bond: its routed view (see `RoutedView`).
6313
6562
  - `options.routedView` — The component that renders the matched child route where a layout or guard puts it. Left out when the bond has none, and `RoutedView` then throws an error saying so.
6314
6563
 
6315
- **Returns:** Environment providers
6564
+ **Returns:** Environment providers, {@link provideDomPlacement} included: `RoutedView` and a bond's routed view render the page with no element of their own.
6316
6565
 
6317
6566
  #### `provideI18n(provider)`
6318
6567