wevu 1.0.0-alpha.2 → 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/README.md +14 -4
- package/dist/compiler.cjs +17 -0
- package/dist/compiler.d.cts +17 -0
- package/dist/compiler.d.mts +17 -0
- package/dist/compiler.mjs +16 -0
- package/dist/index.cjs +1017 -102
- package/dist/index.d.cts +277 -48
- package/dist/index.d.mts +277 -48
- package/dist/index.mjs +953 -51
- package/package.json +15 -1
- package/dist/index-0dF4y5p6.d.mts +0 -80
- package/dist/index-DVEFI-Uo.d.cts +0 -80
- package/dist/store-2q4qcdBi.mjs +0 -726
- package/dist/store-D0GD8ulz.cjs +0 -888
- 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-D0GD8ulz.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;
|
|
@@ -437,6 +925,10 @@ function onShow(handler) {
|
|
|
437
925
|
if (!__currentInstance) throw new Error("onShow() must be called synchronously inside setup()");
|
|
438
926
|
pushHook(__currentInstance, "onShow", handler);
|
|
439
927
|
}
|
|
928
|
+
function onLoad(handler) {
|
|
929
|
+
if (!__currentInstance) throw new Error("onLoad() must be called synchronously inside setup()");
|
|
930
|
+
pushHook(__currentInstance, "onLoad", handler);
|
|
931
|
+
}
|
|
440
932
|
function onHide(handler) {
|
|
441
933
|
if (!__currentInstance) throw new Error("onHide() must be called synchronously inside setup()");
|
|
442
934
|
pushHook(__currentInstance, "onHide", handler);
|
|
@@ -449,6 +941,14 @@ function onReady(handler) {
|
|
|
449
941
|
if (!__currentInstance) throw new Error("onReady() must be called synchronously inside setup()");
|
|
450
942
|
pushHook(__currentInstance, "onReady", handler);
|
|
451
943
|
}
|
|
944
|
+
function onPullDownRefresh(handler) {
|
|
945
|
+
if (!__currentInstance) throw new Error("onPullDownRefresh() must be called synchronously inside setup()");
|
|
946
|
+
pushHook(__currentInstance, "onPullDownRefresh", handler);
|
|
947
|
+
}
|
|
948
|
+
function onReachBottom(handler) {
|
|
949
|
+
if (!__currentInstance) throw new Error("onReachBottom() must be called synchronously inside setup()");
|
|
950
|
+
pushHook(__currentInstance, "onReachBottom", handler);
|
|
951
|
+
}
|
|
452
952
|
function onPageScroll(handler) {
|
|
453
953
|
if (!__currentInstance) throw new Error("onPageScroll() must be called synchronously inside setup()");
|
|
454
954
|
pushHook(__currentInstance, "onPageScroll", handler);
|
|
@@ -461,6 +961,18 @@ function onTabItemTap(handler) {
|
|
|
461
961
|
if (!__currentInstance) throw new Error("onTabItemTap() must be called synchronously inside setup()");
|
|
462
962
|
pushHook(__currentInstance, "onTabItemTap", handler);
|
|
463
963
|
}
|
|
964
|
+
function onResize(handler) {
|
|
965
|
+
if (!__currentInstance) throw new Error("onResize() must be called synchronously inside setup()");
|
|
966
|
+
pushHook(__currentInstance, "onResize", handler);
|
|
967
|
+
}
|
|
968
|
+
function onMoved(handler) {
|
|
969
|
+
if (!__currentInstance) throw new Error("onMoved() must be called synchronously inside setup()");
|
|
970
|
+
pushHook(__currentInstance, "onMoved", handler);
|
|
971
|
+
}
|
|
972
|
+
function onError(handler) {
|
|
973
|
+
if (!__currentInstance) throw new Error("onError() must be called synchronously inside setup()");
|
|
974
|
+
pushHook(__currentInstance, "onError", handler);
|
|
975
|
+
}
|
|
464
976
|
function onSaveExitState(handler) {
|
|
465
977
|
if (!__currentInstance) throw new Error("onSaveExitState() must be called synchronously inside setup()");
|
|
466
978
|
pushHook(__currentInstance, "onSaveExitState", handler, { single: true });
|
|
@@ -633,11 +1145,35 @@ function registerWatches(runtime, watchMap, instance) {
|
|
|
633
1145
|
}
|
|
634
1146
|
return stops;
|
|
635
1147
|
}
|
|
636
|
-
function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
1148
|
+
function mountRuntimeInstance(target, runtimeApp, watchMap, setup, options) {
|
|
637
1149
|
if (target.__wevu) return target.__wevu;
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
1150
|
+
const createDeferredAdapter = (instance) => {
|
|
1151
|
+
let pending;
|
|
1152
|
+
let enabled = false;
|
|
1153
|
+
const adapter$1 = { setData(payload) {
|
|
1154
|
+
if (!enabled) {
|
|
1155
|
+
pending = {
|
|
1156
|
+
...pending ?? {},
|
|
1157
|
+
...payload
|
|
1158
|
+
};
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
if (typeof instance.setData === "function") return instance.setData(payload);
|
|
1162
|
+
} };
|
|
1163
|
+
adapter$1.__wevu_enableSetData = () => {
|
|
1164
|
+
enabled = true;
|
|
1165
|
+
if (pending && Object.keys(pending).length && typeof instance.setData === "function") {
|
|
1166
|
+
const payload = pending;
|
|
1167
|
+
pending = void 0;
|
|
1168
|
+
instance.setData(payload);
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
return adapter$1;
|
|
1172
|
+
};
|
|
1173
|
+
const adapter = options?.deferSetData ? createDeferredAdapter(target) : { setData(payload) {
|
|
1174
|
+
if (typeof target.setData === "function") return target.setData(payload);
|
|
1175
|
+
} };
|
|
1176
|
+
const runtime = runtimeApp.mount({ ...adapter });
|
|
641
1177
|
const runtimeProxy = runtime?.proxy ?? {};
|
|
642
1178
|
const runtimeState = runtime?.state ?? {};
|
|
643
1179
|
if (!runtime?.methods) try {
|
|
@@ -675,15 +1211,17 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
|
675
1211
|
bindModel: runtimeBindModel.bind(runtimeWithDefaults),
|
|
676
1212
|
watch: runtimeWatch.bind(runtimeWithDefaults),
|
|
677
1213
|
instance: target,
|
|
678
|
-
emit: (event,
|
|
679
|
-
if (typeof target.triggerEvent === "function") target.triggerEvent(event,
|
|
1214
|
+
emit: (event, detail, options$1) => {
|
|
1215
|
+
if (typeof target.triggerEvent === "function") target.triggerEvent(event, detail, options$1);
|
|
680
1216
|
},
|
|
681
1217
|
expose: (exposed) => {
|
|
682
1218
|
target.__wevuExposed = exposed;
|
|
683
1219
|
},
|
|
684
|
-
attrs: {}
|
|
1220
|
+
attrs: {},
|
|
1221
|
+
slots: Object.create(null)
|
|
685
1222
|
};
|
|
686
1223
|
setCurrentInstance(target);
|
|
1224
|
+
setCurrentSetupContext(context);
|
|
687
1225
|
try {
|
|
688
1226
|
const result = runSetupFunction(setup, props, context);
|
|
689
1227
|
if (result && typeof result === "object") Object.keys(result).forEach((key) => {
|
|
@@ -692,6 +1230,7 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
|
692
1230
|
else runtime.state[key] = val;
|
|
693
1231
|
});
|
|
694
1232
|
} finally {
|
|
1233
|
+
setCurrentSetupContext(void 0);
|
|
695
1234
|
setCurrentInstance(void 0);
|
|
696
1235
|
}
|
|
697
1236
|
}
|
|
@@ -704,6 +1243,10 @@ function mountRuntimeInstance(target, runtimeApp, watchMap, setup) {
|
|
|
704
1243
|
} catch {}
|
|
705
1244
|
return runtime;
|
|
706
1245
|
}
|
|
1246
|
+
function enableDeferredSetData(target) {
|
|
1247
|
+
const adapter = target.__wevu?.adapter;
|
|
1248
|
+
if (adapter && typeof adapter.__wevu_enableSetData === "function") adapter.__wevu_enableSetData();
|
|
1249
|
+
}
|
|
707
1250
|
function teardownRuntimeInstance(target) {
|
|
708
1251
|
const runtime = target.__wevu;
|
|
709
1252
|
if (runtime && target.__wevuHooks) callHookList(target, "onUnload", []);
|
|
@@ -743,7 +1286,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
743
1286
|
if (typeof userOnHide === "function") userOnHide.apply(this, args);
|
|
744
1287
|
};
|
|
745
1288
|
const userOnError = appOptions.onError;
|
|
746
|
-
appOptions.onError = function onError(...args) {
|
|
1289
|
+
appOptions.onError = function onError$1(...args) {
|
|
747
1290
|
callHookList(this, "onAppError", args);
|
|
748
1291
|
if (typeof userOnError === "function") userOnError.apply(this, args);
|
|
749
1292
|
};
|
|
@@ -760,7 +1303,7 @@ function registerApp(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
|
760
1303
|
}
|
|
761
1304
|
App(appOptions);
|
|
762
1305
|
}
|
|
763
|
-
function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions
|
|
1306
|
+
function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions) {
|
|
764
1307
|
const { methods: userMethods = {}, lifetimes: userLifetimes = {}, pageLifetimes: userPageLifetimes = {}, options: userOptions = {}, ...rest } = mpOptions;
|
|
765
1308
|
const userOnLoad = rest.onLoad;
|
|
766
1309
|
const userOnUnload = rest.onUnload;
|
|
@@ -768,21 +1311,68 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
768
1311
|
const userOnHide = rest.onHide;
|
|
769
1312
|
const userOnReady = rest.onReady;
|
|
770
1313
|
const userOnSaveExitState = rest.onSaveExitState;
|
|
1314
|
+
const userOnPullDownRefresh = rest.onPullDownRefresh;
|
|
1315
|
+
const userOnReachBottom = rest.onReachBottom;
|
|
771
1316
|
const userOnPageScroll = rest.onPageScroll;
|
|
1317
|
+
const userOnRouteDone = rest.onRouteDone;
|
|
1318
|
+
const userOnTabItemTap = rest.onTabItemTap;
|
|
1319
|
+
const userOnResize = rest.onResize;
|
|
772
1320
|
const userOnShareAppMessage = rest.onShareAppMessage;
|
|
773
1321
|
const userOnShareTimeline = rest.onShareTimeline;
|
|
774
1322
|
const userOnAddToFavorites = rest.onAddToFavorites;
|
|
1323
|
+
const features = rest.features ?? {};
|
|
775
1324
|
const restOptions = { ...rest };
|
|
1325
|
+
const legacyCreated = restOptions.created;
|
|
1326
|
+
delete restOptions.features;
|
|
1327
|
+
delete restOptions.created;
|
|
776
1328
|
delete restOptions.onLoad;
|
|
777
1329
|
delete restOptions.onUnload;
|
|
778
1330
|
delete restOptions.onShow;
|
|
779
1331
|
delete restOptions.onHide;
|
|
780
1332
|
delete restOptions.onReady;
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
1333
|
+
const enableOnPullDownRefresh = typeof userOnPullDownRefresh === "function" || Boolean(features.enableOnPullDownRefresh);
|
|
1334
|
+
const enableOnReachBottom = typeof userOnReachBottom === "function" || Boolean(features.enableOnReachBottom);
|
|
1335
|
+
const enableOnPageScroll = typeof userOnPageScroll === "function" || Boolean(features.enableOnPageScroll);
|
|
1336
|
+
const enableOnRouteDone = typeof userOnRouteDone === "function" || Boolean(features.enableOnRouteDone);
|
|
1337
|
+
const enableOnTabItemTap = typeof userOnTabItemTap === "function" || Boolean(features.enableOnTabItemTap);
|
|
1338
|
+
const enableOnResize = typeof userOnResize === "function" || Boolean(features.enableOnResize);
|
|
1339
|
+
const enableOnShareAppMessage = typeof userOnShareAppMessage === "function" || Boolean(features.enableOnShareAppMessage);
|
|
1340
|
+
const enableOnShareTimeline = typeof userOnShareTimeline === "function" || Boolean(features.enableOnShareTimeline);
|
|
1341
|
+
const enableOnAddToFavorites = typeof userOnAddToFavorites === "function" || Boolean(features.enableOnAddToFavorites);
|
|
1342
|
+
const enableOnSaveExitState = typeof userOnSaveExitState === "function" || Boolean(features.enableOnSaveExitState);
|
|
1343
|
+
const fallbackNoop = () => {};
|
|
1344
|
+
const fallbackShareContent = () => ({});
|
|
1345
|
+
const fallbackTimelineContent = () => ({});
|
|
1346
|
+
const effectiveOnSaveExitState = typeof userOnSaveExitState === "function" ? userOnSaveExitState : (() => ({ data: void 0 }));
|
|
1347
|
+
const effectiveOnPullDownRefresh = typeof userOnPullDownRefresh === "function" ? userOnPullDownRefresh : fallbackNoop;
|
|
1348
|
+
const effectiveOnReachBottom = typeof userOnReachBottom === "function" ? userOnReachBottom : fallbackNoop;
|
|
1349
|
+
const effectiveOnPageScroll = typeof userOnPageScroll === "function" ? userOnPageScroll : fallbackNoop;
|
|
1350
|
+
const effectiveOnRouteDone = typeof userOnRouteDone === "function" ? userOnRouteDone : fallbackNoop;
|
|
1351
|
+
const effectiveOnTabItemTap = typeof userOnTabItemTap === "function" ? userOnTabItemTap : fallbackNoop;
|
|
1352
|
+
const effectiveOnResize = typeof userOnResize === "function" ? userOnResize : fallbackNoop;
|
|
1353
|
+
const effectiveOnShareAppMessage = typeof userOnShareAppMessage === "function" ? userOnShareAppMessage : fallbackShareContent;
|
|
1354
|
+
const effectiveOnShareTimeline = typeof userOnShareTimeline === "function" ? userOnShareTimeline : fallbackTimelineContent;
|
|
1355
|
+
const effectiveOnAddToFavorites = typeof userOnAddToFavorites === "function" ? userOnAddToFavorites : (() => ({}));
|
|
1356
|
+
const hasHook = (target, name) => {
|
|
1357
|
+
const hooks = target.__wevuHooks;
|
|
1358
|
+
if (!hooks) return false;
|
|
1359
|
+
const entry = hooks[name];
|
|
1360
|
+
if (!entry) return false;
|
|
1361
|
+
if (Array.isArray(entry)) return entry.length > 0;
|
|
1362
|
+
return typeof entry === "function";
|
|
1363
|
+
};
|
|
1364
|
+
{
|
|
1365
|
+
const userExport = restOptions.export;
|
|
1366
|
+
restOptions.export = function __wevu_export() {
|
|
1367
|
+
const exposed = this.__wevuExposed ?? {};
|
|
1368
|
+
const base = typeof userExport === "function" ? userExport.call(this) : {};
|
|
1369
|
+
if (base && typeof base === "object" && !Array.isArray(base)) return {
|
|
1370
|
+
...exposed,
|
|
1371
|
+
...base
|
|
1372
|
+
};
|
|
1373
|
+
return base ?? exposed;
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
786
1376
|
const finalOptions = {
|
|
787
1377
|
multipleSlots: userOptions.multipleSlots ?? true,
|
|
788
1378
|
...userOptions
|
|
@@ -804,18 +1394,11 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
804
1394
|
return result;
|
|
805
1395
|
};
|
|
806
1396
|
}
|
|
807
|
-
const wrapSpecial = (name) => {
|
|
808
|
-
const user = userLifetimes[name] ?? userPageLifetimes[name];
|
|
809
|
-
finalMethods[name] = function wrapped(...args) {
|
|
810
|
-
callHookList(this, name, args);
|
|
811
|
-
if (typeof user === "function") return user.apply(this, args);
|
|
812
|
-
};
|
|
813
|
-
};
|
|
814
|
-
wrapSpecial("onTabItemTap");
|
|
815
|
-
wrapSpecial("onRouteDone");
|
|
816
1397
|
const pageLifecycleHooks = {
|
|
817
1398
|
onLoad(...args) {
|
|
818
1399
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup);
|
|
1400
|
+
enableDeferredSetData(this);
|
|
1401
|
+
callHookList(this, "onLoad", args);
|
|
819
1402
|
if (typeof userOnLoad === "function") return userOnLoad.apply(this, args);
|
|
820
1403
|
},
|
|
821
1404
|
onUnload(...args) {
|
|
@@ -836,39 +1419,69 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
836
1419
|
callHookList(this, "onReady", args);
|
|
837
1420
|
}
|
|
838
1421
|
if (typeof userOnReady === "function") return userOnReady.apply(this, args);
|
|
839
|
-
},
|
|
840
|
-
onSaveExitState(...args) {
|
|
841
|
-
const ret = callHookReturn(this, "onSaveExitState", args);
|
|
842
|
-
if (ret !== void 0) return ret;
|
|
843
|
-
if (typeof userOnSaveExitState === "function") return userOnSaveExitState.apply(this, args);
|
|
844
1422
|
}
|
|
845
1423
|
};
|
|
846
|
-
if (
|
|
1424
|
+
if (enableOnSaveExitState) pageLifecycleHooks.onSaveExitState = function onSaveExitState$1(...args) {
|
|
1425
|
+
const ret = callHookReturn(this, "onSaveExitState", args);
|
|
1426
|
+
if (ret !== void 0) return ret;
|
|
1427
|
+
return effectiveOnSaveExitState.apply(this, args);
|
|
1428
|
+
};
|
|
1429
|
+
if (enableOnPullDownRefresh) pageLifecycleHooks.onPullDownRefresh = function onPullDownRefresh$1(...args) {
|
|
1430
|
+
callHookList(this, "onPullDownRefresh", args);
|
|
1431
|
+
if (!hasHook(this, "onPullDownRefresh")) return effectiveOnPullDownRefresh.apply(this, args);
|
|
1432
|
+
};
|
|
1433
|
+
if (enableOnReachBottom) pageLifecycleHooks.onReachBottom = function onReachBottom$1(...args) {
|
|
1434
|
+
callHookList(this, "onReachBottom", args);
|
|
1435
|
+
if (!hasHook(this, "onReachBottom")) return effectiveOnReachBottom.apply(this, args);
|
|
1436
|
+
};
|
|
1437
|
+
if (enableOnPageScroll) pageLifecycleHooks.onPageScroll = function onPageScroll$1(...args) {
|
|
847
1438
|
callHookList(this, "onPageScroll", args);
|
|
848
|
-
if (
|
|
1439
|
+
if (!hasHook(this, "onPageScroll")) return effectiveOnPageScroll.apply(this, args);
|
|
1440
|
+
};
|
|
1441
|
+
if (enableOnRouteDone) pageLifecycleHooks.onRouteDone = function onRouteDone$1(...args) {
|
|
1442
|
+
callHookList(this, "onRouteDone", args);
|
|
1443
|
+
if (!hasHook(this, "onRouteDone")) return effectiveOnRouteDone.apply(this, args);
|
|
1444
|
+
};
|
|
1445
|
+
if (enableOnTabItemTap) pageLifecycleHooks.onTabItemTap = function onTabItemTap$1(...args) {
|
|
1446
|
+
callHookList(this, "onTabItemTap", args);
|
|
1447
|
+
if (!hasHook(this, "onTabItemTap")) return effectiveOnTabItemTap.apply(this, args);
|
|
849
1448
|
};
|
|
850
|
-
if (
|
|
1449
|
+
if (enableOnResize) pageLifecycleHooks.onResize = function onResize$1(...args) {
|
|
1450
|
+
callHookList(this, "onResize", args);
|
|
1451
|
+
if (!hasHook(this, "onResize")) return effectiveOnResize.apply(this, args);
|
|
1452
|
+
};
|
|
1453
|
+
if (enableOnShareAppMessage) pageLifecycleHooks.onShareAppMessage = function onShareAppMessage$1(...args) {
|
|
851
1454
|
const ret = callHookReturn(this, "onShareAppMessage", args);
|
|
852
1455
|
if (ret !== void 0) return ret;
|
|
853
|
-
|
|
1456
|
+
return effectiveOnShareAppMessage.apply(this, args);
|
|
854
1457
|
};
|
|
855
|
-
if (
|
|
1458
|
+
if (enableOnShareTimeline) pageLifecycleHooks.onShareTimeline = function onShareTimeline$1(...args) {
|
|
856
1459
|
const ret = callHookReturn(this, "onShareTimeline", args);
|
|
857
1460
|
if (ret !== void 0) return ret;
|
|
858
|
-
|
|
1461
|
+
return effectiveOnShareTimeline.apply(this, args);
|
|
859
1462
|
};
|
|
860
|
-
if (
|
|
1463
|
+
if (enableOnAddToFavorites) pageLifecycleHooks.onAddToFavorites = function onAddToFavorites$1(...args) {
|
|
861
1464
|
const ret = callHookReturn(this, "onAddToFavorites", args);
|
|
862
1465
|
if (ret !== void 0) return ret;
|
|
863
|
-
|
|
1466
|
+
return effectiveOnAddToFavorites.apply(this, args);
|
|
864
1467
|
};
|
|
865
1468
|
Component({
|
|
866
1469
|
...restOptions,
|
|
867
1470
|
...pageLifecycleHooks,
|
|
868
1471
|
lifetimes: {
|
|
869
1472
|
...userLifetimes,
|
|
1473
|
+
created: function created(...args) {
|
|
1474
|
+
mountRuntimeInstance(this, runtimeApp, watch$1, setup, { deferSetData: true });
|
|
1475
|
+
if (typeof legacyCreated === "function") legacyCreated.apply(this, args);
|
|
1476
|
+
if (typeof userLifetimes.created === "function") userLifetimes.created.apply(this, args);
|
|
1477
|
+
},
|
|
1478
|
+
moved: function moved(...args) {
|
|
1479
|
+
callHookList(this, "onMoved", args);
|
|
1480
|
+
if (typeof userLifetimes.moved === "function") userLifetimes.moved.apply(this, args);
|
|
1481
|
+
},
|
|
870
1482
|
attached: function attached(...args) {
|
|
871
1483
|
mountRuntimeInstance(this, runtimeApp, watch$1, setup);
|
|
1484
|
+
enableDeferredSetData(this);
|
|
872
1485
|
if (typeof userLifetimes.attached === "function") userLifetimes.attached.apply(this, args);
|
|
873
1486
|
},
|
|
874
1487
|
ready: function ready(...args) {
|
|
@@ -881,6 +1494,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
881
1494
|
detached: function detached(...args) {
|
|
882
1495
|
teardownRuntimeInstance(this);
|
|
883
1496
|
if (typeof userLifetimes.detached === "function") userLifetimes.detached.apply(this, args);
|
|
1497
|
+
},
|
|
1498
|
+
error: function error(...args) {
|
|
1499
|
+
callHookList(this, "onError", args);
|
|
1500
|
+
if (typeof userLifetimes.error === "function") userLifetimes.error.apply(this, args);
|
|
884
1501
|
}
|
|
885
1502
|
},
|
|
886
1503
|
pageLifetimes: {
|
|
@@ -892,6 +1509,10 @@ function registerComponent(runtimeApp, methods, watch$1, setup, mpOptions, featu
|
|
|
892
1509
|
hide: function hide(...args) {
|
|
893
1510
|
callHookList(this, "onHide", args);
|
|
894
1511
|
if (typeof userPageLifetimes.hide === "function") userPageLifetimes.hide.apply(this, args);
|
|
1512
|
+
},
|
|
1513
|
+
resize: function resize(...args) {
|
|
1514
|
+
callHookList(this, "onResize", args);
|
|
1515
|
+
if (typeof userPageLifetimes.resize === "function") userPageLifetimes.resize.apply(this, args);
|
|
895
1516
|
}
|
|
896
1517
|
},
|
|
897
1518
|
methods: finalMethods,
|
|
@@ -909,7 +1530,7 @@ function createApp(options) {
|
|
|
909
1530
|
const appConfig = { globalProperties: {} };
|
|
910
1531
|
const runtimeApp = {
|
|
911
1532
|
mount(adapter) {
|
|
912
|
-
const state =
|
|
1533
|
+
const state = reactive((data ?? (() => ({})))());
|
|
913
1534
|
const computedDefs = resolvedComputed;
|
|
914
1535
|
const methodDefs = resolvedMethods;
|
|
915
1536
|
const computedRefs = Object.create(null);
|
|
@@ -994,18 +1615,18 @@ function createApp(options) {
|
|
|
994
1615
|
});
|
|
995
1616
|
Object.keys(computedDefs).forEach((key) => {
|
|
996
1617
|
const definition = computedDefs[key];
|
|
997
|
-
if (typeof definition === "function") computedRefs[key] =
|
|
1618
|
+
if (typeof definition === "function") computedRefs[key] = computed(() => definition.call(publicInstance));
|
|
998
1619
|
else {
|
|
999
1620
|
const getter = definition.get?.bind(publicInstance);
|
|
1000
1621
|
if (!getter) throw new Error(`Computed property "${key}" requires a getter`);
|
|
1001
1622
|
const setter = definition.set?.bind(publicInstance);
|
|
1002
1623
|
if (setter) {
|
|
1003
1624
|
computedSetters[key] = setter;
|
|
1004
|
-
computedRefs[key] =
|
|
1625
|
+
computedRefs[key] = computed({
|
|
1005
1626
|
get: getter,
|
|
1006
1627
|
set: setter
|
|
1007
1628
|
});
|
|
1008
|
-
} else computedRefs[key] =
|
|
1629
|
+
} else computedRefs[key] = computed(getter);
|
|
1009
1630
|
}
|
|
1010
1631
|
});
|
|
1011
1632
|
const currentAdapter = adapter ?? { setData: () => {} };
|
|
@@ -1029,19 +1650,19 @@ function createApp(options) {
|
|
|
1029
1650
|
}
|
|
1030
1651
|
};
|
|
1031
1652
|
let tracker;
|
|
1032
|
-
tracker =
|
|
1033
|
-
|
|
1653
|
+
tracker = effect(() => {
|
|
1654
|
+
touchReactive(state);
|
|
1034
1655
|
Object.keys(state).forEach((key) => {
|
|
1035
1656
|
const v = state[key];
|
|
1036
|
-
if (
|
|
1657
|
+
if (isRef(v)) v.value;
|
|
1037
1658
|
});
|
|
1038
1659
|
Object.keys(computedRefs).forEach((key) => computedRefs[key].value);
|
|
1039
1660
|
}, {
|
|
1040
1661
|
lazy: true,
|
|
1041
|
-
scheduler: () =>
|
|
1662
|
+
scheduler: () => queueJob(job)
|
|
1042
1663
|
});
|
|
1043
1664
|
job();
|
|
1044
|
-
stopHandles.push(() =>
|
|
1665
|
+
stopHandles.push(() => stop(tracker));
|
|
1045
1666
|
function registerWatch(source, cb, watchOptions) {
|
|
1046
1667
|
const stopHandle = watch(source, (value, oldValue) => cb(value, oldValue), watchOptions);
|
|
1047
1668
|
stopHandles.push(stopHandle);
|
|
@@ -1126,7 +1747,6 @@ function setComputedValue(setters, key, value) {
|
|
|
1126
1747
|
* @example
|
|
1127
1748
|
* ```ts
|
|
1128
1749
|
* defineComponent({
|
|
1129
|
-
* features: { listenPageScroll: true },
|
|
1130
1750
|
* setup() {
|
|
1131
1751
|
* onPageScroll(() => {})
|
|
1132
1752
|
* }
|
|
@@ -1134,7 +1754,7 @@ function setComputedValue(setters, key, value) {
|
|
|
1134
1754
|
* ```
|
|
1135
1755
|
*/
|
|
1136
1756
|
function defineComponent(options) {
|
|
1137
|
-
const {
|
|
1757
|
+
const { data, computed: computed$1, methods, watch: watch$1, setup, props, ...mpOptions } = options;
|
|
1138
1758
|
const runtimeApp = createApp({
|
|
1139
1759
|
data,
|
|
1140
1760
|
computed: computed$1,
|
|
@@ -1151,10 +1771,9 @@ function defineComponent(options) {
|
|
|
1151
1771
|
methods,
|
|
1152
1772
|
watch: watch$1,
|
|
1153
1773
|
setup: setupWrapper,
|
|
1154
|
-
mpOptions: mpOptionsWithProps
|
|
1155
|
-
features
|
|
1774
|
+
mpOptions: mpOptionsWithProps
|
|
1156
1775
|
};
|
|
1157
|
-
registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps
|
|
1776
|
+
registerComponent(runtimeApp, methods ?? {}, watch$1, setupWrapper, mpOptionsWithProps);
|
|
1158
1777
|
return {
|
|
1159
1778
|
__wevu_runtime: runtimeApp,
|
|
1160
1779
|
__wevu_options: componentOptions
|
|
@@ -1163,7 +1782,7 @@ function defineComponent(options) {
|
|
|
1163
1782
|
function applySetupResult(runtime, _target, result) {
|
|
1164
1783
|
const methods = runtime?.methods ?? Object.create(null);
|
|
1165
1784
|
const state = runtime?.state ?? Object.create(null);
|
|
1166
|
-
const rawState =
|
|
1785
|
+
const rawState = isReactive(state) ? toRaw(state) : state;
|
|
1167
1786
|
if (runtime && !runtime.methods) try {
|
|
1168
1787
|
runtime.methods = methods;
|
|
1169
1788
|
} catch {}
|
|
@@ -1198,7 +1817,7 @@ function isPlainObject(value) {
|
|
|
1198
1817
|
function shouldExposeInSnapshot(value) {
|
|
1199
1818
|
if (value == null) return true;
|
|
1200
1819
|
if (typeof value !== "object") return true;
|
|
1201
|
-
if (
|
|
1820
|
+
if (isRef(value) || isReactive(value)) return true;
|
|
1202
1821
|
if (Array.isArray(value)) return true;
|
|
1203
1822
|
return isPlainObject(value);
|
|
1204
1823
|
}
|
|
@@ -1224,6 +1843,13 @@ function normalizeProps(baseOptions, props, explicitProperties) {
|
|
|
1224
1843
|
return;
|
|
1225
1844
|
}
|
|
1226
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
|
+
}
|
|
1227
1853
|
const propOptions = {};
|
|
1228
1854
|
if ("type" in definition && definition.type !== void 0) propOptions.type = definition.type;
|
|
1229
1855
|
const defaultValue = "default" in definition ? definition.default : definition.value;
|
|
@@ -1314,32 +1940,311 @@ function injectGlobal(key, defaultValue) {
|
|
|
1314
1940
|
}
|
|
1315
1941
|
|
|
1316
1942
|
//#endregion
|
|
1317
|
-
|
|
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;
|
|
1318
2221
|
exports.callHookList = callHookList;
|
|
1319
2222
|
exports.callHookReturn = callHookReturn;
|
|
1320
2223
|
exports.callUpdateHooks = callUpdateHooks;
|
|
1321
|
-
exports.computed =
|
|
2224
|
+
exports.computed = computed;
|
|
1322
2225
|
exports.createApp = createApp;
|
|
1323
|
-
exports.createStore =
|
|
2226
|
+
exports.createStore = createStore;
|
|
1324
2227
|
exports.createWevuComponent = createWevuComponent;
|
|
1325
2228
|
exports.defineComponent = defineComponent;
|
|
1326
|
-
exports.defineStore =
|
|
1327
|
-
exports.effect =
|
|
1328
|
-
exports.effectScope =
|
|
1329
|
-
exports.endBatch =
|
|
2229
|
+
exports.defineStore = defineStore;
|
|
2230
|
+
exports.effect = effect;
|
|
2231
|
+
exports.effectScope = effectScope;
|
|
2232
|
+
exports.endBatch = endBatch;
|
|
1330
2233
|
exports.getCurrentInstance = getCurrentInstance;
|
|
1331
|
-
exports.getCurrentScope =
|
|
2234
|
+
exports.getCurrentScope = getCurrentScope;
|
|
2235
|
+
exports.getCurrentSetupContext = getCurrentSetupContext;
|
|
1332
2236
|
exports.getDeepWatchStrategy = getDeepWatchStrategy;
|
|
1333
2237
|
exports.inject = inject;
|
|
1334
2238
|
exports.injectGlobal = injectGlobal;
|
|
1335
|
-
exports.isRaw =
|
|
1336
|
-
exports.isReactive =
|
|
1337
|
-
exports.isRef =
|
|
1338
|
-
exports.isShallowReactive =
|
|
2239
|
+
exports.isRaw = isRaw;
|
|
2240
|
+
exports.isReactive = isReactive;
|
|
2241
|
+
exports.isRef = isRef;
|
|
2242
|
+
exports.isShallowReactive = isShallowReactive;
|
|
1339
2243
|
exports.isShallowRef = isShallowRef;
|
|
1340
|
-
exports.markRaw =
|
|
2244
|
+
exports.markRaw = markRaw;
|
|
2245
|
+
exports.mergeModels = mergeModels;
|
|
1341
2246
|
exports.mountRuntimeInstance = mountRuntimeInstance;
|
|
1342
|
-
exports.nextTick =
|
|
2247
|
+
exports.nextTick = nextTick;
|
|
1343
2248
|
exports.onActivated = onActivated;
|
|
1344
2249
|
exports.onAddToFavorites = onAddToFavorites;
|
|
1345
2250
|
exports.onAppError = onAppError;
|
|
@@ -1349,14 +2254,20 @@ exports.onBeforeMount = onBeforeMount;
|
|
|
1349
2254
|
exports.onBeforeUnmount = onBeforeUnmount;
|
|
1350
2255
|
exports.onBeforeUpdate = onBeforeUpdate;
|
|
1351
2256
|
exports.onDeactivated = onDeactivated;
|
|
2257
|
+
exports.onError = onError;
|
|
1352
2258
|
exports.onErrorCaptured = onErrorCaptured;
|
|
1353
2259
|
exports.onHide = onHide;
|
|
2260
|
+
exports.onLoad = onLoad;
|
|
1354
2261
|
exports.onMounted = onMounted;
|
|
2262
|
+
exports.onMoved = onMoved;
|
|
1355
2263
|
exports.onPageScroll = onPageScroll;
|
|
2264
|
+
exports.onPullDownRefresh = onPullDownRefresh;
|
|
2265
|
+
exports.onReachBottom = onReachBottom;
|
|
1356
2266
|
exports.onReady = onReady;
|
|
2267
|
+
exports.onResize = onResize;
|
|
1357
2268
|
exports.onRouteDone = onRouteDone;
|
|
1358
2269
|
exports.onSaveExitState = onSaveExitState;
|
|
1359
|
-
exports.onScopeDispose =
|
|
2270
|
+
exports.onScopeDispose = onScopeDispose;
|
|
1360
2271
|
exports.onServerPrefetch = onServerPrefetch;
|
|
1361
2272
|
exports.onShareAppMessage = onShareAppMessage;
|
|
1362
2273
|
exports.onShareTimeline = onShareTimeline;
|
|
@@ -1367,26 +2278,30 @@ exports.onUnmounted = onUnmounted;
|
|
|
1367
2278
|
exports.onUpdated = onUpdated;
|
|
1368
2279
|
exports.provide = provide;
|
|
1369
2280
|
exports.provideGlobal = provideGlobal;
|
|
1370
|
-
exports.reactive =
|
|
2281
|
+
exports.reactive = reactive;
|
|
1371
2282
|
exports.readonly = readonly;
|
|
1372
|
-
exports.ref =
|
|
2283
|
+
exports.ref = ref;
|
|
1373
2284
|
exports.registerApp = registerApp;
|
|
1374
2285
|
exports.registerComponent = registerComponent;
|
|
1375
2286
|
exports.runSetupFunction = runSetupFunction;
|
|
1376
2287
|
exports.setCurrentInstance = setCurrentInstance;
|
|
2288
|
+
exports.setCurrentSetupContext = setCurrentSetupContext;
|
|
1377
2289
|
exports.setDeepWatchStrategy = setDeepWatchStrategy;
|
|
1378
|
-
exports.shallowReactive =
|
|
2290
|
+
exports.shallowReactive = shallowReactive;
|
|
1379
2291
|
exports.shallowRef = shallowRef;
|
|
1380
|
-
exports.startBatch =
|
|
1381
|
-
exports.stop =
|
|
1382
|
-
exports.storeToRefs =
|
|
2292
|
+
exports.startBatch = startBatch;
|
|
2293
|
+
exports.stop = stop;
|
|
2294
|
+
exports.storeToRefs = storeToRefs;
|
|
1383
2295
|
exports.teardownRuntimeInstance = teardownRuntimeInstance;
|
|
1384
|
-
exports.toRaw =
|
|
2296
|
+
exports.toRaw = toRaw;
|
|
1385
2297
|
exports.toRef = toRef;
|
|
1386
2298
|
exports.toRefs = toRefs;
|
|
1387
|
-
exports.touchReactive =
|
|
2299
|
+
exports.touchReactive = touchReactive;
|
|
1388
2300
|
exports.traverse = traverse;
|
|
1389
2301
|
exports.triggerRef = triggerRef;
|
|
1390
|
-
exports.unref =
|
|
2302
|
+
exports.unref = unref;
|
|
2303
|
+
exports.useAttrs = useAttrs;
|
|
2304
|
+
exports.useModel = useModel;
|
|
2305
|
+
exports.useSlots = useSlots;
|
|
1391
2306
|
exports.watch = watch;
|
|
1392
2307
|
exports.watchEffect = watchEffect;
|