@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.
- package/CHANGELOG.md +59 -0
- package/README.md +169 -154
- package/dist/index.js +151 -53
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +242 -170
- package/dist/index.min.js.map +1 -1
- package/es/.dts-output-manifest.json +1 -0
- package/es/.dts.tsbuildinfo +1 -0
- package/es/composables/defineSetupStore.d.ts +0 -1
- package/es/composables/defineSetupStore.d.ts.map +1 -1
- package/es/composables/defineSetupStore.js +1 -1
- package/es/composables/defineSetupStore.js.map +1 -1
- package/es/composables/index.d.ts +8 -9
- package/es/composables/index.d.ts.map +1 -1
- package/es/composables/index.js +1 -1
- package/es/composables/useFormStore.d.ts +0 -1
- package/es/composables/useFormStore.d.ts.map +1 -1
- package/es/composables/useFormStore.js +1 -1
- package/es/composables/useFormStore.js.map +1 -1
- package/es/composables/useOptimistic.d.ts +1 -52
- package/es/composables/useOptimistic.d.ts.map +1 -1
- package/es/composables/useOptimistic.js +35 -20
- package/es/composables/useOptimistic.js.map +1 -1
- package/es/composables/usePersist.d.ts +0 -1
- package/es/composables/usePersist.d.ts.map +1 -1
- package/es/composables/usePersist.js +16 -7
- package/es/composables/usePersist.js.map +1 -1
- package/es/composables/usePersistedState.d.ts +0 -1
- package/es/composables/usePersistedState.d.ts.map +1 -1
- package/es/composables/usePersistedState.js +16 -3
- package/es/composables/usePersistedState.js.map +1 -1
- package/es/composables/useSharedState.d.ts +0 -1
- package/es/composables/useSharedState.d.ts.map +1 -1
- package/es/composables/useSharedState.js +25 -8
- package/es/composables/useSharedState.js.map +1 -1
- package/es/composables/useStore.d.ts +0 -1
- package/es/composables/useStore.js +1 -1
- package/es/composables/useStore.js.map +1 -1
- package/es/composables/useStoreDevtools.d.ts +0 -1
- package/es/composables/useStoreDevtools.d.ts.map +1 -1
- package/es/composables/useStoreDevtools.js +1 -1
- package/es/composables/useStoreDevtools.js.map +1 -1
- package/es/composables/useStoreSnapshot.d.ts +0 -1
- package/es/composables/useStoreSnapshot.d.ts.map +1 -1
- package/es/composables/useStoreSnapshot.js +18 -8
- package/es/composables/useStoreSnapshot.js.map +1 -1
- package/es/composables/useSubscribe.d.ts +0 -1
- package/es/composables/useSubscribe.d.ts.map +1 -1
- package/es/composables/useSubscribe.js +1 -1
- package/es/composables/useSubscribe.js.map +1 -1
- package/es/context/injection-keys.d.ts +0 -1
- package/es/context/injection-keys.d.ts.map +1 -1
- package/es/context/injection-keys.js +1 -1
- package/es/context/injection-keys.js.map +1 -1
- package/es/index.d.ts +1 -2
- package/es/index.js +2 -2
- package/es/index.js.map +1 -1
- package/es/plugins/engine-plugin.d.ts +1 -2
- package/es/plugins/engine-plugin.d.ts.map +1 -1
- package/es/plugins/engine-plugin.js +2 -2
- package/es/plugins/engine-plugin.js.map +1 -1
- package/es/plugins/enhanced-persist-plugin.d.ts +0 -1
- package/es/plugins/enhanced-persist-plugin.js +1 -1
- package/es/plugins/index.d.ts +0 -1
- package/es/plugins/index.js +1 -1
- package/es/plugins/pinia-plugin.d.ts +0 -1
- package/es/plugins/pinia-plugin.d.ts.map +1 -1
- package/es/plugins/pinia-plugin.js +24 -6
- package/es/plugins/pinia-plugin.js.map +1 -1
- package/es/plugins/registry-plugin.d.ts +0 -1
- package/es/plugins/registry-plugin.js +1 -1
- package/es/plugins/vue-plugin.d.ts +0 -1
- package/es/plugins/vue-plugin.d.ts.map +1 -1
- package/es/plugins/vue-plugin.js +1 -1
- package/es/plugins/vue-plugin.js.map +1 -1
- package/es/runtime/install-store-app.d.ts +0 -1
- package/es/runtime/install-store-app.js +1 -1
- package/es/runtime/install-store-app.js.map +1 -1
- package/es/runtime/store-plugin-options.d.ts +0 -1
- package/es/runtime/store-plugin-options.js +1 -1
- package/es/runtime/store-plugin-options.js.map +1 -1
- package/es/runtime/store-registry.d.ts +0 -1
- package/es/runtime/store-registry.d.ts.map +1 -1
- package/es/runtime/store-registry.js +14 -4
- package/es/runtime/store-registry.js.map +1 -1
- package/es/runtime/store-runtime.d.ts +1 -2
- package/es/runtime/store-runtime.d.ts.map +1 -1
- package/es/runtime/store-runtime.js +8 -2
- package/es/runtime/store-runtime.js.map +1 -1
- package/es/types.d.ts +2 -1
- package/es/types.d.ts.map +1 -1
- package/es/types.js +1 -1
- package/esm/composables/defineSetupStore.d.ts.map +1 -1
- package/esm/composables/defineSetupStore.js +1 -1
- package/esm/composables/defineSetupStore.js.map +1 -1
- package/esm/composables/index.d.ts +8 -8
- package/esm/composables/index.d.ts.map +1 -1
- package/esm/composables/index.js +1 -1
- package/esm/composables/useFormStore.d.ts.map +1 -1
- package/esm/composables/useFormStore.js +1 -1
- package/esm/composables/useFormStore.js.map +1 -1
- package/esm/composables/useOptimistic.d.ts +1 -51
- package/esm/composables/useOptimistic.d.ts.map +1 -1
- package/esm/composables/useOptimistic.js +35 -20
- package/esm/composables/useOptimistic.js.map +1 -1
- package/esm/composables/usePersist.d.ts.map +1 -1
- package/esm/composables/usePersist.js +16 -7
- package/esm/composables/usePersist.js.map +1 -1
- package/esm/composables/usePersistedState.d.ts.map +1 -1
- package/esm/composables/usePersistedState.js +16 -3
- package/esm/composables/usePersistedState.js.map +1 -1
- package/esm/composables/useSharedState.d.ts.map +1 -1
- package/esm/composables/useSharedState.js +25 -8
- package/esm/composables/useSharedState.js.map +1 -1
- package/esm/composables/useStore.js +1 -1
- package/esm/composables/useStore.js.map +1 -1
- package/esm/composables/useStoreDevtools.d.ts.map +1 -1
- package/esm/composables/useStoreDevtools.js +1 -1
- package/esm/composables/useStoreDevtools.js.map +1 -1
- package/esm/composables/useStoreSnapshot.d.ts.map +1 -1
- package/esm/composables/useStoreSnapshot.js +18 -8
- package/esm/composables/useStoreSnapshot.js.map +1 -1
- package/esm/composables/useSubscribe.d.ts.map +1 -1
- package/esm/composables/useSubscribe.js +1 -1
- package/esm/composables/useSubscribe.js.map +1 -1
- package/esm/context/injection-keys.d.ts.map +1 -1
- package/esm/context/injection-keys.js +1 -1
- package/esm/context/injection-keys.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/plugins/engine-plugin.d.ts +1 -1
- package/esm/plugins/engine-plugin.d.ts.map +1 -1
- package/esm/plugins/engine-plugin.js +2 -2
- package/esm/plugins/engine-plugin.js.map +1 -1
- package/esm/plugins/enhanced-persist-plugin.js +1 -1
- package/esm/plugins/index.js +1 -1
- package/esm/plugins/pinia-plugin.d.ts.map +1 -1
- package/esm/plugins/pinia-plugin.js +24 -6
- package/esm/plugins/pinia-plugin.js.map +1 -1
- package/esm/plugins/registry-plugin.js +1 -1
- package/esm/plugins/vue-plugin.d.ts.map +1 -1
- package/esm/plugins/vue-plugin.js +1 -1
- package/esm/plugins/vue-plugin.js.map +1 -1
- package/esm/runtime/install-store-app.js +1 -1
- package/esm/runtime/install-store-app.js.map +1 -1
- package/esm/runtime/store-plugin-options.js +1 -1
- package/esm/runtime/store-plugin-options.js.map +1 -1
- package/esm/runtime/store-registry.d.ts.map +1 -1
- package/esm/runtime/store-registry.js +14 -4
- package/esm/runtime/store-registry.js.map +1 -1
- package/esm/runtime/store-runtime.d.ts +1 -1
- package/esm/runtime/store-runtime.d.ts.map +1 -1
- package/esm/runtime/store-runtime.js +8 -2
- package/esm/runtime/store-runtime.js.map +1 -1
- package/esm/types.d.ts +2 -0
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +1 -1
- package/lib/composables/defineSetupStore.cjs +1 -1
- package/lib/composables/defineSetupStore.cjs.map +1 -1
- package/lib/composables/{defineSetupStore.d.ts → defineSetupStore.d.cts} +0 -1
- package/lib/composables/defineSetupStore.d.cts.map +1 -0
- package/lib/composables/index.cjs +1 -1
- package/lib/composables/{index.d.ts → index.d.cts} +8 -9
- package/lib/composables/index.d.cts.map +1 -0
- package/lib/composables/useFormStore.cjs +1 -1
- package/lib/composables/useFormStore.cjs.map +1 -1
- package/lib/composables/{useFormStore.d.ts → useFormStore.d.cts} +0 -1
- package/lib/composables/useFormStore.d.cts.map +1 -0
- package/lib/composables/useOptimistic.cjs +35 -20
- package/lib/composables/useOptimistic.cjs.map +1 -1
- package/lib/composables/useOptimistic.d.cts +16 -0
- package/lib/composables/useOptimistic.d.cts.map +1 -0
- package/lib/composables/usePersist.cjs +16 -7
- package/lib/composables/usePersist.cjs.map +1 -1
- package/lib/composables/{usePersist.d.ts → usePersist.d.cts} +0 -1
- package/lib/composables/usePersist.d.cts.map +1 -0
- package/lib/composables/usePersistedState.cjs +16 -3
- package/lib/composables/usePersistedState.cjs.map +1 -1
- package/lib/composables/{usePersistedState.d.ts → usePersistedState.d.cts} +0 -1
- package/lib/composables/usePersistedState.d.cts.map +1 -0
- package/lib/composables/useSharedState.cjs +24 -7
- package/lib/composables/useSharedState.cjs.map +1 -1
- package/lib/composables/{useSharedState.d.ts → useSharedState.d.cts} +0 -1
- package/lib/composables/useSharedState.d.cts.map +1 -0
- package/lib/composables/useStore.cjs +1 -1
- package/lib/composables/useStore.cjs.map +1 -1
- package/lib/composables/{useStore.d.ts → useStore.d.cts} +0 -1
- package/lib/composables/useStore.d.cts.map +1 -0
- package/lib/composables/useStoreDevtools.cjs +1 -1
- package/lib/composables/useStoreDevtools.cjs.map +1 -1
- package/lib/composables/{useStoreDevtools.d.ts → useStoreDevtools.d.cts} +0 -1
- package/lib/composables/useStoreDevtools.d.cts.map +1 -0
- package/lib/composables/useStoreSnapshot.cjs +18 -8
- package/lib/composables/useStoreSnapshot.cjs.map +1 -1
- package/lib/composables/{useStoreSnapshot.d.ts → useStoreSnapshot.d.cts} +0 -1
- package/lib/composables/useStoreSnapshot.d.cts.map +1 -0
- package/lib/composables/useSubscribe.cjs +1 -1
- package/lib/composables/useSubscribe.cjs.map +1 -1
- package/lib/composables/{useSubscribe.d.ts → useSubscribe.d.cts} +0 -1
- package/lib/composables/useSubscribe.d.cts.map +1 -0
- package/lib/context/injection-keys.cjs +1 -1
- package/lib/context/injection-keys.cjs.map +1 -1
- package/lib/context/{injection-keys.d.ts → injection-keys.d.cts} +0 -1
- package/lib/context/injection-keys.d.cts.map +1 -0
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/{index.d.ts → index.d.cts} +1 -2
- package/lib/index.d.cts.map +1 -0
- package/lib/plugins/engine-plugin.cjs +2 -2
- package/lib/plugins/engine-plugin.cjs.map +1 -1
- package/lib/plugins/{engine-plugin.d.ts → engine-plugin.d.cts} +1 -2
- package/lib/plugins/engine-plugin.d.cts.map +1 -0
- package/lib/plugins/enhanced-persist-plugin.cjs +1 -1
- package/lib/plugins/{enhanced-persist-plugin.d.ts → enhanced-persist-plugin.d.cts} +0 -1
- package/lib/plugins/enhanced-persist-plugin.d.cts.map +1 -0
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/{index.d.ts → index.d.cts} +0 -1
- package/lib/plugins/index.d.cts.map +1 -0
- package/lib/plugins/pinia-plugin.cjs +24 -6
- package/lib/plugins/pinia-plugin.cjs.map +1 -1
- package/lib/plugins/{pinia-plugin.d.ts → pinia-plugin.d.cts} +0 -1
- package/lib/plugins/pinia-plugin.d.cts.map +1 -0
- package/lib/plugins/registry-plugin.cjs +1 -1
- package/lib/plugins/{registry-plugin.d.ts → registry-plugin.d.cts} +0 -1
- package/lib/plugins/registry-plugin.d.cts.map +1 -0
- package/lib/plugins/vue-plugin.cjs +1 -1
- package/lib/plugins/vue-plugin.cjs.map +1 -1
- package/lib/plugins/{vue-plugin.d.ts → vue-plugin.d.cts} +0 -1
- package/lib/plugins/vue-plugin.d.cts.map +1 -0
- package/lib/runtime/install-store-app.cjs +1 -1
- package/lib/runtime/install-store-app.cjs.map +1 -1
- package/lib/runtime/{install-store-app.d.ts → install-store-app.d.cts} +0 -1
- package/lib/runtime/install-store-app.d.cts.map +1 -0
- package/lib/runtime/store-plugin-options.cjs +1 -1
- package/lib/runtime/store-plugin-options.cjs.map +1 -1
- package/lib/runtime/{store-plugin-options.d.ts → store-plugin-options.d.cts} +0 -1
- package/lib/runtime/store-plugin-options.d.cts.map +1 -0
- package/lib/runtime/store-registry.cjs +14 -4
- package/lib/runtime/store-registry.cjs.map +1 -1
- package/lib/runtime/{store-registry.d.ts → store-registry.d.cts} +0 -1
- package/lib/runtime/store-registry.d.cts.map +1 -0
- package/lib/runtime/store-runtime.cjs +8 -2
- package/lib/runtime/store-runtime.cjs.map +1 -1
- package/lib/runtime/{store-runtime.d.ts → store-runtime.d.cts} +1 -2
- package/lib/runtime/store-runtime.d.cts.map +1 -0
- package/lib/types.cjs +1 -1
- package/lib/{types.d.ts → types.d.cts} +2 -1
- package/lib/types.d.cts.map +1 -0
- package/package.json +19 -16
- 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-
|
|
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.
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 (
|
|
37
|
-
|
|
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 (
|
|
52
|
-
|
|
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()
|
|
132
|
-
|
|
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(
|
|
141
|
+
b.add(c);
|
|
135
142
|
return {
|
|
136
143
|
plugin: (e) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
160
|
+
w = !0;
|
|
148
161
|
try {
|
|
149
|
-
|
|
162
|
+
p.beforeRestore?.({ store: c }), function(e, t) {
|
|
150
163
|
e.$patch((e) => {
|
|
151
164
|
(0, n.deepMerge)(e, t);
|
|
152
165
|
});
|
|
153
|
-
}(
|
|
166
|
+
}(c, t), p.afterRestore?.({ store: c });
|
|
154
167
|
} finally {
|
|
155
|
-
|
|
168
|
+
w = !1;
|
|
156
169
|
}
|
|
157
170
|
}, $ = (0, n.debounce)(() => {
|
|
158
|
-
if (!
|
|
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
|
-
}(
|
|
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
|
-
|
|
193
|
+
g.setItem(S, JSON.stringify(t)), i && console.info(`[PersistPlugin] 已保存状态 (${c.$id})`);
|
|
181
194
|
} catch (e) {
|
|
182
|
-
console.error(`[PersistPlugin] 保存状态失败 (${
|
|
195
|
+
console.error(`[PersistPlugin] 保存状态失败 (${c.$id}):`, e);
|
|
183
196
|
}
|
|
184
|
-
},
|
|
185
|
-
|
|
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
|
|
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
|
-
|
|
206
|
+
P(t.state);
|
|
194
207
|
} catch (e) {
|
|
195
|
-
console.error(`[PersistPlugin] 同步状态失败 (${
|
|
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
|
|
203
|
-
$.cancel(), O(), A(), u.delete(
|
|
223
|
+
const C = () => {
|
|
224
|
+
$.cancel(), O(), A(), u.delete(c), c[m]?.();
|
|
204
225
|
};
|
|
205
|
-
u.set(
|
|
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
|
-
}(
|
|
235
|
+
}(c, C), (() => {
|
|
215
236
|
try {
|
|
216
|
-
const e =
|
|
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
|
|
220
|
-
|
|
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] 恢复状态失败 (${
|
|
243
|
+
console.error(`[PersistPlugin] 恢复状态失败 (${c.$id}):`, e);
|
|
223
244
|
}
|
|
224
245
|
})();
|
|
225
246
|
},
|
|
226
|
-
dispose:
|
|
247
|
+
dispose: c
|
|
227
248
|
};
|
|
228
249
|
}
|
|
229
250
|
const S = Symbol("ldesign-store-registry-dispose");
|
|
230
|
-
function
|
|
231
|
-
const e = /* @__PURE__ */ new Map(), t = (t) => {
|
|
232
|
-
e.
|
|
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.
|
|
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(
|
|
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.
|
|
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
|
|
275
|
-
function $(e =
|
|
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
|
|
283
|
-
|
|
307
|
+
function C(e) {
|
|
308
|
+
var t;
|
|
309
|
+
A = e, (t = e?.registry ?? null) !== P && (P.clear(), P = t ?? w());
|
|
284
310
|
}
|
|
285
|
-
function
|
|
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 =
|
|
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(
|
|
302
|
-
|
|
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] ===
|
|
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] =
|
|
341
|
+
return r[O] = u, u;
|
|
312
342
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
315
|
-
const n = e, r = n[
|
|
316
|
-
return r ? (
|
|
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[
|
|
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[
|
|
351
|
+
return e[M] === t && (delete e[M], t.dispose()), n.call(this);
|
|
322
352
|
};
|
|
323
|
-
}(n, t),
|
|
353
|
+
}(n, t), C(t), t);
|
|
324
354
|
}
|
|
325
|
-
function
|
|
355
|
+
function E(e) {
|
|
326
356
|
return !!e && "function" == typeof e.use;
|
|
327
357
|
}
|
|
328
|
-
function
|
|
358
|
+
function V(e, t, n) {
|
|
329
359
|
const r = n, o = r?.app ?? r?.framework?.app ?? e.getApp?.() ?? t.framework?.app;
|
|
330
|
-
return
|
|
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 = "
|
|
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: () =>
|
|
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) =>
|
|
449
|
+
attachToApp: (e, t) => x(e, t),
|
|
420
450
|
getRuntimeFromApp: (e) => function(e) {
|
|
421
|
-
return e[
|
|
451
|
+
return e[M];
|
|
422
452
|
}(e),
|
|
423
|
-
isApp:
|
|
424
|
-
resolveApp:
|
|
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 =
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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))
|
|
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:
|
|
649
|
-
pending:
|
|
650
|
-
isRolledBack:
|
|
690
|
+
isPending: s,
|
|
691
|
+
pending: u,
|
|
692
|
+
isRolledBack: a,
|
|
651
693
|
mutate: async function(e, t) {
|
|
652
|
-
const
|
|
653
|
-
id:
|
|
654
|
-
snapshot:
|
|
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
|
-
|
|
701
|
+
i.push(c), a.value = !1, l();
|
|
659
702
|
try {
|
|
660
|
-
await t(),
|
|
661
|
-
...e,
|
|
662
|
-
status: "confirmed"
|
|
663
|
-
} : e);
|
|
703
|
+
await t(), c.status = "confirmed";
|
|
664
704
|
} catch {
|
|
665
|
-
|
|
666
|
-
...e,
|
|
667
|
-
status: "rolled-back"
|
|
668
|
-
} : e);
|
|
705
|
+
c.status = "rolled-back", a.value = !0;
|
|
669
706
|
} finally {
|
|
670
|
-
|
|
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
|
|
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
|
-
})
|
|
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
|
-
}),
|
|
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),
|
|
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(
|
|
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
|
-
},
|
|
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)),
|
|
780
|
+
v && (n = v(n)), w.value = n, m?.(n);
|
|
731
781
|
} catch (e) {
|
|
732
782
|
console.error(`[usePersistedState] 恢复失败 (${r}):`, e);
|
|
733
783
|
}
|
|
734
|
-
},
|
|
735
|
-
if (e.key === r
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
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
|
|
744
|
-
!1 !== g?.(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
|
-
|
|
799
|
+
O?.cancel(), c && "undefined" != typeof window && window.removeEventListener("storage", j);
|
|
747
800
|
}), {
|
|
748
|
-
state:
|
|
749
|
-
save:
|
|
750
|
-
restore:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
804
|
-
|
|
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
|
|
807
|
-
|
|
874
|
+
function b() {
|
|
875
|
+
m(), c && (c.close(), c = null);
|
|
808
876
|
}
|
|
809
|
-
return i &&
|
|
810
|
-
|
|
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:
|
|
881
|
+
broadcast: v,
|
|
814
882
|
peerCount: u,
|
|
815
883
|
lastSyncAt: l,
|
|
816
|
-
close:
|
|
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
|
|
901
|
-
const
|
|
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)(
|
|
971
|
+
state: (0, n.deepClone)(r),
|
|
904
972
|
timestamp: Date.now(),
|
|
905
|
-
label:
|
|
906
|
-
meta:
|
|
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(
|
|
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 =
|
|
912
|
-
|
|
913
|
-
|
|
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
|
-
|
|
917
|
-
|
|
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:
|
|
924
|
-
canRedo:
|
|
925
|
-
takeSnapshot:
|
|
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
|
-
|
|
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
|
-
|
|
1003
|
+
g = !1;
|
|
934
1004
|
}
|
|
935
1005
|
},
|
|
936
1006
|
undo: () => {
|
|
937
|
-
if (!
|
|
938
|
-
c.value
|
|
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
|
|
1011
|
+
return r((0, n.deepClone)(l.value[e].state)), c.value = e, p = (0, n.deepClone)(y()), !0;
|
|
941
1012
|
} finally {
|
|
942
|
-
|
|
1013
|
+
g = !1;
|
|
943
1014
|
}
|
|
944
1015
|
},
|
|
945
1016
|
redo: () => {
|
|
946
|
-
if (!
|
|
947
|
-
c.value
|
|
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
|
|
1021
|
+
return r((0, n.deepClone)(l.value[e].state)), c.value = e, p = (0, n.deepClone)(y()), !0;
|
|
950
1022
|
} finally {
|
|
951
|
-
|
|
1023
|
+
g = !1;
|
|
952
1024
|
}
|
|
953
1025
|
},
|
|
954
1026
|
goto: (e) => {
|
|
955
1027
|
if (e < 0 || e >= l.value.length) return !1;
|
|
956
|
-
|
|
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
|
-
|
|
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 = "
|
|
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
|