@composy/store-vue 0.0.1 → 0.0.2

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 (251) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +169 -154
  3. package/dist/index.js +151 -53
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +242 -170
  6. package/dist/index.min.js.map +1 -1
  7. package/es/.dts-output-manifest.json +1 -0
  8. package/es/.dts.tsbuildinfo +1 -0
  9. package/es/composables/defineSetupStore.d.ts +0 -1
  10. package/es/composables/defineSetupStore.d.ts.map +1 -1
  11. package/es/composables/defineSetupStore.js +1 -1
  12. package/es/composables/defineSetupStore.js.map +1 -1
  13. package/es/composables/index.d.ts +8 -9
  14. package/es/composables/index.d.ts.map +1 -1
  15. package/es/composables/index.js +1 -1
  16. package/es/composables/useFormStore.d.ts +0 -1
  17. package/es/composables/useFormStore.d.ts.map +1 -1
  18. package/es/composables/useFormStore.js +1 -1
  19. package/es/composables/useFormStore.js.map +1 -1
  20. package/es/composables/useOptimistic.d.ts +1 -52
  21. package/es/composables/useOptimistic.d.ts.map +1 -1
  22. package/es/composables/useOptimistic.js +35 -20
  23. package/es/composables/useOptimistic.js.map +1 -1
  24. package/es/composables/usePersist.d.ts +0 -1
  25. package/es/composables/usePersist.d.ts.map +1 -1
  26. package/es/composables/usePersist.js +16 -7
  27. package/es/composables/usePersist.js.map +1 -1
  28. package/es/composables/usePersistedState.d.ts +0 -1
  29. package/es/composables/usePersistedState.d.ts.map +1 -1
  30. package/es/composables/usePersistedState.js +16 -3
  31. package/es/composables/usePersistedState.js.map +1 -1
  32. package/es/composables/useSharedState.d.ts +0 -1
  33. package/es/composables/useSharedState.d.ts.map +1 -1
  34. package/es/composables/useSharedState.js +25 -8
  35. package/es/composables/useSharedState.js.map +1 -1
  36. package/es/composables/useStore.d.ts +0 -1
  37. package/es/composables/useStore.js +1 -1
  38. package/es/composables/useStore.js.map +1 -1
  39. package/es/composables/useStoreDevtools.d.ts +0 -1
  40. package/es/composables/useStoreDevtools.d.ts.map +1 -1
  41. package/es/composables/useStoreDevtools.js +1 -1
  42. package/es/composables/useStoreDevtools.js.map +1 -1
  43. package/es/composables/useStoreSnapshot.d.ts +0 -1
  44. package/es/composables/useStoreSnapshot.d.ts.map +1 -1
  45. package/es/composables/useStoreSnapshot.js +18 -8
  46. package/es/composables/useStoreSnapshot.js.map +1 -1
  47. package/es/composables/useSubscribe.d.ts +0 -1
  48. package/es/composables/useSubscribe.d.ts.map +1 -1
  49. package/es/composables/useSubscribe.js +1 -1
  50. package/es/composables/useSubscribe.js.map +1 -1
  51. package/es/context/injection-keys.d.ts +0 -1
  52. package/es/context/injection-keys.d.ts.map +1 -1
  53. package/es/context/injection-keys.js +1 -1
  54. package/es/context/injection-keys.js.map +1 -1
  55. package/es/index.d.ts +1 -2
  56. package/es/index.js +2 -2
  57. package/es/index.js.map +1 -1
  58. package/es/plugins/engine-plugin.d.ts +1 -2
  59. package/es/plugins/engine-plugin.d.ts.map +1 -1
  60. package/es/plugins/engine-plugin.js +2 -2
  61. package/es/plugins/engine-plugin.js.map +1 -1
  62. package/es/plugins/enhanced-persist-plugin.d.ts +0 -1
  63. package/es/plugins/enhanced-persist-plugin.js +1 -1
  64. package/es/plugins/index.d.ts +0 -1
  65. package/es/plugins/index.js +1 -1
  66. package/es/plugins/pinia-plugin.d.ts +0 -1
  67. package/es/plugins/pinia-plugin.d.ts.map +1 -1
  68. package/es/plugins/pinia-plugin.js +24 -6
  69. package/es/plugins/pinia-plugin.js.map +1 -1
  70. package/es/plugins/registry-plugin.d.ts +0 -1
  71. package/es/plugins/registry-plugin.js +1 -1
  72. package/es/plugins/vue-plugin.d.ts +0 -1
  73. package/es/plugins/vue-plugin.d.ts.map +1 -1
  74. package/es/plugins/vue-plugin.js +1 -1
  75. package/es/plugins/vue-plugin.js.map +1 -1
  76. package/es/runtime/install-store-app.d.ts +0 -1
  77. package/es/runtime/install-store-app.js +1 -1
  78. package/es/runtime/install-store-app.js.map +1 -1
  79. package/es/runtime/store-plugin-options.d.ts +0 -1
  80. package/es/runtime/store-plugin-options.js +1 -1
  81. package/es/runtime/store-plugin-options.js.map +1 -1
  82. package/es/runtime/store-registry.d.ts +0 -1
  83. package/es/runtime/store-registry.d.ts.map +1 -1
  84. package/es/runtime/store-registry.js +14 -4
  85. package/es/runtime/store-registry.js.map +1 -1
  86. package/es/runtime/store-runtime.d.ts +1 -2
  87. package/es/runtime/store-runtime.d.ts.map +1 -1
  88. package/es/runtime/store-runtime.js +8 -2
  89. package/es/runtime/store-runtime.js.map +1 -1
  90. package/es/types.d.ts +2 -1
  91. package/es/types.d.ts.map +1 -1
  92. package/es/types.js +1 -1
  93. package/esm/composables/defineSetupStore.d.ts.map +1 -1
  94. package/esm/composables/defineSetupStore.js +1 -1
  95. package/esm/composables/defineSetupStore.js.map +1 -1
  96. package/esm/composables/index.d.ts +8 -8
  97. package/esm/composables/index.d.ts.map +1 -1
  98. package/esm/composables/index.js +1 -1
  99. package/esm/composables/useFormStore.d.ts.map +1 -1
  100. package/esm/composables/useFormStore.js +1 -1
  101. package/esm/composables/useFormStore.js.map +1 -1
  102. package/esm/composables/useOptimistic.d.ts +1 -51
  103. package/esm/composables/useOptimistic.d.ts.map +1 -1
  104. package/esm/composables/useOptimistic.js +35 -20
  105. package/esm/composables/useOptimistic.js.map +1 -1
  106. package/esm/composables/usePersist.d.ts.map +1 -1
  107. package/esm/composables/usePersist.js +16 -7
  108. package/esm/composables/usePersist.js.map +1 -1
  109. package/esm/composables/usePersistedState.d.ts.map +1 -1
  110. package/esm/composables/usePersistedState.js +16 -3
  111. package/esm/composables/usePersistedState.js.map +1 -1
  112. package/esm/composables/useSharedState.d.ts.map +1 -1
  113. package/esm/composables/useSharedState.js +25 -8
  114. package/esm/composables/useSharedState.js.map +1 -1
  115. package/esm/composables/useStore.js +1 -1
  116. package/esm/composables/useStore.js.map +1 -1
  117. package/esm/composables/useStoreDevtools.d.ts.map +1 -1
  118. package/esm/composables/useStoreDevtools.js +1 -1
  119. package/esm/composables/useStoreDevtools.js.map +1 -1
  120. package/esm/composables/useStoreSnapshot.d.ts.map +1 -1
  121. package/esm/composables/useStoreSnapshot.js +18 -8
  122. package/esm/composables/useStoreSnapshot.js.map +1 -1
  123. package/esm/composables/useSubscribe.d.ts.map +1 -1
  124. package/esm/composables/useSubscribe.js +1 -1
  125. package/esm/composables/useSubscribe.js.map +1 -1
  126. package/esm/context/injection-keys.d.ts.map +1 -1
  127. package/esm/context/injection-keys.js +1 -1
  128. package/esm/context/injection-keys.js.map +1 -1
  129. package/esm/index.d.ts +1 -1
  130. package/esm/index.js +2 -2
  131. package/esm/index.js.map +1 -1
  132. package/esm/plugins/engine-plugin.d.ts +1 -1
  133. package/esm/plugins/engine-plugin.d.ts.map +1 -1
  134. package/esm/plugins/engine-plugin.js +2 -2
  135. package/esm/plugins/engine-plugin.js.map +1 -1
  136. package/esm/plugins/enhanced-persist-plugin.js +1 -1
  137. package/esm/plugins/index.js +1 -1
  138. package/esm/plugins/pinia-plugin.d.ts.map +1 -1
  139. package/esm/plugins/pinia-plugin.js +24 -6
  140. package/esm/plugins/pinia-plugin.js.map +1 -1
  141. package/esm/plugins/registry-plugin.js +1 -1
  142. package/esm/plugins/vue-plugin.d.ts.map +1 -1
  143. package/esm/plugins/vue-plugin.js +1 -1
  144. package/esm/plugins/vue-plugin.js.map +1 -1
  145. package/esm/runtime/install-store-app.js +1 -1
  146. package/esm/runtime/install-store-app.js.map +1 -1
  147. package/esm/runtime/store-plugin-options.js +1 -1
  148. package/esm/runtime/store-plugin-options.js.map +1 -1
  149. package/esm/runtime/store-registry.d.ts.map +1 -1
  150. package/esm/runtime/store-registry.js +14 -4
  151. package/esm/runtime/store-registry.js.map +1 -1
  152. package/esm/runtime/store-runtime.d.ts +1 -1
  153. package/esm/runtime/store-runtime.d.ts.map +1 -1
  154. package/esm/runtime/store-runtime.js +8 -2
  155. package/esm/runtime/store-runtime.js.map +1 -1
  156. package/esm/types.d.ts +2 -0
  157. package/esm/types.d.ts.map +1 -1
  158. package/esm/types.js +1 -1
  159. package/lib/composables/defineSetupStore.cjs +1 -1
  160. package/lib/composables/defineSetupStore.cjs.map +1 -1
  161. package/lib/composables/{defineSetupStore.d.ts → defineSetupStore.d.cts} +0 -1
  162. package/lib/composables/defineSetupStore.d.cts.map +1 -0
  163. package/lib/composables/index.cjs +1 -1
  164. package/lib/composables/{index.d.ts → index.d.cts} +8 -9
  165. package/lib/composables/index.d.cts.map +1 -0
  166. package/lib/composables/useFormStore.cjs +1 -1
  167. package/lib/composables/useFormStore.cjs.map +1 -1
  168. package/lib/composables/{useFormStore.d.ts → useFormStore.d.cts} +0 -1
  169. package/lib/composables/useFormStore.d.cts.map +1 -0
  170. package/lib/composables/useOptimistic.cjs +35 -20
  171. package/lib/composables/useOptimistic.cjs.map +1 -1
  172. package/lib/composables/useOptimistic.d.cts +16 -0
  173. package/lib/composables/useOptimistic.d.cts.map +1 -0
  174. package/lib/composables/usePersist.cjs +16 -7
  175. package/lib/composables/usePersist.cjs.map +1 -1
  176. package/lib/composables/{usePersist.d.ts → usePersist.d.cts} +0 -1
  177. package/lib/composables/usePersist.d.cts.map +1 -0
  178. package/lib/composables/usePersistedState.cjs +16 -3
  179. package/lib/composables/usePersistedState.cjs.map +1 -1
  180. package/lib/composables/{usePersistedState.d.ts → usePersistedState.d.cts} +0 -1
  181. package/lib/composables/usePersistedState.d.cts.map +1 -0
  182. package/lib/composables/useSharedState.cjs +24 -7
  183. package/lib/composables/useSharedState.cjs.map +1 -1
  184. package/lib/composables/{useSharedState.d.ts → useSharedState.d.cts} +0 -1
  185. package/lib/composables/useSharedState.d.cts.map +1 -0
  186. package/lib/composables/useStore.cjs +1 -1
  187. package/lib/composables/useStore.cjs.map +1 -1
  188. package/lib/composables/{useStore.d.ts → useStore.d.cts} +0 -1
  189. package/lib/composables/useStore.d.cts.map +1 -0
  190. package/lib/composables/useStoreDevtools.cjs +1 -1
  191. package/lib/composables/useStoreDevtools.cjs.map +1 -1
  192. package/lib/composables/{useStoreDevtools.d.ts → useStoreDevtools.d.cts} +0 -1
  193. package/lib/composables/useStoreDevtools.d.cts.map +1 -0
  194. package/lib/composables/useStoreSnapshot.cjs +18 -8
  195. package/lib/composables/useStoreSnapshot.cjs.map +1 -1
  196. package/lib/composables/{useStoreSnapshot.d.ts → useStoreSnapshot.d.cts} +0 -1
  197. package/lib/composables/useStoreSnapshot.d.cts.map +1 -0
  198. package/lib/composables/useSubscribe.cjs +1 -1
  199. package/lib/composables/useSubscribe.cjs.map +1 -1
  200. package/lib/composables/{useSubscribe.d.ts → useSubscribe.d.cts} +0 -1
  201. package/lib/composables/useSubscribe.d.cts.map +1 -0
  202. package/lib/context/injection-keys.cjs +1 -1
  203. package/lib/context/injection-keys.cjs.map +1 -1
  204. package/lib/context/{injection-keys.d.ts → injection-keys.d.cts} +0 -1
  205. package/lib/context/injection-keys.d.cts.map +1 -0
  206. package/lib/index.cjs +2 -2
  207. package/lib/index.cjs.map +1 -1
  208. package/lib/{index.d.ts → index.d.cts} +1 -2
  209. package/lib/index.d.cts.map +1 -0
  210. package/lib/plugins/engine-plugin.cjs +2 -2
  211. package/lib/plugins/engine-plugin.cjs.map +1 -1
  212. package/lib/plugins/{engine-plugin.d.ts → engine-plugin.d.cts} +1 -2
  213. package/lib/plugins/engine-plugin.d.cts.map +1 -0
  214. package/lib/plugins/enhanced-persist-plugin.cjs +1 -1
  215. package/lib/plugins/{enhanced-persist-plugin.d.ts → enhanced-persist-plugin.d.cts} +0 -1
  216. package/lib/plugins/enhanced-persist-plugin.d.cts.map +1 -0
  217. package/lib/plugins/index.cjs +1 -1
  218. package/lib/plugins/{index.d.ts → index.d.cts} +0 -1
  219. package/lib/plugins/index.d.cts.map +1 -0
  220. package/lib/plugins/pinia-plugin.cjs +24 -6
  221. package/lib/plugins/pinia-plugin.cjs.map +1 -1
  222. package/lib/plugins/{pinia-plugin.d.ts → pinia-plugin.d.cts} +0 -1
  223. package/lib/plugins/pinia-plugin.d.cts.map +1 -0
  224. package/lib/plugins/registry-plugin.cjs +1 -1
  225. package/lib/plugins/{registry-plugin.d.ts → registry-plugin.d.cts} +0 -1
  226. package/lib/plugins/registry-plugin.d.cts.map +1 -0
  227. package/lib/plugins/vue-plugin.cjs +1 -1
  228. package/lib/plugins/vue-plugin.cjs.map +1 -1
  229. package/lib/plugins/{vue-plugin.d.ts → vue-plugin.d.cts} +0 -1
  230. package/lib/plugins/vue-plugin.d.cts.map +1 -0
  231. package/lib/runtime/install-store-app.cjs +1 -1
  232. package/lib/runtime/install-store-app.cjs.map +1 -1
  233. package/lib/runtime/{install-store-app.d.ts → install-store-app.d.cts} +0 -1
  234. package/lib/runtime/install-store-app.d.cts.map +1 -0
  235. package/lib/runtime/store-plugin-options.cjs +1 -1
  236. package/lib/runtime/store-plugin-options.cjs.map +1 -1
  237. package/lib/runtime/{store-plugin-options.d.ts → store-plugin-options.d.cts} +0 -1
  238. package/lib/runtime/store-plugin-options.d.cts.map +1 -0
  239. package/lib/runtime/store-registry.cjs +14 -4
  240. package/lib/runtime/store-registry.cjs.map +1 -1
  241. package/lib/runtime/{store-registry.d.ts → store-registry.d.cts} +0 -1
  242. package/lib/runtime/store-registry.d.cts.map +1 -0
  243. package/lib/runtime/store-runtime.cjs +8 -2
  244. package/lib/runtime/store-runtime.cjs.map +1 -1
  245. package/lib/runtime/{store-runtime.d.ts → store-runtime.d.cts} +1 -2
  246. package/lib/runtime/store-runtime.d.cts.map +1 -0
  247. package/lib/types.cjs +1 -1
  248. package/lib/{types.d.ts → types.d.cts} +2 -1
  249. package/lib/types.d.cts.map +1 -0
  250. package/package.json +19 -16
  251. package/lib/composables/useOptimistic.d.ts +0 -67
