@xmachines/docs 1.0.0-beta.10
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/LICENSE +21 -0
- package/README.md +15 -0
- package/api/@xmachines/play/README.md +130 -0
- package/api/@xmachines/play/type-aliases/PlayEvent.md +81 -0
- package/api/@xmachines/play-actor/README.md +247 -0
- package/api/@xmachines/play-actor/classes/AbstractActor.md +520 -0
- package/api/@xmachines/play-actor/interfaces/Routable.md +29 -0
- package/api/@xmachines/play-actor/interfaces/ViewMetadata.md +17 -0
- package/api/@xmachines/play-actor/interfaces/Viewable.md +12 -0
- package/api/@xmachines/play-catalog/README.md +331 -0
- package/api/@xmachines/play-catalog/functions/defineCatalog.md +98 -0
- package/api/@xmachines/play-catalog/functions/defineComponents.md +134 -0
- package/api/@xmachines/play-catalog/type-aliases/Catalog.md +48 -0
- package/api/@xmachines/play-catalog/type-aliases/ComponentsFor.md +20 -0
- package/api/@xmachines/play-catalog/type-aliases/InferComponentProps.md +65 -0
- package/api/@xmachines/play-catalog/type-aliases/NoExtraKeys.md +17 -0
- package/api/@xmachines/play-react/README.md +423 -0
- package/api/@xmachines/play-react/classes/PlayErrorBoundary.md +613 -0
- package/api/@xmachines/play-react/functions/useSignalEffect.md +68 -0
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryProps.md +15 -0
- package/api/@xmachines/play-react/interfaces/PlayErrorBoundaryState.md +14 -0
- package/api/@xmachines/play-react/interfaces/PlayRendererProps.md +15 -0
- package/api/@xmachines/play-react/variables/PlayRenderer.md +64 -0
- package/api/@xmachines/play-react-router/README.md +198 -0
- package/api/@xmachines/play-react-router/classes/ReactRouterBridge.md +321 -0
- package/api/@xmachines/play-react-router/classes/RouteMap.md +137 -0
- package/api/@xmachines/play-react-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-react-router/functions/createRouteMapFromTree.md +35 -0
- package/api/@xmachines/play-react-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-react-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-react-router/interfaces/RouteMapping.md +17 -0
- package/api/@xmachines/play-react-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-react-router-demo/README.md +137 -0
- package/api/@xmachines/play-router/README.md +502 -0
- package/api/@xmachines/play-router/classes/BaseRouteMap.md +142 -0
- package/api/@xmachines/play-router/classes/RouterBridgeBase.md +300 -0
- package/api/@xmachines/play-router/functions/buildRouteTree.md +27 -0
- package/api/@xmachines/play-router/functions/connectRouter.md +67 -0
- package/api/@xmachines/play-router/functions/crawlMachine.md +92 -0
- package/api/@xmachines/play-router/functions/createBrowserHistory.md +47 -0
- package/api/@xmachines/play-router/functions/createRouteMap.md +53 -0
- package/api/@xmachines/play-router/functions/createRouter.md +76 -0
- package/api/@xmachines/play-router/functions/detectDuplicateRoutes.md +32 -0
- package/api/@xmachines/play-router/functions/extractMachineRoutes.md +64 -0
- package/api/@xmachines/play-router/functions/extractRoute.md +45 -0
- package/api/@xmachines/play-router/functions/findRouteById.md +37 -0
- package/api/@xmachines/play-router/functions/findRouteByPath.md +39 -0
- package/api/@xmachines/play-router/functions/getNavigableRoutes.md +35 -0
- package/api/@xmachines/play-router/functions/getRoutableRoutes.md +39 -0
- package/api/@xmachines/play-router/functions/routeExists.md +26 -0
- package/api/@xmachines/play-router/functions/validateRouteFormat.md +29 -0
- package/api/@xmachines/play-router/functions/validateStateExists.md +29 -0
- package/api/@xmachines/play-router/interfaces/BaseRouteMapping.md +27 -0
- package/api/@xmachines/play-router/interfaces/BrowserHistory.md +172 -0
- package/api/@xmachines/play-router/interfaces/BrowserWindow.md +69 -0
- package/api/@xmachines/play-router/interfaces/ConnectRouterOptions.md +13 -0
- package/api/@xmachines/play-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-router/interfaces/RouteInfo.md +19 -0
- package/api/@xmachines/play-router/interfaces/RouteMap.md +56 -0
- package/api/@xmachines/play-router/interfaces/RouteNode.md +21 -0
- package/api/@xmachines/play-router/interfaces/RouteObject.md +21 -0
- package/api/@xmachines/play-router/interfaces/RouteTree.md +20 -0
- package/api/@xmachines/play-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-router/interfaces/StateVisit.md +15 -0
- package/api/@xmachines/play-router/interfaces/VanillaRouter.md +28 -0
- package/api/@xmachines/play-router/type-aliases/RouteMetadata.md +11 -0
- package/api/@xmachines/play-router-demo/README.md +137 -0
- package/api/@xmachines/play-signals/README.md +176 -0
- package/api/@xmachines/play-signals/interfaces/ComputedOptions.md +34 -0
- package/api/@xmachines/play-signals/interfaces/SignalComputed.md +49 -0
- package/api/@xmachines/play-signals/interfaces/SignalOptions.md +35 -0
- package/api/@xmachines/play-signals/interfaces/SignalState.md +68 -0
- package/api/@xmachines/play-signals/interfaces/SignalWatcher.md +97 -0
- package/api/@xmachines/play-signals/namespaces/Signal/README.md +22 -0
- package/api/@xmachines/play-signals/namespaces/Signal/classes/Computed.md +52 -0
- package/api/@xmachines/play-signals/namespaces/Signal/classes/State.md +72 -0
- package/api/@xmachines/play-signals/namespaces/Signal/interfaces/Options.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/README.md +21 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/classes/Watcher.md +85 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/currentComputed.md +13 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSinks.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/hasSources.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSinks.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/introspectSources.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/functions/untrack.md +25 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/unwatched.md +9 -0
- package/api/@xmachines/play-signals/namespaces/Signal/namespaces/subtle/variables/watched.md +9 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isComputed.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isState.md +19 -0
- package/api/@xmachines/play-signals/namespaces/Signal/variables/isWatcher.md +19 -0
- package/api/@xmachines/play-signals/type-aliases/WatcherNotify.md +32 -0
- package/api/@xmachines/play-solid/README.md +311 -0
- package/api/@xmachines/play-solid/interfaces/PlayRendererProps.md +15 -0
- package/api/@xmachines/play-solid/variables/PlayRenderer.md +70 -0
- package/api/@xmachines/play-solid-router/README.md +666 -0
- package/api/@xmachines/play-solid-router/classes/RouteMap.md +150 -0
- package/api/@xmachines/play-solid-router/classes/SolidRouterBridge.md +347 -0
- package/api/@xmachines/play-solid-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-solid-router/functions/createRouteMap.md +32 -0
- package/api/@xmachines/play-solid-router/interfaces/AbstractActor.md +486 -0
- package/api/@xmachines/play-solid-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-solid-router/interfaces/RouteMapping.md +14 -0
- package/api/@xmachines/play-solid-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-solid-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-solid-router/type-aliases/SolidRouterHooks.md +51 -0
- package/api/@xmachines/play-solid-router-demo/README.md +127 -0
- package/api/@xmachines/play-tanstack-react-router/README.md +226 -0
- package/api/@xmachines/play-tanstack-react-router/classes/RouteMap.md +137 -0
- package/api/@xmachines/play-tanstack-react-router/classes/TanStackReactRouterBridge.md +348 -0
- package/api/@xmachines/play-tanstack-react-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMap.md +53 -0
- package/api/@xmachines/play-tanstack-react-router/functions/createRouteMapFromTree.md +35 -0
- package/api/@xmachines/play-tanstack-react-router/functions/extractParams.md +38 -0
- package/api/@xmachines/play-tanstack-react-router/functions/extractQueryParams.md +33 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteMapping.md +17 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouteNavigateEvent.md +26 -0
- package/api/@xmachines/play-tanstack-react-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterInstance.md +9 -0
- package/api/@xmachines/play-tanstack-react-router/type-aliases/TanStackRouterLike.md +78 -0
- package/api/@xmachines/play-tanstack-react-router/variables/extractMachineRoutes.md +64 -0
- package/api/@xmachines/play-tanstack-react-router-demo/README.md +126 -0
- package/api/@xmachines/play-tanstack-solid-router/README.md +285 -0
- package/api/@xmachines/play-tanstack-solid-router/classes/RouteMap.md +150 -0
- package/api/@xmachines/play-tanstack-solid-router/classes/SolidRouterBridge.md +343 -0
- package/api/@xmachines/play-tanstack-solid-router/functions/PlayRouterProvider.md +19 -0
- package/api/@xmachines/play-tanstack-solid-router/functions/createRouteMap.md +32 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/PlayRouterProviderProps.md +14 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouteMapping.md +23 -0
- package/api/@xmachines/play-tanstack-solid-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterInstance.md +9 -0
- package/api/@xmachines/play-tanstack-solid-router/type-aliases/TanStackRouterLike.md +78 -0
- package/api/@xmachines/play-tanstack-solid-router-demo/README.md +126 -0
- package/api/@xmachines/play-vue/README.md +292 -0
- package/api/@xmachines/play-vue/interfaces/PlayRendererProps.md +14 -0
- package/api/@xmachines/play-vue/variables/PlayRenderer.md +9 -0
- package/api/@xmachines/play-vue-router/README.md +604 -0
- package/api/@xmachines/play-vue-router/classes/RouteMap.md +209 -0
- package/api/@xmachines/play-vue-router/classes/VueBaseRouteMap.md +201 -0
- package/api/@xmachines/play-vue-router/classes/VueRouterBridge.md +360 -0
- package/api/@xmachines/play-vue-router/functions/createRouteMap.md +19 -0
- package/api/@xmachines/play-vue-router/interfaces/PlayRouteEvent.md +119 -0
- package/api/@xmachines/play-vue-router/interfaces/RouteMapping.md +15 -0
- package/api/@xmachines/play-vue-router/interfaces/RouterBridge.md +104 -0
- package/api/@xmachines/play-vue-router/type-aliases/RoutableActor.md +9 -0
- package/api/@xmachines/play-vue-router/variables/PlayRouterProvider.md +67 -0
- package/api/@xmachines/play-vue-router-demo/README.md +133 -0
- package/api/@xmachines/play-xstate/README.md +512 -0
- package/api/@xmachines/play-xstate/classes/PlayerActor.md +527 -0
- package/api/@xmachines/play-xstate/functions/buildRouteUrl.md +43 -0
- package/api/@xmachines/play-xstate/functions/composeGuards.md +79 -0
- package/api/@xmachines/play-xstate/functions/composeGuardsOr.md +67 -0
- package/api/@xmachines/play-xstate/functions/definePlayer.md +127 -0
- package/api/@xmachines/play-xstate/functions/deriveRoute.md +109 -0
- package/api/@xmachines/play-xstate/functions/eventMatches.md +40 -0
- package/api/@xmachines/play-xstate/functions/formatPlayRouteTransitions.md +54 -0
- package/api/@xmachines/play-xstate/functions/hasContext.md +42 -0
- package/api/@xmachines/play-xstate/functions/isAbsoluteRoute.md +41 -0
- package/api/@xmachines/play-xstate/functions/mergeViewProps.md +26 -0
- package/api/@xmachines/play-xstate/functions/negateGuard.md +61 -0
- package/api/@xmachines/play-xstate/functions/stateMatches.md +25 -0
- package/api/@xmachines/play-xstate/functions/validateComponentBinding.md +39 -0
- package/api/@xmachines/play-xstate/functions/validateViewProps.md +80 -0
- package/api/@xmachines/play-xstate/interfaces/CatalogEntry.md +16 -0
- package/api/@xmachines/play-xstate/interfaces/PlayerConfig.md +24 -0
- package/api/@xmachines/play-xstate/interfaces/PlayerOptions.md +26 -0
- package/api/@xmachines/play-xstate/interfaces/RouteContext.md +22 -0
- package/api/@xmachines/play-xstate/type-aliases/Catalog.md +21 -0
- package/api/@xmachines/play-xstate/type-aliases/ComposedGuard.md +14 -0
- package/api/@xmachines/play-xstate/type-aliases/Guard.md +34 -0
- package/api/@xmachines/play-xstate/type-aliases/GuardArray.md +20 -0
- package/api/@xmachines/play-xstate/type-aliases/PlayerFactory.md +29 -0
- package/api/@xmachines/play-xstate/type-aliases/RouteMachineConfig.md +45 -0
- package/api/@xmachines/play-xstate/type-aliases/RouteStateNode.md +51 -0
- package/api/@xmachines/play-xstate/type-aliases/ValidationResult.md +17 -0
- package/api/@xmachines/play-xstate/type-aliases/ViewMergeContext.md +35 -0
- package/api/@xmachines/shared/README.md +379 -0
- package/api/@xmachines/shared/functions/defineXmVitestConfig.md +29 -0
- package/api/@xmachines/shared/functions/xmAliases.md +24 -0
- package/api/README.md +25 -0
- package/api/llms.txt +26 -0
- package/examples/README.md +63 -0
- package/examples/basic-state-machine.md +70 -0
- package/examples/form-validation.md +167 -0
- package/examples/multi-router-integration.md +277 -0
- package/examples/routing-patterns.md +260 -0
- package/examples/traffic-light.md +99 -0
- package/guides/README.md +29 -0
- package/guides/getting-started.md +223 -0
- package/guides/installation.md +323 -0
- package/index.d.ts +3 -0
- package/index.js +4 -0
- package/package.json +54 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
[Documentation](../../README.md) / @xmachines/play-tanstack-solid-router
|
|
2
|
+
|
|
3
|
+
# @xmachines/play-tanstack-solid-router
|
|
4
|
+
|
|
5
|
+
**TanStack Solid Router adapter for XMachines Universal Player Architecture**
|
|
6
|
+
|
|
7
|
+
Signals-native integration with TanStack Solid Router enabling logic-driven navigation through Solid.js reactivity.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`@xmachines/play-tanstack-solid-router` provides seamless integration between TanStack Solid Router and XMachines state machines. Built on Solid's reactive primitives, it implements the `RouterBridgeBase` pattern for bidirectional synchronization while remaining framework-swappable.
|
|
12
|
+
|
|
13
|
+
Per [RFC Play v1](https://gitlab.com/xmachin-es/rfc/-/blob/main/src/play-v1.md), this package implements:
|
|
14
|
+
|
|
15
|
+
- **Actor Authority (INV-01):** State machine controls navigation, router reflects decisions
|
|
16
|
+
- **Passive Infrastructure (INV-04):** Router observes `actor.currentRoute` signal
|
|
17
|
+
- **Signal-Only Reactivity (INV-05):** `createEffect` synchronizes URL with actor state
|
|
18
|
+
|
|
19
|
+
**Key Benefits:**
|
|
20
|
+
|
|
21
|
+
- **Signals-native:** Zero adaptation layer between Solid signals and TC39 Signals
|
|
22
|
+
- **Bridge-first:** Extends shared `RouterBridgeBase` policy used by other adapters
|
|
23
|
+
- **Automatic tracking:** `createEffect` handles dependency tracking (no manual Watcher setup needed for the bridge)
|
|
24
|
+
- **Logic-driven navigation:** Business logic in state machines, not components
|
|
25
|
+
- **Type-safe parameters:** Route params flow through state machine context
|
|
26
|
+
|
|
27
|
+
**Framework Compatibility:**
|
|
28
|
+
|
|
29
|
+
- TanStack Solid Router 1.100.0+
|
|
30
|
+
- SolidJS 1.8.0+
|
|
31
|
+
- TC39 Signals polyfill integration
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @tanstack/solid-router@^1.108.0 solid-js@^1.8.0 @xmachines/play-tanstack-solid-router @xmachines/play-solid
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Peer dependencies:**
|
|
40
|
+
|
|
41
|
+
- `@tanstack/solid-router` ^1.108.0 - TanStack Solid Router library
|
|
42
|
+
- `solid-js` ^1.8.0 - SolidJS runtime
|
|
43
|
+
- `@xmachines/play-solid` - Solid renderer (`PlayRenderer`)
|
|
44
|
+
- `@xmachines/play-actor` - Actor base
|
|
45
|
+
- `@xmachines/play-router` - Route extraction
|
|
46
|
+
- `@xmachines/play-signals` - TC39 Signals polyfill
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { Router, createRouter } from "@tanstack/solid-router";
|
|
52
|
+
import { PlayTanStackRouterProvider, createRouteMap } from "@xmachines/play-tanstack-solid-router";
|
|
53
|
+
import { PlayRenderer } from "@xmachines/play-solid";
|
|
54
|
+
import { definePlayer } from "@xmachines/play-xstate";
|
|
55
|
+
import { routeTree as routerRouteTree } from "./routeTree.gen"; // from TanStack
|
|
56
|
+
|
|
57
|
+
function App() {
|
|
58
|
+
// 1. Create player with state machine
|
|
59
|
+
const createPlayer = definePlayer({
|
|
60
|
+
machine: authMachine,
|
|
61
|
+
catalog: componentCatalog,
|
|
62
|
+
});
|
|
63
|
+
const actor = createPlayer();
|
|
64
|
+
actor.start();
|
|
65
|
+
|
|
66
|
+
// 2. Create TanStack router instance
|
|
67
|
+
const router = createRouter({ routeTree: routerRouteTree });
|
|
68
|
+
|
|
69
|
+
// 3. Create route mapping from machine routes
|
|
70
|
+
const routeMap = createRouteMap(authMachine);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
// 4. Wrap with provider to sync actor and router
|
|
74
|
+
<PlayTanStackRouterProvider
|
|
75
|
+
actor={actor}
|
|
76
|
+
router={router}
|
|
77
|
+
routeMap={routeMap}
|
|
78
|
+
renderer={(currentActor, currentRouter) => (
|
|
79
|
+
<Router router={currentRouter}>
|
|
80
|
+
<PlayRenderer actor={currentActor} components={components} />
|
|
81
|
+
</Router>
|
|
82
|
+
)}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API Reference
|
|
89
|
+
|
|
90
|
+
### `SolidRouterBridge`
|
|
91
|
+
|
|
92
|
+
Router adapter implementing the `RouterBridge` protocol for TanStack Solid Router.
|
|
93
|
+
|
|
94
|
+
**Type Signature:**
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
class SolidRouterBridge {
|
|
98
|
+
constructor(router: Router, actor: AbstractActor<any>, routeMap: RouteMap);
|
|
99
|
+
dispose(): void;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Constructor Parameters:**
|
|
104
|
+
|
|
105
|
+
- `router` - TanStack Solid Router instance
|
|
106
|
+
- `actor` - XMachines actor instance
|
|
107
|
+
- `routeMap` - Bidirectional state ID ↔ path mapping
|
|
108
|
+
|
|
109
|
+
**Methods:**
|
|
110
|
+
|
|
111
|
+
- `connect()` - Start bidirectional synchronization.
|
|
112
|
+
- `disconnect()` - Stop synchronization and cleanup bridge resources.
|
|
113
|
+
- `dispose()` - Alias of `disconnect()`.
|
|
114
|
+
|
|
115
|
+
**Internal Behavior:**
|
|
116
|
+
|
|
117
|
+
- Uses `RouterBridgeBase` TC39 watcher lifecycle for actor→router synchronization
|
|
118
|
+
- Updates TanStack Router via `router.navigate({ to: path })` when actor state changes
|
|
119
|
+
- Uses `router.subscribe` to watch history navigation events
|
|
120
|
+
- Sends `play.route` events to actor when user navigates
|
|
121
|
+
|
|
122
|
+
### `PlayTanStackRouterProvider`
|
|
123
|
+
|
|
124
|
+
A Solid component that automatically sets up, connects, and tears down the `SolidRouterBridge` using Solid's lifecycle.
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
interface PlayTanStackRouterProviderProps {
|
|
128
|
+
actor: AbstractActor<any>;
|
|
129
|
+
router: Router;
|
|
130
|
+
routeMap: RouteMap;
|
|
131
|
+
renderer: (actor: AbstractActor<any>, router: Router) => JSX.Element;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Props:**
|
|
136
|
+
|
|
137
|
+
- `actor` - The XMachines player actor
|
|
138
|
+
- `router` - The TanStack Solid Router instance
|
|
139
|
+
- `routeMap` - Mapping between paths and state IDs
|
|
140
|
+
- `renderer` - A render prop function that receives the active actor and router
|
|
141
|
+
|
|
142
|
+
**Behavior:**
|
|
143
|
+
|
|
144
|
+
1. Instantiates `SolidRouterBridge` on mount
|
|
145
|
+
2. Calls `bridge.connect()`
|
|
146
|
+
3. Renders the content returned by the `renderer` function
|
|
147
|
+
4. Calls `bridge.disconnect()` when the component unmounts via `onCleanup`
|
|
148
|
+
|
|
149
|
+
### `createRouteMap()`
|
|
150
|
+
|
|
151
|
+
Helper to build a `RouteMap` instance directly from an XState machine.
|
|
152
|
+
|
|
153
|
+
**Signature:**
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
function createRouteMap(machine: AnyStateMachine): RouteMap;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Usage:**
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { createRouteMap } from "@xmachines/play-tanstack-solid-router";
|
|
163
|
+
|
|
164
|
+
const routeMap = createRouteMap(machine);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Usage Patterns
|
|
168
|
+
|
|
169
|
+
### Dynamic Routes with Parameters
|
|
170
|
+
|
|
171
|
+
TanStack Router and URLPattern (used internally) support dynamic route matching syntax:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
// Machine configuration
|
|
175
|
+
const machineConfig = {
|
|
176
|
+
states: {
|
|
177
|
+
profile: {
|
|
178
|
+
meta: {
|
|
179
|
+
route: "/profile/:userId",
|
|
180
|
+
view: { component: "Profile" },
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Route mapping will natively support URLPattern parameters
|
|
187
|
+
routeMap.getStateIdByPath("/profile/123"); // → '#profile'
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Protected Routes and Guards
|
|
191
|
+
|
|
192
|
+
With XMachines, auth guards are handled entirely inside the state machine, preventing flashes of unauthorized content.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// Machine side
|
|
196
|
+
dashboard: {
|
|
197
|
+
meta: { route: "/dashboard", view: { component: "Dashboard" } },
|
|
198
|
+
always: {
|
|
199
|
+
guard: ({ context }) => !context.isAuthenticated,
|
|
200
|
+
target: "login"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
When a user navigates to `/dashboard`:
|
|
206
|
+
|
|
207
|
+
1. TanStack Router updates location
|
|
208
|
+
2. Bridge intercepts and sends `play.route`
|
|
209
|
+
3. Actor evaluates guard -> denies target, transitions to `login` instead
|
|
210
|
+
4. Bridge observes new actor state (`/login`)
|
|
211
|
+
5. Bridge tells TanStack Router to redirect to `/login`
|
|
212
|
+
|
|
213
|
+
## Circular Update Prevention
|
|
214
|
+
|
|
215
|
+
The `RouterBridgeBase` architecture prevents infinite loops between router and actor using two mechanisms:
|
|
216
|
+
|
|
217
|
+
1. **`lastSyncedPath` tracking:** Stores the last synchronized path to prevent redundant navigations back to the identical location.
|
|
218
|
+
2. **`isProcessingNavigation` flag:** Set during a router event, preventing the router from immediately reacting to the actor's synchronous state update.
|
|
219
|
+
|
|
220
|
+
## Comparison with @solidjs/router Adapter
|
|
221
|
+
|
|
222
|
+
| Aspect | @solidjs/router Adapter | @tanstack/solid-router Adapter |
|
|
223
|
+
| ----------------- | -------------------------------- | ------------------------------- |
|
|
224
|
+
| **Router API** | `navigate(path)` | `router.navigate({ to })` |
|
|
225
|
+
| **Setup Context** | Must be _inside_ Router context | Can wrap Router instance |
|
|
226
|
+
| **State Source** | Uses Solid hooks (`useLocation`) | Subscribes to `router` directly |
|
|
227
|
+
| **Reacting** | `createEffect` on location | `router.subscribe` callback |
|
|
228
|
+
|
|
229
|
+
## Architecture
|
|
230
|
+
|
|
231
|
+
This package implements standard Play invariants:
|
|
232
|
+
|
|
233
|
+
### INV-01: Actor Authority
|
|
234
|
+
|
|
235
|
+
State machine has final authority over all transitions. TanStack Router navigation triggers actor events (`play.route`), but the actor's guards and transitions ultimately dictate if the view changes.
|
|
236
|
+
|
|
237
|
+
### INV-02: Passive Infrastructure
|
|
238
|
+
|
|
239
|
+
Infrastructure reflects actor state. The router observes `actor.currentRoute` and updates the browser URL, never storing independent business state.
|
|
240
|
+
|
|
241
|
+
### Cleanup Contract
|
|
242
|
+
|
|
243
|
+
The bridge implements an explicit `dispose()`/`disconnect()` method. `PlayTanStackRouterProvider` wires this automatically to Solid's `onCleanup` hook to prevent memory leaks and duplicate bridge subscriptions in hot-reloading scenarios.
|
|
244
|
+
|
|
245
|
+
## URLPattern Support
|
|
246
|
+
|
|
247
|
+
This package uses the [URLPattern API](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) for robust route pattern matching via `@xmachines/play-router`.
|
|
248
|
+
|
|
249
|
+
URLPattern is available natively on Node.js 24+ and modern browsers (Chrome 95+, Firefox 117+, Safari 16.4+). On older environments, load a polyfill **before** importing this package — see [`@xmachines/play-router` installation](../play-router/README.md) for details.
|
|
250
|
+
|
|
251
|
+
## Related Packages
|
|
252
|
+
|
|
253
|
+
- **[@xmachines/play-solid](../play-solid/README.md)** - SolidJS renderer
|
|
254
|
+
- **[@xmachines/play-router](../play-router/README.md)** - Core router primitives
|
|
255
|
+
- **[@xmachines/play-solid-router](../play-solid-router/README.md)** - Native SolidJS Router equivalent
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
Copyright (c) 2016 [Mikael Karon](mailto:mikael@karon.se). All rights reserved.
|
|
260
|
+
|
|
261
|
+
This work is licensed under the terms of the MIT license.
|
|
262
|
+
For a copy, see <https://opensource.org/licenses/MIT>.
|
|
263
|
+
|
|
264
|
+
## Classes
|
|
265
|
+
|
|
266
|
+
- [RouteMap](classes/RouteMap.md)
|
|
267
|
+
- [SolidRouterBridge](classes/SolidRouterBridge.md)
|
|
268
|
+
|
|
269
|
+
## Interfaces
|
|
270
|
+
|
|
271
|
+
- [PlayRouteEvent](interfaces/PlayRouteEvent.md)
|
|
272
|
+
- [PlayRouterProviderProps](interfaces/PlayRouterProviderProps.md)
|
|
273
|
+
- [RouteMapping](interfaces/RouteMapping.md)
|
|
274
|
+
- [RouterBridge](interfaces/RouterBridge.md)
|
|
275
|
+
|
|
276
|
+
## Type Aliases
|
|
277
|
+
|
|
278
|
+
- [RoutableActor](type-aliases/RoutableActor.md)
|
|
279
|
+
- [TanStackRouterInstance](type-aliases/TanStackRouterInstance.md)
|
|
280
|
+
- [TanStackRouterLike](type-aliases/TanStackRouterLike.md)
|
|
281
|
+
|
|
282
|
+
## Functions
|
|
283
|
+
|
|
284
|
+
- [createRouteMap](functions/createRouteMap.md)
|
|
285
|
+
- [PlayRouterProvider](functions/PlayRouterProvider.md)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
[Documentation](../../../README.md) / [@xmachines/play-tanstack-solid-router](../README.md) / RouteMap
|
|
2
|
+
|
|
3
|
+
# Class: RouteMap
|
|
4
|
+
|
|
5
|
+
Defined in: [play-tanstack-solid-router/src/route-map.ts:26](https://gitlab.com/xmachin-es/xmachines-js/-/blob/00a28432ed57807112288436d1ae4387d9f06919/packages/play-tanstack-solid-router/src/route-map.ts#L26)
|
|
6
|
+
|
|
7
|
+
Shared bidirectional route map base class.
|
|
8
|
+
|
|
9
|
+
All framework adapter `RouteMap` classes extend this — they add no logic of their
|
|
10
|
+
own and inherit the full public API from here.
|
|
11
|
+
|
|
12
|
+
**Lookup strategy:**
|
|
13
|
+
|
|
14
|
+
- Static paths (no `:param`) → O(1) `Map` lookup
|
|
15
|
+
- Dynamic paths → O(k) bucket-indexed scan using `RegExp`, where `k` is the number
|
|
16
|
+
of routes sharing the same first path segment
|
|
17
|
+
- Results are cached after the first match
|
|
18
|
+
|
|
19
|
+
**Pattern syntax** (`:param` / `:param?`):
|
|
20
|
+
|
|
21
|
+
- `:param` — required segment, matches exactly one non-`/` segment
|
|
22
|
+
- `:param?` — optional segment, matches zero or one non-`/` segment
|
|
23
|
+
|
|
24
|
+
## Example
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { BaseRouteMap } from "@xmachines/play-router";
|
|
28
|
+
|
|
29
|
+
const map = new BaseRouteMap([
|
|
30
|
+
{ stateId: "home", path: "/" },
|
|
31
|
+
{ stateId: "profile", path: "/profile/:userId" },
|
|
32
|
+
{ stateId: "settings", path: "/settings/:section?" },
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
map.getStateIdByPath("/"); // "home"
|
|
36
|
+
map.getStateIdByPath("/profile/123"); // "profile"
|
|
37
|
+
map.getStateIdByPath("/settings"); // "settings"
|
|
38
|
+
map.getStateIdByPath("/unknown"); // null
|
|
39
|
+
|
|
40
|
+
map.getPathByStateId("profile"); // "/profile/:userId"
|
|
41
|
+
map.getPathByStateId("missing"); // null
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Extends
|
|
45
|
+
|
|
46
|
+
- [`BaseRouteMap`](../../play-router/classes/BaseRouteMap.md)
|
|
47
|
+
|
|
48
|
+
## Constructors
|
|
49
|
+
|
|
50
|
+
### Constructor
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
new RouteMap(mappings): RouteMap;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Defined in: play-router/dist/base-route-map.d.ts:81
|
|
57
|
+
|
|
58
|
+
Build a route map from an array of state ID ↔ path mappings.
|
|
59
|
+
|
|
60
|
+
Static paths (no `:param`) are indexed in an O(1) `Map`.
|
|
61
|
+
Parameterized paths are compiled to `RegExp` and grouped into first-segment
|
|
62
|
+
buckets for efficient candidate selection.
|
|
63
|
+
|
|
64
|
+
#### Parameters
|
|
65
|
+
|
|
66
|
+
| Parameter | Type | Description |
|
|
67
|
+
| ---------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `mappings` | [`BaseRouteMapping`](../../play-router/interfaces/BaseRouteMapping.md)[] | Array of `{ stateId, path }` entries. Order determines priority when multiple patterns could match the same path. |
|
|
69
|
+
|
|
70
|
+
#### Returns
|
|
71
|
+
|
|
72
|
+
`RouteMap`
|
|
73
|
+
|
|
74
|
+
#### Inherited from
|
|
75
|
+
|
|
76
|
+
[`BaseRouteMap`](../../play-router/classes/BaseRouteMap.md).[`constructor`](../../play-router/classes/BaseRouteMap.md#constructor)
|
|
77
|
+
|
|
78
|
+
## Methods
|
|
79
|
+
|
|
80
|
+
### getPathByStateId()
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
getPathByStateId(stateId): string | null;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Defined in: play-router/dist/base-route-map.d.ts:111
|
|
87
|
+
|
|
88
|
+
Look up the path pattern registered for a state ID.
|
|
89
|
+
|
|
90
|
+
#### Parameters
|
|
91
|
+
|
|
92
|
+
| Parameter | Type | Description |
|
|
93
|
+
| --------- | -------- | --------------------------------------------------------- |
|
|
94
|
+
| `stateId` | `string` | State machine state ID (e.g., `"profile"`, `"#settings"`) |
|
|
95
|
+
|
|
96
|
+
#### Returns
|
|
97
|
+
|
|
98
|
+
`string` \| `null`
|
|
99
|
+
|
|
100
|
+
The registered path pattern, or `null` if the state ID is unknown
|
|
101
|
+
|
|
102
|
+
#### Example
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
map.getPathByStateId("profile"); // "/profile/:userId"
|
|
106
|
+
map.getPathByStateId("missing"); // null
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Inherited from
|
|
110
|
+
|
|
111
|
+
[`BaseRouteMap`](../../play-router/classes/BaseRouteMap.md).[`getPathByStateId`](../../play-router/classes/BaseRouteMap.md#getpathbystateid)
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### getStateIdByPath()
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
getStateIdByPath(path): string | null;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Defined in: play-router/dist/base-route-map.d.ts:98
|
|
122
|
+
|
|
123
|
+
Resolve a URL path to its mapped state ID.
|
|
124
|
+
|
|
125
|
+
Strips query strings and hash fragments before matching. Tries an O(1) exact
|
|
126
|
+
lookup first, then falls back to bucket-indexed pattern matching. Results are
|
|
127
|
+
cached after the first pattern match.
|
|
128
|
+
|
|
129
|
+
#### Parameters
|
|
130
|
+
|
|
131
|
+
| Parameter | Type | Description |
|
|
132
|
+
| --------- | -------- | ------------------------------------------------------------------------------ |
|
|
133
|
+
| `path` | `string` | URL pathname, optionally including query/hash (e.g., `"/profile/123?ref=nav"`) |
|
|
134
|
+
|
|
135
|
+
#### Returns
|
|
136
|
+
|
|
137
|
+
`string` \| `null`
|
|
138
|
+
|
|
139
|
+
The mapped state ID, or `null` if no route matches
|
|
140
|
+
|
|
141
|
+
#### Example
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
map.getStateIdByPath("/profile/123"); // "profile"
|
|
145
|
+
map.getStateIdByPath("/unknown"); // null
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Inherited from
|
|
149
|
+
|
|
150
|
+
[`BaseRouteMap`](../../play-router/classes/BaseRouteMap.md).[`getStateIdByPath`](../../play-router/classes/BaseRouteMap.md#getstateidbypath)
|