@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,53 @@
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 { 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/es/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,EACZ,QAAQ,GACT,MAAM,eAAe,CAAA;AAEtB,YAAY,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAElB,YAAY,EACV,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,WAAW,CAAA;AAGlB,YAAY,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACf,MAAM,SAAS,CAAA;AAGhB,OAAO,EAEL,KAAK,EAEL,gBAAgB,EAEhB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EAEd,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,cAAc,EACd,0BAA0B,EAC1B,0BAA0B,EAC1B,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,cAAc,GACf,MAAM,qBAAqB,CAAA;AAG5B,OAAO,EACL,WAAW,EACX,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,OAAO,CAAA;AAEd,YAAY,EACV,KAAK,EACL,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,UAAU,GACX,MAAM,OAAO,CAAA;AAGd,eAAO,MAAM,OAAO,UAAU,CAAA;AAC9B,eAAO,MAAM,IAAI,uBAAuB,CAAA"}
package/es/index.js ADDED
@@ -0,0 +1,32 @@
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 { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin } from "./plugins/pinia-plugin.js";
21
+ import { createStoreRegistryPlugin, getStoreRegistry } from "./runtime/store-registry.js";
22
+ import { createStoreEnginePlugin, getGlobalStoreAPI } from "./plugins/engine-plugin.js";
23
+ import { createStoreVuePlugin } from "./plugins/vue-plugin.js";
24
+ import { createPinia, defineStore, getActivePinia, mapActions, mapGetters, mapState, mapStores, mapWritableState, setActivePinia, storeToRefs } from "pinia";
25
+ import { batch, combineSelectors, composePlugins, createAsyncAction, createBatchManager, createEventBus, createLoggerMiddleware, createMiddlewareManager, createPluginFactory, createPubSub, createPubSubWithValue, createSelector, createTimeTravelMiddleware, createValidationMiddleware, deepClone, deepMerge, defineStorePlugin, globalEventBus } from "@composy/store-core";
26
+ //#region src/index.ts
27
+ const version = "1.0.0";
28
+ const name = "@composy/store-vue";
29
+ //#endregion
30
+ 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 };
31
+ /*! End of @composy/store-vue | Powered by @composy/builder */
32
+ //# sourceMappingURL=index.js.map
@@ -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"}
@@ -0,0 +1,36 @@
1
+ import type { /* 引擎抽象接口 */ StoreEnginePluginContextLike } from '@composy/store-core/engine';
2
+ import type { App } from 'vue';
3
+ import type { GlobalStoreAPI, StoreEnginePluginOptions } from '../types';
4
+ /**
5
+ * Store Engine 插件接口
6
+ * 定义了插件的元信息和生命周期方法
7
+ * @property dependencies - 依赖的其他插件名称列表
8
+ * @property name - 插件名称
9
+ * @property version - 插件版本
10
+ * @property install - 安装到引擎上下文(异步)
11
+ * @property installVue - 安装到 Vue App
12
+ * @property uninstall - 从引擎上下文卸载(异步)
13
+ */
14
+ export interface StoreEnginePlugin {
15
+ dependencies: string[];
16
+ name: string;
17
+ version: string;
18
+ install: (context: StoreEnginePluginContextLike) => Promise<void>;
19
+ installVue: (app: App) => void;
20
+ uninstall: (context?: StoreEnginePluginContextLike) => Promise<void>;
21
+ }
22
+ /**
23
+ * 获取当前活跃的全局 Store API
24
+ * @returns 全局 Store API 或 null(未初始化时)
25
+ */
26
+ export declare function getGlobalStoreAPI(): GlobalStoreAPI | null;
27
+ /**
28
+ * 创建 Store Engine 插件工厂函数
29
+ * 这是 Vue 适配层的核心入口,将 core 层的 bridge 包装为 Vue 友好的插件
30
+ *
31
+ * @param options - 插件配置选项
32
+ * @returns StoreEnginePlugin 插件实例
33
+ */
34
+ export declare function createStoreEnginePlugin(options?: StoreEnginePluginOptions): StoreEnginePlugin;
35
+ export default createStoreEnginePlugin;
36
+ //# sourceMappingURL=engine-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/engine-plugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAE4B,YAAY,CAClD,4BAA4B,EAC7B,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAI9B,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAQxE;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjE,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC9B,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,4BAA4B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACrE;AAoCD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CAEzD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,iBAAiB,CAwFjG;AAGD,eAAe,uBAAuB,CAAA"}
@@ -0,0 +1,83 @@
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 { createStoreRuntime, getGlobalStoreAPI as getGlobalStoreAPI$1 } from "../runtime/store-runtime.js";
11
+ import { getInstalledStoreRuntime, installStoreRuntime } from "../runtime/install-store-app.js";
12
+ import { createStoreEngineBridge } from "@composy/store-core/engine";
13
+ //#region src/plugins/engine-plugin.ts
14
+ function isVueApp(value) {
15
+ return !!value && typeof value.use === "function";
16
+ }
17
+ function resolveVueApp(engine, context, payload) {
18
+ const appPayload = payload;
19
+ const app = appPayload?.app ?? appPayload?.framework?.app ?? engine.getApp?.() ?? context.framework?.app;
20
+ return isVueApp(app) ? app : void 0;
21
+ }
22
+ function getGlobalStoreAPI() {
23
+ return getGlobalStoreAPI$1();
24
+ }
25
+ function createStoreEnginePlugin(options = {}) {
26
+ const { debug = false, dependencies = [], name = "store", version = "1.0.0" } = options;
27
+ let bridge = null;
28
+ const createBridge = () => {
29
+ const activeBridge = createStoreEngineBridge({
30
+ name,
31
+ version,
32
+ debug,
33
+ createRuntime: () => createStoreRuntime({
34
+ pinia: options.pinia,
35
+ persist: options.persist,
36
+ persistOptions: options.persistOptions,
37
+ globalProperties: options.globalProperties,
38
+ provide: options.provide,
39
+ debug
40
+ }),
41
+ attachToApp: (app, runtime) => installStoreRuntime(app, runtime),
42
+ getRuntimeFromApp: (app) => getInstalledStoreRuntime(app),
43
+ isApp: isVueApp,
44
+ resolveApp: resolveVueApp
45
+ });
46
+ bridge = activeBridge;
47
+ return activeBridge;
48
+ };
49
+ const getBridge = () => {
50
+ return bridge ?? createBridge();
51
+ };
52
+ return {
53
+ name,
54
+ version,
55
+ dependencies,
56
+ /**
57
+ * 安装到引擎上下文(异步)
58
+ * 通过 bridge 将 store 能力注册到引擎
59
+ */
60
+ async install(context) {
61
+ await getBridge().install(context);
62
+ },
63
+ /**
64
+ * 安装到 Vue App
65
+ * 将 store 运行时连接到 Vue 应用实例
66
+ */
67
+ installVue(app) {
68
+ getBridge().attachToApp(app);
69
+ },
70
+ /**
71
+ * 从引擎上下文卸载(异步)
72
+ * 清理 bridge 引用
73
+ */
74
+ async uninstall(context) {
75
+ await getBridge().uninstall(context);
76
+ bridge = null;
77
+ }
78
+ };
79
+ }
80
+ //#endregion
81
+ export { createStoreEnginePlugin, createStoreEnginePlugin as default, getGlobalStoreAPI };
82
+ /*! End of @composy/store-vue | Powered by @composy/builder */
83
+ //# sourceMappingURL=engine-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-plugin.js","names":[],"sources":["../../src/plugins/engine-plugin.ts"],"sourcesContent":["/* ============================================================\n * engine-plugin.ts\n * Store Engine 插件(Vue 适配层)\n * 将 core 层的 createStoreEngineBridge 包装为 Vue 友好的插件接口\n * 负责创建 bridge、管理运行时生命周期、连接 Vue App\n * ============================================================ */\n\n/* 从 core/engine 导入 bridge 相关类型 */\nimport type {\n StoreEngineBridge, /* 引擎桥接实例接口 */\n StoreEngineLike, /* 引擎抽象接口 */\n StoreEnginePluginContextLike, /* 插件上下文接口 */\n} from '@composy/store-core/engine'\n/* Vue App 类型 */\nimport type { App } from 'vue'\n/* 本地 store 运行时类型 */\nimport type { StoreRuntime } from '../runtime/store-runtime'\n/* 全局 Store API 和插件选项类型 */\nimport type { GlobalStoreAPI, StoreEnginePluginOptions } from '../types'\n/* 从 core/engine 导入 bridge 创建函数 */\nimport { createStoreEngineBridge } from '@composy/store-core/engine'\n/* 导入 Vue App 运行时安装相关函数 */\nimport { getInstalledStoreRuntime, installStoreRuntime } from '../runtime/install-store-app'\n/* 导入运行时创建函数和全局 API 获取函数 */\nimport { createStoreRuntime, getGlobalStoreAPI as getActiveStoreAPI } from '../runtime/store-runtime'\n\n/**\n * Store Engine 插件接口\n * 定义了插件的元信息和生命周期方法\n * @property dependencies - 依赖的其他插件名称列表\n * @property name - 插件名称\n * @property version - 插件版本\n * @property install - 安装到引擎上下文(异步)\n * @property installVue - 安装到 Vue App\n * @property uninstall - 从引擎上下文卸载(异步)\n */\nexport interface StoreEnginePlugin {\n dependencies: string[]\n name: string\n version: string\n install: (context: StoreEnginePluginContextLike) => Promise<void>\n installVue: (app: App) => void\n uninstall: (context?: StoreEnginePluginContextLike) => Promise<void>\n}\n\n/**\n * 类型守卫:判断值是否为 Vue App 实例\n * 通过检查是否有 use 方法来识别\n */\nfunction isVueApp(value: unknown): value is App {\n return !!value && typeof (value as App).use === 'function'\n}\n\n/**\n * 从各种可能的来源解析 Vue App 实例\n * 按优先级尝试:payload.app → payload.framework.app → engine.getApp() → context.framework.app\n *\n * @param engine - Store 引擎实例\n * @param context - 插件上下文\n * @param payload - 安装时传入的额外数据\n * @returns 解析到的 Vue App 或 undefined\n */\nfunction resolveVueApp(\n engine: StoreEngineLike,\n context: StoreEnginePluginContextLike,\n payload?: unknown,\n): App | undefined {\n /* 将 payload 宽松转为可能包含 app 字段的对象 */\n const appPayload = payload as { app?: unknown; framework?: { app?: unknown } } | undefined\n /* 按优先级尝试多个来源获取 app */\n const app = appPayload?.app\n ?? appPayload?.framework?.app\n ?? engine.getApp?.()\n ?? context.framework?.app\n\n /* 使用类型守卫验证是否为 Vue App */\n return isVueApp(app) ? app : undefined\n}\n\n/**\n * 获取当前活跃的全局 Store API\n * @returns 全局 Store API 或 null(未初始化时)\n */\nexport function getGlobalStoreAPI(): GlobalStoreAPI | null {\n return getActiveStoreAPI()\n}\n\n/**\n * 创建 Store Engine 插件工厂函数\n * 这是 Vue 适配层的核心入口,将 core 层的 bridge 包装为 Vue 友好的插件\n *\n * @param options - 插件配置选项\n * @returns StoreEnginePlugin 插件实例\n */\nexport function createStoreEnginePlugin(options: StoreEnginePluginOptions = {}): StoreEnginePlugin {\n /* 解构配置选项,设置默认值 */\n const {\n debug = false, /* 是否开启调试日志 */\n dependencies = [], /* 依赖的插件列表 */\n name = 'store', /* 插件名称 */\n version = '1.0.0', /* 插件版本 */\n } = options\n\n /* 延迟创建的 bridge 实例引用 */\n let bridge: StoreEngineBridge | null = null\n\n /**\n * 创建 bridge 的工厂函数\n * 内部调用 core 层的 createStoreEngineBridge,并传入 Vue 特定的实现\n */\n const createBridge = (): StoreEngineBridge => {\n const activeBridge = createStoreEngineBridge<StoreRuntime>({\n name, /* 插件名称 */\n version, /* 插件版本 */\n debug, /* 调试模式 */\n\n /* 创建运行时:传入所有 Vue 相关配置 */\n createRuntime: () => createStoreRuntime({\n pinia: options.pinia, /* 可选的外部 Pinia 实例 */\n persist: options.persist, /* 是否启用持久化 */\n persistOptions: options.persistOptions, /* 持久化选项 */\n globalProperties: options.globalProperties, /* 是否挂载到全局属性 */\n provide: options.provide, /* 是否通过 provide 注入 */\n debug,\n }),\n\n /* 将运行时安装到 Vue App */\n attachToApp: (app, runtime) => installStoreRuntime(app as App, runtime),\n\n /* 从 Vue App 获取已安装的运行时 */\n getRuntimeFromApp: app => getInstalledStoreRuntime(app as App),\n\n /* Vue App 类型守卫 */\n isApp: isVueApp,\n\n /* Vue App 解析函数 */\n resolveApp: resolveVueApp,\n })\n\n bridge = activeBridge\n return activeBridge\n }\n\n /**\n * 获取 bridge 实例(懒创建)\n * 首次调用时自动创建\n */\n const getBridge = (): StoreEngineBridge => {\n return bridge ?? createBridge()\n }\n\n /* ── 返回插件对象 ── */\n return {\n name, /* 插件名称 */\n version, /* 插件版本 */\n dependencies, /* 插件依赖 */\n\n /**\n * 安装到引擎上下文(异步)\n * 通过 bridge 将 store 能力注册到引擎\n */\n async install(context: StoreEnginePluginContextLike): Promise<void> {\n await getBridge().install(context)\n },\n\n /**\n * 安装到 Vue App\n * 将 store 运行时连接到 Vue 应用实例\n */\n installVue(app: App): void {\n getBridge().attachToApp(app)\n },\n\n /**\n * 从引擎上下文卸载(异步)\n * 清理 bridge 引用\n */\n async uninstall(context?: StoreEnginePluginContextLike): Promise<void> {\n await getBridge().uninstall(context)\n bridge = null /* 释放 bridge 引用,允许垃圾回收 */\n },\n }\n}\n\n/* 默认导出工厂函数 */\nexport default createStoreEnginePlugin\n"],"mappings":";;;;;;;;;;;;;AAiDA,SAAS,SAAS,OAA8B;CAC9C,OAAO,CAAC,CAAC,SAAS,OAAQ,MAAc,QAAQ;AAClD;AAWA,SAAS,cACP,QACA,SACA,SACiB;CAEjB,MAAM,aAAa;CAEnB,MAAM,MAAM,YAAY,OACnB,YAAY,WAAW,OACvB,OAAO,SAAS,KAChB,QAAQ,WAAW;CAGxB,OAAO,SAAS,GAAG,IAAI,MAAM,KAAA;AAC/B;AAMO,SAAS,oBAA2C;CACzD,OAAO,oBAAkB;AAC3B;AASO,SAAS,wBAAwB,UAAoC,CAAC,GAAsB;CAEjG,MAAM,EACJ,QAAQ,OACR,eAAe,CAAC,GAChB,OAAO,SACP,UAAU,YACR;CAGJ,IAAI,SAAmC;CAMvC,MAAM,qBAAwC;EAC5C,MAAM,eAAe,wBAAsC;GACzD;GACA;GACA;GAGA,qBAAqB,mBAAmB;IACtC,OAAO,QAAQ;IACf,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,kBAAkB,QAAQ;IAC1B,SAAS,QAAQ;IACjB;GACF,CAAC;GAGD,cAAc,KAAK,YAAY,oBAAoB,KAAY,OAAO;GAGtE,oBAAmB,QAAO,yBAAyB,GAAU;GAG7D,OAAO;GAGP,YAAY;EACd,CAAC;EAED,SAAS;EACT,OAAO;CACT;CAMA,MAAM,kBAAqC;EACzC,OAAO,UAAU,aAAa;CAChC;CAGA,OAAO;EACL;EACA;EACA;;;;;EAMA,MAAM,QAAQ,SAAsD;GAClE,MAAM,UAAU,CAAA,CAAE,QAAQ,OAAO;EACnC;;;;;EAMA,WAAW,KAAgB;GACzB,UAAU,CAAA,CAAE,YAAY,GAAG;EAC7B;;;;;EAMA,MAAM,UAAU,SAAuD;GACrE,MAAM,UAAU,CAAA,CAAE,UAAU,OAAO;GACnC,SAAS;EACX;CACF;AACF"}
@@ -0,0 +1,3 @@
1
+ export { cleanupEnhancedPersist, createEnhancedPersistPlugin, } from './pinia-plugin';
2
+ export type { EnhancedPersistOptions, EnhancedPersistPluginOptions, } from './pinia-plugin';
3
+ //# sourceMappingURL=enhanced-persist-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enhanced-persist-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/enhanced-persist-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,sBAAsB,EAEtB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAA;AAGvB,YAAY,EAEV,sBAAsB,EAEtB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,12 @@
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 { cleanupEnhancedPersist, createEnhancedPersistPlugin } from "./pinia-plugin.js";
11
+ export { cleanupEnhancedPersist, createEnhancedPersistPlugin };
12
+ /*! End of @composy/store-vue | Powered by @composy/builder */
@@ -0,0 +1,7 @@
1
+ export { createStoreEnginePlugin, getGlobalStoreAPI, } from './engine-plugin';
2
+ export { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin, createPersistPluginController, } from './pinia-plugin';
3
+ export type { EnhancedPersistOptions, EnhancedPersistPluginOptions, PersistPluginOptions, } from './pinia-plugin';
4
+ export { createRegistryMethods, createStoreRegistry, createStoreRegistryPlugin, getStoreRegistry, setGlobalStoreRegistry, } from './registry-plugin';
5
+ export { createStoreVuePlugin, } from './vue-plugin';
6
+ export type { StoreVuePluginOptions } from './vue-plugin';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,uBAAuB,EAEvB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAEL,sBAAsB,EAEtB,2BAA2B,EAE3B,mBAAmB,EAEnB,6BAA6B,GAC9B,MAAM,gBAAgB,CAAA;AAGvB,YAAY,EAEV,sBAAsB,EAEtB,4BAA4B,EAE5B,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAEL,qBAAqB,EAErB,mBAAmB,EAEnB,yBAAyB,EAEzB,gBAAgB,EAEhB,sBAAsB,GACvB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAEL,oBAAoB,GACrB,MAAM,cAAc,CAAA;AAGrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,15 @@
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 { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin, createPersistPluginController } from "./pinia-plugin.js";
11
+ import { createRegistryMethods, createStoreRegistry, createStoreRegistryPlugin, getStoreRegistry, setGlobalStoreRegistry } from "../runtime/store-registry.js";
12
+ import { createStoreEnginePlugin, getGlobalStoreAPI } from "./engine-plugin.js";
13
+ import { createStoreVuePlugin } from "./vue-plugin.js";
14
+ export { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin, createPersistPluginController, createRegistryMethods, createStoreEnginePlugin, createStoreRegistry, createStoreRegistryPlugin, createStoreVuePlugin, getGlobalStoreAPI, getStoreRegistry, setGlobalStoreRegistry };
15
+ /*! End of @composy/store-vue | Powered by @composy/builder */
@@ -0,0 +1,68 @@
1
+ import type { PiniaPlugin } from 'pinia';
2
+ import type { PersistOptions } from '../types';
3
+ type BrowserStorage = 'localStorage' | 'sessionStorage';
4
+ /**
5
+ * 持久化插件控制器接口
6
+ * @property plugin - Pinia 插件函数
7
+ * @property dispose - 清理函数,用于移除所有持久化订阅
8
+ */
9
+ interface PersistPluginController {
10
+ plugin: PiniaPlugin;
11
+ dispose: () => void;
12
+ }
13
+ /**
14
+ * 持久化插件全局配置选项
15
+ * @property storage - 默认存储类型
16
+ * @property keyPrefix - 存储键名前缀
17
+ * @property debounce - 防抖延迟(毫秒)
18
+ * @property debug - 是否开启调试日志
19
+ * @property syncTabs - 是否默认启用跨标签页同步
20
+ * @property defaultTTL - 默认过期时间(毫秒)
21
+ */
22
+ export interface PersistPluginOptions {
23
+ storage?: BrowserStorage;
24
+ keyPrefix?: string;
25
+ debounce?: number;
26
+ debug?: boolean;
27
+ syncTabs?: boolean;
28
+ defaultTTL?: number;
29
+ }
30
+ export interface EnhancedPersistPluginOptions extends PersistPluginOptions {
31
+ }
32
+ /**
33
+ * 增强版持久化选项(Store 级别配置)
34
+ * 在基础 PersistOptions 上增加 excludePaths、syncTabs、ttl
35
+ */
36
+ export interface EnhancedPersistOptions extends PersistOptions {
37
+ syncTabs?: boolean;
38
+ ttl?: number;
39
+ excludePaths?: string[];
40
+ }
41
+ /**
42
+ * 创建持久化插件控制器
43
+ * 返回一个 Pinia 插件函数和对应的 dispose 清理函数
44
+ *
45
+ * @param options - 插件全局配置
46
+ * @returns 控制器对象(包含 plugin 和 dispose)
47
+ */
48
+ export declare function createPersistPluginController(options?: PersistPluginOptions): PersistPluginController;
49
+ /**
50
+ * 创建基础版持久化插件
51
+ * @param options - 插件配置
52
+ * @returns Pinia 插件函数
53
+ */
54
+ export declare function createPersistPlugin(options?: PersistPluginOptions): PiniaPlugin;
55
+ /**
56
+ * 创建增强版持久化插件
57
+ * 与基础版功能相同,类型签名保留扩展空间
58
+ * @param options - 插件配置
59
+ * @returns Pinia 插件函数
60
+ */
61
+ export declare function createEnhancedPersistPlugin(options?: EnhancedPersistPluginOptions): PiniaPlugin;
62
+ /**
63
+ * 全局清理所有活跃的持久化控制器
64
+ * 通常在应用卸载或测试中调用
65
+ */
66
+ export declare function cleanupEnhancedPersist(): void;
67
+ export {};
68
+ //# sourceMappingURL=pinia-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinia-plugin.d.ts","sourceRoot":"","sources":["../../src/plugins/pinia-plugin.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAoC,MAAM,OAAO,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAQ9C,KAAK,cAAc,GAAG,cAAc,GAAG,gBAAgB,CAAA;AAkBvD;;;;GAIG;AACH,UAAU,uBAAuB;IAC/B,MAAM,EAAE,WAAW,CAAA;IACnB,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAGD,MAAM,WAAW,4BAA6B,SAAQ,oBAAoB;CAAG;AAE7E;;;GAGG;AACH,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CACxB;AAiHD;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,GAAE,oBAAyB,GACjC,uBAAuB,CAsNzB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,WAAW,CAEnF;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,4BAAiC,GACzC,WAAW,CAEb;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
@@ -0,0 +1,172 @@
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 { debounce, deepClone, deepMerge, deleteByPath, getByPath, setByPath } from "@composy/store-core";
11
+ //#region src/plugins/pinia-plugin.ts
12
+ const STORE_PERSIST_DISPOSE_KEY = /* @__PURE__ */ Symbol("ldesign-store-persist-dispose");
13
+ const activePersistControllers = /* @__PURE__ */ new Set();
14
+ function getStorage(type) {
15
+ if (typeof window === "undefined") return null;
16
+ return type === "localStorage" ? window.localStorage : window.sessionStorage;
17
+ }
18
+ function normalizePersistConfig(value) {
19
+ if (!value) return null;
20
+ return typeof value === "boolean" ? {} : value;
21
+ }
22
+ function filterState(state, includePaths, excludePaths) {
23
+ if (includePaths?.length) {
24
+ const pickedState = {};
25
+ includePaths.forEach((path) => {
26
+ const value = getByPath(state, path);
27
+ if (value !== void 0) setByPath(pickedState, path, deepClone(value));
28
+ });
29
+ return pickedState;
30
+ }
31
+ if (excludePaths?.length) {
32
+ const nextState = deepClone(state);
33
+ excludePaths.forEach((path) => {
34
+ deleteByPath(nextState, path);
35
+ });
36
+ return nextState;
37
+ }
38
+ return deepClone(state);
39
+ }
40
+ function restoreStoreState(store, nextState) {
41
+ store.$patch((state) => {
42
+ deepMerge(state, nextState);
43
+ });
44
+ }
45
+ function patchPersistDispose(store, cleanup) {
46
+ const restorePatchedDispose = store[STORE_PERSIST_DISPOSE_KEY];
47
+ if (restorePatchedDispose) restorePatchedDispose();
48
+ const originalDispose = store.$dispose;
49
+ store.$dispose = function patchedDispose() {
50
+ cleanup();
51
+ return originalDispose.call(this);
52
+ };
53
+ store[STORE_PERSIST_DISPOSE_KEY] = () => {
54
+ store.$dispose = originalDispose;
55
+ delete store[STORE_PERSIST_DISPOSE_KEY];
56
+ };
57
+ }
58
+ function createPersistPluginController(options = {}) {
59
+ const { storage: defaultStorage = "localStorage", keyPrefix = "ldesign-store:", debounce: debounceDelay = 100, debug = false, syncTabs: defaultSyncTabs = false, defaultTTL } = options;
60
+ const cleanupMap = /* @__PURE__ */ new Map();
61
+ const dispose = () => {
62
+ cleanupMap.forEach((cleanup) => cleanup());
63
+ cleanupMap.clear();
64
+ activePersistControllers.delete(dispose);
65
+ };
66
+ activePersistControllers.add(dispose);
67
+ const plugin = (context) => {
68
+ const { store, options: storeOptions } = context;
69
+ const config = normalizePersistConfig(storeOptions.persist);
70
+ if (!config) return;
71
+ const storage = getStorage(config.storage === "sessionStorage" ? "sessionStorage" : defaultStorage);
72
+ const serializer = config.serializer?.serialize ?? JSON.stringify;
73
+ const deserialize = config.serializer?.deserialize ?? JSON.parse;
74
+ const syncTabs = config.syncTabs ?? defaultSyncTabs;
75
+ const ttl = config.ttl ?? defaultTTL;
76
+ const key = `${keyPrefix}${config.key || store.$id}`;
77
+ if (!storage) {
78
+ if (debug) console.warn(`[PersistPlugin] Storage \u4E0D\u53EF\u7528 (${store.$id})`);
79
+ return;
80
+ }
81
+ let isRestoring = false;
82
+ const applyPersistedValue = (rawState) => {
83
+ const nextState = deserialize(rawState);
84
+ isRestoring = true;
85
+ try {
86
+ config.beforeRestore?.({ store });
87
+ restoreStoreState(store, nextState);
88
+ config.afterRestore?.({ store });
89
+ } finally {
90
+ isRestoring = false;
91
+ }
92
+ };
93
+ const restoreState = () => {
94
+ try {
95
+ const stored = storage.getItem(key);
96
+ if (!stored) return;
97
+ const storageItem = JSON.parse(stored);
98
+ if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) {
99
+ storage.removeItem(key);
100
+ return;
101
+ }
102
+ applyPersistedValue(storageItem.state);
103
+ if (debug) console.info(`[PersistPlugin] \u5DF2\u6062\u590D\u72B6\u6001 (${store.$id})`);
104
+ } catch (error) {
105
+ console.error(`[PersistPlugin] \u6062\u590D\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
106
+ }
107
+ };
108
+ const persistState = () => {
109
+ if (isRestoring) return;
110
+ try {
111
+ const filteredState = filterState(store.$state, config.paths, config.excludePaths);
112
+ const payload = {
113
+ state: serializer(filteredState),
114
+ timestamp: Date.now(),
115
+ expiresAt: ttl ? Date.now() + ttl : void 0,
116
+ version: 1
117
+ };
118
+ storage.setItem(key, JSON.stringify(payload));
119
+ if (debug) console.info(`[PersistPlugin] \u5DF2\u4FDD\u5B58\u72B6\u6001 (${store.$id})`);
120
+ } catch (error) {
121
+ console.error(`[PersistPlugin] \u4FDD\u5B58\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
122
+ }
123
+ };
124
+ const saveState = debounce(persistState, config.debounce ?? debounceDelay);
125
+ const stopSubscribe = store.$subscribe(() => {
126
+ if (!isRestoring) saveState();
127
+ });
128
+ let stopStorageSync = () => {};
129
+ if (syncTabs && typeof window !== "undefined") {
130
+ const handleStorage = (event) => {
131
+ if (event.key !== key || !event.newValue) return;
132
+ try {
133
+ const storageItem = JSON.parse(event.newValue);
134
+ if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) return;
135
+ applyPersistedValue(storageItem.state);
136
+ } catch (error) {
137
+ console.error(`[PersistPlugin] \u540C\u6B65\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
138
+ }
139
+ };
140
+ window.addEventListener("storage", handleStorage);
141
+ stopStorageSync = () => {
142
+ window.removeEventListener("storage", handleStorage);
143
+ };
144
+ }
145
+ const cleanup = () => {
146
+ saveState.cancel();
147
+ stopSubscribe();
148
+ stopStorageSync();
149
+ cleanupMap.delete(key);
150
+ };
151
+ cleanupMap.set(key, cleanup);
152
+ patchPersistDispose(store, cleanup);
153
+ restoreState();
154
+ };
155
+ return {
156
+ plugin,
157
+ dispose
158
+ };
159
+ }
160
+ function createPersistPlugin(options = {}) {
161
+ return createPersistPluginController(options).plugin;
162
+ }
163
+ function createEnhancedPersistPlugin(options = {}) {
164
+ return createPersistPluginController(options).plugin;
165
+ }
166
+ function cleanupEnhancedPersist() {
167
+ Array.from(activePersistControllers).forEach((dispose) => dispose());
168
+ }
169
+ //#endregion
170
+ export { cleanupEnhancedPersist, createEnhancedPersistPlugin, createPersistPlugin, createPersistPluginController };
171
+ /*! End of @composy/store-vue | Powered by @composy/builder */
172
+ //# sourceMappingURL=pinia-plugin.js.map