@runic-artifex/angular 0.6.0-preview.1 → 0.7.0-preview.2
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 +68 -9
- package/dist/esm/index.d.ts +5 -2
- package/dist/esm/index.js +2 -0
- package/dist/esm/inject-collection-viewport.d.ts +13 -0
- package/dist/esm/inject-collection-viewport.js +31 -0
- package/dist/esm/inject-command.d.ts +35 -0
- package/dist/esm/inject-command.js +32 -0
- package/dist/esm/inject-view.d.ts +3 -14
- package/dist/esm/inject-view.js +24 -56
- package/dist/esm/view-outlet.d.ts +6 -9
- package/dist/esm/view-outlet.js +20 -12
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# `@runic-artifex/angular`
|
|
2
2
|
|
|
3
3
|
Angular outlet and signals for generated Runic View clients. The generated
|
|
4
|
-
modules import `@runic-artifex/views`,
|
|
4
|
+
modules import `@runic-artifex/views`, which this package also builds on, so
|
|
5
|
+
install both:
|
|
5
6
|
|
|
6
7
|
```sh
|
|
7
8
|
npm install @runic-artifex/angular@preview @runic-artifex/views@preview
|
|
@@ -16,25 +17,27 @@ match your Runic SDK packages.
|
|
|
16
17
|
|
|
17
18
|
`injectView(source)` connects a generated page reference, or
|
|
18
19
|
`{ connect: connect<Name> }` for a root ViewModel, for the lifetime of the
|
|
19
|
-
injection context and returns `state`, `client` and `
|
|
20
|
-
`retry()`:
|
|
20
|
+
injection context and returns `state`, `client`, `error` and `pending`
|
|
21
|
+
signals and `retry()`:
|
|
21
22
|
|
|
22
23
|
```ts
|
|
23
24
|
import { Component, input } from "@angular/core";
|
|
24
|
-
import { injectView } from "@runic-artifex/angular";
|
|
25
|
+
import { injectCommand, injectView } from "@runic-artifex/angular";
|
|
25
26
|
import type { CounterPageReference } from "./generated/counter";
|
|
26
27
|
|
|
27
28
|
@Component({
|
|
28
29
|
selector: "counter-page",
|
|
29
30
|
template: `
|
|
30
|
-
<button [disabled]="!counter.client()" (click)="
|
|
31
|
+
<button [disabled]="!counter.client() || increment.pending()" (click)="increment.run()">
|
|
31
32
|
{{ counter.state()?.count ?? "…" }}
|
|
32
33
|
</button>
|
|
34
|
+
@if (increment.error() ?? counter.error(); as issue) { <p role="alert">{{ issue }}</p> }
|
|
33
35
|
`,
|
|
34
36
|
})
|
|
35
37
|
export class CounterPage {
|
|
36
38
|
readonly page = input.required<CounterPageReference>();
|
|
37
39
|
readonly counter = injectView(this.page);
|
|
40
|
+
readonly increment = injectCommand(() => this.counter.client()?.increment());
|
|
38
41
|
}
|
|
39
42
|
```
|
|
40
43
|
|
|
@@ -60,7 +63,63 @@ const registry = { document: DocumentPage } satisfies ViewRegistry<DocumentRefer
|
|
|
60
63
|
// <runic-view-outlet [content]="current()" [registry]="registry" />
|
|
61
64
|
```
|
|
62
65
|
|
|
63
|
-
The outlet
|
|
64
|
-
component
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
The outlet is generic over the reference union it receives, so the registry
|
|
67
|
+
must have a component for every kind whose `page` input accepts that reference.
|
|
68
|
+
It remounts the component when the logical View reference changes, and creates
|
|
69
|
+
it outside its own signal tracking. A component's `page` input receives that
|
|
70
|
+
reference; `injectView(this.page)` owns its connection and cleanup. Missing
|
|
71
|
+
kinds render an alert. The generated TypeScript client can also be used
|
|
72
|
+
directly without Angular.
|
|
73
|
+
|
|
74
|
+
## Commands
|
|
75
|
+
|
|
76
|
+
`injectCommand(command)` returns `run(...args)` and `pending`, `error` and
|
|
77
|
+
`failure` signals. `run` resolves to the command's result, or to `undefined` after a
|
|
78
|
+
failure, which `error` then holds until the next run. It never rejects, so
|
|
79
|
+
handlers need no `try`/`catch`. One command can serve several buttons:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
readonly navigate = injectCommand((name: "showWelcome" | "showCounter") => this.workspace.client()?.[name]());
|
|
83
|
+
// <button (click)="navigate.run('showWelcome')">Welcome</button>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
For a command that declares a failure (`[RunicFailure]` in .NET), `run` resolves the
|
|
87
|
+
`BridgeOutcome`, and `failure` holds the declared failure of the latest run, typed
|
|
88
|
+
from the outcome, while `error` keeps unexpected failures. Starting a run and
|
|
89
|
+
`reset()` clear both, and a run superseded by a later run or by `reset()` sets
|
|
90
|
+
neither.
|
|
91
|
+
|
|
92
|
+
Outside an injection context, pass `{ injector }`.
|
|
93
|
+
|
|
94
|
+
## Collection viewports
|
|
95
|
+
|
|
96
|
+
`injectCollectionViewport(element, options)` follows a fixed-row-height scroll
|
|
97
|
+
container and returns a signal with its
|
|
98
|
+
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/main/packages/web/views#collectionviewportoptions)
|
|
99
|
+
range. Pass the container as a signal, such as a `viewChild`, and the options as
|
|
100
|
+
a function or signal, then send the range to the ViewModel from an effect:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
@Component({
|
|
104
|
+
selector: "rows-page",
|
|
105
|
+
template: `
|
|
106
|
+
<div #scroller style="height: 480px; overflow: auto">
|
|
107
|
+
<div [style.height.px]="viewport().totalSize"><!-- rows.state()?.rows --></div>
|
|
108
|
+
</div>
|
|
109
|
+
`,
|
|
110
|
+
})
|
|
111
|
+
export class RowsPage {
|
|
112
|
+
readonly page = input.required<RowsPageReference>();
|
|
113
|
+
readonly rows = injectView(this.page);
|
|
114
|
+
readonly viewport = injectCollectionViewport(viewChild<ElementRef<HTMLElement>>("scroller"),
|
|
115
|
+
() => ({ totalCount: this.rows.state()?.totalCount ?? 0, rowHeight: 32 }));
|
|
116
|
+
|
|
117
|
+
constructor() {
|
|
118
|
+
effect(() => {
|
|
119
|
+
const { start, size } = this.viewport();
|
|
120
|
+
const client = this.rows.client();
|
|
121
|
+
if (client && size !== 0) void client.setViewport({ start, size });
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export { RunicViewOutlet, type
|
|
2
|
-
export { injectView, type InjectViewOptions, type
|
|
1
|
+
export { RunicViewOutlet, type ViewRegistry } from "./view-outlet.js";
|
|
2
|
+
export { injectView, type InjectViewOptions, type ViewHandle } from "./inject-view.js";
|
|
3
|
+
export { injectCommand, type CommandHandle, type InjectCommandOptions } from "./inject-command.js";
|
|
4
|
+
export { injectCollectionViewport, type InjectCollectionViewportOptions } from "./inject-collection-viewport.js";
|
|
5
|
+
export type { CollectionViewport, CollectionViewportOptions, ViewClient, ViewConnector, ViewReference, ViewSource, } from "@runic-artifex/views";
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ElementRef, Injector, type Signal } from "@angular/core";
|
|
2
|
+
import { type CollectionViewport, type CollectionViewportOptions } from "@runic-artifex/views";
|
|
3
|
+
export interface InjectCollectionViewportOptions {
|
|
4
|
+
/** Required outside an injection context. */
|
|
5
|
+
readonly injector?: Injector;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Follows a fixed-row-height scroll container and returns the rows to request
|
|
9
|
+
* from .NET as a signal. Pass the container, for example
|
|
10
|
+
* `viewChild<ElementRef<HTMLElement>>("scroller")`, and the list options as a
|
|
11
|
+
* signal or function, then send `start` and `size` to the ViewModel from an effect.
|
|
12
|
+
*/
|
|
13
|
+
export declare function injectCollectionViewport(element: Signal<ElementRef<HTMLElement> | HTMLElement | null | undefined>, options: () => CollectionViewportOptions, { injector: provided }?: InjectCollectionViewportOptions): Signal<CollectionViewport>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, effect, ElementRef, inject, Injector, NgZone, signal, untracked } from "@angular/core";
|
|
2
|
+
import { createCollectionViewportController } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* Follows a fixed-row-height scroll container and returns the rows to request
|
|
5
|
+
* from .NET as a signal. Pass the container, for example
|
|
6
|
+
* `viewChild<ElementRef<HTMLElement>>("scroller")`, and the list options as a
|
|
7
|
+
* signal or function, then send `start` and `size` to the ViewModel from an effect.
|
|
8
|
+
*/
|
|
9
|
+
export function injectCollectionViewport(element, options, { injector: provided } = {}) {
|
|
10
|
+
if (!provided)
|
|
11
|
+
assertInInjectionContext(injectCollectionViewport);
|
|
12
|
+
const injector = provided ?? inject(Injector);
|
|
13
|
+
const controller = createCollectionViewportController(untracked(options));
|
|
14
|
+
const viewport = signal(controller.current, /* @ts-ignore */
|
|
15
|
+
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
16
|
+
controller.subscribe(() => viewport.set(controller.current));
|
|
17
|
+
effect(() => {
|
|
18
|
+
const { totalCount, rowHeight, overscan } = options();
|
|
19
|
+
untracked(() => controller.update({ totalCount, rowHeight, ...(overscan === undefined ? {} : { overscan }) }));
|
|
20
|
+
}, { injector });
|
|
21
|
+
// Scroll and resize events only update the viewport signal, which schedules
|
|
22
|
+
// change detection itself, so they need not run change detection per event.
|
|
23
|
+
const zone = injector.get(NgZone, null);
|
|
24
|
+
effect(() => {
|
|
25
|
+
const target = element();
|
|
26
|
+
const attach = () => controller.attach(target instanceof ElementRef ? target.nativeElement : target);
|
|
27
|
+
untracked(() => zone ? zone.runOutsideAngular(attach) : attach());
|
|
28
|
+
}, { injector });
|
|
29
|
+
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
30
|
+
return viewport.asReadonly();
|
|
31
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Injector, type Signal } from "@angular/core";
|
|
2
|
+
import { type BridgeOutcomeFailure } from "@runic-artifex/views";
|
|
3
|
+
export interface CommandHandle<TArgs extends readonly unknown[], TResult, TFailure = BridgeOutcomeFailure<TResult>> {
|
|
4
|
+
/**
|
|
5
|
+
* Runs the command. Resolves to its result, including a `BridgeOutcome` with a
|
|
6
|
+
* declared failure, which `failure` then holds, or to undefined after an
|
|
7
|
+
* unexpected failure, which `error` then holds. Never rejects.
|
|
8
|
+
*/
|
|
9
|
+
run(...args: TArgs): Promise<TResult | undefined>;
|
|
10
|
+
/** True while a run is in flight. */
|
|
11
|
+
readonly pending: Signal<boolean>;
|
|
12
|
+
/** Why the latest run failed unexpectedly, until the next run starts. */
|
|
13
|
+
readonly error: Signal<unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* The declared failure of the latest run, for a command that resolves a
|
|
16
|
+
* `BridgeOutcome`, until the next run starts. A superseded run sets neither.
|
|
17
|
+
*/
|
|
18
|
+
readonly failure: Signal<TFailure | undefined>;
|
|
19
|
+
/** Clears `error` and `failure`. */
|
|
20
|
+
reset(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface InjectCommandOptions {
|
|
23
|
+
/** Required outside an injection context. */
|
|
24
|
+
readonly injector?: Injector;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Tracks a command's pending state and failure as signals for the lifetime of
|
|
28
|
+
* the injection context. The command may read signals, such as a client:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* readonly increment = injectCommand(() => this.counter.client()?.increment());
|
|
32
|
+
* // <button [disabled]="!counter.client() || increment.pending()" (click)="increment.run()">
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function injectCommand<TArgs extends readonly unknown[], TReturn>(command: (...args: TArgs) => TReturn, options?: InjectCommandOptions): CommandHandle<TArgs, Awaited<TReturn>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
|
+
import { createCommandController } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* Tracks a command's pending state and failure as signals for the lifetime of
|
|
5
|
+
* the injection context. The command may read signals, such as a client:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* readonly increment = injectCommand(() => this.counter.client()?.increment());
|
|
9
|
+
* // <button [disabled]="!counter.client() || increment.pending()" (click)="increment.run()">
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function injectCommand(command, options = {}) {
|
|
13
|
+
if (!options.injector)
|
|
14
|
+
assertInInjectionContext(injectCommand);
|
|
15
|
+
const injector = options.injector ?? inject(Injector);
|
|
16
|
+
const controller = createCommandController(command);
|
|
17
|
+
const pending = signal(false, /* @ts-ignore */
|
|
18
|
+
...(ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []));
|
|
19
|
+
const error = signal(undefined, /* @ts-ignore */
|
|
20
|
+
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
21
|
+
const failure = signal(undefined, /* @ts-ignore */
|
|
22
|
+
...(ngDevMode ? [{ debugName: "failure" }] : /* istanbul ignore next */ []));
|
|
23
|
+
controller.subscribe(() => {
|
|
24
|
+
pending.set(controller.current.pending);
|
|
25
|
+
error.set(controller.current.error);
|
|
26
|
+
failure.set(controller.current.failure);
|
|
27
|
+
});
|
|
28
|
+
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
29
|
+
return {
|
|
30
|
+
run: controller.run, pending: pending.asReadonly(), error: error.asReadonly(), failure: failure.asReadonly(), reset: controller.reset,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
export interface ViewClient<TState = unknown> {
|
|
4
|
-
readonly snapshot: TState;
|
|
5
|
-
subscribe(listener: (state: TState) => void): () => void;
|
|
6
|
-
dispose(): void;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* A generated content reference or `{ connect: connect<Name> }` for a root
|
|
10
|
-
* ViewModel, which `injectView` connects and disposes, or an already connected
|
|
11
|
-
* client, which it only observes.
|
|
12
|
-
*/
|
|
13
|
-
export type ViewSource<TClient extends ViewClient> = {
|
|
14
|
-
connect(): Promise<TClient>;
|
|
15
|
-
} | TClient | null | undefined;
|
|
2
|
+
import { type ViewClient, type ViewSource } from "@runic-artifex/views";
|
|
16
3
|
export interface ViewHandle<TClient extends ViewClient> {
|
|
17
4
|
/** The latest state, or undefined until the client connects. */
|
|
18
5
|
readonly state: Signal<TClient["snapshot"] | undefined>;
|
|
@@ -20,6 +7,8 @@ export interface ViewHandle<TClient extends ViewClient> {
|
|
|
20
7
|
readonly client: Signal<TClient | undefined>;
|
|
21
8
|
/** The connection failure, if any. */
|
|
22
9
|
readonly error: Signal<unknown>;
|
|
10
|
+
/** True while a reference is connecting. */
|
|
11
|
+
readonly pending: Signal<boolean>;
|
|
23
12
|
/** Connects a reference again after a failure. */
|
|
24
13
|
retry(): void;
|
|
25
14
|
}
|
package/dist/esm/inject-view.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, effect, inject, Injector, isSignal, signal, untracked } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
return typeof source.subscribe === "function";
|
|
4
|
-
}
|
|
1
|
+
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, isSignal, signal, untracked } from "@angular/core";
|
|
2
|
+
import { createViewController, isViewClient, viewSourceIdentity } from "@runic-artifex/views";
|
|
5
3
|
/**
|
|
6
4
|
* Connects a generated View reference for the lifetime of the injection
|
|
7
5
|
* context (normally a component) and exposes its state as signals. Pass a
|
|
@@ -15,70 +13,40 @@ export function injectView(source, options = {}) {
|
|
|
15
13
|
if (!options.injector)
|
|
16
14
|
assertInInjectionContext(injectView);
|
|
17
15
|
const injector = options.injector ?? inject(Injector);
|
|
18
|
-
const
|
|
16
|
+
const controller = createViewController(options.release ? { release: options.release } : {});
|
|
17
|
+
const current = signal(controller.current, /* @ts-ignore */
|
|
18
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
19
|
+
controller.subscribe(() => current.set(controller.current));
|
|
19
20
|
const read = () => isSignal(source) ? source() : source;
|
|
20
|
-
const identity = computed(() =>
|
|
21
|
-
const value = read();
|
|
22
|
-
return value ? isClient(value) ? value : value.connect : undefined;
|
|
23
|
-
}, /* @ts-ignore */
|
|
21
|
+
const identity = computed(() => viewSourceIdentity(read()), /* @ts-ignore */
|
|
24
22
|
...(ngDevMode ? [{ debugName: "identity" }] : /* istanbul ignore next */ []));
|
|
25
23
|
const observed = computed(() => {
|
|
26
24
|
const value = read();
|
|
27
|
-
return value &&
|
|
25
|
+
return value && isViewClient(value) ? value : undefined;
|
|
28
26
|
}, /* @ts-ignore */
|
|
29
27
|
...(ngDevMode ? [{ debugName: "observed" }] : /* istanbul ignore next */ []));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const connectedClient = signal(undefined, /* @ts-ignore */
|
|
35
|
-
...(ngDevMode ? [{ debugName: "connectedClient" }] : /* istanbul ignore next */ []));
|
|
36
|
-
const error = signal(undefined, /* @ts-ignore */
|
|
37
|
-
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
38
|
-
effect(onCleanup => {
|
|
28
|
+
// A changed reference does not show the previous one until the effect follows it.
|
|
29
|
+
const fresh = computed(() => viewSourceIdentity(current().source) === identity(), /* @ts-ignore */
|
|
30
|
+
...(ngDevMode ? [{ debugName: "fresh" }] : /* istanbul ignore next */ []));
|
|
31
|
+
effect(() => {
|
|
39
32
|
identity();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
connectedClient.set(undefined);
|
|
44
|
-
error.set(undefined);
|
|
45
|
-
if (!value)
|
|
46
|
-
return;
|
|
47
|
-
let active = true;
|
|
48
|
-
let connected;
|
|
49
|
-
let unsubscribe;
|
|
50
|
-
const observe = (next) => {
|
|
51
|
-
connectedClient.set(next);
|
|
52
|
-
unsubscribe = next.subscribe(update => { if (active)
|
|
53
|
-
latest.set(update); });
|
|
54
|
-
};
|
|
55
|
-
if (isClient(value))
|
|
56
|
-
observe(value);
|
|
57
|
-
else
|
|
58
|
-
value.connect().then(next => {
|
|
59
|
-
if (!active) {
|
|
60
|
-
release(next);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
connected = next;
|
|
64
|
-
observe(next);
|
|
65
|
-
}, cause => { if (active)
|
|
66
|
-
error.set(cause); });
|
|
67
|
-
onCleanup(() => {
|
|
68
|
-
active = false;
|
|
69
|
-
unsubscribe?.();
|
|
70
|
-
if (connected)
|
|
71
|
-
release(connected);
|
|
33
|
+
untracked(() => {
|
|
34
|
+
controller.setSource(read());
|
|
35
|
+
current.set(controller.current);
|
|
72
36
|
});
|
|
73
37
|
}, { injector });
|
|
38
|
+
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
74
39
|
return {
|
|
75
|
-
// A connected client is readable before the effect
|
|
40
|
+
// A connected client is readable before the effect observes it.
|
|
76
41
|
state: computed(() => {
|
|
77
42
|
const value = observed();
|
|
78
|
-
|
|
43
|
+
if (value && value !== current().client)
|
|
44
|
+
return value.snapshot;
|
|
45
|
+
return fresh() ? current().state : undefined;
|
|
79
46
|
}),
|
|
80
|
-
client: computed(() => observed() ??
|
|
81
|
-
error:
|
|
82
|
-
|
|
47
|
+
client: computed(() => observed() ?? (fresh() ? current().client : undefined)),
|
|
48
|
+
error: computed(() => fresh() ? current().error : undefined),
|
|
49
|
+
pending: computed(() => observed() ? false : fresh() ? current().pending : identity() !== undefined),
|
|
50
|
+
retry: () => controller.retry(),
|
|
83
51
|
};
|
|
84
52
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { type InputSignal, type Type } from "@angular/core";
|
|
2
|
+
import type { ViewReference } from "@runic-artifex/views";
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
3
|
-
export interface ViewReference {
|
|
4
|
-
readonly kind: string;
|
|
5
|
-
connect(): Promise<unknown>;
|
|
6
|
-
}
|
|
7
4
|
/** A build-known map checks each generated reference against its component input. */
|
|
8
5
|
export type ViewRegistry<R extends ViewReference> = {
|
|
9
6
|
readonly [K in R["kind"]]: Type<{
|
|
@@ -13,13 +10,13 @@ export type ViewRegistry<R extends ViewReference> = {
|
|
|
13
10
|
}>;
|
|
14
11
|
};
|
|
15
12
|
/** Headless host for a selected logical .NET View. A changed reference remounts its component. */
|
|
16
|
-
export declare class RunicViewOutlet {
|
|
17
|
-
readonly content: InputSignal<
|
|
18
|
-
readonly registry: InputSignal<
|
|
13
|
+
export declare class RunicViewOutlet<R extends ViewReference = ViewReference> {
|
|
14
|
+
readonly content: InputSignal<R | null | undefined>;
|
|
15
|
+
readonly registry: InputSignal<ViewRegistry<R>>;
|
|
19
16
|
readonly error: import("@angular/core").WritableSignal<string | undefined>;
|
|
20
17
|
private readonly mount;
|
|
21
18
|
private readonly selected;
|
|
22
19
|
constructor();
|
|
23
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RunicViewOutlet
|
|
24
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<RunicViewOutlet
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RunicViewOutlet<any>, never>;
|
|
21
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RunicViewOutlet<any>, "runic-view-outlet", never, { "content": { "alias": "content"; "required": false; "isSignal": true; }; "registry": { "alias": "registry"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
25
22
|
}
|
package/dist/esm/view-outlet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, computed, effect, input, signal, viewChild, ViewContainerRef } from "@angular/core";
|
|
1
|
+
import { Component, computed, effect, input, signal, untracked, viewChild, ViewContainerRef } from "@angular/core";
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
/** Headless host for a selected logical .NET View. A changed reference remounts its component. */
|
|
4
4
|
export class RunicViewOutlet {
|
|
@@ -11,23 +11,31 @@ export class RunicViewOutlet {
|
|
|
11
11
|
mount = viewChild.required("mount", { ...(ngDevMode ? { debugName: "mount" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
|
|
12
12
|
selected = computed(() => {
|
|
13
13
|
const reference = this.content();
|
|
14
|
-
|
|
14
|
+
if (!reference)
|
|
15
|
+
return undefined;
|
|
16
|
+
// A registry built without `satisfies ViewRegistry<R>` may miss a kind at run time.
|
|
17
|
+
const component = this.registry()[reference.kind];
|
|
18
|
+
return { reference, component };
|
|
15
19
|
}, /* @ts-ignore */
|
|
16
20
|
...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
|
|
17
21
|
constructor() {
|
|
18
22
|
effect(() => {
|
|
19
23
|
const container = this.mount();
|
|
20
24
|
const selection = this.selected();
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
// Creating the component runs its constructor and inputs; their signal
|
|
26
|
+
// reads must not become dependencies of this effect.
|
|
27
|
+
untracked(() => {
|
|
28
|
+
container.clear();
|
|
29
|
+
this.error.set(undefined);
|
|
30
|
+
if (!selection)
|
|
31
|
+
return;
|
|
32
|
+
if (!selection.component) {
|
|
33
|
+
this.error.set(`No web component is registered for ${selection.reference.kind}.`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const component = container.createComponent(selection.component);
|
|
37
|
+
component.setInput("page", selection.reference);
|
|
38
|
+
});
|
|
31
39
|
});
|
|
32
40
|
}
|
|
33
41
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: RunicViewOutlet, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-preview.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"./package.json": "./package.json"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@angular/core": ">=20.3.26 <23"
|
|
13
|
+
"@angular/core": ">=20.3.26 <23",
|
|
14
|
+
"@runic-artifex/views": "0.7.0-preview.2"
|
|
14
15
|
},
|
|
15
16
|
"description": "Angular outlet and signals for Runic Views",
|
|
16
17
|
"license": "MIT",
|
|
@@ -42,10 +43,11 @@
|
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "ngc -p tsconfig.json",
|
|
44
45
|
"check": "ngc -p tsconfig.json --noEmit",
|
|
45
|
-
"test": "bun run --bun build && vitest run",
|
|
46
|
+
"test": "bun run --bun build && tsc -p tsconfig.test.json && vitest run",
|
|
46
47
|
"pack:check": "bun pm pack --dry-run"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
50
|
+
"@runic-artifex/views": "0.7.0-preview.2",
|
|
49
51
|
"@angular/common": "22.2.1",
|
|
50
52
|
"@angular/compiler": "22.2.1",
|
|
51
53
|
"@angular/compiler-cli": "22.2.1",
|
|
@@ -55,5 +57,5 @@
|
|
|
55
57
|
"typescript": "6.0.3",
|
|
56
58
|
"vitest": "5.0.3"
|
|
57
59
|
},
|
|
58
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "0e915be4f0618af6260b9d8b416c9afc1826b80d"
|
|
59
61
|
}
|