@xmachines/play-dom 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * types.ts — XMachines-specific type definitions for play-dom.
2
+ * types.ts — the type definitions of play-dom that belong to XMachines.
3
3
  *
4
- * These types depend on @xmachines/play-actor and stay in play-dom.
5
- * Pure json-render types live in @xmachines/json-render-dom.
4
+ * These types depend on @xmachines/play-actor, and they stay in play-dom.
5
+ * Each pure json-render type is in @xmachines/json-render-dom.
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
@@ -10,65 +10,68 @@ import type { StateStore } from "@xmachines/json-render-core";
10
10
  import type { DefineRegistryResult, UIProviderOptions } from "@xmachines/json-render-dom";
11
11
  export type { UIProviderOptions } from "@xmachines/json-render-dom";
12
12
  /**
13
- * Options for `PlayRenderer`.
13
+ * The options of `PlayRenderer`.
14
14
  *
15
- * Extends {@link UIProviderOptions}, which contributes `functions`,
16
- * `directives`, `validationFunctions`, `navigate`, and `onRenderError`. All
17
- * are forwarded into `DomRenderContext` on every render pass and are readable
18
- * by component implementations via `ctx.ctx.*`.
15
+ * This type extends {@link UIProviderOptions}, which gives `functions`,
16
+ * `directives`, `validationFunctions`, `navigate`, and `onRenderError`. Each render
17
+ * pass puts all of them into `DomRenderContext`, and a component implementation
18
+ * reads them at `ctx.ctx.*`.
19
19
  */
20
20
  export interface PlayDomOptions extends UIProviderOptions {
21
21
  /**
22
- * The result from `defineRegistry` provides both the registry and the handlers factory.
22
+ * The result of `defineRegistry`. It gives the registry and the factory of the handlers.
23
23
  *
24
- * When provided, `PlayRenderer` wires `setState` and `getState` from the @xstate/store-backed
25
- * `StateStore` into the handlers factory automatically. This is the preferred approach as it
26
- * ensures actions always receive live `setState` and `state` bound to the current store.
24
+ * With this option, `PlayRenderer` connects `setState` and `getState` of the
25
+ * `StateStore` on @xstate/store to the factory of the handlers for you. This is the
26
+ * preferred way, because each action then always receives a live `setState` and a
27
+ * live `state` on the current store.
27
28
  */
28
29
  registryResult?: DefineRegistryResult;
29
30
  /**
30
- * Optional external StateStore (e.g. from `xstateStoreStateStore` in @xmachines/json-render-xstate).
31
+ * The optional external StateStore, for example from `xstateStoreStateStore` in @xmachines/json-render-xstate.
31
32
  *
32
- * When provided, `PlayRenderer` operates in controlled mode `spec.state` is ignored and
33
- * this store is the single source of truth for UI state (form values, etc.).
34
- * When omitted, a fresh `@xstate/store` atom is created internally per view transition,
35
- * seeded from `spec.state`.
33
+ * With this option, `PlayRenderer` works in the controlled mode: it ignores
34
+ * `spec.state`, and this store is the single source of truth of the UI state, such
35
+ * as a form value. Without this option, the renderer makes a new `@xstate/store`
36
+ * atom for each view transition, with the values of `spec.state`.
36
37
  */
37
38
  store?: StateStore;
38
39
  /**
39
- * When `true`, indicates the spec is still streaming (e.g. from an AI provider).
40
+ * With the value `true`, the spec is still streaming, for example from an AI provider.
40
41
  *
41
- * Forwarded to `renderSpec` so component implementations can read `ctx.ctx.loading`
42
- * to render skeleton states. Also suppresses missing-child warnings during stream
43
- * ingestion, since referenced elements may not yet have arrived in the incremental spec.
42
+ * The renderer gives the flag to `renderSpec`. A component implementation therefore
43
+ * reads `ctx.ctx.loading`, and it can render a skeleton state. The flag also stops
44
+ * each warning about an absent child during the ingestion of the stream, because an
45
+ * element of a reference can still be absent from the incremental spec.
44
46
  *
45
- * Mirrors the `loading` prop from framework renderer providers.
47
+ * This option matches the `loading` prop of the framework renderer providers.
46
48
  */
47
49
  loading?: boolean;
48
50
  }
