@molecule/app-angular 3.11.0 → 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 +478 -9
- package/dist/dom-placement.d.ts +382 -0
- package/dist/dom-placement.d.ts.map +1 -0
- package/dist/dom-placement.js +1376 -0
- package/dist/dom-placement.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/providers.d.ts +2 -1
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +6 -2
- package/dist/providers.js.map +1 -1
- package/dist/routed-view.d.ts +6 -2
- package/dist/routed-view.d.ts.map +1 -1
- package/dist/routed-view.js +15 -9
- package/dist/routed-view.js.map +1 -1
- package/package.json +1 -1
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-
|
|
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.
|
|
1361
|
-
*
|
|
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,143 @@ 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
|
+
|
|
3526
|
+
#### `WrappedChildren`
|
|
3527
|
+
|
|
3528
|
+
The wrappers around a component's projected children: React's
|
|
3529
|
+
`children.map((child) => <div>{child}</div>)`.
|
|
3530
|
+
|
|
3531
|
+
The component lists it in `providers`, injects it, and puts
|
|
3532
|
+
`molWrapEachChild` on the template element that holds `<ng-content>`.
|
|
3533
|
+
Angular then places every projected child — at creation and whenever the
|
|
3534
|
+
consumer's `@for` or `@if` adds one later, anywhere in the list — inside its
|
|
3535
|
+
own wrapper, and a wrapper goes with its child. No node is moved after
|
|
3536
|
+
Angular placed it. The component styles the wrappers from {@link wrappers}
|
|
3537
|
+
(an effect), and reads React's `children.length` as `wrappers().length`.
|
|
3538
|
+
|
|
3539
|
+
```typescript
|
|
3540
|
+
@Injectable()
|
|
3541
|
+
export class WrappedChildren {
|
|
3542
|
+
private readonly state = signal<readonly HTMLElement[]>([])
|
|
3543
|
+
private parent: HTMLElement | null = null
|
|
3544
|
+
private create: (document: Document) => HTMLElement = (document) => document.createElement('div')
|
|
3545
|
+
|
|
3546
|
+
/** The wrappers, in render order. */
|
|
3547
|
+
readonly wrappers: Signal<readonly HTMLElement[]> = this.state.asReadonly()
|
|
3548
|
+
|
|
3549
|
+
constructor() {
|
|
3550
|
+
assertDomPlacement('WrappedChildren')
|
|
3551
|
+
}
|
|
3552
|
+
|
|
3553
|
+
/**
|
|
3554
|
+
* Sets how a wrapper element is created (default: an empty `<div>`). Call it
|
|
3555
|
+
* in the constructor; attributes that depend on the child's index belong in
|
|
3556
|
+
* an effect over {@link wrappers}.
|
|
3557
|
+
*
|
|
3558
|
+
* @param create - Builds one wrapper element.
|
|
3559
|
+
*/
|
|
3560
|
+
wrapWith(create: (document: Document) => HTMLElement): void {
|
|
3561
|
+
this.create = create
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
/**
|
|
3565
|
+
* Starts wrapping the children Angular places in `parent`.
|
|
3566
|
+
*
|
|
3567
|
+
* @param parent - The element that holds the projected content.
|
|
3568
|
+
* @internal
|
|
3569
|
+
*/
|
|
3570
|
+
attach(parent: HTMLElement): void {
|
|
3571
|
+
if (this.parent !== null) {
|
|
3572
|
+
throw new Error('WrappedChildren: one component wraps the children of one element.')
|
|
3573
|
+
}
|
|
3574
|
+
this.parent = parent
|
|
3575
|
+
wrappingParents.set(parent, this)
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3578
|
+
/**
|
|
3579
|
+
* Creates one wrapper.
|
|
3580
|
+
*
|
|
3581
|
+
* @returns The wrapper element.
|
|
3582
|
+
* @internal
|
|
3583
|
+
*/
|
|
3584
|
+
createWrapper(): HTMLElement {
|
|
3585
|
+
const wrapper = this.create((this.parent as HTMLElement).ownerDocument)
|
|
3586
|
+
wrapperOwners.set(wrapper, this)
|
|
3587
|
+
return wrapper
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
/**
|
|
3591
|
+
* Re-reads the wrappers after Angular added or removed a child.
|
|
3592
|
+
*
|
|
3593
|
+
* @internal
|
|
3594
|
+
*/
|
|
3595
|
+
refresh(): void {
|
|
3596
|
+
if (this.parent === null) return
|
|
3597
|
+
const next: HTMLElement[] = []
|
|
3598
|
+
for (const child of Array.from(this.parent.children)) {
|
|
3599
|
+
if (wrapperOwners.get(child) !== this) continue
|
|
3600
|
+
// Angular's `animate.leave` removes a cancelled leaving element without the renderer.
|
|
3601
|
+
if (child.hasChildNodes()) next.push(child as HTMLElement)
|
|
3602
|
+
else child.remove()
|
|
3603
|
+
}
|
|
3604
|
+
const current = this.state()
|
|
3605
|
+
if (next.length === current.length && next.every((wrapper, i) => wrapper === current[i])) return
|
|
3606
|
+
this.state.set(next)
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
```
|
|
3610
|
+
|
|
3611
|
+
#### `MolWrapEachChild`
|
|
3612
|
+
|
|
3613
|
+
Marks the template element whose projected children are each wrapped:
|
|
3614
|
+
`<div molWrapEachChild><ng-content /></div>`. See {@link WrappedChildren}.
|
|
3615
|
+
The marker attribute is taken off the element, so the markup stays React's.
|
|
3616
|
+
|
|
3617
|
+
```typescript
|
|
3618
|
+
@Directive({ selector: '[molWrapEachChild]', standalone: true })
|
|
3619
|
+
export class MolWrapEachChild {
|
|
3620
|
+
constructor() {
|
|
3621
|
+
const parent = inject(ElementRef<HTMLElement>).nativeElement as HTMLElement
|
|
3622
|
+
parent.removeAttribute('molWrapEachChild')
|
|
3623
|
+
inject(WrappedChildren).attach(parent)
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
```
|
|
3627
|
+
|
|
3464
3628
|
#### `Link`
|
|
3465
3629
|
|
|
3466
3630
|
`<a molLink="/settings">`: sets the anchor's `href` and navigates in-app
|
|
@@ -3529,7 +3693,8 @@ export class Link implements OnInit, LinkProps {
|
|
|
3529
3693
|
Renders the matched child route, through whichever routing bond the app wired (an outlet
|
|
3530
3694
|
component under the angular-router bond). A layout or guard renders it where its page goes
|
|
3531
3695
|
when it was given no projected content, so the component imports no router library. The page
|
|
3532
|
-
renders
|
|
3696
|
+
renders where this element stands, and the element itself is not in the page: React's
|
|
3697
|
+
`RoutedView` renders only the page.
|
|
3533
3698
|
|
|
3534
3699
|
Throws an `I18nError` (`angular.error.noRoutedView`) when it is created and the routing bond
|
|
3535
3700
|
has no routed view: project the page instead. Rendering nothing there would show a blank page
|
|
@@ -3539,14 +3704,12 @@ with no error.
|
|
|
3539
3704
|
@Component({
|
|
3540
3705
|
selector: 'mol-routed-view',
|
|
3541
3706
|
standalone: true,
|
|
3707
|
+
hostDirectives: [MolPlacement],
|
|
3542
3708
|
template: '<ng-container #outlet />',
|
|
3543
|
-
host: {
|
|
3544
|
-
'data-parity-unwrap': '',
|
|
3545
|
-
style: 'display: contents',
|
|
3546
|
-
},
|
|
3547
3709
|
})
|
|
3548
3710
|
export class RoutedView implements OnInit {
|
|
3549
3711
|
private readonly view = routedViewOrThrow()
|
|
3712
|
+
private readonly host = inject(ElementRef).nativeElement as HTMLElement
|
|
3550
3713
|
/**
|
|
3551
3714
|
* An anchor of its own template: a RoutedView created outside any template (a test mounting it
|
|
3552
3715
|
* alone) has no parent element for its host's container, so a page placed there never shows. A
|
|
@@ -3555,6 +3718,14 @@ export class RoutedView implements OnInit {
|
|
|
3555
3718
|
*/
|
|
3556
3719
|
@ViewChild('outlet', { read: ViewContainerRef, static: true }) outlet?: ViewContainerRef
|
|
3557
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
|
+
|
|
3558
3729
|
/** Creates the routed view's component at this element's anchor. */
|
|
3559
3730
|
ngOnInit(): void {
|
|
3560
3731
|
this.outlet?.createComponent(this.view)
|
|
@@ -4848,6 +5019,297 @@ function useChat(options: UseChatOptions | Signal<UseChatOptions>): UseChatResul
|
|
|
4848
5019
|
|
|
4849
5020
|
**Returns:** Each state field as a signal, and the chat controls.
|
|
4850
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
|
+
|
|
5059
|
+
#### `provideDomPlacement()`
|
|
5060
|
+
|
|
5061
|
+
Installs the placement rules in the application's renderer. `provideMolecule`
|
|
5062
|
+
includes it; a test that mounts a port without `provideMolecule` adds it to
|
|
5063
|
+
the application's providers. It wraps whatever renderer factory the
|
|
5064
|
+
application configured, so it also applies under an animation renderer.
|
|
5065
|
+
|
|
5066
|
+
```typescript
|
|
5067
|
+
function provideDomPlacement(): EnvironmentProviders
|
|
5068
|
+
```
|
|
5069
|
+
|
|
5070
|
+
**Returns:** The environment providers.
|
|
5071
|
+
|
|
5072
|
+
#### `setElementPresent(element, present)`
|
|
5073
|
+
|
|
5074
|
+
Takes an element out of its parent while `present` is false and puts it back
|
|
5075
|
+
in the same place once it is true: Angular's equivalent of React's
|
|
5076
|
+
`{cond && <span>…</span>}` for an element the template must keep (one that
|
|
5077
|
+
holds an `<ng-content>`). "Attached" means the element has a parent, not
|
|
5078
|
+
that it is in the document, so it also works inside a host that is itself
|
|
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.
|
|
5082
|
+
Angular may remove or move the element while it is absent; its placeholder
|
|
5083
|
+
goes then.
|
|
5084
|
+
|
|
5085
|
+
```typescript
|
|
5086
|
+
function setElementPresent(element: Node | null | undefined, present: boolean): void
|
|
5087
|
+
```
|
|
5088
|
+
|
|
5089
|
+
- `element` — The element (nothing happens without one).
|
|
5090
|
+
- `present` — Whether React would render it now.
|
|
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
|
+
|
|
5108
|
+
#### `placeElement(element, target)`
|
|
5109
|
+
|
|
5110
|
+
Renders an element in another parent while it keeps its place in Angular's
|
|
5111
|
+
view: Angular's equivalent of React's `createPortal(child, document.body)`.
|
|
5112
|
+
An empty comment holds the element's place, so Angular can still insert
|
|
5113
|
+
before it and remove it. `null` puts it back where Angular put it. Calling it
|
|
5114
|
+
again with the same target moves nothing. If Angular moves the element while
|
|
5115
|
+
it is elsewhere, the element follows Angular and the next call moves it
|
|
5116
|
+
again. When Angular removes the view that holds its place, the element is
|
|
5117
|
+
removed from the other parent too, as React unmounts a portal.
|
|
5118
|
+
|
|
5119
|
+
```typescript
|
|
5120
|
+
function placeElement(element: Node | null | undefined, target: Node | null): void
|
|
5121
|
+
```
|
|
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
|
+
|
|
5156
|
+
- `element` — The element (nothing happens without one).
|
|
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).
|
|
5185
|
+
|
|
5186
|
+
#### `placeContent(capture, target, before)`
|
|
5187
|
+
|
|
5188
|
+
Renders a capture element's content somewhere else: Angular's equivalent of
|
|
5189
|
+
React placing the same `{slot}` in a different parent depending on props
|
|
5190
|
+
(`loading ? <span>{label}</span> : label`). The capture element is the
|
|
5191
|
+
template element that holds the `<ng-content>`.
|
|
5192
|
+
|
|
5193
|
+
The whole content moves as one run, Angular's block anchors included, so the
|
|
5194
|
+
consumer's `@for` and `@if` keep working at the new place: Angular inserts a
|
|
5195
|
+
view under the parent of its anchor, before a node of the same run. Never
|
|
5196
|
+
move a filtered or remembered list of nodes instead; the anchors or the
|
|
5197
|
+
nodes Angular adds later stay behind (NG05106). Calling it again with the
|
|
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.
|
|
5200
|
+
|
|
5201
|
+
```typescript
|
|
5202
|
+
function placeContent(
|
|
5203
|
+
capture: Element | null | undefined,
|
|
5204
|
+
target: Node | null,
|
|
5205
|
+
before?: Node | null,
|
|
5206
|
+
): void
|
|
5207
|
+
```
|
|
5208
|
+
|
|
5209
|
+
- `capture` — The element Angular projected the content into.
|
|
5210
|
+
- `target` — The parent to render the content in, or `null` to put it back inside `capture`.
|
|
5211
|
+
- `before` — The child of `target` to place the content before (default: at the end).
|
|
5212
|
+
|
|
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.
|
|
5246
|
+
|
|
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.
|
|
5252
|
+
|
|
5253
|
+
```typescript
|
|
5254
|
+
function hasContent(capture: Node | null | undefined): boolean
|
|
5255
|
+
```
|
|
5256
|
+
|
|
5257
|
+
- `capture` — The capture.
|
|
5258
|
+
|
|
5259
|
+
**Returns:** Whether the slot has content.
|
|
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
|
+
|
|
5293
|
+
#### `useHostPresence(isPresent)`
|
|
5294
|
+
|
|
5295
|
+
Keeps the calling component's host element out of the DOM while
|
|
5296
|
+
`isPresent()` is false: Angular's equivalent of a React component that
|
|
5297
|
+
returns `null`. Call it in the component's injection context.
|
|
5298
|
+
|
|
5299
|
+
The host is put back before the component's own view refreshes whenever that
|
|
5300
|
+
is knowable: when a signal `isPresent` reads changed (an effect, which
|
|
5301
|
+
Angular runs before the view), and when Angular renders the first node into
|
|
5302
|
+
the absent host (so an `@if` branch that turns on with a plain input is
|
|
5303
|
+
built inside the document). Every render ends with the same check, which
|
|
5304
|
+
covers a predicate that reads what the render produced; a host restored
|
|
5305
|
+
there gets one more check with its content in the page.
|
|
5306
|
+
|
|
5307
|
+
```typescript
|
|
5308
|
+
function useHostPresence(isPresent: () => boolean): void
|
|
5309
|
+
```
|
|
5310
|
+
|
|
5311
|
+
- `isPresent` — Whether the component renders anything now. It may read inputs, plain fields or signals.
|
|
5312
|
+
|
|
4851
5313
|
#### `useExternalStore(read, subscribe)`
|
|
4852
5314
|
|
|
4853
5315
|
Subscribes to an external store and mirrors its value into a signal, with
|
|
@@ -6099,7 +6561,7 @@ function provideRouter(
|
|
|
6099
6561
|
- `options` — From a routing bond: its routed view (see `RoutedView`).
|
|
6100
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.
|
|
6101
6563
|
|
|
6102
|
-
**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.
|
|
6103
6565
|
|
|
6104
6566
|
#### `provideI18n(provider)`
|
|
6105
6567
|
|
|
@@ -6591,6 +7053,13 @@ Peer dependencies:
|
|
|
6591
7053
|
Molecule service whose token was never provided fails at DI time.
|
|
6592
7054
|
Per-concern helpers (`provideAuth`, `provideTheme`, ...) exist for
|
|
6593
7055
|
piecemeal setup.
|
|
7056
|
+
- The Molecule Angular components render through `provideDomPlacement()`,
|
|
7057
|
+
which `provideMolecule` includes. An app or test that mounts them without
|
|
7058
|
+
`provideMolecule` adds `provideDomPlacement()` to its providers; a component
|
|
7059
|
+
that needs it throws a message naming it. A component never moves a node
|
|
7060
|
+
Angular rendered (`appendChild`, `insertBefore`, `remove`): it uses
|
|
7061
|
+
`useHostPresence`, `setElementPresent`, `placeElement`, `placeContent` or
|
|
7062
|
+
`WrappedChildren`, which keep Angular's own inserts working (NG05106).
|
|
6594
7063
|
- In-app links use the `Link` directive (`<a molLink="/settings">`, `imports: [Link]`): it
|
|
6595
7064
|
navigates through the molecule router with react-router `<Link>`'s click rules. A bare
|
|
6596
7065
|
`<a href>` reloads the page; a hand-written `(click)` handler that calls `navigate()`
|