@runic-artifex/angular 0.18.0 → 0.20.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 +130 -23
- package/dist/fesm2022/runic-artifex-angular-experimental.mjs +285 -0
- package/dist/fesm2022/runic-artifex-angular-experimental.mjs.map +1 -0
- package/dist/fesm2022/runic-artifex-angular-forms.mjs +246 -0
- package/dist/fesm2022/runic-artifex-angular-forms.mjs.map +1 -0
- package/dist/fesm2022/runic-artifex-angular.mjs +975 -0
- package/dist/fesm2022/runic-artifex-angular.mjs.map +1 -0
- package/dist/types/runic-artifex-angular-experimental.d.ts +85 -0
- package/dist/types/runic-artifex-angular-forms.d.ts +72 -0
- package/dist/types/runic-artifex-angular.d.ts +626 -0
- package/package.json +20 -17
- package/dist/esm/experimental.d.ts +0 -39
- package/dist/esm/experimental.js +0 -64
- package/dist/esm/forms/index.d.ts +0 -2
- package/dist/esm/forms/index.js +0 -2
- package/dist/esm/forms/runic-field.directive.d.ts +0 -48
- package/dist/esm/forms/runic-field.directive.js +0 -195
- package/dist/esm/forms/signal-forms.d.ts +0 -19
- package/dist/esm/forms/signal-forms.js +0 -29
- package/dist/esm/index.d.ts +0 -24
- package/dist/esm/index.js +0 -25
- package/dist/esm/inject-appearance.d.ts +0 -19
- package/dist/esm/inject-appearance.js +0 -28
- package/dist/esm/inject-bridge-connection.d.ts +0 -22
- package/dist/esm/inject-bridge-connection.js +0 -26
- package/dist/esm/inject-collection-viewport.d.ts +0 -13
- package/dist/esm/inject-collection-viewport.js +0 -31
- package/dist/esm/inject-command.d.ts +0 -35
- package/dist/esm/inject-command.js +0 -33
- package/dist/esm/inject-field.d.ts +0 -66
- package/dist/esm/inject-field.js +0 -58
- package/dist/esm/inject-form.d.ts +0 -40
- package/dist/esm/inject-form.js +0 -48
- package/dist/esm/inject-latest-operation.d.ts +0 -25
- package/dist/esm/inject-latest-operation.js +0 -35
- package/dist/esm/inject-menu-bar.d.ts +0 -32
- package/dist/esm/inject-menu-bar.js +0 -39
- package/dist/esm/inject-operation.d.ts +0 -23
- package/dist/esm/inject-operation.js +0 -33
- package/dist/esm/inject-query-collection.d.ts +0 -29
- package/dist/esm/inject-query-collection.js +0 -64
- package/dist/esm/inject-text-field.d.ts +0 -55
- package/dist/esm/inject-text-field.js +0 -51
- package/dist/esm/inject-text.d.ts +0 -57
- package/dist/esm/inject-text.js +0 -107
- package/dist/esm/inject-view-resource.d.ts +0 -39
- package/dist/esm/inject-view-resource.js +0 -98
- package/dist/esm/inject-view.d.ts +0 -41
- package/dist/esm/inject-view.js +0 -67
- package/dist/esm/instance.d.ts +0 -34
- package/dist/esm/instance.js +0 -48
- package/dist/esm/view-outlet.d.ts +0 -101
- package/dist/esm/view-outlet.js +0 -177
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, DestroyRef, effect, ElementRef, inject, Injector, NgZone, signal, untracked } from "@angular/core";
|
|
2
|
-
import { createQueryViewportController, } from "@runic-artifex/views";
|
|
3
|
-
const empty = { items: [], totalSize: 0, total: null, query: { sort: [], filters: [] }, loading: false, error: undefined };
|
|
4
|
-
/**
|
|
5
|
-
* Follows a scroll container for a query collection (`client.queries.{name}`): it loads the rows the container shows
|
|
6
|
-
* from .NET, with placeholders until they arrive, and lays them out with variable heights. Pass the container, for
|
|
7
|
-
* example `viewChild<ElementRef<HTMLElement>>("scroller")`, the collection as a function such as
|
|
8
|
-
* `() => view.client()?.queries.rows`, and the options.
|
|
9
|
-
*/
|
|
10
|
-
export function injectQueryCollection(element, collection, options, { injector: provided } = {}) {
|
|
11
|
-
if (!provided)
|
|
12
|
-
assertInInjectionContext(injectQueryCollection);
|
|
13
|
-
const injector = provided ?? inject(Injector);
|
|
14
|
-
const viewport = signal(empty, /* @ts-ignore */
|
|
15
|
-
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
16
|
-
const zone = injector.get(NgZone, null);
|
|
17
|
-
const outside = (run) => zone ? zone.runOutsideAngular(run) : run();
|
|
18
|
-
let controller;
|
|
19
|
-
const container = () => {
|
|
20
|
-
const target = untracked(element);
|
|
21
|
-
return target instanceof ElementRef ? target.nativeElement : target ?? null;
|
|
22
|
-
};
|
|
23
|
-
let release;
|
|
24
|
-
effect(() => {
|
|
25
|
-
const current = collection();
|
|
26
|
-
untracked(() => {
|
|
27
|
-
release?.();
|
|
28
|
-
release = undefined;
|
|
29
|
-
if (!current) {
|
|
30
|
-
viewport.set(empty);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const created = controller = createQueryViewportController(current, options());
|
|
34
|
-
const stop = created.subscribe(() => viewport.set(created.current));
|
|
35
|
-
outside(() => created.attach(container()));
|
|
36
|
-
viewport.set(created.current);
|
|
37
|
-
release = () => { stop(); created.dispose(); if (controller === created)
|
|
38
|
-
controller = undefined; };
|
|
39
|
-
});
|
|
40
|
-
}, { injector });
|
|
41
|
-
effect(() => {
|
|
42
|
-
const { estimateSize, overscan } = options();
|
|
43
|
-
untracked(() => controller?.update({ estimateSize, ...(overscan === undefined ? {} : { overscan }) }));
|
|
44
|
-
}, { injector });
|
|
45
|
-
// Scroll and resize events only update the viewport signal, which schedules change detection itself.
|
|
46
|
-
effect(() => {
|
|
47
|
-
element();
|
|
48
|
-
untracked(() => outside(() => controller?.attach(container())));
|
|
49
|
-
}, { injector });
|
|
50
|
-
injector.get(DestroyRef).onDestroy(() => { release?.(); release = undefined; });
|
|
51
|
-
return {
|
|
52
|
-
viewport: viewport.asReadonly(),
|
|
53
|
-
observe: (target, index) => controller?.observe(target instanceof ElementRef ? target.nativeElement : target, index) ?? (() => { }),
|
|
54
|
-
scrollToKey: async (key, align) => controller ? controller.scrollToKey(key, align) : false,
|
|
55
|
-
scrollToIndex: (index, align) => controller?.scrollToIndex(index, align),
|
|
56
|
-
setQuery: async (query) => {
|
|
57
|
-
const current = untracked(collection);
|
|
58
|
-
if (!current)
|
|
59
|
-
throw new TypeError("injectQueryCollection has no collection yet.");
|
|
60
|
-
await current.setQuery(query);
|
|
61
|
-
},
|
|
62
|
-
retry: () => untracked(collection)?.retry(),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type ViewClient } from "@runic-artifex/views";
|
|
3
|
-
/** A text input bound to one View member. */
|
|
4
|
-
export interface TextFieldHandle {
|
|
5
|
-
/** What the input shows: the draft while one exists, otherwise the member's value in the View's state. */
|
|
6
|
-
readonly value: Signal<string>;
|
|
7
|
-
/**
|
|
8
|
-
* True while a draft exists, from the first input until the last write settled and the state caught up, and after a
|
|
9
|
-
* failed write. Keep the input enabled while it is true, rather than disabling it on the View's busy state, which
|
|
10
|
-
* the field's own write causes.
|
|
11
|
-
*/
|
|
12
|
-
readonly editing: Signal<boolean>;
|
|
13
|
-
/** Why the latest write failed, until the next input or `reset()`. */
|
|
14
|
-
readonly error: Signal<unknown>;
|
|
15
|
-
/** The user changed the text: pass the `input` event, or the new text. */
|
|
16
|
-
input(event: Event | string): void;
|
|
17
|
-
/** An IME composition started: the text is kept but not written until it ends. Bind it to `compositionstart`. */
|
|
18
|
-
compositionStart(): void;
|
|
19
|
-
/** The IME composition ended: pass the `compositionend` event, or the text, which is then written. */
|
|
20
|
-
compositionEnd(event: Event | string): void;
|
|
21
|
-
/** Drops the draft and the error and shows the View's value. Writes in flight still complete. */
|
|
22
|
-
reset(): void;
|
|
23
|
-
}
|
|
24
|
-
export interface InjectTextFieldOptions {
|
|
25
|
-
/** Required outside an injection context. */
|
|
26
|
-
readonly injector?: Injector;
|
|
27
|
-
/**
|
|
28
|
-
* With `true` (the default) at most one write is in flight, and text typed meanwhile is written next, as one
|
|
29
|
-
* value. With `false` every input is written.
|
|
30
|
-
*/
|
|
31
|
-
readonly coalesce?: boolean;
|
|
32
|
-
/** With `true` (the default) a failed write keeps the draft and sets `error`; with `false` the field shows the View's value again. */
|
|
33
|
-
readonly keepDraftOnError?: boolean;
|
|
34
|
-
}
|
|
35
|
-
/** The View a text field binds to: an {@link injectView} handle, or any pair of state and client signals. */
|
|
36
|
-
export interface TextFieldView<TClient extends ViewClient> {
|
|
37
|
-
readonly state: Signal<TClient["snapshot"] | undefined>;
|
|
38
|
-
readonly client: Signal<TClient | undefined>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Binds a text input to one member of a View for the lifetime of the injection context, through
|
|
42
|
-
* `createTextFieldController`. Typing key by key never loses characters: while its writes are in flight the field
|
|
43
|
-
* shows what the user typed, at most one write is in flight (newer text is written next), nothing is written during
|
|
44
|
-
* IME composition, and once the last write settled it shows the View's value, including any normalization.
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* readonly person = injectView(this.page);
|
|
48
|
-
* readonly name = injectTextField(this.person, state => state.name, (client, value) => client.setName(value));
|
|
49
|
-
* // <input [value]="name.value()" (input)="name.input($event)"
|
|
50
|
-
* // (compositionstart)="name.compositionStart()" (compositionend)="name.compositionEnd($event)">
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* `write` may be a generated setter, a command or a checked write. Its failure sets `error` and keeps the draft.
|
|
54
|
-
*/
|
|
55
|
-
export declare function injectTextField<TClient extends ViewClient>(view: TextFieldView<TClient>, read: (state: TClient["snapshot"]) => string, write: (client: TClient, value: string) => Promise<unknown>, { injector: provided, ...options }?: InjectTextFieldOptions): TextFieldHandle;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, signal, untracked } from "@angular/core";
|
|
2
|
-
import { createTextFieldController } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
function textOf(event) {
|
|
5
|
-
if (typeof event === "string")
|
|
6
|
-
return event;
|
|
7
|
-
const target = event.target;
|
|
8
|
-
return typeof target?.value === "string" ? target.value : "";
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Binds a text input to one member of a View for the lifetime of the injection context, through
|
|
12
|
-
* `createTextFieldController`. Typing key by key never loses characters: while its writes are in flight the field
|
|
13
|
-
* shows what the user typed, at most one write is in flight (newer text is written next), nothing is written during
|
|
14
|
-
* IME composition, and once the last write settled it shows the View's value, including any normalization.
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* readonly person = injectView(this.page);
|
|
18
|
-
* readonly name = injectTextField(this.person, state => state.name, (client, value) => client.setName(value));
|
|
19
|
-
* // <input [value]="name.value()" (input)="name.input($event)"
|
|
20
|
-
* // (compositionstart)="name.compositionStart()" (compositionend)="name.compositionEnd($event)">
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* `write` may be a generated setter, a command or a checked write. Its failure sets `error` and keeps the draft.
|
|
24
|
-
*/
|
|
25
|
-
export function injectTextField(view, read, write, { injector: provided, ...options } = {}) {
|
|
26
|
-
if (!provided)
|
|
27
|
-
assertInInjectionContext(injectTextField);
|
|
28
|
-
const injector = provided ?? inject(Injector);
|
|
29
|
-
const controller = instanceOf(injector).run(() => createTextFieldController({ read, write, ...options }));
|
|
30
|
-
const current = signal(controller.current, /* @ts-ignore */
|
|
31
|
-
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
32
|
-
controller.subscribe(() => current.set(controller.current));
|
|
33
|
-
effect(() => {
|
|
34
|
-
const state = view.state();
|
|
35
|
-
const client = view.client();
|
|
36
|
-
untracked(() => {
|
|
37
|
-
controller.setSource(state === undefined || client === undefined ? undefined : { state, client });
|
|
38
|
-
current.set(controller.current);
|
|
39
|
-
});
|
|
40
|
-
}, { injector });
|
|
41
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
42
|
-
return {
|
|
43
|
-
value: computed(() => current().value),
|
|
44
|
-
editing: computed(() => current().editing),
|
|
45
|
-
error: computed(() => current().error),
|
|
46
|
-
input(event) { controller.input(textOf(event)); },
|
|
47
|
-
compositionStart() { controller.compositionStart(); },
|
|
48
|
-
compositionEnd(event) { controller.compositionEnd(textOf(event)); },
|
|
49
|
-
reset() { controller.reset(); },
|
|
50
|
-
};
|
|
51
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Injector, type OnDestroy, type PipeTransform, type Signal } from "@angular/core";
|
|
2
|
-
import { type FieldError, type RunicInstance, type TextReference } from "@runic-artifex/views";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export interface InjectTextOptions {
|
|
5
|
-
/** Required outside an injection context. */
|
|
6
|
-
readonly injector?: Injector;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
10
|
-
* language (`resolveText`), as a signal that follows a language switch for the lifetime of the injection context.
|
|
11
|
-
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
12
|
-
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
13
|
-
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
14
|
-
* A field's `FieldError` shows the application's text for it (`configureFieldErrorText`), or its English message.
|
|
15
|
-
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* readonly status = injectText(() => this.view.state()?.status);
|
|
19
|
-
* // <p>{{ status() }}</p>
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function injectText(source: () => TextReference | FieldError | string | null | undefined, fallback?: () => string | undefined, { injector: provided }?: InjectTextOptions): Signal<string>;
|
|
23
|
-
/**
|
|
24
|
-
* The window's locale that the application set, or `null` while it sets none, as a signal for the lifetime of the
|
|
25
|
-
* injection context, for example to bind `lang`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function injectWindowLocale({ injector: provided }?: InjectTextOptions): Signal<string | null>;
|
|
28
|
-
/**
|
|
29
|
-
* The locale that text is shown in (`textLocale`: the instance's Translations locale, which follows the window's
|
|
30
|
-
* locale), as a signal. It is one signal per Runic instance and needs no injection context, so the page's locale
|
|
31
|
-
* resolver can read it: a template that calls `m.*()` reads the signal through the resolver and renders again on a
|
|
32
|
-
* language switch. `undefined` while the instance has no Translations runtime and the application sets no window
|
|
33
|
-
* locale. The instance is `instance`, else that of the injection context, else the page instance.
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* const textLocale = textLocaleSignal();
|
|
37
|
-
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function textLocaleSignal(instance?: RunicInstance): Signal<string | undefined>;
|
|
41
|
-
/**
|
|
42
|
-
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
43
|
-
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
44
|
-
* `null` and `undefined` show the fallback argument; a field's error, `{{ name.error() | runicText }}`, the application's
|
|
45
|
-
* text for it (`configureFieldErrorText`). The pipe is impure so that it sees a language switch; it formats
|
|
46
|
-
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
47
|
-
*/
|
|
48
|
-
export declare class RunicTextPipe implements PipeTransform, OnDestroy {
|
|
49
|
-
private readonly changes;
|
|
50
|
-
private readonly instance;
|
|
51
|
-
private readonly stop;
|
|
52
|
-
private last;
|
|
53
|
-
transform(value: TextReference | FieldError | string | null | undefined, fallback?: string): string;
|
|
54
|
-
ngOnDestroy(): void;
|
|
55
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RunicTextPipe, never>;
|
|
56
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<RunicTextPipe, "runicText", true>;
|
|
57
|
-
}
|
package/dist/esm/inject-text.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, ChangeDetectorRef, computed, DestroyRef, inject, Injector, Pipe, PLATFORM_ID, signal, } from "@angular/core";
|
|
2
|
-
import { onWindowLocale, resolveText, subscribeText, textLocale, textVersion, windowLocale, } from "@runic-artifex/views";
|
|
3
|
-
import { contextInstance, instanceOf } from "./instance.js";
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
/**
|
|
6
|
-
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
7
|
-
* language (`resolveText`), as a signal that follows a language switch for the lifetime of the injection context.
|
|
8
|
-
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
9
|
-
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
10
|
-
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
11
|
-
* A field's `FieldError` shows the application's text for it (`configureFieldErrorText`), or its English message.
|
|
12
|
-
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* readonly status = injectText(() => this.view.state()?.status);
|
|
16
|
-
* // <p>{{ status() }}</p>
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export function injectText(source, fallback, { injector: provided } = {}) {
|
|
20
|
-
if (!provided)
|
|
21
|
-
assertInInjectionContext(injectText);
|
|
22
|
-
const injector = provided ?? inject(Injector);
|
|
23
|
-
const instance = instanceOf(injector);
|
|
24
|
-
const version = signal(0, /* @ts-ignore */
|
|
25
|
-
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
26
|
-
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
27
|
-
const stop = instance.run(() => subscribeText(() => version.update(value => value + 1)));
|
|
28
|
-
injector.get(DestroyRef).onDestroy(stop);
|
|
29
|
-
}
|
|
30
|
-
return computed(() => {
|
|
31
|
-
version();
|
|
32
|
-
const value = source(), otherwise = fallback?.();
|
|
33
|
-
return instance.run(() => resolveText(value, otherwise));
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* The window's locale that the application set, or `null` while it sets none, as a signal for the lifetime of the
|
|
38
|
-
* injection context, for example to bind `lang`.
|
|
39
|
-
*/
|
|
40
|
-
export function injectWindowLocale({ injector: provided } = {}) {
|
|
41
|
-
if (!provided)
|
|
42
|
-
assertInInjectionContext(injectWindowLocale);
|
|
43
|
-
const injector = provided ?? inject(Injector);
|
|
44
|
-
const instance = instanceOf(injector);
|
|
45
|
-
const locale = signal(instance.run(windowLocale), /* @ts-ignore */
|
|
46
|
-
...(ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
47
|
-
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
48
|
-
const stop = instance.run(() => onWindowLocale(next => locale.set(next)));
|
|
49
|
-
injector.get(DestroyRef).onDestroy(stop);
|
|
50
|
-
}
|
|
51
|
-
return locale.asReadonly();
|
|
52
|
-
}
|
|
53
|
-
const textLocales = new WeakMap();
|
|
54
|
-
/**
|
|
55
|
-
* The locale that text is shown in (`textLocale`: the instance's Translations locale, which follows the window's
|
|
56
|
-
* locale), as a signal. It is one signal per Runic instance and needs no injection context, so the page's locale
|
|
57
|
-
* resolver can read it: a template that calls `m.*()` reads the signal through the resolver and renders again on a
|
|
58
|
-
* language switch. `undefined` while the instance has no Translations runtime and the application sets no window
|
|
59
|
-
* locale. The instance is `instance`, else that of the injection context, else the page instance.
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* const textLocale = textLocaleSignal();
|
|
63
|
-
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export function textLocaleSignal(instance = contextInstance()) {
|
|
67
|
-
const existing = textLocales.get(instance);
|
|
68
|
-
if (existing)
|
|
69
|
-
return existing;
|
|
70
|
-
const current = signal(instance.run(textLocale), /* @ts-ignore */
|
|
71
|
-
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
72
|
-
instance.run(() => subscribeText(() => current.set(instance.run(textLocale))));
|
|
73
|
-
const locale = current.asReadonly();
|
|
74
|
-
textLocales.set(instance, locale);
|
|
75
|
-
return locale;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
79
|
-
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
80
|
-
* `null` and `undefined` show the fallback argument; a field's error, `{{ name.error() | runicText }}`, the application's
|
|
81
|
-
* text for it (`configureFieldErrorText`). The pipe is impure so that it sees a language switch; it formats
|
|
82
|
-
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
83
|
-
*/
|
|
84
|
-
export class RunicTextPipe {
|
|
85
|
-
changes = inject(ChangeDetectorRef);
|
|
86
|
-
instance = instanceOf(inject(Injector));
|
|
87
|
-
stop = this.instance.run(() => subscribeText(() => this.changes.markForCheck()));
|
|
88
|
-
last;
|
|
89
|
-
transform(value, fallback) {
|
|
90
|
-
const version = this.instance.run(textVersion);
|
|
91
|
-
const last = this.last;
|
|
92
|
-
if (last && last.value === value && last.fallback === fallback && last.version === version)
|
|
93
|
-
return last.text;
|
|
94
|
-
const text = this.instance.run(() => resolveText(value, fallback));
|
|
95
|
-
this.last = { value, fallback, version, text };
|
|
96
|
-
return text;
|
|
97
|
-
}
|
|
98
|
-
ngOnDestroy() {
|
|
99
|
-
this.stop();
|
|
100
|
-
}
|
|
101
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
102
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, isStandalone: true, name: "runicText", pure: false });
|
|
103
|
-
}
|
|
104
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, decorators: [{
|
|
105
|
-
type: Pipe,
|
|
106
|
-
args: [{ name: "runicText", standalone: true, pure: false }]
|
|
107
|
-
}] });
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Resource, type Signal } from "@angular/core";
|
|
2
|
-
import { type ViewClient, type ViewSource } from "@runic-artifex/views";
|
|
3
|
-
import type { InjectViewOptions } from "./inject-view.js";
|
|
4
|
-
/**
|
|
5
|
-
* A View connection as an Angular `Resource`: `value()` is the View's state, `status()` is `loading` until the
|
|
6
|
-
* client connected (`reloading` after `reload()`), then `resolved`, or `error` with `error()` the connection
|
|
7
|
-
* failure; `idle` while the source is `null` or `undefined`.
|
|
8
|
-
*/
|
|
9
|
-
export interface ViewResource<TClient extends ViewClient> extends Resource<TClient["snapshot"] | undefined> {
|
|
10
|
-
/** The connected client for commands, or undefined until it connects. */
|
|
11
|
-
readonly client: Signal<TClient | undefined>;
|
|
12
|
-
/** Connects again, for example after a failure. Returns false while the source is `null` or `undefined`. */
|
|
13
|
-
reload(): boolean;
|
|
14
|
-
/** Releases the client and returns the resource to `idle`; the injector's destruction does this too. */
|
|
15
|
-
destroy(): void;
|
|
16
|
-
}
|
|
17
|
-
export type InjectViewResourceOptions<TClient extends ViewClient> = InjectViewOptions<TClient>;
|
|
18
|
-
/**
|
|
19
|
-
* Connects a generated View reference as an Angular `resource()` for the lifetime of the injection context, the
|
|
20
|
-
* asynchronous counterpart of `injectView` (D053.11): a template branches on `hasValue()`, `isLoading()` and
|
|
21
|
-
* `error()` as for any resource, and `value()` is never `undefined` once `hasValue()` is true.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* readonly page = input.required<CounterPageReference>();
|
|
25
|
-
* readonly counter = injectViewResource(this.page);
|
|
26
|
-
* ```
|
|
27
|
-
* ```html
|
|
28
|
-
* @if (counter.hasValue()) {
|
|
29
|
-
* <button (click)="counter.client()?.increment()">{{ counter.value().count }}</button>
|
|
30
|
-
* } @else if (counter.error()) {
|
|
31
|
-
* <p role="alert">{{ describe(counter.error()) }}</p> <button (click)="counter.reload()">Retry</button>
|
|
32
|
-
* } @else { <p>Connecting…</p> }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* A changed reference (by its `connect` function) releases the previous client and loads the new one. Released
|
|
36
|
-
* clients are kept for `keepAlive` milliseconds, as with `injectView`, so a component that is created again
|
|
37
|
-
* resolves at once.
|
|
38
|
-
*/
|
|
39
|
-
export declare function injectViewResource<TClient extends ViewClient>(source: Signal<ViewSource<TClient>> | ViewSource<TClient>, options?: InjectViewResourceOptions<TClient>): ViewResource<TClient>;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, effect, inject, Injector, isSignal, resource, signal, untracked, } from "@angular/core";
|
|
2
|
-
import { createViewController } from "@runic-artifex/views";
|
|
3
|
-
import { viewSourceIdentity } from "@runic-artifex/views/bindings";
|
|
4
|
-
import { instanceOf } from "./instance.js";
|
|
5
|
-
function asError(cause) {
|
|
6
|
-
return cause instanceof Error ? cause : new Error(String(cause), { cause });
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Connects a generated View reference as an Angular `resource()` for the lifetime of the injection context, the
|
|
10
|
-
* asynchronous counterpart of `injectView` (D053.11): a template branches on `hasValue()`, `isLoading()` and
|
|
11
|
-
* `error()` as for any resource, and `value()` is never `undefined` once `hasValue()` is true.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* readonly page = input.required<CounterPageReference>();
|
|
15
|
-
* readonly counter = injectViewResource(this.page);
|
|
16
|
-
* ```
|
|
17
|
-
* ```html
|
|
18
|
-
* @if (counter.hasValue()) {
|
|
19
|
-
* <button (click)="counter.client()?.increment()">{{ counter.value().count }}</button>
|
|
20
|
-
* } @else if (counter.error()) {
|
|
21
|
-
* <p role="alert">{{ describe(counter.error()) }}</p> <button (click)="counter.reload()">Retry</button>
|
|
22
|
-
* } @else { <p>Connecting…</p> }
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* A changed reference (by its `connect` function) releases the previous client and loads the new one. Released
|
|
26
|
-
* clients are kept for `keepAlive` milliseconds, as with `injectView`, so a component that is created again
|
|
27
|
-
* resolves at once.
|
|
28
|
-
*/
|
|
29
|
-
export function injectViewResource(source, options = {}) {
|
|
30
|
-
if (!options.injector)
|
|
31
|
-
assertInInjectionContext(injectViewResource);
|
|
32
|
-
const injector = options.injector ?? inject(Injector);
|
|
33
|
-
const instance = instanceOf(injector);
|
|
34
|
-
const read = () => isSignal(source) ? source() : source;
|
|
35
|
-
const client = signal(undefined, /* @ts-ignore */
|
|
36
|
-
...(ngDevMode ? [{ debugName: "client" }] : /* istanbul ignore next */ []));
|
|
37
|
-
const controllerOptions = {
|
|
38
|
-
...(options.release ? { release: options.release } : {}),
|
|
39
|
-
...(options.keepAlive === undefined ? {} : { keepAlive: options.keepAlive }),
|
|
40
|
-
};
|
|
41
|
-
// The source is identified by its client or `connect` function, so a new wrapper object does not reload.
|
|
42
|
-
const identity = computed(() => viewSourceIdentity(read()), /* @ts-ignore */
|
|
43
|
-
...(ngDevMode ? [{ debugName: "identity" }] : /* istanbul ignore next */ []));
|
|
44
|
-
// The controller of the latest load. A resource that becomes idle does not abort its last load, so it is released here.
|
|
45
|
-
let active;
|
|
46
|
-
effect(() => {
|
|
47
|
-
if (identity() !== undefined)
|
|
48
|
-
return;
|
|
49
|
-
active?.dispose();
|
|
50
|
-
active = undefined;
|
|
51
|
-
client.set(undefined);
|
|
52
|
-
}, { injector });
|
|
53
|
-
const ref = resource({ ...(ngDevMode ? { debugName: "ref" } : /* istanbul ignore next */ {}), injector,
|
|
54
|
-
params: () => identity(),
|
|
55
|
-
stream: async ({ abortSignal }) => {
|
|
56
|
-
// Each load connects in the injection context's Runic instance.
|
|
57
|
-
const controller = instance.run(() => createViewController(controllerOptions));
|
|
58
|
-
active = controller;
|
|
59
|
-
abortSignal.addEventListener("abort", () => {
|
|
60
|
-
if (active === controller)
|
|
61
|
-
active = undefined;
|
|
62
|
-
controller.dispose();
|
|
63
|
-
if (untracked(client) === controller.current.client)
|
|
64
|
-
client.set(undefined);
|
|
65
|
-
}, { once: true });
|
|
66
|
-
controller.setSource(untracked(read));
|
|
67
|
-
if (controller.current.pending) {
|
|
68
|
-
await new Promise(resolve => {
|
|
69
|
-
const stop = controller.subscribe(() => { if (!controller.current.pending) {
|
|
70
|
-
stop();
|
|
71
|
-
resolve();
|
|
72
|
-
} });
|
|
73
|
-
abortSignal.addEventListener("abort", () => { stop(); resolve(); }, { once: true });
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
const value = signal(controller.current.error !== undefined ? { error: asError(controller.current.error) } : { value: controller.current.state });
|
|
77
|
-
if (abortSignal.aborted)
|
|
78
|
-
return value;
|
|
79
|
-
client.set(controller.current.client);
|
|
80
|
-
controller.subscribe(() => {
|
|
81
|
-
const current = controller.current;
|
|
82
|
-
client.set(current.client);
|
|
83
|
-
value.set(current.error !== undefined ? { error: asError(current.error) } : { value: current.state });
|
|
84
|
-
});
|
|
85
|
-
return value;
|
|
86
|
-
} });
|
|
87
|
-
return {
|
|
88
|
-
value: ref.value.asReadonly(),
|
|
89
|
-
status: ref.status,
|
|
90
|
-
error: ref.error,
|
|
91
|
-
isLoading: ref.isLoading,
|
|
92
|
-
snapshot: ref.snapshot,
|
|
93
|
-
hasValue: () => ref.hasValue(),
|
|
94
|
-
client: client.asReadonly(),
|
|
95
|
-
reload: () => ref.reload(),
|
|
96
|
-
destroy: () => ref.destroy(),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
* Milliseconds a client this helper connected stays connected after the component unmounts or the source changes,
|
|
22
|
-
* for the next helper that follows the same reference (StrictMode, HMR, `<Activity>`, A→B→A navigation). `0`
|
|
23
|
-
* disposes it at once. Defaults to 2000. Read once, when the helper is created.
|
|
24
|
-
*/
|
|
25
|
-
readonly keepAlive?: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Connects a generated View reference for the lifetime of the injection
|
|
29
|
-
* context (normally a component) and exposes its state as signals. Pass a
|
|
30
|
-
* signal, such as a `page` input, to follow it: a changed reference releases
|
|
31
|
-
* the previous client and connects the new one.
|
|
32
|
-
*
|
|
33
|
-
* A released client stays connected for `keepAlive` milliseconds (2000 by
|
|
34
|
-
* default), and the next `injectView` of the same reference takes it over with
|
|
35
|
-
* its state: an `@if` that toggles, HMR and A→B→A navigation show the View at
|
|
36
|
-
* once instead of opening the route again.
|
|
37
|
-
*
|
|
38
|
-
* A reference is identified by its `connect` function, so a signal producing a
|
|
39
|
-
* new `{ connect: connectShell }` object does not reconnect.
|
|
40
|
-
*/
|
|
41
|
-
export declare function injectView<TClient extends ViewClient>(source: Signal<ViewSource<TClient>> | ViewSource<TClient>, options?: InjectViewOptions<TClient>): ViewHandle<TClient>;
|
package/dist/esm/inject-view.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, isSignal, signal, untracked } from "@angular/core";
|
|
2
|
-
import { createViewController } from "@runic-artifex/views";
|
|
3
|
-
import { isViewClient, viewSourceIdentity, viewSourcePreview } from "@runic-artifex/views/bindings";
|
|
4
|
-
import { instanceOf } from "./instance.js";
|
|
5
|
-
/**
|
|
6
|
-
* Connects a generated View reference for the lifetime of the injection
|
|
7
|
-
* context (normally a component) and exposes its state as signals. Pass a
|
|
8
|
-
* signal, such as a `page` input, to follow it: a changed reference releases
|
|
9
|
-
* the previous client and connects the new one.
|
|
10
|
-
*
|
|
11
|
-
* A released client stays connected for `keepAlive` milliseconds (2000 by
|
|
12
|
-
* default), and the next `injectView` of the same reference takes it over with
|
|
13
|
-
* its state: an `@if` that toggles, HMR and A→B→A navigation show the View at
|
|
14
|
-
* once instead of opening the route again.
|
|
15
|
-
*
|
|
16
|
-
* A reference is identified by its `connect` function, so a signal producing a
|
|
17
|
-
* new `{ connect: connectShell }` object does not reconnect.
|
|
18
|
-
*/
|
|
19
|
-
export function injectView(source, options = {}) {
|
|
20
|
-
if (!options.injector)
|
|
21
|
-
assertInInjectionContext(injectView);
|
|
22
|
-
const injector = options.injector ?? inject(Injector);
|
|
23
|
-
// The controller connects in the injection context's Runic instance, also when the source changes or it retries.
|
|
24
|
-
const instance = instanceOf(injector);
|
|
25
|
-
const controller = instance.run(() => createViewController({
|
|
26
|
-
...(options.release ? { release: options.release } : {}),
|
|
27
|
-
...(options.keepAlive === undefined ? {} : { keepAlive: options.keepAlive }),
|
|
28
|
-
}));
|
|
29
|
-
const current = signal(controller.current, /* @ts-ignore */
|
|
30
|
-
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
31
|
-
controller.subscribe(() => current.set(controller.current));
|
|
32
|
-
const read = () => isSignal(source) ? source() : source;
|
|
33
|
-
const identity = computed(() => viewSourceIdentity(read()), /* @ts-ignore */
|
|
34
|
-
...(ngDevMode ? [{ debugName: "identity" }] : /* istanbul ignore next */ []));
|
|
35
|
-
const observed = computed(() => {
|
|
36
|
-
const value = read();
|
|
37
|
-
return value && isViewClient(value) ? value : undefined;
|
|
38
|
-
}, /* @ts-ignore */
|
|
39
|
-
...(ngDevMode ? [{ debugName: "observed" }] : /* istanbul ignore next */ []));
|
|
40
|
-
// A changed reference does not show the previous one until the effect follows it.
|
|
41
|
-
const fresh = computed(() => viewSourceIdentity(current().source) === identity(), /* @ts-ignore */
|
|
42
|
-
...(ngDevMode ? [{ debugName: "fresh" }] : /* istanbul ignore next */ []));
|
|
43
|
-
effect(() => {
|
|
44
|
-
identity();
|
|
45
|
-
untracked(() => {
|
|
46
|
-
controller.setSource(read());
|
|
47
|
-
current.set(controller.current);
|
|
48
|
-
});
|
|
49
|
-
}, { injector });
|
|
50
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
51
|
-
// A connected client is readable before the effect observes it, and so is a client kept for the reference
|
|
52
|
-
// (keep-alive), so a component that is created again shows its View at once.
|
|
53
|
-
const preview = computed(() => {
|
|
54
|
-
const value = observed();
|
|
55
|
-
if (value)
|
|
56
|
-
return value === current().client ? undefined : instance.run(() => viewSourcePreview(value));
|
|
57
|
-
return fresh() ? undefined : instance.run(() => viewSourcePreview(read()));
|
|
58
|
-
}, /* @ts-ignore */
|
|
59
|
-
...(ngDevMode ? [{ debugName: "preview" }] : /* istanbul ignore next */ []));
|
|
60
|
-
return {
|
|
61
|
-
state: computed(() => preview()?.state ?? (fresh() ? current().state : undefined)),
|
|
62
|
-
client: computed(() => preview()?.client ?? (fresh() ? current().client : undefined)),
|
|
63
|
-
error: computed(() => fresh() ? current().error : undefined),
|
|
64
|
-
pending: computed(() => preview() ? false : fresh() ? current().pending : identity() !== undefined),
|
|
65
|
-
retry: () => controller.retry(),
|
|
66
|
-
};
|
|
67
|
-
}
|
package/dist/esm/instance.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, type Injector, type Provider } from "@angular/core";
|
|
2
|
-
import { type RunicInstance } from "@runic-artifex/views";
|
|
3
|
-
/**
|
|
4
|
-
* The Runic instance (`createRunicInstance` in `@runic-artifex/views`) that the `inject*` helpers, `ViewOutlet` and the
|
|
5
|
-
* `runicText` pipe connect and read through. Without a provider it is the default instance: the page instance, on
|
|
6
|
-
* `globalThis.__runicBridge`, as before instances existed, or in a component bundle its element's.
|
|
7
|
-
*/
|
|
8
|
-
export declare const RUNIC_INSTANCE: InjectionToken<RunicInstance>;
|
|
9
|
-
/**
|
|
10
|
-
* Provides `instance` as the {@link RUNIC_INSTANCE} of an injector: `injectView`, `injectField`, `injectText`,
|
|
11
|
-
* `injectBridgeConnection`, `injectAppearance` and the other helpers below it use it instead of the page instance. A
|
|
12
|
-
* guest that renders inside another page, such as an embedded component, adds it to its application's or its root
|
|
13
|
-
* component's `providers`.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const instance = createRunicInstance({ bridge });
|
|
17
|
-
* bootstrapApplication(App, { providers: [provideRunicInstance(instance)] });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function provideRunicInstance(instance: RunicInstance): Provider;
|
|
21
|
-
/** Options of {@link injectRunicInstance}. */
|
|
22
|
-
export interface InjectRunicInstanceOptions {
|
|
23
|
-
/** Required outside an injection context. */
|
|
24
|
-
readonly injector?: Injector;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* The Runic instance of the injection context: the nearest {@link provideRunicInstance}, or the default instance
|
|
28
|
-
* (`defaultInstance()`: the page instance, or in a component bundle its element's).
|
|
29
|
-
*/
|
|
30
|
-
export declare function injectRunicInstance({ injector }?: InjectRunicInstanceOptions): RunicInstance;
|
|
31
|
-
/** @internal The Runic instance of `injector`. */
|
|
32
|
-
export declare function instanceOf(injector: Injector): RunicInstance;
|
|
33
|
-
/** @internal The Runic instance of the injection context, or the default instance outside one. */
|
|
34
|
-
export declare function contextInstance(): RunicInstance;
|