@runic-artifex/angular 0.5.0-preview.3 → 0.7.0-preview.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 +111 -6
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -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 +30 -0
- package/dist/esm/inject-view.js +52 -0
- package/dist/esm/view-outlet.d.ts +6 -9
- package/dist/esm/view-outlet.js +23 -15
- package/package.json +20 -13
package/README.md
CHANGED
|
@@ -1,7 +1,56 @@
|
|
|
1
1
|
# `@runic-artifex/angular`
|
|
2
2
|
|
|
3
|
-
Angular outlet for generated Runic View
|
|
4
|
-
|
|
3
|
+
Angular outlet and signals for generated Runic View clients. The generated
|
|
4
|
+
modules import `@runic-artifex/views`, which this package also builds on, so
|
|
5
|
+
install both:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @runic-artifex/angular@preview @runic-artifex/views@preview
|
|
9
|
+
pnpm add @runic-artifex/angular@preview @runic-artifex/views@preview
|
|
10
|
+
bun add @runic-artifex/angular@preview @runic-artifex/views@preview
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Previews are published under the `preview` dist-tag. Install the versions that
|
|
14
|
+
match your Runic SDK packages.
|
|
15
|
+
|
|
16
|
+
## Connecting a View
|
|
17
|
+
|
|
18
|
+
`injectView(source)` connects a generated page reference, or
|
|
19
|
+
`{ connect: connect<Name> }` for a root ViewModel, for the lifetime of the
|
|
20
|
+
injection context and returns `state`, `client`, `error` and `pending`
|
|
21
|
+
signals and `retry()`:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { Component, input } from "@angular/core";
|
|
25
|
+
import { injectCommand, injectView } from "@runic-artifex/angular";
|
|
26
|
+
import type { CounterPageReference } from "./generated/counter";
|
|
27
|
+
|
|
28
|
+
@Component({
|
|
29
|
+
selector: "counter-page",
|
|
30
|
+
template: `
|
|
31
|
+
<button [disabled]="!counter.client() || increment.pending()" (click)="increment.run()">
|
|
32
|
+
{{ counter.state()?.count ?? "…" }}
|
|
33
|
+
</button>
|
|
34
|
+
@if (increment.error() ?? counter.error(); as issue) { <p role="alert">{{ issue }}</p> }
|
|
35
|
+
`,
|
|
36
|
+
})
|
|
37
|
+
export class CounterPage {
|
|
38
|
+
readonly page = input.required<CounterPageReference>();
|
|
39
|
+
readonly counter = injectView(this.page);
|
|
40
|
+
readonly increment = injectCommand(() => this.counter.client()?.increment());
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Pass a signal, such as an input, to follow it: a reference with a different
|
|
45
|
+
`connect` function releases the previous client and connects the new one. An
|
|
46
|
+
already connected client is observed and left to its owner. Outside an
|
|
47
|
+
injection context, pass `{ injector }`; pass `{ release }` to defer disposal,
|
|
48
|
+
for example until queued commands finish.
|
|
49
|
+
|
|
50
|
+
## Outlet
|
|
51
|
+
|
|
52
|
+
Register a component for each generated View kind and pass the current
|
|
53
|
+
reference to the outlet.
|
|
5
54
|
|
|
6
55
|
```ts
|
|
7
56
|
import { RunicViewOutlet, type ViewRegistry } from "@runic-artifex/angular";
|
|
@@ -14,7 +63,63 @@ const registry = { document: DocumentPage } satisfies ViewRegistry<DocumentRefer
|
|
|
14
63
|
// <runic-view-outlet [content]="current()" [registry]="registry" />
|
|
15
64
|
```
|
|
16
65
|
|
|
17
|
-
The outlet
|
|
18
|
-
component
|
|
19
|
-
|
|
20
|
-
|
|
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
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
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";
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Injector, type Signal } from "@angular/core";
|
|
2
|
+
import { type ViewClient, type ViewSource } from "@runic-artifex/views";
|
|
3
|
+
export interface ViewHandle<TClient extends ViewClient> {
|
|
4
|
+
/** The latest state, or undefined until the client connects. */
|
|
5
|
+
readonly state: Signal<TClient["snapshot"] | undefined>;
|
|
6
|
+
/** The connected client for commands, or undefined until it connects. */
|
|
7
|
+
readonly client: Signal<TClient | undefined>;
|
|
8
|
+
/** The connection failure, if any. */
|
|
9
|
+
readonly error: Signal<unknown>;
|
|
10
|
+
/** True while a reference is connecting. */
|
|
11
|
+
readonly pending: Signal<boolean>;
|
|
12
|
+
/** Connects a reference again after a failure. */
|
|
13
|
+
retry(): void;
|
|
14
|
+
}
|
|
15
|
+
export interface InjectViewOptions<TClient extends ViewClient> {
|
|
16
|
+
/** Required outside an injection context. */
|
|
17
|
+
readonly injector?: Injector;
|
|
18
|
+
/** Releases a client this helper connected. Defaults to `client.dispose()`. */
|
|
19
|
+
readonly release?: (client: TClient) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Connects a generated View reference for the lifetime of the injection
|
|
23
|
+
* context (normally a component) and exposes its state as signals. Pass a
|
|
24
|
+
* signal, such as a `page` input, to follow it: a changed reference releases
|
|
25
|
+
* the previous client and connects the new one.
|
|
26
|
+
*
|
|
27
|
+
* A reference is identified by its `connect` function, so a signal producing a
|
|
28
|
+
* new `{ connect: connectShell }` object does not reconnect.
|
|
29
|
+
*/
|
|
30
|
+
export declare function injectView<TClient extends ViewClient>(source: Signal<ViewSource<TClient>> | ViewSource<TClient>, options?: InjectViewOptions<TClient>): ViewHandle<TClient>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, isSignal, signal, untracked } from "@angular/core";
|
|
2
|
+
import { createViewController, isViewClient, viewSourceIdentity } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* Connects a generated View reference for the lifetime of the injection
|
|
5
|
+
* context (normally a component) and exposes its state as signals. Pass a
|
|
6
|
+
* signal, such as a `page` input, to follow it: a changed reference releases
|
|
7
|
+
* the previous client and connects the new one.
|
|
8
|
+
*
|
|
9
|
+
* A reference is identified by its `connect` function, so a signal producing a
|
|
10
|
+
* new `{ connect: connectShell }` object does not reconnect.
|
|
11
|
+
*/
|
|
12
|
+
export function injectView(source, options = {}) {
|
|
13
|
+
if (!options.injector)
|
|
14
|
+
assertInInjectionContext(injectView);
|
|
15
|
+
const injector = options.injector ?? inject(Injector);
|
|
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));
|
|
20
|
+
const read = () => isSignal(source) ? source() : source;
|
|
21
|
+
const identity = computed(() => viewSourceIdentity(read()), /* @ts-ignore */
|
|
22
|
+
...(ngDevMode ? [{ debugName: "identity" }] : /* istanbul ignore next */ []));
|
|
23
|
+
const observed = computed(() => {
|
|
24
|
+
const value = read();
|
|
25
|
+
return value && isViewClient(value) ? value : undefined;
|
|
26
|
+
}, /* @ts-ignore */
|
|
27
|
+
...(ngDevMode ? [{ debugName: "observed" }] : /* istanbul ignore next */ []));
|
|
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(() => {
|
|
32
|
+
identity();
|
|
33
|
+
untracked(() => {
|
|
34
|
+
controller.setSource(read());
|
|
35
|
+
current.set(controller.current);
|
|
36
|
+
});
|
|
37
|
+
}, { injector });
|
|
38
|
+
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
39
|
+
return {
|
|
40
|
+
// A connected client is readable before the effect observes it.
|
|
41
|
+
state: computed(() => {
|
|
42
|
+
const value = observed();
|
|
43
|
+
if (value && value !== current().client)
|
|
44
|
+
return value.snapshot;
|
|
45
|
+
return fresh() ? current().state : undefined;
|
|
46
|
+
}),
|
|
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(),
|
|
51
|
+
};
|
|
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,32 +11,40 @@ 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
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1
|
|
34
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1
|
|
41
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: RunicViewOutlet, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
42
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.1", type: RunicViewOutlet, isStandalone: true, selector: "runic-view-outlet", inputs: { content: { classPropertyName: "content", publicName: "content", isSignal: true, isRequired: false, transformFunction: null }, registry: { classPropertyName: "registry", publicName: "registry", isSignal: true, isRequired: true, transformFunction: null } }, viewQueries: [{ propertyName: "mount", first: true, predicate: ["mount"], descendants: true, read: ViewContainerRef, isSignal: true }], ngImport: i0, template: `
|
|
35
43
|
<ng-container #mount />
|
|
36
44
|
@if (error(); as issue) { <p role="alert">{{ issue }}</p> }
|
|
37
45
|
`, isInline: true });
|
|
38
46
|
}
|
|
39
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1
|
|
47
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: RunicViewOutlet, decorators: [{
|
|
40
48
|
type: Component,
|
|
41
49
|
args: [{
|
|
42
50
|
selector: "runic-view-outlet",
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-preview.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
|
-
"types": "./dist/esm/
|
|
8
|
-
"import": "./dist/esm/
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"import": "./dist/esm/index.js"
|
|
9
9
|
},
|
|
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.1"
|
|
14
15
|
},
|
|
15
|
-
"description": "Angular outlet for Runic Views",
|
|
16
|
+
"description": "Angular outlet and signals for Runic Views",
|
|
16
17
|
"license": "MIT",
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -37,18 +38,24 @@
|
|
|
37
38
|
},
|
|
38
39
|
"packageManager": "bun@1.4.2",
|
|
39
40
|
"sideEffects": false,
|
|
40
|
-
"main": "./dist/esm/
|
|
41
|
-
"types": "./dist/esm/
|
|
41
|
+
"main": "./dist/esm/index.js",
|
|
42
|
+
"types": "./dist/esm/index.d.ts",
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "ngc -p tsconfig.json",
|
|
44
45
|
"check": "ngc -p tsconfig.json --noEmit",
|
|
46
|
+
"test": "bun run --bun build && tsc -p tsconfig.test.json && vitest run",
|
|
45
47
|
"pack:check": "bun pm pack --dry-run"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@angular/
|
|
50
|
-
"@angular/
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
"@runic-artifex/views": "0.7.0-preview.1",
|
|
51
|
+
"@angular/common": "22.2.1",
|
|
52
|
+
"@angular/compiler": "22.2.1",
|
|
53
|
+
"@angular/compiler-cli": "22.2.1",
|
|
54
|
+
"@angular/core": "22.2.1",
|
|
55
|
+
"@angular/platform-browser": "22.2.1",
|
|
56
|
+
"happy-dom": "20.14.5",
|
|
57
|
+
"typescript": "6.0.3",
|
|
58
|
+
"vitest": "5.0.3"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "7bc41a71c8a4d22ff5855e56b51067d6c02699c1"
|
|
54
61
|
}
|