@dcloudio/uni-quickapp-webview 0.0.1-nvue3.3030820220125001

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.
@@ -0,0 +1,1129 @@
1
+ import { camelize, isPlainObject, isArray, hasOwn, isFunction, extend, isObject } from '@vue/shared';
2
+ import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
3
+
4
+ const ON_READY$1 = 'onReady';
5
+
6
+ class EventChannel$1 {
7
+ constructor(id, events) {
8
+ this.id = id;
9
+ this.listener = {};
10
+ this.emitCache = {};
11
+ if (events) {
12
+ Object.keys(events).forEach((name) => {
13
+ this.on(name, events[name]);
14
+ });
15
+ }
16
+ }
17
+ emit(eventName, ...args) {
18
+ const fns = this.listener[eventName];
19
+ if (!fns) {
20
+ return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args);
21
+ }
22
+ fns.forEach((opt) => {
23
+ opt.fn.apply(opt.fn, args);
24
+ });
25
+ this.listener[eventName] = fns.filter((opt) => opt.type !== 'once');
26
+ }
27
+ on(eventName, fn) {
28
+ this._addListener(eventName, 'on', fn);
29
+ this._clearCache(eventName);
30
+ }
31
+ once(eventName, fn) {
32
+ this._addListener(eventName, 'once', fn);
33
+ this._clearCache(eventName);
34
+ }
35
+ off(eventName, fn) {
36
+ const fns = this.listener[eventName];
37
+ if (!fns) {
38
+ return;
39
+ }
40
+ if (fn) {
41
+ for (let i = 0; i < fns.length;) {
42
+ if (fns[i].fn === fn) {
43
+ fns.splice(i, 1);
44
+ i--;
45
+ }
46
+ i++;
47
+ }
48
+ }
49
+ else {
50
+ delete this.listener[eventName];
51
+ }
52
+ }
53
+ _clearCache(eventName) {
54
+ const cacheArgs = this.emitCache[eventName];
55
+ if (cacheArgs) {
56
+ for (; cacheArgs.length > 0;) {
57
+ this.emit.apply(this, [eventName, ...cacheArgs.shift()]);
58
+ }
59
+ }
60
+ }
61
+ _addListener(eventName, type, fn) {
62
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({
63
+ fn,
64
+ type,
65
+ });
66
+ }
67
+ }
68
+
69
+ // quickapp-webview 不能使用 default 作为插槽名称
70
+ const SLOT_DEFAULT_NAME = 'd';
71
+ // lifecycle
72
+ // App and Page
73
+ const ON_SHOW = 'onShow';
74
+ const ON_HIDE = 'onHide';
75
+ //App
76
+ const ON_LAUNCH = 'onLaunch';
77
+ const ON_ERROR = 'onError';
78
+ const ON_THEME_CHANGE = 'onThemeChange';
79
+ const ON_PAGE_NOT_FOUND = 'onPageNotFound';
80
+ const ON_UNHANDLE_REJECTION = 'onUnhandledRejection';
81
+ //Page
82
+ const ON_LOAD = 'onLoad';
83
+ const ON_READY = 'onReady';
84
+ const ON_UNLOAD = 'onUnload';
85
+ const ON_RESIZE = 'onResize';
86
+ const ON_TAB_ITEM_TAP = 'onTabItemTap';
87
+ const ON_REACH_BOTTOM = 'onReachBottom';
88
+ const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
89
+ const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
90
+
91
+ const customizeRE = /:/g;
92
+ function customizeEvent(str) {
93
+ return camelize(str.replace(customizeRE, '-'));
94
+ }
95
+
96
+ const encode = encodeURIComponent;
97
+ function stringifyQuery(obj, encodeStr = encode) {
98
+ const res = obj
99
+ ? Object.keys(obj)
100
+ .map((key) => {
101
+ let val = obj[key];
102
+ if (typeof val === undefined || val === null) {
103
+ val = '';
104
+ }
105
+ else if (isPlainObject(val)) {
106
+ val = JSON.stringify(val);
107
+ }
108
+ return encodeStr(key) + '=' + encodeStr(val);
109
+ })
110
+ .filter((x) => x.length > 0)
111
+ .join('&')
112
+ : null;
113
+ return res ? `?${res}` : '';
114
+ }
115
+
116
+ function hasLeadingSlash(str) {
117
+ return str.indexOf('/') === 0;
118
+ }
119
+ function addLeadingSlash(str) {
120
+ return hasLeadingSlash(str) ? str : '/' + str;
121
+ }
122
+ const invokeArrayFns = (fns, arg) => {
123
+ let ret;
124
+ for (let i = 0; i < fns.length; i++) {
125
+ ret = fns[i](arg);
126
+ }
127
+ return ret;
128
+ };
129
+
130
+ class EventChannel {
131
+ constructor(id, events) {
132
+ this.id = id;
133
+ this.listener = {};
134
+ this.emitCache = {};
135
+ if (events) {
136
+ Object.keys(events).forEach((name) => {
137
+ this.on(name, events[name]);
138
+ });
139
+ }
140
+ }
141
+ emit(eventName, ...args) {
142
+ const fns = this.listener[eventName];
143
+ if (!fns) {
144
+ return (this.emitCache[eventName] || (this.emitCache[eventName] = [])).push(args);
145
+ }
146
+ fns.forEach((opt) => {
147
+ opt.fn.apply(opt.fn, args);
148
+ });
149
+ this.listener[eventName] = fns.filter((opt) => opt.type !== 'once');
150
+ }
151
+ on(eventName, fn) {
152
+ this._addListener(eventName, 'on', fn);
153
+ this._clearCache(eventName);
154
+ }
155
+ once(eventName, fn) {
156
+ this._addListener(eventName, 'once', fn);
157
+ this._clearCache(eventName);
158
+ }
159
+ off(eventName, fn) {
160
+ const fns = this.listener[eventName];
161
+ if (!fns) {
162
+ return;
163
+ }
164
+ if (fn) {
165
+ for (let i = 0; i < fns.length;) {
166
+ if (fns[i].fn === fn) {
167
+ fns.splice(i, 1);
168
+ i--;
169
+ }
170
+ i++;
171
+ }
172
+ }
173
+ else {
174
+ delete this.listener[eventName];
175
+ }
176
+ }
177
+ _clearCache(eventName) {
178
+ const cacheArgs = this.emitCache[eventName];
179
+ if (cacheArgs) {
180
+ for (; cacheArgs.length > 0;) {
181
+ this.emit.apply(this, [eventName, ...cacheArgs.shift()]);
182
+ }
183
+ }
184
+ }
185
+ _addListener(eventName, type, fn) {
186
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({
187
+ fn,
188
+ type,
189
+ });
190
+ }
191
+ }
192
+
193
+ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = {
194
+ onPageScroll: 1,
195
+ onShareAppMessage: 1 << 1,
196
+ onShareTimeline: 1 << 2,
197
+ };
198
+
199
+ const eventChannels = {};
200
+ const eventChannelStack = [];
201
+ function getEventChannel(id) {
202
+ if (id) {
203
+ const eventChannel = eventChannels[id];
204
+ delete eventChannels[id];
205
+ return eventChannel;
206
+ }
207
+ return eventChannelStack.shift();
208
+ }
209
+
210
+ const MP_METHODS = [
211
+ 'createSelectorQuery',
212
+ 'createIntersectionObserver',
213
+ 'selectAllComponents',
214
+ 'selectComponent',
215
+ ];
216
+ function createEmitFn(oldEmit, ctx) {
217
+ return function emit(event, ...args) {
218
+ const scope = ctx.$scope;
219
+ if (scope && event) {
220
+ const detail = { __args__: args };
221
+ {
222
+ scope.triggerEvent(event, detail);
223
+ }
224
+ }
225
+ return oldEmit.apply(this, [event, ...args]);
226
+ };
227
+ }
228
+ function initBaseInstance(instance, options) {
229
+ const ctx = instance.ctx;
230
+ // mp
231
+ ctx.mpType = options.mpType; // @deprecated
232
+ ctx.$mpType = options.mpType;
233
+ ctx.$mpPlatform = "quickapp-webview";
234
+ ctx.$scope = options.mpInstance;
235
+ // TODO @deprecated
236
+ ctx.$mp = {};
237
+ if (__VUE_OPTIONS_API__) {
238
+ ctx._self = {};
239
+ }
240
+ // slots
241
+ instance.slots = {};
242
+ if (isArray(options.slots) && options.slots.length) {
243
+ options.slots.forEach((name) => {
244
+ instance.slots[name] = true;
245
+ });
246
+ if (instance.slots[SLOT_DEFAULT_NAME]) {
247
+ instance.slots.default = true;
248
+ }
249
+ }
250
+ ctx.getOpenerEventChannel = function () {
251
+ if (!this.__eventChannel__) {
252
+ this.__eventChannel__ = new EventChannel();
253
+ }
254
+ return this.__eventChannel__;
255
+ };
256
+ ctx.$hasHook = hasHook;
257
+ ctx.$callHook = callHook;
258
+ // $emit
259
+ instance.emit = createEmitFn(instance.emit, ctx);
260
+ }
261
+ function initComponentInstance(instance, options) {
262
+ initBaseInstance(instance, options);
263
+ const ctx = instance.ctx;
264
+ MP_METHODS.forEach((method) => {
265
+ ctx[method] = function (...args) {
266
+ const mpInstance = ctx.$scope;
267
+ if (mpInstance && mpInstance[method]) {
268
+ return mpInstance[method].apply(mpInstance, args);
269
+ }
270
+ };
271
+ });
272
+ }
273
+ function initMocks(instance, mpInstance, mocks) {
274
+ const ctx = instance.ctx;
275
+ mocks.forEach((mock) => {
276
+ if (hasOwn(mpInstance, mock)) {
277
+ instance[mock] = ctx[mock] = mpInstance[mock];
278
+ }
279
+ });
280
+ }
281
+ function hasHook(name) {
282
+ const hooks = this.$[name];
283
+ if (hooks && hooks.length) {
284
+ return true;
285
+ }
286
+ return false;
287
+ }
288
+ function callHook(name, args) {
289
+ if (name === 'mounted') {
290
+ callHook.call(this, 'bm'); // beforeMount
291
+ this.$.isMounted = true;
292
+ name = 'm';
293
+ }
294
+ else if (name === 'onLoad' && args && args.__id__) {
295
+ this.__eventChannel__ = getEventChannel(args.__id__);
296
+ delete args.__id__;
297
+ }
298
+ const hooks = this.$[name];
299
+ return hooks && invokeArrayFns(hooks, args);
300
+ }
301
+
302
+ const PAGE_INIT_HOOKS = [
303
+ ON_LOAD,
304
+ ON_SHOW,
305
+ ON_HIDE,
306
+ ON_UNLOAD,
307
+ ON_RESIZE,
308
+ ON_TAB_ITEM_TAP,
309
+ ON_REACH_BOTTOM,
310
+ ON_PULL_DOWN_REFRESH,
311
+ ON_ADD_TO_FAVORITES,
312
+ // 'onReady', // lifetimes.ready
313
+ // 'onPageScroll', // 影响性能,开发者手动注册
314
+ // 'onShareTimeline', // 右上角菜单,开发者手动注册
315
+ // 'onShareAppMessage' // 右上角菜单,开发者手动注册
316
+ ];
317
+ function findHooks(vueOptions, hooks = new Set()) {
318
+ if (vueOptions) {
319
+ Object.keys(vueOptions).forEach((name) => {
320
+ if (name.indexOf('on') === 0 && isFunction(vueOptions[name])) {
321
+ hooks.add(name);
322
+ }
323
+ });
324
+ if (__VUE_OPTIONS_API__) {
325
+ const { extends: extendsOptions, mixins } = vueOptions;
326
+ if (mixins) {
327
+ mixins.forEach((mixin) => findHooks(mixin, hooks));
328
+ }
329
+ if (extendsOptions) {
330
+ findHooks(extendsOptions, hooks);
331
+ }
332
+ }
333
+ }
334
+ return hooks;
335
+ }
336
+ function initHook$1(mpOptions, hook, excludes) {
337
+ if (excludes.indexOf(hook) === -1 && !hasOwn(mpOptions, hook)) {
338
+ mpOptions[hook] = function (args) {
339
+ return this.$vm && this.$vm.$callHook(hook, args);
340
+ };
341
+ }
342
+ }
343
+ const EXCLUDE_HOOKS = [ON_READY];
344
+ function initHooks(mpOptions, hooks, excludes = EXCLUDE_HOOKS) {
345
+ hooks.forEach((hook) => initHook$1(mpOptions, hook, excludes));
346
+ }
347
+ function initUnknownHooks(mpOptions, vueOptions, excludes = EXCLUDE_HOOKS) {
348
+ findHooks(vueOptions).forEach((hook) => initHook$1(mpOptions, hook, excludes));
349
+ }
350
+ function initRuntimeHooks(mpOptions, runtimeHooks) {
351
+ if (!runtimeHooks) {
352
+ return;
353
+ }
354
+ const hooks = Object.keys(MINI_PROGRAM_PAGE_RUNTIME_HOOKS);
355
+ hooks.forEach((hook) => {
356
+ if (runtimeHooks & MINI_PROGRAM_PAGE_RUNTIME_HOOKS[hook]) {
357
+ initHook$1(mpOptions, hook, []);
358
+ }
359
+ });
360
+ }
361
+
362
+ qa.appLaunchHooks = [];
363
+ function injectAppLaunchHooks(appInstance) {
364
+ qa.appLaunchHooks.forEach((hook) => {
365
+ injectHook(ON_LAUNCH, hook, appInstance);
366
+ });
367
+ }
368
+
369
+ const HOOKS = [
370
+ ON_SHOW,
371
+ ON_HIDE,
372
+ ON_ERROR,
373
+ ON_THEME_CHANGE,
374
+ ON_PAGE_NOT_FOUND,
375
+ ON_UNHANDLE_REJECTION,
376
+ ];
377
+ function parseApp(instance, parseAppOptions) {
378
+ const internalInstance = instance.$;
379
+ const appOptions = {
380
+ globalData: (instance.$options && instance.$options.globalData) || {},
381
+ $vm: instance,
382
+ onLaunch(options) {
383
+ const ctx = internalInstance.ctx;
384
+ if (this.$vm && ctx.$scope) {
385
+ // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
386
+ return;
387
+ }
388
+ initBaseInstance(internalInstance, {
389
+ mpType: 'app',
390
+ mpInstance: this,
391
+ slots: [],
392
+ });
393
+ injectAppLaunchHooks(internalInstance);
394
+ ctx.globalData = this.globalData;
395
+ instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
396
+ },
397
+ };
398
+ initLocale(instance);
399
+ const vueOptions = instance.$.type;
400
+ initHooks(appOptions, HOOKS);
401
+ initUnknownHooks(appOptions, vueOptions);
402
+ if (__VUE_OPTIONS_API__) {
403
+ const methods = vueOptions.methods;
404
+ methods && extend(appOptions, methods);
405
+ }
406
+ if (parseAppOptions) {
407
+ parseAppOptions.parse(appOptions);
408
+ }
409
+ return appOptions;
410
+ }
411
+ function initCreateApp(parseAppOptions) {
412
+ return function createApp(vm) {
413
+ return App(parseApp(vm, parseAppOptions));
414
+ };
415
+ }
416
+ function initCreateSubpackageApp(parseAppOptions) {
417
+ return function createApp(vm) {
418
+ const appOptions = parseApp(vm, parseAppOptions);
419
+ const app = getApp({
420
+ allowDefault: true,
421
+ });
422
+ vm.$.ctx.$scope = app;
423
+ const globalData = app.globalData;
424
+ if (globalData) {
425
+ Object.keys(appOptions.globalData).forEach((name) => {
426
+ if (!hasOwn(globalData, name)) {
427
+ globalData[name] = appOptions.globalData[name];
428
+ }
429
+ });
430
+ }
431
+ Object.keys(appOptions).forEach((name) => {
432
+ if (!hasOwn(app, name)) {
433
+ app[name] = appOptions[name];
434
+ }
435
+ });
436
+ initAppLifecycle(appOptions, vm);
437
+ };
438
+ }
439
+ function initAppLifecycle(appOptions, vm) {
440
+ if (isFunction(appOptions.onShow) && qa.onAppShow) {
441
+ qa.onAppShow((args) => {
442
+ vm.$callHook('onShow', args);
443
+ });
444
+ }
445
+ if (isFunction(appOptions.onHide) && qa.onAppHide) {
446
+ qa.onAppHide((args) => {
447
+ vm.$callHook('onHide', args);
448
+ });
449
+ }
450
+ if (isFunction(appOptions.onLaunch)) {
451
+ const args = qa.getLaunchOptionsSync && qa.getLaunchOptionsSync();
452
+ vm.$callHook('onLaunch', args || {});
453
+ }
454
+ }
455
+ function initLocale(appVm) {
456
+ const locale = ref(qa.getSystemInfoSync().language || 'zh-Hans');
457
+ Object.defineProperty(appVm, '$locale', {
458
+ get() {
459
+ return locale.value;
460
+ },
461
+ set(v) {
462
+ locale.value = v;
463
+ },
464
+ });
465
+ }
466
+
467
+ function initVueIds(vueIds, mpInstance) {
468
+ if (!vueIds) {
469
+ return;
470
+ }
471
+ const ids = vueIds.split(',');
472
+ const len = ids.length;
473
+ if (len === 1) {
474
+ mpInstance._$vueId = ids[0];
475
+ }
476
+ else if (len === 2) {
477
+ mpInstance._$vueId = ids[0];
478
+ mpInstance._$vuePid = ids[1];
479
+ }
480
+ }
481
+ const EXTRAS = ['externalClasses'];
482
+ function initExtraOptions(miniProgramComponentOptions, vueOptions) {
483
+ EXTRAS.forEach((name) => {
484
+ if (hasOwn(vueOptions, name)) {
485
+ miniProgramComponentOptions[name] = vueOptions[name];
486
+ }
487
+ });
488
+ }
489
+ function initWxsCallMethods(methods, wxsCallMethods) {
490
+ if (!isArray(wxsCallMethods)) {
491
+ return;
492
+ }
493
+ wxsCallMethods.forEach((callMethod) => {
494
+ methods[callMethod] = function (args) {
495
+ return this.$vm[callMethod](args);
496
+ };
497
+ });
498
+ }
499
+ function selectAllComponents(mpInstance, selector, $refs) {
500
+ const components = mpInstance.selectAllComponents(selector);
501
+ components.forEach((component) => {
502
+ const ref = component.properties.uR;
503
+ $refs[ref] = component.$vm || component;
504
+ });
505
+ }
506
+ function initRefs(instance, mpInstance) {
507
+ Object.defineProperty(instance, 'refs', {
508
+ get() {
509
+ const $refs = {};
510
+ selectAllComponents(mpInstance, '.r', $refs);
511
+ const forComponents = mpInstance.selectAllComponents('.r-i-f');
512
+ forComponents.forEach((component) => {
513
+ const ref = component.properties.uR;
514
+ if (!ref) {
515
+ return;
516
+ }
517
+ if (!$refs[ref]) {
518
+ $refs[ref] = [];
519
+ }
520
+ $refs[ref].push(component.$vm || component);
521
+ });
522
+ return $refs;
523
+ },
524
+ });
525
+ }
526
+ function nextSetDataTick(mpInstance, fn) {
527
+ // 随便设置一个字段来触发回调(部分平台必须有字段才可以,比如头条)
528
+ mpInstance.setData({ r1: 1 }, () => fn());
529
+ }
530
+ function initSetRef(mpInstance) {
531
+ if (!mpInstance._$setRef) {
532
+ mpInstance._$setRef = (fn) => {
533
+ nextTick(() => nextSetDataTick(mpInstance, fn));
534
+ };
535
+ }
536
+ }
537
+
538
+ const builtInProps = [
539
+ // 百度小程序,快手小程序自定义组件不支持绑定动态事件,动态dataset,故通过props传递事件信息
540
+ // event-opts
541
+ 'eO',
542
+ // 组件 ref
543
+ 'uR',
544
+ // 组件 ref-in-for
545
+ 'uRIF',
546
+ // 组件 id
547
+ 'uI',
548
+ // 组件类型 m: 小程序组件
549
+ 'uT',
550
+ // 组件 props
551
+ 'uP',
552
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
553
+ 'uS',
554
+ ];
555
+ function initDefaultProps(isBehavior = false) {
556
+ const properties = {};
557
+ if (!isBehavior) {
558
+ // 均不指定类型,避免微信小程序 property received type-uncompatible value 警告
559
+ builtInProps.forEach((name) => {
560
+ properties[name] = {
561
+ type: null,
562
+ value: '',
563
+ };
564
+ });
565
+ // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
566
+ properties.uS = {
567
+ type: null,
568
+ value: [],
569
+ observer: function (newVal) {
570
+ const $slots = Object.create(null);
571
+ newVal &&
572
+ newVal.forEach((slotName) => {
573
+ $slots[slotName] = true;
574
+ });
575
+ this.setData({
576
+ $slots,
577
+ });
578
+ },
579
+ };
580
+ }
581
+ return properties;
582
+ }
583
+ /**
584
+ *
585
+ * @param mpComponentOptions
586
+ * @param isBehavior
587
+ */
588
+ function initProps(mpComponentOptions) {
589
+ if (!mpComponentOptions.properties) {
590
+ mpComponentOptions.properties = {};
591
+ }
592
+ extend(mpComponentOptions.properties, initDefaultProps());
593
+ }
594
+ const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
595
+ function parsePropType(type, defaultValue) {
596
+ // [String]=>String
597
+ if (isArray(type) && type.length === 1) {
598
+ return type[0];
599
+ }
600
+ return type;
601
+ }
602
+ function normalizePropType(type, defaultValue) {
603
+ const res = parsePropType(type);
604
+ return PROP_TYPES.indexOf(res) !== -1 ? res : null;
605
+ }
606
+ /**
607
+ * 初始化页面 props,方便接收页面参数,类型均为String,默认值均为''
608
+ * @param param
609
+ * @param rawProps
610
+ */
611
+ function initPageProps({ properties }, rawProps) {
612
+ if (isArray(rawProps)) {
613
+ rawProps.forEach((key) => {
614
+ properties[key] = {
615
+ type: String,
616
+ value: '',
617
+ };
618
+ });
619
+ }
620
+ else if (isPlainObject(rawProps)) {
621
+ Object.keys(rawProps).forEach((key) => {
622
+ const opts = rawProps[key];
623
+ if (isPlainObject(opts)) {
624
+ // title:{type:String,default:''}
625
+ let value = opts.default;
626
+ if (isFunction(value)) {
627
+ value = value();
628
+ }
629
+ const type = opts.type;
630
+ opts.type = normalizePropType(type);
631
+ properties[key] = {
632
+ type: opts.type,
633
+ value,
634
+ };
635
+ }
636
+ else {
637
+ // content:String
638
+ properties[key] = {
639
+ type: normalizePropType(opts),
640
+ };
641
+ }
642
+ });
643
+ }
644
+ }
645
+ function findPropsData(properties, isPage) {
646
+ return ((isPage
647
+ ? findPagePropsData(properties)
648
+ : findComponentPropsData(properties.uP)) || {});
649
+ }
650
+ function findPagePropsData(properties) {
651
+ const propsData = {};
652
+ if (isPlainObject(properties)) {
653
+ Object.keys(properties).forEach((name) => {
654
+ if (builtInProps.indexOf(name) === -1) {
655
+ propsData[name] = properties[name];
656
+ }
657
+ });
658
+ }
659
+ return propsData;
660
+ }
661
+
662
+ function initData(_) {
663
+ return {};
664
+ }
665
+ function initPropsObserver(componentOptions) {
666
+ const observe = function observe() {
667
+ const up = this.properties.uP;
668
+ if (!up) {
669
+ return;
670
+ }
671
+ if (this.$vm) {
672
+ updateComponentProps(up, this.$vm.$);
673
+ }
674
+ else if (this.properties.uT === 'm') {
675
+ // 小程序组件
676
+ updateMiniProgramComponentProperties(up, this);
677
+ }
678
+ };
679
+ {
680
+ componentOptions.properties.uP.observer = observe;
681
+ }
682
+ }
683
+ function updateMiniProgramComponentProperties(up, mpInstance) {
684
+ const prevProps = mpInstance.properties;
685
+ const nextProps = findComponentPropsData(up) || {};
686
+ if (hasPropsChanged(prevProps, nextProps, false)) {
687
+ mpInstance.setData(nextProps);
688
+ }
689
+ }
690
+ function updateComponentProps(up, instance) {
691
+ const prevProps = toRaw(instance.props);
692
+ const nextProps = findComponentPropsData(up) || {};
693
+ if (hasPropsChanged(prevProps, nextProps)) {
694
+ updateProps(instance, nextProps, prevProps, false);
695
+ invalidateJob(instance.update);
696
+ instance.update();
697
+ }
698
+ }
699
+ function hasPropsChanged(prevProps, nextProps, checkLen = true) {
700
+ const nextKeys = Object.keys(nextProps);
701
+ if (checkLen && nextKeys.length !== Object.keys(prevProps).length) {
702
+ return true;
703
+ }
704
+ for (let i = 0; i < nextKeys.length; i++) {
705
+ const key = nextKeys[i];
706
+ if (nextProps[key] !== prevProps[key]) {
707
+ return true;
708
+ }
709
+ }
710
+ return false;
711
+ }
712
+ function initBehaviors(vueOptions) {
713
+ const vueBehaviors = vueOptions.behaviors;
714
+ let vueProps = vueOptions.props;
715
+ if (!vueProps) {
716
+ vueOptions.props = vueProps = [];
717
+ }
718
+ const behaviors = [];
719
+ if (isArray(vueBehaviors)) {
720
+ vueBehaviors.forEach((behavior) => {
721
+ behaviors.push(behavior.replace('uni://', 'qa://'));
722
+ if (behavior === 'uni://form-field') {
723
+ if (isArray(vueProps)) {
724
+ vueProps.push('name');
725
+ vueProps.push('value');
726
+ }
727
+ else {
728
+ vueProps.name = {
729
+ type: String,
730
+ default: '',
731
+ };
732
+ vueProps.value = {
733
+ type: [String, Number, Boolean, Array, Object, Date],
734
+ default: '',
735
+ };
736
+ }
737
+ }
738
+ });
739
+ }
740
+ return behaviors;
741
+ }
742
+ function applyOptions(componentOptions, vueOptions) {
743
+ componentOptions.data = initData();
744
+ componentOptions.behaviors = initBehaviors(vueOptions);
745
+ }
746
+
747
+ function parseComponent(vueOptions, { parse, mocks, isPage, initRelation, handleLink, initLifetimes, }) {
748
+ vueOptions = vueOptions.default || vueOptions;
749
+ const options = {
750
+ multipleSlots: true,
751
+ addGlobalClass: true,
752
+ pureDataPattern: /^uP$/,
753
+ };
754
+ if (vueOptions.options) {
755
+ extend(options, vueOptions.options);
756
+ }
757
+ const mpComponentOptions = {
758
+ options,
759
+ lifetimes: initLifetimes({ mocks, isPage, initRelation, vueOptions }),
760
+ pageLifetimes: {
761
+ show() {
762
+ this.$vm && this.$vm.$callHook('onPageShow');
763
+ },
764
+ hide() {
765
+ this.$vm && this.$vm.$callHook('onPageHide');
766
+ },
767
+ resize(size) {
768
+ this.$vm && this.$vm.$callHook('onPageResize', size);
769
+ },
770
+ },
771
+ methods: {
772
+ __l: handleLink,
773
+ },
774
+ };
775
+ if (__VUE_OPTIONS_API__) {
776
+ applyOptions(mpComponentOptions, vueOptions);
777
+ }
778
+ initProps(mpComponentOptions);
779
+ initPropsObserver(mpComponentOptions);
780
+ initExtraOptions(mpComponentOptions, vueOptions);
781
+ initWxsCallMethods(mpComponentOptions.methods, vueOptions.wxsCallMethods);
782
+ if (parse) {
783
+ parse(mpComponentOptions, { handleLink });
784
+ }
785
+ return mpComponentOptions;
786
+ }
787
+ function initCreateComponent(parseOptions) {
788
+ return function createComponent(vueComponentOptions) {
789
+ return Component(parseComponent(vueComponentOptions, parseOptions));
790
+ };
791
+ }
792
+ let $createComponentFn;
793
+ let $destroyComponentFn;
794
+ function $createComponent(initialVNode, options) {
795
+ if (!$createComponentFn) {
796
+ $createComponentFn = getApp().$vm.$createComponent;
797
+ }
798
+ const proxy = $createComponentFn(initialVNode, options);
799
+ return getExposeProxy(proxy.$) || proxy;
800
+ }
801
+ function $destroyComponent(instance) {
802
+ if (!$destroyComponentFn) {
803
+ $destroyComponentFn = getApp().$vm.$destroyComponent;
804
+ }
805
+ return $destroyComponentFn(instance);
806
+ }
807
+
808
+ function parsePage(vueOptions, parseOptions) {
809
+ const { parse, mocks, isPage, initRelation, handleLink, initLifetimes } = parseOptions;
810
+ const miniProgramPageOptions = parseComponent(vueOptions, {
811
+ mocks,
812
+ isPage,
813
+ initRelation,
814
+ handleLink,
815
+ initLifetimes,
816
+ });
817
+ initPageProps(miniProgramPageOptions, (vueOptions.default || vueOptions).props);
818
+ const methods = miniProgramPageOptions.methods;
819
+ methods.onLoad = function (query) {
820
+ this.options = query;
821
+ this.$page = {
822
+ fullPath: addLeadingSlash(this.route + stringifyQuery(query)),
823
+ };
824
+ return this.$vm && this.$vm.$callHook(ON_LOAD, query);
825
+ };
826
+ initHooks(methods, PAGE_INIT_HOOKS);
827
+ initUnknownHooks(methods, vueOptions);
828
+ initRuntimeHooks(methods, vueOptions.__runtimeHooks);
829
+ parse && parse(miniProgramPageOptions, { handleLink });
830
+ return miniProgramPageOptions;
831
+ }
832
+ function initCreatePage(parseOptions) {
833
+ return function createPage(vuePageOptions) {
834
+ return Component(parsePage(vuePageOptions, parseOptions));
835
+ };
836
+ }
837
+
838
+ const MPPage = Page;
839
+ const MPComponent = Component;
840
+ function initTriggerEvent(mpInstance) {
841
+ const oldTriggerEvent = mpInstance.triggerEvent;
842
+ mpInstance.triggerEvent = function (event, ...args) {
843
+ return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
844
+ };
845
+ }
846
+ function initHook(name, options, isComponent) {
847
+ const oldHook = options[name];
848
+ if (!oldHook) {
849
+ options[name] = function () {
850
+ initTriggerEvent(this);
851
+ };
852
+ }
853
+ else {
854
+ options[name] = function (...args) {
855
+ initTriggerEvent(this);
856
+ return oldHook.apply(this, args);
857
+ };
858
+ }
859
+ }
860
+ Page = function (options) {
861
+ initHook(ON_LOAD, options);
862
+ return MPPage(options);
863
+ };
864
+ Component = function (options) {
865
+ initHook('created', options);
866
+ // 小程序组件
867
+ const isVueComponent = options.properties && options.properties.uP;
868
+ if (!isVueComponent) {
869
+ initProps(options);
870
+ initPropsObserver(options);
871
+ }
872
+ return MPComponent(options);
873
+ };
874
+
875
+ function provide(instance, key, value) {
876
+ if (!instance) {
877
+ if ((process.env.NODE_ENV !== 'production')) {
878
+ console.warn(`provide() can only be used inside setup().`);
879
+ }
880
+ }
881
+ else {
882
+ let provides = instance.provides;
883
+ // by default an instance inherits its parent's provides object
884
+ // but when it needs to provide values of its own, it creates its
885
+ // own provides object using parent provides object as prototype.
886
+ // this way in `inject` we can simply look up injections from direct
887
+ // parent and let the prototype chain do the work.
888
+ const parentProvides = instance.parent && instance.parent.provides;
889
+ if (parentProvides === provides) {
890
+ provides = instance.provides = Object.create(parentProvides);
891
+ }
892
+ // TS doesn't allow symbol as index type
893
+ provides[key] = value;
894
+ }
895
+ }
896
+ function initProvide(instance) {
897
+ const provideOptions = instance.$options.provide;
898
+ if (!provideOptions) {
899
+ return;
900
+ }
901
+ const provides = isFunction(provideOptions)
902
+ ? provideOptions.call(instance)
903
+ : provideOptions;
904
+ const internalInstance = instance.$;
905
+ for (const key in provides) {
906
+ provide(internalInstance, key, provides[key]);
907
+ }
908
+ }
909
+ function inject(instance, key, defaultValue, treatDefaultAsFactory = false) {
910
+ if (instance) {
911
+ // #2400
912
+ // to support `app.use` plugins,
913
+ // fallback to appContext's `provides` if the intance is at root
914
+ const provides = instance.parent == null
915
+ ? instance.vnode.appContext && instance.vnode.appContext.provides
916
+ : instance.parent.provides;
917
+ if (provides && key in provides) {
918
+ // TS doesn't allow symbol as index type
919
+ return provides[key];
920
+ }
921
+ else if (arguments.length > 1) {
922
+ return treatDefaultAsFactory && isFunction(defaultValue)
923
+ ? defaultValue()
924
+ : defaultValue;
925
+ }
926
+ else if ((process.env.NODE_ENV !== 'production')) {
927
+ console.warn(`injection "${String(key)}" not found.`);
928
+ }
929
+ }
930
+ else if ((process.env.NODE_ENV !== 'production')) {
931
+ console.warn(`inject() can only be used inside setup() or functional components.`);
932
+ }
933
+ }
934
+ function initInjections(instance) {
935
+ const injectOptions = instance.$options.inject;
936
+ if (!injectOptions) {
937
+ return;
938
+ }
939
+ const internalInstance = instance.$;
940
+ const ctx = internalInstance.ctx;
941
+ if (isArray(injectOptions)) {
942
+ for (let i = 0; i < injectOptions.length; i++) {
943
+ const key = injectOptions[i];
944
+ ctx[key] = inject(internalInstance, key);
945
+ }
946
+ }
947
+ else {
948
+ for (const key in injectOptions) {
949
+ const opt = injectOptions[key];
950
+ if (isObject(opt)) {
951
+ ctx[key] = inject(internalInstance, opt.from || key, opt.default, true /* treat default function as factory */);
952
+ }
953
+ else {
954
+ ctx[key] = inject(internalInstance, opt);
955
+ }
956
+ }
957
+ }
958
+ }
959
+
960
+ // @ts-ignore
961
+ function initLifetimes$1({ mocks, isPage, initRelation, vueOptions, }) {
962
+ function attached() {
963
+ initSetRef(this);
964
+ const properties = this.properties;
965
+ initVueIds(properties.uI, this);
966
+ const relationOptions = {
967
+ vuePid: this._$vuePid,
968
+ };
969
+ // 初始化 vue 实例
970
+ const mpInstance = this;
971
+ const mpType = isPage(mpInstance) ? 'page' : 'component';
972
+ if (mpType === 'page' && !mpInstance.route && mpInstance.__route__) {
973
+ mpInstance.route = mpInstance.__route__;
974
+ }
975
+ this.$vm = $createComponent({
976
+ type: vueOptions,
977
+ props: findPropsData(properties, mpType === 'page'),
978
+ }, {
979
+ mpType,
980
+ mpInstance,
981
+ slots: properties.uS || {},
982
+ parentComponent: relationOptions.parent && relationOptions.parent.$,
983
+ onBeforeSetup(instance, options) {
984
+ initRefs(instance, mpInstance);
985
+ initMocks(instance, mpInstance, mocks);
986
+ initComponentInstance(instance, options);
987
+ },
988
+ });
989
+ // 处理父子关系
990
+ initRelation(this, relationOptions);
991
+ }
992
+ function detached() {
993
+ if (this.$vm) {
994
+ pruneComponentPropsCache(this.$vm.$.uid);
995
+ $destroyComponent(this.$vm);
996
+ }
997
+ }
998
+ {
999
+ return { attached, detached };
1000
+ }
1001
+ }
1002
+
1003
+ const instances = Object.create(null);
1004
+ function parse(componentOptions, { handleLink }) {
1005
+ componentOptions.methods.__l = handleLink;
1006
+ }
1007
+
1008
+ function initLifetimes(lifetimesOptions) {
1009
+ return extend(initLifetimes$1(lifetimesOptions), {
1010
+ ready() {
1011
+ if (this.$vm && lifetimesOptions.isPage(this)) {
1012
+ if (this.pageinstance) {
1013
+ this.__webviewId__ = this.pageinstance.__pageId__;
1014
+ }
1015
+ this.$vm.$callCreatedHook();
1016
+ nextSetDataTick(this, () => {
1017
+ this.$vm.$callHook('mounted');
1018
+ this.$vm.$callHook(ON_READY$1);
1019
+ });
1020
+ }
1021
+ else {
1022
+ this.is && console.warn(this.is + ' is not ready');
1023
+ }
1024
+ },
1025
+ detached() {
1026
+ this.$vm && $destroyComponent(this.$vm);
1027
+ // 清理
1028
+ const webviewId = this.__webviewId__;
1029
+ webviewId &&
1030
+ Object.keys(instances).forEach((key) => {
1031
+ if (key.indexOf(webviewId + '_') === 0) {
1032
+ delete instances[key];
1033
+ }
1034
+ });
1035
+ },
1036
+ });
1037
+ }
1038
+
1039
+ const mocks = ['nodeId', 'componentName', '_componentId', 'uniquePrefix'];
1040
+ function isPage(mpInstance) {
1041
+ return !hasOwn(mpInstance, 'ownerId');
1042
+ }
1043
+
1044
+ function initRelation(mpInstance) {
1045
+ // triggerEvent 后,接收事件时机特别晚,已经到了 ready 之后
1046
+ const nodeId = mpInstance.nodeId + '';
1047
+ const webviewId = mpInstance.pageinstance.__pageId__ + '';
1048
+ instances[webviewId + '_' + nodeId] = mpInstance.$vm;
1049
+ mpInstance.triggerEvent('__l', {
1050
+ nodeId,
1051
+ webviewId,
1052
+ });
1053
+ }
1054
+ function handleLink({ detail: { nodeId, webviewId }, }) {
1055
+ const vm = instances[webviewId + '_' + nodeId];
1056
+ if (!vm) {
1057
+ return;
1058
+ }
1059
+ let parentVm = instances[webviewId + '_' + vm.$scope.ownerId];
1060
+ if (!parentVm) {
1061
+ parentVm = this.$vm;
1062
+ }
1063
+ vm.$.parent = parentVm.$;
1064
+ const createdVm = function () {
1065
+ if (__VUE_OPTIONS_API__) {
1066
+ parentVm.$children.push(vm);
1067
+ const parent = parentVm.$;
1068
+ vm.$.provides = parent
1069
+ ? parent.provides
1070
+ : Object.create(parent.appContext.provides);
1071
+ initInjections(vm);
1072
+ initProvide(vm);
1073
+ }
1074
+ vm.$callCreatedHook();
1075
+ };
1076
+ const mountedVm = function () {
1077
+ // 处理当前 vm 子
1078
+ if (vm._$childVues) {
1079
+ vm._$childVues.forEach(([createdVm]) => createdVm());
1080
+ vm._$childVues.forEach(([, mountedVm]) => mountedVm());
1081
+ delete vm._$childVues;
1082
+ }
1083
+ vm.$callHook('mounted');
1084
+ vm.$callHook(ON_READY$1);
1085
+ };
1086
+ // 当 parentVm 已经 mounted 时,直接触发,否则延迟
1087
+ if (!parentVm || parentVm.$.isMounted) {
1088
+ createdVm();
1089
+ mountedVm();
1090
+ }
1091
+ else {
1092
+ (parentVm._$childVues || (parentVm._$childVues = [])).push([
1093
+ createdVm,
1094
+ mountedVm,
1095
+ ]);
1096
+ }
1097
+ }
1098
+
1099
+ var parseComponentOptions = /*#__PURE__*/Object.freeze({
1100
+ __proto__: null,
1101
+ initRelation: initRelation,
1102
+ handleLink: handleLink,
1103
+ mocks: mocks,
1104
+ isPage: isPage,
1105
+ parse: parse,
1106
+ initLifetimes: initLifetimes$1
1107
+ });
1108
+
1109
+ var parsePageOptions = /*#__PURE__*/Object.freeze({
1110
+ __proto__: null,
1111
+ mocks: mocks,
1112
+ isPage: isPage,
1113
+ initRelation: initRelation,
1114
+ handleLink: handleLink,
1115
+ parse: parse,
1116
+ initLifetimes: initLifetimes
1117
+ });
1118
+
1119
+ const createApp = initCreateApp();
1120
+ const createPage = initCreatePage(parsePageOptions);
1121
+ const createComponent = initCreateComponent(parseComponentOptions);
1122
+ const createSubpackageApp = initCreateSubpackageApp();
1123
+ qa.EventChannel = EventChannel$1;
1124
+ qa.createApp = global.createApp = createApp;
1125
+ qa.createPage = createPage;
1126
+ qa.createComponent = createComponent;
1127
+ qa.createSubpackageApp = createSubpackageApp;
1128
+
1129
+ export { createApp, createComponent, createPage, createSubpackageApp };