@xmachines/play-solid 1.0.0-beta.3 → 1.0.0-beta.30

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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +229 -66
  3. package/dist/PlayRenderer.js +54 -24
  4. package/dist/PlayRenderer.js.map +1 -1
  5. package/dist/index.js +4 -2
  6. package/dist/node_modules/@json-render/core/dist/chunk-AFLK3Q4T.js +111 -0
  7. package/dist/node_modules/@json-render/core/dist/chunk-AFLK3Q4T.js.map +1 -0
  8. package/dist/node_modules/@json-render/core/dist/index.js +863 -0
  9. package/dist/node_modules/@json-render/core/dist/index.js.map +1 -0
  10. package/dist/node_modules/@json-render/core/dist/store-utils.js +1 -0
  11. package/dist/node_modules/@json-render/solid/dist/chunk-XTSB6FIM.js +57 -0
  12. package/dist/node_modules/@json-render/solid/dist/chunk-XTSB6FIM.js.map +1 -0
  13. package/dist/node_modules/@json-render/solid/dist/index.js +617 -0
  14. package/dist/node_modules/@json-render/solid/dist/index.js.map +1 -0
  15. package/dist/node_modules/@json-render/xstate/dist/index.js +20 -0
  16. package/dist/node_modules/@json-render/xstate/dist/index.js.map +1 -0
  17. package/dist/node_modules/@xstate/store/dist/store-69e7e2d5.esm.js +227 -0
  18. package/dist/node_modules/@xstate/store/dist/store-69e7e2d5.esm.js.map +1 -0
  19. package/dist/node_modules/zod/v4/classic/errors.js +25 -0
  20. package/dist/node_modules/zod/v4/classic/errors.js.map +1 -0
  21. package/dist/node_modules/zod/v4/classic/iso.js +33 -0
  22. package/dist/node_modules/zod/v4/classic/iso.js.map +1 -0
  23. package/dist/node_modules/zod/v4/classic/parse.js +8 -0
  24. package/dist/node_modules/zod/v4/classic/parse.js.map +1 -0
  25. package/dist/node_modules/zod/v4/classic/schemas.js +362 -0
  26. package/dist/node_modules/zod/v4/classic/schemas.js.map +1 -0
  27. package/dist/node_modules/zod/v4/core/api.js +530 -0
  28. package/dist/node_modules/zod/v4/core/api.js.map +1 -0
  29. package/dist/node_modules/zod/v4/core/checks.js +285 -0
  30. package/dist/node_modules/zod/v4/core/checks.js.map +1 -0
  31. package/dist/node_modules/zod/v4/core/core.js +46 -0
  32. package/dist/node_modules/zod/v4/core/core.js.map +1 -0
  33. package/dist/node_modules/zod/v4/core/doc.js +25 -0
  34. package/dist/node_modules/zod/v4/core/doc.js.map +1 -0
  35. package/dist/node_modules/zod/v4/core/errors.js +43 -0
  36. package/dist/node_modules/zod/v4/core/errors.js.map +1 -0
  37. package/dist/node_modules/zod/v4/core/json-schema-processors.js +183 -0
  38. package/dist/node_modules/zod/v4/core/json-schema-processors.js.map +1 -0
  39. package/dist/node_modules/zod/v4/core/parse.js +70 -0
  40. package/dist/node_modules/zod/v4/core/parse.js.map +1 -0
  41. package/dist/node_modules/zod/v4/core/regexes.js +27 -0
  42. package/dist/node_modules/zod/v4/core/regexes.js.map +1 -0
  43. package/dist/node_modules/zod/v4/core/registries.js +42 -0
  44. package/dist/node_modules/zod/v4/core/registries.js.map +1 -0
  45. package/dist/node_modules/zod/v4/core/schemas.js +823 -0
  46. package/dist/node_modules/zod/v4/core/schemas.js.map +1 -0
  47. package/dist/node_modules/zod/v4/core/to-json-schema.js +224 -0
  48. package/dist/node_modules/zod/v4/core/to-json-schema.js.map +1 -0
  49. package/dist/node_modules/zod/v4/core/util.js +268 -0
  50. package/dist/node_modules/zod/v4/core/util.js.map +1 -0
  51. package/dist/node_modules/zod/v4/core/versions.js +10 -0
  52. package/dist/node_modules/zod/v4/core/versions.js.map +1 -0
  53. package/dist/useActor.js +12 -0
  54. package/dist/useActor.js.map +1 -0
  55. package/package.json +28 -12
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mikael Karon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,110 +1,273 @@
1
1
  # @xmachines/play-solid
2
2
 
3
- SolidJS renderer for XMachines Play architecture. Enables catalog-driven view rendering with actor-owned business state.
3
+ **Solid renderer for XMachines Play Architecture**
4
+
5
+ Bridges TC39 Signal-driven actors to Solid's fine-grained reactivity. Business logic stays in the actor; Solid is purely a rendering target.
6
+
7
+ ## Overview
8
+
9
+ `@xmachines/play-solid` provides `PlayRenderer`, a Solid component that:
10
+
11
+ - Subscribes to `actor.currentView` (TC39 Signal) and re-renders on every state transition
12
+ - Renders the current view's JSON spec via `@json-render/solid`
13
+ - Routes action names from spec elements to `actor.send()` via the `actions` prop
14
+ - Manages per-view UI state in an `@xstate/store` atom (automatic or caller-supplied)
15
+
16
+ Per [Play RFC](../docs/rfc/play.md):
17
+
18
+ - **Actor Authority (INV-01):** Guards in the machine decide all state transitions
19
+ - **Passive Infrastructure (INV-04):** Solid observes signals and dispatches events — never decides
20
+ - **Signal-Only Reactivity (INV-05):** `actor.currentView` signal is the sole render trigger
4
21
 
5
22
  ## Installation
6
23
 
