@dcloudio/uni-mp-toutiao 3.0.0-alpha-3031220220222001 → 3.0.0-alpha-3040020220225001

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.
@@ -1,8 +1,22 @@
1
- import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
2
- import { injectHook } from 'vue';
1
+ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
3
2
 
4
- //App
5
- const ON_LAUNCH = 'onLaunch';
3
+ let vueApp;
4
+ const createVueAppHooks = [];
5
+ /**
6
+ * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑
7
+ * @param hook
8
+ */
9
+ function onCreateVueApp(hook) {
10
+ // TODO 每个 nvue 页面都会触发
11
+ if (vueApp) {
12
+ return hook(vueApp);
13
+ }
14
+ createVueAppHooks.push(hook);
15
+ }
16
+ function invokeCreateVueAppHook(app) {
17
+ vueApp = app;
18
+ createVueAppHooks.forEach((hook) => hook(app));
19
+ }
6
20
 
7
21
  const eventChannels = {};
8
22
  const eventChannelStack = [];
@@ -40,19 +54,61 @@ const navigateTo = {
40
54
  },
41
55
  };
42
56
 
43
- tt.appLaunchHooks = [];
44
- function onAppLaunch(hook) {
45
- const app = getApp({ allowDefault: true });
46
- if (app && app.$vm) {
47
- return injectHook(ON_LAUNCH, hook, app.$vm.$);
48
- }
49
- tt.appLaunchHooks.push(hook);
50
- }
51
-
52
57
  function getBaseSystemInfo() {
53
58
  return tt.getSystemInfoSync()
54
59
  }
55
60
 
61
+ const E = function () {
62
+ // Keep this empty so it's easier to inherit from
63
+ // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
64
+ };
65
+ E.prototype = {
66
+ on: function (name, callback, ctx) {
67
+ var e = this.e || (this.e = {});
68
+ (e[name] || (e[name] = [])).push({
69
+ fn: callback,
70
+ ctx: ctx,
71
+ });
72
+ return this;
73
+ },
74
+ once: function (name, callback, ctx) {
75
+ var self = this;
76
+ function listener() {
77
+ self.off(name, listener);
78
+ callback.apply(ctx, arguments);
79
+ }
80
+ listener._ = callback;
81
+ return this.on(name, listener, ctx);
82
+ },
83
+ emit: function (name) {
84
+ var data = [].slice.call(arguments, 1);
85
+ var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
86
+ var i = 0;
87
+ var len = evtArr.length;
88
+ for (i; i < len; i++) {
89
+ evtArr[i].fn.apply(evtArr[i].ctx, data);
90
+ }
91
+ return this;
92
+ },
93
+ off: function (name, callback) {
94
+ var e = this.e || (this.e = {});
95
+ var evts = e[name];
96
+ var liveEvents = [];
97
+ if (evts && callback) {
98
+ for (var i = 0, len = evts.length; i < len; i++) {
99
+ if (evts[i].fn !== callback && evts[i].fn._ !== callback)
100
+ liveEvents.push(evts[i]);
101
+ }
102
+ }
103
+ // Remove event from queue to prevent memory leak
104
+ // Suggested by https://github.com/lazd
105
+ // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
106
+ liveEvents.length ? (e[name] = liveEvents) : delete e[name];
107
+ return this;
108
+ },
109
+ };
110
+ var E$1 = E;
111
+
56
112
  function validateProtocolFail(name, msg) {
57
113
  console.warn(`${name}: ${msg}`);
58
114
  }
@@ -189,6 +245,30 @@ function isBoolean(...args) {
189
245
  return args.some((elem) => elem.toLowerCase() === 'boolean');
190
246
  }
191
247
 
248
+ function tryCatch(fn) {
249
+ return function () {
250
+ try {
251
+ return fn.apply(fn, arguments);
252
+ }
253
+ catch (e) {
254
+ // TODO
255
+ console.error(e);
256
+ }
257
+ };
258
+ }
259
+
260
+ function getApiCallbacks(args) {
261
+ const apiCallbacks = {};
262
+ for (const name in args) {
263
+ const fn = args[name];
264
+ if (isFunction(fn)) {
265
+ apiCallbacks[name] = tryCatch(fn);
266
+ delete args[name];
267
+ }
268
+ }
269
+ return apiCallbacks;
270
+ }
271
+
192
272
  const HOOK_SUCCESS = 'success';
