@runic-artifex/angular 0.19.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,26 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
|
-
import { onBridgeConnection } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
/**
|
|
5
|
-
* Follows the connection of the injection context's Runic instance to its .NET host (`connecting`, `connected`, `reconnecting`,
|
|
6
|
-
* `lost` or `closed`) as a signal through `onBridgeConnection`, for the lifetime of the injection context.
|
|
7
|
-
* Destruction unsubscribes. Under server rendering (`PLATFORM_ID` `"server"`) it does not
|
|
8
|
-
* observe and stays `connecting`.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* readonly connection = injectBridgeConnection();
|
|
12
|
-
* // @if (connection.state() === "lost") { <p role="alert">The application stopped responding.</p> }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function injectBridgeConnection({ injector: provided, ...options } = {}) {
|
|
16
|
-
if (!provided)
|
|
17
|
-
assertInInjectionContext(injectBridgeConnection);
|
|
18
|
-
const injector = provided ?? inject(Injector);
|
|
19
|
-
const state = signal("connecting", /* @ts-ignore */
|
|
20
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
21
|
-
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
22
|
-
const stop = instanceOf(injector).run(() => onBridgeConnection(next => state.set(next), options));
|
|
23
|
-
injector.get(DestroyRef).onDestroy(stop);
|
|
24
|
-
}
|
|
25
|
-
return { state: state.asReadonly() };
|
|
26
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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>;
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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>>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
|
-
import { createCommandController } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
/**
|
|
5
|
-
* Tracks a command's pending state and failure as signals for the lifetime of
|
|
6
|
-
* the injection context. The command may read signals, such as a client:
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* readonly increment = injectCommand(() => this.counter.client()?.increment());
|
|
10
|
-
* // <button [disabled]="!counter.client() || increment.pending()" (click)="increment.run()">
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export function injectCommand(command, options = {}) {
|
|
14
|
-
if (!options.injector)
|
|
15
|
-
assertInInjectionContext(injectCommand);
|
|
16
|
-
const injector = options.injector ?? inject(Injector);
|
|
17
|
-
const controller = instanceOf(injector).run(() => createCommandController(command));
|
|
18
|
-
const pending = signal(false, /* @ts-ignore */
|
|
19
|
-
...(ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []));
|
|
20
|
-
const error = signal(undefined, /* @ts-ignore */
|
|
21
|
-
...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
22
|
-
const failure = signal(undefined, /* @ts-ignore */
|
|
23
|
-
...(ngDevMode ? [{ debugName: "failure" }] : /* istanbul ignore next */ []));
|
|
24
|
-
controller.subscribe(() => {
|
|
25
|
-
pending.set(controller.current.pending);
|
|
26
|
-
error.set(controller.current.error);
|
|
27
|
-
failure.set(controller.current.failure);
|
|
28
|
-
});
|
|
29
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
30
|
-
return {
|
|
31
|
-
run: controller.run, pending: pending.asReadonly(), error: error.asReadonly(), failure: failure.asReadonly(), reset: controller.reset,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type BridgeField, type FieldBaseline, type FieldController, type FieldDefinition, type FieldOptions, type FieldState, type ViewClient } from "@runic-artifex/views";
|
|
3
|
-
/** The View a field binds to: an {@link injectView} handle, or any pair of state and client signals. */
|
|
4
|
-
export interface FieldView<TClient extends ViewClient> {
|
|
5
|
-
readonly state: Signal<TClient["snapshot"] | undefined>;
|
|
6
|
-
readonly client: Signal<TClient | undefined>;
|
|
7
|
-
}
|
|
8
|
-
export interface InjectFieldOptions<TValue = any> extends FieldOptions<TValue> {
|
|
9
|
-
/** Required outside an injection context. */
|
|
10
|
-
readonly injector?: Injector;
|
|
11
|
-
}
|
|
12
|
-
/** One View member bound to an input, as signals. See `FieldState` and `FieldController` in `@runic-artifex/views`. */
|
|
13
|
-
export interface FieldHandle<TValue> {
|
|
14
|
-
/** The draft while one exists, otherwise the member's value in the View's state. */
|
|
15
|
-
readonly value: Signal<TValue>;
|
|
16
|
-
/** What a text input shows: the text typed while it does not parse or still means `value`, otherwise `value` formatted. */
|
|
17
|
-
readonly text: Signal<string>;
|
|
18
|
-
/**
|
|
19
|
-
* True while a draft exists, from the first input until the last write settled and the state caught up, and after a
|
|
20
|
-
* failed write. Keep the input enabled while it is true, rather than disabling it on the View's busy state, which
|
|
21
|
-
* the field's own write causes.
|
|
22
|
-
*/
|
|
23
|
-
readonly editing: Signal<boolean>;
|
|
24
|
-
/** Why the latest write or text failed: a `BridgeError` of the write, or a `FieldError`. `undefined` otherwise. */
|
|
25
|
-
readonly error: Signal<unknown>;
|
|
26
|
-
/** The member's validation messages; `[]` when valid. */
|
|
27
|
-
readonly errors: Signal<readonly string[]>;
|
|
28
|
-
/** The producer's value and version while a checked write's `conflict` keeps the draft. */
|
|
29
|
-
readonly conflict: Signal<FieldBaseline<TValue> | undefined>;
|
|
30
|
-
/** The member's validation is in progress, such as an asynchronous rule that is still checking: show "checking…". */
|
|
31
|
-
readonly validating: Signal<boolean>;
|
|
32
|
-
/** The definition's `kind`, `nullable`, `integer` and `choices`. */
|
|
33
|
-
readonly field: FieldController<unknown, unknown, TValue>["field"];
|
|
34
|
-
/** The user changed the value, such as a checkbox's `checked`. */
|
|
35
|
-
input(value: TValue): void;
|
|
36
|
-
/** The user changed the text: pass the `input` event, or the text. It is parsed for the field's kind. */
|
|
37
|
-
inputText(event: Event | string): void;
|
|
38
|
-
/** An IME composition started: the text is kept but not written until it ends. Bind it to `compositionstart`. */
|
|
39
|
-
compositionStart(): void;
|
|
40
|
-
/** The IME composition ended: pass the `compositionend` event, or the text, which is then written. */
|
|
41
|
-
compositionEnd(event: Event | string): void;
|
|
42
|
-
/**
|
|
43
|
-
* The user is done with the field (bind it to `blur`): with `commit: "pause"` the draft is written now. Resolves
|
|
44
|
-
* with the field's state once its writes settled, so a command that depends on the field can follow it.
|
|
45
|
-
*/
|
|
46
|
-
commit(): Promise<FieldState<TValue>>;
|
|
47
|
-
/** Writes the draft again after a failed write; after a `conflict`, over the producer's value. */
|
|
48
|
-
retry(): void;
|
|
49
|
-
/** Drops the draft, the error and a conflict and shows the View's value. Writes in flight still complete. */
|
|
50
|
-
reset(): void;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Binds one member of a View to an input for the lifetime of the injection context, through
|
|
54
|
-
* `createFieldController`: pass a generated descriptor such as `EditorFields.title`. Typing never loses characters,
|
|
55
|
-
* nothing is written during IME composition, checked-write receipts and the member's validation show as `error`,
|
|
56
|
-
* `errors` and `conflict`, and once the last write settled the field shows the View's value.
|
|
57
|
-
*
|
|
58
|
-
* ```ts
|
|
59
|
-
* readonly editor = injectView(this.page);
|
|
60
|
-
* readonly title = injectField(this.editor, EditorFields.title);
|
|
61
|
-
* // <input [runicField]="title"> with RunicFieldDirective from @runic-artifex/angular/forms, or by hand:
|
|
62
|
-
* // <input [value]="title.text()" (input)="title.inputText($event)" (blur)="title.commit()"
|
|
63
|
-
* // (compositionstart)="title.compositionStart()" (compositionend)="title.compositionEnd($event)">
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export declare function injectField<TClient extends ViewClient, TValue>(view: FieldView<TClient>, field: BridgeField<TClient, TClient["snapshot"], TValue> | FieldDefinition<TClient, TClient["snapshot"], TValue>, { injector: provided, ...options }?: InjectFieldOptions<TValue>): FieldHandle<TValue>;
|
package/dist/esm/inject-field.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, signal, untracked } from "@angular/core";
|
|
2
|
-
import { createFieldController, } 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 one member of a View to an input for the lifetime of the injection context, through
|
|
12
|
-
* `createFieldController`: pass a generated descriptor such as `EditorFields.title`. Typing never loses characters,
|
|
13
|
-
* nothing is written during IME composition, checked-write receipts and the member's validation show as `error`,
|
|
14
|
-
* `errors` and `conflict`, and once the last write settled the field shows the View's value.
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* readonly editor = injectView(this.page);
|
|
18
|
-
* readonly title = injectField(this.editor, EditorFields.title);
|
|
19
|
-
* // <input [runicField]="title"> with RunicFieldDirective from @runic-artifex/angular/forms, or by hand:
|
|
20
|
-
* // <input [value]="title.text()" (input)="title.inputText($event)" (blur)="title.commit()"
|
|
21
|
-
* // (compositionstart)="title.compositionStart()" (compositionend)="title.compositionEnd($event)">
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function injectField(view, field, { injector: provided, ...options } = {}) {
|
|
25
|
-
if (!provided)
|
|
26
|
-
assertInInjectionContext(injectField);
|
|
27
|
-
const injector = provided ?? inject(Injector);
|
|
28
|
-
const controller = instanceOf(injector).run(() => createFieldController(field, options));
|
|
29
|
-
const current = signal(controller.current, /* @ts-ignore */
|
|
30
|
-
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
31
|
-
controller.subscribe(() => current.set(controller.current));
|
|
32
|
-
effect(() => {
|
|
33
|
-
const state = view.state();
|
|
34
|
-
const client = view.client();
|
|
35
|
-
untracked(() => {
|
|
36
|
-
controller.setSource(state === undefined || client === undefined ? undefined : { state, client });
|
|
37
|
-
current.set(controller.current);
|
|
38
|
-
});
|
|
39
|
-
}, { injector });
|
|
40
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
41
|
-
return {
|
|
42
|
-
value: computed(() => current().value),
|
|
43
|
-
text: computed(() => current().text),
|
|
44
|
-
editing: computed(() => current().editing),
|
|
45
|
-
error: computed(() => current().error),
|
|
46
|
-
errors: computed(() => current().errors),
|
|
47
|
-
conflict: computed(() => current().conflict),
|
|
48
|
-
validating: computed(() => current().validating),
|
|
49
|
-
field: controller.field,
|
|
50
|
-
input(value) { controller.input(value); },
|
|
51
|
-
inputText(event) { controller.inputText(textOf(event)); },
|
|
52
|
-
compositionStart() { controller.compositionStart(); },
|
|
53
|
-
compositionEnd(event) { controller.compositionEnd(textOf(event)); },
|
|
54
|
-
commit() { return controller.commit(); },
|
|
55
|
-
retry() { controller.retry(); },
|
|
56
|
-
reset() { controller.reset(); },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type Signal } from "@angular/core";
|
|
2
|
-
import { type FormField, type FormFields, type FormState, type FormSubmitOptions, type FormSubmitResult } from "@runic-artifex/views";
|
|
3
|
-
/** A field as {@link injectForm} reads it: an `injectField` handle. */
|
|
4
|
-
export interface FormFieldHandle extends FormField {
|
|
5
|
-
readonly editing: Signal<boolean>;
|
|
6
|
-
readonly validating: Signal<boolean>;
|
|
7
|
-
readonly errors: Signal<readonly string[]>;
|
|
8
|
-
readonly error: Signal<unknown>;
|
|
9
|
-
}
|
|
10
|
-
export interface InjectFormOptions {
|
|
11
|
-
/** Whether the View reports unsaved changes, such as `computed(() => this.editor.state()?.isDirty === true)`. */
|
|
12
|
-
readonly dirty?: Signal<boolean | undefined>;
|
|
13
|
-
}
|
|
14
|
-
/** A form bound by {@link injectForm}: its state as signals, and its actions. */
|
|
15
|
-
export interface FormHandle {
|
|
16
|
-
/** The whole state. */
|
|
17
|
-
readonly state: Signal<FormState>;
|
|
18
|
-
readonly dirty: Signal<boolean>;
|
|
19
|
-
readonly editing: Signal<boolean>;
|
|
20
|
-
readonly validating: Signal<boolean>;
|
|
21
|
-
readonly pending: Signal<boolean>;
|
|
22
|
-
readonly valid: Signal<boolean>;
|
|
23
|
-
readonly submitting: Signal<boolean>;
|
|
24
|
-
/** Commits every field, waits for their writes and runs `command` unless a field's write or text failed. */
|
|
25
|
-
submit<T>(command: () => T | PromiseLike<T>, options?: FormSubmitOptions): Promise<FormSubmitResult<T>>;
|
|
26
|
-
/** Commits every field and resolves once their writes settled. */
|
|
27
|
-
commit(): Promise<FormState>;
|
|
28
|
-
/** Resets every field. */
|
|
29
|
-
reset(): void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* One dirty, pending and valid state over `injectField` handles, and a `submit` that writes every field before its
|
|
33
|
-
* command (`createFormController` in `@runic-artifex/views`). It needs no injection context.
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* readonly form = injectForm({ title: this.title, body: this.body }, { dirty: computed(() => this.editor.state()?.isDirty === true) });
|
|
37
|
-
* // <button [disabled]="!form.valid() || form.submitting()" (click)="form.submit(() => editor.client()!.save())">Save</button>
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export declare function injectForm(fields: FormFields<FormFieldHandle>, options?: InjectFormOptions): FormHandle;
|
package/dist/esm/inject-form.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { computed, signal } from "@angular/core";
|
|
2
|
-
import { formFieldList, formStateOf, submitFields, } from "@runic-artifex/views";
|
|
3
|
-
/**
|
|
4
|
-
* One dirty, pending and valid state over `injectField` handles, and a `submit` that writes every field before its
|
|
5
|
-
* command (`createFormController` in `@runic-artifex/views`). It needs no injection context.
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* readonly form = injectForm({ title: this.title, body: this.body }, { dirty: computed(() => this.editor.state()?.isDirty === true) });
|
|
9
|
-
* // <button [disabled]="!form.valid() || form.submitting()" (click)="form.submit(() => editor.client()!.save())">Save</button>
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export function injectForm(fields, options = {}) {
|
|
13
|
-
const list = formFieldList(fields);
|
|
14
|
-
const submitting = signal(false, /* @ts-ignore */
|
|
15
|
-
...(ngDevMode ? [{ debugName: "submitting" }] : /* istanbul ignore next */ []));
|
|
16
|
-
const state = computed(() => formStateOf(list.map(field => ({ editing: field.editing(), validating: field.validating(), errors: field.errors(), error: field.error() })), options.dirty?.() === true, submitting()), /* @ts-ignore */
|
|
17
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
18
|
-
return {
|
|
19
|
-
state,
|
|
20
|
-
dirty: computed(() => state().dirty),
|
|
21
|
-
editing: computed(() => state().editing),
|
|
22
|
-
validating: computed(() => state().validating),
|
|
23
|
-
pending: computed(() => state().pending),
|
|
24
|
-
valid: computed(() => state().valid),
|
|
25
|
-
submitting: computed(() => state().submitting),
|
|
26
|
-
async submit(command, submitOptions = {}) {
|
|
27
|
-
if (submitting())
|
|
28
|
-
return { status: "busy" };
|
|
29
|
-
submitting.set(true);
|
|
30
|
-
const read = (index) => {
|
|
31
|
-
const field = list[index];
|
|
32
|
-
return { editing: field.editing(), error: field.error(), validating: field.validating() };
|
|
33
|
-
};
|
|
34
|
-
try {
|
|
35
|
-
return await submitFields(list, command, submitOptions, read);
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
submitting.set(false);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
async commit() {
|
|
42
|
-
await Promise.all(list.map(field => field.commit()));
|
|
43
|
-
return state();
|
|
44
|
-
},
|
|
45
|
-
reset() { for (const field of list)
|
|
46
|
-
field.reset(); },
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type LatestOperationController, type LatestOperationState } from "@runic-artifex/views";
|
|
3
|
-
/** Each field of the latest-operation feedback as a signal, with `run` and `clear`. */
|
|
4
|
-
export type LatestOperationHandle<TResult, TFailure = never> = {
|
|
5
|
-
readonly [K in keyof LatestOperationState<TResult, TFailure>]: Signal<LatestOperationState<TResult, TFailure>[K]>;
|
|
6
|
-
} & Pick<LatestOperationController<TResult, TFailure>, "run" | "clear">;
|
|
7
|
-
export interface InjectLatestOperationOptions {
|
|
8
|
-
/** Required outside an injection context. */
|
|
9
|
-
readonly injector?: Injector;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Admits only the newest selection, for reads such as "load the selected item", as signals
|
|
13
|
-
* for the lifetime of the injection context. Each `run(intent)` replaces the queued intent
|
|
14
|
-
* and cancels the active read, and the next read starts only after the previous one has
|
|
15
|
-
* finished (including `waitForCompletion`). `blocked` means admission is uncertain; only
|
|
16
|
-
* `clear("replace")`, after the application has established a fresh session, clears it.
|
|
17
|
-
* Destruction settles run promises without cancelling accepted work.
|
|
18
|
-
*
|
|
19
|
-
* ```ts
|
|
20
|
-
* readonly load = injectLatestOperation<Item>();
|
|
21
|
-
* select(id: string) { void this.load.run({ start: () => this.items.client()?.startLoad(id) }); }
|
|
22
|
-
* // @if (load.outcome()?.ok) { <item-view [item]="load.outcome()!.value" /> }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare function injectLatestOperation<TResult = void, TFailure = never>({ injector: provided }?: InjectLatestOperationOptions): LatestOperationHandle<TResult, TFailure>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
|
-
import { createLatestOperationController, } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
/**
|
|
5
|
-
* Admits only the newest selection, for reads such as "load the selected item", as signals
|
|
6
|
-
* for the lifetime of the injection context. Each `run(intent)` replaces the queued intent
|
|
7
|
-
* and cancels the active read, and the next read starts only after the previous one has
|
|
8
|
-
* finished (including `waitForCompletion`). `blocked` means admission is uncertain; only
|
|
9
|
-
* `clear("replace")`, after the application has established a fresh session, clears it.
|
|
10
|
-
* Destruction settles run promises without cancelling accepted work.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* readonly load = injectLatestOperation<Item>();
|
|
14
|
-
* select(id: string) { void this.load.run({ start: () => this.items.client()?.startLoad(id) }); }
|
|
15
|
-
* // @if (load.outcome()?.ok) { <item-view [item]="load.outcome()!.value" /> }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export function injectLatestOperation({ injector: provided } = {}) {
|
|
19
|
-
if (!provided)
|
|
20
|
-
assertInInjectionContext(injectLatestOperation);
|
|
21
|
-
const injector = provided ?? inject(Injector);
|
|
22
|
-
const controller = instanceOf(injector).run(() => createLatestOperationController());
|
|
23
|
-
const state = signal(controller.current, /* @ts-ignore */
|
|
24
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
25
|
-
controller.subscribe(() => state.set(controller.current));
|
|
26
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
27
|
-
const field = (key) => computed(() => state()[key]);
|
|
28
|
-
return {
|
|
29
|
-
run: controller.run, clear: controller.clear,
|
|
30
|
-
pending: field("pending"), admitting: field("admitting"), operation: field("operation"), status: field("status"),
|
|
31
|
-
outcome: field("outcome"), failure: field("failure"), error: field("error"), cancelled: field("cancelled"),
|
|
32
|
-
cancellationRequested: field("cancellationRequested"), cancelling: field("cancelling"),
|
|
33
|
-
progress: field("progress"), cancellation: field("cancellation"), cancelError: field("cancelError"), blocked: field("blocked"),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type MenuBarController, type MenuBarControllerOptions, type MenuBarRequest, type MenuBarState } from "@runic-artifex/views";
|
|
3
|
-
export type { MenuBarEntry, MenuBarInvokeResult, MenuBarItem, MenuBarMenu, MenuBarRequest, MenuBarSeparator, MenuBarState, } from "@runic-artifex/views";
|
|
4
|
-
export interface MenuBarHandle {
|
|
5
|
-
/** The menu bar as the page renders it; render a bar only when `placement` is `"page"`. */
|
|
6
|
-
readonly state: Signal<MenuBarState>;
|
|
7
|
-
/** Runs an item through the native bar's command path. Rejects with a BridgeError under server rendering. */
|
|
8
|
-
readonly invoke: MenuBarController["invoke"];
|
|
9
|
-
/** Matches a `keydown` event against the items' shortcuts, for the `shortcuts: "app"` option. */
|
|
10
|
-
readonly handleKeyDown: MenuBarController["handleKeyDown"];
|
|
11
|
-
}
|
|
12
|
-
export interface InjectMenuBarOptions extends Omit<MenuBarControllerOptions, "signal"> {
|
|
13
|
-
/**
|
|
14
|
-
* Receives the `focus` (Alt tap, F10) and `open` (Alt plus a menu's access key) requests: focus the first
|
|
15
|
-
* `cdkMenuItem` of the bar or open a menu's `CdkMenuTrigger`.
|
|
16
|
-
*/
|
|
17
|
-
readonly onRequest?: (request: MenuBarRequest) => void;
|
|
18
|
-
/** Required outside an injection context. */
|
|
19
|
-
readonly injector?: Injector;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Follows the window's declared menu bar (Runic Desktop's `DesktopMenuBarPresentation.Page`) as a signal, as headless
|
|
23
|
-
* state for the application's own menubar (for example the CDK Menu's `cdkMenuBar`), through
|
|
24
|
-
* `createMenuBarController`, for the lifetime of the injection context. Destruction disposes the controller. Under
|
|
25
|
-
* server rendering (`PLATFORM_ID` `"server"`) it creates none and stays `connecting`.
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* readonly menuBar = injectMenuBar({ onRequest: request => this.onMenuRequest(request) });
|
|
29
|
-
* // @if (menuBar.state().placement === "page") { <div cdkMenuBar>…<button cdkMenuItem (cdkMenuItemTriggered)="menuBar.invoke(item)"> }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function injectMenuBar({ injector: provided, onRequest, ...options }?: InjectMenuBarOptions): MenuBarHandle;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
|
-
import { BridgeError, createMenuBarController, } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
/**
|
|
5
|
-
* Follows the window's declared menu bar (Runic Desktop's `DesktopMenuBarPresentation.Page`) as a signal, as headless
|
|
6
|
-
* state for the application's own menubar (for example the CDK Menu's `cdkMenuBar`), through
|
|
7
|
-
* `createMenuBarController`, for the lifetime of the injection context. Destruction disposes the controller. Under
|
|
8
|
-
* server rendering (`PLATFORM_ID` `"server"`) it creates none and stays `connecting`.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* readonly menuBar = injectMenuBar({ onRequest: request => this.onMenuRequest(request) });
|
|
12
|
-
* // @if (menuBar.state().placement === "page") { <div cdkMenuBar>…<button cdkMenuItem (cdkMenuItemTriggered)="menuBar.invoke(item)"> }
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function injectMenuBar({ injector: provided, onRequest, ...options } = {}) {
|
|
16
|
-
if (!provided)
|
|
17
|
-
assertInInjectionContext(injectMenuBar);
|
|
18
|
-
const injector = provided ?? inject(Injector);
|
|
19
|
-
if (injector.get(PLATFORM_ID, null) === "server") {
|
|
20
|
-
const state = signal(Object.freeze({
|
|
21
|
-
status: "connecting", placement: "none", shortcuts: options.shortcuts === "app" ? "app" : "host",
|
|
22
|
-
accessKeyHints: false, revision: 0, menus: Object.freeze([]),
|
|
23
|
-
}), /* @ts-ignore */
|
|
24
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
25
|
-
return {
|
|
26
|
-
state: state.asReadonly(),
|
|
27
|
-
invoke: () => Promise.reject(new BridgeError("unavailable", "The menu bar is not followed during server rendering.", { route: "runic.menu-bar" })),
|
|
28
|
-
handleKeyDown: () => false,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const controller = instanceOf(injector).run(() => createMenuBarController(options));
|
|
32
|
-
const state = signal(controller.current, /* @ts-ignore */
|
|
33
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
34
|
-
controller.subscribe(() => state.set(controller.current));
|
|
35
|
-
if (onRequest)
|
|
36
|
-
controller.onRequest(onRequest);
|
|
37
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
38
|
-
return { state: state.asReadonly(), invoke: controller.invoke, handleKeyDown: controller.handleKeyDown };
|
|
39
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type BridgeOperation, type OperationController, type OperationControllerOptions, type OperationState } from "@runic-artifex/views";
|
|
3
|
-
/** Each field of the operation's feedback as a signal, with `run`, `cancel` and `reset`. */
|
|
4
|
-
export type OperationHandle<TArgs extends readonly unknown[], TResult, TFailure = never> = {
|
|
5
|
-
readonly [K in keyof OperationState<TResult, TFailure>]: Signal<OperationState<TResult, TFailure>[K]>;
|
|
6
|
-
} & Pick<OperationController<TArgs, TResult, TFailure>, "run" | "cancel" | "reset">;
|
|
7
|
-
export interface InjectOperationOptions<TResult, TFailure = never> extends OperationControllerOptions<TResult, TFailure> {
|
|
8
|
-
/** Required outside an injection context. */
|
|
9
|
-
readonly injector?: Injector;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Tracks Start admission, pending work, cancellation and terminal feedback of a
|
|
13
|
-
* generated `start<Command>()` operation as signals for the lifetime of the
|
|
14
|
-
* injection context. A run that ends `cancelled` sets `cancelled`, not `error`.
|
|
15
|
-
* Destruction settles run promises without cancelling accepted work.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* readonly push = injectOperation((remote: string) => this.workspace.client()?.startPush(remote));
|
|
19
|
-
* // <button [disabled]="push.pending()" (click)="push.run('origin')">Push</button>
|
|
20
|
-
* // @if (push.cancelled()) { <p role="status">Push cancelled.</p> }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function injectOperation<TArgs extends readonly unknown[], TResult, TFailure = never>(start: (...args: TArgs) => BridgeOperation<TResult, TFailure> | undefined | PromiseLike<BridgeOperation<TResult, TFailure> | undefined>, { injector: provided, ...options }?: InjectOperationOptions<TResult, TFailure>): OperationHandle<TArgs, TResult, TFailure>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, computed, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
|
-
import { createOperationController, } from "@runic-artifex/views";
|
|
3
|
-
import { instanceOf } from "./instance.js";
|
|
4
|
-
/**
|
|
5
|
-
* Tracks Start admission, pending work, cancellation and terminal feedback of a
|
|
6
|
-
* generated `start<Command>()` operation as signals for the lifetime of the
|
|
7
|
-
* injection context. A run that ends `cancelled` sets `cancelled`, not `error`.
|
|
8
|
-
* Destruction settles run promises without cancelling accepted work.
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* readonly push = injectOperation((remote: string) => this.workspace.client()?.startPush(remote));
|
|
12
|
-
* // <button [disabled]="push.pending()" (click)="push.run('origin')">Push</button>
|
|
13
|
-
* // @if (push.cancelled()) { <p role="status">Push cancelled.</p> }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
export function injectOperation(start, { injector: provided, ...options } = {}) {
|
|
17
|
-
if (!provided)
|
|
18
|
-
assertInInjectionContext(injectOperation);
|
|
19
|
-
const injector = provided ?? inject(Injector);
|
|
20
|
-
const controller = instanceOf(injector).run(() => createOperationController(start, options));
|
|
21
|
-
const state = signal(controller.current, /* @ts-ignore */
|
|
22
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
23
|
-
controller.subscribe(() => state.set(controller.current));
|
|
24
|
-
injector.get(DestroyRef).onDestroy(() => controller.dispose());
|
|
25
|
-
const field = (key) => computed(() => state()[key]);
|
|
26
|
-
return {
|
|
27
|
-
run: controller.run, cancel: controller.cancel, reset: controller.reset,
|
|
28
|
-
pending: field("pending"), admitting: field("admitting"), operation: field("operation"), status: field("status"),
|
|
29
|
-
outcome: field("outcome"), failure: field("failure"), error: field("error"), cancelled: field("cancelled"),
|
|
30
|
-
cancellationRequested: field("cancellationRequested"), cancelling: field("cancelling"),
|
|
31
|
-
progress: field("progress"), cancellation: field("cancellation"), cancelError: field("cancelError"),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ElementRef, Injector, type Signal } from "@angular/core";
|
|
2
|
-
import { type QueryCollection, type QueryViewport, type QueryViewportOptions, type RunicQuery } from "@runic-artifex/views";
|
|
3
|
-
export interface InjectQueryCollectionOptions {
|
|
4
|
-
/** Required outside an injection context. */
|
|
5
|
-
readonly injector?: Injector;
|
|
6
|
-
}
|
|
7
|
-
export interface QueryCollectionHandle<TRow> {
|
|
8
|
-
/** The rows to render with their offsets, the spacer's `totalSize`, the total, query, loading and error state. */
|
|
9
|
-
readonly viewport: Signal<QueryViewport<TRow>>;
|
|
10
|
-
/**
|
|
11
|
-
* Measures a rendered row's height until the returned function is called, for example from an `effect` over
|
|
12
|
-
* `viewChildren` of the rows.
|
|
13
|
-
*/
|
|
14
|
-
observe(element: Element | ElementRef<Element>, index: number): () => void;
|
|
15
|
-
/** Scrolls to the row with `key` in the current query; resolves `false` when no row has it. */
|
|
16
|
-
scrollToKey(key: string, align?: "start" | "center" | "end"): Promise<boolean>;
|
|
17
|
-
scrollToIndex(index: number, align?: "start" | "center" | "end"): void;
|
|
18
|
-
/** Changes the collection's sort and filter (ViewModel state every presentation shares). */
|
|
19
|
-
setQuery(query: RunicQuery): Promise<void>;
|
|
20
|
-
/** Loads the range again after a failure. */
|
|
21
|
-
retry(): void;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Follows a scroll container for a query collection (`client.queries.{name}`): it loads the rows the container shows
|
|
25
|
-
* from .NET, with placeholders until they arrive, and lays them out with variable heights. Pass the container, for
|
|
26
|
-
* example `viewChild<ElementRef<HTMLElement>>("scroller")`, the collection as a function such as
|
|
27
|
-
* `() => view.client()?.queries.rows`, and the options.
|
|
28
|
-
*/
|
|
29
|
-
export declare function injectQueryCollection<TRow>(element: Signal<ElementRef<HTMLElement> | HTMLElement | null | undefined>, collection: () => QueryCollection<TRow> | undefined, options: () => QueryViewportOptions, { injector: provided }?: InjectQueryCollectionOptions): QueryCollectionHandle<TRow>;
|