7
24
  ```bash
8
- npm install @xmachines/play-solid solid-js
25
+ npm install @xmachines/play-solid
26
+ npm install @json-render/solid @json-render/core # peer deps
27
+ npm install @json-render/xstate @xstate/store # store integration
9
28
  ```
10
29
 
30
+ In this monorepo, the root install applies a `patch-package` patch to `@json-render/solid`
31
+ so `defineRegistry(..., { onRenderError })` can intercept inner element-boundary errors
32
+ without muting console output.
33
+
11
34
  ## Current Exports
12
35
 
13
- - `PlayRenderer`
36
+ - `PlayRenderer` — main renderer component
37
+ - `useActor` — hook for accessing the actor inside a `PlayRenderer` tree
38
+ - `defineRegistry` — re-exported from `@json-render/solid`
39
+ - `useStateBinding` — re-exported from `@json-render/solid`
40
+ - `ComponentFn` (type) — re-exported from `@json-render/solid`
41
+ - `ComponentContext` (type) — re-exported from `@json-render/solid`
14
42
  - `PlayRendererProps` (type)
43
+ - `PlayActor` (type)
15
44
 
16
- ## Usage
45
+ ## Quick Start
17
46
 
18
- ```typescript
19
- import { PlayRenderer } from '@xmachines/play-solid';
20
- import { definePlayer } from '@xmachines/play-xstate';
21
- import { defineCatalog } from '@xmachines/play-catalog';
47
+ ```tsx
48
+ import { definePlayer, formatPlayRouteTransitions } from "@xmachines/play-xstate";
49
+ import { PlayRenderer } from "@xmachines/play-solid";
50
+ import { defineCatalog } from "@json-render/core";
51
+ import { defineRegistry } from "@xmachines/play-solid";
52
+ import type { ComponentFn } from "@xmachines/play-solid";
53
+ import { setup, assign } from "xstate";
54
+ import { z } from "zod";
22
55
 
23
- // Define catalog
56
+ // 1. Define catalog — the contract between machine spec and UI components
24
57
  const catalog = defineCatalog({
25
- Home: { component: 'Home', props: {} },
26
- Login: { component: 'Login', props: { error: { type: 'string' } } }
58
+ elements: {
59
+ Login: { props: z.object({ title: z.string() }), description: "Login form" },
60
+ Dashboard: { props: z.object({ username: z.string() }), description: "Dashboard" },
61
+ },
27
62
  });
28
63
 
