@runic-artifex/angular 0.16.0 → 0.17.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 +58 -22
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +4 -2
- package/dist/esm/inject-appearance.d.ts +19 -0
- package/dist/esm/inject-appearance.js +26 -0
- package/dist/esm/inject-text.d.ts +18 -4
- package/dist/esm/inject-text.js +24 -2
- package/dist/esm/view-outlet.d.ts +12 -9
- package/dist/esm/view-outlet.js +10 -4
- package/package.json +5 -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.17.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.17.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`,
|
|
@@ -230,7 +230,10 @@ A checked write's receipt is read: `rejected` keeps the draft with a `FieldError
|
|
|
230
230
|
`rejected`; `conflict` keeps the draft, sets `conflict` to the producer's
|
|
231
231
|
`{ value, version }` and writes nothing until `retry()` (write the draft over it) or
|
|
232
232
|
`reset()` (take the producer's value); `committed-with-error` keeps the committed value
|
|
233
|
-
with a `FieldError`. `
|
|
233
|
+
with a `FieldError`. A text that does not parse is a `FieldError` `invalid-text` with a `reason` and `arguments`:
|
|
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.17.0/packages/web/views#translating-field-errors)).
|
|
236
|
+
`errors` follows the member's validation in the View's state:
|
|
234
237
|
|
|
235
238
|
```html
|
|
236
239
|
@if (title.conflict(); as theirs) {
|
|
@@ -246,7 +249,7 @@ Since 0.16, `InvoiceFields.address.street` and `InvoiceFields.lines.at(line.id).
|
|
|
246
249
|
`injectField(view, InvoiceFields.lines.at(line.id).quantity)` in the row's component, or bind it with
|
|
247
250
|
`[runicField]`; `at(key)` returns the same descriptor for the same key. Such a field always writes checked, conflicts
|
|
248
251
|
only when another writer changed the same cell, and shows the messages .NET reports at the cell's validation path. See
|
|
249
|
-
[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.17.0/packages/web/angular/../views/README.md#fields-below-a-member-and-row-cells).
|
|
250
253
|
|
|
251
254
|
### Forms: `injectForm(fields, options?)`
|
|
252
255
|
|
|
@@ -375,8 +378,15 @@ it outside its own signal tracking. A component's `page` input receives that
|
|
|
375
378
|
reference; `injectView(this.page)` owns its connection and cleanup. Declare
|
|
376
379
|
`page` as a required signal input, `input.required<DocumentReference>()`: a
|
|
377
380
|
decorator `@Input() page` or an optional `input<DocumentReference>()` does not
|
|
378
|
-
satisfy `ViewRegistry`.
|
|
379
|
-
|
|
381
|
+
satisfy `ViewRegistry`. A component whose `page` input is a shared page
|
|
382
|
+
reference, `input.required<ResultPagePageReference>()` for a .NET
|
|
383
|
+
[`[RunicSharedClient]`](https://github.com/Runic-Artifex/runic-sdk/blob/v0.17.0/packages/web/angular/../../dotnet/Runic.Application.Views/README.md#shared-clients)
|
|
384
|
+
interface, registers for each of its kinds without a cast:
|
|
385
|
+
`{ ...registryEntries(resultPageKinds, ResultPage), settings: Settings }`. Missing kinds render an English `<p role="alert">` in a
|
|
386
|
+
development build (`isDevMode()`); a production build renders nothing and
|
|
387
|
+
reports the kind once through the page's error reporting
|
|
388
|
+
(`installErrorReporting`, `onBridgeDiagnostic`). The generated TypeScript client
|
|
389
|
+
can also be used directly without Angular.
|
|
380
390
|
|
|
381
391
|
The `missing` input replaces that alert with a template, for example with
|
|
382
392
|
localized text. Its context (`ViewOutletMissingContext`) passes the reference
|
|
@@ -483,14 +493,14 @@ For example, a navigation command whose departure guard awaits a dialog's
|
|
|
483
493
|
answer never completes while the answer waits behind it. Order such commands
|
|
484
494
|
by dispatch instead: start the next one once the previous one has been sent,
|
|
485
495
|
as the Notes example's
|
|
486
|
-
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
496
|
+
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/examples/notes-view-first/Angular/src/app/window-operations.ts)
|
|
487
497
|
does for its navigation commands.
|
|
488
498
|
|
|
489
499
|
## Operations
|
|
490
500
|
|
|
491
501
|
`injectOperation(start, options?)` observes a generated `start<Command>()` operation
|
|
492
502
|
through the framework-neutral
|
|
493
|
-
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
503
|
+
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/views#operation-feedback-and-latest-selection)
|
|
494
504
|
for the lifetime of the injection context:
|
|
495
505
|
|
|
496
506
|
```ts
|
|
@@ -516,7 +526,7 @@ context.
|
|
|
516
526
|
|
|
517
527
|
`injectLatestOperation(options?)` admits only the newest of several reads, for example
|
|
518
528
|
loading the item the user selected last, through the framework-neutral
|
|
519
|
-
[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.17.0/packages/web/views#operation-feedback-and-latest-selection).
|
|
520
530
|
Each `run(intent)` replaces the queued intent and cancels the active read; the next
|
|
521
531
|
read starts only after the previous one reaches its terminal status and the intent's
|
|
522
532
|
optional `waitForCompletion` barrier:
|
|
@@ -548,7 +558,7 @@ from `@runic-artifex/views` (re-exported here since 0.11, with the
|
|
|
548
558
|
`BridgeConnectionState` and `BridgeConnectionOptions` types) and returns `{ state }`, a signal of a
|
|
549
559
|
`BridgeConnectionState`: `connecting`, `connected`, `reconnecting`, `lost` or `closed` (the
|
|
550
560
|
application closed the window, since 0.15; a closed set, see
|
|
551
|
-
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
561
|
+
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/views#connection-state)):
|
|
552
562
|
|
|
553
563
|
```ts
|
|
554
564
|
import { injectBridgeConnection } from "@runic-artifex/angular";
|
|
@@ -566,7 +576,7 @@ not observe and stays `connecting`. An invalid `lostAfter` throws a `RangeError`
|
|
|
566
576
|
`injectMenuBar(options?)` follows the declared menu bar of a Runic Desktop
|
|
567
577
|
window that leaves it to the page (`DesktopMenuBarPresentation.Page`) for the
|
|
568
578
|
lifetime of the injection context. It wraps `createMenuBarController` from
|
|
569
|
-
`@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.17.0/packages/web/views#in-page-menu-bar))
|
|
570
580
|
and returns `{ state, invoke, handleKeyDown }`, where `state` is a signal of a
|
|
571
581
|
`MenuBarState`. The bar is rendered by the application's own menubar, for
|
|
572
582
|
example the CDK Menu's `cdkMenuBar`. Runic ships no menubar component.
|
|
@@ -591,7 +601,7 @@ it creates none and stays `connecting`.
|
|
|
591
601
|
### With the CDK Menu
|
|
592
602
|
|
|
593
603
|
The CDK's `cdkMenuBar` with `CdkMenuTrigger.open()` for `open` requests; the
|
|
594
|
-
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
604
|
+
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/examples/notes-view-first#in-page-menu-bar) adds submenus, check and radio
|
|
595
605
|
items (`cdkMenuItemCheckbox`, `cdkMenuItemRadio` in a `cdkMenuGroup`) and is
|
|
596
606
|
tested with real keys:
|
|
597
607
|
|
|
@@ -645,8 +655,21 @@ export class AppMenuBar {
|
|
|
645
655
|
`injectText(() => source, () => fallback?)` is a signal of a text reference in
|
|
646
656
|
the window's language, and the `runicText` pipe does the same in templates; both
|
|
647
657
|
follow a language switch. Connect the page's Translations runtime once with
|
|
648
|
-
`configureTranslatedText` ([Translated text](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
649
|
-
`injectWindowLocale()` reads the window's locale.
|
|
658
|
+
`configureTranslatedText` ([Translated text](https://github.com/Runic-Artifex/runic-sdk/blob/v0.17.0/packages/dotnet/Runic.Application.Views/README.md#translated-text)).
|
|
659
|
+
`injectWindowLocale()` reads the window's locale. `textLocaleSignal()` is the
|
|
660
|
+
locale that text is shown in, as one signal for the page that needs no injection
|
|
661
|
+
context; when the locale resolver reads it, templates that call `m.*()`, also
|
|
662
|
+
`OnPush` ones, render again on a language switch:
|
|
663
|
+
|
|
664
|
+
```ts
|
|
665
|
+
// main.ts
|
|
666
|
+
const textLocale = textLocaleSignal();
|
|
667
|
+
configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
668
|
+
configureTranslatedText({ ...locale, resolve, direction: localeDirection });
|
|
669
|
+
syncDocumentLocale(); // <html lang dir>
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
The pipe formats again only
|
|
650
673
|
when its value, fallback or the language changed. Under server rendering, call
|
|
651
674
|
`configureTranslatedText` behind `isPlatformBrowser`, or render on the server
|
|
652
675
|
with `resolveTextReference` and the request's locale.
|
|
@@ -659,6 +682,19 @@ with `resolveTextReference` and the request's locale.
|
|
|
659
682
|
})
|
|
660
683
|
```
|
|
661
684
|
|
|
685
|
+
## Appearance
|
|
686
|
+
|
|
687
|
+
`injectAppearance()` is the page's appearance as a signal for the lifetime of the
|
|
688
|
+
injection context: the colour scheme, contrast and reduced motion of the page's
|
|
689
|
+
engine, combined with the desktop's text scale, accent colour, forced-colours
|
|
690
|
+
palette, contrast and motion that a Runic host pushes
|
|
691
|
+
([Appearance](https://github.com/Runic-Artifex/runic-sdk/blob/v0.17.0/packages/web/views/README.md#appearance)). On the server every member is `null`.
|
|
692
|
+
|
|
693
|
+
```ts
|
|
694
|
+
readonly appearance = injectAppearance();
|
|
695
|
+
readonly fontSize = computed(() => `${this.appearance().textScale ?? 1}rem`);
|
|
696
|
+
```
|
|
697
|
+
|
|
662
698
|
## Errors
|
|
663
699
|
|
|
664
700
|
The `error()` signal of `injectView` and of a command or operation is typed
|
|
@@ -676,7 +712,7 @@ readonly message = computed(() => describeBridgeError(this.view.error()));
|
|
|
676
712
|
```
|
|
677
713
|
|
|
678
714
|
`instanceof` holds for errors from every copy of the package on the page.
|
|
679
|
-
[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.17.0/packages/web/views#errors-and-diagnostics)
|
|
680
716
|
lists the kinds. Any other value, such as an exception that your own connect
|
|
681
717
|
function or command callback throws, arrives unchanged.
|
|
682
718
|
|
|
@@ -727,10 +763,10 @@ application's own dialog.
|
|
|
727
763
|
departure before that is answered by the ViewModel's .NET fallback handler, or
|
|
728
764
|
fails closed without one.
|
|
729
765
|
|
|
730
|
-
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.17.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
|
|
731
767
|
has the .NET side and which View answers which departure. In a frontend test,
|
|
732
768
|
the generated mock's `interactions.<name>.request(input)` resolves with the
|
|
733
|
-
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.17.0/packages/web/views#testing).
|
|
734
770
|
|
|
735
771
|
## View requests
|
|
736
772
|
|
|
@@ -768,15 +804,15 @@ the page painted the state the request was raised with, so the field of that
|
|
|
768
804
|
state is rendered; `signal` aborts when the handler is replaced or removed, the
|
|
769
805
|
client is disposed or the connection is lost. A request is never replayed: one
|
|
770
806
|
raised before the effect ran, or while the page is disconnected, is not
|
|
771
|
-
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.17.0/packages/web/views#view-requests) for the rules, and in a frontend
|
|
772
808
|
test raise one with the generated mock's `requests.<name>.raise(input)` (the
|
|
773
|
-
[Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
809
|
+
[Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/views#testing)).
|
|
774
810
|
|
|
775
811
|
## Collection viewports
|
|
776
812
|
|
|
777
813
|
`injectCollectionViewport(element, options)` follows a fixed-row-height scroll
|
|
778
814
|
container and returns a signal with its
|
|
779
|
-
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
815
|
+
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/views#collectionviewportoptions)
|
|
780
816
|
range. Pass the container as a signal, such as a `viewChild`, and the options as
|
|
781
817
|
a function or signal, then send the range to the ViewModel from an effect:
|
|
782
818
|
|
|
@@ -808,7 +844,7 @@ export class RowsPage {
|
|
|
808
844
|
## Query collections
|
|
809
845
|
|
|
810
846
|
`injectQueryCollection(element, collection, options)` follows a scroll container for a
|
|
811
|
-
[query collection](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
847
|
+
[query collection](https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/views#query-collections) (`client.queries.{name}`), whose rows stay in .NET: it loads the rows the container shows,
|
|
812
848
|
with placeholders until they arrive, and lays them out with variable heights. `viewport` is a signal of the
|
|
813
849
|
`QueryViewport` (`items` with `top` and `size`, `totalSize`, `total`, `query`, `loading`, `error`); `observe(element,
|
|
814
850
|
index)` measures a rendered row, and `scrollToKey`, `scrollToIndex`, `setQuery` and `retry` act on the collection.
|
|
@@ -825,4 +861,4 @@ The package re-exports `installBackNavigation`, `installNavigationPath`,
|
|
|
825
861
|
`@runic-artifex/views` (since 0.16). Call the installs once where the page
|
|
826
862
|
starts, before or after mounting: the mouse's Back button and Alt+Left then go
|
|
827
863
|
back in the .NET window, and `#/customers/42` follows its path region. See
|
|
828
|
-
[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.17.0/packages/web/views/README.md#back-and-the-url).
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -11,8 +11,10 @@ export { injectLatestOperation, type InjectLatestOperationOptions, type LatestOp
|
|
|
11
11
|
export { injectCollectionViewport, type InjectCollectionViewportOptions } from "./inject-collection-viewport.js";
|
|
12
12
|
export { injectQueryCollection, type InjectQueryCollectionOptions, type QueryCollectionHandle } from "./inject-query-collection.js";
|
|
13
13
|
export { injectBridgeConnection, type BridgeConnectionHandle, type InjectBridgeConnectionOptions } from "./inject-bridge-connection.js";
|
|
14
|
-
export { injectText, injectWindowLocale, RunicTextPipe, type InjectTextOptions } from "./inject-text.js";
|
|
15
|
-
export {
|
|
14
|
+
export { injectText, injectWindowLocale, RunicTextPipe, textLocaleSignal, type InjectTextOptions } from "./inject-text.js";
|
|
15
|
+
export { injectAppearance, type InjectAppearanceOptions } from "./inject-appearance.js";
|
|
16
|
+
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
|
+
export { appearance, onAppearance, type Appearance, type AppearanceColorScheme, type AppearanceContrast, type AppearanceSystemColors, type HostAppearance, } from "@runic-artifex/views";
|
|
16
18
|
export { onBridgeConnection, type BridgeConnectionOptions, type BridgeConnectionState } from "@runic-artifex/views";
|
|
17
19
|
export { upload, type BlobRef, type RunicBlob, type UploadOptions, type UploadProgress } from "@runic-artifex/views";
|
|
18
20
|
export { regionEntries, selectedRegion, type RegionCollection, type RegionEntry, type RegionOutcome, type RegionSlot, } from "@runic-artifex/views";
|
package/dist/esm/index.js
CHANGED
|
@@ -11,8 +11,10 @@ export { injectLatestOperation, } from "./inject-latest-operation.js";
|
|
|
11
11
|
export { injectCollectionViewport } from "./inject-collection-viewport.js";
|
|
12
12
|
export { injectQueryCollection } from "./inject-query-collection.js";
|
|
13
13
|
export { injectBridgeConnection } from "./inject-bridge-connection.js";
|
|
14
|
-
export { injectText, injectWindowLocale, RunicTextPipe } from "./inject-text.js";
|
|
15
|
-
export {
|
|
14
|
+
export { injectText, injectWindowLocale, RunicTextPipe, textLocaleSignal } from "./inject-text.js";
|
|
15
|
+
export { injectAppearance } from "./inject-appearance.js";
|
|
16
|
+
export { configureFieldErrorText, configureTranslatedText, fieldErrorText, resolveText, syncDocumentLocale, textDirection, windowLocale, } from "@runic-artifex/views";
|
|
17
|
+
export { appearance, onAppearance, } from "@runic-artifex/views";
|
|
16
18
|
export { onBridgeConnection } from "@runic-artifex/views";
|
|
17
19
|
// blobs/1: uploads from the page and the blob values of state.
|
|
18
20
|
export { upload } from "@runic-artifex/views";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Injector, type Signal } from "@angular/core";
|
|
2
|
+
import { type Appearance } from "@runic-artifex/views";
|
|
3
|
+
/** Options of {@link injectAppearance}. */
|
|
4
|
+
export interface InjectAppearanceOptions {
|
|
5
|
+
/** The injector to use outside an injection context. */
|
|
6
|
+
readonly injector?: Injector;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The page's appearance (`appearance` from `@runic-artifex/views`) as a signal for the lifetime of the injection
|
|
10
|
+
* context: the colour scheme, contrast and reduced motion of the page's engine combined with the desktop's values that a
|
|
11
|
+
* Runic host pushes (`appearance/1`), which also carry the text scale, the accent colour and the forced-colours palette.
|
|
12
|
+
* Every member is `null` under server rendering.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* readonly appearance = injectAppearance();
|
|
16
|
+
* readonly animate = computed(() => this.appearance().reducedMotion !== true);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function injectAppearance({ injector: provided }?: InjectAppearanceOptions): Signal<Appearance>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, inject, Injector, PLATFORM_ID, signal } from "@angular/core";
|
|
2
|
+
import { appearance, onAppearance, unknownAppearance } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* The page's appearance (`appearance` from `@runic-artifex/views`) as a signal for the lifetime of the injection
|
|
5
|
+
* context: the colour scheme, contrast and reduced motion of the page's engine combined with the desktop's values that a
|
|
6
|
+
* Runic host pushes (`appearance/1`), which also carry the text scale, the accent colour and the forced-colours palette.
|
|
7
|
+
* Every member is `null` under server rendering.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* readonly appearance = injectAppearance();
|
|
11
|
+
* readonly animate = computed(() => this.appearance().reducedMotion !== true);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function injectAppearance({ injector: provided } = {}) {
|
|
15
|
+
if (!provided)
|
|
16
|
+
assertInInjectionContext(injectAppearance);
|
|
17
|
+
const injector = provided ?? inject(Injector);
|
|
18
|
+
if (injector.get(PLATFORM_ID, null) === "server")
|
|
19
|
+
return signal(unknownAppearance).asReadonly();
|
|
20
|
+
const current = signal(appearance(), /* @ts-ignore */
|
|
21
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
22
|
+
const stop = onAppearance(next => current.set(next));
|
|
23
|
+
injector.get(DestroyRef).onDestroy(stop);
|
|
24
|
+
current.set(appearance());
|
|
25
|
+
return current.asReadonly();
|
|
26
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Injector, type OnDestroy, type PipeTransform, type Signal } from "@angular/core";
|
|
2
|
-
import { type TextReference } from "@runic-artifex/views";
|
|
2
|
+
import { type FieldError, 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. */
|
|
@@ -11,6 +11,7 @@ export interface InjectTextOptions {
|
|
|
11
11
|
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
12
12
|
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
13
13
|
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
14
|
+
* A field's `FieldError` shows the application's text for it (`configureFieldErrorText`), or its English message.
|
|
14
15
|
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
15
16
|
*
|
|
16
17
|
* ```ts
|
|
@@ -18,23 +19,36 @@ export interface InjectTextOptions {
|
|
|
18
19
|
* // <p>{{ status() }}</p>
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
export declare function injectText(source: () => TextReference | string | null | undefined, fallback?: () => string | undefined, { injector: provided }?: InjectTextOptions): Signal<string>;
|
|
22
|
+
export declare function injectText(source: () => TextReference | FieldError | string | null | undefined, fallback?: () => string | undefined, { injector: provided }?: InjectTextOptions): Signal<string>;
|
|
22
23
|
/**
|
|
23
24
|
* The window's locale that the application set, or `null` while it sets none, as a signal for the lifetime of the
|
|
24
25
|
* injection context, for example to bind `lang`.
|
|
25
26
|
*/
|
|
26
27
|
export declare function injectWindowLocale({ injector: provided }?: InjectTextOptions): Signal<string | null>;
|
|
28
|
+
/**
|
|
29
|
+
* The locale that text is shown in (`textLocale`: the page's Translations locale, which follows the window's locale),
|
|
30
|
+
* as a signal. It is one signal for the page and needs no injection context, so the page's locale resolver can read
|
|
31
|
+
* it: a template that calls `m.*()` reads the signal through the resolver and renders again on a language switch.
|
|
32
|
+
* `undefined` while the page has no Translations runtime and the application sets no window locale.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const textLocale = textLocaleSignal();
|
|
36
|
+
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function textLocaleSignal(): Signal<string | undefined>;
|
|
27
40
|
/**
|
|
28
41
|
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
29
42
|
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
30
|
-
* `null` and `undefined` show the fallback argument
|
|
43
|
+
* `null` and `undefined` show the fallback argument; a field's error, `{{ name.error() | runicText }}`, the application's
|
|
44
|
+
* text for it (`configureFieldErrorText`). The pipe is impure so that it sees a language switch; it formats
|
|
31
45
|
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
32
46
|
*/
|
|
33
47
|
export declare class RunicTextPipe implements PipeTransform, OnDestroy {
|
|
34
48
|
private readonly changes;
|
|
35
49
|
private readonly stop;
|
|
36
50
|
private last;
|
|
37
|
-
transform(value: TextReference | string | null | undefined, fallback?: string): string;
|
|
51
|
+
transform(value: TextReference | FieldError | string | null | undefined, fallback?: string): string;
|
|
38
52
|
ngOnDestroy(): void;
|
|
39
53
|
static ɵfac: i0.ɵɵFactoryDeclaration<RunicTextPipe, never>;
|
|
40
54
|
static ɵpipe: i0.ɵɵPipeDeclaration<RunicTextPipe, "runicText", true>;
|
package/dist/esm/inject-text.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertInInjectionContext, ChangeDetectorRef, computed, DestroyRef, inject, Injector, Pipe, PLATFORM_ID, signal, } from "@angular/core";
|
|
2
|
-
import { onWindowLocale, resolveText, subscribeText, textVersion, windowLocale } from "@runic-artifex/views";
|
|
2
|
+
import { onWindowLocale, resolveText, subscribeText, textLocale, textVersion, windowLocale, } from "@runic-artifex/views";
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
/**
|
|
5
5
|
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
@@ -7,6 +7,7 @@ import * as i0 from "@angular/core";
|
|
|
7
7
|
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
8
8
|
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
9
9
|
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
10
|
+
* A field's `FieldError` shows the application's text for it (`configureFieldErrorText`), or its English message.
|
|
10
11
|
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
11
12
|
*
|
|
12
13
|
* ```ts
|
|
@@ -45,10 +46,31 @@ export function injectWindowLocale({ injector: provided } = {}) {
|
|
|
45
46
|
}
|
|
46
47
|
return locale.asReadonly();
|
|
47
48
|
}
|
|
49
|
+
let pageTextLocale;
|
|
50
|
+
/**
|
|
51
|
+
* The locale that text is shown in (`textLocale`: the page's Translations locale, which follows the window's locale),
|
|
52
|
+
* as a signal. It is one signal for the page and needs no injection context, so the page's locale resolver can read
|
|
53
|
+
* it: a template that calls `m.*()` reads the signal through the resolver and renders again on a language switch.
|
|
54
|
+
* `undefined` while the page has no Translations runtime and the application sets no window locale.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const textLocale = textLocaleSignal();
|
|
58
|
+
* configureLocaleResolver(() => textLocale() ?? locale.getLocale());
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function textLocaleSignal() {
|
|
62
|
+
if (pageTextLocale)
|
|
63
|
+
return pageTextLocale;
|
|
64
|
+
const current = signal(textLocale(), /* @ts-ignore */
|
|
65
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
66
|
+
subscribeText(() => current.set(textLocale()));
|
|
67
|
+
return pageTextLocale = current.asReadonly();
|
|
68
|
+
}
|
|
48
69
|
/**
|
|
49
70
|
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
50
71
|
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
51
|
-
* `null` and `undefined` show the fallback argument
|
|
72
|
+
* `null` and `undefined` show the fallback argument; a field's error, `{{ name.error() | runicText }}`, the application's
|
|
73
|
+
* text for it (`configureFieldErrorText`). The pipe is impure so that it sees a language switch; it formats
|
|
52
74
|
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
53
75
|
*/
|
|
54
76
|
export class RunicTextPipe {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { type InputSignal, type TemplateRef, type Type } from "@angular/core";
|
|
2
|
-
import { type PageReference, type RegionCollection, type RegionEntry } from "@runic-artifex/views";
|
|
2
|
+
import { type PageReference, type RegionCollection, type RegionEntry, type ViewRegistryPage } from "@runic-artifex/views";
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
/**
|
|
5
5
|
* A build-known map checks each generated reference against its component input. A nullable
|
|
6
|
-
* reference, such as a region slot's `State["main"]`, checks its non-null kinds.
|
|
6
|
+
* reference, such as a region slot's `State["main"]`, checks its non-null kinds. A component whose `page` input is a
|
|
7
|
+
* shared page reference (`[RunicSharedClient]`), such as `ResultPagePageReference`, registers for each of its kinds.
|
|
7
8
|
*/
|
|
8
9
|
export type ViewRegistry<R extends PageReference | null | undefined> = {
|
|
9
|
-
readonly [K in NonNullable<R>["kind"]]:
|
|
10
|
-
readonly page: InputSignal<Extract<NonNullable<R>, {
|
|
11
|
-
readonly kind: K;
|
|
12
|
-
}>>;
|
|
13
|
-
}>;
|
|
10
|
+
readonly [K in NonNullable<R>["kind"]]: PageComponent<ViewRegistryPage<R, K>>;
|
|
14
11
|
};
|
|
12
|
+
type PageComponent<P> = P extends unknown ? Type<{
|
|
13
|
+
readonly page: InputSignal<P>;
|
|
14
|
+
}> : never;
|
|
15
15
|
/** The context of a `missing` template: the reference without a component, as `$implicit` (`let-page`) and `content`. */
|
|
16
16
|
export interface ViewOutletMissingContext<R extends PageReference = PageReference> {
|
|
17
17
|
readonly $implicit: R;
|
|
@@ -20,7 +20,9 @@ export interface ViewOutletMissingContext<R extends PageReference = PageReferenc
|
|
|
20
20
|
/**
|
|
21
21
|
* Headless host for a selected logical .NET View. A changed reference remounts its component, and
|
|
22
22
|
* the projected content renders while there is no reference. A kind without a component renders
|
|
23
|
-
* the `missing` template, for example localized text,
|
|
23
|
+
* the `missing` template, for example localized text. Without it, a development build (`isDevMode()`) renders an
|
|
24
|
+
* English alert, and a production build renders nothing and reports the kind (`installErrorReporting`,
|
|
25
|
+
* `onBridgeDiagnostic`):
|
|
24
26
|
*
|
|
25
27
|
* ```html
|
|
26
28
|
* <runic-view-outlet [content]="state()?.main" [registry]="pages" [missing]="missingView" />
|
|
@@ -32,7 +34,7 @@ export interface ViewOutletMissingContext<R extends PageReference = PageReferenc
|
|
|
32
34
|
export declare class ViewOutlet<R extends PageReference = PageReference> {
|
|
33
35
|
readonly content: InputSignal<R | null | undefined>;
|
|
34
36
|
readonly registry: InputSignal<ViewRegistry<R>>;
|
|
35
|
-
/** Renders a reference whose kind has no registered component instead of the
|
|
37
|
+
/** Renders a reference whose kind has no registered component instead of the development alert. */
|
|
36
38
|
readonly missing: InputSignal<TemplateRef<ViewOutletMissingContext<R>> | undefined>;
|
|
37
39
|
readonly error: import("@angular/core").WritableSignal<string | undefined>;
|
|
38
40
|
private readonly mount;
|
|
@@ -96,3 +98,4 @@ export declare const RunicViewOutlet: typeof ViewOutlet;
|
|
|
96
98
|
* @deprecated Import `ViewOutlet` instead; this alias is removed in the next major release.
|
|
97
99
|
*/
|
|
98
100
|
export type RunicViewOutlet<R extends PageReference = PageReference> = ViewOutlet<R>;
|
|
101
|
+
export {};
|
package/dist/esm/view-outlet.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { Component, computed, Directive, effect, ElementRef, inject, input, Renderer2, signal, untracked, viewChild, ViewContainerRef, } from "@angular/core";
|
|
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
|
+
import { missingViewMessage, reportMissingView } from "@runic-artifex/views/bindings";
|
|
3
4
|
import * as i0 from "@angular/core";
|
|
4
5
|
// Projected content renders while there is no reference, like React's `fallback`, Vue's default slot
|
|
5
6
|
// and Svelte's `fallback` snippet: `<runic-view-outlet [content]="…" [registry]="…">Loading…</runic-view-outlet>`.
|
|
6
7
|
/**
|
|
7
8
|
* Headless host for a selected logical .NET View. A changed reference remounts its component, and
|
|
8
9
|
* the projected content renders while there is no reference. A kind without a component renders
|
|
9
|
-
* the `missing` template, for example localized text,
|
|
10
|
+
* the `missing` template, for example localized text. Without it, a development build (`isDevMode()`) renders an
|
|
11
|
+
* English alert, and a production build renders nothing and reports the kind (`installErrorReporting`,
|
|
12
|
+
* `onBridgeDiagnostic`):
|
|
10
13
|
*
|
|
11
14
|
* ```html
|
|
12
15
|
* <runic-view-outlet [content]="state()?.main" [registry]="pages" [missing]="missingView" />
|
|
@@ -20,7 +23,7 @@ export class ViewOutlet {
|
|
|
20
23
|
...(ngDevMode ? [undefined, { debugName: "content" }] : /* istanbul ignore next */ []));
|
|
21
24
|
registry = input.required(/* @ts-ignore */
|
|
22
25
|
...(ngDevMode ? [{ debugName: "registry" }] : /* istanbul ignore next */ []));
|
|
23
|
-
/** Renders a reference whose kind has no registered component instead of the
|
|
26
|
+
/** Renders a reference whose kind has no registered component instead of the development alert. */
|
|
24
27
|
missing = input(/* @ts-ignore */
|
|
25
28
|
...(ngDevMode ? [undefined, { debugName: "missing" }] : /* istanbul ignore next */ []));
|
|
26
29
|
error = signal(undefined, /* @ts-ignore */
|
|
@@ -52,7 +55,10 @@ export class ViewOutlet {
|
|
|
52
55
|
container.createEmbeddedView(selection.missing, { $implicit: selection.reference, content: selection.reference });
|
|
53
56
|
return;
|
|
54
57
|
}
|
|
55
|
-
|
|
58
|
+
if (isDevMode())
|
|
59
|
+
this.error.set(missingViewMessage(selection.reference.kind));
|
|
60
|
+
else
|
|
61
|
+
reportMissingView(selection.reference.kind);
|
|
56
62
|
return;
|
|
57
63
|
}
|
|
58
64
|
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.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"@angular/core": ">=22.0.0 <23",
|
|
20
20
|
"@angular/forms": ">=22.0.0 <23",
|
|
21
|
-
"@runic-artifex/views": "0.
|
|
21
|
+
"@runic-artifex/views": "0.17.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependenciesMeta": {
|
|
24
24
|
"@angular/forms": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
|
|
33
33
|
"directory": "packages/web/angular"
|
|
34
34
|
},
|
|
35
|
-
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
35
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.17.0/packages/web/angular#readme",
|
|
36
36
|
"bugs": {
|
|
37
37
|
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
38
38
|
},
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"pack:check": "bun pm pack --dry-run"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@runic-artifex/views": "0.
|
|
59
|
+
"@runic-artifex/views": "0.17.0",
|
|
60
60
|
"@angular/common": "22.2.3",
|
|
61
61
|
"@angular/compiler": "22.2.3",
|
|
62
62
|
"@angular/compiler-cli": "22.2.3",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"typescript": "6.0.3",
|
|
70
70
|
"vitest": "5.0.3"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "daeb17e5c3fb0b625d5d988d359cd12ffa51f8c6"
|
|
73
73
|
}
|