@runic-artifex/svelte 0.8.0-preview.6 → 0.9.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 +83 -16
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.js +3 -0
- package/dist/views/ViewOutlet.svelte +3 -2
- package/dist/views/ViewOutlet.svelte.d.ts +7 -6
- package/dist/views/index.d.ts +2 -4
- package/dist/views/index.js +0 -1
- package/dist/views/use-collection-viewport.svelte.d.ts +1 -1
- package/dist/views/use-collection-viewport.svelte.js +4 -3
- package/dist/views/use-command.svelte.d.ts +4 -1
- package/dist/views/use-command.svelte.js +14 -2
- package/dist/views/use-view.svelte.d.ts +5 -1
- package/dist/views/use-view.svelte.js +8 -14
- package/dist/views/view-registry.d.ts +2 -3
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# `@runic-artifex/svelte`
|
|
2
2
|
|
|
3
|
-
Svelte 5 Application Views helpers. `@runic-artifex/svelte`
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Svelte 5 Application Views helpers. `@runic-artifex/svelte` exports `useView`,
|
|
4
|
+
`ViewOutlet`, `ViewRegistry`, `useCommand` and `useOperation` for generated
|
|
5
|
+
Window/View clients, and `@runic-artifex/svelte/experimental` exports
|
|
6
|
+
`useCollectionViewport`. The `@runic-artifex/svelte/views` entry of earlier
|
|
7
|
+
previews is gone: import from `@runic-artifex/svelte`.
|
|
6
8
|
|
|
7
9
|
Generated View clients import `@runic-artifex/views`, which this package also
|
|
8
10
|
builds on, so a Views application installs both packages:
|
|
@@ -14,11 +16,12 @@ bun add @runic-artifex/svelte@preview @runic-artifex/views@preview
|
|
|
14
16
|
```
|
|
15
17
|
|
|
16
18
|
Previews are published under the `preview` dist-tag. Install the versions that
|
|
17
|
-
match your Runic SDK packages.
|
|
19
|
+
match your Runic SDK packages. Svelte 5.57.1 or a later 5.x release is supported,
|
|
20
|
+
the same floor as SvelteKit 3 and `@runic-artifex/sveltekit`.
|
|
18
21
|
|
|
19
22
|
```svelte
|
|
20
23
|
<script lang="ts">
|
|
21
|
-
import { useCommand, useView } from "@runic-artifex/svelte
|
|
24
|
+
import { useCommand, useView } from "@runic-artifex/svelte";
|
|
22
25
|
import type { CounterPageReference } from "./generated/counter.js";
|
|
23
26
|
|
|
24
27
|
let { page }: { page: CounterPageReference } = $props();
|
|
@@ -32,9 +35,10 @@ match your Runic SDK packages.
|
|
|
32
35
|
{#if increment.error ?? counter.error}<p role="alert">{String(increment.error ?? counter.error)}</p>{/if}
|
|
33
36
|
```
|
|
34
37
|
|
|
35
|
-
## `useView(source)`
|
|
38
|
+
## `useView(source, options?)`
|
|
36
39
|
|
|
37
|
-
Call `useView` during component initialization.
|
|
40
|
+
Call `useView` during component initialization. `options.release(client)`
|
|
41
|
+
replaces `client.dispose()` for a client the helper connected. It connects a generated page
|
|
38
42
|
reference, or `{ connect: connect<Name> }` for a root ViewModel, while the
|
|
39
43
|
component is mounted and disposes it on destroy or when the getter returns a
|
|
40
44
|
reference with a different `connect` function. An already connected client is
|
|
@@ -52,7 +56,7 @@ Read state one way from `state`. A property with a public C# setter also gets a
|
|
|
52
56
|
```svelte
|
|
53
57
|
<script lang="ts">
|
|
54
58
|
// C#: public partial int Count { get; private set; } public partial int Step { get; set; }
|
|
55
|
-
import { useCommand, useView } from "@runic-artifex/svelte
|
|
59
|
+
import { useCommand, useView } from "@runic-artifex/svelte";
|
|
56
60
|
import type { CounterPageReference } from "./generated/counter.js";
|
|
57
61
|
|
|
58
62
|
let { page }: { page: CounterPageReference } = $props();
|
|
@@ -74,7 +78,7 @@ the reference as its `page` prop:
|
|
|
74
78
|
|
|
75
79
|
```svelte
|
|
76
80
|
<script lang="ts">
|
|
77
|
-
import { useView, ViewOutlet, type ViewRegistry } from "@runic-artifex/svelte
|
|
81
|
+
import { useView, ViewOutlet, type ViewRegistry } from "@runic-artifex/svelte";
|
|
78
82
|
import { connectWorkspace, type WorkspaceState } from "./generated/workspace.js";
|
|
79
83
|
import CounterPage from "./pages/CounterPage.svelte";
|
|
80
84
|
import WelcomePage from "./pages/WelcomePage.svelte";
|
|
@@ -101,7 +105,9 @@ and `failure`.
|
|
|
101
105
|
failure, which `error` then holds until the next run. It never rejects, so
|
|
102
106
|
handlers need no `try`/`catch`. One command can serve several buttons:
|
|
103
107
|
`useCommand((name: "showWelcome" | "showCounter") => workspace.client?.[name]())`
|
|
104
|
-
and `navigate.run("showWelcome")`.
|
|
108
|
+
and `navigate.run("showWelcome")`. Called during component initialization, it
|
|
109
|
+
stops publishing state when the component is destroyed, even before its first
|
|
110
|
+
effect flush; a run in flight is not cancelled and its promise still settles.
|
|
105
111
|
|
|
106
112
|
For a command that declares a failure (`[RunicFailure]` in .NET), `run` resolves the
|
|
107
113
|
`BridgeOutcome`, and `failure` holds the declared failure of the latest run, typed
|
|
@@ -117,7 +123,7 @@ generated View snapshot:
|
|
|
117
123
|
|
|
118
124
|
```svelte
|
|
119
125
|
<script lang="ts">
|
|
120
|
-
import { useOperation, useView } from "@runic-artifex/svelte
|
|
126
|
+
import { useOperation, useView } from "@runic-artifex/svelte";
|
|
121
127
|
import { connectWorkspace } from "./generated/workspace.js";
|
|
122
128
|
|
|
123
129
|
const workspace = useView(() => ({ connect: connectWorkspace }));
|
|
@@ -137,7 +143,7 @@ The result exposes reactive `pending`, `admitting`, `operation`, `status`, `outc
|
|
|
137
143
|
`failure`, `error`, `cancelled`, `cancellationRequested`, `cancelling`, `cancellation`
|
|
138
144
|
and `cancelError`, with `run(...args)`, `cancel()` and `reset()`. Both async methods never
|
|
139
145
|
reject. A run that ends with a `cancelled` status sets `cancelled` and leaves `error`
|
|
140
|
-
undefined; `failed` and `
|
|
146
|
+
undefined; `failed` and `timed-out` statuses are still `error`. Cancel before a delayed Start receipt is retained for that captured run;
|
|
141
147
|
its response does not release pending state. `reset()` clears feedback while
|
|
142
148
|
preserving busy state and cancellation identity. Component destruction settles UI
|
|
143
149
|
observation promises and detaches feedback without cancelling accepted mutations.
|
|
@@ -150,13 +156,13 @@ uses the operation's public `wait()` and `outcome()`; the desktop transport keep
|
|
|
150
156
|
Cancel and other callbacks responsive during observation.
|
|
151
157
|
|
|
152
158
|
For rapid read selection, compose the framework-neutral
|
|
153
|
-
[`createLatestOperationController`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
159
|
+
[`createLatestOperationController`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.9.0/packages/web/views#operation-feedback-and-latest-selection)
|
|
154
160
|
with Svelte state. It coalesces latest intent across delayed receipts and orders
|
|
155
161
|
the next admission after terminal observation and any application drain barrier:
|
|
156
162
|
|
|
157
163
|
```svelte
|
|
158
164
|
<script lang="ts">
|
|
159
|
-
import { createLatestOperationController } from "@runic-artifex/views";
|
|
165
|
+
import { createLatestOperationController } from "@runic-artifex/views/experimental";
|
|
160
166
|
|
|
161
167
|
const selections = createLatestOperationController<void>();
|
|
162
168
|
let selection = $state.raw(selections.current);
|
|
@@ -176,10 +182,71 @@ establish that replacement boundary and own the old work's drain. Lost terminal
|
|
|
176
182
|
observation blocks further Starts instead of retrying blindly, with its reason in
|
|
177
183
|
`current.error`; ordinary Cancel does not clear this block.
|
|
178
184
|
|
|
179
|
-
##
|
|
185
|
+
## Errors
|
|
186
|
+
|
|
187
|
+
The `error` of `useView` and of a command or operation helper is typed
|
|
188
|
+
`unknown`: it holds whatever the connection or the call rejected with. A Bridge
|
|
189
|
+
failure is a `BridgeError` from `@runic-artifex/views`; narrow it with
|
|
190
|
+
`instanceof` before reading `kind`, `route` or `detail`:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { BridgeError } from "@runic-artifex/views";
|
|
194
|
+
|
|
195
|
+
const offline = view.error instanceof BridgeError && view.error.kind === "disconnected";
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`instanceof` holds for errors from every copy of the package on the page.
|
|
199
|
+
[Errors and diagnostics](https://github.com/Runic-Artifex/runic-sdk/tree/v0.9.0/packages/web/views#errors-and-diagnostics)
|
|
200
|
+
lists the kinds. Any other value, such as an exception that your own connect
|
|
201
|
+
function or command callback throws, arrives unchanged.
|
|
202
|
+
|
|
203
|
+
## Interactions
|
|
204
|
+
|
|
205
|
+
A ReactiveUI `Interaction<TInput, TOutput>` on the ViewModel, such as the
|
|
206
|
+
question of a `ReactiveLeaveConfirmation.WithInteraction` leave guard, is
|
|
207
|
+
`client.interactions.<name>` on the generated client. Register the page's answer
|
|
208
|
+
in `$effect`: `handle((prompt, { signal }) => …)` returns the function that
|
|
209
|
+
removes it, so return that from the effect, and Svelte removes the handler when
|
|
210
|
+
the client changes or the component is destroyed:
|
|
211
|
+
|
|
212
|
+
```svelte
|
|
213
|
+
<script lang="ts">
|
|
214
|
+
import { useView } from "@runic-artifex/svelte";
|
|
215
|
+
import type { EditPageReference } from "./generated/edit.js";
|
|
216
|
+
|
|
217
|
+
let { page }: { page: EditPageReference } = $props();
|
|
218
|
+
const view = useView(() => page);
|
|
219
|
+
$effect(() => view.client?.interactions.confirmDiscard.handle(
|
|
220
|
+
async (prompt, { signal }) => confirmDialog(`Discard the changes to ${prompt.itemName}?`, signal),
|
|
221
|
+
));
|
|
222
|
+
</script>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`prompt` and the answer are typed from the ViewModel's interaction. The handler
|
|
226
|
+
may return the answer or a promise of it; `confirmDialog` stands for the
|
|
227
|
+
application's own dialog.
|
|
228
|
+
|
|
229
|
+
- The page is asked for a departure that its own window starts: its Close, the
|
|
230
|
+
shell's Back in the same window, or a guarded window close.
|
|
231
|
+
- `signal` aborts when .NET no longer needs the answer, for example when the
|
|
232
|
+
departure is superseded or the window closes. Close the dialog then; a late
|
|
233
|
+
answer is ignored.
|
|
234
|
+
- The handler exists only after the client connected and the effect ran. A
|
|
235
|
+
departure before that is answered by the ViewModel's .NET fallback handler, or
|
|
236
|
+
fails closed without one.
|
|
237
|
+
|
|
238
|
+
The [ReactiveUI leave confirmation](https://github.com/Runic-Artifex/runic-sdk/blob/v0.9.0/packages/dotnet/Runic.Application.Views.ReactiveUI/README.md#leave-confirmation-in-a-web-view)
|
|
239
|
+
has the .NET side and which View answers which departure. In a frontend test,
|
|
240
|
+
the generated mock's `interactions.<name>.request(input)` resolves with the
|
|
241
|
+
registered handler's answer; see the [Testing guide](https://github.com/Runic-Artifex/runic-sdk/tree/v0.9.0/packages/web/views#testing).
|
|
242
|
+
|
|
243
|
+
## `useCollectionViewport(options)` (experimental)
|
|
244
|
+
|
|
245
|
+
Exported from `@runic-artifex/svelte/experimental`, like the
|
|
246
|
+
`@runic-artifex/views/experimental` controller it wraps.
|
|
180
247
|
|
|
181
248
|
Follows a fixed-row-height scroll container and returns `{ viewport, attach }`.
|
|
182
|
-
`viewport` is the reactive [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
249
|
+
`viewport` is the reactive [`collectionViewport`](https://github.com/Runic-Artifex/runic-sdk/tree/v0.9.0/packages/web/views#collectionviewportoptions-experimental)
|
|
183
250
|
range; `attach` is an attachment for the container. Call it during component
|
|
184
251
|
initialization and send the range to the ViewModel from an effect:
|
|
185
252
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCollectionViewport, type CollectionViewportHandle } from "./views/use-collection-viewport.svelte.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
<script lang="ts" generics="R extends
|
|
1
|
+
<script lang="ts" generics="R extends PageReference">
|
|
2
2
|
import type { Component, Snippet } from "svelte";
|
|
3
|
-
import type {
|
|
3
|
+
import type { PageReference } from "@runic-artifex/views";
|
|
4
|
+
import type { ViewRegistry } from "./view-registry.js";
|
|
4
5
|
|
|
5
6
|
let { content, registry, fallback }: {
|
|
6
7
|
content: R | null | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Snippet } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { PageReference } from "@runic-artifex/views";
|
|
3
|
+
import type { ViewRegistry } from "./view-registry.js";
|
|
4
|
+
declare function $$render<R extends PageReference>(): {
|
|
4
5
|
props: {
|
|
5
6
|
content: R | null | undefined;
|
|
6
7
|
registry: ViewRegistry<R>;
|
|
@@ -12,7 +13,7 @@ declare function $$render<R extends ViewReference>(): {
|
|
|
12
13
|
slots: {};
|
|
13
14
|
events: {};
|
|
14
15
|
};
|
|
15
|
-
declare class __sveltets_Render<R extends
|
|
16
|
+
declare class __sveltets_Render<R extends PageReference> {
|
|
16
17
|
props(): ReturnType<typeof $$render<R>>['props'];
|
|
17
18
|
events(): ReturnType<typeof $$render<R>>['events'];
|
|
18
19
|
slots(): ReturnType<typeof $$render<R>>['slots'];
|
|
@@ -20,12 +21,12 @@ declare class __sveltets_Render<R extends ViewReference> {
|
|
|
20
21
|
exports(): {};
|
|
21
22
|
}
|
|
22
23
|
interface $$IsomorphicComponent {
|
|
23
|
-
new <R extends
|
|
24
|
+
new <R extends PageReference>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
|
24
25
|
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
|
25
26
|
} & ReturnType<__sveltets_Render<R>['exports']>;
|
|
26
|
-
<R extends
|
|
27
|
+
<R extends PageReference>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
|
27
28
|
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
28
29
|
}
|
|
29
30
|
declare const ViewOutlet: $$IsomorphicComponent;
|
|
30
|
-
type ViewOutlet<R extends
|
|
31
|
+
type ViewOutlet<R extends PageReference> = InstanceType<typeof ViewOutlet<R>>;
|
|
31
32
|
export default ViewOutlet;
|
package/dist/views/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export { default as ViewOutlet } from "./ViewOutlet.svelte";
|
|
2
|
-
export type {
|
|
3
|
-
export { useView, type ViewHandle } from "./use-view.svelte.js";
|
|
2
|
+
export type { ViewRegistry } from "./view-registry.js";
|
|
3
|
+
export { useView, type UseViewOptions, type ViewHandle } from "./use-view.svelte.js";
|
|
4
4
|
export { useCommand, type CommandHandle } from "./use-command.svelte.js";
|
|
5
5
|
export { useOperation, type OperationHandle } from "./use-operation.svelte.js";
|
|
6
|
-
export { useCollectionViewport, type CollectionViewportHandle } from "./use-collection-viewport.svelte.js";
|
|
7
|
-
export type { CollectionViewport, CollectionViewportOptions, ViewClient, ViewConnector, ViewSource } from "@runic-artifex/views";
|
package/dist/views/index.js
CHANGED
|
@@ -2,4 +2,3 @@ export { default as ViewOutlet } from "./ViewOutlet.svelte";
|
|
|
2
2
|
export { useView } from "./use-view.svelte.js";
|
|
3
3
|
export { useCommand } from "./use-command.svelte.js";
|
|
4
4
|
export { useOperation } from "./use-operation.svelte.js";
|
|
5
|
-
export { useCollectionViewport } from "./use-collection-viewport.svelte.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Attachment } from "svelte/attachments";
|
|
2
|
-
import { type CollectionViewport, type CollectionViewportOptions } from "@runic-artifex/views";
|
|
2
|
+
import { type CollectionViewport, type CollectionViewportOptions } from "@runic-artifex/views/experimental";
|
|
3
3
|
export interface CollectionViewportHandle {
|
|
4
4
|
/** The rows to request and the sizes to render. */
|
|
5
5
|
readonly viewport: CollectionViewport;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { untrack } from "svelte";
|
|
2
|
-
import { createCollectionViewportController } from "@runic-artifex/views";
|
|
2
|
+
import { createCollectionViewportController } from "@runic-artifex/views/experimental";
|
|
3
3
|
/**
|
|
4
4
|
* Follows a fixed-row-height scroll container and returns the rows to request
|
|
5
5
|
* from .NET. Call it during component initialization with a getter, such as
|
|
@@ -9,12 +9,13 @@ import { createCollectionViewportController } from "@runic-artifex/views";
|
|
|
9
9
|
export function useCollectionViewport(options) {
|
|
10
10
|
const controller = createCollectionViewportController(untrack(options));
|
|
11
11
|
let viewport = $state.raw(controller.current);
|
|
12
|
-
controller.subscribe(() => { viewport = controller.current; });
|
|
12
|
+
const unsubscribe = controller.subscribe(() => { viewport = controller.current; });
|
|
13
|
+
// Registered before the first flush, so a destroyed owner never leaks the controller (see useOperation).
|
|
14
|
+
$effect.pre(() => () => { unsubscribe(); controller.dispose(); });
|
|
13
15
|
$effect.pre(() => {
|
|
14
16
|
const { totalCount, rowHeight, overscan } = options();
|
|
15
17
|
controller.update({ totalCount, rowHeight, ...(overscan === undefined ? {} : { overscan }) });
|
|
16
18
|
});
|
|
17
|
-
$effect(() => () => controller.dispose());
|
|
18
19
|
return {
|
|
19
20
|
get viewport() { return viewport; },
|
|
20
21
|
attach(element) {
|
|
@@ -19,7 +19,10 @@ export interface CommandHandle<TArgs extends readonly unknown[], TResult, TFailu
|
|
|
19
19
|
reset(): void;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Tracks a command's pending state and failure as reactive properties.
|
|
22
|
+
* Tracks a command's pending state and failure as reactive properties. Called
|
|
23
|
+
* during component initialization (or in `$effect.root`), owner destruction
|
|
24
|
+
* stops publishing state without cancelling a run in flight, whose promise
|
|
25
|
+
* still settles. The
|
|
23
26
|
* command may close over reactive values:
|
|
24
27
|
*
|
|
25
28
|
* ```svelte
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { createCommandController } from "@runic-artifex/views";
|
|
2
2
|
/**
|
|
3
|
-
* Tracks a command's pending state and failure as reactive properties.
|
|
3
|
+
* Tracks a command's pending state and failure as reactive properties. Called
|
|
4
|
+
* during component initialization (or in `$effect.root`), owner destruction
|
|
5
|
+
* stops publishing state without cancelling a run in flight, whose promise
|
|
6
|
+
* still settles. The
|
|
4
7
|
* command may close over reactive values:
|
|
5
8
|
*
|
|
6
9
|
* ```svelte
|
|
@@ -11,7 +14,16 @@ import { createCommandController } from "@runic-artifex/views";
|
|
|
11
14
|
export function useCommand(command) {
|
|
12
15
|
const controller = createCommandController(command);
|
|
13
16
|
let current = $state.raw(controller.current);
|
|
14
|
-
controller.subscribe(() => { current = controller.current; });
|
|
17
|
+
const unsubscribe = controller.subscribe(() => { current = controller.current; });
|
|
18
|
+
// Registered before the first flush, so a destroyed owner never leaks the controller (see useOperation).
|
|
19
|
+
// Outside an owner, which useCommand has always allowed, there is nothing to release it with.
|
|
20
|
+
try {
|
|
21
|
+
$effect.pre(() => () => { unsubscribe(); controller.dispose(); });
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (!String(error?.message).includes("effect_orphan"))
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
15
27
|
return {
|
|
16
28
|
run: controller.run,
|
|
17
29
|
get pending() { return current.pending; },
|
|
@@ -20,4 +20,8 @@ export interface ViewHandle<TClient extends ViewClient> {
|
|
|
20
20
|
* A reference is identified by its `connect` function, so a getter returning a
|
|
21
21
|
* new `{ connect: connectShell }` object does not reconnect.
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export interface UseViewOptions<TClient extends ViewClient> {
|
|
24
|
+
/** Releases a client this helper connected. Defaults to `client.dispose()`. */
|
|
25
|
+
readonly release?: (client: TClient) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare function useView<TClient extends ViewClient>(source: () => ViewSource<TClient>, options?: UseViewOptions<TClient>): ViewHandle<TClient>;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { untrack } from "svelte";
|
|
2
|
-
import { createViewController
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* initialization with a getter, such as `useView(() => page)`, so a changed
|
|
7
|
-
* prop disposes the previous client and connects the new one.
|
|
8
|
-
*
|
|
9
|
-
* A reference is identified by its `connect` function, so a getter returning a
|
|
10
|
-
* new `{ connect: connectShell }` object does not reconnect.
|
|
11
|
-
*/
|
|
12
|
-
export function useView(source) {
|
|
13
|
-
const controller = createViewController();
|
|
2
|
+
import { createViewController } from "@runic-artifex/views";
|
|
3
|
+
import { isViewClient, viewSourceIdentity } from "@runic-artifex/views/bindings";
|
|
4
|
+
export function useView(source, options = {}) {
|
|
5
|
+
const controller = createViewController(options.release ? { release: options.release } : {});
|
|
14
6
|
let current = $state.raw(controller.current);
|
|
15
|
-
controller.subscribe(() => { current = controller.current; });
|
|
7
|
+
const unsubscribe = controller.subscribe(() => { current = controller.current; });
|
|
8
|
+
// A pre effect runs when it is created, so the teardown exists even if the
|
|
9
|
+
// owner is destroyed before its first flush (see useOperation).
|
|
10
|
+
$effect.pre(() => () => { unsubscribe(); controller.dispose(); });
|
|
16
11
|
const identity = $derived(viewSourceIdentity(source()));
|
|
17
12
|
$effect(() => {
|
|
18
13
|
void identity;
|
|
@@ -21,7 +16,6 @@ export function useView(source) {
|
|
|
21
16
|
current = controller.current;
|
|
22
17
|
});
|
|
23
18
|
});
|
|
24
|
-
$effect(() => () => controller.dispose());
|
|
25
19
|
// A connected client is readable before the effect observes it, and a
|
|
26
20
|
// changed reference does not show the previous one until the effect follows it.
|
|
27
21
|
const observed = () => {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Component } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
export type { ViewReference } from "@runic-artifex/views";
|
|
2
|
+
import type { PageReference } from "@runic-artifex/views";
|
|
4
3
|
/**
|
|
5
4
|
* Compile-time check that every View kind has a component with a matching page prop. A nullable
|
|
6
5
|
* reference, such as a region slot's `State["main"]`, checks its non-null kinds.
|
|
7
6
|
*/
|
|
8
|
-
export type ViewRegistry<R extends
|
|
7
|
+
export type ViewRegistry<R extends PageReference | null | undefined> = {
|
|
9
8
|
readonly [K in NonNullable<R>["kind"]]: Component<{
|
|
10
9
|
page: Extract<NonNullable<R>, {
|
|
11
10
|
readonly kind: K;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runic-artifex/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Svelte 5 Application Views helpers for Runic",
|
|
5
|
-
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.
|
|
5
|
+
"homepage": "https://github.com/Runic-Artifex/runic-sdk/tree/v0.9.0/packages/web/svelte#readme",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/Runic-Artifex/runic-sdk/issues"
|
|
8
8
|
},
|
|
@@ -21,13 +21,16 @@
|
|
|
21
21
|
".": {
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"svelte": "./dist/index.js",
|
|
24
|
-
"import": "./dist/index.js"
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"default": "./dist/index.js"
|
|
25
26
|
},
|
|
26
|
-
"./
|
|
27
|
-
"types": "./dist/
|
|
28
|
-
"svelte": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
30
|
-
|
|
27
|
+
"./experimental": {
|
|
28
|
+
"types": "./dist/experimental.d.ts",
|
|
29
|
+
"svelte": "./dist/experimental.js",
|
|
30
|
+
"import": "./dist/experimental.js",
|
|
31
|
+
"default": "./dist/experimental.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
31
34
|
},
|
|
32
35
|
"files": [
|
|
33
36
|
"dist",
|
|
@@ -38,12 +41,12 @@
|
|
|
38
41
|
"clean": "bun -e \"import('node:fs').then(({rmSync}) => rmSync('dist', { recursive: true, force: true }))\"",
|
|
39
42
|
"build": "bun run --bun clean && svelte-package -i src -o dist",
|
|
40
43
|
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
41
|
-
"test": "bun run --bun build && svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && vitest run test/use-view.svelte.test.ts test/glue.svelte.test.ts test/use-operation.svelte.test.ts",
|
|
44
|
+
"test": "bun run --bun build && svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && vitest run test/use-view.svelte.test.ts test/glue.svelte.test.ts test/use-operation.svelte.test.ts test/lifecycle.svelte.test.ts",
|
|
42
45
|
"pack:check": "bun pm pack --dry-run"
|
|
43
46
|
},
|
|
44
47
|
"peerDependencies": {
|
|
45
|
-
"svelte": ">=5.
|
|
46
|
-
"@runic-artifex/views": "0.
|
|
48
|
+
"svelte": ">=5.57.1 <6",
|
|
49
|
+
"@runic-artifex/views": "0.9.0"
|
|
47
50
|
},
|
|
48
51
|
"publishConfig": {
|
|
49
52
|
"access": "public",
|
|
@@ -55,11 +58,8 @@
|
|
|
55
58
|
"directory": "packages/web/svelte"
|
|
56
59
|
},
|
|
57
60
|
"packageManager": "bun@1.4.2",
|
|
58
|
-
"engines": {
|
|
59
|
-
"node": ">=24.18.0 <25"
|
|
60
|
-
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@runic-artifex/views": "0.
|
|
62
|
+
"@runic-artifex/views": "0.9.0",
|
|
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": "6793f99c726af8b1d05067108761905aa5e8d0d6"
|
|
76
76
|
}
|