@xmachines/play-sveltekit-router 3.0.0 → 4.0.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
@@ -2,36 +2,37 @@
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
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Version](https://img.shields.io/badge/version-3.0.0-blue)](https://www.npmjs.com/package/@xmachines/play-sveltekit-router)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Version](https://img.shields.io/badge/version-4.0.0-blue)](https://www.npmjs.com/package/@xmachines/play-sveltekit-router)
6
6
 
7
7
  ## Installation
8
8
 
9
9
  ```bash
10
- pnpm add @xmachines/play-sveltekit-router
10
+ pnpm add @xmachines/play-sveltekit-router @xmachines/play-router
11
11
  ```
12
12
 
13
13
  **Peer dependencies.** Install them separately:
14
14
 
15
15
  ```bash
16
- pnpm add @sveltejs/kit svelte xstate
16
+ pnpm add @sveltejs/kit svelte
17
17
  ```
18
18
 
19
19
  | Peer dependency | Required version |
20
20
  | --------------- | ---------------- |
21
21
  | `@sveltejs/kit` | `^2.0.0` |
22
22
  | `svelte` | `^5.0.0` |
23
- | `xstate` | `^5.31.0` |
24
23
 
25
24
  ## Quick Start
26
25
 
27
26
  ```typescript
28
27
  import { onDestroy } from "svelte";
29
- import { connectRouter, createRouteMap } from "@xmachines/play-sveltekit-router";
30
- import { definePlayer } from "@xmachines/play-xstate";
28
+ import { connectRouter } from "@xmachines/play-sveltekit-router";
29
+ import { createRouteMap } from "@xmachines/play-router/xstate";
30
+ import { definePlayer, compose, PlayerActor } from "@xmachines/play-xstate";
31
+ import { withRouting } from "@xmachines/play-xstate/routing";
31
32
  import { myMachine } from "./machine.js";
32
33
 
33
- // 1. Create the actor
34
- const createPlayer = definePlayer({ machine: myMachine });
34
+ // 1. Create the actor — `connectRouter` needs the routing capability
35
+ const createPlayer = definePlayer({ machine: myMachine, actor: compose(PlayerActor, withRouting) });
35
36
  const actor = createPlayer();
36
37
  actor.start();
37
38
 
@@ -58,8 +59,8 @@ This function is the primary integration point. It creates a `SvelteKitRouterBri
58
59
 
59
60
  ```typescript
60
61
  import { onDestroy } from "svelte";
61
- import { connectRouter, createRouteMap } from "@xmachines/play-sveltekit-router";
62
-
62
+ import { connectRouter } from "@xmachines/play-sveltekit-router";
63
+ import { createRouteMap } from "@xmachines/play-router/xstate";
63
64
  // machine and actor as in the Quick Start above
64
65
  const routeMap = createRouteMap(machine);
65
66
 
@@ -90,8 +91,8 @@ onDestroy(() => disconnect());
90
91
  This class extends `RouterBridgeBase` from `@xmachines/play-router`. Use it directly when you need more control over the connection lifecycle.
91
92
 
92
93
  ```typescript
93
- import { SvelteKitRouterBridge, createRouteMap } from "@xmachines/play-sveltekit-router";
94
-
94
+ import { SvelteKitRouterBridge } from "@xmachines/play-sveltekit-router";
95
+ import { createRouteMap } from "@xmachines/play-router/xstate";
95
96
  // machine and actor as in the Quick Start above
96
97
  const routeMap = createRouteMap(machine);
97
98
  const bridge = new SvelteKitRouterBridge(actor, routeMap, location);
@@ -107,12 +108,12 @@ bridge.disconnect();
107
108
  - `watchRouterChanges` → registers an `afterNavigate` callback through an indirection cell, which prevents a direct capture of `this`
108
109
  - `unwatchRouterChanges` → sets the indirection cell to null, which releases the bridge reference before the component unmounts (SvelteKit has no API to cancel `afterNavigate`)
109
110
 
110
- ### `createRouteMap(machine)`
111
+ ### `createRouteMap(machine)` — from `@xmachines/play-router/xstate`
111
112
 
112
- This factory builds a `RouteMap` from an XState machine definition. It reads each route pattern from `state.meta.route`.
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
114
 
114
115
  ```typescript
115
- import { createRouteMap } from "@xmachines/play-sveltekit-router";
116
+ import { createRouteMap } from "@xmachines/play-router/xstate";
116
117
  import { createMachine } from "xstate";
117
118
 
118
119
  const machine = createMachine({
@@ -151,7 +152,6 @@ const routeMap = new RouteMap([
151
152
  | `connectRouter` | function | High-level factory — connects the SvelteKit router to an actor, returns a cleanup function |
152
153
  | `SvelteKitRouterBridge` | class | The low-level bridge class. It extends `RouterBridgeBase`. Use it directly for full lifecycle control |
153
154
  | `ConnectRouterOptions` | type | The options object for `connectRouter` |
154
- | `createRouteMap` | function | Builds a `RouteMap` from an XState machine definition |
155
155
  | `RouteMap` | class | Bidirectional state ID ↔ URL path mapping (re-exported from `@xmachines/play-router`) |
156
156
  | `RouteMapping` | type | Single `{ stateId, path }` entry for `RouteMap` construction |
157
157
  | `RouteMapOptions` | type | Options for `RouteMap` construction |
@@ -171,20 +171,6 @@ pnpm --filter @xmachines/play-sveltekit-router-demo run dev
171
171
 
172
172
  Then open `http://localhost:5173`.
173
173
 
174
- ## Testing
175
-
176
- Run tests for this package in isolation:
177
-
178
- ```bash
179
- # From the monorepo root
180
- pnpm --filter @xmachines/play-sveltekit-router test
181
-
182
- # Or from this package directory
183
- pnpm test
184
- ```
185
-
186
- Coverage thresholds: **80%** lines, functions, branches, and statements.
187
-
188
174
  ## License
189
175
 
190
176
  MIT — see [LICENSE](LICENSE).
@@ -17,7 +17,8 @@ export interface ConnectRouterOptions extends BasePathOptions {
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
- * import { connectRouter, createRouteMap } from '@xmachines/play-sveltekit-router';
20
+ * import { connectRouter } from '@xmachines/play-sveltekit-router';
21
+ * import { createRouteMap } from '@xmachines/play-router/xstate';
21
22
  * const routeMap = createRouteMap(machine);
22
23
  * const disconnect = connectRouter({ actor, routeMap });
23
24
  * onDestroy(() => disconnect());
@@ -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,eAAe,EACf,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC5D,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;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,gBAAgB,CAO7E"}
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,eAAe,EACf,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC5D,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,CAO7E"}
@@ -7,7 +7,8 @@ import { SvelteKitRouterBridge } from "./sveltekit-router-bridge.js";
7
7
  *
8
8
  * @example
9
9
  * ```typescript
10
- * import { connectRouter, createRouteMap } from '@xmachines/play-sveltekit-router';
10
+ * import { connectRouter } from '@xmachines/play-sveltekit-router';
11
+ * import { createRouteMap } from '@xmachines/play-router/xstate';
11
12
  * const routeMap = createRouteMap(machine);
12
13
  * const disconnect = connectRouter({ actor, routeMap });
13
14
  * onDestroy(() => disconnect());
@@ -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;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,OAA6B;IAC1D,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3F,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;KACtC,CAAC,CAAC;IACH,MAAM,CAAC,OAAO,EAAE,CAAC;IACjB,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
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,MAAM,MAAM,GAAG,IAAI,qBAAqB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC3F,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;KACtC,CAAC,CAAC;IACH,MAAM,CAAC,OAAO,EAAE,CAAC;IACjB,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @xmachines/play-sveltekit-router - SvelteKit router adapter for XMachines Play
3
3
  */
4
- export { RouteMap, createRouteMap, type RouteMapping, type RouteMapOptions, } from "@xmachines/play-router";
4
+ export { RouteMap, type RouteMapping, type RouteMapOptions } from "@xmachines/play-router";
5
5
  export { SvelteKitRouterBridge } from "./sveltekit-router-bridge.js";
6
6
  export { connectRouter } from "./connect-router.js";
7
7
  export type { BasePathOptions, RouterConnection } from "@xmachines/play-router";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,QAAQ,EACR,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,eAAe,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChF,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChF,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,12 @@
1
1
  /**
2
2
  * @xmachines/play-sveltekit-router - SvelteKit router adapter for XMachines Play
3
3
  */
4
- export { RouteMap, createRouteMap, } from "@xmachines/play-router";
4
+ // This barrel names NO state machine. `createRouteMap` and `extractMachineRoutes`
5
+ // read an XState machine, and they live in `@xmachines/play-router/xstate`, where
6
+ // `xstate` is an OPTIONAL peer. A re-export here loads that module for every
7
+ // consumer of this package, and the import fails when the consumer installed no
8
+ // `xstate`. Import those two from `@xmachines/play-router/xstate` directly.
9
+ export { RouteMap } from "@xmachines/play-router";
5
10
  export { SvelteKitRouterBridge } from "./sveltekit-router-bridge.js";
6
11
  export { connectRouter } from "./connect-router.js";
7
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,QAAQ,EACR,cAAc,GAGd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,kFAAkF;AAClF,kFAAkF;AAClF,6EAA6E;AAC7E,gFAAgF;AAChF,4EAA4E;AAE5E,OAAO,EAAE,QAAQ,EAA2C,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  /**
2
2
  * The type definitions of @xmachines/play-sveltekit-router
3
3
  */
4
- import type { AbstractActor, Routable } from "@xmachines/play-actor";
5
- import type { AnyActorLogic } from "xstate";
6
4
  export type { PlayRouteEvent, RouterBridge } from "@xmachines/play-router";
7
- export type RoutableActor = AbstractActor<AnyActorLogic> & Routable;
5
+ export type { RoutableActor } from "@xmachines/play-router";
8
6
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3E,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3E,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-sveltekit-router",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "SvelteKit router adapter for XMachines Universal Player Architecture",
5
5
  "keywords": [
6
6
  "adapter",
@@ -40,38 +40,38 @@
40
40
  "scripts": {
41
41
  "build": "vite build && tsc --build",
42
42
  "lint": "oxlint .",
43
+ "lint:security": "node ../../scripts/semgrep-scan.mjs",
43
44
  "format": "oxfmt .",
44
45
  "test": "vitest",
45
46
  "test:coverage": "vitest run --coverage",
46
47
  "clean": "rm -rf dist *.tsbuildinfo coverage .vitest-attachments node_modules/.svelte2tsx-* node_modules/.vite*"
47
48
  },
48
49
  "dependencies": {
49
- "@xmachines/play": "3.0.0",
50
- "@xmachines/play-actor": "3.0.0",
51
- "@xmachines/play-router": "3.0.0",
52
- "@xmachines/play-signals": "3.0.0"
50
+ "@xmachines/play-router": "4.0.0"
53
51
  },
54
52
  "devDependencies": {
55
- "@sveltejs/kit": "^2.70.2",
56
- "@sveltejs/vite-plugin-svelte": "^7.0.0",
57
- "@testing-library/jest-dom": "^6.9.1",
58
- "@types/node": "^26.2.0",
59
- "@vitest/browser-playwright": "^4.1.11",
60
- "@xmachines/play-svelte": "3.0.0",
61
- "oxfmt": "^0.64.0",
62
- "oxlint": "^1.79.0",
63
- "svelte": "^5.55.5",
53
+ "@sveltejs/kit": "^2.70.3",
54
+ "@sveltejs/vite-plugin-svelte": "^7.3.0",
55
+ "@testing-library/jest-dom": "^7.0.1",
56
+ "@types/node": "^26.6.2",
57
+ "@vitest/browser-playwright": "^5.0.1",
58
+ "@xmachines/play": "4.0.0",
59
+ "@xmachines/play-actor": "4.0.0",
60
+ "@xmachines/play-signals": "4.0.0",
61
+ "@xmachines/play-svelte": "4.0.0",
62
+ "oxfmt": "^0.68.0",
63
+ "oxlint": "^1.83.0",
64
+ "svelte": "^5.57.0",
64
65
  "typescript": "^5.9.3 || ^6.0.3",
65
- "vite": "^8.0.10",
66
- "vitest": "^4.1.11",
67
- "xstate": "^5.31.0"
66
+ "vite": "^8.3.0",
67
+ "vitest": "^5.0.1",
68
+ "xstate": "^5.33.0"
68
69
  },
69
70
  "peerDependencies": {
70
71
  "@sveltejs/kit": "^2.0.0",
71
- "svelte": "^5.0.0",
72
- "xstate": "^5.31.0"
72
+ "svelte": "^5.0.0"
73
73
  },
74
74
  "engines": {
75
- "node": ">=22.0.0"
75
+ "node": ">=24.0.0"
76
76
  }
77
77
  }