xstate 4.35.2 → 5.0.0-alpha.1

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.
Files changed (203) hide show
  1. package/README.md +25 -16
  2. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  3. package/actions/dist/xstate-actions.cjs.dev.js +30 -0
  4. package/actions/dist/xstate-actions.cjs.js +7 -0
  5. package/actions/dist/xstate-actions.cjs.prod.js +30 -0
  6. package/actions/dist/xstate-actions.esm.js +2 -0
  7. package/actions/dist/xstate-actions.umd.min.js +2 -0
  8. package/actions/dist/xstate-actions.umd.min.js.map +1 -0
  9. package/actions/dynamicAction.ts +34 -0
  10. package/actions/package.json +8 -0
  11. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  12. package/actors/dist/xstate-actors.cjs.dev.js +20 -0
  13. package/actors/dist/xstate-actors.cjs.js +7 -0
  14. package/actors/dist/xstate-actors.cjs.prod.js +20 -0
  15. package/actors/dist/xstate-actors.esm.js +2 -0
  16. package/actors/dist/xstate-actors.umd.min.js +2 -0
  17. package/actors/dist/xstate-actors.umd.min.js.map +1 -0
  18. package/actors/package.json +8 -0
  19. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  20. package/dev/dist/xstate-dev.cjs.dev.js +11 -0
  21. package/dev/dist/xstate-dev.cjs.js +7 -0
  22. package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
  23. package/dev/dist/xstate-dev.esm.js +1 -0
  24. package/dev/dist/xstate-dev.umd.min.js +2 -0
  25. package/dev/dist/xstate-dev.umd.min.js.map +1 -0
  26. package/dev/package.json +8 -0
  27. package/dist/actions-7ea9280f.cjs.prod.js +4674 -0
  28. package/dist/actions-b08d0da8.cjs.dev.js +4718 -0
  29. package/dist/actions-b673cb13.esm.js +4660 -0
  30. package/dist/declarations/actions/dynamicAction.d.ts +5 -0
  31. package/dist/declarations/src/Machine.d.ts +4 -0
  32. package/dist/declarations/src/Mailbox.d.ts +12 -0
  33. package/{es → dist/declarations/src}/SimulatedClock.d.ts +16 -17
  34. package/dist/declarations/src/State.d.ts +97 -0
  35. package/dist/declarations/src/StateMachine.d.ts +120 -0
  36. package/dist/declarations/src/StateNode.d.ts +127 -0
  37. package/{es → dist/declarations/src}/actionTypes.d.ts +16 -20
  38. package/dist/declarations/src/actions/assign.d.ts +7 -0
  39. package/dist/declarations/src/actions/cancel.d.ts +10 -0
  40. package/dist/declarations/src/actions/choose.d.ts +3 -0
  41. package/dist/declarations/src/actions/invoke.d.ts +3 -0
  42. package/dist/declarations/src/actions/log.d.ts +11 -0
  43. package/dist/declarations/src/actions/pure.d.ts +3 -0
  44. package/dist/declarations/src/actions/raise.d.ts +9 -0
  45. package/dist/declarations/src/actions/send.d.ts +51 -0
  46. package/dist/declarations/src/actions/stop.d.ts +7 -0
  47. package/dist/declarations/src/actions.d.ts +43 -0
  48. package/dist/declarations/src/actors.d.ts +37 -0
  49. package/dist/declarations/src/constants.d.ts +5 -0
  50. package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +14 -14
  51. package/{es → dist/declarations/src}/environment.d.ts +1 -2
  52. package/dist/declarations/src/guards.d.ts +8 -0
  53. package/dist/declarations/src/index.d.ts +44 -0
  54. package/dist/declarations/src/interpreter.d.ts +108 -0
  55. package/{es → dist/declarations/src}/mapState.d.ts +3 -4
  56. package/dist/declarations/src/memo.d.ts +2 -0
  57. package/dist/declarations/src/registry.d.ts +8 -0
  58. package/{es → dist/declarations/src}/schema.d.ts +2 -3
  59. package/dist/declarations/src/spawn.d.ts +2 -0
  60. package/dist/declarations/src/stateUtils.d.ts +70 -0
  61. package/dist/declarations/src/symbolObservable.d.ts +1 -0
  62. package/{lib → dist/declarations/src}/typegenTypes.d.ts +132 -133
  63. package/dist/declarations/src/types.d.ts +1001 -0
  64. package/dist/declarations/src/utils.d.ts +54 -0
  65. package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
  66. package/dist/index-2a564d03.cjs.dev.js +64 -0
  67. package/dist/xstate.cjs.d.ts +1 -0
  68. package/dist/xstate.cjs.dev.js +993 -0
  69. package/dist/xstate.cjs.js +7 -0
  70. package/dist/xstate.cjs.prod.js +993 -0
  71. package/dist/xstate.esm.js +952 -0
  72. package/dist/xstate.umd.min.js +2 -0
  73. package/dist/xstate.umd.min.js.map +1 -0
  74. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  75. package/guards/dist/xstate-guards.cjs.dev.js +15 -0
  76. package/guards/dist/xstate-guards.cjs.js +7 -0
  77. package/guards/dist/xstate-guards.cjs.prod.js +15 -0
  78. package/guards/dist/xstate-guards.esm.js +2 -0
  79. package/guards/dist/xstate-guards.umd.min.js +2 -0
  80. package/guards/dist/xstate-guards.umd.min.js.map +1 -0
  81. package/guards/package.json +8 -0
  82. package/invoke/package.json +4 -0
  83. package/package.json +44 -30
  84. package/dist/xstate.interpreter.js +0 -15
  85. package/dist/xstate.js +0 -15
  86. package/dist/xstate.web.js +0 -15
  87. package/es/Actor.d.ts +0 -25
  88. package/es/Actor.js +0 -99
  89. package/es/Machine.d.ts +0 -12
  90. package/es/Machine.js +0 -21
  91. package/es/SimulatedClock.js +0 -81
  92. package/es/State.d.ts +0 -123
  93. package/es/State.js +0 -274
  94. package/es/StateNode.d.ts +0 -282
  95. package/es/StateNode.js +0 -1587
  96. package/es/_virtual/_tslib.js +0 -78
  97. package/es/actionTypes.js +0 -22
  98. package/es/actions.d.ts +0 -157
  99. package/es/actions.js +0 -630
  100. package/es/behaviors.d.ts +0 -37
  101. package/es/behaviors.js +0 -131
  102. package/es/constants.d.ts +0 -6
  103. package/es/constants.js +0 -6
  104. package/es/devTools.d.ts +0 -14
  105. package/es/each.d.ts +0 -4
  106. package/es/each.js +0 -13
  107. package/es/environment.js +0 -3
  108. package/es/index.d.ts +0 -22
  109. package/es/index.js +0 -25
  110. package/es/interpreter.d.ts +0 -217
  111. package/es/interpreter.js +0 -1488
  112. package/es/invoke.d.ts +0 -11
  113. package/es/invokeUtils.d.ts +0 -7
  114. package/es/invokeUtils.js +0 -40
  115. package/es/json.d.ts +0 -31
  116. package/es/json.js +0 -86
  117. package/es/mapState.js +0 -32
  118. package/es/match.d.ts +0 -9
  119. package/es/match.js +0 -34
  120. package/es/model.d.ts +0 -8
  121. package/es/model.js +0 -50
  122. package/es/model.types.d.ts +0 -56
  123. package/es/patterns.d.ts +0 -14
  124. package/es/patterns.js +0 -48
  125. package/es/registry.d.ts +0 -9
  126. package/es/registry.js +0 -19
  127. package/es/scheduler.d.ts +0 -17
  128. package/es/scheduler.js +0 -79
  129. package/es/schema.js +0 -6
  130. package/es/scxml.d.ts +0 -6
  131. package/es/serviceScope.d.ts +0 -4
  132. package/es/serviceScope.js +0 -16
  133. package/es/stateUtils.d.ts +0 -18
  134. package/es/stateUtils.js +0 -262
  135. package/es/typegenTypes.d.ts +0 -133
  136. package/es/types.d.ts +0 -1040
  137. package/es/types.js +0 -33
  138. package/es/utils.d.ts +0 -72
  139. package/es/utils.js +0 -622
  140. package/es/waitFor.d.ts +0 -34
  141. package/es/waitFor.js +0 -73
  142. package/lib/Actor.d.ts +0 -25
  143. package/lib/Actor.js +0 -108
  144. package/lib/Machine.d.ts +0 -12
  145. package/lib/Machine.js +0 -26
  146. package/lib/SimulatedClock.d.ts +0 -17
  147. package/lib/SimulatedClock.js +0 -85
  148. package/lib/State.d.ts +0 -123
  149. package/lib/State.js +0 -282
  150. package/lib/StateNode.d.ts +0 -282
  151. package/lib/StateNode.js +0 -1591
  152. package/lib/_virtual/_tslib.js +0 -85
  153. package/lib/actionTypes.d.ts +0 -20
  154. package/lib/actionTypes.js +0 -43
  155. package/lib/actions.d.ts +0 -157
  156. package/lib/actions.js +0 -662
  157. package/lib/behaviors.d.ts +0 -37
  158. package/lib/behaviors.js +0 -137
  159. package/lib/constants.d.ts +0 -6
  160. package/lib/constants.js +0 -13
  161. package/lib/each.d.ts +0 -4
  162. package/lib/each.js +0 -17
  163. package/lib/environment.d.ts +0 -2
  164. package/lib/environment.js +0 -7
  165. package/lib/index.d.ts +0 -22
  166. package/lib/index.js +0 -64
  167. package/lib/interpreter.d.ts +0 -217
  168. package/lib/interpreter.js +0 -1494
  169. package/lib/invoke.d.ts +0 -11
  170. package/lib/invoke.js +0 -20
  171. package/lib/invokeUtils.d.ts +0 -7
  172. package/lib/invokeUtils.js +0 -45
  173. package/lib/json.d.ts +0 -31
  174. package/lib/json.js +0 -94
  175. package/lib/mapState.d.ts +0 -4
  176. package/lib/mapState.js +0 -36
  177. package/lib/match.d.ts +0 -9
  178. package/lib/match.js +0 -38
  179. package/lib/model.d.ts +0 -8
  180. package/lib/model.js +0 -54
  181. package/lib/model.types.d.ts +0 -56
  182. package/lib/model.types.js +0 -2
  183. package/lib/patterns.d.ts +0 -14
  184. package/lib/patterns.js +0 -53
  185. package/lib/registry.d.ts +0 -9
  186. package/lib/registry.js +0 -23
  187. package/lib/scheduler.d.ts +0 -17
  188. package/lib/scheduler.js +0 -83
  189. package/lib/schema.d.ts +0 -3
  190. package/lib/schema.js +0 -11
  191. package/lib/scxml.d.ts +0 -6
  192. package/lib/scxml.js +0 -350
  193. package/lib/serviceScope.d.ts +0 -4
  194. package/lib/serviceScope.js +0 -21
  195. package/lib/stateUtils.d.ts +0 -18
  196. package/lib/stateUtils.js +0 -277
  197. package/lib/typegenTypes.js +0 -2
  198. package/lib/types.d.ts +0 -1040
  199. package/lib/types.js +0 -35
  200. package/lib/utils.d.ts +0 -72
  201. package/lib/utils.js +0 -669
  202. package/lib/waitFor.d.ts +0 -34
  203. package/lib/waitFor.js +0 -77
