@zag-js/core
Advanced tools
+9
-4
@@ -33,2 +33,3 @@ "use strict"; | ||
| module.exports = __toCommonJS(state_exports); | ||
| var import_utils = require("@zag-js/utils"); | ||
| var STATE_DELIMITER = "."; | ||
@@ -64,3 +65,3 @@ var ABSOLUTE_PREFIX = "#"; | ||
| if (idIndex.has(stateId)) { | ||
| throw new Error(`Duplicate state id: ${stateId}`); | ||
| (0, import_utils.invariant)(`[zag-js] Duplicate state id: "${stateId}"`); | ||
| } | ||
@@ -71,2 +72,8 @@ idIndex.set(stateId, basePath); | ||
| if (!childStates) return; | ||
| (0, import_utils.ensure)(state.initial, () => `[zag-js] Compound state "${basePath}" has child states but no "initial" property`); | ||
| if (!(state.initial in childStates)) { | ||
| (0, import_utils.invariant)( | ||
| `[zag-js] Compound state "${basePath}" has initial "${String(state.initial)}" which is not a child state` | ||
| ); | ||
| } | ||
| for (const [childKey, childState] of Object.entries(childStates)) { | ||
@@ -145,5 +152,3 @@ if (!childState) continue; | ||
| const statePath = getStatePathById(machine, stateId); | ||
| if (!statePath) { | ||
| throw new Error(`Unknown state id: ${stateId}`); | ||
| } | ||
| (0, import_utils.ensure)(statePath, () => `[zag-js] Unknown state id: "${stateId}"`); | ||
| return resolveAbsoluteStateValue(machine, statePath); | ||
@@ -150,0 +155,0 @@ } |
+9
-4
| // src/state.ts | ||
| import { ensure, invariant } from "@zag-js/utils"; | ||
| var STATE_DELIMITER = "."; | ||
@@ -32,3 +33,3 @@ var ABSOLUTE_PREFIX = "#"; | ||
| if (idIndex.has(stateId)) { | ||
| throw new Error(`Duplicate state id: ${stateId}`); | ||
| invariant(`[zag-js] Duplicate state id: "${stateId}"`); | ||
| } | ||
@@ -39,2 +40,8 @@ idIndex.set(stateId, basePath); | ||
| if (!childStates) return; | ||
| ensure(state.initial, () => `[zag-js] Compound state "${basePath}" has child states but no "initial" property`); | ||
| if (!(state.initial in childStates)) { | ||
| invariant( | ||
| `[zag-js] Compound state "${basePath}" has initial "${String(state.initial)}" which is not a child state` | ||
| ); | ||
| } | ||
| for (const [childKey, childState] of Object.entries(childStates)) { | ||
@@ -113,5 +120,3 @@ if (!childState) continue; | ||
| const statePath = getStatePathById(machine, stateId); | ||
| if (!statePath) { | ||
| throw new Error(`Unknown state id: ${stateId}`); | ||
| } | ||
| ensure(statePath, () => `[zag-js] Unknown state id: "${stateId}"`); | ||
| return resolveAbsoluteStateValue(machine, statePath); | ||
@@ -118,0 +123,0 @@ } |
+3
-3
| { | ||
| "name": "@zag-js/core", | ||
| "version": "1.38.0", | ||
| "version": "1.38.1", | ||
| "description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -28,4 +28,4 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@zag-js/utils": "1.38.0", | ||
| "@zag-js/dom-query": "1.38.0" | ||
| "@zag-js/utils": "1.38.1", | ||
| "@zag-js/dom-query": "1.38.1" | ||
| }, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
64592
1.2%1164
0.87%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated