@runic-artifex/angular 0.17.1 → 0.18.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 +38 -22
- package/dist/esm/experimental.d.ts +39 -0
- package/dist/esm/experimental.js +64 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/inject-appearance.d.ts +1 -1
- package/dist/esm/inject-appearance.js +6 -4
- package/dist/esm/inject-bridge-connection.d.ts +1 -1
- package/dist/esm/inject-bridge-connection.js +3 -2
- package/dist/esm/inject-command.js +2 -1
- package/dist/esm/inject-field.js +2 -1
- package/dist/esm/inject-latest-operation.js +2 -1
- package/dist/esm/inject-menu-bar.js +2 -1
- package/dist/esm/inject-operation.js +2 -1
- package/dist/esm/inject-text-field.js +2 -1
- package/dist/esm/inject-text.d.ts +8 -6
- package/dist/esm/inject-text.js +27 -18
- package/dist/esm/inject-view-resource.js +4 -1
- package/dist/esm/inject-view.js +7 -4
- package/dist/esm/instance.d.ts +34 -0
- package/dist/esm/instance.js +48 -0
- package/dist/esm/view-outlet.js +3 -1
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -140,7 +140,7 @@ export class CounterPage {
|
|
|
140
140
|
|
|
141
141
|
Bind a text input to a member with `injectTextField(view, read, write, options?)`,
|
|
142
142
|
which wraps the framework-neutral
|
|
143
|
-
[text field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
143
|
+
[text field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#text-inputs)
|
|
144
144
|
for the lifetime of the injection context:
|
|
145
145
|
|
|
146
146
|
```ts
|
|
@@ -183,7 +183,7 @@ text at once and hides the race.
|
|
|
183
183
|
|
|
184
184
|
For generated Views prefer `injectField(view, field, options?)`: pass a descriptor of the
|
|
185
185
|
generated `{View}Fields`, such as `EditorFields.title`. It wraps the framework-neutral
|
|
186
|
-
[field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
186
|
+
[field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#fields)
|
|
187
187
|
for every kind (text, numbers, booleans, enums) and returns signals and actions:
|
|
188
188
|
|
|
189
189
|
- `value`, `text` (what a text input shows: `1.` stays while typing `1.5`), `editing`,
|
|
@@ -232,7 +232,7 @@ A checked write's receipt is read: `rejected` keeps the draft with a `FieldError
|
|
|
232
232
|
`reset()` (take the producer's value); `committed-with-error` keeps the committed value
|
|
233
233
|
with a `FieldError`. A text that does not parse is a `FieldError` `invalid-text` with a `reason` and `arguments`:
|
|
234
234
|
`{{ title.error() | runicText }}` shows your text for it after `configureFieldErrorText`, in the window's language
|
|
235
|
-
([Translating field errors](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
235
|
+
([Translating field errors](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#translating-field-errors)).
|
|
236
236
|
`errors` follows the member's validation in the View's state:
|
|
237
237
|
|
|
238
238
|
```html
|
|
@@ -249,7 +249,7 @@ Since 0.16, `InvoiceFields.address.street` and `InvoiceFields.lines.at(line.id).
|
|
|
249
249
|
`injectField(view, InvoiceFields.lines.at(line.id).quantity)` in the row's component, or bind it with
|
|
250
250
|
`[runicField]`; `at(key)` returns the same descriptor for the same key. Such a field always writes checked, conflicts
|
|
251
251
|
only when another writer changed the same cell, and shows the messages .NET reports at the cell's validation path. See
|
|
252
|
-
[Fields below a member and row cells](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
252
|
+
[Fields below a member and row cells](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/web/angular/../views/README.md#fields-below-a-member-and-row-cells).
|
|
253
253
|
|
|
254
254
|
### Forms: `injectForm(fields, options?)`
|
|
255
255
|
|
|
@@ -380,7 +380,7 @@ reference; `injectView(this.page)` owns its connection and cleanup. Declare
|
|
|
380
380
|
decorator `@Input() page` or an optional `input<DocumentReference>()` does not
|
|
381
381
|
satisfy `ViewRegistry`. A component whose `page` input is a shared page
|
|
382
382
|
reference, `input.required<ResultPagePageReference>()` for a .NET
|
|
383
|
-
[`[RunicSharedClient]`](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
383
|
+
[`[RunicSharedClient]`](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/web/angular/../../dotnet/Runic.Application.Views/README.md#shared-clients)
|
|
384
384
|
interface, registers for each of its kinds without a cast:
|
|
385
385
|
`{ ...registryEntries(resultPageKinds, ResultPage), settings: Settings }`. Missing kinds render an English `<p role="alert">` in a
|
|
386
386
|
development build (`isDevMode()`); a production build renders nothing and
|
|
@@ -493,14 +493,14 @@ For example, a navigation command whose departure guard awaits a dialog's
|
|
|
493
493
|
answer never completes while the answer waits behind it. Order such commands
|
|
494
494
|
by dispatch instead: start the next one once the previous one has been sent,
|
|
495
495
|
as the Notes example's
|
|
496
|
-
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
496
|
+
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/examples/notes-view-first/Angular/src/app/window-operations.ts)
|
|
497
497
|
does for its navigation commands.
|
|
498
498
|
|
|
499
499
|
## Operations
|
|
500
500
|
|
|
501
501
|
`injectOperation(start, options?)` observes a generated `start<Command>()` operation
|
|
502
502
|
through the framework-neutral
|
|
503
|
-
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
503
|
+
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#operation-feedback-and-latest-selection)
|
|
504
504
|
for the lifetime of the injection context:
|
|
505
505
|
|
|
506
506
|
```ts
|
|
@@ -526,7 +526,7 @@ context.
|
|
|
526
526
|
|
|
527
527
|
`injectLatestOperation(options?)` admits only the newest of several reads, for example
|
|
528
528
|
loading the item the user selected last, through the framework-neutral
|
|
529
|
-
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
529
|
+
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#operation-feedback-and-latest-selection).
|
|
530
530
|
Each `run(intent)` replaces the queued intent and cancels the active read; the next
|
|
531
531
|
read starts only after the previous one reaches its terminal status and the intent's
|
|
532
532
|
optional `waitForCompletion` barrier:
|
|
@@ -558,7 +558,7 @@ from `@runic-artifex/views` (re-exported here since 0.11, with the
|
|
|
558
558
|
`BridgeConnectionState` and `BridgeConnectionOptions` types) and returns `{ state }`, a signal of a
|
|
559
559
|
`BridgeConnectionState`: `connecting`, `connected`, `reconnecting`, `lost` or `closed` (the
|
|
560
560
|
application closed the window, since 0.15; a closed set, see
|
|
561
|
-
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
561
|
+
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#connection-state)):
|
|
562
562
|
|
|
563
563
|
```ts
|
|
564
564
|
import { injectBridgeConnection } from "@runic-artifex/angular";
|
|
@@ -576,7 +576,7 @@ not observe and stays `connecting`. An invalid `lostAfter` throws a `RangeError`
|
|
|
576
576
|
`injectMenuBar(options?)` follows the declared menu bar of a Runic Desktop
|
|
577
577
|
window that leaves it to the page (`DesktopMenuBarPresentation.Page`) for the
|
|
578
578
|
lifetime of the injection context. It wraps `createMenuBarController` from
|
|
579
|
-
`@runic-artifex/views` (see [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
579
|
+
`@runic-artifex/views` (see [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#in-page-menu-bar))
|
|
580
580
|
and returns `{ state, invoke, handleKeyDown }`, where `state` is a signal of a
|
|
581
581
|
`MenuBarState`. The bar is rendered by the application's own menubar, for
|
|
582
582
|
example the CDK Menu's `cdkMenuBar`. Runic ships no menubar component.
|
|
@@ -601,7 +601,7 @@ it creates none and stays `connecting`.
|
|
|
601
601
|
### With the CDK Menu
|
|
602
602
|
|
|
603
603
|
The CDK's `cdkMenuBar` with `CdkMenuTrigger.open()` for `open` requests; the
|
|
604
|
-
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
604
|
+
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/examples/notes-view-first#in-page-menu-bar) adds submenus, check and radio
|
|
605
605
|
items (`cdkMenuItemCheckbox`, `cdkMenuItemRadio` in a `cdkMenuGroup`) and is
|
|
606
606
|
tested with real keys:
|
|
607
607
|
|
|
@@ -655,7 +655,7 @@ export class AppMenuBar {
|
|
|
655
655
|
`injectText(() => source, () => fallback?)` is a signal of a text reference in
|
|
656
656
|
the window's language, and the `runicText` pipe does the same in templates; both
|
|
657
657
|
follow a language switch. Connect the page's Translations runtime once with
|
|
658
|
-
`configureTranslatedText` ([Translated text](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
658
|
+
`configureTranslatedText` ([Translated text](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/dotnet/Runic.Application.Views/README.md#translated-text)).
|
|
659
659
|
`injectWindowLocale()` reads the window's locale. `textLocaleSignal()` is the
|
|
660
660
|
locale that text is shown in, as one signal for the page that needs no injection
|
|
661
661
|
context; when the locale resolver reads it, templates that call `m.*()`, also
|
|
@@ -688,7 +688,7 @@ with `resolveTextReference` and the request's locale.
|
|
|
688
688
|
injection context: the colour scheme, contrast and reduced motion of the page's
|
|
689
689
|
engine, combined with the desktop's text scale, accent colour, forced-colours
|
|
690
690
|
palette, contrast and motion that a Runic host pushes
|
|
691
|
-
([Appearance](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
691
|
+
([Appearance](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/web/views/README.md#appearance)). On the server every member is `null`.
|
|
692
692
|
|
|
693
693
|
```ts
|
|
694
694
|
readonly appearance = injectAppearance();
|
|
@@ -700,7 +700,7 @@ readonly fontSize = computed(() => `${this.appearance().textScale ?? 1}rem`);
|
|
|
700
700
|
The `error()` signal of `injectView` and of a command or operation is typed
|
|
701
701
|
`unknown`: it holds whatever the connection or the call rejected with. A Bridge
|
|
702
702
|
failure is a `BridgeError` from `@runic-artifex/views`. Show it with
|
|
703
|
-
`describeBridgeError(error)`, one
|
|
703
|
+
`describeBridgeError(error)`, one sentence (in the window's language with `configureRunicViewsText()`), instead of interpolating
|
|
704
704
|
the error, and narrow it with `isBridgeError` (or `instanceof`) before reading
|
|
705
705
|
`kind`, `route` or `detail`:
|
|
706
706
|
|
|
@@ -712,7 +712,7 @@ readonly message = computed(() => describeBridgeError(this.view.error()));
|
|
|
712
712
|
```
|
|
713
713
|
|
|
714
714
|
`instanceof` holds for errors from every copy of the package on the page.
|
|
715
|
-
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
715
|
+
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#errors-and-diagnostics)
|
|
716
716
|
lists the kinds. Any other value, such as an exception that your own connect
|
|
717
717
|
function or command callback throws, arrives unchanged.
|
|
718
718
|
|
|
@@ -763,10 +763,10 @@ application's own dialog.
|
|
|
763
763
|
departure before that is answered by the ViewModel's .NET fallback handler, or
|
|
764
764
|
fails closed without one.
|
|
765
765
|
|
|
766
|
-
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
766
|
+
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
|
|
767
767
|
has the .NET side and which View answers which departure. In a frontend test,
|
|
768
768
|
the generated mock's `interactions.<name>.request(input)` resolves with the
|
|
769
|
-
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
769
|
+
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#testing).
|
|
770
770
|
|
|
771
771
|
## View requests
|
|
772
772
|
|
|
@@ -804,15 +804,15 @@ the page painted the state the request was raised with, so the field of that
|
|
|
804
804
|
state is rendered; `signal` aborts when the handler is replaced or removed, the
|
|
805
805
|
client is disposed or the connection is lost. A request is never replayed: one
|
|
806
806
|
raised before the effect ran, or while the page is disconnected, is not
|
|
807
|
-
delivered later. See [View requests](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
807
|
+
delivered later. See [View requests](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#view-requests) for the rules, and in a frontend
|
|
808
808
|
test raise one with the generated mock's `requests.<name>.raise(input)` (the
|
|
809
|
-
[Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
809
|
+
[Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#testing)).
|
|
810
810
|
|
|
811
811
|
## Collection viewports
|
|
812
812
|
|
|
813
813
|
`injectCollectionViewport(element, options)` follows a fixed-row-height scroll
|
|
814
814
|
container and returns a signal with its
|
|
815
|
-
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
815
|
+
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#collectionviewportoptions)
|
|
816
816
|
range. Pass the container as a signal, such as a `viewChild`, and the options as
|
|
817
817
|
a function or signal, then send the range to the ViewModel from an effect:
|
|
818
818
|
|
|
@@ -844,7 +844,7 @@ export class RowsPage {
|
|
|
844
844
|
## Query collections
|
|
845
845
|
|
|
846
846
|
`injectQueryCollection(element, collection, options)` follows a scroll container for a
|
|
847
|
-
[query collection](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
847
|
+
[query collection](https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/views#query-collections) (`client.queries.{name}`), whose rows stay in .NET: it loads the rows the container shows,
|
|
848
848
|
with placeholders until they arrive, and lays them out with variable heights. `viewport` is a signal of the
|
|
849
849
|
`QueryViewport` (`items` with `top` and `size`, `totalSize`, `total`, `query`, `loading`, `error`); `observe(element,
|
|
850
850
|
index)` measures a rendered row, and `scrollToKey`, `scrollToIndex`, `setQuery` and `retry` act on the collection.
|
|
@@ -861,4 +861,20 @@ The package re-exports `installBackNavigation`, `installNavigationPath`,
|
|
|
861
861
|
`@runic-artifex/views` (since 0.16). Call the installs once where the page
|
|
862
862
|
starts, before or after mounting: the mouse's Back button and Alt+Left then go
|
|
863
863
|
back in the .NET window, and `#/customers/42` follows its path region. See
|
|
864
|
-
[Back and the URL](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
864
|
+
[Back and the URL](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/web/views/README.md#back-and-the-url).
|
|
865
|
+
|
|
866
|
+
## Hosted regions (experimental)
|
|
867
|
+
|
|
868
|
+
`RunicHostedRegion` from `@runic-artifex/angular/experimental` is the component whose
|
|
869
|
+
element is `<runic-hosted-region>` itself, a region where the host application shows
|
|
870
|
+
a hosted guest's Window ([hosted regions](https://github.com/Runic-Artifex/runic-sdk/blob/v0.18.0/packages/web/angular/../views/README.md#hosted-regions-experimental)). Projected content shows while no
|
|
871
|
+
guest page shows in it, and `state()` tells which state the region is in:
|
|
872
|
+
|
|
873
|
+
```html
|
|
874
|
+
<runic-hosted-region #check="runicHostedRegion" name="check" style="height: 420px" (stateChange)="onState($event)">
|
|
875
|
+
@if (check.state() === "ended") { <button (click)="runAgain()">Run the check again</button> }
|
|
876
|
+
@else { <p>Starting the check…</p> }
|
|
877
|
+
</runic-hosted-region>
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
Add `RunicHostedRegion` to the component's `imports`.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type HostedRegionSizing, type HostedRegionState } from "@runic-artifex/views/experimental";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export type { HostedRegionSizing, HostedRegionState, RunicHostedRegionElement } from "@runic-artifex/views/experimental";
|
|
4
|
+
/** The `stateChange` output of {@link RunicHostedRegion}. */
|
|
5
|
+
export interface HostedRegionStateChange {
|
|
6
|
+
readonly state: HostedRegionState;
|
|
7
|
+
readonly previous: HostedRegionState;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A region where the host application shows a hosted guest's Window: the component's element is
|
|
11
|
+
* `<runic-hosted-region>` itself, and the page never gets a reference to its frame. Projected content shows while no
|
|
12
|
+
* guest page shows in the region; `state()` tells which state it is in:
|
|
13
|
+
*
|
|
14
|
+
* ```html
|
|
15
|
+
* <runic-hosted-region #check name="check" style="height: 420px" (stateChange)="onState($event)">
|
|
16
|
+
* @if (check.state() === "ended") { <button (click)="runAgain()">Run the check again</button> }
|
|
17
|
+
* @else { <p>Starting the check…</p> }
|
|
18
|
+
* </runic-hosted-region>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class RunicHostedRegion {
|
|
22
|
+
#private;
|
|
23
|
+
/** The region's name, which the host application's policy embeds a guest's Window in. */
|
|
24
|
+
readonly name: import("@angular/core").InputSignal<string>;
|
|
25
|
+
/** `fill` (the default): the page's layout sets the height. `content-height`: the guest's page does. */
|
|
26
|
+
readonly sizing: import("@angular/core").InputSignal<HostedRegionSizing | undefined>;
|
|
27
|
+
/** The region's accessible name; without it, the guest page's title. */
|
|
28
|
+
readonly label: import("@angular/core").InputSignal<string | undefined>;
|
|
29
|
+
readonly stateChange: import("@angular/core").OutputEmitterRef<HostedRegionStateChange>;
|
|
30
|
+
/** The guest page's title as the host passed it on, or `null`. */
|
|
31
|
+
readonly titleChange: import("@angular/core").OutputEmitterRef<string | null>;
|
|
32
|
+
/** What the region shows now. */
|
|
33
|
+
readonly state: import("@angular/core").Signal<HostedRegionState>;
|
|
34
|
+
constructor();
|
|
35
|
+
protected stateChanged(event: Event): void;
|
|
36
|
+
protected titleChanged(event: Event): void;
|
|
37
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RunicHostedRegion, never>;
|
|
38
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RunicHostedRegion, "runic-hosted-region", ["runicHostedRegion"], { "name": { "alias": "name"; "required": true; "isSignal": true; }; "sizing": { "alias": "sizing"; "required": false; "isSignal": true; }; "label": { "alias": "label"; "required": false; "isSignal": true; }; }, { "stateChange": "stateChange"; "titleChange": "titleChange"; }, never, ["*"], true, never>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The experimental entry (docs/experimental.md, "npm packages"): importing it is the opt-in. Hosted regions (0.18): the
|
|
2
|
+
// .NET side is the experimental family RUNICDESK103.
|
|
3
|
+
import { Component, input, output, signal } from "@angular/core";
|
|
4
|
+
import { defineHostedRegion, } from "@runic-artifex/views/experimental";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* A region where the host application shows a hosted guest's Window: the component's element is
|
|
8
|
+
* `<runic-hosted-region>` itself, and the page never gets a reference to its frame. Projected content shows while no
|
|
9
|
+
* guest page shows in the region; `state()` tells which state it is in:
|
|
10
|
+
*
|
|
11
|
+
* ```html
|
|
12
|
+
* <runic-hosted-region #check name="check" style="height: 420px" (stateChange)="onState($event)">
|
|
13
|
+
* @if (check.state() === "ended") { <button (click)="runAgain()">Run the check again</button> }
|
|
14
|
+
* @else { <p>Starting the check…</p> }
|
|
15
|
+
* </runic-hosted-region>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class RunicHostedRegion {
|
|
19
|
+
/** The region's name, which the host application's policy embeds a guest's Window in. */
|
|
20
|
+
name = input.required(/* @ts-ignore */
|
|
21
|
+
...(ngDevMode ? [{ debugName: "name" }] : /* istanbul ignore next */ []));
|
|
22
|
+
/** `fill` (the default): the page's layout sets the height. `content-height`: the guest's page does. */
|
|
23
|
+
sizing = input(/* @ts-ignore */
|
|
24
|
+
...(ngDevMode ? [undefined, { debugName: "sizing" }] : /* istanbul ignore next */ []));
|
|
25
|
+
/** The region's accessible name; without it, the guest page's title. */
|
|
26
|
+
label = input(/* @ts-ignore */
|
|
27
|
+
...(ngDevMode ? [undefined, { debugName: "label" }] : /* istanbul ignore next */ []));
|
|
28
|
+
stateChange = output();
|
|
29
|
+
/** The guest page's title as the host passed it on, or `null`. */
|
|
30
|
+
titleChange = output();
|
|
31
|
+
#state = signal("waiting", /* @ts-ignore */
|
|
32
|
+
...(ngDevMode ? [{ debugName: "#state" }] : /* istanbul ignore next */ []));
|
|
33
|
+
/** What the region shows now. */
|
|
34
|
+
state = this.#state.asReadonly();
|
|
35
|
+
constructor() {
|
|
36
|
+
defineHostedRegion();
|
|
37
|
+
}
|
|
38
|
+
stateChanged(event) {
|
|
39
|
+
const detail = event.detail;
|
|
40
|
+
this.#state.set(detail.state);
|
|
41
|
+
this.stateChange.emit({ state: detail.state, previous: detail.previous });
|
|
42
|
+
}
|
|
43
|
+
titleChanged(event) {
|
|
44
|
+
this.titleChange.emit(event.detail.title);
|
|
45
|
+
}
|
|
46
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicHostedRegion, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
47
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.3", type: RunicHostedRegion, isStandalone: true, selector: "runic-hosted-region", inputs: { name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: true, transformFunction: null }, sizing: { classPropertyName: "sizing", publicName: "sizing", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { stateChange: "stateChange", titleChange: "titleChange" }, host: { listeners: { "runicregionstatechange": "stateChanged($event)", "runicregiontitlechange": "titleChanged($event)" }, properties: { "attr.name": "name()", "attr.sizing": "sizing() ?? null", "attr.label": "label() ?? null" } }, exportAs: ["runicHostedRegion"], ngImport: i0, template: `<div slot="fallback" style="display: contents"><ng-content /></div>`, isInline: true });
|
|
48
|
+
}
|
|
49
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicHostedRegion, decorators: [{
|
|
50
|
+
type: Component,
|
|
51
|
+
args: [{
|
|
52
|
+
selector: "runic-hosted-region",
|
|
53
|
+
standalone: true,
|
|
54
|
+
exportAs: "runicHostedRegion",
|
|
55
|
+
host: {
|
|
56
|
+
"[attr.name]": "name()",
|
|
57
|
+
"[attr.sizing]": "sizing() ?? null",
|
|
58
|
+
"[attr.label]": "label() ?? null",
|
|
59
|
+
"(runicregionstatechange)": "stateChanged($event)",
|
|
60
|
+
"(runicregiontitlechange)": "titleChanged($event)",
|
|
61
|
+
},
|
|
62
|
+
template: `<div slot="fallback" style="display: contents"><ng-content /></div>`,
|
|
63
|
+
}]
|
|
64
|
+
}], ctorParameters: () => [], propDecorators: { name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: true }] }], sizing: [{ type: i0.Input, args: [{ isSignal: true, alias: "sizing", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], stateChange: [{ type: i0.Output, args: ["stateChange"] }], titleChange: [{ type: i0.Output, args: ["titleChange"] }] } });
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export { injectQueryCollection, type InjectQueryCollectionOptions, type QueryCol
|
|
|
13
13
|
export { injectBridgeConnection, type BridgeConnectionHandle, type InjectBridgeConnectionOptions } from "./inject-bridge-connection.js";
|
|
14
14
|
export { injectText, injectWindowLocale, RunicTextPipe, textLocaleSignal, type InjectTextOptions } from "./inject-text.js";
|
|
15
15
|
export { injectAppearance, type InjectAppearanceOptions } from "./inject-appearance.js";
|
|
16
|
+
export { injectRunicInstance, provideRunicInstance, RUNIC_INSTANCE, type InjectRunicInstanceOptions, } from "./instance.js";
|
|
17
|
+
export { createRunicInstance, pageInstance, type RunicInstance, type RunicInstanceOptions } from "@runic-artifex/views";
|
|
16
18
|
export { configureFieldErrorText, configureTranslatedText, fieldErrorText, resolveText, syncDocumentLocale, textDirection, windowLocale, type DocumentLocaleOptions, type FieldErrorArguments, type FieldErrorReason, type FieldErrorText, type TextReference, type TextTranslations, } from "@runic-artifex/views";
|
|
17
19
|
export { appearance, onAppearance, type Appearance, type AppearanceColorScheme, type AppearanceContrast, type AppearanceSystemColors, type HostAppearance, } from "@runic-artifex/views";
|
|
18
20
|
export { onBridgeConnection, type BridgeConnectionOptions, type BridgeConnectionState } from "@runic-artifex/views";
|
package/dist/esm/index.js
CHANGED
|
@@ -13,6 +13,8 @@ export { injectQueryCollection } from "./inject-query-collection.js";
|
|
|
13
13
|
export { injectBridgeConnection } from "./inject-bridge-connection.js";
|
|
14
14
|
export { injectText, injectWindowLocale, RunicTextPipe, textLocaleSignal } from "./inject-text.js";
|
|
15
15
|
export { injectAppearance } from "./inject-appearance.js";
|
|
16
|
+
export { injectRunicInstance, provideRunicInstance, RUNIC_INSTANCE, } from "./instance.js";
|
|
17
|
+
export { createRunicInstance, pageInstance } from "@runic-artifex/views";
|
|
16
18
|
export { configureFieldErrorText, configureTranslatedText, fieldErrorText, resolveText, syncDocumentLocale, textDirection, windowLocale, } from "@runic-artifex/views";
|
|
17
19
|
export { appearance, onAppearance, } from "@runic-artifex/views";
|
|
18
20
|
export { onBridgeConnection } from "@runic-artifex/views";
|
|
@@ -6,7 +6,7 @@ export interface InjectAppearanceOptions {
|
|
|
6
6
|
readonly injector?: Injector;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
9
|
+
* The appearance of the injection context's Runic instance (`appearance` from `@runic-artifex/views`) as a signal for the lifetime of the injection
|
|
10
10
|
* context: the colour scheme, contrast and reduced motion of the page's engine combined with the desktop's values that a
|
|
11
11
|
* Runic host pushes (`appearance/1`), which also carry the text scale, the accent colour and the forced-colours palette.
|
|
12
12
|
* Every member is `null` under server rendering.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
2
|
import { appearance, onAppearance, unknownAppearance } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
|
-
* The
|
|
5
|
+
* The appearance of the injection context's Runic instance (`appearance` from `@runic-artifex/views`) as a signal for the lifetime of the injection
|
|
5
6
|
* context: the colour scheme, contrast and reduced motion of the page's engine combined with the desktop's values that a
|
|
6
7
|
* Runic host pushes (`appearance/1`), which also carry the text scale, the accent colour and the forced-colours palette.
|
|
7
8
|
* Every member is `null` under server rendering.
|
|
@@ -17,10 +18,11 @@ export function injectAppearance({ injector: provided } = {}) {
|
|
|
17
18
|
const injector = provided ?? inject(Injector);
|
|
18
19
|
if (injector.get(PLATFORM_ID, null) === "server")
|
|
19
20
|
return signal(unknownAppearance).asReadonly();
|
|
20
|
-
const
|
|
21
|
+
const instance = instanceOf(injector);
|
|
22
|
+
const current = signal(instance.run(appearance), /* @ts-ignore */
|
|
21
23
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
22
|
-
const stop = onAppearance(next => current.set(next));
|
|
24
|
+
const stop = instance.run(() => onAppearance(next => current.set(next)));
|
|
23
25
|
injector.get(DestroyRef).onDestroy(stop);
|
|
24
|
-
current.set(appearance
|
|
26
|
+
current.set(instance.run(appearance));
|
|
25
27
|
return current.asReadonly();
|
|
26
28
|
}
|
|
@@ -9,7 +9,7 @@ export interface InjectBridgeConnectionOptions extends BridgeConnectionOptions {
|
|
|
9
9
|
readonly injector?: Injector;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Follows the
|
|
12
|
+
* Follows the connection of the injection context's Runic instance to its .NET host (`connecting`, `connected`, `reconnecting`,
|
|
13
13
|
* `lost` or `closed`) as a signal through `onBridgeConnection`, for the lifetime of the injection context.
|
|
14
14
|
* Destruction unsubscribes. Under server rendering (`PLATFORM_ID` `"server"`) it does not
|
|
15
15
|
* observe and stays `connecting`.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
2
|
import { onBridgeConnection } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
|
-
* Follows the
|
|
5
|
+
* Follows the connection of the injection context's Runic instance to its .NET host (`connecting`, `connected`, `reconnecting`,
|
|
5
6
|
* `lost` or `closed`) as a signal through `onBridgeConnection`, for the lifetime of the injection context.
|
|
6
7
|
* Destruction unsubscribes. Under server rendering (`PLATFORM_ID` `"server"`) it does not
|
|
7
8
|
* observe and stays `connecting`.
|
|
@@ -18,7 +19,7 @@ export function injectBridgeConnection({ injector: provided, ...options } = {})
|
|
|
18
19
|
const state = signal("connecting", /* @ts-ignore */
|
|
19
20
|
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
20
21
|
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
21
|
-
const stop = onBridgeConnection(next => state.set(next), options);
|
|
22
|
+
const stop = instanceOf(injector).run(() => onBridgeConnection(next => state.set(next), options));
|
|
22
23
|
injector.get(DestroyRef).onDestroy(stop);
|
|
23
24
|
}
|
|
24
25
|
return { state: state.asReadonly() };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
2
|
import { createCommandController } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
5
|
* Tracks a command's pending state and failure as signals for the lifetime of
|
|
5
6
|
* the injection context. The command may read signals, such as a client:
|
|
@@ -13,7 +14,7 @@ export function injectCommand(command, options = {}) {
|
|
|
13
14
|
if (!options.injector)
|
|
14
15
|
assertInInjectionContext(injectCommand);
|
|
15
16
|
const injector = options.injector ?? inject(Injector);
|
|
16
|
-
const controller = createCommandController(command);
|
|
17
|
+
const controller = instanceOf(injector).run(() => createCommandController(command));
|
|
17
18
|
const pending = signal(false, /* @ts-ignore */
|
|
18
19
|
...(ngDevMode ? [{ debugName: "pending" }] : /* istanbul ignore next */ []));
|
|
19
20
|
const error = signal(undefined, /* @ts-ignore */
|
package/dist/esm/inject-field.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, signal, untracked } from "@angular/core";
|
|
2
2
|
import { createFieldController, } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
function textOf(event) {
|
|
4
5
|
if (typeof event === "string")
|
|
5
6
|
return event;
|
|
@@ -24,7 +25,7 @@ export function injectField(view, field, { injector: provided, ...options } = {}
|
|
|
24
25
|
if (!provided)
|
|
25
26
|
assertInInjectionContext(injectField);
|
|
26
27
|
const injector = provided ?? inject(Injector);
|
|
27
|
-
const controller = createFieldController(field, options);
|
|
28
|
+
const controller = instanceOf(injector).run(() => createFieldController(field, options));
|
|
28
29
|
const current = signal(controller.current, /* @ts-ignore */
|
|
29
30
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
30
31
|
controller.subscribe(() => current.set(controller.current));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
2
|
import { createLatestOperationController, } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
5
|
* Admits only the newest selection, for reads such as "load the selected item", as signals
|
|
5
6
|
* for the lifetime of the injection context. Each `run(intent)` replaces the queued intent
|
|
@@ -18,7 +19,7 @@ export function injectLatestOperation({ injector: provided } = {}) {
|
|
|
18
19
|
if (!provided)
|
|
19
20
|
assertInInjectionContext(injectLatestOperation);
|
|
20
21
|
const injector = provided ?? inject(Injector);
|
|
21
|
-
const controller = createLatestOperationController();
|
|
22
|
+
const controller = instanceOf(injector).run(() => createLatestOperationController());
|
|
22
23
|
const state = signal(controller.current, /* @ts-ignore */
|
|
23
24
|
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
24
25
|
controller.subscribe(() => state.set(controller.current));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
2
|
import { BridgeError, createMenuBarController, } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
5
|
* Follows the window's declared menu bar (Runic Desktop's `DesktopMenuBarPresentation.Page`) as a signal, as headless
|
|
5
6
|
* state for the application's own menubar (for example the CDK Menu's `cdkMenuBar`), through
|
|
@@ -27,7 +28,7 @@ export function injectMenuBar({ injector: provided, onRequest, ...options } = {}
|
|
|
27
28
|
handleKeyDown: () => false,
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
const controller = createMenuBarController(options);
|
|
31
|
+
const controller = instanceOf(injector).run(() => createMenuBarController(options));
|
|
31
32
|
const state = signal(controller.current, /* @ts-ignore */
|
|
32
33
|
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
33
34
|
controller.subscribe(() => state.set(controller.current));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, DestroyRef, inject, Injector, signal } from "@angular/core";
|
|
2
2
|
import { createOperationController, } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
/**
|
|
4
5
|
* Tracks Start admission, pending work, cancellation and terminal feedback of a
|
|
5
6
|
* generated `start<Command>()` operation as signals for the lifetime of the
|
|
@@ -16,7 +17,7 @@ export function injectOperation(start, { injector: provided, ...options } = {})
|
|
|
16
17
|
if (!provided)
|
|
17
18
|
assertInInjectionContext(injectOperation);
|
|
18
19
|
const injector = provided ?? inject(Injector);
|
|
19
|
-
const controller = createOperationController(start, options);
|
|
20
|
+
const controller = instanceOf(injector).run(() => createOperationController(start, options));
|
|
20
21
|
const state = signal(controller.current, /* @ts-ignore */
|
|
21
22
|
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
22
23
|
controller.subscribe(() => state.set(controller.current));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, signal, untracked } from "@angular/core";
|
|
2
2
|
import { createTextFieldController } from "@runic-artifex/views";
|
|
3
|
+
import { instanceOf } from "./instance.js";
|
|
3
4
|
function textOf(event) {
|
|
4
5
|
if (typeof event === "string")
|
|
5
6
|
return event;
|
|
@@ -25,7 +26,7 @@ export function injectTextField(view, read, write, { injector: provided, ...opti
|
|
|
25
26
|
if (!provided)
|
|
26
27
|
assertInInjectionContext(injectTextField);
|
|
27
28
|
const injector = provided ?? inject(Injector);
|
|
28
|
-
const controller = createTextFieldController({ read, write, ...options });
|
|
29
|
+
const controller = instanceOf(injector).run(() => createTextFieldController({ read, write, ...options }));
|
|
29
30
|
const current = signal(controller.current, /* @ts-ignore */
|
|
30
31
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
31
32
|
controller.subscribe(() => current.set(controller.current));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Injector, type OnDestroy, type PipeTransform, type Signal } from "@angular/core";
|
|
2
|
-
import { type FieldError, type TextReference } from "@runic-artifex/views";
|
|
2
|
+
import { type FieldError, type RunicInstance, type TextReference } from "@runic-artifex/views";
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export interface InjectTextOptions {
|
|
5
5
|
/** Required outside an injection context. */
|
|
@@ -26,17 +26,18 @@ export declare function injectText(source: () => TextReference | FieldError | st
|
|
|
26
26
|
*/
|
|
27
27
|
export declare function injectWindowLocale({ injector: provided }?: InjectTextOptions): Signal<string | null>;
|
|
28
28
|
/**
|
|
29
|
-
* The locale that text is shown in (`textLocale`: the
|
|
30
|
-
* as a signal. It is one signal
|
|
31
|
-
* it: a template that calls `m.*()` reads the signal through the resolver and renders again on a
|
|
32
|
-
* `undefined` while the
|
|
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.
|
|
33
34
|
*
|
|
34
35
|
* ```ts
|
|
35
36
|
* const textLocale = textLocaleSignal();
|
|
36
37
|
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
37
38
|
* ```
|
|
38
39
|
*/
|
|
39
|
-
export declare function textLocaleSignal(): Signal<string | undefined>;
|
|
40
|
+
export declare function textLocaleSignal(instance?: RunicInstance): Signal<string | undefined>;
|
|
40
41
|
/**
|
|
41
42
|
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
42
43
|
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
@@ -46,6 +47,7 @@ export declare function textLocaleSignal(): Signal<string | undefined>;
|
|
|
46
47
|
*/
|
|
47
48
|
export declare class RunicTextPipe implements PipeTransform, OnDestroy {
|
|
48
49
|
private readonly changes;
|
|
50
|
+
private readonly instance;
|
|
49
51
|
private readonly stop;
|
|
50
52
|
private last;
|
|
51
53
|
transform(value: TextReference | FieldError | string | null | undefined, fallback?: string): string;
|
package/dist/esm/inject-text.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInInjectionContext, ChangeDetectorRef, computed, DestroyRef, inject, Injector, Pipe, PLATFORM_ID, signal, } from "@angular/core";
|
|
2
2
|
import { onWindowLocale, resolveText, subscribeText, textLocale, textVersion, windowLocale, } from "@runic-artifex/views";
|
|
3
|
+
import { contextInstance, instanceOf } from "./instance.js";
|
|
3
4
|
import * as i0 from "@angular/core";
|
|
4
5
|
/**
|
|
5
6
|
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
@@ -19,15 +20,17 @@ export function injectText(source, fallback, { injector: provided } = {}) {
|
|
|
19
20
|
if (!provided)
|
|
20
21
|
assertInInjectionContext(injectText);
|
|
21
22
|
const injector = provided ?? inject(Injector);
|
|
23
|
+
const instance = instanceOf(injector);
|
|
22
24
|
const version = signal(0, /* @ts-ignore */
|
|
23
25
|
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
24
26
|
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
25
|
-
const stop = subscribeText(() => version.update(value => value + 1));
|
|
27
|
+
const stop = instance.run(() => subscribeText(() => version.update(value => value + 1)));
|
|
26
28
|
injector.get(DestroyRef).onDestroy(stop);
|
|
27
29
|
}
|
|
28
30
|
return computed(() => {
|
|
29
31
|
version();
|
|
30
|
-
|
|
32
|
+
const value = source(), otherwise = fallback?.();
|
|
33
|
+
return instance.run(() => resolveText(value, otherwise));
|
|
31
34
|
});
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
@@ -38,33 +41,38 @@ export function injectWindowLocale({ injector: provided } = {}) {
|
|
|
38
41
|
if (!provided)
|
|
39
42
|
assertInInjectionContext(injectWindowLocale);
|
|
40
43
|
const injector = provided ?? inject(Injector);
|
|
41
|
-
const
|
|
44
|
+
const instance = instanceOf(injector);
|
|
45
|
+
const locale = signal(instance.run(windowLocale), /* @ts-ignore */
|
|
42
46
|
...(ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
43
47
|
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
44
|
-
const stop = onWindowLocale(next => locale.set(next));
|
|
48
|
+
const stop = instance.run(() => onWindowLocale(next => locale.set(next)));
|
|
45
49
|
injector.get(DestroyRef).onDestroy(stop);
|
|
46
50
|
}
|
|
47
51
|
return locale.asReadonly();
|
|
48
52
|
}
|
|
49
|
-
|
|
53
|
+
const textLocales = new WeakMap();
|
|
50
54
|
/**
|
|
51
|
-
* The locale that text is shown in (`textLocale`: the
|
|
52
|
-
* as a signal. It is one signal
|
|
53
|
-
* it: a template that calls `m.*()` reads the signal through the resolver and renders again on a
|
|
54
|
-
* `undefined` while the
|
|
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.
|
|
55
60
|
*
|
|
56
61
|
* ```ts
|
|
57
62
|
* const textLocale = textLocaleSignal();
|
|
58
63
|
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
59
64
|
* ```
|
|
60
65
|
*/
|
|
61
|
-
export function textLocaleSignal() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 */
|
|
65
71
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
66
|
-
subscribeText(() => current.set(textLocale
|
|
67
|
-
|
|
72
|
+
instance.run(() => subscribeText(() => current.set(instance.run(textLocale))));
|
|
73
|
+
const locale = current.asReadonly();
|
|
74
|
+
textLocales.set(instance, locale);
|
|
75
|
+
return locale;
|
|
68
76
|
}
|
|
69
77
|
/**
|
|
70
78
|
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
@@ -75,14 +83,15 @@ export function textLocaleSignal() {
|
|
|
75
83
|
*/
|
|
76
84
|
export class RunicTextPipe {
|
|
77
85
|
changes = inject(ChangeDetectorRef);
|
|
78
|
-
|
|
86
|
+
instance = instanceOf(inject(Injector));
|
|
87
|
+
stop = this.instance.run(() => subscribeText(() => this.changes.markForCheck()));
|
|
79
88
|
last;
|
|
80
89
|
transform(value, fallback) {
|
|
81
|
-
const version = textVersion
|
|
90
|
+
const version = this.instance.run(textVersion);
|
|
82
91
|
const last = this.last;
|
|
83
92
|
if (last && last.value === value && last.fallback === fallback && last.version === version)
|
|
84
93
|
return last.text;
|
|
85
|
-
const text = resolveText(value, fallback);
|
|
94
|
+
const text = this.instance.run(() => resolveText(value, fallback));
|
|
86
95
|
this.last = { value, fallback, version, text };
|
|
87
96
|
return text;
|
|
88
97
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, effect, inject, Injector, isSignal, resource, signal, untracked, } from "@angular/core";
|
|
2
2
|
import { createViewController } from "@runic-artifex/views";
|
|
3
3
|
import { viewSourceIdentity } from "@runic-artifex/views/bindings";
|
|
4
|
+
import { instanceOf } from "./instance.js";
|
|
4
5
|
function asError(cause) {
|
|
5
6
|
return cause instanceof Error ? cause : new Error(String(cause), { cause });
|
|
6
7
|
}
|
|
@@ -29,6 +30,7 @@ export function injectViewResource(source, options = {}) {
|
|
|
29
30
|
if (!options.injector)
|
|
30
31
|
assertInInjectionContext(injectViewResource);
|
|
31
32
|
const injector = options.injector ?? inject(Injector);
|
|
33
|
+
const instance = instanceOf(injector);
|
|
32
34
|
const read = () => isSignal(source) ? source() : source;
|
|
33
35
|
const client = signal(undefined, /* @ts-ignore */
|
|
34
36
|
...(ngDevMode ? [{ debugName: "client" }] : /* istanbul ignore next */ []));
|
|
@@ -51,7 +53,8 @@ export function injectViewResource(source, options = {}) {
|
|
|
51
53
|
const ref = resource({ ...(ngDevMode ? { debugName: "ref" } : /* istanbul ignore next */ {}), injector,
|
|
52
54
|
params: () => identity(),
|
|
53
55
|
stream: async ({ abortSignal }) => {
|
|
54
|
-
|
|
56
|
+
// Each load connects in the injection context's Runic instance.
|
|
57
|
+
const controller = instance.run(() => createViewController(controllerOptions));
|
|
55
58
|
active = controller;
|
|
56
59
|
abortSignal.addEventListener("abort", () => {
|
|
57
60
|
if (active === controller)
|
package/dist/esm/inject-view.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { assertInInjectionContext, computed, DestroyRef, effect, inject, Injector, isSignal, signal, untracked } from "@angular/core";
|
|
2
2
|
import { createViewController } from "@runic-artifex/views";
|
|
3
3
|
import { isViewClient, viewSourceIdentity, viewSourcePreview } from "@runic-artifex/views/bindings";
|
|
4
|
+
import { instanceOf } from "./instance.js";
|
|
4
5
|
/**
|
|
5
6
|
* Connects a generated View reference for the lifetime of the injection
|
|
6
7
|
* context (normally a component) and exposes its state as signals. Pass a
|
|
@@ -19,10 +20,12 @@ export function injectView(source, options = {}) {
|
|
|
19
20
|
if (!options.injector)
|
|
20
21
|
assertInInjectionContext(injectView);
|
|
21
22
|
const injector = options.injector ?? inject(Injector);
|
|
22
|
-
|
|
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({
|
|
23
26
|
...(options.release ? { release: options.release } : {}),
|
|
24
27
|
...(options.keepAlive === undefined ? {} : { keepAlive: options.keepAlive }),
|
|
25
|
-
});
|
|
28
|
+
}));
|
|
26
29
|
const current = signal(controller.current, /* @ts-ignore */
|
|
27
30
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
28
31
|
controller.subscribe(() => current.set(controller.current));
|
|
@@ -50,8 +53,8 @@ export function injectView(source, options = {}) {
|
|
|
50
53
|
const preview = computed(() => {
|
|
51
54
|
const value = observed();
|
|
52
55
|
if (value)
|
|
53
|
-
return value === current().client ? undefined : viewSourcePreview(value);
|
|
54
|
-
return fresh() ? undefined : viewSourcePreview(read());
|
|
56
|
+
return value === current().client ? undefined : instance.run(() => viewSourcePreview(value));
|
|
57
|
+
return fresh() ? undefined : instance.run(() => viewSourcePreview(read()));
|
|
55
58
|
}, /* @ts-ignore */
|
|
56
59
|
...(ngDevMode ? [{ debugName: "preview" }] : /* istanbul ignore next */ []));
|
|
57
60
|
return {
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, InjectionToken } from "@angular/core";
|
|
2
|
+
import { defaultInstance } 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 const RUNIC_INSTANCE = new InjectionToken("RUNIC_INSTANCE", {
|
|
9
|
+
providedIn: "root",
|
|
10
|
+
factory: () => defaultInstance(),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Provides `instance` as the {@link RUNIC_INSTANCE} of an injector: `injectView`, `injectField`, `injectText`,
|
|
14
|
+
* `injectBridgeConnection`, `injectAppearance` and the other helpers below it use it instead of the page instance. A
|
|
15
|
+
* guest that renders inside another page, such as an embedded component, adds it to its application's or its root
|
|
16
|
+
* component's `providers`.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const instance = createRunicInstance({ bridge });
|
|
20
|
+
* bootstrapApplication(App, { providers: [provideRunicInstance(instance)] });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function provideRunicInstance(instance) {
|
|
24
|
+
return { provide: RUNIC_INSTANCE, useValue: instance };
|
|
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 function injectRunicInstance({ injector } = {}) {
|
|
31
|
+
if (injector)
|
|
32
|
+
return instanceOf(injector);
|
|
33
|
+
assertInInjectionContext(injectRunicInstance);
|
|
34
|
+
return inject(RUNIC_INSTANCE, { optional: true }) ?? defaultInstance();
|
|
35
|
+
}
|
|
36
|
+
/** @internal The Runic instance of `injector`. */
|
|
37
|
+
export function instanceOf(injector) {
|
|
38
|
+
return injector.get(RUNIC_INSTANCE, null) ?? defaultInstance();
|
|
39
|
+
}
|
|
40
|
+
/** @internal The Runic instance of the injection context, or the default instance outside one. */
|
|
41
|
+
export function contextInstance() {
|
|
42
|
+
try {
|
|
43
|
+
return inject(RUNIC_INSTANCE, { optional: true }) ?? defaultInstance();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return defaultInstance();
|
|
47
|
+
}
|
|
48
|
+
}
|
package/dist/esm/view-outlet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, computed, Directive, effect, ElementRef, inject, input, isDevMode, Renderer2, signal, untracked, viewChild, ViewContainerRef, } from "@angular/core";
|
|
2
2
|
import { regionEntries } from "@runic-artifex/views";
|
|
3
3
|
import { missingViewMessage, reportMissingView } from "@runic-artifex/views/bindings";
|
|
4
|
+
import { injectRunicInstance } from "./instance.js";
|
|
4
5
|
import * as i0 from "@angular/core";
|
|
5
6
|
// Projected content renders while there is no reference, like React's `fallback`, Vue's default slot
|
|
6
7
|
// and Svelte's `fallback` snippet: `<runic-view-outlet [content]="…" [registry]="…">Loading…</runic-view-outlet>`.
|
|
@@ -40,6 +41,7 @@ export class ViewOutlet {
|
|
|
40
41
|
}, /* @ts-ignore */
|
|
41
42
|
...(ngDevMode ? [{ debugName: "selected" }] : /* istanbul ignore next */ []));
|
|
42
43
|
constructor() {
|
|
44
|
+
const instance = injectRunicInstance();
|
|
43
45
|
effect(() => {
|
|
44
46
|
const container = this.mount();
|
|
45
47
|
const selection = this.selected();
|
|
@@ -58,7 +60,7 @@ export class ViewOutlet {
|
|
|
58
60
|
if (isDevMode())
|
|
59
61
|
this.error.set(missingViewMessage(selection.reference.kind));
|
|
60
62
|
else
|
|
61
|
-
reportMissingView(selection.reference.kind);
|
|
63
|
+
instance.run(() => reportMissingView(selection.reference.kind));
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
66
|
const component = container.createComponent(selection.component);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -13,12 +13,17 @@
|
|
|
13
13
|
"import": "./dist/esm/forms/index.js",
|
|
14
14
|
"default": "./dist/esm/forms/index.js"
|
|
15
15
|
},
|
|
16
|
+
"./experimental": {
|
|
17
|
+
"types": "./dist/esm/experimental.d.ts",
|
|
18
|
+
"import": "./dist/esm/experimental.js",
|
|
19
|
+
"default": "./dist/esm/experimental.js"
|
|
20
|
+
},
|
|
16
21
|
"./package.json": "./package.json"
|
|
17
22
|
},
|
|
18
23
|
"peerDependencies": {
|
|
19
24
|
"@angular/core": ">=22.0.0 <23",
|
|
20
25
|
"@angular/forms": ">=22.0.0 <23",
|
|
21
|
-
"@runic-artifex/views": "0.
|
|
26
|
+
"@runic-artifex/views": "0.18.0"
|
|
22
27
|
},
|
|
23
28
|
"peerDependenciesMeta": {
|
|
24
29
|
"@angular/forms": {
|
|
@@ -32,7 +37,7 @@
|
|
|
32
37
|
"url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
|
|
33
38
|
"directory": "packages/web/angular"
|
|
34
39
|
},
|
|
35
|
-
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
40
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.18.0/packages/web/angular#readme",
|
|
36
41
|
"bugs": {
|
|
37
42
|
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
38
43
|
},
|
|
@@ -56,7 +61,7 @@
|
|
|
56
61
|
"pack:check": "bun pm pack --dry-run"
|
|
57
62
|
},
|
|
58
63
|
"devDependencies": {
|
|
59
|
-
"@runic-artifex/views": "0.
|
|
64
|
+
"@runic-artifex/views": "0.18.0",
|
|
60
65
|
"@angular/common": "22.2.3",
|
|
61
66
|
"@angular/compiler": "22.2.3",
|
|
62
67
|
"@angular/compiler-cli": "22.2.3",
|
|
@@ -69,5 +74,5 @@
|
|
|
69
74
|
"typescript": "6.0.3",
|
|
70
75
|
"vitest": "5.0.3"
|
|
71
76
|
},
|
|
72
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "e025c0ab74aa76547e2d0307de223c43d5271228"
|
|
73
78
|
}
|