@vue-mini/core 1.0.0-rc.10
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/vue-mini.cjs.js +2454 -0
- package/dist/vue-mini.cjs.prod.js +8 -0
- package/dist/vue-mini.d.ts +107 -0
- package/dist/vue-mini.esm-bundler.js +1118 -0
- package/package.json +29 -0
|
@@ -0,0 +1,2454 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* vue-mini v1.0.0-rc.10
|
|
3
|
+
* https://github.com/vue-mini/vue-mini
|
|
4
|
+
* (c) 2019-present Yang Mingshan
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @vue/shared v3.4.27
|
|
11
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
12
|
+
* @license MIT
|
|
13
|
+
**/
|
|
14
|
+
/*! #__NO_SIDE_EFFECTS__ */
|
|
15
|
+
// @__NO_SIDE_EFFECTS__
|
|
16
|
+
function makeMap(str, expectsLowerCase) {
|
|
17
|
+
const set = new Set(str.split(","));
|
|
18
|
+
return (val) => set.has(val);
|
|
19
|
+
}
|
|
20
|
+
const NOOP$1 = () => {
|
|
21
|
+
};
|
|
22
|
+
const extend$1 = Object.assign;
|
|
23
|
+
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
24
|
+
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
25
|
+
const isArray$1 = Array.isArray;
|
|
26
|
+
const isMap$1 = (val) => toTypeString(val) === "[object Map]";
|
|
27
|
+
const isFunction$1 = (val) => typeof val === "function";
|
|
28
|
+
const isString = (val) => typeof val === "string";
|
|
29
|
+
const isSymbol = (val) => typeof val === "symbol";
|
|
30
|
+
const isObject$1 = (val) => val !== null && typeof val === "object";
|
|
31
|
+
const objectToString = Object.prototype.toString;
|
|
32
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
33
|
+
const toRawType = (value) => {
|
|
34
|
+
return toTypeString(value).slice(8, -1);
|
|
35
|
+
};
|
|
36
|
+
const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
37
|
+
const cacheStringFunction = (fn) => {
|
|
38
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
39
|
+
return (str) => {
|
|
40
|
+
const hit = cache[str];
|
|
41
|
+
return hit || (cache[str] = fn(str));
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const capitalize = cacheStringFunction((str) => {
|
|
45
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
46
|
+
});
|
|
47
|
+
const hasChanged$1 = (value, oldValue) => !Object.is(value, oldValue);
|
|
48
|
+
const def = (obj, key, value, writable = false) => {
|
|
49
|
+
Object.defineProperty(obj, key, {
|
|
50
|
+
configurable: true,
|
|
51
|
+
enumerable: false,
|
|
52
|
+
writable,
|
|
53
|
+
value
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @vue/reactivity v3.4.27
|
|
59
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
60
|
+
* @license MIT
|
|
61
|
+
**/
|
|
62
|
+
|
|
63
|
+
function warn(msg, ...args) {
|
|
64
|
+
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let activeEffectScope;
|
|
68
|
+
class EffectScope {
|
|
69
|
+
constructor(detached = false) {
|
|
70
|
+
this.detached = detached;
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
this._active = true;
|
|
75
|
+
/**
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
this.effects = [];
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
this.cleanups = [];
|
|
83
|
+
this.parent = activeEffectScope;
|
|
84
|
+
if (!detached && activeEffectScope) {
|
|
85
|
+
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
|
86
|
+
this
|
|
87
|
+
) - 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
get active() {
|
|
91
|
+
return this._active;
|
|
92
|
+
}
|
|
93
|
+
run(fn) {
|
|
94
|
+
if (this._active) {
|
|
95
|
+
const currentEffectScope = activeEffectScope;
|
|
96
|
+
try {
|
|
97
|
+
activeEffectScope = this;
|
|
98
|
+
return fn();
|
|
99
|
+
} finally {
|
|
100
|
+
activeEffectScope = currentEffectScope;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
warn(`cannot run an inactive effect scope.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* This should only be called on non-detached scopes
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
on() {
|
|
111
|
+
activeEffectScope = this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* This should only be called on non-detached scopes
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
off() {
|
|
118
|
+
activeEffectScope = this.parent;
|
|
119
|
+
}
|
|
120
|
+
stop(fromParent) {
|
|
121
|
+
if (this._active) {
|
|
122
|
+
let i, l;
|
|
123
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
124
|
+
this.effects[i].stop();
|
|
125
|
+
}
|
|
126
|
+
for (i = 0, l = this.cleanups.length; i < l; i++) {
|
|
127
|
+
this.cleanups[i]();
|
|
128
|
+
}
|
|
129
|
+
if (this.scopes) {
|
|
130
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
131
|
+
this.scopes[i].stop(true);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!this.detached && this.parent && !fromParent) {
|
|
135
|
+
const last = this.parent.scopes.pop();
|
|
136
|
+
if (last && last !== this) {
|
|
137
|
+
this.parent.scopes[this.index] = last;
|
|
138
|
+
last.index = this.index;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
this.parent = void 0;
|
|
142
|
+
this._active = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function effectScope(detached) {
|
|
147
|
+
return new EffectScope(detached);
|
|
148
|
+
}
|
|
149
|
+
function recordEffectScope(effect, scope = activeEffectScope) {
|
|
150
|
+
if (scope && scope.active) {
|
|
151
|
+
scope.effects.push(effect);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function getCurrentScope() {
|
|
155
|
+
return activeEffectScope;
|
|
156
|
+
}
|
|
157
|
+
function onScopeDispose(fn) {
|
|
158
|
+
if (activeEffectScope) {
|
|
159
|
+
activeEffectScope.cleanups.push(fn);
|
|
160
|
+
} else {
|
|
161
|
+
warn(
|
|
162
|
+
`onScopeDispose() is called when there is no active effect scope to be associated with.`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let activeEffect;
|
|
168
|
+
class ReactiveEffect {
|
|
169
|
+
constructor(fn, trigger, scheduler, scope) {
|
|
170
|
+
this.fn = fn;
|
|
171
|
+
this.trigger = trigger;
|
|
172
|
+
this.scheduler = scheduler;
|
|
173
|
+
this.active = true;
|
|
174
|
+
this.deps = [];
|
|
175
|
+
/**
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
this._dirtyLevel = 4;
|
|
179
|
+
/**
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
this._trackId = 0;
|
|
183
|
+
/**
|
|
184
|
+
* @internal
|
|
185
|
+
*/
|
|
186
|
+
this._runnings = 0;
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
this._shouldSchedule = false;
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
this._depsLength = 0;
|
|
195
|
+
recordEffectScope(this, scope);
|
|
196
|
+
}
|
|
197
|
+
get dirty() {
|
|
198
|
+
if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
|
|
199
|
+
this._dirtyLevel = 1;
|
|
200
|
+
pauseTracking();
|
|
201
|
+
for (let i = 0; i < this._depsLength; i++) {
|
|
202
|
+
const dep = this.deps[i];
|
|
203
|
+
if (dep.computed) {
|
|
204
|
+
triggerComputed(dep.computed);
|
|
205
|
+
if (this._dirtyLevel >= 4) {
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (this._dirtyLevel === 1) {
|
|
211
|
+
this._dirtyLevel = 0;
|
|
212
|
+
}
|
|
213
|
+
resetTracking();
|
|
214
|
+
}
|
|
215
|
+
return this._dirtyLevel >= 4;
|
|
216
|
+
}
|
|
217
|
+
set dirty(v) {
|
|
218
|
+
this._dirtyLevel = v ? 4 : 0;
|
|
219
|
+
}
|
|
220
|
+
run() {
|
|
221
|
+
this._dirtyLevel = 0;
|
|
222
|
+
if (!this.active) {
|
|
223
|
+
return this.fn();
|
|
224
|
+
}
|
|
225
|
+
let lastShouldTrack = shouldTrack;
|
|
226
|
+
let lastEffect = activeEffect;
|
|
227
|
+
try {
|
|
228
|
+
shouldTrack = true;
|
|
229
|
+
activeEffect = this;
|
|
230
|
+
this._runnings++;
|
|
231
|
+
preCleanupEffect(this);
|
|
232
|
+
return this.fn();
|
|
233
|
+
} finally {
|
|
234
|
+
postCleanupEffect(this);
|
|
235
|
+
this._runnings--;
|
|
236
|
+
activeEffect = lastEffect;
|
|
237
|
+
shouldTrack = lastShouldTrack;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
stop() {
|
|
241
|
+
if (this.active) {
|
|
242
|
+
preCleanupEffect(this);
|
|
243
|
+
postCleanupEffect(this);
|
|
244
|
+
this.onStop && this.onStop();
|
|
245
|
+
this.active = false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function triggerComputed(computed) {
|
|
250
|
+
return computed.value;
|
|
251
|
+
}
|
|
252
|
+
function preCleanupEffect(effect2) {
|
|
253
|
+
effect2._trackId++;
|
|
254
|
+
effect2._depsLength = 0;
|
|
255
|
+
}
|
|
256
|
+
function postCleanupEffect(effect2) {
|
|
257
|
+
if (effect2.deps.length > effect2._depsLength) {
|
|
258
|
+
for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
|
|
259
|
+
cleanupDepEffect(effect2.deps[i], effect2);
|
|
260
|
+
}
|
|
261
|
+
effect2.deps.length = effect2._depsLength;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function cleanupDepEffect(dep, effect2) {
|
|
265
|
+
const trackId = dep.get(effect2);
|
|
266
|
+
if (trackId !== void 0 && effect2._trackId !== trackId) {
|
|
267
|
+
dep.delete(effect2);
|
|
268
|
+
if (dep.size === 0) {
|
|
269
|
+
dep.cleanup();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function effect(fn, options) {
|
|
274
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
275
|
+
fn = fn.effect.fn;
|
|
276
|
+
}
|
|
277
|
+
const _effect = new ReactiveEffect(fn, NOOP$1, () => {
|
|
278
|
+
if (_effect.dirty) {
|
|
279
|
+
_effect.run();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
if (options) {
|
|
283
|
+
extend$1(_effect, options);
|
|
284
|
+
if (options.scope)
|
|
285
|
+
recordEffectScope(_effect, options.scope);
|
|
286
|
+
}
|
|
287
|
+
if (!options || !options.lazy) {
|
|
288
|
+
_effect.run();
|
|
289
|
+
}
|
|
290
|
+
const runner = _effect.run.bind(_effect);
|
|
291
|
+
runner.effect = _effect;
|
|
292
|
+
return runner;
|
|
293
|
+
}
|
|
294
|
+
function stop(runner) {
|
|
295
|
+
runner.effect.stop();
|
|
296
|
+
}
|
|
297
|
+
let shouldTrack = true;
|
|
298
|
+
let pauseScheduleStack = 0;
|
|
299
|
+
const trackStack = [];
|
|
300
|
+
function pauseTracking() {
|
|
301
|
+
trackStack.push(shouldTrack);
|
|
302
|
+
shouldTrack = false;
|
|
303
|
+
}
|
|
304
|
+
function resetTracking() {
|
|
305
|
+
const last = trackStack.pop();
|
|
306
|
+
shouldTrack = last === void 0 ? true : last;
|
|
307
|
+
}
|
|
308
|
+
function pauseScheduling() {
|
|
309
|
+
pauseScheduleStack++;
|
|
310
|
+
}
|
|
311
|
+
function resetScheduling() {
|
|
312
|
+
pauseScheduleStack--;
|
|
313
|
+
while (!pauseScheduleStack && queueEffectSchedulers.length) {
|
|
314
|
+
queueEffectSchedulers.shift()();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function trackEffect(effect2, dep, debuggerEventExtraInfo) {
|
|
318
|
+
var _a;
|
|
319
|
+
if (dep.get(effect2) !== effect2._trackId) {
|
|
320
|
+
dep.set(effect2, effect2._trackId);
|
|
321
|
+
const oldDep = effect2.deps[effect2._depsLength];
|
|
322
|
+
if (oldDep !== dep) {
|
|
323
|
+
if (oldDep) {
|
|
324
|
+
cleanupDepEffect(oldDep, effect2);
|
|
325
|
+
}
|
|
326
|
+
effect2.deps[effect2._depsLength++] = dep;
|
|
327
|
+
} else {
|
|
328
|
+
effect2._depsLength++;
|
|
329
|
+
}
|
|
330
|
+
{
|
|
331
|
+
(_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend$1({ effect: effect2 }, debuggerEventExtraInfo));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const queueEffectSchedulers = [];
|
|
336
|
+
function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
|
|
337
|
+
var _a;
|
|
338
|
+
pauseScheduling();
|
|
339
|
+
for (const effect2 of dep.keys()) {
|
|
340
|
+
let tracking;
|
|
341
|
+
if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
|
342
|
+
effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
|
|
343
|
+
effect2._dirtyLevel = dirtyLevel;
|
|
344
|
+
}
|
|
345
|
+
if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
|
|
346
|
+
{
|
|
347
|
+
(_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend$1({ effect: effect2 }, debuggerEventExtraInfo));
|
|
348
|
+
}
|
|
349
|
+
effect2.trigger();
|
|
350
|
+
if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
|
|
351
|
+
effect2._shouldSchedule = false;
|
|
352
|
+
if (effect2.scheduler) {
|
|
353
|
+
queueEffectSchedulers.push(effect2.scheduler);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
resetScheduling();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const createDep = (cleanup, computed) => {
|
|
362
|
+
const dep = /* @__PURE__ */ new Map();
|
|
363
|
+
dep.cleanup = cleanup;
|
|
364
|
+
dep.computed = computed;
|
|
365
|
+
return dep;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
369
|
+
const ITERATE_KEY = Symbol("iterate" );
|
|
370
|
+
const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
|
|
371
|
+
function track(target, type, key) {
|
|
372
|
+
if (shouldTrack && activeEffect) {
|
|
373
|
+
let depsMap = targetMap.get(target);
|
|
374
|
+
if (!depsMap) {
|
|
375
|
+
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
376
|
+
}
|
|
377
|
+
let dep = depsMap.get(key);
|
|
378
|
+
if (!dep) {
|
|
379
|
+
depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
|
|
380
|
+
}
|
|
381
|
+
trackEffect(
|
|
382
|
+
activeEffect,
|
|
383
|
+
dep,
|
|
384
|
+
{
|
|
385
|
+
target,
|
|
386
|
+
type,
|
|
387
|
+
key
|
|
388
|
+
}
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
393
|
+
const depsMap = targetMap.get(target);
|
|
394
|
+
if (!depsMap) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
let deps = [];
|
|
398
|
+
if (type === "clear") {
|
|
399
|
+
deps = [...depsMap.values()];
|
|
400
|
+
} else if (key === "length" && isArray$1(target)) {
|
|
401
|
+
const newLength = Number(newValue);
|
|
402
|
+
depsMap.forEach((dep, key2) => {
|
|
403
|
+
if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
|
|
404
|
+
deps.push(dep);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
} else {
|
|
408
|
+
if (key !== void 0) {
|
|
409
|
+
deps.push(depsMap.get(key));
|
|
410
|
+
}
|
|
411
|
+
switch (type) {
|
|
412
|
+
case "add":
|
|
413
|
+
if (!isArray$1(target)) {
|
|
414
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
415
|
+
if (isMap$1(target)) {
|
|
416
|
+
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
417
|
+
}
|
|
418
|
+
} else if (isIntegerKey(key)) {
|
|
419
|
+
deps.push(depsMap.get("length"));
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
case "delete":
|
|
423
|
+
if (!isArray$1(target)) {
|
|
424
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
425
|
+
if (isMap$1(target)) {
|
|
426
|
+
deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
430
|
+
case "set":
|
|
431
|
+
if (isMap$1(target)) {
|
|
432
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
433
|
+
}
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
pauseScheduling();
|
|
438
|
+
for (const dep of deps) {
|
|
439
|
+
if (dep) {
|
|
440
|
+
triggerEffects(
|
|
441
|
+
dep,
|
|
442
|
+
4,
|
|
443
|
+
{
|
|
444
|
+
target,
|
|
445
|
+
type,
|
|
446
|
+
key,
|
|
447
|
+
newValue,
|
|
448
|
+
oldValue,
|
|
449
|
+
oldTarget
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
resetScheduling();
|
|
455
|
+
}
|
|
456
|
+
function getDepFromReactive(object, key) {
|
|
457
|
+
const depsMap = targetMap.get(object);
|
|
458
|
+
return depsMap && depsMap.get(key);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
462
|
+
const builtInSymbols = new Set(
|
|
463
|
+
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
|
|
464
|
+
);
|
|
465
|
+
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
466
|
+
function createArrayInstrumentations() {
|
|
467
|
+
const instrumentations = {};
|
|
468
|
+
["includes", "indexOf", "lastIndexOf"].forEach((key) => {
|
|
469
|
+
instrumentations[key] = function(...args) {
|
|
470
|
+
const arr = toRaw(this);
|
|
471
|
+
for (let i = 0, l = this.length; i < l; i++) {
|
|
472
|
+
track(arr, "get", i + "");
|
|
473
|
+
}
|
|
474
|
+
const res = arr[key](...args);
|
|
475
|
+
if (res === -1 || res === false) {
|
|
476
|
+
return arr[key](...args.map(toRaw));
|
|
477
|
+
} else {
|
|
478
|
+
return res;
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
});
|
|
482
|
+
["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
|
|
483
|
+
instrumentations[key] = function(...args) {
|
|
484
|
+
pauseTracking();
|
|
485
|
+
pauseScheduling();
|
|
486
|
+
const res = toRaw(this)[key].apply(this, args);
|
|
487
|
+
resetScheduling();
|
|
488
|
+
resetTracking();
|
|
489
|
+
return res;
|
|
490
|
+
};
|
|
491
|
+
});
|
|
492
|
+
return instrumentations;
|
|
493
|
+
}
|
|
494
|
+
function hasOwnProperty(key) {
|
|
495
|
+
if (!isSymbol(key))
|
|
496
|
+
key = String(key);
|
|
497
|
+
const obj = toRaw(this);
|
|
498
|
+
track(obj, "has", key);
|
|
499
|
+
return obj.hasOwnProperty(key);
|
|
500
|
+
}
|
|
501
|
+
class BaseReactiveHandler {
|
|
502
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
503
|
+
this._isReadonly = _isReadonly;
|
|
504
|
+
this._isShallow = _isShallow;
|
|
505
|
+
}
|
|
506
|
+
get(target, key, receiver) {
|
|
507
|
+
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
|
508
|
+
if (key === "__v_isReactive") {
|
|
509
|
+
return !isReadonly2;
|
|
510
|
+
} else if (key === "__v_isReadonly") {
|
|
511
|
+
return isReadonly2;
|
|
512
|
+
} else if (key === "__v_isShallow") {
|
|
513
|
+
return isShallow2;
|
|
514
|
+
} else if (key === "__v_raw") {
|
|
515
|
+
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || // receiver is not the reactive proxy, but has the same prototype
|
|
516
|
+
// this means the reciever is a user proxy of the reactive proxy
|
|
517
|
+
Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
|
518
|
+
return target;
|
|
519
|
+
}
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const targetIsArray = isArray$1(target);
|
|
523
|
+
if (!isReadonly2) {
|
|
524
|
+
if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
|
|
525
|
+
return Reflect.get(arrayInstrumentations, key, receiver);
|
|
526
|
+
}
|
|
527
|
+
if (key === "hasOwnProperty") {
|
|
528
|
+
return hasOwnProperty;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const res = Reflect.get(target, key, receiver);
|
|
532
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
533
|
+
return res;
|
|
534
|
+
}
|
|
535
|
+
if (!isReadonly2) {
|
|
536
|
+
track(target, "get", key);
|
|
537
|
+
}
|
|
538
|
+
if (isShallow2) {
|
|
539
|
+
return res;
|
|
540
|
+
}
|
|
541
|
+
if (isRef(res)) {
|
|
542
|
+
return targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
543
|
+
}
|
|
544
|
+
if (isObject$1(res)) {
|
|
545
|
+
return isReadonly2 ? readonly(res) : reactive(res);
|
|
546
|
+
}
|
|
547
|
+
return res;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
class MutableReactiveHandler extends BaseReactiveHandler {
|
|
551
|
+
constructor(isShallow2 = false) {
|
|
552
|
+
super(false, isShallow2);
|
|
553
|
+
}
|
|
554
|
+
set(target, key, value, receiver) {
|
|
555
|
+
let oldValue = target[key];
|
|
556
|
+
if (!this._isShallow) {
|
|
557
|
+
const isOldValueReadonly = isReadonly(oldValue);
|
|
558
|
+
if (!isShallow(value) && !isReadonly(value)) {
|
|
559
|
+
oldValue = toRaw(oldValue);
|
|
560
|
+
value = toRaw(value);
|
|
561
|
+
}
|
|
562
|
+
if (!isArray$1(target) && isRef(oldValue) && !isRef(value)) {
|
|
563
|
+
if (isOldValueReadonly) {
|
|
564
|
+
return false;
|
|
565
|
+
} else {
|
|
566
|
+
oldValue.value = value;
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const hadKey = isArray$1(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key);
|
|
572
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
573
|
+
if (target === toRaw(receiver)) {
|
|
574
|
+
if (!hadKey) {
|
|
575
|
+
trigger(target, "add", key, value);
|
|
576
|
+
} else if (hasChanged$1(value, oldValue)) {
|
|
577
|
+
trigger(target, "set", key, value, oldValue);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return result;
|
|
581
|
+
}
|
|
582
|
+
deleteProperty(target, key) {
|
|
583
|
+
const hadKey = hasOwn(target, key);
|
|
584
|
+
const oldValue = target[key];
|
|
585
|
+
const result = Reflect.deleteProperty(target, key);
|
|
586
|
+
if (result && hadKey) {
|
|
587
|
+
trigger(target, "delete", key, void 0, oldValue);
|
|
588
|
+
}
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
has(target, key) {
|
|
592
|
+
const result = Reflect.has(target, key);
|
|
593
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
|
594
|
+
track(target, "has", key);
|
|
595
|
+
}
|
|
596
|
+
return result;
|
|
597
|
+
}
|
|
598
|
+
ownKeys(target) {
|
|
599
|
+
track(
|
|
600
|
+
target,
|
|
601
|
+
"iterate",
|
|
602
|
+
isArray$1(target) ? "length" : ITERATE_KEY
|
|
603
|
+
);
|
|
604
|
+
return Reflect.ownKeys(target);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
608
|
+
constructor(isShallow2 = false) {
|
|
609
|
+
super(true, isShallow2);
|
|
610
|
+
}
|
|
611
|
+
set(target, key) {
|
|
612
|
+
{
|
|
613
|
+
warn(
|
|
614
|
+
`Set operation on key "${String(key)}" failed: target is readonly.`,
|
|
615
|
+
target
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
deleteProperty(target, key) {
|
|
621
|
+
{
|
|
622
|
+
warn(
|
|
623
|
+
`Delete operation on key "${String(key)}" failed: target is readonly.`,
|
|
624
|
+
target
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
631
|
+
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
632
|
+
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
|
|
633
|
+
true
|
|
634
|
+
);
|
|
635
|
+
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
636
|
+
|
|
637
|
+
const toShallow = (value) => value;
|
|
638
|
+
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
639
|
+
function get(target, key, isReadonly = false, isShallow = false) {
|
|
640
|
+
target = target["__v_raw"];
|
|
641
|
+
const rawTarget = toRaw(target);
|
|
642
|
+
const rawKey = toRaw(key);
|
|
643
|
+
if (!isReadonly) {
|
|
644
|
+
if (hasChanged$1(key, rawKey)) {
|
|
645
|
+
track(rawTarget, "get", key);
|
|
646
|
+
}
|
|
647
|
+
track(rawTarget, "get", rawKey);
|
|
648
|
+
}
|
|
649
|
+
const { has: has2 } = getProto(rawTarget);
|
|
650
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
651
|
+
if (has2.call(rawTarget, key)) {
|
|
652
|
+
return wrap(target.get(key));
|
|
653
|
+
} else if (has2.call(rawTarget, rawKey)) {
|
|
654
|
+
return wrap(target.get(rawKey));
|
|
655
|
+
} else if (target !== rawTarget) {
|
|
656
|
+
target.get(key);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function has(key, isReadonly = false) {
|
|
660
|
+
const target = this["__v_raw"];
|
|
661
|
+
const rawTarget = toRaw(target);
|
|
662
|
+
const rawKey = toRaw(key);
|
|
663
|
+
if (!isReadonly) {
|
|
664
|
+
if (hasChanged$1(key, rawKey)) {
|
|
665
|
+
track(rawTarget, "has", key);
|
|
666
|
+
}
|
|
667
|
+
track(rawTarget, "has", rawKey);
|
|
668
|
+
}
|
|
669
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
670
|
+
}
|
|
671
|
+
function size(target, isReadonly = false) {
|
|
672
|
+
target = target["__v_raw"];
|
|
673
|
+
!isReadonly && track(toRaw(target), "iterate", ITERATE_KEY);
|
|
674
|
+
return Reflect.get(target, "size", target);
|
|
675
|
+
}
|
|
676
|
+
function add(value) {
|
|
677
|
+
value = toRaw(value);
|
|
678
|
+
const target = toRaw(this);
|
|
679
|
+
const proto = getProto(target);
|
|
680
|
+
const hadKey = proto.has.call(target, value);
|
|
681
|
+
if (!hadKey) {
|
|
682
|
+
target.add(value);
|
|
683
|
+
trigger(target, "add", value, value);
|
|
684
|
+
}
|
|
685
|
+
return this;
|
|
686
|
+
}
|
|
687
|
+
function set(key, value) {
|
|
688
|
+
value = toRaw(value);
|
|
689
|
+
const target = toRaw(this);
|
|
690
|
+
const { has: has2, get: get2 } = getProto(target);
|
|
691
|
+
let hadKey = has2.call(target, key);
|
|
692
|
+
if (!hadKey) {
|
|
693
|
+
key = toRaw(key);
|
|
694
|
+
hadKey = has2.call(target, key);
|
|
695
|
+
} else {
|
|
696
|
+
checkIdentityKeys(target, has2, key);
|
|
697
|
+
}
|
|
698
|
+
const oldValue = get2.call(target, key);
|
|
699
|
+
target.set(key, value);
|
|
700
|
+
if (!hadKey) {
|
|
701
|
+
trigger(target, "add", key, value);
|
|
702
|
+
} else if (hasChanged$1(value, oldValue)) {
|
|
703
|
+
trigger(target, "set", key, value, oldValue);
|
|
704
|
+
}
|
|
705
|
+
return this;
|
|
706
|
+
}
|
|
707
|
+
function deleteEntry(key) {
|
|
708
|
+
const target = toRaw(this);
|
|
709
|
+
const { has: has2, get: get2 } = getProto(target);
|
|
710
|
+
let hadKey = has2.call(target, key);
|
|
711
|
+
if (!hadKey) {
|
|
712
|
+
key = toRaw(key);
|
|
713
|
+
hadKey = has2.call(target, key);
|
|
714
|
+
} else {
|
|
715
|
+
checkIdentityKeys(target, has2, key);
|
|
716
|
+
}
|
|
717
|
+
const oldValue = get2 ? get2.call(target, key) : void 0;
|
|
718
|
+
const result = target.delete(key);
|
|
719
|
+
if (hadKey) {
|
|
720
|
+
trigger(target, "delete", key, void 0, oldValue);
|
|
721
|
+
}
|
|
722
|
+
return result;
|
|
723
|
+
}
|
|
724
|
+
function clear() {
|
|
725
|
+
const target = toRaw(this);
|
|
726
|
+
const hadItems = target.size !== 0;
|
|
727
|
+
const oldTarget = isMap$1(target) ? new Map(target) : new Set(target) ;
|
|
728
|
+
const result = target.clear();
|
|
729
|
+
if (hadItems) {
|
|
730
|
+
trigger(target, "clear", void 0, void 0, oldTarget);
|
|
731
|
+
}
|
|
732
|
+
return result;
|
|
733
|
+
}
|
|
734
|
+
function createForEach(isReadonly, isShallow) {
|
|
735
|
+
return function forEach(callback, thisArg) {
|
|
736
|
+
const observed = this;
|
|
737
|
+
const target = observed["__v_raw"];
|
|
738
|
+
const rawTarget = toRaw(target);
|
|
739
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
740
|
+
!isReadonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
741
|
+
return target.forEach((value, key) => {
|
|
742
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
743
|
+
});
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function createIterableMethod(method, isReadonly, isShallow) {
|
|
747
|
+
return function(...args) {
|
|
748
|
+
const target = this["__v_raw"];
|
|
749
|
+
const rawTarget = toRaw(target);
|
|
750
|
+
const targetIsMap = isMap$1(rawTarget);
|
|
751
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
752
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
753
|
+
const innerIterator = target[method](...args);
|
|
754
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
755
|
+
!isReadonly && track(
|
|
756
|
+
rawTarget,
|
|
757
|
+
"iterate",
|
|
758
|
+
isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY
|
|
759
|
+
);
|
|
760
|
+
return {
|
|
761
|
+
// iterator protocol
|
|
762
|
+
next() {
|
|
763
|
+
const { value, done } = innerIterator.next();
|
|
764
|
+
return done ? { value, done } : {
|
|
765
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
766
|
+
done
|
|
767
|
+
};
|
|
768
|
+
},
|
|
769
|
+
// iterable protocol
|
|
770
|
+
[Symbol.iterator]() {
|
|
771
|
+
return this;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
function createReadonlyMethod(type) {
|
|
777
|
+
return function(...args) {
|
|
778
|
+
{
|
|
779
|
+
const key = args[0] ? `on key "${args[0]}" ` : ``;
|
|
780
|
+
warn(
|
|
781
|
+
`${capitalize(type)} operation ${key}failed: target is readonly.`,
|
|
782
|
+
toRaw(this)
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
function createInstrumentations() {
|
|
789
|
+
const mutableInstrumentations2 = {
|
|
790
|
+
get(key) {
|
|
791
|
+
return get(this, key);
|
|
792
|
+
},
|
|
793
|
+
get size() {
|
|
794
|
+
return size(this);
|
|
795
|
+
},
|
|
796
|
+
has,
|
|
797
|
+
add,
|
|
798
|
+
set,
|
|
799
|
+
delete: deleteEntry,
|
|
800
|
+
clear,
|
|
801
|
+
forEach: createForEach(false, false)
|
|
802
|
+
};
|
|
803
|
+
const shallowInstrumentations2 = {
|
|
804
|
+
get(key) {
|
|
805
|
+
return get(this, key, false, true);
|
|
806
|
+
},
|
|
807
|
+
get size() {
|
|
808
|
+
return size(this);
|
|
809
|
+
},
|
|
810
|
+
has,
|
|
811
|
+
add,
|
|
812
|
+
set,
|
|
813
|
+
delete: deleteEntry,
|
|
814
|
+
clear,
|
|
815
|
+
forEach: createForEach(false, true)
|
|
816
|
+
};
|
|
817
|
+
const readonlyInstrumentations2 = {
|
|
818
|
+
get(key) {
|
|
819
|
+
return get(this, key, true);
|
|
820
|
+
},
|
|
821
|
+
get size() {
|
|
822
|
+
return size(this, true);
|
|
823
|
+
},
|
|
824
|
+
has(key) {
|
|
825
|
+
return has.call(this, key, true);
|
|
826
|
+
},
|
|
827
|
+
add: createReadonlyMethod("add"),
|
|
828
|
+
set: createReadonlyMethod("set"),
|
|
829
|
+
delete: createReadonlyMethod("delete"),
|
|
830
|
+
clear: createReadonlyMethod("clear"),
|
|
831
|
+
forEach: createForEach(true, false)
|
|
832
|
+
};
|
|
833
|
+
const shallowReadonlyInstrumentations2 = {
|
|
834
|
+
get(key) {
|
|
835
|
+
return get(this, key, true, true);
|
|
836
|
+
},
|
|
837
|
+
get size() {
|
|
838
|
+
return size(this, true);
|
|
839
|
+
},
|
|
840
|
+
has(key) {
|
|
841
|
+
return has.call(this, key, true);
|
|
842
|
+
},
|
|
843
|
+
add: createReadonlyMethod("add"),
|
|
844
|
+
set: createReadonlyMethod("set"),
|
|
845
|
+
delete: createReadonlyMethod("delete"),
|
|
846
|
+
clear: createReadonlyMethod("clear"),
|
|
847
|
+
forEach: createForEach(true, true)
|
|
848
|
+
};
|
|
849
|
+
const iteratorMethods = [
|
|
850
|
+
"keys",
|
|
851
|
+
"values",
|
|
852
|
+
"entries",
|
|
853
|
+
Symbol.iterator
|
|
854
|
+
];
|
|
855
|
+
iteratorMethods.forEach((method) => {
|
|
856
|
+
mutableInstrumentations2[method] = createIterableMethod(method, false, false);
|
|
857
|
+
readonlyInstrumentations2[method] = createIterableMethod(method, true, false);
|
|
858
|
+
shallowInstrumentations2[method] = createIterableMethod(method, false, true);
|
|
859
|
+
shallowReadonlyInstrumentations2[method] = createIterableMethod(
|
|
860
|
+
method,
|
|
861
|
+
true,
|
|
862
|
+
true
|
|
863
|
+
);
|
|
864
|
+
});
|
|
865
|
+
return [
|
|
866
|
+
mutableInstrumentations2,
|
|
867
|
+
readonlyInstrumentations2,
|
|
868
|
+
shallowInstrumentations2,
|
|
869
|
+
shallowReadonlyInstrumentations2
|
|
870
|
+
];
|
|
871
|
+
}
|
|
872
|
+
const [
|
|
873
|
+
mutableInstrumentations,
|
|
874
|
+
readonlyInstrumentations,
|
|
875
|
+
shallowInstrumentations,
|
|
876
|
+
shallowReadonlyInstrumentations
|
|
877
|
+
] = /* @__PURE__ */ createInstrumentations();
|
|
878
|
+
function createInstrumentationGetter(isReadonly, shallow) {
|
|
879
|
+
const instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations;
|
|
880
|
+
return (target, key, receiver) => {
|
|
881
|
+
if (key === "__v_isReactive") {
|
|
882
|
+
return !isReadonly;
|
|
883
|
+
} else if (key === "__v_isReadonly") {
|
|
884
|
+
return isReadonly;
|
|
885
|
+
} else if (key === "__v_raw") {
|
|
886
|
+
return target;
|
|
887
|
+
}
|
|
888
|
+
return Reflect.get(
|
|
889
|
+
hasOwn(instrumentations, key) && key in target ? instrumentations : target,
|
|
890
|
+
key,
|
|
891
|
+
receiver
|
|
892
|
+
);
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
const mutableCollectionHandlers = {
|
|
896
|
+
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
897
|
+
};
|
|
898
|
+
const shallowCollectionHandlers = {
|
|
899
|
+
get: /* @__PURE__ */ createInstrumentationGetter(false, true)
|
|
900
|
+
};
|
|
901
|
+
const readonlyCollectionHandlers = {
|
|
902
|
+
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
903
|
+
};
|
|
904
|
+
const shallowReadonlyCollectionHandlers = {
|
|
905
|
+
get: /* @__PURE__ */ createInstrumentationGetter(true, true)
|
|
906
|
+
};
|
|
907
|
+
function checkIdentityKeys(target, has2, key) {
|
|
908
|
+
const rawKey = toRaw(key);
|
|
909
|
+
if (rawKey !== key && has2.call(target, rawKey)) {
|
|
910
|
+
const type = toRawType(target);
|
|
911
|
+
warn(
|
|
912
|
+
`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
918
|
+
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
919
|
+
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
920
|
+
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
921
|
+
function targetTypeMap(rawType) {
|
|
922
|
+
switch (rawType) {
|
|
923
|
+
case "Object":
|
|
924
|
+
case "Array":
|
|
925
|
+
return 1 /* COMMON */;
|
|
926
|
+
case "Map":
|
|
927
|
+
case "Set":
|
|
928
|
+
case "WeakMap":
|
|
929
|
+
case "WeakSet":
|
|
930
|
+
return 2 /* COLLECTION */;
|
|
931
|
+
default:
|
|
932
|
+
return 0 /* INVALID */;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
function getTargetType(value) {
|
|
936
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 /* INVALID */ : targetTypeMap(toRawType(value));
|
|
937
|
+
}
|
|
938
|
+
function reactive(target) {
|
|
939
|
+
if (isReadonly(target)) {
|
|
940
|
+
return target;
|
|
941
|
+
}
|
|
942
|
+
return createReactiveObject(
|
|
943
|
+
target,
|
|
944
|
+
false,
|
|
945
|
+
mutableHandlers,
|
|
946
|
+
mutableCollectionHandlers,
|
|
947
|
+
reactiveMap
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
function shallowReactive(target) {
|
|
951
|
+
return createReactiveObject(
|
|
952
|
+
target,
|
|
953
|
+
false,
|
|
954
|
+
shallowReactiveHandlers,
|
|
955
|
+
shallowCollectionHandlers,
|
|
956
|
+
shallowReactiveMap
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
function readonly(target) {
|
|
960
|
+
return createReactiveObject(
|
|
961
|
+
target,
|
|
962
|
+
true,
|
|
963
|
+
readonlyHandlers,
|
|
964
|
+
readonlyCollectionHandlers,
|
|
965
|
+
readonlyMap
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
function shallowReadonly(target) {
|
|
969
|
+
return createReactiveObject(
|
|
970
|
+
target,
|
|
971
|
+
true,
|
|
972
|
+
shallowReadonlyHandlers,
|
|
973
|
+
shallowReadonlyCollectionHandlers,
|
|
974
|
+
shallowReadonlyMap
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
|
978
|
+
if (!isObject$1(target)) {
|
|
979
|
+
{
|
|
980
|
+
warn(`value cannot be made reactive: ${String(target)}`);
|
|
981
|
+
}
|
|
982
|
+
return target;
|
|
983
|
+
}
|
|
984
|
+
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
|
985
|
+
return target;
|
|
986
|
+
}
|
|
987
|
+
const existingProxy = proxyMap.get(target);
|
|
988
|
+
if (existingProxy) {
|
|
989
|
+
return existingProxy;
|
|
990
|
+
}
|
|
991
|
+
const targetType = getTargetType(target);
|
|
992
|
+
if (targetType === 0 /* INVALID */) {
|
|
993
|
+
return target;
|
|
994
|
+
}
|
|
995
|
+
const proxy = new Proxy(
|
|
996
|
+
target,
|
|
997
|
+
targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
|
|
998
|
+
);
|
|
999
|
+
proxyMap.set(target, proxy);
|
|
1000
|
+
return proxy;
|
|
1001
|
+
}
|
|
1002
|
+
function isReactive(value) {
|
|
1003
|
+
if (isReadonly(value)) {
|
|
1004
|
+
return isReactive(value["__v_raw"]);
|
|
1005
|
+
}
|
|
1006
|
+
return !!(value && value["__v_isReactive"]);
|
|
1007
|
+
}
|
|
1008
|
+
function isReadonly(value) {
|
|
1009
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1010
|
+
}
|
|
1011
|
+
function isShallow(value) {
|
|
1012
|
+
return !!(value && value["__v_isShallow"]);
|
|
1013
|
+
}
|
|
1014
|
+
function isProxy(value) {
|
|
1015
|
+
return value ? !!value["__v_raw"] : false;
|
|
1016
|
+
}
|
|
1017
|
+
function toRaw(observed) {
|
|
1018
|
+
const raw = observed && observed["__v_raw"];
|
|
1019
|
+
return raw ? toRaw(raw) : observed;
|
|
1020
|
+
}
|
|
1021
|
+
function markRaw(value) {
|
|
1022
|
+
if (Object.isExtensible(value)) {
|
|
1023
|
+
def(value, "__v_skip", true);
|
|
1024
|
+
}
|
|
1025
|
+
return value;
|
|
1026
|
+
}
|
|
1027
|
+
const toReactive = (value) => isObject$1(value) ? reactive(value) : value;
|
|
1028
|
+
const toReadonly = (value) => isObject$1(value) ? readonly(value) : value;
|
|
1029
|
+
|
|
1030
|
+
const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
|
|
1031
|
+
class ComputedRefImpl {
|
|
1032
|
+
constructor(getter, _setter, isReadonly, isSSR) {
|
|
1033
|
+
this.getter = getter;
|
|
1034
|
+
this._setter = _setter;
|
|
1035
|
+
this.dep = void 0;
|
|
1036
|
+
this.__v_isRef = true;
|
|
1037
|
+
this["__v_isReadonly"] = false;
|
|
1038
|
+
this.effect = new ReactiveEffect(
|
|
1039
|
+
() => getter(this._value),
|
|
1040
|
+
() => triggerRefValue(
|
|
1041
|
+
this,
|
|
1042
|
+
this.effect._dirtyLevel === 2 ? 2 : 3
|
|
1043
|
+
)
|
|
1044
|
+
);
|
|
1045
|
+
this.effect.computed = this;
|
|
1046
|
+
this.effect.active = this._cacheable = !isSSR;
|
|
1047
|
+
this["__v_isReadonly"] = isReadonly;
|
|
1048
|
+
}
|
|
1049
|
+
get value() {
|
|
1050
|
+
const self = toRaw(this);
|
|
1051
|
+
if ((!self._cacheable || self.effect.dirty) && hasChanged$1(self._value, self._value = self.effect.run())) {
|
|
1052
|
+
triggerRefValue(self, 4);
|
|
1053
|
+
}
|
|
1054
|
+
trackRefValue(self);
|
|
1055
|
+
if (self.effect._dirtyLevel >= 2) {
|
|
1056
|
+
if (this._warnRecursive) {
|
|
1057
|
+
warn(COMPUTED_SIDE_EFFECT_WARN, `
|
|
1058
|
+
|
|
1059
|
+
getter: `, this.getter);
|
|
1060
|
+
}
|
|
1061
|
+
triggerRefValue(self, 2);
|
|
1062
|
+
}
|
|
1063
|
+
return self._value;
|
|
1064
|
+
}
|
|
1065
|
+
set value(newValue) {
|
|
1066
|
+
this._setter(newValue);
|
|
1067
|
+
}
|
|
1068
|
+
// #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
|
|
1069
|
+
get _dirty() {
|
|
1070
|
+
return this.effect.dirty;
|
|
1071
|
+
}
|
|
1072
|
+
set _dirty(v) {
|
|
1073
|
+
this.effect.dirty = v;
|
|
1074
|
+
}
|
|
1075
|
+
// #endregion
|
|
1076
|
+
}
|
|
1077
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1078
|
+
let getter;
|
|
1079
|
+
let setter;
|
|
1080
|
+
const onlyGetter = isFunction$1(getterOrOptions);
|
|
1081
|
+
if (onlyGetter) {
|
|
1082
|
+
getter = getterOrOptions;
|
|
1083
|
+
setter = () => {
|
|
1084
|
+
warn("Write operation failed: computed value is readonly");
|
|
1085
|
+
} ;
|
|
1086
|
+
} else {
|
|
1087
|
+
getter = getterOrOptions.get;
|
|
1088
|
+
setter = getterOrOptions.set;
|
|
1089
|
+
}
|
|
1090
|
+
const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
|
|
1091
|
+
if (debugOptions && !isSSR) {
|
|
1092
|
+
cRef.effect.onTrack = debugOptions.onTrack;
|
|
1093
|
+
cRef.effect.onTrigger = debugOptions.onTrigger;
|
|
1094
|
+
}
|
|
1095
|
+
return cRef;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function trackRefValue(ref2) {
|
|
1099
|
+
var _a;
|
|
1100
|
+
if (shouldTrack && activeEffect) {
|
|
1101
|
+
ref2 = toRaw(ref2);
|
|
1102
|
+
trackEffect(
|
|
1103
|
+
activeEffect,
|
|
1104
|
+
(_a = ref2.dep) != null ? _a : ref2.dep = createDep(
|
|
1105
|
+
() => ref2.dep = void 0,
|
|
1106
|
+
ref2 instanceof ComputedRefImpl ? ref2 : void 0
|
|
1107
|
+
),
|
|
1108
|
+
{
|
|
1109
|
+
target: ref2,
|
|
1110
|
+
type: "get",
|
|
1111
|
+
key: "value"
|
|
1112
|
+
}
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
|
|
1117
|
+
ref2 = toRaw(ref2);
|
|
1118
|
+
const dep = ref2.dep;
|
|
1119
|
+
if (dep) {
|
|
1120
|
+
triggerEffects(
|
|
1121
|
+
dep,
|
|
1122
|
+
dirtyLevel,
|
|
1123
|
+
{
|
|
1124
|
+
target: ref2,
|
|
1125
|
+
type: "set",
|
|
1126
|
+
key: "value",
|
|
1127
|
+
newValue: newVal
|
|
1128
|
+
}
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
function isRef(r) {
|
|
1133
|
+
return !!(r && r.__v_isRef === true);
|
|
1134
|
+
}
|
|
1135
|
+
function ref(value) {
|
|
1136
|
+
return createRef(value, false);
|
|
1137
|
+
}
|
|
1138
|
+
function shallowRef(value) {
|
|
1139
|
+
return createRef(value, true);
|
|
1140
|
+
}
|
|
1141
|
+
function createRef(rawValue, shallow) {
|
|
1142
|
+
if (isRef(rawValue)) {
|
|
1143
|
+
return rawValue;
|
|
1144
|
+
}
|
|
1145
|
+
return new RefImpl(rawValue, shallow);
|
|
1146
|
+
}
|
|
1147
|
+
class RefImpl {
|
|
1148
|
+
constructor(value, __v_isShallow) {
|
|
1149
|
+
this.__v_isShallow = __v_isShallow;
|
|
1150
|
+
this.dep = void 0;
|
|
1151
|
+
this.__v_isRef = true;
|
|
1152
|
+
this._rawValue = __v_isShallow ? value : toRaw(value);
|
|
1153
|
+
this._value = __v_isShallow ? value : toReactive(value);
|
|
1154
|
+
}
|
|
1155
|
+
get value() {
|
|
1156
|
+
trackRefValue(this);
|
|
1157
|
+
return this._value;
|
|
1158
|
+
}
|
|
1159
|
+
set value(newVal) {
|
|
1160
|
+
const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
|
|
1161
|
+
newVal = useDirectValue ? newVal : toRaw(newVal);
|
|
1162
|
+
if (hasChanged$1(newVal, this._rawValue)) {
|
|
1163
|
+
this._rawValue = newVal;
|
|
1164
|
+
this._value = useDirectValue ? newVal : toReactive(newVal);
|
|
1165
|
+
triggerRefValue(this, 4, newVal);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function triggerRef(ref2) {
|
|
1170
|
+
triggerRefValue(ref2, 4, ref2.value );
|
|
1171
|
+
}
|
|
1172
|
+
function unref(ref2) {
|
|
1173
|
+
return isRef(ref2) ? ref2.value : ref2;
|
|
1174
|
+
}
|
|
1175
|
+
function toValue(source) {
|
|
1176
|
+
return isFunction$1(source) ? source() : unref(source);
|
|
1177
|
+
}
|
|
1178
|
+
const shallowUnwrapHandlers = {
|
|
1179
|
+
get: (target, key, receiver) => unref(Reflect.get(target, key, receiver)),
|
|
1180
|
+
set: (target, key, value, receiver) => {
|
|
1181
|
+
const oldValue = target[key];
|
|
1182
|
+
if (isRef(oldValue) && !isRef(value)) {
|
|
1183
|
+
oldValue.value = value;
|
|
1184
|
+
return true;
|
|
1185
|
+
} else {
|
|
1186
|
+
return Reflect.set(target, key, value, receiver);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
function proxyRefs(objectWithRefs) {
|
|
1191
|
+
return isReactive(objectWithRefs) ? objectWithRefs : new Proxy(objectWithRefs, shallowUnwrapHandlers);
|
|
1192
|
+
}
|
|
1193
|
+
class CustomRefImpl {
|
|
1194
|
+
constructor(factory) {
|
|
1195
|
+
this.dep = void 0;
|
|
1196
|
+
this.__v_isRef = true;
|
|
1197
|
+
const { get, set } = factory(
|
|
1198
|
+
() => trackRefValue(this),
|
|
1199
|
+
() => triggerRefValue(this)
|
|
1200
|
+
);
|
|
1201
|
+
this._get = get;
|
|
1202
|
+
this._set = set;
|
|
1203
|
+
}
|
|
1204
|
+
get value() {
|
|
1205
|
+
return this._get();
|
|
1206
|
+
}
|
|
1207
|
+
set value(newVal) {
|
|
1208
|
+
this._set(newVal);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
function customRef(factory) {
|
|
1212
|
+
return new CustomRefImpl(factory);
|
|
1213
|
+
}
|
|
1214
|
+
function toRefs(object) {
|
|
1215
|
+
if (!isProxy(object)) {
|
|
1216
|
+
warn(`toRefs() expects a reactive object but received a plain one.`);
|
|
1217
|
+
}
|
|
1218
|
+
const ret = isArray$1(object) ? new Array(object.length) : {};
|
|
1219
|
+
for (const key in object) {
|
|
1220
|
+
ret[key] = propertyToRef(object, key);
|
|
1221
|
+
}
|
|
1222
|
+
return ret;
|
|
1223
|
+
}
|
|
1224
|
+
class ObjectRefImpl {
|
|
1225
|
+
constructor(_object, _key, _defaultValue) {
|
|
1226
|
+
this._object = _object;
|
|
1227
|
+
this._key = _key;
|
|
1228
|
+
this._defaultValue = _defaultValue;
|
|
1229
|
+
this.__v_isRef = true;
|
|
1230
|
+
}
|
|
1231
|
+
get value() {
|
|
1232
|
+
const val = this._object[this._key];
|
|
1233
|
+
return val === void 0 ? this._defaultValue : val;
|
|
1234
|
+
}
|
|
1235
|
+
set value(newVal) {
|
|
1236
|
+
this._object[this._key] = newVal;
|
|
1237
|
+
}
|
|
1238
|
+
get dep() {
|
|
1239
|
+
return getDepFromReactive(toRaw(this._object), this._key);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
class GetterRefImpl {
|
|
1243
|
+
constructor(_getter) {
|
|
1244
|
+
this._getter = _getter;
|
|
1245
|
+
this.__v_isRef = true;
|
|
1246
|
+
this.__v_isReadonly = true;
|
|
1247
|
+
}
|
|
1248
|
+
get value() {
|
|
1249
|
+
return this._getter();
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
function toRef(source, key, defaultValue) {
|
|
1253
|
+
if (isRef(source)) {
|
|
1254
|
+
return source;
|
|
1255
|
+
} else if (isFunction$1(source)) {
|
|
1256
|
+
return new GetterRefImpl(source);
|
|
1257
|
+
} else if (isObject$1(source) && arguments.length > 1) {
|
|
1258
|
+
return propertyToRef(source, key, defaultValue);
|
|
1259
|
+
} else {
|
|
1260
|
+
return ref(source);
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
function propertyToRef(source, key, defaultValue) {
|
|
1264
|
+
const val = source[key];
|
|
1265
|
+
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
const TrackOpTypes = {
|
|
1269
|
+
"GET": "get",
|
|
1270
|
+
"HAS": "has",
|
|
1271
|
+
"ITERATE": "iterate"
|
|
1272
|
+
};
|
|
1273
|
+
const TriggerOpTypes = {
|
|
1274
|
+
"SET": "set",
|
|
1275
|
+
"ADD": "add",
|
|
1276
|
+
"DELETE": "delete",
|
|
1277
|
+
"CLEAR": "clear"
|
|
1278
|
+
};
|
|
1279
|
+
const ReactiveFlags = {
|
|
1280
|
+
"SKIP": "__v_skip",
|
|
1281
|
+
"IS_REACTIVE": "__v_isReactive",
|
|
1282
|
+
"IS_READONLY": "__v_isReadonly",
|
|
1283
|
+
"IS_SHALLOW": "__v_isShallow",
|
|
1284
|
+
"RAW": "__v_raw"
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1288
|
+
const NOOP = () => { };
|
|
1289
|
+
const { isArray } = Array;
|
|
1290
|
+
const extend = Object.assign;
|
|
1291
|
+
function exclude(obj, keys) {
|
|
1292
|
+
const ret = {};
|
|
1293
|
+
Object.keys(obj).forEach((key) => {
|
|
1294
|
+
if (!keys.includes(key)) {
|
|
1295
|
+
ret[key] = obj[key];
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
return ret;
|
|
1299
|
+
}
|
|
1300
|
+
function getType(x) {
|
|
1301
|
+
return Object.prototype.toString.call(x).slice(8, -1);
|
|
1302
|
+
}
|
|
1303
|
+
function isSimpleValue(x) {
|
|
1304
|
+
const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
|
|
1305
|
+
return x === null || simpleTypes.has(typeof x);
|
|
1306
|
+
}
|
|
1307
|
+
function isObject(x) {
|
|
1308
|
+
return x !== null && typeof x === 'object';
|
|
1309
|
+
}
|
|
1310
|
+
function isPlainObject(x) {
|
|
1311
|
+
return getType(x) === 'Object';
|
|
1312
|
+
}
|
|
1313
|
+
function isFunction(x) {
|
|
1314
|
+
return typeof x === 'function';
|
|
1315
|
+
}
|
|
1316
|
+
function isMap(x) {
|
|
1317
|
+
return getType(x) === 'Map';
|
|
1318
|
+
}
|
|
1319
|
+
function isSet(x) {
|
|
1320
|
+
return getType(x) === 'Set';
|
|
1321
|
+
}
|
|
1322
|
+
// Compare whether a value has changed, accounting for NaN.
|
|
1323
|
+
function hasChanged(value, oldValue) {
|
|
1324
|
+
// eslint-disable-next-line no-self-compare
|
|
1325
|
+
return value !== oldValue && (value === value || oldValue === oldValue);
|
|
1326
|
+
}
|
|
1327
|
+
function remove(arr, el) {
|
|
1328
|
+
const i = arr.indexOf(el);
|
|
1329
|
+
if (i > -1) {
|
|
1330
|
+
arr.splice(i, 1);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
function toHiddenField(name) {
|
|
1334
|
+
return `__${name}__`;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
let isFlushing = false;
|
|
1338
|
+
let isFlushPending = false;
|
|
1339
|
+
const queue = [];
|
|
1340
|
+
let flushIndex = 0;
|
|
1341
|
+
const pendingPostFlushCbs = [];
|
|
1342
|
+
let activePostFlushCbs = null;
|
|
1343
|
+
let postFlushIndex = 0;
|
|
1344
|
+
// eslint-disable-next-line spaced-comment
|
|
1345
|
+
const resolvedPromise = /*#__PURE__*/ Promise.resolve();
|
|
1346
|
+
let currentFlushPromise = null;
|
|
1347
|
+
const RECURSION_LIMIT = 100;
|
|
1348
|
+
function nextTick(fn) {
|
|
1349
|
+
const p = currentFlushPromise || resolvedPromise;
|
|
1350
|
+
return fn ? p.then(fn) : p;
|
|
1351
|
+
}
|
|
1352
|
+
function queueJob(job) {
|
|
1353
|
+
// The dedupe search uses the startIndex argument of Array.includes()
|
|
1354
|
+
// by default the search index includes the current job that is being run
|
|
1355
|
+
// so it cannot recursively trigger itself again.
|
|
1356
|
+
// if the job is a watch() callback, the search will start with a +1 index to
|
|
1357
|
+
// allow it recursively trigger itself - it is the user's responsibility to
|
|
1358
|
+
// ensure it doesn't end up in an infinite loop.
|
|
1359
|
+
if (queue.length === 0 ||
|
|
1360
|
+
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
|
|
1361
|
+
queue.push(job);
|
|
1362
|
+
queueFlush();
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
function queueFlush() {
|
|
1366
|
+
if (!isFlushing && !isFlushPending) {
|
|
1367
|
+
isFlushPending = true;
|
|
1368
|
+
currentFlushPromise = resolvedPromise.then(flushJobs);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
function queuePostFlushCb(cb) {
|
|
1372
|
+
if (!activePostFlushCbs ||
|
|
1373
|
+
!activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
|
|
1374
|
+
pendingPostFlushCbs.push(cb);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
function flushPostFlushCbs() {
|
|
1378
|
+
if (pendingPostFlushCbs.length > 0) {
|
|
1379
|
+
activePostFlushCbs = [...new Set(pendingPostFlushCbs)];
|
|
1380
|
+
pendingPostFlushCbs.length = 0;
|
|
1381
|
+
for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
|
|
1382
|
+
activePostFlushCbs[postFlushIndex]();
|
|
1383
|
+
}
|
|
1384
|
+
activePostFlushCbs = null;
|
|
1385
|
+
postFlushIndex = 0;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
function flushJobs(seen) {
|
|
1389
|
+
isFlushPending = false;
|
|
1390
|
+
isFlushing = true;
|
|
1391
|
+
/* istanbul ignore else -- @preserve */
|
|
1392
|
+
{
|
|
1393
|
+
seen = seen || new Map();
|
|
1394
|
+
}
|
|
1395
|
+
// Conditional usage of checkRecursiveUpdate must be determined out of
|
|
1396
|
+
// try ... catch block since Rollup by default de-optimizes treeshaking
|
|
1397
|
+
// inside try-catch. This can leave all warning code unshaked. Although
|
|
1398
|
+
// they would get eventually shaken by a minifier like terser, some minifiers
|
|
1399
|
+
// would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
|
|
1400
|
+
const check = (job) => checkRecursiveUpdates(seen, job)
|
|
1401
|
+
;
|
|
1402
|
+
try {
|
|
1403
|
+
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
|
1404
|
+
const job = queue[flushIndex];
|
|
1405
|
+
if (job.active !== false) {
|
|
1406
|
+
/* istanbul ignore if -- @preserve */
|
|
1407
|
+
if (true && check(job)) {
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
job();
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
finally {
|
|
1415
|
+
flushIndex = 0;
|
|
1416
|
+
queue.length = 0;
|
|
1417
|
+
isFlushing = false;
|
|
1418
|
+
currentFlushPromise = null;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
function checkRecursiveUpdates(seen, fn) {
|
|
1422
|
+
const count = seen.get(fn) || 0;
|
|
1423
|
+
/* istanbul ignore if -- @preserve */
|
|
1424
|
+
if (count > RECURSION_LIMIT) {
|
|
1425
|
+
console.warn(`Maximum recursive updates exceeded. ` +
|
|
1426
|
+
`This means you have a reactive effect that is mutating its own ` +
|
|
1427
|
+
`dependencies and thus recursively triggering itself.`);
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
seen.set(fn, count + 1);
|
|
1431
|
+
return false;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// Simple effect.
|
|
1435
|
+
function watchEffect(effect, options) {
|
|
1436
|
+
return doWatch(effect, null, options);
|
|
1437
|
+
}
|
|
1438
|
+
function watchPostEffect(effect, options) {
|
|
1439
|
+
return doWatch(effect, null, extend({}, options, { flush: 'post' })
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
function watchSyncEffect(effect, options) {
|
|
1443
|
+
return doWatch(effect, null, extend({}, options, { flush: 'sync' })
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
// Initial value for watchers to trigger on undefined initial values
|
|
1447
|
+
const INITIAL_WATCHER_VALUE = {};
|
|
1448
|
+
// Implementation
|
|
1449
|
+
function watch(source, cb, options) {
|
|
1450
|
+
if (!isFunction(cb)) {
|
|
1451
|
+
console.warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
|
1452
|
+
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
|
|
1453
|
+
`supports \`watch(source, cb, options?) signature.`);
|
|
1454
|
+
}
|
|
1455
|
+
return doWatch(source, cb, options);
|
|
1456
|
+
}
|
|
1457
|
+
// eslint-disable-next-line complexity
|
|
1458
|
+
function doWatch(source, cb, { immediate, deep, flush, once, onTrack, onTrigger } = {}) {
|
|
1459
|
+
if (cb && once) {
|
|
1460
|
+
const _cb = cb;
|
|
1461
|
+
cb = (...args) => {
|
|
1462
|
+
_cb(...args);
|
|
1463
|
+
unwatch();
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
if (deep !== undefined && typeof deep === 'number') {
|
|
1467
|
+
console.warn(`watch() "deep" option with number value will be used as watch depth in future versions. ` +
|
|
1468
|
+
`Please use a boolean instead to avoid potential breakage.`);
|
|
1469
|
+
}
|
|
1470
|
+
if (!cb) {
|
|
1471
|
+
if (immediate !== undefined) {
|
|
1472
|
+
console.warn(`watch() "immediate" option is only respected when using the ` +
|
|
1473
|
+
`watch(source, callback, options?) signature.`);
|
|
1474
|
+
}
|
|
1475
|
+
if (deep !== undefined) {
|
|
1476
|
+
console.warn(`watch() "deep" option is only respected when using the ` +
|
|
1477
|
+
`watch(source, callback, options?) signature.`);
|
|
1478
|
+
}
|
|
1479
|
+
if (once !== undefined) {
|
|
1480
|
+
console.warn(`watch() "once" option is only respected when using the ` +
|
|
1481
|
+
`watch(source, callback, options?) signature.`);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
const warnInvalidSource = (s) => {
|
|
1485
|
+
console.warn(`Invalid watch source:`, s, `A watch source can only be a getter/effect function, a ref, ` +
|
|
1486
|
+
`a reactive object, or an array of these types.`);
|
|
1487
|
+
};
|
|
1488
|
+
const reactiveGetter = (source) => deep === true ?
|
|
1489
|
+
source // Traverse will happen in wrapped getter below
|
|
1490
|
+
// For deep: false, only traverse root-level properties
|
|
1491
|
+
: traverse(source, deep === false ? 1 : undefined);
|
|
1492
|
+
let getter;
|
|
1493
|
+
let forceTrigger = false;
|
|
1494
|
+
let isMultiSource = false;
|
|
1495
|
+
if (isRef(source)) {
|
|
1496
|
+
getter = () => source.value;
|
|
1497
|
+
forceTrigger = isShallow(source);
|
|
1498
|
+
}
|
|
1499
|
+
else if (isReactive(source)) {
|
|
1500
|
+
getter = () => reactiveGetter(source);
|
|
1501
|
+
forceTrigger = true;
|
|
1502
|
+
}
|
|
1503
|
+
else if (isArray(source)) {
|
|
1504
|
+
isMultiSource = true;
|
|
1505
|
+
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
1506
|
+
getter = () => source.map((s) => {
|
|
1507
|
+
if (isRef(s)) {
|
|
1508
|
+
return s.value;
|
|
1509
|
+
}
|
|
1510
|
+
if (isReactive(s)) {
|
|
1511
|
+
return reactiveGetter(s);
|
|
1512
|
+
}
|
|
1513
|
+
if (isFunction(s)) {
|
|
1514
|
+
return s();
|
|
1515
|
+
}
|
|
1516
|
+
/* istanbul ignore else -- @preserve */
|
|
1517
|
+
{
|
|
1518
|
+
warnInvalidSource(s);
|
|
1519
|
+
}
|
|
1520
|
+
return undefined;
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
else if (isFunction(source)) {
|
|
1524
|
+
if (cb) {
|
|
1525
|
+
// Getter with cb
|
|
1526
|
+
getter = () => source();
|
|
1527
|
+
}
|
|
1528
|
+
else {
|
|
1529
|
+
// No cb -> simple effect
|
|
1530
|
+
getter = () => {
|
|
1531
|
+
if (cleanup) {
|
|
1532
|
+
cleanup();
|
|
1533
|
+
}
|
|
1534
|
+
return source(onCleanup);
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
getter = NOOP;
|
|
1540
|
+
/* istanbul ignore else -- @preserve */
|
|
1541
|
+
{
|
|
1542
|
+
warnInvalidSource(source);
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (cb && deep) {
|
|
1546
|
+
const baseGetter = getter;
|
|
1547
|
+
getter = () => traverse(baseGetter());
|
|
1548
|
+
}
|
|
1549
|
+
let cleanup;
|
|
1550
|
+
const onCleanup = (fn) => {
|
|
1551
|
+
// eslint-disable-next-line no-multi-assign
|
|
1552
|
+
cleanup = effect.onStop = () => {
|
|
1553
|
+
fn();
|
|
1554
|
+
// eslint-disable-next-line no-multi-assign
|
|
1555
|
+
cleanup = effect.onStop = undefined;
|
|
1556
|
+
};
|
|
1557
|
+
};
|
|
1558
|
+
let oldValue = isMultiSource ?
|
|
1559
|
+
Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE)
|
|
1560
|
+
: INITIAL_WATCHER_VALUE;
|
|
1561
|
+
const job = () => {
|
|
1562
|
+
if (!effect.active || !effect.dirty) {
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
if (cb) {
|
|
1566
|
+
// Watch(source, cb)
|
|
1567
|
+
const newValue = effect.run();
|
|
1568
|
+
if (deep ||
|
|
1569
|
+
forceTrigger ||
|
|
1570
|
+
(isMultiSource ?
|
|
1571
|
+
newValue.some((v, i) => hasChanged(v, oldValue[i]))
|
|
1572
|
+
: hasChanged(newValue, oldValue))) {
|
|
1573
|
+
// Cleanup before running cb again
|
|
1574
|
+
if (cleanup) {
|
|
1575
|
+
cleanup();
|
|
1576
|
+
}
|
|
1577
|
+
cb(newValue,
|
|
1578
|
+
// Pass undefined as the old value when it's changed for the first time
|
|
1579
|
+
oldValue === INITIAL_WATCHER_VALUE ? undefined
|
|
1580
|
+
: isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? []
|
|
1581
|
+
: oldValue, onCleanup);
|
|
1582
|
+
oldValue = newValue;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
else {
|
|
1586
|
+
// WatchEffect
|
|
1587
|
+
effect.run();
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
// Important: mark the job as a watcher callback so that scheduler knows
|
|
1591
|
+
// it is allowed to self-trigger
|
|
1592
|
+
job.allowRecurse = Boolean(cb);
|
|
1593
|
+
let scheduler;
|
|
1594
|
+
if (flush === 'sync') {
|
|
1595
|
+
scheduler = job; // The scheduler function gets called directly
|
|
1596
|
+
}
|
|
1597
|
+
else if (flush === 'post') {
|
|
1598
|
+
scheduler = () => {
|
|
1599
|
+
queuePostFlushCb(job);
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
else {
|
|
1603
|
+
scheduler = () => {
|
|
1604
|
+
queueJob(job);
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
const effect = new ReactiveEffect(getter, NOOP, scheduler);
|
|
1608
|
+
const scope = getCurrentScope();
|
|
1609
|
+
const unwatch = () => {
|
|
1610
|
+
effect.stop();
|
|
1611
|
+
if (scope) {
|
|
1612
|
+
// @ts-expect-error
|
|
1613
|
+
remove(scope.effects, effect);
|
|
1614
|
+
}
|
|
1615
|
+
};
|
|
1616
|
+
/* istanbul ignore else -- @preserve */
|
|
1617
|
+
{
|
|
1618
|
+
effect.onTrack = onTrack;
|
|
1619
|
+
effect.onTrigger = onTrigger;
|
|
1620
|
+
}
|
|
1621
|
+
// Initial run
|
|
1622
|
+
if (cb) {
|
|
1623
|
+
if (immediate) {
|
|
1624
|
+
job();
|
|
1625
|
+
}
|
|
1626
|
+
else {
|
|
1627
|
+
oldValue = effect.run();
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
effect.run();
|
|
1632
|
+
}
|
|
1633
|
+
return unwatch;
|
|
1634
|
+
}
|
|
1635
|
+
function traverse(value, depth = Number.POSITIVE_INFINITY, seen) {
|
|
1636
|
+
if (depth <= 0 || !isObject(value) || value[ReactiveFlags.SKIP]) {
|
|
1637
|
+
return value;
|
|
1638
|
+
}
|
|
1639
|
+
seen = seen || new Set();
|
|
1640
|
+
if (seen.has(value)) {
|
|
1641
|
+
return value;
|
|
1642
|
+
}
|
|
1643
|
+
seen.add(value);
|
|
1644
|
+
depth--;
|
|
1645
|
+
/* istanbul ignore else -- @preserve */
|
|
1646
|
+
if (isRef(value)) {
|
|
1647
|
+
traverse(value.value, depth, seen);
|
|
1648
|
+
}
|
|
1649
|
+
else if (isArray(value)) {
|
|
1650
|
+
for (let i = 0; i < value.length; i++) {
|
|
1651
|
+
traverse(value[i], depth, seen);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
else if (isSet(value) || isMap(value)) {
|
|
1655
|
+
value.forEach((v) => {
|
|
1656
|
+
traverse(v, depth, seen);
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
else if (isPlainObject(value)) {
|
|
1660
|
+
// eslint-disable-next-line guard-for-in
|
|
1661
|
+
for (const key in value) {
|
|
1662
|
+
traverse(value[key], depth, seen);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
return value;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
const provides = Object.create(null);
|
|
1669
|
+
function provide(key, value) {
|
|
1670
|
+
// TS doesn't allow symbol as index type
|
|
1671
|
+
provides[key] = value;
|
|
1672
|
+
}
|
|
1673
|
+
function inject(key, defaultValue, treatDefaultAsFactory = false) {
|
|
1674
|
+
if (key in provides) {
|
|
1675
|
+
// TS doesn't allow symbol as index type
|
|
1676
|
+
return provides[key];
|
|
1677
|
+
}
|
|
1678
|
+
if (arguments.length > 1) {
|
|
1679
|
+
return treatDefaultAsFactory && isFunction(defaultValue) ? defaultValue()
|
|
1680
|
+
: defaultValue;
|
|
1681
|
+
}
|
|
1682
|
+
/* istanbul ignore else -- @preserve */
|
|
1683
|
+
{
|
|
1684
|
+
console.warn(`injection "${String(key)}" not found.`);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
let currentApp = null;
|
|
1689
|
+
let currentPage = null;
|
|
1690
|
+
let currentComponent = null;
|
|
1691
|
+
function getCurrentInstance() {
|
|
1692
|
+
return currentPage || currentComponent;
|
|
1693
|
+
}
|
|
1694
|
+
function setCurrentApp(page) {
|
|
1695
|
+
currentApp = page;
|
|
1696
|
+
}
|
|
1697
|
+
function unsetCurrentApp() {
|
|
1698
|
+
currentApp = null;
|
|
1699
|
+
}
|
|
1700
|
+
function setCurrentPage(page) {
|
|
1701
|
+
currentPage = page;
|
|
1702
|
+
// @ts-expect-error
|
|
1703
|
+
page.__scope__.on();
|
|
1704
|
+
}
|
|
1705
|
+
function unsetCurrentPage() {
|
|
1706
|
+
/* istanbul ignore else -- @preserve */
|
|
1707
|
+
if (currentPage) {
|
|
1708
|
+
// @ts-expect-error
|
|
1709
|
+
currentPage.__scope__.off();
|
|
1710
|
+
}
|
|
1711
|
+
currentPage = null;
|
|
1712
|
+
}
|
|
1713
|
+
function setCurrentComponent(component) {
|
|
1714
|
+
currentComponent = component;
|
|
1715
|
+
// @ts-expect-error
|
|
1716
|
+
component.__scope__.on();
|
|
1717
|
+
}
|
|
1718
|
+
function unsetCurrentComponent() {
|
|
1719
|
+
/* istanbul ignore else -- @preserve */
|
|
1720
|
+
if (currentComponent) {
|
|
1721
|
+
// @ts-expect-error
|
|
1722
|
+
currentComponent.__scope__.off();
|
|
1723
|
+
}
|
|
1724
|
+
currentComponent = null;
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
var AppLifecycle;
|
|
1728
|
+
(function (AppLifecycle) {
|
|
1729
|
+
AppLifecycle["ON_LAUNCH"] = "onLaunch";
|
|
1730
|
+
AppLifecycle["ON_SHOW"] = "onShow";
|
|
1731
|
+
AppLifecycle["ON_HIDE"] = "onHide";
|
|
1732
|
+
AppLifecycle["ON_ERROR"] = "onError";
|
|
1733
|
+
AppLifecycle["ON_PAGE_NOT_FOUND"] = "onPageNotFound";
|
|
1734
|
+
AppLifecycle["ON_UNHANDLED_REJECTION"] = "onUnhandledRejection";
|
|
1735
|
+
AppLifecycle["ON_THEME_CHANGE"] = "onThemeChange";
|
|
1736
|
+
})(AppLifecycle || (AppLifecycle = {}));
|
|
1737
|
+
function createApp(optionsOrSetup) {
|
|
1738
|
+
let setup;
|
|
1739
|
+
let options;
|
|
1740
|
+
if (isFunction(optionsOrSetup)) {
|
|
1741
|
+
setup = optionsOrSetup;
|
|
1742
|
+
options = {};
|
|
1743
|
+
}
|
|
1744
|
+
else {
|
|
1745
|
+
if (optionsOrSetup.setup === undefined) {
|
|
1746
|
+
// eslint-disable-next-line new-cap
|
|
1747
|
+
App(optionsOrSetup);
|
|
1748
|
+
return;
|
|
1749
|
+
}
|
|
1750
|
+
setup = optionsOrSetup.setup;
|
|
1751
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
1752
|
+
}
|
|
1753
|
+
const originOnLaunch = options[AppLifecycle.ON_LAUNCH];
|
|
1754
|
+
options[AppLifecycle.ON_LAUNCH] = function (options) {
|
|
1755
|
+
setCurrentApp(this);
|
|
1756
|
+
const bindings = setup(options);
|
|
1757
|
+
if (bindings !== undefined) {
|
|
1758
|
+
Object.keys(bindings).forEach((key) => {
|
|
1759
|
+
this[key] = bindings[key];
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
unsetCurrentApp();
|
|
1763
|
+
if (originOnLaunch !== undefined) {
|
|
1764
|
+
originOnLaunch.call(this, options);
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
options[AppLifecycle.ON_SHOW] = createLifecycle$2(options, AppLifecycle.ON_SHOW);
|
|
1768
|
+
options[AppLifecycle.ON_HIDE] = createLifecycle$2(options, AppLifecycle.ON_HIDE);
|
|
1769
|
+
options[AppLifecycle.ON_ERROR] = createLifecycle$2(options, AppLifecycle.ON_ERROR);
|
|
1770
|
+
options[AppLifecycle.ON_PAGE_NOT_FOUND] = createLifecycle$2(options, AppLifecycle.ON_PAGE_NOT_FOUND);
|
|
1771
|
+
options[AppLifecycle.ON_UNHANDLED_REJECTION] = createLifecycle$2(options, AppLifecycle.ON_UNHANDLED_REJECTION);
|
|
1772
|
+
options[AppLifecycle.ON_THEME_CHANGE] = createLifecycle$2(options, AppLifecycle.ON_THEME_CHANGE);
|
|
1773
|
+
// eslint-disable-next-line new-cap
|
|
1774
|
+
App(options);
|
|
1775
|
+
}
|
|
1776
|
+
function createLifecycle$2(options, lifecycle) {
|
|
1777
|
+
const originLifecycle = options[lifecycle];
|
|
1778
|
+
return function (...args) {
|
|
1779
|
+
const hooks = this[toHiddenField(lifecycle)];
|
|
1780
|
+
if (hooks) {
|
|
1781
|
+
hooks.forEach((hook) => hook(...args));
|
|
1782
|
+
}
|
|
1783
|
+
if (originLifecycle !== undefined) {
|
|
1784
|
+
originLifecycle.call(this, ...args);
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
function deepToRaw(x) {
|
|
1790
|
+
if (isSimpleValue(x) || isFunction(x)) {
|
|
1791
|
+
return x;
|
|
1792
|
+
}
|
|
1793
|
+
if (isRef(x)) {
|
|
1794
|
+
return deepToRaw(x.value);
|
|
1795
|
+
}
|
|
1796
|
+
if (isProxy(x)) {
|
|
1797
|
+
return deepToRaw(toRaw(x));
|
|
1798
|
+
}
|
|
1799
|
+
if (isArray(x)) {
|
|
1800
|
+
return x.map((item) => deepToRaw(item));
|
|
1801
|
+
}
|
|
1802
|
+
if (isPlainObject(x)) {
|
|
1803
|
+
const obj = {};
|
|
1804
|
+
Object.keys(x).forEach((key) => {
|
|
1805
|
+
obj[key] = deepToRaw(x[key]);
|
|
1806
|
+
});
|
|
1807
|
+
return obj;
|
|
1808
|
+
}
|
|
1809
|
+
throw new TypeError(`${getType(x)} value is not supported`);
|
|
1810
|
+
}
|
|
1811
|
+
function deepWatch(key, value) {
|
|
1812
|
+
if (!isObject(value)) {
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
watch(isRef(value) ? value : () => value, () => {
|
|
1816
|
+
this.setData({ [key]: deepToRaw(value) }, flushPostFlushCbs);
|
|
1817
|
+
}, {
|
|
1818
|
+
deep: true,
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
var PageLifecycle;
|
|
1823
|
+
(function (PageLifecycle) {
|
|
1824
|
+
PageLifecycle["ON_LOAD"] = "onLoad";
|
|
1825
|
+
PageLifecycle["ON_SHOW"] = "onShow";
|
|
1826
|
+
PageLifecycle["ON_READY"] = "onReady";
|
|
1827
|
+
PageLifecycle["ON_HIDE"] = "onHide";
|
|
1828
|
+
PageLifecycle["ON_UNLOAD"] = "onUnload";
|
|
1829
|
+
PageLifecycle["ON_ROUTE_DONE"] = "onRouteDone";
|
|
1830
|
+
PageLifecycle["ON_PULL_DOWN_REFRESH"] = "onPullDownRefresh";
|
|
1831
|
+
PageLifecycle["ON_REACH_BOTTOM"] = "onReachBottom";
|
|
1832
|
+
PageLifecycle["ON_PAGE_SCROLL"] = "onPageScroll";
|
|
1833
|
+
PageLifecycle["ON_SHARE_APP_MESSAGE"] = "onShareAppMessage";
|
|
1834
|
+
PageLifecycle["ON_SHARE_TIMELINE"] = "onShareTimeline";
|
|
1835
|
+
PageLifecycle["ON_ADD_TO_FAVORITES"] = "onAddToFavorites";
|
|
1836
|
+
PageLifecycle["ON_RESIZE"] = "onResize";
|
|
1837
|
+
PageLifecycle["ON_TAB_ITEM_TAP"] = "onTabItemTap";
|
|
1838
|
+
PageLifecycle["ON_SAVE_EXIT_STATE"] = "onSaveExitState";
|
|
1839
|
+
})(PageLifecycle || (PageLifecycle = {}));
|
|
1840
|
+
function definePage(optionsOrSetup, config) {
|
|
1841
|
+
config = extend({
|
|
1842
|
+
listenPageScroll: false,
|
|
1843
|
+
canShareToOthers: false,
|
|
1844
|
+
canShareToTimeline: false,
|
|
1845
|
+
}, config);
|
|
1846
|
+
let setup;
|
|
1847
|
+
let options;
|
|
1848
|
+
if (isFunction(optionsOrSetup)) {
|
|
1849
|
+
setup = optionsOrSetup;
|
|
1850
|
+
options = {};
|
|
1851
|
+
}
|
|
1852
|
+
else {
|
|
1853
|
+
if (optionsOrSetup.setup === undefined) {
|
|
1854
|
+
// eslint-disable-next-line new-cap
|
|
1855
|
+
Page(optionsOrSetup);
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
setup = optionsOrSetup.setup;
|
|
1859
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
1860
|
+
}
|
|
1861
|
+
const originOnLoad = options[PageLifecycle.ON_LOAD];
|
|
1862
|
+
options[PageLifecycle.ON_LOAD] = function (query) {
|
|
1863
|
+
this.__scope__ = new EffectScope();
|
|
1864
|
+
setCurrentPage(this);
|
|
1865
|
+
const context = {
|
|
1866
|
+
is: this.is,
|
|
1867
|
+
route: this.route,
|
|
1868
|
+
options: this.options,
|
|
1869
|
+
exitState: this.exitState,
|
|
1870
|
+
router: this.router,
|
|
1871
|
+
pageRouter: this.pageRouter,
|
|
1872
|
+
renderer: this.renderer,
|
|
1873
|
+
createSelectorQuery: this.createSelectorQuery.bind(this),
|
|
1874
|
+
createIntersectionObserver: this.createIntersectionObserver.bind(this),
|
|
1875
|
+
createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
|
|
1876
|
+
selectComponent: this.selectComponent.bind(this),
|
|
1877
|
+
selectAllComponents: this.selectAllComponents.bind(this),
|
|
1878
|
+
getTabBar: this.getTabBar.bind(this),
|
|
1879
|
+
getPageId: this.getPageId.bind(this),
|
|
1880
|
+
animate: this.animate.bind(this),
|
|
1881
|
+
clearAnimation: this.clearAnimation.bind(this),
|
|
1882
|
+
getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
|
|
1883
|
+
applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
|
|
1884
|
+
clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
|
|
1885
|
+
setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
|
|
1886
|
+
getPassiveEvent: this.getPassiveEvent.bind(this),
|
|
1887
|
+
setPassiveEvent: this.setPassiveEvent.bind(this),
|
|
1888
|
+
};
|
|
1889
|
+
const bindings = setup(query, context);
|
|
1890
|
+
if (bindings !== undefined) {
|
|
1891
|
+
Object.keys(bindings).forEach((key) => {
|
|
1892
|
+
const value = bindings[key];
|
|
1893
|
+
if (isFunction(value)) {
|
|
1894
|
+
this[key] = value;
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
this.setData({ [key]: deepToRaw(value) });
|
|
1898
|
+
deepWatch.call(this, key, value);
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
unsetCurrentPage();
|
|
1902
|
+
if (originOnLoad !== undefined) {
|
|
1903
|
+
originOnLoad.call(this, query);
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
const onUnload = createLifecycle$1(options, PageLifecycle.ON_UNLOAD);
|
|
1907
|
+
options[PageLifecycle.ON_UNLOAD] = function () {
|
|
1908
|
+
onUnload.call(this);
|
|
1909
|
+
this.__scope__.stop();
|
|
1910
|
+
};
|
|
1911
|
+
if (options[PageLifecycle.ON_PAGE_SCROLL] || config.listenPageScroll) {
|
|
1912
|
+
options[PageLifecycle.ON_PAGE_SCROLL] = createLifecycle$1(options, PageLifecycle.ON_PAGE_SCROLL);
|
|
1913
|
+
/* istanbul ignore next -- @preserve */
|
|
1914
|
+
options.__listenPageScroll__ = () => true;
|
|
1915
|
+
}
|
|
1916
|
+
if (options[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
|
|
1917
|
+
config.canShareToOthers) {
|
|
1918
|
+
options[PageLifecycle.ON_SHARE_APP_MESSAGE] = function (share) {
|
|
1919
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE)];
|
|
1920
|
+
if (hook) {
|
|
1921
|
+
return hook(share);
|
|
1922
|
+
}
|
|
1923
|
+
return {};
|
|
1924
|
+
};
|
|
1925
|
+
/* istanbul ignore next -- @preserve */
|
|
1926
|
+
options.__isInjectedShareToOthersHook__ = () => true;
|
|
1927
|
+
}
|
|
1928
|
+
if (options[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
|
|
1929
|
+
config.canShareToTimeline) {
|
|
1930
|
+
options[PageLifecycle.ON_SHARE_TIMELINE] = function () {
|
|
1931
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_TIMELINE)];
|
|
1932
|
+
if (hook) {
|
|
1933
|
+
return hook();
|
|
1934
|
+
}
|
|
1935
|
+
return {};
|
|
1936
|
+
};
|
|
1937
|
+
/* istanbul ignore next -- @preserve */
|
|
1938
|
+
options.__isInjectedShareToTimelineHook__ = () => true;
|
|
1939
|
+
}
|
|
1940
|
+
if (options[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
|
|
1941
|
+
options[PageLifecycle.ON_ADD_TO_FAVORITES] = function (favorites) {
|
|
1942
|
+
const hook = this[toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES)];
|
|
1943
|
+
if (hook) {
|
|
1944
|
+
return hook(favorites);
|
|
1945
|
+
}
|
|
1946
|
+
return {};
|
|
1947
|
+
};
|
|
1948
|
+
/* istanbul ignore next -- @preserve */
|
|
1949
|
+
options.__isInjectedFavoritesHook__ = () => true;
|
|
1950
|
+
}
|
|
1951
|
+
if (options[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
|
|
1952
|
+
options[PageLifecycle.ON_SAVE_EXIT_STATE] = function () {
|
|
1953
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE)];
|
|
1954
|
+
if (hook) {
|
|
1955
|
+
return hook();
|
|
1956
|
+
}
|
|
1957
|
+
return { data: undefined };
|
|
1958
|
+
};
|
|
1959
|
+
/* istanbul ignore next -- @preserve */
|
|
1960
|
+
options.__isInjectedExitStateHook__ = () => true;
|
|
1961
|
+
}
|
|
1962
|
+
options[PageLifecycle.ON_SHOW] = createLifecycle$1(options, PageLifecycle.ON_SHOW);
|
|
1963
|
+
options[PageLifecycle.ON_READY] = createLifecycle$1(options, PageLifecycle.ON_READY);
|
|
1964
|
+
options[PageLifecycle.ON_HIDE] = createLifecycle$1(options, PageLifecycle.ON_HIDE);
|
|
1965
|
+
options[PageLifecycle.ON_ROUTE_DONE] = createLifecycle$1(options, PageLifecycle.ON_ROUTE_DONE);
|
|
1966
|
+
options[PageLifecycle.ON_PULL_DOWN_REFRESH] = createLifecycle$1(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
1967
|
+
options[PageLifecycle.ON_REACH_BOTTOM] = createLifecycle$1(options, PageLifecycle.ON_REACH_BOTTOM);
|
|
1968
|
+
options[PageLifecycle.ON_RESIZE] = createLifecycle$1(options, PageLifecycle.ON_RESIZE);
|
|
1969
|
+
options[PageLifecycle.ON_TAB_ITEM_TAP] = createLifecycle$1(options, PageLifecycle.ON_TAB_ITEM_TAP);
|
|
1970
|
+
// eslint-disable-next-line new-cap
|
|
1971
|
+
Page(options);
|
|
1972
|
+
}
|
|
1973
|
+
function createLifecycle$1(options, lifecycle) {
|
|
1974
|
+
const originLifecycle = options[lifecycle];
|
|
1975
|
+
return function (...args) {
|
|
1976
|
+
const hooks = this[toHiddenField(lifecycle)];
|
|
1977
|
+
if (hooks) {
|
|
1978
|
+
hooks.forEach((hook) => hook(...args));
|
|
1979
|
+
}
|
|
1980
|
+
if (originLifecycle !== undefined) {
|
|
1981
|
+
originLifecycle.call(this, ...args);
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
var ComponentLifecycle;
|
|
1987
|
+
(function (ComponentLifecycle) {
|
|
1988
|
+
ComponentLifecycle["ATTACHED"] = "attached";
|
|
1989
|
+
ComponentLifecycle["READY"] = "ready";
|
|
1990
|
+
ComponentLifecycle["MOVED"] = "moved";
|
|
1991
|
+
ComponentLifecycle["DETACHED"] = "detached";
|
|
1992
|
+
ComponentLifecycle["ERROR"] = "error";
|
|
1993
|
+
})(ComponentLifecycle || (ComponentLifecycle = {}));
|
|
1994
|
+
const SpecialLifecycleMap = {
|
|
1995
|
+
[PageLifecycle.ON_SHOW]: 'show',
|
|
1996
|
+
[PageLifecycle.ON_HIDE]: 'hide',
|
|
1997
|
+
[PageLifecycle.ON_RESIZE]: 'resize',
|
|
1998
|
+
[PageLifecycle.ON_ROUTE_DONE]: 'routeDone',
|
|
1999
|
+
[ComponentLifecycle.READY]: PageLifecycle.ON_READY,
|
|
2000
|
+
};
|
|
2001
|
+
function defineComponent(optionsOrSetup, config) {
|
|
2002
|
+
config = extend({
|
|
2003
|
+
listenPageScroll: false,
|
|
2004
|
+
canShareToOthers: false,
|
|
2005
|
+
canShareToTimeline: false,
|
|
2006
|
+
}, config);
|
|
2007
|
+
let setup;
|
|
2008
|
+
let options;
|
|
2009
|
+
let properties = null;
|
|
2010
|
+
if (isFunction(optionsOrSetup)) {
|
|
2011
|
+
setup = optionsOrSetup;
|
|
2012
|
+
options = {};
|
|
2013
|
+
}
|
|
2014
|
+
else {
|
|
2015
|
+
if (optionsOrSetup.setup === undefined) {
|
|
2016
|
+
// eslint-disable-next-line new-cap
|
|
2017
|
+
return Component(optionsOrSetup);
|
|
2018
|
+
}
|
|
2019
|
+
setup = optionsOrSetup.setup;
|
|
2020
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
2021
|
+
if (options.properties) {
|
|
2022
|
+
properties = Object.keys(options.properties);
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
if (options.lifetimes === undefined) {
|
|
2026
|
+
options.lifetimes = {};
|
|
2027
|
+
}
|
|
2028
|
+
const originAttached = options.lifetimes[ComponentLifecycle.ATTACHED] ||
|
|
2029
|
+
options[ComponentLifecycle.ATTACHED];
|
|
2030
|
+
options.lifetimes[ComponentLifecycle.ATTACHED] = function () {
|
|
2031
|
+
this.__scope__ = new EffectScope();
|
|
2032
|
+
setCurrentComponent(this);
|
|
2033
|
+
const rawProps = {};
|
|
2034
|
+
if (properties) {
|
|
2035
|
+
properties.forEach((property) => {
|
|
2036
|
+
rawProps[property] = this.data[property];
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
this.__props__ = shallowReactive(rawProps);
|
|
2040
|
+
const context = {
|
|
2041
|
+
is: this.is,
|
|
2042
|
+
id: this.id,
|
|
2043
|
+
dataset: this.dataset,
|
|
2044
|
+
exitState: this.exitState,
|
|
2045
|
+
router: this.router,
|
|
2046
|
+
pageRouter: this.pageRouter,
|
|
2047
|
+
renderer: this.renderer,
|
|
2048
|
+
triggerEvent: this.triggerEvent.bind(this),
|
|
2049
|
+
createSelectorQuery: this.createSelectorQuery.bind(this),
|
|
2050
|
+
createIntersectionObserver: this.createIntersectionObserver.bind(this),
|
|
2051
|
+
createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
|
|
2052
|
+
selectComponent: this.selectComponent.bind(this),
|
|
2053
|
+
selectAllComponents: this.selectAllComponents.bind(this),
|
|
2054
|
+
selectOwnerComponent: this.selectOwnerComponent.bind(this),
|
|
2055
|
+
getRelationNodes: this.getRelationNodes.bind(this),
|
|
2056
|
+
getTabBar: this.getTabBar.bind(this),
|
|
2057
|
+
getPageId: this.getPageId.bind(this),
|
|
2058
|
+
animate: this.animate.bind(this),
|
|
2059
|
+
clearAnimation: this.clearAnimation.bind(this),
|
|
2060
|
+
getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
|
|
2061
|
+
applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
|
|
2062
|
+
clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
|
|
2063
|
+
setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
|
|
2064
|
+
getPassiveEvent: this.getPassiveEvent.bind(this),
|
|
2065
|
+
setPassiveEvent: this.setPassiveEvent.bind(this),
|
|
2066
|
+
};
|
|
2067
|
+
const bindings = setup(shallowReadonly(this.__props__)
|
|
2068
|
+
, context);
|
|
2069
|
+
if (bindings !== undefined) {
|
|
2070
|
+
Object.keys(bindings).forEach((key) => {
|
|
2071
|
+
const value = bindings[key];
|
|
2072
|
+
if (isFunction(value)) {
|
|
2073
|
+
this[key] = value;
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
this.setData({ [key]: deepToRaw(value) });
|
|
2077
|
+
deepWatch.call(this, key, value);
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
unsetCurrentComponent();
|
|
2081
|
+
if (originAttached !== undefined) {
|
|
2082
|
+
originAttached.call(this);
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
const detached = createComponentLifecycle(options, ComponentLifecycle.DETACHED);
|
|
2086
|
+
options.lifetimes[ComponentLifecycle.DETACHED] = function () {
|
|
2087
|
+
detached.call(this);
|
|
2088
|
+
this.__scope__.stop();
|
|
2089
|
+
};
|
|
2090
|
+
const originReady = options.lifetimes[ComponentLifecycle.READY] ||
|
|
2091
|
+
options[ComponentLifecycle.READY];
|
|
2092
|
+
options.lifetimes[ComponentLifecycle.READY] = createLifecycle(SpecialLifecycleMap[ComponentLifecycle.READY], originReady);
|
|
2093
|
+
options.lifetimes[ComponentLifecycle.MOVED] = createComponentLifecycle(options, ComponentLifecycle.MOVED);
|
|
2094
|
+
options.lifetimes[ComponentLifecycle.ERROR] = createComponentLifecycle(options, ComponentLifecycle.ERROR);
|
|
2095
|
+
if (options.methods === undefined) {
|
|
2096
|
+
options.methods = {};
|
|
2097
|
+
}
|
|
2098
|
+
if (options.methods[PageLifecycle.ON_PAGE_SCROLL] ||
|
|
2099
|
+
config.listenPageScroll) {
|
|
2100
|
+
options.methods[PageLifecycle.ON_PAGE_SCROLL] = createPageLifecycle(options, PageLifecycle.ON_PAGE_SCROLL);
|
|
2101
|
+
/* istanbul ignore next -- @preserve */
|
|
2102
|
+
options.methods.__listenPageScroll__ = () => true;
|
|
2103
|
+
}
|
|
2104
|
+
if (options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
|
|
2105
|
+
config.canShareToOthers) {
|
|
2106
|
+
options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] = function (share) {
|
|
2107
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE)];
|
|
2108
|
+
if (hook) {
|
|
2109
|
+
return hook(share);
|
|
2110
|
+
}
|
|
2111
|
+
return {};
|
|
2112
|
+
};
|
|
2113
|
+
/* istanbul ignore next -- @preserve */
|
|
2114
|
+
options.methods.__isInjectedShareToOthersHook__ = () => true;
|
|
2115
|
+
}
|
|
2116
|
+
if (options.methods[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
|
|
2117
|
+
config.canShareToTimeline) {
|
|
2118
|
+
options.methods[PageLifecycle.ON_SHARE_TIMELINE] = function () {
|
|
2119
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_TIMELINE)];
|
|
2120
|
+
if (hook) {
|
|
2121
|
+
return hook();
|
|
2122
|
+
}
|
|
2123
|
+
return {};
|
|
2124
|
+
};
|
|
2125
|
+
/* istanbul ignore next -- @preserve */
|
|
2126
|
+
options.methods.__isInjectedShareToTimelineHook__ = () => true;
|
|
2127
|
+
}
|
|
2128
|
+
if (options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
|
|
2129
|
+
options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] = function (favorites) {
|
|
2130
|
+
const hook = this[toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES)];
|
|
2131
|
+
if (hook) {
|
|
2132
|
+
return hook(favorites);
|
|
2133
|
+
}
|
|
2134
|
+
return {};
|
|
2135
|
+
};
|
|
2136
|
+
/* istanbul ignore next -- @preserve */
|
|
2137
|
+
options.methods.__isInjectedFavoritesHook__ = () => true;
|
|
2138
|
+
}
|
|
2139
|
+
if (options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
|
|
2140
|
+
options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] = function () {
|
|
2141
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE)];
|
|
2142
|
+
if (hook) {
|
|
2143
|
+
return hook();
|
|
2144
|
+
}
|
|
2145
|
+
return { data: undefined };
|
|
2146
|
+
};
|
|
2147
|
+
/* istanbul ignore next -- @preserve */
|
|
2148
|
+
options.methods.__isInjectedExitStateHook__ = () => true;
|
|
2149
|
+
}
|
|
2150
|
+
options.methods[PageLifecycle.ON_LOAD] = createPageLifecycle(options, PageLifecycle.ON_LOAD);
|
|
2151
|
+
options.methods[PageLifecycle.ON_PULL_DOWN_REFRESH] = createPageLifecycle(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
2152
|
+
options.methods[PageLifecycle.ON_REACH_BOTTOM] = createPageLifecycle(options, PageLifecycle.ON_REACH_BOTTOM);
|
|
2153
|
+
options.methods[PageLifecycle.ON_TAB_ITEM_TAP] = createPageLifecycle(options, PageLifecycle.ON_TAB_ITEM_TAP);
|
|
2154
|
+
if (options.pageLifetimes === undefined) {
|
|
2155
|
+
options.pageLifetimes = {};
|
|
2156
|
+
}
|
|
2157
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_SHOW]] =
|
|
2158
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_SHOW);
|
|
2159
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_HIDE]] =
|
|
2160
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_HIDE);
|
|
2161
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_RESIZE]] =
|
|
2162
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_RESIZE);
|
|
2163
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_ROUTE_DONE]] =
|
|
2164
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_ROUTE_DONE);
|
|
2165
|
+
if (properties) {
|
|
2166
|
+
if (options.observers === undefined) {
|
|
2167
|
+
options.observers = {};
|
|
2168
|
+
}
|
|
2169
|
+
properties.forEach((property) => {
|
|
2170
|
+
const originObserver = options.observers[property];
|
|
2171
|
+
options.observers[property] = function (value) {
|
|
2172
|
+
// Observer executes before attached
|
|
2173
|
+
if (this.__props__) {
|
|
2174
|
+
this.__props__[property] = value;
|
|
2175
|
+
}
|
|
2176
|
+
if (originObserver !== undefined) {
|
|
2177
|
+
originObserver.call(this, value);
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
// eslint-disable-next-line new-cap
|
|
2183
|
+
return Component(options);
|
|
2184
|
+
}
|
|
2185
|
+
function createComponentLifecycle(options, lifecycle) {
|
|
2186
|
+
const originLifecycle = options.lifetimes[lifecycle] || options[lifecycle];
|
|
2187
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
2188
|
+
}
|
|
2189
|
+
function createPageLifecycle(options, lifecycle) {
|
|
2190
|
+
const originLifecycle = options.methods[lifecycle];
|
|
2191
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
2192
|
+
}
|
|
2193
|
+
function createSpecialPageLifecycle(options, lifecycle) {
|
|
2194
|
+
const originLifecycle = options.pageLifetimes[SpecialLifecycleMap[lifecycle]];
|
|
2195
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
2196
|
+
}
|
|
2197
|
+
function createLifecycle(lifecycle, originLifecycle) {
|
|
2198
|
+
const hiddenField = toHiddenField(lifecycle);
|
|
2199
|
+
return function (...args) {
|
|
2200
|
+
const hooks = this[hiddenField];
|
|
2201
|
+
if (hooks) {
|
|
2202
|
+
hooks.forEach((hook) => hook(...args));
|
|
2203
|
+
}
|
|
2204
|
+
if (originLifecycle !== undefined) {
|
|
2205
|
+
originLifecycle.call(this, ...args);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
const pageHookWarn = 'Page specific lifecycle injection APIs can only be used during execution of setup() in definePage() or defineComponent().';
|
|
2211
|
+
const onAppShow = createAppHook(AppLifecycle.ON_SHOW);
|
|
2212
|
+
const onAppHide = createAppHook(AppLifecycle.ON_HIDE);
|
|
2213
|
+
const onAppError = createAppHook(AppLifecycle.ON_ERROR);
|
|
2214
|
+
const onPageNotFound = createAppHook(AppLifecycle.ON_PAGE_NOT_FOUND);
|
|
2215
|
+
const onUnhandledRejection = createAppHook(AppLifecycle.ON_UNHANDLED_REJECTION);
|
|
2216
|
+
const onThemeChange = createAppHook(AppLifecycle.ON_THEME_CHANGE);
|
|
2217
|
+
const onShow = createPageHook(PageLifecycle.ON_SHOW);
|
|
2218
|
+
const onHide = createPageHook(PageLifecycle.ON_HIDE);
|
|
2219
|
+
const onUnload = createPageHook(PageLifecycle.ON_UNLOAD);
|
|
2220
|
+
const onRouteDone = createPageHook(PageLifecycle.ON_ROUTE_DONE);
|
|
2221
|
+
const onPullDownRefresh = createPageHook(PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
2222
|
+
const onReachBottom = createPageHook(PageLifecycle.ON_REACH_BOTTOM);
|
|
2223
|
+
const onResize = createPageHook(PageLifecycle.ON_RESIZE);
|
|
2224
|
+
const onTabItemTap = createPageHook(PageLifecycle.ON_TAB_ITEM_TAP);
|
|
2225
|
+
const onPageScroll = (hook) => {
|
|
2226
|
+
const currentInstance = getCurrentInstance();
|
|
2227
|
+
/* istanbul ignore else -- @preserve */
|
|
2228
|
+
if (currentInstance) {
|
|
2229
|
+
/* istanbul ignore else -- @preserve */
|
|
2230
|
+
if (currentInstance.__listenPageScroll__) {
|
|
2231
|
+
injectHook(currentInstance, PageLifecycle.ON_PAGE_SCROLL, hook);
|
|
2232
|
+
}
|
|
2233
|
+
else {
|
|
2234
|
+
console.warn('onPageScroll() hook only works when `listenPageScroll` is configured to true.');
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
else {
|
|
2238
|
+
console.warn(pageHookWarn);
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
const onShareAppMessage = (hook) => {
|
|
2242
|
+
const currentInstance = getCurrentInstance();
|
|
2243
|
+
/* istanbul ignore else -- @preserve */
|
|
2244
|
+
if (currentInstance) {
|
|
2245
|
+
/* istanbul ignore else -- @preserve */
|
|
2246
|
+
if (currentInstance[PageLifecycle.ON_SHARE_APP_MESSAGE] &&
|
|
2247
|
+
currentInstance.__isInjectedShareToOthersHook__) {
|
|
2248
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE);
|
|
2249
|
+
/* istanbul ignore else -- @preserve */
|
|
2250
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
2251
|
+
currentInstance[hiddenField] = hook;
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
console.warn('onShareAppMessage() hook can only be called once.');
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
else {
|
|
2258
|
+
console.warn('onShareAppMessage() hook only works when `onShareAppMessage` option is not exist and `canShareToOthers` is configured to true.');
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
else {
|
|
2262
|
+
console.warn(pageHookWarn);
|
|
2263
|
+
}
|
|
2264
|
+
};
|
|
2265
|
+
const onShareTimeline = (hook) => {
|
|
2266
|
+
const currentInstance = getCurrentInstance();
|
|
2267
|
+
/* istanbul ignore else -- @preserve */
|
|
2268
|
+
if (currentInstance) {
|
|
2269
|
+
/* istanbul ignore else -- @preserve */
|
|
2270
|
+
if (currentInstance[PageLifecycle.ON_SHARE_TIMELINE] &&
|
|
2271
|
+
currentInstance.__isInjectedShareToTimelineHook__) {
|
|
2272
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SHARE_TIMELINE);
|
|
2273
|
+
/* istanbul ignore else -- @preserve */
|
|
2274
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
2275
|
+
currentInstance[hiddenField] = hook;
|
|
2276
|
+
}
|
|
2277
|
+
else {
|
|
2278
|
+
console.warn('onShareTimeline() hook can only be called once.');
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
else {
|
|
2282
|
+
console.warn('onShareTimeline() hook only works when `onShareTimeline` option is not exist and `canShareToTimeline` is configured to true.');
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
else {
|
|
2286
|
+
console.warn(pageHookWarn);
|
|
2287
|
+
}
|
|
2288
|
+
};
|
|
2289
|
+
const onAddToFavorites = (hook) => {
|
|
2290
|
+
const currentInstance = getCurrentInstance();
|
|
2291
|
+
/* istanbul ignore else -- @preserve */
|
|
2292
|
+
if (currentInstance) {
|
|
2293
|
+
/* istanbul ignore else -- @preserve */
|
|
2294
|
+
if (currentInstance.__isInjectedFavoritesHook__) {
|
|
2295
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES);
|
|
2296
|
+
/* istanbul ignore else -- @preserve */
|
|
2297
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
2298
|
+
currentInstance[hiddenField] = hook;
|
|
2299
|
+
}
|
|
2300
|
+
else {
|
|
2301
|
+
console.warn('onAddToFavorites() hook can only be called once.');
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
else {
|
|
2305
|
+
console.warn('onAddToFavorites() hook only works when `onAddToFavorites` option is not exist.');
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
else {
|
|
2309
|
+
console.warn(pageHookWarn);
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
const onSaveExitState = (hook) => {
|
|
2313
|
+
const currentInstance = getCurrentInstance();
|
|
2314
|
+
/* istanbul ignore else -- @preserve */
|
|
2315
|
+
if (currentInstance) {
|
|
2316
|
+
/* istanbul ignore else -- @preserve */
|
|
2317
|
+
if (currentInstance.__isInjectedExitStateHook__) {
|
|
2318
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE);
|
|
2319
|
+
/* istanbul ignore else -- @preserve */
|
|
2320
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
2321
|
+
currentInstance[hiddenField] = hook;
|
|
2322
|
+
}
|
|
2323
|
+
else {
|
|
2324
|
+
console.warn('onSaveExitState() hook can only be called once.');
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
else {
|
|
2328
|
+
console.warn('onSaveExitState() hook only works when `onSaveExitState` option is not exist.');
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
else {
|
|
2332
|
+
console.warn(pageHookWarn);
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
const onReady = (hook) => {
|
|
2336
|
+
const currentInstance = getCurrentInstance();
|
|
2337
|
+
/* istanbul ignore else -- @preserve */
|
|
2338
|
+
if (currentInstance) {
|
|
2339
|
+
injectHook(currentInstance, PageLifecycle.ON_READY, hook);
|
|
2340
|
+
}
|
|
2341
|
+
else {
|
|
2342
|
+
console.warn('onReady() hook can only be called during execution of setup() in definePage() or defineComponent().');
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
const onLoad = createComponentHook(PageLifecycle.ON_LOAD);
|
|
2346
|
+
const onMove = createComponentHook(ComponentLifecycle.MOVED);
|
|
2347
|
+
const onDetach = createComponentHook(ComponentLifecycle.DETACHED);
|
|
2348
|
+
const onError = createComponentHook(ComponentLifecycle.ERROR);
|
|
2349
|
+
function createAppHook(lifecycle) {
|
|
2350
|
+
return (hook) => {
|
|
2351
|
+
/* istanbul ignore else -- @preserve */
|
|
2352
|
+
if (currentApp) {
|
|
2353
|
+
injectHook(currentApp, lifecycle, hook);
|
|
2354
|
+
}
|
|
2355
|
+
else {
|
|
2356
|
+
console.warn('App specific lifecycle injection APIs can only be used during execution of setup() in createApp().');
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
function createPageHook(lifecycle) {
|
|
2361
|
+
return (hook) => {
|
|
2362
|
+
const currentInstance = getCurrentInstance();
|
|
2363
|
+
/* istanbul ignore else -- @preserve */
|
|
2364
|
+
if (currentInstance) {
|
|
2365
|
+
injectHook(currentInstance, lifecycle, hook);
|
|
2366
|
+
}
|
|
2367
|
+
else {
|
|
2368
|
+
console.warn(pageHookWarn);
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
function createComponentHook(lifecycle) {
|
|
2373
|
+
return (hook) => {
|
|
2374
|
+
/* istanbul ignore else -- @preserve */
|
|
2375
|
+
if (currentComponent) {
|
|
2376
|
+
injectHook(currentComponent, lifecycle, hook);
|
|
2377
|
+
}
|
|
2378
|
+
else {
|
|
2379
|
+
console.warn('Component specific lifecycle injection APIs can only be used during execution of setup() in defineComponent().');
|
|
2380
|
+
}
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
function injectHook(currentInstance, lifecycle, hook) {
|
|
2384
|
+
const hiddenField = toHiddenField(lifecycle);
|
|
2385
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
2386
|
+
currentInstance[hiddenField] = [];
|
|
2387
|
+
}
|
|
2388
|
+
currentInstance[hiddenField].push(hook);
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
exports.EffectScope = EffectScope;
|
|
2392
|
+
exports.ReactiveEffect = ReactiveEffect;
|
|
2393
|
+
exports.TrackOpTypes = TrackOpTypes;
|
|
2394
|
+
exports.TriggerOpTypes = TriggerOpTypes;
|
|
2395
|
+
exports.computed = computed;
|
|
2396
|
+
exports.createApp = createApp;
|
|
2397
|
+
exports.customRef = customRef;
|
|
2398
|
+
exports.defineComponent = defineComponent;
|
|
2399
|
+
exports.definePage = definePage;
|
|
2400
|
+
exports.effect = effect;
|
|
2401
|
+
exports.effectScope = effectScope;
|
|
2402
|
+
exports.getCurrentScope = getCurrentScope;
|
|
2403
|
+
exports.inject = inject;
|
|
2404
|
+
exports.isProxy = isProxy;
|
|
2405
|
+
exports.isReactive = isReactive;
|
|
2406
|
+
exports.isReadonly = isReadonly;
|
|
2407
|
+
exports.isRef = isRef;
|
|
2408
|
+
exports.isShallow = isShallow;
|
|
2409
|
+
exports.markRaw = markRaw;
|
|
2410
|
+
exports.nextTick = nextTick;
|
|
2411
|
+
exports.onAddToFavorites = onAddToFavorites;
|
|
2412
|
+
exports.onAppError = onAppError;
|
|
2413
|
+
exports.onAppHide = onAppHide;
|
|
2414
|
+
exports.onAppShow = onAppShow;
|
|
2415
|
+
exports.onDetach = onDetach;
|
|
2416
|
+
exports.onError = onError;
|
|
2417
|
+
exports.onHide = onHide;
|
|
2418
|
+
exports.onLoad = onLoad;
|
|
2419
|
+
exports.onMove = onMove;
|
|
2420
|
+
exports.onPageNotFound = onPageNotFound;
|
|
2421
|
+
exports.onPageScroll = onPageScroll;
|
|
2422
|
+
exports.onPullDownRefresh = onPullDownRefresh;
|
|
2423
|
+
exports.onReachBottom = onReachBottom;
|
|
2424
|
+
exports.onReady = onReady;
|
|
2425
|
+
exports.onResize = onResize;
|
|
2426
|
+
exports.onRouteDone = onRouteDone;
|
|
2427
|
+
exports.onSaveExitState = onSaveExitState;
|
|
2428
|
+
exports.onScopeDispose = onScopeDispose;
|
|
2429
|
+
exports.onShareAppMessage = onShareAppMessage;
|
|
2430
|
+
exports.onShareTimeline = onShareTimeline;
|
|
2431
|
+
exports.onShow = onShow;
|
|
2432
|
+
exports.onTabItemTap = onTabItemTap;
|
|
2433
|
+
exports.onThemeChange = onThemeChange;
|
|
2434
|
+
exports.onUnhandledRejection = onUnhandledRejection;
|
|
2435
|
+
exports.onUnload = onUnload;
|
|
2436
|
+
exports.provide = provide;
|
|
2437
|
+
exports.proxyRefs = proxyRefs;
|
|
2438
|
+
exports.reactive = reactive;
|
|
2439
|
+
exports.readonly = readonly;
|
|
2440
|
+
exports.ref = ref;
|
|
2441
|
+
exports.shallowReactive = shallowReactive;
|
|
2442
|
+
exports.shallowReadonly = shallowReadonly;
|
|
2443
|
+
exports.shallowRef = shallowRef;
|
|
2444
|
+
exports.stop = stop;
|
|
2445
|
+
exports.toRaw = toRaw;
|
|
2446
|
+
exports.toRef = toRef;
|
|
2447
|
+
exports.toRefs = toRefs;
|
|
2448
|
+
exports.toValue = toValue;
|
|
2449
|
+
exports.triggerRef = triggerRef;
|
|
2450
|
+
exports.unref = unref;
|
|
2451
|
+
exports.watch = watch;
|
|
2452
|
+
exports.watchEffect = watchEffect;
|
|
2453
|
+
exports.watchPostEffect = watchPostEffect;
|
|
2454
|
+
exports.watchSyncEffect = watchSyncEffect;
|