@xmachines/play-xstate 1.0.0-beta.2 → 1.0.0-beta.21
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 +263 -107
- package/dist/define-player.d.ts +6 -56
- package/dist/define-player.d.ts.map +1 -1
- package/dist/define-player.js +8 -60
- package/dist/define-player.js.map +1 -1
- package/dist/define-player.typecheck.d.ts +2 -0
- package/dist/define-player.typecheck.d.ts.map +1 -0
- package/dist/define-player.typecheck.js +48 -0
- package/dist/define-player.typecheck.js.map +1 -0
- package/dist/errors.d.ts +66 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/guards/compose.d.ts +14 -3
- package/dist/guards/compose.d.ts.map +1 -1
- package/dist/guards/compose.js +26 -0
- package/dist/guards/compose.js.map +1 -1
- package/dist/guards/helpers.d.ts +13 -17
- package/dist/guards/helpers.d.ts.map +1 -1
- package/dist/guards/helpers.js +20 -25
- package/dist/guards/helpers.js.map +1 -1
- package/dist/guards/index.d.ts +2 -1
- package/dist/guards/index.d.ts.map +1 -1
- package/dist/guards/index.js +1 -1
- package/dist/guards/index.js.map +1 -1
- package/dist/guards/types.d.ts +3 -2
- package/dist/guards/types.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/player-actor.d.ts +70 -22
- package/dist/player-actor.d.ts.map +1 -1
- package/dist/player-actor.js +290 -88
- package/dist/player-actor.js.map +1 -1
- package/dist/player-actor.typecheck.d.ts +2 -0
- package/dist/player-actor.typecheck.d.ts.map +1 -0
- package/dist/player-actor.typecheck.js +27 -0
- package/dist/player-actor.typecheck.js.map +1 -0
- package/dist/routing/build-url.d.ts +22 -16
- package/dist/routing/build-url.d.ts.map +1 -1
- package/dist/routing/build-url.js +27 -20
- package/dist/routing/build-url.js.map +1 -1
- package/dist/routing/derive-route.d.ts +2 -2
- package/dist/routing/derive-route.d.ts.map +1 -1
- package/dist/routing/derive-route.js +3 -3
- package/dist/routing/derive-route.js.map +1 -1
- package/dist/routing/format-play-route-transitions.d.ts +41 -4
- package/dist/routing/format-play-route-transitions.d.ts.map +1 -1
- package/dist/routing/format-play-route-transitions.js +22 -19
- package/dist/routing/format-play-route-transitions.js.map +1 -1
- package/dist/routing/index.d.ts +2 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/types.d.ts +8 -13
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/signals/index.d.ts +0 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +0 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/state-signal.d.ts +1 -1
- package/dist/signals/state-signal.d.ts.map +1 -1
- package/dist/types.d.ts +20 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +26 -19
- package/dist/catalog/index.d.ts +0 -12
- package/dist/catalog/index.d.ts.map +0 -1
- package/dist/catalog/index.js +0 -11
- package/dist/catalog/index.js.map +0 -1
- package/dist/catalog/types.d.ts +0 -36
- package/dist/catalog/types.d.ts.map +0 -1
- package/dist/catalog/types.js +0 -2
- package/dist/catalog/types.js.map +0 -1
- package/dist/catalog/validate-binding.d.ts +0 -21
- package/dist/catalog/validate-binding.d.ts.map +0 -1
- package/dist/catalog/validate-binding.js +0 -30
- package/dist/catalog/validate-binding.js.map +0 -1
- package/dist/catalog/validate-props.d.ts +0 -41
- package/dist/catalog/validate-props.d.ts.map +0 -1
- package/dist/catalog/validate-props.js +0 -95
- package/dist/catalog/validate-props.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @xmachines/play-xstate - XState v5 adapter for Play Architecture
|
|
3
3
|
*
|
|
4
4
|
* Provides definePlayer() API for binding XState state machines to the
|
|
5
|
-
* actor base with
|
|
5
|
+
* actor base with signal lifecycle and DevTools integration.
|
|
6
6
|
*
|
|
7
|
-
* Per
|
|
7
|
+
* Per the Play RFC, this package implements the Logic Layer adapter that
|
|
8
8
|
* transforms declarative machine definitions into live actors with signal-driven
|
|
9
9
|
* reactivity.
|
|
10
10
|
*
|
|
@@ -12,11 +12,10 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export { definePlayer } from "./define-player.js";
|
|
14
14
|
export { PlayerActor } from "./player-actor.js";
|
|
15
|
-
export type { PlayerConfig, PlayerOptions, PlayerFactory } from "./types.js";
|
|
16
|
-
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches,
|
|
17
|
-
export type { Guard, GuardArray } from "./guards/
|
|
15
|
+
export type { PlayerConfig, PlayerOptions, PlayerFactory, PlayerFactoryResumeOptions, } from "./types.js";
|
|
16
|
+
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches, contextFieldMatches, } from "./guards/index.js";
|
|
17
|
+
export type { Guard, GuardArray, ComposedGuard } from "./guards/index.js";
|
|
18
18
|
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions, } from "./routing/index.js";
|
|
19
|
-
export type {
|
|
20
|
-
export {
|
|
21
|
-
export type { Catalog, CatalogEntry, ViewMetadata } from "./catalog/types.js";
|
|
19
|
+
export type { RouteMachineConfig, RouteStateNode } from "./routing/index.js";
|
|
20
|
+
export type { RouteContext } from "./routing/types.js";
|
|
22
21
|
//# 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":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,0BAA0B,GAC1B,MAAM,YAAY,CAAC;AAGpB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* @xmachines/play-xstate - XState v5 adapter for Play Architecture
|
|
3
3
|
*
|
|
4
4
|
* Provides definePlayer() API for binding XState state machines to the
|
|
5
|
-
* actor base with
|
|
5
|
+
* actor base with signal lifecycle and DevTools integration.
|
|
6
6
|
*
|
|
7
|
-
* Per
|
|
7
|
+
* Per the Play RFC, this package implements the Logic Layer adapter that
|
|
8
8
|
* transforms declarative machine definitions into live actors with signal-driven
|
|
9
9
|
* reactivity.
|
|
10
10
|
*
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
export { definePlayer } from "./define-player.js";
|
|
14
14
|
export { PlayerActor } from "./player-actor.js";
|
|
15
15
|
// Guard utilities
|
|
16
|
-
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches,
|
|
16
|
+
export { composeGuards, composeGuardsOr, negateGuard, hasContext, eventMatches, contextFieldMatches, } from "./guards/index.js";
|
|
17
17
|
// Routing utilities
|
|
18
18
|
export { deriveRoute, isAbsoluteRoute, buildRouteUrl, formatPlayRouteTransitions, } from "./routing/index.js";
|
|
19
|
-
// Catalog utilities
|
|
20
|
-
export { validateComponentBinding, validateViewProps, mergeViewProps } from "./catalog/index.js";
|
|
21
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhD,kBAAkB;AAClB,OAAO,EACN,aAAa,EACb,eAAe,EACf,WAAW,EACX,UAAU,EACV,YAAY,EACZ,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAG3B,oBAAoB;AACpB,OAAO,EACN,WAAW,EACX,eAAe,EACf,aAAa,EACb,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC"}
|
package/dist/player-actor.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AnyStateMachine, type AnyActorLogic } from "xstate";
|
|
2
|
-
import { AbstractActor, type Routable, type Viewable } from "@xmachines/play-actor";
|
|
1
|
+
import { type AnyStateMachine, type Actor, type AnyActorLogic, type AnyMachineSnapshot, type InputFrom, type SnapshotFrom, type EventFromLogic } from "xstate";
|
|
2
|
+
import { AbstractActor, type Routable, type Viewable, type ViewMetadata } from "@xmachines/play-actor";
|
|
3
3
|
import { Signal } from "@xmachines/play-signals";
|
|
4
|
-
import type { PlayEvent } from "@xmachines/play";
|
|
5
4
|
import type { PlayerOptions } from "./types.js";
|
|
6
5
|
/**
|
|
7
6
|
* Concrete XState actor implementing Play Architecture signal protocol
|
|
@@ -63,7 +62,7 @@ import type { PlayerOptions } from "./types.js";
|
|
|
63
62
|
* // Watcher notification scheduled via microtask
|
|
64
63
|
* ```
|
|
65
64
|
*
|
|
66
|
-
* @see
|
|
65
|
+
* @see [Play RFC](../../docs/rfc/play.md)
|
|
67
66
|
* @see {@link definePlayer} for factory creation
|
|
68
67
|
* @see {@link @xmachines/play-actor!AbstractActor} for signal protocol
|
|
69
68
|
* @see {@link @xmachines/play-actor!Routable} for routing capability
|
|
@@ -78,20 +77,66 @@ import type { PlayerOptions } from "./types.js";
|
|
|
78
77
|
* `Signal.Computed`) to ensure proper watcher propagation in PlayRenderer. Views are
|
|
79
78
|
* cached and updated at state entry, not computed on every read.
|
|
80
79
|
*/
|
|
81
|
-
export declare class PlayerActor<TMachine extends AnyStateMachine> extends AbstractActor<AnyActorLogic
|
|
80
|
+
export declare class PlayerActor<TMachine extends AnyStateMachine> extends AbstractActor<AnyActorLogic, EventFromLogic<TMachine>> implements Routable, Viewable {
|
|
82
81
|
private _xstateActor;
|
|
83
82
|
private _stateManager;
|
|
84
83
|
private _options;
|
|
85
|
-
private _catalog;
|
|
86
84
|
private _viewSignal;
|
|
87
|
-
state: Signal.State<
|
|
85
|
+
state: Signal.State<AnyMachineSnapshot>;
|
|
86
|
+
/**
|
|
87
|
+
* A TC39 `Signal.Computed` that derives the current URL path from the active
|
|
88
|
+
* machine state's `meta.route` template and the actor's context.
|
|
89
|
+
*
|
|
90
|
+
* Returns `null` when the current state has no `meta.route`, or when the route
|
|
91
|
+
* template cannot be fully resolved (e.g. a required parameter is absent from
|
|
92
|
+
* context).
|
|
93
|
+
*
|
|
94
|
+
* @throws {MissingRouteParamError} When a required `:param` placeholder in the
|
|
95
|
+
* route template has no matching value in the actor's context. Import the class
|
|
96
|
+
* from `@xmachines/play-xstate/errors`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Returns "/profile/alice" when context.userId === "alice"
|
|
101
|
+
* const route = actor.currentRoute.get();
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
88
104
|
currentRoute: Signal.Computed<string | null>;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
/**
|
|
106
|
+
* The route derived from the machine's initial state — fixed at construction,
|
|
107
|
+
* never changes even when the actor is restored from a snapshot.
|
|
108
|
+
*
|
|
109
|
+
* Router bridges compare this against the browser URL to distinguish a deep-link
|
|
110
|
+
* (non-initial URL → router wins) from a restore (initial URL + actor at a
|
|
111
|
+
* different restored route → actor wins).
|
|
112
|
+
*/
|
|
113
|
+
readonly initialRoute: string | null;
|
|
114
|
+
/**
|
|
115
|
+
* Reactive signal containing the current view spec derived from the active state's
|
|
116
|
+
* `meta.view` metadata.
|
|
117
|
+
*
|
|
118
|
+
* Always emits a **fresh object reference** on every state transition (including
|
|
119
|
+
* self-transitions with `reenter: true`) so TC39 Signal equality checks reliably
|
|
120
|
+
* detect changes.
|
|
121
|
+
*
|
|
122
|
+
* The emitted `ViewMetadata` has its spec element `props` enriched with
|
|
123
|
+
* `context.routeParams` before emission — URL path parameters (e.g. `:section?`)
|
|
124
|
+
* flow into component props automatically. See `mergeRouteParamsIntoProps` for the
|
|
125
|
+
* merge priority rules.
|
|
126
|
+
*
|
|
127
|
+
* Returns `null` when the current state has no `meta.view` metadata.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const view = actor.currentView.get();
|
|
132
|
+
* if (view) {
|
|
133
|
+
* console.log(view.component); // e.g. "Dashboard"
|
|
134
|
+
* console.log(view.spec); // @json-render/core Spec object
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
currentView: Signal.State<ViewMetadata | null>;
|
|
139
|
+
constructor(machine: TMachine, options: PlayerOptions<TMachine>, input?: InputFrom<TMachine>, snapshot?: SnapshotFrom<TMachine>);
|
|
95
140
|
/**
|
|
96
141
|
* Start the actor
|
|
97
142
|
*
|
|
@@ -103,27 +148,30 @@ export declare class PlayerActor<TMachine extends AnyStateMachine> extends Abstr
|
|
|
103
148
|
*/
|
|
104
149
|
stop(): this;
|
|
105
150
|
/**
|
|
106
|
-
* Send event to actor
|
|
151
|
+
* Send an event to the underlying XState actor.
|
|
152
|
+
*
|
|
153
|
+
* The actor's state machine guards decide whether the event causes a transition.
|
|
154
|
+
* Pass any event from the machine's event union — domain events, routing events, etc.
|
|
107
155
|
*
|
|
108
|
-
*
|
|
109
|
-
* guards determine whether each event is valid from the current state.
|
|
156
|
+
* @param event - An event from the machine's `EventFromLogic<TMachine>` union.
|
|
110
157
|
*
|
|
111
|
-
* @
|
|
158
|
+
* @throws {InvalidEventError} When `event` is not a plain object (`null`, `undefined`,
|
|
159
|
+
* a string, number, etc.). Import the class from `@xmachines/play-xstate/errors`.
|
|
112
160
|
*
|
|
113
161
|
* @example
|
|
114
162
|
* ```typescript
|
|
115
|
-
* // Domain event
|
|
116
|
-
* actor.send({ type:
|
|
163
|
+
* // Domain event (typed to machine's event union)
|
|
164
|
+
* actor.send({ type: "auth.login", userId: "123" });
|
|
117
165
|
*
|
|
118
166
|
* // Routing event
|
|
119
|
-
* actor.send({ type:
|
|
167
|
+
* actor.send({ type: "play.route", to: "#home" });
|
|
120
168
|
* ```
|
|
121
169
|
*/
|
|
122
|
-
send(event:
|
|
170
|
+
send(event: EventFromLogic<TMachine>): void;
|
|
123
171
|
/**
|
|
124
172
|
* Get current snapshot
|
|
125
173
|
*/
|
|
126
|
-
getSnapshot():
|
|
174
|
+
getSnapshot(): ReturnType<Actor<TMachine>["getSnapshot"]>;
|
|
127
175
|
/**
|
|
128
176
|
* Validate view at state entry and cache result
|
|
129
177
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player-actor.d.ts","sourceRoot":"","sources":["../src/player-act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