wevu 1.0.0-alpha.3 → 1.0.0-alpha.4
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/dist/index.cjs +843 -62
- package/dist/index.d.cts +92 -3
- package/dist/index.d.mts +92 -3
- package/dist/index.mjs +785 -11
- package/package.json +1 -1
- package/dist/index-B63NgJPS.d.cts +0 -80
- package/dist/index-Bq83Mwxo.d.mts +0 -80
- package/dist/store-DTqmKv0w.cjs +0 -887
- package/dist/store-YHZDsE3y.mjs +0 -725
- package/dist/store.cjs +0 -5
- package/dist/store.d.cts +0 -2
- package/dist/store.d.mts +0 -2
- package/dist/store.mjs +0 -3
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,489 @@
|
|
|
1
|
-
const require_store = require('./store-DTqmKv0w.cjs');
|
|
2
1
|
|
|
2
|
+
//#region src/scheduler.ts
|
|
3
|
+
const resolvedPromise = Promise.resolve();
|
|
4
|
+
const jobQueue = /* @__PURE__ */ new Set();
|
|
5
|
+
let isFlushing = false;
|
|
6
|
+
function flushJobs() {
|
|
7
|
+
isFlushing = true;
|
|
8
|
+
try {
|
|
9
|
+
jobQueue.forEach((job) => job());
|
|
10
|
+
} finally {
|
|
11
|
+
jobQueue.clear();
|
|
12
|
+
isFlushing = false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function queueJob(job) {
|
|
16
|
+
jobQueue.add(job);
|
|
17
|
+
if (!isFlushing) resolvedPromise.then(flushJobs);
|
|
18
|
+
}
|
|
19
|
+
function nextTick(fn) {
|
|
20
|
+
return fn ? resolvedPromise.then(fn) : resolvedPromise;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/reactivity/core.ts
|
|
25
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
let activeEffect = null;
|
|
27
|
+
const effectStack = [];
|
|
28
|
+
let batchDepth = 0;
|
|
29
|
+
const batchedEffects = /* @__PURE__ */ new Set();
|
|
30
|
+
function startBatch() {
|
|
31
|
+
batchDepth++;
|
|
32
|
+
}
|
|
33
|
+
function endBatch() {
|
|
34
|
+
if (batchDepth === 0) return;
|
|
35
|
+
batchDepth--;
|
|
36
|
+
if (batchDepth === 0) flushBatchedEffects();
|
|
37
|
+
}
|
|
38
|
+
function batch(fn) {
|
|
39
|
+
startBatch();
|
|
40
|
+
try {
|
|
41
|
+
return fn();
|
|
42
|
+
} finally {
|
|
43
|
+
endBatch();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function flushBatchedEffects() {
|
|
47
|
+
while (batchedEffects.size) {
|
|
48
|
+
const effects = Array.from(batchedEffects);
|
|
49
|
+
batchedEffects.clear();
|
|
50
|
+
for (const ef of effects) ef();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
let activeEffectScope;
|
|
54
|
+
var EffectScopeImpl = class {
|
|
55
|
+
active = true;
|
|
56
|
+
effects = [];
|
|
57
|
+
cleanups = [];
|
|
58
|
+
parent;
|
|
59
|
+
scopes;
|
|
60
|
+
constructor(detached = false) {
|
|
61
|
+
this.detached = detached;
|
|
62
|
+
if (!detached && activeEffectScope) {
|
|
63
|
+
this.parent = activeEffectScope;
|
|
64
|
+
(activeEffectScope.scopes ||= []).push(this);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
run(fn) {
|
|
68
|
+
if (!this.active) return;
|
|
69
|
+
const prev = activeEffectScope;
|
|
70
|
+
activeEffectScope = this;
|
|
71
|
+
try {
|
|
72
|
+
return fn();
|
|
73
|
+
} finally {
|
|
74
|
+
activeEffectScope = prev;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
if (!this.active) return;
|
|
79
|
+
this.active = false;
|
|
80
|
+
for (const effect$1 of this.effects) stop(effect$1);
|
|
81
|
+
this.effects.length = 0;
|
|
82
|
+
for (const cleanup of this.cleanups) cleanup();
|
|
83
|
+
this.cleanups.length = 0;
|
|
84
|
+
if (this.scopes) {
|
|
85
|
+
for (const scope of this.scopes) scope.stop();
|
|
86
|
+
this.scopes.length = 0;
|
|
87
|
+
}
|
|
88
|
+
if (this.parent?.scopes) {
|
|
89
|
+
const index = this.parent.scopes.indexOf(this);
|
|
90
|
+
if (index >= 0) this.parent.scopes.splice(index, 1);
|
|
91
|
+
}
|
|
92
|
+
this.parent = void 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function effectScope(detached = false) {
|
|
96
|
+
return new EffectScopeImpl(detached);
|
|
97
|
+
}
|
|
98
|
+
function getCurrentScope() {
|
|
99
|
+
return activeEffectScope;
|
|
100
|
+
}
|
|
101
|
+
function onScopeDispose(fn) {
|
|
102
|
+
if (activeEffectScope?.active) activeEffectScope.cleanups.push(fn);
|
|
103
|
+
}
|
|
104
|
+
function recordEffectScope(effect$1) {
|
|
105
|
+
if (activeEffectScope?.active) activeEffectScope.effects.push(effect$1);
|
|
106
|
+
}
|
|
107
|
+
function cleanupEffect(effect$1) {
|
|
108
|
+
const { deps } = effect$1;
|
|
109
|
+
for (let i = 0; i < deps.length; i++) deps[i].delete(effect$1);
|
|
110
|
+
deps.length = 0;
|
|
111
|
+
}
|
|
112
|
+
function createReactiveEffect(fn, options = {}) {
|
|
113
|
+
const effect$1 = function reactiveEffect() {
|
|
114
|
+
if (!effect$1.active) return fn();
|
|
115
|
+
if (effect$1._running) return fn();
|
|
116
|
+
cleanupEffect(effect$1);
|
|
117
|
+
try {
|
|
118
|
+
effect$1._running = true;
|
|
119
|
+
effectStack.push(effect$1);
|
|
120
|
+
activeEffect = effect$1;
|
|
121
|
+
return fn();
|
|
122
|
+
} finally {
|
|
123
|
+
effectStack.pop();
|
|
124
|
+
activeEffect = effectStack[effectStack.length - 1] ?? null;
|
|
125
|
+
effect$1._running = false;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
effect$1.deps = [];
|
|
129
|
+
effect$1.scheduler = options.scheduler;
|
|
130
|
+
effect$1.onStop = options.onStop;
|
|
131
|
+
effect$1.active = true;
|
|
132
|
+
effect$1._running = false;
|
|
133
|
+
effect$1._fn = fn;
|
|
134
|
+
return effect$1;
|
|
135
|
+
}
|
|
136
|
+
function effect(fn, options = {}) {
|
|
137
|
+
const _effect = createReactiveEffect(fn, options);
|
|
138
|
+
recordEffectScope(_effect);
|
|
139
|
+
if (!options.lazy) _effect();
|
|
140
|
+
return _effect;
|
|
141
|
+
}
|
|
142
|
+
function stop(runner) {
|
|
143
|
+
if (!runner.active) return;
|
|
144
|
+
runner.active = false;
|
|
145
|
+
cleanupEffect(runner);
|
|
146
|
+
runner.onStop?.();
|
|
147
|
+
}
|
|
148
|
+
function track(target, key) {
|
|
149
|
+
if (!activeEffect) return;
|
|
150
|
+
let depsMap = targetMap.get(target);
|
|
151
|
+
if (!depsMap) {
|
|
152
|
+
depsMap = /* @__PURE__ */ new Map();
|
|
153
|
+
targetMap.set(target, depsMap);
|
|
154
|
+
}
|
|
155
|
+
let dep = depsMap.get(key);
|
|
156
|
+
if (!dep) {
|
|
157
|
+
dep = /* @__PURE__ */ new Set();
|
|
158
|
+
depsMap.set(key, dep);
|
|
159
|
+
}
|
|
160
|
+
if (!dep.has(activeEffect)) {
|
|
161
|
+
dep.add(activeEffect);
|
|
162
|
+
activeEffect.deps.push(dep);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function trigger(target, key) {
|
|
166
|
+
const depsMap = targetMap.get(target);
|
|
167
|
+
if (!depsMap) return;
|
|
168
|
+
const effects = depsMap.get(key);
|
|
169
|
+
if (!effects) return;
|
|
170
|
+
const effectsToRun = /* @__PURE__ */ new Set();
|
|
171
|
+
effects.forEach((ef) => {
|
|
172
|
+
if (ef !== activeEffect) effectsToRun.add(ef);
|
|
173
|
+
});
|
|
174
|
+
effectsToRun.forEach(scheduleEffect);
|
|
175
|
+
}
|
|
176
|
+
function trackEffects(dep) {
|
|
177
|
+
if (!activeEffect) return;
|
|
178
|
+
if (!dep.has(activeEffect)) {
|
|
179
|
+
dep.add(activeEffect);
|
|
180
|
+
activeEffect.deps.push(dep);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function triggerEffects(dep) {
|
|
184
|
+
dep.forEach(scheduleEffect);
|
|
185
|
+
}
|
|
186
|
+
function scheduleEffect(ef) {
|
|
187
|
+
if (ef.scheduler) {
|
|
188
|
+
ef.scheduler();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (batchDepth > 0) {
|
|
192
|
+
batchedEffects.add(ef);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
ef();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/reactivity/computed.ts
|
|
200
|
+
function computed(getterOrOptions) {
|
|
201
|
+
let getter;
|
|
202
|
+
let setter;
|
|
203
|
+
const onlyGetter = typeof getterOrOptions === "function";
|
|
204
|
+
if (onlyGetter) {
|
|
205
|
+
getter = getterOrOptions;
|
|
206
|
+
setter = () => {
|
|
207
|
+
throw new Error("Computed value is readonly");
|
|
208
|
+
};
|
|
209
|
+
} else {
|
|
210
|
+
getter = getterOrOptions.get;
|
|
211
|
+
setter = getterOrOptions.set;
|
|
212
|
+
}
|
|
213
|
+
let value;
|
|
214
|
+
let dirty = true;
|
|
215
|
+
let runner;
|
|
216
|
+
const obj = {
|
|
217
|
+
get value() {
|
|
218
|
+
if (dirty) {
|
|
219
|
+
value = runner();
|
|
220
|
+
dirty = false;
|
|
221
|
+
}
|
|
222
|
+
track(obj, "value");
|
|
223
|
+
return value;
|
|
224
|
+
},
|
|
225
|
+
set value(newValue) {
|
|
226
|
+
setter(newValue);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
runner = effect(getter, {
|
|
230
|
+
lazy: true,
|
|
231
|
+
scheduler: () => {
|
|
232
|
+
if (!dirty) {
|
|
233
|
+
dirty = true;
|
|
234
|
+
trigger(obj, "value");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return onlyGetter ? obj : obj;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/reactivity/reactive.ts
|
|
243
|
+
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
244
|
+
const rawMap = /* @__PURE__ */ new WeakMap();
|
|
245
|
+
const rawRootMap = /* @__PURE__ */ new WeakMap();
|
|
246
|
+
let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags$1) {
|
|
247
|
+
ReactiveFlags$1["IS_REACTIVE"] = "__r_isReactive";
|
|
248
|
+
ReactiveFlags$1["RAW"] = "__r_raw";
|
|
249
|
+
ReactiveFlags$1["SKIP"] = "__r_skip";
|
|
250
|
+
return ReactiveFlags$1;
|
|
251
|
+
}({});
|
|
252
|
+
function isObject$1(value) {
|
|
253
|
+
return typeof value === "object" && value !== null;
|
|
254
|
+
}
|
|
255
|
+
const VERSION_KEY = Symbol("wevu.version");
|
|
256
|
+
const mutableHandlers = {
|
|
257
|
+
get(target, key, receiver) {
|
|
258
|
+
if (key === ReactiveFlags.IS_REACTIVE) return true;
|
|
259
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
260
|
+
const res = Reflect.get(target, key, receiver);
|
|
261
|
+
track(target, key);
|
|
262
|
+
if (isObject$1(res)) {
|
|
263
|
+
if (res[ReactiveFlags.SKIP]) return res;
|
|
264
|
+
const child = res;
|
|
265
|
+
const parentRoot = rawRootMap.get(target) ?? target;
|
|
266
|
+
if (!rawRootMap.has(child)) rawRootMap.set(child, parentRoot);
|
|
267
|
+
return reactive(res);
|
|
268
|
+
}
|
|
269
|
+
return res;
|
|
270
|
+
},
|
|
271
|
+
set(target, key, value, receiver) {
|
|
272
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
273
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
274
|
+
if (!Object.is(oldValue, value)) {
|
|
275
|
+
trigger(target, key);
|
|
276
|
+
trigger(target, VERSION_KEY);
|
|
277
|
+
const root = rawRootMap.get(target);
|
|
278
|
+
if (root && root !== target) trigger(root, VERSION_KEY);
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
},
|
|
282
|
+
deleteProperty(target, key) {
|
|
283
|
+
const hadKey = Object.prototype.hasOwnProperty.call(target, key);
|
|
284
|
+
const result = Reflect.deleteProperty(target, key);
|
|
285
|
+
if (hadKey && result) {
|
|
286
|
+
trigger(target, key);
|
|
287
|
+
trigger(target, VERSION_KEY);
|
|
288
|
+
const root = rawRootMap.get(target);
|
|
289
|
+
if (root && root !== target) trigger(root, VERSION_KEY);
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
},
|
|
293
|
+
ownKeys(target) {
|
|
294
|
+
track(target, Symbol.iterator);
|
|
295
|
+
track(target, VERSION_KEY);
|
|
296
|
+
return Reflect.ownKeys(target);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
function reactive(target) {
|
|
300
|
+
if (!isObject$1(target)) return target;
|
|
301
|
+
const existingProxy = reactiveMap.get(target);
|
|
302
|
+
if (existingProxy) return existingProxy;
|
|
303
|
+
if (target[ReactiveFlags.IS_REACTIVE]) return target;
|
|
304
|
+
const proxy = new Proxy(target, mutableHandlers);
|
|
305
|
+
reactiveMap.set(target, proxy);
|
|
306
|
+
rawMap.set(proxy, target);
|
|
307
|
+
if (!rawRootMap.has(target)) rawRootMap.set(target, target);
|
|
308
|
+
return proxy;
|
|
309
|
+
}
|
|
310
|
+
function isReactive(value) {
|
|
311
|
+
return Boolean(value && value[ReactiveFlags.IS_REACTIVE]);
|
|
312
|
+
}
|
|
313
|
+
function toRaw(observed) {
|
|
314
|
+
return observed?.[ReactiveFlags.RAW] ?? observed;
|
|
315
|
+
}
|
|
316
|
+
function convertToReactive(value) {
|
|
317
|
+
return isObject$1(value) ? reactive(value) : value;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
|
|
321
|
+
*/
|
|
322
|
+
function touchReactive(target) {
|
|
323
|
+
track(toRaw(target), VERSION_KEY);
|
|
324
|
+
}
|
|
325
|
+
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
326
|
+
const shallowHandlers = {
|
|
327
|
+
get(target, key, receiver) {
|
|
328
|
+
if (key === ReactiveFlags.IS_REACTIVE) return true;
|
|
329
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
330
|
+
const res = Reflect.get(target, key, receiver);
|
|
331
|
+
track(target, key);
|
|
332
|
+
return res;
|
|
333
|
+
},
|
|
334
|
+
set(target, key, value, receiver) {
|
|
335
|
+
const oldValue = Reflect.get(target, key, receiver);
|
|
336
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
337
|
+
if (!Object.is(oldValue, value)) {
|
|
338
|
+
trigger(target, key);
|
|
339
|
+
trigger(target, VERSION_KEY);
|
|
340
|
+
}
|
|
341
|
+
return result;
|
|
342
|
+
},
|
|
343
|
+
deleteProperty(target, key) {
|
|
344
|
+
const hadKey = Object.prototype.hasOwnProperty.call(target, key);
|
|
345
|
+
const result = Reflect.deleteProperty(target, key);
|
|
346
|
+
if (hadKey && result) {
|
|
347
|
+
trigger(target, key);
|
|
348
|
+
trigger(target, VERSION_KEY);
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
},
|
|
352
|
+
ownKeys(target) {
|
|
353
|
+
track(target, Symbol.iterator);
|
|
354
|
+
track(target, VERSION_KEY);
|
|
355
|
+
return Reflect.ownKeys(target);
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
|
|
360
|
+
*
|
|
361
|
+
* @param target 待转换的对象
|
|
362
|
+
* @returns 浅层响应式代理
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* const state = shallowReactive({ nested: { count: 0 } })
|
|
367
|
+
*
|
|
368
|
+
* state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
|
|
369
|
+
* state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
function shallowReactive(target) {
|
|
373
|
+
if (!isObject$1(target)) return target;
|
|
374
|
+
const existingProxy = shallowReactiveMap.get(target);
|
|
375
|
+
if (existingProxy) return existingProxy;
|
|
376
|
+
if (target[ReactiveFlags.IS_REACTIVE]) return target;
|
|
377
|
+
const proxy = new Proxy(target, shallowHandlers);
|
|
378
|
+
shallowReactiveMap.set(target, proxy);
|
|
379
|
+
rawMap.set(proxy, target);
|
|
380
|
+
return proxy;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* 判断一个值是否为 shallowReactive 创建的浅层响应式对象
|
|
384
|
+
*/
|
|
385
|
+
function isShallowReactive(value) {
|
|
386
|
+
const raw = toRaw(value);
|
|
387
|
+
return shallowReactiveMap.has(raw);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
|
|
391
|
+
*
|
|
392
|
+
* @param value 需要标记的对象
|
|
393
|
+
* @returns 带有跳过标记的原对象
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* const foo = markRaw({
|
|
398
|
+
* nested: {}
|
|
399
|
+
* })
|
|
400
|
+
*
|
|
401
|
+
* const state = reactive({
|
|
402
|
+
* foo
|
|
403
|
+
* })
|
|
404
|
+
*
|
|
405
|
+
* state.foo // 不是响应式对象
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
function markRaw(value) {
|
|
409
|
+
if (!isObject$1(value)) return value;
|
|
410
|
+
Object.defineProperty(value, ReactiveFlags.SKIP, {
|
|
411
|
+
value: true,
|
|
412
|
+
configurable: true,
|
|
413
|
+
enumerable: false,
|
|
414
|
+
writable: true
|
|
415
|
+
});
|
|
416
|
+
return value;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* 判断某个值是否被标记为原始(即不应转换为响应式)。
|
|
420
|
+
*
|
|
421
|
+
* @param value 待检测的值
|
|
422
|
+
* @returns 若含有跳过标记则返回 true
|
|
423
|
+
*/
|
|
424
|
+
function isRaw(value) {
|
|
425
|
+
return isObject$1(value) && ReactiveFlags.SKIP in value;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/reactivity/ref.ts
|
|
430
|
+
function isRef(value) {
|
|
431
|
+
return Boolean(value && typeof value === "object" && "value" in value);
|
|
432
|
+
}
|
|
433
|
+
var RefImpl = class {
|
|
434
|
+
_value;
|
|
435
|
+
_rawValue;
|
|
436
|
+
dep;
|
|
437
|
+
constructor(value) {
|
|
438
|
+
this._rawValue = value;
|
|
439
|
+
this._value = convertToReactive(value);
|
|
440
|
+
}
|
|
441
|
+
get value() {
|
|
442
|
+
if (!this.dep) this.dep = /* @__PURE__ */ new Set();
|
|
443
|
+
trackEffects(this.dep);
|
|
444
|
+
return this._value;
|
|
445
|
+
}
|
|
446
|
+
set value(newValue) {
|
|
447
|
+
if (!Object.is(newValue, this._rawValue)) {
|
|
448
|
+
this._rawValue = newValue;
|
|
449
|
+
this._value = convertToReactive(newValue);
|
|
450
|
+
if (this.dep) triggerEffects(this.dep);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
function ref(value) {
|
|
455
|
+
if (isRef(value)) return value;
|
|
456
|
+
return markRaw(new RefImpl(value));
|
|
457
|
+
}
|
|
458
|
+
function unref(value) {
|
|
459
|
+
return isRef(value) ? value.value : value;
|
|
460
|
+
}
|
|
461
|
+
var CustomRefImpl = class {
|
|
462
|
+
_value;
|
|
463
|
+
_factory;
|
|
464
|
+
dep;
|
|
465
|
+
constructor(factory, defaultValue) {
|
|
466
|
+
this._factory = factory;
|
|
467
|
+
this._value = defaultValue;
|
|
468
|
+
}
|
|
469
|
+
get value() {
|
|
470
|
+
if (!this.dep) this.dep = /* @__PURE__ */ new Set();
|
|
471
|
+
trackEffects(this.dep);
|
|
472
|
+
return this._factory.get();
|
|
473
|
+
}
|
|
474
|
+
set value(newValue) {
|
|
475
|
+
this._factory.set(newValue);
|
|
476
|
+
if (this.dep) triggerEffects(this.dep);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
function customRef(factory, defaultValue) {
|
|
480
|
+
return markRaw(new CustomRefImpl(factory, defaultValue));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
//#endregion
|
|
3
484
|
//#region src/reactivity/readonly.ts
|
|
4
485
|
function readonly(target) {
|
|
5
|
-
if (
|
|
486
|
+
if (isRef(target)) {
|
|
6
487
|
const source = target;
|
|
7
488
|
return {
|
|
8
489
|
get value() {
|
|
@@ -13,7 +494,7 @@ function readonly(target) {
|
|
|
13
494
|
}
|
|
14
495
|
};
|
|
15
496
|
}
|
|
16
|
-
if (!
|
|
497
|
+
if (!isObject$1(target)) return target;
|
|
17
498
|
return new Proxy(target, {
|
|
18
499
|
set() {
|
|
19
500
|
throw new Error("Cannot set property on readonly object");
|
|
@@ -33,15 +514,15 @@ function readonly(target) {
|
|
|
33
514
|
//#endregion
|
|
34
515
|
//#region src/reactivity/shallowRef.ts
|
|
35
516
|
function shallowRef(value, defaultValue) {
|
|
36
|
-
return
|
|
517
|
+
return customRef((track$1, trigger$1) => ({
|
|
37
518
|
get() {
|
|
38
|
-
track();
|
|
519
|
+
track$1();
|
|
39
520
|
return value;
|
|
40
521
|
},
|
|
41
522
|
set(newValue) {
|
|
42
523
|
if (Object.is(value, newValue)) return;
|
|
43
524
|
value = newValue;
|
|
44
|
-
trigger();
|
|
525
|
+
trigger$1();
|
|
45
526
|
}
|
|
46
527
|
}), defaultValue);
|
|
47
528
|
}
|
|
@@ -81,22 +562,22 @@ function triggerRef(ref$1) {
|
|
|
81
562
|
* ```
|
|
82
563
|
*/
|
|
83
564
|
function toRefs(object) {
|
|
84
|
-
if (!
|
|
565
|
+
if (!isReactive(object)) console.warn(`toRefs() expects a reactive object but received a plain one.`);
|
|
85
566
|
const result = Array.isArray(object) ? Array.from({ length: object.length }) : {};
|
|
86
567
|
for (const key in object) result[key] = toRef(object, key);
|
|
87
568
|
return result;
|
|
88
569
|
}
|
|
89
570
|
function toRef(object, key, defaultValue) {
|
|
90
571
|
const value = object[key];
|
|
91
|
-
if (
|
|
92
|
-
return
|
|
572
|
+
if (isRef(value)) return value;
|
|
573
|
+
return customRef((track$1, trigger$1) => ({
|
|
93
574
|
get() {
|
|
94
|
-
track();
|
|
575
|
+
track$1();
|
|
95
576
|
return object[key];
|
|
96
577
|
},
|
|
97
578
|
set(newValue) {
|
|
98
579
|
object[key] = newValue;
|
|
99
|
-
trigger();
|
|
580
|
+
trigger$1();
|
|
100
581
|
}
|
|
101
582
|
}), defaultValue);
|
|
102
583
|
}
|
|
@@ -104,7 +585,7 @@ function toRef(object, key, defaultValue) {
|
|
|
104
585
|
//#endregion
|
|
105
586
|
//#region src/reactivity/traverse.ts
|
|
106
587
|
function traverse(value, seen = /* @__PURE__ */ new Set()) {
|
|
107
|
-
if (!
|
|
588
|
+
if (!isObject$1(value) || seen.has(value)) return value;
|
|
108
589
|
seen.add(value);
|
|
109
590
|
for (const key in value) traverse(value[key], seen);
|
|
110
591
|
return value;
|
|
@@ -122,15 +603,15 @@ function getDeepWatchStrategy() {
|
|
|
122
603
|
function watch(source, cb, options = {}) {
|
|
123
604
|
let getter;
|
|
124
605
|
if (typeof source === "function") getter = source;
|
|
125
|
-
else if (
|
|
126
|
-
else if (
|
|
606
|
+
else if (isRef(source)) getter = () => source.value;
|
|
607
|
+
else if (isReactive(source)) getter = () => source;
|
|
127
608
|
else throw new Error("Invalid watch source");
|
|
128
609
|
if (options.deep) {
|
|
129
610
|
const baseGetter = getter;
|
|
130
611
|
getter = () => {
|
|
131
612
|
const val = baseGetter();
|
|
132
|
-
if (__deepWatchStrategy === "version" &&
|
|
133
|
-
|
|
613
|
+
if (__deepWatchStrategy === "version" && isReactive(val)) {
|
|
614
|
+
touchReactive(val);
|
|
134
615
|
return val;
|
|
135
616
|
}
|
|
136
617
|
return traverse(val);
|
|
@@ -149,8 +630,8 @@ function watch(source, cb, options = {}) {
|
|
|
149
630
|
cb(newValue, oldValue, onCleanup);
|
|
150
631
|
oldValue = newValue;
|
|
151
632
|
};
|
|
152
|
-
runner =
|
|
153
|
-
scheduler: () =>
|
|
633
|
+
runner = effect(() => getter(), {
|
|
634
|
+
scheduler: () => queueJob(job),
|
|
154
635
|
lazy: true
|
|
155
636
|
});
|
|
156
637
|
if (options.immediate) job();
|
|
@@ -158,9 +639,9 @@ function watch(source, cb, options = {}) {
|
|
|
158
639
|
const stopHandle = () => {
|
|
159
640
|
cleanup?.();
|
|
160
641
|
cleanup = void 0;
|
|
161
|
-
|
|
642
|
+
stop(runner);
|
|
162
643
|
};
|
|
163
|
-
|
|
644
|
+
onScopeDispose(stopHandle);
|
|
164
645
|
return stopHandle;
|
|
165
646
|
}
|
|
166
647
|
/**
|
|
@@ -172,13 +653,13 @@ function watchEffect(effectFn) {
|
|
|
172
653
|
const onCleanup = (fn) => {
|
|
173
654
|
cleanup = fn;
|
|
174
655
|
};
|
|
175
|
-
const runner =
|
|
656
|
+
const runner = effect(() => {
|
|
176
657
|
cleanup?.();
|
|
177
658
|
cleanup = void 0;
|
|
178
659
|
effectFn(onCleanup);
|
|
179
660
|
}, {
|
|
180
661
|
lazy: true,
|
|
181
|
-
scheduler: () =>
|
|
662
|
+
scheduler: () => queueJob(() => {
|
|
182
663
|
if (runner.active) runner();
|
|
183
664
|
})
|
|
184
665
|
});
|
|
@@ -186,9 +667,9 @@ function watchEffect(effectFn) {
|
|
|
186
667
|
const stopHandle = () => {
|
|
187
668
|
cleanup?.();
|
|
188
669
|
cleanup = void 0;
|
|
189
|
-
|
|
670
|
+
stop(runner);
|
|
190
671
|
};
|
|
191
|
-
|
|
672
|
+
onScopeDispose(stopHandle);
|
|
192
673
|
return stopHandle;
|
|
193
674
|
}
|
|
194
675
|
|
|
@@ -298,9 +779,9 @@ function isPlainObject$1(value) {
|
|
|
298
779
|
return proto === null || proto === Object.prototype;
|
|
299
780
|
}
|
|
300
781
|
function toPlain(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
301
|
-
const unwrapped =
|
|
782
|
+
const unwrapped = unref(value);
|
|
302
783
|
if (typeof unwrapped !== "object" || unwrapped === null) return unwrapped;
|
|
303
|
-
const raw =
|
|
784
|
+
const raw = isReactive(unwrapped) ? toRaw(unwrapped) : unwrapped;
|
|
304
785
|
if (seen.has(raw)) return seen.get(raw);
|
|
305
786
|
if (Array.isArray(raw)) {
|
|
306
787
|
const arr = [];
|
|
@@ -374,12 +855,19 @@ function diffSnapshots(prev, next) {
|
|
|
374
855
|
//#endregion
|
|
375
856
|
//#region src/runtime/hooks.ts
|
|
376
857
|
let __currentInstance;
|
|
858
|
+
let __currentSetupContext;
|
|
377
859
|
function getCurrentInstance() {
|
|
378
860
|
return __currentInstance;
|
|
379
861
|
}
|
|
380
862
|
function setCurrentInstance(inst) {
|
|
381
863
|
__currentInstance = inst;
|
|
382
864
|
}
|
|
865
|
+
function getCurrentSetupContext() {
|
|
866
|
+
return __currentSetupContext;
|
|
867
|
+
}
|
|
868
|
+
function setCurrentSetupContext(ctx) {
|
|
869
|
+
__currentSetupContext = ctx;
|
|
870
|
+
}
|
|
383
871
|
function ensureHookBucket(target) {
|
|
384
872
|
if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
|
|
385
873
|
return target.__wevuHooks;
|
|
@@ -729,9 +1217,11 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
729
1217
|
expose: (exposed) => {
|
|
730
1218
|
target.__wevuExposed = exposed;
|
|
731
1219
|
},
|
|
732
|
-
attrs: {}
|
|
1220
|
+
attrs: {},
|
|
1221
|
+
slots: Object.create(null)
|
|
733
1222
|
};
|
|
734
1223
|
setCurrentInstance(target);
|
|
1224
|
+
setCurrentSetupContext(context);
|
|
735
1225
|
try {
|
|
736
1226
|
const result = runSetupFunction(setup, props, context);
|
|
737
1227
|
if (result && typeof result === "object") Object.keys(result).forEach((key) => {
|
|
@@ -740,6 +1230,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
740
1230
|
else runtime.state[key] = val;
|
|
741
1231
|
});
|
|
742
1232
|
} finally {
|
|
1233
|
+
setCurrentSetupContext(void 0);
|
|
743
1234
|
setCurrentInstance(void 0);
|
|
744
1235
|
}
|
|
745
1236
|
}
|
|
@@ -1039,7 +1530,7 @@ function createApp(options) {
|
|
|
1039
1530
|
const appConfig = { globalProperties: {} };
|
|
1040
1531
|
const runtimeApp = {
|
|
1041
1532
|
mount(adapter) {
|
|
1042
|
-
const state =
|
|
1533
|
+
const state = reactive((data ?? (() => ({})))());
|
|
1043
1534
|
const computedDefs = resolvedComputed;
|
|
1044
1535
|
const methodDefs = resolvedMethods;
|
|
1045
1536
|
const computedRefs = Object.create(null);
|
|
@@ -1124,18 +1615,18 @@ function createApp(options) {
|
|
|
1124
1615
|
});
|
|
1125
1616
|
Object.keys(computedDefs).forEach((key) => {
|
|
1126
1617
|
const definition = computedDefs[key];
|
|
1127
|
-
if (typeof definition === "function") computedRefs[key] =
|
|
1618
|
+
if (typeof definition === "function") computedRefs[key] = computed(() => definition.call(publicInstance));
|
|
1128
1619
|
else {
|
|
1129
1620
|
const getter = definition.get?.bind(publicInstance);
|
|
1130
1621
|
if (!getter) throw new Error(`Computed property "${key}" requires a getter`);
|
|
1131
1622
|
const setter = definition.set?.bind(publicInstance);
|
|
1132
1623
|
if (setter) {
|
|
1133
1624
|
computedSetters[key] = setter;
|
|
1134
|
-
computedRefs[key] =
|
|
1625
|
+
computedRefs[key] = computed({
|
|
1135
1626
|
get: getter,
|
|
1136
1627
|
set: setter
|
|
1137
1628
|
});
|
|
1138
|
-
} else computedRefs[key] =
|
|
1629
|
+
} else computedRefs[key] = computed(getter);
|
|
1139
1630
|
}
|
|
1140
1631
|
});
|
|
1141
1632
|
const currentAdapter = adapter ?? { setData: () => {} };
|
|
@@ -1159,19 +1650,19 @@ function createApp(options) {
|
|
|
1159
1650
|
}
|
|
1160
1651
|
};
|
|
1161
1652
|
let tracker;
|
|
1162
|
-
tracker =
|
|
1163
|
-
|
|
1653
|
+
tracker = effect(() => {
|
|
1654
|
+
touchReactive(state);
|
|
1164
1655
|
Object.keys(state).forEach((key) => {
|
|
1165
1656
|
const v = state[key];
|
|
1166
|
-
if (
|
|
1657
|
+
if (isRef(v)) v.value;
|
|
1167
1658
|
});
|
|
1168
1659
|
Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
|
|
1169
1660
|
}, {
|
|
1170
1661
|
lazy: true,
|
|
1171
|
-
scheduler: () =>
|
|
1662
|
+
scheduler: () => queueJob(job)
|
|
1172
1663
|
});
|
|
1173
1664
|
job();
|
|
1174
|
-
stopHandles.push(() =>
|
|
1665
|
+
stopHandles.push(() => stop(tracker));
|
|
1175
1666
|
function registerWatch(source, cb, watchOptions) {
|
|
1176
1667
|
const stopHandle = watch(source, (value, oldValue) => cb(value, oldValue), watchOptions);
|
|
1177
1668
|
stopHandles.push(stopHandle);
|
|
@@ -1291,7 +1782,7 @@ function defineComponent(options) {
|
|
|
1291
1782
|
function applySetupResult(runtime, _target, result) {
|
|
1292
1783
|
const methods = runtime?.methods ?? Object.create(null);
|
|
1293
1784
|
const state = runtime?.state ?? Object.create(null);
|
|
1294
|
-
const rawState =
|
|
1785
|
+
const rawState = isReactive(state) ? toRaw(state) : state;
|
|
1295
1786
|
if (runtime && !runtime.methods) try {
|
|
1296
1787
|
runtime.methods = methods;
|
|
1297
1788
|
} catch {}
|
|
@@ -1326,7 +1817,7 @@ function isPlainObject(value) {
|
|
|
1326
1817
|
function shouldExposeInSnapshot(value) {
|
|
1327
1818
|
if (value == null) return true;
|
|
1328
1819
|
if (typeof value !== "object") return true;
|
|
1329
|
-
if (
|
|
1820
|
+
if (isRef(value) || isReactive(value)) return true;
|
|
1330
1821
|
if (Array.isArray(value)) return true;
|
|
1331
1822
|
return isPlainObject(value);
|
|
1332
1823
|
}
|
|
@@ -1352,6 +1843,13 @@ function normalizeProps(baseOptions, props, explicitProperties) {
|
|
|
1352
1843
|
return;
|
|
1353
1844
|
}
|
|
1354
1845
|
if (typeof definition === "object") {
|
|
1846
|
+
if (key.endsWith("Modifiers") && Object.keys(definition).length === 0) {
|
|
1847
|
+
properties[key] = {
|
|
1848
|
+
type: Object,
|
|
1849
|
+
value: {}
|
|
1850
|
+
};
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1355
1853
|
const propOptions = {};
|
|
1356
1854
|
if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
|
|
1357
1855
|
const defaultValue = "default" in definition ? definition.default : definition.value;
|
|
@@ -1442,32 +1940,311 @@ function injectGlobal(key, defaultValue) {
|
|
|
1442
1940
|
}
|
|
1443
1941
|
|
|
1444
1942
|
//#endregion
|
|
1445
|
-
|
|
1943
|
+
//#region src/runtime/vueCompat.ts
|
|
1944
|
+
function useAttrs() {
|
|
1945
|
+
const ctx = getCurrentSetupContext();
|
|
1946
|
+
if (!ctx) throw new Error("useAttrs() must be called synchronously inside setup()");
|
|
1947
|
+
return ctx.attrs ?? {};
|
|
1948
|
+
}
|
|
1949
|
+
function useSlots() {
|
|
1950
|
+
const ctx = getCurrentSetupContext();
|
|
1951
|
+
if (!ctx) throw new Error("useSlots() must be called synchronously inside setup()");
|
|
1952
|
+
return ctx.slots ?? Object.create(null);
|
|
1953
|
+
}
|
|
1954
|
+
function useModel(props, name) {
|
|
1955
|
+
const ctx = getCurrentSetupContext();
|
|
1956
|
+
if (!ctx) throw new Error("useModel() must be called synchronously inside setup()");
|
|
1957
|
+
const emit = ctx.emit;
|
|
1958
|
+
const eventName = `update:${name}`;
|
|
1959
|
+
return customRef({
|
|
1960
|
+
get: () => props?.[name],
|
|
1961
|
+
set: (value) => {
|
|
1962
|
+
emit?.(eventName, value);
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
}
|
|
1966
|
+
function mergeModels(a, b) {
|
|
1967
|
+
if (a == null) return b;
|
|
1968
|
+
if (b == null) return a;
|
|
1969
|
+
if (Array.isArray(a) && Array.isArray(b)) return Array.from(new Set([...a, ...b]));
|
|
1970
|
+
if (typeof a === "object" && typeof b === "object") return {
|
|
1971
|
+
...a,
|
|
1972
|
+
...b
|
|
1973
|
+
};
|
|
1974
|
+
return b;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
//#endregion
|
|
1978
|
+
//#region src/store/actions.ts
|
|
1979
|
+
function wrapAction(store, name, action, actionSubs) {
|
|
1980
|
+
return function wrapped(...args) {
|
|
1981
|
+
const afterCbs = [];
|
|
1982
|
+
const errorCbs = [];
|
|
1983
|
+
const after = (cb) => afterCbs.push(cb);
|
|
1984
|
+
const onError$1 = (cb) => errorCbs.push(cb);
|
|
1985
|
+
actionSubs.forEach((sub) => {
|
|
1986
|
+
try {
|
|
1987
|
+
sub({
|
|
1988
|
+
name,
|
|
1989
|
+
store,
|
|
1990
|
+
args,
|
|
1991
|
+
after,
|
|
1992
|
+
onError: onError$1
|
|
1993
|
+
});
|
|
1994
|
+
} catch {}
|
|
1995
|
+
});
|
|
1996
|
+
let res;
|
|
1997
|
+
try {
|
|
1998
|
+
res = action.apply(store, args);
|
|
1999
|
+
} catch (e) {
|
|
2000
|
+
errorCbs.forEach((cb) => cb(e));
|
|
2001
|
+
throw e;
|
|
2002
|
+
}
|
|
2003
|
+
const finalize = (r) => {
|
|
2004
|
+
afterCbs.forEach((cb) => cb(r));
|
|
2005
|
+
return r;
|
|
2006
|
+
};
|
|
2007
|
+
if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
|
|
2008
|
+
errorCbs.forEach((cb) => cb(e));
|
|
2009
|
+
return Promise.reject(e);
|
|
2010
|
+
});
|
|
2011
|
+
return finalize(res);
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
//#endregion
|
|
2016
|
+
//#region src/store/utils.ts
|
|
2017
|
+
function isObject(val) {
|
|
2018
|
+
return typeof val === "object" && val !== null;
|
|
2019
|
+
}
|
|
2020
|
+
function mergeShallow(target, patch) {
|
|
2021
|
+
for (const k in patch) target[k] = patch[k];
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
//#endregion
|
|
2025
|
+
//#region src/store/base.ts
|
|
2026
|
+
function createBaseApi(id, stateObj, notify, resetImpl) {
|
|
2027
|
+
const api = { $id: id };
|
|
2028
|
+
Object.defineProperty(api, "$state", {
|
|
2029
|
+
get() {
|
|
2030
|
+
return stateObj;
|
|
2031
|
+
},
|
|
2032
|
+
set(v) {
|
|
2033
|
+
if (stateObj && isObject(v)) {
|
|
2034
|
+
mergeShallow(stateObj, v);
|
|
2035
|
+
notify("patch object");
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
api.$patch = (patch) => {
|
|
2040
|
+
if (!stateObj) {
|
|
2041
|
+
if (typeof patch === "function") {
|
|
2042
|
+
patch(api);
|
|
2043
|
+
notify("patch function");
|
|
2044
|
+
} else {
|
|
2045
|
+
mergeShallow(api, patch);
|
|
2046
|
+
notify("patch object");
|
|
2047
|
+
}
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
if (typeof patch === "function") {
|
|
2051
|
+
patch(stateObj);
|
|
2052
|
+
notify("patch function");
|
|
2053
|
+
} else {
|
|
2054
|
+
mergeShallow(stateObj, patch);
|
|
2055
|
+
notify("patch object");
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
if (resetImpl) api.$reset = () => resetImpl();
|
|
2059
|
+
const subs = /* @__PURE__ */ new Set();
|
|
2060
|
+
api.$subscribe = (cb, _opts) => {
|
|
2061
|
+
subs.add(cb);
|
|
2062
|
+
return () => subs.delete(cb);
|
|
2063
|
+
};
|
|
2064
|
+
const actionSubs = /* @__PURE__ */ new Set();
|
|
2065
|
+
api.$onAction = (cb) => {
|
|
2066
|
+
actionSubs.add(cb);
|
|
2067
|
+
return () => actionSubs.delete(cb);
|
|
2068
|
+
};
|
|
2069
|
+
return {
|
|
2070
|
+
api,
|
|
2071
|
+
subs,
|
|
2072
|
+
actionSubs
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
//#endregion
|
|
2077
|
+
//#region src/store/manager.ts
|
|
2078
|
+
function createStore() {
|
|
2079
|
+
const manager = {
|
|
2080
|
+
_stores: /* @__PURE__ */ new Map(),
|
|
2081
|
+
_plugins: [],
|
|
2082
|
+
install(_app) {},
|
|
2083
|
+
use(plugin) {
|
|
2084
|
+
if (typeof plugin === "function") manager._plugins.push(plugin);
|
|
2085
|
+
return manager;
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
createStore._instance = manager;
|
|
2089
|
+
return manager;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
//#endregion
|
|
2093
|
+
//#region src/store/define.ts
|
|
2094
|
+
function defineStore(id, setupOrOptions) {
|
|
2095
|
+
let instance;
|
|
2096
|
+
let created = false;
|
|
2097
|
+
const manager = createStore._instance;
|
|
2098
|
+
return function useStore() {
|
|
2099
|
+
if (created && instance) return instance;
|
|
2100
|
+
created = true;
|
|
2101
|
+
if (typeof setupOrOptions === "function") {
|
|
2102
|
+
const result = setupOrOptions();
|
|
2103
|
+
let notify$1 = () => {};
|
|
2104
|
+
const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
|
|
2105
|
+
notify$1 = (type) => {
|
|
2106
|
+
base$1.subs.forEach((cb) => {
|
|
2107
|
+
try {
|
|
2108
|
+
cb({
|
|
2109
|
+
type,
|
|
2110
|
+
storeId: id
|
|
2111
|
+
}, instance);
|
|
2112
|
+
} catch {}
|
|
2113
|
+
});
|
|
2114
|
+
};
|
|
2115
|
+
instance = Object.assign({}, result);
|
|
2116
|
+
for (const key of Object.getOwnPropertyNames(base$1.api)) {
|
|
2117
|
+
const d = Object.getOwnPropertyDescriptor(base$1.api, key);
|
|
2118
|
+
if (d) Object.defineProperty(instance, key, d);
|
|
2119
|
+
}
|
|
2120
|
+
Object.keys(result).forEach((k) => {
|
|
2121
|
+
const val = result[k];
|
|
2122
|
+
if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
|
|
2123
|
+
});
|
|
2124
|
+
const plugins$1 = manager?._plugins ?? [];
|
|
2125
|
+
for (const plugin of plugins$1) try {
|
|
2126
|
+
plugin({ store: instance });
|
|
2127
|
+
} catch {}
|
|
2128
|
+
return instance;
|
|
2129
|
+
}
|
|
2130
|
+
const options = setupOrOptions;
|
|
2131
|
+
const rawState = options.state ? options.state() : {};
|
|
2132
|
+
const state = reactive(rawState);
|
|
2133
|
+
const initialSnapshot = { ...toRaw(rawState) };
|
|
2134
|
+
let notify = () => {};
|
|
2135
|
+
const base = createBaseApi(id, state, (t) => notify(t), () => {
|
|
2136
|
+
mergeShallow(state, initialSnapshot);
|
|
2137
|
+
notify("patch object");
|
|
2138
|
+
});
|
|
2139
|
+
notify = (type) => {
|
|
2140
|
+
base.subs.forEach((cb) => {
|
|
2141
|
+
try {
|
|
2142
|
+
cb({
|
|
2143
|
+
type,
|
|
2144
|
+
storeId: id
|
|
2145
|
+
}, state);
|
|
2146
|
+
} catch {}
|
|
2147
|
+
});
|
|
2148
|
+
};
|
|
2149
|
+
const store = {};
|
|
2150
|
+
for (const key of Object.getOwnPropertyNames(base.api)) {
|
|
2151
|
+
const d = Object.getOwnPropertyDescriptor(base.api, key);
|
|
2152
|
+
if (d) Object.defineProperty(store, key, d);
|
|
2153
|
+
}
|
|
2154
|
+
const getterDefs = options.getters ?? {};
|
|
2155
|
+
const computedMap = {};
|
|
2156
|
+
Object.keys(getterDefs).forEach((key) => {
|
|
2157
|
+
const getter = getterDefs[key];
|
|
2158
|
+
if (typeof getter === "function") {
|
|
2159
|
+
const c = computed(() => getter.call(store, state));
|
|
2160
|
+
computedMap[key] = c;
|
|
2161
|
+
Object.defineProperty(store, key, {
|
|
2162
|
+
enumerable: true,
|
|
2163
|
+
configurable: true,
|
|
2164
|
+
get() {
|
|
2165
|
+
return c.value;
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
});
|
|
2170
|
+
const actionDefs = options.actions ?? {};
|
|
2171
|
+
Object.keys(actionDefs).forEach((key) => {
|
|
2172
|
+
const act = actionDefs[key];
|
|
2173
|
+
if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
|
|
2174
|
+
return act.apply(store, args);
|
|
2175
|
+
}, base.actionSubs);
|
|
2176
|
+
});
|
|
2177
|
+
Object.keys(state).forEach((k) => {
|
|
2178
|
+
Object.defineProperty(store, k, {
|
|
2179
|
+
enumerable: true,
|
|
2180
|
+
configurable: true,
|
|
2181
|
+
get() {
|
|
2182
|
+
return state[k];
|
|
2183
|
+
},
|
|
2184
|
+
set(v) {
|
|
2185
|
+
state[k] = v;
|
|
2186
|
+
}
|
|
2187
|
+
});
|
|
2188
|
+
});
|
|
2189
|
+
instance = store;
|
|
2190
|
+
const plugins = manager?._plugins ?? [];
|
|
2191
|
+
for (const plugin of plugins) try {
|
|
2192
|
+
plugin({ store: instance });
|
|
2193
|
+
} catch {}
|
|
2194
|
+
return instance;
|
|
2195
|
+
};
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
//#endregion
|
|
2199
|
+
//#region src/store/storeToRefs.ts
|
|
2200
|
+
function storeToRefs(store) {
|
|
2201
|
+
const result = {};
|
|
2202
|
+
for (const key in store) {
|
|
2203
|
+
const value = store[key];
|
|
2204
|
+
if (typeof value === "function") {
|
|
2205
|
+
result[key] = value;
|
|
2206
|
+
continue;
|
|
2207
|
+
}
|
|
2208
|
+
if (isRef(value)) result[key] = value;
|
|
2209
|
+
else result[key] = computed({
|
|
2210
|
+
get: () => store[key],
|
|
2211
|
+
set: (v) => {
|
|
2212
|
+
store[key] = v;
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
return result;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
//#endregion
|
|
2220
|
+
exports.batch = batch;
|
|
1446
2221
|
exports.callHookList = callHookList;
|
|
1447
2222
|
exports.callHookReturn = callHookReturn;
|
|
1448
2223
|
exports.callUpdateHooks = callUpdateHooks;
|
|
1449
|
-
exports.computed =
|
|
2224
|
+
exports.computed = computed;
|
|
1450
2225
|
exports.createApp = createApp;
|
|
1451
|
-
exports.createStore =
|
|
2226
|
+
exports.createStore = createStore;
|
|
1452
2227
|
exports.createWevuComponent = createWevuComponent;
|
|
1453
2228
|
exports.defineComponent = defineComponent;
|
|
1454
|
-
exports.defineStore =
|
|
1455
|
-
exports.effect =
|
|
1456
|
-
exports.effectScope =
|
|
1457
|
-
exports.endBatch =
|
|
2229
|
+
exports.defineStore = defineStore;
|
|
2230
|
+
exports.effect = effect;
|
|
2231
|
+
exports.effectScope = effectScope;
|
|
2232
|
+
exports.endBatch = endBatch;
|
|
1458
2233
|
exports.getCurrentInstance = getCurrentInstance;
|
|
1459
|
-
exports.getCurrentScope =
|
|
2234
|
+
exports.getCurrentScope = getCurrentScope;
|
|
2235
|
+
exports.getCurrentSetupContext = getCurrentSetupContext;
|
|
1460
2236
|
exports.getDeepWatchStrategy = getDeepWatchStrategy;
|
|
1461
2237
|
exports.inject = inject;
|
|
1462
2238
|
exports.injectGlobal = injectGlobal;
|
|
1463
|
-
exports.isRaw =
|
|
1464
|
-
exports.isReactive =
|
|
1465
|
-
exports.isRef =
|
|
1466
|
-
exports.isShallowReactive =
|
|
2239
|
+
exports.isRaw = isRaw;
|
|
2240
|
+
exports.isReactive = isReactive;
|
|
2241
|
+
exports.isRef = isRef;
|
|
2242
|
+
exports.isShallowReactive = isShallowReactive;
|
|
1467
2243
|
exports.isShallowRef = isShallowRef;
|
|
1468
|
-
exports.markRaw =
|
|
2244
|
+
exports.markRaw = markRaw;
|
|
2245
|
+
exports.mergeModels = mergeModels;
|
|
1469
2246
|
exports.mountRuntimeInstance = mountRuntimeInstance;
|
|
1470
|
-
exports.nextTick =
|
|
2247
|
+
exports.nextTick = nextTick;
|
|
1471
2248
|
exports.onActivated = onActivated;
|
|
1472
2249
|
exports.onAddToFavorites = onAddToFavorites;
|
|
1473
2250
|
exports.onAppError = onAppError;
|
|
@@ -1490,7 +2267,7 @@ exports.onReady = onReady;
|
|
|
1490
2267
|
exports.onResize = onResize;
|
|
1491
2268
|
exports.onRouteDone = onRouteDone;
|
|
1492
2269
|
exports.onSaveExitState = onSaveExitState;
|
|
1493
|
-
exports.onScopeDispose =
|
|
2270
|
+
exports.onScopeDispose = onScopeDispose;
|
|
1494
2271
|
exports.onServerPrefetch = onServerPrefetch;
|
|
1495
2272
|
exports.onShareAppMessage = onShareAppMessage;
|
|
1496
2273
|
exports.onShareTimeline = onShareTimeline;
|
|
@@ -1501,26 +2278,30 @@ exports.onUnmounted = onUnmounted;
|
|
|
1501
2278
|
exports.onUpdated = onUpdated;
|
|
1502
2279
|
exports.provide = provide;
|
|
1503
2280
|
exports.provideGlobal = provideGlobal;
|
|
1504
|
-
exports.reactive =
|
|
2281
|
+
exports.reactive = reactive;
|
|
1505
2282
|
exports.readonly = readonly;
|
|
1506
|
-
exports.ref =
|
|
2283
|
+
exports.ref = ref;
|
|
1507
2284
|
exports.registerApp = registerApp;
|
|
1508
2285
|
exports.registerComponent = registerComponent;
|
|
1509
2286
|
exports.runSetupFunction = runSetupFunction;
|
|
1510
2287
|
exports.setCurrentInstance = setCurrentInstance;
|
|
2288
|
+
exports.setCurrentSetupContext = setCurrentSetupContext;
|
|
1511
2289
|
exports.setDeepWatchStrategy = setDeepWatchStrategy;
|
|
1512
|
-
exports.shallowReactive =
|
|
2290
|
+
exports.shallowReactive = shallowReactive;
|
|
1513
2291
|
exports.shallowRef = shallowRef;
|
|
1514
|
-
exports.startBatch =
|
|
1515
|
-
exports.stop =
|
|
1516
|
-
exports.storeToRefs =
|
|
2292
|
+
exports.startBatch = startBatch;
|
|
2293
|
+
exports.stop = stop;
|
|
2294
|
+
exports.storeToRefs = storeToRefs;
|
|
1517
2295
|
exports.teardownRuntimeInstance = teardownRuntimeInstance;
|
|
1518
|
-
exports.toRaw =
|
|
2296
|
+
exports.toRaw = toRaw;
|
|
1519
2297
|
exports.toRef = toRef;
|
|
1520
2298
|
exports.toRefs = toRefs;
|
|
1521
|
-
exports.touchReactive =
|
|
2299
|
+
exports.touchReactive = touchReactive;
|
|
1522
2300
|
exports.traverse = traverse;
|
|
1523
2301
|
exports.triggerRef = triggerRef;
|
|
1524
|
-
exports.unref =
|
|
2302
|
+
exports.unref = unref;
|
|
2303
|
+
exports.useAttrs = useAttrs;
|
|
2304
|
+
exports.useModel = useModel;
|
|
2305
|
+
exports.useSlots = useSlots;
|
|
1525
2306
|
exports.watch = watch;
|
|
1526
2307
|
exports.watchEffect = watchEffect;
|