@runic-artifex/vue 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 CHANGED
@@ -50,6 +50,9 @@ connected:
50
50
  "Connecting…" and do not open the route again. `keepAlive: 0` disposes at
51
51
  once.
52
52
  - An already connected client is observed and left to its owner.
53
+ - Each member is its own ref: `client` stays the same object for the
54
+ connection, so a `watch` or `watchEffect` that reads only `client` does not
55
+ run again when the View's state changes.
53
56
  - The source can be a value, a ref or a getter such as `() => props.page`.
54
57
  - `pending` is true while a reference connects. `error` holds a failed
55
58
  connection; `retry()` connects again.
@@ -193,13 +196,32 @@ is written. A string set on `value` of a field that is not text is taken as its
193
196
  `errors` holds the member's validation messages from the descriptor (`[]` when valid), `error` why the latest write
194
197
  or text failed (a `BridgeError` or a `FieldError`, whose `kind` is `rejected`, `conflict`, `committed-with-error` or
195
198
  `invalid-text`). `FieldError`, `FieldOptions`, `FieldState` and `BridgeField` are exported from this package. See the
196
- [field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#fields) for the receipts
199
+ [field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#fields) for the receipts
197
200
  and text forms.
198
201
 
202
+ #### Row cells and nested members
203
+
204
+ Since 0.16, `InvoiceFields.address.street` and `InvoiceFields.lines.at(line.id).quantity` are fields too
205
+ (`field-paths/1`): a member of an object member, and a cell of a row that .NET edits with `[RunicRowEditor]`. Call
206
+ `useField` in the row's component (`v-model="quantity.text"`); `at(key)` returns the same descriptor for the same
207
+ key. Such a field always writes checked, conflicts only when another writer changed the same cell, and shows the
208
+ messages .NET reports at the cell's validation path. See
209
+ [Fields below a member and row cells](https://github.com/Runic-Artifex/runic-sdk/blob/v0.16.0/packages/web/vue/../views/README.md#fields-below-a-member-and-row-cells).
210
+
211
+ ### Forms: `useForm(fields, options?)`
212
+
213
+ One `reactive` state over field handles, and a `submit` that writes every field before its command
214
+ (`createFormController` in `@runic-artifex/views`). `dirty` counts drafts not written yet and the `dirty` option.
215
+
216
+ ```vue
217
+ const form = useForm({ title, step }, { dirty: () => editor.state.value?.isDirty === true });
218
+ <button :disabled="!form.valid || form.submitting" @click="form.submit(() => editor.client.value!.save())">Save</button>
219
+ ```
220
+
199
221
  ### Text inputs: `useTextField(view, read, write, options?)`
200
222
 
201
223
  Binds a text input to a member through the framework-neutral
202
- [text field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#text-inputs)
224
+ [text field controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#text-inputs)
203
225
  while the effect scope is active. Each field is a ref, so the handle can be destructured:
204
226
 
205
227
  ```vue
@@ -274,6 +296,70 @@ markup (including any `role`) is yours:
274
296
  </ViewOutlet>
275
297
  ```
276
298
 
299
+ ### Region collections
300
+
301
+ A .NET `[RunicRegionCollection]` member, such as `state.documents`, lists
302
+ regions that each keep their own back stack. `<RegionOutlets>` renders a
303
+ `ViewOutlet` for each region, keyed by the region's key, inside a
304
+ `<div data-region-key>`. The default `mode="keep-mounted"` keeps every region mounted
305
+ and sets `hidden` and an inline `display: none` on all but the selected one, so
306
+ a tab keeps its component, scroll position and unsent input. Author CSS cannot
307
+ show a hidden panel without `!important`. `mode="selected"` renders only the
308
+ selected region. The default slot renders while there is no region, and the
309
+ `missing` slot is passed to each outlet. A region with `content: null` renders
310
+ nothing.
311
+
312
+ The package has no tab bar. Build one with `regionEntries` and the generated
313
+ `selectDocuments(key)` and `closeDocuments(key)`. The `panelProps(entry)` prop returns attributes for each region's wrapper,
314
+ such as `id`, `role="tabpanel"` and `aria-labelledby`, so each tab can name its
315
+ panel in `aria-controls`. `hidden` and `data-region-key` stay controlled by the
316
+ outlet, and a returned `style` is merged with its `display: none`.
317
+
318
+ ```vue
319
+ <script setup lang="ts">
320
+ const tabId = (key: string) => `document-tab-${key}`;
321
+ const panelId = (key: string) => `document-panel-${key}`;
322
+ async function close(key: string) {
323
+ if ((await client.value?.closeDocuments(key))?.kind !== "Committed") return;
324
+ await nextTick();
325
+ const selected = selectedRegion(state.value?.documents);
326
+ if (selected) document.getElementById(tabId(selected.key))?.focus();
327
+ }
328
+ </script>
329
+
330
+ <template>
331
+ <div role="tablist">
332
+ <span v-for="tab in regionEntries(state?.documents)" :key="tab.key">
333
+ <button :id="tabId(tab.key)" role="tab" :aria-selected="tab.selected" :aria-controls="panelId(tab.key)"
334
+ @click="client?.selectDocuments(tab.key)">
335
+ {{ tab.content?.kind ?? "Empty" }}
336
+ </button>
337
+ <button aria-label="Close" @click="close(tab.key)">×</button>
338
+ </span>
339
+ </div>
340
+ <RegionOutlets :collection="state?.documents" :registry="documentPages"
341
+ :panel-props="tab => ({ id: panelId(tab.key), role: 'tabpanel', 'aria-labelledby': tabId(tab.key) })">
342
+ <p>No open documents</p>
343
+ </RegionOutlets>
344
+ </template>
345
+ ```
346
+
347
+ `selected` changes only when a switch or close commits. A departure guard can
348
+ keep the current tab, so highlight `selected` and do not move the highlight
349
+ before the request settles. `select…` and `close…` resolve to the .NET
350
+ `NavigationOutcome`, such as `{ kind: "Rejected", rejection: "Guard" }`.
351
+
352
+ Closing the selected tab removes its button, and the next tab becomes selected
353
+ when the close commits. After `closeDocuments` resolves with `kind: "Committed"`,
354
+ move focus to the button of the new selected tab, as `close` above does.
355
+
356
+ In both modes the region collection keeps presenting every region's content,
357
+ so the pages of hidden tabs stay live and still receive state. `"selected"`
358
+ mode only unmounts the components of the regions that are not selected.
359
+
360
+ `regionEntries`, `selectedRegion` and the region types are re-exported from
361
+ `@runic-artifex/views`.
362
+
277
363
  ## `useCommand(command)`
278
364
 
279
365
  Returns `{ run, pending, error, failure, reset }`, with `pending`, `error` and
@@ -301,7 +387,7 @@ neither.
301
387
  ## `useOperation(start, options?)`
302
388
 
303
389
  Observes a generated `start<Command>()` operation through the framework-neutral
304
- [operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#operation-feedback-and-latest-selection)
390
+ [operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#operation-feedback-and-latest-selection)
305
391
  and returns each state field as a shallow ref, with `run`, `cancel` and `reset`:
306
392
 
307
393
  ```vue
@@ -333,7 +419,7 @@ Disposing the effect scope settles run promises without cancelling accepted work
333
419
 
334
420
  Admits only the newest of several reads, for example loading the item the user
335
421
  selected last, through the framework-neutral
336
- [latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#operation-feedback-and-latest-selection),
422
+ [latest-operation controller](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#operation-feedback-and-latest-selection),
337
423
  and returns each state field as a shallow ref, with `run` and `clear`. Each
338
424
  `run(intent)` replaces the queued intent and cancels the active read; the next read
339
425
  starts only after the previous one reaches its terminal status and the intent's
@@ -370,7 +456,7 @@ from `@runic-artifex/views` (re-exported here since 0.11, with the
370
456
  `BridgeConnectionState` and `BridgeConnectionOptions` types) and returns `{ state }`, a shallow ref holding a
371
457
  `BridgeConnectionState`: `connecting`, `connected`, `reconnecting`, `lost` or `closed` (the
372
458
  application closed the window, since 0.15; a closed set, see
373
- [Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#connection-state)):
459
+ [Connection state](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#connection-state)):
374
460
 
375
461
  ```vue
376
462
  <script setup lang="ts">
@@ -393,7 +479,7 @@ development builds warn. An invalid `lostAfter` throws a `RangeError`.
393
479
  Follows the declared menu bar of a Runic Desktop window that leaves it to the
394
480
  page (`DesktopMenuBarPresentation.Page`) until the current effect scope is
395
481
  disposed. It wraps `createMenuBarController` from `@runic-artifex/views` (see
396
- [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#in-page-menu-bar)) and returns `{ state, invoke, handleKeyDown }`: `state` is a shallow ref
482
+ [In-page menu bar](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#in-page-menu-bar)) and returns `{ state, invoke, handleKeyDown }`: `state` is a shallow ref
397
483
  of a `MenuBarState`, and the bar is rendered by the menubar component of the
398
484
  application's own UI library. Runic ships no menubar component.
399
485
 
@@ -424,7 +510,7 @@ rendering creates no controller: `state` stays `connecting`.
424
510
  ### With Reka UI
425
511
 
426
512
  Reka UI's `MenubarRoot` with `v-model` of the open menu; the
427
- [Notes example](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/examples/notes-view-first#in-page-menu-bar) adds submenus, check and radio
513
+ [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
428
514
  items and is tested with real keys:
429
515
 
430
516
  ```vue
@@ -469,6 +555,20 @@ const { state: menuBar, invoke } = useMenuBar({
469
555
  </template>
470
556
  ```
471
557
 
558
+ ## `useText(value, fallback?)`
559
+
560
+ Shows a text reference that a ViewModel produced, such as a status line or a
561
+ validation error's `text`, in the window's language, and renders again when the
562
+ language changes. A string shows as it is; `null` and `undefined` show
563
+ `fallback`. Connect the page's Translations runtime once with
564
+ `configureTranslatedText` ([Translated text](https://github.com/Runic-Artifex/runic-sdk/blob/v0.16.0/packages/dotnet/Runic.Application.Views/README.md#translated-text)).
565
+ `useWindowLocale()` reads the window's locale.
566
+
567
+ ```ts
568
+ const status = useText(() => view.state.value?.status);
569
+ // <p>{{ status }}</p>
570
+ ```
571
+
472
572
  ## Errors
473
573
 
474
574
  The `error` of `useView` and of a command or operation handle is typed
@@ -486,7 +586,7 @@ const message = computed(() => describeBridgeError(error.value));
486
586
  ```
487
587
 
488
588
  `instanceof` holds for errors from every copy of the package on the page.
489
- [Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#errors-and-diagnostics)
589
+ [Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#errors-and-diagnostics)
490
590
  lists the kinds. Any other value, such as an exception that your own connect
491
591
  function or command callback throws, arrives unchanged.
492
592
 
@@ -533,15 +633,53 @@ application's own dialog.
533
633
  departure before that is answered by the ViewModel's .NET fallback handler, or
534
634
  fails closed without one.
535
635
 
536
- The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.15.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
636
+ 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)
537
637
  has the .NET side and which View answers which departure. In a frontend test,
538
638
  the generated mock's `interactions.<name>.request(input)` resolves with the
539
- registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#testing).
639
+ registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#testing).
640
+
641
+ ## View requests
642
+
643
+ A `ViewRequest<T>` property of the ViewModel asks the View for a one-way
644
+ presentation action, such as focusing a field or showing a toast, and is
645
+ `client.requests.<name>` on the generated client. Register the page's
646
+ handler in `watchEffect`: `handle((input, { signal }) => …)` returns the function
647
+ that removes it, so pass that to `onCleanup`, and Vue removes the handler when
648
+ the client changes or the component unmounts:
649
+
650
+ ```vue
651
+ <script setup lang="ts">
652
+ import { useTemplateRef, watchEffect } from "vue";
653
+ import { useView } from "@runic-artifex/vue";
654
+ import type { EditPageReference } from "./generated/edit.js";
655
+
656
+ const props = defineProps<{ page: EditPageReference }>();
657
+ const { client } = useView(() => props.page);
658
+ const name = useTemplateRef<HTMLInputElement>("name");
659
+ watchEffect(onCleanup => {
660
+ const remove = client.value?.requests.focus.handle(({ member }) => {
661
+ if (member === "name") name.value?.focus();
662
+ });
663
+ if (remove) onCleanup(remove);
664
+ });
665
+ </script>
666
+
667
+ <template><input ref="name"></template>
668
+ ```
669
+
670
+ `input` is typed from the request's `ViewRequest<T>`. The handler runs once
671
+ the page painted the state the request was raised with, so the field of that
672
+ state is rendered; `signal` aborts when the handler is replaced or removed, the
673
+ client is disposed or the connection is lost. A request is never replayed: one
674
+ raised before the effect ran, or while the page is disconnected, is not
675
+ 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
676
+ test raise one with the generated mock's `requests.<name>.raise(input)` (the
677
+ [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#testing)).
540
678
 
541
679
  ## `useCollectionViewport(options)`
542
680
 
543
681
  Follows a fixed-row-height scroll container and returns `{ viewport, attach }`.
544
- `viewport` is a shallow ref with the [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/views#collectionviewportoptions)
682
+ `viewport` is a shallow ref with the [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/views#collectionviewportoptions)
545
683
  range; `attach` is a function ref for the container. Bind it to a native element
546
684
  such as a `<div>`: a component instance (`:ref="attach"` on a component) or a
547
685
  non-HTML element detaches the viewport, and development builds warn. Pass a getter for the
@@ -562,3 +700,34 @@ watch(() => [viewport.value.start, viewport.value.size] as const, ([start, size]
562
700
  </div>
563
701
  </template>
564
702
  ```
703
+
704
+ ## `useQueryCollection(collection, options)`
705
+
706
+ Follows a scroll container for a [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
707
+ loads the rows the container shows, with placeholders until they arrive, and lays them out with variable heights.
708
+ Pass the collection or a getter (`() => client.value?.queries.rows`) and the options. `viewport` is a ref of the
709
+ `QueryViewport` (`items` with `top` and `size`, `totalSize`, `total`, `query`, `loading`, `error`); bind `attach` to the
710
+ container and `measure` to each row, and call `scrollToKey`, `scrollToIndex`, `setQuery` or `retry`:
711
+
712
+ ```vue
713
+ <script setup lang="ts">
714
+ const list = useQueryCollection(() => client.value?.queries.rows, { estimateSize: 32 });
715
+ </script>
716
+ <template>
717
+ <div :ref="list.attach" style="height: 480px; overflow: auto">
718
+ <div :style="{ height: `${list.viewport.value.totalSize}px`, position: 'relative' }">
719
+ <div v-for="item in list.viewport.value.items" :key="item.key ?? `p${item.index}`" :ref="el => list.measure(el, item.index)"
720
+ :style="{ position: 'absolute', top: `${item.top}px`, width: '100%' }">{{ item.row?.label ?? "…" }}</div>
721
+ </div>
722
+ </div>
723
+ </template>
724
+ ```
725
+
726
+ ## Back and the URL
727
+
728
+ The package re-exports `installBackNavigation`, `installNavigationPath`,
729
+ `navigateBack`, `openNavigationPath` and `onNavigationPath` from
730
+ `@runic-artifex/views` (since 0.16). Call the installs once where the page
731
+ starts, before or after mounting: the mouse's Back button and Alt+Left then go
732
+ back in the .NET window, and `#/customers/42` follows its path region. See
733
+ [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/form.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { type MaybeRefOrGetter } from "vue";
2
+ import { type FieldState, type FormField, type FormFields, type FormState, type FormSubmitOptions, type FormSubmitResult } from "@runic-artifex/views";
3
+ /** A field as {@link useForm} reads it: a `useField` handle. */
4
+ export type FormFieldHandle = FormField & Pick<FieldState<unknown>, "editing" | "validating" | "errors" | "error">;
5
+ export interface UseFormOptions {
6
+ /** Whether the View reports unsaved changes, such as `() => editor.state.value?.isDirty === true`. */
7
+ readonly dirty?: MaybeRefOrGetter<boolean | undefined>;
8
+ }
9
+ /** A form bound by {@link useForm}: a `reactive` state and its actions. */
10
+ export interface FormHandle extends FormState {
11
+ /** Commits every field, waits for their writes and runs `command` unless a field's write or text failed. */
12
+ submit<T>(command: () => T | PromiseLike<T>, options?: FormSubmitOptions): Promise<FormSubmitResult<T>>;
13
+ /** Commits every field and resolves once their writes settled. */
14
+ commit(): Promise<FormState>;
15
+ /** Resets every field. */
16
+ reset(): void;
17
+ }
18
+ /**
19
+ * One dirty, pending and valid state over `useField` handles, and a `submit` that writes every field before its
20
+ * command (`createFormController` in `@runic-artifex/views`):
21
+ *
22
+ * ```vue
23
+ * const form = useForm({ title, body }, { dirty: () => editor.state.value?.isDirty === true });
24
+ * <button :disabled="!form.valid || form.submitting" @click="form.submit(() => editor.client.value!.save())">Save</button>
25
+ * ```
26
+ */
27
+ export declare function useForm(fields: FormFields<FormFieldHandle>, options?: UseFormOptions): FormHandle;
package/dist/form.js ADDED
@@ -0,0 +1,41 @@
1
+ import { computed, reactive, shallowRef, toValue } from "vue";
2
+ import { formFieldList, formStateOf, submitFields, } from "@runic-artifex/views";
3
+ /**
4
+ * One dirty, pending and valid state over `useField` handles, and a `submit` that writes every field before its
5
+ * command (`createFormController` in `@runic-artifex/views`):
6
+ *
7
+ * ```vue
8
+ * const form = useForm({ title, body }, { dirty: () => editor.state.value?.isDirty === true });
9
+ * <button :disabled="!form.valid || form.submitting" @click="form.submit(() => editor.client.value!.save())">Save</button>
10
+ * ```
11
+ */
12
+ export function useForm(fields, options = {}) {
13
+ const list = formFieldList(fields);
14
+ const submitting = shallowRef(false);
15
+ const state = computed(() => formStateOf(list, toValue(options.dirty) === true, submitting.value));
16
+ return reactive({
17
+ dirty: computed(() => state.value.dirty),
18
+ editing: computed(() => state.value.editing),
19
+ validating: computed(() => state.value.validating),
20
+ pending: computed(() => state.value.pending),
21
+ valid: computed(() => state.value.valid),
22
+ submitting: computed(() => state.value.submitting),
23
+ async submit(command, submitOptions = {}) {
24
+ if (submitting.value)
25
+ return { status: "busy" };
26
+ submitting.value = true;
27
+ try {
28
+ return await submitFields(list, command, submitOptions, index => list[index]);
29
+ }
30
+ finally {
31
+ submitting.value = false;
32
+ }
33
+ },
34
+ async commit() {
35
+ await Promise.all(list.map(field => field.commit()));
36
+ return state.value;
37
+ },
38
+ reset() { for (const field of list)
39
+ field.reset(); },
40
+ });
41
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type Component, type MaybeRefOrGetter, type Ref, type WritableComputedRef } from "vue";
2
- import { type BridgeConnectionOptions, type BridgeConnectionState, type BridgeField, type BridgeOperation, type BridgeOutcomeFailure, type FieldBaseline, type FieldDefinition, type FieldState, type FieldOptions, type LatestOperationController, type LatestOperationState, type OperationController, type OperationControllerOptions, type OperationState, type PageReference, type ViewClient, type ViewConnector, type ViewSource } from "@runic-artifex/views";
1
+ import { type Component, type ComputedRef, type HTMLAttributes, type MaybeRefOrGetter, type Ref, type WritableComputedRef } from "vue";
2
+ import { type BridgeConnectionOptions, type BridgeConnectionState, type BridgeField, type BridgeOperation, type BridgeOutcomeFailure, type FieldBaseline, type FieldDefinition, type FieldState, type FieldOptions, type LatestOperationController, type LatestOperationState, type OperationController, type OperationControllerOptions, type OperationState, type PageReference, type TextReference, type RegionCollection, type RegionEntry, type ViewClient, type ViewConnector, type ViewSource } from "@runic-artifex/views";
3
3
  export interface ViewHandle<TClient extends ViewClient> {
4
4
  /** The latest state, or undefined until the client connects. */
5
5
  readonly state: Readonly<Ref<TClient["snapshot"] | undefined>>;
@@ -107,6 +107,61 @@ export declare const ViewOutlet: new <R extends PageReference>(props: (ViewOutle
107
107
  }) | (ViewOutletProps<R> & {
108
108
  [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
109
109
  }), {}, {}, {}, {}, {}>;
110
+ /** How {@link RegionOutlets} renders the regions of a collection. */
111
+ export type RegionOutletsMode = "keep-mounted" | "selected";
112
+ /**
113
+ * Attributes that {@link RegionOutlets} merges onto a region's wrapper, such as `id`, `role` and `aria-labelledby`.
114
+ * `hidden` and `data-region-key` stay controlled by the outlet, and a `style` is merged with its `display: none`.
115
+ */
116
+ export type RegionPanelAttributes = Omit<HTMLAttributes, "hidden"> & {
117
+ readonly [attribute: `data-${string}`]: string | undefined;
118
+ };
119
+ export interface RegionOutletsProps<R extends PageReference> {
120
+ /** The presented region collection, such as `state.documents`. */
121
+ collection: RegionCollection<R> | null | undefined;
122
+ registry: ViewRegistry<R>;
123
+ /**
124
+ * `"keep-mounted"` (the default) renders every region and hides all but the selected one, so each region keeps
125
+ * its component and DOM. `"selected"` renders only the selected region.
126
+ */
127
+ mode?: RegionOutletsMode;
128
+ /**
129
+ * Returns attributes for a region's wrapper, for example `{ id, role: "tabpanel", "aria-labelledby" }`, so a tab
130
+ * can point `aria-controls` at the panel.
131
+ */
132
+ panelProps?: (entry: RegionEntry<R>) => RegionPanelAttributes;
133
+ }
134
+ /**
135
+ * Renders a {@link ViewOutlet} for the regions of a region collection, each in a `<div data-region-key>` keyed by
136
+ * the region's key. A region that is not selected is rendered with `hidden` and an inline `display: none`, which
137
+ * author CSS without `!important` cannot override. A new content reference in a region remounts only that region's
138
+ * component. The default slot renders while the collection has no region, and the
139
+ * `missing` slot is passed to each outlet:
140
+ *
141
+ * ```vue
142
+ * <RegionOutlets :collection="state?.documents" :registry="pages"><p>No open documents</p></RegionOutlets>
143
+ * ```
144
+ */
145
+ export declare const RegionOutlets: new <R extends PageReference>(props: (RegionOutletsProps<R> & ({
146
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
147
+ } | {
148
+ [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
149
+ })) & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps) => import("vue").CreateComponentPublicInstanceWithMixins<RegionOutletsProps<R> & ({
150
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
151
+ } | {
152
+ [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
153
+ }), {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, import("vue").PublicProps, {}, false, {}, {}, {}, {}, string, {}, any, import("vue").ComponentProvideOptions, {
154
+ P: {};
155
+ B: {};
156
+ D: {};
157
+ C: {};
158
+ M: {};
159
+ Defaults: {};
160
+ }, (RegionOutletsProps<R> & {
161
+ [x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
162
+ }) | (RegionOutletsProps<R> & {
163
+ [x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
164
+ }), {}, {}, {}, {}, {}>;
110
165
  export interface CommandHandle<TArgs extends readonly unknown[], TResult, TFailure = BridgeOutcomeFailure<TResult>> {
111
166
  /**
112
167
  * Runs the command. Resolves to its result, including a `BridgeOutcome` with a
@@ -256,6 +311,8 @@ export interface FieldHandle<TValue> {
256
311
  readonly errors: readonly string[];
257
312
  /** The producer's field while a checked write's `conflict` keeps the draft; `undefined` otherwise. */
258
313
  readonly conflict: FieldBaseline<TValue> | undefined;
314
+ /** The member's validation is in progress, such as an asynchronous rule that is still checking: show "checking…". */
315
+ readonly validating: boolean;
259
316
  /** The user changed the value. */
260
317
  input(value: TValue): void;
261
318
  /**
@@ -289,7 +346,7 @@ export interface FieldHandle<TValue> {
289
346
  * conflict holds further writes until `retry()` or `reset()`. Leaving the scope writes a value that waits to be
290
347
  * written.
291
348
  */
292
- export declare function useField<TClient extends ViewClient, TValue>(view: TextFieldView<TClient>, field: BridgeField<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue> | FieldDefinition<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue>, options?: FieldOptions): FieldHandle<TValue>;
349
+ export declare function useField<TClient extends ViewClient, TValue>(view: TextFieldView<TClient>, field: BridgeField<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue> | FieldDefinition<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue>, options?: FieldOptions<TValue>): FieldHandle<TValue>;
293
350
  export interface BridgeConnectionHandle {
294
351
  /** The connection to the .NET host, as `onBridgeConnection` reports it. */
295
352
  readonly state: Readonly<Ref<BridgeConnectionState>>;
@@ -306,7 +363,29 @@ export interface BridgeConnectionHandle {
306
363
  * ```
307
364
  */
308
365
  export declare function useBridgeConnection(options?: BridgeConnectionOptions): BridgeConnectionHandle;
366
+ /**
367
+ * A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
368
+ * language (`resolveText`), as a computed ref that follows a language switch until the effect scope stops. `source` and
369
+ * `fallback` may be refs or getters: `useText(() => view.state.value?.status)`. A string shows as it is; `null` and
370
+ * `undefined` show `fallback`. Configure the page's Translations runtime once with `configureTranslatedText`; without
371
+ * one, a reference shows its fallback text.
372
+ *
373
+ * ```vue
374
+ * const status = useText(() => view.state.value?.status);
375
+ * <p>{{ status }}</p>
376
+ * ```
377
+ */
378
+ export declare function useText(source: MaybeRefOrGetter<TextReference | string | null | undefined>, fallback?: MaybeRefOrGetter<string | undefined>): ComputedRef<string>;
379
+ /** The window's locale that the application set, or `null` while it sets none, as a ref, until the effect scope stops. */
380
+ export declare function useWindowLocale(): Readonly<Ref<string | null>>;
309
381
  export { useCollectionViewport, type CollectionViewportHandle } from "./viewport.js";
382
+ export { useForm, type FormFieldHandle, type FormHandle, type UseFormOptions } from "./form.js";
383
+ export { commitAllFields, type FormState, type FormSubmitOptions, type FormSubmitResult } from "@runic-artifex/views";
384
+ export { configureTranslatedText, resolveText, windowLocale, type TextReference, type TextTranslations, } from "@runic-artifex/views";
385
+ export { useQueryCollection, type QueryCollectionHandle } from "./query.js";
310
386
  export { onBridgeConnection, type BridgeConnectionOptions, type BridgeConnectionState } from "@runic-artifex/views";
311
- export { FieldError, type BridgeField, type BridgeFieldKind, type FieldBaseline, type FieldDefinition, type FieldErrorKind, type FieldOptions, type FieldState, } from "@runic-artifex/views";
387
+ export { upload, type BlobRef, type RunicBlob, type UploadOptions, type UploadProgress } from "@runic-artifex/views";
388
+ export { regionEntries, selectedRegion, type RegionCollection, type RegionEntry, type RegionOutcome, type RegionSlot, } from "@runic-artifex/views";
389
+ export { installBackNavigation, installNavigationPath, navigateBack, onNavigationPath, openNavigationPath, type NavigationPathChange, type NavigationPathOptions, type NavigationReply, } from "@runic-artifex/views";
390
+ export { FieldError, type BridgeField, type BridgeFieldConstraints, type BridgeFieldKind, type FieldBaseline, type FieldDefinition, type FieldErrorKind, type FieldOptions, type FieldState, } from "@runic-artifex/views";
312
391
  export { useMenuBar, type MenuBarEntry, type MenuBarHandle, type MenuBarInvokeResult, type MenuBarItem, type MenuBarMenu, type MenuBarRequest, type MenuBarSeparator, type MenuBarState, type UseMenuBarOptions, } from "./menu-bar.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { computed, defineComponent, h, reactive, shallowRef, toValue, watch, } from "vue";
2
- import { createCommandController, createLatestOperationController, createOperationController, createFieldController, createTextFieldController, createViewController, onBridgeConnection, } from "@runic-artifex/views";
2
+ import { createCommandController, createLatestOperationController, createOperationController, createFieldController, createTextFieldController, createViewController, onBridgeConnection, onWindowLocale, resolveText, subscribeText, windowLocale, regionEntries, } from "@runic-artifex/views";
3
3
  import { viewSourceIdentity } from "@runic-artifex/views/bindings";
4
4
  import { releaseWithScope } from "./scope.js";
5
5
  function controllerOptions(options) {
@@ -90,6 +90,29 @@ export const ViewOutlet = defineComponent((props, { slots }) => () => {
90
90
  }
91
91
  return h(component, { key: referenceKey(content), page: content });
92
92
  }, { name: "ViewOutlet", props: ["content", "registry"] });
93
+ /**
94
+ * Renders a {@link ViewOutlet} for the regions of a region collection, each in a `<div data-region-key>` keyed by
95
+ * the region's key. A region that is not selected is rendered with `hidden` and an inline `display: none`, which
96
+ * author CSS without `!important` cannot override. A new content reference in a region remounts only that region's
97
+ * component. The default slot renders while the collection has no region, and the
98
+ * `missing` slot is passed to each outlet:
99
+ *
100
+ * ```vue
101
+ * <RegionOutlets :collection="state?.documents" :registry="pages"><p>No open documents</p></RegionOutlets>
102
+ * ```
103
+ */
104
+ export const RegionOutlets = defineComponent((props, { slots }) => () => {
105
+ const mode = props.mode ?? "keep-mounted";
106
+ const shown = regionEntries(props.collection).filter(region => mode === "keep-mounted" || region.selected);
107
+ if (shown.length === 0)
108
+ return slots.default?.();
109
+ const missing = slots["missing"];
110
+ return shown.map(region => {
111
+ const panel = props.panelProps?.(region) ?? {};
112
+ const hidden = !region.selected;
113
+ return h("div", { ...panel, key: region.key, "data-region-key": region.key, hidden, style: hidden ? [panel.style, { display: "none" }] : panel.style }, h((ViewOutlet), { content: region.content, registry: props.registry }, missing ? { missing } : {}));
114
+ });
115
+ }, { name: "RegionOutlets", props: ["collection", "registry", "mode", "panelProps"] });
93
116
  /**
94
117
  * Tracks a command's pending state and failure as shallow refs, like `useView`,
95
118
  * so the handle can be destructured. Call it in `setup()` or `effectScope().run()`
@@ -259,6 +282,7 @@ export function useField(view, field, options = {}) {
259
282
  error: computed(() => current.value.error),
260
283
  errors: computed(() => current.value.errors),
261
284
  conflict: computed(() => current.value.conflict),
285
+ validating: computed(() => current.value.validating),
262
286
  input: (value) => controller.input(value),
263
287
  commit: () => controller.commit(),
264
288
  retry: () => controller.retry(),
@@ -282,7 +306,41 @@ export function useBridgeConnection(options = {}) {
282
306
  releaseWithScope("useBridgeConnection", stop);
283
307
  return { state };
284
308
  }
309
+ /**
310
+ * A text reference that a ViewModel produced, such as a status line or a validation message's `text`, in the window's
311
+ * language (`resolveText`), as a computed ref that follows a language switch until the effect scope stops. `source` and
312
+ * `fallback` may be refs or getters: `useText(() => view.state.value?.status)`. A string shows as it is; `null` and
313
+ * `undefined` show `fallback`. Configure the page's Translations runtime once with `configureTranslatedText`; without
314
+ * one, a reference shows its fallback text.
315
+ *
316
+ * ```vue
317
+ * const status = useText(() => view.state.value?.status);
318
+ * <p>{{ status }}</p>
319
+ * ```
320
+ */
321
+ export function useText(source, fallback) {
322
+ const version = shallowRef(0);
323
+ releaseWithScope("useText", subscribeText(() => { version.value++; }));
324
+ return computed(() => {
325
+ void version.value;
326
+ return resolveText(toValue(source), toValue(fallback));
327
+ });
328
+ }
329
+ /** The window's locale that the application set, or `null` while it sets none, as a ref, until the effect scope stops. */
330
+ export function useWindowLocale() {
331
+ const locale = shallowRef(windowLocale());
332
+ releaseWithScope("useWindowLocale", onWindowLocale(next => { locale.value = next; }));
333
+ return locale;
334
+ }
285
335
  export { useCollectionViewport } from "./viewport.js";
336
+ export { useForm } from "./form.js";
337
+ export { commitAllFields } from "@runic-artifex/views";
338
+ export { configureTranslatedText, resolveText, windowLocale, } from "@runic-artifex/views";
339
+ export { useQueryCollection } from "./query.js";
286
340
  export { onBridgeConnection } from "@runic-artifex/views";
341
+ // blobs/1: uploads from the page and the blob values of state.
342
+ export { upload } from "@runic-artifex/views";
343
+ export { regionEntries, selectedRegion, } from "@runic-artifex/views";
344
+ export { installBackNavigation, installNavigationPath, navigateBack, onNavigationPath, openNavigationPath, } from "@runic-artifex/views";
287
345
  export { FieldError, } from "@runic-artifex/views";
288
346
  export { useMenuBar, } from "./menu-bar.js";
@@ -0,0 +1,23 @@
1
+ import { type ComponentPublicInstance, type MaybeRefOrGetter, type Ref } from "vue";
2
+ import { type QueryCollection, type QueryViewport, type QueryViewportOptions, type RunicQuery } from "@runic-artifex/views";
3
+ export interface QueryCollectionHandle<TRow> {
4
+ /** The rows to render with their offsets, the spacer's `totalSize`, the total, query, loading and error state. */
5
+ readonly viewport: Readonly<Ref<QueryViewport<TRow>>>;
6
+ /** A function ref for the scroll container, bound to a native element: `<div :ref="attach">`. */
7
+ attach(element: Element | ComponentPublicInstance | null): void;
8
+ /** A function ref for each rendered row, which measures its height: `<div :ref="el => measure(el, item.index)">`. */
9
+ measure(element: Element | ComponentPublicInstance | null, index: number): void;
10
+ /** Scrolls to the row with `key` in the current query; resolves `false` when no row has it. */
11
+ scrollToKey(key: string, align?: "start" | "center" | "end"): Promise<boolean>;
12
+ scrollToIndex(index: number, align?: "start" | "center" | "end"): void;
13
+ /** Changes the collection's sort and filter (ViewModel state every presentation shares). */
14
+ setQuery(query: RunicQuery): Promise<void>;
15
+ /** Loads the range again after a failure. */
16
+ retry(): void;
17
+ }
18
+ /**
19
+ * Follows a scroll container for a query collection (`client.queries.{name}`): it loads the rows the container shows
20
+ * from .NET, with placeholders until they arrive, and lays them out with variable heights. Pass the collection or a
21
+ * getter of it (`() => client.value?.queries.rows`). Call it in `setup()` or `effectScope().run()`.
22
+ */
23
+ export declare function useQueryCollection<TRow>(collection: MaybeRefOrGetter<QueryCollection<TRow> | undefined>, options: MaybeRefOrGetter<QueryViewportOptions>): QueryCollectionHandle<TRow>;
package/dist/query.js ADDED
@@ -0,0 +1,67 @@
1
+ import { shallowRef, toValue, watch } from "vue";
2
+ import { createQueryViewportController, } from "@runic-artifex/views";
3
+ import { releaseWithScope } from "./scope.js";
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 collection or a
7
+ * getter of it (`() => client.value?.queries.rows`). Call it in `setup()` or `effectScope().run()`.
8
+ */
9
+ export function useQueryCollection(collection, options) {
10
+ const empty = { items: [], totalSize: 0, total: null, query: { sort: [], filters: [] }, loading: false, error: undefined };
11
+ const viewport = shallowRef(empty);
12
+ let controller;
13
+ let stop;
14
+ let container = null;
15
+ const rows = new Map();
16
+ const release = () => {
17
+ stop?.();
18
+ stop = undefined;
19
+ for (const unobserve of rows.values())
20
+ unobserve();
21
+ rows.clear();
22
+ controller?.dispose();
23
+ controller = undefined;
24
+ };
25
+ watch(() => toValue(collection), next => {
26
+ release();
27
+ if (!next) {
28
+ viewport.value = empty;
29
+ return;
30
+ }
31
+ const created = controller = createQueryViewportController(next, toValue(options));
32
+ stop = created.subscribe(() => { viewport.value = created.current; });
33
+ created.attach(container);
34
+ viewport.value = created.current;
35
+ }, { immediate: true });
36
+ watch(() => {
37
+ const { estimateSize, overscan } = toValue(options);
38
+ return [estimateSize, overscan];
39
+ }, ([estimateSize, overscan]) => {
40
+ controller?.update({ estimateSize, ...(overscan === undefined ? {} : { overscan }) });
41
+ });
42
+ releaseWithScope("useQueryCollection", release);
43
+ const element = (value) => typeof HTMLElement !== "undefined" && value instanceof HTMLElement ? value : null;
44
+ return {
45
+ viewport,
46
+ attach(value) {
47
+ container = element(value);
48
+ controller?.attach(container);
49
+ },
50
+ measure(value, index) {
51
+ rows.get(index)?.();
52
+ rows.delete(index);
53
+ const row = element(value);
54
+ if (row && controller)
55
+ rows.set(index, controller.observe(row, index));
56
+ },
57
+ scrollToKey: async (key, align) => controller ? controller.scrollToKey(key, align) : false,
58
+ scrollToIndex: (index, align) => controller?.scrollToIndex(index, align),
59
+ setQuery: async (query) => {
60
+ const current = toValue(collection);
61
+ if (!current)
62
+ throw new TypeError("useQueryCollection has no collection yet.");
63
+ await current.setQuery(query);
64
+ },
65
+ retry: () => toValue(collection)?.retry(),
66
+ };
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runic-artifex/vue",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Vue composables for generated Runic Views clients",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,10 +30,10 @@
30
30
  },
31
31
  "peerDependencies": {
32
32
  "vue": ">=3.5.30 <4",
33
- "@runic-artifex/views": "0.15.0"
33
+ "@runic-artifex/views": "0.16.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@runic-artifex/views": "0.15.0",
36
+ "@runic-artifex/views": "0.16.0",
37
37
  "esbuild": "0.28.2",
38
38
  "happy-dom": "21.0.4",
39
39
  "playwright-core": "1.63.0",
@@ -50,7 +50,7 @@
50
50
  "url": "git+https://github.com/Runic-Artifex/runic-sdk.git",
51
51
  "directory": "packages/web/vue"
52
52
  },
53
- "homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.15.0/packages/web/vue#readme",
53
+ "homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.16.0/packages/web/vue#readme",
54
54
  "bugs": {
55
55
  "url": "https://github.com/Runic-Artifex/runic-sdk/issues"
56
56
  },
@@ -60,5 +60,5 @@
60
60
  "views",
61
61
  "vue"
62
62
  ],
63
- "gitHead": "c94bda07cf363bad056eda86ae77c514b66e61dd"
63
+ "gitHead": "ff96e52727212344c407489283a9cafc614f0270"
64
64
  }