package/dist/index.min.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * ***********************************
3
3
  * @composy/store-vue v0.0.1 *
4
4
  * Built with rollup *
5
- * Build time: 2024-08-17 11:39:29 *
5
+ * Build time: 2024-10-12 17:40:04 *
6
6
  * Build mode: production *
7
7
  * Minified: No *
8
8
  * ***********************************
@@ -15,7 +15,7 @@
15
15
  "vue",
16
16
  "@composy/store-core",
17
17
  "@composy/store-core/engine"
18
- ], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).LDesignStoreVue = {}, e.Pinia, e.Vue, e.ComposyStoreCore, e.ComposyStoreCore);
18
+ ], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).LDesignStoreVue = {}, e.Pinia, e.Vue, e.LDesignStoreCore, e.LDesignStoreCore);
19
19
  })(this, function(exports, e, t, n, r) {
20
20
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
21
21
  const o = "此字段为必填项", i = /^[^\s@]+@[^@][^.@]*\.[^\s@]+$/;
@@ -23,23 +23,28 @@
23
23
  return (n) => "string" != typeof n || e.test(n) ? null : t;
24
24
  }
25
25
  function a(e) {
26
- const { key: n, storage: r = "localStorage", defaultValue: o, serialize: i = JSON.stringify, deserialize: s = JSON.parse } = e, a = (u = r, "undefined" == typeof window ? null : "localStorage" === u ? localStorage : sessionStorage);
27
- var u;
28
- const l = (0, t.ref)(o), c = () => {
29
- if (a) try {
30
- const e = a.getItem(n);
26
+ const { key: n, storage: r = "localStorage", defaultValue: o, serialize: i = JSON.stringify, deserialize: s = JSON.parse, restoreOnMounted: a = !0 } = e, u = function(e) {
27
+ if ("undefined" == typeof window) return null;
28
+ try {
29
+ return "localStorage" === e ? window.localStorage : window.sessionStorage;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }(r), l = (0, t.ref)(o), c = () => {
34
+ if (u) try {
35
+ const e = u.getItem(n);
31
36
  null !== e && (l.value = s(e));
32
37
  } catch (e) {
33
38
  console.error(`[usePersist] 恢复失败 (${n}):`, e);
34
39
  }
35
40
  }, d = () => {
36
- if (a) try {
37
- a.setItem(n, i(l.value));
41
+ if (u) try {
42
+ u.setItem(n, i(l.value));
38
43
  } catch (e) {
39
44
  console.error(`[usePersist] 保存失败 (${n}):`, e);
40
45
  }
41
46
  };
42
- return (0, t.onMounted)(() => {
47
+ return a && (0, t.onMounted)(() => {
43
48
  c();
44
49
  }), (0, t.watch)(l, () => {
45
50
  d();
@@ -48,8 +53,8 @@
48
53
  save: d,
49
54
  restore: c,
50
55
  clear: () => {
51
- if (a) try {
52
- a.removeItem(n), l.value = o;
56
+ if (u) try {
57
+ u.removeItem(n), l.value = o;
53
58
  } catch (e) {
54
59
  console.error(`[usePersist] 清除失败 (${n}):`, e);
55
60
  }
@@ -128,34 +133,42 @@
128
133
  }
129
134
  const g = Symbol("ldesign-store-api"), y = Symbol("ldesign-store-pinia"), v = Symbol("ldesign-store-runtime"), m = Symbol("ldesign-store-persist-dispose"), b = /* @__PURE__ */ new Set();
130
135
  function h(e = {}) {
131
- const { storage: t = "localStorage", keyPrefix: r = "ldesign-store:", debounce: o = 100, debug: i = !1, syncTabs: s = !1, defaultTTL: a } = e, u = /* @__PURE__ */ new Map(), l = () => {
132
- u.forEach((e) => e()), u.clear(), b.delete(l);
136
+ const { storage: t = "localStorage", keyPrefix: r = "ldesign-store:", debounce: o = 100, debug: i = !1, syncTabs: s = !1, defaultTTL: a } = e, u = /* @__PURE__ */ new Map();
137
+ let l = !1;
138
+ const c = () => {
139
+ l || (l = !0, u.forEach((e) => e()), u.clear(), b.delete(c));
133
140
  };
134
- b.add(l);
141
+ b.add(c);
135
142
  return {
136
143
  plugin: (e) => {
137
- const { store: l, options: c } = e, d = (p = c.persist) ? "boolean" == typeof p ? {} : p : null;
138
- var p;
139
- if (!d) return;
140
- const f = (g = "sessionStorage" === d.storage ? "sessionStorage" : t, "undefined" == typeof window ? null : "localStorage" === g ? window.localStorage : window.sessionStorage);
141
- var g;
142
- const y = d.serializer?.serialize ?? JSON.stringify, v = d.serializer?.deserialize ?? JSON.parse, b = d.syncTabs ?? s, h = d.ttl ?? a, S = `${r}${d.key || l.$id}`;
143
- if (!f) return void (i && console.warn(`[PersistPlugin] Storage 不可用 (${l.$id})`));
144
- let P = !1;
145
- const w = (e) => {
144
+ if (l) return;
145
+ const { store: c, options: d } = e, p = (f = d.persist) ? "boolean" == typeof f ? {} : f : null;
146
+ var f;
147
+ if (!p) return;
148
+ const g = function(e) {
149
+ if ("undefined" == typeof window) return null;
150
+ try {
151
+ return "localStorage" === e ? window.localStorage : window.sessionStorage;
152
+ } catch {
153
+ return null;
154
+ }
155
+ }(p.storage ?? t), y = p.serializer?.serialize ?? JSON.stringify, v = p.serializer?.deserialize ?? JSON.parse, b = p.syncTabs ?? s, h = p.ttl ?? a, S = `${r}${p.key || c.$id}`;
156
+ if (!g) return void (i && console.warn(`[PersistPlugin] Storage 不可用 (${c.$id})`));
157
+ let w = !1;
158
+ const P = (e) => {
146
159
  const t = v(e);
147
- P = !0;
160
+ w = !0;
148
161
  try {
149
- d.beforeRestore?.({ store: l }), function(e, t) {
162
+ p.beforeRestore?.({ store: c }), function(e, t) {
150
163
  e.$patch((e) => {
151
164
  (0, n.deepMerge)(e, t);
152
165
  });
153
- }(l, t), d.afterRestore?.({ store: l });
166
+ }(c, t), p.afterRestore?.({ store: c });
154
167
  } finally {
155
- P = !1;
168
+ w = !1;
156
169
  }
157
170
  }, $ = (0, n.debounce)(() => {
158
- if (!P) try {
171
+ if (!w) try {
159
172
  const e = function(e, t, r) {
160
173
  if (t?.length) {
161
174
  const r = {};
@@ -171,38 +184,46 @@
171
184
  }), t;
172
185
  }
173
186
  return (0, n.deepClone)(e);
174
- }(l.$state, d.paths, d.excludePaths), t = {
187
+ }(c.$state, p.paths, p.excludePaths), t = {
175
188
  state: y(e),
176
189
  timestamp: Date.now(),
177
190
  expiresAt: h ? Date.now() + h : void 0,
178
191
  version: 1
179
192
  };
180
- f.setItem(S, JSON.stringify(t)), i && console.info(`[PersistPlugin] 已保存状态 (${l.$id})`);
193
+ g.setItem(S, JSON.stringify(t)), i && console.info(`[PersistPlugin] 已保存状态 (${c.$id})`);
181
194
  } catch (e) {
182
- console.error(`[PersistPlugin] 保存状态失败 (${l.$id}):`, e);
195
+ console.error(`[PersistPlugin] 保存状态失败 (${c.$id}):`, e);
183
196
  }
184
- }, d.debounce ?? o), O = l.$subscribe(() => {
185
- P || $();
197
+ }, p.debounce ?? o), O = c.$subscribe(() => {
198
+ w || $();
186
199
  });
187
200
  let A = () => {};
188
201
  if (b && "undefined" != typeof window) {
189
202
  const e = (e) => {
190
- if (e.key === S && e.newValue) try {
203
+ if (e.key === S) if (null !== e.newValue) try {
191
204
  const t = JSON.parse(e.newValue);
192
205
  if (t.expiresAt && Date.now() > t.expiresAt) return;
193
- w(t.state);
206
+ P(t.state);
194
207
  } catch (e) {
195
- console.error(`[PersistPlugin] 同步状态失败 (${l.$id}):`, e);
208
+ console.error(`[PersistPlugin] 同步状态失败 (${c.$id}):`, e);
209
+ }
210
+ else {
211
+ w = !0;
212
+ try {
213
+ c.$reset?.();
214
+ } finally {
215
+ w = !1;
216
+ }
196
217
  }
197
218
  };
198
219
  window.addEventListener("storage", e), A = () => {
199
220
  window.removeEventListener("storage", e);
200
221
  };
201
222
  }
202
- const j = () => {
203
- $.cancel(), O(), A(), u.delete(S);
223
+ const C = () => {
224
+ $.cancel(), O(), A(), u.delete(c), c[m]?.();
204
225
  };
205
- u.set(S, j), function(e, t) {
226
+ u.set(c, C), function(e, t) {
206
227
  const n = e[m];
207
228
  n && n();
208
229
  const r = e.$dispose;
@@ -211,36 +232,38 @@
211
232
  }, e[m] = () => {
212
233
  e.$dispose = r, delete e[m];
213
234
  };
214
- }(l, j), (() => {
235
+ }(c, C), (() => {
215
236
  try {
216
- const e = f.getItem(S);
237
+ const e = g.getItem(S);
217
238
  if (!e) return;
218
239
  const t = JSON.parse(e);
219
- if (t.expiresAt && Date.now() > t.expiresAt) return void f.removeItem(S);
220
- w(t.state), i && console.info(`[PersistPlugin] 已恢复状态 (${l.$id})`);
240
+ if (t.expiresAt && Date.now() > t.expiresAt) return void g.removeItem(S);
241
+ P(t.state), i && console.info(`[PersistPlugin] 已恢复状态 (${c.$id})`);
221
242
  } catch (e) {
222
- console.error(`[PersistPlugin] 恢复状态失败 (${l.$id}):`, e);
243
+ console.error(`[PersistPlugin] 恢复状态失败 (${c.$id}):`, e);
223
244
  }
224
245
  })();
225
246
  },
226
- dispose: l
247
+ dispose: c
227
248
  };
228
249
  }
229
250
  const S = Symbol("ldesign-store-registry-dispose");
230
- function P() {
231
- const e = /* @__PURE__ */ new Map(), t = (t) => {
232
- e.delete(t);
251
+ function w() {
252
+ const e = /* @__PURE__ */ new Map(), t = (t, n) => {
253
+ const r = e.get(t);
254
+ !r || n && r !== n || (e.delete(t), r[S]?.());
233
255
  }, n = (n) => {
234
- e.set(n.$id, n), function(e, t) {
256
+ const r = e.get(n.$id);
257
+ r && r !== n && t(n.$id, r), e.set(n.$id, n), function(e, t) {
235
258
  const n = e[S];
236
259
  n && n();
237
260
  const r = e.$dispose;
238
261
  e.$dispose = function() {
239
- return t(e.$id), r.call(this);
262
+ return t(), r.call(this);
240
263
  }, e[S] = () => {
241
264
  e.$dispose = r, delete e[S];
242
265
  };
243
- }(n, t);
266
+ }(n, () => t(n.$id, n));
244
267
  }, r = (t) => e.has(t), o = (t) => e.get(t), i = () => Array.from(e.keys()), s = () => {
245
268
  e.forEach((e) => {
246
269
  if ("function" == typeof e.$reset) try {
@@ -257,7 +280,9 @@
257
280
  getStoreIds: i,
258
281
  resetAll: s,
259
282
  clear: () => {
260
- e.clear();
283
+ e.forEach((e) => {
284
+ e[S]?.();
285
+ }), e.clear();
261
286
  },
262
287
  registerExistingStores: (e) => {
263
288
  e._s?.forEach((e) => n(e));
@@ -271,18 +296,19 @@
271
296
  })
272
297
  };
273
298
  }
274
- let w = P();
275
- function $(e = w) {
299
+ let P = w();
300
+ function $(e = P) {
276
301
  return ({ store: t }) => {
277
302
  e.register(t);
278
303
  };
279
304
  }
280
305
  const O = Symbol("ldesign-store-runtime");
281
306
  let A = null;
282
- function j(e) {
283
- A = e, w = e?.registry ?? null ?? P();
307
+ function C(e) {
308
+ var t;
309
+ A = e, (t = e?.registry ?? null) !== P && (P.clear(), P = t ?? w());
284
310
  }
285
- function C(t = {}) {
311
+ function j(t = {}) {
286
312
  const n = function(e = {}) {
287
313
  return {
288
314
  pinia: e.pinia,
@@ -294,40 +320,44 @@
294
320
  };
295
321
  }(t), r = n.pinia ?? (0, e.createPinia)();
296
322
  if (r[O]) return r[O];
297
- const o = P(), i = n.persist ? h({
323
+ const o = w();
324
+ let i = !0;
325
+ const s = n.persist ? h({
298
326
  ...n.persistOptions,
299
327
  debug: n.debug || n.persistOptions.debug
300
- }) : null;
301
- r.use($(o)), i && r.use(i.plugin), o.registerExistingStores(r);
302
- const s = {
328
+ }) : null, a = $(o);
329
+ r.use((e) => {
330
+ i && a(e);
331
+ }), s && r.use(s.plugin), o.registerExistingStores(r);
332
+ const u = {
303
333
  pinia: r,
304
334
  registry: o,
305
335
  storeAPI: o.createStoreAPI(r),
306
336
  options: n,
307
337
  dispose: () => {
308
- r[O] === s && delete r[O], i?.dispose(), o.clear(), A === s && j(null);
338
+ i && (i = !1, r[O] === u && delete r[O], s?.dispose(), o.clear(), A === u && C(null));
309
339
  }
310
340
  };
311
- return r[O] = s, s;
341
+ return r[O] = u, u;
312
342
  }
313
- const x = Symbol("ldesign-store-app-runtime");
314
- function M(e, t) {
315
- const n = e, r = n[x];
316
- return r ? (j(r), r) : (function(e, t) {
343
+ const M = Symbol("ldesign-store-app-runtime");
344
+ function x(e, t) {
345
+ const n = e, r = n[M];
346
+ return r ? (C(r), r) : (function(e, t) {
317
347
  return e.config.globalProperties.$pinia === t.pinia;
318
- }(e, t) || e.use(t.pinia), n[x] = t, t.options.provide && (e.provide(v, t), e.provide(g, t.storeAPI), e.provide(y, t.pinia), e.provide("store", t.storeAPI), e.provide("pinia", t.pinia)), t.options.globalProperties && (e.config.globalProperties.$store = t.storeAPI), function(e, t) {
348
+ }(e, t) || e.use(t.pinia), n[M] = t, t.options.provide && (e.provide(v, t), e.provide(g, t.storeAPI), e.provide(y, t.pinia), e.provide("store", t.storeAPI), e.provide("pinia", t.pinia)), t.options.globalProperties && (e.config.globalProperties.$store = t.storeAPI), function(e, t) {
319
349
  const n = e.unmount;
320
350
  e.unmount = function() {
321
- return e[x] === t && (delete e[x], t.dispose()), n.call(this);
351
+ return e[M] === t && (delete e[M], t.dispose()), n.call(this);
322
352
  };
323
- }(n, t), j(t), t);
353
+ }(n, t), C(t), t);
324
354
  }
325
- function V(e) {
355
+ function E(e) {
326
356
  return !!e && "function" == typeof e.use;
327
357
  }
328
- function E(e, t, n) {
358
+ function V(e, t, n) {
329
359
  const r = n, o = r?.app ?? r?.framework?.app ?? e.getApp?.() ?? t.framework?.app;
330
- return V(o) ? o : void 0;
360
+ return E(o) ? o : void 0;
331
361
  }
332
362
  Object.defineProperty(exports, "batch", {
333
363
  enumerable: !0,
@@ -401,14 +431,14 @@
401
431
  return n.createSelector;
402
432
  }
403
433
  }), exports.createStoreEnginePlugin = function(e = {}) {
404
- const { debug: t = !1, dependencies: n = [], name: o = "store", version: i = "1.0.0" } = e;
434
+ const { debug: t = !1, dependencies: n = [], name: o = "store", version: i = "0.0.1" } = e;
405
435
  let s = null;
406
436
  const a = () => {
407
437
  const n = (0, r.createStoreEngineBridge)({
408
438
  name: o,
409
439
  version: i,
410
440
  debug: t,
411
- createRuntime: () => C({
441
+ createRuntime: () => j({
412
442
  pinia: e.pinia,
413
443
  persist: e.persist,
414
444
  persistOptions: e.persistOptions,
@@ -416,12 +446,12 @@
416
446
  provide: e.provide,
417
447
  debug: t
418
448
  }),
419
- attachToApp: (e, t) => M(e, t),
449
+ attachToApp: (e, t) => x(e, t),
420
450
  getRuntimeFromApp: (e) => function(e) {
421
- return e[x];
451
+ return e[M];
422
452
  }(e),
423
- isApp: V,
424
- resolveApp: E
453
+ isApp: E,
454
+ resolveApp: V
425
455
  });
426
456
  return s = n, n;
427
457
  }, u = () => s ?? a();
@@ -449,7 +479,7 @@
449
479
  return n;
450
480
  }, exports.createStoreVuePlugin = function(e = {}) {
451
481
  return { install(t) {
452
- const n = C(e), r = M(t, n);
482
+ const n = j(e), r = x(t, n);
453
483
  r !== n && n.dispose(), r.options.debug && console.info("[StoreVuePlugin] installed");
454
484
  } };
455
485
  }, Object.defineProperty(exports, "createTimeTravelMiddleware", {
@@ -494,7 +524,7 @@
494
524
  }), exports.getGlobalStoreAPI = function() {
495
525
  return A?.storeAPI ?? null;
496
526
  }, exports.getStoreRegistry = function() {
497
- return w.stores;
527
+ return P.stores;
498
528
  }, Object.defineProperty(exports, "globalEventBus", {
499
529
  enumerable: !0,
500
530
  get: function() {
@@ -578,7 +608,7 @@
578
608
  t.validating = !1;
579
609
  }
580
610
  }
581
- async function P() {
611
+ async function w() {
582
612
  return (await Promise.all(p.map((e) => S(e)))).every((e) => null === e);
583
613
  }
584
614
  return p.forEach((e) => {
@@ -602,12 +632,12 @@
602
632
  t && (t.touched = !0), "blur" === a && S(e);
603
633
  },
604
634
  validateField: S,
605
- validateAll: P,
635
+ validateAll: w,
606
636
  handleSubmit: async function() {
607
637
  if (v.value++, y.value = null, p.forEach((e) => {
608
638
  const t = f[e];
609
639
  t && (t.touched = !0);
610
- }), await P() && s) {
640
+ }), await w() && s) {
611
641
  g.value = !0;
612
642
  try {
613
643
  await s((0, n.deepClone)(l));
@@ -642,32 +672,45 @@
642
672
  }
643
673
  return console.warn("[useOnAction] Store 不支持 $onAction 方法"), () => {};
644
674
  }, exports.useOptimistic = function(e) {
645
- const r = (0, t.ref)((0, n.deepClone)(e)), o = (0, t.ref)(!1), i = (0, t.ref)(!1), s = (0, t.ref)([]);
675
+ const r = (0, t.ref)((0, n.deepClone)(e));
676
+ let o = (0, n.deepClone)(e);
677
+ const i = [], s = (0, t.ref)(!1), a = (0, t.ref)(!1), u = (0, t.ref)([]), l = () => {
678
+ let e = (0, n.deepClone)(o);
679
+ i.forEach((t) => {
680
+ "rolled-back" !== t.status && (e = t.apply(e));
681
+ }), r.value = (0, n.deepClone)(e), u.value = i.filter((e) => "pending" === e.status).map((e) => ({
682
+ id: e.id,
683
+ snapshot: (0, n.deepClone)(e.snapshot),
684
+ status: e.status,
685
+ timestamp: e.timestamp
686
+ })), s.value = u.value.length > 0;
687
+ };
646
688
  return {
647
689
  state: r,
648
- isPending: o,
649
- pending: s,
650
- isRolledBack: i,
690
+ isPending: s,
691
+ pending: u,
692
+ isRolledBack: a,
651
693
  mutate: async function(e, t) {
652
- const a = (0, n.deepClone)(r.value), u = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, l = {
653
- id: u,
654
- snapshot: a,
694
+ const s = (0, n.deepClone)(r.value), u = "function" == typeof e ? (t) => (0, n.deepClone)(e((0, n.deepClone)(t))) : () => (0, n.deepClone)(e), c = {
695
+ id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
696
+ snapshot: s,
655
697
  status: "pending",
656
- timestamp: Date.now()
698
+ timestamp: Date.now(),
699
+ apply: u
657
700
  };
658
- s.value = [...s.value, l], o.value = !0, i.value = !1, r.value = "function" == typeof e ? e(r.value) : e;
701
+ i.push(c), a.value = !1, l();
659
702
  try {
660
- await t(), s.value = s.value.map((e) => e.id === u ? {
661
- ...e,
662
- status: "confirmed"
663
- } : e);
703
+ await t(), c.status = "confirmed";
664
704
  } catch {
665
- r.value = a, i.value = !0, s.value = s.value.map((e) => e.id === u ? {
666
- ...e,
667
- status: "rolled-back"
668
- } : e);
705
+ c.status = "rolled-back", a.value = !0;
669
706
  } finally {
670
- s.value = s.value.filter((e) => "pending" === e.status), o.value = s.value.length > 0;
707
+ (() => {
708
+ for (; i[0] && "pending" !== i[0].status;) {
709
+ const e = i.shift();
710
+ e && "rolled-back" !== e.status && (o = e.apply((0, n.deepClone)(o)));
711
+ }
712
+ l();
713
+ })();
671
714
  }
672
715
  }
673
716
  };
@@ -679,12 +722,13 @@
679
722
  });
680
723
  return r;
681
724
  }, exports.usePersistedRefWithTTL = function(e, n, r) {
682
- const { value: o } = a({
725
+ const o = a({
683
726
  key: e,
684
727
  defaultValue: {
685
728
  value: n,
686
729
  expiry: 0
687
730
  },
731
+ restoreOnMounted: !1,
688
732
  serialize: (e) => JSON.stringify(e),
689
733
  deserialize: (e) => {
690
734
  const t = JSON.parse(e);
@@ -693,20 +737,26 @@
693
737
  expiry: 0
694
738
  } : t;
695
739
  }
696
- }), i = (0, t.ref)(o.value.value);
740
+ });
741
+ o.restore();
742
+ const i = (0, t.ref)(o.value.value.value);
697
743
  return (0, t.watch)(i, (e) => {
698
- o.value = {
744
+ o.value.value = {
699
745
  value: e,
700
746
  expiry: Date.now() + r
701
747
  };
702
- }), i;
748
+ }), (0, t.watch)(o.value, (e) => {
749
+ Object.is(i.value, e.value) || (i.value = e.value);
750
+ }, { deep: !0 }), i;
703
751
  }, exports.usePersistedState = function(e) {
704
752
  const { key: r, storage: o = "localStorage", defaultValue: i, serializer: s = u, deserializer: a = l, syncTabs: c = !1, debounce: d = 0, deep: p = !0, ttl: f, onBeforeChange: g, onAfterChange: y, onBeforeRestore: v, onAfterRestore: m } = e, b = (h = o, "undefined" == typeof window ? null : "localStorage" === h ? window.localStorage : window.sessionStorage);
705
753
  var h;
706
- const S = () => (0, n.deepClone)(i), P = (0, t.ref)(S()), w = () => {
754
+ const S = () => (0, n.deepClone)(i), w = (0, t.ref)(S());
755
+ let P = !1;
756
+ const $ = () => {
707
757
  if (b) try {
708
758
  const e = {
709
- value: s(P.value),
759
+ value: s(w.value),
710
760
  timestamp: Date.now(),
711
761
  expiresAt: f ? Date.now() + f : void 0
712
762
  };
@@ -714,43 +764,46 @@
714
764
  } catch (e) {
715
765
  console.error(`[usePersistedState] 保存失败 (${r}):`, e);
716
766
  }
717
- }, $ = () => {
767
+ }, O = d > 0 ? (0, n.debounce)($, d) : null, A = () => {
718
768
  if (b) try {
719
769
  b.removeItem(r);
720
770
  } catch (e) {
721
771
  console.error(`[usePersistedState] 清除失败 (${r}):`, e);
722
772
  }
723
- }, O = () => {
773
+ }, C = () => {
724
774
  if (b) try {
725
775
  const e = b.getItem(r);
726
776
  if (!e) return;
727
777
  const t = JSON.parse(e);
728
- if (t.expiresAt && Date.now() > t.expiresAt) return void $();
778
+ if (t.expiresAt && Date.now() > t.expiresAt) return void A();
729
779
  let n = a(t.value);
730
- v && (n = v(n)), P.value = n, m?.(n);
780
+ v && (n = v(n)), w.value = n, m?.(n);
731
781
  } catch (e) {
732
782
  console.error(`[usePersistedState] 恢复失败 (${r}):`, e);
733
783
  }
734
- }, A = d > 0 ? (0, n.debounce)(w, d) : null, j = (e) => {
735
- if (e.key === r && e.newValue) try {
736
- const t = JSON.parse(e.newValue);
737
- if (t.expiresAt && Date.now() > t.expiresAt) return;
738
- P.value = a(t.value);
739
- } catch (e) {
740
- console.error(`[usePersistedState] 同步失败 (${r}):`, e);
784
+ }, j = (e) => {
785
+ if (e.key === r) {
786
+ if (!e.newValue) return O?.cancel(), P = !0, void (w.value = S());
787
+ try {
788
+ const t = JSON.parse(e.newValue);
789
+ if (t.expiresAt && Date.now() > t.expiresAt) return;
790
+ w.value = a(t.value);
791
+ } catch (e) {
792
+ console.error(`[usePersistedState] 同步失败 (${r}):`, e);
793
+ }
741
794
  }
742
795
  };
743
- return O(), (0, t.watch)(P, (e, t) => {
744
- !1 !== g?.(e, t) && (A ? A() : w(), y?.(e, t));
796
+ return C(), (0, t.watch)(w, (e, t) => {
797
+ P ? P = !1 : !1 !== g?.(e, t) && (O ? O() : $(), y?.(e, t));
745
798
  }, { deep: p }), c && "undefined" != typeof window && window.addEventListener("storage", j), (0, t.onUnmounted)(() => {
746
- A?.cancel(), c && "undefined" != typeof window && window.removeEventListener("storage", j);
799
+ O?.cancel(), c && "undefined" != typeof window && window.removeEventListener("storage", j);
747
800
  }), {
748
- state: P,
749
- save: w,
750
- restore: O,
751
- clear: $,
801
+ state: w,
802
+ save: $,
803
+ restore: C,
804
+ clear: A,
752
805
  reset: () => {
753
- P.value = S(), $();
806
+ O?.cancel(), P = !0, w.value = S(), A();
754
807
  },
755
808
  isExpired: () => {
756
809
  if (!b || !f) return !1;
@@ -766,7 +819,11 @@
766
819
  };
767
820
  }, exports.useSharedState = function(e, r, o = {}) {
768
821
  const { immediate: i = !1, deep: s = !0 } = o, a = (0, t.ref)((0, n.deepClone)(r)), u = (0, t.ref)(0), l = (0, t.ref)(null);
769
- let c = null, d = !1;
822
+ let c = null;
823
+ const d = `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
824
+ let p = 0;
825
+ const f = /* @__PURE__ */ new Map();
826
+ let g, y = !1;
770
827
  if ("undefined" == typeof BroadcastChannel) return console.warn("[useSharedState] BroadcastChannel not supported in this environment"), {
771
828
  state: a,
772
829
  broadcast: () => {},
@@ -785,12 +842,14 @@
785
842
  close: () => {}
786
843
  };
787
844
  }
788
- function p() {
845
+ function v() {
789
846
  if (c) try {
790
847
  c.postMessage({
791
848
  type: "state-update",
792
849
  payload: (0, n.deepClone)(a.value),
793
- timestamp: Date.now()
850
+ timestamp: Date.now(),
851
+ origin: d,
852
+ revision: ++p
794
853
  });
795
854
  } catch (e) {
796
855
  console.warn("[useSharedState] broadcast error:", e);
@@ -798,22 +857,31 @@
798
857
  }
799
858
  c.onmessage = (e) => {
800
859
  const t = e.data;
801
- t && "object" == typeof t && ("state-update" === t.type ? (d = !0, a.value = t.payload, l.value = t.timestamp || Date.now(), d = !1) : "ping" === t.type ? c?.postMessage({ type: "pong" }) : "pong" === t.type && u.value++);
860
+ if (t && "object" == typeof t) if ("state-update" === t.type) {
861
+ if (t.origin === d) return;
862
+ const e = "number" == typeof t.revision ? t.revision : 0;
863
+ if (e <= (f.get(String(t.origin)) ?? -1)) return;
864
+ f.set(String(t.origin), e), g = (0, n.deepClone)(t.payload), y = !0, a.value = g, l.value = t.timestamp || Date.now();
865
+ } else "ping" === t.type ? c?.postMessage({ type: "pong" }) : "pong" === t.type && u.value++;
802
866
  };
803
- const f = (0, t.watch)(a, () => {
804
- d || p();
867
+ const m = (0, t.watch)(a, () => {
868
+ if (y) {
869
+ if ((0, n.deepEqual)(a.value, g)) return void (y = !1);
870
+ y = !1;
871
+ }
872
+ v();
805
873
  }, { deep: s });
806
- function g() {
807
- f(), c && (c.close(), c = null);
874
+ function b() {
875
+ m(), c && (c.close(), c = null);
808
876
  }
809
- return i && p(), c && (u.value = 0, c.postMessage({ type: "ping" })), (0, t.onUnmounted)(() => {
810
- g();
877
+ return i && v(), c && (u.value = 0, c.postMessage({ type: "ping" })), (0, t.onUnmounted)(() => {
878
+ b();
811
879
  }), {
812
880
  state: a,
813
- broadcast: p,
881
+ broadcast: v,
814
882
  peerCount: u,
815
883
  lastSyncAt: l,
816
- close: g
884
+ close: b
817
885
  };
818
886
  }, exports.useSimpleStore = function(e) {
819
887
  const n = (0, t.ref)({ ...e }), r = { ...e };
@@ -896,68 +964,72 @@
896
964
  };
897
965
  }, exports.useStoreSnapshot = function(e, r, o = {}) {
898
966
  const { maxSnapshots: i = 100, autoRecord: s = !1, debounceMs: a = 300, deep: u = !0 } = o, l = (0, t.ref)([]), c = (0, t.ref)(-1);
899
- let d, p = !1;
900
- const g = (0, t.computed)(() => c.value > 0), y = (0, t.computed)(() => c.value < l.value.length - 1), v = (t, r) => {
901
- const o = "function" == typeof e ? e() : e.value, s = {
967
+ let d, p, g = !1;
968
+ const y = () => "function" == typeof e ? e() : e.value, v = (0, t.computed)(() => c.value > 0), m = (0, t.computed)(() => c.value < l.value.length - 1), b = (e, t) => {
969
+ const r = y(), o = {
902
970
  id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
903
- state: (0, n.deepClone)(o),
971
+ state: (0, n.deepClone)(r),
904
972
  timestamp: Date.now(),
905
- label: t,
906
- meta: r
973
+ label: e,
974
+ meta: t
907
975
  };
908
- return c.value < l.value.length - 1 && (l.value = l.value.slice(0, c.value + 1)), l.value.push(s), c.value = l.value.length - 1, l.value.length > i && (l.value.shift(), c.value--), s;
976
+ return c.value < l.value.length - 1 && (l.value = l.value.slice(0, c.value + 1)), l.value.push(o), c.value = l.value.length - 1, l.value.length > i && (l.value.shift(), c.value--), o;
909
977
  };
910
978
  if (s) {
911
- const r = (0, t.watch)("function" == typeof e ? (0, t.computed)(e) : e, (e, t) => {
912
- p || (0, n.deepEqual)(e, t) || (d && clearTimeout(d), d = setTimeout(() => {
913
- v();
979
+ const r = "function" == typeof e ? (0, t.computed)(e) : e;
980
+ p = (0, n.deepClone)(y());
981
+ const o = (0, t.watch)(r, (e, t) => {
982
+ g || (0, n.deepEqual)(e, p ?? t) || (p = (0, n.deepClone)(e), d && clearTimeout(d), d = setTimeout(() => {
983
+ b();
914
984
  }, a));
915
985
  }, { deep: u });
916
- v("初始状态"), (0, t.onUnmounted)(() => {
917
- r(), d && clearTimeout(d);
986
+ b("初始状态"), (0, t.onUnmounted)(() => {
987
+ o(), d && clearTimeout(d);
918
988
  });
919
989
  }
920
990
  return {
921
991
  snapshots: l,
922
992
  currentIndex: c,
923
- canUndo: g,
924
- canRedo: y,
925
- takeSnapshot: v,
993
+ canUndo: v,
994
+ canRedo: m,
995
+ takeSnapshot: b,
926
996
  restoreSnapshot: (e) => {
927
997
  const t = l.value.findIndex((t) => t.id === e);
928
998
  if (-1 === t) return !1;
929
- p = !0;
999
+ g = !0;
930
1000
  try {
931
- return r((0, n.deepClone)(l.value[t].state)), c.value = t, !0;
1001
+ return r((0, n.deepClone)(l.value[t].state)), c.value = t, p = (0, n.deepClone)(y()), !0;
932
1002
  } finally {
933
- p = !1;
1003
+ g = !1;
934
1004
  }
935
1005
  },
936
1006
  undo: () => {
937
- if (!g.value) return !1;
938
- c.value--, p = !0;
1007
+ if (!v.value) return !1;
1008
+ const e = c.value - 1;
1009
+ g = !0;
939
1010
  try {
940
- return r((0, n.deepClone)(l.value[c.value].state)), !0;
1011
+ return r((0, n.deepClone)(l.value[e].state)), c.value = e, p = (0, n.deepClone)(y()), !0;
941
1012
  } finally {
942
- p = !1;
1013
+ g = !1;
943
1014
  }
944
1015
  },
945
1016
  redo: () => {
946
- if (!y.value) return !1;
947
- c.value++, p = !0;
1017
+ if (!m.value) return !1;
1018
+ const e = c.value + 1;
1019
+ g = !0;
948
1020
  try {
949
- return r((0, n.deepClone)(l.value[c.value].state)), !0;
1021
+ return r((0, n.deepClone)(l.value[e].state)), c.value = e, p = (0, n.deepClone)(y()), !0;
950
1022
  } finally {
951
- p = !1;
1023
+ g = !1;
952
1024
  }
953
1025
  },
954
1026
  goto: (e) => {
955
1027
  if (e < 0 || e >= l.value.length) return !1;
956
- c.value = e, p = !0;
1028
+ g = !0;
957
1029
  try {
958
- return r((0, n.deepClone)(l.value[e].state)), !0;
1030
+ return r((0, n.deepClone)(l.value[e].state)), c.value = e, p = (0, n.deepClone)(y()), !0;
959
1031
  } finally {
960
- p = !1;
1032
+ g = !1;
961
1033
  }
962
1034
  },
963
1035
  clearSnapshots: () => {
@@ -1002,7 +1074,7 @@
1002
1074
  return s || (0, t.onUnmounted)(() => {
1003
1075
  a();
1004
1076
  }), a;
1005
- }, exports.version = "1.0.0";
1077
+ }, exports.version = "0.0.1";
1006
1078
  });
1007
1079
  /*! End of @composy/store-vue | Powered by @composy/builder */
1008
1080
  //# sourceMappingURL=index.min.js.map