@composy/store-vue 0.0.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 +154 -0
- package/dist/index.js +1536 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1008 -0
- package/dist/index.min.js.map +1 -0
- package/es/composables/defineSetupStore.d.ts +120 -0
- package/es/composables/defineSetupStore.d.ts.map +1 -0
- package/es/composables/defineSetupStore.js +29 -0
- package/es/composables/defineSetupStore.js.map +1 -0
- package/es/composables/index.d.ts +24 -0
- package/es/composables/index.d.ts.map +1 -0
- package/es/composables/index.js +21 -0
- package/es/composables/useFormStore.d.ts +131 -0
- package/es/composables/useFormStore.d.ts.map +1 -0
- package/es/composables/useFormStore.js +189 -0
- package/es/composables/useFormStore.js.map +1 -0
- package/es/composables/useOptimistic.d.ts +67 -0
- package/es/composables/useOptimistic.d.ts.map +1 -0
- package/es/composables/useOptimistic.js +64 -0
- package/es/composables/useOptimistic.js.map +1 -0
- package/es/composables/usePersist.d.ts +68 -0
- package/es/composables/usePersist.d.ts.map +1 -0
- package/es/composables/usePersist.js +96 -0
- package/es/composables/usePersist.js.map +1 -0
- package/es/composables/usePersistedState.d.ts +59 -0
- package/es/composables/usePersistedState.d.ts.map +1 -0
- package/es/composables/usePersistedState.js +121 -0
- package/es/composables/usePersistedState.js.map +1 -0
- package/es/composables/useSharedState.d.ts +62 -0
- package/es/composables/useSharedState.d.ts.map +1 -0
- package/es/composables/useSharedState.js +94 -0
- package/es/composables/useSharedState.js.map +1 -0
- package/es/composables/useStore.d.ts +99 -0
- package/es/composables/useStore.d.ts.map +1 -0
- package/es/composables/useStore.js +61 -0
- package/es/composables/useStore.js.map +1 -0
- package/es/composables/useStoreDevtools.d.ts +31 -0
- package/es/composables/useStoreDevtools.d.ts.map +1 -0
- package/es/composables/useStoreDevtools.js +112 -0
- package/es/composables/useStoreDevtools.js.map +1 -0
- package/es/composables/useStoreSnapshot.d.ts +122 -0
- package/es/composables/useStoreSnapshot.d.ts.map +1 -0
- package/es/composables/useStoreSnapshot.js +209 -0
- package/es/composables/useStoreSnapshot.js.map +1 -0
- package/es/composables/useSubscribe.d.ts +90 -0
- package/es/composables/useSubscribe.d.ts.map +1 -0
- package/es/composables/useSubscribe.js +53 -0
- package/es/composables/useSubscribe.js.map +1 -0
- package/es/context/injection-keys.d.ts +8 -0
- package/es/context/injection-keys.d.ts.map +1 -0
- package/es/context/injection-keys.js +17 -0
- package/es/context/injection-keys.js.map +1 -0
- package/es/index.d.ts +24 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +32 -0
- package/es/index.js.map +1 -0
- package/es/plugins/engine-plugin.d.ts +36 -0
- package/es/plugins/engine-plugin.d.ts.map +1 -0
- package/es/plugins/engine-plugin.js +83 -0
- package/es/plugins/engine-plugin.js.map +1 -0
- package/es/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/es/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/es/plugins/enhanced-persist-plugin.js +12 -0
- package/es/plugins/index.d.ts +7 -0
- package/es/plugins/index.d.ts.map +1 -0
- package/es/plugins/index.js +15 -0
- package/es/plugins/pinia-plugin.d.ts +68 -0
- package/es/plugins/pinia-plugin.d.ts.map +1 -0
- package/es/plugins/pinia-plugin.js +172 -0
- package/es/plugins/pinia-plugin.js.map +1 -0
- package/es/plugins/registry-plugin.d.ts +2 -0
- package/es/plugins/registry-plugin.d.ts.map +1 -0
- package/es/plugins/registry-plugin.js +12 -0
- package/es/plugins/vue-plugin.d.ts +10 -0
- package/es/plugins/vue-plugin.d.ts.map +1 -0
- package/es/plugins/vue-plugin.js +24 -0
- package/es/plugins/vue-plugin.js.map +1 -0
- package/es/runtime/install-store-app.d.ts +23 -0
- package/es/runtime/install-store-app.d.ts.map +1 -0
- package/es/runtime/install-store-app.js +54 -0
- package/es/runtime/install-store-app.js.map +1 -0
- package/es/runtime/store-plugin-options.d.ts +40 -0
- package/es/runtime/store-plugin-options.d.ts.map +1 -0
- package/es/runtime/store-plugin-options.js +24 -0
- package/es/runtime/store-plugin-options.js.map +1 -0
- package/es/runtime/store-registry.d.ts +64 -0
- package/es/runtime/store-registry.d.ts.map +1 -0
- package/es/runtime/store-registry.js +102 -0
- package/es/runtime/store-registry.js.map +1 -0
- package/es/runtime/store-runtime.d.ts +46 -0
- package/es/runtime/store-runtime.d.ts.map +1 -0
- package/es/runtime/store-runtime.js +58 -0
- package/es/runtime/store-runtime.js.map +1 -0
- package/es/types.d.ts +167 -0
- package/es/types.d.ts.map +1 -0
- package/es/types.js +10 -0
- package/esm/composables/defineSetupStore.d.ts +120 -0
- package/esm/composables/defineSetupStore.d.ts.map +1 -0
- package/esm/composables/defineSetupStore.js +29 -0
- package/esm/composables/defineSetupStore.js.map +1 -0
- package/esm/composables/index.d.ts +24 -0
- package/esm/composables/index.d.ts.map +1 -0
- package/esm/composables/index.js +21 -0
- package/esm/composables/useFormStore.d.ts +131 -0
- package/esm/composables/useFormStore.d.ts.map +1 -0
- package/esm/composables/useFormStore.js +189 -0
- package/esm/composables/useFormStore.js.map +1 -0
- package/esm/composables/useOptimistic.d.ts +67 -0
- package/esm/composables/useOptimistic.d.ts.map +1 -0
- package/esm/composables/useOptimistic.js +64 -0
- package/esm/composables/useOptimistic.js.map +1 -0
- package/esm/composables/usePersist.d.ts +68 -0
- package/esm/composables/usePersist.d.ts.map +1 -0
- package/esm/composables/usePersist.js +96 -0
- package/esm/composables/usePersist.js.map +1 -0
- package/esm/composables/usePersistedState.d.ts +59 -0
- package/esm/composables/usePersistedState.d.ts.map +1 -0
- package/esm/composables/usePersistedState.js +121 -0
- package/esm/composables/usePersistedState.js.map +1 -0
- package/esm/composables/useSharedState.d.ts +62 -0
- package/esm/composables/useSharedState.d.ts.map +1 -0
- package/esm/composables/useSharedState.js +94 -0
- package/esm/composables/useSharedState.js.map +1 -0
- package/esm/composables/useStore.d.ts +99 -0
- package/esm/composables/useStore.d.ts.map +1 -0
- package/esm/composables/useStore.js +61 -0
- package/esm/composables/useStore.js.map +1 -0
- package/esm/composables/useStoreDevtools.d.ts +31 -0
- package/esm/composables/useStoreDevtools.d.ts.map +1 -0
- package/esm/composables/useStoreDevtools.js +112 -0
- package/esm/composables/useStoreDevtools.js.map +1 -0
- package/esm/composables/useStoreSnapshot.d.ts +122 -0
- package/esm/composables/useStoreSnapshot.d.ts.map +1 -0
- package/esm/composables/useStoreSnapshot.js +209 -0
- package/esm/composables/useStoreSnapshot.js.map +1 -0
- package/esm/composables/useSubscribe.d.ts +90 -0
- package/esm/composables/useSubscribe.d.ts.map +1 -0
- package/esm/composables/useSubscribe.js +53 -0
- package/esm/composables/useSubscribe.js.map +1 -0
- package/esm/context/injection-keys.d.ts +8 -0
- package/esm/context/injection-keys.d.ts.map +1 -0
- package/esm/context/injection-keys.js +17 -0
- package/esm/context/injection-keys.js.map +1 -0
- package/esm/index.d.ts +24 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +34 -0
- package/esm/index.js.map +1 -0
- package/esm/plugins/engine-plugin.d.ts +36 -0
- package/esm/plugins/engine-plugin.d.ts.map +1 -0
- package/esm/plugins/engine-plugin.js +83 -0
- package/esm/plugins/engine-plugin.js.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/esm/plugins/enhanced-persist-plugin.d.ts.map +1 -0
- package/esm/plugins/enhanced-persist-plugin.js +12 -0
- package/esm/plugins/index.d.ts +7 -0
- package/esm/plugins/index.d.ts.map +1 -0
- package/esm/plugins/index.js +16 -0
- package/esm/plugins/pinia-plugin.d.ts +68 -0
- package/esm/plugins/pinia-plugin.d.ts.map +1 -0
- package/esm/plugins/pinia-plugin.js +172 -0
- package/esm/plugins/pinia-plugin.js.map +1 -0
- package/esm/plugins/registry-plugin.d.ts +2 -0
- package/esm/plugins/registry-plugin.d.ts.map +1 -0
- package/esm/plugins/registry-plugin.js +12 -0
- package/esm/plugins/vue-plugin.d.ts +10 -0
- package/esm/plugins/vue-plugin.d.ts.map +1 -0
- package/esm/plugins/vue-plugin.js +24 -0
- package/esm/plugins/vue-plugin.js.map +1 -0
- package/esm/runtime/install-store-app.d.ts +23 -0
- package/esm/runtime/install-store-app.d.ts.map +1 -0
- package/esm/runtime/install-store-app.js +54 -0
- package/esm/runtime/install-store-app.js.map +1 -0
- package/esm/runtime/store-plugin-options.d.ts +40 -0
- package/esm/runtime/store-plugin-options.d.ts.map +1 -0
- package/esm/runtime/store-plugin-options.js +24 -0
- package/esm/runtime/store-plugin-options.js.map +1 -0
- package/esm/runtime/store-registry.d.ts +64 -0
- package/esm/runtime/store-registry.d.ts.map +1 -0
- package/esm/runtime/store-registry.js +94 -0
- package/esm/runtime/store-registry.js.map +1 -0
- package/esm/runtime/store-runtime.d.ts +46 -0
- package/esm/runtime/store-runtime.d.ts.map +1 -0
- package/esm/runtime/store-runtime.js +58 -0
- package/esm/runtime/store-runtime.js.map +1 -0
- package/esm/types.d.ts +167 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +10 -0
- package/lib/composables/defineSetupStore.cjs +33 -0
- package/lib/composables/defineSetupStore.cjs.map +1 -0
- package/lib/composables/defineSetupStore.d.ts +120 -0
- package/lib/composables/index.cjs +46 -0
- package/lib/composables/index.d.ts +24 -0
- package/lib/composables/useFormStore.cjs +197 -0
- package/lib/composables/useFormStore.cjs.map +1 -0
- package/lib/composables/useFormStore.d.ts +131 -0
- package/lib/composables/useOptimistic.cjs +66 -0
- package/lib/composables/useOptimistic.cjs.map +1 -0
- package/lib/composables/useOptimistic.d.ts +67 -0
- package/lib/composables/usePersist.cjs +100 -0
- package/lib/composables/usePersist.cjs.map +1 -0
- package/lib/composables/usePersist.d.ts +68 -0
- package/lib/composables/usePersistedState.cjs +123 -0
- package/lib/composables/usePersistedState.cjs.map +1 -0
- package/lib/composables/usePersistedState.d.ts +59 -0
- package/lib/composables/useSharedState.cjs +96 -0
- package/lib/composables/useSharedState.cjs.map +1 -0
- package/lib/composables/useSharedState.d.ts +62 -0
- package/lib/composables/useStore.cjs +65 -0
- package/lib/composables/useStore.cjs.map +1 -0
- package/lib/composables/useStore.d.ts +99 -0
- package/lib/composables/useStoreDevtools.cjs +114 -0
- package/lib/composables/useStoreDevtools.cjs.map +1 -0
- package/lib/composables/useStoreDevtools.d.ts +31 -0
- package/lib/composables/useStoreSnapshot.cjs +211 -0
- package/lib/composables/useStoreSnapshot.cjs.map +1 -0
- package/lib/composables/useStoreSnapshot.d.ts +122 -0
- package/lib/composables/useSubscribe.cjs +57 -0
- package/lib/composables/useSubscribe.cjs.map +1 -0
- package/lib/composables/useSubscribe.d.ts +90 -0
- package/lib/context/injection-keys.cjs +21 -0
- package/lib/context/injection-keys.cjs.map +1 -0
- package/lib/context/injection-keys.d.ts +8 -0
- package/lib/index.cjs +235 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +24 -0
- package/lib/package.json +3 -0
- package/lib/plugins/engine-plugin.cjs +90 -0
- package/lib/plugins/engine-plugin.cjs.map +1 -0
- package/lib/plugins/engine-plugin.d.ts +36 -0
- package/lib/plugins/enhanced-persist-plugin.cjs +15 -0
- package/lib/plugins/enhanced-persist-plugin.d.ts +3 -0
- package/lib/plugins/index.cjs +28 -0
- package/lib/plugins/index.d.ts +7 -0
- package/lib/plugins/pinia-plugin.cjs +177 -0
- package/lib/plugins/pinia-plugin.cjs.map +1 -0
- package/lib/plugins/pinia-plugin.d.ts +68 -0
- package/lib/plugins/registry-plugin.cjs +18 -0
- package/lib/plugins/registry-plugin.d.ts +2 -0
- package/lib/plugins/vue-plugin.cjs +26 -0
- package/lib/plugins/vue-plugin.cjs.map +1 -0
- package/lib/plugins/vue-plugin.d.ts +10 -0
- package/lib/runtime/install-store-app.cjs +57 -0
- package/lib/runtime/install-store-app.cjs.map +1 -0
- package/lib/runtime/install-store-app.d.ts +23 -0
- package/lib/runtime/store-plugin-options.cjs +26 -0
- package/lib/runtime/store-plugin-options.cjs.map +1 -0
- package/lib/runtime/store-plugin-options.d.ts +40 -0
- package/lib/runtime/store-registry.cjs +108 -0
- package/lib/runtime/store-registry.cjs.map +1 -0
- package/lib/runtime/store-registry.d.ts +64 -0
- package/lib/runtime/store-runtime.cjs +62 -0
- package/lib/runtime/store-runtime.cjs.map +1 -0
- package/lib/runtime/store-runtime.d.ts +46 -0
- package/lib/types.cjs +12 -0
- package/lib/types.d.ts +167 -0
- package/package.json +115 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useStoreSnapshot - Store 状态快照工具
|
|
3
|
+
*
|
|
4
|
+
* 提供状态快照、历史记录和调试功能
|
|
5
|
+
* @module composables/useStoreSnapshot
|
|
6
|
+
*/
|
|
7
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
8
|
+
/**
|
|
9
|
+
* 状态快照
|
|
10
|
+
*/
|
|
11
|
+
export interface StateSnapshot<S = unknown> {
|
|
12
|
+
/** 快照 ID */
|
|
13
|
+
id: string;
|
|
14
|
+
/** 状态数据 */
|
|
15
|
+
state: S;
|
|
16
|
+
/** 时间戳 */
|
|
17
|
+
timestamp: number;
|
|
18
|
+
/** 快照标签 */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** 元数据 */
|
|
21
|
+
meta?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 状态差异
|
|
25
|
+
*/
|
|
26
|
+
export interface StateDiff {
|
|
27
|
+
/** 差异路径 */
|
|
28
|
+
path: string;
|
|
29
|
+
/** 旧值 */
|
|
30
|
+
oldValue: unknown;
|
|
31
|
+
/** 新值 */
|
|
32
|
+
newValue: unknown;
|
|
33
|
+
/** 差异类型 */
|
|
34
|
+
type: 'add' | 'remove' | 'change';
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* useStoreSnapshot 选项
|
|
38
|
+
*/
|
|
39
|
+
export interface UseStoreSnapshotOptions {
|
|
40
|
+
/** 最大快照数量 */
|
|
41
|
+
maxSnapshots?: number;
|
|
42
|
+
/** 是否自动记录 */
|
|
43
|
+
autoRecord?: boolean;
|
|
44
|
+
/** 自动记录防抖延迟(毫秒) */
|
|
45
|
+
debounceMs?: number;
|
|
46
|
+
/** 是否深度监听 */
|
|
47
|
+
deep?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* useStoreSnapshot 返回值
|
|
51
|
+
*/
|
|
52
|
+
export interface UseStoreSnapshotReturn<S> {
|
|
53
|
+
/** 快照列表 */
|
|
54
|
+
snapshots: Ref<Array<StateSnapshot<S>>>;
|
|
55
|
+
/** 当前快照索引 */
|
|
56
|
+
currentIndex: Ref<number>;
|
|
57
|
+
/** 是否可以撤销 */
|
|
58
|
+
canUndo: ComputedRef<boolean>;
|
|
59
|
+
/** 是否可以重做 */
|
|
60
|
+
canRedo: ComputedRef<boolean>;
|
|
61
|
+
/** 创建快照 */
|
|
62
|
+
takeSnapshot: (label?: string, meta?: Record<string, unknown>) => StateSnapshot<S>;
|
|
63
|
+
/** 恢复快照 */
|
|
64
|
+
restoreSnapshot: (id: string) => boolean;
|
|
65
|
+
/** 撤销 */
|
|
66
|
+
undo: () => boolean;
|
|
67
|
+
/** 重做 */
|
|
68
|
+
redo: () => boolean;
|
|
69
|
+
/** 跳转到指定快照 */
|
|
70
|
+
goto: (index: number) => boolean;
|
|
71
|
+
/** 清空快照 */
|
|
72
|
+
clearSnapshots: () => void;
|
|
73
|
+
/** 获取状态差异 */
|
|
74
|
+
getDiff: (snapshotId1: string, snapshotId2: string) => StateDiff[];
|
|
75
|
+
/** 导出快照 */
|
|
76
|
+
exportSnapshots: () => string;
|
|
77
|
+
/** 导入快照 */
|
|
78
|
+
importSnapshots: (data: string) => boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Store 状态快照 Hook
|
|
82
|
+
*
|
|
83
|
+
* 提供状态快照、撤销/重做和调试功能
|
|
84
|
+
*
|
|
85
|
+
* @template S - 状态类型
|
|
86
|
+
* @param state - 响应式状态
|
|
87
|
+
* @param setState - 状态设置函数
|
|
88
|
+
* @param options - 配置选项
|
|
89
|
+
* @returns 快照操作对象
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const store = useCounterStore()
|
|
94
|
+
*
|
|
95
|
+
* const {
|
|
96
|
+
* snapshots,
|
|
97
|
+
* canUndo,
|
|
98
|
+
* canRedo,
|
|
99
|
+
* takeSnapshot,
|
|
100
|
+
* undo,
|
|
101
|
+
* redo,
|
|
102
|
+
* getDiff
|
|
103
|
+
* } = useStoreSnapshot(
|
|
104
|
+
* () => store.$state,
|
|
105
|
+
* (state) => store.$patch(state),
|
|
106
|
+
* { maxSnapshots: 50, autoRecord: true }
|
|
107
|
+
* )
|
|
108
|
+
*
|
|
109
|
+
* // 手动创建快照
|
|
110
|
+
* takeSnapshot('保存点 1')
|
|
111
|
+
*
|
|
112
|
+
* // 撤销操作
|
|
113
|
+
* if (canUndo.value) {
|
|
114
|
+
* undo()
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* // 获取状态差异
|
|
118
|
+
* const diff = getDiff(snapshots.value[0].id, snapshots.value[1].id)
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function useStoreSnapshot<S>(state: Ref<S> | (() => S), setState: (state: S) => void, options?: UseStoreSnapshotOptions): UseStoreSnapshotReturn<S>;
|
|
122
|
+
//# sourceMappingURL=useStoreSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoreSnapshot.d.ts","sourceRoot":"","sources":["../../src/composables/useStoreSnapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAE,GAAG,EAAC,MAAM,KAAK,CAAC;AAI1C;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,OAAO;IACxC,YAAY;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,WAAW;IACX,KAAK,EAAE,CAAC,CAAA;IACR,UAAU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AS;IACT,IAAI,EAAE,MAAM,OAAO,CAAA;IACnB,cAAc;IACd,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IAChC,WAAW;IACX,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,aAAa;IACb,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,SAAS,EAAE,CAAA;IAClE,WAAW;IACX,eAAe,EAAE,MAAM,MAAM,CAAA;IAC7B,WAAW;IACX,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;CAC3C;AAmHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAC5B,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CAAC,CAAC,CAAC,CAuO3B"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { computed, onUnmounted, ref, watch } from "vue";
|
|
11
|
+
import { deepClone, deepEqual } from "@composy/store-core";
|
|
12
|
+
//#region src/composables/useStoreSnapshot.ts
|
|
13
|
+
function generateId() {
|
|
14
|
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
15
|
+
}
|
|
16
|
+
function computeDiff(oldObj, newObj, path = "") {
|
|
17
|
+
const diffs = [];
|
|
18
|
+
if (typeof oldObj !== typeof newObj) {
|
|
19
|
+
diffs.push({
|
|
20
|
+
path: path || ".",
|
|
21
|
+
oldValue: oldObj,
|
|
22
|
+
newValue: newObj,
|
|
23
|
+
type: "change"
|
|
24
|
+
});
|
|
25
|
+
return diffs;
|
|
26
|
+
}
|
|
27
|
+
if (typeof oldObj !== "object" || oldObj === null || newObj === null) {
|
|
28
|
+
if (!Object.is(oldObj, newObj)) diffs.push({
|
|
29
|
+
path: path || ".",
|
|
30
|
+
oldValue: oldObj,
|
|
31
|
+
newValue: newObj,
|
|
32
|
+
type: "change"
|
|
33
|
+
});
|
|
34
|
+
return diffs;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(oldObj) && Array.isArray(newObj)) {
|
|
37
|
+
const maxLen = Math.max(oldObj.length, newObj.length);
|
|
38
|
+
for (let i = 0; i < maxLen; i++) {
|
|
39
|
+
const itemPath = path ? `${path}[${i}]` : `[${i}]`;
|
|
40
|
+
if (i >= oldObj.length) diffs.push({
|
|
41
|
+
path: itemPath,
|
|
42
|
+
oldValue: void 0,
|
|
43
|
+
newValue: newObj[i],
|
|
44
|
+
type: "add"
|
|
45
|
+
});
|
|
46
|
+
else if (i >= newObj.length) diffs.push({
|
|
47
|
+
path: itemPath,
|
|
48
|
+
oldValue: oldObj[i],
|
|
49
|
+
newValue: void 0,
|
|
50
|
+
type: "remove"
|
|
51
|
+
});
|
|
52
|
+
else diffs.push(...computeDiff(oldObj[i], newObj[i], itemPath));
|
|
53
|
+
}
|
|
54
|
+
return diffs;
|
|
55
|
+
}
|
|
56
|
+
const oldKeys = new Set(Object.keys(oldObj));
|
|
57
|
+
const newKeys = new Set(Object.keys(newObj));
|
|
58
|
+
for (const key of newKeys) if (!oldKeys.has(key)) diffs.push({
|
|
59
|
+
path: path ? `${path}.${key}` : key,
|
|
60
|
+
oldValue: void 0,
|
|
61
|
+
newValue: newObj[key],
|
|
62
|
+
type: "add"
|
|
63
|
+
});
|
|
64
|
+
for (const key of oldKeys) if (!newKeys.has(key)) diffs.push({
|
|
65
|
+
path: path ? `${path}.${key}` : key,
|
|
66
|
+
oldValue: oldObj[key],
|
|
67
|
+
newValue: void 0,
|
|
68
|
+
type: "remove"
|
|
69
|
+
});
|
|
70
|
+
for (const key of oldKeys) if (newKeys.has(key)) diffs.push(...computeDiff(oldObj[key], newObj[key], path ? `${path}.${key}` : key));
|
|
71
|
+
return diffs;
|
|
72
|
+
}
|
|
73
|
+
function useStoreSnapshot(state, setState, options = {}) {
|
|
74
|
+
const { maxSnapshots = 100, autoRecord = false, debounceMs = 300, deep = true } = options;
|
|
75
|
+
const snapshots = ref([]);
|
|
76
|
+
const currentIndex = ref(-1);
|
|
77
|
+
let debounceTimer;
|
|
78
|
+
let isRestoring = false;
|
|
79
|
+
const getState = () => {
|
|
80
|
+
return typeof state === "function" ? state() : state.value;
|
|
81
|
+
};
|
|
82
|
+
const canUndo = computed(() => currentIndex.value > 0);
|
|
83
|
+
const canRedo = computed(() => currentIndex.value < snapshots.value.length - 1);
|
|
84
|
+
const takeSnapshot = (label, meta) => {
|
|
85
|
+
const currentState = getState();
|
|
86
|
+
const snapshot = {
|
|
87
|
+
id: generateId(),
|
|
88
|
+
state: deepClone(currentState),
|
|
89
|
+
timestamp: Date.now(),
|
|
90
|
+
label,
|
|
91
|
+
meta
|
|
92
|
+
};
|
|
93
|
+
if (currentIndex.value < snapshots.value.length - 1) snapshots.value = snapshots.value.slice(0, currentIndex.value + 1);
|
|
94
|
+
snapshots.value.push(snapshot);
|
|
95
|
+
currentIndex.value = snapshots.value.length - 1;
|
|
96
|
+
if (snapshots.value.length > maxSnapshots) {
|
|
97
|
+
snapshots.value.shift();
|
|
98
|
+
currentIndex.value--;
|
|
99
|
+
}
|
|
100
|
+
return snapshot;
|
|
101
|
+
};
|
|
102
|
+
const restoreSnapshot = (id) => {
|
|
103
|
+
const index = snapshots.value.findIndex((s) => s.id === id);
|
|
104
|
+
if (index === -1) return false;
|
|
105
|
+
isRestoring = true;
|
|
106
|
+
try {
|
|
107
|
+
setState(deepClone(snapshots.value[index].state));
|
|
108
|
+
currentIndex.value = index;
|
|
109
|
+
return true;
|
|
110
|
+
} finally {
|
|
111
|
+
isRestoring = false;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const undo = () => {
|
|
115
|
+
if (!canUndo.value) return false;
|
|
116
|
+
currentIndex.value--;
|
|
117
|
+
isRestoring = true;
|
|
118
|
+
try {
|
|
119
|
+
setState(deepClone(snapshots.value[currentIndex.value].state));
|
|
120
|
+
return true;
|
|
121
|
+
} finally {
|
|
122
|
+
isRestoring = false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const redo = () => {
|
|
126
|
+
if (!canRedo.value) return false;
|
|
127
|
+
currentIndex.value++;
|
|
128
|
+
isRestoring = true;
|
|
129
|
+
try {
|
|
130
|
+
setState(deepClone(snapshots.value[currentIndex.value].state));
|
|
131
|
+
return true;
|
|
132
|
+
} finally {
|
|
133
|
+
isRestoring = false;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const goto = (index) => {
|
|
137
|
+
if (index < 0 || index >= snapshots.value.length) return false;
|
|
138
|
+
currentIndex.value = index;
|
|
139
|
+
isRestoring = true;
|
|
140
|
+
try {
|
|
141
|
+
setState(deepClone(snapshots.value[index].state));
|
|
142
|
+
return true;
|
|
143
|
+
} finally {
|
|
144
|
+
isRestoring = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const clearSnapshots = () => {
|
|
148
|
+
snapshots.value = [];
|
|
149
|
+
currentIndex.value = -1;
|
|
150
|
+
};
|
|
151
|
+
const getDiff = (snapshotId1, snapshotId2) => {
|
|
152
|
+
const snapshot1 = snapshots.value.find((s) => s.id === snapshotId1);
|
|
153
|
+
const snapshot2 = snapshots.value.find((s) => s.id === snapshotId2);
|
|
154
|
+
if (!snapshot1 || !snapshot2) return [];
|
|
155
|
+
return computeDiff(snapshot1.state, snapshot2.state);
|
|
156
|
+
};
|
|
157
|
+
const exportSnapshots = () => {
|
|
158
|
+
return JSON.stringify({
|
|
159
|
+
snapshots: snapshots.value,
|
|
160
|
+
currentIndex: currentIndex.value,
|
|
161
|
+
exportedAt: Date.now()
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const importSnapshots = (data) => {
|
|
165
|
+
try {
|
|
166
|
+
const parsed = JSON.parse(data);
|
|
167
|
+
if (!Array.isArray(parsed.snapshots)) return false;
|
|
168
|
+
snapshots.value = parsed.snapshots;
|
|
169
|
+
currentIndex.value = Math.min(parsed.currentIndex ?? snapshots.value.length - 1, snapshots.value.length - 1);
|
|
170
|
+
return true;
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
if (autoRecord) {
|
|
176
|
+
const stopWatch = watch(typeof state === "function" ? computed(state) : state, (newState, oldState) => {
|
|
177
|
+
if (isRestoring) return;
|
|
178
|
+
if (deepEqual(newState, oldState)) return;
|
|
179
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
180
|
+
debounceTimer = setTimeout(() => {
|
|
181
|
+
takeSnapshot();
|
|
182
|
+
}, debounceMs);
|
|
183
|
+
}, { deep });
|
|
184
|
+
takeSnapshot("初始状态");
|
|
185
|
+
onUnmounted(() => {
|
|
186
|
+
stopWatch();
|
|
187
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
snapshots,
|
|
192
|
+
currentIndex,
|
|
193
|
+
canUndo,
|
|
194
|
+
canRedo,
|
|
195
|
+
takeSnapshot,
|
|
196
|
+
restoreSnapshot,
|
|
197
|
+
undo,
|
|
198
|
+
redo,
|
|
199
|
+
goto,
|
|
200
|
+
clearSnapshots,
|
|
201
|
+
getDiff,
|
|
202
|
+
exportSnapshots,
|
|
203
|
+
importSnapshots
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
//#endregion
|
|
207
|
+
export { useStoreSnapshot };
|
|
208
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
209
|
+
//# sourceMappingURL=useStoreSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStoreSnapshot.js","names":[],"sources":["../../src/composables/useStoreSnapshot.ts"],"sourcesContent":["/**\n * useStoreSnapshot - Store 状态快照工具\n *\n * 提供状态快照、历史记录和调试功能\n * @module composables/useStoreSnapshot\n */\n\nimport type {ComputedRef, Ref} from 'vue';\nimport { deepClone, deepEqual } from '@composy/store-core'\nimport { computed, onUnmounted, ref, watch } from 'vue'\n\n/**\n * 状态快照\n */\nexport interface StateSnapshot<S = unknown> {\n /** 快照 ID */\n id: string\n /** 状态数据 */\n state: S\n /** 时间戳 */\n timestamp: number\n /** 快照标签 */\n label?: string\n /** 元数据 */\n meta?: Record<string, unknown>\n}\n\n/**\n * 状态差异\n */\nexport interface StateDiff {\n /** 差异路径 */\n path: string\n /** 旧值 */\n oldValue: unknown\n /** 新值 */\n newValue: unknown\n /** 差异类型 */\n type: 'add' | 'remove' | 'change'\n}\n\n/**\n * useStoreSnapshot 选项\n */\nexport interface UseStoreSnapshotOptions {\n /** 最大快照数量 */\n maxSnapshots?: number\n /** 是否自动记录 */\n autoRecord?: boolean\n /** 自动记录防抖延迟(毫秒) */\n debounceMs?: number\n /** 是否深度监听 */\n deep?: boolean\n}\n\n/**\n * useStoreSnapshot 返回值\n */\nexport interface UseStoreSnapshotReturn<S> {\n /** 快照列表 */\n snapshots: Ref<Array<StateSnapshot<S>>>\n /** 当前快照索引 */\n currentIndex: Ref<number>\n /** 是否可以撤销 */\n canUndo: ComputedRef<boolean>\n /** 是否可以重做 */\n canRedo: ComputedRef<boolean>\n /** 创建快照 */\n takeSnapshot: (label?: string, meta?: Record<string, unknown>) => StateSnapshot<S>\n /** 恢复快照 */\n restoreSnapshot: (id: string) => boolean\n /** 撤销 */\n undo: () => boolean\n /** 重做 */\n redo: () => boolean\n /** 跳转到指定快照 */\n goto: (index: number) => boolean\n /** 清空快照 */\n clearSnapshots: () => void\n /** 获取状态差异 */\n getDiff: (snapshotId1: string, snapshotId2: string) => StateDiff[]\n /** 导出快照 */\n exportSnapshots: () => string\n /** 导入快照 */\n importSnapshots: (data: string) => boolean\n}\n\n/**\n * 生成唯一 ID\n */\nfunction generateId(): string {\n return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`\n}\n\n/**\n * 计算两个对象的差异\n */\nfunction computeDiff(\n oldObj: unknown,\n newObj: unknown,\n path = '',\n): StateDiff[] {\n const diffs: StateDiff[] = []\n\n // 类型不同\n if (typeof oldObj !== typeof newObj) {\n diffs.push({\n path: path || '.',\n oldValue: oldObj,\n newValue: newObj,\n type: 'change',\n })\n return diffs\n }\n\n // 基础类型比较\n if (typeof oldObj !== 'object' || oldObj === null || newObj === null) {\n if (!Object.is(oldObj, newObj)) {\n diffs.push({\n path: path || '.',\n oldValue: oldObj,\n newValue: newObj,\n type: 'change',\n })\n }\n return diffs\n }\n\n // 数组比较\n if (Array.isArray(oldObj) && Array.isArray(newObj)) {\n const maxLen = Math.max(oldObj.length, newObj.length)\n for (let i = 0; i < maxLen; i++) {\n const itemPath = path ? `${path}[${i}]` : `[${i}]`\n if (i >= oldObj.length) {\n diffs.push({\n path: itemPath,\n oldValue: undefined,\n newValue: newObj[i],\n type: 'add',\n })\n }\n else if (i >= newObj.length) {\n diffs.push({\n path: itemPath,\n oldValue: oldObj[i],\n newValue: undefined,\n type: 'remove',\n })\n }\n else {\n diffs.push(...computeDiff(oldObj[i], newObj[i], itemPath))\n }\n }\n return diffs\n }\n\n // 对象比较\n const oldKeys = new Set(Object.keys(oldObj as Record<string, unknown>))\n const newKeys = new Set(Object.keys(newObj as Record<string, unknown>))\n\n // 检查新增的键\n for (const key of newKeys) {\n if (!oldKeys.has(key)) {\n diffs.push({\n path: path ? `${path}.${key}` : key,\n oldValue: undefined,\n newValue: (newObj as Record<string, unknown>)[key],\n type: 'add',\n })\n }\n }\n\n // 检查删除的键\n for (const key of oldKeys) {\n if (!newKeys.has(key)) {\n diffs.push({\n path: path ? `${path}.${key}` : key,\n oldValue: (oldObj as Record<string, unknown>)[key],\n newValue: undefined,\n type: 'remove',\n })\n }\n }\n\n // 检查修改的键\n for (const key of oldKeys) {\n if (newKeys.has(key)) {\n diffs.push(\n ...computeDiff(\n (oldObj as Record<string, unknown>)[key],\n (newObj as Record<string, unknown>)[key],\n path ? `${path}.${key}` : key,\n ),\n )\n }\n }\n\n return diffs\n}\n\n/**\n * Store 状态快照 Hook\n *\n * 提供状态快照、撤销/重做和调试功能\n *\n * @template S - 状态类型\n * @param state - 响应式状态\n * @param setState - 状态设置函数\n * @param options - 配置选项\n * @returns 快照操作对象\n *\n * @example\n * ```typescript\n * const store = useCounterStore()\n *\n * const {\n * snapshots,\n * canUndo,\n * canRedo,\n * takeSnapshot,\n * undo,\n * redo,\n * getDiff\n * } = useStoreSnapshot(\n * () => store.$state,\n * (state) => store.$patch(state),\n * { maxSnapshots: 50, autoRecord: true }\n * )\n *\n * // 手动创建快照\n * takeSnapshot('保存点 1')\n *\n * // 撤销操作\n * if (canUndo.value) {\n * undo()\n * }\n *\n * // 获取状态差异\n * const diff = getDiff(snapshots.value[0].id, snapshots.value[1].id)\n * ```\n */\nexport function useStoreSnapshot<S>(\n state: Ref<S> | (() => S),\n setState: (state: S) => void,\n options: UseStoreSnapshotOptions = {},\n): UseStoreSnapshotReturn<S> {\n const {\n maxSnapshots = 100,\n autoRecord = false,\n debounceMs = 300,\n deep = true,\n } = options\n\n const snapshots = ref<Array<StateSnapshot<S>>>([]) as Ref<Array<StateSnapshot<S>>>\n const currentIndex = ref(-1)\n let debounceTimer: ReturnType<typeof setTimeout> | undefined\n let isRestoring = false\n\n // 获取当前状态\n const getState = (): S => {\n return typeof state === 'function' ? state() : state.value\n }\n\n // 是否可以撤销\n const canUndo = computed(() => currentIndex.value > 0)\n\n // 是否可以重做\n const canRedo = computed(() => currentIndex.value < snapshots.value.length - 1)\n\n /**\n * 创建快照\n */\n const takeSnapshot = (label?: string, meta?: Record<string, unknown>): StateSnapshot<S> => {\n const currentState = getState()\n const snapshot: StateSnapshot<S> = {\n id: generateId(),\n state: deepClone(currentState),\n timestamp: Date.now(),\n label,\n meta,\n }\n\n // 如果当前不在最新位置,删除后面的快照\n if (currentIndex.value < snapshots.value.length - 1) {\n snapshots.value = snapshots.value.slice(0, currentIndex.value + 1)\n }\n\n // 添加新快照\n snapshots.value.push(snapshot)\n currentIndex.value = snapshots.value.length - 1\n\n // 限制快照数量\n if (snapshots.value.length > maxSnapshots) {\n snapshots.value.shift()\n currentIndex.value--\n }\n\n return snapshot\n }\n\n /**\n * 恢复快照\n */\n const restoreSnapshot = (id: string): boolean => {\n const index = snapshots.value.findIndex(s => s.id === id)\n if (index === -1) return false\n\n isRestoring = true\n try {\n setState(deepClone(snapshots.value[index].state))\n currentIndex.value = index\n return true\n }\n finally {\n isRestoring = false\n }\n }\n\n /**\n * 撤销\n */\n const undo = (): boolean => {\n if (!canUndo.value) return false\n\n currentIndex.value--\n isRestoring = true\n try {\n setState(deepClone(snapshots.value[currentIndex.value].state))\n return true\n }\n finally {\n isRestoring = false\n }\n }\n\n /**\n * 重做\n */\n const redo = (): boolean => {\n if (!canRedo.value) return false\n\n currentIndex.value++\n isRestoring = true\n try {\n setState(deepClone(snapshots.value[currentIndex.value].state))\n return true\n }\n finally {\n isRestoring = false\n }\n }\n\n /**\n * 跳转到指定快照\n */\n const goto = (index: number): boolean => {\n if (index < 0 || index >= snapshots.value.length) return false\n\n currentIndex.value = index\n isRestoring = true\n try {\n setState(deepClone(snapshots.value[index].state))\n return true\n }\n finally {\n isRestoring = false\n }\n }\n\n /**\n * 清空快照\n */\n const clearSnapshots = (): void => {\n snapshots.value = []\n currentIndex.value = -1\n }\n\n /**\n * 获取状态差异\n */\n const getDiff = (snapshotId1: string, snapshotId2: string): StateDiff[] => {\n const snapshot1 = snapshots.value.find(s => s.id === snapshotId1)\n const snapshot2 = snapshots.value.find(s => s.id === snapshotId2)\n\n if (!snapshot1 || !snapshot2) return []\n\n return computeDiff(snapshot1.state, snapshot2.state)\n }\n\n /**\n * 导出快照\n */\n const exportSnapshots = (): string => {\n return JSON.stringify({\n snapshots: snapshots.value,\n currentIndex: currentIndex.value,\n exportedAt: Date.now(),\n })\n }\n\n /**\n * 导入快照\n */\n const importSnapshots = (data: string): boolean => {\n try {\n const parsed = JSON.parse(data) as {\n snapshots: Array<StateSnapshot<S>>\n currentIndex: number\n }\n\n if (!Array.isArray(parsed.snapshots)) return false\n\n snapshots.value = parsed.snapshots\n currentIndex.value = Math.min(\n parsed.currentIndex ?? snapshots.value.length - 1,\n snapshots.value.length - 1,\n )\n\n return true\n }\n catch {\n return false\n }\n }\n\n // 自动记录\n if (autoRecord) {\n const stateRef = typeof state === 'function' ? computed(state) : state\n\n const stopWatch = watch(\n stateRef,\n (newState, oldState) => {\n // 如果是恢复操作,不记录\n if (isRestoring) return\n\n // 如果状态未变化,不记录\n if (deepEqual(newState, oldState)) return\n\n // 防抖记录\n if (debounceTimer) {\n clearTimeout(debounceTimer)\n }\n\n debounceTimer = setTimeout(() => {\n takeSnapshot()\n }, debounceMs)\n },\n { deep },\n )\n\n // 初始快照\n takeSnapshot('初始状态')\n\n onUnmounted(() => {\n stopWatch()\n if (debounceTimer) {\n clearTimeout(debounceTimer)\n }\n })\n }\n\n return {\n snapshots,\n currentIndex,\n canUndo,\n canRedo,\n takeSnapshot,\n restoreSnapshot,\n undo,\n redo,\n goto,\n clearSnapshots,\n getDiff,\n exportSnapshots,\n importSnapshots,\n }\n}\n\n"],"mappings":";;;;;;;;;;;;AA0FA,SAAS,aAAqB;CAC5B,OAAO,GAAG,KAAK,IAAI,EAAC,GAAI,KAAK,OAAO,CAAA,CAAE,SAAS,EAAE,CAAA,CAAE,OAAO,GAAG,CAAC;AAChE;AAKA,SAAS,YACP,QACA,QACA,OAAO,IACM;CACb,MAAM,QAAqB,CAAC;CAG5B,IAAI,OAAO,WAAW,OAAO,QAAQ;EACnC,MAAM,KAAK;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AAC,MAAM,QAAQ,OAAO,SAAS,GAAG,OAAO;GAE7C,UAAU,QAAQ,OAAO;GACzB,aAAa,QAAQ,KAAK,IACxB,OAAO,gBAAgB,UAAU,MAAM,SAAS,GAChD,UAAU,MAAM,SAAS,CAC3B;GAEA,OAAO;EACT,QACM;GACJ,OAAO;EACT;CACF;CAGA,IAAI,YAAY;EAGd,MAAM,YAAY,MAFD,OAAO,UAAU,aAAa,SAAS,KAAK,IAAI,QAI9D,UAAU,aAAa;GAEtB,IAAI,aAAa;GAGjB,IAAI,UAAU,UAAU,QAAQ,GAAG;GAGnC,IAAI,eACF,aAAa,aAAa;GAG5B,gBAAgB,iBAAiB;IAC/B,aAAa;GACf,GAAG,UAAU;EACf,GACA,EAAE,KAAK,CACT;EAGA,aAAa,MAAM;EAEnB,kBAAkB;GAChB,UAAU;GACV,IAAI,eACF,aAAa,aAAa;EAE9B,CAAC;CACH;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSubscribe Composable
|
|
3
|
+
*
|
|
4
|
+
* 提供 Store 订阅功能
|
|
5
|
+
* @module composables/useSubscribe
|
|
6
|
+
*/
|
|
7
|
+
import type { Ref, WatchStopHandle } from 'vue';
|
|
8
|
+
import type { MutationInfo, SubscribeOptions } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* 订阅 Store 状态变化
|
|
11
|
+
*
|
|
12
|
+
* @template S - 状态类型
|
|
13
|
+
* @param store - Pinia Store 实例
|
|
14
|
+
* @param callback - 回调函数
|
|
15
|
+
* @param options - 订阅选项
|
|
16
|
+
* @returns 取消订阅函数
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const store = useCounterStore()
|
|
21
|
+
*
|
|
22
|
+
* // 订阅状态变化
|
|
23
|
+
* const unsubscribe = useSubscribe(store, (mutation, state) => {
|
|
24
|
+
* console.log('State changed:', mutation.type, state)
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // 取消订阅
|
|
28
|
+
* unsubscribe()
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useSubscribe<S extends Record<string, unknown>>(store: S & {
|
|
32
|
+
$subscribe?: (callback: (mutation: MutationInfo<S>, state: S) => void, options?: {
|
|
33
|
+
detached?: boolean;
|
|
34
|
+
}) => () => void;
|
|
35
|
+
}, callback: (mutation: MutationInfo<S>, state: S) => void, options?: SubscribeOptions): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* 订阅 Store Action 调用
|
|
38
|
+
*
|
|
39
|
+
* @template S - Store 类型
|
|
40
|
+
* @param store - Pinia Store 实例
|
|
41
|
+
* @param callback - 回调函数
|
|
42
|
+
* @returns 取消订阅函数
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const store = useCounterStore()
|
|
47
|
+
*
|
|
48
|
+
* // 订阅 Action 调用
|
|
49
|
+
* useOnAction(store, ({ name, args, after, onError }) => {
|
|
50
|
+
* console.log(`Action ${name} called with:`, args)
|
|
51
|
+
*
|
|
52
|
+
* after((result) => {
|
|
53
|
+
* console.log(`Action ${name} finished with:`, result)
|
|
54
|
+
* })
|
|
55
|
+
*
|
|
56
|
+
* onError((error) => {
|
|
57
|
+
* console.error(`Action ${name} failed:`, error)
|
|
58
|
+
* })
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function useOnAction<S extends Record<string, unknown>>(store: S & {
|
|
63
|
+
$onAction?: (callback: (context: ActionContext) => void, detached?: boolean) => () => void;
|
|
64
|
+
}, callback: (context: ActionContext) => void, detached?: boolean): () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Action 上下文
|
|
67
|
+
*/
|
|
68
|
+
export interface ActionContext {
|
|
69
|
+
/** Action 名称 */
|
|
70
|
+
name: string;
|
|
71
|
+
/** Store 实例 */
|
|
72
|
+
store: unknown;
|
|
73
|
+
/** Action 参数 */
|
|
74
|
+
args: unknown[];
|
|
75
|
+
/** Action 完成后回调 */
|
|
76
|
+
after: (callback: (result: unknown) => void) => void;
|
|
77
|
+
/** Action 错误回调 */
|
|
78
|
+
onError: (callback: (error: unknown) => void) => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 监听 ref 变化
|
|
82
|
+
*
|
|
83
|
+
* @template T - 值类型
|
|
84
|
+
* @param source - 监听源
|
|
85
|
+
* @param callback - 回调函数
|
|
86
|
+
* @param options - 监听选项
|
|
87
|
+
* @returns 停止监听函数
|
|
88
|
+
*/
|
|
89
|
+
export declare function useWatch<T>(source: Ref<T>, callback: (newValue: T, oldValue: T | undefined) => void, options?: SubscribeOptions): WatchStopHandle;
|
|
90
|
+
//# sourceMappingURL=useSubscribe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscribe.d.ts","sourceRoot":"","sources":["../../src/composables/useSubscribe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAG9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,KAAK,EAAE,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,MAAM,IAAI,CAAA;CAAE,EACrI,QAAQ,EAAE,CAAC,QAAQ,E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
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { onUnmounted, watch } from "vue";
|
|
11
|
+
//#region src/composables/useSubscribe.ts
|
|
12
|
+
function useSubscribe(store, callback, options = {}) {
|
|
13
|
+
const { detached = false } = options;
|
|
14
|
+
if (store.$subscribe) {
|
|
15
|
+
const unsubscribe = store.$subscribe((mutation, state) => {
|
|
16
|
+
callback(mutation, state);
|
|
17
|
+
}, { detached });
|
|
18
|
+
if (!detached) onUnmounted(() => {
|
|
19
|
+
unsubscribe();
|
|
20
|
+
});
|
|
21
|
+
return unsubscribe;
|
|
22
|
+
}
|
|
23
|
+
console.warn("[useSubscribe] Store 不支持 $subscribe 方法");
|
|
24
|
+
return () => {};
|
|
25
|
+
}
|
|
26
|
+
function useOnAction(store, callback, detached = false) {
|
|
27
|
+
if (store.$onAction) {
|
|
28
|
+
const unsubscribe = store.$onAction(callback, detached);
|
|
29
|
+
if (!detached) onUnmounted(() => {
|
|
30
|
+
unsubscribe();
|
|
31
|
+
});
|
|
32
|
+
return unsubscribe;
|
|
33
|
+
}
|
|
34
|
+
console.warn("[useOnAction] Store 不支持 $onAction 方法");
|
|
35
|
+
return () => {};
|
|
36
|
+
}
|
|
37
|
+
function useWatch(source, callback, options = {}) {
|
|
38
|
+
const { immediate = false, deep = false, detached = false } = options;
|
|
39
|
+
const stop = watch(source, (newValue, oldValue) => {
|
|
40
|
+
callback(newValue, oldValue);
|
|
41
|
+
}, {
|
|
42
|
+
immediate,
|
|
43
|
+
deep
|
|
44
|
+
});
|
|
45
|
+
if (!detached) onUnmounted(() => {
|
|
46
|
+
stop();
|
|
47
|
+
});
|
|
48
|
+
return stop;
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { useOnAction, useSubscribe, useWatch };
|
|
52
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
53
|
+
//# sourceMappingURL=useSubscribe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSubscribe.js","names":[],"sources":["../../src/composables/useSubscribe.ts"],"sourcesContent":["/**\n * useSubscribe Composable\n *\n * 提供 Store 订阅功能\n * @module composables/useSubscribe\n */\n\nimport type { Ref, WatchStopHandle } from 'vue'\nimport type { MutationInfo, SubscribeOptions } from '../types'\nimport { onUnmounted, watch } from 'vue'\n\n/**\n * 订阅 Store 状态变化\n *\n * @template S - 状态类型\n * @param store - Pinia Store 实例\n * @param callback - 回调函数\n * @param options - 订阅选项\n * @returns 取消订阅函数\n *\n * @example\n * ```typescript\n * const store = useCounterStore()\n *\n * // 订阅状态变化\n * const unsubscribe = useSubscribe(store, (mutation, state) => {\n * console.log('State changed:', mutation.type, state)\n * })\n *\n * // 取消订阅\n * unsubscribe()\n * ```\n */\nexport function useSubscribe<S extends Record<string, unknown>>(\n store: S & { $subscribe?: (callback: (mutation: MutationInfo<S>, state: S) => void, options?: { detached?: boolean }) => () => void },\n callback: (mutation: MutationInfo<S>, state: S) => void,\n options: SubscribeOptions = {},\n): () => void {\n const { detached = false } = options\n\n // 使用 Pinia 的 $subscribe\n if (store.$subscribe) {\n const unsubscribe = store.$subscribe(\n (mutation, state) => {\n callback(mutation as MutationInfo<S>, state as S)\n },\n { detached },\n )\n\n // 组件卸载时自动取消订阅\n if (!detached) {\n onUnmounted(() => {\n unsubscribe()\n })\n }\n\n return unsubscribe\n }\n\n // 如果不是 Pinia Store,返回空函数\n console.warn('[useSubscribe] Store 不支持 $subscribe 方法')\n return () => {}\n}\n\n/**\n * 订阅 Store Action 调用\n *\n * @template S - Store 类型\n * @param store - Pinia Store 实例\n * @param callback - 回调函数\n * @returns 取消订阅函数\n *\n * @example\n * ```typescript\n * const store = useCounterStore()\n *\n * // 订阅 Action 调用\n * useOnAction(store, ({ name, args, after, onError }) => {\n * console.log(`Action ${name} called with:`, args)\n *\n * after((result) => {\n * console.log(`Action ${name} finished with:`, result)\n * })\n *\n * onError((error) => {\n * console.error(`Action ${name} failed:`, error)\n * })\n * })\n * ```\n */\nexport function useOnAction<S extends Record<string, unknown>>(\n store: S & { $onAction?: (callback: (context: ActionContext) => void, detached?: boolean) => () => void },\n callback: (context: ActionContext) => void,\n detached = false,\n): () => void {\n if (store.$onAction) {\n const unsubscribe = store.$onAction(callback, detached)\n\n if (!detached) {\n onUnmounted(() => {\n unsubscribe()\n })\n }\n\n return unsubscribe\n }\n\n console.warn('[useOnAction] Store 不支持 $onAction 方法')\n return () => {}\n}\n\n/**\n * Action 上下文\n */\nexport interface ActionContext {\n /** Action 名称 */\n name: string\n /** Store 实例 */\n store: unknown\n /** Action 参数 */\n args: unknown[]\n /** Action 完成后回调 */\n after: (callback: (result: unknown) => void) => void\n /** Action 错误回调 */\n onError: (callback: (error: unknown) => void) => void\n}\n\n/**\n * 监听 ref 变化\n *\n * @template T - 值类型\n * @param source - 监听源\n * @param callback - 回调函数\n * @param options - 监听选项\n * @returns 停止监听函数\n */\nexport function useWatch<T>(\n source: Ref<T>,\n callback: (newValue: T, oldValue: T | undefined) => void,\n options: SubscribeOptions = {},\n): WatchStopHandle {\n const { immediate = false, deep = false, detached = false } = options\n\n const stop = watch(\n source,\n (newValue, oldValue) => {\n callback(newValue, oldValue)\n },\n { immediate, deep },\n )\n\n if (!detached) {\n onUnmounted(() => {\n stop()\n })\n }\n\n return stop\n}\n\n"],"mappings":";;;;;;;;;;;AAiCO,SAAS,aACd,OACA,UACA,UAA4B,CAAC,GACjB;CACZ,MAAM,EAAE,WAAW,UAAU;CAG7B,IAAI,MAAM,YAAY;EACpB,MAAM,cAAc,MAAM,YACvB,UAAU,UAAU;GACnB,SAAS,UAA6B,KAAU;EAClD,GACA,EAAE,SAAS,CACb;EAGA,IAAI,CAAC,UACH,kBAAkB;GAChB,YAAY;EACd,CAAC;EAGH,OAAO;CACT;CAGA,QAAQ,KAAK,wCAAwC;CACrD,aAAa,CAAC;AAChB;AA4BO,SAAS,YACd,OACA,UACA,WAAW,OACC;CACZ,IAAI,MAAM,WAAW;EACnB,MAAM,cAAc,MAAM,UAAU,UAAU,QAAQ;EAEtD,IAAI,CAAC,UACH,kBAAkB;GAChB,YAAY;EACd,CAAC;EAGH,OAAO;CACT;CAEA,QAAQ,KAAK,sCAAsC;CACnD,aAAa,CAAC;AAChB;AA2BO,SAAS,SACd,QACA,UACA,UAA4B,CAAC,GACZ;CACjB,MAAM,EAAE,YAAY,OAAO,OAAO,OAAO,WAAW,UAAU;CAE9D,MAAM,OAAO,MACX,SACC,UAAU,aAAa;EACtB,SAAS,UAAU,QAAQ;CAC7B,GACA;EAAE;EAAW;CAAK,CACpB;CAEA,IAAI,CAAC,UACH,kBAAkB;EAChB,KAAK;CACP,CAAC;CAGH,OAAO;AACT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Pinia } from 'pinia';
|
|
2
|
+
import type { InjectionKey } from 'vue';
|
|
3
|
+
import type { StoreRuntime } from '../runtime/store-runtime';
|
|
4
|
+
import type { GlobalStoreAPI } from '../types';
|
|
5
|
+
export declare const STORE_API_SYMBOL: InjectionKey<GlobalStoreAPI>;
|
|
6
|
+
export declare const STORE_PINIA_SYMBOL: InjectionKey<Pinia>;
|
|
7
|
+
export declare const STORE_RUNTIME_SYMBOL: InjectionKey<StoreRuntime>;
|
|
8
|
+
//# sourceMappingURL=injection-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-keys.d.ts","sourceRoot":"","sources":["../../src/context/injection-keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAElC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAG9C,eAAO,MAAM,gBAAgB,EAAkC,YAAY,CAAC,cAAc,CAAC,CAAA;AAE3F,eAAO,MAAM,kBAAkB,EAAoC,YAAY,CAAC,KAAK,CAAC,CAAA;AAEtF,eAAO,MAAM,oBAAoB,EAAsC,YAAY,CAAC,YAAY,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
//#region src/context/injection-keys.ts
|
|
11
|
+
const STORE_API_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-api");
|
|
12
|
+
const STORE_PINIA_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-pinia");
|
|
13
|
+
const STORE_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-runtime");
|
|
14
|
+
//#endregion
|
|
15
|
+
export { STORE_API_SYMBOL, STORE_PINIA_SYMBOL, STORE_RUNTIME_SYMBOL };
|
|
16
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
17
|
+
//# sourceMappingURL=injection-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-keys.js","names":[],"sources":["../../src/context/injection-keys.ts"],"sourcesContent":["// 从 pinia 导入 Pinia 类型\nimport type { Pinia } from 'pinia'\n// 从 vue 导入 InjectionKey 类型,用于类型安全的依赖注入\nimport type { InjectionKey } from 'vue'\n// 导入 StoreRuntime 类型,表示 store 运行时实例\nimport type { StoreRuntime } from '../runtime/store-runtime'\n// 导入 GlobalStoreAPI 类型,表示全局 store API 接口\nimport type { GlobalStoreAPI } from '../types'\n\n// store 全局 API 的注入键符号,用于 provide/inject 传递 GlobalStoreAPI 实例\nexport const STORE_API_SYMBOL = Symbol('ldesign-store-api') as InjectionKey<GlobalStoreAPI>\n// store Pinia 实例的注入键符号,用于 provide/inject 传递 Pinia 实例\nexport const STORE_PINIA_SYMBOL = Symbol('ldesign-store-pinia') as InjectionKey<Pinia>\n// store 运行时实例的注入键符号,用于 provide/inject 传递 StoreRuntime 实例\nexport const STORE_RUNTIME_SYMBOL = Symbol('ldesign-store-runtime') as InjectionKey<StoreRuntime>\n"],"mappings":";;;;;;;;;;AAUO,MAAM,mBAAmB,uBAAO,mBAAmB;AAEnD,MAAM,qBAAqB,uBAAO,qBAAqB;AAEvD,MAAM,uBAAuB,uBAAO,uBAAuB"}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @composy/store-vue - Vue 3 状态管理适配器
|
|
3
|
+
*
|
|
4
|
+
* 基于 Pinia 的增强版状态管理解决方案
|
|
5
|
+
*
|
|
6
|
+
* 主要功能:
|
|
7
|
+
* - Pinia 集成与增强
|
|
8
|
+
* - 状态持久化
|
|
9
|
+
* - Engine 插件集成
|
|
10
|
+
* - 丰富的 Composables
|
|
11
|
+
*
|
|
12
|
+
* @module @composy/store-vue
|
|
13
|
+
*/
|
|
14
|
+
export { createStoreGetters, createStoreState, defineSetupStore, email, maxLength, minLength, numberRange, pattern, required, useComputedStore, useFormStore, useOnAction, useOptimistic, usePersist, usePersistedRef, usePersistedRefWithTTL, usePersistedState, useSharedState, useSimpleStore, useStore, useStoreDevtools, useStoreSnapshot, useSubscribe, useWatch, } from './composables';
|
|
15
|
+
export type { ActionContext, EventLogEntry, FormFieldRules, FormFieldState, FormValidator, OptimisticEntry, PersistedStateOptions, PersistedStateReturn, StateDiff, StateSnapshot, StoreInfo, UseFormStoreOptions, UseFormStoreReturn, UseOptimisticReturn, UseSharedStateOptions, UseSharedStateReturn, UseStoreDevtoolsReturn, UseStoreSnapshotOptions, UseStoreSnapshotReturn, } from './composables';
|
|
16
|
+
export { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin, createStoreEnginePlugin, createStoreRegistryPlugin, createStoreVuePlugin, getGlobalStoreAPI, getStoreRegistry, } from './plugins';
|
|
17
|
+
export type { EnhancedPersistOptions, EnhancedPersistPluginOptions, PersistPluginOptions, StoreVuePluginOptions, } from './plugins';
|
|
18
|
+
export type { GlobalStoreAPI, MutationInfo, PersistOptions, StoreEnginePluginOptions, StoreOptions, StoreProviderProps, SubscribeOptions, UsePersistOptions, UsePersistReturn, UseStoreReturn, } from './types';
|
|
19
|
+
export { batch, combineSelectors, composePlugins, createAsyncAction, createBatchManager, createEventBus, createLoggerMiddleware, createMiddlewareManager, createPluginFactory, createPubSub, createPubSubWithValue, createSelector, createTimeTravelMiddleware, createValidationMiddleware, deepClone, deepMerge, defineStorePlugin, globalEventBus, } from '@composy/store-core';
|
|
20
|
+
export { createPinia, defineStore, getActivePinia, mapActions, mapGetters, mapState, mapStores, mapWritableState, setActivePinia, storeToRefs, } from 'pinia';
|
|
21
|
+
export type { Pinia, PiniaPlugin, PiniaPluginContext, StateTree, Store, StoreDefinition, StoreGeneric, StoreGetters, StoreState, } from 'pinia';
|
|
22
|
+
export declare const version = "1.0.0";
|
|
23
|
+
export declare const name = "@composy/store-vue";
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAEhB,gBAAgB,EAChB,KAAK,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,OAAO,EAEP,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,aAAa,EACb,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,YAAY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Ae,EACf,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,OAAO,CAAA;AAGd,eAAO,MAAM,OAAO,UAAU,CAAA;AAC9B,eAAO,MAAM,IAAI,uBAAuB,CAAA"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-vue v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:39:29 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
import { createStoreGetters, createStoreState, defineSetupStore } from "./composables/defineSetupStore.js";
|
|
11
|
+
import { email, maxLength, minLength, numberRange, pattern, required, useFormStore } from "./composables/useFormStore.js";
|
|
12
|
+
import { useOptimistic } from "./composables/useOptimistic.js";
|
|
13
|
+
import { usePersist, usePersistedRef, usePersistedRefWithTTL } from "./composables/usePersist.js";
|
|
14
|
+
import { usePersistedState } from "./composables/usePersistedState.js";
|
|
15
|
+
import { useSharedState } from "./composables/useSharedState.js";
|
|
16
|
+
import { useComputedStore, useSimpleStore, useStore } from "./composables/useStore.js";
|
|
17
|
+
import { useStoreDevtools } from "./composables/useStoreDevtools.js";
|
|
18
|
+
import { useStoreSnapshot } from "./composables/useStoreSnapshot.js";
|
|
19
|
+
import { useOnAction, useSubscribe, useWatch } from "./composables/useSubscribe.js";
|
|
20
|
+
import "./composables/index.js";
|
|
21
|
+
import { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin } from "./plugins/pinia-plugin.js";
|
|
22
|
+
import { createStoreRegistryPlugin, getStoreRegistry } from "./runtime/store-registry.js";
|
|
23
|
+
import { createStoreEnginePlugin, getGlobalStoreAPI } from "./plugins/engine-plugin.js";
|
|
24
|
+
import { createStoreVuePlugin } from "./plugins/vue-plugin.js";
|
|
25
|
+
import "./plugins/index.js";
|
|
26
|
+
import { createPinia, defineStore, getActivePinia, mapActions, mapGetters, mapState, mapStores, mapWritableState, setActivePinia, storeToRefs } from "pinia";
|
|
27
|
+
import { batch, combineSelectors, composePlugins, createAsyncAction, createBatchManager, createEventBus, createLoggerMiddleware, createMiddlewareManager, createPluginFactory, createPubSub, createPubSubWithValue, createSelector, createTimeTravelMiddleware, createValidationMiddleware, deepClone, deepMerge, defineStorePlugin, globalEventBus } from "@composy/store-core";
|
|
28
|
+
//#region src/index.ts
|
|
29
|
+
const version = "1.0.0";
|
|
30
|
+
const name = "@composy/store-vue";
|
|
31
|
+
//#endregion
|
|
32
|
+
export { batch, cleanupEnhancedPersist, combineSelectors, composePlugins, createAsyncAction, createBatchManager, createEnhancedPersistPlugin, createEventBus, createLoggerMiddleware, createMiddlewareManager, createPersistPlugin, createPinia, createPluginFactory, createPubSub, createPubSubWithValue, createSelector, createStoreEnginePlugin, createStoreGetters, createStoreRegistryPlugin, createStoreState, createStoreVuePlugin, createTimeTravelMiddleware, createValidationMiddleware, deepClone, deepMerge, defineSetupStore, defineStore, defineStorePlugin, email, getActivePinia, getGlobalStoreAPI, getStoreRegistry, globalEventBus, mapActions, mapGetters, mapState, mapStores, mapWritableState, maxLength, minLength, name, numberRange, pattern, required, setActivePinia, storeToRefs, useComputedStore, useFormStore, useOnAction, useOptimistic, usePersist, usePersistedRef, usePersistedRefWithTTL, usePersistedState, useSharedState, useSimpleStore, useStore, useStoreDevtools, useStoreSnapshot, useSubscribe, useWatch, version };
|
|
33
|
+
/*! End of @composy/store-vue | Powered by @composy/builder */
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @composy/store-vue - Vue 3 状态管理适配器\n *\n * 基于 Pinia 的增强版状态管理解决方案\n *\n * 主要功能:\n * - Pinia 集成与增强\n * - 状态持久化\n * - Engine 插件集成\n * - 丰富的 Composables\n *\n * @module @composy/store-vue\n */\n\n// === Composables ===\nexport {\n createStoreGetters,\n createStoreState,\n // Setup Store 助手\n defineSetupStore,\n email,\n maxLength,\n minLength,\n numberRange,\n pattern,\n // 验证规则工具\n required,\n useComputedStore,\n useFormStore,\n useOnAction,\n useOptimistic,\n usePersist,\n usePersistedRef,\n usePersistedRefWithTTL,\n usePersistedState,\n useSharedState,\n useSimpleStore,\n useStore,\n useStoreDevtools,\n useStoreSnapshot,\n useSubscribe,\n useWatch,\n} from './composables'\n\nexport type {\n ActionContext,\n EventLogEntry,\n FormFieldRules,\n FormFieldState,\n FormValidator,\n OptimisticEntry,\n PersistedStateOptions,\n PersistedStateReturn,\n StateDiff,\n StateSnapshot,\n StoreInfo,\n UseFormStoreOptions,\n UseFormStoreReturn,\n UseOptimisticReturn,\n UseSharedStateOptions,\n UseSharedStateReturn,\n UseStoreDevtoolsReturn,\n UseStoreSnapshotOptions,\n UseStoreSnapshotReturn,\n} from './composables'\n\n// === 插件 ===\nexport {\n cleanupEnhancedPersist,\n createEnhancedPersistPlugin,\n createPersistPlugin,\n createStoreEnginePlugin,\n createStoreRegistryPlugin,\n createStoreVuePlugin,\n getGlobalStoreAPI,\n getStoreRegistry,\n} from './plugins'\n\nexport type {\n EnhancedPersistOptions,\n EnhancedPersistPluginOptions,\n PersistPluginOptions,\n StoreVuePluginOptions,\n} from './plugins'\n\n// === 类型 ===\nexport type {\n GlobalStoreAPI,\n MutationInfo,\n PersistOptions,\n StoreEnginePluginOptions,\n StoreOptions,\n StoreProviderProps,\n SubscribeOptions,\n UsePersistOptions,\n UsePersistReturn,\n UseStoreReturn,\n} from './types'\n\n// === 从 @composy/store-core 重新导出常用功能 ===\nexport {\n // 核心\n batch,\n // 工具\n combineSelectors,\n // 插件\n composePlugins,\n createAsyncAction,\n createBatchManager,\n createEventBus,\n // 中间件\n createLoggerMiddleware,\n createMiddlewareManager,\n createPluginFactory,\n createPubSub,\n createPubSubWithValue,\n createSelector,\n createTimeTravelMiddleware,\n createValidationMiddleware,\n deepClone,\n deepMerge,\n defineStorePlugin,\n globalEventBus,\n} from '@composy/store-core'\n\n// === 从 Pinia 重新导出 ===\nexport {\n createPinia,\n defineStore,\n getActivePinia,\n mapActions,\n mapGetters,\n mapState,\n mapStores,\n mapWritableState,\n setActivePinia,\n storeToRefs,\n} from 'pinia'\n\nexport type {\n Pinia,\n PiniaPlugin,\n PiniaPluginContext,\n StateTree,\n Store,\n StoreDefinition,\n StoreGeneric,\n StoreGetters,\n StoreState,\n} from 'pinia'\n\n// === 版本信息 ===\nexport const version = '1.0.0'\nexport const name = '@composy/store-vue'\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwJO,MAAM,UAAU;AAChB,MAAM,OAAO"}
|