29
- // Create player
30
- const createPlayer = definePlayer({
31
- machine: authMachine,
32
- catalog
64
+ // 2. Implement components using ComponentFn — typed against catalog entries
65
+ const Login: ComponentFn<typeof catalog, "Login"> = ({ props, emit }) => (
66
+ <div class="view">
67
+ <h2>{props.title}</h2>
68
+ <form
69
+ onSubmit={(e) => {
70
+ e.preventDefault();
71
+ emit("submit");
72
+ }}
73
+ >
74
+ <button type="submit">Log In</button>
75
+ </form>
76
+ </div>
77
+ );
78
+
79
+ const Dashboard: ComponentFn<typeof catalog, "Dashboard"> = ({ props }) => (
80
+ <div class="view">Welcome, {props.username}!</div>
81
+ );
82
+
83
+ // 3. Build registry
84
+ const { registry } = defineRegistry(catalog, {
85
+ components: { Login, Dashboard },
86
+ actions: { login: async () => {}, logout: async () => {} },
33
87
  });
34
88
 
89
+ // 4. Define machine with view metadata
90
+ const machine = setup({
91
+ types: {
92
+ context: {} as {
93
+ isAuthenticated: boolean;
94
+ username: string | null;
95
+ params: Record<string, string>;
96
+ query: Record<string, string>;
97
+ },
98
+ events: {} as
99
+ | { type: "auth.login"; username: string }
100
+ | { type: "auth.logout" }
101
+ | { type: "play.route"; to: string; params?: Record<string, string> },
102
+ },
103
+ }).createMachine(
104
+ formatPlayRouteTransitions({
105
+ id: "app",
106
+ initial: "login",
107
+ context: { isAuthenticated: false, username: null, params: {}, query: {} },
108
+ states: {
109
+ login: {
110
+ id: "login",
111
+ meta: {
112
+ route: "/login",
113
+ view: {
114
+ component: "Login",
115
+ spec: {
116
+ root: "root",
117
+ elements: {
118
+ root: { type: "Login", props: { title: "Sign In" }, children: [] },
119
+ },
120
+ },
121
+ },
122
+ },
123
+ },
124
+ dashboard: {
125
+ id: "dashboard",
126
+ meta: {
127
+ route: "/dashboard",
128
+ view: {
129
+ component: "Dashboard",
130
+ spec: {
131
+ root: "root",
132
+ elements: {
133
+ root: { type: "Dashboard", props: { username: "" }, children: [] },
134
+ },
135
+ },
136
+ },
137
+ },
138
+ },
139
+ },
140
+ on: {
141
+ "auth.login": {
142
+ target: ".dashboard",
143
+ guard: ({ context }) => !context.isAuthenticated,
144
+ actions: assign({ isAuthenticated: true, username: ({ event }) => event.username }),
145
+ },
146
+ "auth.logout": {
147
+ target: ".login",
148
+ guard: ({ context }) => context.isAuthenticated,
149
+ actions: assign({ isAuthenticated: false, username: null }),
150
+ },
151
+ },
152
+ }),
153
+ );
154
+
155
+ // 5. Create actor and render
156
+ const createPlayer = definePlayer({ machine });
35
157
  const actor = createPlayer();
36
158
  actor.start();
37
159
 
38
- // Define components
39
- const components = {
40
- Home: (props) => <div>Home</div>,
41
- Login: (props) => (
42
- <form onSubmit={(e) => {
43
- e.preventDefault();
44
- props.send({ type: 'auth.login', payload: {...} });
45
- }}>
46
- {props.error && <p>{props.error}</p>}
47
- <input type="text" name="username" />
48
- <button type="submit">Login</button>
49
- </form>
50
- )
51
- };
52
-
53
- // Render
54
- <PlayRenderer actor={actor} components={components} />
160
+ function App() {
161
+ return (
162
+ <PlayRenderer
163
+ actor={actor}
164
+ registry={registry}
165
+ actions={{ login: "auth.login", logout: "auth.logout" }}
166
+ />
167
+ );
168
+ }
169
+ ```
170
+
171
+ ## API Reference
172
+
173
+ ### `PlayRenderer`
174
+
175
+ Main component. Subscribes to `actor.currentView` and renders the spec.
176
+
177
+ ```tsx
178
+ <PlayRenderer
179
+ actor={actor}
180
+ registry={registry}
181
+ actions={{ login: "auth.login" }}
182
+ store={myStore}
183
+ fallback={<p>Loading…</p>}
184
+ />
55
185
  ```
56
186
 
57
- ## API
187
+ **`actor`** — A `PlayerActor` (or any `AbstractActor & Viewable`). Provides the `currentView` signal.
58
188
 
59
- ### PlayRenderer
189
+ **`registry`** — Built with `defineRegistry(catalog, { components, actions })` from `@xmachines/play-solid`.
60
190
 
61
- Component that observes `actor.currentView` signal and renders the appropriate component from the catalog.
191
+ `defineRegistry` also accepts `onRenderError(error, elementType)`, which receives errors
192
+ caught by `@json-render/solid`'s inner element boundary before the default logger is used.
62
193
 
63
- **Props:**
194
+ **`actions`** — Maps json-render action names (from spec `on` bindings) to XState event type strings. Type-checked against `EventFromLogic<TLogic>["type"]` when `TLogic` is specified:
64
195
 
65
- - `actor: AbstractActor & Viewable` - Actor instance with currentView signal
66
- - `components: Record<string, Component<any>>` - Map of component names to SolidJS components
67
- - `fallback?: JSX.Element` - Optional fallback to show when currentView is null
196
+ ```tsx
197
+ <PlayRenderer<typeof machine>
198
+ actor={actor}
199
+ registry={registry}
200
+ actions={{ login: "auth.login", logout: "auth.logout" }}
201
+ />
202
+ ```
203
+
204
+ **`store`** (optional) — Controls per-view UI state (`$state` bindings, form values):
205
+
206
+ - **Omitted (uncontrolled, default):** A fresh `@xstate/store` atom is created per view transition, seeded from `view.spec.state`.
207
+ - **Provided (controlled):** The caller owns the store; `spec.state` is ignored.
208
+
209
+ ```tsx
210
+ import { createAtom } from "@xstate/store";
211
+ import { xstateStoreStateStore } from "@json-render/xstate";
212
+ import type { StateStore } from "@json-render/core";
213
+
214
+ const store: StateStore = xstateStoreStateStore({ atom: createAtom({ username: "" }) });
215
+
216
+ <PlayRenderer actor={actor} registry={registry} store={store} actions={{ login: "auth.login" }} />;
217
+ ```
218
+
219
+ **Inner render errors** — You can intercept catalog component render failures without
220
+ overriding the outer Solid error boundary:
68
221
 
69
- **Features:**
222
+ ```tsx
223
+ const { registry } = defineRegistry(catalog, {
224
+ components: { Login, Dashboard },
225
+ actions: { login: async () => {}, logout: async () => {} },
226
+ onRenderError(error, elementType) {
227
+ reportExpectedRenderError(error, elementType);
228
+ },
229
+ });
230
+ ```
70
231
 
71
- - Automatically bridges TC39 Signals to SolidJS reactivity
72
- - Passes `send` function to components for event forwarding
73
- - Handles missing components gracefully with error logging
74
- - Uses one-shot watcher re-watch pattern for proper signal observation
232
+ **`fallback`** Shown when `actor.currentView.get()` is `null`.
75
233
 
76
- ## Canonical Watcher Lifecycle
234
+ ---
77
235
 
78
- Use the same watcher flow as React/Vue/router packages:
236
+ ### `useActor`
79
237
 
80
- 1. `notify`
81
- 2. `queueMicrotask`
82
- 3. `getPending()`
83
- 4. read actor signals and update framework-local render trigger
84
- 5. re-arm with `watch(...)` or `watch()`
238
+ Solid hook for accessing the actor from inside any component rendered by `PlayRenderer`. No prop drilling needed.
85
239
 
86
- Watcher notifications are one-shot, so re-arm is mandatory.
240
+ ```tsx
241
+ import { useActor } from "@xmachines/play-solid";
87
242
 
88
- ## Cleanup Contract
243
+ // Inside any component rendered inside PlayRenderer:
244
+ function LogoutButton() {
245
+ const actor = useActor();
246
+ return <button onClick={() => actor.send({ type: "auth.logout" })}>Log Out</button>;
247
+ }
248
+ ```
89
249
 
90
- Solid integrations must perform explicit teardown:
250
+ Throws `"useActor() must be called inside <PlayRenderer>"` if called outside the tree.
91
251
 
92
- - Use `onCleanup` for lifecycle teardown.
93
- - Call `unwatch(...)` on teardown, not only reference nulling.
94
- - Keep adapters/renderers passive; state validity remains actor-owned.
252
+ ---
95
253
 
96
- ## Architecture
254
+ ## Route Parameters in Props
97
255
 
98
- PlayRenderer follows the XMachines Play architecture:
256
+ When using `formatPlayRouteTransitions`, URL path parameters flow automatically into component props. Declare an `undefined` slot in the spec to opt in:
99
257
 
100
- - **Actor Authority**: Actor controls all state transitions via guards
101
- - **Passive Infrastructure**: Renderer observes signals, sends events
102
- - **Signal-Only Reactivity**: Business logic state lives in actor signals
258
+ ```ts
259
+ // spec: { section: undefined, user: "alice" }
260
+ // After play.route to /settings/profile context.params = { section: "profile" }
261
+ // Component receives: { section: "profile", user: "alice" }
262
+ ```
103
263
 
104
- The renderer bridges TC39 Signals (used by XMachines actors) to SolidJS's reactivity system using `Signal.subtle.Watcher` with a one-shot re-watch pattern.
264
+ Priority: **route param fills `undefined` slots; explicit non-`undefined` spec props always win.**
105
265
 
106
- Signals remain observation plumbing, not an alternate mutation channel.
266
+ ---
107
267
 
108
- ## License
268
+ ## Architecture Notes
109
269
 
110
- MIT
270
+ - SolidJS signals are only used to trigger re-renders — not for business logic
271
+ - `actor.currentView` (TC39 Signal) is bridged into a SolidJS `createSignal` inside `PlayRenderer`
272
+ - Per-view UI state lives in an `@xstate/store` atom, not in SolidJS reactive state
273
+ - `@json-render/solid` drives rendering; `PlayRenderer` is the signal bridge — import `defineRegistry`, `ComponentFn`, `ComponentContext`, and `useStateBinding` from `@xmachines/play-solid`
@@ -1,31 +1,61 @@
1
- import { Dynamic as e, createComponent as t, insert as n, memo as r, mergeProps as i, template as a } from "solid-js/web";
2
- import { createSignal as o, onMount as s } from "solid-js";
3
- import { Signal as c } from "@xmachines/play-signals";
1
+ import { ActionProvider as e, Renderer as t, StateProvider as n, VisibilityProvider as r } from "./node_modules/@json-render/solid/dist/index.js";
2
+ import { createAtom as i } from "./node_modules/@xstate/store/dist/store-69e7e2d5.esm.js";
3
+ import { xstateStoreStateStore as a } from "./node_modules/@json-render/xstate/dist/index.js";
4
+ import { ActorProvider as o } from "./useActor.js";
5
+ import { createComponent as s } from "solid-js/web";
6
+ import { ErrorBoundary as c, createSignal as l, onCleanup as u } from "solid-js";
7
+ import { watchSignal as d } from "@xmachines/play-signals";
4
8
  //#region src/PlayRenderer.tsx
5
- var l = /* @__PURE__ */ a("<div class=play-renderer-error>Component \"<!>\" not found in catalog. Available: "), u = (a) => {
6
- let [u, d] = o(a.actor.currentView.get());
7
- s(() => {
8
- let e = new c.subtle.Watcher(() => {
9
- queueMicrotask(() => {
10
- e.getPending(), d(a.actor.currentView.get()), e.watch(a.actor.currentView);
9
+ var f = (f) => {
10
+ let [p, m] = l(f.actor.currentView.get()), h = null, g = null, _ = d(f.actor.currentView, (e) => {
11
+ m(e);
12
+ });
13
+ return u(() => {
14
+ _();
15
+ }), s(o, {
16
+ get value() {
17
+ return f.actor;
18
+ },
19
+ get children() {
20
+ return s(c, {
21
+ fallback: (e) => (f.onError?.(e), f.fallback ?? null),
22
+ get children() {
23
+ return (() => {
24
+ let o = p();
25
+ if (!o) return f.fallback ?? null;
26
+ let c;
27
+ f.store ? c = f.store : ((h === null || g !== o) && (h = a({ atom: i(o.spec.state ?? {}) }), g = o), c = h);
28
+ let l = Object.fromEntries(Object.entries(f.actions ?? {}).map(([e, t]) => [e, async (e = {}) => f.actor.send({
29
+ type: t,
30
+ ...e
31
+ })]));
32
+ return s(n, {
33
+ store: c,
34
+ get children() {
35
+ return s(e, {
36
+ handlers: l,
37
+ get children() {
38
+ return s(r, { get children() {
39
+ return s(t, {
40
+ get spec() {
41
+ return o.spec;
42
+ },
43
+ get registry() {
44
+ return f.registry;
45
+ }
46
+ });
47
+ } });
48
+ }
49
+ });
50
+ }
51
+ });
52
+ })();
53
+ }
11
54
  });
12
- });
13
- e.watch(a.actor.currentView);
55
+ }
14
56
  });
15
- let f = a.actor.send.bind(a.actor);
16
- return [
17
- r(() => r(() => !u())() && (a.fallback || null)),
18
- r(() => r(() => !!(u() && !a.components))() && (console.error(`Components catalog is ${a.components === null ? "null" : "undefined"}. Cannot render component "${u().component}".`), a.fallback || null)),
19
- r(() => r(() => !!(u() && a.components && !a.components[u().component]))() && (console.error(`Component "${u().component}" not found in catalog. Available components: ${Object.keys(a.components).join(", ")}`), (() => {
20
- var e = l(), t = e.firstChild.nextSibling;
21
- return t.nextSibling, n(e, () => u().component, t), n(e, () => Object.keys(a.components).join(", "), null), e;
22
- })())),
23
- r(() => r(() => !!(u() && a.components && a.components[u().component]))() && t(e, i({ get component() {
24
- return a.components[u().component];
25
- } }, () => u().props, { send: f })))
26
- ];
27
57
  };
28
58
  //#endregion
29
- export { u as PlayRenderer };
59
+ export { f as PlayRenderer };
30
60
 
31
61
  //# sourceMappingURL=PlayRenderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlayRenderer.js","names":["createSignal","onMount","Component","Dynamic","Signal","PlayRendererProps","SolidView","PlayRenderer","props","view","setView","actor","currentView","get","watcher","subtle","Watcher","queueMicrotask","getPending","watch","sendBound","send","bind","_$memo","fallback","components","console","error","component","Object","keys","join","_el$","_tmpl$","_el$2","firstChild","_el$5","nextSibling","_el$3","_$insert","_$createComponent","_$mergeProps"],"sources":["../src/PlayRenderer.tsx"],"sourcesContent":["/**\n * PlayRenderer - Main SolidJS renderer component for XMachines Play architecture\n *\n * @packageDocumentation\n */\n\nimport { createSignal, onMount, type Component } from \"solid-js\";\nimport { Dynamic } from \"solid-js/web\";\nimport { Signal } from \"@xmachines/play-signals\";\nimport type { PlayRendererProps, SolidView } from \"./types.js\";\n\n/**\n * Main renderer component that subscribes to actor signals and renders UI\n *\n * Architecture (per XMachines Play patterns):\n * - Subscribes to actor.currentView signal via TC39 Signal.subtle.Watcher\n * - Dynamically renders catalog components based on view.component string\n * - Forwards user events to actor via actor.send()\n * - SolidJS signal only for triggering renders, NOT business logic\n *\n * Invariant: Actor Authority - Actor decides all state transitions via guards.\n * Invariant: Passive Infrastructure - Component observes signals and sends events.\n * Invariant: Signal-Only Reactivity - Business logic state lives in actor signals.\n *\n * @example\n * ```typescript\n * import { PlayRenderer } from \"@xmachines/play-solidjs\";\n * import { definePlayer } from \"@xmachines/play-xstate\";\n *\n * const actor = definePlayer({ machine, catalog })();\n * actor.start();\n *\n * const components = {\n * Dashboard: (props) => <div>User: {props.userId}</div>,\n * LoginForm: (props) => (\n * <form onSubmit={(e) => {\n * e.preventDefault();\n * props.send({ type: \"auth.login\", payload: {...} });\n * }}>...</form>\n * )\n * };\n *\n * <PlayRenderer actor={actor} components={components} />\n * ```\n *\n * @param props - Component props\n * @returns SolidJS element rendering current view from actor\n *\n * @remarks\n * **Component lookup:** Dynamically looks up component from `components` map\n * using `view.component` string from actor.currentView signal.\n *\n * **Event forwarding:** Injects `send` function as prop to components. Components\n * call `send(event)` to forward intents to actor. Actor guards decide validity.\n *\n * **Error handling:** If component not found in catalog, logs error and shows\n * fallback. This indicates missing component registration, not runtime error.\n *\n * **Signal bridge:** Uses one-shot re-watch pattern. TC39 Signal watchers stop\n * watching after notification, so watcher.watch() must be called in microtask\n * after getPending() to re-arm for next notification.\n *\n * **CRITICAL:** Never call actor.send() during render - only in event handlers.\n * Calling send during render causes infinite render loops.\n */\nexport const PlayRenderer: Component<PlayRendererProps> = (props) => {\n\t// Create SolidJS signal for view\n\t// Signal is NOT business logic state - it's just SolidJS's render trigger\n\tconst [view, setView] = createSignal<SolidView>(props.actor.currentView.get() as SolidView);\n\n\t// Bridge TC39 Signal to SolidJS signal\n\t// Uses one-shot re-watch pattern (must re-watch after each notification)\n\tonMount(() => {\n\t\tconst watcher = new Signal.subtle.Watcher(() => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\t// Acknowledge the notification\n\t\t\t\twatcher.getPending();\n\n\t\t\t\t// Update SolidJS signal (triggers SolidJS reactivity)\n\t\t\t\tsetView(props.actor.currentView.get() as SolidView);\n\n\t\t\t\t// Re-watch for next notification (one-shot pattern)\n\t\t\t\t// TC39 Signal watchers stop watching after notification\n\t\t\t\twatcher.watch(props.actor.currentView);\n\t\t\t});\n\t\t});\n\n\t\t// Watch actor.currentView for changes\n\t\twatcher.watch(props.actor.currentView);\n\n\t\t// Note: TC39 Signal watchers don't have explicit disposal\n\t\t// The watcher will be garbage collected when the component unmounts\n\t});\n\n\t// Bind send function (ensures correct 'this' context)\n\tconst sendBound = props.actor.send.bind(props.actor);\n\n\treturn (\n\t\t<>\n\t\t\t{/* No view - show fallback */}\n\t\t\t{!view() && (props.fallback || null)}\n\n\t\t\t{/* Handle null/undefined components catalog gracefully */}\n\t\t\t{view() &&\n\t\t\t\t!props.components &&\n\t\t\t\t(() => {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Components catalog is ${props.components === null ? \"null\" : \"undefined\"}. ` +\n\t\t\t\t\t\t\t`Cannot render component \"${view()!.component}\".`,\n\t\t\t\t\t);\n\t\t\t\t\treturn props.fallback || null;\n\t\t\t\t})()}\n\n\t\t\t{/* View exists but component not found */}\n\t\t\t{view() &&\n\t\t\t\tprops.components &&\n\t\t\t\t!props.components[view()!.component] &&\n\t\t\t\t(() => {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`Component \"${view()!.component}\" not found in catalog. ` +\n\t\t\t\t\t\t\t`Available components: ${Object.keys(props.components).join(\", \")}`,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div class=\"play-renderer-error\">\n\t\t\t\t\t\t\tComponent \"{view()!.component}\" not found in catalog. Available:{\" \"}\n\t\t\t\t\t\t\t{Object.keys(props.components).join(\", \")}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})()}\n\n\t\t\t{/* Render matched component dynamically */}\n\t\t\t{view() && props.components && props.components[view()!.component] && (\n\t\t\t\t<Dynamic\n\t\t\t\t\tcomponent={props.components[view()!.component]}\n\t\t\t\t\t{...view()!.props}\n\t\t\t\t\tsend={sendBound}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</>\n\t);\n};\n"],"mappings":";;;;iHAiEaO,KAA8CC,MAAU;CAGpE,IAAM,CAACC,GAAMC,KAAWV,EAAwBQ,EAAMG,MAAMC,YAAYC,KAAK,CAAc;AAI3FZ,SAAc;EACb,IAAMa,IAAU,IAAIV,EAAOW,OAAOC,cAAc;AAC/CC,wBAAqB;AASpBH,IAPAA,EAAQI,YAAY,EAGpBR,EAAQF,EAAMG,MAAMC,YAAYC,KAAK,CAAc,EAInDC,EAAQK,MAAMX,EAAMG,MAAMC,YAAY;KACrC;IACD;AAGFE,IAAQK,MAAMX,EAAMG,MAAMC,YAAY;GAIrC;CAGF,IAAMQ,IAAYZ,EAAMG,MAAMU,KAAKC,KAAKd,EAAMG,MAAM;AAEpD,QAAA;EAAAY,QAGGA,QAAA,CAACd,GAAM,CAAA,EAAA,KAAKD,EAAMgB,YAAY,MAAK;EAAAD,QAGnCA,QAAA,CAAA,EAAAd,GAAM,IACN,CAACD,EAAMiB,YAAU,EAAA,KAEhBC,QAAQC,MACP,yBAAyBnB,EAAMiB,eAAe,OAAO,SAAS,YAAW,6BAC5ChB,GAAM,CAAEmB,UAAS,IAC9C,EACMpB,EAAMgB,YAAY,MACtB;EAAAD,QAGJA,QAAA,CAAA,EAAAd,GAAM,IACND,EAAMiB,cACN,CAACjB,EAAMiB,WAAWhB,GAAM,CAAEmB,YAAU,EAAA,KAEnCF,QAAQC,MACP,cAAclB,GAAM,CAAEmB,UAAS,gDACLC,OAAOC,KAAKtB,EAAMiB,WAAW,CAACM,KAAK,KAAK,GAClE,SACD;GAAA,IAAAC,IAAAC,GAAA,EAAAG,IAAAJ,EAAAG,WAAAE;AAG2C,UAH3CD,EAAAC,aAAAE,EAAAP,SAEcvB,GAAM,CAAEmB,WAASQ,EAAA,EAAAG,EAAAP,SAC5BH,OAAOC,KAAKtB,EAAMiB,WAAW,CAACM,KAAK,KAAK,EAAA,KAAA,EAAAC;MAAA,EAGxC;EAAAT,QAGJA,QAAA,CAAA,EAAAd,GAAM,IAAID,EAAMiB,cAAcjB,EAAMiB,WAAWhB,GAAM,CAAEmB,YAAU,EAAA,IAAAY,EAChErC,GAAOsC,EAAA,EAAA,IACPb,YAAS;AAAA,UAAEpB,EAAMiB,WAAWhB,GAAM,CAAEmB;KAAU,QAC1CnB,GAAM,CAAED,OAAK,EACjBa,MAAMD,GAAS,CAAA,CAEhB,CAAA;EAAA"}
