@runic-artifex/svelte 0.7.0-preview.6 → 0.7.0-preview.7
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
|
@@ -41,6 +41,32 @@ reference with a different `connect` function. An already connected client is
|
|
|
41
41
|
observed and left to its owner. The result exposes reactive `state`, `client`,
|
|
42
42
|
`error` and `pending` properties and `retry()`.
|
|
43
43
|
|
|
44
|
+
### Read-only state and `bind:value`
|
|
45
|
+
|
|
46
|
+
As in any MVVM View, the ViewModel's C# setters decide what the page may set.
|
|
47
|
+
Read state one way from `state`. A property with a public C# setter also gets a
|
|
48
|
+
`set<Property>` client method; pass a getter and setter pair to `bind:value`
|
|
49
|
+
(Svelte 5.9 or later) to bind it two way. Status with a `private set`, such as
|
|
50
|
+
`IsDirty` or `Error`, has no setter and is only rendered:
|
|
51
|
+
|
|
52
|
+
```svelte
|
|
53
|
+
<script lang="ts">
|
|
54
|
+
// C#: public partial int Count { get; private set; } public partial int Step { get; set; }
|
|
55
|
+
import { useCommand, useView } from "@runic-artifex/svelte/views";
|
|
56
|
+
import type { CounterPageReference } from "./generated/counter.js";
|
|
57
|
+
|
|
58
|
+
let { page }: { page: CounterPageReference } = $props();
|
|
59
|
+
const counter = useView(() => page);
|
|
60
|
+
const setStep = useCommand((step: number) => counter.client?.setStep(step));
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<p>{counter.state?.count ?? "…"}</p>
|
|
64
|
+
<select bind:value={() => counter.state?.step ?? 1, step => setStep.run(step)}>
|
|
65
|
+
<option value={1}>1</option>
|
|
66
|
+
<option value={5}>5</option>
|
|
67
|
+
</select>
|
|
68
|
+
```
|
|
69
|
+
|
|
44
70
|
## `ViewOutlet`
|
|
45
71
|
|
|
46
72
|
Renders the component registered for a generated reference's `kind` and passes
|
|
@@ -103,13 +129,15 @@ generated View snapshot:
|
|
|
103
129
|
<p role="status">{workspace.state?.operationMessage ?? "Starting…"}</p>
|
|
104
130
|
<button disabled={push.cancellationRequested} onclick={() => push.cancel()}>Cancel</button>
|
|
105
131
|
{/if}
|
|
132
|
+
{#if push.cancelled}<p role="status">Push cancelled.</p>{/if}
|
|
106
133
|
{#if push.error ?? push.cancelError}<p role="alert">{String(push.error ?? push.cancelError)}</p>{/if}
|
|
107
134
|
```
|
|
108
135
|
|
|
109
136
|
The result exposes reactive `pending`, `admitting`, `operation`, `status`, `outcome`,
|
|
110
|
-
`failure`, `error`, `cancellationRequested`, `cancelling`, `cancellation`
|
|
111
|
-
`cancelError`, with `run(...args)`, `cancel()` and `reset()`. Both async methods never
|
|
112
|
-
reject.
|
|
137
|
+
`failure`, `error`, `cancelled`, `cancellationRequested`, `cancelling`, `cancellation`
|
|
138
|
+
and `cancelError`, with `run(...args)`, `cancel()` and `reset()`. Both async methods never
|
|
139
|
+
reject. A run that ends with a `cancelled` status sets `cancelled` and leaves `error`
|
|
140
|
+
undefined; `failed` and `timedOut` statuses are still `error`. Cancel before a delayed Start receipt is retained for that captured run;
|
|
113
141
|
its response does not release pending state. `reset()` clears feedback while
|
|
114
142
|
preserving busy state and cancellation identity. Component destruction settles UI
|
|
115
143
|
observation promises and detaches feedback without cancelling accepted mutations.
|
|
@@ -122,7 +150,7 @@ uses the operation's public `wait()` and `outcome()`; the desktop transport keep
|
|
|
122
150
|
Cancel and other callbacks responsive during observation.
|
|
123
151
|
|
|
124
152
|
For rapid read selection, compose the framework-neutral
|
|
125
|
-
[`createLatestOperationController`](https://github.com/Runic-Artifex/runic-sdk/tree/
|
|
153
|
+
[`createLatestOperationController`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.7.0-preview.7/packages/web/views#operation-feedback-and-latest-selection)
|
|
126
154
|
with Svelte state. It coalesces latest intent across delayed receipts and orders
|
|
127
155
|
the next admission after terminal observation and any application drain barrier:
|
|
128
156
|
|
|
@@ -151,7 +179,7 @@ observation blocks further Starts instead of retrying blindly, with its reason i
|
|
|
151
179
|
## `useCollectionViewport(options)`
|
|
152
180
|
|
|
153
181
|
Follows a fixed-row-height scroll container and returns `{ viewport, attach }`.
|
|
154
|
-
`viewport` is the reactive [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/
|
|
182
|
+
`viewport` is the reactive [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.7.0-preview.7/packages/web/views#collectionviewportoptions)
|
|
155
183
|
range; `attach` is an attachment for the container. Call it during component
|
|
156
184
|
initialization and send the range to the ViewModel from an effect:
|
|
157
185
|
|
|
@@ -171,5 +199,5 @@ initialization and send the range to the ViewModel from an effect:
|
|
|
171
199
|
```
|
|
172
200
|
|
|
173
201
|
Translation helpers moved to
|
|
174
|
-
[`@runic-artifex/translations-svelte`](https://
|
|
175
|
-
|
|
202
|
+
[`@runic-artifex/translations-svelte`](https://www.npmjs.com/package/@runic-artifex/translations-svelte).
|
|
203
|
+
Import them from there instead of `@runic-artifex/svelte`.
|
|
@@ -9,8 +9,10 @@ export function useOperation(start, options = {}) {
|
|
|
9
9
|
const controller = createOperationController(start, options);
|
|
10
10
|
let current = $state.raw(controller.current);
|
|
11
11
|
const unsubscribe = controller.subscribe(() => { current = controller.current; });
|
|
12
|
-
//
|
|
13
|
-
//
|
|
12
|
+
// Svelte runs a pre effect when it is created, during owner initialization,
|
|
13
|
+
// so this teardown exists even if the owner is destroyed before its first
|
|
14
|
+
// flush. onMount/onDestroy and $effect are deferred to that flush and would
|
|
15
|
+
// leak the controller then. The effect reads no state, so it never re-runs.
|
|
14
16
|
$effect.pre(() => () => { unsubscribe(); controller.dispose(); });
|
|
15
17
|
return {
|
|
16
18
|
run: controller.run,
|
|
@@ -23,6 +25,7 @@ export function useOperation(start, options = {}) {
|
|
|
23
25
|
get outcome() { return current.outcome; },
|
|
24
26
|
get failure() { return current.failure; },
|
|
25
27
|
get error() { return current.error; },
|
|
28
|
+
get cancelled() { return current.cancelled; },
|
|
26
29
|
get cancellationRequested() { return current.cancellationRequested; },
|
|
27
30
|
get cancelling() { return current.cancelling; },
|
|
28
31
|
get cancellation() { return current.cancellation; },
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Component } from "svelte";
|
|
2
2
|
import type { ViewReference } from "@runic-artifex/views";
|
|
3
3
|
export type { ViewReference } from "@runic-artifex/views";
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Compile-time check that every View kind has a component with a matching page prop. A nullable
|
|
6
|
+
* reference, such as a region slot's `State["main"]`, checks its non-null kinds.
|
|
7
|
+
*/
|
|
8
|
+
export type ViewRegistry<R extends ViewReference | null | undefined> = {
|
|
9
|
+
readonly [K in NonNullable<R>["kind"]]: Component<{
|
|
10
|
+
page: Extract<NonNullable<R>, {
|
|
8
11
|
readonly kind: K;
|
|
9
12
|
}>;
|
|
10
13
|
}>;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/svelte",
|
|
3
|
-
"version": "0.7.0-preview.
|
|
3
|
+
"version": "0.7.0-preview.7",
|
|
4
4
|
"description": "Svelte 5 Application Views helpers for Runic",
|
|
5
|
-
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/
|
|
5
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.7.0-preview.7/packages/web/svelte#readme",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
8
8
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"svelte": ">=5.46.4 <6",
|
|
46
|
-
"@runic-artifex/views": "0.7.0-preview.
|
|
46
|
+
"@runic-artifex/views": "0.7.0-preview.7"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"node": ">=24.18.0 <25"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@runic-artifex/views": "0.7.0-preview.
|
|
62
|
+
"@runic-artifex/views": "0.7.0-preview.7",
|
|
63
63
|
"@sveltejs/adapter-static": "4.0.0",
|
|
64
64
|
"@sveltejs/kit": "3.0.0",
|
|
65
65
|
"@sveltejs/package": "3.0.0",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"vitest": "5.0.3",
|
|
73
73
|
"vite": "8.3.2"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "d274acebd19284557ad6a3d02562ddfac93ae4e1"
|
|
76
76
|
}
|