xstate 6.0.0-alpha.26 → 6.0.0-alpha.27
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/{StateMachine-70bbb88f.development.esm.js → StateMachine-24c5e3f9.development.esm.js} +4 -1
- package/dist/{StateMachine-89f725ff.development.cjs.js → StateMachine-673e9a91.development.cjs.js} +4 -1
- package/dist/{StateMachine-bfbf8d6e.esm.js → StateMachine-7daabf24.esm.js} +4 -1
- package/dist/{StateMachine-1a51a14a.cjs.js → StateMachine-bcb27183.cjs.js} +4 -1
- package/dist/declarations/src/createMachine.d.ts +3 -3
- package/dist/declarations/src/createMachineFromConfig.d.ts +1 -1
- package/dist/declarations/src/setup.d.ts +2 -2
- package/dist/declarations/src/types.d.ts +2 -0
- package/dist/declarations/src/types.v6.d.ts +161 -1
- package/dist/{index-b90ebcd4.development.esm.js → index-41508d62.development.esm.js} +39 -1
- package/dist/{index-f58cc498.cjs.js → index-b228b8b6.cjs.js} +39 -1
- package/dist/{index-1ad8a761.development.cjs.js → index-c55fff73.development.cjs.js} +39 -1
- package/dist/{index-036a773f.esm.js → index-d33c7b85.esm.js} +39 -1
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +5 -2
- package/dist/xstate.development.cjs.js +5 -2
- package/dist/xstate.development.esm.js +7 -4
- package/dist/xstate.esm.js +7 -4
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/{StateMachine-70bbb88f.development.esm.js → StateMachine-24c5e3f9.development.esm.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-41508d62.development.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
4
4
|
return (src, options) => {
|
|
@@ -316,6 +316,9 @@ class StateNode {
|
|
|
316
316
|
}
|
|
317
317
|
function validateStateNodeConfig(stateNode) {
|
|
318
318
|
const config = stateNode.config;
|
|
319
|
+
if (stateNode.type === 'history' && !(typeof config.target === 'string' && config.target.trim().length > 0 || Array.isArray(config.target) && config.target.length > 0 && config.target.every(target => typeof target === 'string' && target.trim().length > 0))) {
|
|
320
|
+
throw new Error(`History state "${stateNode.id}" must declare a non-empty \`target\`.` );
|
|
321
|
+
}
|
|
319
322
|
if (stateNode.type !== 'choice') {
|
|
320
323
|
if (config.choice !== undefined) {
|
|
321
324
|
throw new Error(`State "${stateNode.id}" has \`choice\`, but \`choice\` can only be used with \`type: 'choice'\`.`);
|
package/dist/{StateMachine-89f725ff.development.cjs.js → StateMachine-673e9a91.development.cjs.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-c55fff73.development.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
6
6
|
return (src, options) => {
|
|
@@ -318,6 +318,9 @@ class StateNode {
|
|
|
318
318
|
}
|
|
319
319
|
function validateStateNodeConfig(stateNode) {
|
|
320
320
|
const config = stateNode.config;
|
|
321
|
+
if (stateNode.type === 'history' && !(typeof config.target === 'string' && config.target.trim().length > 0 || Array.isArray(config.target) && config.target.length > 0 && config.target.every(target => typeof target === 'string' && target.trim().length > 0))) {
|
|
322
|
+
throw new Error(`History state "${stateNode.id}" must declare a non-empty \`target\`.` );
|
|
323
|
+
}
|
|
321
324
|
if (stateNode.type !== 'choice') {
|
|
322
325
|
if (config.choice !== undefined) {
|
|
323
326
|
throw new Error(`State "${stateNode.id}" has \`choice\`, but \`choice\` can only be used with \`type: 'choice'\`.`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-
|
|
1
|
+
import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-d33c7b85.esm.js';
|
|
2
2
|
|
|
3
3
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
4
4
|
return (src, options) => {
|
|
@@ -315,6 +315,9 @@ class StateNode {
|
|
|
315
315
|
}
|
|
316
316
|
function validateStateNodeConfig(stateNode) {
|
|
317
317
|
const config = stateNode.config;
|
|
318
|
+
if (stateNode.type === 'history' && !(typeof config.target === 'string' && config.target.trim().length > 0 || Array.isArray(config.target) && config.target.length > 0 && config.target.every(target => typeof target === 'string' && target.trim().length > 0))) {
|
|
319
|
+
throw new Error(`Missing history target on "${stateNode.id}"`);
|
|
320
|
+
}
|
|
318
321
|
if (stateNode.type !== 'choice') {
|
|
319
322
|
return;
|
|
320
323
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var dist_xstateActors = require('./index-b228b8b6.cjs.js');
|
|
4
4
|
|
|
5
5
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
6
6
|
return (src, options) => {
|
|
@@ -317,6 +317,9 @@ class StateNode {
|
|
|
317
317
|
}
|
|
318
318
|
function validateStateNodeConfig(stateNode) {
|
|
319
319
|
const config = stateNode.config;
|
|
320
|
+
if (stateNode.type === 'history' && !(typeof config.target === 'string' && config.target.trim().length > 0 || Array.isArray(config.target) && config.target.length > 0 && config.target.every(target => typeof target === 'string' && target.trim().length > 0))) {
|
|
321
|
+
throw new Error(`Missing history target on "${stateNode.id}"`);
|
|
322
|
+
}
|
|
320
323
|
if (stateNode.type !== 'choice') {
|
|
321
324
|
return;
|
|
322
325
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import { AnyActorRef, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValue, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId, Compute } from "./types.js";
|
|
4
|
-
import { Sources, DelayMapFromNames, InferChildren, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
4
|
+
import { Sources, DelayMapFromNames, InferChildren, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateHistoryDefaults, ValidateStateTargets, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
5
5
|
type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
|
|
6
6
|
/**
|
|
7
7
|
* Creates a state machine (statechart) with the given configuration.
|
|
@@ -45,7 +45,7 @@ type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TA
|
|
|
45
45
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
46
46
|
* to provide machine sources instead.
|
|
47
47
|
*/
|
|
48
|
-
export declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TDelays extends string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, TInput, const TSS extends StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
48
|
+
export declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TDelays extends string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, TInput, const TSS extends StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & Next_MachineConfig<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
49
49
|
schemas: {
|
|
50
50
|
context: TContextSchema;
|
|
51
51
|
children?: TChildrenSchemaMap;
|
|
@@ -58,7 +58,7 @@ TSS, // TStateSchema
|
|
|
58
58
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
59
59
|
states: TSS;
|
|
60
60
|
};
|
|
61
|
-
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = Sources['actions'], TActorMap extends Sources['actors'] = Sources['actors'], TGuardMap extends Sources['guards'] = Sources['guards'], TDelayMap extends Sources['delays'] = Sources['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
|
|
61
|
+
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = Sources['actions'], TActorMap extends Sources['actors'] = Sources['actors'], TGuardMap extends Sources['guards'] = Sources['guards'], TDelayMap extends Sources['delays'] = Sources['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
|
|
62
62
|
schemas?: {
|
|
63
63
|
context?: never;
|
|
64
64
|
};
|
|
@@ -172,7 +172,7 @@ export interface StateNodeJSON {
|
|
|
172
172
|
timeout?: number | string | ResolvableJSON;
|
|
173
173
|
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
174
174
|
history?: 'shallow' | 'deep';
|
|
175
|
-
target?: string;
|
|
175
|
+
target?: string | [string, ...string[]];
|
|
176
176
|
output?: unknown;
|
|
177
177
|
context?: Record<string, unknown>;
|
|
178
178
|
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
@@ -4,7 +4,7 @@ import { type Actor, type RequiredActorOptionsKeys } from "./createActor.js";
|
|
|
4
4
|
import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute, EnqueueObject, DoneActorEvent, DoneStateEvent, ErrorActorEvent, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg, SnapshotEvent, SingleOrArray, AfterEvent, TimeoutEvent, ErrorEvent } from "./types.js";
|
|
5
5
|
import { AnyActorSystem } from "./system.js";
|
|
6
6
|
import { InspectionEvent } from "./inspection.js";
|
|
7
|
-
import { ActionSchemas, DelayMapFromNames, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferOutput, InferEvents, Next_MachineConfig, Next_InvokeConfig, Next_StateNodeConfig, Next_TransitionConfigOrTarget, WithDefault } from "./types.v6.js";
|
|
7
|
+
import { ActionSchemas, DelayMapFromNames, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferOutput, InferEvents, Next_MachineConfig, Next_InvokeConfig, Next_StateNodeConfig, Next_TransitionConfigOrTarget, ValidateHistoryDefaults, ValidateStateTargets, WithDefault } from "./types.v6.js";
|
|
8
8
|
export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays']> = {
|
|
9
9
|
schemas?: TSchemas & SetupSchemas;
|
|
10
10
|
states?: TStates;
|
|
@@ -382,7 +382,7 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
|
|
|
382
382
|
guards?: TGuardMap;
|
|
383
383
|
delays?: TDelayMap;
|
|
384
384
|
states?: Record<TStateKeys, unknown>;
|
|
385
|
-
} & TConfig & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeSourceMaps<TSetupActorMap, TActorMap>>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
385
|
+
} & TConfig & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateHistoryDefaults<TConfig> & ValidateStateTargets<TConfig> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeSourceMaps<TSetupActorMap, TActorMap>>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
386
386
|
type: 'xstate.route';
|
|
387
387
|
to: RoutableStateId<Cast<TConfig, StateSchema>>;
|
|
388
388
|
}), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
|
|
@@ -418,7 +418,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
418
418
|
/** A text description of the state node */
|
|
419
419
|
description?: string;
|
|
420
420
|
/** A default target for a history state */
|
|
421
|
-
target?: string | undefined;
|
|
421
|
+
target?: string | string[] | undefined;
|
|
422
422
|
}
|
|
423
423
|
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TInput = undefined> = undefined | {
|
|
424
424
|
matches?: EventPayloadPattern<TExpressionEvent>;
|
|
@@ -467,4 +467,164 @@ type InvalidDelayReferences<TConfig, TDelays extends string> = (TConfig extends
|
|
|
467
467
|
[K in keyof TStates]: InvalidDelayReferences<TStates[K], TDelays>;
|
|
468
468
|
}[keyof TStates] : never : never);
|
|
469
469
|
export type ValidateDelayReferences<TConfig> = string extends DelayNamesFromConfig<TConfig> ? unknown : InvalidDelayReferences<TConfig, DelayNamesFromConfig<TConfig>> extends never ? unknown : never;
|
|
470
|
+
type IsHistoryStateConfig<TConfig> = TConfig extends {
|
|
471
|
+
type: 'history';
|
|
472
|
+
} ? true : TConfig extends {
|
|
473
|
+
history: false | undefined;
|
|
474
|
+
} ? false : TConfig extends {
|
|
475
|
+
history: unknown;
|
|
476
|
+
} ? true : false;
|
|
477
|
+
type MissingHistoryDefault<TConfig> = 0 extends 1 & TConfig ? never : IsHistoryStateConfig<TConfig> extends true ? TConfig extends {
|
|
478
|
+
target: string | readonly [string, ...string[]];
|
|
479
|
+
} ? never : true : TConfig extends {
|
|
480
|
+
states: infer TStates;
|
|
481
|
+
} ? TStates extends Record<string, unknown> ? {
|
|
482
|
+
[K in keyof TStates]: MissingHistoryDefault<TStates[K]>;
|
|
483
|
+
}[keyof TStates] : never : never;
|
|
484
|
+
/**
|
|
485
|
+
* Rejects authored machines containing a history state without its SCXML
|
|
486
|
+
* default target.
|
|
487
|
+
*/
|
|
488
|
+
export type ValidateHistoryDefaults<TConfig> = MissingHistoryDefault<TConfig> extends never ? unknown : never;
|
|
489
|
+
type StatePath = readonly string[];
|
|
490
|
+
type AppendStatePath<TPrefix extends StatePath, TKey extends string> = [
|
|
491
|
+
...TPrefix,
|
|
492
|
+
TKey
|
|
493
|
+
];
|
|
494
|
+
type EscapeStatePathDots<TValue extends string> = TValue extends `${infer THead}.${infer TTail}` ? `${THead}\\.${EscapeStatePathDots<TTail>}` : TValue;
|
|
495
|
+
type ProtectEscapedStatePathDots<TValue extends string> = TValue extends `${infer THead}\\.${infer TTail}` ? `${THead}__XSTATE_ESCAPED_DOT__${ProtectEscapedStatePathDots<TTail>}` : TValue;
|
|
496
|
+
type RestoreEscapedStatePathDots<TValue extends string> = TValue extends `${infer THead}__XSTATE_ESCAPED_DOT__${infer TTail}` ? `${THead}.${RestoreEscapedStatePathDots<TTail>}` : TValue;
|
|
497
|
+
type SplitStatePath<TPath extends string> = ProtectEscapedStatePathDots<TPath> extends infer TProtected extends string ? TProtected extends '' ? [] : TProtected extends `${infer THead}.${infer TTail}` ? [RestoreEscapedStatePathDots<THead>, ...SplitStatePath<TTail>] : [RestoreEscapedStatePathDots<TProtected>] : never;
|
|
498
|
+
type ParentStatePath<TPath extends StatePath> = TPath extends readonly [
|
|
499
|
+
...infer TParent extends string[],
|
|
500
|
+
string
|
|
501
|
+
] ? TParent : [];
|
|
502
|
+
type StatePathsFromStates<TStates, TPrefix extends StatePath = []> = TStates extends Record<string, unknown> ? {
|
|
503
|
+
[K in keyof TStates & string]: AppendStatePath<TPrefix, K> | (0 extends 1 & TStates[K] ? never : TStates[K] extends {
|
|
504
|
+
states: infer TChildren;
|
|
505
|
+
} ? StatePathsFromStates<TChildren, AppendStatePath<TPrefix, K>> : never);
|
|
506
|
+
}[keyof TStates & string] : never;
|
|
507
|
+
type AuthoredStatePaths<TConfig> = TConfig extends {
|
|
508
|
+
states: infer TStates;
|
|
509
|
+
} ? StatePathsFromStates<TStates> : never;
|
|
510
|
+
type OpaqueStatePathsFromStates<TStates, TPrefix extends StatePath = []> = TStates extends Record<string, unknown> ? {
|
|
511
|
+
[K in keyof TStates & string]: 0 extends 1 & TStates[K] ? AppendStatePath<TPrefix, K> : TStates[K] extends {
|
|
512
|
+
states: infer TChildren;
|
|
513
|
+
} ? OpaqueStatePathsFromStates<TChildren, AppendStatePath<TPrefix, K>> : never;
|
|
514
|
+
}[keyof TStates & string] : never;
|
|
515
|
+
type OpaqueStatePaths<TConfig> = TConfig extends {
|
|
516
|
+
states: infer TStates;
|
|
517
|
+
} ? OpaqueStatePathsFromStates<TStates> : never;
|
|
518
|
+
type IsWithinStatePath<TPath extends StatePath, TAncestor> = TAncestor extends StatePath ? TPath extends readonly [...TAncestor, ...string[]] ? true : false : false;
|
|
519
|
+
type JoinStateTargetString<TPrefix extends string, TKey extends string> = TPrefix extends '' ? TKey : `${TPrefix}.${TKey}`;
|
|
520
|
+
type StateTargetStringsFromStates<TStates, TPrefix extends string = ''> = TStates extends Record<string, unknown> ? {
|
|
521
|
+
[K in keyof TStates & string]: JoinStateTargetString<TPrefix, EscapeStatePathDots<K>> | (0 extends 1 & TStates[K] ? never : TStates[K] extends {
|
|
522
|
+
states: infer TChildren;
|
|
523
|
+
} ? StateTargetStringsFromStates<TChildren, JoinStateTargetString<TPrefix, EscapeStatePathDots<K>>> : never);
|
|
524
|
+
}[keyof TStates & string] : never;
|
|
525
|
+
type IdTargetsForNode<TNode> = TNode extends {
|
|
526
|
+
id: infer TId extends string;
|
|
527
|
+
} ? string extends TId ? never : TNode extends {
|
|
528
|
+
states: infer TStates;
|
|
529
|
+
} ? `#${EscapeStatePathDots<TId>}` | `#${EscapeStatePathDots<TId>}.${StateTargetStringsFromStates<TStates>}` : `#${EscapeStatePathDots<TId>}` : never;
|
|
530
|
+
type IdTargetsFromStates<TStates> = TStates extends Record<string, unknown> ? {
|
|
531
|
+
[K in keyof TStates & string]: IdTargetsForNode<TStates[K]> | (0 extends 1 & TStates[K] ? never : TStates[K] extends {
|
|
532
|
+
states: infer TChildren;
|
|
533
|
+
} ? IdTargetsFromStates<TChildren> : never);
|
|
534
|
+
}[keyof TStates & string] : never;
|
|
535
|
+
type AuthoredIdTargets<TConfig> = IdTargetsForNode<TConfig> | (TConfig extends {
|
|
536
|
+
states: infer TStates;
|
|
537
|
+
} ? IdTargetsFromStates<TStates> : never);
|
|
538
|
+
type ResolveIdTargetAtNode<TNode, TNodePath extends StatePath, TTarget extends string> = TNode extends {
|
|
539
|
+
id: infer TId extends string;
|
|
540
|
+
} ? string extends TId ? never : TTarget extends `#${EscapeStatePathDots<TId>}` ? TNodePath : TTarget extends `#${EscapeStatePathDots<TId>}.${infer TDescendant}` ? [...TNodePath, ...SplitStatePath<TDescendant>] : never : never;
|
|
541
|
+
type ResolveIdTargetInStates<TStates, TTarget extends string, TPrefix extends StatePath = []> = TStates extends Record<string, unknown> ? {
|
|
542
|
+
[K in keyof TStates & string]: ResolveIdTargetAtNode<TStates[K], AppendStatePath<TPrefix, K>, TTarget> | (0 extends 1 & TStates[K] ? never : TStates[K] extends {
|
|
543
|
+
states: infer TChildren;
|
|
544
|
+
} ? ResolveIdTargetInStates<TChildren, TTarget, AppendStatePath<TPrefix, K>> : never);
|
|
545
|
+
}[keyof TStates & string] : never;
|
|
546
|
+
type ResolveIdTargetPath<TConfig, TTarget extends string> = ResolveIdTargetAtNode<TConfig, [], TTarget> | (TConfig extends {
|
|
547
|
+
states: infer TStates;
|
|
548
|
+
} ? ResolveIdTargetInStates<TStates, TTarget> : never);
|
|
549
|
+
type ResolveAuthoredTarget<TSourcePath extends StatePath, TTarget extends string> = TTarget extends `#${string}` ? never : TTarget extends '.' ? TSourcePath : TTarget extends `.${infer TDescendant}` ? [...TSourcePath, ...SplitStatePath<TDescendant>] : [...ParentStatePath<TSourcePath>, ...SplitStatePath<TTarget>];
|
|
550
|
+
type StateNodeAtPath<TConfig, TPath extends StatePath> = TConfig extends {
|
|
551
|
+
states: infer TStates;
|
|
552
|
+
} ? TPath extends readonly [
|
|
553
|
+
infer THead extends string,
|
|
554
|
+
...infer TTail extends string[]
|
|
555
|
+
] ? THead extends keyof TStates ? TTail extends [] ? TStates[THead] : StateNodeAtPath<TStates[THead], TTail> : never : TConfig : never;
|
|
556
|
+
type CommonStatePathSegments<TLeft extends readonly string[], TRight extends readonly string[], TCommon extends readonly string[] = []> = TLeft extends readonly [
|
|
557
|
+
infer TLeftHead extends string,
|
|
558
|
+
...infer TLeftTail extends string[]
|
|
559
|
+
] ? TRight extends readonly [
|
|
560
|
+
infer TRightHead extends string,
|
|
561
|
+
...infer TRightTail extends string[]
|
|
562
|
+
] ? TLeftHead extends TRightHead ? CommonStatePathSegments<TLeftTail, TRightTail, [...TCommon, TLeftHead]> : TCommon : TCommon : TCommon;
|
|
563
|
+
type NearestCommonStatePath<TLeft extends StatePath, TRight extends StatePath> = CommonStatePathSegments<TLeft, TRight>;
|
|
564
|
+
type IsAncestorStatePath<TAncestor extends StatePath, TDescendant extends StatePath> = TDescendant extends readonly [...TAncestor, ...infer TRest] ? TRest extends [] ? false : true : false;
|
|
565
|
+
type IsParallelStatePath<TConfig, TPath extends StatePath> = TPath extends readonly [] ? TConfig extends {
|
|
566
|
+
type: 'parallel';
|
|
567
|
+
} ? true : false : StateNodeAtPath<TConfig, TPath> extends {
|
|
568
|
+
type: 'parallel';
|
|
569
|
+
} ? true : false;
|
|
570
|
+
type ResolvedAuthoredTargetPath<TRootConfig, TSourcePath extends StatePath, TTarget> = TTarget extends string ? TTarget extends `#${string}` ? ResolveIdTargetPath<TRootConfig, TTarget> : ResolveAuthoredTarget<TSourcePath, TTarget> : never;
|
|
571
|
+
type InvalidTargetPair<TRootConfig, TLeftPath extends StatePath, TRightPath extends StatePath> = TLeftPath extends TRightPath ? TRightPath extends TLeftPath ? true : never : IsAncestorStatePath<TLeftPath, TRightPath> extends true ? true : IsAncestorStatePath<TRightPath, TLeftPath> extends true ? true : IsParallelStatePath<TRootConfig, NearestCommonStatePath<TLeftPath, TRightPath>> extends true ? never : true;
|
|
572
|
+
type InvalidTargetPairsWithHead<TRootConfig, TSourcePath extends StatePath, THead, TRest extends readonly unknown[]> = TRest extends readonly [infer TNext, ...infer TTail] ? (ResolvedAuthoredTargetPath<TRootConfig, TSourcePath, THead> extends infer THeadPath extends StatePath ? ResolvedAuthoredTargetPath<TRootConfig, TSourcePath, TNext> extends infer TNextPath extends StatePath ? InvalidTargetPair<TRootConfig, THeadPath, TNextPath> : never : never) | InvalidTargetPairsWithHead<TRootConfig, TSourcePath, THead, TTail> : never;
|
|
573
|
+
type InvalidTargetSet<TRootConfig, TSourcePath extends StatePath, TTargets> = TTargets extends readonly [infer THead, ...infer TRest] ? InvalidTargetPairsWithHead<TRootConfig, TSourcePath, THead, TRest> | InvalidTargetSet<TRootConfig, TSourcePath, TRest> : never;
|
|
574
|
+
type InvalidTargetValue<TRootConfig, TSourcePath extends StatePath, TTarget> = TTarget extends string ? string extends TTarget ? never : TTarget extends `#${string}` ? TTarget extends AuthoredIdTargets<TRootConfig> ? never : TTarget : ResolveAuthoredTarget<TSourcePath, TTarget> extends infer TResolvedTarget extends StatePath ? TResolvedTarget extends AuthoredStatePaths<TRootConfig> ? never : true extends IsWithinStatePath<TResolvedTarget, OpaqueStatePaths<TRootConfig>> ? never : TTarget : TTarget : TTarget extends readonly unknown[] ? InvalidTargetValue<TRootConfig, TSourcePath, TTarget[number]> : never;
|
|
575
|
+
type InvalidTransitionTarget<TRootConfig, TSourcePath extends StatePath, TTransition> = 0 extends 1 & TTransition ? never : TTransition extends (...args: any[]) => any ? InvalidTransitionTarget<TRootConfig, TSourcePath, ReturnType<TTransition>> : TTransition extends readonly unknown[] ? InvalidTransitionTarget<TRootConfig, TSourcePath, TTransition[number]> : TTransition extends {
|
|
576
|
+
target: infer TTarget;
|
|
577
|
+
} ? InvalidTargetValue<TRootConfig, TSourcePath, TTarget> | InvalidTargetSet<TRootConfig, TSourcePath, TTarget> : never;
|
|
578
|
+
type InvalidTransitionMapTargets<TRootConfig, TSourcePath extends StatePath, TTransitionMap> = 0 extends 1 & TTransitionMap ? never : TTransitionMap extends Record<string, unknown> ? {
|
|
579
|
+
[K in keyof TTransitionMap]: InvalidTransitionTarget<TRootConfig, TSourcePath, TTransitionMap[K]>;
|
|
580
|
+
}[keyof TTransitionMap] : never;
|
|
581
|
+
type InvalidInvokeTargets<TRootConfig, TSourcePath extends StatePath, TInvoke> = 0 extends 1 & TInvoke ? never : TInvoke extends readonly unknown[] ? InvalidInvokeTargets<TRootConfig, TSourcePath, TInvoke[number]> : TInvoke extends Record<string, unknown> ? (TInvoke extends {
|
|
582
|
+
onDone: infer TOnDone;
|
|
583
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnDone> : never) | (TInvoke extends {
|
|
584
|
+
onError: infer TOnError;
|
|
585
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnError> : never) | (TInvoke extends {
|
|
586
|
+
onSnapshot: infer TOnSnapshot;
|
|
587
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnSnapshot> : never) | (TInvoke extends {
|
|
588
|
+
onTimeout: infer TOnTimeout;
|
|
589
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnTimeout> : never) : never;
|
|
590
|
+
type InvalidNodeTargets<TRootConfig, TNode, TSourcePath extends StatePath> = 0 extends 1 & TNode ? never : (TNode extends {
|
|
591
|
+
initial: infer TInitial;
|
|
592
|
+
states: infer TChildStates;
|
|
593
|
+
} ? (TInitial extends {
|
|
594
|
+
target: infer TInitialTarget;
|
|
595
|
+
} ? TInitialTarget : TInitial) extends infer TInitialTarget ? TInitialTarget extends string ? string extends TInitialTarget ? never : TInitialTarget extends keyof TChildStates ? never : TInitialTarget : never : never : never) | (TNode extends {
|
|
596
|
+
on: infer TOn;
|
|
597
|
+
} ? InvalidTransitionMapTargets<TRootConfig, TSourcePath, TOn> : never) | (TNode extends {
|
|
598
|
+
always: infer TAlways;
|
|
599
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TAlways> : never) | (TNode extends {
|
|
600
|
+
choice: infer TChoice;
|
|
601
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TChoice> : never) | (TNode extends {
|
|
602
|
+
after: infer TAfter;
|
|
603
|
+
} ? InvalidTransitionMapTargets<TRootConfig, TSourcePath, TAfter> : never) | (TNode extends {
|
|
604
|
+
onDone: infer TOnDone;
|
|
605
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnDone> : never) | (TNode extends {
|
|
606
|
+
onError: infer TOnError;
|
|
607
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnError> : never) | (TNode extends {
|
|
608
|
+
onTimeout: infer TOnTimeout;
|
|
609
|
+
} ? InvalidTransitionTarget<TRootConfig, TSourcePath, TOnTimeout> : never) | (TNode extends {
|
|
610
|
+
invoke: infer TInvoke;
|
|
611
|
+
} ? InvalidInvokeTargets<TRootConfig, TSourcePath, TInvoke> : never) | (TNode extends {
|
|
612
|
+
target: infer THistoryTarget;
|
|
613
|
+
} ? InvalidTargetValue<TRootConfig, TSourcePath, THistoryTarget> : never);
|
|
614
|
+
type InvalidTargetsInStates<TRootConfig, TStates, TPrefix extends StatePath = []> = TStates extends Record<string, unknown> ? {
|
|
615
|
+
[K in keyof TStates & string]: 0 extends 1 & TStates[K] ? never : InvalidNodeTargets<TRootConfig, TStates[K], AppendStatePath<TPrefix, K>> | (TStates[K] extends {
|
|
616
|
+
states: infer TChildren;
|
|
617
|
+
} ? InvalidTargetsInStates<TRootConfig, TChildren, AppendStatePath<TPrefix, K>> : never);
|
|
618
|
+
}[keyof TStates & string] : never;
|
|
619
|
+
/**
|
|
620
|
+
* Rejects authored literal transition targets that do not resolve in the
|
|
621
|
+
* machine topology.
|
|
622
|
+
*/
|
|
623
|
+
export type ValidateStateTargets<TConfig> = 0 extends 1 & TConfig ? unknown : TConfig extends {
|
|
624
|
+
states: infer TStates;
|
|
625
|
+
} ? (TConfig extends {
|
|
626
|
+
initial: infer TInitial;
|
|
627
|
+
} ? (TInitial extends {
|
|
628
|
+
target: infer TInitialTarget;
|
|
629
|
+
} ? TInitialTarget : TInitial) extends infer TInitialTarget ? TInitialTarget extends string ? string extends TInitialTarget ? never : TInitialTarget extends keyof TStates ? never : TInitialTarget : never : never : never) | InvalidNodeTargets<TConfig, TConfig, []> | InvalidTargetsInStates<TConfig, TStates> extends never ? unknown : never : unknown;
|
|
470
630
|
export {};
|
|
@@ -1285,6 +1285,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1285
1285
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1286
1286
|
const reenter = transitionConfig.reenter ?? false;
|
|
1287
1287
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1288
|
+
assertLegalTargetSet(stateNode, target);
|
|
1288
1289
|
const transition = {
|
|
1289
1290
|
...transitionConfig,
|
|
1290
1291
|
target,
|
|
@@ -1299,6 +1300,41 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1299
1300
|
};
|
|
1300
1301
|
return transition;
|
|
1301
1302
|
}
|
|
1303
|
+
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
1304
|
+
for (let current = stateNode.parent; current; current = current.parent) {
|
|
1305
|
+
if (current === ancestor) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
function getLeastCommonStateNodeAncestor(left, right) {
|
|
1312
|
+
const leftAncestors = new Set();
|
|
1313
|
+
for (let current = left; current; current = current.parent) {
|
|
1314
|
+
leftAncestors.add(current);
|
|
1315
|
+
}
|
|
1316
|
+
for (let current = right; current; current = current.parent) {
|
|
1317
|
+
if (leftAncestors.has(current)) {
|
|
1318
|
+
return current;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return undefined;
|
|
1322
|
+
}
|
|
1323
|
+
function assertLegalTargetSet(source, targets) {
|
|
1324
|
+
if (!targets || targets.length < 2) {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
for (let leftIndex = 0; leftIndex < targets.length; leftIndex++) {
|
|
1328
|
+
for (let rightIndex = leftIndex + 1; rightIndex < targets.length; rightIndex++) {
|
|
1329
|
+
const left = targets[leftIndex];
|
|
1330
|
+
const right = targets[rightIndex];
|
|
1331
|
+
const commonAncestor = getLeastCommonStateNodeAncestor(left, right);
|
|
1332
|
+
if (left === right || isStateNodeDescendantOf(left, right) || isStateNodeDescendantOf(right, left) || commonAncestor?.type !== 'parallel') {
|
|
1333
|
+
throw new Error(`Invalid transition definition for state node '${source.id}': target set is not a legal SCXML configuration.` );
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1302
1338
|
|
|
1303
1339
|
/**
|
|
1304
1340
|
* Collects route transitions from all descendants with explicit IDs. Called
|
|
@@ -1401,8 +1437,10 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
1401
1437
|
}
|
|
1402
1438
|
return stateNode.parent.initial;
|
|
1403
1439
|
}
|
|
1440
|
+
const target = normalizedTarget.map(t => typeof t === 'string' ? getStateNodeByPath(stateNode.parent, t) : t);
|
|
1441
|
+
assertLegalTargetSet(stateNode, target);
|
|
1404
1442
|
return {
|
|
1405
|
-
target
|
|
1443
|
+
target,
|
|
1406
1444
|
source: stateNode,
|
|
1407
1445
|
reenter: false,
|
|
1408
1446
|
eventType: ''
|
|
@@ -1276,6 +1276,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1276
1276
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1277
1277
|
const reenter = transitionConfig.reenter ?? false;
|
|
1278
1278
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1279
|
+
assertLegalTargetSet(stateNode, target);
|
|
1279
1280
|
const transition = {
|
|
1280
1281
|
...transitionConfig,
|
|
1281
1282
|
target,
|
|
@@ -1290,6 +1291,41 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1290
1291
|
};
|
|
1291
1292
|
return transition;
|
|
1292
1293
|
}
|
|
1294
|
+
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
1295
|
+
for (let current = stateNode.parent; current; current = current.parent) {
|
|
1296
|
+
if (current === ancestor) {
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return false;
|
|
1301
|
+
}
|
|
1302
|
+
function getLeastCommonStateNodeAncestor(left, right) {
|
|
1303
|
+
const leftAncestors = new Set();
|
|
1304
|
+
for (let current = left; current; current = current.parent) {
|
|
1305
|
+
leftAncestors.add(current);
|
|
1306
|
+
}
|
|
1307
|
+
for (let current = right; current; current = current.parent) {
|
|
1308
|
+
if (leftAncestors.has(current)) {
|
|
1309
|
+
return current;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return undefined;
|
|
1313
|
+
}
|
|
1314
|
+
function assertLegalTargetSet(source, targets) {
|
|
1315
|
+
if (!targets || targets.length < 2) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
for (let leftIndex = 0; leftIndex < targets.length; leftIndex++) {
|
|
1319
|
+
for (let rightIndex = leftIndex + 1; rightIndex < targets.length; rightIndex++) {
|
|
1320
|
+
const left = targets[leftIndex];
|
|
1321
|
+
const right = targets[rightIndex];
|
|
1322
|
+
const commonAncestor = getLeastCommonStateNodeAncestor(left, right);
|
|
1323
|
+
if (left === right || isStateNodeDescendantOf(left, right) || isStateNodeDescendantOf(right, left) || commonAncestor?.type !== 'parallel') {
|
|
1324
|
+
throw new Error(`Invalid target set for '${source.id}'`);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1293
1329
|
|
|
1294
1330
|
/**
|
|
1295
1331
|
* Collects route transitions from all descendants with explicit IDs. Called
|
|
@@ -1392,8 +1428,10 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
1392
1428
|
}
|
|
1393
1429
|
return stateNode.parent.initial;
|
|
1394
1430
|
}
|
|
1431
|
+
const target = normalizedTarget.map(t => typeof t === 'string' ? getStateNodeByPath(stateNode.parent, t) : t);
|
|
1432
|
+
assertLegalTargetSet(stateNode, target);
|
|
1395
1433
|
return {
|
|
1396
|
-
target
|
|
1434
|
+
target,
|
|
1397
1435
|
source: stateNode,
|
|
1398
1436
|
reenter: false,
|
|
1399
1437
|
eventType: ''
|
|
@@ -1287,6 +1287,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1287
1287
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1288
1288
|
const reenter = transitionConfig.reenter ?? false;
|
|
1289
1289
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1290
|
+
assertLegalTargetSet(stateNode, target);
|
|
1290
1291
|
const transition = {
|
|
1291
1292
|
...transitionConfig,
|
|
1292
1293
|
target,
|
|
@@ -1301,6 +1302,41 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1301
1302
|
};
|
|
1302
1303
|
return transition;
|
|
1303
1304
|
}
|
|
1305
|
+
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
1306
|
+
for (let current = stateNode.parent; current; current = current.parent) {
|
|
1307
|
+
if (current === ancestor) {
|
|
1308
|
+
return true;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1313
|
+
function getLeastCommonStateNodeAncestor(left, right) {
|
|
1314
|
+
const leftAncestors = new Set();
|
|
1315
|
+
for (let current = left; current; current = current.parent) {
|
|
1316
|
+
leftAncestors.add(current);
|
|
1317
|
+
}
|
|
1318
|
+
for (let current = right; current; current = current.parent) {
|
|
1319
|
+
if (leftAncestors.has(current)) {
|
|
1320
|
+
return current;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
return undefined;
|
|
1324
|
+
}
|
|
1325
|
+
function assertLegalTargetSet(source, targets) {
|
|
1326
|
+
if (!targets || targets.length < 2) {
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
for (let leftIndex = 0; leftIndex < targets.length; leftIndex++) {
|
|
1330
|
+
for (let rightIndex = leftIndex + 1; rightIndex < targets.length; rightIndex++) {
|
|
1331
|
+
const left = targets[leftIndex];
|
|
1332
|
+
const right = targets[rightIndex];
|
|
1333
|
+
const commonAncestor = getLeastCommonStateNodeAncestor(left, right);
|
|
1334
|
+
if (left === right || isStateNodeDescendantOf(left, right) || isStateNodeDescendantOf(right, left) || commonAncestor?.type !== 'parallel') {
|
|
1335
|
+
throw new Error(`Invalid transition definition for state node '${source.id}': target set is not a legal SCXML configuration.` );
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1304
1340
|
|
|
1305
1341
|
/**
|
|
1306
1342
|
* Collects route transitions from all descendants with explicit IDs. Called
|
|
@@ -1403,8 +1439,10 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
1403
1439
|
}
|
|
1404
1440
|
return stateNode.parent.initial;
|
|
1405
1441
|
}
|
|
1442
|
+
const target = normalizedTarget.map(t => typeof t === 'string' ? getStateNodeByPath(stateNode.parent, t) : t);
|
|
1443
|
+
assertLegalTargetSet(stateNode, target);
|
|
1406
1444
|
return {
|
|
1407
|
-
target
|
|
1445
|
+
target,
|
|
1408
1446
|
source: stateNode,
|
|
1409
1447
|
reenter: false,
|
|
1410
1448
|
eventType: ''
|
|
@@ -1274,6 +1274,7 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1274
1274
|
const normalizedTarget = normalizeTarget(transitionConfig.target);
|
|
1275
1275
|
const reenter = transitionConfig.reenter ?? false;
|
|
1276
1276
|
const target = resolveTarget(stateNode, normalizedTarget);
|
|
1277
|
+
assertLegalTargetSet(stateNode, target);
|
|
1277
1278
|
const transition = {
|
|
1278
1279
|
...transitionConfig,
|
|
1279
1280
|
target,
|
|
@@ -1288,6 +1289,41 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
|
|
|
1288
1289
|
};
|
|
1289
1290
|
return transition;
|
|
1290
1291
|
}
|
|
1292
|
+
function isStateNodeDescendantOf(stateNode, ancestor) {
|
|
1293
|
+
for (let current = stateNode.parent; current; current = current.parent) {
|
|
1294
|
+
if (current === ancestor) {
|
|
1295
|
+
return true;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return false;
|
|
1299
|
+
}
|
|
1300
|
+
function getLeastCommonStateNodeAncestor(left, right) {
|
|
1301
|
+
const leftAncestors = new Set();
|
|
1302
|
+
for (let current = left; current; current = current.parent) {
|
|
1303
|
+
leftAncestors.add(current);
|
|
1304
|
+
}
|
|
1305
|
+
for (let current = right; current; current = current.parent) {
|
|
1306
|
+
if (leftAncestors.has(current)) {
|
|
1307
|
+
return current;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
return undefined;
|
|
1311
|
+
}
|
|
1312
|
+
function assertLegalTargetSet(source, targets) {
|
|
1313
|
+
if (!targets || targets.length < 2) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
for (let leftIndex = 0; leftIndex < targets.length; leftIndex++) {
|
|
1317
|
+
for (let rightIndex = leftIndex + 1; rightIndex < targets.length; rightIndex++) {
|
|
1318
|
+
const left = targets[leftIndex];
|
|
1319
|
+
const right = targets[rightIndex];
|
|
1320
|
+
const commonAncestor = getLeastCommonStateNodeAncestor(left, right);
|
|
1321
|
+
if (left === right || isStateNodeDescendantOf(left, right) || isStateNodeDescendantOf(right, left) || commonAncestor?.type !== 'parallel') {
|
|
1322
|
+
throw new Error(`Invalid target set for '${source.id}'`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1291
1327
|
|
|
1292
1328
|
/**
|
|
1293
1329
|
* Collects route transitions from all descendants with explicit IDs. Called
|
|
@@ -1390,8 +1426,10 @@ function resolveHistoryDefaultTransition(stateNode) {
|
|
|
1390
1426
|
}
|
|
1391
1427
|
return stateNode.parent.initial;
|
|
1392
1428
|
}
|
|
1429
|
+
const target = normalizedTarget.map(t => typeof t === 'string' ? getStateNodeByPath(stateNode.parent, t) : t);
|
|
1430
|
+
assertLegalTargetSet(stateNode, target);
|
|
1393
1431
|
return {
|
|
1394
|
-
target
|
|
1432
|
+
target,
|
|
1395
1433
|
source: stateNode,
|
|
1396
1434
|
reenter: false,
|
|
1397
1435
|
eventType: ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { T as TimeoutError, H as createAsyncLogic, D as createCallbackLogic, C as createEmptyActor, F as createEventObservableLogic, I as createListenerLogic, G as createLogic, E as createObservableLogic, K as createSubscriptionLogic, J as listenerLogic, L as subscriptionLogic } from './index-
|
|
1
|
+
export { T as TimeoutError, H as createAsyncLogic, D as createCallbackLogic, C as createEmptyActor, F as createEventObservableLogic, I as createListenerLogic, G as createLogic, E as createObservableLogic, K as createSubscriptionLogic, J as listenerLogic, L as subscriptionLogic } from './index-41508d62.development.esm.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { T as TimeoutError, H as createAsyncLogic, D as createCallbackLogic, C as createEmptyActor, F as createEventObservableLogic, I as createListenerLogic, G as createLogic, E as createObservableLogic, K as createSubscriptionLogic, J as listenerLogic, L as subscriptionLogic } from './index-
|
|
1
|
+
export { T as TimeoutError, H as createAsyncLogic, D as createCallbackLogic, C as createEmptyActor, F as createEventObservableLogic, I as createListenerLogic, G as createLogic, E as createObservableLogic, K as createSubscriptionLogic, J as listenerLogic, L as subscriptionLogic } from './index-d33c7b85.esm.js';
|
package/dist/xstate-graph.cjs.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_xstateActors = require('./index-
|
|
6
|
-
var StateMachine = require('./StateMachine-
|
|
5
|
+
var dist_xstateActors = require('./index-b228b8b6.cjs.js');
|
|
6
|
+
var StateMachine = require('./StateMachine-bcb27183.cjs.js');
|
|
7
7
|
|
|
8
8
|
function simpleStringify(value) {
|
|
9
9
|
return JSON.stringify(value);
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var dist_xstateActors = require('./index-
|
|
6
|
-
var StateMachine = require('./StateMachine-
|
|
5
|
+
var dist_xstateActors = require('./index-c55fff73.development.cjs.js');
|
|
6
|
+
var StateMachine = require('./StateMachine-673e9a91.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
function simpleStringify(value) {
|
|
9
9
|
return JSON.stringify(value);
|