@xmachines/play-solid-router 2.0.0-alpha.1 → 2.1.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 +39 -34
- package/dist/create-play-router-provider.d.ts +30 -29
- package/dist/create-play-router-provider.d.ts.map +1 -1
- package/dist/create-play-router-provider.js +51 -0
- package/dist/create-play-router-provider.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -10
- package/dist/play-router-provider.d.ts +24 -23
- package/dist/play-router-provider.d.ts.map +1 -1
- package/dist/play-router-provider.js +47 -0
- package/dist/play-router-provider.js.map +1 -0
- package/dist/solid-router-bridge.d.ts +69 -54
- package/dist/solid-router-bridge.d.ts.map +1 -1
- package/dist/solid-router-bridge.js +178 -162
- package/dist/solid-router-bridge.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +21 -21
- package/dist/create-play-router-provider.jsx +0 -45
- package/dist/create-play-router-provider.jsx.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/play-router-provider.jsx +0 -41
- package/dist/play-router-provider.jsx.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
<!-- generated-by: gsd-doc-writer -->
|
|
2
|
-
|
|
3
1
|
# @xmachines/play-solid-router
|
|
4
2
|
|
|
5
|
-
SolidJS Router adapter for the XMachines Universal Player Architecture.
|
|
3
|
+
SolidJS Router adapter for the XMachines Universal Player Architecture. It keeps the state machine routes of a `PlayerActor` and the browser URL in step, in both directions, through `@solidjs/router`.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
[](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@xmachines/play-solid-router)
|
|
8
6
|
|
|
9
7
|
## Installation
|
|
10
8
|
|
|
@@ -12,7 +10,7 @@ Part of the [xmachines-js monorepo](../../README.md).
|
|
|
12
10
|
pnpm add @xmachines/play-solid-router
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
**Peer dependencies
|
|
13
|
+
**Peer dependencies.** Install them separately:
|
|
16
14
|
|
|
17
15
|
```bash
|
|
18
16
|
pnpm add solid-js @solidjs/router xstate
|
|
@@ -20,7 +18,7 @@ pnpm add solid-js @solidjs/router xstate
|
|
|
20
18
|
|
|
21
19
|
- `solid-js` `^1.8.0`
|
|
22
20
|
- `@solidjs/router` `^0.16.1`
|
|
23
|
-
- `xstate` `^
|
|
21
|
+
- `xstate` `^5.31.0`
|
|
24
22
|
|
|
25
23
|
## Quick Start
|
|
26
24
|
|
|
@@ -36,6 +34,10 @@ actor.start();
|
|
|
36
34
|
|
|
37
35
|
const routeMap = createRouteMap(myMachine);
|
|
38
36
|
|
|
37
|
+
// Minimal app shell stub — a real app renders PlayUIProvider + PlayRenderer from
|
|
38
|
+
// @xmachines/play-solid here (see the workspace-only @xmachines/play-solid-demo Shell)
|
|
39
|
+
const MyApp = (props: { actor: typeof actor }) => <main />;
|
|
40
|
+
|
|
39
41
|
const Layout: ParentComponent = () => {
|
|
40
42
|
const navigate = useNavigate();
|
|
41
43
|
const location = useLocation();
|
|
@@ -62,7 +64,7 @@ export default function App() {
|
|
|
62
64
|
|
|
63
65
|
### `PlayRouterProvider`
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
This SolidJS component connects a `PlayerActor` to Solid Router. It creates and connects a `SolidRouterBridge` on mount. It disconnects the bridge with `onCleanup` on unmount.
|
|
66
68
|
|
|
67
69
|
```tsx
|
|
68
70
|
interface PlayRouterProviderProps<TActor extends PlayActor> {
|
|
@@ -83,14 +85,17 @@ interface PlayRouterProviderProps<TActor extends PlayActor> {
|
|
|
83
85
|
|
|
84
86
|
### `SolidRouterBridge`
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
The low-level class for a manual integration. It extends `RouterBridgeBase` from `@xmachines/play-router`. It uses the Solid `createEffect` to send each router change to the actor.
|
|
87
89
|
|
|
88
|
-
> **Important:** `connect()`
|
|
90
|
+
> **Important:** call `connect()` inside a Solid reactive owner: a component, or `createRoot`. The bridge does not clean up by itself. Call `disconnect()` or `dispose()` yourself, usually in `onCleanup()`.
|
|
89
91
|
|
|
90
92
|
```tsx
|
|
91
|
-
import { useNavigate, useLocation, useParams
|
|
93
|
+
import { useNavigate, useLocation, useParams } from "@solidjs/router";
|
|
94
|
+
import { onCleanup } from "solid-js";
|
|
92
95
|
import { SolidRouterBridge, RouteMap } from "@xmachines/play-solid-router";
|
|
93
96
|
|
|
97
|
+
// actor: your started player (see the Quick Start above)
|
|
98
|
+
|
|
94
99
|
function App() {
|
|
95
100
|
const navigate = useNavigate();
|
|
96
101
|
const location = useLocation();
|
|
@@ -111,7 +116,7 @@ function App() {
|
|
|
111
116
|
|
|
112
117
|
### `createRouteMap(machine)`
|
|
113
118
|
|
|
114
|
-
|
|
119
|
+
This factory builds a `RouteMap` directly from an XState machine definition. It comes from `@xmachines/play-router`.
|
|
115
120
|
|
|
116
121
|
```ts
|
|
117
122
|
import { createRouteMap } from "@xmachines/play-solid-router";
|
|
@@ -121,7 +126,7 @@ const routeMap = createRouteMap(myMachine);
|
|
|
121
126
|
|
|
122
127
|
### `RouteMap` / `RouteMapping`
|
|
123
128
|
|
|
124
|
-
|
|
129
|
+
The bidirectional map between the state IDs and the URL paths. It comes from `@xmachines/play-router`.
|
|
125
130
|
|
|
126
131
|
```ts
|
|
127
132
|
import { RouteMap } from "@xmachines/play-solid-router";
|
|
@@ -135,44 +140,44 @@ const routeMap = new RouteMap([
|
|
|
135
140
|
|
|
136
141
|
### Types
|
|
137
142
|
|
|
138
|
-
| Export | Description
|
|
139
|
-
| ------------------------- |
|
|
140
|
-
| `PlayActor` | `AbstractActor & Routable & Viewable` — canonical actor shape from `@xmachines/play-router`.
|
|
141
|
-
| `RoutableActor` | Deprecated alias for `PlayActor`. Use `PlayActor` from `@xmachines/play-router` in new code.
|
|
142
|
-
| `AbstractActor` |
|
|
143
|
-
| `SolidRouterHooks` | Shape of the `router` prop: `{ navigate, location, params }`
|
|
144
|
-
| `PlayRouterProviderProps` | Full props interface for `PlayRouterProvider`
|
|
145
|
-
| `PlayRouteEvent` |
|
|
146
|
-
| `RouterBridge` |
|
|
147
|
-
| `RouteMapOptions` |
|
|
143
|
+
| Export | Description |
|
|
144
|
+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
145
|
+
| `PlayActor` | `AbstractActor & Routable & Viewable` — the canonical actor shape from `@xmachines/play-router`. `PlayRouterProvider` requires it, because it renders the current view spec and also keeps the routes in step. |
|
|
146
|
+
| `RoutableActor` | Deprecated alias for `PlayActor`. Use `PlayActor` from `@xmachines/play-router` in new code. |
|
|
147
|
+
| `AbstractActor` | It comes from `@xmachines/play-actor`. Use it for the type of a renderer callback. |
|
|
148
|
+
| `SolidRouterHooks` | Shape of the `router` prop: `{ navigate, location, params }` |
|
|
149
|
+
| `PlayRouterProviderProps` | Full props interface for `PlayRouterProvider` |
|
|
150
|
+
| `PlayRouteEvent` | The event type that the bridge sends to the actor on a URL change (`play.route`) |
|
|
151
|
+
| `RouterBridge` | The interface that `SolidRouterBridge` implements |
|
|
152
|
+
| `RouteMapOptions` | The options object for the `RouteMap` constructor. It comes from `@xmachines/play-router`. |
|
|
148
153
|
|
|
149
154
|
## Usage Patterns
|
|
150
155
|
|
|
151
156
|
### Protected Routes and Guards
|
|
152
157
|
|
|
153
|
-
|
|
158
|
+
The auth guards are inside the state machine only. Unauthorized content therefore never appears, not even for a moment:
|
|
154
159
|
|
|
155
160
|
```ts
|
|
156
161
|
const machineConfig = {
|
|
157
162
|
states: {
|
|
158
163
|
dashboard: {
|
|
159
164
|
meta: { route: "/dashboard" },
|
|
160
|
-
always:
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
always: {
|
|
166
|
+
guard: ({ context }) => !context.isAuthenticated,
|
|
167
|
+
target: "login",
|
|
163
168
|
},
|
|
164
169
|
},
|
|
165
170
|
},
|
|
166
171
|
};
|
|
167
172
|
```
|
|
168
173
|
|
|
169
|
-
|
|
174
|
+
A user navigates to `/dashboard`, and the user is not authenticated:
|
|
170
175
|
|
|
171
176
|
1. Solid Router updates the URL.
|
|
172
|
-
2.
|
|
173
|
-
3.
|
|
174
|
-
4.
|
|
175
|
-
5.
|
|
177
|
+
2. The bridge receives the change and sends `play.route` to the actor.
|
|
178
|
+
3. The actor evaluates the guard. The guard refuses the transition, and the actor moves to `login`.
|
|
179
|
+
4. The bridge reads the new actor route (`/login`) from the TC39 Signal.
|
|
180
|
+
5. The bridge calls `navigate("/login")`.
|
|
176
181
|
|
|
177
182
|
### Dynamic Routes with Parameters
|
|
178
183
|
|
|
@@ -186,7 +191,7 @@ const routeMap = new RouteMap([
|
|
|
186
191
|
// { type: "play.route", to: "#post", params: { userId: "123", postId: "456" }, query: {} }
|
|
187
192
|
```
|
|
188
193
|
|
|
189
|
-
|
|
194
|
+
The bridge reads the path parameters from the reactive `useParams()` proxy of Solid. A parameterized route therefore does not need the URLPattern polyfill.
|
|
190
195
|
|
|
191
196
|
## Testing
|
|
192
197
|
|
|
@@ -200,7 +205,7 @@ pnpm --filter @xmachines/play-solid-router test
|
|
|
200
205
|
pnpm test
|
|
201
206
|
```
|
|
202
207
|
|
|
203
|
-
**Browser tests** (`test/browser/**/*.browser.test.ts`) run
|
|
208
|
+
**Browser tests** (`test/browser/**/*.browser.test.ts`) run in real Chromium through Playwright. They cover the asynchronous sequences that jsdom cannot reproduce:
|
|
204
209
|
|
|
205
210
|
```bash
|
|
206
211
|
pnpm exec vitest --config vitest.browser.config.ts --project play-solid-router-browser
|
|
@@ -213,7 +218,7 @@ Coverage thresholds: **80%** lines, functions, branches, and statements.
|
|
|
213
218
|
- [@xmachines/play-router](../play-router/README.md) — core router primitives and `RouterBridgeBase`
|
|
214
219
|
- [@xmachines/play-tanstack-solid-router](../play-tanstack-solid-router/README.md) — TanStack Solid Router adapter
|
|
215
220
|
- [@xmachines/play-solid](../play-solid/README.md) — SolidJS view renderer
|
|
216
|
-
- [@xmachines/play-xstate](../play-xstate/README.md) — XState
|
|
221
|
+
- [@xmachines/play-xstate](../play-xstate/README.md) — XState v5 player factory
|
|
217
222
|
|
|
218
223
|
## Learn More
|
|
219
224
|
|
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* createPlayRouterProvider — factory
|
|
2
|
+
* createPlayRouterProvider — the factory of a Solid `PlayRouterProvider` component
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* factory.
|
|
4
|
+
* The factory holds the shape of the provider component of this package: it creates a
|
|
5
|
+
* bridge synchronously, during the evaluation of the component, it calls `connect()`,
|
|
6
|
+
* and it calls `disconnect()` in `onCleanup`. One call therefore wraps each Solid
|
|
7
|
+
* bridge with the standard `(router, actor, routeMap)` constructor in a provider. The
|
|
8
|
+
* bridge class, and therefore the type of the `router` prop, is the one difference
|
|
9
|
+
* between two providers of this factory.
|
|
11
10
|
*
|
|
12
11
|
* @packageDocumentation
|
|
13
12
|
*/
|
|
14
13
|
import { type JSX } from "solid-js";
|
|
15
14
|
import type { PlayActor, RouteMap, RouterBridge } from "@xmachines/play-router";
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* The constructor shape that a bridge class must satisfy for
|
|
18
17
|
* `createPlayRouterProvider`: `(router, actor, routeMap) → RouterBridge`.
|
|
19
18
|
*
|
|
20
|
-
*
|
|
21
|
-
* takes
|
|
22
|
-
* subclass
|
|
19
|
+
* A bridge with another constructor shape, for example `SolidRouterBridge`, which
|
|
20
|
+
* takes each hook result as a separate argument, receives a thin subclass. That
|
|
21
|
+
* subclass packs the `router` prop again.
|
|
23
22
|
*/
|
|
24
23
|
export type PlayRouterBridgeConstructor<TRouter> = new (router: TRouter, actor: PlayActor, routeMap: RouteMap) => RouterBridge;
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* The props that every Solid `PlayRouterProvider` of the factory shares.
|
|
27
26
|
*
|
|
28
|
-
*
|
|
29
|
-
* router
|
|
27
|
+
* An adapter package re-exports a concrete alias, with `TRouter` bound to the type of
|
|
28
|
+
* its router. For example, `SolidRouterHooks` in `@xmachines/play-solid-router`.
|
|
30
29
|
*/
|
|
31
30
|
export interface PlayRouterProviderBaseProps<TRouter, TActor extends PlayActor = PlayActor> {
|
|
32
|
-
/** The actor to
|
|
31
|
+
/** The actor to keep in step with the router. */
|
|
33
32
|
actor: TActor;
|
|
34
|
-
/** The router the bridge
|
|
33
|
+
/** The router that the bridge keeps in step with the actor. */
|
|
35
34
|
router: TRouter;
|
|
36
|
-
/**
|
|
35
|
+
/** The route map of both directions, for the lookup between a state ID and a URL path. */
|
|
37
36
|
routeMap: RouteMap;
|
|
38
|
-
/**
|
|
37
|
+
/** The renderer callback receives the same concrete actor type as the prop. */
|
|
39
38
|
renderer: (actor: TActor, router: TRouter) => JSX.Element;
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
|
-
*
|
|
41
|
+
* Creates a Solid `PlayRouterProvider` component of one bridge class.
|
|
43
42
|
*
|
|
44
|
-
* The
|
|
45
|
-
*
|
|
43
|
+
* The component of the return value connects a `PlayerActor` to the framework
|
|
44
|
+
* router. It keeps the actor state and the browser URL in step, in both directions.
|
|
46
45
|
*
|
|
47
|
-
* The
|
|
48
|
-
* execution model
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* The component creates the bridge synchronously, during its own evaluation, because
|
|
47
|
+
* this is the execution model of Solid. It disconnects the bridge in `onCleanup`,
|
|
48
|
+
* when Solid disposes of the component. React is different: the stability of a prop
|
|
49
|
+
* is no concern here, because the `props` accessor of Solid is reactive already, and
|
|
50
|
+
* the component creates the bridge one time for each of its instances.
|
|
51
51
|
*
|
|
52
|
-
* @param BridgeCtor -
|
|
53
|
-
* @returns A `PlayRouterProvider` component
|
|
54
|
-
* `renderer` callback receives the same concrete actor type
|
|
52
|
+
* @param BridgeCtor - The bridge class. The provider builds it as `new BridgeCtor(router, actor, routeMap)`.
|
|
53
|
+
* @returns A `PlayRouterProvider` component. It is generic over the actor type.
|
|
54
|
+
* Therefore the `renderer` callback receives the same concrete actor type as the
|
|
55
|
+
* prop.
|
|
55
56
|
*
|
|
56
57
|
* @example
|
|
57
58
|
* ```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-play-router-provider.d.ts","sourceRoot":"","sources":["../src/create-play-router-provider.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"create-play-router-provider.d.ts","sourceRoot":"","sources":["../src/create-play-router-provider.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAa,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEhF;;;;;;;GAOG;AACH,MAAM,MAAM,2BAA2B,CAAC,OAAO,IAAI,KAClD,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,SAAS,EAChB,QAAQ,EAAE,QAAQ,KACd,YAAY,CAAC;AAElB;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B,CAAC,OAAO,EAAE,MAAM,SAAS,SAAS,GAAG,SAAS;IACzF,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,MAAM,EAAE,OAAO,CAAC;IAChB,0FAA0F;IAC1F,QAAQ,EAAE,QAAQ,CAAC;IACnB,+EAA+E;IAC/E,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC;CAC1D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAC/C,UAAU,EAAE,2BAA2B,CAAC,OAAO,CAAC,IAEb,MAAM,SAAS,SAAS,EAC1D,OAAO,2BAA2B,CAAC,OAAO,EAAE,MAAM,CAAC,SAWpD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { onCleanup } from "solid-js";
|
|
2
|
+
import { memo } from "solid-js/web";
|
|
3
|
+
//#region packages/play-solid-router/src/create-play-router-provider.tsx
|
|
4
|
+
/**
|
|
5
|
+
* createPlayRouterProvider — the factory of a Solid `PlayRouterProvider` component
|
|
6
|
+
*
|
|
7
|
+
* The factory holds the shape of the provider component of this package: it creates a
|
|
8
|
+
* bridge synchronously, during the evaluation of the component, it calls `connect()`,
|
|
9
|
+
* and it calls `disconnect()` in `onCleanup`. One call therefore wraps each Solid
|
|
10
|
+
* bridge with the standard `(router, actor, routeMap)` constructor in a provider. The
|
|
11
|
+
* bridge class, and therefore the type of the `router` prop, is the one difference
|
|
12
|
+
* between two providers of this factory.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Creates a Solid `PlayRouterProvider` component of one bridge class.
|
|
18
|
+
*
|
|
19
|
+
* The component of the return value connects a `PlayerActor` to the framework
|
|
20
|
+
* router. It keeps the actor state and the browser URL in step, in both directions.
|
|
21
|
+
*
|
|
22
|
+
* The component creates the bridge synchronously, during its own evaluation, because
|
|
23
|
+
* this is the execution model of Solid. It disconnects the bridge in `onCleanup`,
|
|
24
|
+
* when Solid disposes of the component. React is different: the stability of a prop
|
|
25
|
+
* is no concern here, because the `props` accessor of Solid is reactive already, and
|
|
26
|
+
* the component creates the bridge one time for each of its instances.
|
|
27
|
+
*
|
|
28
|
+
* @param BridgeCtor - The bridge class. The provider builds it as `new BridgeCtor(router, actor, routeMap)`.
|
|
29
|
+
* @returns A `PlayRouterProvider` component. It is generic over the actor type.
|
|
30
|
+
* Therefore the `renderer` callback receives the same concrete actor type as the
|
|
31
|
+
* prop.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* export const PlayRouterProvider = createPlayRouterProvider(MySolidRouterBridge);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createPlayRouterProvider(BridgeCtor) {
|
|
39
|
+
return function PlayRouterProvider(props) {
|
|
40
|
+
const bridge = new BridgeCtor(props.router, props.actor, props.routeMap);
|
|
41
|
+
bridge.connect();
|
|
42
|
+
onCleanup(() => {
|
|
43
|
+
bridge.disconnect();
|
|
44
|
+
});
|
|
45
|
+
return memo(() => props.renderer(props.actor, props.router));
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createPlayRouterProvider };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=create-play-router-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-play-router-provider.js","names":["onCleanup","JSX","PlayActor","RouteMap","RouterBridge","PlayRouterBridgeConstructor","router","TRouter","actor","routeMap","PlayRouterProviderBaseProps","TActor","renderer","Element","createPlayRouterProvider","BridgeCtor","PlayRouterProvider","props","bridge","connect","disconnect","_$memo"],"sources":["../src/create-play-router-provider.tsx"],"sourcesContent":["/**\n * createPlayRouterProvider — the factory of a Solid `PlayRouterProvider` component\n *\n * The factory holds the shape of the provider component of this package: it creates a\n * bridge synchronously, during the evaluation of the component, it calls `connect()`,\n * and it calls `disconnect()` in `onCleanup`. One call therefore wraps each Solid\n * bridge with the standard `(router, actor, routeMap)` constructor in a provider. The\n * bridge class, and therefore the type of the `router` prop, is the one difference\n * between two providers of this factory.\n *\n * @packageDocumentation\n */\nimport { onCleanup, type JSX } from \"solid-js\";\nimport type { PlayActor, RouteMap, RouterBridge } from \"@xmachines/play-router\";\n\n/**\n * The constructor shape that a bridge class must satisfy for\n * `createPlayRouterProvider`: `(router, actor, routeMap) → RouterBridge`.\n *\n * A bridge with another constructor shape, for example `SolidRouterBridge`, which\n * takes each hook result as a separate argument, receives a thin subclass. That\n * subclass packs the `router` prop again.\n */\nexport type PlayRouterBridgeConstructor<TRouter> = new (\n\trouter: TRouter,\n\tactor: PlayActor,\n\trouteMap: RouteMap,\n) => RouterBridge;\n\n/**\n * The props that every Solid `PlayRouterProvider` of the factory shares.\n *\n * An adapter package re-exports a concrete alias, with `TRouter` bound to the type of\n * its router. For example, `SolidRouterHooks` in `@xmachines/play-solid-router`.\n */\nexport interface PlayRouterProviderBaseProps<TRouter, TActor extends PlayActor = PlayActor> {\n\t/** The actor to keep in step with the router. */\n\tactor: TActor;\n\t/** The router that the bridge keeps in step with the actor. */\n\trouter: TRouter;\n\t/** The route map of both directions, for the lookup between a state ID and a URL path. */\n\trouteMap: RouteMap;\n\t/** The renderer callback receives the same concrete actor type as the prop. */\n\trenderer: (actor: TActor, router: TRouter) => JSX.Element;\n}\n\n/**\n * Creates a Solid `PlayRouterProvider` component of one bridge class.\n *\n * The component of the return value connects a `PlayerActor` to the framework\n * router. It keeps the actor state and the browser URL in step, in both directions.\n *\n * The component creates the bridge synchronously, during its own evaluation, because\n * this is the execution model of Solid. It disconnects the bridge in `onCleanup`,\n * when Solid disposes of the component. React is different: the stability of a prop\n * is no concern here, because the `props` accessor of Solid is reactive already, and\n * the component creates the bridge one time for each of its instances.\n *\n * @param BridgeCtor - The bridge class. The provider builds it as `new BridgeCtor(router, actor, routeMap)`.\n * @returns A `PlayRouterProvider` component. It is generic over the actor type.\n * Therefore the `renderer` callback receives the same concrete actor type as the\n * prop.\n *\n * @example\n * ```tsx\n * export const PlayRouterProvider = createPlayRouterProvider(MySolidRouterBridge);\n * ```\n */\nexport function createPlayRouterProvider<TRouter>(\n\tBridgeCtor: PlayRouterBridgeConstructor<TRouter>,\n) {\n\treturn function PlayRouterProvider<TActor extends PlayActor>(\n\t\tprops: PlayRouterProviderBaseProps<TRouter, TActor>,\n\t) {\n\t\tconst bridge = new BridgeCtor(props.router, props.actor, props.routeMap);\n\t\tvoid bridge.connect();\n\n\t\tonCleanup(() => {\n\t\t\tvoid bridge.disconnect();\n\t\t});\n\n\t\treturn <>{props.renderer(props.actor, props.router)}</>;\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgBc,yBACfC,YACC;CACD,OAAO,SAASC,mBACfC,OACC;EACD,MAAMC,SAAS,IAAIH,WAAWE,MAAMX,QAAQW,MAAMT,OAAOS,MAAMR,QAAQ;EACvE,OAAYU,QAAQ;EAEpBnB,gBAAgB;GACf,OAAYoB,WAAW;EACxB,CAAC;EAED,OAAAC,WAAUJ,MAAML,SAASK,MAAMT,OAAOS,MAAMX,MAAM,CAAC;CACpD;AACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @xmachines/play-solid-router
|
|
3
3
|
*
|
|
4
|
-
* SolidJS Router adapter for XMachines Universal Player Architecture
|
|
4
|
+
* SolidJS Router adapter for the XMachines Universal Player Architecture
|
|
5
5
|
*/
|
|
6
6
|
export { SolidRouterBridge } from "./solid-router-bridge.js";
|
|
7
7
|
export { PlayRouterProvider } from "./play-router-provider.js";
|
|
8
|
-
export type { PlayRouterProviderProps, PlayActor, RoutableActor, // @deprecated — use PlayActor
|
|
8
|
+
export type { PlayRouterProviderProps, PlayActor, RoutableActor, // @deprecated — use PlayActor of @xmachines/play-router
|
|
9
9
|
SolidRouterHooks, } from "./play-router-provider.js";
|
|
10
10
|
export { createPlayRouterProvider } from "./create-play-router-provider.js";
|
|
11
11
|
export type { PlayRouterProviderBaseProps, PlayRouterBridgeConstructor, } from "./create-play-router-provider.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EACX,uBAAuB,EACvB,SAAS,EACT,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EACX,uBAAuB,EACvB,SAAS,EACT,aAAa,EAAE,wDAAwD;AACvE,gBAAgB,GAChB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,YAAY,EACX,2BAA2B,EAC3B,2BAA2B,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,QAAQ,EACR,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,eAAe,GACpB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { SolidRouterBridge } from "./solid-router-bridge.js";
|
|
7
|
-
export { PlayRouterProvider } from "./play-router-provider.js";
|
|
8
|
-
export { createPlayRouterProvider } from "./create-play-router-provider.js";
|
|
9
|
-
export { RouteMap, createRouteMap, } from "@xmachines/play-router";
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { SolidRouterBridge } from "./solid-router-bridge.js";
|
|
2
|
+
import { createPlayRouterProvider } from "./create-play-router-provider.js";
|
|
3
|
+
import { PlayRouterProvider } from "./play-router-provider.js";
|
|
4
|
+
import { RouteMap, createRouteMap } from "@xmachines/play-router";
|
|
5
|
+
export { PlayRouterProvider, RouteMap, SolidRouterBridge, createPlayRouterProvider, createRouteMap };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* PlayRouterProvider — Solid
|
|
2
|
+
* PlayRouterProvider — the Solid wrapper of SolidRouterBridge
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `onCleanup
|
|
4
|
+
* The shared `createPlayRouterProvider` factory makes this component: it creates the
|
|
5
|
+
* bridge synchronously, during the evaluation of the component, and it disconnects the
|
|
6
|
+
* bridge in `onCleanup`, when Solid disposes of the component.
|
|
7
7
|
*/
|
|
8
8
|
import type { Navigator, Location, Params } from "@solidjs/router";
|
|
9
9
|
import type { PlayActor } from "@xmachines/play-router";
|
|
10
10
|
import { type PlayRouterProviderBaseProps } from "./create-play-router-provider.js";
|
|
11
11
|
export type { PlayActor };
|
|
12
|
-
/** @deprecated Use `PlayActor` from `@xmachines/play-router`.
|
|
12
|
+
/** @deprecated Use `PlayActor` from `@xmachines/play-router`. The next major version removes this alias. */
|
|
13
13
|
export type RoutableActor = PlayActor;
|
|
14
14
|
/**
|
|
15
|
-
* The three Solid Router
|
|
16
|
-
*
|
|
15
|
+
* The three results of the Solid Router hooks that `PlayRouterProvider` and
|
|
16
|
+
* `SolidRouterBridge` need. Give them directly from the hook calls of your component:
|
|
17
17
|
*
|
|
18
18
|
* ```tsx
|
|
19
19
|
* const navigate = useNavigate(); // → SolidRouterHooks.navigate
|
|
@@ -21,11 +21,11 @@ export type RoutableActor = PlayActor;
|
|
|
21
21
|
* const params = useParams(); // → SolidRouterHooks.params
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
|
-
* - `navigate` —
|
|
25
|
-
* - `location` — `pathname` and `search`
|
|
26
|
-
*
|
|
27
|
-
* - `params` —
|
|
28
|
-
* directly in `extractParams()
|
|
24
|
+
* - `navigate` — the bridge pushes each URL change with it, when the `currentRoute` of the actor changes.
|
|
25
|
+
* - `location` — the bridge reads `pathname` and `search` at the moment of `connect()`, for a deep link.
|
|
26
|
+
* Each later change of the pathname then goes to the actor, through `createEffect`.
|
|
27
|
+
* - `params` — the path parameters of the current route segment, which Solid parsed already. The bridge
|
|
28
|
+
* uses them directly in `extractParams()`, and it parses them not again with URLPattern.
|
|
29
29
|
*/
|
|
30
30
|
export type SolidRouterHooks = {
|
|
31
31
|
navigate: Navigator;
|
|
@@ -33,24 +33,25 @@ export type SolidRouterHooks = {
|
|
|
33
33
|
params: Params;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* The props of the `PlayRouterProvider` of Solid Router.
|
|
37
37
|
*
|
|
38
|
-
* `router`
|
|
39
|
-
*
|
|
40
|
-
* in the parent component
|
|
38
|
+
* `router` holds the three results of the Solid Router hooks that drive the work in
|
|
39
|
+
* both directions. Take them from `useNavigate()`, from `useLocation()`, and from
|
|
40
|
+
* `useParams()` in the parent component. Call each hook inside a router context.
|
|
41
41
|
*/
|
|
42
42
|
export interface PlayRouterProviderProps<TActor extends PlayActor = PlayActor> extends PlayRouterProviderBaseProps<SolidRouterHooks, TActor> {
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Connects a `PlayerActor` to Solid Router
|
|
46
|
-
* in
|
|
45
|
+
* Connects a `PlayerActor` to Solid Router. It keeps the actor state and the browser
|
|
46
|
+
* URL in step, in both directions.
|
|
47
47
|
*
|
|
48
|
-
* The
|
|
49
|
-
* execution model
|
|
50
|
-
*
|
|
51
|
-
*
|
|
48
|
+
* The component creates the bridge synchronously, during its own evaluation, because
|
|
49
|
+
* this is the execution model of Solid. It disconnects the bridge in `onCleanup`,
|
|
50
|
+
* when Solid disposes of the component. React is different: the stability of a prop
|
|
51
|
+
* is no concern here, because the `props` accessor of Solid is reactive already, and
|
|
52
|
+
* the component creates the bridge one time for each of its instances.
|
|
52
53
|
*
|
|
53
|
-
*
|
|
54
|
+
* Take the `router` prop from the Solid Router hooks in the parent component:
|
|
54
55
|
*
|
|
55
56
|
* ```tsx
|
|
56
57
|
* function AppShell() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"play-router-provider.d.ts","sourceRoot":"","sources":["../src/play-router-provider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAEN,KAAK,2BAA2B,EAChC,MAAM,kCAAkC,CAAC;AAE1C,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,4GAA4G;AAC5G,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB,CACvC,MAAM,SAAS,SAAS,GAAG,SAAS,CACnC,SAAQ,2BAA2B,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAAG;
|
|
1
|
+
{"version":3,"file":"play-router-provider.d.ts","sourceRoot":"","sources":["../src/play-router-provider.tsx"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAEN,KAAK,2BAA2B,EAChC,MAAM,kCAAkC,CAAC;AAE1C,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,4GAA4G;AAC5G,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB,CACvC,MAAM,SAAS,SAAS,GAAG,SAAS,CACnC,SAAQ,2BAA2B,CAAC,gBAAgB,EAAE,MAAM,CAAC;CAAG;AAalE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,kBAAkB,iGAAmD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SolidRouterBridge } from "./solid-router-bridge.js";
|
|
2
|
+
import { createPlayRouterProvider } from "./create-play-router-provider.js";
|
|
3
|
+
//#region packages/play-solid-router/src/play-router-provider.tsx
|
|
4
|
+
/**
|
|
5
|
+
* The adapter binds the constructor of `SolidRouterBridge`, which takes the hook
|
|
6
|
+
* results, to the `(router, actor, routeMap)` shape of
|
|
7
|
+
* `createPlayRouterProvider`.
|
|
8
|
+
*/
|
|
9
|
+
var SolidHooksRouterBridge = class extends SolidRouterBridge {
|
|
10
|
+
constructor(router, actor, routeMap) {
|
|
11
|
+
super(router.navigate, router.location, router.params, actor, routeMap);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Connects a `PlayerActor` to Solid Router. It keeps the actor state and the browser
|
|
16
|
+
* URL in step, in both directions.
|
|
17
|
+
*
|
|
18
|
+
* The component creates the bridge synchronously, during its own evaluation, because
|
|
19
|
+
* this is the execution model of Solid. It disconnects the bridge in `onCleanup`,
|
|
20
|
+
* when Solid disposes of the component. React is different: the stability of a prop
|
|
21
|
+
* is no concern here, because the `props` accessor of Solid is reactive already, and
|
|
22
|
+
* the component creates the bridge one time for each of its instances.
|
|
23
|
+
*
|
|
24
|
+
* Take the `router` prop from the Solid Router hooks in the parent component:
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function AppShell() {
|
|
28
|
+
* const navigate = useNavigate();
|
|
29
|
+
* const location = useLocation();
|
|
30
|
+
* const params = useParams();
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <PlayRouterProvider
|
|
34
|
+
* actor={actor}
|
|
35
|
+
* routeMap={routeMap}
|
|
36
|
+
* router={{ navigate, location, params }}
|
|
37
|
+
* renderer={(a) => <PlayRenderer actor={a} registry={registry} />}
|
|
38
|
+
* />
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
var PlayRouterProvider = createPlayRouterProvider(SolidHooksRouterBridge);
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PlayRouterProvider };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=play-router-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"play-router-provider.js","names":["Navigator","Location","Params","PlayActor","RouteMap","SolidRouterBridge","createPlayRouterProvider","PlayRouterProviderBaseProps","RoutableActor","SolidRouterHooks","navigate","location","params","PlayRouterProviderProps","TActor","SolidHooksRouterBridge","constructor","router","actor","routeMap","PlayRouterProvider"],"sources":["../src/play-router-provider.tsx"],"sourcesContent":["/**\n * PlayRouterProvider — the Solid wrapper of SolidRouterBridge\n *\n * The shared `createPlayRouterProvider` factory makes this component: it creates the\n * bridge synchronously, during the evaluation of the component, and it disconnects the\n * bridge in `onCleanup`, when Solid disposes of the component.\n */\nimport type { Navigator, Location, Params } from \"@solidjs/router\";\nimport type { PlayActor, RouteMap } from \"@xmachines/play-router\";\nimport { SolidRouterBridge } from \"./solid-router-bridge.js\";\nimport {\n\tcreatePlayRouterProvider,\n\ttype PlayRouterProviderBaseProps,\n} from \"./create-play-router-provider.js\";\n\nexport type { PlayActor };\n\n/** @deprecated Use `PlayActor` from `@xmachines/play-router`. The next major version removes this alias. */\nexport type RoutableActor = PlayActor;\n\n/**\n * The three results of the Solid Router hooks that `PlayRouterProvider` and\n * `SolidRouterBridge` need. Give them directly from the hook calls of your component:\n *\n * ```tsx\n * const navigate = useNavigate(); // → SolidRouterHooks.navigate\n * const location = useLocation(); // → SolidRouterHooks.location\n * const params = useParams(); // → SolidRouterHooks.params\n * ```\n *\n * - `navigate` — the bridge pushes each URL change with it, when the `currentRoute` of the actor changes.\n * - `location` — the bridge reads `pathname` and `search` at the moment of `connect()`, for a deep link.\n * Each later change of the pathname then goes to the actor, through `createEffect`.\n * - `params` — the path parameters of the current route segment, which Solid parsed already. The bridge\n * uses them directly in `extractParams()`, and it parses them not again with URLPattern.\n */\nexport type SolidRouterHooks = {\n\tnavigate: Navigator;\n\tlocation: Location;\n\tparams: Params;\n};\n\n/**\n * The props of the `PlayRouterProvider` of Solid Router.\n *\n * `router` holds the three results of the Solid Router hooks that drive the work in\n * both directions. Take them from `useNavigate()`, from `useLocation()`, and from\n * `useParams()` in the parent component. Call each hook inside a router context.\n */\nexport interface PlayRouterProviderProps<\n\tTActor extends PlayActor = PlayActor,\n> extends PlayRouterProviderBaseProps<SolidRouterHooks, TActor> {}\n\n/**\n * The adapter binds the constructor of `SolidRouterBridge`, which takes the hook\n * results, to the `(router, actor, routeMap)` shape of\n * `createPlayRouterProvider`.\n */\nclass SolidHooksRouterBridge extends SolidRouterBridge {\n\tconstructor(router: SolidRouterHooks, actor: PlayActor, routeMap: RouteMap) {\n\t\tsuper(router.navigate, router.location, router.params, actor, routeMap);\n\t}\n}\n\n/**\n * Connects a `PlayerActor` to Solid Router. It keeps the actor state and the browser\n * URL in step, in both directions.\n *\n * The component creates the bridge synchronously, during its own evaluation, because\n * this is the execution model of Solid. It disconnects the bridge in `onCleanup`,\n * when Solid disposes of the component. React is different: the stability of a prop\n * is no concern here, because the `props` accessor of Solid is reactive already, and\n * the component creates the bridge one time for each of its instances.\n *\n * Take the `router` prop from the Solid Router hooks in the parent component:\n *\n * ```tsx\n * function AppShell() {\n * const navigate = useNavigate();\n * const location = useLocation();\n * const params = useParams();\n *\n * return (\n * <PlayRouterProvider\n * actor={actor}\n * routeMap={routeMap}\n * router={{ navigate, location, params }}\n * renderer={(a) => <PlayRenderer actor={a} registry={registry} />}\n * />\n * );\n * }\n * ```\n */\nexport const PlayRouterProvider = createPlayRouterProvider(SolidHooksRouterBridge);\n"],"mappings":";;;;;;;;AA0DA,IAAMe,yBAAN,cAAqCV,kBAAkB;CACtDW,YAAYC,QAA0BC,OAAkBC,UAAoB;EAC3E,MAAMF,OAAOP,UAAUO,OAAON,UAAUM,OAAOL,QAAQM,OAAOC,QAAQ;CACvE;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAaC,qBAAqBd,yBAAyBS,sBAAsB"}
|