@zag-js/core 1.36.0 → 1.38.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/state.js +9 -1
- package/dist/state.mjs +9 -1
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +3 -3
package/dist/state.js
CHANGED
|
@@ -43,6 +43,9 @@ function isAbsoluteStatePath(value) {
|
|
|
43
43
|
function isExplicitAbsoluteStatePath(value) {
|
|
44
44
|
return value.startsWith(ABSOLUTE_PREFIX);
|
|
45
45
|
}
|
|
46
|
+
function isChildTarget(value) {
|
|
47
|
+
return value.startsWith(STATE_DELIMITER);
|
|
48
|
+
}
|
|
46
49
|
function stripAbsolutePrefix(value) {
|
|
47
50
|
return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value;
|
|
48
51
|
}
|
|
@@ -141,13 +144,18 @@ function resolveStateValue(machine, value, source) {
|
|
|
141
144
|
}
|
|
142
145
|
return resolveAbsoluteStateValue(machine, statePath);
|
|
143
146
|
}
|
|
147
|
+
if (isChildTarget(stateValue) && source) {
|
|
148
|
+
const childPath = appendStatePath(source, stateValue.slice(1));
|
|
149
|
+
return resolveAbsoluteStateValue(machine, childPath);
|
|
150
|
+
}
|
|
144
151
|
if (!isAbsoluteStatePath(stateValue) && source) {
|
|
145
152
|
const sourceSegments = toSegments(source);
|
|
146
|
-
for (let index = sourceSegments.length; index >= 1; index--) {
|
|
153
|
+
for (let index = sourceSegments.length - 1; index >= 1; index--) {
|
|
147
154
|
const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
|
|
148
155
|
const candidate = appendStatePath(base, stateValue);
|
|
149
156
|
if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
|
|
150
157
|
}
|
|
158
|
+
if (hasStatePath(machine, stateValue)) return resolveAbsoluteStateValue(machine, stateValue);
|
|
151
159
|
}
|
|
152
160
|
return resolveAbsoluteStateValue(machine, stateValue);
|
|
153
161
|
}
|
package/dist/state.mjs
CHANGED
|
@@ -12,6 +12,9 @@ function isAbsoluteStatePath(value) {
|
|
|
12
12
|
function isExplicitAbsoluteStatePath(value) {
|
|
13
13
|
return value.startsWith(ABSOLUTE_PREFIX);
|
|
14
14
|
}
|
|
15
|
+
function isChildTarget(value) {
|
|
16
|
+
return value.startsWith(STATE_DELIMITER);
|
|
17
|
+
}
|
|
15
18
|
function stripAbsolutePrefix(value) {
|
|
16
19
|
return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value;
|
|
17
20
|
}
|
|
@@ -110,13 +113,18 @@ function resolveStateValue(machine, value, source) {
|
|
|
110
113
|
}
|
|
111
114
|
return resolveAbsoluteStateValue(machine, statePath);
|
|
112
115
|
}
|
|
116
|
+
if (isChildTarget(stateValue) && source) {
|
|
117
|
+
const childPath = appendStatePath(source, stateValue.slice(1));
|
|
118
|
+
return resolveAbsoluteStateValue(machine, childPath);
|
|
119
|
+
}
|
|
113
120
|
if (!isAbsoluteStatePath(stateValue) && source) {
|
|
114
121
|
const sourceSegments = toSegments(source);
|
|
115
|
-
for (let index = sourceSegments.length; index >= 1; index--) {
|
|
122
|
+
for (let index = sourceSegments.length - 1; index >= 1; index--) {
|
|
116
123
|
const base = sourceSegments.slice(0, index).join(STATE_DELIMITER);
|
|
117
124
|
const candidate = appendStatePath(base, stateValue);
|
|
118
125
|
if (hasStatePath(machine, candidate)) return resolveAbsoluteStateValue(machine, candidate);
|
|
119
126
|
}
|
|
127
|
+
if (hasStatePath(machine, stateValue)) return resolveAbsoluteStateValue(machine, stateValue);
|
|
120
128
|
}
|
|
121
129
|
return resolveAbsoluteStateValue(machine, stateValue);
|
|
122
130
|
}
|
package/dist/types.d.mts
CHANGED
|
@@ -108,10 +108,11 @@ type TopLevelState<S extends string> = S extends `${infer Top}.${string}` ? Top
|
|
|
108
108
|
type ChildStateKey<S extends string, Parent extends string> = S extends `${Parent}.${infer Rest}` ? Rest extends `${infer Child}.${string}` ? Child : Rest : never;
|
|
109
109
|
type ParentPath<S extends string> = S extends `${infer Parent}.${string}` ? Parent : never;
|
|
110
110
|
type AncestorPaths<S extends string> = S | (ParentPath<S> extends never ? never : AncestorPaths<ParentPath<S>>);
|
|
111
|
-
type RelativeStateTarget<S extends string, Source extends string> = ChildStateKey<S, AncestorPaths<Source>>;
|
|
112
111
|
type StateIdTarget = `#${string}`;
|
|
112
|
+
type SiblingStateTarget<S extends string, Source extends string> = TopLevelState<S> | ChildStateKey<S, Exclude<AncestorPaths<Source>, Source>>;
|
|
113
|
+
type ChildStateTarget<S extends string, Source extends string> = `.${ChildStateKey<S, Source>}`;
|
|
113
114
|
interface Transition<T extends Dict, Source extends string | undefined = string | undefined> {
|
|
114
|
-
target?: T["state"] | StateIdTarget | (Source extends string ?
|
|
115
|
+
target?: T["state"] | StateIdTarget | (Source extends string ? SiblingStateTarget<T["state"], Source> : never) | (Source extends string ? ChildStateTarget<T["state"], Source> : never) | undefined;
|
|
115
116
|
actions?: T["action"][] | undefined;
|
|
116
117
|
guard?: T["guard"] | GuardFn<T> | undefined;
|
|
117
118
|
reenter?: boolean | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -108,10 +108,11 @@ type TopLevelState<S extends string> = S extends `${infer Top}.${string}` ? Top
|
|
|
108
108
|
type ChildStateKey<S extends string, Parent extends string> = S extends `${Parent}.${infer Rest}` ? Rest extends `${infer Child}.${string}` ? Child : Rest : never;
|
|
109
109
|
type ParentPath<S extends string> = S extends `${infer Parent}.${string}` ? Parent : never;
|
|
110
110
|
type AncestorPaths<S extends string> = S | (ParentPath<S> extends never ? never : AncestorPaths<ParentPath<S>>);
|
|
111
|
-
type RelativeStateTarget<S extends string, Source extends string> = ChildStateKey<S, AncestorPaths<Source>>;
|
|
112
111
|
type StateIdTarget = `#${string}`;
|
|
112
|
+
type SiblingStateTarget<S extends string, Source extends string> = TopLevelState<S> | ChildStateKey<S, Exclude<AncestorPaths<Source>, Source>>;
|
|
113
|
+
type ChildStateTarget<S extends string, Source extends string> = `.${ChildStateKey<S, Source>}`;
|
|
113
114
|
interface Transition<T extends Dict, Source extends string | undefined = string | undefined> {
|
|
114
|
-
target?: T["state"] | StateIdTarget | (Source extends string ?
|
|
115
|
+
target?: T["state"] | StateIdTarget | (Source extends string ? SiblingStateTarget<T["state"], Source> : never) | (Source extends string ? ChildStateTarget<T["state"], Source> : never) | undefined;
|
|
115
116
|
actions?: T["action"][] | undefined;
|
|
116
117
|
guard?: T["guard"] | GuardFn<T> | undefined;
|
|
117
118
|
reenter?: boolean | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
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.
|
|
29
|
-
"@zag-js/dom-query": "1.
|
|
28
|
+
"@zag-js/utils": "1.38.0",
|
|
29
|
+
"@zag-js/dom-query": "1.38.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"clean-package": "2.2.0"
|