@zag-js/core 1.34.1 → 1.35.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.
- package/README.md +97 -49
- package/dist/create-machine.d.mts +19 -0
- package/dist/create-machine.d.ts +19 -0
- package/dist/create-machine.js +70 -0
- package/dist/create-machine.mjs +43 -0
- package/dist/index.d.mts +7 -257
- package/dist/index.d.ts +7 -257
- package/dist/index.js +31 -137
- package/dist/index.mjs +7 -131
- package/dist/memo.d.mts +6 -0
- package/dist/memo.d.ts +6 -0
- package/dist/memo.js +43 -0
- package/dist/memo.mjs +18 -0
- package/dist/merge-props.d.mts +8 -0
- package/dist/merge-props.d.ts +8 -0
- package/dist/merge-props.js +80 -0
- package/dist/merge-props.mjs +55 -0
- package/dist/scope.d.mts +15 -0
- package/dist/scope.d.ts +15 -0
- package/dist/scope.js +46 -0
- package/dist/scope.mjs +21 -0
- package/dist/state.d.mts +25 -0
- package/dist/state.d.ts +25 -0
- package/dist/state.js +201 -0
- package/dist/state.mjs +169 -0
- package/dist/types.d.mts +234 -0
- package/dist/types.d.ts +234 -0
- package/dist/types.js +38 -0
- package/dist/types.mjs +12 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,18 +5,18 @@ machines** with addition of extra features we need for our components.
|
|
|
5
5
|
|
|
6
6
|
## Features
|
|
7
7
|
|
|
8
|
-
- Finite states (
|
|
8
|
+
- Finite states with optional nested (hierarchical) states
|
|
9
9
|
- Initial state
|
|
10
10
|
- Transitions (object or strings)
|
|
11
11
|
- Context
|
|
12
12
|
- Entry actions
|
|
13
13
|
- Exit actions
|
|
14
|
-
- Delayed timeout actions (basically `setTimeout`)
|
|
15
|
-
- Delayed interval actions (basically `setInterval`)
|
|
16
14
|
- Transition actions
|
|
15
|
+
- Effects
|
|
17
16
|
- Boolean guard helpers (`and`, `or`, `not`)
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
|
|
18
|
+
> Note: The core package is intentionally minimal. It doesn't include delayed transitions, interval scheduling, spawn
|
|
19
|
+
> helpers, or activities. Use actions/effects to perform side effects.
|
|
20
20
|
|
|
21
21
|
> To better understand the state machines, we strongly recommend going though the
|
|
22
22
|
> [xstate docs](https://xstate.js.org/docs/) and videos. It'll give you the foundations you need.
|
|
@@ -46,34 +46,101 @@ const toggleMachine = createMachine({
|
|
|
46
46
|
active: { on: { TOGGLE: "inactive" } },
|
|
47
47
|
},
|
|
48
48
|
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Usage (service via adapter):**
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { createMachine } from "@zag-js/core"
|
|
55
|
+
import { VanillaMachine } from "@zag-js/vanilla"
|
|
56
|
+
|
|
57
|
+
const machine = createMachine({
|
|
58
|
+
initialState() {
|
|
59
|
+
return "inactive"
|
|
60
|
+
},
|
|
61
|
+
states: {
|
|
62
|
+
inactive: { on: { TOGGLE: "active" } },
|
|
63
|
+
active: { on: { TOGGLE: "inactive" } },
|
|
64
|
+
},
|
|
65
|
+
})
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
const service = new VanillaMachine(machine)
|
|
68
|
+
service.start()
|
|
52
69
|
|
|
53
|
-
|
|
54
|
-
console.log(
|
|
70
|
+
service.subscribe(() => {
|
|
71
|
+
console.log(service.state.get())
|
|
72
|
+
})
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
service.send({ type: "TOGGLE" })
|
|
75
|
+
service.send({ type: "TOGGLE" })
|
|
76
|
+
service.stop()
|
|
58
77
|
```
|
|
59
78
|
|
|
60
|
-
|
|
79
|
+
### Nested states (dot notation)
|
|
61
80
|
|
|
62
|
-
```
|
|
81
|
+
```ts
|
|
63
82
|
import { createMachine } from "@zag-js/core"
|
|
64
83
|
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
const machine = createMachine({
|
|
85
|
+
initialState() {
|
|
86
|
+
return "dialog"
|
|
87
|
+
},
|
|
88
|
+
states: {
|
|
89
|
+
dialog: {
|
|
90
|
+
tags: ["overlay"],
|
|
91
|
+
initial: "closed",
|
|
92
|
+
states: {
|
|
93
|
+
closed: { on: { OPEN: { target: "dialog.open" } } },
|
|
94
|
+
open: { on: { CLOSE: { target: "dialog.closed" } } },
|
|
95
|
+
},
|
|
96
|
+
// parent-level transitions still work
|
|
97
|
+
on: { RESET: { target: "dialog.closed" } },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
70
100
|
})
|
|
71
101
|
|
|
72
|
-
|
|
73
|
-
toggleService.send("TOGGLE")
|
|
74
|
-
toggleService.stop()
|
|
102
|
+
// service.state.matches("dialog.open") === true when nested state is active
|
|
75
103
|
```
|
|
76
104
|
|
|
105
|
+
### State IDs and `#id` targets
|
|
106
|
+
|
|
107
|
+
Use `id` on a state node when you want to target it explicitly from anywhere in the machine.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { createMachine } from "@zag-js/core"
|
|
111
|
+
|
|
112
|
+
const machine = createMachine({
|
|
113
|
+
initialState() {
|
|
114
|
+
return "dialog"
|
|
115
|
+
},
|
|
116
|
+
states: {
|
|
117
|
+
dialog: {
|
|
118
|
+
initial: "open",
|
|
119
|
+
states: {
|
|
120
|
+
focused: {
|
|
121
|
+
id: "dialogFocused",
|
|
122
|
+
},
|
|
123
|
+
open: {
|
|
124
|
+
initial: "idle",
|
|
125
|
+
states: {
|
|
126
|
+
idle: {
|
|
127
|
+
on: {
|
|
128
|
+
CLOSE: { target: "#dialogFocused" },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Notes:
|
|
140
|
+
|
|
141
|
+
- `#id` targets resolve by state node `id` (XState-style).
|
|
142
|
+
- State IDs must be unique within a machine.
|
|
143
|
+
|
|
77
144
|
## API
|
|
78
145
|
|
|
79
146
|
### `createMachine(config, options)`
|
|
@@ -87,39 +154,20 @@ Creates a new finite state machine from the config.
|
|
|
87
154
|
|
|
88
155
|
**Returns:**
|
|
89
156
|
|
|
90
|
-
A
|
|
91
|
-
|
|
92
|
-
- `machine.initialState`: the machine's resolved initial state
|
|
93
|
-
- `machine.start()`: the function to start the machine in the specified initial state.
|
|
94
|
-
- `machine.stop()`: the function to stop the machine completely. It also cleans up all scheduled actions and timeouts.
|
|
95
|
-
- `machine.transition(state, event)`: a transition function that returns the next state given the current `state` and
|
|
96
|
-
`event`. It also performs any delayed, entry or exit side-effects.
|
|
97
|
-
- `machine.send(event)`: a transition function instructs the machine to execute a transition based on the event.
|
|
98
|
-
- `machine.onTransition(fn)`: a function that gets called when the machine transition function instructs the machine to
|
|
99
|
-
execute a transition based on the event.
|
|
100
|
-
- `machine.onChange(fn)`: a function that gets called when the machine's context value changes.
|
|
101
|
-
- `machine.state`: the state object that describes the machine at a specific point in time. It contains the following
|
|
102
|
-
properties:
|
|
103
|
-
- `value`: the current state value
|
|
104
|
-
- `previousValue`: the previous state value
|
|
105
|
-
- `event`: the event that triggered the transition to the current state
|
|
106
|
-
- `nextEvents`: the list of events the machine can respond to at its current state
|
|
107
|
-
- `tags`: the tags associated with this state
|
|
108
|
-
- `done`: whether the machine that reached its final state
|
|
109
|
-
- `context`: the current context value
|
|
110
|
-
- `matches(...)`: a function used to test whether the current state matches one or more state values
|
|
157
|
+
A machine definition object consumed by framework adapters (React, Solid, Svelte, Vue, Preact, Vanilla) to create a
|
|
158
|
+
runtime service.
|
|
111
159
|
|
|
112
160
|
The machine config has this schema:
|
|
113
161
|
|
|
114
162
|
### Machine config
|
|
115
163
|
|
|
116
|
-
- `
|
|
117
|
-
- `
|
|
118
|
-
|
|
119
|
-
- `
|
|
120
|
-
- `
|
|
121
|
-
- `
|
|
122
|
-
|
|
164
|
+
- `initialState` (function) - returns the machine's initial state value.
|
|
165
|
+
- `states` (object) - mapping of state names to state configs. Supports nested `states` and `initial` for child states.
|
|
166
|
+
- `on` (object) - optional global transitions available from any state.
|
|
167
|
+
- `context` (function) - returns bindable context fields.
|
|
168
|
+
- `computed` (object) - derived values based on context, props, refs.
|
|
169
|
+
- `entry` / `exit` / `effects` - root-level actions/effects.
|
|
170
|
+
- `implementations` (object) - lookup tables for `actions`, `guards`, `effects`.
|
|
123
171
|
|
|
124
172
|
### State config
|
|
125
173
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MachineSchema, GuardFn, Machine, Transition, Params } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare function createGuards<T extends MachineSchema>(): {
|
|
4
|
+
and: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
5
|
+
or: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
6
|
+
not: (guard: GuardFn<T> | T["guard"]) => (params: any) => boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function createMachine<T extends MachineSchema>(config: Machine<T>): Machine<T>;
|
|
9
|
+
declare function setup<T extends MachineSchema>(): {
|
|
10
|
+
guards: {
|
|
11
|
+
and: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
12
|
+
or: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
13
|
+
not: (guard: T["guard"] | GuardFn<T>) => (params: any) => boolean;
|
|
14
|
+
};
|
|
15
|
+
createMachine: (config: Machine<T>) => Machine<T>;
|
|
16
|
+
choose: (transitions: Transition<T> | Transition<T>[]) => ({ choose }: Params<T>) => T["action"][] | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createGuards, createMachine, setup };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MachineSchema, GuardFn, Machine, Transition, Params } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare function createGuards<T extends MachineSchema>(): {
|
|
4
|
+
and: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
5
|
+
or: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
6
|
+
not: (guard: GuardFn<T> | T["guard"]) => (params: any) => boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function createMachine<T extends MachineSchema>(config: Machine<T>): Machine<T>;
|
|
9
|
+
declare function setup<T extends MachineSchema>(): {
|
|
10
|
+
guards: {
|
|
11
|
+
and: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
12
|
+
or: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
13
|
+
not: (guard: T["guard"] | GuardFn<T>) => (params: any) => boolean;
|
|
14
|
+
};
|
|
15
|
+
createMachine: (config: Machine<T>) => Machine<T>;
|
|
16
|
+
choose: (transitions: Transition<T> | Transition<T>[]) => ({ choose }: Params<T>) => T["action"][] | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createGuards, createMachine, setup };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/create-machine.ts
|
|
21
|
+
var create_machine_exports = {};
|
|
22
|
+
__export(create_machine_exports, {
|
|
23
|
+
createGuards: () => createGuards,
|
|
24
|
+
createMachine: () => createMachine,
|
|
25
|
+
setup: () => setup
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(create_machine_exports);
|
|
28
|
+
var import_state = require("./state.cjs");
|
|
29
|
+
function createGuards() {
|
|
30
|
+
return {
|
|
31
|
+
and: (...guards) => {
|
|
32
|
+
return function andGuard(params) {
|
|
33
|
+
return guards.every((str) => params.guard(str));
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
or: (...guards) => {
|
|
37
|
+
return function orGuard(params) {
|
|
38
|
+
return guards.some((str) => params.guard(str));
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
not: (guard) => {
|
|
42
|
+
return function notGuard(params) {
|
|
43
|
+
return !params.guard(guard);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function createMachine(config) {
|
|
49
|
+
(0, import_state.ensureStateIndex)(config);
|
|
50
|
+
return config;
|
|
51
|
+
}
|
|
52
|
+
function setup() {
|
|
53
|
+
return {
|
|
54
|
+
guards: createGuards(),
|
|
55
|
+
createMachine: (config) => {
|
|
56
|
+
return createMachine(config);
|
|
57
|
+
},
|
|
58
|
+
choose: (transitions) => {
|
|
59
|
+
return function chooseFn({ choose }) {
|
|
60
|
+
return choose(transitions)?.actions;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
createGuards,
|
|
68
|
+
createMachine,
|
|
69
|
+
setup
|
|
70
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/create-machine.ts
|
|
2
|
+
import { ensureStateIndex } from "./state.mjs";
|
|
3
|
+
function createGuards() {
|
|
4
|
+
return {
|
|
5
|
+
and: (...guards) => {
|
|
6
|
+
return function andGuard(params) {
|
|
7
|
+
return guards.every((str) => params.guard(str));
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
or: (...guards) => {
|
|
11
|
+
return function orGuard(params) {
|
|
12
|
+
return guards.some((str) => params.guard(str));
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
not: (guard) => {
|
|
16
|
+
return function notGuard(params) {
|
|
17
|
+
return !params.guard(guard);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function createMachine(config) {
|
|
23
|
+
ensureStateIndex(config);
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
26
|
+
function setup() {
|
|
27
|
+
return {
|
|
28
|
+
guards: createGuards(),
|
|
29
|
+
createMachine: (config) => {
|
|
30
|
+
return createMachine(config);
|
|
31
|
+
},
|
|
32
|
+
choose: (transitions) => {
|
|
33
|
+
return function chooseFn({ choose }) {
|
|
34
|
+
return choose(transitions)?.actions;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
createGuards,
|
|
41
|
+
createMachine,
|
|
42
|
+
setup
|
|
43
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,257 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare function mergeProps<T extends Props>(...args: Array<T | undefined>): UnionToIntersection<TupleTypes<T[]>>;
|
|
9
|
-
|
|
10
|
-
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
11
|
-
declare function memo<TDeps extends any[], TDepArgs, TResult>(getDeps: (depArgs: TDepArgs) => [...TDeps], fn: (args: NoInfer<[...TDeps]>, deps: TDepArgs) => TResult, opts?: {
|
|
12
|
-
onChange?: ((result: TResult) => void) | undefined;
|
|
13
|
-
}): (depArgs: TDepArgs) => TResult;
|
|
14
|
-
|
|
15
|
-
type Dict = Record<string, any>;
|
|
16
|
-
interface ComputedParams<T extends Dict> {
|
|
17
|
-
context: BindableContext<T>;
|
|
18
|
-
event: EventType<T["event"]>;
|
|
19
|
-
prop: PropFn<T>;
|
|
20
|
-
refs: BindableRefs<T>;
|
|
21
|
-
scope: Scope;
|
|
22
|
-
computed: ComputedFn<T>;
|
|
23
|
-
}
|
|
24
|
-
interface ContextParams<T extends Dict> {
|
|
25
|
-
prop: PropFn<T>;
|
|
26
|
-
bindable: BindableFn;
|
|
27
|
-
scope: Scope;
|
|
28
|
-
getContext: () => BindableContext<T>;
|
|
29
|
-
getComputed: () => ComputedFn<T>;
|
|
30
|
-
getRefs: () => BindableRefs<T>;
|
|
31
|
-
getEvent: () => EventType<T["event"]>;
|
|
32
|
-
flush: (fn: VoidFunction) => void;
|
|
33
|
-
}
|
|
34
|
-
interface PropFn<T extends Dict> {
|
|
35
|
-
<K extends keyof T["props"]>(key: K): T["props"][K];
|
|
36
|
-
}
|
|
37
|
-
interface ComputedFn<T extends Dict> {
|
|
38
|
-
<K extends keyof T["computed"]>(key: K): T["computed"][K];
|
|
39
|
-
}
|
|
40
|
-
type AnyFunction = () => string | number | boolean | null | undefined;
|
|
41
|
-
type TrackFn = (deps: AnyFunction[], fn: VoidFunction) => void;
|
|
42
|
-
interface BindableParams<T> {
|
|
43
|
-
defaultValue?: T | undefined;
|
|
44
|
-
value?: T | undefined;
|
|
45
|
-
hash?: ((a: T) => string) | undefined;
|
|
46
|
-
isEqual?: ((a: T, b: T | undefined) => boolean) | undefined;
|
|
47
|
-
onChange?: ((value: T, prev: T | undefined) => void) | undefined;
|
|
48
|
-
debug?: string | undefined;
|
|
49
|
-
sync?: boolean | undefined;
|
|
50
|
-
}
|
|
51
|
-
type ValueOrFn<T> = T | ((prev: T) => T);
|
|
52
|
-
interface Bindable<T> {
|
|
53
|
-
initial: T | undefined;
|
|
54
|
-
ref: any;
|
|
55
|
-
get: () => T;
|
|
56
|
-
set(value: ValueOrFn<T>): void;
|
|
57
|
-
invoke(nextValue: T, prevValue: T): void;
|
|
58
|
-
hash(value: T): string;
|
|
59
|
-
}
|
|
60
|
-
interface BindableRefs<T extends Dict> {
|
|
61
|
-
set<K extends keyof T["refs"]>(key: K, value: T["refs"][K]): void;
|
|
62
|
-
get<K extends keyof T["refs"]>(key: K): T["refs"][K];
|
|
63
|
-
}
|
|
64
|
-
interface BindableContext<T extends Dict> {
|
|
65
|
-
set<K extends keyof T["context"]>(key: K, value: ValueOrFn<T["context"][K]>): void;
|
|
66
|
-
get<K extends keyof T["context"]>(key: K): T["context"][K];
|
|
67
|
-
initial<K extends keyof T["context"]>(key: K): T["context"][K];
|
|
68
|
-
hash<K extends keyof T["context"]>(key: K): string;
|
|
69
|
-
}
|
|
70
|
-
interface BindableRef<T> {
|
|
71
|
-
get: () => T;
|
|
72
|
-
set: (next: T) => void;
|
|
73
|
-
}
|
|
74
|
-
interface BindableFn {
|
|
75
|
-
<K>(params: () => BindableParams<K>): Bindable<K>;
|
|
76
|
-
cleanup: (fn: VoidFunction) => void;
|
|
77
|
-
ref: <T>(defaultValue: T) => BindableRef<T>;
|
|
78
|
-
}
|
|
79
|
-
interface Scope {
|
|
80
|
-
id?: string | undefined;
|
|
81
|
-
ids?: Record<string, any> | undefined;
|
|
82
|
-
getRootNode: () => ShadowRoot | Document | Node;
|
|
83
|
-
getById: <T extends Element = HTMLElement>(id: string) => T | null;
|
|
84
|
-
getActiveElement: () => HTMLElement | null;
|
|
85
|
-
isActiveElement: (elem: HTMLElement | null) => boolean;
|
|
86
|
-
getDoc: () => typeof document;
|
|
87
|
-
getWin: () => typeof window;
|
|
88
|
-
}
|
|
89
|
-
type EventType<T = any> = T & {
|
|
90
|
-
previousEvent?: (T & {
|
|
91
|
-
[key: string]: any;
|
|
92
|
-
}) | undefined;
|
|
93
|
-
src?: string | undefined;
|
|
94
|
-
[key: string]: any;
|
|
95
|
-
};
|
|
96
|
-
type EventObject = EventType<{
|
|
97
|
-
type: string;
|
|
98
|
-
}>;
|
|
99
|
-
interface Params<T extends Dict> {
|
|
100
|
-
prop: PropFn<T>;
|
|
101
|
-
action: (action: T["action"][]) => void;
|
|
102
|
-
context: BindableContext<T>;
|
|
103
|
-
refs: BindableRefs<T>;
|
|
104
|
-
track: TrackFn;
|
|
105
|
-
flush: (fn: VoidFunction) => void;
|
|
106
|
-
event: EventType<T["event"]> & {
|
|
107
|
-
current: () => EventType<T["event"]>;
|
|
108
|
-
previous: () => EventType<T["event"]>;
|
|
109
|
-
};
|
|
110
|
-
send: (event: EventType<T["event"]>) => void;
|
|
111
|
-
computed: ComputedFn<T>;
|
|
112
|
-
scope: Scope;
|
|
113
|
-
state: Bindable<T["state"]> & {
|
|
114
|
-
matches: (...values: T["state"][]) => boolean;
|
|
115
|
-
hasTag: (tag: T["tag"]) => boolean;
|
|
116
|
-
};
|
|
117
|
-
choose: ChooseFn<T>;
|
|
118
|
-
guard: (key: T["guard"] | GuardFn<T>) => boolean | undefined;
|
|
119
|
-
}
|
|
120
|
-
type GuardFn<T extends Dict> = (params: Params<T>) => boolean;
|
|
121
|
-
interface Transition<T extends Dict> {
|
|
122
|
-
target?: T["state"] | undefined;
|
|
123
|
-
actions?: T["action"][] | undefined;
|
|
124
|
-
guard?: T["guard"] | GuardFn<T> | undefined;
|
|
125
|
-
reenter?: boolean | undefined;
|
|
126
|
-
}
|
|
127
|
-
type MaybeArray<T> = T | T[];
|
|
128
|
-
type ChooseFn<T extends Dict> = (transitions: MaybeArray<Omit<Transition<T>, "target">>) => Transition<T> | undefined;
|
|
129
|
-
interface PropsParams<T extends Dict> {
|
|
130
|
-
props: Partial<T["props"]>;
|
|
131
|
-
scope: Scope;
|
|
132
|
-
}
|
|
133
|
-
interface RefsParams<T extends Dict> {
|
|
134
|
-
prop: PropFn<T>;
|
|
135
|
-
context: BindableContext<T>;
|
|
136
|
-
}
|
|
137
|
-
type ActionsOrFn<T extends Dict> = T["action"][] | ((params: Params<T>) => T["action"][] | undefined);
|
|
138
|
-
type EffectsOrFn<T extends Dict> = T["effect"][] | ((params: Params<T>) => T["effect"][] | undefined);
|
|
139
|
-
interface Machine<T extends Dict> {
|
|
140
|
-
debug?: boolean | undefined;
|
|
141
|
-
props?: ((params: PropsParams<T>) => T["props"]) | undefined;
|
|
142
|
-
context?: ((params: ContextParams<T>) => {
|
|
143
|
-
[K in keyof T["context"]]: Bindable<T["context"][K]>;
|
|
144
|
-
}) | undefined;
|
|
145
|
-
computed?: {
|
|
146
|
-
[K in keyof T["computed"]]: (params: ComputedParams<T>) => T["computed"][K];
|
|
147
|
-
} | undefined;
|
|
148
|
-
initialState: (params: {
|
|
149
|
-
prop: PropFn<T>;
|
|
150
|
-
}) => T["state"];
|
|
151
|
-
entry?: ActionsOrFn<T> | undefined;
|
|
152
|
-
exit?: ActionsOrFn<T> | undefined;
|
|
153
|
-
effects?: EffectsOrFn<T> | undefined;
|
|
154
|
-
refs?: ((params: RefsParams<T>) => T["refs"]) | undefined;
|
|
155
|
-
watch?: ((params: Params<T>) => void) | undefined;
|
|
156
|
-
on?: {
|
|
157
|
-
[E in T["event"]["type"]]?: Transition<T> | Array<Transition<T>>;
|
|
158
|
-
} | undefined;
|
|
159
|
-
states: {
|
|
160
|
-
[K in T["state"]]: {
|
|
161
|
-
tags?: T["tag"][] | undefined;
|
|
162
|
-
entry?: ActionsOrFn<T> | undefined;
|
|
163
|
-
exit?: ActionsOrFn<T> | undefined;
|
|
164
|
-
effects?: EffectsOrFn<T> | undefined;
|
|
165
|
-
on?: {
|
|
166
|
-
[E in T["event"]["type"]]?: Transition<T> | Array<Transition<T>>;
|
|
167
|
-
} | undefined;
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
implementations?: {
|
|
171
|
-
guards?: {
|
|
172
|
-
[K in T["guard"]]: (params: Params<T>) => boolean;
|
|
173
|
-
} | undefined;
|
|
174
|
-
actions?: {
|
|
175
|
-
[K in T["action"]]: (params: Params<T>) => void;
|
|
176
|
-
} | undefined;
|
|
177
|
-
effects?: {
|
|
178
|
-
[K in T["effect"]]: (params: Params<T>) => void | VoidFunction;
|
|
179
|
-
} | undefined;
|
|
180
|
-
} | undefined;
|
|
181
|
-
}
|
|
182
|
-
interface MachineBaseProps {
|
|
183
|
-
id?: string | undefined;
|
|
184
|
-
ids?: Record<string, any> | undefined;
|
|
185
|
-
getRootNode?: (() => ShadowRoot | Document | Node) | undefined;
|
|
186
|
-
[key: string]: any;
|
|
187
|
-
}
|
|
188
|
-
interface MachineSchema {
|
|
189
|
-
props?: MachineBaseProps | undefined;
|
|
190
|
-
context?: Record<string, any> | undefined;
|
|
191
|
-
refs?: Record<string, any> | undefined;
|
|
192
|
-
computed?: Record<string, any> | undefined;
|
|
193
|
-
state?: string | undefined;
|
|
194
|
-
tag?: string | undefined;
|
|
195
|
-
guard?: string | undefined;
|
|
196
|
-
action?: string | undefined;
|
|
197
|
-
effect?: string | undefined;
|
|
198
|
-
event?: ({
|
|
199
|
-
type: string;
|
|
200
|
-
} & Dict) | undefined;
|
|
201
|
-
}
|
|
202
|
-
type State<T extends MachineSchema> = Bindable<T["state"]> & {
|
|
203
|
-
hasTag: (tag: T["tag"]) => boolean;
|
|
204
|
-
matches: (...values: T["state"][]) => boolean;
|
|
205
|
-
};
|
|
206
|
-
type Service<T extends MachineSchema> = {
|
|
207
|
-
getStatus: () => MachineStatus;
|
|
208
|
-
state: State<T> & {
|
|
209
|
-
matches: (...values: T["state"][]) => boolean;
|
|
210
|
-
hasTag: (tag: T["tag"]) => boolean;
|
|
211
|
-
};
|
|
212
|
-
context: BindableContext<T>;
|
|
213
|
-
send: (event: EventType<T["event"]>) => void;
|
|
214
|
-
prop: PropFn<T>;
|
|
215
|
-
scope: Scope;
|
|
216
|
-
computed: ComputedFn<T>;
|
|
217
|
-
refs: BindableRefs<T>;
|
|
218
|
-
event: EventType<T["event"]> & {
|
|
219
|
-
current: () => EventType<T["event"]>;
|
|
220
|
-
previous: () => EventType<T["event"]>;
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
declare enum MachineStatus {
|
|
224
|
-
NotStarted = "Not Started",
|
|
225
|
-
Started = "Started",
|
|
226
|
-
Stopped = "Stopped"
|
|
227
|
-
}
|
|
228
|
-
declare const INIT_STATE = "__init__";
|
|
229
|
-
|
|
230
|
-
declare function createGuards<T extends MachineSchema>(): {
|
|
231
|
-
and: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
232
|
-
or: (...guards: Array<GuardFn<T> | T["guard"]>) => (params: any) => boolean;
|
|
233
|
-
not: (guard: GuardFn<T> | T["guard"]) => (params: any) => boolean;
|
|
234
|
-
};
|
|
235
|
-
declare function createMachine<T extends MachineSchema>(config: Machine<T>): Machine<T>;
|
|
236
|
-
declare function setup<T extends MachineSchema>(): {
|
|
237
|
-
guards: {
|
|
238
|
-
and: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
239
|
-
or: (...guards: (T["guard"] | GuardFn<T>)[]) => (params: any) => boolean;
|
|
240
|
-
not: (guard: T["guard"] | GuardFn<T>) => (params: any) => boolean;
|
|
241
|
-
};
|
|
242
|
-
createMachine: (config: Machine<T>) => Machine<T>;
|
|
243
|
-
choose: (transitions: Transition<T> | Transition<T>[]) => ({ choose }: Params<T>) => T["action"][] | undefined;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
declare function createScope(props: Pick<Scope, "id" | "ids" | "getRootNode">): {
|
|
247
|
-
getRootNode: () => Document | ShadowRoot;
|
|
248
|
-
getDoc: () => Document;
|
|
249
|
-
getWin: () => Window & typeof globalThis;
|
|
250
|
-
getActiveElement: () => HTMLElement | null;
|
|
251
|
-
isActiveElement: typeof isActiveElement;
|
|
252
|
-
getById: <T extends Element = HTMLElement>(id: string) => T | null;
|
|
253
|
-
id?: string | undefined | undefined;
|
|
254
|
-
ids?: Record<string, any> | undefined;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
export { type ActionsOrFn, type Bindable, type BindableContext, type BindableFn, type BindableParams, type BindableRefs, type ChooseFn, type ComputedFn, type EffectsOrFn, type EventObject, type GuardFn, INIT_STATE, type Machine, type MachineSchema, MachineStatus, type Params, type PropFn, type Scope, type Service, type Transition, type ValueOrFn, createGuards, createMachine, createScope, memo, mergeProps, setup };
|
|
1
|
+
export { mergeProps } from './merge-props.mjs';
|
|
2
|
+
export { memo } from './memo.mjs';
|
|
3
|
+
export { createGuards, createMachine, setup } from './create-machine.mjs';
|
|
4
|
+
export { ensureStateIndex, findTransition, getExitEnterStates, getStateChain, getStateDefinition, hasTag, matchesState, resolveStateValue } from './state.mjs';
|
|
5
|
+
export { ActionsOrFn, Bindable, BindableContext, BindableFn, BindableParams, BindableRefs, ChooseFn, ComputedFn, EffectsOrFn, EventObject, GuardFn, INIT_STATE, Machine, MachineSchema, MachineState, MachineStatus, Params, PropFn, Scope, Service, Transition, TransitionMap, TransitionMatch, TransitionSet, ValueOrFn } from './types.mjs';
|
|
6
|
+
export { createScope } from './scope.mjs';
|
|
7
|
+
import '@zag-js/dom-query';
|