@zag-js/stringify-state 1.3.0 → 1.3.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/index.js +5 -1
- package/dist/index.mjs +5 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var formatHighlight__default = /*#__PURE__*/_interopDefault(formatHighlight);
|
|
|
10
10
|
var pick = (obj, keys) => Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]));
|
|
11
11
|
var hasProp = (v, prop) => Object.prototype.hasOwnProperty.call(v, prop);
|
|
12
12
|
var isTimeObject = (v) => hasProp(v, "hour") && hasProp(v, "minute") && hasProp(v, "second");
|
|
13
|
+
var isMachine = (v) => ["state", "context", "scope"].every((prop) => hasProp(v, prop));
|
|
13
14
|
function stringifyState(state, omit) {
|
|
14
15
|
const code = JSON.stringify(
|
|
15
16
|
state,
|
|
@@ -38,8 +39,11 @@ function stringifyState(state, omit) {
|
|
|
38
39
|
if (value instanceof Set) {
|
|
39
40
|
return Array.from(value);
|
|
40
41
|
}
|
|
42
|
+
if (isMachine(value)) {
|
|
43
|
+
return `Machine: ${value.scope.id}`;
|
|
44
|
+
}
|
|
41
45
|
switch (value?.toString()) {
|
|
42
|
-
case "[object
|
|
46
|
+
case "[object ShadowRoot]":
|
|
43
47
|
const id = value.state.context.id ?? value.id;
|
|
44
48
|
return `Machine: ${id}`;
|
|
45
49
|
case "[object ShadowRoot]":
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import formatHighlight from 'json-format-highlight';
|
|
|
4
4
|
var pick = (obj, keys) => Object.fromEntries(keys.filter((key) => key in obj).map((key) => [key, obj[key]]));
|
|
5
5
|
var hasProp = (v, prop) => Object.prototype.hasOwnProperty.call(v, prop);
|
|
6
6
|
var isTimeObject = (v) => hasProp(v, "hour") && hasProp(v, "minute") && hasProp(v, "second");
|
|
7
|
+
var isMachine = (v) => ["state", "context", "scope"].every((prop) => hasProp(v, prop));
|
|
7
8
|
function stringifyState(state, omit) {
|
|
8
9
|
const code = JSON.stringify(
|
|
9
10
|
state,
|
|
@@ -32,8 +33,11 @@ function stringifyState(state, omit) {
|
|
|
32
33
|
if (value instanceof Set) {
|
|
33
34
|
return Array.from(value);
|
|
34
35
|
}
|
|
36
|
+
if (isMachine(value)) {
|
|
37
|
+
return `Machine: ${value.scope.id}`;
|
|
38
|
+
}
|
|
35
39
|
switch (value?.toString()) {
|
|
36
|
-
case "[object
|
|
40
|
+
case "[object ShadowRoot]":
|
|
37
41
|
const id = value.state.context.id ?? value.id;
|
|
38
42
|
return `Machine: ${id}`;
|
|
39
43
|
case "[object ShadowRoot]":
|