193
273
  const HOOK_FAIL = 'fail';
194
274
  const HOOK_COMPLETE = 'complete';
@@ -419,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
419
499
  if (!interceptors || !interceptor) {
420
500
  return;
421
501
  }
422
- Object.keys(interceptor).forEach((hook) => {
423
- if (isFunction(interceptor[hook])) {
424
- removeHook(interceptors[hook], interceptor[hook]);
502
+ Object.keys(interceptor).forEach((name) => {
503
+ const hooks = interceptors[name];
504
+ const hook = interceptor[name];
505
+ if (isArray(hooks) && isFunction(hook)) {
506
+ remove(hooks, hook);
425
507
  }
426
508
  });
427
509
  }
@@ -444,15 +526,6 @@ function dedupeHooks(hooks) {
444
526
  }
445
527
  return res;
446
528
  }
447
- function removeHook(hooks, hook) {
448
- if (!hooks) {
449
- return;
450
- }
451
- const index = hooks.indexOf(hook);
452
- if (index !== -1) {
453
- hooks.splice(index, 1);
454
- }
455
- }
456
529
  const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
457
530
  if (typeof method === 'string' && isPlainObject(interceptor)) {
458
531
  mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
@@ -511,58 +584,7 @@ const EmitProtocol = [
511
584
  },
512
585
  ];
513
586
 
514
- const E = function () {
515
- // Keep this empty so it's easier to inherit from
516
- // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
517
- };
518
- E.prototype = {
519
- on: function (name, callback, ctx) {
520
- var e = this.e || (this.e = {});
521
- (e[name] || (e[name] = [])).push({
522
- fn: callback,
523
- ctx: ctx,
524
- });
525
- return this;
526
- },
527
- once: function (name, callback, ctx) {
528
- var self = this;
529
- function listener() {
530
- self.off(name, listener);
531
- callback.apply(ctx, arguments);
532
- }
533
- listener._ = callback;
534
- return this.on(name, listener, ctx);
535
- },
536
- emit: function (name) {
537
- var data = [].slice.call(arguments, 1);
538
- var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
539
- var i = 0;
540
- var len = evtArr.length;
541
- for (i; i < len; i++) {
542
- evtArr[i].fn.apply(evtArr[i].ctx, data);
543
- }
544
- return this;
545
- },
546
- off: function (name, callback) {
547
- var e = this.e || (this.e = {});
548
- var evts = e[name];
549
- var liveEvents = [];
550
- if (evts && callback) {
551
- for (var i = 0, len = evts.length; i < len; i++) {
552
- if (evts[i].fn !== callback && evts[i].fn._ !== callback)
553
- liveEvents.push(evts[i]);
554
- }
555
- }
556
- // Remove event from queue to prevent memory leak
557
- // Suggested by https://github.com/lazd
558
- // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
559
- liveEvents.length ? (e[name] = liveEvents) : delete e[name];
560
- return this;
561
- },
562
- };
563
- var Emitter = E;
564
-
565
- const emitter = new Emitter();
587
+ const emitter = new E$1();
566
588
  const $on = defineSyncApi(API_ON, (name, callback) => {
567
589
  emitter.on(name, callback);
568
590
  return () => emitter.off(name, callback);
@@ -584,6 +606,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
584
606
  emitter.emit(name, ...args);
585
607
  }, EmitProtocol);
586
608
 
609
+ let cid = '';
610
+ /**
611
+ * @private
612
+ * @param args
613
+ */
614
+ function invokePushCallback(args) {
615
+ if (args.type === 'clientId') {
616
+ cid = args.cid;
617
+ invokeGetPushCidCallbacks(cid);
618
+ }
619
+ else if (args.type === 'pushMsg') {
620
+ onPushMessageCallbacks.forEach((callback) => {
621
+ callback({ data: args.message });
622
+ });
623
+ }
624
+ }
625
+ const getPushCidCallbacks = [];
626
+ function invokeGetPushCidCallbacks(cid) {
627
+ getPushCidCallbacks.forEach((callback) => {
628
+ callback(cid);
629
+ });
630
+ getPushCidCallbacks.length = 0;
631
+ }
632
+ function getPushCid(args) {
633
+ if (!isPlainObject(args)) {
634
+ args = {};
635
+ }
636
+ const { success, fail, complete } = getApiCallbacks(args);
637
+ const hasSuccess = isFunction(success);
638
+ const hasFail = isFunction(fail);
639
+ const hasComplete = isFunction(complete);
640
+ getPushCidCallbacks.push((cid) => {
641
+ let res;
642
+ if (cid) {
643
+ res = { errMsg: 'getPushCid:ok', cid };
644
+ hasSuccess && success(res);
645
+ }
646
+ else {
647
+ res = { errMsg: 'getPushCid:fail' };
648
+ hasFail && fail(res);
649
+ }
650
+ hasComplete && complete(res);
651
+ });
652
+ if (cid) {
653
+ Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
654
+ }
655
+ }
656
+ const onPushMessageCallbacks = [];
657
+ // 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
658
+ const onPushMessage = (fn) => {
659
+ if (onPushMessageCallbacks.indexOf(fn) === -1) {
660
+ onPushMessageCallbacks.push(fn);
661
+ }
662
+ };
663
+ const offPushMessage = (fn) => {
664
+ if (!fn) {
665
+ onPushMessageCallbacks.length = 0;
666
+ }
667
+ else {
668
+ const index = onPushMessageCallbacks.indexOf(fn);
669
+ if (index > -1) {
670
+ onPushMessageCallbacks.splice(index, 1);
671
+ }
672
+ }
673
+ };
674
+
587
675
  const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
588
676
  const CONTEXT_API_RE = /^create|Manager$/;
589
677
  // Context例外情况
@@ -768,10 +856,15 @@ const baseApis = {
768
856
  interceptors,
769
857
  addInterceptor,
770
858
  removeInterceptor,
771
- onAppLaunch,
859
+ onCreateVueApp,
860
+ invokeCreateVueAppHook,
772
861
  getLocale,
773
862
  setLocale,
774
863
  onLocaleChange,
864
+ getPushCid,
865
+ onPushMessage,
866
+ offPushMessage,
867
+ invokePushCallback,
775
868
  };
776
869
  function initUni(api, protocols) {
777
870
  const wrapper = initWrapper(protocols);
@@ -1,5 +1,5 @@
1
- import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
2
- import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
1
+ import { camelize, isPlainObject, isArray, hasOwn, isFunction, extend, isObject } from '@vue/shared';
2
+ import { ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
3
3
 
4
4
  const ON_READY$1 = 'onReady';
5
5
 
@@ -88,6 +88,25 @@ const ON_REACH_BOTTOM = 'onReachBottom';
88
88
  const ON_PULL_DOWN_REFRESH = 'onPullDownRefresh';
89
89
  const ON_ADD_TO_FAVORITES = 'onAddToFavorites';
90
90
 
91
+ const customizeRE = /:/g;
92
+ function customizeEvent(str) {
93
+ return camelize(str.replace(customizeRE, '-'));
94
+ }
95
+
96
+ function hasLeadingSlash(str) {
97
+ return str.indexOf('/') === 0;
98
+ }
99
+ function addLeadingSlash(str) {
100
+ return hasLeadingSlash(str) ? str : '/' + str;
101
+ }
102
+ const invokeArrayFns = (fns, arg) => {
103
+ let ret;
104
+ for (let i = 0; i < fns.length; i++) {
105
+ ret = fns[i](arg);
106
+ }
107
+ return ret;
108
+ };
109
+
91
110
  const encode = encodeURIComponent;
92
111
  function stringifyQuery(obj, encodeStr = encode) {
93
112
  const res = obj
@@ -108,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
108
127
  return res ? `?${res}` : '';
109
128
  }
110
129
 
111
- function hasLeadingSlash(str) {
112
- return str.indexOf('/') === 0;
113
- }
114
- function addLeadingSlash(str) {
115
- return hasLeadingSlash(str) ? str : '/' + str;
116
- }
117
- const invokeArrayFns = (fns, arg) => {
118
- let ret;
119
- for (let i = 0; i < fns.length; i++) {
120
- ret = fns[i](arg);
121
- }
122
- return ret;
123
- };
124
-
125
130
  class EventChannel {
126
131
  constructor(id, events) {
127
132
  this.id = id;
@@ -185,11 +190,13 @@ class EventChannel {
185
190
  }
186
191
  }
187
192
 
188
- const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = {
189
- onPageScroll: 1,
190
- onShareAppMessage: 1 << 1,
191
- onShareTimeline: 1 << 2,
192
- };
193
+ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => {
194
+ return {
195
+ onPageScroll: 1,
196
+ onShareAppMessage: 1 << 1,
197
+ onShareTimeline: 1 << 2,
198
+ };
199
+ })();
193
200
 
194
201
  const eventChannels = {};
195
202
  const eventChannelStack = [];
@@ -357,13 +364,6 @@ function initRuntimeHooks(mpOptions, runtimeHooks) {
357
364
  });
358
365
  }
359
366
 
360
- tt.appLaunchHooks = [];
361
- function injectAppLaunchHooks(appInstance) {
362
- tt.appLaunchHooks.forEach((hook) => {
363
- injectHook(ON_LAUNCH, hook, appInstance);
364
- });
365
- }
366
-
367
367
  const HOOKS = [
368
368
  ON_SHOW,
369
369
  ON_HIDE,
@@ -388,9 +388,8 @@ function parseApp(instance, parseAppOptions) {
388
388
  mpInstance: this,
389
389
  slots: [],
390
390
  });
391
- injectAppLaunchHooks(internalInstance);
392
391
  ctx.globalData = this.globalData;
393
- instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
392
+ instance.$callHook(ON_LAUNCH, options);
394
393
  },
