@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,1118 @@
|
|
|
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
|
+
import { isRef, isShallow, isReactive, ReactiveEffect, getCurrentScope, ReactiveFlags, isProxy, toRaw, EffectScope, shallowReactive, shallowReadonly } from '@vue/reactivity';
|
|
8
|
+
export { EffectScope, ReactiveEffect, TrackOpTypes, TriggerOpTypes, computed, customRef, effect, effectScope, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, toValue, triggerRef, unref } from '@vue/reactivity';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
11
|
+
const NOOP = () => { };
|
|
12
|
+
const { isArray } = Array;
|
|
13
|
+
const extend = Object.assign;
|
|
14
|
+
function exclude(obj, keys) {
|
|
15
|
+
const ret = {};
|
|
16
|
+
Object.keys(obj).forEach((key) => {
|
|
17
|
+
if (!keys.includes(key)) {
|
|
18
|
+
ret[key] = obj[key];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
function getType(x) {
|
|
24
|
+
return Object.prototype.toString.call(x).slice(8, -1);
|
|
25
|
+
}
|
|
26
|
+
function isSimpleValue(x) {
|
|
27
|
+
const simpleTypes = new Set(['undefined', 'boolean', 'number', 'string']);
|
|
28
|
+
return x === null || simpleTypes.has(typeof x);
|
|
29
|
+
}
|
|
30
|
+
function isObject(x) {
|
|
31
|
+
return x !== null && typeof x === 'object';
|
|
32
|
+
}
|
|
33
|
+
function isPlainObject(x) {
|
|
34
|
+
return getType(x) === 'Object';
|
|
35
|
+
}
|
|
36
|
+
function isFunction(x) {
|
|
37
|
+
return typeof x === 'function';
|
|
38
|
+
}
|
|
39
|
+
function isMap(x) {
|
|
40
|
+
return getType(x) === 'Map';
|
|
41
|
+
}
|
|
42
|
+
function isSet(x) {
|
|
43
|
+
return getType(x) === 'Set';
|
|
44
|
+
}
|
|
45
|
+
// Compare whether a value has changed, accounting for NaN.
|
|
46
|
+
function hasChanged(value, oldValue) {
|
|
47
|
+
// eslint-disable-next-line no-self-compare
|
|
48
|
+
return value !== oldValue && (value === value || oldValue === oldValue);
|
|
49
|
+
}
|
|
50
|
+
function remove(arr, el) {
|
|
51
|
+
const i = arr.indexOf(el);
|
|
52
|
+
if (i > -1) {
|
|
53
|
+
arr.splice(i, 1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function toHiddenField(name) {
|
|
57
|
+
return `__${name}__`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let isFlushing = false;
|
|
61
|
+
let isFlushPending = false;
|
|
62
|
+
const queue = [];
|
|
63
|
+
let flushIndex = 0;
|
|
64
|
+
const pendingPostFlushCbs = [];
|
|
65
|
+
let activePostFlushCbs = null;
|
|
66
|
+
let postFlushIndex = 0;
|
|
67
|
+
// eslint-disable-next-line spaced-comment
|
|
68
|
+
const resolvedPromise = /*#__PURE__*/ Promise.resolve();
|
|
69
|
+
let currentFlushPromise = null;
|
|
70
|
+
const RECURSION_LIMIT = 100;
|
|
71
|
+
function nextTick(fn) {
|
|
72
|
+
const p = currentFlushPromise || resolvedPromise;
|
|
73
|
+
return fn ? p.then(fn) : p;
|
|
74
|
+
}
|
|
75
|
+
function queueJob(job) {
|
|
76
|
+
// The dedupe search uses the startIndex argument of Array.includes()
|
|
77
|
+
// by default the search index includes the current job that is being run
|
|
78
|
+
// so it cannot recursively trigger itself again.
|
|
79
|
+
// if the job is a watch() callback, the search will start with a +1 index to
|
|
80
|
+
// allow it recursively trigger itself - it is the user's responsibility to
|
|
81
|
+
// ensure it doesn't end up in an infinite loop.
|
|
82
|
+
if (queue.length === 0 ||
|
|
83
|
+
!queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) {
|
|
84
|
+
queue.push(job);
|
|
85
|
+
queueFlush();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function queueFlush() {
|
|
89
|
+
if (!isFlushing && !isFlushPending) {
|
|
90
|
+
isFlushPending = true;
|
|
91
|
+
currentFlushPromise = resolvedPromise.then(flushJobs);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function queuePostFlushCb(cb) {
|
|
95
|
+
if (!activePostFlushCbs ||
|
|
96
|
+
!activePostFlushCbs.includes(cb, cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex)) {
|
|
97
|
+
pendingPostFlushCbs.push(cb);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function flushPostFlushCbs() {
|
|
101
|
+
if (pendingPostFlushCbs.length > 0) {
|
|
102
|
+
activePostFlushCbs = [...new Set(pendingPostFlushCbs)];
|
|
103
|
+
pendingPostFlushCbs.length = 0;
|
|
104
|
+
for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
|
|
105
|
+
activePostFlushCbs[postFlushIndex]();
|
|
106
|
+
}
|
|
107
|
+
activePostFlushCbs = null;
|
|
108
|
+
postFlushIndex = 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function flushJobs(seen) {
|
|
112
|
+
isFlushPending = false;
|
|
113
|
+
isFlushing = true;
|
|
114
|
+
/* istanbul ignore else -- @preserve */
|
|
115
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
116
|
+
seen = seen || new Map();
|
|
117
|
+
}
|
|
118
|
+
// Conditional usage of checkRecursiveUpdate must be determined out of
|
|
119
|
+
// try ... catch block since Rollup by default de-optimizes treeshaking
|
|
120
|
+
// inside try-catch. This can leave all warning code unshaked. Although
|
|
121
|
+
// they would get eventually shaken by a minifier like terser, some minifiers
|
|
122
|
+
// would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
|
|
123
|
+
const check = (process.env.NODE_ENV !== 'production') ?
|
|
124
|
+
(job) => checkRecursiveUpdates(seen, job)
|
|
125
|
+
: /* istanbul ignore next -- @preserve */ NOOP;
|
|
126
|
+
try {
|
|
127
|
+
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
|
|
128
|
+
const job = queue[flushIndex];
|
|
129
|
+
if (job.active !== false) {
|
|
130
|
+
/* istanbul ignore if -- @preserve */
|
|
131
|
+
if ((process.env.NODE_ENV !== 'production') && check(job)) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
job();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
flushIndex = 0;
|
|
140
|
+
queue.length = 0;
|
|
141
|
+
isFlushing = false;
|
|
142
|
+
currentFlushPromise = null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function checkRecursiveUpdates(seen, fn) {
|
|
146
|
+
const count = seen.get(fn) || 0;
|
|
147
|
+
/* istanbul ignore if -- @preserve */
|
|
148
|
+
if (count > RECURSION_LIMIT) {
|
|
149
|
+
console.warn(`Maximum recursive updates exceeded. ` +
|
|
150
|
+
`This means you have a reactive effect that is mutating its own ` +
|
|
151
|
+
`dependencies and thus recursively triggering itself.`);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
seen.set(fn, count + 1);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Simple effect.
|
|
159
|
+
function watchEffect(effect, options) {
|
|
160
|
+
return doWatch(effect, null, options);
|
|
161
|
+
}
|
|
162
|
+
function watchPostEffect(effect, options) {
|
|
163
|
+
return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ?
|
|
164
|
+
extend({}, options, { flush: 'post' })
|
|
165
|
+
: /* istanbul ignore next -- @preserve */ { flush: 'post' });
|
|
166
|
+
}
|
|
167
|
+
function watchSyncEffect(effect, options) {
|
|
168
|
+
return doWatch(effect, null, (process.env.NODE_ENV !== 'production') ?
|
|
169
|
+
extend({}, options, { flush: 'sync' })
|
|
170
|
+
: /* istanbul ignore next -- @preserve */ { flush: 'sync' });
|
|
171
|
+
}
|
|
172
|
+
// Initial value for watchers to trigger on undefined initial values
|
|
173
|
+
const INITIAL_WATCHER_VALUE = {};
|
|
174
|
+
// Implementation
|
|
175
|
+
function watch(source, cb, options) {
|
|
176
|
+
if ((process.env.NODE_ENV !== 'production') && !isFunction(cb)) {
|
|
177
|
+
console.warn(`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
|
178
|
+
`Use \`watchEffect(fn, options?)\` instead. \`watch\` now only ` +
|
|
179
|
+
`supports \`watch(source, cb, options?) signature.`);
|
|
180
|
+
}
|
|
181
|
+
return doWatch(source, cb, options);
|
|
182
|
+
}
|
|
183
|
+
// eslint-disable-next-line complexity
|
|
184
|
+
function doWatch(source, cb, { immediate, deep, flush, once, onTrack, onTrigger } = {}) {
|
|
185
|
+
if (cb && once) {
|
|
186
|
+
const _cb = cb;
|
|
187
|
+
cb = (...args) => {
|
|
188
|
+
_cb(...args);
|
|
189
|
+
unwatch();
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if ((process.env.NODE_ENV !== 'production') && deep !== undefined && typeof deep === 'number') {
|
|
193
|
+
console.warn(`watch() "deep" option with number value will be used as watch depth in future versions. ` +
|
|
194
|
+
`Please use a boolean instead to avoid potential breakage.`);
|
|
195
|
+
}
|
|
196
|
+
if ((process.env.NODE_ENV !== 'production') && !cb) {
|
|
197
|
+
if (immediate !== undefined) {
|
|
198
|
+
console.warn(`watch() "immediate" option is only respected when using the ` +
|
|
199
|
+
`watch(source, callback, options?) signature.`);
|
|
200
|
+
}
|
|
201
|
+
if (deep !== undefined) {
|
|
202
|
+
console.warn(`watch() "deep" option is only respected when using the ` +
|
|
203
|
+
`watch(source, callback, options?) signature.`);
|
|
204
|
+
}
|
|
205
|
+
if (once !== undefined) {
|
|
206
|
+
console.warn(`watch() "once" option is only respected when using the ` +
|
|
207
|
+
`watch(source, callback, options?) signature.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const warnInvalidSource = (s) => {
|
|
211
|
+
console.warn(`Invalid watch source:`, s, `A watch source can only be a getter/effect function, a ref, ` +
|
|
212
|
+
`a reactive object, or an array of these types.`);
|
|
213
|
+
};
|
|
214
|
+
const reactiveGetter = (source) => deep === true ?
|
|
215
|
+
source // Traverse will happen in wrapped getter below
|
|
216
|
+
// For deep: false, only traverse root-level properties
|
|
217
|
+
: traverse(source, deep === false ? 1 : undefined);
|
|
218
|
+
let getter;
|
|
219
|
+
let forceTrigger = false;
|
|
220
|
+
let isMultiSource = false;
|
|
221
|
+
if (isRef(source)) {
|
|
222
|
+
getter = () => source.value;
|
|
223
|
+
forceTrigger = isShallow(source);
|
|
224
|
+
}
|
|
225
|
+
else if (isReactive(source)) {
|
|
226
|
+
getter = () => reactiveGetter(source);
|
|
227
|
+
forceTrigger = true;
|
|
228
|
+
}
|
|
229
|
+
else if (isArray(source)) {
|
|
230
|
+
isMultiSource = true;
|
|
231
|
+
forceTrigger = source.some((s) => isReactive(s) || isShallow(s));
|
|
232
|
+
getter = () => source.map((s) => {
|
|
233
|
+
if (isRef(s)) {
|
|
234
|
+
return s.value;
|
|
235
|
+
}
|
|
236
|
+
if (isReactive(s)) {
|
|
237
|
+
return reactiveGetter(s);
|
|
238
|
+
}
|
|
239
|
+
if (isFunction(s)) {
|
|
240
|
+
return s();
|
|
241
|
+
}
|
|
242
|
+
/* istanbul ignore else -- @preserve */
|
|
243
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
244
|
+
warnInvalidSource(s);
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else if (isFunction(source)) {
|
|
250
|
+
if (cb) {
|
|
251
|
+
// Getter with cb
|
|
252
|
+
getter = () => source();
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// No cb -> simple effect
|
|
256
|
+
getter = () => {
|
|
257
|
+
if (cleanup) {
|
|
258
|
+
cleanup();
|
|
259
|
+
}
|
|
260
|
+
return source(onCleanup);
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
getter = NOOP;
|
|
266
|
+
/* istanbul ignore else -- @preserve */
|
|
267
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
268
|
+
warnInvalidSource(source);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (cb && deep) {
|
|
272
|
+
const baseGetter = getter;
|
|
273
|
+
getter = () => traverse(baseGetter());
|
|
274
|
+
}
|
|
275
|
+
let cleanup;
|
|
276
|
+
const onCleanup = (fn) => {
|
|
277
|
+
// eslint-disable-next-line no-multi-assign
|
|
278
|
+
cleanup = effect.onStop = () => {
|
|
279
|
+
fn();
|
|
280
|
+
// eslint-disable-next-line no-multi-assign
|
|
281
|
+
cleanup = effect.onStop = undefined;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
let oldValue = isMultiSource ?
|
|
285
|
+
Array.from({ length: source.length }).fill(INITIAL_WATCHER_VALUE)
|
|
286
|
+
: INITIAL_WATCHER_VALUE;
|
|
287
|
+
const job = () => {
|
|
288
|
+
if (!effect.active || !effect.dirty) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (cb) {
|
|
292
|
+
// Watch(source, cb)
|
|
293
|
+
const newValue = effect.run();
|
|
294
|
+
if (deep ||
|
|
295
|
+
forceTrigger ||
|
|
296
|
+
(isMultiSource ?
|
|
297
|
+
newValue.some((v, i) => hasChanged(v, oldValue[i]))
|
|
298
|
+
: hasChanged(newValue, oldValue))) {
|
|
299
|
+
// Cleanup before running cb again
|
|
300
|
+
if (cleanup) {
|
|
301
|
+
cleanup();
|
|
302
|
+
}
|
|
303
|
+
cb(newValue,
|
|
304
|
+
// Pass undefined as the old value when it's changed for the first time
|
|
305
|
+
oldValue === INITIAL_WATCHER_VALUE ? undefined
|
|
306
|
+
: isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? []
|
|
307
|
+
: oldValue, onCleanup);
|
|
308
|
+
oldValue = newValue;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
// WatchEffect
|
|
313
|
+
effect.run();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
// Important: mark the job as a watcher callback so that scheduler knows
|
|
317
|
+
// it is allowed to self-trigger
|
|
318
|
+
job.allowRecurse = Boolean(cb);
|
|
319
|
+
let scheduler;
|
|
320
|
+
if (flush === 'sync') {
|
|
321
|
+
scheduler = job; // The scheduler function gets called directly
|
|
322
|
+
}
|
|
323
|
+
else if (flush === 'post') {
|
|
324
|
+
scheduler = () => {
|
|
325
|
+
queuePostFlushCb(job);
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
scheduler = () => {
|
|
330
|
+
queueJob(job);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
const effect = new ReactiveEffect(getter, NOOP, scheduler);
|
|
334
|
+
const scope = getCurrentScope();
|
|
335
|
+
const unwatch = () => {
|
|
336
|
+
effect.stop();
|
|
337
|
+
if (scope) {
|
|
338
|
+
// @ts-expect-error
|
|
339
|
+
remove(scope.effects, effect);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
/* istanbul ignore else -- @preserve */
|
|
343
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
344
|
+
effect.onTrack = onTrack;
|
|
345
|
+
effect.onTrigger = onTrigger;
|
|
346
|
+
}
|
|
347
|
+
// Initial run
|
|
348
|
+
if (cb) {
|
|
349
|
+
if (immediate) {
|
|
350
|
+
job();
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
oldValue = effect.run();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
effect.run();
|
|
358
|
+
}
|
|
359
|
+
return unwatch;
|
|
360
|
+
}
|
|
361
|
+
function traverse(value, depth = Number.POSITIVE_INFINITY, seen) {
|
|
362
|
+
if (depth <= 0 || !isObject(value) || value[ReactiveFlags.SKIP]) {
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
seen = seen || new Set();
|
|
366
|
+
if (seen.has(value)) {
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
seen.add(value);
|
|
370
|
+
depth--;
|
|
371
|
+
/* istanbul ignore else -- @preserve */
|
|
372
|
+
if (isRef(value)) {
|
|
373
|
+
traverse(value.value, depth, seen);
|
|
374
|
+
}
|
|
375
|
+
else if (isArray(value)) {
|
|
376
|
+
for (let i = 0; i < value.length; i++) {
|
|
377
|
+
traverse(value[i], depth, seen);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else if (isSet(value) || isMap(value)) {
|
|
381
|
+
value.forEach((v) => {
|
|
382
|
+
traverse(v, depth, seen);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
else if (isPlainObject(value)) {
|
|
386
|
+
// eslint-disable-next-line guard-for-in
|
|
387
|
+
for (const key in value) {
|
|
388
|
+
traverse(value[key], depth, seen);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const provides = Object.create(null);
|
|
395
|
+
function provide(key, value) {
|
|
396
|
+
// TS doesn't allow symbol as index type
|
|
397
|
+
provides[key] = value;
|
|
398
|
+
}
|
|
399
|
+
function inject(key, defaultValue, treatDefaultAsFactory = false) {
|
|
400
|
+
if (key in provides) {
|
|
401
|
+
// TS doesn't allow symbol as index type
|
|
402
|
+
return provides[key];
|
|
403
|
+
}
|
|
404
|
+
if (arguments.length > 1) {
|
|
405
|
+
return treatDefaultAsFactory && isFunction(defaultValue) ? defaultValue()
|
|
406
|
+
: defaultValue;
|
|
407
|
+
}
|
|
408
|
+
/* istanbul ignore else -- @preserve */
|
|
409
|
+
if ((process.env.NODE_ENV !== 'production')) {
|
|
410
|
+
console.warn(`injection "${String(key)}" not found.`);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let currentApp = null;
|
|
415
|
+
let currentPage = null;
|
|
416
|
+
let currentComponent = null;
|
|
417
|
+
function getCurrentInstance() {
|
|
418
|
+
return currentPage || currentComponent;
|
|
419
|
+
}
|
|
420
|
+
function setCurrentApp(page) {
|
|
421
|
+
currentApp = page;
|
|
422
|
+
}
|
|
423
|
+
function unsetCurrentApp() {
|
|
424
|
+
currentApp = null;
|
|
425
|
+
}
|
|
426
|
+
function setCurrentPage(page) {
|
|
427
|
+
currentPage = page;
|
|
428
|
+
// @ts-expect-error
|
|
429
|
+
page.__scope__.on();
|
|
430
|
+
}
|
|
431
|
+
function unsetCurrentPage() {
|
|
432
|
+
/* istanbul ignore else -- @preserve */
|
|
433
|
+
if (currentPage) {
|
|
434
|
+
// @ts-expect-error
|
|
435
|
+
currentPage.__scope__.off();
|
|
436
|
+
}
|
|
437
|
+
currentPage = null;
|
|
438
|
+
}
|
|
439
|
+
function setCurrentComponent(component) {
|
|
440
|
+
currentComponent = component;
|
|
441
|
+
// @ts-expect-error
|
|
442
|
+
component.__scope__.on();
|
|
443
|
+
}
|
|
444
|
+
function unsetCurrentComponent() {
|
|
445
|
+
/* istanbul ignore else -- @preserve */
|
|
446
|
+
if (currentComponent) {
|
|
447
|
+
// @ts-expect-error
|
|
448
|
+
currentComponent.__scope__.off();
|
|
449
|
+
}
|
|
450
|
+
currentComponent = null;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
var AppLifecycle;
|
|
454
|
+
(function (AppLifecycle) {
|
|
455
|
+
AppLifecycle["ON_LAUNCH"] = "onLaunch";
|
|
456
|
+
AppLifecycle["ON_SHOW"] = "onShow";
|
|
457
|
+
AppLifecycle["ON_HIDE"] = "onHide";
|
|
458
|
+
AppLifecycle["ON_ERROR"] = "onError";
|
|
459
|
+
AppLifecycle["ON_PAGE_NOT_FOUND"] = "onPageNotFound";
|
|
460
|
+
AppLifecycle["ON_UNHANDLED_REJECTION"] = "onUnhandledRejection";
|
|
461
|
+
AppLifecycle["ON_THEME_CHANGE"] = "onThemeChange";
|
|
462
|
+
})(AppLifecycle || (AppLifecycle = {}));
|
|
463
|
+
function createApp(optionsOrSetup) {
|
|
464
|
+
let setup;
|
|
465
|
+
let options;
|
|
466
|
+
if (isFunction(optionsOrSetup)) {
|
|
467
|
+
setup = optionsOrSetup;
|
|
468
|
+
options = {};
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
if (optionsOrSetup.setup === undefined) {
|
|
472
|
+
// eslint-disable-next-line new-cap
|
|
473
|
+
App(optionsOrSetup);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
setup = optionsOrSetup.setup;
|
|
477
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
478
|
+
}
|
|
479
|
+
const originOnLaunch = options[AppLifecycle.ON_LAUNCH];
|
|
480
|
+
options[AppLifecycle.ON_LAUNCH] = function (options) {
|
|
481
|
+
setCurrentApp(this);
|
|
482
|
+
const bindings = setup(options);
|
|
483
|
+
if (bindings !== undefined) {
|
|
484
|
+
Object.keys(bindings).forEach((key) => {
|
|
485
|
+
this[key] = bindings[key];
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
unsetCurrentApp();
|
|
489
|
+
if (originOnLaunch !== undefined) {
|
|
490
|
+
originOnLaunch.call(this, options);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
options[AppLifecycle.ON_SHOW] = createLifecycle$2(options, AppLifecycle.ON_SHOW);
|
|
494
|
+
options[AppLifecycle.ON_HIDE] = createLifecycle$2(options, AppLifecycle.ON_HIDE);
|
|
495
|
+
options[AppLifecycle.ON_ERROR] = createLifecycle$2(options, AppLifecycle.ON_ERROR);
|
|
496
|
+
options[AppLifecycle.ON_PAGE_NOT_FOUND] = createLifecycle$2(options, AppLifecycle.ON_PAGE_NOT_FOUND);
|
|
497
|
+
options[AppLifecycle.ON_UNHANDLED_REJECTION] = createLifecycle$2(options, AppLifecycle.ON_UNHANDLED_REJECTION);
|
|
498
|
+
options[AppLifecycle.ON_THEME_CHANGE] = createLifecycle$2(options, AppLifecycle.ON_THEME_CHANGE);
|
|
499
|
+
// eslint-disable-next-line new-cap
|
|
500
|
+
App(options);
|
|
501
|
+
}
|
|
502
|
+
function createLifecycle$2(options, lifecycle) {
|
|
503
|
+
const originLifecycle = options[lifecycle];
|
|
504
|
+
return function (...args) {
|
|
505
|
+
const hooks = this[toHiddenField(lifecycle)];
|
|
506
|
+
if (hooks) {
|
|
507
|
+
hooks.forEach((hook) => hook(...args));
|
|
508
|
+
}
|
|
509
|
+
if (originLifecycle !== undefined) {
|
|
510
|
+
originLifecycle.call(this, ...args);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function deepToRaw(x) {
|
|
516
|
+
if (isSimpleValue(x) || isFunction(x)) {
|
|
517
|
+
return x;
|
|
518
|
+
}
|
|
519
|
+
if (isRef(x)) {
|
|
520
|
+
return deepToRaw(x.value);
|
|
521
|
+
}
|
|
522
|
+
if (isProxy(x)) {
|
|
523
|
+
return deepToRaw(toRaw(x));
|
|
524
|
+
}
|
|
525
|
+
if (isArray(x)) {
|
|
526
|
+
return x.map((item) => deepToRaw(item));
|
|
527
|
+
}
|
|
528
|
+
if (isPlainObject(x)) {
|
|
529
|
+
const obj = {};
|
|
530
|
+
Object.keys(x).forEach((key) => {
|
|
531
|
+
obj[key] = deepToRaw(x[key]);
|
|
532
|
+
});
|
|
533
|
+
return obj;
|
|
534
|
+
}
|
|
535
|
+
throw new TypeError(`${getType(x)} value is not supported`);
|
|
536
|
+
}
|
|
537
|
+
function deepWatch(key, value) {
|
|
538
|
+
if (!isObject(value)) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
watch(isRef(value) ? value : () => value, () => {
|
|
542
|
+
this.setData({ [key]: deepToRaw(value) }, flushPostFlushCbs);
|
|
543
|
+
}, {
|
|
544
|
+
deep: true,
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
var PageLifecycle;
|
|
549
|
+
(function (PageLifecycle) {
|
|
550
|
+
PageLifecycle["ON_LOAD"] = "onLoad";
|
|
551
|
+
PageLifecycle["ON_SHOW"] = "onShow";
|
|
552
|
+
PageLifecycle["ON_READY"] = "onReady";
|
|
553
|
+
PageLifecycle["ON_HIDE"] = "onHide";
|
|
554
|
+
PageLifecycle["ON_UNLOAD"] = "onUnload";
|
|
555
|
+
PageLifecycle["ON_ROUTE_DONE"] = "onRouteDone";
|
|
556
|
+
PageLifecycle["ON_PULL_DOWN_REFRESH"] = "onPullDownRefresh";
|
|
557
|
+
PageLifecycle["ON_REACH_BOTTOM"] = "onReachBottom";
|
|
558
|
+
PageLifecycle["ON_PAGE_SCROLL"] = "onPageScroll";
|
|
559
|
+
PageLifecycle["ON_SHARE_APP_MESSAGE"] = "onShareAppMessage";
|
|
560
|
+
PageLifecycle["ON_SHARE_TIMELINE"] = "onShareTimeline";
|
|
561
|
+
PageLifecycle["ON_ADD_TO_FAVORITES"] = "onAddToFavorites";
|
|
562
|
+
PageLifecycle["ON_RESIZE"] = "onResize";
|
|
563
|
+
PageLifecycle["ON_TAB_ITEM_TAP"] = "onTabItemTap";
|
|
564
|
+
PageLifecycle["ON_SAVE_EXIT_STATE"] = "onSaveExitState";
|
|
565
|
+
})(PageLifecycle || (PageLifecycle = {}));
|
|
566
|
+
function definePage(optionsOrSetup, config) {
|
|
567
|
+
config = extend({
|
|
568
|
+
listenPageScroll: false,
|
|
569
|
+
canShareToOthers: false,
|
|
570
|
+
canShareToTimeline: false,
|
|
571
|
+
}, config);
|
|
572
|
+
let setup;
|
|
573
|
+
let options;
|
|
574
|
+
if (isFunction(optionsOrSetup)) {
|
|
575
|
+
setup = optionsOrSetup;
|
|
576
|
+
options = {};
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
if (optionsOrSetup.setup === undefined) {
|
|
580
|
+
// eslint-disable-next-line new-cap
|
|
581
|
+
Page(optionsOrSetup);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
setup = optionsOrSetup.setup;
|
|
585
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
586
|
+
}
|
|
587
|
+
const originOnLoad = options[PageLifecycle.ON_LOAD];
|
|
588
|
+
options[PageLifecycle.ON_LOAD] = function (query) {
|
|
589
|
+
this.__scope__ = new EffectScope();
|
|
590
|
+
setCurrentPage(this);
|
|
591
|
+
const context = {
|
|
592
|
+
is: this.is,
|
|
593
|
+
route: this.route,
|
|
594
|
+
options: this.options,
|
|
595
|
+
exitState: this.exitState,
|
|
596
|
+
router: this.router,
|
|
597
|
+
pageRouter: this.pageRouter,
|
|
598
|
+
renderer: this.renderer,
|
|
599
|
+
createSelectorQuery: this.createSelectorQuery.bind(this),
|
|
600
|
+
createIntersectionObserver: this.createIntersectionObserver.bind(this),
|
|
601
|
+
createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
|
|
602
|
+
selectComponent: this.selectComponent.bind(this),
|
|
603
|
+
selectAllComponents: this.selectAllComponents.bind(this),
|
|
604
|
+
getTabBar: this.getTabBar.bind(this),
|
|
605
|
+
getPageId: this.getPageId.bind(this),
|
|
606
|
+
animate: this.animate.bind(this),
|
|
607
|
+
clearAnimation: this.clearAnimation.bind(this),
|
|
608
|
+
getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
|
|
609
|
+
applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
|
|
610
|
+
clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
|
|
611
|
+
setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
|
|
612
|
+
getPassiveEvent: this.getPassiveEvent.bind(this),
|
|
613
|
+
setPassiveEvent: this.setPassiveEvent.bind(this),
|
|
614
|
+
};
|
|
615
|
+
const bindings = setup(query, context);
|
|
616
|
+
if (bindings !== undefined) {
|
|
617
|
+
Object.keys(bindings).forEach((key) => {
|
|
618
|
+
const value = bindings[key];
|
|
619
|
+
if (isFunction(value)) {
|
|
620
|
+
this[key] = value;
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
this.setData({ [key]: deepToRaw(value) });
|
|
624
|
+
deepWatch.call(this, key, value);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
unsetCurrentPage();
|
|
628
|
+
if (originOnLoad !== undefined) {
|
|
629
|
+
originOnLoad.call(this, query);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
const onUnload = createLifecycle$1(options, PageLifecycle.ON_UNLOAD);
|
|
633
|
+
options[PageLifecycle.ON_UNLOAD] = function () {
|
|
634
|
+
onUnload.call(this);
|
|
635
|
+
this.__scope__.stop();
|
|
636
|
+
};
|
|
637
|
+
if (options[PageLifecycle.ON_PAGE_SCROLL] || config.listenPageScroll) {
|
|
638
|
+
options[PageLifecycle.ON_PAGE_SCROLL] = createLifecycle$1(options, PageLifecycle.ON_PAGE_SCROLL);
|
|
639
|
+
/* istanbul ignore next -- @preserve */
|
|
640
|
+
options.__listenPageScroll__ = () => true;
|
|
641
|
+
}
|
|
642
|
+
if (options[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
|
|
643
|
+
config.canShareToOthers) {
|
|
644
|
+
options[PageLifecycle.ON_SHARE_APP_MESSAGE] = function (share) {
|
|
645
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE)];
|
|
646
|
+
if (hook) {
|
|
647
|
+
return hook(share);
|
|
648
|
+
}
|
|
649
|
+
return {};
|
|
650
|
+
};
|
|
651
|
+
/* istanbul ignore next -- @preserve */
|
|
652
|
+
options.__isInjectedShareToOthersHook__ = () => true;
|
|
653
|
+
}
|
|
654
|
+
if (options[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
|
|
655
|
+
config.canShareToTimeline) {
|
|
656
|
+
options[PageLifecycle.ON_SHARE_TIMELINE] = function () {
|
|
657
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_TIMELINE)];
|
|
658
|
+
if (hook) {
|
|
659
|
+
return hook();
|
|
660
|
+
}
|
|
661
|
+
return {};
|
|
662
|
+
};
|
|
663
|
+
/* istanbul ignore next -- @preserve */
|
|
664
|
+
options.__isInjectedShareToTimelineHook__ = () => true;
|
|
665
|
+
}
|
|
666
|
+
if (options[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
|
|
667
|
+
options[PageLifecycle.ON_ADD_TO_FAVORITES] = function (favorites) {
|
|
668
|
+
const hook = this[toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES)];
|
|
669
|
+
if (hook) {
|
|
670
|
+
return hook(favorites);
|
|
671
|
+
}
|
|
672
|
+
return {};
|
|
673
|
+
};
|
|
674
|
+
/* istanbul ignore next -- @preserve */
|
|
675
|
+
options.__isInjectedFavoritesHook__ = () => true;
|
|
676
|
+
}
|
|
677
|
+
if (options[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
|
|
678
|
+
options[PageLifecycle.ON_SAVE_EXIT_STATE] = function () {
|
|
679
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE)];
|
|
680
|
+
if (hook) {
|
|
681
|
+
return hook();
|
|
682
|
+
}
|
|
683
|
+
return { data: undefined };
|
|
684
|
+
};
|
|
685
|
+
/* istanbul ignore next -- @preserve */
|
|
686
|
+
options.__isInjectedExitStateHook__ = () => true;
|
|
687
|
+
}
|
|
688
|
+
options[PageLifecycle.ON_SHOW] = createLifecycle$1(options, PageLifecycle.ON_SHOW);
|
|
689
|
+
options[PageLifecycle.ON_READY] = createLifecycle$1(options, PageLifecycle.ON_READY);
|
|
690
|
+
options[PageLifecycle.ON_HIDE] = createLifecycle$1(options, PageLifecycle.ON_HIDE);
|
|
691
|
+
options[PageLifecycle.ON_ROUTE_DONE] = createLifecycle$1(options, PageLifecycle.ON_ROUTE_DONE);
|
|
692
|
+
options[PageLifecycle.ON_PULL_DOWN_REFRESH] = createLifecycle$1(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
693
|
+
options[PageLifecycle.ON_REACH_BOTTOM] = createLifecycle$1(options, PageLifecycle.ON_REACH_BOTTOM);
|
|
694
|
+
options[PageLifecycle.ON_RESIZE] = createLifecycle$1(options, PageLifecycle.ON_RESIZE);
|
|
695
|
+
options[PageLifecycle.ON_TAB_ITEM_TAP] = createLifecycle$1(options, PageLifecycle.ON_TAB_ITEM_TAP);
|
|
696
|
+
// eslint-disable-next-line new-cap
|
|
697
|
+
Page(options);
|
|
698
|
+
}
|
|
699
|
+
function createLifecycle$1(options, lifecycle) {
|
|
700
|
+
const originLifecycle = options[lifecycle];
|
|
701
|
+
return function (...args) {
|
|
702
|
+
const hooks = this[toHiddenField(lifecycle)];
|
|
703
|
+
if (hooks) {
|
|
704
|
+
hooks.forEach((hook) => hook(...args));
|
|
705
|
+
}
|
|
706
|
+
if (originLifecycle !== undefined) {
|
|
707
|
+
originLifecycle.call(this, ...args);
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
var ComponentLifecycle;
|
|
713
|
+
(function (ComponentLifecycle) {
|
|
714
|
+
ComponentLifecycle["ATTACHED"] = "attached";
|
|
715
|
+
ComponentLifecycle["READY"] = "ready";
|
|
716
|
+
ComponentLifecycle["MOVED"] = "moved";
|
|
717
|
+
ComponentLifecycle["DETACHED"] = "detached";
|
|
718
|
+
ComponentLifecycle["ERROR"] = "error";
|
|
719
|
+
})(ComponentLifecycle || (ComponentLifecycle = {}));
|
|
720
|
+
const SpecialLifecycleMap = {
|
|
721
|
+
[PageLifecycle.ON_SHOW]: 'show',
|
|
722
|
+
[PageLifecycle.ON_HIDE]: 'hide',
|
|
723
|
+
[PageLifecycle.ON_RESIZE]: 'resize',
|
|
724
|
+
[PageLifecycle.ON_ROUTE_DONE]: 'routeDone',
|
|
725
|
+
[ComponentLifecycle.READY]: PageLifecycle.ON_READY,
|
|
726
|
+
};
|
|
727
|
+
function defineComponent(optionsOrSetup, config) {
|
|
728
|
+
config = extend({
|
|
729
|
+
listenPageScroll: false,
|
|
730
|
+
canShareToOthers: false,
|
|
731
|
+
canShareToTimeline: false,
|
|
732
|
+
}, config);
|
|
733
|
+
let setup;
|
|
734
|
+
let options;
|
|
735
|
+
let properties = null;
|
|
736
|
+
if (isFunction(optionsOrSetup)) {
|
|
737
|
+
setup = optionsOrSetup;
|
|
738
|
+
options = {};
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
if (optionsOrSetup.setup === undefined) {
|
|
742
|
+
// eslint-disable-next-line new-cap
|
|
743
|
+
return Component(optionsOrSetup);
|
|
744
|
+
}
|
|
745
|
+
setup = optionsOrSetup.setup;
|
|
746
|
+
options = exclude(optionsOrSetup, ['setup']);
|
|
747
|
+
if (options.properties) {
|
|
748
|
+
properties = Object.keys(options.properties);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (options.lifetimes === undefined) {
|
|
752
|
+
options.lifetimes = {};
|
|
753
|
+
}
|
|
754
|
+
const originAttached = options.lifetimes[ComponentLifecycle.ATTACHED] ||
|
|
755
|
+
options[ComponentLifecycle.ATTACHED];
|
|
756
|
+
options.lifetimes[ComponentLifecycle.ATTACHED] = function () {
|
|
757
|
+
this.__scope__ = new EffectScope();
|
|
758
|
+
setCurrentComponent(this);
|
|
759
|
+
const rawProps = {};
|
|
760
|
+
if (properties) {
|
|
761
|
+
properties.forEach((property) => {
|
|
762
|
+
rawProps[property] = this.data[property];
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
this.__props__ = shallowReactive(rawProps);
|
|
766
|
+
const context = {
|
|
767
|
+
is: this.is,
|
|
768
|
+
id: this.id,
|
|
769
|
+
dataset: this.dataset,
|
|
770
|
+
exitState: this.exitState,
|
|
771
|
+
router: this.router,
|
|
772
|
+
pageRouter: this.pageRouter,
|
|
773
|
+
renderer: this.renderer,
|
|
774
|
+
triggerEvent: this.triggerEvent.bind(this),
|
|
775
|
+
createSelectorQuery: this.createSelectorQuery.bind(this),
|
|
776
|
+
createIntersectionObserver: this.createIntersectionObserver.bind(this),
|
|
777
|
+
createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
|
|
778
|
+
selectComponent: this.selectComponent.bind(this),
|
|
779
|
+
selectAllComponents: this.selectAllComponents.bind(this),
|
|
780
|
+
selectOwnerComponent: this.selectOwnerComponent.bind(this),
|
|
781
|
+
getRelationNodes: this.getRelationNodes.bind(this),
|
|
782
|
+
getTabBar: this.getTabBar.bind(this),
|
|
783
|
+
getPageId: this.getPageId.bind(this),
|
|
784
|
+
animate: this.animate.bind(this),
|
|
785
|
+
clearAnimation: this.clearAnimation.bind(this),
|
|
786
|
+
getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
|
|
787
|
+
applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
|
|
788
|
+
clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
|
|
789
|
+
setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
|
|
790
|
+
getPassiveEvent: this.getPassiveEvent.bind(this),
|
|
791
|
+
setPassiveEvent: this.setPassiveEvent.bind(this),
|
|
792
|
+
};
|
|
793
|
+
const bindings = setup((process.env.NODE_ENV !== 'production') ?
|
|
794
|
+
shallowReadonly(this.__props__)
|
|
795
|
+
: /* istanbul ignore next -- @preserve */ this.__props__, context);
|
|
796
|
+
if (bindings !== undefined) {
|
|
797
|
+
Object.keys(bindings).forEach((key) => {
|
|
798
|
+
const value = bindings[key];
|
|
799
|
+
if (isFunction(value)) {
|
|
800
|
+
this[key] = value;
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
this.setData({ [key]: deepToRaw(value) });
|
|
804
|
+
deepWatch.call(this, key, value);
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
unsetCurrentComponent();
|
|
808
|
+
if (originAttached !== undefined) {
|
|
809
|
+
originAttached.call(this);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
const detached = createComponentLifecycle(options, ComponentLifecycle.DETACHED);
|
|
813
|
+
options.lifetimes[ComponentLifecycle.DETACHED] = function () {
|
|
814
|
+
detached.call(this);
|
|
815
|
+
this.__scope__.stop();
|
|
816
|
+
};
|
|
817
|
+
const originReady = options.lifetimes[ComponentLifecycle.READY] ||
|
|
818
|
+
options[ComponentLifecycle.READY];
|
|
819
|
+
options.lifetimes[ComponentLifecycle.READY] = createLifecycle(SpecialLifecycleMap[ComponentLifecycle.READY], originReady);
|
|
820
|
+
options.lifetimes[ComponentLifecycle.MOVED] = createComponentLifecycle(options, ComponentLifecycle.MOVED);
|
|
821
|
+
options.lifetimes[ComponentLifecycle.ERROR] = createComponentLifecycle(options, ComponentLifecycle.ERROR);
|
|
822
|
+
if (options.methods === undefined) {
|
|
823
|
+
options.methods = {};
|
|
824
|
+
}
|
|
825
|
+
if (options.methods[PageLifecycle.ON_PAGE_SCROLL] ||
|
|
826
|
+
config.listenPageScroll) {
|
|
827
|
+
options.methods[PageLifecycle.ON_PAGE_SCROLL] = createPageLifecycle(options, PageLifecycle.ON_PAGE_SCROLL);
|
|
828
|
+
/* istanbul ignore next -- @preserve */
|
|
829
|
+
options.methods.__listenPageScroll__ = () => true;
|
|
830
|
+
}
|
|
831
|
+
if (options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
|
|
832
|
+
config.canShareToOthers) {
|
|
833
|
+
options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] = function (share) {
|
|
834
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE)];
|
|
835
|
+
if (hook) {
|
|
836
|
+
return hook(share);
|
|
837
|
+
}
|
|
838
|
+
return {};
|
|
839
|
+
};
|
|
840
|
+
/* istanbul ignore next -- @preserve */
|
|
841
|
+
options.methods.__isInjectedShareToOthersHook__ = () => true;
|
|
842
|
+
}
|
|
843
|
+
if (options.methods[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
|
|
844
|
+
config.canShareToTimeline) {
|
|
845
|
+
options.methods[PageLifecycle.ON_SHARE_TIMELINE] = function () {
|
|
846
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SHARE_TIMELINE)];
|
|
847
|
+
if (hook) {
|
|
848
|
+
return hook();
|
|
849
|
+
}
|
|
850
|
+
return {};
|
|
851
|
+
};
|
|
852
|
+
/* istanbul ignore next -- @preserve */
|
|
853
|
+
options.methods.__isInjectedShareToTimelineHook__ = () => true;
|
|
854
|
+
}
|
|
855
|
+
if (options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
|
|
856
|
+
options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] = function (favorites) {
|
|
857
|
+
const hook = this[toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES)];
|
|
858
|
+
if (hook) {
|
|
859
|
+
return hook(favorites);
|
|
860
|
+
}
|
|
861
|
+
return {};
|
|
862
|
+
};
|
|
863
|
+
/* istanbul ignore next -- @preserve */
|
|
864
|
+
options.methods.__isInjectedFavoritesHook__ = () => true;
|
|
865
|
+
}
|
|
866
|
+
if (options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
|
|
867
|
+
options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] = function () {
|
|
868
|
+
const hook = this[toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE)];
|
|
869
|
+
if (hook) {
|
|
870
|
+
return hook();
|
|
871
|
+
}
|
|
872
|
+
return { data: undefined };
|
|
873
|
+
};
|
|
874
|
+
/* istanbul ignore next -- @preserve */
|
|
875
|
+
options.methods.__isInjectedExitStateHook__ = () => true;
|
|
876
|
+
}
|
|
877
|
+
options.methods[PageLifecycle.ON_LOAD] = createPageLifecycle(options, PageLifecycle.ON_LOAD);
|
|
878
|
+
options.methods[PageLifecycle.ON_PULL_DOWN_REFRESH] = createPageLifecycle(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
879
|
+
options.methods[PageLifecycle.ON_REACH_BOTTOM] = createPageLifecycle(options, PageLifecycle.ON_REACH_BOTTOM);
|
|
880
|
+
options.methods[PageLifecycle.ON_TAB_ITEM_TAP] = createPageLifecycle(options, PageLifecycle.ON_TAB_ITEM_TAP);
|
|
881
|
+
if (options.pageLifetimes === undefined) {
|
|
882
|
+
options.pageLifetimes = {};
|
|
883
|
+
}
|
|
884
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_SHOW]] =
|
|
885
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_SHOW);
|
|
886
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_HIDE]] =
|
|
887
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_HIDE);
|
|
888
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_RESIZE]] =
|
|
889
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_RESIZE);
|
|
890
|
+
options.pageLifetimes[SpecialLifecycleMap[PageLifecycle.ON_ROUTE_DONE]] =
|
|
891
|
+
createSpecialPageLifecycle(options, PageLifecycle.ON_ROUTE_DONE);
|
|
892
|
+
if (properties) {
|
|
893
|
+
if (options.observers === undefined) {
|
|
894
|
+
options.observers = {};
|
|
895
|
+
}
|
|
896
|
+
properties.forEach((property) => {
|
|
897
|
+
const originObserver = options.observers[property];
|
|
898
|
+
options.observers[property] = function (value) {
|
|
899
|
+
// Observer executes before attached
|
|
900
|
+
if (this.__props__) {
|
|
901
|
+
this.__props__[property] = value;
|
|
902
|
+
}
|
|
903
|
+
if (originObserver !== undefined) {
|
|
904
|
+
originObserver.call(this, value);
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
// eslint-disable-next-line new-cap
|
|
910
|
+
return Component(options);
|
|
911
|
+
}
|
|
912
|
+
function createComponentLifecycle(options, lifecycle) {
|
|
913
|
+
const originLifecycle = options.lifetimes[lifecycle] || options[lifecycle];
|
|
914
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
915
|
+
}
|
|
916
|
+
function createPageLifecycle(options, lifecycle) {
|
|
917
|
+
const originLifecycle = options.methods[lifecycle];
|
|
918
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
919
|
+
}
|
|
920
|
+
function createSpecialPageLifecycle(options, lifecycle) {
|
|
921
|
+
const originLifecycle = options.pageLifetimes[SpecialLifecycleMap[lifecycle]];
|
|
922
|
+
return createLifecycle(lifecycle, originLifecycle);
|
|
923
|
+
}
|
|
924
|
+
function createLifecycle(lifecycle, originLifecycle) {
|
|
925
|
+
const hiddenField = toHiddenField(lifecycle);
|
|
926
|
+
return function (...args) {
|
|
927
|
+
const hooks = this[hiddenField];
|
|
928
|
+
if (hooks) {
|
|
929
|
+
hooks.forEach((hook) => hook(...args));
|
|
930
|
+
}
|
|
931
|
+
if (originLifecycle !== undefined) {
|
|
932
|
+
originLifecycle.call(this, ...args);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
const pageHookWarn = 'Page specific lifecycle injection APIs can only be used during execution of setup() in definePage() or defineComponent().';
|
|
938
|
+
const onAppShow = createAppHook(AppLifecycle.ON_SHOW);
|
|
939
|
+
const onAppHide = createAppHook(AppLifecycle.ON_HIDE);
|
|
940
|
+
const onAppError = createAppHook(AppLifecycle.ON_ERROR);
|
|
941
|
+
const onPageNotFound = createAppHook(AppLifecycle.ON_PAGE_NOT_FOUND);
|
|
942
|
+
const onUnhandledRejection = createAppHook(AppLifecycle.ON_UNHANDLED_REJECTION);
|
|
943
|
+
const onThemeChange = createAppHook(AppLifecycle.ON_THEME_CHANGE);
|
|
944
|
+
const onShow = createPageHook(PageLifecycle.ON_SHOW);
|
|
945
|
+
const onHide = createPageHook(PageLifecycle.ON_HIDE);
|
|
946
|
+
const onUnload = createPageHook(PageLifecycle.ON_UNLOAD);
|
|
947
|
+
const onRouteDone = createPageHook(PageLifecycle.ON_ROUTE_DONE);
|
|
948
|
+
const onPullDownRefresh = createPageHook(PageLifecycle.ON_PULL_DOWN_REFRESH);
|
|
949
|
+
const onReachBottom = createPageHook(PageLifecycle.ON_REACH_BOTTOM);
|
|
950
|
+
const onResize = createPageHook(PageLifecycle.ON_RESIZE);
|
|
951
|
+
const onTabItemTap = createPageHook(PageLifecycle.ON_TAB_ITEM_TAP);
|
|
952
|
+
const onPageScroll = (hook) => {
|
|
953
|
+
const currentInstance = getCurrentInstance();
|
|
954
|
+
/* istanbul ignore else -- @preserve */
|
|
955
|
+
if (currentInstance) {
|
|
956
|
+
/* istanbul ignore else -- @preserve */
|
|
957
|
+
if (currentInstance.__listenPageScroll__) {
|
|
958
|
+
injectHook(currentInstance, PageLifecycle.ON_PAGE_SCROLL, hook);
|
|
959
|
+
}
|
|
960
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
961
|
+
console.warn('onPageScroll() hook only works when `listenPageScroll` is configured to true.');
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
965
|
+
console.warn(pageHookWarn);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
const onShareAppMessage = (hook) => {
|
|
969
|
+
const currentInstance = getCurrentInstance();
|
|
970
|
+
/* istanbul ignore else -- @preserve */
|
|
971
|
+
if (currentInstance) {
|
|
972
|
+
/* istanbul ignore else -- @preserve */
|
|
973
|
+
if (currentInstance[PageLifecycle.ON_SHARE_APP_MESSAGE] &&
|
|
974
|
+
currentInstance.__isInjectedShareToOthersHook__) {
|
|
975
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SHARE_APP_MESSAGE);
|
|
976
|
+
/* istanbul ignore else -- @preserve */
|
|
977
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
978
|
+
currentInstance[hiddenField] = hook;
|
|
979
|
+
}
|
|
980
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
981
|
+
console.warn('onShareAppMessage() hook can only be called once.');
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
985
|
+
console.warn('onShareAppMessage() hook only works when `onShareAppMessage` option is not exist and `canShareToOthers` is configured to true.');
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
989
|
+
console.warn(pageHookWarn);
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
const onShareTimeline = (hook) => {
|
|
993
|
+
const currentInstance = getCurrentInstance();
|
|
994
|
+
/* istanbul ignore else -- @preserve */
|
|
995
|
+
if (currentInstance) {
|
|
996
|
+
/* istanbul ignore else -- @preserve */
|
|
997
|
+
if (currentInstance[PageLifecycle.ON_SHARE_TIMELINE] &&
|
|
998
|
+
currentInstance.__isInjectedShareToTimelineHook__) {
|
|
999
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SHARE_TIMELINE);
|
|
1000
|
+
/* istanbul ignore else -- @preserve */
|
|
1001
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
1002
|
+
currentInstance[hiddenField] = hook;
|
|
1003
|
+
}
|
|
1004
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1005
|
+
console.warn('onShareTimeline() hook can only be called once.');
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1009
|
+
console.warn('onShareTimeline() hook only works when `onShareTimeline` option is not exist and `canShareToTimeline` is configured to true.');
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1013
|
+
console.warn(pageHookWarn);
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
const onAddToFavorites = (hook) => {
|
|
1017
|
+
const currentInstance = getCurrentInstance();
|
|
1018
|
+
/* istanbul ignore else -- @preserve */
|
|
1019
|
+
if (currentInstance) {
|
|
1020
|
+
/* istanbul ignore else -- @preserve */
|
|
1021
|
+
if (currentInstance.__isInjectedFavoritesHook__) {
|
|
1022
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_ADD_TO_FAVORITES);
|
|
1023
|
+
/* istanbul ignore else -- @preserve */
|
|
1024
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
1025
|
+
currentInstance[hiddenField] = hook;
|
|
1026
|
+
}
|
|
1027
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1028
|
+
console.warn('onAddToFavorites() hook can only be called once.');
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1032
|
+
console.warn('onAddToFavorites() hook only works when `onAddToFavorites` option is not exist.');
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1036
|
+
console.warn(pageHookWarn);
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
const onSaveExitState = (hook) => {
|
|
1040
|
+
const currentInstance = getCurrentInstance();
|
|
1041
|
+
/* istanbul ignore else -- @preserve */
|
|
1042
|
+
if (currentInstance) {
|
|
1043
|
+
/* istanbul ignore else -- @preserve */
|
|
1044
|
+
if (currentInstance.__isInjectedExitStateHook__) {
|
|
1045
|
+
const hiddenField = toHiddenField(PageLifecycle.ON_SAVE_EXIT_STATE);
|
|
1046
|
+
/* istanbul ignore else -- @preserve */
|
|
1047
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
1048
|
+
currentInstance[hiddenField] = hook;
|
|
1049
|
+
}
|
|
1050
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1051
|
+
console.warn('onSaveExitState() hook can only be called once.');
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1055
|
+
console.warn('onSaveExitState() hook only works when `onSaveExitState` option is not exist.');
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1059
|
+
console.warn(pageHookWarn);
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
const onReady = (hook) => {
|
|
1063
|
+
const currentInstance = getCurrentInstance();
|
|
1064
|
+
/* istanbul ignore else -- @preserve */
|
|
1065
|
+
if (currentInstance) {
|
|
1066
|
+
injectHook(currentInstance, PageLifecycle.ON_READY, hook);
|
|
1067
|
+
}
|
|
1068
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1069
|
+
console.warn('onReady() hook can only be called during execution of setup() in definePage() or defineComponent().');
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
const onLoad = createComponentHook(PageLifecycle.ON_LOAD);
|
|
1073
|
+
const onMove = createComponentHook(ComponentLifecycle.MOVED);
|
|
1074
|
+
const onDetach = createComponentHook(ComponentLifecycle.DETACHED);
|
|
1075
|
+
const onError = createComponentHook(ComponentLifecycle.ERROR);
|
|
1076
|
+
function createAppHook(lifecycle) {
|
|
1077
|
+
return (hook) => {
|
|
1078
|
+
/* istanbul ignore else -- @preserve */
|
|
1079
|
+
if (currentApp) {
|
|
1080
|
+
injectHook(currentApp, lifecycle, hook);
|
|
1081
|
+
}
|
|
1082
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1083
|
+
console.warn('App specific lifecycle injection APIs can only be used during execution of setup() in createApp().');
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
function createPageHook(lifecycle) {
|
|
1088
|
+
return (hook) => {
|
|
1089
|
+
const currentInstance = getCurrentInstance();
|
|
1090
|
+
/* istanbul ignore else -- @preserve */
|
|
1091
|
+
if (currentInstance) {
|
|
1092
|
+
injectHook(currentInstance, lifecycle, hook);
|
|
1093
|
+
}
|
|
1094
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1095
|
+
console.warn(pageHookWarn);
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
function createComponentHook(lifecycle) {
|
|
1100
|
+
return (hook) => {
|
|
1101
|
+
/* istanbul ignore else -- @preserve */
|
|
1102
|
+
if (currentComponent) {
|
|
1103
|
+
injectHook(currentComponent, lifecycle, hook);
|
|
1104
|
+
}
|
|
1105
|
+
else if ((process.env.NODE_ENV !== 'production')) {
|
|
1106
|
+
console.warn('Component specific lifecycle injection APIs can only be used during execution of setup() in defineComponent().');
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function injectHook(currentInstance, lifecycle, hook) {
|
|
1111
|
+
const hiddenField = toHiddenField(lifecycle);
|
|
1112
|
+
if (currentInstance[hiddenField] === undefined) {
|
|
1113
|
+
currentInstance[hiddenField] = [];
|
|
1114
|
+
}
|
|
1115
|
+
currentInstance[hiddenField].push(hook);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
export { createApp, defineComponent, definePage, inject, nextTick, onAddToFavorites, onAppError, onAppHide, onAppShow, onDetach, onError, onHide, onLoad, onMove, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onResize, onRouteDone, onSaveExitState, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, provide, watch, watchEffect, watchPostEffect, watchSyncEffect };
|