@composy/store-core 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.
- package/CHANGELOG.md +5 -0
- package/README.md +172 -0
- package/dist/index.js +1852 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1082 -0
- package/dist/index.min.js.map +1 -0
- package/es/core/async-action.d.ts +95 -0
- package/es/core/async-action.d.ts.map +1 -0
- package/es/core/async-action.js +116 -0
- package/es/core/async-action.js.map +1 -0
- package/es/core/base-store.d.ts +85 -0
- package/es/core/base-store.d.ts.map +1 -0
- package/es/core/base-store.js +185 -0
- package/es/core/base-store.js.map +1 -0
- package/es/core/batch-manager.d.ts +46 -0
- package/es/core/batch-manager.d.ts.map +1 -0
- package/es/core/batch-manager.js +64 -0
- package/es/core/batch-manager.js.map +1 -0
- package/es/core/create-store.d.ts +66 -0
- package/es/core/create-store.d.ts.map +1 -0
- package/es/core/create-store.js +29 -0
- package/es/core/create-store.js.map +1 -0
- package/es/core/event-bus.d.ts +34 -0
- package/es/core/event-bus.d.ts.map +1 -0
- package/es/core/event-bus.js +71 -0
- package/es/core/event-bus.js.map +1 -0
- package/es/core/index.d.ts +14 -0
- package/es/core/index.d.ts.map +1 -0
- package/es/core/index.js +17 -0
- package/es/core/pub-sub.d.ts +41 -0
- package/es/core/pub-sub.d.ts.map +1 -0
- package/es/core/pub-sub.js +71 -0
- package/es/core/pub-sub.js.map +1 -0
- package/es/engine/index.d.ts +10 -0
- package/es/engine/index.d.ts.map +1 -0
- package/es/engine/index.js +12 -0
- package/es/engine/plugin.d.ts +20 -0
- package/es/engine/plugin.d.ts.map +1 -0
- package/es/engine/plugin.js +153 -0
- package/es/engine/plugin.js.map +1 -0
- package/es/engine/types.d.ts +81 -0
- package/es/engine/types.d.ts.map +1 -0
- package/es/engine/types.js +10 -0
- package/es/errors/index.d.ts +208 -0
- package/es/errors/index.d.ts.map +1 -0
- package/es/errors/index.js +217 -0
- package/es/errors/index.js.map +1 -0
- package/es/index.d.ts +27 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +34 -0
- package/es/index.js.map +1 -0
- package/es/middleware/index.d.ts +13 -0
- package/es/middleware/index.d.ts.map +1 -0
- package/es/middleware/index.js +16 -0
- package/es/middleware/logger.d.ts +67 -0
- package/es/middleware/logger.d.ts.map +1 -0
- package/es/middleware/logger.js +136 -0
- package/es/middleware/logger.js.map +1 -0
- package/es/middleware/middleware-manager.d.ts +40 -0
- package/es/middleware/middleware-manager.d.ts.map +1 -0
- package/es/middleware/middleware-manager.js +79 -0
- package/es/middleware/middleware-manager.js.map +1 -0
- package/es/middleware/persist.d.ts +34 -0
- package/es/middleware/persist.d.ts.map +1 -0
- package/es/middleware/persist.js +102 -0
- package/es/middleware/persist.js.map +1 -0
- package/es/middleware/time-travel.d.ts +30 -0
- package/es/middleware/time-travel.d.ts.map +1 -0
- package/es/middleware/time-travel.js +151 -0
- package/es/middleware/time-travel.js.map +1 -0
- package/es/middleware/validation.d.ts +100 -0
- package/es/middleware/validation.d.ts.map +1 -0
- package/es/middleware/validation.js +74 -0
- package/es/middleware/validation.js.map +1 -0
- package/es/plugins/define-plugin.d.ts +74 -0
- package/es/plugins/define-plugin.d.ts.map +1 -0
- package/es/plugins/define-plugin.js +52 -0
- package/es/plugins/define-plugin.js.map +1 -0
- package/es/plugins/index.d.ts +8 -0
- package/es/plugins/index.d.ts.map +1 -0
- package/es/plugins/index.js +13 -0
- package/es/plugins/plugin-manager.d.ts +35 -0
- package/es/plugins/plugin-manager.d.ts.map +1 -0
- package/es/plugins/plugin-manager.js +77 -0
- package/es/plugins/plugin-manager.js.map +1 -0
- package/es/types/index.d.ts +12 -0
- package/es/types/index.d.ts.map +1 -0
- package/es/types/index.js +10 -0
- package/es/types/middleware.d.ts +172 -0
- package/es/types/middleware.d.ts.map +1 -0
- package/es/types/middleware.js +10 -0
- package/es/types/plugin.d.ts +136 -0
- package/es/types/plugin.d.ts.map +1 -0
- package/es/types/plugin.js +10 -0
- package/es/types/store.d.ts +198 -0
- package/es/types/store.d.ts.map +1 -0
- package/es/types/store.js +10 -0
- package/es/types/subscription.d.ts +158 -0
- package/es/types/subscription.d.ts.map +1 -0
- package/es/types/subscription.js +10 -0
- package/es/types/utility.d.ts +312 -0
- package/es/types/utility.d.ts.map +1 -0
- package/es/types/utility.js +10 -0
- package/es/utils/debounce-throttle.d.ts +86 -0
- package/es/utils/debounce-throttle.d.ts.map +1 -0
- package/es/utils/debounce-throttle.js +86 -0
- package/es/utils/debounce-throttle.js.map +1 -0
- package/es/utils/deep-clone.d.ts +143 -0
- package/es/utils/deep-clone.d.ts.map +1 -0
- package/es/utils/deep-clone.js +193 -0
- package/es/utils/deep-clone.js.map +1 -0
- package/es/utils/index.d.ts +13 -0
- package/es/utils/index.d.ts.map +1 -0
- package/es/utils/index.js +14 -0
- package/es/utils/selector.d.ts +213 -0
- package/es/utils/selector.d.ts.map +1 -0
- package/es/utils/selector.js +151 -0
- package/es/utils/selector.js.map +1 -0
- package/esm/core/async-action.d.ts +95 -0
- package/esm/core/async-action.js +116 -0
- package/esm/core/async-action.js.map +1 -0
- package/esm/core/base-store.d.ts +85 -0
- package/esm/core/base-store.js +185 -0
- package/esm/core/base-store.js.map +1 -0
- package/esm/core/batch-manager.d.ts +46 -0
- package/esm/core/batch-manager.js +64 -0
- package/esm/core/batch-manager.js.map +1 -0
- package/esm/core/create-store.d.ts +66 -0
- package/esm/core/create-store.js +29 -0
- package/esm/core/create-store.js.map +1 -0
- package/esm/core/event-bus.d.ts +34 -0
- package/esm/core/event-bus.js +71 -0
- package/esm/core/event-bus.js.map +1 -0
- package/esm/core/index.d.ts +14 -0
- package/esm/core/index.js +17 -0
- package/esm/core/pub-sub.d.ts +41 -0
- package/esm/core/pub-sub.js +71 -0
- package/esm/core/pub-sub.js.map +1 -0
- package/esm/engine/index.d.ts +10 -0
- package/esm/engine/index.js +12 -0
- package/esm/engine/plugin.d.ts +20 -0
- package/esm/engine/plugin.js +153 -0
- package/esm/engine/plugin.js.map +1 -0
- package/esm/engine/types.d.ts +81 -0
- package/esm/errors/index.d.ts +208 -0
- package/esm/errors/index.js +217 -0
- package/esm/errors/index.js.map +1 -0
- package/esm/index.d.ts +27 -0
- package/esm/index.js +36 -0
- package/esm/index.js.map +1 -0
- package/esm/middleware/index.d.ts +13 -0
- package/esm/middleware/logger.d.ts +67 -0
- package/esm/middleware/logger.js +119 -0
- package/esm/middleware/logger.js.map +1 -0
- package/esm/middleware/middleware-manager.d.ts +40 -0
- package/esm/middleware/middleware-manager.js +79 -0
- package/esm/middleware/middleware-manager.js.map +1 -0
- package/esm/middleware/persist.d.ts +34 -0
- package/esm/middleware/persist.js +102 -0
- package/esm/middleware/persist.js.map +1 -0
- package/esm/middleware/time-travel.d.ts +30 -0
- package/esm/middleware/time-travel.js +151 -0
- package/esm/middleware/time-travel.js.map +1 -0
- package/esm/middleware/validation.d.ts +100 -0
- package/esm/middleware/validation.js +74 -0
- package/esm/middleware/validation.js.map +1 -0
- package/esm/plugins/define-plugin.d.ts +74 -0
- package/esm/plugins/define-plugin.js +52 -0
- package/esm/plugins/define-plugin.js.map +1 -0
- package/esm/plugins/index.d.ts +8 -0
- package/esm/plugins/plugin-manager.d.ts +35 -0
- package/esm/plugins/plugin-manager.js +77 -0
- package/esm/plugins/plugin-manager.js.map +1 -0
- package/esm/types/index.d.ts +12 -0
- package/esm/types/middleware.d.ts +172 -0
- package/esm/types/plugin.d.ts +136 -0
- package/esm/types/store.d.ts +198 -0
- package/esm/types/subscription.d.ts +158 -0
- package/esm/types/utility.d.ts +312 -0
- package/esm/utils/debounce-throttle.d.ts +86 -0
- package/esm/utils/debounce-throttle.js +86 -0
- package/esm/utils/debounce-throttle.js.map +1 -0
- package/esm/utils/deep-clone.d.ts +143 -0
- package/esm/utils/deep-clone.js +193 -0
- package/esm/utils/deep-clone.js.map +1 -0
- package/esm/utils/index.d.ts +13 -0
- package/esm/utils/selector.d.ts +213 -0
- package/esm/utils/selector.js +151 -0
- package/esm/utils/selector.js.map +1 -0
- package/lib/core/async-action.cjs +118 -0
- package/lib/core/async-action.cjs.map +1 -0
- package/lib/core/async-action.d.ts +95 -0
- package/lib/core/base-store.cjs +187 -0
- package/lib/core/base-store.cjs.map +1 -0
- package/lib/core/base-store.d.ts +85 -0
- package/lib/core/batch-manager.cjs +69 -0
- package/lib/core/batch-manager.cjs.map +1 -0
- package/lib/core/batch-manager.d.ts +46 -0
- package/lib/core/create-store.cjs +31 -0
- package/lib/core/create-store.cjs.map +1 -0
- package/lib/core/create-store.d.ts +66 -0
- package/lib/core/event-bus.cjs +74 -0
- package/lib/core/event-bus.cjs.map +1 -0
- package/lib/core/event-bus.d.ts +34 -0
- package/lib/core/index.cjs +29 -0
- package/lib/core/index.d.ts +14 -0
- package/lib/core/pub-sub.cjs +74 -0
- package/lib/core/pub-sub.cjs.map +1 -0
- package/lib/core/pub-sub.d.ts +41 -0
- package/lib/engine/index.cjs +16 -0
- package/lib/engine/index.d.ts +10 -0
- package/lib/engine/plugin.cjs +157 -0
- package/lib/engine/plugin.cjs.map +1 -0
- package/lib/engine/plugin.d.ts +20 -0
- package/lib/engine/types.cjs +12 -0
- package/lib/engine/types.d.ts +81 -0
- package/lib/errors/index.cjs +233 -0
- package/lib/errors/index.cjs.map +1 -0
- package/lib/errors/index.d.ts +208 -0
- package/lib/index.cjs +101 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +27 -0
- package/lib/middleware/index.cjs +28 -0
- package/lib/middleware/index.d.ts +13 -0
- package/lib/middleware/logger.cjs +140 -0
- package/lib/middleware/logger.cjs.map +1 -0
- package/lib/middleware/logger.d.ts +67 -0
- package/lib/middleware/middleware-manager.cjs +83 -0
- package/lib/middleware/middleware-manager.cjs.map +1 -0
- package/lib/middleware/middleware-manager.d.ts +40 -0
- package/lib/middleware/persist.cjs +105 -0
- package/lib/middleware/persist.cjs.map +1 -0
- package/lib/middleware/persist.d.ts +34 -0
- package/lib/middleware/time-travel.cjs +154 -0
- package/lib/middleware/time-travel.cjs.map +1 -0
- package/lib/middleware/time-travel.d.ts +30 -0
- package/lib/middleware/validation.cjs +76 -0
- package/lib/middleware/validation.cjs.map +1 -0
- package/lib/middleware/validation.d.ts +100 -0
- package/lib/package.json +3 -0
- package/lib/plugins/define-plugin.cjs +56 -0
- package/lib/plugins/define-plugin.cjs.map +1 -0
- package/lib/plugins/define-plugin.d.ts +74 -0
- package/lib/plugins/index.cjs +20 -0
- package/lib/plugins/index.d.ts +8 -0
- package/lib/plugins/plugin-manager.cjs +81 -0
- package/lib/plugins/plugin-manager.cjs.map +1 -0
- package/lib/plugins/plugin-manager.d.ts +35 -0
- package/lib/types/index.cjs +12 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/middleware.cjs +12 -0
- package/lib/types/middleware.d.ts +172 -0
- package/lib/types/plugin.cjs +12 -0
- package/lib/types/plugin.d.ts +136 -0
- package/lib/types/store.cjs +12 -0
- package/lib/types/store.d.ts +198 -0
- package/lib/types/subscription.cjs +12 -0
- package/lib/types/subscription.d.ts +158 -0
- package/lib/types/utility.cjs +12 -0
- package/lib/types/utility.d.ts +312 -0
- package/lib/utils/debounce-throttle.cjs +89 -0
- package/lib/utils/debounce-throttle.cjs.map +1 -0
- package/lib/utils/debounce-throttle.d.ts +86 -0
- package/lib/utils/deep-clone.cjs +202 -0
- package/lib/utils/deep-clone.cjs.map +1 -0
- package/lib/utils/deep-clone.d.ts +143 -0
- package/lib/utils/index.cjs +34 -0
- package/lib/utils/index.d.ts +13 -0
- package/lib/utils/selector.cjs +161 -0
- package/lib/utils/selector.cjs.map +1 -0
- package/lib/utils/selector.d.ts +213 -0
- package/package.json +155 -0
|
@@ -0,0 +1,1082 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ***********************************
|
|
3
|
+
* @composy/store-core v0.0.1 *
|
|
4
|
+
* Built with rollup *
|
|
5
|
+
* Build time: 2024-08-17 11:27:33 *
|
|
6
|
+
* Build mode: production *
|
|
7
|
+
* Minified: No *
|
|
8
|
+
* ***********************************
|
|
9
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
(function(t, e) {
|
|
12
|
+
"object" == typeof exports && "undefined" != typeof module ? e(exports) : "function" == typeof define && define.amd ? define(["exports"], e) : e((t = "undefined" != typeof globalThis ? globalThis : t || self).LDesignStoreCore = {});
|
|
13
|
+
})(this, function(exports) {
|
|
14
|
+
function t() {
|
|
15
|
+
const t = /* @__PURE__ */ new Set();
|
|
16
|
+
return {
|
|
17
|
+
subscribe: (e, r = {}) => {
|
|
18
|
+
const n = {
|
|
19
|
+
callback: e,
|
|
20
|
+
options: r
|
|
21
|
+
};
|
|
22
|
+
return t.add(n), () => {
|
|
23
|
+
t.delete(n);
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
publish: (e, r) => {
|
|
27
|
+
t.forEach((t) => {
|
|
28
|
+
try {
|
|
29
|
+
t.callback(e, r);
|
|
30
|
+
} catch (t) {
|
|
31
|
+
console.error("[PubSub] 订阅回调执行出错:", t);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
clear: () => {
|
|
36
|
+
t.clear();
|
|
37
|
+
},
|
|
38
|
+
size: () => t.size
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function e() {
|
|
42
|
+
const t = /* @__PURE__ */ new Map(), e = (e, r) => {
|
|
43
|
+
const n = ((e) => {
|
|
44
|
+
let r = t.get(e);
|
|
45
|
+
return r || (r = /* @__PURE__ */ new Set(), t.set(e, r)), r;
|
|
46
|
+
})(e);
|
|
47
|
+
return n.add(r), () => {
|
|
48
|
+
n.delete(r), 0 === n.size && t.delete(e);
|
|
49
|
+
};
|
|
50
|
+
}, r = (e, r) => {
|
|
51
|
+
if (r) {
|
|
52
|
+
const n = t.get(e);
|
|
53
|
+
n && (n.delete(r), 0 === n.size && t.delete(e));
|
|
54
|
+
} else t.delete(e);
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
on: e,
|
|
58
|
+
once: (t, n) => {
|
|
59
|
+
const o = (e) => {
|
|
60
|
+
n(e), r(t, o);
|
|
61
|
+
};
|
|
62
|
+
return e(t, o);
|
|
63
|
+
},
|
|
64
|
+
off: r,
|
|
65
|
+
emit: (e, r) => {
|
|
66
|
+
const n = {
|
|
67
|
+
type: e,
|
|
68
|
+
payload: r,
|
|
69
|
+
timestamp: Date.now()
|
|
70
|
+
}, o = t.get(e);
|
|
71
|
+
o && o.forEach((t) => t(n));
|
|
72
|
+
const s = t.get("*");
|
|
73
|
+
s && s.forEach((t) => t(n));
|
|
74
|
+
},
|
|
75
|
+
clear: () => {
|
|
76
|
+
t.clear();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
81
|
+
const r = e();
|
|
82
|
+
async function n(t, e) {
|
|
83
|
+
for (const r of t) await r(e);
|
|
84
|
+
}
|
|
85
|
+
var o = class {
|
|
86
|
+
constructor(e, n = {}) {
|
|
87
|
+
this.stateSubscribers = t(), this.actionSubscribers = t(), this.disposed = !1, this.$id = e.id, this.initialStateFactory = e.state, this._state = e.state(), this.getters = this.createGetters(e.getters || {}), this.actions = this.createActions(e.actions || {}), r.emit("store:created", { storeId: this.$id });
|
|
88
|
+
}
|
|
89
|
+
get $state() {
|
|
90
|
+
return this._state;
|
|
91
|
+
}
|
|
92
|
+
set $state(t) {
|
|
93
|
+
this._state = t;
|
|
94
|
+
}
|
|
95
|
+
$reset() {
|
|
96
|
+
this.checkDisposed();
|
|
97
|
+
const t = { ...this._state };
|
|
98
|
+
this._state = this.initialStateFactory(), this.notifyStateChange({
|
|
99
|
+
type: "direct",
|
|
100
|
+
storeId: this.$id,
|
|
101
|
+
oldState: t
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
$patch(t) {
|
|
105
|
+
this.checkDisposed();
|
|
106
|
+
const e = { ...this._state };
|
|
107
|
+
"function" == typeof t ? (t(this._state), this.notifyStateChange({
|
|
108
|
+
type: "patch function",
|
|
109
|
+
storeId: this.$id,
|
|
110
|
+
oldState: e
|
|
111
|
+
})) : (Object.assign(this._state, t), this.notifyStateChange({
|
|
112
|
+
type: "patch object",
|
|
113
|
+
storeId: this.$id,
|
|
114
|
+
oldState: e,
|
|
115
|
+
events: Object.keys(t)
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
$subscribe(t, e = {}) {
|
|
119
|
+
return this.checkDisposed(), this.stateSubscribers.subscribe(({ mutation: e, state: r }) => t(e, r), { immediate: e.immediate });
|
|
120
|
+
}
|
|
121
|
+
$onAction(t) {
|
|
122
|
+
return this.checkDisposed(), this.actionSubscribers.subscribe(t);
|
|
123
|
+
}
|
|
124
|
+
$dispose() {
|
|
125
|
+
this.disposed || (this.disposed = !0, this.stateSubscribers.clear(), this.actionSubscribers.clear(), r.emit("store:disposed", { storeId: this.$id }));
|
|
126
|
+
}
|
|
127
|
+
notifyStateChange(t) {
|
|
128
|
+
this.stateSubscribers.publish({
|
|
129
|
+
mutation: t,
|
|
130
|
+
state: this._state
|
|
131
|
+
}), r.emit("state:changed", {
|
|
132
|
+
storeId: this.$id,
|
|
133
|
+
state: this._state,
|
|
134
|
+
mutation: t
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
notifyAction(t) {
|
|
138
|
+
this.actionSubscribers.publish(t);
|
|
139
|
+
}
|
|
140
|
+
checkDisposed() {
|
|
141
|
+
if (this.disposed) throw new Error(`[Store] Store "${this.$id}" 已被销毁`);
|
|
142
|
+
}
|
|
143
|
+
createGetters(t) {
|
|
144
|
+
const e = {};
|
|
145
|
+
for (const r of Object.keys(t)) Object.defineProperty(e, r, {
|
|
146
|
+
enumerable: !0,
|
|
147
|
+
get: () => t[r](this._state)
|
|
148
|
+
});
|
|
149
|
+
return e;
|
|
150
|
+
}
|
|
151
|
+
createActions(t) {
|
|
152
|
+
const e = {};
|
|
153
|
+
for (const r of Object.keys(t)) {
|
|
154
|
+
const o = t[r];
|
|
155
|
+
e[r] = (...t) => {
|
|
156
|
+
this.checkDisposed();
|
|
157
|
+
const e = [], s = [], i = {
|
|
158
|
+
after: (t) => e.push(t),
|
|
159
|
+
args: t,
|
|
160
|
+
name: r,
|
|
161
|
+
onError: (t) => s.push(t),
|
|
162
|
+
storeId: this.$id
|
|
163
|
+
};
|
|
164
|
+
this.notifyAction(i);
|
|
165
|
+
try {
|
|
166
|
+
const r = o.apply(this, t);
|
|
167
|
+
return (a = r) && "function" == typeof a.then ? r.then(async (t) => (await n(e, t), t)).catch(async (t) => {
|
|
168
|
+
throw await n(s, t), t;
|
|
169
|
+
}) : (n(e, r), r);
|
|
170
|
+
} catch (t) {
|
|
171
|
+
throw n(s, t), t;
|
|
172
|
+
}
|
|
173
|
+
var a;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return e;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
function s(t) {
|
|
180
|
+
let e = 0;
|
|
181
|
+
const r = /* @__PURE__ */ new Set(), n = () => {
|
|
182
|
+
if (r.size > 0) {
|
|
183
|
+
const e = new Set(r);
|
|
184
|
+
r.clear(), t?.(e);
|
|
185
|
+
}
|
|
186
|
+
}, o = () => {
|
|
187
|
+
e++;
|
|
188
|
+
}, s = () => {
|
|
189
|
+
0 !== e && (e--, 0 === e && n());
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
start: o,
|
|
193
|
+
end: s,
|
|
194
|
+
markDirty: (t) => {
|
|
195
|
+
r.add(t), 0 === e && n();
|
|
196
|
+
},
|
|
197
|
+
batch: (t) => {
|
|
198
|
+
o();
|
|
199
|
+
try {
|
|
200
|
+
return t();
|
|
201
|
+
} finally {
|
|
202
|
+
s();
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
isBatching: () => e > 0
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
let i = null;
|
|
209
|
+
function a() {
|
|
210
|
+
return i || (i = s()), i;
|
|
211
|
+
}
|
|
212
|
+
const c = {
|
|
213
|
+
BUS: "store:bus",
|
|
214
|
+
PINIA: "store:pinia",
|
|
215
|
+
API: "store:api",
|
|
216
|
+
REGISTRY: "store:registry",
|
|
217
|
+
RUNTIME: "store:runtime"
|
|
218
|
+
}, l = {
|
|
219
|
+
INSTALLED: "store:installed",
|
|
220
|
+
UNINSTALLED: "store:uninstalled"
|
|
221
|
+
};
|
|
222
|
+
function u(t) {
|
|
223
|
+
const e = t;
|
|
224
|
+
return e && "object" == typeof e && "engine" in e ? e.engine ?? {} : e ?? {};
|
|
225
|
+
}
|
|
226
|
+
function f(t, e, r) {
|
|
227
|
+
const n = r;
|
|
228
|
+
return n?.app ?? n?.framework?.app ?? t.getApp?.() ?? e?.framework?.app;
|
|
229
|
+
}
|
|
230
|
+
var d = ((t) => (t.STORE_DISPOSED = "STORE_DISPOSED", t.STORE_NOT_FOUND = "STORE_NOT_FOUND", t.STORE_ALREADY_EXISTS = "STORE_ALREADY_EXISTS", t.INVALID_STATE = "INVALID_STATE", t.INVALID_ACTION = "INVALID_ACTION", t.SERIALIZATION_ERROR = "SERIALIZATION_ERROR", t.DESERIALIZATION_ERROR = "DESERIALIZATION_ERROR", t.STORAGE_ERROR = "STORAGE_ERROR", t.PLUGIN_ERROR = "PLUGIN_ERROR", t.MIDDLEWARE_ERROR = "MIDDLEWARE_ERROR", t.SUBSCRIPTION_ERROR = "SUBSCRIPTION_ERROR", t.TIMEOUT_ERROR = "TIMEOUT_ERROR", t.UNKNOWN_ERROR = "UNKNOWN_ERROR", t))(d || {}), p = ((t) => (t.WARNING = "warning", t.ERROR = "error", t.FATAL = "fatal", t))(p || {}), g = class t extends Error {
|
|
231
|
+
constructor(e, r = "UNKNOWN_ERROR", n = {}, o = "error", s) {
|
|
232
|
+
super(e), this.name = "StoreError", this.code = r, this.context = {
|
|
233
|
+
...n,
|
|
234
|
+
timestamp: n.timestamp ?? Date.now()
|
|
235
|
+
}, this.severity = o, this.cause = s, Object.setPrototypeOf(this, t.prototype), Error.captureStackTrace && Error.captureStackTrace(this, t);
|
|
236
|
+
}
|
|
237
|
+
toJSON() {
|
|
238
|
+
return {
|
|
239
|
+
name: this.name,
|
|
240
|
+
message: this.message,
|
|
241
|
+
code: this.code,
|
|
242
|
+
context: this.context,
|
|
243
|
+
severity: this.severity,
|
|
244
|
+
stack: this.stack
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
format() {
|
|
248
|
+
const t = [`[${this.code}] ${this.message}`];
|
|
249
|
+
return this.context.storeId && t.push(`Store: ${this.context.storeId}`), this.context.action && t.push(`Action: ${this.context.action}`), t.join(" | ");
|
|
250
|
+
}
|
|
251
|
+
}, h = class t extends g {
|
|
252
|
+
constructor(e, r, n) {
|
|
253
|
+
super(e, "MIDDLEWARE_ERROR", { middleware: r }, "error", n), this.name = "MiddlewareError", Object.setPrototypeOf(this, t.prototype);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const y = {
|
|
257
|
+
isStoreError: (t) => t instanceof g,
|
|
258
|
+
isErrorCode: (t, e) => t instanceof g && t.code === e,
|
|
259
|
+
wrap(t, e = "UNKNOWN_ERROR", r = {}) {
|
|
260
|
+
if (t instanceof g) return t;
|
|
261
|
+
return new g(t instanceof Error ? t.message : String(t), e, r, "error", t instanceof Error ? t : void 0);
|
|
262
|
+
},
|
|
263
|
+
async tryCatch(t, e = "UNKNOWN_ERROR", r = {}) {
|
|
264
|
+
try {
|
|
265
|
+
return await t();
|
|
266
|
+
} catch (t) {
|
|
267
|
+
throw y.wrap(t, e, r);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
createLogger: (t) => ({
|
|
271
|
+
error(e) {
|
|
272
|
+
console.error(`[${t}]`, e.format()), e.cause && console.error(`[${t}] Caused by:`, e.cause);
|
|
273
|
+
},
|
|
274
|
+
warn(e) {
|
|
275
|
+
console.warn(`[${t}]`, e.format());
|
|
276
|
+
},
|
|
277
|
+
log(t) {
|
|
278
|
+
"fatal" === t.severity || "error" === t.severity ? this.error(t) : this.warn(t);
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
};
|
|
282
|
+
function S(t, e, r = !1) {
|
|
283
|
+
let n = null, o = null;
|
|
284
|
+
const s = (...s) => {
|
|
285
|
+
o = s, n && clearTimeout(n), r && !n ? (t(...s), n = setTimeout(() => {
|
|
286
|
+
n = null, o = null;
|
|
287
|
+
}, e)) : n = setTimeout(() => {
|
|
288
|
+
t(...s), n = null, o = null;
|
|
289
|
+
}, e);
|
|
290
|
+
};
|
|
291
|
+
return s.cancel = () => {
|
|
292
|
+
n && (clearTimeout(n), n = null, o = null);
|
|
293
|
+
}, s.flush = () => {
|
|
294
|
+
n && o && (clearTimeout(n), t(...o), n = null, o = null);
|
|
295
|
+
}, s.pending = () => null !== n, s;
|
|
296
|
+
}
|
|
297
|
+
const m = Object.prototype.hasOwnProperty;
|
|
298
|
+
function b(t, e) {
|
|
299
|
+
return m.call(t, e);
|
|
300
|
+
}
|
|
301
|
+
function E(t) {
|
|
302
|
+
return null !== t && "object" == typeof t;
|
|
303
|
+
}
|
|
304
|
+
function R(t) {
|
|
305
|
+
if (!E(t)) return !1;
|
|
306
|
+
const e = Object.getPrototypeOf(t);
|
|
307
|
+
return null === e || e === Object.prototype;
|
|
308
|
+
}
|
|
309
|
+
function w(t) {
|
|
310
|
+
return null == t || "boolean" == typeof t || "number" == typeof t || "string" == typeof t || "bigint" == typeof t || "function" != typeof t && "symbol" != typeof t && (t instanceof Date || t instanceof RegExp || t instanceof ArrayBuffer || t instanceof DataView || t instanceof Map || t instanceof Set || !!ArrayBuffer.isView(t) || (Array.isArray(t) ? t.every((t) => w(t)) : !!R(t) && Object.values(t).every((t) => w(t))));
|
|
311
|
+
}
|
|
312
|
+
function O(t, e = {}) {
|
|
313
|
+
const { useStructuredClone: r = !0, cloneFunctions: n = !1, cloneSymbols: o = !1, maxDepth: s = Infinity, customCloner: i } = e;
|
|
314
|
+
if (r && "function" == typeof structuredClone && w(t)) try {
|
|
315
|
+
return structuredClone(t);
|
|
316
|
+
} catch {}
|
|
317
|
+
const a = /* @__PURE__ */ new WeakMap();
|
|
318
|
+
return function t(e, r) {
|
|
319
|
+
if (null == e) return e;
|
|
320
|
+
if ("boolean" == typeof e || "number" == typeof e || "string" == typeof e) return e;
|
|
321
|
+
if ("bigint" == typeof e) return e;
|
|
322
|
+
if ("symbol" == typeof e) return o ? Symbol(e.description) : e;
|
|
323
|
+
if ("function" == typeof e) return n ? e.bind({}) : e;
|
|
324
|
+
if (r > s) return e;
|
|
325
|
+
if (i) {
|
|
326
|
+
const n = i(e, (e) => t(e, r + 1));
|
|
327
|
+
if (void 0 !== n) return n;
|
|
328
|
+
}
|
|
329
|
+
if ("object" == typeof e && null !== e && a.has(e)) return a.get(e);
|
|
330
|
+
if (e instanceof Date) return new Date(e.getTime());
|
|
331
|
+
if (e instanceof RegExp) {
|
|
332
|
+
const t = new RegExp(e.source, e.flags);
|
|
333
|
+
return t.lastIndex = e.lastIndex, t;
|
|
334
|
+
}
|
|
335
|
+
if (e instanceof Error) {
|
|
336
|
+
const t = new e.constructor(e.message);
|
|
337
|
+
return t.stack = e.stack, t.name = e.name, t;
|
|
338
|
+
}
|
|
339
|
+
if (e instanceof Map) {
|
|
340
|
+
const n = /* @__PURE__ */ new Map();
|
|
341
|
+
return a.set(e, n), e.forEach((e, o) => {
|
|
342
|
+
n.set(t(o, r + 1), t(e, r + 1));
|
|
343
|
+
}), n;
|
|
344
|
+
}
|
|
345
|
+
if (e instanceof Set) {
|
|
346
|
+
const n = /* @__PURE__ */ new Set();
|
|
347
|
+
return a.set(e, n), e.forEach((e) => {
|
|
348
|
+
n.add(t(e, r + 1));
|
|
349
|
+
}), n;
|
|
350
|
+
}
|
|
351
|
+
if (e instanceof ArrayBuffer) return e.slice(0);
|
|
352
|
+
if (ArrayBuffer.isView(e) && !(e instanceof DataView)) return new e.constructor(e.buffer.slice(0));
|
|
353
|
+
if (Array.isArray(e)) {
|
|
354
|
+
const n = [];
|
|
355
|
+
a.set(e, n);
|
|
356
|
+
for (let o = 0; o < e.length; o++) n[o] = t(e[o], r + 1);
|
|
357
|
+
return n;
|
|
358
|
+
}
|
|
359
|
+
if (R(e)) {
|
|
360
|
+
const n = {};
|
|
361
|
+
a.set(e, n);
|
|
362
|
+
const s = Object.keys(e);
|
|
363
|
+
for (const o of s) n[o] = t(e[o], r + 1);
|
|
364
|
+
if (o) {
|
|
365
|
+
const o = Object.getOwnPropertySymbols(e);
|
|
366
|
+
for (const s of o) n[s] = t(e[s], r + 1);
|
|
367
|
+
}
|
|
368
|
+
return n;
|
|
369
|
+
}
|
|
370
|
+
return e;
|
|
371
|
+
}(t, 0);
|
|
372
|
+
}
|
|
373
|
+
function I(t, e, ...r) {
|
|
374
|
+
const { arrayStrategy: n = "replace", clone: o = !0, maxDepth: s = Infinity } = e;
|
|
375
|
+
function i(t, e, r) {
|
|
376
|
+
if (r > s) return t;
|
|
377
|
+
for (const s of Object.keys(e)) {
|
|
378
|
+
const a = e[s], c = t[s];
|
|
379
|
+
if (Array.isArray(a)) if ("concat" === n && Array.isArray(c)) t[s] = [...c, ...a];
|
|
380
|
+
else if ("merge" === n && Array.isArray(c)) {
|
|
381
|
+
const e = [...c];
|
|
382
|
+
a.forEach((t, n) => {
|
|
383
|
+
R(t) && R(e[n]) ? e[n] = i(e[n], t, r + 1) : e[n] = o ? O(t) : t;
|
|
384
|
+
}), t[s] = e;
|
|
385
|
+
} else t[s] = o ? O(a) : a;
|
|
386
|
+
else R(a) ? R(c) ? t[s] = i(c, a, r + 1) : t[s] = o ? O(a) : a : t[s] = o && E(a) ? O(a) : a;
|
|
387
|
+
}
|
|
388
|
+
return t;
|
|
389
|
+
}
|
|
390
|
+
let a = t;
|
|
391
|
+
for (const t of r) null != t && (a = i(a, t, 0));
|
|
392
|
+
return a;
|
|
393
|
+
}
|
|
394
|
+
const A = /^\d+$/;
|
|
395
|
+
function T(t, e = Object.is) {
|
|
396
|
+
let r, n, o = !1;
|
|
397
|
+
return (s) => {
|
|
398
|
+
if (o && r === s) return n;
|
|
399
|
+
const i = t(s);
|
|
400
|
+
return o && e(i, n) || (n = i), r = s, o = !0, n;
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const v = {
|
|
404
|
+
logState: !0,
|
|
405
|
+
logAction: !0,
|
|
406
|
+
collapsed: !0,
|
|
407
|
+
timestamp: !0,
|
|
408
|
+
level: "log"
|
|
409
|
+
}, P = "color: #9E9E9E; font-weight: bold", $ = "color: #03A9F4; font-weight: bold", D = "color: #4CAF50; font-weight: bold", N = "color: #F44336; font-weight: bold", _ = "color: #9C27B0; font-weight: normal", x = "color: inherit; font-weight: bold";
|
|
410
|
+
function M(t) {
|
|
411
|
+
try {
|
|
412
|
+
return O(t);
|
|
413
|
+
} catch {
|
|
414
|
+
return { ...t };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function j() {
|
|
418
|
+
const t = /* @__PURE__ */ new Map();
|
|
419
|
+
let e = null;
|
|
420
|
+
const r = () => (null === e && (e = Array.from(t.values()).sort((t, e) => (t.priority ?? 100) - (e.priority ?? 100))), e), n = () => {
|
|
421
|
+
e = null;
|
|
422
|
+
};
|
|
423
|
+
return {
|
|
424
|
+
use: (e) => {
|
|
425
|
+
t.has(e.name) && console.warn(`[Middleware] 中间件 "${e.name}" 已存在,将被覆盖`), t.set(e.name, e), n();
|
|
426
|
+
},
|
|
427
|
+
remove: (e) => {
|
|
428
|
+
t.delete(e) && n();
|
|
429
|
+
},
|
|
430
|
+
get: (e) => t.get(e),
|
|
431
|
+
has: (e) => t.has(e),
|
|
432
|
+
execute: async (t) => {
|
|
433
|
+
const e = r();
|
|
434
|
+
if (0 === e.length) return;
|
|
435
|
+
const n = async (r) => {
|
|
436
|
+
const o = e[r];
|
|
437
|
+
if (!o) return;
|
|
438
|
+
let s = !1;
|
|
439
|
+
await o.handler(t, async () => {
|
|
440
|
+
if (s) throw new Error(`[Middleware] next() called multiple times in "${o.name}"`);
|
|
441
|
+
s = !0, await n(r + 1);
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
await n(0);
|
|
445
|
+
},
|
|
446
|
+
getAll: () => r(),
|
|
447
|
+
clear: () => {
|
|
448
|
+
t.clear(), n();
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
let C = null;
|
|
453
|
+
const k = {
|
|
454
|
+
keyPrefix: "ldesign-store:",
|
|
455
|
+
storage: "localStorage",
|
|
456
|
+
debounce: 100,
|
|
457
|
+
serialize: JSON.stringify,
|
|
458
|
+
deserialize: JSON.parse
|
|
459
|
+
};
|
|
460
|
+
function L(t) {
|
|
461
|
+
return {
|
|
462
|
+
...k,
|
|
463
|
+
...t
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function z(t) {
|
|
467
|
+
return "undefined" == typeof window ? null : "localStorage" === t ? localStorage : sessionStorage;
|
|
468
|
+
}
|
|
469
|
+
const B = {
|
|
470
|
+
maxHistory: 100,
|
|
471
|
+
enabled: !0
|
|
472
|
+
};
|
|
473
|
+
function U(t) {
|
|
474
|
+
return {
|
|
475
|
+
name: t.name,
|
|
476
|
+
version: t.version,
|
|
477
|
+
description: t.description,
|
|
478
|
+
install: t.install,
|
|
479
|
+
uninstall: t.uninstall,
|
|
480
|
+
onStoreCreated: t.onStoreCreated,
|
|
481
|
+
onStoreDisposed: t.onStoreDisposed,
|
|
482
|
+
onStateChange: t.onStateChange
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function F() {
|
|
486
|
+
const t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Map();
|
|
487
|
+
return {
|
|
488
|
+
use: (r, n) => {
|
|
489
|
+
t.has(r.name) && console.warn(`[Plugin] 插件 "${r.name}" 已存在,将被覆盖`), t.set(r.name, r);
|
|
490
|
+
const o = {
|
|
491
|
+
storeManager: {
|
|
492
|
+
getStore: () => null,
|
|
493
|
+
hasStore: () => !1,
|
|
494
|
+
getStoreIds: () => []
|
|
495
|
+
},
|
|
496
|
+
storeId: "",
|
|
497
|
+
store: null,
|
|
498
|
+
options: n || {}
|
|
499
|
+
};
|
|
500
|
+
e.set(r.name, o);
|
|
501
|
+
},
|
|
502
|
+
remove: (r) => {
|
|
503
|
+
const n = t.get(r), o = e.get(r);
|
|
504
|
+
n && o && n.uninstall?.(o), t.delete(r), e.delete(r);
|
|
505
|
+
},
|
|
506
|
+
get: (e) => t.get(e),
|
|
507
|
+
has: (e) => t.has(e),
|
|
508
|
+
getAll: () => new Map(t),
|
|
509
|
+
size: () => t.size,
|
|
510
|
+
clear: () => {
|
|
511
|
+
t.forEach((t, r) => {
|
|
512
|
+
const n = e.get(r);
|
|
513
|
+
n && t.uninstall?.(n);
|
|
514
|
+
}), t.clear(), e.clear();
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
let G = null;
|
|
519
|
+
exports.BaseStore = o, exports.DeserializationError = class t extends g {
|
|
520
|
+
constructor(e, r, n) {
|
|
521
|
+
super(e, "DESERIALIZATION_ERROR", { storeId: n }, "error", r), this.name = "DeserializationError", Object.setPrototypeOf(this, t.prototype);
|
|
522
|
+
}
|
|
523
|
+
}, exports.ErrorSeverity = p, exports.InvalidStateError = class t extends g {
|
|
524
|
+
constructor(e, r, n) {
|
|
525
|
+
super(e, "INVALID_STATE", {
|
|
526
|
+
storeId: r,
|
|
527
|
+
data: n
|
|
528
|
+
}, "error"), this.name = "InvalidStateError", Object.setPrototypeOf(this, t.prototype);
|
|
529
|
+
}
|
|
530
|
+
}, exports.MiddlewareError = h, exports.PluginError = class t extends g {
|
|
531
|
+
constructor(e, r, n) {
|
|
532
|
+
super(e, "PLUGIN_ERROR", { plugin: r }, "error", n), this.name = "PluginError", Object.setPrototypeOf(this, t.prototype);
|
|
533
|
+
}
|
|
534
|
+
}, exports.SerializationError = class t extends g {
|
|
535
|
+
constructor(e, r, n) {
|
|
536
|
+
super(e, "SERIALIZATION_ERROR", { storeId: n }, "error", r), this.name = "SerializationError", Object.setPrototypeOf(this, t.prototype);
|
|
537
|
+
}
|
|
538
|
+
}, exports.StorageError = class t extends g {
|
|
539
|
+
constructor(e, r, n) {
|
|
540
|
+
super(e, "STORAGE_ERROR", { storeId: n }, "error", r), this.name = "StorageError", Object.setPrototypeOf(this, t.prototype);
|
|
541
|
+
}
|
|
542
|
+
}, exports.StoreAlreadyExistsError = class t extends g {
|
|
543
|
+
constructor(e) {
|
|
544
|
+
super(`Store "${e}" 已存在`, "STORE_ALREADY_EXISTS", { storeId: e }, "warning"), this.name = "StoreAlreadyExistsError", Object.setPrototypeOf(this, t.prototype);
|
|
545
|
+
}
|
|
546
|
+
}, exports.StoreDisposedError = class t extends g {
|
|
547
|
+
constructor(e, r) {
|
|
548
|
+
super(`Store "${e}" 已被销毁,无法执行操作${r ? `: ${r}` : ""}`, "STORE_DISPOSED", {
|
|
549
|
+
storeId: e,
|
|
550
|
+
action: r
|
|
551
|
+
}, "error"), this.name = "StoreDisposedError", Object.setPrototypeOf(this, t.prototype);
|
|
552
|
+
}
|
|
553
|
+
}, exports.StoreError = g, exports.StoreErrorCode = d, exports.StoreNotFoundError = class t extends g {
|
|
554
|
+
constructor(e) {
|
|
555
|
+
super(`Store "${e}" 不存在`, "STORE_NOT_FOUND", { storeId: e }, "error"), this.name = "StoreNotFoundError", Object.setPrototypeOf(this, t.prototype);
|
|
556
|
+
}
|
|
557
|
+
}, exports.SubscriptionError = class t extends g {
|
|
558
|
+
constructor(e, r, n) {
|
|
559
|
+
super(e, "SUBSCRIPTION_ERROR", { storeId: n }, "warning", r), this.name = "SubscriptionError", Object.setPrototypeOf(this, t.prototype);
|
|
560
|
+
}
|
|
561
|
+
}, exports.TimeoutError = class t extends g {
|
|
562
|
+
constructor(e, r, n) {
|
|
563
|
+
super(e, "TIMEOUT_ERROR", {
|
|
564
|
+
storeId: r,
|
|
565
|
+
action: n
|
|
566
|
+
}, "error"), this.name = "TimeoutError", Object.setPrototypeOf(this, t.prototype);
|
|
567
|
+
}
|
|
568
|
+
}, exports.batch = function(t) {
|
|
569
|
+
return a().batch(t);
|
|
570
|
+
}, exports.combineSelectors = function(t, e) {
|
|
571
|
+
return (r) => e(...t.map((t) => t(r)));
|
|
572
|
+
}, exports.composePlugins = function(t) {
|
|
573
|
+
return {
|
|
574
|
+
name: "composed-plugins",
|
|
575
|
+
version: "1.0.0",
|
|
576
|
+
async install(e, r) {
|
|
577
|
+
for (const n of t) await n.install(e, r);
|
|
578
|
+
},
|
|
579
|
+
async uninstall(e) {
|
|
580
|
+
for (let r = t.length - 1; r >= 0; r--) await t[r].uninstall?.(e);
|
|
581
|
+
},
|
|
582
|
+
onStoreCreated(e) {
|
|
583
|
+
t.forEach((t) => t.onStoreCreated?.(e));
|
|
584
|
+
},
|
|
585
|
+
onStoreDisposed(e) {
|
|
586
|
+
t.forEach((t) => t.onStoreDisposed?.(e));
|
|
587
|
+
},
|
|
588
|
+
onStateChange(e, r, n) {
|
|
589
|
+
t.forEach((t) => t.onStateChange?.(e, r, n));
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}, exports.createAsyncAction = function(e, r = {}) {
|
|
593
|
+
const { retryCount: n = 0, retryDelay: o = 1e3, timeout: s = 0, resetOnExecute: i = !0 } = r, a = {
|
|
594
|
+
data: null,
|
|
595
|
+
error: null,
|
|
596
|
+
loading: !1,
|
|
597
|
+
executionCount: 0,
|
|
598
|
+
lastExecutedAt: null
|
|
599
|
+
}, c = t(), l = t(), u = t();
|
|
600
|
+
let f = null;
|
|
601
|
+
const d = () => {
|
|
602
|
+
c.publish({ ...a });
|
|
603
|
+
}, p = async (t, r) => {
|
|
604
|
+
try {
|
|
605
|
+
return await e(...t);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
if (r > 0 && !f?.signal.aborted) {
|
|
608
|
+
if (await (n = o, new Promise((t) => setTimeout(t, n))), f?.signal.aborted) throw new Error("Aborted");
|
|
609
|
+
return p(t, r - 1);
|
|
610
|
+
}
|
|
611
|
+
throw e;
|
|
612
|
+
}
|
|
613
|
+
var n;
|
|
614
|
+
};
|
|
615
|
+
return {
|
|
616
|
+
get state() {
|
|
617
|
+
return { ...a };
|
|
618
|
+
},
|
|
619
|
+
execute: async (...t) => {
|
|
620
|
+
f && f.abort(), f = new AbortController(), i && (a.error = null), a.loading = !0, a.executionCount++, a.lastExecutedAt = Date.now(), d();
|
|
621
|
+
try {
|
|
622
|
+
let e;
|
|
623
|
+
if (s > 0) {
|
|
624
|
+
const r = new Promise((t, e) => {
|
|
625
|
+
setTimeout(() => e(/* @__PURE__ */ new Error(`Timeout after ${s}ms`)), s);
|
|
626
|
+
});
|
|
627
|
+
e = await Promise.race([p(t, n), r]);
|
|
628
|
+
} else e = await p(t, n);
|
|
629
|
+
return f.signal.aborted || (a.data = e, a.error = null, a.loading = !1, d(), l.publish(e)), e;
|
|
630
|
+
} catch (t) {
|
|
631
|
+
if (!f.signal.aborted) {
|
|
632
|
+
const e = t instanceof Error ? t : new Error(String(t));
|
|
633
|
+
a.error = e, a.loading = !1, d(), u.publish(e);
|
|
634
|
+
}
|
|
635
|
+
throw t;
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
reset: () => {
|
|
639
|
+
f && (f.abort(), f = null), a.data = null, a.error = null, a.loading = !1, a.executionCount = 0, a.lastExecutedAt = null, d();
|
|
640
|
+
},
|
|
641
|
+
abort: () => {
|
|
642
|
+
f && (f.abort(), f = null), a.loading && (a.loading = !1, a.error = /* @__PURE__ */ new Error("Aborted"), d());
|
|
643
|
+
},
|
|
644
|
+
subscribe: (t) => c.subscribe(t),
|
|
645
|
+
onSuccess: (t) => l.subscribe(t),
|
|
646
|
+
onError: (t) => u.subscribe(t)
|
|
647
|
+
};
|
|
648
|
+
}, exports.createBatchManager = s, exports.createCachedSelector = function(t, e = {}) {
|
|
649
|
+
const { maxSize: r = 10 } = e, n = /* @__PURE__ */ new Map(), o = (e) => {
|
|
650
|
+
if (n.has(e)) {
|
|
651
|
+
const t = n.get(e);
|
|
652
|
+
return n.delete(e), n.set(e, t), t;
|
|
653
|
+
}
|
|
654
|
+
const o = t(e);
|
|
655
|
+
if (n.size >= r) {
|
|
656
|
+
const t = n.keys().next().value;
|
|
657
|
+
void 0 !== t && n.delete(t);
|
|
658
|
+
}
|
|
659
|
+
return n.set(e, o), o;
|
|
660
|
+
};
|
|
661
|
+
return o.clearCache = () => n.clear(), o.getCacheSize = () => n.size, o;
|
|
662
|
+
}, exports.createEventBus = e, exports.createLoggerMiddleware = function(t = {}) {
|
|
663
|
+
const e = {
|
|
664
|
+
...v,
|
|
665
|
+
...t
|
|
666
|
+
}, r = e.logger ?? console;
|
|
667
|
+
return {
|
|
668
|
+
name: "logger",
|
|
669
|
+
priority: 0,
|
|
670
|
+
handler: async (t, n) => {
|
|
671
|
+
const { storeId: o, type: s, state: i, payload: a } = t;
|
|
672
|
+
if (e.filter && !e.filter(t)) return void await n();
|
|
673
|
+
const c = s.startsWith("state:"), l = s.startsWith("action:");
|
|
674
|
+
if (c && !e.logState || l && !e.logAction) return void await n();
|
|
675
|
+
const u = e.timestamp ? `${(f = /* @__PURE__ */ new Date()).getHours().toString().padStart(2, "0")}:${f.getMinutes().toString().padStart(2, "0")}:${f.getSeconds().toString().padStart(2, "0")}.${f.getMilliseconds().toString().padStart(3, "0")}` : "";
|
|
676
|
+
var f;
|
|
677
|
+
const d = `[Store: ${o}]`, p = performance.now(), g = M(i), y = u ? `${u} ${d} ${s}` : `${d} ${s}`;
|
|
678
|
+
e.collapsed && "function" == typeof r.groupCollapsed ? r.groupCollapsed(`%c${y}`, x) : "function" == typeof r.group && r.group(`%c${y}`, x);
|
|
679
|
+
try {
|
|
680
|
+
const o = r[e.level ?? "log"] ?? r.log;
|
|
681
|
+
"function" == typeof o && (o.call(r, "%c prev state", P, g), void 0 !== a && o.call(r, "%c payload", $, a)), await n();
|
|
682
|
+
const s = performance.now();
|
|
683
|
+
"function" == typeof o && (o.call(r, "%c next state", D, M(t.state)), o.call(r, "%c duration", _, function(t, e) {
|
|
684
|
+
const r = e - t;
|
|
685
|
+
return r < 1 ? "< 1ms" : `${r.toFixed(2)}ms`;
|
|
686
|
+
}(p, s)));
|
|
687
|
+
} catch (t) {
|
|
688
|
+
throw "function" == typeof r.error && r.error("%c error", N, t), new h(`日志中间件执行错误: ${t instanceof Error ? t.message : String(t)}`, "logger", t instanceof Error ? t : void 0);
|
|
689
|
+
} finally {
|
|
690
|
+
"function" == typeof r.groupEnd && r.groupEnd();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
}, exports.createMemoizedSelector = function(t, e = {}) {
|
|
695
|
+
return T(t, e.equalityFn);
|
|
696
|
+
}, exports.createMiddlewareManager = j, exports.createPersistMiddleware = function(t = {}) {
|
|
697
|
+
const e = L(t), r = z(e.storage), n = /* @__PURE__ */ new Map(), o = (t, n) => {
|
|
698
|
+
if (r) try {
|
|
699
|
+
const o = ((t, r) => {
|
|
700
|
+
const n = e.paths?.[t];
|
|
701
|
+
if (!n || 0 === n.length) return r;
|
|
702
|
+
const o = {};
|
|
703
|
+
for (const t of n) {
|
|
704
|
+
const e = t.split(".");
|
|
705
|
+
let n = r, s = o;
|
|
706
|
+
for (let t = 0; t < e.length; t++) {
|
|
707
|
+
const r = e[t];
|
|
708
|
+
t === e.length - 1 ? s[r] = n?.[r] : (s[r] = s[r] || {}, s = s[r], n = n?.[r]);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return o;
|
|
712
|
+
})(t, n), s = e.serialize(o);
|
|
713
|
+
r.setItem(((t) => `${e.keyPrefix}${t}`)(t), s);
|
|
714
|
+
} catch (e) {
|
|
715
|
+
console.error(`[Persist] 保存状态失败 (${t}):`, e);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
return {
|
|
719
|
+
name: "persist",
|
|
720
|
+
priority: 100,
|
|
721
|
+
handler: async (t, r) => {
|
|
722
|
+
await r();
|
|
723
|
+
const { storeId: s, type: i, state: a } = t;
|
|
724
|
+
i.startsWith("state:") && (e.stores && !e.stores.includes(s) || ((t) => {
|
|
725
|
+
let r = n.get(t);
|
|
726
|
+
return r || (r = S((e) => o(t, e), e.debounce), n.set(t, r)), r;
|
|
727
|
+
})(s)(a));
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}, exports.createPluginFactory = function(t) {
|
|
731
|
+
return (e) => U(t(e));
|
|
732
|
+
}, exports.createPluginManager = F, exports.createPubSub = t, exports.createPubSubWithValue = function(e) {
|
|
733
|
+
let r = e;
|
|
734
|
+
const n = t();
|
|
735
|
+
return {
|
|
736
|
+
subscribe: (t, e = {}) => {
|
|
737
|
+
const o = n.subscribe(t, e);
|
|
738
|
+
return e.immediate && t(r), o;
|
|
739
|
+
},
|
|
740
|
+
publish: n.publish,
|
|
741
|
+
clear: n.clear,
|
|
742
|
+
size: n.size,
|
|
743
|
+
getValue: () => r,
|
|
744
|
+
setValue: (t) => {
|
|
745
|
+
const e = r;
|
|
746
|
+
r = t, n.publish(t, e);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
}, exports.createSelector = T, exports.createSelectorWithDeps = function(t, e, r = {}) {
|
|
750
|
+
const { equalityFn: n = Object.is, trackHitRate: o = !1 } = r;
|
|
751
|
+
let s, i, a = !1, c = 0, l = 0;
|
|
752
|
+
const u = (r) => {
|
|
753
|
+
o && l++;
|
|
754
|
+
const u = t.map((t) => t(r));
|
|
755
|
+
if (a && s) {
|
|
756
|
+
let t = !1;
|
|
757
|
+
for (let e = 0; e < u.length; e++) if (!Object.is(u[e], s[e])) {
|
|
758
|
+
t = !0;
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
if (!t) return o && c++, i;
|
|
762
|
+
}
|
|
763
|
+
const f = e(...u);
|
|
764
|
+
return a && n(f, i) || (i = f), s = u, a = !0, i;
|
|
765
|
+
};
|
|
766
|
+
return o && (u.getHitRate = () => l > 0 ? c / l : 0), u;
|
|
767
|
+
}, exports.createSimpleLoggerMiddleware = function(t = {}) {
|
|
768
|
+
const { includePayload: e = !0, format: r, filter: n } = t;
|
|
769
|
+
return {
|
|
770
|
+
name: "simple-logger",
|
|
771
|
+
priority: 0,
|
|
772
|
+
handler: async (t, o) => {
|
|
773
|
+
const { storeId: s, type: i, payload: a } = t;
|
|
774
|
+
if (n && !n(t)) return void await o();
|
|
775
|
+
const c = r ? r(t) : `[Store: ${s}] ${i}`;
|
|
776
|
+
e && void 0 !== a ? console.info(c, a) : console.info(c), await o();
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
}, exports.createStore = function(t) {
|
|
780
|
+
let e = null;
|
|
781
|
+
return () => {
|
|
782
|
+
if (e) return e;
|
|
783
|
+
const r = new o(t), n = r.$dispose.bind(r);
|
|
784
|
+
return r.$dispose = () => {
|
|
785
|
+
n(), e = null;
|
|
786
|
+
}, e = r, r;
|
|
787
|
+
};
|
|
788
|
+
}, exports.createStoreEngineBridge = function(t) {
|
|
789
|
+
const { createRuntime: e, debug: n = !1, name: o = "store", onRuntimeChange: s, version: i = "1.0.0" } = t;
|
|
790
|
+
let a, d = {}, p = null, g = null;
|
|
791
|
+
const h = (e, n) => {
|
|
792
|
+
const l = p, u = g;
|
|
793
|
+
return p = e, g = n, s?.(e), function(t, e, n, o) {
|
|
794
|
+
t.state?.set?.(c.RUNTIME, o), t.state?.set?.(c.PINIA, o.pinia), t.state?.set?.(c.API, o.storeAPI), t.state?.set?.(c.REGISTRY, o.registry), t.state?.set?.(c.BUS, r), t.state?.set?.(`plugins.${e}`, o.storeAPI), t.state?.set?.(`plugins.${e}.config`, n);
|
|
795
|
+
}(d, o, t, e), function(t, e, r, n) {
|
|
796
|
+
if (!t.api?.register) return;
|
|
797
|
+
const o = function(t, e, r) {
|
|
798
|
+
return {
|
|
799
|
+
name: t,
|
|
800
|
+
version: e,
|
|
801
|
+
pinia: r.pinia,
|
|
802
|
+
getStore: r.storeAPI.getStore,
|
|
803
|
+
hasStore: r.storeAPI.hasStore,
|
|
804
|
+
getStoreIds: r.storeAPI.getStoreIds,
|
|
805
|
+
resetAll: r.storeAPI.resetAll
|
|
806
|
+
};
|
|
807
|
+
}(e, r, n);
|
|
808
|
+
t.api.unregister?.(e), t.api.register.length >= 2 ? t.api.register(e, o) : t.api.register(o);
|
|
809
|
+
}(d, o, i, e), function(t, e) {
|
|
810
|
+
if (t?.container?.singleton) try {
|
|
811
|
+
t.container.singleton("pinia", e.pinia), t.container.singleton("storeAPI", e.storeAPI), t.container.singleton("storeRegistry", e.registry), t.container.singleton("storeRuntime", e);
|
|
812
|
+
} catch {}
|
|
813
|
+
}(a, e), l && l !== e && "engine" === u && l.dispose?.(), e;
|
|
814
|
+
}, y = () => p && "engine" === g ? p : e(), S = (e) => {
|
|
815
|
+
const r = t.getRuntimeFromApp?.(e);
|
|
816
|
+
if (r) return h(r, "external");
|
|
817
|
+
const n = y(), o = t.attachToApp ? t.attachToApp(e, n) : n;
|
|
818
|
+
return h(o, o === n ? "engine" : "external");
|
|
819
|
+
};
|
|
820
|
+
return {
|
|
821
|
+
attachToApp: S,
|
|
822
|
+
getRuntime: () => p,
|
|
823
|
+
install: async (e) => {
|
|
824
|
+
d = u(e), a = function(t) {
|
|
825
|
+
return t && "object" == typeof t ? t : void 0;
|
|
826
|
+
}(e);
|
|
827
|
+
const r = t.resolveApp ? t.resolveApp(d, a ?? {}, void 0) : f(d, a);
|
|
828
|
+
!r || t.isApp && !t.isApp(r) ? (h(y(), "engine"), d.events?.once?.("app:created", (e) => {
|
|
829
|
+
const r = t.resolveApp ? t.resolveApp(d, a ?? {}, e) : f(d, a, e);
|
|
830
|
+
!r || t.isApp && !t.isApp(r) || S(r);
|
|
831
|
+
})) : S(r), await d.events?.emit?.(l.INSTALLED, {
|
|
832
|
+
name: o,
|
|
833
|
+
version: i,
|
|
834
|
+
pinia: p?.pinia,
|
|
835
|
+
storeAPI: p?.storeAPI
|
|
836
|
+
}), n && d.logger?.info?.("[StoreEngineBridge] installed");
|
|
837
|
+
},
|
|
838
|
+
uninstall: async (t) => {
|
|
839
|
+
const e = t ? u(t) : d;
|
|
840
|
+
e.api?.unregister?.(o), function(t, e) {
|
|
841
|
+
t.state?.delete?.(c.RUNTIME), t.state?.delete?.(c.PINIA), t.state?.delete?.(c.API), t.state?.delete?.(c.REGISTRY), t.state?.delete?.(c.BUS), t.state?.delete?.(`plugins.${e}`), t.state?.delete?.(`plugins.${e}.config`);
|
|
842
|
+
}(e, o), await e.events?.emit?.(l.UNINSTALLED, { name: o }), p && "engine" === g && p.dispose?.(), p = null, g = null, s?.(null), n && e.logger?.info?.("[StoreEngineBridge] uninstalled");
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
}, exports.createTimeTravelMiddleware = function(t = {}) {
|
|
846
|
+
const e = {
|
|
847
|
+
...B,
|
|
848
|
+
...t
|
|
849
|
+
}, r = e.maxHistory ?? B.maxHistory ?? 100, n = [];
|
|
850
|
+
let o = -1, s = !1, i = () => {};
|
|
851
|
+
const a = {
|
|
852
|
+
undo: () => {
|
|
853
|
+
if (!a.canUndo()) return;
|
|
854
|
+
s = !0, o--;
|
|
855
|
+
const t = n[o];
|
|
856
|
+
i(t.storeId, O(t.state)), s = !1;
|
|
857
|
+
},
|
|
858
|
+
redo: () => {
|
|
859
|
+
if (!a.canRedo()) return;
|
|
860
|
+
s = !0, o++;
|
|
861
|
+
const t = n[o];
|
|
862
|
+
i(t.storeId, O(t.state)), s = !1;
|
|
863
|
+
},
|
|
864
|
+
goto: (t) => {
|
|
865
|
+
if (t < 0 || t >= n.length) return;
|
|
866
|
+
s = !0, o = t;
|
|
867
|
+
const e = n[o];
|
|
868
|
+
i(e.storeId, O(e.state)), s = !1;
|
|
869
|
+
},
|
|
870
|
+
getHistory: () => O(n),
|
|
871
|
+
getCurrentIndex: () => o,
|
|
872
|
+
canUndo: () => o > 0,
|
|
873
|
+
canRedo: () => o < n.length - 1,
|
|
874
|
+
clear: () => {
|
|
875
|
+
n.length = 0, o = -1;
|
|
876
|
+
},
|
|
877
|
+
__setRestoreCallback: (t) => {
|
|
878
|
+
i = t;
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
return {
|
|
882
|
+
middleware: {
|
|
883
|
+
name: "time-travel",
|
|
884
|
+
priority: 50,
|
|
885
|
+
handler: async (t, i) => {
|
|
886
|
+
const { storeId: a, type: c, state: l } = t;
|
|
887
|
+
if (!c.startsWith("state:") || s) return void await i();
|
|
888
|
+
const u = {
|
|
889
|
+
timestamp: Date.now(),
|
|
890
|
+
state: O(l),
|
|
891
|
+
type: c,
|
|
892
|
+
storeId: a
|
|
893
|
+
};
|
|
894
|
+
await i(), ((t) => {
|
|
895
|
+
e.enabled && !s && (o < n.length - 1 && n.splice(o + 1), n.push(t), o = n.length - 1, n.length > r && (n.shift(), o--));
|
|
896
|
+
})(u);
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
controller: a
|
|
900
|
+
};
|
|
901
|
+
}, exports.createValidationMiddleware = function(t) {
|
|
902
|
+
const { rules: e, onValidationError: r, blocking: n = !1, patchOnly: o = !1 } = t;
|
|
903
|
+
let s = [];
|
|
904
|
+
async function i(t, r) {
|
|
905
|
+
const n = e[t];
|
|
906
|
+
if (!n) return {
|
|
907
|
+
valid: !0,
|
|
908
|
+
errors: []
|
|
909
|
+
};
|
|
910
|
+
const o = [];
|
|
911
|
+
for (const [e, s] of Object.entries(n)) {
|
|
912
|
+
const n = Array.isArray(s) ? s : [s], i = r[e];
|
|
913
|
+
for (const s of n) try {
|
|
914
|
+
await s.validate(i, r) || o.push({
|
|
915
|
+
storeId: t,
|
|
916
|
+
field: e,
|
|
917
|
+
message: s.message,
|
|
918
|
+
value: i
|
|
919
|
+
});
|
|
920
|
+
} catch {
|
|
921
|
+
o.push({
|
|
922
|
+
storeId: t,
|
|
923
|
+
field: e,
|
|
924
|
+
message: s.message || `Validation error on field "${e}"`,
|
|
925
|
+
value: i
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return {
|
|
930
|
+
valid: 0 === o.length,
|
|
931
|
+
errors: o
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
return {
|
|
935
|
+
middleware: {
|
|
936
|
+
name: "validation",
|
|
937
|
+
priority: 5,
|
|
938
|
+
handler: async (t, a) => {
|
|
939
|
+
const { storeId: c, type: l, state: u } = t;
|
|
940
|
+
if (!(o ? "state:patch" === l : l.startsWith("state:")) || !e[c]) return void await a();
|
|
941
|
+
await a();
|
|
942
|
+
const f = await i(c, u);
|
|
943
|
+
if (f.valid) s = s.filter((t) => t.storeId !== c);
|
|
944
|
+
else if (s = f.errors, r?.(f), n) throw new Error(`[Validation] ${c}: ${f.errors.map((t) => t.message).join("; ")}`);
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
validate: i,
|
|
948
|
+
getErrors: () => [...s],
|
|
949
|
+
clearErrors: () => {
|
|
950
|
+
s = [];
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
}, exports.debounce = S, exports.deepClone = O, exports.deepEqual = function t(e, r) {
|
|
954
|
+
if (e === r) return !0;
|
|
955
|
+
if (null === e || null === r || void 0 === e || void 0 === r) return e === r;
|
|
956
|
+
if (typeof e != typeof r) return !1;
|
|
957
|
+
if ("object" != typeof e) return e === r;
|
|
958
|
+
if (e instanceof Date && r instanceof Date) return e.getTime() === r.getTime();
|
|
959
|
+
if (e instanceof RegExp && r instanceof RegExp) return e.source === r.source && e.flags === r.flags;
|
|
960
|
+
if (e instanceof Map && r instanceof Map) {
|
|
961
|
+
if (e.size !== r.size) return !1;
|
|
962
|
+
for (const [n, o] of e) if (!r.has(n) || !t(o, r.get(n))) return !1;
|
|
963
|
+
return !0;
|
|
964
|
+
}
|
|
965
|
+
if (e instanceof Set && r instanceof Set) {
|
|
966
|
+
if (e.size !== r.size) return !1;
|
|
967
|
+
for (const t of e) if (!r.has(t)) return !1;
|
|
968
|
+
return !0;
|
|
969
|
+
}
|
|
970
|
+
if (Array.isArray(e) && Array.isArray(r)) {
|
|
971
|
+
if (e.length !== r.length) return !1;
|
|
972
|
+
for (let n = 0; n < e.length; n++) if (!t(e[n], r[n])) return !1;
|
|
973
|
+
return !0;
|
|
974
|
+
}
|
|
975
|
+
if (R(e) && R(r)) {
|
|
976
|
+
const n = Object.keys(e), o = Object.keys(r);
|
|
977
|
+
if (n.length !== o.length) return !1;
|
|
978
|
+
for (const o of n) {
|
|
979
|
+
if (!b(r, o)) return !1;
|
|
980
|
+
if (!t(e[o], r[o])) return !1;
|
|
981
|
+
}
|
|
982
|
+
return !0;
|
|
983
|
+
}
|
|
984
|
+
return !1;
|
|
985
|
+
}, exports.deepFreeze = function t(e) {
|
|
986
|
+
const r = Object.getOwnPropertyNames(e);
|
|
987
|
+
for (const n of r) {
|
|
988
|
+
const r = e[n];
|
|
989
|
+
r && "object" == typeof r && t(r);
|
|
990
|
+
}
|
|
991
|
+
return Object.freeze(e);
|
|
992
|
+
}, exports.deepMerge = function(t, ...e) {
|
|
993
|
+
return I(t, {}, ...e);
|
|
994
|
+
}, exports.deepMergeWithOptions = I, exports.defineStorePlugin = U, exports.deleteByPath = function(t, e) {
|
|
995
|
+
if (!e || 0 === e.length) return !1;
|
|
996
|
+
const r = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
|
|
997
|
+
let n = t;
|
|
998
|
+
for (let t = 0; t < r.length - 1; t++) {
|
|
999
|
+
const e = r[t];
|
|
1000
|
+
if (void 0 === n[e] || null === n[e]) return !1;
|
|
1001
|
+
n = n[e];
|
|
1002
|
+
}
|
|
1003
|
+
const o = r[r.length - 1];
|
|
1004
|
+
if (o in n) {
|
|
1005
|
+
if (Array.isArray(n)) {
|
|
1006
|
+
const t = Number.parseInt(o, 10);
|
|
1007
|
+
if (!Number.isNaN(t)) return n.splice(t, 1), !0;
|
|
1008
|
+
}
|
|
1009
|
+
return delete n[o], !0;
|
|
1010
|
+
}
|
|
1011
|
+
return !1;
|
|
1012
|
+
}, exports.errorUtils = y, exports.getByPath = function(t, e, r) {
|
|
1013
|
+
if (!e || 0 === e.length) return t;
|
|
1014
|
+
const n = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1015
|
+
let o = t;
|
|
1016
|
+
for (const t of n) {
|
|
1017
|
+
if (null == o) return r;
|
|
1018
|
+
if ("object" != typeof o) return r;
|
|
1019
|
+
o = o[t];
|
|
1020
|
+
}
|
|
1021
|
+
return void 0 === o ? r : o;
|
|
1022
|
+
}, exports.getGlobalBatchManager = a, exports.getGlobalMiddlewareManager = function() {
|
|
1023
|
+
return C || (C = j()), C;
|
|
1024
|
+
}, exports.getGlobalPluginManager = function() {
|
|
1025
|
+
return G || (G = F()), G;
|
|
1026
|
+
}, exports.globalEventBus = r, exports.hasPath = function(t, e) {
|
|
1027
|
+
if (!e || 0 === e.length) return !0;
|
|
1028
|
+
const r = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1029
|
+
let n = t;
|
|
1030
|
+
for (const t of r) {
|
|
1031
|
+
if (null == n) return !1;
|
|
1032
|
+
if ("object" != typeof n) return !1;
|
|
1033
|
+
if (!(t in n)) return !1;
|
|
1034
|
+
n = n[t];
|
|
1035
|
+
}
|
|
1036
|
+
return !0;
|
|
1037
|
+
}, exports.isObject = E, exports.isPlainObject = R, exports.name = "@composy/store-core", exports.restoreState = function(t, e = {}) {
|
|
1038
|
+
const r = L(e), n = z(r.storage);
|
|
1039
|
+
if (!n) return null;
|
|
1040
|
+
try {
|
|
1041
|
+
const e = `${r.keyPrefix}${t}`, o = n.getItem(e);
|
|
1042
|
+
if (o) return r.deserialize(o);
|
|
1043
|
+
} catch (e) {
|
|
1044
|
+
console.error(`[Persist] 恢复状态失败 (${t}):`, e);
|
|
1045
|
+
}
|
|
1046
|
+
return null;
|
|
1047
|
+
}, exports.setByPath = function(t, e, r) {
|
|
1048
|
+
if (!e || 0 === e.length) return !1;
|
|
1049
|
+
const n = e.replace(/\[([^\]]+)\]/g, ".$1").split(".").filter(Boolean);
|
|
1050
|
+
let o = t;
|
|
1051
|
+
for (let t = 0; t < n.length - 1; t++) {
|
|
1052
|
+
const e = n[t], r = n[t + 1] ?? "", s = o[e] ?? (A.test(r) ? [] : {});
|
|
1053
|
+
o[e] = s, o = o[e];
|
|
1054
|
+
}
|
|
1055
|
+
return o[n[n.length - 1]] = r, !0;
|
|
1056
|
+
}, exports.setGlobalBatchManager = function(t) {
|
|
1057
|
+
i = t;
|
|
1058
|
+
}, exports.setGlobalMiddlewareManager = function(t) {
|
|
1059
|
+
C = t;
|
|
1060
|
+
}, exports.setGlobalPluginManager = function(t) {
|
|
1061
|
+
G = t;
|
|
1062
|
+
}, exports.setRestoreCallback = function(t, e) {
|
|
1063
|
+
const r = t;
|
|
1064
|
+
"function" != typeof r.__setRestoreCallback ? console.warn("[TimeTravel] 请使用 createTimeTravelMiddleware 返回的 controller") : r.__setRestoreCallback(e);
|
|
1065
|
+
}, exports.shallowClone = function(t) {
|
|
1066
|
+
return null == t || "object" != typeof t ? t : Array.isArray(t) ? [...t] : t instanceof Map ? new Map(t) : t instanceof Set ? new Set(t) : t instanceof Date ? new Date(t.getTime()) : { ...t };
|
|
1067
|
+
}, exports.storeEventKeys = l, exports.storeStateKeys = c, exports.throttle = function(t, e, r = {}) {
|
|
1068
|
+
const { leading: n = !0, trailing: o = !0 } = r;
|
|
1069
|
+
let s = null, i = 0, a = null;
|
|
1070
|
+
const c = (...r) => {
|
|
1071
|
+
const c = Date.now(), l = e - (c - i);
|
|
1072
|
+
a = r, l <= 0 || l > e ? (s && (clearTimeout(s), s = null), i = c, (n || 0 !== i) && t(...r), a = null) : !s && o && (s = setTimeout(() => {
|
|
1073
|
+
i = o ? Date.now() : 0, s = null, a && (t(...a), a = null);
|
|
1074
|
+
}, l));
|
|
1075
|
+
};
|
|
1076
|
+
return c.cancel = () => {
|
|
1077
|
+
s && (clearTimeout(s), s = null), i = 0, a = null;
|
|
1078
|
+
}, c;
|
|
1079
|
+
}, exports.version = "1.0.0";
|
|
1080
|
+
});
|
|
1081
|
+
/*! End of @composy/store-core | Powered by @composy/builder */
|
|
1082
|
+
//# sourceMappingURL=index.min.js.map
|