@@ -0,0 +1,54 @@
1
+ import { AnyState } from '.';
2
+ import { NULL_EVENT } from './constants';
3
+ import type { StateNode } from './StateNode';
4
+ import type { Behavior, BehaviorCreator, EventObject, EventType, InvokeConfig, InvokeSourceDefinition, MachineContext, Mapper, Observer, PropertyMapper, SCXML, SCXMLErrorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfig, TransitionConfigTarget } from './types';
5
+ import { AnyStateMachine } from './types';
6
+ export declare function keys<T extends object>(value: T): Array<keyof T & string>;
7
+ export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;
8
+ export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
9
+ export declare function isStateLike(state: any): state is AnyState;
10
+ export declare function toStateValue(stateValue: StateLike<any> | StateValue | string[], delimiter: string): StateValue;
11
+ export declare function pathToStateValue(statePath: string[]): StateValue;
12
+ export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
13
+ [key in keyof O]: P;
14
+ };
15
+ export declare function mapFilterValues<T, P>(collection: {
16
+ [key: string]: T;
17
+ }, iteratee: (item: T, key: string, collection: {
18
+ [key: string]: T;
19
+ }) => P, predicate: (item: T) => boolean): {
20
+ [key: string]: P;
21
+ };
22
+ /**
23
+ * Retrieves a value at the given path.
24
+ * @param props The deep path to the prop of the desired value
25
+ */
26
+ export declare function path<T extends Record<string, any>>(props: string[]): any;
27
+ export declare function toStatePaths(stateValue: StateValue | undefined): string[][];
28
+ export declare function flatten<T>(array: Array<T | T[]>): T[];
29
+ export declare function toArrayStrict<T>(value: T[] | T): T[];
30
+ export declare function toArray<T>(value: T[] | T | undefined): T[];
31
+ export declare function mapContext<TContext extends MachineContext, TEvent extends EventObject>(mapper: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>, context: TContext, _event: SCXML.Event<TEvent>): any;
32
+ export declare function isBuiltInEvent(eventType: EventType): boolean;
33
+ export declare function isPromiseLike(value: any): value is PromiseLike<any>;
34
+ export declare function isBehavior(value: any): value is Behavior<any, any>;
35
+ export declare function partition<T, A extends T, B extends T>(items: T[], predicate: (item: T) => item is A): [A[], B[]];
36
+ export declare let warn: (condition: boolean | Error, message: string) => void;
37
+ export declare function isArray(value: any): value is any[];
38
+ export declare function isFunction(value: any): value is Function;
39
+ export declare function isString(value: any): value is string;
40
+ export declare function isObservable<T>(value: any): value is Subscribable<T>;
41
+ export declare function isStateMachine(value: any): value is AnyStateMachine;
42
+ export declare const uniqueId: () => string;
43
+ export declare function isSCXMLEvent<TEvent extends EventObject>(event: TEvent | SCXML.Event<TEvent>): event is SCXML.Event<TEvent>;
44
+ export declare function isSCXMLErrorEvent(event: SCXML.Event<any>): event is SCXMLErrorEvent;
45
+ export declare function toSCXMLEvent<TEvent extends EventObject>(event: TEvent | SCXML.Event<TEvent>, scxmlEvent?: Partial<SCXML.Event<TEvent>>): SCXML.Event<TEvent>;
46
+ export declare function toTransitionConfigArray<TContext extends MachineContext, TEvent extends EventObject>(event: TEvent['type'] | typeof NULL_EVENT | '*', configLike: SingleOrArray<TransitionConfig<TContext, TEvent> | TransitionConfigTarget<TContext, TEvent>>): Array<TransitionConfig<TContext, TEvent> & {
47
+ event: TEvent['type'] | typeof NULL_EVENT | '*';
48
+ }>;
49
+ export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): Array<string | StateNode<TContext, TEvent>> | undefined;
50
+ export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
51
+ export declare function toInvokeConfig<TContext extends MachineContext, TEvent extends EventObject>(invocable: InvokeConfig<TContext, TEvent> | string | BehaviorCreator<TContext, TEvent> | Behavior<any, any>, id: string): InvokeConfig<TContext, TEvent>;
52
+ export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
53
+ export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
54
+ export declare function createInvokeId(stateNodeId: string, index: number): string;
@@ -1,5 +1,6 @@
1
- import { IS_PRODUCTION } from './environment.js';
1
+ var IS_PRODUCTION = process.env.NODE_ENV === 'production';
2
2
 