1
+ {"version":3,"file":"PlayRenderer.js","names":["createSignal","onCleanup","ErrorBoundary","Component","Renderer","StateProvider","ActionProvider","VisibilityProvider","ActionHandler","StateStore","createAtom","xstateStoreStateStore","watchSignal","PlayRendererProps","ViewMetadata","ActorProvider","PlayActor","PlayRenderer","props","view","setView","actor","currentView","get","internalStore","lastView","unwatch","nextView","_$createComponent","value","children","fallback","err","onError","store","initialState","spec","state","Record","atom","handlers","Object","fromEntries","entries","actions","map","actionName","eventType","params","send","type","registry"],"sources":["../src/PlayRenderer.tsx"],"sourcesContent":["/**\n * PlayRenderer - Main SolidJS renderer component for XMachines Play architecture\n *\n * @packageDocumentation\n */\n\nimport { createSignal, onCleanup, ErrorBoundary, type Component } from \"solid-js\";\nimport { Renderer, StateProvider, ActionProvider, VisibilityProvider } from \"@json-render/solid\";\nimport type { ActionHandler, StateStore } from \"@json-render/core\";\nimport { createAtom } from \"@xstate/store\";\nimport { xstateStoreStateStore } from \"@json-render/xstate\";\nimport { watchSignal } from \"@xmachines/play-signals\";\nimport type { PlayRendererProps } from \"./types.js\";\nimport type { ViewMetadata } from \"@xmachines/play-actor\";\nimport { ActorProvider, type PlayActor } from \"./useActor.js\";\n\n/**\n * Main renderer component that subscribes to actor signals and renders UI\n *\n * Architecture (per XMachines Play patterns):\n * - Subscribes to actor.currentView signal via TC39 Signal.subtle.Watcher\n * - Renders view.spec via @json-render/solid Renderer backed by the registry\n * - Routes actions to actor.send() via ActionProvider handlers\n * - SolidJS signal only for triggering renders, NOT business logic\n * - State store: uses external `store` prop if provided (controlled mode); otherwise\n * creates a fresh @xstate/store atom per view transition seeded from spec.state.\n * - Wraps the render path in a SolidJS `ErrorBoundary` to contain catalog component\n * render failures. The `fallback` prop is shown on error; `onError` is called for\n * observability forwarding (Sentry, Datadog, etc.).\n *\n * Invariant: Actor Authority - Actor decides all state transitions via guards.\n * Invariant: Passive Infrastructure - Component observes signals and sends events.\n * Invariant: Signal-Only Reactivity - Business logic state lives in actor signals.\n *\n * @example\n * ```typescript\n * import { PlayRenderer } from \"@xmachines/play-solid\";\n * import { defineRegistry } from \"@json-render/solid\";\n *\n * const { registry } = defineRegistry(catalog, { components: { ... } });\n *\n * // Uncontrolled fresh atom per view, seeded from spec.state:\n * <PlayRenderer actor={actor} registry={registry} actions={{ login: \"auth.login\" }} />\n *\n * // Controlled caller provides and owns the store:\n * import { createAtom } from \"@xstate/store\";\n * import { xstateStoreStateStore } from \"@json-render/xstate\";\n * const store = xstateStoreStateStore({ atom: createAtom({ username: \"\" }) });\n * <PlayRenderer actor={actor} registry={registry} store={store} actions={{ login: \"auth.login\" }} />\n *\n * // With observability hook:\n * <PlayRenderer actor={actor} registry={registry} onError={(err) => Sentry.captureException(err)} />\n * ```\n */\nexport const PlayRenderer: Component<PlayRendererProps> = (props) => {\n\t// Create SolidJS signal for view\n\t// Signal is NOT business logic state - it's just SolidJS's render trigger\n\tconst [view, setView] = createSignal<ViewMetadata | null>(\n\t\tprops.actor.currentView.get() as ViewMetadata | null,\n\t);\n\n\t// Internal per-view store — recreated on each view transition when no external store.\n\tlet internalStore: StateStore | null = null;\n\tlet lastView: ViewMetadata | null = null;\n\n\t// Bridge TC39 Signal to SolidJS signal — subscribe synchronously during setup\n\t// (matching React/Vue behavior; onMount would defer until after DOM insertion,\n\t// silently dropping signal changes between createSignal and mount)\n\tconst unwatch = watchSignal(props.actor.currentView, (nextView: ViewMetadata | null) => {\n\t\tsetView(nextView);\n\t});\n\tonCleanup(() => {\n\t\tunwatch();\n\t});\n\n\treturn (\n\t\t<ActorProvider value={props.actor as PlayActor}>\n\t\t\t<ErrorBoundary\n\t\t\t\tfallback={(err: unknown) => {\n\t\t\t\t\tprops.onError?.(err);\n\t\t\t\t\treturn props.fallback ?? null;\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{(() => {\n\t\t\t\t\tconst currentView = view();\n\t\t\t\t\tif (!currentView) return props.fallback ?? null;\n\n\t\t\t\t\t// Resolve the store: external (controlled) or internal per-view atom\n\t\t\t\t\tlet store: StateStore;\n\t\t\t\t\tif (props.store) {\n\t\t\t\t\t\tstore = props.store;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (internalStore === null || lastView !== currentView) {\n\t\t\t\t\t\t\tconst initialState =\n\t\t\t\t\t\t\t\t(currentView.spec.state as Record<string, unknown>) ?? {};\n\t\t\t\t\t\t\tinternalStore = xstateStoreStateStore({\n\t\t\t\t\t\t\t\tatom: createAtom(initialState),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tlastView = currentView;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstore = internalStore;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst handlers: Record<string, ActionHandler> = Object.fromEntries(\n\t\t\t\t\t\tObject.entries(props.actions ?? {}).map(([actionName, eventType]) => [\n\t\t\t\t\t\t\tactionName,\n\t\t\t\t\t\t\tasync (params: Record<string, unknown> = {}) =>\n\t\t\t\t\t\t\t\tprops.actor.send({ type: eventType, ...params }),\n\t\t\t\t\t\t]),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<StateProvider store={store}>\n\t\t\t\t\t\t\t<ActionProvider handlers={handlers}>\n\t\t\t\t\t\t\t\t<VisibilityProvider>\n\t\t\t\t\t\t\t\t\t<Renderer spec={currentView.spec} registry={props.registry} />\n\t\t\t\t\t\t\t\t</VisibilityProvider>\n\t\t\t\t\t\t\t</ActionProvider>\n\t\t\t\t\t\t</StateProvider>\n\t\t\t\t\t);\n\t\t\t\t})()}\n\t\t\t</ErrorBoundary>\n\t\t</ActorProvider>\n\t);\n};\n"],"mappings":";;;;;;;;AAsDA,IAAaiB,KAA8CC,MAAU;CAGpE,IAAM,CAACC,GAAMC,KAAWpB,EACvBkB,EAAMG,MAAMC,YAAYC,KAAK,CAC7B,EAGGC,IAAmC,MACnCC,IAAgC,MAK9BC,IAAUd,EAAYM,EAAMG,MAAMC,cAAcK,MAAkC;AACvFP,IAAQO,EAAS;GAChB;AAKF,QAJA1B,QAAgB;AACfyB,KAAS;GACR,EAEFE,EACEb,GAAa;EAAA,IAACc,QAAK;AAAA,UAAEX,EAAMG;;EAAkB,IAAAS,WAAA;AAAA,UAAAF,EAC5C1B,GAAa;IACb6B,WAAWC,OACVd,EAAMe,UAAUD,EAAI,EACbd,EAAMa,YAAY;IACzB,IAAAD,WAAA;AAAA,mBAEO;MACP,IAAMR,IAAcH,GAAM;AAC1B,UAAI,CAACG,EAAa,QAAOJ,EAAMa,YAAY;MAG3C,IAAIG;AACJ,MAAIhB,EAAMgB,QACTA,IAAQhB,EAAMgB,UAEVV,MAAkB,QAAQC,MAAaH,OAG1CE,IAAgBb,EAAsB,EACrC4B,MAAM7B,EAFLY,EAAYc,KAAKC,SAAqC,EAAE,CAE5B,EAC7B,CAAC,EACFZ,IAAWH,IAEZY,IAAQV;MAGT,IAAMgB,IAA0CC,OAAOC,YACtDD,OAAOE,QAAQzB,EAAM0B,WAAW,EAAE,CAAC,CAACC,KAAK,CAACC,GAAYC,OAAe,CACpED,GACA,OAAOE,IAAkC,EAAE,KAC1C9B,EAAMG,MAAM4B,KAAK;OAAEC,MAAMH;OAAW,GAAGC;OAAQ,CAAC,CACjD,CACF,CAAC;AAED,aAAApB,EACEvB,GAAa;OAAQ6B;OAAK,IAAAJ,WAAA;AAAA,eAAAF,EACzBtB,GAAc;SAAWkC;SAAQ,IAAAV,WAAA;AAAA,iBAAAF,EAChCrB,GAAkB,EAAA,IAAAuB,WAAA;AAAA,kBAAAF,EACjBxB,GAAQ;YAAA,IAACgC,OAAI;AAAA,oBAAEd,EAAYc;;YAAI,IAAEe,WAAQ;AAAA,oBAAEjC,EAAMiC;;YAAQ,CAAA;aAAA,CAAA;;SAAA,CAAA;;OAAA,CAAA;SAK3D;;IAAA,CAAA;;EAAA,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
- import { PlayRenderer as e } from "./PlayRenderer.js";
2
- export { e as PlayRenderer };
1
+ import { defineRegistry as e, useStateBinding as t } from "./node_modules/@json-render/solid/dist/index.js";
2
+ import { useActor as n } from "./useActor.js";
3
+ import { PlayRenderer as r } from "./PlayRenderer.js";
4
+ export { r as PlayRenderer, e as defineRegistry, n as useActor, t as useStateBinding };
@@ -0,0 +1,111 @@
1
+ import { _null as e, boolean as t, number as n, object as r, string as i, union as a } from "../../../zod/v4/classic/schemas.js";
2
+ //#region ../../node_modules/@json-render/core/dist/chunk-AFLK3Q4T.mjs
3
+ var o = a([
4
+ i(),
5
+ n(),
6
+ t(),
7
+ e(),
8
+ r({ $state: i() })
9
+ ]);
10
+ a([i(), r({ $state: i() })]), a([n(), r({ $state: i() })]), a([t(), r({ $state: i() })]);
11
+ function s(e, t) {
12
+ if (e != null) return typeof e == "object" && "$state" in e ? u(t, e.$state) : e;
13
+ }
14
+ function c(e) {
15
+ return e.replace(/~1/g, "/").replace(/~0/g, "~");
16
+ }
17
+ function l(e) {
18
+ return (e.startsWith("/") ? e.slice(1).split("/") : e.split("/")).map(c);
19
+ }
20
+ function u(e, t) {
21
+ if (!t || t === "/") return e;
22
+ let n = l(t), r = e;
23
+ for (let e of n) {
24
+ if (r == null) return;
25
+ if (Array.isArray(r)) r = r[parseInt(e, 10)];
26
+ else if (typeof r == "object") r = r[e];
27
+ else return;
28
+ }
29
+ return r;
30
+ }
31
+ var d = "spec";
32
+ `${d}`;
33
+ function f(e, t, n) {
34
+ let r = l(t);
35
+ if (r.length === 0) return e;
36
+ let i = { ...e }, a = i;
37
+ for (let e = 0; e < r.length - 1; e++) {
38
+ let t = r[e], n = a[t];
39
+ if (Array.isArray(n)) a[t] = [...n];
40
+ else if (typeof n == "object" && n) a[t] = { ...n };
41
+ else {
42
+ let n = r[e + 1];
43
+ a[t] = n !== void 0 && /^\d+$/.test(n) ? [] : {};
44
+ }
45
+ a = a[t];
46
+ }
47
+ let o = r[r.length - 1];
48
+ return Array.isArray(a) ? o === "-" ? a.push(n) : a[parseInt(o, 10)] = n : a[o] = n, i;
49
+ }
50
+ function p(e = {}) {
51
+ let t = { ...e }, n = /* @__PURE__ */ new Set();
52
+ function r() {
53
+ for (let e of n) e();
54
+ }
55
+ return {
56
+ get(e) {
57
+ return u(t, e);
58
+ },
59
+ set(e, n) {
60
+ u(t, e) !== n && (t = f(t, e, n), r());
61
+ },
62
+ update(e) {
63
+ let n = !1, i = t;
64
+ for (let [t, r] of Object.entries(e)) u(i, t) !== r && (i = f(i, t, r), n = !0);
65
+ n && (t = i, r());
66
+ },
67
+ getSnapshot() {
68
+ return t;
69
+ },
70
+ getServerSnapshot() {
71
+ return t;
72
+ },
73
+ subscribe(e) {
74
+ return n.add(e), () => {
75
+ n.delete(e);
76
+ };
77
+ }
78
+ };
79
+ }
80
+ function m(e) {
81
+ return {
82
+ get(t) {
83
+ return u(e.getSnapshot(), t);
84
+ },
85
+ set(t, n) {
86
+ let r = e.getSnapshot();
87
+ u(r, t) !== n && e.setSnapshot(f(r, t, n));
88
+ },
89
+ update(t) {
90
+ let n = e.getSnapshot(), r = !1;
91
+ for (let [e, i] of Object.entries(t)) u(n, e) !== i && (n = f(n, e, i), r = !0);
92
+ r && e.setSnapshot(n);
93
+ },
94
+ getSnapshot: e.getSnapshot,
95
+ getServerSnapshot: e.getSnapshot,
96
+ subscribe: e.subscribe
97
+ };
98
+ }
99
+ var h = 20;
100
+ function g(e, t = "", n = 0, r, i) {
101
+ let a = r ?? /* @__PURE__ */ new Set(), o = i ?? { current: !1 }, s = {};
102
+ for (let [r, i] of Object.entries(e)) {
103
+ let e = `${t}/${r}`;
104
+ n < h && typeof i == "object" && i && !Array.isArray(i) && Object.getPrototypeOf(i) === Object.prototype && !a.has(i) ? (a.add(i), Object.assign(s, g(i, e, n + 1, a, o))) : (process.env.NODE_ENV !== "production" && !o.current && n >= h && typeof i == "object" && i && !Array.isArray(i) && Object.getPrototypeOf(i) === Object.prototype && !a.has(i) && (o.current = !0, console.warn(`flattenToPointers: depth limit (${h}) reached. Nested state beyond this depth will be treated as a leaf value.`)), s[e] = i);
105
+ }
106
+ return s;
107
+ }
108
+ //#endregion
109
+ export { o as DynamicValueSchema, d as SPEC_DATA_PART, p as createStateStore, m as createStoreAdapter, g as flattenToPointers, u as getByPath, f as immutableSetByPath, s as resolveDynamicValue };
110
+
111
+ //# sourceMappingURL=chunk-AFLK3Q4T.js.map