49
51
  /**
50
- * Options for `createPlayUI()` the batteries-included DOM factory.
52
+ * The options of `createPlayUI()`, the complete DOM factory.
51
53
  *
52
- * Extends {@link UIProviderOptions}, which contributes `functions`,
53
- * `directives`, `validationFunctions`, `navigate`, and `onRenderError`. All
54
- * are closed over at factory creation time and forwarded into `PlayRenderer`
55
- * on every `mount()` call.
54
+ * This type extends {@link UIProviderOptions}, which gives `functions`,
55
+ * `directives`, `validationFunctions`, `navigate`, and `onRenderError`. The factory
56
+ * holds all of them from the moment of its creation, and it gives them to
57
+ * `PlayRenderer` on every `mount()` call.
56
58
  *
57
- * Parallel to `PlayUIProvider`'s props in the framework renderers.
59
+ * This type is parallel to the props of `PlayUIProvider` in the framework renderers.
58
60
  *
59
61
  * @see createPlayUI
60
62
  */
61
63
  export interface CreatePlayUIOptions extends UIProviderOptions {
62
64
  /**
63
- * Optional fallback element shown when `currentView` is `null` on **initial mount** only.
65
+ * The optional fallback element. The factory shows it when `currentView` is `null` on the **first mount** only.
64
66
  *
65
- * The fallback is appended immediately after `mount()` if the container is empty at
66
- * that moment (i.e. the actor's initial view is `null`).
67
+ * The factory appends the fallback directly after `mount()`, when the container is
68
+ * empty at that moment, which means that the first view of the actor is `null`.
67
69
  *
68
- * **Limitation:** If the actor's view transitions to `null` after mount, the container
69
- * will be cleared but this fallback will NOT be re-appended. For dynamic fallback
70
- * behavior (null view after non-null), use `PlayRenderer` directly and wrap the
71
- * `actor.currentView` signal to inject fallback content.
70
+ * **Limitation:** when the view of the actor becomes `null` after the mount, the
71
+ * renderer clears the container, and it does NOT append this fallback again. For a
72
+ * dynamic fallback, which follows a null view after a view that was not null, use
73
+ * `PlayRenderer` directly and wrap the `actor.currentView` signal to add the
74
+ * fallback content.
72
75
  */
73
76
  fallback?: HTMLElement | null;
74
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE1F,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACxD;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;IAEtC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IAEnB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE1F,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACxD;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;IAEtC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IAEnB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC9B"}
package/dist/types.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * types.ts — XMachines-specific type definitions for play-dom.
2
+ * types.ts — the type definitions of play-dom that belong to XMachines.
3
3
  *
4
- * These types depend on @xmachines/play-actor and stay in play-dom.
5
- * Pure json-render types live in @xmachines/json-render-dom.
4
+ * These types depend on @xmachines/play-actor, and they stay in play-dom.
5
+ * Each pure json-render type is in @xmachines/json-render-dom.
6
6
  *
7
7
  * @packageDocumentation
8
8
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmachines/play-dom",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Vanilla DOM renderer for XMachines Play architecture with signal-driven rendering",
5
5
  "keywords": [
6
6
  "actor",
@@ -42,12 +42,13 @@
42
42
  "clean": "rm -rf dist *.tsbuildinfo coverage .vitest-attachments test/browser/__screenshots__ node_modules/.svelte2tsx-* node_modules/.vite*",
43
43
  "lint": "oxlint .",
44
44
  "format": "oxfmt .",
45
- "test": "vitest"
45
+ "test": "vitest",
46
+ "test:coverage": "vitest run --coverage"
46
47
  },
47
48
  "dependencies": {
48
- "@xmachines/play": "2.0.0",
49
- "@xmachines/play-actor": "2.0.0",
50
- "@xmachines/play-signals": "2.0.0"
49
+ "@xmachines/play": "2.1.0",
50
+ "@xmachines/play-actor": "2.1.0",
51
+ "@xmachines/play-signals": "2.1.0"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@testing-library/jest-dom": "^6.9.1",
package/dist/errors.d.ts DELETED
@@ -1,46 +0,0 @@
1
- import { PlayError } from "@xmachines/play";
2
- /**
3
- * Thrown by `PlayRenderer` when the `components` option is `null` or `undefined`.
4
- *
5
- * A missing catalog is a programmer error — the components map must be provided
6
- * to the renderer. The `componentName` that was being looked up is encoded in
7
- * the error message.
8
- *
9
- * **Error code:** `PLAY_DOM_MISSING_CATALOG`
10
- *
11
- * @example
12
- * ```typescript
13
- * import { MissingCatalogError } from "@xmachines/play-dom";
14
- *
15
- * // In a catch block:
16
- * if (err instanceof MissingCatalogError) {
17
- * console.error("components option was not provided to the renderer");
18
- * }
19
- * ```
20
- */
21
- export declare class MissingCatalogError extends PlayError {
22
- constructor(componentName: string, catalogValue: null | undefined);
23
- }
24
- /**
25
- * Thrown by `PlayRenderer` when the component name from `actor.currentView` does
26
- * not exist as a key in the `components` catalog.
27
- *
28
- * This is a programmer error — either the machine's `meta.view.component` name is
29
- * misspelled, or the component was not registered in the catalog passed to the renderer.
30
- *
31
- * **Error code:** `PLAY_DOM_MISSING_COMPONENT`
32
- *
33
- * @example
34
- * ```typescript
35
- * import { MissingComponentError } from "@xmachines/play-dom";
36
- *
37
- * if (err instanceof MissingComponentError) {
38
- * // err.message lists both the missing name and available components
39
- * console.error(err.message);
40
- * }
41
- * ```
42
- */
43
- export declare class MissingComponentError extends PlayError {
44
- constructor(componentName: string, availableComponents: string[]);
45
- }
46
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBACrC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,GAAG,SAAS;CAQjE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;gBACvC,aAAa,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE;CAQhE"}
package/dist/errors.js DELETED
@@ -1,52 +0,0 @@
1
- import { PlayError } from "@xmachines/play";
2
- /**
3
- * Thrown by `PlayRenderer` when the `components` option is `null` or `undefined`.
4
- *
5
- * A missing catalog is a programmer error — the components map must be provided
6
- * to the renderer. The `componentName` that was being looked up is encoded in
7
- * the error message.
8
- *
9
- * **Error code:** `PLAY_DOM_MISSING_CATALOG`
10
- *
11
- * @example
12
- * ```typescript
13
- * import { MissingCatalogError } from "@xmachines/play-dom";
14
- *
15
- * // In a catch block:
16
- * if (err instanceof MissingCatalogError) {
17
- * console.error("components option was not provided to the renderer");
18
- * }
19
- * ```
20
- */
21
- export class MissingCatalogError extends PlayError {
22
- constructor(componentName, catalogValue) {
23
- super("PlayRenderer", "PLAY_DOM_MISSING_CATALOG", `Components catalog is ${catalogValue === null ? "null" : "undefined"}. Cannot render component "${componentName}".`);
24
- this.name = "MissingCatalogError";
25
- }
26
- }
27
- /**
28
- * Thrown by `PlayRenderer` when the component name from `actor.currentView` does
29
- * not exist as a key in the `components` catalog.
30
- *
31
- * This is a programmer error — either the machine's `meta.view.component` name is
32
- * misspelled, or the component was not registered in the catalog passed to the renderer.
33
- *
34
- * **Error code:** `PLAY_DOM_MISSING_COMPONENT`
35
- *
36
- * @example
37
- * ```typescript
38
- * import { MissingComponentError } from "@xmachines/play-dom";
39
- *
40
- * if (err instanceof MissingComponentError) {
41
- * // err.message lists both the missing name and available components
42
- * console.error(err.message);
43
- * }
44
- * ```
45
- */
46
- export class MissingComponentError extends PlayError {
47
- constructor(componentName, availableComponents) {
48
- super("PlayRenderer", "PLAY_DOM_MISSING_COMPONENT", `Component "${componentName}" not found in catalog. Available components: ${availableComponents.join(", ")}`);
49
- this.name = "MissingComponentError";
50
- }
51
- }
52
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,mBAAoB,SAAQ,SAAS;IACjD,YAAY,aAAqB,EAAE,YAA8B;QAChE,KAAK,CACJ,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,8BAA8B,aAAa,IAAI,CACpH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IACnD,YAAY,aAAqB,EAAE,mBAA6B;QAC/D,KAAK,CACJ,cAAc,EACd,4BAA4B,EAC5B,cAAc,aAAa,iDAAiD,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC5G,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACrC,CAAC;CACD"}