@voidhash/mimic-react 0.0.1 → 0.0.3

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 (61) hide show
  1. package/.turbo/turbo-build.log +60 -26
  2. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
  9. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
  10. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
  11. package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
  12. package/dist/zustand/index.cjs +2 -94
  13. package/dist/zustand/index.d.cts +3 -115
  14. package/dist/zustand/index.d.mts +3 -115
  15. package/dist/zustand/index.mjs +2 -95
  16. package/dist/zustand/middleware.cjs +95 -0
  17. package/dist/zustand/middleware.d.cts +47 -0
  18. package/dist/zustand/middleware.d.cts.map +1 -0
  19. package/dist/zustand/middleware.d.mts +47 -0
  20. package/dist/zustand/middleware.d.mts.map +1 -0
  21. package/dist/zustand/middleware.mjs +96 -0
  22. package/dist/zustand/middleware.mjs.map +1 -0
  23. package/dist/zustand/types.d.cts +75 -0
  24. package/dist/zustand/types.d.cts.map +1 -0
  25. package/dist/zustand/types.d.mts +75 -0
  26. package/dist/zustand/types.d.mts.map +1 -0
  27. package/dist/zustand-commander/commander.cjs +187 -0
  28. package/dist/zustand-commander/commander.d.cts +52 -0
  29. package/dist/zustand-commander/commander.d.cts.map +1 -0
  30. package/dist/zustand-commander/commander.d.mts +52 -0
  31. package/dist/zustand-commander/commander.d.mts.map +1 -0
  32. package/dist/zustand-commander/commander.mjs +185 -0
  33. package/dist/zustand-commander/commander.mjs.map +1 -0
  34. package/dist/zustand-commander/hooks.cjs +145 -0
  35. package/dist/zustand-commander/hooks.d.cts +78 -0
  36. package/dist/zustand-commander/hooks.d.cts.map +1 -0
  37. package/dist/zustand-commander/hooks.d.mts +78 -0
  38. package/dist/zustand-commander/hooks.d.mts.map +1 -0
  39. package/dist/zustand-commander/hooks.mjs +144 -0
  40. package/dist/zustand-commander/hooks.mjs.map +1 -0
  41. package/dist/zustand-commander/index.cjs +15 -354
  42. package/dist/zustand-commander/index.d.cts +4 -313
  43. package/dist/zustand-commander/index.d.mts +4 -313
  44. package/dist/zustand-commander/index.mjs +4 -344
  45. package/dist/zustand-commander/types.cjs +28 -0
  46. package/dist/zustand-commander/types.d.cts +195 -0
  47. package/dist/zustand-commander/types.d.cts.map +1 -0
  48. package/dist/zustand-commander/types.d.mts +195 -0
  49. package/dist/zustand-commander/types.d.mts.map +1 -0
  50. package/dist/zustand-commander/types.mjs +25 -0
  51. package/dist/zustand-commander/types.mjs.map +1 -0
  52. package/package.json +3 -3
  53. package/tsdown.config.ts +1 -1
  54. package/dist/objectSpread2-CIP_6jda.cjs +0 -73
  55. package/dist/objectSpread2-CxTyNSYl.mjs +0 -67
  56. package/dist/zustand/index.d.cts.map +0 -1
  57. package/dist/zustand/index.d.mts.map +0 -1
  58. package/dist/zustand/index.mjs.map +0 -1
  59. package/dist/zustand-commander/index.d.cts.map +0 -1
  60. package/dist/zustand-commander/index.d.mts.map +0 -1
  61. package/dist/zustand-commander/index.mjs.map +0 -1
@@ -1,345 +1,5 @@
1
- import { t as _objectSpread2 } from "../objectSpread2-CxTyNSYl.mjs";
2
- import { useCallback, useEffect, useMemo } from "react";
3
- import { useStore } from "zustand";
1
+ import { COMMAND_SYMBOL, UNDOABLE_COMMAND_SYMBOL, isCommand, isUndoableCommand } from "./types.mjs";
2
+ import { clearUndoHistory, createCommander, performRedo, performUndo } from "./commander.mjs";
3
+ import { useCommander, useUndoRedo, useUndoRedoKeyboard } from "./hooks.mjs";
4
4
 
