@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 @@
1
+ {"version":3,"file":"engine-plugin.cjs","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,sBAAA,kBAAkB;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,gBAAA,GAAA,2BAAA,wBAAA,CAAqD;GACzD;GACA;GACA;GAGA,qBAAqB,sBAAA,mBAAmB;IACtC,OAAO,QAAQ;IACf,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,kBAAkB,QAAQ;IAC1B,SAAS,QAAQ;IACjB;GACF,CAAC;GAGD,cAAc,KAAK,YAAY,0BAAA,oBAAoB,KAAY,OAAO;GAGtE,oBAAmB,QAAO,0BAAA,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,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,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
+ "use strict";
11
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
12
+ const require_pinia_plugin = require("./pinia-plugin.cjs");
13
+ exports.cleanupEnhancedPersist = require_pinia_plugin.cleanupEnhancedPersist;
14
+ exports.createEnhancedPersistPlugin = require_pinia_plugin.createEnhancedPersistPlugin;
15
+ /*! End of @composy/store-vue | Powered by @composy/builder */
@@ -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,28 @@
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_pinia_plugin = require("./pinia-plugin.cjs");
13
+ const require_store_registry = require("../runtime/store-registry.cjs");
14
+ const require_engine_plugin = require("./engine-plugin.cjs");
15
+ const require_vue_plugin = require("./vue-plugin.cjs");
16
+ exports.cleanupEnhancedPersist = require_pinia_plugin.cleanupEnhancedPersist;
17
+ exports.createEnhancedPersistPlugin = require_pinia_plugin.createEnhancedPersistPlugin;
18
+ exports.createPersistPlugin = require_pinia_plugin.createPersistPlugin;
19
+ exports.createPersistPluginController = require_pinia_plugin.createPersistPluginController;
20
+ exports.createRegistryMethods = require_store_registry.createRegistryMethods;
21
+ exports.createStoreEnginePlugin = require_engine_plugin.createStoreEnginePlugin;
22
+ exports.createStoreRegistry = require_store_registry.createStoreRegistry;
23
+ exports.createStoreRegistryPlugin = require_store_registry.createStoreRegistryPlugin;
24
+ exports.createStoreVuePlugin = require_vue_plugin.createStoreVuePlugin;
25
+ exports.getGlobalStoreAPI = require_engine_plugin.getGlobalStoreAPI;
26
+ exports.getStoreRegistry = require_store_registry.getStoreRegistry;
27
+ exports.setGlobalStoreRegistry = require_store_registry.setGlobalStoreRegistry;
28
+ /*! 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,177 @@
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 _composy_store_core = require("@composy/store-core");
13
+ //#region src/plugins/pinia-plugin.ts
14
+ const STORE_PERSIST_DISPOSE_KEY = /* @__PURE__ */ Symbol("ldesign-store-persist-dispose");
15
+ const activePersistControllers = /* @__PURE__ */ new Set();
16
+ function getStorage(type) {
17
+ if (typeof window === "undefined") return null;
18
+ return type === "localStorage" ? window.localStorage : window.sessionStorage;
19
+ }
20
+ function normalizePersistConfig(value) {
21
+ if (!value) return null;
22
+ return typeof value === "boolean" ? {} : value;
23
+ }
24
+ function filterState(state, includePaths, excludePaths) {
25
+ if (includePaths?.length) {
26
+ const pickedState = {};
27
+ includePaths.forEach((path) => {
28
+ const value = (0, _composy_store_core.getByPath)(state, path);
29
+ if (value !== void 0) (0, _composy_store_core.setByPath)(pickedState, path, (0, _composy_store_core.deepClone)(value));
30
+ });
31
+ return pickedState;
32
+ }
33
+ if (excludePaths?.length) {
34
+ const nextState = (0, _composy_store_core.deepClone)(state);
35
+ excludePaths.forEach((path) => {
36
+ (0, _composy_store_core.deleteByPath)(nextState, path);
37
+ });
38
+ return nextState;
39
+ }
40
+ return (0, _composy_store_core.deepClone)(state);
41
+ }
42
+ function restoreStoreState(store, nextState) {
43
+ store.$patch((state) => {
44
+ (0, _composy_store_core.deepMerge)(state, nextState);
45
+ });
46
+ }
47
+ function patchPersistDispose(store, cleanup) {
48
+ const restorePatchedDispose = store[STORE_PERSIST_DISPOSE_KEY];
49
+ if (restorePatchedDispose) restorePatchedDispose();
50
+ const originalDispose = store.$dispose;
51
+ store.$dispose = function patchedDispose() {
52
+ cleanup();
53
+ return originalDispose.call(this);
54
+ };
55
+ store[STORE_PERSIST_DISPOSE_KEY] = () => {
56
+ store.$dispose = originalDispose;
57
+ delete store[STORE_PERSIST_DISPOSE_KEY];
58
+ };
59
+ }
60
+ function createPersistPluginController(options = {}) {
61
+ const { storage: defaultStorage = "localStorage", keyPrefix = "ldesign-store:", debounce: debounceDelay = 100, debug = false, syncTabs: defaultSyncTabs = false, defaultTTL } = options;
62
+ const cleanupMap = /* @__PURE__ */ new Map();
63
+ const dispose = () => {
64
+ cleanupMap.forEach((cleanup) => cleanup());
65
+ cleanupMap.clear();
66
+ activePersistControllers.delete(dispose);
67
+ };
68
+ activePersistControllers.add(dispose);
69
+ const plugin = (context) => {
70
+ const { store, options: storeOptions } = context;
71
+ const config = normalizePersistConfig(storeOptions.persist);
72
+ if (!config) return;
73
+ const storage = getStorage(config.storage === "sessionStorage" ? "sessionStorage" : defaultStorage);
74
+ const serializer = config.serializer?.serialize ?? JSON.stringify;
75
+ const deserialize = config.serializer?.deserialize ?? JSON.parse;
76
+ const syncTabs = config.syncTabs ?? defaultSyncTabs;
77
+ const ttl = config.ttl ?? defaultTTL;
78
+ const key = `${keyPrefix}${config.key || store.$id}`;
79
+ if (!storage) {
80
+ if (debug) console.warn(`[PersistPlugin] Storage \u4E0D\u53EF\u7528 (${store.$id})`);
81
+ return;
82
+ }
83
+ let isRestoring = false;
84
+ const applyPersistedValue = (rawState) => {
85
+ const nextState = deserialize(rawState);
86
+ isRestoring = true;
87
+ try {
88
+ config.beforeRestore?.({ store });
89
+ restoreStoreState(store, nextState);
90
+ config.afterRestore?.({ store });
91
+ } finally {
92
+ isRestoring = false;
93
+ }
94
+ };
95
+ const restoreState = () => {
96
+ try {
97
+ const stored = storage.getItem(key);
98
+ if (!stored) return;
99
+ const storageItem = JSON.parse(stored);
100
+ if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) {
101
+ storage.removeItem(key);
102
+ return;
103
+ }
104
+ applyPersistedValue(storageItem.state);
105
+ if (debug) console.info(`[PersistPlugin] \u5DF2\u6062\u590D\u72B6\u6001 (${store.$id})`);
106
+ } catch (error) {
107
+ console.error(`[PersistPlugin] \u6062\u590D\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
108
+ }
109
+ };
110
+ const persistState = () => {
111
+ if (isRestoring) return;
112
+ try {
113
+ const filteredState = filterState(store.$state, config.paths, config.excludePaths);
114
+ const payload = {
115
+ state: serializer(filteredState),
116
+ timestamp: Date.now(),
117
+ expiresAt: ttl ? Date.now() + ttl : void 0,
118
+ version: 1
119
+ };
120
+ storage.setItem(key, JSON.stringify(payload));
121
+ if (debug) console.info(`[PersistPlugin] \u5DF2\u4FDD\u5B58\u72B6\u6001 (${store.$id})`);
122
+ } catch (error) {
123
+ console.error(`[PersistPlugin] \u4FDD\u5B58\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
124
+ }
125
+ };
126
+ const saveState = (0, _composy_store_core.debounce)(persistState, config.debounce ?? debounceDelay);
127
+ const stopSubscribe = store.$subscribe(() => {
128
+ if (!isRestoring) saveState();
129
+ });
130
+ let stopStorageSync = () => {};
131
+ if (syncTabs && typeof window !== "undefined") {
132
+ const handleStorage = (event) => {
133
+ if (event.key !== key || !event.newValue) return;
134
+ try {
135
+ const storageItem = JSON.parse(event.newValue);
136
+ if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) return;
137
+ applyPersistedValue(storageItem.state);
138
+ } catch (error) {
139
+ console.error(`[PersistPlugin] \u540C\u6B65\u72B6\u6001\u5931\u8D25 (${store.$id}):`, error);
140
+ }
141
+ };
142
+ window.addEventListener("storage", handleStorage);
143
+ stopStorageSync = () => {
144
+ window.removeEventListener("storage", handleStorage);
145
+ };
146
+ }
147
+ const cleanup = () => {
148
+ saveState.cancel();
149
+ stopSubscribe();
150
+ stopStorageSync();
151
+ cleanupMap.delete(key);
152
+ };
153
+ cleanupMap.set(key, cleanup);
154
+ patchPersistDispose(store, cleanup);
155
+ restoreState();
156
+ };
157
+ return {
158
+ plugin,
159
+ dispose
160
+ };
161
+ }
162
+ function createPersistPlugin(options = {}) {
163
+ return createPersistPluginController(options).plugin;
164
+ }
165
+ function createEnhancedPersistPlugin(options = {}) {
166
+ return createPersistPluginController(options).plugin;
167
+ }
168
+ function cleanupEnhancedPersist() {
169
+ Array.from(activePersistControllers).forEach((dispose) => dispose());
170
+ }
171
+ //#endregion
172
+ exports.cleanupEnhancedPersist = cleanupEnhancedPersist;
173
+ exports.createEnhancedPersistPlugin = createEnhancedPersistPlugin;
174
+ exports.createPersistPlugin = createPersistPlugin;
175
+ exports.createPersistPluginController = createPersistPluginController;
176
+ /*! End of @composy/store-vue | Powered by @composy/builder */
177
+ //# sourceMappingURL=pinia-plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pinia-plugin.cjs","names":[],"sources":["../../src/plugins/pinia-plugin.ts"],"sourcesContent":["/* ============================================================\n * pinia-plugin.ts\n * Pinia 持久化插件\n * 提供将 Pinia Store 状态自动持久化到浏览器存储的能力\n * 支持 TTL 过期、跨标签页同步、include/exclude 路径过滤、\n * 防抖保存、$dispose 生命周期钩子等特性\n * ============================================================ */\n\n/* 从 Pinia 导入插件相关类型 */\nimport type { PiniaPlugin, PiniaPluginContext, StoreGeneric } from 'pinia'\n/* 从本地类型文件导入持久化选项 */\nimport type { PersistOptions } from '../types'\n/* 从 store-core 导入工具函数 */\nimport { debounce, deepClone, deepMerge, deleteByPath, getByPath, setByPath } from '@composy/store-core'\n\n/* 用于标记 store 的 $dispose 是否已被 patch 的 Symbol 键 */\nconst STORE_PERSIST_DISPOSE_KEY = Symbol('ldesign-store-persist-dispose')\n\n/* 浏览器存储类型 */\ntype BrowserStorage = 'localStorage' | 'sessionStorage'\n\n/* 可被 patch $dispose 的 Store 扩展类型 */\ntype DisposableStore = StoreGeneric & {\n [STORE_PERSIST_DISPOSE_KEY]?: () => void /* 恢复原始 $dispose 的函数 */\n}\n\n/**\n * 持久化存储项的内部格式接口\n * 包含序列化的状态、时间戳、过期时间和版本号\n */\ninterface PersistedStorageItem {\n state: string /* 序列化后的状态字符串 */\n timestamp: number /* 保存时间戳 */\n expiresAt?: number /* 过期时间戳(可选) */\n version: number /* 数据格式版本号 */\n}\n\n/**\n * 持久化插件控制器接口\n * @property plugin - Pinia 插件函数\n * @property dispose - 清理函数,用于移除所有持久化订阅\n */\ninterface PersistPluginController {\n plugin: PiniaPlugin\n dispose: () => void\n}\n\n/**\n * 持久化插件全局配置选项\n * @property storage - 默认存储类型\n * @property keyPrefix - 存储键名前缀\n * @property debounce - 防抖延迟(毫秒)\n * @property debug - 是否开启调试日志\n * @property syncTabs - 是否默认启用跨标签页同步\n * @property defaultTTL - 默认过期时间(毫秒)\n */\nexport interface PersistPluginOptions {\n storage?: BrowserStorage\n keyPrefix?: string\n debounce?: number\n debug?: boolean\n syncTabs?: boolean\n defaultTTL?: number\n}\n\n/* 增强版持久化插件选项(与基础版相同,预留扩展) */\nexport interface EnhancedPersistPluginOptions extends PersistPluginOptions {}\n\n/**\n * 增强版持久化选项(Store 级别配置)\n * 在基础 PersistOptions 上增加 excludePaths、syncTabs、ttl\n */\nexport interface EnhancedPersistOptions extends PersistOptions {\n syncTabs?: boolean\n ttl?: number\n excludePaths?: string[]\n}\n\n/* 活跃的持久化控制器集合,用于全局清理 */\nconst activePersistControllers = new Set<() => void>()\n\n/**\n * 获取浏览器存储对象\n * 在 SSR 环境下返回 null\n */\nfunction getStorage(type: BrowserStorage): Storage | null {\n if (typeof window === 'undefined') {\n return null\n }\n\n return type === 'localStorage' ? window.localStorage : window.sessionStorage\n}\n\n/**\n * 规范化 Store 的 persist 配置\n * 将 boolean/对象/undefined 统一为 EnhancedPersistOptions | null\n */\nfunction normalizePersistConfig(\n value: boolean | PersistOptions | EnhancedPersistOptions | undefined,\n): EnhancedPersistOptions | null {\n if (!value) {\n return null /* 未配置持久化 */\n }\n\n /* boolean true 表示使用默认配置的空对象 */\n return typeof value === 'boolean' ? {} : value\n}\n\n/**\n * 根据 include/exclude 路径过滤状态\n * 优先使用 includePaths(白名单),其次使用 excludePaths(黑名单)\n *\n * @param state - 完整状态对象\n * @param includePaths - 包含路径列表(白名单模式)\n * @param excludePaths - 排除路径列表(黑名单模式)\n * @returns 过滤后的状态对象\n */\nfunction filterState(\n state: Record<string, unknown>,\n includePaths?: string[],\n excludePaths?: string[],\n): Record<string, unknown> {\n /* 白名单模式:只保留指定路径 */\n if (includePaths?.length) {\n const pickedState: Record<string, unknown> = {}\n includePaths.forEach((path) => {\n const value = getByPath(state, path)\n if (value !== undefined) {\n setByPath(pickedState, path, deepClone(value))\n }\n })\n return pickedState\n }\n\n /* 黑名单模式:排除指定路径 */\n if (excludePaths?.length) {\n const nextState = deepClone(state)\n excludePaths.forEach((path) => {\n deleteByPath(nextState, path)\n })\n return nextState\n }\n\n /* 无过滤:返回状态的深拷贝 */\n return deepClone(state)\n}\n\n/**\n * 将持久化的状态恢复到 Store\n * 使用 $patch + deepMerge 避免覆盖整个 state 引用\n */\nfunction restoreStoreState(\n store: StoreGeneric,\n nextState: Record<string, unknown>,\n): void {\n store.$patch((state) => {\n deepMerge(state as Record<string, unknown>, nextState)\n })\n}\n\n/**\n * 为 Store 的 $dispose 方法打补丁\n * 在 Store 被销毁时自动执行清理逻辑(取消订阅、移除事件监听等)\n *\n * @param store - 目标 Store\n * @param cleanup - 清理回调函数\n */\nfunction patchPersistDispose(store: DisposableStore, cleanup: () => void): void {\n /* 如果之前已有补丁,先恢复原始方法 */\n const restorePatchedDispose = store[STORE_PERSIST_DISPOSE_KEY]\n if (restorePatchedDispose) {\n restorePatchedDispose()\n }\n\n /* 保存原始 $dispose 方法 */\n const originalDispose = store.$dispose\n /* 替换为带清理逻辑的版本 */\n store.$dispose = function patchedDispose() {\n cleanup() /* 先执行清理 */\n return originalDispose.call(this) /* 再调用原始 dispose */\n }\n\n /* 保存恢复函数,供后续补丁使用 */\n store[STORE_PERSIST_DISPOSE_KEY] = () => {\n store.$dispose = originalDispose\n delete store[STORE_PERSIST_DISPOSE_KEY]\n }\n}\n\n/**\n * 创建持久化插件控制器\n * 返回一个 Pinia 插件函数和对应的 dispose 清理函数\n *\n * @param options - 插件全局配置\n * @returns 控制器对象(包含 plugin 和 dispose)\n */\nexport function createPersistPluginController(\n options: PersistPluginOptions = {},\n): PersistPluginController {\n /* 解构配置选项,设置默认值 */\n const {\n storage: defaultStorage = 'localStorage', /* 默认存储类型 */\n keyPrefix = 'ldesign-store:', /* 存储键前缀 */\n debounce: debounceDelay = 100, /* 默认 100ms 防抖 */\n debug = false, /* 调试模式 */\n syncTabs: defaultSyncTabs = false, /* 默认不跨标签页同步 */\n defaultTTL, /* 默认 TTL */\n } = options\n\n /* 清理函数映射表(key → cleanup) */\n const cleanupMap = new Map<string, () => void>()\n\n /**\n * 全局 dispose 函数\n * 清理所有 Store 的持久化订阅\n */\n const dispose = (): void => {\n cleanupMap.forEach(cleanup => cleanup())\n cleanupMap.clear()\n activePersistControllers.delete(dispose)\n }\n\n /* 注册到活跃控制器集合 */\n activePersistControllers.add(dispose)\n\n /**\n * Pinia 插件函数\n * 每当创建/使用一个 Pinia Store 时自动调用\n */\n const plugin: PiniaPlugin = (context: PiniaPluginContext): void => {\n const { store, options: storeOptions } = context\n /* 规范化该 Store 的持久化配置 */\n const config = normalizePersistConfig(\n (storeOptions as { persist?: boolean | PersistOptions | EnhancedPersistOptions }).persist,\n )\n\n /* 该 Store 未配置持久化则跳过 */\n if (!config) {\n return\n }\n\n /* 解析该 Store 的存储配置(Store 级别配置优先于全局配置) */\n const storageType = config.storage === 'sessionStorage' ? 'sessionStorage' : defaultStorage\n const storage = getStorage(storageType)\n const serializer = config.serializer?.serialize ?? JSON.stringify /* 序列化函数 */\n const deserialize = config.serializer?.deserialize ?? JSON.parse /* 反序列化函数 */\n const syncTabs = config.syncTabs ?? defaultSyncTabs /* 跨标签页同步 */\n const ttl = config.ttl ?? defaultTTL /* 过期时间 */\n const key = `${keyPrefix}${config.key || store.$id}` /* 存储键名 */\n\n /* 存储不可用则跳过 */\n if (!storage) {\n if (debug) {\n console.warn(`[PersistPlugin] Storage 不可用 (${store.$id})`)\n }\n return\n }\n\n /* 标记:是否正在从存储恢复状态(防止恢复过程中触发保存) */\n let isRestoring = false\n\n /**\n * 将持久化的原始状态字符串应用到 Store\n * 反序列化 → beforeRestore 钩子 → 恢复状态 → afterRestore 钩子\n */\n const applyPersistedValue = (rawState: string): void => {\n const nextState = deserialize(rawState) as Record<string, unknown>\n isRestoring = true /* 标记恢复中 */\n try {\n config.beforeRestore?.({ store }) /* 恢复前钩子 */\n restoreStoreState(store, nextState) /* 恢复状态 */\n config.afterRestore?.({ store }) /* 恢复后钩子 */\n }\n finally {\n isRestoring = false /* 恢复结束 */\n }\n }\n\n /**\n * 从存储恢复 Store 状态\n * 检查过期 → 反序列化 → 应用到 Store\n */\n const restoreState = (): void => {\n try {\n const stored = storage.getItem(key)\n if (!stored) {\n return /* 无持久化数据 */\n }\n\n const storageItem = JSON.parse(stored) as PersistedStorageItem\n /* 检查是否过期 */\n if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) {\n storage.removeItem(key) /* 过期则清除 */\n return\n }\n\n /* 应用持久化值 */\n applyPersistedValue(storageItem.state)\n\n if (debug) {\n console.info(`[PersistPlugin] 已恢复状态 (${store.$id})`)\n }\n }\n catch (error) {\n console.error(`[PersistPlugin] 恢复状态失败 (${store.$id}):`, error)\n }\n }\n\n /**\n * 将当前 Store 状态持久化到存储\n * 过滤状态 → 序列化 → 包装为存储项 → 写入存储\n */\n const persistState = (): void => {\n /* 正在恢复时跳过保存,避免循环 */\n if (isRestoring) {\n return\n }\n\n try {\n /* 根据 include/exclude 路径过滤状态 */\n const filteredState = filterState(\n store.$state as Record<string, unknown>,\n config.paths,\n config.excludePaths,\n )\n\n /* 构建存储项 */\n const payload: PersistedStorageItem = {\n state: serializer(filteredState), /* 序列化过滤后的状态 */\n timestamp: Date.now(), /* 保存时间 */\n expiresAt: ttl ? Date.now() + ttl : undefined, /* 过期时间 */\n version: 1, /* 数据版本号 */\n }\n\n /* 写入存储 */\n storage.setItem(key, JSON.stringify(payload))\n\n if (debug) {\n console.info(`[PersistPlugin] 已保存状态 (${store.$id})`)\n }\n }\n catch (error) {\n console.error(`[PersistPlugin] 保存状态失败 (${store.$id}):`, error)\n }\n }\n\n /* 创建防抖版的保存函数 */\n const saveState = debounce(persistState, config.debounce ?? debounceDelay)\n\n /* 订阅 Store 状态变化,自动触发保存 */\n const stopSubscribe = store.$subscribe(() => {\n /* 恢复中不保存 */\n if (!isRestoring) {\n saveState()\n }\n })\n\n /* ── 跨标签页同步 ── */\n let stopStorageSync = (): void => {} /* 清理函数占位 */\n if (syncTabs && typeof window !== 'undefined') {\n /* 监听 storage 事件,同步其他标签页的状态变化 */\n const handleStorage = (event: StorageEvent): void => {\n /* 只关注目标 key 且有新值 */\n if (event.key !== key || !event.newValue) {\n return\n }\n\n try {\n const storageItem = JSON.parse(event.newValue) as PersistedStorageItem\n /* 跳过过期数据 */\n if (storageItem.expiresAt && Date.now() > storageItem.expiresAt) {\n return\n }\n\n /* 应用其他标签页的状态 */\n applyPersistedValue(storageItem.state)\n }\n catch (error) {\n console.error(`[PersistPlugin] 同步状态失败 (${store.$id}):`, error)\n }\n }\n\n window.addEventListener('storage', handleStorage)\n /* 保存清理函数 */\n stopStorageSync = () => {\n window.removeEventListener('storage', handleStorage)\n }\n }\n\n /**\n * 该 Store 的清理函数\n * 取消防抖、停止订阅、移除事件监听\n */\n const cleanup = (): void => {\n saveState.cancel() /* 取消待执行的防抖保存 */\n stopSubscribe() /* 取消状态订阅 */\n stopStorageSync() /* 移除跨标签页同步监听 */\n cleanupMap.delete(key) /* 从清理映射中移除 */\n }\n\n /* 注册清理函数 */\n cleanupMap.set(key, cleanup)\n /* 为 Store 的 $dispose 打补丁,确保销毁时自动清理 */\n patchPersistDispose(store as DisposableStore, cleanup)\n /* 立即尝试从存储恢复状态 */\n restoreState()\n }\n\n return {\n plugin, /* Pinia 插件函数 */\n dispose, /* 全局清理函数 */\n }\n}\n\n/**\n * 创建基础版持久化插件\n * @param options - 插件配置\n * @returns Pinia 插件函数\n */\nexport function createPersistPlugin(options: PersistPluginOptions = {}): PiniaPlugin {\n return createPersistPluginController(options).plugin\n}\n\n/**\n * 创建增强版持久化插件\n * 与基础版功能相同,类型签名保留扩展空间\n * @param options - 插件配置\n * @returns Pinia 插件函数\n */\nexport function createEnhancedPersistPlugin(\n options: EnhancedPersistPluginOptions = {},\n): PiniaPlugin {\n return createPersistPluginController(options).plugin\n}\n\n/**\n * 全局清理所有活跃的持久化控制器\n * 通常在应用卸载或测试中调用\n */\nexport function cleanupEnhancedPersist(): void {\n Array.from(activePersistControllers).forEach(dispose => dispose())\n}\n"],"mappings":"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"}
@@ -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,18 @@
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_store_registry = require("../runtime/store-registry.cjs");
13
+ exports.createRegistryMethods = require_store_registry.createRegistryMethods;
14
+ exports.createStoreRegistry = require_store_registry.createStoreRegistry;
15
+ exports.createStoreRegistryPlugin = require_store_registry.createStoreRegistryPlugin;
16
+ exports.getStoreRegistry = require_store_registry.getStoreRegistry;
17
+ exports.setGlobalStoreRegistry = require_store_registry.setGlobalStoreRegistry;
18
+ /*! End of @composy/store-vue | Powered by @composy/builder */
@@ -0,0 +1,2 @@
1
+ export { createRegistryMethods, createStoreRegistry, createStoreRegistryPlugin, getStoreRegistry, setGlobalStoreRegistry, } from '../runtime/store-registry';
2
+ //# sourceMappingURL=registry-plugin.d.ts.map
@@ -0,0 +1,26 @@
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_store_runtime = require("../runtime/store-runtime.cjs");
13
+ const require_install_store_app = require("../runtime/install-store-app.cjs");
14
+ //#region src/plugins/vue-plugin.ts
15
+ function createStoreVuePlugin(options = {}) {
16
+ return { install(app) {
17
+ const runtime = require_store_runtime.createStoreRuntime(options);
18
+ const installedRuntime = require_install_store_app.installStoreRuntime(app, runtime);
19
+ if (installedRuntime !== runtime) runtime.dispose();
20
+ if (installedRuntime.options.debug) console.info("[StoreVuePlugin] installed");
21
+ } };
22
+ }
23
+ //#endregion
24
+ exports.createStoreVuePlugin = createStoreVuePlugin;
25
+ /*! End of @composy/store-vue | Powered by @composy/builder */
26
+ //# sourceMappingURL=vue-plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue-plugin.cjs","names":[],"sources":["../../src/plugins/vue-plugin.ts"],"sourcesContent":["// 从 vue 导入 App 和 Plugin 类型\nimport type { App, Plugin } from 'vue'\n// 导入 store Vue 插件选项类型\nimport type { StoreVuePluginOptions } from '../runtime/store-plugin-options'\n// 导入安装 store 运行时的函数\nimport { installStoreRuntime } from '../runtime/install-store-app'\n// 导入创建 store 运行时的函数\nimport { createStoreRuntime } from '../runtime/store-runtime'\n\n// 重新导出 store Vue 插件选项类型\nexport type { StoreVuePluginOptions } from '../runtime/store-plugin-options'\n\n/**\n * 创建 store Vue 插件\n * @param options - store Vue 插件配置选项\n * @returns 返回 Vue Plugin 对象,可通过 app.use() 安装\n */\nexport function createStoreVuePlugin(options: StoreVuePluginOptions = {}): Plugin {\n return {\n // 安装插件到 Vue 应用\n install(app: App): void {\n // 创建 store 运行时实例\n const runtime = createStoreRuntime(options)\n // 将运行时安装到 Vue 应用,如果已安装则返回已有的运行时\n const installedRuntime = installStoreRuntime(app, runtime)\n\n // 如果安装的运行时不是新创建的,则销毁新建的运行时以避免内存泄漏\n if (installedRuntime !== runtime) {\n runtime.dispose()\n }\n\n // 如果开启了调试模式,输出安装成功日志\n if (installedRuntime.options.debug) {\n console.info('[StoreVuePlugin] installed')\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBO,SAAS,qBAAqB,UAAiC,CAAC,GAAW;CAChF,OAAO,EAEL,QAAQ,KAAgB;EAEtB,MAAM,UAAU,sBAAA,mBAAmB,OAAO;EAE1C,MAAM,mBAAmB,0BAAA,oBAAoB,KAAK,OAAO;EAGzD,IAAI,qBAAqB,SACvB,QAAQ,QAAQ;EAIlB,IAAI,iBAAiB,QAAQ,OAC3B,QAAQ,KAAK,4BAA4B;CAE7C,EACF;AACF"}
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'vue';
2
+ import type { StoreVuePluginOptions } from '../runtime/store-plugin-options';
3
+ export type { StoreVuePluginOptions } from '../runtime/store-plugin-options';
4
+ /**
5
+ * 创建 store Vue 插件
6
+ * @param options - store Vue 插件配置选项
7
+ * @returns 返回 Vue Plugin 对象,可通过 app.use() 安装
8
+ */
9
+ export declare function createStoreVuePlugin(options?: StoreVuePluginOptions): Plugin;
10
+ //# sourceMappingURL=vue-plugin.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
+ const require_injection_keys = require("../context/injection-keys.cjs");
13
+ const require_store_runtime = require("./store-runtime.cjs");
14
+ //#region src/runtime/install-store-app.ts
15
+ const STORE_APP_RUNTIME_KEY = /* @__PURE__ */ Symbol("ldesign-store-app-runtime");
16
+ function isPiniaInstalled(app, runtime) {
17
+ return app.config.globalProperties.$pinia === runtime.pinia;
18
+ }
19
+ function patchUnmount(app, runtime) {
20
+ const originalUnmount = app.unmount;
21
+ app.unmount = function patchedUnmount() {
22
+ if (app[STORE_APP_RUNTIME_KEY] === runtime) {
23
+ delete app[STORE_APP_RUNTIME_KEY];
24
+ runtime.dispose();
25
+ }
26
+ return originalUnmount.call(this);
27
+ };
28
+ }
29
+ function getInstalledStoreRuntime(app) {
30
+ return app[STORE_APP_RUNTIME_KEY];
31
+ }
32
+ function installStoreRuntime(app, runtime) {
33
+ const storeApp = app;
34
+ const installedRuntime = storeApp[STORE_APP_RUNTIME_KEY];
35
+ if (installedRuntime) {
36
+ require_store_runtime.setGlobalStoreRuntime(installedRuntime);
37
+ return installedRuntime;
38
+ }
39
+ if (!isPiniaInstalled(app, runtime)) app.use(runtime.pinia);
40
+ storeApp[STORE_APP_RUNTIME_KEY] = runtime;
41
+ if (runtime.options.provide) {
42
+ app.provide(require_injection_keys.STORE_RUNTIME_SYMBOL, runtime);
43
+ app.provide(require_injection_keys.STORE_API_SYMBOL, runtime.storeAPI);
44
+ app.provide(require_injection_keys.STORE_PINIA_SYMBOL, runtime.pinia);
45
+ app.provide("store", runtime.storeAPI);
46
+ app.provide("pinia", runtime.pinia);
47
+ }
48
+ if (runtime.options.globalProperties) app.config.globalProperties.$store = runtime.storeAPI;
49
+ patchUnmount(storeApp, runtime);
50
+ require_store_runtime.setGlobalStoreRuntime(runtime);
51
+ return runtime;
52
+ }
53
+ //#endregion
54
+ exports.getInstalledStoreRuntime = getInstalledStoreRuntime;
55
+ exports.installStoreRuntime = installStoreRuntime;
56
+ /*! End of @composy/store-vue | Powered by @composy/builder */
57
+ //# sourceMappingURL=install-store-app.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-store-app.cjs","names":[],"sources":["../../src/runtime/install-store-app.ts"],"sourcesContent":["/* ============================================================\n * install-store-app.ts\n * Store 运行时安装到 Vue App 的模块\n * 负责将 StoreRuntime 安装到 Vue 应用实例,管理 Pinia 注入、\n * provide/globalProperties 注入和 unmount 生命周期清理\n * ============================================================ */\n\n/* Vue App 类型 */\nimport type { App } from 'vue'\n/* Store 运行时类型 */\nimport type { StoreRuntime } from './store-runtime'\n/* 从注入键模块导入 Symbol 常量 */\nimport {\n STORE_API_SYMBOL, /* Store API 的注入键 */\n STORE_PINIA_SYMBOL, /* Pinia 实例的注入键 */\n STORE_RUNTIME_SYMBOL, /* 运行时的注入键 */\n} from '../context/injection-keys'\n/* 导入全局运行时设置函数 */\nimport { setGlobalStoreRuntime } from './store-runtime'\n\n/* 用于标记 App 上已安装的运行时的 Symbol 键 */\nconst STORE_APP_RUNTIME_KEY = Symbol('ldesign-store-app-runtime')\n\n/* 扩展 Vue App 类型,添加运行时引用 */\ntype StoreApp = App & {\n [STORE_APP_RUNTIME_KEY]?: StoreRuntime\n}\n\n/**\n * 检查 Pinia 是否已安装到 Vue App\n * 通过比较 app.config.globalProperties.$pinia 与 runtime 的 pinia 实例\n *\n * @param app - Vue 应用实例\n * @param runtime - Store 运行时\n * @returns Pinia 是否已安装\n */\nfunction isPiniaInstalled(app: App, runtime: StoreRuntime): boolean {\n return app.config.globalProperties.$pinia === runtime.pinia\n}\n\n/**\n * 为 Vue App 的 unmount 方法打补丁\n * 在应用卸载时自动清理 Store 运行时(dispose)\n * 确保资源不会泄漏\n *\n * @param app - Vue 应用实例\n * @param runtime - Store 运行时\n */\nfunction patchUnmount(app: StoreApp, runtime: StoreRuntime): void {\n /* 保存原始 unmount 方法 */\n const originalUnmount = app.unmount\n\n /* 替换为带清理逻辑的版本 */\n app.unmount = function patchedUnmount() {\n /* 检查当前运行时是否仍是这个 runtime(防止被后续安装覆盖) */\n const activeRuntime = app[STORE_APP_RUNTIME_KEY]\n if (activeRuntime === runtime) {\n /* 清除 App 上的运行时引用 */\n delete app[STORE_APP_RUNTIME_KEY]\n /* 执行运行时的 dispose(清理持久化、注册表等) */\n runtime.dispose()\n }\n\n /* 调用原始 unmount 方法 */\n return originalUnmount.call(this)\n }\n}\n\n/**\n * 获取 Vue App 上已安装的 Store 运行时\n * @param app - Vue 应用实例\n * @returns 已安装的运行时或 undefined\n */\nexport function getInstalledStoreRuntime(app: App): StoreRuntime | undefined {\n return (app as StoreApp)[STORE_APP_RUNTIME_KEY]\n}\n\n/**\n * 将 Store 运行时安装到 Vue App\n * 这是 Vue 适配层的核心安装入口,负责:\n * 1. 安装 Pinia 插件\n * 2. 通过 provide 注入 Store 能力\n * 3. 挂载到 globalProperties\n * 4. 打 unmount 补丁进行生命周期管理\n * 5. 设置全局运行时引用\n *\n * @param app - Vue 应用实例\n * @param runtime - Store 运行时实例\n * @returns 安装的运行时(如果已安装则返回已有的)\n */\nexport function installStoreRuntime(\n app: App,\n runtime: StoreRuntime,\n): StoreRuntime {\n const storeApp = app as StoreApp\n /* 检查是否已安装(幂等性) */\n const installedRuntime = storeApp[STORE_APP_RUNTIME_KEY]\n\n if (installedRuntime) {\n /* 已安装则设置全局引用并返回已有的运行时 */\n setGlobalStoreRuntime(installedRuntime)\n return installedRuntime\n }\n\n /* 如果 Pinia 尚未安装,使用 app.use() 安装 */\n if (!isPiniaInstalled(app, runtime)) {\n app.use(runtime.pinia)\n }\n\n /* 在 App 上保存运行时引用(标记已安装) */\n storeApp[STORE_APP_RUNTIME_KEY] = runtime\n\n /* 如果配置了 provide 注入,通过 Vue 的 provide/inject 注入 Store 能力 */\n if (runtime.options.provide) {\n app.provide(STORE_RUNTIME_SYMBOL, runtime) /* 注入运行时 */\n app.provide(STORE_API_SYMBOL, runtime.storeAPI) /* 注入 Store API */\n app.provide(STORE_PINIA_SYMBOL, runtime.pinia) /* 注入 Pinia 实例 */\n app.provide('store', runtime.storeAPI) /* 简写键 'store' */\n app.provide('pinia', runtime.pinia) /* 简写键 'pinia' */\n }\n\n /* 如果配置了 globalProperties,挂载到全局属性上 */\n if (runtime.options.globalProperties) {\n app.config.globalProperties.$store = runtime.storeAPI\n }\n\n /* 打 unmount 补丁,确保卸载时自动清理 */\n patchUnmount(storeApp, runtime)\n /* 设置为全局运行时引用 */\n setGlobalStoreRuntime(runtime)\n\n return runtime\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,wBAAwB,uBAAO,2BAA2B;AAehE,SAAS,iBAAiB,KAAU,SAAgC;CAClE,OAAO,IAAI,OAAO,iBAAiB,WAAW,QAAQ;AACxD;AAUA,SAAS,aAAa,KAAe,SAA6B;CAEhE,MAAM,kBAAkB,IAAI;CAG5B,IAAI,UAAU,SAAS,iBAAiB;EAGtC,IADsB,IAAI,2BACJ,SAAS;GAE7B,OAAO,IAAI;GAEX,QAAQ,QAAQ;EAClB;EAGA,OAAO,gBAAgB,KAAK,IAAI;CAClC;AACF;AAOO,SAAS,yBAAyB,KAAoC;CAC3E,OAAQ,IAAiB;AAC3B;AAeO,SAAS,oBACd,KACA,SACc;CACd,MAAM,WAAW;CAEjB,MAAM,mBAAmB,SAAS;CAElC,IAAI,kBAAkB;EAEpB,sBAAA,sBAAsB,gBAAgB;EACtC,OAAO;CACT;CAGA,IAAI,CAAC,iBAAiB,KAAK,OAAO,GAChC,IAAI,IAAI,QAAQ,KAAK;CAIvB,SAAS,yBAAyB;CAGlC,IAAI,QAAQ,QAAQ,SAAS;EAC3B,IAAI,QAAQ,uBAAA,sBAAsB,OAAO;EACzC,IAAI,QAAQ,uBAAA,kBAAkB,QAAQ,QAAQ;EAC9C,IAAI,QAAQ,uBAAA,oBAAoB,QAAQ,KAAK;EAC7C,IAAI,QAAQ,SAAS,QAAQ,QAAQ;EACrC,IAAI,QAAQ,SAAS,QAAQ,KAAK;CACpC;CAGA,IAAI,QAAQ,QAAQ,kBAClB,IAAI,OAAO,iBAAiB,SAAS,QAAQ;CAI/C,aAAa,UAAU,OAAO;CAE9B,sBAAA,sBAAsB,OAAO;CAE7B,OAAO;AACT"}
@@ -0,0 +1,23 @@
1
+ import type { App } from 'vue';
2
+ import type { StoreRuntime } from './store-runtime';
3
+ /**
4
+ * 获取 Vue App 上已安装的 Store 运行时
5
+ * @param app - Vue 应用实例
6
+ * @returns 已安装的运行时或 undefined
7
+ */
8
+ export declare function getInstalledStoreRuntime(app: App): StoreRuntime | undefined;
9
+ /**
10
+ * 将 Store 运行时安装到 Vue App
11
+ * 这是 Vue 适配层的核心安装入口,负责:
12
+ * 1. 安装 Pinia 插件
13
+ * 2. 通过 provide 注入 Store 能力
14
+ * 3. 挂载到 globalProperties
15
+ * 4. 打 unmount 补丁进行生命周期管理
16
+ * 5. 设置全局运行时引用
17
+ *
18
+ * @param app - Vue 应用实例
19
+ * @param runtime - Store 运行时实例
20
+ * @returns 安装的运行时(如果已安装则返回已有的)
21
+ */
22
+ export declare function installStoreRuntime(app: App, runtime: StoreRuntime): StoreRuntime;
23
+ //# sourceMappingURL=install-store-app.d.ts.map
@@ -0,0 +1,26 @@
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/runtime/store-plugin-options.ts
13
+ function normalizeStoreRuntimeOptions(options = {}) {
14
+ return {
15
+ pinia: options.pinia,
16
+ persist: options.persist ?? false,
17
+ persistOptions: options.persistOptions ?? {},
18
+ globalProperties: options.globalProperties ?? true,
19
+ provide: options.provide ?? true,
20
+ debug: options.debug ?? false
21
+ };
22
+ }
23
+ //#endregion
24
+ exports.normalizeStoreRuntimeOptions = normalizeStoreRuntimeOptions;
25
+ /*! End of @composy/store-vue | Powered by @composy/builder */
26
+ //# sourceMappingURL=store-plugin-options.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-plugin-options.cjs","names":[],"sources":["../../src/runtime/store-plugin-options.ts"],"sourcesContent":["// 从 pinia 导入 Pinia 类型\nimport type { Pinia } from 'pinia'\n// 导入增强持久化插件选项类型\nimport type { EnhancedPersistPluginOptions } from '../plugins/pinia-plugin'\n\n/**\n * store 运行时配置选项接口\n * 用于配置 store 运行时的行为\n */\nexport interface StoreRuntimeOptions {\n // 可选的 Pinia 实例,如果不提供则自动创建\n pinia?: Pinia\n // 是否启用持久化功能\n persist?: boolean\n // 持久化插件的详细配置选项\n persistOptions?: EnhancedPersistPluginOptions\n // 是否将 store API 注册到 Vue 全局属性\n globalProperties?: boolean\n // 是否通过 provide/inject 提供 store 实例\n provide?: boolean\n // 是否开启调试模式\n debug?: boolean\n}\n\n/**\n * store Vue 插件选项接口\n * 继承自 StoreRuntimeOptions,当前无额外扩展\n */\nexport interface StoreVuePluginOptions extends StoreRuntimeOptions {}\n\n/**\n * 解析后的 store 运行时选项接口\n * 所有字段均已填充默认值,不再包含可选标记\n */\nexport interface ResolvedStoreRuntimeOptions {\n // Pinia 实例\n pinia?: Pinia\n // 是否启用持久化\n persist: boolean\n // 持久化插件配置\n persistOptions: EnhancedPersistPluginOptions\n // 是否注册全局属性\n globalProperties: boolean\n // 是否通过 provide 提供\n provide: boolean\n // 是否开启调试\n debug: boolean\n}\n\n/**\n * 将用户传入的 store 运行时选项规范化为完整配置\n * 为每个可选字段填充默认值\n * @param options - 用户传入的配置选项\n * @returns 规范化后的完整配置对象\n */\nexport function normalizeStoreRuntimeOptions(\n options: StoreRuntimeOptions = {},\n): ResolvedStoreRuntimeOptions {\n return {\n pinia: options.pinia, // 透传 Pinia 实例\n persist: options.persist ?? false, // 默认不启用持久化\n persistOptions: options.persistOptions ?? {}, // 默认空持久化配置\n globalProperties: options.globalProperties ?? true, // 默认注册全局属性\n provide: options.provide ?? true, // 默认通过 provide 提供\n debug: options.debug ?? false, // 默认关闭调试\n }\n}\n"],"mappings":";;;;;;;;;;;;AAuDO,SAAS,6BACd,UAA+B,CAAC,GACH;CAC7B,OAAO;EACL,OAAO,QAAQ;EACf,SAAS,QAAQ,WAAW;EAC5B,gBAAgB,QAAQ,kBAAkB,CAAC;EAC3C,kBAAkB,QAAQ,oBAAoB;EAC9C,SAAS,QAAQ,WAAW;EAC5B,OAAO,QAAQ,SAAS;CAC1B;AACF"}