wevu 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +927 -65
- package/dist/index.d.cts +89 -2
- package/dist/index.d.mts +89 -2
- package/dist/index.mjs +869 -14
- package/package.json +2 -2
- 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
|
|
|
@@ -224,7 +705,11 @@ function setByPath(state, computedRefs, computedSetters, segments, value) {
|
|
|
224
705
|
const [head, ...rest] = segments;
|
|
225
706
|
if (!rest.length) {
|
|
226
707
|
if (computedRefs[head]) setComputedValue$1(computedSetters, head, value);
|
|
227
|
-
else
|
|
708
|
+
else {
|
|
709
|
+
const current = state[head];
|
|
710
|
+
if (isRef(current)) current.value = value;
|
|
711
|
+
else state[head] = value;
|
|
712
|
+
}
|
|
228
713
|
return;
|
|
229
714
|
}
|
|
230
715
|
if (computedRefs[head]) {
|
|
@@ -298,9 +783,9 @@ function isPlainObject$1(value) {
|
|
|
298
783
|
return proto === null || proto === Object.prototype;
|
|
299
784
|
}
|
|
300
785
|
function toPlain(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
301
|
-
const unwrapped =
|
|
786
|
+
const unwrapped = unref(value);
|
|
302
787
|
if (typeof unwrapped !== "object" || unwrapped === null) return unwrapped;
|
|
303
|
-
const raw =
|
|
788
|
+
const raw = isReactive(unwrapped) ? toRaw(unwrapped) : unwrapped;
|
|
304
789
|
if (seen.has(raw)) return seen.get(raw);
|
|
305
790
|
if (Array.isArray(raw)) {
|
|
306
791
|
const arr = [];
|
|
@@ -374,12 +859,19 @@ function diffSnapshots(prev, next) {
|
|
|
374
859
|
//#endregion
|
|
375
860
|
//#region src/runtime/hooks.ts
|
|
376
861
|
let __currentInstance;
|
|
862
|
+
let __currentSetupContext;
|
|
377
863
|
function getCurrentInstance() {
|
|
378
864
|
return __currentInstance;
|
|
379
865
|
}
|
|
380
866
|
function setCurrentInstance(inst) {
|
|
381
867
|
__currentInstance = inst;
|
|
382
868
|
}
|
|
869
|
+
function getCurrentSetupContext() {
|
|
870
|
+
return __currentSetupContext;
|
|
871
|
+
}
|
|
872
|
+
function setCurrentSetupContext(ctx) {
|
|
873
|
+
__currentSetupContext = ctx;
|
|
874
|
+
}
|
|
383
875
|
function ensureHookBucket(target) {
|
|
384
876
|
if (!target.__wevuHooks) target.__wevuHooks = Object.create(null);
|
|
385
877
|
return target.__wevuHooks;
|
|
@@ -579,6 +1071,17 @@ function callUpdateHooks(target, phase) {
|
|
|
579
1071
|
|
|
580
1072
|
//#endregion
|
|
581
1073
|
//#region src/runtime/register.ts
|
|
1074
|
+
function decodeWxmlEntities(value) {
|
|
1075
|
+
return value.replace(/&/g, "&").replace(/"/g, "\"").replace(/"/g, "\"").replace(/'/g, "'").replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
1076
|
+
}
|
|
1077
|
+
function parseModelEventValue(event) {
|
|
1078
|
+
if (event == null) return event;
|
|
1079
|
+
if (typeof event === "object") {
|
|
1080
|
+
if ("detail" in event && event.detail && "value" in event.detail) return event.detail.value;
|
|
1081
|
+
if ("target" in event && event.target && "value" in event.target) return event.target.value;
|
|
1082
|
+
}
|
|
1083
|
+
return event;
|
|
1084
|
+
}
|
|
582
1085
|
function runInlineExpression(ctx, expr, event) {
|
|
583
1086
|
const handlerName = typeof expr === "string" ? expr : void 0;
|
|
584
1087
|
if (!handlerName) return;
|
|
@@ -587,8 +1090,13 @@ function runInlineExpression(ctx, expr, event) {
|
|
|
587
1090
|
if (typeof argsRaw === "string") try {
|
|
588
1091
|
args = JSON.parse(argsRaw);
|
|
589
1092
|
} catch {
|
|
590
|
-
|
|
1093
|
+
try {
|
|
1094
|
+
args = JSON.parse(decodeWxmlEntities(argsRaw));
|
|
1095
|
+
} catch {
|
|
1096
|
+
args = [];
|
|
1097
|
+
}
|
|
591
1098
|
}
|
|
1099
|
+
if (!Array.isArray(args)) args = [];
|
|
592
1100
|
const resolvedArgs = args.map((item) => item === "$event" ? event : item);
|
|
593
1101
|
const handler = ctx?.[handlerName];
|
|
594
1102
|
if (typeof handler === "function") return handler.apply(ctx, resolvedArgs);
|
|
@@ -714,7 +1222,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
714
1222
|
if (stops.length) target.__wevuWatchStops = stops;
|
|
715
1223
|
}
|
|
716
1224
|
if (setup) {
|
|
717
|
-
const props = target.properties || {};
|
|
1225
|
+
const props = shallowReactive({ ...target.properties || {} });
|
|
1226
|
+
try {
|
|
1227
|
+
Object.defineProperty(target, "__wevuProps", {
|
|
1228
|
+
value: props,
|
|
1229
|
+
configurable: true,
|
|
1230
|
+
enumerable: false,
|
|
1231
|
+
writable: false
|
|
1232
|
+
});
|
|
1233
|
+
} catch {
|
|
1234
|
+
target.__wevuProps = props;
|
|
1235
|
+
}
|
|
718
1236
|
const context = {
|
|
719
1237
|
props,
|
|
720
1238
|
runtime: runtimeWithDefaults,
|
|
@@ -729,9 +1247,11 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
729
1247
|
expose: (exposed) => {
|
|
730
1248
|
target.__wevuExposed = exposed;
|
|
731
1249
|
},
|
|
732
|
-
attrs: {}
|
|
1250
|
+
attrs: {},
|
|
1251
|
+
slots: Object.create(null)
|
|
733
1252
|
};
|
|
734
1253
|
setCurrentInstance(target);
|
|
1254
|
+
setCurrentSetupContext(context);
|
|
735
1255
|
try {
|
|
736
1256
|
const result = runSetupFunction(setup, props, context);
|
|
737
1257
|
if (result && typeof result === "object") Object.keys(result).forEach((key) => {
|
|
@@ -740,6 +1260,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
|
740
1260
|
else runtime.state[key] = val;
|
|
741
1261
|
});
|
|
742
1262
|
} finally {
|
|
1263
|
+
setCurrentSetupContext(void 0);
|
|
743
1264
|
setCurrentInstance(void 0);
|
|
744
1265
|
}
|
|
745
1266
|
}
|
|
@@ -831,6 +1352,7 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
831
1352
|
const userOnAddToFavorites = rest.onAddToFavorites;
|
|
832
1353
|
const features = rest.features ?? {};
|
|
833
1354
|
const restOptions = { ...rest };
|
|
1355
|
+
const userObservers = restOptions.observers;
|
|
834
1356
|
const legacyCreated = restOptions.created;
|
|
835
1357
|
delete restOptions.features;
|
|
836
1358
|
delete restOptions.created;
|
|
@@ -886,11 +1408,56 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
886
1408
|
multipleSlots: userOptions.multipleSlots ?? true,
|
|
887
1409
|
...userOptions
|
|
888
1410
|
};
|
|
1411
|
+
const syncWevuPropsFromInstance = (instance) => {
|
|
1412
|
+
const propsProxy = instance.__wevuProps;
|
|
1413
|
+
const properties = instance.properties;
|
|
1414
|
+
if (!propsProxy || typeof propsProxy !== "object") return;
|
|
1415
|
+
if (!properties || typeof properties !== "object") return;
|
|
1416
|
+
const next = properties;
|
|
1417
|
+
const currentKeys = Object.keys(propsProxy);
|
|
1418
|
+
for (const existingKey of currentKeys) if (!Object.prototype.hasOwnProperty.call(next, existingKey)) try {
|
|
1419
|
+
delete propsProxy[existingKey];
|
|
1420
|
+
} catch {}
|
|
1421
|
+
for (const [k, v] of Object.entries(next)) try {
|
|
1422
|
+
propsProxy[k] = v;
|
|
1423
|
+
} catch {}
|
|
1424
|
+
};
|
|
1425
|
+
const syncWevuPropValue = (instance, key, value) => {
|
|
1426
|
+
const propsProxy = instance.__wevuProps;
|
|
1427
|
+
if (!propsProxy || typeof propsProxy !== "object") return;
|
|
1428
|
+
try {
|
|
1429
|
+
propsProxy[key] = value;
|
|
1430
|
+
} catch {}
|
|
1431
|
+
};
|
|
1432
|
+
const propKeys = restOptions.properties && typeof restOptions.properties === "object" ? Object.keys(restOptions.properties) : [];
|
|
1433
|
+
const injectedObservers = {};
|
|
1434
|
+
if (propKeys.length) for (const key of propKeys) injectedObservers[key] = function __wevu_prop_observer(newValue) {
|
|
1435
|
+
syncWevuPropValue(this, key, newValue);
|
|
1436
|
+
};
|
|
1437
|
+
const finalObservers = { ...userObservers ?? {} };
|
|
1438
|
+
for (const [key, injected] of Object.entries(injectedObservers)) {
|
|
1439
|
+
const existing = finalObservers[key];
|
|
1440
|
+
if (typeof existing === "function") finalObservers[key] = function chainedObserver(...args) {
|
|
1441
|
+
existing.apply(this, args);
|
|
1442
|
+
injected.apply(this, args);
|
|
1443
|
+
};
|
|
1444
|
+
else finalObservers[key] = injected;
|
|
1445
|
+
}
|
|
889
1446
|
const finalMethods = { ...userMethods };
|
|
890
1447
|
if (!finalMethods.__weapp_vite_inline) finalMethods.__weapp_vite_inline = function __weapp_vite_inline(event) {
|
|
891
1448
|
const expr = event?.currentTarget?.dataset?.wvHandler ?? event?.target?.dataset?.wvHandler;
|
|
892
1449
|
return runInlineExpression(this.__wevu?.proxy ?? this, expr, event);
|
|
893
1450
|
};
|
|
1451
|
+
if (!finalMethods.__weapp_vite_model) finalMethods.__weapp_vite_model = function __weapp_vite_model(event) {
|
|
1452
|
+
const path = event?.currentTarget?.dataset?.wvModel ?? event?.target?.dataset?.wvModel;
|
|
1453
|
+
if (typeof path !== "string" || !path) return;
|
|
1454
|
+
const runtime = this.__wevu;
|
|
1455
|
+
if (!runtime || typeof runtime.bindModel !== "function") return;
|
|
1456
|
+
const value = parseModelEventValue(event);
|
|
1457
|
+
try {
|
|
1458
|
+
runtime.bindModel(path).update(value);
|
|
1459
|
+
} catch {}
|
|
1460
|
+
};
|
|
894
1461
|
const methodNames = Object.keys(methods ?? {});
|
|
895
1462
|
for (const methodName of methodNames) {
|
|
896
1463
|
const userMethod = finalMethods[methodName];
|
|
@@ -977,10 +1544,12 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
977
1544
|
Component({
|
|
978
1545
|
...restOptions,
|
|
979
1546
|
...pageLifecycleHooks,
|
|
1547
|
+
observers: finalObservers,
|
|
980
1548
|
lifetimes: {
|
|
981
1549
|
...userLifetimes,
|
|
982
1550
|
created: function created(...args) {
|
|
983
1551
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
|
|
1552
|
+
syncWevuPropsFromInstance(this);
|
|
984
1553
|
if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
|
|
985
1554
|
if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
|
|
986
1555
|
},
|
|
@@ -990,12 +1559,14 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
990
1559
|
},
|
|
991
1560
|
attached: function attached(...args) {
|
|
992
1561
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup);
|
|
1562
|
+
syncWevuPropsFromInstance(this);
|
|
993
1563
|
enableDeferredSetData(this);
|
|
994
1564
|
if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
|
|
995
1565
|
},
|
|
996
1566
|
ready: function ready(...args) {
|
|
997
1567
|
if (!this.__wevuReadyCalled) {
|
|
998
1568
|
this.__wevuReadyCalled = true;
|
|
1569
|
+
syncWevuPropsFromInstance(this);
|
|
999
1570
|
callHookList(this, "onReady", args);
|
|
1000
1571
|
}
|
|
1001
1572
|
if (typeof userLifetimes.ready === "function") userLifetimes.ready.apply(this, args);
|
|
@@ -1039,7 +1610,7 @@ function createApp(options) {
|
|
|
1039
1610
|
const appConfig = { globalProperties: {} };
|
|
1040
1611
|
const runtimeApp = {
|
|
1041
1612
|
mount(adapter) {
|
|
1042
|
-
const state =
|
|
1613
|
+
const state = reactive((data ?? (() => ({})))());
|
|
1043
1614
|
const computedDefs = resolvedComputed;
|
|
1044
1615
|
const methodDefs = resolvedMethods;
|
|
1045
1616
|
const computedRefs = Object.create(null);
|
|
@@ -1124,18 +1695,18 @@ function createApp(options) {
|
|
|
1124
1695
|
});
|
|
1125
1696
|
Object.keys(computedDefs).forEach((key) => {
|
|
1126
1697
|
const definition = computedDefs[key];
|
|
1127
|
-
if (typeof definition === "function") computedRefs[key] =
|
|
1698
|
+
if (typeof definition === "function") computedRefs[key] = computed(() => definition.call(publicInstance));
|
|
1128
1699
|
else {
|
|
1129
1700
|
const getter = definition.get?.bind(publicInstance);
|
|
1130
1701
|
if (!getter) throw new Error(`Computed property "${key}" requires a getter`);
|
|
1131
1702
|
const setter = definition.set?.bind(publicInstance);
|
|
1132
1703
|
if (setter) {
|
|
1133
1704
|
computedSetters[key] = setter;
|
|
1134
|
-
computedRefs[key] =
|
|
1705
|
+
computedRefs[key] = computed({
|
|
1135
1706
|
get: getter,
|
|
1136
1707
|
set: setter
|
|
1137
1708
|
});
|
|
1138
|
-
} else computedRefs[key] =
|
|
1709
|
+
} else computedRefs[key] = computed(getter);
|
|
1139
1710
|
}
|
|
1140
1711
|
});
|
|
1141
1712
|
const currentAdapter = adapter ?? { setData: () => {} };
|
|
@@ -1159,19 +1730,20 @@ function createApp(options) {
|
|
|
1159
1730
|
}
|
|
1160
1731
|
};
|
|
1161
1732
|
let tracker;
|
|
1162
|
-
tracker =
|
|
1163
|
-
|
|
1733
|
+
tracker = effect(() => {
|
|
1734
|
+
touchReactive(state);
|
|
1164
1735
|
Object.keys(state).forEach((key) => {
|
|
1165
1736
|
const v = state[key];
|
|
1166
|
-
if (
|
|
1737
|
+
if (isRef(v)) v.value;
|
|
1738
|
+
else if (isReactive(v)) touchReactive(v);
|
|
1167
1739
|
});
|
|
1168
1740
|
Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
|
|
1169
1741
|
}, {
|
|
1170
1742
|
lazy: true,
|
|
1171
|
-
scheduler: () =>
|
|
1743
|
+
scheduler: () => queueJob(job)
|
|
1172
1744
|
});
|
|
1173
1745
|
job();
|
|
1174
|
-
stopHandles.push(() =>
|
|
1746
|
+
stopHandles.push(() => stop(tracker));
|
|
1175
1747
|
function registerWatch(source, cb, watchOptions) {
|
|
1176
1748
|
const stopHandle = watch(source, (value, oldValue) => cb(value, oldValue), watchOptions);
|
|
1177
1749
|
stopHandles.push(stopHandle);
|
|
@@ -1291,7 +1863,7 @@ function defineComponent(options) {
|
|
|
1291
1863
|
function applySetupResult(runtime, _target, result) {
|
|
1292
1864
|
const methods = runtime?.methods ?? Object.create(null);
|
|
1293
1865
|
const state = runtime?.state ?? Object.create(null);
|
|
1294
|
-
const rawState =
|
|
1866
|
+
const rawState = isReactive(state) ? toRaw(state) : state;
|
|
1295
1867
|
if (runtime && !runtime.methods) try {
|
|
1296
1868
|
runtime.methods = methods;
|
|
1297
1869
|
} catch {}
|
|
@@ -1326,7 +1898,7 @@ function isPlainObject(value) {
|
|
|
1326
1898
|
function shouldExposeInSnapshot(value) {
|
|
1327
1899
|
if (value == null) return true;
|
|
1328
1900
|
if (typeof value !== "object") return true;
|
|
1329
|
-
if (
|
|
1901
|
+
if (isRef(value) || isReactive(value)) return true;
|
|
1330
1902
|
if (Array.isArray(value)) return true;
|
|
1331
1903
|
return isPlainObject(value);
|
|
1332
1904
|
}
|
|
@@ -1352,6 +1924,13 @@ function normalizeProps(baseOptions, props, explicitProperties) {
|
|
|
1352
1924
|
return;
|
|
1353
1925
|
}
|
|
1354
1926
|
if (typeof definition === "object") {
|
|
1927
|
+
if (key.endsWith("Modifiers") && Object.keys(definition).length === 0) {
|
|
1928
|
+
properties[key] = {
|
|
1929
|
+
type: Object,
|
|
1930
|
+
value: {}
|
|
1931
|
+
};
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1355
1934
|
const propOptions = {};
|
|
1356
1935
|
if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
|
|
1357
1936
|
const defaultValue = "default" in definition ? definition.default : definition.value;
|
|
@@ -1442,32 +2021,311 @@ function injectGlobal(key, defaultValue) {
|
|
|
1442
2021
|
}
|
|
1443
2022
|
|
|
1444
2023
|
//#endregion
|
|
1445
|
-
|
|
2024
|
+
//#region src/runtime/vueCompat.ts
|
|
2025
|
+
function useAttrs() {
|
|
2026
|
+
const ctx = getCurrentSetupContext();
|
|
2027
|
+
if (!ctx) throw new Error("useAttrs() must be called synchronously inside setup()");
|
|
2028
|
+
return ctx.attrs ?? {};
|
|
2029
|
+
}
|
|
2030
|
+
function useSlots() {
|
|
2031
|
+
const ctx = getCurrentSetupContext();
|
|
2032
|
+
if (!ctx) throw new Error("useSlots() must be called synchronously inside setup()");
|
|
2033
|
+
return ctx.slots ?? Object.create(null);
|
|
2034
|
+
}
|
|
2035
|
+
function useModel(props, name) {
|
|
2036
|
+
const ctx = getCurrentSetupContext();
|
|
2037
|
+
if (!ctx) throw new Error("useModel() must be called synchronously inside setup()");
|
|
2038
|
+
const emit = ctx.emit;
|
|
2039
|
+
const eventName = `update:${name}`;
|
|
2040
|
+
return customRef({
|
|
2041
|
+
get: () => props?.[name],
|
|
2042
|
+
set: (value) => {
|
|
2043
|
+
emit?.(eventName, value);
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
function mergeModels(a, b) {
|
|
2048
|
+
if (a == null) return b;
|
|
2049
|
+
if (b == null) return a;
|
|
2050
|
+
if (Array.isArray(a) && Array.isArray(b)) return Array.from(new Set([...a, ...b]));
|
|
2051
|
+
if (typeof a === "object" && typeof b === "object") return {
|
|
2052
|
+
...a,
|
|
2053
|
+
...b
|
|
2054
|
+
};
|
|
2055
|
+
return b;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
//#endregion
|
|
2059
|
+
//#region src/store/actions.ts
|
|
2060
|
+
function wrapAction(store, name, action, actionSubs) {
|
|
2061
|
+
return function wrapped(...args) {
|
|
2062
|
+
const afterCbs = [];
|
|
2063
|
+
const errorCbs = [];
|
|
2064
|
+
const after = (cb) => afterCbs.push(cb);
|
|
2065
|
+
const onError$1 = (cb) => errorCbs.push(cb);
|
|
2066
|
+
actionSubs.forEach((sub) => {
|
|
2067
|
+
try {
|
|
2068
|
+
sub({
|
|
2069
|
+
name,
|
|
2070
|
+
store,
|
|
2071
|
+
args,
|
|
2072
|
+
after,
|
|
2073
|
+
onError: onError$1
|
|
2074
|
+
});
|
|
2075
|
+
} catch {}
|
|
2076
|
+
});
|
|
2077
|
+
let res;
|
|
2078
|
+
try {
|
|
2079
|
+
res = action.apply(store, args);
|
|
2080
|
+
} catch (e) {
|
|
2081
|
+
errorCbs.forEach((cb) => cb(e));
|
|
2082
|
+
throw e;
|
|
2083
|
+
}
|
|
2084
|
+
const finalize = (r) => {
|
|
2085
|
+
afterCbs.forEach((cb) => cb(r));
|
|
2086
|
+
return r;
|
|
2087
|
+
};
|
|
2088
|
+
if (res && typeof res.then === "function") return res.then((r) => finalize(r), (e) => {
|
|
2089
|
+
errorCbs.forEach((cb) => cb(e));
|
|
2090
|
+
return Promise.reject(e);
|
|
2091
|
+
});
|
|
2092
|
+
return finalize(res);
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
//#endregion
|
|
2097
|
+
//#region src/store/utils.ts
|
|
2098
|
+
function isObject(val) {
|
|
2099
|
+
return typeof val === "object" && val !== null;
|
|
2100
|
+
}
|
|
2101
|
+
function mergeShallow(target, patch) {
|
|
2102
|
+
for (const k in patch) target[k] = patch[k];
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
//#endregion
|
|
2106
|
+
//#region src/store/base.ts
|
|
2107
|
+
function createBaseApi(id, stateObj, notify, resetImpl) {
|
|
2108
|
+
const api = { $id: id };
|
|
2109
|
+
Object.defineProperty(api, "$state", {
|
|
2110
|
+
get() {
|
|
2111
|
+
return stateObj;
|
|
2112
|
+
},
|
|
2113
|
+
set(v) {
|
|
2114
|
+
if (stateObj && isObject(v)) {
|
|
2115
|
+
mergeShallow(stateObj, v);
|
|
2116
|
+
notify("patch object");
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
});
|
|
2120
|
+
api.$patch = (patch) => {
|
|
2121
|
+
if (!stateObj) {
|
|
2122
|
+
if (typeof patch === "function") {
|
|
2123
|
+
patch(api);
|
|
2124
|
+
notify("patch function");
|
|
2125
|
+
} else {
|
|
2126
|
+
mergeShallow(api, patch);
|
|
2127
|
+
notify("patch object");
|
|
2128
|
+
}
|
|
2129
|
+
return;
|
|
2130
|
+
}
|
|
2131
|
+
if (typeof patch === "function") {
|
|
2132
|
+
patch(stateObj);
|
|
2133
|
+
notify("patch function");
|
|
2134
|
+
} else {
|
|
2135
|
+
mergeShallow(stateObj, patch);
|
|
2136
|
+
notify("patch object");
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
if (resetImpl) api.$reset = () => resetImpl();
|
|
2140
|
+
const subs = /* @__PURE__ */ new Set();
|
|
2141
|
+
api.$subscribe = (cb, _opts) => {
|
|
2142
|
+
subs.add(cb);
|
|
2143
|
+
return () => subs.delete(cb);
|
|
2144
|
+
};
|
|
2145
|
+
const actionSubs = /* @__PURE__ */ new Set();
|
|
2146
|
+
api.$onAction = (cb) => {
|
|
2147
|
+
actionSubs.add(cb);
|
|
2148
|
+
return () => actionSubs.delete(cb);
|
|
2149
|
+
};
|
|
2150
|
+
return {
|
|
2151
|
+
api,
|
|
2152
|
+
subs,
|
|
2153
|
+
actionSubs
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
//#endregion
|
|
2158
|
+
//#region src/store/manager.ts
|
|
2159
|
+
function createStore() {
|
|
2160
|
+
const manager = {
|
|
2161
|
+
_stores: /* @__PURE__ */ new Map(),
|
|
2162
|
+
_plugins: [],
|
|
2163
|
+
install(_app) {},
|
|
2164
|
+
use(plugin) {
|
|
2165
|
+
if (typeof plugin === "function") manager._plugins.push(plugin);
|
|
2166
|
+
return manager;
|
|
2167
|
+
}
|
|
2168
|
+
};
|
|
2169
|
+
createStore._instance = manager;
|
|
2170
|
+
return manager;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
//#endregion
|
|
2174
|
+
//#region src/store/define.ts
|
|
2175
|
+
function defineStore(id, setupOrOptions) {
|
|
2176
|
+
let instance;
|
|
2177
|
+
let created = false;
|
|
2178
|
+
const manager = createStore._instance;
|
|
2179
|
+
return function useStore() {
|
|
2180
|
+
if (created && instance) return instance;
|
|
2181
|
+
created = true;
|
|
2182
|
+
if (typeof setupOrOptions === "function") {
|
|
2183
|
+
const result = setupOrOptions();
|
|
2184
|
+
let notify$1 = () => {};
|
|
2185
|
+
const base$1 = createBaseApi(id, void 0, (t) => notify$1(t));
|
|
2186
|
+
notify$1 = (type) => {
|
|
2187
|
+
base$1.subs.forEach((cb) => {
|
|
2188
|
+
try {
|
|
2189
|
+
cb({
|
|
2190
|
+
type,
|
|
2191
|
+
storeId: id
|
|
2192
|
+
}, instance);
|
|
2193
|
+
} catch {}
|
|
2194
|
+
});
|
|
2195
|
+
};
|
|
2196
|
+
instance = Object.assign({}, result);
|
|
2197
|
+
for (const key of Object.getOwnPropertyNames(base$1.api)) {
|
|
2198
|
+
const d = Object.getOwnPropertyDescriptor(base$1.api, key);
|
|
2199
|
+
if (d) Object.defineProperty(instance, key, d);
|
|
2200
|
+
}
|
|
2201
|
+
Object.keys(result).forEach((k) => {
|
|
2202
|
+
const val = result[k];
|
|
2203
|
+
if (typeof val === "function" && !k.startsWith("$")) instance[k] = wrapAction(instance, k, val, base$1.actionSubs);
|
|
2204
|
+
});
|
|
2205
|
+
const plugins$1 = manager?._plugins ?? [];
|
|
2206
|
+
for (const plugin of plugins$1) try {
|
|
2207
|
+
plugin({ store: instance });
|
|
2208
|
+
} catch {}
|
|
2209
|
+
return instance;
|
|
2210
|
+
}
|
|
2211
|
+
const options = setupOrOptions;
|
|
2212
|
+
const rawState = options.state ? options.state() : {};
|
|
2213
|
+
const state = reactive(rawState);
|
|
2214
|
+
const initialSnapshot = { ...toRaw(rawState) };
|
|
2215
|
+
let notify = () => {};
|
|
2216
|
+
const base = createBaseApi(id, state, (t) => notify(t), () => {
|
|
2217
|
+
mergeShallow(state, initialSnapshot);
|
|
2218
|
+
notify("patch object");
|
|
2219
|
+
});
|
|
2220
|
+
notify = (type) => {
|
|
2221
|
+
base.subs.forEach((cb) => {
|
|
2222
|
+
try {
|
|
2223
|
+
cb({
|
|
2224
|
+
type,
|
|
2225
|
+
storeId: id
|
|
2226
|
+
}, state);
|
|
2227
|
+
} catch {}
|
|
2228
|
+
});
|
|
2229
|
+
};
|
|
2230
|
+
const store = {};
|
|
2231
|
+
for (const key of Object.getOwnPropertyNames(base.api)) {
|
|
2232
|
+
const d = Object.getOwnPropertyDescriptor(base.api, key);
|
|
2233
|
+
if (d) Object.defineProperty(store, key, d);
|
|
2234
|
+
}
|
|
2235
|
+
const getterDefs = options.getters ?? {};
|
|
2236
|
+
const computedMap = {};
|
|
2237
|
+
Object.keys(getterDefs).forEach((key) => {
|
|
2238
|
+
const getter = getterDefs[key];
|
|
2239
|
+
if (typeof getter === "function") {
|
|
2240
|
+
const c = computed(() => getter.call(store, state));
|
|
2241
|
+
computedMap[key] = c;
|
|
2242
|
+
Object.defineProperty(store, key, {
|
|
2243
|
+
enumerable: true,
|
|
2244
|
+
configurable: true,
|
|
2245
|
+
get() {
|
|
2246
|
+
return c.value;
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
});
|
|
2251
|
+
const actionDefs = options.actions ?? {};
|
|
2252
|
+
Object.keys(actionDefs).forEach((key) => {
|
|
2253
|
+
const act = actionDefs[key];
|
|
2254
|
+
if (typeof act === "function") store[key] = wrapAction(store, key, (...args) => {
|
|
2255
|
+
return act.apply(store, args);
|
|
2256
|
+
}, base.actionSubs);
|
|
2257
|
+
});
|
|
2258
|
+
Object.keys(state).forEach((k) => {
|
|
2259
|
+
Object.defineProperty(store, k, {
|
|
2260
|
+
enumerable: true,
|
|
2261
|
+
configurable: true,
|
|
2262
|
+
get() {
|
|
2263
|
+
return state[k];
|
|
2264
|
+
},
|
|
2265
|
+
set(v) {
|
|
2266
|
+
state[k] = v;
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
});
|
|
2270
|
+
instance = store;
|
|
2271
|
+
const plugins = manager?._plugins ?? [];
|
|
2272
|
+
for (const plugin of plugins) try {
|
|
2273
|
+
plugin({ store: instance });
|
|
2274
|
+
} catch {}
|
|
2275
|
+
return instance;
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
//#endregion
|
|
2280
|
+
//#region src/store/storeToRefs.ts
|
|
2281
|
+
function storeToRefs(store) {
|
|
2282
|
+
const result = {};
|
|
2283
|
+
for (const key in store) {
|
|
2284
|
+
const value = store[key];
|
|
2285
|
+
if (typeof value === "function") {
|
|
2286
|
+
result[key] = value;
|
|
2287
|
+
continue;
|
|
2288
|
+
}
|
|
2289
|
+
if (isRef(value)) result[key] = value;
|
|
2290
|
+
else result[key] = computed({
|
|
2291
|
+
get: () => store[key],
|
|
2292
|
+
set: (v) => {
|
|
2293
|
+
store[key] = v;
|
|
2294
|
+
}
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
return result;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
//#endregion
|
|
2301
|
+
exports.batch = batch;
|
|
1446
2302
|
exports.callHookList = callHookList;
|
|
1447
2303
|
exports.callHookReturn = callHookReturn;
|
|
1448
2304
|
exports.callUpdateHooks = callUpdateHooks;
|
|
1449
|
-
exports.computed =
|
|
2305
|
+
exports.computed = computed;
|
|
1450
2306
|
exports.createApp = createApp;
|
|
1451
|
-
exports.createStore =
|
|
2307
|
+
exports.createStore = createStore;
|
|
1452
2308
|
exports.createWevuComponent = createWevuComponent;
|
|
1453
2309
|
exports.defineComponent = defineComponent;
|
|
1454
|
-
exports.defineStore =
|
|
1455
|
-
exports.effect =
|
|
1456
|
-
exports.effectScope =
|
|
1457
|
-
exports.endBatch =
|
|
2310
|
+
exports.defineStore = defineStore;
|
|
2311
|
+
exports.effect = effect;
|
|
2312
|
+
exports.effectScope = effectScope;
|
|
2313
|
+
exports.endBatch = endBatch;
|
|
1458
2314
|
exports.getCurrentInstance = getCurrentInstance;
|
|
1459
|
-
exports.getCurrentScope =
|
|
2315
|
+
exports.getCurrentScope = getCurrentScope;
|
|
2316
|
+
exports.getCurrentSetupContext = getCurrentSetupContext;
|
|
1460
2317
|
exports.getDeepWatchStrategy = getDeepWatchStrategy;
|
|
1461
2318
|
exports.inject = inject;
|
|
1462
2319
|
exports.injectGlobal = injectGlobal;
|
|
1463
|
-
exports.isRaw =
|
|
1464
|
-
exports.isReactive =
|
|
1465
|
-
exports.isRef =
|
|
1466
|
-
exports.isShallowReactive =
|
|
2320
|
+
exports.isRaw = isRaw;
|
|
2321
|
+
exports.isReactive = isReactive;
|
|
2322
|
+
exports.isRef = isRef;
|
|
2323
|
+
exports.isShallowReactive = isShallowReactive;
|
|
1467
2324
|
exports.isShallowRef = isShallowRef;
|
|
1468
|
-
exports.markRaw =
|
|
2325
|
+
exports.markRaw = markRaw;
|
|
2326
|
+
exports.mergeModels = mergeModels;
|
|
1469
2327
|
exports.mountRuntimeInstance = mountRuntimeInstance;
|
|
1470
|
-
exports.nextTick =
|
|
2328
|
+
exports.nextTick = nextTick;
|
|
1471
2329
|
exports.onActivated = onActivated;
|
|
1472
2330
|
exports.onAddToFavorites = onAddToFavorites;
|
|
1473
2331
|
exports.onAppError = onAppError;
|
|
@@ -1490,7 +2348,7 @@ exports.onReady = onReady;
|
|
|
1490
2348
|
exports.onResize = onResize;
|
|
1491
2349
|
exports.onRouteDone = onRouteDone;
|
|
1492
2350
|
exports.onSaveExitState = onSaveExitState;
|
|
1493
|
-
exports.onScopeDispose =
|
|
2351
|
+
exports.onScopeDispose = onScopeDispose;
|
|
1494
2352
|
exports.onServerPrefetch = onServerPrefetch;
|
|
1495
2353
|
exports.onShareAppMessage = onShareAppMessage;
|
|
1496
2354
|
exports.onShareTimeline = onShareTimeline;
|
|
@@ -1501,26 +2359,30 @@ exports.onUnmounted = onUnmounted;
|
|
|
1501
2359
|
exports.onUpdated = onUpdated;
|
|
1502
2360
|
exports.provide = provide;
|
|
1503
2361
|
exports.provideGlobal = provideGlobal;
|
|
1504
|
-
exports.reactive =
|
|
2362
|
+
exports.reactive = reactive;
|
|
1505
2363
|
exports.readonly = readonly;
|
|
1506
|
-
exports.ref =
|
|
2364
|
+
exports.ref = ref;
|
|
1507
2365
|
exports.registerApp = registerApp;
|
|
1508
2366
|
exports.registerComponent = registerComponent;
|
|
1509
2367
|
exports.runSetupFunction = runSetupFunction;
|
|
1510
2368
|
exports.setCurrentInstance = setCurrentInstance;
|
|
2369
|
+
exports.setCurrentSetupContext = setCurrentSetupContext;
|
|
1511
2370
|
exports.setDeepWatchStrategy = setDeepWatchStrategy;
|
|
1512
|
-
exports.shallowReactive =
|
|
2371
|
+
exports.shallowReactive = shallowReactive;
|
|
1513
2372
|
exports.shallowRef = shallowRef;
|
|
1514
|
-
exports.startBatch =
|
|
1515
|
-
exports.stop =
|
|
1516
|
-
exports.storeToRefs =
|
|
2373
|
+
exports.startBatch = startBatch;
|
|
2374
|
+
exports.stop = stop;
|
|
2375
|
+
exports.storeToRefs = storeToRefs;
|
|
1517
2376
|
exports.teardownRuntimeInstance = teardownRuntimeInstance;
|
|
1518
|
-
exports.toRaw =
|
|
2377
|
+
exports.toRaw = toRaw;
|
|
1519
2378
|
exports.toRef = toRef;
|
|
1520
2379
|
exports.toRefs = toRefs;
|
|
1521
|
-
exports.touchReactive =
|
|
2380
|
+
exports.touchReactive = touchReactive;
|
|
1522
2381
|
exports.traverse = traverse;
|
|
1523
2382
|
exports.triggerRef = triggerRef;
|
|
1524
|
-
exports.unref =
|
|
2383
|
+
exports.unref = unref;
|
|
2384
|
+
exports.useAttrs = useAttrs;
|
|
2385
|
+
exports.useModel = useModel;
|
|
2386
|
+
exports.useSlots = useSlots;
|
|
1525
2387
|
exports.watch = watch;
|
|
1526
2388
|
exports.watchEffect = watchEffect;
|