5
- //#region src/zustand-commander/types.ts
6
- /**
7
- * Symbol used to identify Command objects at runtime.
8
- */
9
- const COMMAND_SYMBOL = Symbol.for("zustand-commander/command");
10
- /**
11
- * Symbol used to identify UndoableCommand objects at runtime.
12
- */
13
- const UNDOABLE_COMMAND_SYMBOL = Symbol.for("zustand-commander/undoable-command");
14
- /**
15
- * Type guard to check if a value is a Command.
16
- */
17
- function isCommand(value) {
18
- return typeof value === "object" && value !== null && COMMAND_SYMBOL in value && value[COMMAND_SYMBOL] === true;
19
- }
20
- /**
21
- * Type guard to check if a command is undoable.
22
- */
23
- function isUndoableCommand(value) {
24
- return isCommand(value) && UNDOABLE_COMMAND_SYMBOL in value && value[UNDOABLE_COMMAND_SYMBOL] === true;
25
- }
26
-
27
- //#endregion
28
- //#region src/zustand-commander/commander.ts
29
- const DEFAULT_OPTIONS = { maxUndoStackSize: 100 };
30
- /**
31
- * Creates a commander instance bound to a specific store type.
32
- *
33
- * @example
34
- * ```ts
35
- * // Create commander for your store type
36
- * const commander = createCommander<StoreState>();
37
- *
38
- * // Define commands
39
- * const addItem = commander.action(
40
- * Schema.Struct({ name: Schema.String }),
41
- * (ctx, params) => {
42
- * const { mimic } = ctx.getState();
43
- * mimic.document.transaction(root => {
44
- * // add item
45
- * });
46
- * }
47
- * );
48
- *
49
- * // Create store with middleware
50
- * const useStore = create(
51
- * commander.middleware(
52
- * mimic(document, (set, get) => ({
53
- * // your state
54
- * }))
55
- * )
56
- * );
57
- * ```
58
- */
59
- function createCommander(options = {}) {
60
- const { maxUndoStackSize } = _objectSpread2(_objectSpread2({}, DEFAULT_OPTIONS), options);
61
- let _storeApi = null;
62
- /**
63
- * Creates the dispatch function for use within command handlers.
64
- */
65
- const createDispatch = () => {
66
- return (command) => {
67
- return (params) => {
68
- if (!_storeApi) throw new Error("Commander: Store not initialized. Make sure to use the commander middleware.");
69
- const ctx = {
70
- getState: () => _storeApi.getState(),
71
- setState: (partial) => _storeApi.setState(partial),
72
- dispatch: createDispatch()
73
- };
74
- const result = command.fn(ctx, params);
75
- if (isUndoableCommand(command)) {
76
- const entry = {
77
- command,
78
- params,
79
- result,
80
- timestamp: Date.now()
81
- };
82
- _storeApi.setState((state) => {
83
- const { undoStack, redoStack } = state._commander;
84
- const newUndoStack = [...undoStack, entry].slice(-maxUndoStackSize);
85
- return _objectSpread2(_objectSpread2({}, state), {}, { _commander: {
86
- undoStack: newUndoStack,
87
- redoStack: []
88
- } });
89
- });
90
- }
91
- return result;
92
- };
93
- };
94
- };
95
- /**
96
- * Create a regular command (no undo support).
97
- */
98
- function action(fn) {
99
- return {
100
- [COMMAND_SYMBOL]: true,
101
- fn
102
- };
103
- }
104
- /**
105
- * Create an undoable command with undo/redo support.
106
- */
107
- function undoableAction(fn, revert) {
108
- return {
109
- [COMMAND_SYMBOL]: true,
110
- [UNDOABLE_COMMAND_SYMBOL]: true,
111
- fn,
112
- revert
113
- };
114
- }
115
- /**
116
- * Zustand middleware that adds commander functionality.
117
- */
118
- const middleware = (config) => {
119
- return (set, get, api) => {
120
- _storeApi = api;
121
- return _objectSpread2(_objectSpread2({}, config(set, get, api)), {}, { _commander: {
122
- undoStack: [],
123
- redoStack: []
124
- } });
125
- };
126
- };
127
- return {
128
- action,
129
- undoableAction,
130
- middleware
131
- };
132
- }
133
- /**
134
- * Perform an undo operation on the store.
135
- * Returns true if an undo was performed, false if undo stack was empty.
136
- */
137
- function performUndo(storeApi) {
138
- const { undoStack, redoStack } = storeApi.getState()._commander;
139
- const entry = undoStack[undoStack.length - 1];
140
- if (!entry) return false;
141
- const newUndoStack = undoStack.slice(0, -1);
142
- const ctx = {
143
- getState: () => storeApi.getState(),
144
- setState: (partial) => storeApi.setState(partial),
145
- dispatch: createDispatchForUndo(storeApi)
146
- };
147
- entry.command.revert(ctx, entry.params, entry.result);
148
- storeApi.setState((state) => _objectSpread2(_objectSpread2({}, state), {}, { _commander: {
149
- undoStack: newUndoStack,
150
- redoStack: [...redoStack, entry]
151
- } }));
152
- return true;
153
- }
154
- /**
155
- * Perform a redo operation on the store.
156
- * Returns true if a redo was performed, false if redo stack was empty.
157
- */
158
- function performRedo(storeApi) {
159
- const { undoStack, redoStack } = storeApi.getState()._commander;
160
- const entry = redoStack[redoStack.length - 1];
161
- if (!entry) return false;
162
- const newRedoStack = redoStack.slice(0, -1);
163
- const ctx = {
164
- getState: () => storeApi.getState(),
165
- setState: (partial) => storeApi.setState(partial),
166
- dispatch: createDispatchForUndo(storeApi)
167
- };
168
- const result = entry.command.fn(ctx, entry.params);
169
- const newEntry = {
170
- command: entry.command,
171
- params: entry.params,
172
- result,
173
- timestamp: Date.now()
174
- };
175
- storeApi.setState((state) => _objectSpread2(_objectSpread2({}, state), {}, { _commander: {
176
- undoStack: [...undoStack, newEntry],
177
- redoStack: newRedoStack
178
- } }));
179
- return true;
180
- }
181
- /**
182
- * Creates a dispatch function for use during undo/redo operations.
183
- * This dispatch does NOT add to undo stack (to avoid infinite loops).
184
- */
185
- function createDispatchForUndo(storeApi) {
186
- return (command) => {
187
- return (params) => {
188
- const ctx = {
189
- getState: () => storeApi.getState(),
190
- setState: (partial) => storeApi.setState(partial),
191
- dispatch: createDispatchForUndo(storeApi)
192
- };
193
- return command.fn(ctx, params);
194
- };
195
- };
196
- }
197
- /**
198
- * Clear the undo and redo stacks.
199
- */
200
- function clearUndoHistory(storeApi) {
201
- storeApi.setState((state) => _objectSpread2(_objectSpread2({}, state), {}, { _commander: {
202
- undoStack: [],
203
- redoStack: []
204
- } }));
205
- }
206
-
207
- //#endregion
208
- //#region src/zustand-commander/hooks.ts
209
- /**
210
- * @voidhash/mimic-react/zustand-commander
211
- *
212
- * React hooks for zustand-commander.
213
- *
214
- * @since 0.0.1
215
- */
216
- /**
217
- * Creates a dispatch function for commands.
218
- * This is for use outside of React components (e.g., in command handlers).
219
- */
220
- function createDispatchFromApi(storeApi, maxUndoStackSize = 100) {
221
- const dispatch = (command) => {
222
- return (params) => {
223
- const ctx = {
224
- getState: () => storeApi.getState(),
225
- setState: (partial) => storeApi.setState(partial),
226
- dispatch
227
- };
228
- const result = command.fn(ctx, params);
229
- if (isUndoableCommand(command)) storeApi.setState((state) => {
230
- const { undoStack } = state._commander;
231
- const newUndoStack = [...undoStack, {
232
- command,
233
- params,
234
- result,
235
- timestamp: Date.now()
236
- }].slice(-maxUndoStackSize);
237
- return _objectSpread2(_objectSpread2({}, state), {}, { _commander: {
238
- undoStack: newUndoStack,
239
- redoStack: []
240
- } });
241
- });
242
- return result;
243
- };
244
- };
245
- return dispatch;
246
- }
247
- /**
248
- * React hook to get a dispatch function for commands.
249
- * The dispatch function executes commands and manages undo/redo state.
250
- *
251
- * @example
252
- * ```tsx
253
- * const dispatch = useCommander(useStore);
254
- *
255
- * const handleClick = () => {
256
- * dispatch(addCard)({ columnId: "col-1", title: "New Card" });
257
- * };
258
- * ```
259
- */
260
- function useCommander(store) {
261
- const storeApi = useMemo(() => {
262
- return store;
263
- }, [store]);
264
- return useMemo(() => createDispatchFromApi(storeApi), [storeApi]);
265
- }
266
- /**
267
- * React hook for undo/redo functionality.
268
- * Provides state (canUndo, canRedo) and actions (undo, redo, clear).
269
- *
270
- * @example
271
- * ```tsx
272
- * const { canUndo, canRedo, undo, redo } = useUndoRedo(useStore);
273
- *
274
- * return (
275
- * <>
276
- * <button onClick={undo} disabled={!canUndo}>Undo</button>
277
- * <button onClick={redo} disabled={!canRedo}>Redo</button>
278
- * </>
279
- * );
280
- * ```
281
- */
282
- function useUndoRedo(store) {
283
- const storeApi = useMemo(() => {
284
- return store;
285
- }, [store]);
286
- const commanderState = useStore(store, (state) => state._commander);
287
- return {
288
- canUndo: commanderState.undoStack.length > 0,
289
- canRedo: commanderState.redoStack.length > 0,
290
- undoCount: commanderState.undoStack.length,
291
- redoCount: commanderState.redoStack.length,
292
- undo: useCallback(() => {
293
- return performUndo(storeApi);
294
- }, [storeApi]),
295
- redo: useCallback(() => {
296
- return performRedo(storeApi);
297
- }, [storeApi]),
298
- clear: useCallback(() => {
299
- clearUndoHistory(storeApi);
300
- }, [storeApi])
301
- };
302
- }
303
- /**
304
- * React hook that adds keyboard shortcuts for undo/redo.
305
- * Listens for Ctrl/Cmd+Z (undo) and Ctrl/Cmd+Shift+Z or Ctrl+Y (redo).
306
- *
307
- * @example
308
- * ```tsx
309
- * // In your app component
310
- * useUndoRedoKeyboard(useStore);
311
- * ```
312
- */
313
- function useUndoRedoKeyboard(store, options = {}) {
314
- const { enableUndo = true, enableRedo = true } = options;
315
- const storeApi = useMemo(() => {
316
- return store;
317
- }, [store]);
318
- useEffect(() => {
319
- if (typeof window === "undefined") return;
320
- const handleKeyDown = (event) => {
321
- if (!(navigator.platform.toUpperCase().indexOf("MAC") >= 0 ? event.metaKey : event.ctrlKey)) return;
322
- if (enableUndo && event.key === "z" && !event.shiftKey) {
323
- event.preventDefault();
324
- performUndo(storeApi);
325
- return;
326
- }
327
- if (enableRedo) {
328
- if (event.key === "z" && event.shiftKey || event.key === "y") {
329
- event.preventDefault();
330
- performRedo(storeApi);
331
- }
332
- }
333
- };
334
- window.addEventListener("keydown", handleKeyDown);
335
- return () => window.removeEventListener("keydown", handleKeyDown);
336
- }, [
337
- storeApi,
338
- enableUndo,
339
- enableRedo
340
- ]);
341
- }
342
-
343
- //#endregion
344
- export { COMMAND_SYMBOL, UNDOABLE_COMMAND_SYMBOL, clearUndoHistory, createCommander, isCommand, isUndoableCommand, performRedo, performUndo, useCommander, useUndoRedo, useUndoRedoKeyboard };
345
- //# sourceMappingURL=index.mjs.map
5
+ export { COMMAND_SYMBOL, UNDOABLE_COMMAND_SYMBOL, clearUndoHistory, createCommander, isCommand, isUndoableCommand, performRedo, performUndo, useCommander, useUndoRedo, useUndoRedoKeyboard };
@@ -0,0 +1,28 @@
1
+
2
+ //#region src/zustand-commander/types.ts
3
+ /**
4
+ * Symbol used to identify Command objects at runtime.
5
+ */
6
+ const COMMAND_SYMBOL = Symbol.for("zustand-commander/command");
7
+ /**
8
+ * Symbol used to identify UndoableCommand objects at runtime.
9
+ */
10
+ const UNDOABLE_COMMAND_SYMBOL = Symbol.for("zustand-commander/undoable-command");
11
+ /**
12
+ * Type guard to check if a value is a Command.
13
+ */
14
+ function isCommand(value) {
15
+ return typeof value === "object" && value !== null && COMMAND_SYMBOL in value && value[COMMAND_SYMBOL] === true;
16
+ }
17
+ /**
18
+ * Type guard to check if a command is undoable.
19
+ */
20
+ function isUndoableCommand(value) {
21
+ return isCommand(value) && UNDOABLE_COMMAND_SYMBOL in value && value[UNDOABLE_COMMAND_SYMBOL] === true;
22
+ }
23
+
24
+ //#endregion
25
+ exports.COMMAND_SYMBOL = COMMAND_SYMBOL;
26
+ exports.UNDOABLE_COMMAND_SYMBOL = UNDOABLE_COMMAND_SYMBOL;
27
+ exports.isCommand = isCommand;
28
+ exports.isUndoableCommand = isUndoableCommand;
@@ -0,0 +1,195 @@
1
+ import { StoreApi, UseBoundStore } from "zustand";
2
+
3
+ //#region src/zustand-commander/types.d.ts
4
+
5
+ /**
6
+ * Symbol used to identify Command objects at runtime.
7
+ */
8
+ declare const COMMAND_SYMBOL: unique symbol;
9
+ /**
10
+ * Symbol used to identify UndoableCommand objects at runtime.
11
+ */
12
+ declare const UNDOABLE_COMMAND_SYMBOL: unique symbol;
13
+ /**
14
+ * Context provided to command functions.
15
+ * Gives access to store state and dispatch capabilities.
16
+ */
17
+ interface CommandContext<TStore> {
18
+ /**
19
+ * Get the current store state.
20
+ */
21
+ readonly getState: () => TStore;
22
+ /**
23
+ * Set partial store state (for local/browser state updates).
24
+ */
25
+ readonly setState: (partial: Partial<TStore>) => void;
26
+ /**
27
+ * Dispatch another command.
28
+ * Returns the result of the dispatched command.
29
+ *
30
+ * @example
31
+ * dispatch(otherCommand)({ param: "value" });
32
+ */
33
+ readonly dispatch: CommandDispatch<TStore>;
34
+ }
35
+ /**
36
+ * The function signature for a command handler.
37
+ */
38
+ type CommandFn<TStore, TParams, TReturn> = (ctx: CommandContext<TStore>, params: TParams) => TReturn;
39
+ /**
40
+ * The function signature for an undoable command's revert handler.
41
+ * Receives the original params and the result from the forward execution.
42
+ */
43
+ type RevertFn<TStore, TParams, TReturn> = (ctx: CommandContext<TStore>, params: TParams, result: TReturn) => void;
44
+ /**
45
+ * A command that can be dispatched to modify store state.
46
+ * Regular commands do not support undo/redo.
47
+ */
48
+ interface Command<TStore, TParams, TReturn> {
49
+ readonly [COMMAND_SYMBOL]: true;
50
+ readonly fn: CommandFn<TStore, TParams, TReturn>;
51
+ }
52
+ /**
53
+ * An undoable command that supports undo/redo.
54
+ * Must provide a revert function that knows how to undo the change.
55
+ */
56
+ interface UndoableCommand<TStore, TParams, TReturn> extends Command<TStore, TParams, TReturn> {
57
+ readonly [UNDOABLE_COMMAND_SYMBOL]: true;
58
+ readonly revert: RevertFn<TStore, TParams, TReturn>;
59
+ }
60
+ /**
61
+ * Any command type (regular or undoable).
62
+ */
63
+ type AnyCommand = Command<any, any, any>;
64
+ /**
65
+ * Any undoable command type.
66
+ */
67
+ type AnyUndoableCommand = UndoableCommand<any, any, any>;
68
+ /**
69
+ * Dispatch function that accepts commands and returns a function to call with params.
70
+ * Returns the result of the command execution.
71
+ *
72
+ * @example
73
+ * const result = dispatch(myCommand)({ param: "value" });
74
+ */
75
+ type CommandDispatch<TStore> = <TParams, TReturn>(command: Command<TStore, TParams, TReturn>) => (params: TParams) => TReturn;
76
+ /**
77
+ * An entry in the undo/redo stack.
78
+ * Contains all information needed to revert or redo a command.
79
+ */
80
+ interface UndoEntry<TParams = unknown, TReturn = unknown> {
81
+ /** The undoable command that was executed */
82
+ readonly command: AnyUndoableCommand;
83
+ /** The parameters that were passed to the command */
84
+ readonly params: TParams;
85
+ /** The result returned by the command (passed to revert) */
86
+ readonly result: TReturn;
87
+ /** Timestamp when the command was executed */
88
+ readonly timestamp: number;
89
+ }
90
+ /**
91
+ * State slice for undo/redo functionality.
92
+ */
93
+ interface CommanderSlice {
94
+ readonly _commander: {
95
+ /** Stack of commands that can be undone */
96
+ readonly undoStack: ReadonlyArray<UndoEntry>;
97
+ /** Stack of commands that can be redone */
98
+ readonly redoStack: ReadonlyArray<UndoEntry>;
99
+ };
100
+ }
101
+ /**
102
+ * Options for creating a commander.
103
+ */
104
+ interface CommanderOptions {
105
+ /**
106
+ * Maximum number of undo entries to keep.
107
+ * @default 100
108
+ */
109
+ readonly maxUndoStackSize?: number;
110
+ }
111
+ /**
112
+ * A commander instance bound to a specific store type.
113
+ * Used to create commands and the middleware.
114
+ */
115
+ interface Commander<TStore> {
116
+ /**
117
+ * Create a regular command (no undo support).
118
+ *
119
+ * @example
120
+ * // With params
121
+ * const addItem = commander.action<{ name: string }>(
122
+ * (ctx, params) => {
123
+ * // modify state using params.name
124
+ * }
125
+ * );
126
+ *
127
+ * // Without params
128
+ * const clearAll = commander.action((ctx) => {
129
+ * // modify state
130
+ * });
131
+ */
132
+ readonly action: {
133
+ <TParams, TReturn = void>(fn: CommandFn<TStore, TParams, TReturn>): Command<TStore, TParams, TReturn>;
134
+ <TReturn = void>(fn: CommandFn<TStore, void, TReturn>): Command<TStore, void, TReturn>;
135
+ };
136
+ /**
137
+ * Create an undoable command with undo/redo support.
138
+ * The revert function is called when undoing the command.
139
+ *
140
+ * @example
141
+ * const moveItem = commander.undoableAction<{ id: string; toIndex: number }, { fromIndex: number }>(
142
+ * (ctx, params) => {
143
+ * const fromIndex = // get current index
144
+ * // perform move
145
+ * return { fromIndex }; // return data needed for revert
146
+ * },
147
+ * (ctx, params, result) => {
148
+ * // revert: move back to original position
149
+ * ctx.dispatch(moveItem)({ id: params.id, toIndex: result.fromIndex });
150
+ * }
151
+ * );
152
+ */
153
+ readonly undoableAction: {
154
+ <TParams, TReturn>(fn: CommandFn<TStore, TParams, TReturn>, revert: RevertFn<TStore, TParams, TReturn>): UndoableCommand<TStore, TParams, TReturn>;
155
+ <TReturn>(fn: CommandFn<TStore, void, TReturn>, revert: RevertFn<TStore, void, TReturn>): UndoableCommand<TStore, void, TReturn>;
156
+ };
157
+ /**
158
+ * Zustand middleware that adds commander functionality.
159
+ * Adds undo/redo stacks to the store state.
160
+ */
161
+ readonly middleware: CommanderMiddleware<TStore>;
162
+ }
163
+ /**
164
+ * Type for the commander middleware.
165
+ * Note: TStore is intentionally unused here to match the Commander interface signature.
166
+ * The middleware is generic over T (the inner store type) and adds CommanderSlice.
167
+ */
168
+ type CommanderMiddleware<_TStore> = <T extends object>(config: (set: StoreApi<T & CommanderSlice>["setState"], get: StoreApi<T & CommanderSlice>["getState"], api: StoreApi<T & CommanderSlice>) => T) => (set: StoreApi<T & CommanderSlice>["setState"], get: StoreApi<T & CommanderSlice>["getState"], api: StoreApi<T & CommanderSlice>) => T & CommanderSlice;
169
+ /**
170
+ * Extract the params type from a command.
171
+ */
172
+ type CommandParams<T> = T extends Command<any, infer P, any> ? P : never;
173
+ /**
174
+ * Extract the return type from a command.
175
+ */
176
+ type CommandReturn<T> = T extends Command<any, any, infer R> ? R : undefined;
177
+ /**
178
+ * Extract the store type from a command.
179
+ */
180
+ type CommandStore<T> = T extends Command<infer S, any, any> ? S : never;
181
+ /**
182
+ * Type guard to check if a value is a Command.
183
+ */
184
+ declare function isCommand(value: unknown): value is AnyCommand;
185
+ /**
186
+ * Type guard to check if a command is undoable.
187
+ */
188
+ declare function isUndoableCommand(value: unknown): value is AnyUndoableCommand;
189
+ /**
190
+ * Helper type to extract the state type from a zustand store.
191
+ */
192
+ type ExtractState<TStore> = TStore extends UseBoundStore<StoreApi<infer S>> ? S : TStore extends StoreApi<infer S> ? S : never;
193
+ //#endregion
194
+ export { AnyCommand, AnyUndoableCommand, COMMAND_SYMBOL, Command, CommandContext, CommandDispatch, CommandFn, CommandParams, CommandReturn, CommandStore, Commander, CommanderMiddleware, CommanderOptions, CommanderSlice, ExtractState, RevertFn, UNDOABLE_COMMAND_SYMBOL, UndoEntry, UndoableCommand, isCommand, isUndoableCommand };
195
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/zustand-commander/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAoDoC,cAnCvB,cAmCuB,EAAA,OAAA,MAAA;AAUpC;;;AAEU,cA1CG,uBA0CH,EAAA,OAAA,MAAA;;;AAOV;;AACO,UAtCU,cAsCV,CAAA,MAAA,CAAA,CAAA;EACG;;;EAYO,SAAA,QAAO,EAAA,GAAA,GA/CG,MA+CH;EACZ;;;EAC8B,SAAA,QAAA,EAAA,CAAA,OAAA,EA5CX,OA4CW,CA5CH,MA4CG,CAAA,EAAA,GAAA,IAAA;EAA3B;;AAOf;;;;;EAG4B,SAAA,QAAA,EA7CP,eA6CO,CA7CS,MA6CT,CAAA;;;;;AAFX,KAjCL,SAiCK,CAAA,MAAA,EAAA,OAAA,EAAA,OAAA,CAAA,GAAA,CAAA,GAAA,EAhCV,cAgCU,CAhCK,MAgCL,CAAA,EAAA,MAAA,EA/BP,OA+BO,EAAA,GA9BZ,OA8BY;AAQjB;AAKA;AAaA;;AAC2B,KAnDf,QAmDe,CAAA,MAAA,EAAA,OAAA,EAAA,OAAA,CAAA,GAAA,CAAA,GAAA,EAlDpB,cAkDoB,CAlDL,MAkDK,CAAA,EAAA,MAAA,EAjDjB,OAiDiB,EAAA,MAAA,EAhDjB,OAgDiB,EAAA,GAAA,IAAA;;;;;AACM,UAtChB,OAsCgB,CAAA,MAAA,EAAA,OAAA,EAAA,OAAA,CAAA,CAAA;EAUhB,UA/CL,cAAA,CA+Cc,EAAA,IAAA;EAEN,SAAA,EAAA,EAhDL,SAgDK,CAhDK,MAgDL,EAhDa,OAgDb,EAhDsB,OAgDtB,CAAA;;;;AAYpB;;AAGwB,UAxDP,eAwDO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