@zag-js/core 1.34.0 → 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -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 +172 -0
- package/dist/state.mjs +140 -0
- package/dist/types.d.mts +232 -0
- package/dist/types.d.ts +232 -0
- package/dist/types.js +38 -0
- package/dist/types.mjs +12 -0
- package/package.json +3 -3
package/dist/index.d.ts
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.js';
|
|
2
|
+
export { memo } from './memo.js';
|
|
3
|
+
export { createGuards, createMachine, setup } from './create-machine.js';
|
|
4
|
+
export { ensureStateIndex, findTransition, getExitEnterStates, getStateChain, getStateDefinition, hasTag, matchesState, resolveStateValue } from './state.js';
|
|
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.js';
|
|
6
|
+
export { createScope } from './scope.js';
|
|
7
|
+
import '@zag-js/dom-query';
|
package/dist/index.js
CHANGED
|
@@ -1,140 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let match;
|
|
12
|
-
while (match = CSS_REGEX.exec(style)) {
|
|
13
|
-
res[match[1]] = match[2];
|
|
14
|
-
}
|
|
15
|
-
return res;
|
|
16
|
-
};
|
|
17
|
-
var css = (a, b) => {
|
|
18
|
-
if (utils.isString(a)) {
|
|
19
|
-
if (utils.isString(b)) return `${a};${b}`;
|
|
20
|
-
a = serialize(a);
|
|
21
|
-
} else if (utils.isString(b)) {
|
|
22
|
-
b = serialize(b);
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
11
|
}
|
|
24
|
-
return
|
|
12
|
+
return to;
|
|
25
13
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (let props of args) {
|
|
29
|
-
if (!props) continue;
|
|
30
|
-
for (let key in result) {
|
|
31
|
-
if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
|
|
32
|
-
result[key] = utils.callAll(props[key], result[key]);
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
if (key === "className" || key === "class") {
|
|
36
|
-
result[key] = clsx(result[key], props[key]);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (key === "style") {
|
|
40
|
-
result[key] = css(result[key], props[key]);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
result[key] = props[key] !== void 0 ? props[key] : result[key];
|
|
44
|
-
}
|
|
45
|
-
for (let key in props) {
|
|
46
|
-
if (result[key] === void 0) {
|
|
47
|
-
result[key] = props[key];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const symbols = Object.getOwnPropertySymbols(props);
|
|
51
|
-
for (let symbol of symbols) {
|
|
52
|
-
result[symbol] = props[symbol];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
function memo(getDeps, fn, opts) {
|
|
58
|
-
let deps = [];
|
|
59
|
-
let result;
|
|
60
|
-
return (depArgs) => {
|
|
61
|
-
const newDeps = getDeps(depArgs);
|
|
62
|
-
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => !utils.isEqual(deps[index], dep));
|
|
63
|
-
if (!depsChanged) return result;
|
|
64
|
-
deps = newDeps;
|
|
65
|
-
result = fn(newDeps, depArgs);
|
|
66
|
-
opts?.onChange?.(result);
|
|
67
|
-
return result;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/create-machine.ts
|
|
72
|
-
function createGuards() {
|
|
73
|
-
return {
|
|
74
|
-
and: (...guards) => {
|
|
75
|
-
return function andGuard(params) {
|
|
76
|
-
return guards.every((str) => params.guard(str));
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
or: (...guards) => {
|
|
80
|
-
return function orGuard(params) {
|
|
81
|
-
return guards.some((str) => params.guard(str));
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
not: (guard) => {
|
|
85
|
-
return function notGuard(params) {
|
|
86
|
-
return !params.guard(guard);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function createMachine(config) {
|
|
92
|
-
return config;
|
|
93
|
-
}
|
|
94
|
-
function setup() {
|
|
95
|
-
return {
|
|
96
|
-
guards: createGuards(),
|
|
97
|
-
createMachine: (config) => {
|
|
98
|
-
return createMachine(config);
|
|
99
|
-
},
|
|
100
|
-
choose: (transitions) => {
|
|
101
|
-
return function chooseFn({ choose }) {
|
|
102
|
-
return choose(transitions)?.actions;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/types.ts
|
|
109
|
-
var MachineStatus = /* @__PURE__ */ ((MachineStatus2) => {
|
|
110
|
-
MachineStatus2["NotStarted"] = "Not Started";
|
|
111
|
-
MachineStatus2["Started"] = "Started";
|
|
112
|
-
MachineStatus2["Stopped"] = "Stopped";
|
|
113
|
-
return MachineStatus2;
|
|
114
|
-
})(MachineStatus || {});
|
|
115
|
-
var INIT_STATE = "__init__";
|
|
116
|
-
function createScope(props) {
|
|
117
|
-
const getRootNode = () => props.getRootNode?.() ?? document;
|
|
118
|
-
const getDoc = () => domQuery.getDocument(getRootNode());
|
|
119
|
-
const getWin = () => getDoc().defaultView ?? window;
|
|
120
|
-
const getActiveElementFn = () => domQuery.getActiveElement(getRootNode());
|
|
121
|
-
const getById = (id) => getRootNode().getElementById(id);
|
|
122
|
-
return {
|
|
123
|
-
...props,
|
|
124
|
-
getRootNode,
|
|
125
|
-
getDoc,
|
|
126
|
-
getWin,
|
|
127
|
-
getActiveElement: getActiveElementFn,
|
|
128
|
-
isActiveElement: domQuery.isActiveElement,
|
|
129
|
-
getById
|
|
130
|
-
};
|
|
131
|
-
}
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
132
16
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
exports
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
17
|
+
// src/index.ts
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("./merge-props.cjs"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./memo.cjs"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./create-machine.cjs"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./state.cjs"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./types.cjs"), module.exports);
|
|
25
|
+
__reExport(index_exports, require("./scope.cjs"), module.exports);
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
...require("./merge-props.cjs"),
|
|
29
|
+
...require("./memo.cjs"),
|
|
30
|
+
...require("./create-machine.cjs"),
|
|
31
|
+
...require("./state.cjs"),
|
|
32
|
+
...require("./types.cjs"),
|
|
33
|
+
...require("./scope.cjs")
|
|
34
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,131 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const res = {};
|
|
9
|
-
let match;
|
|
10
|
-
while (match = CSS_REGEX.exec(style)) {
|
|
11
|
-
res[match[1]] = match[2];
|
|
12
|
-
}
|
|
13
|
-
return res;
|
|
14
|
-
};
|
|
15
|
-
var css = (a, b) => {
|
|
16
|
-
if (isString(a)) {
|
|
17
|
-
if (isString(b)) return `${a};${b}`;
|
|
18
|
-
a = serialize(a);
|
|
19
|
-
} else if (isString(b)) {
|
|
20
|
-
b = serialize(b);
|
|
21
|
-
}
|
|
22
|
-
return Object.assign({}, a ?? {}, b ?? {});
|
|
23
|
-
};
|
|
24
|
-
function mergeProps(...args) {
|
|
25
|
-
let result = {};
|
|
26
|
-
for (let props of args) {
|
|
27
|
-
if (!props) continue;
|
|
28
|
-
for (let key in result) {
|
|
29
|
-
if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
|
|
30
|
-
result[key] = callAll(props[key], result[key]);
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (key === "className" || key === "class") {
|
|
34
|
-
result[key] = clsx(result[key], props[key]);
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
if (key === "style") {
|
|
38
|
-
result[key] = css(result[key], props[key]);
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
result[key] = props[key] !== void 0 ? props[key] : result[key];
|
|
42
|
-
}
|
|
43
|
-
for (let key in props) {
|
|
44
|
-
if (result[key] === void 0) {
|
|
45
|
-
result[key] = props[key];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const symbols = Object.getOwnPropertySymbols(props);
|
|
49
|
-
for (let symbol of symbols) {
|
|
50
|
-
result[symbol] = props[symbol];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
function memo(getDeps, fn, opts) {
|
|
56
|
-
let deps = [];
|
|
57
|
-
let result;
|
|
58
|
-
return (depArgs) => {
|
|
59
|
-
const newDeps = getDeps(depArgs);
|
|
60
|
-
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => !isEqual(deps[index], dep));
|
|
61
|
-
if (!depsChanged) return result;
|
|
62
|
-
deps = newDeps;
|
|
63
|
-
result = fn(newDeps, depArgs);
|
|
64
|
-
opts?.onChange?.(result);
|
|
65
|
-
return result;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// src/create-machine.ts
|
|
70
|
-
function createGuards() {
|
|
71
|
-
return {
|
|
72
|
-
and: (...guards) => {
|
|
73
|
-
return function andGuard(params) {
|
|
74
|
-
return guards.every((str) => params.guard(str));
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
or: (...guards) => {
|
|
78
|
-
return function orGuard(params) {
|
|
79
|
-
return guards.some((str) => params.guard(str));
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
not: (guard) => {
|
|
83
|
-
return function notGuard(params) {
|
|
84
|
-
return !params.guard(guard);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function createMachine(config) {
|
|
90
|
-
return config;
|
|
91
|
-
}
|
|
92
|
-
function setup() {
|
|
93
|
-
return {
|
|
94
|
-
guards: createGuards(),
|
|
95
|
-
createMachine: (config) => {
|
|
96
|
-
return createMachine(config);
|
|
97
|
-
},
|
|
98
|
-
choose: (transitions) => {
|
|
99
|
-
return function chooseFn({ choose }) {
|
|
100
|
-
return choose(transitions)?.actions;
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// src/types.ts
|
|
107
|
-
var MachineStatus = /* @__PURE__ */ ((MachineStatus2) => {
|
|
108
|
-
MachineStatus2["NotStarted"] = "Not Started";
|
|
109
|
-
MachineStatus2["Started"] = "Started";
|
|
110
|
-
MachineStatus2["Stopped"] = "Stopped";
|
|
111
|
-
return MachineStatus2;
|
|
112
|
-
})(MachineStatus || {});
|
|
113
|
-
var INIT_STATE = "__init__";
|
|
114
|
-
function createScope(props) {
|
|
115
|
-
const getRootNode = () => props.getRootNode?.() ?? document;
|
|
116
|
-
const getDoc = () => getDocument(getRootNode());
|
|
117
|
-
const getWin = () => getDoc().defaultView ?? window;
|
|
118
|
-
const getActiveElementFn = () => getActiveElement(getRootNode());
|
|
119
|
-
const getById = (id) => getRootNode().getElementById(id);
|
|
120
|
-
return {
|
|
121
|
-
...props,
|
|
122
|
-
getRootNode,
|
|
123
|
-
getDoc,
|
|
124
|
-
getWin,
|
|
125
|
-
getActiveElement: getActiveElementFn,
|
|
126
|
-
isActiveElement,
|
|
127
|
-
getById
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export { INIT_STATE, MachineStatus, createGuards, createMachine, createScope, memo, mergeProps, setup };
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "./merge-props.mjs";
|
|
3
|
+
export * from "./memo.mjs";
|
|
4
|
+
export * from "./create-machine.mjs";
|
|
5
|
+
export * from "./state.mjs";
|
|
6
|
+
export * from "./types.mjs";
|
|
7
|
+
export * from "./scope.mjs";
|
package/dist/memo.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
2
|
+
declare function memo<TDeps extends any[], TDepArgs, TResult>(getDeps: (depArgs: TDepArgs) => [...TDeps], fn: (args: NoInfer<[...TDeps]>, deps: TDepArgs) => TResult, opts?: {
|
|
3
|
+
onChange?: ((result: TResult) => void) | undefined;
|
|
4
|
+
}): (depArgs: TDepArgs) => TResult;
|
|
5
|
+
|
|
6
|
+
export { memo };
|
package/dist/memo.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
2
|
+
declare function memo<TDeps extends any[], TDepArgs, TResult>(getDeps: (depArgs: TDepArgs) => [...TDeps], fn: (args: NoInfer<[...TDeps]>, deps: TDepArgs) => TResult, opts?: {
|
|
3
|
+
onChange?: ((result: TResult) => void) | undefined;
|
|
4
|
+
}): (depArgs: TDepArgs) => TResult;
|
|
5
|
+
|
|
6
|
+
export { memo };
|
package/dist/memo.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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/memo.ts
|
|
21
|
+
var memo_exports = {};
|
|
22
|
+
__export(memo_exports, {
|
|
23
|
+
memo: () => memo
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(memo_exports);
|
|
26
|
+
var import_utils = require("@zag-js/utils");
|
|
27
|
+
function memo(getDeps, fn, opts) {
|
|
28
|
+
let deps = [];
|
|
29
|
+
let result;
|
|
30
|
+
return (depArgs) => {
|
|
31
|
+
const newDeps = getDeps(depArgs);
|
|
32
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => !(0, import_utils.isEqual)(deps[index], dep));
|
|
33
|
+
if (!depsChanged) return result;
|
|
34
|
+
deps = newDeps;
|
|
35
|
+
result = fn(newDeps, depArgs);
|
|
36
|
+
opts?.onChange?.(result);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
memo
|
|
43
|
+
});
|
package/dist/memo.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/memo.ts
|
|
2
|
+
import { isEqual } from "@zag-js/utils";
|
|
3
|
+
function memo(getDeps, fn, opts) {
|
|
4
|
+
let deps = [];
|
|
5
|
+
let result;
|
|
6
|
+
return (depArgs) => {
|
|
7
|
+
const newDeps = getDeps(depArgs);
|
|
8
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => !isEqual(deps[index], dep));
|
|
9
|
+
if (!depsChanged) return result;
|
|
10
|
+
deps = newDeps;
|
|
11
|
+
result = fn(newDeps, depArgs);
|
|
12
|
+
opts?.onChange?.(result);
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
memo
|
|
18
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
[key: string | symbol]: any;
|
|
3
|
+
}
|
|
4
|
+
type TupleTypes<T extends any[]> = T[number];
|
|
5
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
6
|
+
declare function mergeProps<T extends Props>(...args: Array<T | undefined>): UnionToIntersection<TupleTypes<T[]>>;
|
|
7
|
+
|
|
8
|
+
export { mergeProps };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
[key: string | symbol]: any;
|
|
3
|
+
}
|
|
4
|
+
type TupleTypes<T extends any[]> = T[number];
|
|
5
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
6
|
+
declare function mergeProps<T extends Props>(...args: Array<T | undefined>): UnionToIntersection<TupleTypes<T[]>>;
|
|
7
|
+
|
|
8
|
+
export { mergeProps };
|