@runic-artifex/angular 0.15.0 → 0.16.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 +184 -13
- package/dist/esm/index.d.ts +9 -1
- package/dist/esm/index.js +10 -1
- package/dist/esm/inject-field.d.ts +4 -2
- package/dist/esm/inject-field.js +1 -0
- package/dist/esm/inject-form.d.ts +40 -0
- package/dist/esm/inject-form.js +48 -0
- package/dist/esm/inject-query-collection.d.ts +29 -0
- package/dist/esm/inject-query-collection.js +64 -0
- package/dist/esm/inject-text.d.ts +41 -0
- package/dist/esm/inject-text.js +76 -0
- package/dist/esm/view-outlet.d.ts +44 -1
- package/dist/esm/view-outlet.js +87 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -18,7 +18,9 @@ match your Runic SDK packages. Angular 22 is supported.
|
|
|
18
18
|
`injectView(source)` connects a generated page reference, or
|
|
19
19
|
`{ connect: connect<Name> }` for a root ViewModel, for the lifetime of the
|
|
20
20
|
injection context and returns `state`, `client`, `error` and `pending`
|
|
21
|
-
signals and `retry()
|
|
21
|
+
signals and `retry()`. Each is its own signal: `client` stays the same object
|
|
22
|
+
for the connection, so an `effect` that reads only `client()` does not run
|
|
23
|
+
again when the View's state changes.
|
|
22
24
|
|
|
23
25
|
```ts
|
|
24
26
|
import { Component, input } from "@angular/core";
|
|
@@ -138,7 +140,7 @@ export class CounterPage {
|
|
|
138
140
|
|
|
139
141
|
Bind a text input to a member with `injectTextField(view, read, write, options?)`,
|
|
140
142
|
which wraps the framework-neutral
|
|
141
|
-
[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.16.0/packages/web/views#text-inputs)
|
|
142
144
|
for the lifetime of the injection context:
|
|
143
145
|
|
|
144
146
|
```ts
|
|
@@ -181,7 +183,7 @@ text at once and hides the race.
|
|
|
181
183
|
|
|
182
184
|
For generated Views prefer `injectField(view, field, options?)`: pass a descriptor of the
|
|
183
185
|
generated `{View}Fields`, such as `EditorFields.title`. It wraps the framework-neutral
|
|
184
|
-
[field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
186
|
+
[field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#fields)
|
|
185
187
|
for every kind (text, numbers, booleans, enums) and returns signals and actions:
|
|
186
188
|
|
|
187
189
|
- `value`, `text` (what a text input shows: `1.` stays while typing `1.5`), `editing`,
|
|
@@ -237,6 +239,26 @@ with a `FieldError`. `errors` follows the member's validation in the View's stat
|
|
|
237
239
|
}
|
|
238
240
|
```
|
|
239
241
|
|
|
242
|
+
### Row cells and nested members
|
|
243
|
+
|
|
244
|
+
Since 0.16, `InvoiceFields.address.street` and `InvoiceFields.lines.at(line.id).quantity` are fields too
|
|
245
|
+
(`field-paths/1`): a member of an object member, and a cell of a row that .NET edits with `[RunicRowEditor]`. Call
|
|
246
|
+
`injectField(view, InvoiceFields.lines.at(line.id).quantity)` in the row's component, or bind it with
|
|
247
|
+
`[runicField]`; `at(key)` returns the same descriptor for the same key. Such a field always writes checked, conflicts
|
|
248
|
+
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.16.0/packages/web/angular/../views/README.md#fields-below-a-member-and-row-cells).
|
|
250
|
+
|
|
251
|
+
### Forms: `injectForm(fields, options?)`
|
|
252
|
+
|
|
253
|
+
Signals over `injectField` handles (`dirty`, `editing`, `validating`, `pending`, `valid`, `submitting`, `state`), and a
|
|
254
|
+
`submit` that writes every field before its command (`createFormController` in `@runic-artifex/views`). It needs no
|
|
255
|
+
injection context.
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
readonly form = injectForm({ title: this.title, step: this.step }, { dirty: computed(() => this.editor.state()?.isDirty === true) });
|
|
259
|
+
// <button [disabled]="!form.valid() || form.submitting()" (click)="form.submit(() => editor.client()!.save())">Save</button>
|
|
260
|
+
```
|
|
261
|
+
|
|
240
262
|
### `[runicField]` and Reactive Forms
|
|
241
263
|
|
|
242
264
|
`@runic-artifex/angular/forms` needs `@angular/forms` (an optional peer; the main
|
|
@@ -366,6 +388,74 @@ whose kind has no component as `$implicit` and as `content`, and its markup
|
|
|
366
388
|
<ng-template #missingView let-page><p role="alert">{{ missingText(page.kind) }}</p></ng-template>
|
|
367
389
|
```
|
|
368
390
|
|
|
391
|
+
### Region collections
|
|
392
|
+
|
|
393
|
+
A .NET `[RunicRegionCollection]` member, such as `state.documents`, lists
|
|
394
|
+
regions that each keep their own back stack. `<runic-region-outlets>`
|
|
395
|
+
(`RegionOutlets`) renders a `ViewOutlet` for each region, tracked by the
|
|
396
|
+
region's key, inside a `<div data-region-key>`. The default
|
|
397
|
+
`mode="keep-mounted"` keeps every region mounted and sets `hidden` and an inline
|
|
398
|
+
`display: none` on all but the selected one, so a tab keeps its component,
|
|
399
|
+
scroll position and unsent input. Author CSS cannot show a hidden panel without
|
|
400
|
+
`!important`. `mode="selected"` renders only the selected region. Projected
|
|
401
|
+
content renders while there is no region, and `missing` is passed to each
|
|
402
|
+
outlet. A region with `content: null` renders nothing.
|
|
403
|
+
|
|
404
|
+
The package has no tab bar. Build one with `regionEntries` and the generated
|
|
405
|
+
`selectDocuments(key)` and `closeDocuments(key)`. The `panelProps` input is a function that returns attributes
|
|
406
|
+
(`RegionPanelAttributes`) for each region's wrapper, such as `id`,
|
|
407
|
+
`role="tabpanel"` and `aria-labelledby`, so each tab can name its panel in
|
|
408
|
+
`aria-controls`. A `null` value leaves an attribute out. `hidden`, `style` and
|
|
409
|
+
`data-region-key` stay controlled by the outlet and are ignored.
|
|
410
|
+
|
|
411
|
+
```html
|
|
412
|
+
<div role="tablist">
|
|
413
|
+
@for (tab of tabs(); track tab.key) {
|
|
414
|
+
<button [id]="tabId(tab.key)" role="tab" [attr.aria-selected]="tab.selected" [attr.aria-controls]="panelId(tab.key)"
|
|
415
|
+
(click)="client()?.selectDocuments(tab.key)">
|
|
416
|
+
{{ tab.content?.kind ?? "Empty" }}
|
|
417
|
+
</button>
|
|
418
|
+
<button aria-label="Close" (click)="close(tab.key)">×</button>
|
|
419
|
+
}
|
|
420
|
+
</div>
|
|
421
|
+
<runic-region-outlets [collection]="state()?.documents" [registry]="documentPages" [panelProps]="panel">
|
|
422
|
+
No open documents
|
|
423
|
+
</runic-region-outlets>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
```ts
|
|
427
|
+
readonly tabs = computed(() => regionEntries(this.state()?.documents));
|
|
428
|
+
readonly tabId = (key: string) => `document-tab-${key}`;
|
|
429
|
+
readonly panelId = (key: string) => `document-panel-${key}`;
|
|
430
|
+
readonly panel = (tab: RegionEntry<DocumentReference>): RegionPanelAttributes =>
|
|
431
|
+
({ id: this.panelId(tab.key), role: "tabpanel", "aria-labelledby": this.tabId(tab.key) });
|
|
432
|
+
private readonly injector = inject(Injector);
|
|
433
|
+
|
|
434
|
+
async close(key: string) {
|
|
435
|
+
if ((await this.client()?.closeDocuments(key))?.kind !== "Committed") return;
|
|
436
|
+
afterNextRender(() => {
|
|
437
|
+
const selected = selectedRegion(this.state()?.documents);
|
|
438
|
+
if (selected) document.getElementById(this.tabId(selected.key))?.focus();
|
|
439
|
+
}, { injector: this.injector });
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
`selected` changes only when a switch or close commits. A departure guard can
|
|
444
|
+
keep the current tab, so highlight `selected` and do not move the highlight
|
|
445
|
+
before the request settles. `select…` and `close…` resolve to the .NET
|
|
446
|
+
`NavigationOutcome`, such as `{ kind: "Rejected", rejection: "Guard" }`.
|
|
447
|
+
|
|
448
|
+
Closing the selected tab removes its button, and the next tab becomes selected
|
|
449
|
+
when the close commits. After `closeDocuments` resolves with `kind: "Committed"`,
|
|
450
|
+
move focus to the button of the new selected tab, as `close` above does.
|
|
451
|
+
|
|
452
|
+
In both modes the region collection keeps presenting every region's content,
|
|
453
|
+
so the pages of hidden tabs stay live and still receive state. `"selected"`
|
|
454
|
+
mode only unmounts the components of the regions that are not selected.
|
|
455
|
+
|
|
456
|
+
`regionEntries`, `selectedRegion` and the region types are re-exported from
|
|
457
|
+
`@runic-artifex/views`.
|
|
458
|
+
|
|
369
459
|
## Commands
|
|
370
460
|
|
|
371
461
|
`injectCommand(command)` returns `run(...args)` and `pending`, `error` and
|
|
@@ -393,14 +483,14 @@ For example, a navigation command whose departure guard awaits a dialog's
|
|
|
393
483
|
answer never completes while the answer waits behind it. Order such commands
|
|
394
484
|
by dispatch instead: start the next one once the previous one has been sent,
|
|
395
485
|
as the Notes example's
|
|
396
|
-
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
486
|
+
[`WindowOperations.runDispatched`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/examples/notes-view-first/Angular/src/app/window-operations.ts)
|
|
397
487
|
does for its navigation commands.
|
|
398
488
|
|
|
399
489
|
## Operations
|
|
400
490
|
|
|
401
491
|
`injectOperation(start, options?)` observes a generated `start<Command>()` operation
|
|
402
492
|
through the framework-neutral
|
|
403
|
-
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
493
|
+
[operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#operation-feedback-and-latest-selection)
|
|
404
494
|
for the lifetime of the injection context:
|
|
405
495
|
|
|
406
496
|
```ts
|
|
@@ -426,7 +516,7 @@ context.
|
|
|
426
516
|
|
|
427
517
|
`injectLatestOperation(options?)` admits only the newest of several reads, for example
|
|
428
518
|
loading the item the user selected last, through the framework-neutral
|
|
429
|
-
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
519
|
+
[latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#operation-feedback-and-latest-selection).
|
|
430
520
|
Each `run(intent)` replaces the queued intent and cancels the active read; the next
|
|
431
521
|
read starts only after the previous one reaches its terminal status and the intent's
|
|
432
522
|
optional `waitForCompletion` barrier:
|
|
@@ -458,7 +548,7 @@ from `@runic-artifex/views` (re-exported here since 0.11, with the
|
|
|
458
548
|
`BridgeConnectionState` and `BridgeConnectionOptions` types) and returns `{ state }`, a signal of a
|
|
459
549
|
`BridgeConnectionState`: `connecting`, `connected`, `reconnecting`, `lost` or `closed` (the
|
|
460
550
|
application closed the window, since 0.15; a closed set, see
|
|
461
|
-
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
551
|
+
[Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#connection-state)):
|
|
462
552
|
|
|
463
553
|
```ts
|
|
464
554
|
import { injectBridgeConnection } from "@runic-artifex/angular";
|
|
@@ -476,7 +566,7 @@ not observe and stays `connecting`. An invalid `lostAfter` throws a `RangeError`
|
|
|
476
566
|
`injectMenuBar(options?)` follows the declared menu bar of a Runic Desktop
|
|
477
567
|
window that leaves it to the page (`DesktopMenuBarPresentation.Page`) for the
|
|
478
568
|
lifetime of the injection context. It wraps `createMenuBarController` from
|
|
479
|
-
`@runic-artifex/views` (see [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
569
|
+
`@runic-artifex/views` (see [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#in-page-menu-bar))
|
|
480
570
|
and returns `{ state, invoke, handleKeyDown }`, where `state` is a signal of a
|
|
481
571
|
`MenuBarState`. The bar is rendered by the application's own menubar, for
|
|
482
572
|
example the CDK Menu's `cdkMenuBar`. Runic ships no menubar component.
|
|
@@ -501,7 +591,7 @@ it creates none and stays `connecting`.
|
|
|
501
591
|
### With the CDK Menu
|
|
502
592
|
|
|
503
593
|
The CDK's `cdkMenuBar` with `CdkMenuTrigger.open()` for `open` requests; the
|
|
504
|
-
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
594
|
+
[Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/examples/notes-view-first#in-page-menu-bar) adds submenus, check and radio
|
|
505
595
|
items (`cdkMenuItemCheckbox`, `cdkMenuItemRadio` in a `cdkMenuGroup`) and is
|
|
506
596
|
tested with real keys:
|
|
507
597
|
|
|
@@ -550,6 +640,25 @@ export class AppMenuBar {
|
|
|
550
640
|
}
|
|
551
641
|
```
|
|
552
642
|
|
|
643
|
+
## Translated text
|
|
644
|
+
|
|
645
|
+
`injectText(() => source, () => fallback?)` is a signal of a text reference in
|
|
646
|
+
the window's language, and the `runicText` pipe does the same in templates; both
|
|
647
|
+
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.16.0/packages/dotnet/Runic.Application.Views/README.md#translated-text)).
|
|
649
|
+
`injectWindowLocale()` reads the window's locale. The pipe formats again only
|
|
650
|
+
when its value, fallback or the language changed. Under server rendering, call
|
|
651
|
+
`configureTranslatedText` behind `isPlatformBrowser`, or render on the server
|
|
652
|
+
with `resolveTextReference` and the request's locale.
|
|
653
|
+
|
|
654
|
+
```ts
|
|
655
|
+
@Component({
|
|
656
|
+
imports: [RunicTextPipe],
|
|
657
|
+
template: `<p>{{ view.state()?.status | runicText }}</p>
|
|
658
|
+
@for (error of view.state()?.validation.errors; track $index) { <li>{{ error.text | runicText: error.message }}</li> }`,
|
|
659
|
+
})
|
|
660
|
+
```
|
|
661
|
+
|
|
553
662
|
## Errors
|
|
554
663
|
|
|
555
664
|
The `error()` signal of `injectView` and of a command or operation is typed
|
|
@@ -567,7 +676,7 @@ readonly message = computed(() => describeBridgeError(this.view.error()));
|
|
|
567
676
|
```
|
|
568
677
|
|
|
569
678
|
`instanceof` holds for errors from every copy of the package on the page.
|
|
570
|
-
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
679
|
+
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#errors-and-diagnostics)
|
|
571
680
|
lists the kinds. Any other value, such as an exception that your own connect
|
|
572
681
|
function or command callback throws, arrives unchanged.
|
|
573
682
|
|
|
@@ -618,16 +727,56 @@ application's own dialog.
|
|
|
618
727
|
departure before that is answered by the ViewModel's .NET fallback handler, or
|
|
619
728
|
fails closed without one.
|
|
620
729
|
|
|
621
|
-
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.
|
|
730
|
+
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.16.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
|
|
622
731
|
has the .NET side and which View answers which departure. In a frontend test,
|
|
623
732
|
the generated mock's `interactions.<name>.request(input)` resolves with the
|
|
624
|
-
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
733
|
+
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#testing).
|
|
734
|
+
|
|
735
|
+
## View requests
|
|
736
|
+
|
|
737
|
+
A `ViewRequest<T>` property of the ViewModel asks the View for a one-way
|
|
738
|
+
presentation action, such as focusing a field or showing a toast, and is
|
|
739
|
+
`client.requests.<name>` on the generated client. Register the page's
|
|
740
|
+
handler in an `effect`: `handle((input, { signal }) => …)` returns the function
|
|
741
|
+
that removes it, so pass that to `onCleanup`, and Angular removes the handler
|
|
742
|
+
when the client changes or the component is destroyed:
|
|
743
|
+
|
|
744
|
+
```ts
|
|
745
|
+
import { Component, effect, ElementRef, input, viewChild } from "@angular/core";
|
|
746
|
+
import { injectView } from "@runic-artifex/angular";
|
|
747
|
+
import type { EditPageReference } from "./generated/edit";
|
|
748
|
+
|
|
749
|
+
@Component({ selector: "edit-page", template: `<input #name>` })
|
|
750
|
+
export class EditPage {
|
|
751
|
+
readonly page = input.required<EditPageReference>();
|
|
752
|
+
readonly view = injectView(this.page);
|
|
753
|
+
readonly name = viewChild<ElementRef<HTMLInputElement>>("name");
|
|
754
|
+
|
|
755
|
+
constructor() {
|
|
756
|
+
effect(onCleanup => {
|
|
757
|
+
const remove = this.view.client()?.requests.focus.handle(({ member }) => {
|
|
758
|
+
if (member === "name") this.name()?.nativeElement.focus();
|
|
759
|
+
});
|
|
760
|
+
if (remove) onCleanup(remove);
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
`input` is typed from the request's `ViewRequest<T>`. The handler runs once
|
|
767
|
+
the page painted the state the request was raised with, so the field of that
|
|
768
|
+
state is rendered; `signal` aborts when the handler is replaced or removed, the
|
|
769
|
+
client is disposed or the connection is lost. A request is never replayed: one
|
|
770
|
+
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.16.0/packages/web/views#view-requests) for the rules, and in a frontend
|
|
772
|
+
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.16.0/packages/web/views#testing)).
|
|
625
774
|
|
|
626
775
|
## Collection viewports
|
|
627
776
|
|
|
628
777
|
`injectCollectionViewport(element, options)` follows a fixed-row-height scroll
|
|
629
778
|
container and returns a signal with its
|
|
630
|
-
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
779
|
+
[`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#collectionviewportoptions)
|
|
631
780
|
range. Pass the container as a signal, such as a `viewChild`, and the options as
|
|
632
781
|
a function or signal, then send the range to the ViewModel from an effect:
|
|
633
782
|
|
|
@@ -655,3 +804,25 @@ export class RowsPage {
|
|
|
655
804
|
}
|
|
656
805
|
}
|
|
657
806
|
```
|
|
807
|
+
|
|
808
|
+
## Query collections
|
|
809
|
+
|
|
810
|
+
`injectQueryCollection(element, collection, options)` follows a scroll container for a
|
|
811
|
+
[query collection](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#query-collections) (`client.queries.{name}`), whose rows stay in .NET: it loads the rows the container shows,
|
|
812
|
+
with placeholders until they arrive, and lays them out with variable heights. `viewport` is a signal of the
|
|
813
|
+
`QueryViewport` (`items` with `top` and `size`, `totalSize`, `total`, `query`, `loading`, `error`); `observe(element,
|
|
814
|
+
index)` measures a rendered row, and `scrollToKey`, `scrollToIndex`, `setQuery` and `retry` act on the collection.
|
|
815
|
+
|
|
816
|
+
```ts
|
|
817
|
+
readonly list = injectQueryCollection(viewChild<ElementRef<HTMLElement>>("scroller"),
|
|
818
|
+
() => this.view.client()?.queries.rows, () => ({ estimateSize: 32 }));
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
## Back and the URL
|
|
822
|
+
|
|
823
|
+
The package re-exports `installBackNavigation`, `installNavigationPath`,
|
|
824
|
+
`navigateBack`, `openNavigationPath` and `onNavigationPath` from
|
|
825
|
+
`@runic-artifex/views` (since 0.16). Call the installs once where the page
|
|
826
|
+
starts, before or after mounting: the mouse's Back button and Alt+Left then go
|
|
827
|
+
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.16.0/packages/web/views/README.md#back-and-the-url).
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
export { ViewOutlet, RunicViewOutlet, type ViewOutletMissingContext, type ViewRegistry } from "./view-outlet.js";
|
|
1
|
+
export { ViewOutlet, RegionOutlets, RunicViewOutlet, type RegionOutletsMode, type RegionPanelAttributes, type ViewOutletMissingContext, type ViewRegistry, } from "./view-outlet.js";
|
|
2
2
|
export { injectView, type InjectViewOptions, type ViewHandle } from "./inject-view.js";
|
|
3
3
|
export { injectViewResource, type InjectViewResourceOptions, type ViewResource } from "./inject-view-resource.js";
|
|
4
4
|
export { injectCommand, type CommandHandle, type InjectCommandOptions } from "./inject-command.js";
|
|
5
5
|
export { injectOperation, type InjectOperationOptions, type OperationHandle } from "./inject-operation.js";
|
|
6
6
|
export { injectField, type FieldHandle, type FieldView, type InjectFieldOptions } from "./inject-field.js";
|
|
7
|
+
export { injectForm, type FormFieldHandle, type FormHandle, type InjectFormOptions } from "./inject-form.js";
|
|
8
|
+
export { commitAllFields, type FormState, type FormSubmitOptions, type FormSubmitResult } from "@runic-artifex/views";
|
|
7
9
|
export { injectTextField, type InjectTextFieldOptions, type TextFieldHandle, type TextFieldView } from "./inject-text-field.js";
|
|
8
10
|
export { injectLatestOperation, type InjectLatestOperationOptions, type LatestOperationHandle, } from "./inject-latest-operation.js";
|
|
9
11
|
export { injectCollectionViewport, type InjectCollectionViewportOptions } from "./inject-collection-viewport.js";
|
|
12
|
+
export { injectQueryCollection, type InjectQueryCollectionOptions, type QueryCollectionHandle } from "./inject-query-collection.js";
|
|
10
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 { configureTranslatedText, resolveText, windowLocale, type TextReference, type TextTranslations, } from "@runic-artifex/views";
|
|
11
16
|
export { onBridgeConnection, type BridgeConnectionOptions, type BridgeConnectionState } from "@runic-artifex/views";
|
|
17
|
+
export { upload, type BlobRef, type RunicBlob, type UploadOptions, type UploadProgress } from "@runic-artifex/views";
|
|
18
|
+
export { regionEntries, selectedRegion, type RegionCollection, type RegionEntry, type RegionOutcome, type RegionSlot, } from "@runic-artifex/views";
|
|
19
|
+
export { installBackNavigation, installNavigationPath, navigateBack, onNavigationPath, openNavigationPath, type NavigationPathChange, type NavigationPathOptions, type NavigationReply, } from "@runic-artifex/views";
|
|
12
20
|
export { injectMenuBar, type InjectMenuBarOptions, type MenuBarEntry, type MenuBarHandle, type MenuBarInvokeResult, type MenuBarItem, type MenuBarMenu, type MenuBarRequest, type MenuBarSeparator, type MenuBarState, } from "./inject-menu-bar.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
export { ViewOutlet, RunicViewOutlet } from "./view-outlet.js";
|
|
1
|
+
export { ViewOutlet, RegionOutlets, RunicViewOutlet, } from "./view-outlet.js";
|
|
2
2
|
export { injectView } from "./inject-view.js";
|
|
3
3
|
export { injectViewResource } from "./inject-view-resource.js";
|
|
4
4
|
export { injectCommand } from "./inject-command.js";
|
|
5
5
|
export { injectOperation } from "./inject-operation.js";
|
|
6
6
|
export { injectField } from "./inject-field.js";
|
|
7
|
+
export { injectForm } from "./inject-form.js";
|
|
8
|
+
export { commitAllFields } from "@runic-artifex/views";
|
|
7
9
|
export { injectTextField } from "./inject-text-field.js";
|
|
8
10
|
export { injectLatestOperation, } from "./inject-latest-operation.js";
|
|
9
11
|
export { injectCollectionViewport } from "./inject-collection-viewport.js";
|
|
12
|
+
export { injectQueryCollection } from "./inject-query-collection.js";
|
|
10
13
|
export { injectBridgeConnection } from "./inject-bridge-connection.js";
|
|
14
|
+
export { injectText, injectWindowLocale, RunicTextPipe } from "./inject-text.js";
|
|
15
|
+
export { configureTranslatedText, resolveText, windowLocale, } from "@runic-artifex/views";
|
|
11
16
|
export { onBridgeConnection } from "@runic-artifex/views";
|
|
17
|
+
// blobs/1: uploads from the page and the blob values of state.
|
|
18
|
+
export { upload } from "@runic-artifex/views";
|
|
19
|
+
export { regionEntries, selectedRegion, } from "@runic-artifex/views";
|
|
20
|
+
export { installBackNavigation, installNavigationPath, navigateBack, onNavigationPath, openNavigationPath, } from "@runic-artifex/views";
|
|
12
21
|
export { injectMenuBar, } from "./inject-menu-bar.js";
|
|
@@ -5,7 +5,7 @@ export interface FieldView<TClient extends ViewClient> {
|
|
|
5
5
|
readonly state: Signal<TClient["snapshot"] | undefined>;
|
|
6
6
|
readonly client: Signal<TClient | undefined>;
|
|
7
7
|
}
|
|
8
|
-
export interface InjectFieldOptions extends FieldOptions {
|
|
8
|
+
export interface InjectFieldOptions<TValue = any> extends FieldOptions<TValue> {
|
|
9
9
|
/** Required outside an injection context. */
|
|
10
10
|
readonly injector?: Injector;
|
|
11
11
|
}
|
|
@@ -27,6 +27,8 @@ export interface FieldHandle<TValue> {
|
|
|
27
27
|
readonly errors: Signal<readonly string[]>;
|
|
28
28
|
/** The producer's value and version while a checked write's `conflict` keeps the draft. */
|
|
29
29
|
readonly conflict: Signal<FieldBaseline<TValue> | undefined>;
|
|
30
|
+
/** The member's validation is in progress, such as an asynchronous rule that is still checking: show "checking…". */
|
|
31
|
+
readonly validating: Signal<boolean>;
|
|
30
32
|
/** The definition's `kind`, `nullable`, `integer` and `choices`. */
|
|
31
33
|
readonly field: FieldController<unknown, unknown, TValue>["field"];
|
|
32
34
|
/** The user changed the value, such as a checkbox's `checked`. */
|
|
@@ -61,4 +63,4 @@ export interface FieldHandle<TValue> {
|
|
|
61
63
|
* // (compositionstart)="title.compositionStart()" (compositionend)="title.compositionEnd($event)">
|
|
62
64
|
* ```
|
|
63
65
|
*/
|
|
64
|
-
export declare function injectField<TClient extends ViewClient, TValue>(view: FieldView<TClient>, field: BridgeField<TClient, TClient["snapshot"], TValue> | FieldDefinition<TClient, TClient["snapshot"], TValue>, { injector: provided, ...options }?: InjectFieldOptions): FieldHandle<TValue>;
|
|
66
|
+
export declare function injectField<TClient extends ViewClient, TValue>(view: FieldView<TClient>, field: BridgeField<TClient, TClient["snapshot"], TValue> | FieldDefinition<TClient, TClient["snapshot"], TValue>, { injector: provided, ...options }?: InjectFieldOptions<TValue>): FieldHandle<TValue>;
|
package/dist/esm/inject-field.js
CHANGED
|
@@ -44,6 +44,7 @@ export function injectField(view, field, { injector: provided, ...options } = {}
|
|
|
44
44
|
error: computed(() => current().error),
|
|
45
45
|
errors: computed(() => current().errors),
|
|
46
46
|
conflict: computed(() => current().conflict),
|
|
47
|
+
validating: computed(() => current().validating),
|
|
47
48
|
field: controller.field,
|
|
48
49
|
input(value) { controller.input(value); },
|
|
49
50
|
inputText(event) { controller.inputText(textOf(event)); },
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Signal } from "@angular/core";
|
|
2
|
+
import { type FormField, type FormFields, type FormState, type FormSubmitOptions, type FormSubmitResult } from "@runic-artifex/views";
|
|
3
|
+
/** A field as {@link injectForm} reads it: an `injectField` handle. */
|
|
4
|
+
export interface FormFieldHandle extends FormField {
|
|
5
|
+
readonly editing: Signal<boolean>;
|
|
6
|
+
readonly validating: Signal<boolean>;
|
|
7
|
+
readonly errors: Signal<readonly string[]>;
|
|
8
|
+
readonly error: Signal<unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface InjectFormOptions {
|
|
11
|
+
/** Whether the View reports unsaved changes, such as `computed(() => this.editor.state()?.isDirty === true)`. */
|
|
12
|
+
readonly dirty?: Signal<boolean | undefined>;
|
|
13
|
+
}
|
|
14
|
+
/** A form bound by {@link injectForm}: its state as signals, and its actions. */
|
|
15
|
+
export interface FormHandle {
|
|
16
|
+
/** The whole state. */
|
|
17
|
+
readonly state: Signal<FormState>;
|
|
18
|
+
readonly dirty: Signal<boolean>;
|
|
19
|
+
readonly editing: Signal<boolean>;
|
|
20
|
+
readonly validating: Signal<boolean>;
|
|
21
|
+
readonly pending: Signal<boolean>;
|
|
22
|
+
readonly valid: Signal<boolean>;
|
|
23
|
+
readonly submitting: Signal<boolean>;
|
|
24
|
+
/** Commits every field, waits for their writes and runs `command` unless a field's write or text failed. */
|
|
25
|
+
submit<T>(command: () => T | PromiseLike<T>, options?: FormSubmitOptions): Promise<FormSubmitResult<T>>;
|
|
26
|
+
/** Commits every field and resolves once their writes settled. */
|
|
27
|
+
commit(): Promise<FormState>;
|
|
28
|
+
/** Resets every field. */
|
|
29
|
+
reset(): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One dirty, pending and valid state over `injectField` handles, and a `submit` that writes every field before its
|
|
33
|
+
* command (`createFormController` in `@runic-artifex/views`). It needs no injection context.
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* readonly form = injectForm({ title: this.title, body: this.body }, { dirty: computed(() => this.editor.state()?.isDirty === true) });
|
|
37
|
+
* // <button [disabled]="!form.valid() || form.submitting()" (click)="form.submit(() => editor.client()!.save())">Save</button>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function injectForm(fields: FormFields<FormFieldHandle>, options?: InjectFormOptions): FormHandle;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { computed, signal } from "@angular/core";
|
|
2
|
+
import { formFieldList, formStateOf, submitFields, } from "@runic-artifex/views";
|
|
3
|
+
/**
|
|
4
|
+
* One dirty, pending and valid state over `injectField` handles, and a `submit` that writes every field before its
|
|
5
|
+
* command (`createFormController` in `@runic-artifex/views`). It needs no injection context.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* readonly form = injectForm({ title: this.title, body: this.body }, { dirty: computed(() => this.editor.state()?.isDirty === true) });
|
|
9
|
+
* // <button [disabled]="!form.valid() || form.submitting()" (click)="form.submit(() => editor.client()!.save())">Save</button>
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function injectForm(fields, options = {}) {
|
|
13
|
+
const list = formFieldList(fields);
|
|
14
|
+
const submitting = signal(false, /* @ts-ignore */
|
|
15
|
+
...(ngDevMode ? [{ debugName: "submitting" }] : /* istanbul ignore next */ []));
|
|
16
|
+
const state = computed(() => formStateOf(list.map(field => ({ editing: field.editing(), validating: field.validating(), errors: field.errors(), error: field.error() })), options.dirty?.() === true, submitting()), /* @ts-ignore */
|
|
17
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
18
|
+
return {
|
|
19
|
+
state,
|
|
20
|
+
dirty: computed(() => state().dirty),
|
|
21
|
+
editing: computed(() => state().editing),
|
|
22
|
+
validating: computed(() => state().validating),
|
|
23
|
+
pending: computed(() => state().pending),
|
|
24
|
+
valid: computed(() => state().valid),
|
|
25
|
+
submitting: computed(() => state().submitting),
|
|
26
|
+
async submit(command, submitOptions = {}) {
|
|
27
|
+
if (submitting())
|
|
28
|
+
return { status: "busy" };
|
|
29
|
+
submitting.set(true);
|
|
30
|
+
const read = (index) => {
|
|
31
|
+
const field = list[index];
|
|
32
|
+
return { editing: field.editing(), error: field.error(), validating: field.validating() };
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
return await submitFields(list, command, submitOptions, read);
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
submitting.set(false);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async commit() {
|
|
42
|
+
await Promise.all(list.map(field => field.commit()));
|
|
43
|
+
return state();
|
|
44
|
+
},
|
|
45
|
+
reset() { for (const field of list)
|
|
46
|
+
field.reset(); },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ElementRef, Injector, type Signal } from "@angular/core";
|
|
2
|
+
import { type QueryCollection, type QueryViewport, type QueryViewportOptions, type RunicQuery } from "@runic-artifex/views";
|
|
3
|
+
export interface InjectQueryCollectionOptions {
|
|
4
|
+
/** Required outside an injection context. */
|
|
5
|
+
readonly injector?: Injector;
|
|
6
|
+
}
|
|
7
|
+
export interface QueryCollectionHandle<TRow> {
|
|
8
|
+
/** The rows to render with their offsets, the spacer's `totalSize`, the total, query, loading and error state. */
|
|
9
|
+
readonly viewport: Signal<QueryViewport<TRow>>;
|
|
10
|
+
/**
|
|
11
|
+
* Measures a rendered row's height until the returned function is called, for example from an `effect` over
|
|
12
|
+
* `viewChildren` of the rows.
|
|
13
|
+
*/
|
|
14
|
+
observe(element: Element | ElementRef<Element>, index: number): () => void;
|
|
15
|
+
/** Scrolls to the row with `key` in the current query; resolves `false` when no row has it. */
|
|
16
|
+
scrollToKey(key: string, align?: "start" | "center" | "end"): Promise<boolean>;
|
|
17
|
+
scrollToIndex(index: number, align?: "start" | "center" | "end"): void;
|
|
18
|
+
/** Changes the collection's sort and filter (ViewModel state every presentation shares). */
|
|
19
|
+
setQuery(query: RunicQuery): Promise<void>;
|
|
20
|
+
/** Loads the range again after a failure. */
|
|
21
|
+
retry(): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Follows a scroll container for a query collection (`client.queries.{name}`): it loads the rows the container shows
|
|
25
|
+
* from .NET, with placeholders until they arrive, and lays them out with variable heights. Pass the container, for
|
|
26
|
+
* example `viewChild<ElementRef<HTMLElement>>("scroller")`, the collection as a function such as
|
|
27
|
+
* `() => view.client()?.queries.rows`, and the options.
|
|
28
|
+
*/
|
|
29
|
+
export declare function injectQueryCollection<TRow>(element: Signal<ElementRef<HTMLElement> | HTMLElement | null | undefined>, collection: () => QueryCollection<TRow> | undefined, options: () => QueryViewportOptions, { injector: provided }?: InjectQueryCollectionOptions): QueryCollectionHandle<TRow>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { assertInInjectionContext, DestroyRef, effect, ElementRef, inject, Injector, NgZone, signal, untracked } from "@angular/core";
|
|
2
|
+
import { createQueryViewportController, } from "@runic-artifex/views";
|
|
3
|
+
const empty = { items: [], totalSize: 0, total: null, query: { sort: [], filters: [] }, loading: false, error: undefined };
|
|
4
|
+
/**
|
|
5
|
+
* Follows a scroll container for a query collection (`client.queries.{name}`): it loads the rows the container shows
|
|
6
|
+
* from .NET, with placeholders until they arrive, and lays them out with variable heights. Pass the container, for
|
|
7
|
+
* example `viewChild<ElementRef<HTMLElement>>("scroller")`, the collection as a function such as
|
|
8
|
+
* `() => view.client()?.queries.rows`, and the options.
|
|
9
|
+
*/
|
|
10
|
+
export function injectQueryCollection(element, collection, options, { injector: provided } = {}) {
|
|
11
|
+
if (!provided)
|
|
12
|
+
assertInInjectionContext(injectQueryCollection);
|
|
13
|
+
const injector = provided ?? inject(Injector);
|
|
14
|
+
const viewport = signal(empty, /* @ts-ignore */
|
|
15
|
+
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
16
|
+
const zone = injector.get(NgZone, null);
|
|
17
|
+
const outside = (run) => zone ? zone.runOutsideAngular(run) : run();
|
|
18
|
+
let controller;
|
|
19
|
+
const container = () => {
|
|
20
|
+
const target = untracked(element);
|
|
21
|
+
return target instanceof ElementRef ? target.nativeElement : target ?? null;
|
|
22
|
+
};
|
|
23
|
+
let release;
|
|
24
|
+
effect(() => {
|
|
25
|
+
const current = collection();
|
|
26
|
+
untracked(() => {
|
|
27
|
+
release?.();
|
|
28
|
+
release = undefined;
|
|
29
|
+
if (!current) {
|
|
30
|
+
viewport.set(empty);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const created = controller = createQueryViewportController(current, options());
|
|
34
|
+
const stop = created.subscribe(() => viewport.set(created.current));
|
|
35
|
+
outside(() => created.attach(container()));
|
|
36
|
+
viewport.set(created.current);
|
|
37
|
+
release = () => { stop(); created.dispose(); if (controller === created)
|
|
38
|
+
controller = undefined; };
|
|
39
|
+
});
|
|
40
|
+
}, { injector });
|
|
41
|
+
effect(() => {
|
|
42
|
+
const { estimateSize, overscan } = options();
|
|
43
|
+
untracked(() => controller?.update({ estimateSize, ...(overscan === undefined ? {} : { overscan }) }));
|
|
44
|
+
}, { injector });
|
|
45
|
+
// Scroll and resize events only update the viewport signal, which schedules change detection itself.
|
|
46
|
+
effect(() => {
|
|
47
|
+
element();
|
|
48
|
+
untracked(() => outside(() => controller?.attach(container())));
|
|
49
|
+
}, { injector });
|
|
50
|
+
injector.get(DestroyRef).onDestroy(() => { release?.(); release = undefined; });
|
|
51
|
+
return {
|
|
52
|
+
viewport: viewport.asReadonly(),
|
|
53
|
+
observe: (target, index) => controller?.observe(target instanceof ElementRef ? target.nativeElement : target, index) ?? (() => { }),
|
|
54
|
+
scrollToKey: async (key, align) => controller ? controller.scrollToKey(key, align) : false,
|
|
55
|
+
scrollToIndex: (index, align) => controller?.scrollToIndex(index, align),
|
|
56
|
+
setQuery: async (query) => {
|
|
57
|
+
const current = untracked(collection);
|
|
58
|
+
if (!current)
|
|
59
|
+
throw new TypeError("injectQueryCollection has no collection yet.");
|
|
60
|
+
await current.setQuery(query);
|
|
61
|
+
},
|
|
62
|
+
retry: () => untracked(collection)?.retry(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Injector, type OnDestroy, type PipeTransform, type Signal } from "@angular/core";
|
|
2
|
+
import { type TextReference } from "@runic-artifex/views";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export interface InjectTextOptions {
|
|
5
|
+
/** Required outside an injection context. */
|
|
6
|
+
readonly injector?: Injector;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
10
|
+
* language (`resolveText`), as a signal that follows a language switch for the lifetime of the injection context.
|
|
11
|
+
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
12
|
+
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
13
|
+
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
14
|
+
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* readonly status = injectText(() => this.view.state()?.status);
|
|
18
|
+
* // <p>{{ status() }}</p>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function injectText(source: () => TextReference | string | null | undefined, fallback?: () => string | undefined, { injector: provided }?: InjectTextOptions): Signal<string>;
|
|
22
|
+
/**
|
|
23
|
+
* The window's locale that the application set, or `null` while it sets none, as a signal for the lifetime of the
|
|
24
|
+
* injection context, for example to bind `lang`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function injectWindowLocale({ injector: provided }?: InjectTextOptions): Signal<string | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
29
|
+
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
30
|
+
* `null` and `undefined` show the fallback argument. The pipe is impure so that it sees a language switch; it formats
|
|
31
|
+
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export declare class RunicTextPipe implements PipeTransform, OnDestroy {
|
|
34
|
+
private readonly changes;
|
|
35
|
+
private readonly stop;
|
|
36
|
+
private last;
|
|
37
|
+
transform(value: TextReference | string | null | undefined, fallback?: string): string;
|
|
38
|
+
ngOnDestroy(): void;
|
|
39
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RunicTextPipe, never>;
|
|
40
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<RunicTextPipe, "runicText", true>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
|
|
6
|
+
* language (`resolveText`), as a signal that follows a language switch for the lifetime of the injection context.
|
|
7
|
+
* `source` and `fallback` are read in a computed signal, so they may read other signals:
|
|
8
|
+
* `injectText(() => view.state()?.status)`. A string shows as it is; `null` and `undefined` show `fallback`. Configure
|
|
9
|
+
* the page's Translations runtime once with `configureTranslatedText`; without one, a reference shows its fallback text.
|
|
10
|
+
* Under server rendering it does not observe a language switch. In templates, the `runicText` pipe does the same.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* readonly status = injectText(() => this.view.state()?.status);
|
|
14
|
+
* // <p>{{ status() }}</p>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export function injectText(source, fallback, { injector: provided } = {}) {
|
|
18
|
+
if (!provided)
|
|
19
|
+
assertInInjectionContext(injectText);
|
|
20
|
+
const injector = provided ?? inject(Injector);
|
|
21
|
+
const version = signal(0, /* @ts-ignore */
|
|
22
|
+
...(ngDevMode ? [{ debugName: "version" }] : /* istanbul ignore next */ []));
|
|
23
|
+
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
24
|
+
const stop = subscribeText(() => version.update(value => value + 1));
|
|
25
|
+
injector.get(DestroyRef).onDestroy(stop);
|
|
26
|
+
}
|
|
27
|
+
return computed(() => {
|
|
28
|
+
version();
|
|
29
|
+
return resolveText(source(), fallback?.());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The window's locale that the application set, or `null` while it sets none, as a signal for the lifetime of the
|
|
34
|
+
* injection context, for example to bind `lang`.
|
|
35
|
+
*/
|
|
36
|
+
export function injectWindowLocale({ injector: provided } = {}) {
|
|
37
|
+
if (!provided)
|
|
38
|
+
assertInInjectionContext(injectWindowLocale);
|
|
39
|
+
const injector = provided ?? inject(Injector);
|
|
40
|
+
const locale = signal(windowLocale(), /* @ts-ignore */
|
|
41
|
+
...(ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []));
|
|
42
|
+
if (injector.get(PLATFORM_ID, null) !== "server") {
|
|
43
|
+
const stop = onWindowLocale(next => locale.set(next));
|
|
44
|
+
injector.get(DestroyRef).onDestroy(stop);
|
|
45
|
+
}
|
|
46
|
+
return locale.asReadonly();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Shows a text reference in the window's language in a template, and marks the view for check when the language
|
|
50
|
+
* changes: `{{ error.text | runicText: error.message }}`, `{{ state.status | runicText }}`. A string shows as it is;
|
|
51
|
+
* `null` and `undefined` show the fallback argument. The pipe is impure so that it sees a language switch; it formats
|
|
52
|
+
* again only when the value, the fallback or the language changed, and returns its last text otherwise.
|
|
53
|
+
*/
|
|
54
|
+
export class RunicTextPipe {
|
|
55
|
+
changes = inject(ChangeDetectorRef);
|
|
56
|
+
stop = subscribeText(() => this.changes.markForCheck());
|
|
57
|
+
last;
|
|
58
|
+
transform(value, fallback) {
|
|
59
|
+
const version = textVersion();
|
|
60
|
+
const last = this.last;
|
|
61
|
+
if (last && last.value === value && last.fallback === fallback && last.version === version)
|
|
62
|
+
return last.text;
|
|
63
|
+
const text = resolveText(value, fallback);
|
|
64
|
+
this.last = { value, fallback, version, text };
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
67
|
+
ngOnDestroy() {
|
|
68
|
+
this.stop();
|
|
69
|
+
}
|
|
70
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
71
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, isStandalone: true, name: "runicText", pure: false });
|
|
72
|
+
}
|
|
73
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RunicTextPipe, decorators: [{
|
|
74
|
+
type: Pipe,
|
|
75
|
+
args: [{ name: "runicText", standalone: true, pure: false }]
|
|
76
|
+
}] });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type InputSignal, type TemplateRef, type Type } from "@angular/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type PageReference, type RegionCollection, type RegionEntry } 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
|
|
@@ -41,6 +41,49 @@ export declare class ViewOutlet<R extends PageReference = PageReference> {
|
|
|
41
41
|
static ɵfac: i0.ɵɵFactoryDeclaration<ViewOutlet<any>, never>;
|
|
42
42
|
static ɵcmp: i0.ɵɵComponentDeclaration<ViewOutlet<any>, "runic-view-outlet", never, { "content": { "alias": "content"; "required": false; "isSignal": true; }; "registry": { "alias": "registry"; "required": true; "isSignal": true; }; "missing": { "alias": "missing"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
|
|
43
43
|
}
|
|
44
|
+
/** How {@link RegionOutlets} renders the regions of a collection. */
|
|
45
|
+
export type RegionOutletsMode = "keep-mounted" | "selected";
|
|
46
|
+
/**
|
|
47
|
+
* Attributes that {@link RegionOutlets} sets on a region's wrapper, such as `id`, `role` and `aria-labelledby`. A
|
|
48
|
+
* `null` or `undefined` value leaves the attribute out. `hidden`, `style` and `data-region-key` stay controlled by
|
|
49
|
+
* the outlet and are ignored here.
|
|
50
|
+
*/
|
|
51
|
+
export type RegionPanelAttributes = Readonly<Record<string, string | null | undefined>>;
|
|
52
|
+
export declare class RegionPanel {
|
|
53
|
+
readonly attributes: InputSignal<Readonly<Record<string, string | null | undefined>> | undefined>;
|
|
54
|
+
constructor();
|
|
55
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RegionPanel, never>;
|
|
56
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RegionPanel, "[runicRegionPanel]", never, { "attributes": { "alias": "runicRegionPanel"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Renders a {@link ViewOutlet} for the regions of a region collection, each in a `<div data-region-key>` tracked by
|
|
60
|
+
* the region's key. A region that is not selected is rendered with `hidden` and an inline `display: none`, which
|
|
61
|
+
* author CSS without `!important` cannot override. A new content reference in a region remounts only that region's
|
|
62
|
+
* component. The projected content renders while the collection has no region, and `missing` is passed to each
|
|
63
|
+
* outlet. `panelProps` returns attributes for each wrapper, so a tab can point `aria-controls` at its panel:
|
|
64
|
+
*
|
|
65
|
+
* ```html
|
|
66
|
+
* <runic-region-outlets [collection]="state()?.documents" [registry]="pages" [panelProps]="panel">No open documents</runic-region-outlets>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* `mode` `"keep-mounted"` (the default) renders every region and hides all but the selected one, so each region
|
|
70
|
+
* keeps its component and DOM. `"selected"` renders only the selected region.
|
|
71
|
+
*/
|
|
72
|
+
export declare class RegionOutlets<R extends PageReference = PageReference> {
|
|
73
|
+
readonly collection: InputSignal<RegionCollection<R> | null | undefined>;
|
|
74
|
+
readonly registry: InputSignal<ViewRegistry<R>>;
|
|
75
|
+
/** Renders a reference whose kind has no registered component instead of the English alert. */
|
|
76
|
+
readonly missing: InputSignal<TemplateRef<ViewOutletMissingContext<R>> | undefined>;
|
|
77
|
+
readonly mode: InputSignal<RegionOutletsMode>;
|
|
78
|
+
/** Returns attributes for a region's wrapper, for example `{ id, role: "tabpanel", "aria-labelledby" }`. */
|
|
79
|
+
readonly panelProps: InputSignal<((entry: RegionEntry<R>) => RegionPanelAttributes) | undefined>;
|
|
80
|
+
protected readonly shown: import("@angular/core").Signal<{
|
|
81
|
+
region: RegionEntry<R>;
|
|
82
|
+
attributes: Readonly<Record<string, string | null | undefined>> | undefined;
|
|
83
|
+
}[]>;
|
|
84
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RegionOutlets<any>, never>;
|
|
85
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RegionOutlets<any>, "runic-region-outlets", never, { "collection": { "alias": "collection"; "required": false; "isSignal": true; }; "registry": { "alias": "registry"; "required": true; "isSignal": true; }; "missing": { "alias": "missing"; "required": false; "isSignal": true; }; "mode": { "alias": "mode"; "required": false; "isSignal": true; }; "panelProps": { "alias": "panelProps"; "required": false; "isSignal": true; }; }, {}, never, ["*"], true, never>;
|
|
86
|
+
}
|
|
44
87
|
/**
|
|
45
88
|
* The name of {@link ViewOutlet} before 0.7.0-preview.7, where React, Vue and Svelte already used
|
|
46
89
|
* `ViewOutlet`. It is the same component class, so it renders the same `<runic-view-outlet>` element
|
package/dist/esm/view-outlet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Component, computed, effect, input, signal, untracked, viewChild, ViewContainerRef } from "@angular/core";
|
|
1
|
+
import { Component, computed, Directive, effect, ElementRef, inject, input, Renderer2, signal, untracked, viewChild, ViewContainerRef, } from "@angular/core";
|
|
2
|
+
import { regionEntries } from "@runic-artifex/views";
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
3
4
|
// Projected content renders while there is no reference, like React's `fallback`, Vue's default slot
|
|
4
5
|
// and Svelte's `fallback` snippet: `<runic-view-outlet [content]="…" [registry]="…">Loading…</runic-view-outlet>`.
|
|
@@ -74,6 +75,91 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImpor
|
|
|
74
75
|
@if (error(); as issue) { <p role="alert">{{ issue }}</p> }
|
|
75
76
|
` }]
|
|
76
77
|
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "content", required: false }] }], registry: [{ type: i0.Input, args: [{ isSignal: true, alias: "registry", required: true }] }], missing: [{ type: i0.Input, args: [{ isSignal: true, alias: "missing", required: false }] }], mount: [{ type: i0.ViewChild, args: ["mount", { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
|
|
78
|
+
const outletAttributes = new Set(["hidden", "style", "data-region-key"]);
|
|
79
|
+
// Sets the attributes of the latest panelProps result on its element and removes the ones it no longer returns.
|
|
80
|
+
export class RegionPanel {
|
|
81
|
+
attributes = input(undefined, { ...(ngDevMode ? { debugName: "attributes" } : /* istanbul ignore next */ {}), alias: "runicRegionPanel" });
|
|
82
|
+
constructor() {
|
|
83
|
+
const element = inject(ElementRef).nativeElement;
|
|
84
|
+
const renderer = inject(Renderer2);
|
|
85
|
+
let applied = new Set();
|
|
86
|
+
effect(() => {
|
|
87
|
+
const set = new Set();
|
|
88
|
+
for (const [name, value] of Object.entries(this.attributes() ?? {})) {
|
|
89
|
+
if (value === null || value === undefined || outletAttributes.has(name.toLowerCase()))
|
|
90
|
+
continue;
|
|
91
|
+
renderer.setAttribute(element, name, value);
|
|
92
|
+
set.add(name);
|
|
93
|
+
}
|
|
94
|
+
for (const name of applied)
|
|
95
|
+
if (!set.has(name))
|
|
96
|
+
renderer.removeAttribute(element, name);
|
|
97
|
+
applied = set;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RegionPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
101
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.3", type: RegionPanel, isStandalone: true, selector: "[runicRegionPanel]", inputs: { attributes: { classPropertyName: "attributes", publicName: "runicRegionPanel", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
102
|
+
}
|
|
103
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RegionPanel, decorators: [{
|
|
104
|
+
type: Directive,
|
|
105
|
+
args: [{ selector: "[runicRegionPanel]", standalone: true }]
|
|
106
|
+
}], ctorParameters: () => [], propDecorators: { attributes: [{ type: i0.Input, args: [{ isSignal: true, alias: "runicRegionPanel", required: false }] }] } });
|
|
107
|
+
/**
|
|
108
|
+
* Renders a {@link ViewOutlet} for the regions of a region collection, each in a `<div data-region-key>` tracked by
|
|
109
|
+
* the region's key. A region that is not selected is rendered with `hidden` and an inline `display: none`, which
|
|
110
|
+
* author CSS without `!important` cannot override. A new content reference in a region remounts only that region's
|
|
111
|
+
* component. The projected content renders while the collection has no region, and `missing` is passed to each
|
|
112
|
+
* outlet. `panelProps` returns attributes for each wrapper, so a tab can point `aria-controls` at its panel:
|
|
113
|
+
*
|
|
114
|
+
* ```html
|
|
115
|
+
* <runic-region-outlets [collection]="state()?.documents" [registry]="pages" [panelProps]="panel">No open documents</runic-region-outlets>
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* `mode` `"keep-mounted"` (the default) renders every region and hides all but the selected one, so each region
|
|
119
|
+
* keeps its component and DOM. `"selected"` renders only the selected region.
|
|
120
|
+
*/
|
|
121
|
+
export class RegionOutlets {
|
|
122
|
+
collection = input(/* @ts-ignore */
|
|
123
|
+
...(ngDevMode ? [undefined, { debugName: "collection" }] : /* istanbul ignore next */ []));
|
|
124
|
+
registry = input.required(/* @ts-ignore */
|
|
125
|
+
...(ngDevMode ? [{ debugName: "registry" }] : /* istanbul ignore next */ []));
|
|
126
|
+
/** Renders a reference whose kind has no registered component instead of the English alert. */
|
|
127
|
+
missing = input(/* @ts-ignore */
|
|
128
|
+
...(ngDevMode ? [undefined, { debugName: "missing" }] : /* istanbul ignore next */ []));
|
|
129
|
+
mode = input("keep-mounted", /* @ts-ignore */
|
|
130
|
+
...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
131
|
+
/** Returns attributes for a region's wrapper, for example `{ id, role: "tabpanel", "aria-labelledby" }`. */
|
|
132
|
+
panelProps = input(/* @ts-ignore */
|
|
133
|
+
...(ngDevMode ? [undefined, { debugName: "panelProps" }] : /* istanbul ignore next */ []));
|
|
134
|
+
shown = computed(() => {
|
|
135
|
+
const keepMounted = this.mode() === "keep-mounted";
|
|
136
|
+
const panelProps = this.panelProps();
|
|
137
|
+
return regionEntries(this.collection())
|
|
138
|
+
.filter(region => keepMounted || region.selected)
|
|
139
|
+
.map(region => ({ region, attributes: panelProps?.(region) }));
|
|
140
|
+
}, /* @ts-ignore */
|
|
141
|
+
...(ngDevMode ? [{ debugName: "shown" }] : /* istanbul ignore next */ []));
|
|
142
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RegionOutlets, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
143
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.3", type: RegionOutlets, isStandalone: true, selector: "runic-region-outlets", inputs: { collection: { classPropertyName: "collection", publicName: "collection", isSignal: true, isRequired: false, transformFunction: null }, registry: { classPropertyName: "registry", publicName: "registry", isSignal: true, isRequired: true, transformFunction: null }, missing: { classPropertyName: "missing", publicName: "missing", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, panelProps: { classPropertyName: "panelProps", publicName: "panelProps", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: `
|
|
144
|
+
@for (panel of shown(); track panel.region.key) {
|
|
145
|
+
<div [runicRegionPanel]="panel.attributes" [hidden]="!panel.region.selected" [style.display]="panel.region.selected ? null : 'none'"
|
|
146
|
+
[attr.data-region-key]="panel.region.key">
|
|
147
|
+
<runic-view-outlet [content]="panel.region.content" [registry]="registry()" [missing]="missing()" />
|
|
148
|
+
</div>
|
|
149
|
+
} @empty { <ng-content /> }
|
|
150
|
+
`, isInline: true, dependencies: [{ kind: "component", type: ViewOutlet, selector: "runic-view-outlet", inputs: ["content", "registry", "missing"] }, { kind: "directive", type: RegionPanel, selector: "[runicRegionPanel]", inputs: ["runicRegionPanel"] }] });
|
|
151
|
+
}
|
|
152
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.3", ngImport: i0, type: RegionOutlets, decorators: [{
|
|
153
|
+
type: Component,
|
|
154
|
+
args: [{ selector: "runic-region-outlets", standalone: true, imports: [ViewOutlet, RegionPanel], template: `
|
|
155
|
+
@for (panel of shown(); track panel.region.key) {
|
|
156
|
+
<div [runicRegionPanel]="panel.attributes" [hidden]="!panel.region.selected" [style.display]="panel.region.selected ? null : 'none'"
|
|
157
|
+
[attr.data-region-key]="panel.region.key">
|
|
158
|
+
<runic-view-outlet [content]="panel.region.content" [registry]="registry()" [missing]="missing()" />
|
|
159
|
+
</div>
|
|
160
|
+
} @empty { <ng-content /> }
|
|
161
|
+
` }]
|
|
162
|
+
}], propDecorators: { collection: [{ type: i0.Input, args: [{ isSignal: true, alias: "collection", required: false }] }], registry: [{ type: i0.Input, args: [{ isSignal: true, alias: "registry", required: true }] }], missing: [{ type: i0.Input, args: [{ isSignal: true, alias: "missing", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], panelProps: [{ type: i0.Input, args: [{ isSignal: true, alias: "panelProps", required: false }] }] } });
|
|
77
163
|
/**
|
|
78
164
|
* The name of {@link ViewOutlet} before 0.7.0-preview.7, where React, Vue and Svelte already used
|
|
79
165
|
* `ViewOutlet`. It is the same component class, so it renders the same `<runic-view-outlet>` element
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.16.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.16.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.16.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": "ff96e52727212344c407489283a9cafc614f0270"
|
|
73
73
|
}
|