@xmachines/play-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 +99 -115
- package/dist/base-route-map.d.ts +7 -1
- package/dist/base-route-map.d.ts.map +1 -1
- package/dist/base-route-map.js +25 -12
- package/dist/base-route-map.js.map +1 -1
- package/dist/build-tree.d.ts +16 -1
- package/dist/build-tree.d.ts.map +1 -1
- package/dist/build-tree.js +22 -4
- package/dist/build-tree.js.map +1 -1
- package/dist/create-route-map-from-tree.d.ts +12 -6
- package/dist/create-route-map-from-tree.d.ts.map +1 -1
- package/dist/create-route-map-from-tree.js +13 -5
- package/dist/create-route-map-from-tree.js.map +1 -1
- package/dist/errors.d.ts +2 -134
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +11 -151
- package/dist/errors.js.map +1 -1
- package/dist/find-route.d.ts.map +1 -1
- package/dist/find-route.js +14 -19
- package/dist/find-route.js.map +1 -1
- package/dist/index.d.ts +6 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/dist/provider-lifecycle.d.ts +10 -6
- package/dist/provider-lifecycle.d.ts.map +1 -1
- package/dist/provider-lifecycle.js +1 -1
- package/dist/provider-lifecycle.js.map +1 -1
- package/dist/router-bridge-base.d.ts +42 -23
- package/dist/router-bridge-base.d.ts.map +1 -1
- package/dist/router-bridge-base.js +249 -76
- package/dist/router-bridge-base.js.map +1 -1
- package/dist/router-sync.d.ts +1 -1
- package/dist/router-sync.d.ts.map +1 -1
- package/dist/router-sync.js +28 -13
- package/dist/router-sync.js.map +1 -1
- package/dist/types.d.ts +186 -87
- package/dist/types.d.ts.map +1 -1
- package/dist/{create-route-map.d.ts → xstate/create-route-map.d.ts} +6 -20
- package/dist/xstate/create-route-map.d.ts.map +1 -0
- package/dist/{create-route-map.js → xstate/create-route-map.js} +5 -3
- package/dist/xstate/create-route-map.js.map +1 -0
- package/dist/{extract-routes.d.ts → xstate/extract-routes.d.ts} +3 -2
- package/dist/xstate/extract-routes.d.ts.map +1 -0
- package/dist/{extract-routes.js → xstate/extract-routes.js} +8 -3
- package/dist/xstate/extract-routes.js.map +1 -0
- package/dist/xstate/index.d.ts +35 -0
- package/dist/xstate/index.d.ts.map +1 -0
- package/dist/xstate/index.js +33 -0
- package/dist/xstate/index.js.map +1 -0
- package/dist/{machine-to-graph.d.ts → xstate/machine-to-graph.d.ts} +1 -1
- package/dist/xstate/machine-to-graph.d.ts.map +1 -0
- package/dist/{machine-to-graph.js → xstate/machine-to-graph.js} +2 -2
- package/dist/xstate/machine-to-graph.js.map +1 -0
- package/dist/xstate/machine-types.d.ts +42 -0
- package/dist/xstate/machine-types.d.ts.map +1 -0
- package/dist/xstate/machine-types.js +2 -0
- package/dist/xstate/machine-types.js.map +1 -0
- package/dist/{query.d.ts → xstate/query.d.ts} +6 -4
- package/dist/xstate/query.d.ts.map +1 -0
- package/dist/{query.js → xstate/query.js} +3 -2
- package/dist/xstate/query.js.map +1 -0
- package/package.json +26 -20
- package/dist/base-path.d.ts +0 -209
- package/dist/base-path.d.ts.map +0 -1
- package/dist/base-path.js +0 -418
- package/dist/base-path.js.map +0 -1
- package/dist/create-route-map.d.ts.map +0 -1
- package/dist/create-route-map.js.map +0 -1
- package/dist/extract-routes.d.ts.map +0 -1
- package/dist/extract-routes.js.map +0 -1
- package/dist/framework-params.d.ts +0 -144
- package/dist/framework-params.d.ts.map +0 -1
- package/dist/framework-params.js +0 -291
- package/dist/framework-params.js.map +0 -1
- package/dist/machine-to-graph.d.ts.map +0 -1
- package/dist/machine-to-graph.js.map +0 -1
- package/dist/query.d.ts.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/url-pattern-utils.d.ts +0 -93
- package/dist/url-pattern-utils.d.ts.map +0 -1
- package/dist/url-pattern-utils.js +0 -233
- package/dist/url-pattern-utils.js.map +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { RouteMap } from "./base-route-map.js";
|
|
2
|
+
import { ROOT_NODE_ID } from "./build-tree.js";
|
|
2
3
|
/**
|
|
3
4
|
* Creates a `RouteMap` from the node structure of a `RouteTree`.
|
|
4
5
|
*
|
|
5
|
-
* A framework router adapter uses this function when it
|
|
6
|
-
* `extractMachineRoutes()`, and not when it calls
|
|
6
|
+
* A framework router adapter uses this function when it holds a `RouteTree`, for example
|
|
7
|
+
* from `extractMachineRoutes()` of `@xmachines/play-router/xstate`, and not when it calls
|
|
8
|
+
* `createRouteMap()` of that package directly.
|
|
7
9
|
*
|
|
8
10
|
* The function walks every node, and it collects the pairs
|
|
9
11
|
* `{ stateId: node.id, path: node.fullPath }`. `node.fullPath` is always the
|
|
@@ -11,6 +13,11 @@ import { RouteMap } from "./base-route-map.js";
|
|
|
11
13
|
* that path for the match of a browser URL. `createRouteMap(machine)` behaves in the
|
|
12
14
|
* same way, because it also uses `node.fullPath`.
|
|
13
15
|
*
|
|
16
|
+
* The walk SKIPS the synthetic root node. `buildRouteTree` makes that node to hold each
|
|
17
|
+
* absolute route, and no state of a machine declares it. `createRouteMap` skips it as
|
|
18
|
+
* well, through `getRoutableRoutes`, and the two functions therefore answer the same map
|
|
19
|
+
* for the same tree.
|
|
20
|
+
*
|
|
14
21
|
* @param routeTree - A `RouteTree`, as `extractMachineRoutes()` returns it.
|
|
15
22
|
* @param options - The optional configuration, for example `{ cacheSize }` to change the size of the LRU cache.
|
|
16
23
|
* @returns A `RouteMap` for each adapter on `RouterBridgeBase`.
|
|
@@ -18,11 +25,12 @@ import { RouteMap } from "./base-route-map.js";
|
|
|
18
25
|
* @example
|
|
19
26
|
* ```typescript
|
|
20
27
|
* // The preferred form — one call for an XState machine:
|
|
21
|
-
* import { createRouteMap } from '@xmachines/play-router';
|
|
28
|
+
* import { createRouteMap } from '@xmachines/play-router/xstate';
|
|
22
29
|
* const routeMap = createRouteMap(machine); // it takes an AnyStateMachine
|
|
23
30
|
*
|
|
24
31
|
* // The two-step form, for a framework adapter that works with a route tree:
|
|
25
|
-
* import {
|
|
32
|
+
* import { createRouteMapFromTree } from '@xmachines/play-router';
|
|
33
|
+
* import { extractMachineRoutes } from '@xmachines/play-router/xstate';
|
|
26
34
|
* const routeTree = extractMachineRoutes(machine);
|
|
27
35
|
* const routeMap = createRouteMapFromTree(routeTree); // it uses node.fullPath, which is absolute
|
|
28
36
|
* ```
|
|
@@ -30,7 +38,7 @@ import { RouteMap } from "./base-route-map.js";
|
|
|
30
38
|
export function createRouteMapFromTree(routeTree, options) {
|
|
31
39
|
const routes = [];
|
|
32
40
|
function traverse(node) {
|
|
33
|
-
if (node.id && node.fullPath) {
|
|
41
|
+
if (node.id && node.fullPath && node.id !== ROOT_NODE_ID) {
|
|
34
42
|
routes.push({ stateId: node.id, path: node.fullPath });
|
|
35
43
|
}
|
|
36
44
|
if (node.children) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-route-map-from-tree.js","sourceRoot":"","sources":["../src/create-route-map-from-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-route-map-from-tree.js","sourceRoot":"","sources":["../src/create-route-map-from-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAoB,EAAE,OAAyB;IACrF,MAAM,MAAM,GAA6C,EAAE,CAAC;IAE5D,SAAS,QAAQ,CAAC,IAAe;QAChC,IAAI,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,EAAE,KAAK,YAAY,EAAE,CAAC;YAC1D,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzB,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PlayError } from "@xmachines/play";
|
|
1
|
+
import { PlayError } from "@xmachines/play/errors";
|
|
2
|
+
export { InvalidRoutePatternError, InvalidBasePathError, MissingBasePathParamError, } from "@xmachines/play-url/errors";
|
|
2
3
|
/**
|
|
3
4
|
* The bridge throws this error when `RouterBridgeBase.syncActorFromRouter()`
|
|
4
5
|
* cannot process a location change of the router and send the `play.route` event to
|
|
@@ -55,27 +56,6 @@ export declare class RouterSyncError extends PlayError {
|
|
|
55
56
|
export declare class DuplicateBridgeError extends PlayError {
|
|
56
57
|
constructor();
|
|
57
58
|
}
|
|
58
|
-
/**
|
|
59
|
-
* The `RouteMap` constructor throws this error when the caller registers a
|
|
60
|
-
* parameterized route, the current runtime has no `URLPattern` API, and no polyfill
|
|
61
|
-
* is loaded.
|
|
62
|
-
*
|
|
63
|
-
* **The remedy:** load `urlpattern-polyfill` at the entry point of your application,
|
|
64
|
-
* before each import of `@xmachines/play-router`:
|
|
65
|
-
*
|
|
66
|
-
* ```typescript
|
|
67
|
-
* // the entry point of the application — it must run first
|
|
68
|
-
* import "urlpattern-polyfill";
|
|
69
|
-
* ```
|
|
70
|
-
*
|
|
71
|
-
* URLPattern is native in Node.js ≥ 24 and in a modern browser (Chrome 95+,
|
|
72
|
-
* Firefox 117+, Safari 16.4+). Use the polyfill for an older target.
|
|
73
|
-
*
|
|
74
|
-
* **Error code:** `PLAY_ROUTE_MAP_URLPATTERN_UNAVAILABLE`
|
|
75
|
-
*/
|
|
76
|
-
export declare class URLPatternUnavailableError extends PlayError {
|
|
77
|
-
constructor();
|
|
78
|
-
}
|
|
79
59
|
/**
|
|
80
60
|
* `validateRouteFormat()` throws this error when a state declares a `meta.route`
|
|
81
61
|
* field with an empty string as its path.
|
|
@@ -122,116 +102,4 @@ export declare class UnknownStateTypeError extends PlayError {
|
|
|
122
102
|
readonly nodeId: string;
|
|
123
103
|
constructor(stateType: string, nodeId: string, validTypes: string[]);
|
|
124
104
|
}
|
|
125
|
-
/**
|
|
126
|
-
* The library throws this error when `URLPattern` cannot compile the string of a route
|
|
127
|
-
* pattern. The `pattern` field holds the string in question, and `cause` holds the
|
|
128
|
-
* original error of the `URLPattern` constructor.
|
|
129
|
-
*
|
|
130
|
-
* Every compilation reports through this error, so `extractRouteParams` raises it for a
|
|
131
|
-
* pattern that no `RouteMap` ever held, and not a bare `TypeError`.
|
|
132
|
-
*
|
|
133
|
-
* The common causes:
|
|
134
|
-
* - A parenthesis or a bracket without its pair in the string of the pattern
|
|
135
|
-
* - A character that a URL pathname pattern does not permit
|
|
136
|
-
* - Two params of one pattern that land on the same URLPattern group. A name with a
|
|
137
|
-
* hyphen compiles with an underscore, so `:cat-id` and `:cat_id` are one group. The
|
|
138
|
-
* message names the two params and the group, and `cause` is absent: the library
|
|
139
|
-
* refuses the pattern before URLPattern sees it.
|
|
140
|
-
*
|
|
141
|
-
* **Error code:** `PLAY_ROUTE_MAP_INVALID_PATTERN`
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* import { InvalidRoutePatternError } from "@xmachines/play-router/errors";
|
|
146
|
-
*
|
|
147
|
-
* try {
|
|
148
|
-
* const routeMap = createRouteMap(machine);
|
|
149
|
-
* } catch (err) {
|
|
150
|
-
* if (err instanceof InvalidRoutePatternError) {
|
|
151
|
-
* console.error(`Bad route pattern: "${err.pattern}"`, err.cause);
|
|
152
|
-
* }
|
|
153
|
-
* }
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
export declare class InvalidRoutePatternError extends PlayError {
|
|
157
|
-
/** The string of the route pattern. URLPattern could not compile it. */
|
|
158
|
-
readonly pattern: string;
|
|
159
|
-
/**
|
|
160
|
-
* @param pattern - The route pattern that URLPattern could not compile.
|
|
161
|
-
* @param options - The standard `cause`, and an optional `reason` that says WHY. Give
|
|
162
|
-
* a reason whenever the library knows it: the pattern alone shows a caller nothing
|
|
163
|
-
* when the fault is a rewrite that the library made, and not the text they wrote.
|
|
164
|
-
*/
|
|
165
|
-
constructor(pattern: string, options?: ErrorOptions & {
|
|
166
|
-
reason?: string;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Thrown when a `basePath` option resolves to one concrete URL prefix never.
|
|
171
|
-
*
|
|
172
|
-
* A bridge writes a real browser URL from its prefix, so every segment must hold
|
|
173
|
-
* exactly one value. A wildcard segment (`*`), an optional segment (`:section?`), a
|
|
174
|
-
* nameless `:` segment, a query string, and a hash fragment each describe a SET of
|
|
175
|
-
* prefixes instead, or no prefix at all. A `$param` segment is the route-param
|
|
176
|
-
* syntax of TanStack Router: a base path writes a param as `:param`, and it takes
|
|
177
|
-
* the value of that param from `basePathParams`.
|
|
178
|
-
*
|
|
179
|
-
* **How to fix it:** mount on the prefix itself, and let the machine own the rest.
|
|
180
|
-
* For the splat route `/$machineId/play/$` of TanStack, the base path is
|
|
181
|
-
* `"/:machineId/play"` with `basePathParams: { machineId }`.
|
|
182
|
-
*
|
|
183
|
-
* **Error code:** `PLAY_ROUTER_INVALID_BASE_PATH`
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```typescript
|
|
187
|
-
* import { InvalidBasePathError } from "@xmachines/play-router/errors";
|
|
188
|
-
*
|
|
189
|
-
* try {
|
|
190
|
-
* bridge.setBasePath("/:machineId/play/*");
|
|
191
|
-
* } catch (err) {
|
|
192
|
-
* if (err instanceof InvalidBasePathError) {
|
|
193
|
-
* console.error(`Bad base path: "${err.basePath}"`, err.message);
|
|
194
|
-
* }
|
|
195
|
-
* }
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export declare class InvalidBasePathError extends PlayError {
|
|
199
|
-
/** The `basePath` option of the refusal, exactly as the caller gave it. */
|
|
200
|
-
readonly basePath: string;
|
|
201
|
-
constructor(basePath: string, reason: string);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Thrown when a `:param` segment of a `basePath` has no value in `basePathParams`.
|
|
205
|
-
*
|
|
206
|
-
* A base path can be a pattern, so a host keeps one string that mirrors its own
|
|
207
|
-
* route config. The bridge must still resolve that pattern to a concrete prefix,
|
|
208
|
-
* because it writes a real browser URL, and it removes a literal prefix from every
|
|
209
|
-
* inbound location. Every `:param` therefore needs a value.
|
|
210
|
-
*
|
|
211
|
-
* **How to fix it:** give the value that the host resolved already — a loader of
|
|
212
|
-
* TanStack, or a `useParams()` call, holds it — as `basePathParams: { machineId }`.
|
|
213
|
-
* An empty string counts as an absent value, because it would collapse the segment.
|
|
214
|
-
*
|
|
215
|
-
* **Error code:** `PLAY_ROUTER_MISSING_BASE_PATH_PARAM`
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* import { MissingBasePathParamError } from "@xmachines/play-router/errors";
|
|
220
|
-
*
|
|
221
|
-
* try {
|
|
222
|
-
* connectRouter({ actor, router, routeMap, basePath: "/:machineId/play" });
|
|
223
|
-
* } catch (err) {
|
|
224
|
-
* if (err instanceof MissingBasePathParamError) {
|
|
225
|
-
* console.error(`basePath needs a value for :${err.param}`);
|
|
226
|
-
* }
|
|
227
|
-
* }
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
export declare class MissingBasePathParamError extends PlayError {
|
|
231
|
-
/** The name of the `:param` segment without a value, and without its `:`. */
|
|
232
|
-
readonly param: string;
|
|
233
|
-
/** The `basePath` option that declares the param. */
|
|
234
|
-
readonly basePath: string;
|
|
235
|
-
constructor(param: string, basePath: string);
|
|
236
|
-
}
|
|
237
105
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAWnD,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,GACzB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAInD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;;CAUlD;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAS3B;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAS3B;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IACrD,sFAAsF;IACtF,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;gBAElB,UAAU,EAAE,MAAM,EAAE;CAWhC;AAED;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;IACnD,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE;CAWnE"}
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import { PlayError } from "@xmachines/play";
|
|
1
|
+
import { PlayError } from "@xmachines/play/errors";
|
|
2
|
+
// The errors of the URL language live in `@xmachines/play-url`, with the parser that
|
|
3
|
+
// raises them. They are re-exported here, so that a consumer of this package sorts every
|
|
4
|
+
// routing error from one import, exactly as before the split.
|
|
5
|
+
//
|
|
6
|
+
// The specifier is the `./errors` subpath, and not the root barrel. A consumer that
|
|
7
|
+
// imports `@xmachines/play-router/errors` to name a fault in a `catch` then loads the
|
|
8
|
+
// three classes alone: no pattern parser, no base path, and neither `quick-lru` nor
|
|
9
|
+
// `urlpattern-polyfill`. The root barrel of this package reaches the rest of
|
|
10
|
+
// `@xmachines/play-url` for the consumer that needs it.
|
|
11
|
+
export { InvalidRoutePatternError, InvalidBasePathError, MissingBasePathParamError, } from "@xmachines/play-url/errors";
|
|
2
12
|
/**
|
|
3
13
|
* The bridge throws this error when `RouterBridgeBase.syncActorFromRouter()`
|
|
4
14
|
* cannot process a location change of the router and send the `play.route` event to
|
|
@@ -62,30 +72,6 @@ export class DuplicateBridgeError extends PlayError {
|
|
|
62
72
|
this.name = "DuplicateBridgeError";
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
|
-
/**
|
|
66
|
-
* The `RouteMap` constructor throws this error when the caller registers a
|
|
67
|
-
* parameterized route, the current runtime has no `URLPattern` API, and no polyfill
|
|
68
|
-
* is loaded.
|
|
69
|
-
*
|
|
70
|
-
* **The remedy:** load `urlpattern-polyfill` at the entry point of your application,
|
|
71
|
-
* before each import of `@xmachines/play-router`:
|
|
72
|
-
*
|
|
73
|
-
* ```typescript
|
|
74
|
-
* // the entry point of the application — it must run first
|
|
75
|
-
* import "urlpattern-polyfill";
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* URLPattern is native in Node.js ≥ 24 and in a modern browser (Chrome 95+,
|
|
79
|
-
* Firefox 117+, Safari 16.4+). Use the polyfill for an older target.
|
|
80
|
-
*
|
|
81
|
-
* **Error code:** `PLAY_ROUTE_MAP_URLPATTERN_UNAVAILABLE`
|
|
82
|
-
*/
|
|
83
|
-
export class URLPatternUnavailableError extends PlayError {
|
|
84
|
-
constructor() {
|
|
85
|
-
super("RouteMap", "PLAY_ROUTE_MAP_URLPATTERN_UNAVAILABLE", "URLPattern is not available. Load a polyfill (e.g. urlpattern-polyfill) before using @xmachines/play-router on Node < 24 or older browsers.");
|
|
86
|
-
this.name = "URLPatternUnavailableError";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
75
|
/**
|
|
90
76
|
* `validateRouteFormat()` throws this error when a state declares a `meta.route`
|
|
91
77
|
* field with an empty string as its path.
|
|
@@ -152,130 +138,4 @@ export class UnknownStateTypeError extends PlayError {
|
|
|
152
138
|
this.nodeId = nodeId;
|
|
153
139
|
}
|
|
154
140
|
}
|
|
155
|
-
/**
|
|
156
|
-
* The library throws this error when `URLPattern` cannot compile the string of a route
|
|
157
|
-
* pattern. The `pattern` field holds the string in question, and `cause` holds the
|
|
158
|
-
* original error of the `URLPattern` constructor.
|
|
159
|
-
*
|
|
160
|
-
* Every compilation reports through this error, so `extractRouteParams` raises it for a
|
|
161
|
-
* pattern that no `RouteMap` ever held, and not a bare `TypeError`.
|
|
162
|
-
*
|
|
163
|
-
* The common causes:
|
|
164
|
-
* - A parenthesis or a bracket without its pair in the string of the pattern
|
|
165
|
-
* - A character that a URL pathname pattern does not permit
|
|
166
|
-
* - Two params of one pattern that land on the same URLPattern group. A name with a
|
|
167
|
-
* hyphen compiles with an underscore, so `:cat-id` and `:cat_id` are one group. The
|
|
168
|
-
* message names the two params and the group, and `cause` is absent: the library
|
|
169
|
-
* refuses the pattern before URLPattern sees it.
|
|
170
|
-
*
|
|
171
|
-
* **Error code:** `PLAY_ROUTE_MAP_INVALID_PATTERN`
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* import { InvalidRoutePatternError } from "@xmachines/play-router/errors";
|
|
176
|
-
*
|
|
177
|
-
* try {
|
|
178
|
-
* const routeMap = createRouteMap(machine);
|
|
179
|
-
* } catch (err) {
|
|
180
|
-
* if (err instanceof InvalidRoutePatternError) {
|
|
181
|
-
* console.error(`Bad route pattern: "${err.pattern}"`, err.cause);
|
|
182
|
-
* }
|
|
183
|
-
* }
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
export class InvalidRoutePatternError extends PlayError {
|
|
187
|
-
/** The string of the route pattern. URLPattern could not compile it. */
|
|
188
|
-
pattern;
|
|
189
|
-
/**
|
|
190
|
-
* @param pattern - The route pattern that URLPattern could not compile.
|
|
191
|
-
* @param options - The standard `cause`, and an optional `reason` that says WHY. Give
|
|
192
|
-
* a reason whenever the library knows it: the pattern alone shows a caller nothing
|
|
193
|
-
* when the fault is a rewrite that the library made, and not the text they wrote.
|
|
194
|
-
*/
|
|
195
|
-
constructor(pattern, options) {
|
|
196
|
-
const reason = options?.reason;
|
|
197
|
-
super("RouteMap", "PLAY_ROUTE_MAP_INVALID_PATTERN", reason
|
|
198
|
-
? `Invalid route pattern: "${pattern}". ${reason}`
|
|
199
|
-
: `Invalid route pattern: "${pattern}"`, options);
|
|
200
|
-
this.name = "InvalidRoutePatternError";
|
|
201
|
-
this.pattern = pattern;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Thrown when a `basePath` option resolves to one concrete URL prefix never.
|
|
206
|
-
*
|
|
207
|
-
* A bridge writes a real browser URL from its prefix, so every segment must hold
|
|
208
|
-
* exactly one value. A wildcard segment (`*`), an optional segment (`:section?`), a
|
|
209
|
-
* nameless `:` segment, a query string, and a hash fragment each describe a SET of
|
|
210
|
-
* prefixes instead, or no prefix at all. A `$param` segment is the route-param
|
|
211
|
-
* syntax of TanStack Router: a base path writes a param as `:param`, and it takes
|
|
212
|
-
* the value of that param from `basePathParams`.
|
|
213
|
-
*
|
|
214
|
-
* **How to fix it:** mount on the prefix itself, and let the machine own the rest.
|
|
215
|
-
* For the splat route `/$machineId/play/$` of TanStack, the base path is
|
|
216
|
-
* `"/:machineId/play"` with `basePathParams: { machineId }`.
|
|
217
|
-
*
|
|
218
|
-
* **Error code:** `PLAY_ROUTER_INVALID_BASE_PATH`
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* import { InvalidBasePathError } from "@xmachines/play-router/errors";
|
|
223
|
-
*
|
|
224
|
-
* try {
|
|
225
|
-
* bridge.setBasePath("/:machineId/play/*");
|
|
226
|
-
* } catch (err) {
|
|
227
|
-
* if (err instanceof InvalidBasePathError) {
|
|
228
|
-
* console.error(`Bad base path: "${err.basePath}"`, err.message);
|
|
229
|
-
* }
|
|
230
|
-
* }
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
export class InvalidBasePathError extends PlayError {
|
|
234
|
-
/** The `basePath` option of the refusal, exactly as the caller gave it. */
|
|
235
|
-
basePath;
|
|
236
|
-
constructor(basePath, reason) {
|
|
237
|
-
super("resolveBasePath", "PLAY_ROUTER_INVALID_BASE_PATH", `Invalid basePath "${basePath}": ${reason}`);
|
|
238
|
-
this.name = "InvalidBasePathError";
|
|
239
|
-
this.basePath = basePath;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Thrown when a `:param` segment of a `basePath` has no value in `basePathParams`.
|
|
244
|
-
*
|
|
245
|
-
* A base path can be a pattern, so a host keeps one string that mirrors its own
|
|
246
|
-
* route config. The bridge must still resolve that pattern to a concrete prefix,
|
|
247
|
-
* because it writes a real browser URL, and it removes a literal prefix from every
|
|
248
|
-
* inbound location. Every `:param` therefore needs a value.
|
|
249
|
-
*
|
|
250
|
-
* **How to fix it:** give the value that the host resolved already — a loader of
|
|
251
|
-
* TanStack, or a `useParams()` call, holds it — as `basePathParams: { machineId }`.
|
|
252
|
-
* An empty string counts as an absent value, because it would collapse the segment.
|
|
253
|
-
*
|
|
254
|
-
* **Error code:** `PLAY_ROUTER_MISSING_BASE_PATH_PARAM`
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* ```typescript
|
|
258
|
-
* import { MissingBasePathParamError } from "@xmachines/play-router/errors";
|
|
259
|
-
*
|
|
260
|
-
* try {
|
|
261
|
-
* connectRouter({ actor, router, routeMap, basePath: "/:machineId/play" });
|
|
262
|
-
* } catch (err) {
|
|
263
|
-
* if (err instanceof MissingBasePathParamError) {
|
|
264
|
-
* console.error(`basePath needs a value for :${err.param}`);
|
|
265
|
-
* }
|
|
266
|
-
* }
|
|
267
|
-
* ```
|
|
268
|
-
*/
|
|
269
|
-
export class MissingBasePathParamError extends PlayError {
|
|
270
|
-
/** The name of the `:param` segment without a value, and without its `:`. */
|
|
271
|
-
param;
|
|
272
|
-
/** The `basePath` option that declares the param. */
|
|
273
|
-
basePath;
|
|
274
|
-
constructor(param, basePath) {
|
|
275
|
-
super("resolveBasePath", "PLAY_ROUTER_MISSING_BASE_PATH_PARAM", `basePath "${basePath}" declares ":${param}", but basePathParams has no value for it.`);
|
|
276
|
-
this.name = "MissingBasePathParamError";
|
|
277
|
-
this.param = param;
|
|
278
|
-
this.basePath = basePath;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
141
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,qFAAqF;AACrF,yFAAyF;AACzF,8DAA8D;AAC9D,EAAE;AACF,oFAAoF;AACpF,sFAAsF;AACtF,oFAAoF;AACpF,6EAA6E;AAC7E,wDAAwD;AACxD,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,GACzB,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC7C,YAAY,OAAe,EAAE,OAAsB;QAClD,KAAK,CAAC,kBAAkB,EAAE,yBAAyB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACvE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IAClD;QACC,KAAK,CACJ,kBAAkB,EAClB,8BAA8B,EAC9B,iEAAiE;YAChE,uEAAuE,CACxE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACpC,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IACjD,8CAA8C;IACrC,OAAO,CAAS;IAEzB,YAAY,OAAe;QAC1B,KAAK,CACJ,UAAU,EACV,uBAAuB,EACvB,8BAA8B,OAAO,sCAAsC,CAC3E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IACjD,iEAAiE;IACxD,OAAO,CAAS;IAEzB,YAAY,OAAe;QAC1B,KAAK,CACJ,UAAU,EACV,6BAA6B,EAC7B,2CAA2C,OAAO,EAAE,CACpD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACrD,sFAAsF;IAC7E,UAAU,CAAW;IAE9B,YAAY,UAAoB;QAC/B,KAAK,CACJ,UAAU,EACV,2BAA2B,EAC3B,oCAAoC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;YAC9D,kDAAkD;YAClD,6FAA6F,CAC9F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IACnD,mEAAmE;IAC1D,SAAS,CAAS;IAC3B,sDAAsD;IAC7C,MAAM,CAAS;IAExB,YAAY,SAAiB,EAAE,MAAc,EAAE,UAAoB;QAClE,KAAK,CACJ,gBAAgB,EAChB,+BAA+B,EAC/B,8BAA8B,SAAS,cAAc,MAAM,KAAK;YAC/D,oBAAoB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAC7C,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD"}
|
package/dist/find-route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-route.d.ts","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"find-route.d.ts","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAkCvD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,SAAS,EAAE,IAAI,MAAM,KAAG,SAAS,GAAG,SAEvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,SAAS,EAAE,MAAM,MAAM,KAAG,SAAS,GAAG,SAyB3E,CAAC"}
|
package/dist/find-route.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { URLPatternUnavailableError, InvalidRoutePatternError } from "./errors.js";
|
|
1
|
+
import { getCompiledPattern, isParameterizedPattern } from "@xmachines/play-url";
|
|
3
2
|
/**
|
|
4
3
|
* Tells you if a URL path matches a route pattern, with URLPattern.
|
|
5
4
|
*
|
|
6
|
-
* For a static pattern, which holds no
|
|
7
|
-
*
|
|
8
|
-
* never, and it needs no polyfill.
|
|
5
|
+
* For a static pattern, which holds no param, the function makes a direct equality
|
|
6
|
+
* test, and it compiles nothing.
|
|
9
7
|
*
|
|
10
8
|
* The function uses the compiled-pattern cache of the module level
|
|
11
9
|
* (`getCompiledPattern`). A repeated lookup therefore compiles the same pattern
|
|
12
10
|
* never again. The cache also normalizes a param name with a hyphen (`:cat-id`)
|
|
13
11
|
* exactly like `RouteMap`: one match engine is below both.
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* It throws an `InvalidRoutePatternError` when URLPattern cannot compile the
|
|
18
|
-
* pattern.
|
|
13
|
+
* It throws the `InvalidRoutePatternError` of `getCompiledPattern` when URLPattern
|
|
14
|
+
* cannot compile the pattern.
|
|
19
15
|
*
|
|
20
16
|
* This function is private. The public API of the package does not export it.
|
|
21
17
|
*
|
|
@@ -24,17 +20,16 @@ import { URLPatternUnavailableError, InvalidRoutePatternError } from "./errors.j
|
|
|
24
20
|
* @returns True when the path matches the pattern
|
|
25
21
|
*/
|
|
26
22
|
function matchesPattern(path, pattern) {
|
|
27
|
-
|
|
23
|
+
// The test reads the PARSE. `pattern.includes(":")` called `/docs/*` and `/a{/b}?/c`
|
|
24
|
+
// static, and the equality test below then answered `false` for every path that the
|
|
25
|
+
// pattern matches.
|
|
26
|
+
if (!isParameterizedPattern(pattern))
|
|
28
27
|
return path === pattern;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
throw new InvalidRoutePatternError(pattern, { cause: err });
|
|
37
|
-
}
|
|
28
|
+
// `getCompiledPattern` reports an invalid pattern itself, and with the REASON when it
|
|
29
|
+
// knows one — two params that land on one URLPattern group, for example. A wrap here
|
|
30
|
+
// replaced that message with the generic one and pushed the explanation down to
|
|
31
|
+
// `cause`, which is the same defect that `RouteMap` guards against in its constructor.
|
|
32
|
+
return getCompiledPattern(pattern).test({ pathname: path });
|
|
38
33
|
}
|
|
39
34
|
/**
|
|
40
35
|
* Finds a route node by its state ID
|
package/dist/find-route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-route.js","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"find-route.js","sourceRoot":"","sources":["../src/find-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGjF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,OAAe;IACpD,qFAAqF;IACrF,oFAAoF;IACpF,mBAAmB;IACnB,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,KAAK,OAAO,CAAC;IAC9D,sFAAsF;IACtF,qFAAqF;IACrF,gFAAgF;IAChF,uFAAuF;IACvF,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAe,EAAE,EAAU,EAAyB,EAAE;IACnF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAe,EAAE,IAAY,EAAyB,EAAE;IACvF,wEAAwE;IACxE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEnC,IAAI,IAAI,EAAE,QAAQ,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,oFAAoF;IACpF,4BAA4B;IAC5B,gEAAgE;IAChE,0EAA0E;IAC1E,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YACzB,SAAS,CAAC,iCAAiC;QAC5C,CAAC;QAED,iDAAiD;QACjD,IAAI,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;IAED,yFAAyF;IACzF,OAAO,IAAI,CAAC;AACb,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
|
-
import type { RouteMapping } from "./base-route-map.js";
|
|
2
1
|
export { RouterBridgeBase } from "./router-bridge-base.js";
|
|
3
2
|
export type { RouteWatcherHandle } from "./router-bridge-base.js";
|
|
4
3
|
export { sanitizePathname, buildPlayRouteEvent, extractQuery, extractRouteParams, } from "./router-sync.js";
|
|
5
4
|
export type { RouteMatch, BuildPlayRouteEventOptions } from "./router-sync.js";
|
|
6
5
|
export { validateRouteFormat, validateStateExists, detectDuplicateRoutes, } from "./validate-routes.js";
|
|
7
6
|
export type { ResolvedRoutePath } from "./validate-routes.js";
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export { normalizeBasePath, resolveBasePath, stripBasePath, joinBasePath, NO_BASE_PATH, } from "./base-path.js";
|
|
12
|
-
export type { BasePathOptions, ResolvedBasePath } from "./base-path.js";
|
|
13
|
-
export { cleanFrameworkParams, getPatternParamNames, getRequiredPatternParamNames, pickOwnParams, resolveFrameworkParams, type FrameworkParamsSource, } from "./framework-params.js";
|
|
7
|
+
export { normalizeBasePath, resolveBasePath, stripBasePath, joinBasePath, NO_BASE_PATH, } from "@xmachines/play-url";
|
|
8
|
+
export type { BasePathOptions, ResolvedBasePath } from "@xmachines/play-url";
|
|
9
|
+
export { cleanFrameworkParams, getPatternParamNames, getRequiredPatternParamNames, pickOwnParams, resolveFrameworkParams, type FrameworkParamsSource, } from "@xmachines/play-url";
|
|
14
10
|
export { isMountableBridge, mountKey, createRouterConnection, openProviderBridge, repointProviderBridge, } from "./provider-lifecycle.js";
|
|
15
11
|
export type { OpenProviderBridgeArgs, PlayRouterBridgeConstructor, PlayRouterProviderBaseProps, RouterConnection, } from "./provider-lifecycle.js";
|
|
16
|
-
export {
|
|
17
|
-
export type { MachineGraph } from "./machine-to-graph.js";
|
|
18
|
-
export type { RouteInfo, RouteNode, RouteTree, RouteObject, RouteMetadata, PlayRouteEvent, RoutableActor, PlayActor, RouterBridge, MountableRouterBridge, MachineNodeData, MachineEdgeData, WindowLike, LocationLike, } from "./types.js";
|
|
12
|
+
export type { RouteInfo, RouteNode, RouteTree, RouteObject, RouteMetadata, RouteData, RouteDataResolver, PlayRouteEvent, Routable, RoutableActor, RouterBridge, MountableRouterBridge, WindowLike, LocationLike, } from "./types.js";
|
|
19
13
|
export { RouteMap, type RouteMapping } from "./base-route-map.js";
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated Use {@link RouteMapping}. Will be removed in the next major.
|
|
22
|
-
*/
|
|
23
|
-
export type BaseRouteMapping = RouteMapping;
|
|
24
|
-
export { createRouteMap } from "./create-route-map.js";
|
|
25
|
-
export type { RouteMapOptions } from "./create-route-map.js";
|
|
26
14
|
export { createRouteMapFromTree } from "./create-route-map-from-tree.js";
|
|
27
15
|
export { findRouteById, findRouteByPath } from "./find-route.js";
|
|
28
16
|
export { DISPOSE } from "@xmachines/play";
|
|
17
|
+
export { buildRouteTree, ROOT_NODE_ID } from "./build-tree.js";
|
|
18
|
+
export type { RouteMapOptions } from "./types.js";
|
|
29
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAM9D,OAAO,EACN,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG7E,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,aAAa,EACb,sBAAsB,EACtB,KAAK,qBAAqB,GAC1B,MAAM,qBAAqB,CAAC;AAK7B,OAAO,EACN,iBAAiB,EACjB,QAAQ,EACR,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,GACrB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,sBAAsB,EACtB,2BAA2B,EAC3B,2BAA2B,EAC3B,gBAAgB,GAChB,MAAM,yBAAyB,CAAC;AAEjC,YAAY,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,WAAW,EACX,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,UAAU,EACV,YAAY,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAGzE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAMjE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAI1C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,30 +4,21 @@ export { RouterBridgeBase } from "./router-bridge-base.js";
|
|
|
4
4
|
export { sanitizePathname, buildPlayRouteEvent, extractQuery, extractRouteParams, } from "./router-sync.js";
|
|
5
5
|
// The route utilities
|
|
6
6
|
export { validateRouteFormat, validateStateExists, detectDuplicateRoutes, } from "./validate-routes.js";
|
|
7
|
-
export { buildRouteTree } from "./build-tree.js";
|
|
8
|
-
export { extractMachineRoutes } from "./extract-routes.js";
|
|
9
|
-
export { getNavigableRoutes, getRoutableRoutes, routeExists, getRouteMappings, getTransitionReachableRoutes, isRouteReachable, } from "./query.js";
|
|
10
7
|
// The base-path mount — it lets a host own a part of the same router as a machine.
|
|
11
8
|
// A consumer normally gives `basePath` to a bridge, to `connectRouter`, or to a
|
|
12
9
|
// `PlayRouterProvider`. These primitives serve an adapter, and a host that builds its
|
|
13
10
|
// own route table.
|
|
14
|
-
export { normalizeBasePath, resolveBasePath, stripBasePath, joinBasePath, NO_BASE_PATH, } from "
|
|
11
|
+
export { normalizeBasePath, resolveBasePath, stripBasePath, joinBasePath, NO_BASE_PATH, } from "@xmachines/play-url";
|
|
15
12
|
// The params of a framework router, reconciled with the pattern of the machine. A
|
|
16
13
|
// bridge whose framework parses the params itself calls this, and it keeps that parse.
|
|
17
|
-
export { cleanFrameworkParams, getPatternParamNames, getRequiredPatternParamNames, pickOwnParams, resolveFrameworkParams, } from "
|
|
14
|
+
export { cleanFrameworkParams, getPatternParamNames, getRequiredPatternParamNames, pickOwnParams, resolveFrameworkParams, } from "@xmachines/play-url";
|
|
18
15
|
// The framework-free half of a PlayRouterProvider: the props, the constructor shape,
|
|
19
16
|
// and the lifecycle of the bridge. A provider of a framework adds its own effects and
|
|
20
17
|
// nothing else. This entry stays framework-agnostic — nothing here imports one.
|
|
21
18
|
export { isMountableBridge, mountKey, createRouterConnection, openProviderBridge, repointProviderBridge, } from "./provider-lifecycle.js";
|
|
22
|
-
// The graph adapter — it converts an XState machine into a Graph of @statelyai/graph
|
|
23
|
-
export { machineToGraph } from "./machine-to-graph.js";
|
|
24
19
|
// The shared base class of the route map for both directions.
|
|
25
|
-
// This module exports RouteMapping directly. BaseRouteMapping stays as an alias, for
|
|
26
|
-
// the compatibility.
|
|
27
20
|
export { RouteMap } from "./base-route-map.js";
|
|
28
21
|
// The factories: each one creates a RouteMap from a machine or from a route tree.
|
|
29
|
-
// Every RouterBridgeBase adapter uses them, and it writes no factory of its own.
|
|
30
|
-
export { createRouteMap } from "./create-route-map.js";
|
|
31
22
|
export { createRouteMapFromTree } from "./create-route-map-from-tree.js";
|
|
32
23
|
// The helpers of a route lookup. matchesPattern stays private inside find-route.ts
|
|
33
24
|
export { findRouteById, findRouteByPath } from "./find-route.js";
|
|
@@ -36,4 +27,7 @@ export { findRouteById, findRouteByPath } from "./find-route.js";
|
|
|
36
27
|
// entry. It names `asCleanup` nowhere: a consumer of this package RECEIVES a
|
|
37
28
|
// release, and builds one only with @xmachines/play itself.
|
|
38
29
|
export { DISPOSE } from "@xmachines/play";
|
|
30
|
+
// The tree builder and its options. `@xmachines/play-router/xstate` reads both: it walks
|
|
31
|
+
// a machine, and it hands the routes here to become a tree and then a route map.
|
|
32
|
+
export { buildRouteTree, ROOT_NODE_ID } from "./build-tree.js";
|
|
39
33
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,wHAAwH;AACxH,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,sBAAsB;AACtB,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,sBAAsB,CAAC;AAG9B,mFAAmF;AACnF,gFAAgF;AAChF,sFAAsF;AACtF,mBAAmB;AACnB,OAAO,EACN,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,YAAY,GACZ,MAAM,qBAAqB,CAAC;AAE7B,kFAAkF;AAClF,uFAAuF;AACvF,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,aAAa,EACb,sBAAsB,GAEtB,MAAM,qBAAqB,CAAC;AAE7B,qFAAqF;AACrF,sFAAsF;AACtF,gFAAgF;AAChF,OAAO,EACN,iBAAiB,EACjB,QAAQ,EACR,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,GACrB,MAAM,yBAAyB,CAAC;AAyBjC,8DAA8D;AAC9D,OAAO,EAAE,QAAQ,EAAqB,MAAM,qBAAqB,CAAC;AAElE,kFAAkF;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,mFAAmF;AACnF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEjE,sFAAsF;AACtF,iFAAiF;AACjF,6EAA6E;AAC7E,4DAA4D;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,yFAAyF;AACzF,iFAAiF;AACjF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @see [Multi-router integration](../../docs/examples/multi-router-integration.md)
|
|
19
19
|
*/
|
|
20
|
+
import { type BasePathOptions } from "@xmachines/play-url";
|
|
20
21
|
import { DISPOSE } from "@xmachines/play";
|
|
21
|
-
import {
|
|
22
|
-
import type { MountableRouterBridge, PlayActor, RouterBridge } from "./types.js";
|
|
22
|
+
import type { MountableRouterBridge, RoutableActor, RouterBridge } from "./types.js";
|
|
23
23
|
import type { RouteMap } from "./base-route-map.js";
|
|
24
24
|
/**
|
|
25
25
|
* The props that every `PlayRouterProvider` of a framework shares.
|
|
@@ -31,7 +31,7 @@ import type { RouteMap } from "./base-route-map.js";
|
|
|
31
31
|
* An adapter re-exports a two-parameter alias of this type, with `TRouter` bound to
|
|
32
32
|
* the type of its router instance and `TNode` bound to its own node type.
|
|
33
33
|
*/
|
|
34
|
-
export interface PlayRouterProviderBaseProps<TRouter, TActor extends
|
|
34
|
+
export interface PlayRouterProviderBaseProps<TRouter, TActor extends RoutableActor, TNode> {
|
|
35
35
|
/**
|
|
36
36
|
* The actor to keep in step with the router. It must be a stable reference: give
|
|
37
37
|
* the same actor instance on every render. An actor in the JSX, or a new actor on
|
|
@@ -91,13 +91,17 @@ export interface PlayRouterProviderBaseProps<TRouter, TActor extends PlayActor,
|
|
|
91
91
|
/**
|
|
92
92
|
* The constructor shape that a bridge class must satisfy for a provider factory: `(router, actor, routeMap, options?) → RouterBridge`.
|
|
93
93
|
*
|
|
94
|
+
* `TActor` carries the actor type of the caller through to the constructor, so the spec
|
|
95
|
+
* type of that actor reaches the bridge whole. A bridge that reads no spec binds nothing
|
|
96
|
+
* and receives the default.
|
|
97
|
+
*
|
|
94
98
|
* The return type is `RouterBridge`, the published contract of a bridge, so a
|
|
95
99
|
* consumer bridge of its own keeps compiling. Every bridge on `RouterBridgeBase` also
|
|
96
100
|
* satisfies `MountableRouterBridge`, and the provider finds that mount API at run
|
|
97
101
|
* time: a bridge without it ignores `basePath`, exactly as it did before the option
|
|
98
102
|
* existed.
|
|
99
103
|
*/
|
|
100
|
-
export type PlayRouterBridgeConstructor<TRouter> = new (router: TRouter, actor:
|
|
104
|
+
export type PlayRouterBridgeConstructor<TRouter, TActor extends RoutableActor = RoutableActor> = new (router: TRouter, actor: TActor, routeMap: RouteMap, options?: BasePathOptions) => RouterBridge;
|
|
101
105
|
/**
|
|
102
106
|
* Tells you whether a bridge can move its mount.
|
|
103
107
|
*
|
|
@@ -118,7 +122,7 @@ export declare function isMountableBridge(bridge: RouterBridge | null | undefine
|
|
|
118
122
|
*/
|
|
119
123
|
export declare function mountKey(basePath?: BasePathOptions["basePath"], basePathParams?: BasePathOptions["basePathParams"]): string;
|
|
120
124
|
/** What {@link openProviderBridge} needs to build and connect a bridge. */
|
|
121
|
-
export interface OpenProviderBridgeArgs<TRouter, TActor extends
|
|
125
|
+
export interface OpenProviderBridgeArgs<TRouter, TActor extends RoutableActor> extends BasePathOptions {
|
|
122
126
|
router: TRouter;
|
|
123
127
|
actor: TActor;
|
|
124
128
|
routeMap: RouteMap;
|
|
@@ -133,7 +137,7 @@ export interface OpenProviderBridgeArgs<TRouter, TActor extends PlayActor> exten
|
|
|
133
137
|
*
|
|
134
138
|
* @returns The bridge, and a `close` that disconnects it one time.
|
|
135
139
|
*/
|
|
136
|
-
export declare function openProviderBridge<TRouter, TActor extends
|
|
140
|
+
export declare function openProviderBridge<TRouter, TActor extends RoutableActor>(BridgeCtor: PlayRouterBridgeConstructor<TRouter, TActor>, { router, actor, routeMap, basePath, basePathParams }: OpenProviderBridgeArgs<TRouter, TActor>): {
|
|
137
141
|
bridge: RouterBridge;
|
|
138
142
|
close: () => void;
|
|
139
143
|
};
|