controlled-machine 0.1.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 +572 -0
- package/dist/index.cjs +160 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +143 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.js +160 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +103 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +100 -0
- package/dist/react.d.ts +100 -0
- package/dist/react.js +103 -0
- package/dist/react.js.map +1 -0
- package/package.json +75 -0
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
declare type Actions<T extends MachineTypes> = T['actions'] extends string ? T['actions'] : string;
|
|
2
|
+
|
|
3
|
+
declare type Cleanup = () => void;
|
|
4
|
+
|
|
5
|
+
declare type Computed<T extends MachineTypes> = T['computed'] extends ComputedConfig ? T['computed'] : Record<string, never>;
|
|
6
|
+
|
|
7
|
+
declare type ComputedConfig = Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
declare type Context<T extends MachineTypes> = Input<T> & Computed<T>;
|
|
10
|
+
|
|
11
|
+
declare type Effect<TContext, TEvents extends EventsConfig, TWatched = unknown> = {
|
|
12
|
+
watch: (context: TContext) => TWatched;
|
|
13
|
+
enter?: (context: TContext, helpers: EffectHelpers<TEvents>) => void | Cleanup | Promise<void>;
|
|
14
|
+
exit?: (context: TContext, helpers: EffectHelpers<TEvents>) => void | Cleanup;
|
|
15
|
+
change?: (context: TContext, prev: TWatched | undefined, curr: TWatched, helpers: EffectHelpers<TEvents>) => void | Cleanup;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare type EffectHelpers<TEvents extends EventsConfig> = {
|
|
19
|
+
send: Send<TEvents>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare type Events<T extends MachineTypes> = T['events'] extends EventsConfig ? T['events'] : Record<string, undefined>;
|
|
23
|
+
|
|
24
|
+
declare type EventsConfig = Record<string, unknown>;
|
|
25
|
+
|
|
26
|
+
declare type Handler<TContext, TPayload = undefined, TActions extends string = string> = TActions | TActions[] | Rule<TContext, TPayload, TActions>[];
|
|
27
|
+
|
|
28
|
+
declare type Input<T extends MachineTypes> = T['input'];
|
|
29
|
+
|
|
30
|
+
declare type Machine<T extends MachineTypes> = {
|
|
31
|
+
computed?: {
|
|
32
|
+
[K in keyof Computed<T>]: (input: Input<T>) => Computed<T>[K];
|
|
33
|
+
};
|
|
34
|
+
on?: {
|
|
35
|
+
[K in keyof Events<T>]?: Handler<Context<T>, Events<T>[K], Actions<T>>;
|
|
36
|
+
};
|
|
37
|
+
states?: StatesConfig<State<T>, Context<T>, Events<T>, Actions<T>>;
|
|
38
|
+
always?: Rule<Context<T>, undefined, Actions<T>>[];
|
|
39
|
+
effects?: Effect<Context<T>, Events<T>, any>[];
|
|
40
|
+
actions?: {
|
|
41
|
+
[K in Actions<T>]: (context: Context<T>, payload?: any) => void;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Object-based generic types - specify only needed types in any order
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* createMachine<{
|
|
50
|
+
* input: MyInput
|
|
51
|
+
* events: MyEvents
|
|
52
|
+
* actions: 'foo' | 'bar'
|
|
53
|
+
* }>({...})
|
|
54
|
+
*/
|
|
55
|
+
declare type MachineTypes = {
|
|
56
|
+
input?: unknown;
|
|
57
|
+
events?: EventsConfig;
|
|
58
|
+
computed?: ComputedConfig;
|
|
59
|
+
actions?: string;
|
|
60
|
+
state?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Controlled Machine
|
|
65
|
+
*
|
|
66
|
+
* A controlled state machine where state lives outside the machine.
|
|
67
|
+
*
|
|
68
|
+
* - input: External data passed in
|
|
69
|
+
* - computed: Derived values from input
|
|
70
|
+
* - context: input + computed (full context available in handlers)
|
|
71
|
+
* - on: Event → conditional actions
|
|
72
|
+
* - effects: Watch-based side effects
|
|
73
|
+
* - always: Auto-evaluated rules on context change
|
|
74
|
+
*/
|
|
75
|
+
declare type Rule<TContext, TPayload = undefined, TActions extends string = string> = {
|
|
76
|
+
when?: (context: TContext, payload: TPayload) => boolean;
|
|
77
|
+
do: TActions | TActions[];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export declare type Send<TEvents extends EventsConfig> = <K extends keyof TEvents>(event: K, ...args: TEvents[K] extends undefined ? [] : [payload: TEvents[K]]) => void;
|
|
81
|
+
|
|
82
|
+
declare type State<T extends MachineTypes> = T['state'] extends string ? T['state'] : string;
|
|
83
|
+
|
|
84
|
+
declare type StateConfig<TContext, TEvents extends EventsConfig, TActions extends string = string> = {
|
|
85
|
+
on?: {
|
|
86
|
+
[K in keyof TEvents]?: Handler<TContext, TEvents[K], TActions>;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare type StatesConfig<TState extends string, TContext, TEvents extends EventsConfig, TActions extends string = string> = {
|
|
91
|
+
[K in TState]?: StateConfig<TContext, TEvents, TActions>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export declare function useMachine<T extends MachineTypes>(machine: Machine<T>, input: T['input']): {
|
|
95
|
+
send: Send<Events<T>>;
|
|
96
|
+
computed: Computed<T>;
|
|
97
|
+
state: State<T>;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export { }
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
declare type Actions<T extends MachineTypes> = T['actions'] extends string ? T['actions'] : string;
|
|
2
|
+
|
|
3
|
+
declare type Cleanup = () => void;
|
|
4
|
+
|
|
5
|
+
declare type Computed<T extends MachineTypes> = T['computed'] extends ComputedConfig ? T['computed'] : Record<string, never>;
|
|
6
|
+
|
|
7
|
+
declare type ComputedConfig = Record<string, unknown>;
|
|
8
|
+
|
|
9
|
+
declare type Context<T extends MachineTypes> = Input<T> & Computed<T>;
|
|
10
|
+
|
|
11
|
+
declare type Effect<TContext, TEvents extends EventsConfig, TWatched = unknown> = {
|
|
12
|
+
watch: (context: TContext) => TWatched;
|
|
13
|
+
enter?: (context: TContext, helpers: EffectHelpers<TEvents>) => void | Cleanup | Promise<void>;
|
|
14
|
+
exit?: (context: TContext, helpers: EffectHelpers<TEvents>) => void | Cleanup;
|
|
15
|
+
change?: (context: TContext, prev: TWatched | undefined, curr: TWatched, helpers: EffectHelpers<TEvents>) => void | Cleanup;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
declare type EffectHelpers<TEvents extends EventsConfig> = {
|
|
19
|
+
send: Send<TEvents>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare type Events<T extends MachineTypes> = T['events'] extends EventsConfig ? T['events'] : Record<string, undefined>;
|
|
23
|
+
|
|
24
|
+
declare type EventsConfig = Record<string, unknown>;
|
|
25
|
+
|
|
26
|
+
declare type Handler<TContext, TPayload = undefined, TActions extends string = string> = TActions | TActions[] | Rule<TContext, TPayload, TActions>[];
|
|
27
|
+
|
|
28
|
+
declare type Input<T extends MachineTypes> = T['input'];
|
|
29
|
+
|
|
30
|
+
declare type Machine<T extends MachineTypes> = {
|
|
31
|
+
computed?: {
|
|
32
|
+
[K in keyof Computed<T>]: (input: Input<T>) => Computed<T>[K];
|
|
33
|
+
};
|
|
34
|
+
on?: {
|
|
35
|
+
[K in keyof Events<T>]?: Handler<Context<T>, Events<T>[K], Actions<T>>;
|
|
36
|
+
};
|
|
37
|
+
states?: StatesConfig<State<T>, Context<T>, Events<T>, Actions<T>>;
|
|
38
|
+
always?: Rule<Context<T>, undefined, Actions<T>>[];
|
|
39
|
+
effects?: Effect<Context<T>, Events<T>, any>[];
|
|
40
|
+
actions?: {
|
|
41
|
+
[K in Actions<T>]: (context: Context<T>, payload?: any) => void;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Object-based generic types - specify only needed types in any order
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* createMachine<{
|
|
50
|
+
* input: MyInput
|
|
51
|
+
* events: MyEvents
|
|
52
|
+
* actions: 'foo' | 'bar'
|
|
53
|
+
* }>({...})
|
|
54
|
+
*/
|
|
55
|
+
declare type MachineTypes = {
|
|
56
|
+
input?: unknown;
|
|
57
|
+
events?: EventsConfig;
|
|
58
|
+
computed?: ComputedConfig;
|
|
59
|
+
actions?: string;
|
|
60
|
+
state?: string;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Controlled Machine
|
|
65
|
+
*
|
|
66
|
+
* A controlled state machine where state lives outside the machine.
|
|
67
|
+
*
|
|
68
|
+
* - input: External data passed in
|
|
69
|
+
* - computed: Derived values from input
|
|
70
|
+
* - context: input + computed (full context available in handlers)
|
|
71
|
+
* - on: Event → conditional actions
|
|
72
|
+
* - effects: Watch-based side effects
|
|
73
|
+
* - always: Auto-evaluated rules on context change
|
|
74
|
+
*/
|
|
75
|
+
declare type Rule<TContext, TPayload = undefined, TActions extends string = string> = {
|
|
76
|
+
when?: (context: TContext, payload: TPayload) => boolean;
|
|
77
|
+
do: TActions | TActions[];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export declare type Send<TEvents extends EventsConfig> = <K extends keyof TEvents>(event: K, ...args: TEvents[K] extends undefined ? [] : [payload: TEvents[K]]) => void;
|
|
81
|
+
|
|
82
|
+
declare type State<T extends MachineTypes> = T['state'] extends string ? T['state'] : string;
|
|
83
|
+
|
|
84
|
+
declare type StateConfig<TContext, TEvents extends EventsConfig, TActions extends string = string> = {
|
|
85
|
+
on?: {
|
|
86
|
+
[K in keyof TEvents]?: Handler<TContext, TEvents[K], TActions>;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
declare type StatesConfig<TState extends string, TContext, TEvents extends EventsConfig, TActions extends string = string> = {
|
|
91
|
+
[K in TState]?: StateConfig<TContext, TEvents, TActions>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export declare function useMachine<T extends MachineTypes>(machine: Machine<T>, input: T['input']): {
|
|
95
|
+
send: Send<Events<T>>;
|
|
96
|
+
computed: Computed<T>;
|
|
97
|
+
state: State<T>;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export { }
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useRef, useMemo, useCallback, useEffect } from "react";
|
|
2
|
+
import { computeValues, executeActions, executeHandler, processEffects, clearEffectStore } from "./index.js";
|
|
3
|
+
function useMachine(machine, input) {
|
|
4
|
+
const inputRef = useRef(input);
|
|
5
|
+
const machineRef = useRef(machine);
|
|
6
|
+
const isMountedRef = useRef(true);
|
|
7
|
+
inputRef.current = input;
|
|
8
|
+
machineRef.current = machine;
|
|
9
|
+
const { computed: computedDef } = machine;
|
|
10
|
+
const context = useMemo(
|
|
11
|
+
() => computeValues(input, computedDef),
|
|
12
|
+
[input, computedDef]
|
|
13
|
+
);
|
|
14
|
+
const computed = useMemo(() => {
|
|
15
|
+
if (!computedDef) return {};
|
|
16
|
+
const result = {};
|
|
17
|
+
for (const key in computedDef) {
|
|
18
|
+
result[key] = context[key];
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}, [context, computedDef]);
|
|
22
|
+
const contextRef = useRef(context);
|
|
23
|
+
contextRef.current = context;
|
|
24
|
+
const prevContextRef = useRef(context);
|
|
25
|
+
const effectStoreRef = useRef({
|
|
26
|
+
watchedValues: /* @__PURE__ */ new Map(),
|
|
27
|
+
enterCleanups: /* @__PURE__ */ new Map(),
|
|
28
|
+
changeCleanups: /* @__PURE__ */ new Map(),
|
|
29
|
+
exitCleanups: /* @__PURE__ */ new Map()
|
|
30
|
+
});
|
|
31
|
+
const { always, actions } = machine;
|
|
32
|
+
if (prevContextRef.current !== context && always && actions) {
|
|
33
|
+
const actionsMap = actions;
|
|
34
|
+
for (const rule of always) {
|
|
35
|
+
if (!rule.when || rule.when(context, void 0)) {
|
|
36
|
+
executeActions(rule.do, actionsMap, context, void 0);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
prevContextRef.current = context;
|
|
42
|
+
const send = useCallback(
|
|
43
|
+
(event, ...args) => {
|
|
44
|
+
const currentMachine = machineRef.current;
|
|
45
|
+
const currentInput = inputRef.current;
|
|
46
|
+
const currentContext = computeValues(
|
|
47
|
+
currentInput,
|
|
48
|
+
currentMachine.computed
|
|
49
|
+
);
|
|
50
|
+
const payload = args[0];
|
|
51
|
+
const state2 = currentContext.state;
|
|
52
|
+
if (state2 && currentMachine.states?.[state2]?.on?.[event]) {
|
|
53
|
+
const stateHandler = currentMachine.states[state2].on[event];
|
|
54
|
+
executeHandler(
|
|
55
|
+
stateHandler,
|
|
56
|
+
currentMachine.actions ?? {},
|
|
57
|
+
currentContext,
|
|
58
|
+
payload
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const globalHandler = currentMachine.on?.[event];
|
|
62
|
+
if (globalHandler) {
|
|
63
|
+
executeHandler(
|
|
64
|
+
globalHandler,
|
|
65
|
+
currentMachine.actions ?? {},
|
|
66
|
+
currentContext,
|
|
67
|
+
payload
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
[]
|
|
72
|
+
// no dependencies - uses refs
|
|
73
|
+
);
|
|
74
|
+
const safeSend = useCallback(
|
|
75
|
+
(event, ...args) => {
|
|
76
|
+
if (!isMountedRef.current) return;
|
|
77
|
+
send(event, ...args);
|
|
78
|
+
},
|
|
79
|
+
[send]
|
|
80
|
+
);
|
|
81
|
+
const effectHelpers = useMemo(
|
|
82
|
+
() => ({ send: safeSend }),
|
|
83
|
+
[safeSend]
|
|
84
|
+
);
|
|
85
|
+
const { effects } = machine;
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
processEffects(effects, context, effectHelpers, effectStoreRef.current);
|
|
88
|
+
}, [context, effects, effectHelpers]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
isMountedRef.current = true;
|
|
91
|
+
const store = effectStoreRef.current;
|
|
92
|
+
return () => {
|
|
93
|
+
isMountedRef.current = false;
|
|
94
|
+
clearEffectStore(store);
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
const state = context.state ?? "";
|
|
98
|
+
return { send, computed, state };
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
useMachine
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../src/react.ts"],"sourcesContent":["/**\n * Controlled Machine - React Integration\n *\n * React hook for using controlled-machine in React components.\n */\n\nimport { useCallback, useRef, useEffect, useMemo } from 'react'\nimport {\n type MachineTypes,\n type Machine,\n type Events,\n type Computed,\n type State,\n type Send,\n type EffectHelpers,\n type EffectStore,\n type Context,\n computeValues,\n executeActions,\n executeHandler,\n processEffects,\n clearEffectStore,\n} from './index'\n\n// ============================================\n// React Hook\n// ============================================\n\nexport function useMachine<T extends MachineTypes>(\n machine: Machine<T>,\n input: T['input'],\n): { send: Send<Events<T>>; computed: Computed<T>; state: State<T> } {\n // refs for stable callbacks\n const inputRef = useRef(input)\n const machineRef = useRef(machine)\n const isMountedRef = useRef(true)\n\n inputRef.current = input\n machineRef.current = machine\n\n // compute values\n const { computed: computedDef } = machine\n const context = useMemo(\n () => computeValues(input, computedDef),\n [input, computedDef],\n )\n\n // extract computed only\n const computed = useMemo(() => {\n if (!computedDef) return {} as Computed<T>\n const result = {} as Computed<T>\n for (const key in computedDef) {\n result[key] = context[key]\n }\n return result\n }, [context, computedDef])\n\n const contextRef = useRef(context)\n contextRef.current = context\n\n const prevContextRef = useRef<Context<T>>(context)\n const effectStoreRef = useRef<EffectStore>({\n watchedValues: new Map(),\n enterCleanups: new Map(),\n changeCleanups: new Map(),\n exitCleanups: new Map(),\n })\n\n // always: auto-evaluate when context changes (synchronous, during render)\n const { always, actions } = machine\n if (prevContextRef.current !== context && always && actions) {\n const actionsMap = actions as Record<string, (context: Context<T>) => void>\n for (const rule of always) {\n if (!rule.when || rule.when(context, undefined)) {\n executeActions(rule.do, actionsMap, context, undefined)\n break\n }\n }\n }\n prevContextRef.current = context\n\n // send: stable function (no deps, uses refs)\n const send: Send<Events<T>> = useCallback(\n <K extends keyof Events<T>>(\n event: K,\n ...args: Events<T>[K] extends undefined ? [] : [payload: Events<T>[K]]\n ) => {\n const currentMachine = machineRef.current\n const currentInput = inputRef.current\n const currentContext = computeValues(\n currentInput,\n currentMachine.computed,\n )\n const payload = args[0] as Events<T>[K]\n\n // 1. State-specific handler first\n const state = (currentContext as { state?: State<T> }).state\n if (state && currentMachine.states?.[state]?.on?.[event]) {\n const stateHandler = currentMachine.states[state].on![event]!\n executeHandler(\n stateHandler,\n currentMachine.actions ?? {},\n currentContext,\n payload,\n )\n }\n\n // 2. Global handler\n const globalHandler = currentMachine.on?.[event]\n if (globalHandler) {\n executeHandler(\n globalHandler,\n currentMachine.actions ?? {},\n currentContext,\n payload,\n )\n }\n },\n [], // no dependencies - uses refs\n )\n\n // safeSend: won't be called after unmount\n const safeSend: Send<Events<T>> = useCallback(\n <K extends keyof Events<T>>(\n event: K,\n ...args: Events<T>[K] extends undefined ? [] : [payload: Events<T>[K]]\n ) => {\n if (!isMountedRef.current) return\n send(event, ...args)\n },\n [send],\n )\n\n // effect helpers\n const effectHelpers: EffectHelpers<Events<T>> = useMemo(\n () => ({ send: safeSend }),\n [safeSend],\n )\n\n // effects: detect watch value changes\n const { effects } = machine\n useEffect(() => {\n processEffects(effects, context, effectHelpers, effectStoreRef.current)\n }, [context, effects, effectHelpers])\n\n // mount/unmount management\n useEffect(() => {\n isMountedRef.current = true\n const store = effectStoreRef.current\n return () => {\n isMountedRef.current = false\n clearEffectStore(store)\n }\n }, [])\n\n // state from context (default to empty string if not provided)\n const state = (context as { state?: State<T> }).state ?? ('' as State<T>)\n\n return { send, computed, state }\n}\n\n// Re-export types for convenience\nexport type { Send } from './index'\n"],"names":["state"],"mappings":";;AA4BO,SAAS,WACd,SACA,OACmE;AAEnE,QAAM,WAAW,OAAO,KAAK;AAC7B,QAAM,aAAa,OAAO,OAAO;AACjC,QAAM,eAAe,OAAO,IAAI;AAEhC,WAAS,UAAU;AACnB,aAAW,UAAU;AAGrB,QAAM,EAAE,UAAU,YAAA,IAAgB;AAClC,QAAM,UAAU;AAAA,IACd,MAAM,cAAc,OAAO,WAAW;AAAA,IACtC,CAAC,OAAO,WAAW;AAAA,EAAA;AAIrB,QAAM,WAAW,QAAQ,MAAM;AAC7B,QAAI,CAAC,YAAa,QAAO,CAAA;AACzB,UAAM,SAAS,CAAA;AACf,eAAW,OAAO,aAAa;AAC7B,aAAO,GAAG,IAAI,QAAQ,GAAG;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,GAAG,CAAC,SAAS,WAAW,CAAC;AAEzB,QAAM,aAAa,OAAO,OAAO;AACjC,aAAW,UAAU;AAErB,QAAM,iBAAiB,OAAmB,OAAO;AACjD,QAAM,iBAAiB,OAAoB;AAAA,IACzC,mCAAmB,IAAA;AAAA,IACnB,mCAAmB,IAAA;AAAA,IACnB,oCAAoB,IAAA;AAAA,IACpB,kCAAkB,IAAA;AAAA,EAAI,CACvB;AAGD,QAAM,EAAE,QAAQ,QAAA,IAAY;AAC5B,MAAI,eAAe,YAAY,WAAW,UAAU,SAAS;AAC3D,UAAM,aAAa;AACnB,eAAW,QAAQ,QAAQ;AACzB,UAAI,CAAC,KAAK,QAAQ,KAAK,KAAK,SAAS,MAAS,GAAG;AAC/C,uBAAe,KAAK,IAAI,YAAY,SAAS,MAAS;AACtD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,iBAAe,UAAU;AAGzB,QAAM,OAAwB;AAAA,IAC5B,CACE,UACG,SACA;AACH,YAAM,iBAAiB,WAAW;AAClC,YAAM,eAAe,SAAS;AAC9B,YAAM,iBAAiB;AAAA,QACrB;AAAA,QACA,eAAe;AAAA,MAAA;AAEjB,YAAM,UAAU,KAAK,CAAC;AAGtB,YAAMA,SAAS,eAAwC;AACvD,UAAIA,UAAS,eAAe,SAASA,MAAK,GAAG,KAAK,KAAK,GAAG;AACxD,cAAM,eAAe,eAAe,OAAOA,MAAK,EAAE,GAAI,KAAK;AAC3D;AAAA,UACE;AAAA,UACA,eAAe,WAAW,CAAA;AAAA,UAC1B;AAAA,UACA;AAAA,QAAA;AAAA,MAEJ;AAGA,YAAM,gBAAgB,eAAe,KAAK,KAAK;AAC/C,UAAI,eAAe;AACjB;AAAA,UACE;AAAA,UACA,eAAe,WAAW,CAAA;AAAA,UAC1B;AAAA,UACA;AAAA,QAAA;AAAA,MAEJ;AAAA,IACF;AAAA,IACA,CAAA;AAAA;AAAA,EAAC;AAIH,QAAM,WAA4B;AAAA,IAChC,CACE,UACG,SACA;AACH,UAAI,CAAC,aAAa,QAAS;AAC3B,WAAK,OAAO,GAAG,IAAI;AAAA,IACrB;AAAA,IACA,CAAC,IAAI;AAAA,EAAA;AAIP,QAAM,gBAA0C;AAAA,IAC9C,OAAO,EAAE,MAAM;IACf,CAAC,QAAQ;AAAA,EAAA;AAIX,QAAM,EAAE,YAAY;AACpB,YAAU,MAAM;AACd,mBAAe,SAAS,SAAS,eAAe,eAAe,OAAO;AAAA,EACxE,GAAG,CAAC,SAAS,SAAS,aAAa,CAAC;AAGpC,YAAU,MAAM;AACd,iBAAa,UAAU;AACvB,UAAM,QAAQ,eAAe;AAC7B,WAAO,MAAM;AACX,mBAAa,UAAU;AACvB,uBAAiB,KAAK;AAAA,IACxB;AAAA,EACF,GAAG,CAAA,CAAE;AAGL,QAAM,QAAS,QAAiC,SAAU;AAE1D,SAAO,EAAE,MAAM,UAAU,MAAA;AAC3B;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "controlled-machine",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A controlled state machine where state lives outside the machine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/react.d.ts",
|
|
21
|
+
"default": "./dist/react.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/react.d.cts",
|
|
25
|
+
"default": "./dist/react.cjs"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "vite build",
|
|
37
|
+
"test": "vitest",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
},
|
|
40
|
+
"keywords": [
|
|
41
|
+
"state-machine",
|
|
42
|
+
"controlled",
|
|
43
|
+
"event-driven",
|
|
44
|
+
"declarative",
|
|
45
|
+
"typescript"
|
|
46
|
+
],
|
|
47
|
+
"author": "Hobin Jang",
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/dev-hobin/controlled-machine.git"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/dev-hobin/controlled-machine/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/dev-hobin/controlled-machine#readme",
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"react": ">=18.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"react": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@testing-library/react": "^16.3.1",
|
|
67
|
+
"@types/react": "^19.2.8",
|
|
68
|
+
"jsdom": "^27.4.0",
|
|
69
|
+
"react": "^19.2.3",
|
|
70
|
+
"typescript": "^5.9.3",
|
|
71
|
+
"vite": "^7.3.1",
|
|
72
|
+
"vite-plugin-dts": "^4.5.4",
|
|
73
|
+
"vitest": "^4.0.16"
|
|
74
|
+
}
|
|
75
|
+
}
|