@zag-js/core
Advanced tools
+9
-1
@@ -46,2 +46,5 @@ "use strict"; | ||
| } | ||
| function isChildTarget(value) { | ||
| return value.startsWith(STATE_DELIMITER); | ||
| } | ||
| function stripAbsolutePrefix(value) { | ||
@@ -145,5 +148,9 @@ return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value; | ||
| } | ||
| if (isChildTarget(stateValue) && source) { | ||
| const childPath = appendStatePath(source, stateValue.slice(1)); | ||
| return resolveAbsoluteStateValue(machine, childPath); | ||
| } | ||
| if (!isAbsoluteStatePath(stateValue) && source) { | ||
| const sourceSegments = toSegments(source); | ||
| for (let index = sourceSegments.length; index >= 1; index--) { | ||
| for (let index = sourceSegments.length - 1; index >= 1; index--) { | ||
| const base = sourceSegments.slice(0, index).join(STATE_DELIMITER); | ||
@@ -153,2 +160,3 @@ const candidate = appendStatePath(base, stateValue); | ||
| } | ||
| if (hasStatePath(machine, stateValue)) return resolveAbsoluteStateValue(machine, stateValue); | ||
| } | ||
@@ -155,0 +163,0 @@ return resolveAbsoluteStateValue(machine, stateValue); |
+9
-1
@@ -15,2 +15,5 @@ // src/state.ts | ||
| } | ||
| function isChildTarget(value) { | ||
| return value.startsWith(STATE_DELIMITER); | ||
| } | ||
| function stripAbsolutePrefix(value) { | ||
@@ -114,5 +117,9 @@ return isExplicitAbsoluteStatePath(value) ? value.slice(ABSOLUTE_PREFIX.length) : value; | ||
| } | ||
| if (isChildTarget(stateValue) && source) { | ||
| const childPath = appendStatePath(source, stateValue.slice(1)); | ||
| return resolveAbsoluteStateValue(machine, childPath); | ||
| } | ||
| if (!isAbsoluteStatePath(stateValue) && source) { | ||
| const sourceSegments = toSegments(source); | ||
| for (let index = sourceSegments.length; index >= 1; index--) { | ||
| for (let index = sourceSegments.length - 1; index >= 1; index--) { | ||
| const base = sourceSegments.slice(0, index).join(STATE_DELIMITER); | ||
@@ -122,2 +129,3 @@ const candidate = appendStatePath(base, stateValue); | ||
| } | ||
| if (hasStatePath(machine, stateValue)) return resolveAbsoluteStateValue(machine, stateValue); | ||
| } | ||
@@ -124,0 +132,0 @@ return resolveAbsoluteStateValue(machine, stateValue); |
+3
-2
@@ -111,6 +111,7 @@ type Dict = Record<string, any>; | ||
| type AncestorPaths<S extends string> = S | (ParentPath<S> extends never ? never : AncestorPaths<ParentPath<S>>); | ||
| type RelativeStateTarget<S extends string, Source extends string> = ChildStateKey<S, AncestorPaths<Source>>; | ||
| type StateIdTarget = `#${string}`; | ||
| type SiblingStateTarget<S extends string, Source extends string> = TopLevelState<S> | ChildStateKey<S, Exclude<AncestorPaths<Source>, Source>>; | ||
| type ChildStateTarget<S extends string, Source extends string> = `.${ChildStateKey<S, Source>}`; | ||
| interface Transition<T extends Dict, Source extends string | undefined = string | undefined> { | ||
| target?: T["state"] | StateIdTarget | (Source extends string ? RelativeStateTarget<T["state"], Source> : never) | undefined; | ||
| target?: T["state"] | StateIdTarget | (Source extends string ? SiblingStateTarget<T["state"], Source> : never) | (Source extends string ? ChildStateTarget<T["state"], Source> : never) | undefined; | ||
| actions?: T["action"][] | undefined; | ||
@@ -117,0 +118,0 @@ guard?: T["guard"] | GuardFn<T> | undefined; |
+3
-2
@@ -111,6 +111,7 @@ type Dict = Record<string, any>; | ||
| type AncestorPaths<S extends string> = S | (ParentPath<S> extends never ? never : AncestorPaths<ParentPath<S>>); | ||
| type RelativeStateTarget<S extends string, Source extends string> = ChildStateKey<S, AncestorPaths<Source>>; | ||
| type StateIdTarget = `#${string}`; | ||
| type SiblingStateTarget<S extends string, Source extends string> = TopLevelState<S> | ChildStateKey<S, Exclude<AncestorPaths<Source>, Source>>; | ||
| type ChildStateTarget<S extends string, Source extends string> = `.${ChildStateKey<S, Source>}`; | ||
| interface Transition<T extends Dict, Source extends string | undefined = string | undefined> { | ||
| target?: T["state"] | StateIdTarget | (Source extends string ? RelativeStateTarget<T["state"], Source> : never) | undefined; | ||
| target?: T["state"] | StateIdTarget | (Source extends string ? SiblingStateTarget<T["state"], Source> : never) | (Source extends string ? ChildStateTarget<T["state"], Source> : never) | undefined; | ||
| actions?: T["action"][] | undefined; | ||
@@ -117,0 +118,0 @@ guard?: T["guard"] | GuardFn<T> | undefined; |
+3
-3
| { | ||
| "name": "@zag-js/core", | ||
| "version": "1.37.0", | ||
| "version": "1.38.0", | ||
| "description": "A minimal implementation of xstate fsm for UI machines", | ||
@@ -28,4 +28,4 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@zag-js/utils": "1.37.0", | ||
| "@zag-js/dom-query": "1.37.0" | ||
| "@zag-js/utils": "1.38.0", | ||
| "@zag-js/dom-query": "1.38.0" | ||
| }, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
63824
1.78%1154
1.5%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated