@zag-js/core 1.38.0 → 1.38.2

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/state.js CHANGED
@@ -30,6 +30,7 @@ __export(state_exports, {
30
30
  resolveStateValue: () => resolveStateValue
31
31
  });
32
32
  module.exports = __toCommonJS(state_exports);
33
+ var import_utils = require("@zag-js/utils");
33
34
  var STATE_DELIMITER = ".";
34
35
  var ABSOLUTE_PREFIX = "#";
35
36
  var stateIndexCache = /* @__PURE__ */ new WeakMap();
@@ -60,12 +61,18 @@ function buildStateIndex(machine) {
60
61
  const stateId = state.id;
61
62
  if (stateId) {
62
63
  if (idIndex.has(stateId)) {
63
- throw new Error(`Duplicate state id: ${stateId}`);
64
+ (0, import_utils.invariant)(`[zag-js] Duplicate state id: "${stateId}"`);
64
65
  }
65
66
  idIndex.set(stateId, basePath);
66
67
  }
67
68
  const childStates = state.states;
68
69
  if (!childStates) return;
70
+ (0, import_utils.ensure)(state.initial, () => `[zag-js] Compound state "${basePath}" has child states but no "initial" property`);
71
+ if (!(state.initial in childStates)) {
72
+ (0, import_utils.invariant)(
73
+ `[zag-js] Compound state "${basePath}" has initial "${String(state.initial)}" which is not a child state`
74
+ );
75
+ }
69
76
  for (const [childKey, childState] of Object.entries(childStates)) {
70
77
  if (!childState) continue;
71
78
  const childPath = appendStatePath(basePath, childKey);
@@ -139,9 +146,7 @@ function resolveStateValue(machine, value, source) {
139
146
  if (isExplicitAbsoluteStatePath(stateValue)) {
140
147
  const stateId = stripAbsolutePrefix(stateValue);
141
148
  const statePath = getStatePathById(machine, stateId);
142
- if (!statePath) {
143
- throw new Error(`Unknown state id: ${stateId}`);
144
- }
149
+ (0, import_utils.ensure)(statePath, () => `[zag-js] Unknown state id: "${stateId}"`);
145
150
  return resolveAbsoluteStateValue(machine, statePath);
146
151
  }
147
152
  if (isChildTarget(stateValue) && source) {
package/dist/state.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/state.ts
2
+ import { ensure, invariant } from "@zag-js/utils";
2
3
  var STATE_DELIMITER = ".";
3
4
  var ABSOLUTE_PREFIX = "#";
4
5
  var stateIndexCache = /* @__PURE__ */ new WeakMap();
@@ -29,12 +30,18 @@ function buildStateIndex(machine) {
29
30
  const stateId = state.id;
30
31
  if (stateId) {
31
32
  if (idIndex.has(stateId)) {
32
- throw new Error(`Duplicate state id: ${stateId}`);
33
+ invariant(`[zag-js] Duplicate state id: "${stateId}"`);
33
34
  }
34
35
  idIndex.set(stateId, basePath);
35
36
  }
36
37
  const childStates = state.states;
37
38
  if (!childStates) return;
39
+ ensure(state.initial, () => `[zag-js] Compound state "${basePath}" has child states but no "initial" property`);
40
+ if (!(state.initial in childStates)) {
41
+ invariant(
42
+ `[zag-js] Compound state "${basePath}" has initial "${String(state.initial)}" which is not a child state`
43
+ );
44
+ }
38
45
  for (const [childKey, childState] of Object.entries(childStates)) {
39
46
  if (!childState) continue;
40
47
  const childPath = appendStatePath(basePath, childKey);
@@ -108,9 +115,7 @@ function resolveStateValue(machine, value, source) {
108
115
  if (isExplicitAbsoluteStatePath(stateValue)) {
109
116
  const stateId = stripAbsolutePrefix(stateValue);
110
117
  const statePath = getStatePathById(machine, stateId);
111
- if (!statePath) {
112
- throw new Error(`Unknown state id: ${stateId}`);
113
- }
118
+ ensure(statePath, () => `[zag-js] Unknown state id: "${stateId}"`);
114
119
  return resolveAbsoluteStateValue(machine, statePath);
115
120
  }
116
121
  if (isChildTarget(stateValue) && source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/core",
3
- "version": "1.38.0",
3
+ "version": "1.38.2",
4
4
  "description": "A minimal implementation of xstate fsm for UI machines",
5
5
  "keywords": [
6
6
  "ui-machines",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/chakra-ui/zag/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@zag-js/utils": "1.38.0",
29
- "@zag-js/dom-query": "1.38.0"
28
+ "@zag-js/utils": "1.38.2",
29
+ "@zag-js/dom-query": "1.38.2"
30
30
  },
31
31
  "devDependencies": {
32
32
  "clean-package": "2.2.0"