3
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
3
4
  function getGlobal() {
4
5
  if (typeof globalThis !== 'undefined') {
5
6
  return globalThis;
@@ -23,17 +24,17 @@ function getGlobal() {
23
24
  }
24
25
 
25
26
  function getDevTools() {
26
- var global = getGlobal();
27
+ var w = getGlobal();
27
28
 
28
- if (global && '__xstate__' in global) {
29
- return global.__xstate__;
29
+ if (!!w.__xstate__) {
30
+ return w.__xstate__;
30
31
  }
31
32
 
32
33
  return undefined;
33
34
  }
34
35
 
35
36
  function registerService(service) {
36
- if (!getGlobal()) {
37
+ if (typeof window === 'undefined') {
37
38
  return;
38
39
  }
39
40
 
@@ -43,5 +44,16 @@ function registerService(service) {
43
44
  devTools.register(service);
44
45
  }
45
46
  }
47
+ var devToolsAdapter = function devToolsAdapter(service) {
48
+ if (typeof window === 'undefined') {
49
+ return;
50
+ }
51
+
52
+ var devTools = getDevTools();
53
+
54
+ if (devTools) {
55
+ devTools.register(service);
56
+ }
57
+ };
46
58
 
47
- export { getGlobal, registerService };
59
+ export { IS_PRODUCTION as I, devToolsAdapter as d, getGlobal as g, registerService as r };
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ var IS_PRODUCTION = process.env.NODE_ENV === 'production';
4
+
5
+ // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6
+ function getGlobal() {
7
+ if (typeof globalThis !== 'undefined') {
8
+ return globalThis;
9
+ }
10
+
11
+ if (typeof self !== 'undefined') {
12
+ return self;
13
+ }
14
+
15
+ if (typeof window !== 'undefined') {
16
+ return window;
17
+ }
18
+
19
+ if (typeof global !== 'undefined') {
20
+ return global;
21
+ }
22
+
23
+ if (!IS_PRODUCTION) {
24
+ console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
25
+ }
26
+ }
27
+
28
+ function getDevTools() {
29
+ var w = getGlobal();
30
+
31
+ if (!!w.__xstate__) {
32
+ return w.__xstate__;
33
+ }
34
+
35
+ return undefined;
36
+ }
37
+
38
+ function registerService(service) {
39
+ if (typeof window === 'undefined') {
40
+ return;
41
+ }
42
+
43
+ var devTools = getDevTools();
44
+
45
+ if (devTools) {
46
+ devTools.register(service);
47
+ }
48
+ }
49
+ var devToolsAdapter = function devToolsAdapter(service) {
50
+ if (typeof window === 'undefined') {
51
+ return;
52
+ }
53
+
54
+ var devTools = getDevTools();
55
+
56
+ if (devTools) {
57
+ devTools.register(service);
58
+ }
59
+ };
60
+
61
+ exports.IS_PRODUCTION = IS_PRODUCTION;
62
+ exports.devToolsAdapter = devToolsAdapter;
63
+ exports.getGlobal = getGlobal;
64
+ exports.registerService = registerService;
@@ -0,0 +1 @@
1
+ export * from "./declarations/src/index";