@xmachines/play-sveltekit-router 4.0.0 → 5.0.1
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 +17 -17
- package/dist/connect-router.d.ts +2 -2
- package/dist/connect-router.d.ts.map +1 -1
- package/dist/connect-router.js +5 -4
- package/dist/connect-router.js.map +1 -1
- package/dist/sveltekit-router-bridge.d.ts +2 -2
- package/dist/sveltekit-router-bridge.d.ts.map +1 -1
- package/dist/sveltekit-router-bridge.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
SvelteKit router adapter for the XMachines Universal Player Architecture. It keeps the state machine routes of a `RoutableActor` and the browser URL in step, in both directions, through the `$app/navigation` module of SvelteKit.
|
|
4
4
|
|
|
5
|
-
[](https://opensource.org/licenses/MIT) [](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@xmachines/play-sveltekit-router)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -49,7 +49,7 @@ onDestroy(() => disconnect());
|
|
|
49
49
|
The bridge works in both directions:
|
|
50
50
|
|
|
51
51
|
- **URL → actor:** the bridge converts each SvelteKit `afterNavigate` event into a `play.route` event, then sends it to the actor.
|
|
52
|
-
- **Actor → URL:** the bridge writes each change of the actor `currentRoute`
|
|
52
|
+
- **Actor → URL:** the bridge writes each change of the actor `currentRoute` atom to the browser URL with `goto()`.
|
|
53
53
|
|
|
54
54
|
## Usage
|
|
55
55
|
|
|
@@ -88,7 +88,7 @@ onDestroy(() => disconnect());
|
|
|
88
88
|
|
|
89
89
|
### `SvelteKitRouterBridge` — low-level class
|
|
90
90
|
|
|
91
|
-
This class extends `RouterBridgeBase` from `@xmachines/play-router
|
|
91
|
+
This class extends `RouterBridgeBase` from [`@xmachines/play-router`](../play-router/README.md). Use it directly when you need more control over the connection lifecycle.
|
|
92
92
|
|
|
93
93
|
```typescript
|
|
94
94
|
import { SvelteKitRouterBridge } from "@xmachines/play-sveltekit-router";
|
|
@@ -110,7 +110,7 @@ bridge.disconnect();
|
|
|
110
110
|
|
|
111
111
|
### `createRouteMap(machine)` — from `@xmachines/play-router/xstate`
|
|
112
112
|
|
|
113
|
-
This factory builds a `RouteMap` from an XState machine definition. It reads each route pattern from `state.meta.route`. This package re-exports it never: the barrel names no state machine, so import the function from `@xmachines/play-router/xstate
|
|
113
|
+
This factory builds a `RouteMap` from an XState machine definition. It reads each route pattern from `state.meta.route`. This package re-exports it never: the barrel names no state machine, so import the function from [`@xmachines/play-router/xstate`](../play-router/README.md).
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
116
|
import { createRouteMap } from "@xmachines/play-router/xstate";
|
|
@@ -131,7 +131,7 @@ const routeMap = createRouteMap(machine);
|
|
|
131
131
|
|
|
132
132
|
### `RouteMap` / `RouteMapping`
|
|
133
133
|
|
|
134
|
-
The bidirectional map between the state IDs and the URL paths. It comes from `@xmachines/play-router
|
|
134
|
+
The bidirectional map between the state IDs and the URL paths. It comes from [`@xmachines/play-router`](../play-router/README.md).
|
|
135
135
|
|
|
136
136
|
```typescript
|
|
137
137
|
import { RouteMap } from "@xmachines/play-sveltekit-router";
|
|
@@ -147,18 +147,18 @@ const routeMap = new RouteMap([
|
|
|
147
147
|
|
|
148
148
|
### Exported symbols
|
|
149
149
|
|
|
150
|
-
| Export | Kind | Description
|
|
151
|
-
| ----------------------- | -------- |
|
|
152
|
-
| `connectRouter` | function | High-level factory — connects the SvelteKit router to an actor, returns a cleanup function
|
|
153
|
-
| `SvelteKitRouterBridge` | class | The low-level bridge class. It extends `RouterBridgeBase`. Use it directly for full lifecycle control
|
|
154
|
-
| `ConnectRouterOptions` | type | The options object for `connectRouter`
|
|
155
|
-
| `RouteMap` | class | Bidirectional state ID ↔ URL path mapping (re-exported from `@xmachines/play-router`) |
|
|
156
|
-
| `RouteMapping` | type | Single `{ stateId, path }` entry for `RouteMap` construction
|
|
157
|
-
| `RouteMapOptions` | type | Options for `RouteMap` construction
|
|
158
|
-
| `LocationLike` | type | Minimal `{ pathname, search }` interface for location stubs
|
|
159
|
-
| `PlayRouteEvent` | type | The event that the bridge sends to the actor on a URL change (`{ type: "play.route", to, params?, query? }`)
|
|
160
|
-
| `RouterBridge` | type | The interface that `SvelteKitRouterBridge` implements
|
|
161
|
-
| `RoutableActor` | type | Minimal actor interface from `@xmachines/play-router` — `currentRoute`, `initialRoute`, `send(PlayRouteEvent)` |
|
|
150
|
+
| Export | Kind | Description |
|
|
151
|
+
| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
152
|
+
| `connectRouter` | function | High-level factory — connects the SvelteKit router to an actor, returns a cleanup function |
|
|
153
|
+
| `SvelteKitRouterBridge` | class | The low-level bridge class. It extends `RouterBridgeBase`. Use it directly for full lifecycle control |
|
|
154
|
+
| `ConnectRouterOptions` | type | The options object for `connectRouter` |
|
|
155
|
+
| `RouteMap` | class | Bidirectional state ID ↔ URL path mapping (re-exported from [`@xmachines/play-router`](../play-router/README.md)) |
|
|
156
|
+
| `RouteMapping` | type | Single `{ stateId, path }` entry for `RouteMap` construction |
|
|
157
|
+
| `RouteMapOptions` | type | Options for `RouteMap` construction |
|
|
158
|
+
| `LocationLike` | type | Minimal `{ pathname, search }` interface for location stubs |
|
|
159
|
+
| `PlayRouteEvent` | type | The event that the bridge sends to the actor on a URL change (`{ type: "play.route", to, params?, query? }`) |
|
|
160
|
+
| `RouterBridge` | type | The interface that `SvelteKitRouterBridge` implements |
|
|
161
|
+
| `RoutableActor` | type | Minimal actor interface from [`@xmachines/play-router`](../play-router/README.md) — `currentRoute`, `initialRoute`, `send(PlayRouteEvent)` |
|
|
162
162
|
|
|
163
163
|
## Demo
|
|
164
164
|
|
package/dist/connect-router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RouterConnection } from "@xmachines/play-router";
|
|
2
|
-
import type {
|
|
3
|
-
export interface ConnectRouterOptions extends
|
|
2
|
+
import type { RouterBridgeOptions, RoutableActor, RouteMap, LocationLike } from "@xmachines/play-router";
|
|
3
|
+
export interface ConnectRouterOptions extends RouterBridgeOptions {
|
|
4
4
|
readonly actor: RoutableActor;
|
|
5
5
|
readonly routeMap: RouteMap;
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-router.d.ts","sourceRoot":"","sources":["../src/connect-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EACX,
|
|
1
|
+
{"version":3,"file":"connect-router.d.ts","sourceRoot":"","sources":["../src/connect-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EACX,mBAAmB,EACnB,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAChE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CAQ7E"}
|
package/dist/connect-router.js
CHANGED
|
@@ -15,10 +15,11 @@ import { SvelteKitRouterBridge } from "./sveltekit-router-bridge.js";
|
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export function connectRouter(options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
18
|
+
// The REST travels whole, exactly as `openProviderBridge` hands it on. A hand-written
|
|
19
|
+
// list of the bridge options dropped every cache of the caller in silence there, and
|
|
20
|
+
// it would drop whatever a later release adds here.
|
|
21
|
+
const { actor, routeMap, location: loc, ...bridgeOptions } = options;
|
|
22
|
+
const bridge = new SvelteKitRouterBridge(actor, routeMap, loc, bridgeOptions);
|
|
22
23
|
bridge.connect();
|
|
23
24
|
return createRouterConnection(bridge);
|
|
24
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect-router.js","sourceRoot":"","sources":["../src/connect-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,wBAAwB,CAAC;AAOvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAarE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IAC1D,
|
|
1
|
+
{"version":3,"file":"connect-router.js","sourceRoot":"","sources":["../src/connect-router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAyB,MAAM,wBAAwB,CAAC;AAOvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAarE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IAC1D,sFAAsF;IACtF,qFAAqF;IACrF,oDAAoD;IACpD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IACrE,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;IAC9E,MAAM,CAAC,OAAO,EAAE,CAAC;IACjB,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RouterBridgeBase } from "@xmachines/play-router";
|
|
2
2
|
import type { LocationLike, RouteMap } from "@xmachines/play-router";
|
|
3
3
|
import type { RoutableActor } from "@xmachines/play-router";
|
|
4
|
-
import type {
|
|
4
|
+
import type { RouterBridgeOptions } from "@xmachines/play-router";
|
|
5
5
|
/**
|
|
6
6
|
* The SvelteKit router bridge — it connects the SvelteKit navigation to RouterBridgeBase.
|
|
7
7
|
*
|
|
@@ -39,7 +39,7 @@ export declare class SvelteKitRouterBridge extends RouterBridgeBase {
|
|
|
39
39
|
* callback registry of SvelteKit untouched.
|
|
40
40
|
*/
|
|
41
41
|
private afterNavigateCell;
|
|
42
|
-
constructor(actor: RoutableActor, routeMap: RouteMap, loc?: LocationLike | null, options?:
|
|
42
|
+
constructor(actor: RoutableActor, routeMap: RouteMap, loc?: LocationLike | null, options?: RouterBridgeOptions);
|
|
43
43
|
/**
|
|
44
44
|
* Pushes a RESOLVED concrete URL path through the SvelteKit `goto` function.
|
|
45
45
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sveltekit-router-bridge.d.ts","sourceRoot":"","sources":["../src/sveltekit-router-bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"sveltekit-router-bridge.d.ts","sourceRoot":"","sources":["../src/sveltekit-router-bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAclE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,qBAAsB,SAAQ,gBAAgB;IAC1D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAsB;IAE1C;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,iBAAiB,CAAsC;gBAG9D,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,QAAQ,EAClB,GAAG,GAAE,YAAY,GAAG,IAAmE,EACvF,OAAO,CAAC,EAAE,mBAAmB;IAM9B;;;;;;OAMG;IACH,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI5C,SAAS,CAAC,kBAAkB,IAAI,IAAI;IAmBpC;;;;;;;OAOG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;cAOnB,oBAAoB,IAAI,MAAM,GAAG,IAAI;cAIrC,sBAAsB,IAAI,MAAM,GAAG,SAAS;CAG/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sveltekit-router-bridge.js","sourceRoot":"","sources":["../src/sveltekit-router-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiB1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,qBAAsB,SAAQ,gBAAgB;IACzC,GAAG,CAAsB;IAE1C;;;;;;;;;;;OAWG;IACK,iBAAiB,GAAiC,IAAI,CAAC;IAE/D,YACC,KAAoB,EACpB,QAAkB,EAClB,MAA4B,UAA0C,CAAC,QAAQ,IAAI,IAAI,EACvF,
|
|
1
|
+
{"version":3,"file":"sveltekit-router-bridge.js","sourceRoot":"","sources":["../src/sveltekit-router-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiB1D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,qBAAsB,SAAQ,gBAAg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QACtC,OAAO,IAAI,CAAC,GAAG,EAAE,QAAQ,IAAI,IAAI,CAAC;IACnC,CAAC;IAEkB,sBAAsB;QACxC,OAAO,IAAI,CAAC,GAAG,EAAE,MAAM,IAAI,SAAS,CAAC;IACtC,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/play-sveltekit-router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "SvelteKit router adapter for XMachines Universal Player Architecture",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"clean": "rm -rf dist *.tsbuildinfo coverage .vitest-attachments node_modules/.svelte2tsx-* node_modules/.vite*"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@xmachines/play-router": "
|
|
50
|
+
"@xmachines/play-router": "5.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@sveltejs/kit": "^2.70.3",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"@testing-library/jest-dom": "^7.0.1",
|
|
56
56
|
"@types/node": "^26.6.2",
|
|
57
57
|
"@vitest/browser-playwright": "^5.0.1",
|
|
58
|
-
"@xmachines/play": "
|
|
59
|
-
"@xmachines/play-actor": "
|
|
60
|
-
"@xmachines/play-
|
|
61
|
-
"@xmachines/play-svelte": "
|
|
62
|
-
"oxfmt": "^0.
|
|
63
|
-
"oxlint": "^1.
|
|
58
|
+
"@xmachines/play": "5.0.1",
|
|
59
|
+
"@xmachines/play-actor": "5.0.1",
|
|
60
|
+
"@xmachines/play-atom": "5.0.1",
|
|
61
|
+
"@xmachines/play-svelte": "5.0.1",
|
|
62
|
+
"oxfmt": "^0.70.0",
|
|
63
|
+
"oxlint": "^1.85.0",
|
|
64
64
|
"svelte": "^5.57.0",
|
|
65
65
|
"typescript": "^5.9.3 || ^6.0.3",
|
|
66
66
|
"vite": "^8.3.0",
|