@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.
Files changed (256) hide show
  1. package/README.md +154 -0
  2. package/dist/index.js +1536 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.min.js +1008 -0
  5. package/dist/index.min.js.map +1 -0
  6. package/es/composables/defineSetupStore.d.ts +120 -0
  7. package/es/composables/defineSetupStore.d.ts.map +1 -0
  8. package/es/composables/defineSetupStore.js +29 -0
  9. package/es/composables/defineSetupStore.js.map +1 -0
  10. package/es/composables/index.d.ts +24 -0
  11. package/es/composables/index.d.ts.map +1 -0
  12. package/es/composables/index.js +21 -0
  13. package/es/composables/useFormStore.d.ts +131 -0
  14. package/es/composables/useFormStore.d.ts.map +1 -0
  15. package/es/composables/useFormStore.js +189 -0
  16. package/es/composables/useFormStore.js.map +1 -0
  17. package/es/composables/useOptimistic.d.ts +67 -0
  18. package/es/composables/useOptimistic.d.ts.map +1 -0
  19. package/es/composables/useOptimistic.js +64 -0
  20. package/es/composables/useOptimistic.js.map +1 -0
  21. package/es/composables/usePersist.d.ts +68 -0
  22. package/es/composables/usePersist.d.ts.map +1 -0
  23. package/es/composables/usePersist.js +96 -0
  24. package/es/composables/usePersist.js.map +1 -0
  25. package/es/composables/usePersistedState.d.ts +59 -0
  26. package/es/composables/usePersistedState.d.ts.map +1 -0
  27. package/es/composables/usePersistedState.js +121 -0
  28. package/es/composables/usePersistedState.js.map +1 -0
  29. package/es/composables/useSharedState.d.ts +62 -0
  30. package/es/composables/useSharedState.d.ts.map +1 -0
  31. package/es/composables/useSharedState.js +94 -0
  32. package/es/composables/useSharedState.js.map +1 -0
  33. package/es/composables/useStore.d.ts +99 -0
  34. package/es/composables/useStore.d.ts.map +1 -0
  35. package/es/composables/useStore.js +61 -0
  36. package/es/composables/useStore.js.map +1 -0
  37. package/es/composables/useStoreDevtools.d.ts +31 -0
  38. package/es/composables/useStoreDevtools.d.ts.map +1 -0
  39. package/es/composables/useStoreDevtools.js +112 -0
  40. package/es/composables/useStoreDevtools.js.map +1 -0
  41. package/es/composables/useStoreSnapshot.d.ts +122 -0
  42. package/es/composables/useStoreSnapshot.d.ts.map +1 -0
  43. package/es/composables/useStoreSnapshot.js +209 -0
  44. package/es/composables/useStoreSnapshot.js.map +1 -0
  45. package/es/composables/useSubscribe.d.ts +90 -0
  46. package/es/composables/useSubscribe.d.ts.map +1 -0
  47. package/es/composables/useSubscribe.js +53 -0
  48. package/es/composables/useSubscribe.js.map +1 -0
  49. package/es/context/injection-keys.d.ts +8 -0
  50. package/es/context/injection-keys.d.ts.map +1 -0
  51. package/es/context/injection-keys.js +17 -0
  52. package/es/context/injection-keys.js.map +1 -0
  53. package/es/index.d.ts +24 -0
  54. package/es/index.d.ts.map +1 -0
  55. package/es/index.js +32 -0
  56. package/es/index.js.map +1 -0
  57. package/es/plugins/engine-plugin.d.ts +36 -0
  58. package/es/plugins/engine-plugin.d.ts.map +1 -0
  59. package/es/plugins/engine-plugin.js +83 -0
  60. package/es/plugins/engine-plugin.js.map +1 -0
  61. package/es/plugins/enhanced-persist-plugin.d.ts +3 -0
  62. package/es/plugins/enhanced-persist-plugin.d.ts.map +1 -0
  63. package/es/plugins/enhanced-persist-plugin.js +12 -0
  64. package/es/plugins/index.d.ts +7 -0
  65. package/es/plugins/index.d.ts.map +1 -0
  66. package/es/plugins/index.js +15 -0
  67. package/es/plugins/pinia-plugin.d.ts +68 -0
  68. package/es/plugins/pinia-plugin.d.ts.map +1 -0
  69. package/es/plugins/pinia-plugin.js +172 -0
  70. package/es/plugins/pinia-plugin.js.map +1 -0
  71. package/es/plugins/registry-plugin.d.ts +2 -0
  72. package/es/plugins/registry-plugin.d.ts.map +1 -0
  73. package/es/plugins/registry-plugin.js +12 -0
  74. package/es/plugins/vue-plugin.d.ts +10 -0
  75. package/es/plugins/vue-plugin.d.ts.map +1 -0
  76. package/es/plugins/vue-plugin.js +24 -0
  77. package/es/plugins/vue-plugin.js.map +1 -0
  78. package/es/runtime/install-store-app.d.ts +23 -0
  79. package/es/runtime/install-store-app.d.ts.map +1 -0
  80. package/es/runtime/install-store-app.js +54 -0
  81. package/es/runtime/install-store-app.js.map +1 -0
  82. package/es/runtime/store-plugin-options.d.ts +40 -0
  83. package/es/runtime/store-plugin-options.d.ts.map +1 -0
  84. package/es/runtime/store-plugin-options.js +24 -0
  85. package/es/runtime/store-plugin-options.js.map +1 -0
  86. package/es/runtime/store-registry.d.ts +64 -0
  87. package/es/runtime/store-registry.d.ts.map +1 -0
  88. package/es/runtime/store-registry.js +102 -0
  89. package/es/runtime/store-registry.js.map +1 -0
  90. package/es/runtime/store-runtime.d.ts +46 -0
  91. package/es/runtime/store-runtime.d.ts.map +1 -0
  92. package/es/runtime/store-runtime.js +58 -0
  93. package/es/runtime/store-runtime.js.map +1 -0
  94. package/es/types.d.ts +167 -0
  95. package/es/types.d.ts.map +1 -0
  96. package/es/types.js +10 -0
  97. package/esm/composables/defineSetupStore.d.ts +120 -0
  98. package/esm/composables/defineSetupStore.d.ts.map +1 -0
  99. package/esm/composables/defineSetupStore.js +29 -0
  100. package/esm/composables/defineSetupStore.js.map +1 -0
  101. package/esm/composables/index.d.ts +24 -0
  102. package/esm/composables/index.d.ts.map +1 -0
  103. package/esm/composables/index.js +21 -0
  104. package/esm/composables/useFormStore.d.ts +131 -0
  105. package/esm/composables/useFormStore.d.ts.map +1 -0
  106. package/esm/composables/useFormStore.js +189 -0
  107. package/esm/composables/useFormStore.js.map +1 -0
  108. package/esm/composables/useOptimistic.d.ts +67 -0
  109. package/esm/composables/useOptimistic.d.ts.map +1 -0
  110. package/esm/composables/useOptimistic.js +64 -0
  111. package/esm/composables/useOptimistic.js.map +1 -0
  112. package/esm/composables/usePersist.d.ts +68 -0
  113. package/esm/composables/usePersist.d.ts.map +1 -0
  114. package/esm/composables/usePersist.js +96 -0
  115. package/esm/composables/usePersist.js.map +1 -0
  116. package/esm/composables/usePersistedState.d.ts +59 -0
  117. package/esm/composables/usePersistedState.d.ts.map +1 -0
  118. package/esm/composables/usePersistedState.js +121 -0
  119. package/esm/composables/usePersistedState.js.map +1 -0
  120. package/esm/composables/useSharedState.d.ts +62 -0
  121. package/esm/composables/useSharedState.d.ts.map +1 -0
  122. package/esm/composables/useSharedState.js +94 -0
  123. package/esm/composables/useSharedState.js.map +1 -0
  124. package/esm/composables/useStore.d.ts +99 -0
  125. package/esm/composables/useStore.d.ts.map +1 -0
  126. package/esm/composables/useStore.js +61 -0
  127. package/esm/composables/useStore.js.map +1 -0
  128. package/esm/composables/useStoreDevtools.d.ts +31 -0
  129. package/esm/composables/useStoreDevtools.d.ts.map +1 -0
  130. package/esm/composables/useStoreDevtools.js +112 -0
  131. package/esm/composables/useStoreDevtools.js.map +1 -0
  132. package/esm/composables/useStoreSnapshot.d.ts +122 -0
  133. package/esm/composables/useStoreSnapshot.d.ts.map +1 -0
  134. package/esm/composables/useStoreSnapshot.js +209 -0
  135. package/esm/composables/useStoreSnapshot.js.map +1 -0
  136. package/esm/composables/useSubscribe.d.ts +90 -0
  137. package/esm/composables/useSubscribe.d.ts.map +1 -0
  138. package/esm/composables/useSubscribe.js +53 -0
  139. package/esm/composables/useSubscribe.js.map +1 -0
  140. package/esm/context/injection-keys.d.ts +8 -0
  141. package/esm/context/injection-keys.d.ts.map +1 -0
  142. package/esm/context/injection-keys.js +17 -0
  143. package/esm/context/injection-keys.js.map +1 -0
  144. package/esm/index.d.ts +24 -0
  145. package/esm/index.d.ts.map +1 -0
  146. package/esm/index.js +34 -0
  147. package/esm/index.js.map +1 -0
  148. package/esm/plugins/engine-plugin.d.ts +36 -0
  149. package/esm/plugins/engine-plugin.d.ts.map +1 -0
  150. package/esm/plugins/engine-plugin.js +83 -0
  151. package/esm/plugins/engine-plugin.js.map +1 -0
  152. package/esm/plugins/enhanced-persist-plugin.d.ts +3 -0
  153. package/esm/plugins/enhanced-persist-plugin.d.ts.map +1 -0
  154. package/esm/plugins/enhanced-persist-plugin.js +12 -0
  155. package/esm/plugins/index.d.ts +7 -0
  156. package/esm/plugins/index.d.ts.map +1 -0
  157. package/esm/plugins/index.js +16 -0
  158. package/esm/plugins/pinia-plugin.d.ts +68 -0
  159. package/esm/plugins/pinia-plugin.d.ts.map +1 -0
  160. package/esm/plugins/pinia-plugin.js +172 -0
  161. package/esm/plugins/pinia-plugin.js.map +1 -0
  162. package/esm/plugins/registry-plugin.d.ts +2 -0
  163. package/esm/plugins/registry-plugin.d.ts.map +1 -0
  164. package/esm/plugins/registry-plugin.js +12 -0
  165. package/esm/plugins/vue-plugin.d.ts +10 -0
  166. package/esm/plugins/vue-plugin.d.ts.map +1 -0
  167. package/esm/plugins/vue-plugin.js +24 -0
  168. package/esm/plugins/vue-plugin.js.map +1 -0
  169. package/esm/runtime/install-store-app.d.ts +23 -0
  170. package/esm/runtime/install-store-app.d.ts.map +1 -0
  171. package/esm/runtime/install-store-app.js +54 -0
  172. package/esm/runtime/install-store-app.js.map +1 -0
  173. package/esm/runtime/store-plugin-options.d.ts +40 -0
  174. package/esm/runtime/store-plugin-options.d.ts.map +1 -0
  175. package/esm/runtime/store-plugin-options.js +24 -0
  176. package/esm/runtime/store-plugin-options.js.map +1 -0
  177. package/esm/runtime/store-registry.d.ts +64 -0
  178. package/esm/runtime/store-registry.d.ts.map +1 -0
  179. package/esm/runtime/store-registry.js +94 -0
  180. package/esm/runtime/store-registry.js.map +1 -0
  181. package/esm/runtime/store-runtime.d.ts +46 -0
  182. package/esm/runtime/store-runtime.d.ts.map +1 -0
  183. package/esm/runtime/store-runtime.js +58 -0
  184. package/esm/runtime/store-runtime.js.map +1 -0
  185. package/esm/types.d.ts +167 -0
  186. package/esm/types.d.ts.map +1 -0
  187. package/esm/types.js +10 -0
  188. package/lib/composables/defineSetupStore.cjs +33 -0
  189. package/lib/composables/defineSetupStore.cjs.map +1 -0
  190. package/lib/composables/defineSetupStore.d.ts +120 -0
  191. package/lib/composables/index.cjs +46 -0
  192. package/lib/composables/index.d.ts +24 -0
  193. package/lib/composables/useFormStore.cjs +197 -0
  194. package/lib/composables/useFormStore.cjs.map +1 -0
  195. package/lib/composables/useFormStore.d.ts +131 -0
  196. package/lib/composables/useOptimistic.cjs +66 -0
  197. package/lib/composables/useOptimistic.cjs.map +1 -0
  198. package/lib/composables/useOptimistic.d.ts +67 -0
  199. package/lib/composables/usePersist.cjs +100 -0
  200. package/lib/composables/usePersist.cjs.map +1 -0
  201. package/lib/composables/usePersist.d.ts +68 -0
  202. package/lib/composables/usePersistedState.cjs +123 -0
  203. package/lib/composables/usePersistedState.cjs.map +1 -0
  204. package/lib/composables/usePersistedState.d.ts +59 -0
  205. package/lib/composables/useSharedState.cjs +96 -0
  206. package/lib/composables/useSharedState.cjs.map +1 -0
  207. package/lib/composables/useSharedState.d.ts +62 -0
  208. package/lib/composables/useStore.cjs +65 -0
  209. package/lib/composables/useStore.cjs.map +1 -0
  210. package/lib/composables/useStore.d.ts +99 -0
  211. package/lib/composables/useStoreDevtools.cjs +114 -0
  212. package/lib/composables/useStoreDevtools.cjs.map +1 -0
  213. package/lib/composables/useStoreDevtools.d.ts +31 -0
  214. package/lib/composables/useStoreSnapshot.cjs +211 -0
  215. package/lib/composables/useStoreSnapshot.cjs.map +1 -0
  216. package/lib/composables/useStoreSnapshot.d.ts +122 -0
  217. package/lib/composables/useSubscribe.cjs +57 -0
  218. package/lib/composables/useSubscribe.cjs.map +1 -0
  219. package/lib/composables/useSubscribe.d.ts +90 -0
  220. package/lib/context/injection-keys.cjs +21 -0
  221. package/lib/context/injection-keys.cjs.map +1 -0
  222. package/lib/context/injection-keys.d.ts +8 -0
  223. package/lib/index.cjs +235 -0
  224. package/lib/index.cjs.map +1 -0
  225. package/lib/index.d.ts +24 -0
  226. package/lib/package.json +3 -0
  227. package/lib/plugins/engine-plugin.cjs +90 -0
  228. package/lib/plugins/engine-plugin.cjs.map +1 -0
  229. package/lib/plugins/engine-plugin.d.ts +36 -0
  230. package/lib/plugins/enhanced-persist-plugin.cjs +15 -0
  231. package/lib/plugins/enhanced-persist-plugin.d.ts +3 -0
  232. package/lib/plugins/index.cjs +28 -0
  233. package/lib/plugins/index.d.ts +7 -0
  234. package/lib/plugins/pinia-plugin.cjs +177 -0
  235. package/lib/plugins/pinia-plugin.cjs.map +1 -0
  236. package/lib/plugins/pinia-plugin.d.ts +68 -0
  237. package/lib/plugins/registry-plugin.cjs +18 -0
  238. package/lib/plugins/registry-plugin.d.ts +2 -0
  239. package/lib/plugins/vue-plugin.cjs +26 -0
  240. package/lib/plugins/vue-plugin.cjs.map +1 -0
  241. package/lib/plugins/vue-plugin.d.ts +10 -0
  242. package/lib/runtime/install-store-app.cjs +57 -0
  243. package/lib/runtime/install-store-app.cjs.map +1 -0
  244. package/lib/runtime/install-store-app.d.ts +23 -0
  245. package/lib/runtime/store-plugin-options.cjs +26 -0
  246. package/lib/runtime/store-plugin-options.cjs.map +1 -0
  247. package/lib/runtime/store-plugin-options.d.ts +40 -0
  248. package/lib/runtime/store-registry.cjs +108 -0
  249. package/lib/runtime/store-registry.cjs.map +1 -0
  250. package/lib/runtime/store-registry.d.ts +64 -0
  251. package/lib/runtime/store-runtime.cjs +62 -0
  252. package/lib/runtime/store-runtime.cjs.map +1 -0
  253. package/lib/runtime/store-runtime.d.ts +46 -0
  254. package/lib/types.cjs +12 -0
  255. package/lib/types.d.ts +167 -0
  256. 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,57 @@
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
+ "use strict";
11
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
+ let vue = require("vue");
13
+ //#region src/composables/useSubscribe.ts
14
+ function useSubscribe(store, callback, options = {}) {
15
+ const { detached = false } = options;
16
+ if (store.$subscribe) {
17
+ const unsubscribe = store.$subscribe((mutation, state) => {
18
+ callback(mutation, state);
19
+ }, { detached });
20
+ if (!detached) (0, vue.onUnmounted)(() => {
21
+ unsubscribe();
22
+ });
23
+ return unsubscribe;
24
+ }
25
+ console.warn("[useSubscribe] Store 不支持 $subscribe 方法");
26
+ return () => {};
27
+ }
28
+ function useOnAction(store, callback, detached = false) {
29
+ if (store.$onAction) {
30
+ const unsubscribe = store.$onAction(callback, detached);
31
+ if (!detached) (0, vue.onUnmounted)(() => {
32
+ unsubscribe();
33
+ });
34
+ return unsubscribe;
35
+ }
36
+ console.warn("[useOnAction] Store 不支持 $onAction 方法");
37
+ return () => {};
38
+ }
39
+ function useWatch(source, callback, options = {}) {
40
+ const { immediate = false, deep = false, detached = false } = options;
41
+ const stop = (0, vue.watch)(source, (newValue, oldValue) => {
42
+ callback(newValue, oldValue);
43
+ }, {
44
+ immediate,
45
+ deep
46
+ });
47
+ if (!detached) (0, vue.onUnmounted)(() => {
48
+ stop();
49
+ });
50
+ return stop;
51
+ }
52
+ //#endregion
53
+ exports.useOnAction = useOnAction;
54
+ exports.useSubscribe = useSubscribe;
55
+ exports.useWatch = useWatch;
56
+ /*! End of @composy/store-vue | Powered by @composy/builder */
57
+ //# sourceMappingURL=useSubscribe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubscribe.cjs","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,CAAA,GAAA,IAAA,YAAA,OAAkB;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,CAAA,GAAA,IAAA,YAAA,OAAkB;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,QAAA,GAAA,IAAA,MAAA,CACJ,SACC,UAAU,aAAa;EACtB,SAAS,UAAU,QAAQ;CAC7B,GACA;EAAE;EAAW;CAAK,CACpB;CAEA,IAAI,CAAC,UACH,CAAA,GAAA,IAAA,YAAA,OAAkB;EAChB,KAAK;CACP,CAAC;CAGH,OAAO;AACT"}
@@ -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,21 @@
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
+ "use strict";
11
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
+ //#region src/context/injection-keys.ts
13
+ const STORE_API_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-api");
14
+ const STORE_PINIA_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-pinia");
15
+ const STORE_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol("ldesign-store-runtime");
16
+ //#endregion
17
+ exports.STORE_API_SYMBOL = STORE_API_SYMBOL;
18
+ exports.STORE_PINIA_SYMBOL = STORE_PINIA_SYMBOL;
19
+ exports.STORE_RUNTIME_SYMBOL = STORE_RUNTIME_SYMBOL;
20
+ /*! End of @composy/store-vue | Powered by @composy/builder */
21
+ //# sourceMappingURL=injection-keys.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injection-keys.cjs","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"}
@@ -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
package/lib/index.cjs ADDED
@@ -0,0 +1,235 @@
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
+ "use strict";
11
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
+ const require_defineSetupStore = require("./composables/defineSetupStore.cjs");
13
+ const require_useFormStore = require("./composables/useFormStore.cjs");
14
+ const require_useOptimistic = require("./composables/useOptimistic.cjs");
15
+ const require_usePersist = require("./composables/usePersist.cjs");
16
+ const require_usePersistedState = require("./composables/usePersistedState.cjs");
17
+ const require_useSharedState = require("./composables/useSharedState.cjs");
18
+ const require_useStore = require("./composables/useStore.cjs");
19
+ const require_useStoreDevtools = require("./composables/useStoreDevtools.cjs");
20
+ const require_useStoreSnapshot = require("./composables/useStoreSnapshot.cjs");
21
+ const require_useSubscribe = require("./composables/useSubscribe.cjs");
22
+ const require_pinia_plugin = require("./plugins/pinia-plugin.cjs");
23
+ const require_store_registry = require("./runtime/store-registry.cjs");
24
+ const require_engine_plugin = require("./plugins/engine-plugin.cjs");
25
+ const require_vue_plugin = require("./plugins/vue-plugin.cjs");
26
+ let pinia = require("pinia");
27
+ let _composy_store_core = require("@composy/store-core");
28
+ //#region src/index.ts
29
+ const version = "1.0.0";
30
+ const name = "@composy/store-vue";
31
+ //#endregion
32
+ Object.defineProperty(exports, "batch", {
33
+ enumerable: true,
34
+ get: function() {
35
+ return _composy_store_core.batch;
36
+ }
37
+ });
38
+ exports.cleanupEnhancedPersist = require_pinia_plugin.cleanupEnhancedPersist;
39
+ Object.defineProperty(exports, "combineSelectors", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return _composy_store_core.combineSelectors;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "composePlugins", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return _composy_store_core.composePlugins;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "createAsyncAction", {
52
+ enumerable: true,
53
+ get: function() {
54
+ return _composy_store_core.createAsyncAction;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "createBatchManager", {
58
+ enumerable: true,
59
+ get: function() {
60
+ return _composy_store_core.createBatchManager;
61
+ }
62
+ });
63
+ exports.createEnhancedPersistPlugin = require_pinia_plugin.createEnhancedPersistPlugin;
64
+ Object.defineProperty(exports, "createEventBus", {
65
+ enumerable: true,
66
+ get: function() {
67
+ return _composy_store_core.createEventBus;
68
+ }
69
+ });
70
+ Object.defineProperty(exports, "createLoggerMiddleware", {
71
+ enumerable: true,
72
+ get: function() {
73
+ return _composy_store_core.createLoggerMiddleware;
74
+ }
75
+ });
76
+ Object.defineProperty(exports, "createMiddlewareManager", {
77
+ enumerable: true,
78
+ get: function() {
79
+ return _composy_store_core.createMiddlewareManager;
80
+ }
81
+ });
82
+ exports.createPersistPlugin = require_pinia_plugin.createPersistPlugin;
83
+ Object.defineProperty(exports, "createPinia", {
84
+ enumerable: true,
85
+ get: function() {
86
+ return pinia.createPinia;
87
+ }
88
+ });
89
+ Object.defineProperty(exports, "createPluginFactory", {
90
+ enumerable: true,
91
+ get: function() {
92
+ return _composy_store_core.createPluginFactory;
93
+ }
94
+ });
95
+ Object.defineProperty(exports, "createPubSub", {
96
+ enumerable: true,
97
+ get: function() {
98
+ return _composy_store_core.createPubSub;
99
+ }
100
+ });
101
+ Object.defineProperty(exports, "createPubSubWithValue", {
102
+ enumerable: true,
103
+ get: function() {
104
+ return _composy_store_core.createPubSubWithValue;
105
+ }
106
+ });
107
+ Object.defineProperty(exports, "createSelector", {
108
+ enumerable: true,
109
+ get: function() {
110
+ return _composy_store_core.createSelector;
111
+ }
112
+ });
113
+ exports.createStoreEnginePlugin = require_engine_plugin.createStoreEnginePlugin;
114
+ exports.createStoreGetters = require_defineSetupStore.createStoreGetters;
115
+ exports.createStoreRegistryPlugin = require_store_registry.createStoreRegistryPlugin;
116
+ exports.createStoreState = require_defineSetupStore.createStoreState;
117
+ exports.createStoreVuePlugin = require_vue_plugin.createStoreVuePlugin;
118
+ Object.defineProperty(exports, "createTimeTravelMiddleware", {
119
+ enumerable: true,
120
+ get: function() {
121
+ return _composy_store_core.createTimeTravelMiddleware;
122
+ }
123
+ });
124
+ Object.defineProperty(exports, "createValidationMiddleware", {
125
+ enumerable: true,
126
+ get: function() {
127
+ return _composy_store_core.createValidationMiddleware;
128
+ }
129
+ });
130
+ Object.defineProperty(exports, "deepClone", {
131
+ enumerable: true,
132
+ get: function() {
133
+ return _composy_store_core.deepClone;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, "deepMerge", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return _composy_store_core.deepMerge;
140
+ }
141
+ });
142
+ exports.defineSetupStore = require_defineSetupStore.defineSetupStore;
143
+ Object.defineProperty(exports, "defineStore", {
144
+ enumerable: true,
145
+ get: function() {
146
+ return pinia.defineStore;
147
+ }
148
+ });
149
+ Object.defineProperty(exports, "defineStorePlugin", {
150
+ enumerable: true,
151
+ get: function() {
152
+ return _composy_store_core.defineStorePlugin;
153
+ }
154
+ });
155
+ exports.email = require_useFormStore.email;
156
+ Object.defineProperty(exports, "getActivePinia", {
157
+ enumerable: true,
158
+ get: function() {
159
+ return pinia.getActivePinia;
160
+ }
161
+ });
162
+ exports.getGlobalStoreAPI = require_engine_plugin.getGlobalStoreAPI;
163
+ exports.getStoreRegistry = require_store_registry.getStoreRegistry;
164
+ Object.defineProperty(exports, "globalEventBus", {
165
+ enumerable: true,
166
+ get: function() {
167
+ return _composy_store_core.globalEventBus;
168
+ }
169
+ });
170
+ Object.defineProperty(exports, "mapActions", {
171
+ enumerable: true,
172
+ get: function() {
173
+ return pinia.mapActions;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, "mapGetters", {
177
+ enumerable: true,
178
+ get: function() {
179
+ return pinia.mapGetters;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, "mapState", {
183
+ enumerable: true,
184
+ get: function() {
185
+ return pinia.mapState;
186
+ }
187
+ });
188
+ Object.defineProperty(exports, "mapStores", {
189
+ enumerable: true,
190
+ get: function() {
191
+ return pinia.mapStores;
192
+ }
193
+ });
194
+ Object.defineProperty(exports, "mapWritableState", {
195
+ enumerable: true,
196
+ get: function() {
197
+ return pinia.mapWritableState;
198
+ }
199
+ });
200
+ exports.maxLength = require_useFormStore.maxLength;
201
+ exports.minLength = require_useFormStore.minLength;
202
+ exports.name = name;
203
+ exports.numberRange = require_useFormStore.numberRange;
204
+ exports.pattern = require_useFormStore.pattern;
205
+ exports.required = require_useFormStore.required;
206
+ Object.defineProperty(exports, "setActivePinia", {
207
+ enumerable: true,
208
+ get: function() {
209
+ return pinia.setActivePinia;
210
+ }
211
+ });
212
+ Object.defineProperty(exports, "storeToRefs", {
213
+ enumerable: true,
214
+ get: function() {
215
+ return pinia.storeToRefs;
216
+ }
217
+ });
218
+ exports.useComputedStore = require_useStore.useComputedStore;
219
+ exports.useFormStore = require_useFormStore.useFormStore;
220
+ exports.useOnAction = require_useSubscribe.useOnAction;
221
+ exports.useOptimistic = require_useOptimistic.useOptimistic;
222
+ exports.usePersist = require_usePersist.usePersist;
223
+ exports.usePersistedRef = require_usePersist.usePersistedRef;
224
+ exports.usePersistedRefWithTTL = require_usePersist.usePersistedRefWithTTL;
225
+ exports.usePersistedState = require_usePersistedState.usePersistedState;
226
+ exports.useSharedState = require_useSharedState.useSharedState;
227
+ exports.useSimpleStore = require_useStore.useSimpleStore;
228
+ exports.useStore = require_useStore.useStore;
229
+ exports.useStoreDevtools = require_useStoreDevtools.useStoreDevtools;
230
+ exports.useStoreSnapshot = require_useStoreSnapshot.useStoreSnapshot;
231
+ exports.useSubscribe = require_useSubscribe.useSubscribe;
232
+ exports.useWatch = require_useSubscribe.useWatch;
233
+ exports.version = version;
234
+ /*! End of @composy/store-vue | Powered by @composy/builder */
235
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","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"}
package/lib/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,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,90 @@
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
+ "use strict";
11
+ Object.defineProperties(exports, {
12
+ __esModule: { value: true },
13
+ [Symbol.toStringTag]: { value: "Module" }
14
+ });
15
+ const require_store_runtime = require("../runtime/store-runtime.cjs");
16
+ const require_install_store_app = require("../runtime/install-store-app.cjs");
17
+ let _composy_store_core_engine = require("@composy/store-core/engine");
18
+ //#region src/plugins/engine-plugin.ts
19
+ function isVueApp(value) {
20
+ return !!value && typeof value.use === "function";
21
+ }
22
+ function resolveVueApp(engine, context, payload) {
23
+ const appPayload = payload;
24
+ const app = appPayload?.app ?? appPayload?.framework?.app ?? engine.getApp?.() ?? context.framework?.app;
25
+ return isVueApp(app) ? app : void 0;
26
+ }
27
+ function getGlobalStoreAPI() {
28
+ return require_store_runtime.getGlobalStoreAPI();
29
+ }
30
+ function createStoreEnginePlugin(options = {}) {
31
+ const { debug = false, dependencies = [], name = "store", version = "1.0.0" } = options;
32
+ let bridge = null;
33
+ const createBridge = () => {
34
+ const activeBridge = (0, _composy_store_core_engine.createStoreEngineBridge)({
35
+ name,
36
+ version,
37
+ debug,
38
+ createRuntime: () => require_store_runtime.createStoreRuntime({
39
+ pinia: options.pinia,
40
+ persist: options.persist,
41
+ persistOptions: options.persistOptions,
42
+ globalProperties: options.globalProperties,
43
+ provide: options.provide,
44
+ debug
45
+ }),
46
+ attachToApp: (app, runtime) => require_install_store_app.installStoreRuntime(app, runtime),
47
+ getRuntimeFromApp: (app) => require_install_store_app.getInstalledStoreRuntime(app),
48
+ isApp: isVueApp,
49
+ resolveApp: resolveVueApp
50
+ });
51
+ bridge = activeBridge;
52
+ return activeBridge;
53
+ };
54
+ const getBridge = () => {
55
+ return bridge ?? createBridge();
56
+ };
57
+ return {
58
+ name,
59
+ version,
60
+ dependencies,
61
+ /**
62
+ * 安装到引擎上下文(异步)
63
+ * 通过 bridge 将 store 能力注册到引擎
64
+ */
65
+ async install(context) {
66
+ await getBridge().install(context);
67
+ },
68
+ /**
69
+ * 安装到 Vue App
70
+ * 将 store 运行时连接到 Vue 应用实例
71
+ */
72
+ installVue(app) {
73
+ getBridge().attachToApp(app);
74
+ },
75
+ /**
76
+ * 从引擎上下文卸载(异步)
77
+ * 清理 bridge 引用
78
+ */
79
+ async uninstall(context) {
80
+ await getBridge().uninstall(context);
81
+ bridge = null;
82
+ }
83
+ };
84
+ }
85
+ //#endregion
86
+ exports.createStoreEnginePlugin = createStoreEnginePlugin;
87
+ exports.default = createStoreEnginePlugin;
88
+ exports.getGlobalStoreAPI = getGlobalStoreAPI;
89
+ /*! End of @composy/store-vue | Powered by @composy/builder */
90
+ //# sourceMappingURL=engine-plugin.cjs.map