395
394
  };
396
395
  initLocale(instance);
@@ -854,14 +853,10 @@ function initCreatePage(parseOptions) {
854
853
 
855
854
  const MPPage = Page;
856
855
  const MPComponent = Component;
857
- const customizeRE = /:/g;
858
- function customize(str) {
859
- return camelize(str.replace(customizeRE, '-'));
860
- }
861
856
  function initTriggerEvent(mpInstance) {
862
857
  const oldTriggerEvent = mpInstance.triggerEvent;
863
858
  mpInstance.triggerEvent = function (event, ...args) {
864
- return oldTriggerEvent.apply(mpInstance, [customize(event), ...args]);
859
+ return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
865
860
  };
866
861
  }
867
862
  function initHook(name, options, isComponent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-mp-toutiao",
3
- "version": "3.0.0-alpha-3031220220222001",
3
+ "version": "3.0.0-alpha-3040020220225001",
4
4
  "description": "uni-app mp-toutiao",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -22,11 +22,11 @@
22
22
  },
23
23
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
24
24
  "dependencies": {
25
- "@dcloudio/uni-cli-shared": "3.0.0-alpha-3031220220222001",
26
- "@dcloudio/uni-mp-compiler": "3.0.0-alpha-3031220220222001",
27
- "@dcloudio/uni-mp-vite": "3.0.0-alpha-3031220220222001",
28
- "@dcloudio/uni-mp-vue": "3.0.0-alpha-3031220220222001",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-3031220220222001",
30
- "@vue/compiler-core": "3.2.26"
25
+ "@dcloudio/uni-cli-shared": "3.0.0-alpha-3040020220225001",
26
+ "@dcloudio/uni-mp-compiler": "3.0.0-alpha-3040020220225001",
27
+ "@dcloudio/uni-mp-vite": "3.0.0-alpha-3040020220225001",
28
+ "@dcloudio/uni-mp-vue": "3.0.0-alpha-3040020220225001",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3040020220225001",
30
+ "@vue/compiler-core": "3.2.31"
31
31
  }
32
32
  }