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

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,4 +1,4 @@
1
- import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
1
+ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
2
2
  import { injectHook } from 'vue';
3
3
 
4
4
  //App
@@ -53,6 +53,57 @@ function getBaseSystemInfo() {
53
53
  return tt.getSystemInfoSync()
54
54
  }
55
55
 
56
+ const E = function () {
57
+ // Keep this empty so it's easier to inherit from
58
+ // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
59
+ };
60
+ E.prototype = {
61
+ on: function (name, callback, ctx) {
62
+ var e = this.e || (this.e = {});
63
+ (e[name] || (e[name] = [])).push({
64
+ fn: callback,
65
+ ctx: ctx,
66
+ });
67
+ return this;
68
+ },
69
+ once: function (name, callback, ctx) {
70
+ var self = this;
71
+ function listener() {
72
+ self.off(name, listener);
73
+ callback.apply(ctx, arguments);
74
+ }
75
+ listener._ = callback;
76
+ return this.on(name, listener, ctx);
77
+ },
78
+ emit: function (name) {
79
+ var data = [].slice.call(arguments, 1);
80
+ var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
81
+ var i = 0;
82
+ var len = evtArr.length;
83
+ for (i; i < len; i++) {
84
+ evtArr[i].fn.apply(evtArr[i].ctx, data);
85
+ }
86
+ return this;
87
+ },
88
+ off: function (name, callback) {
89
+ var e = this.e || (this.e = {});
90
+ var evts = e[name];
91
+ var liveEvents = [];
92
+ if (evts && callback) {
93
+ for (var i = 0, len = evts.length; i < len; i++) {
94
+ if (evts[i].fn !== callback && evts[i].fn._ !== callback)
95
+ liveEvents.push(evts[i]);
96
+ }
97
+ }
98
+ // Remove event from queue to prevent memory leak
99
+ // Suggested by https://github.com/lazd
100
+ // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
101
+ liveEvents.length ? (e[name] = liveEvents) : delete e[name];
102
+ return this;
103
+ },
104
+ };
105
+ var E$1 = E;
106
+
56
107
  function validateProtocolFail(name, msg) {
57
108
  console.warn(`${name}: ${msg}`);
58
109
  }
@@ -189,6 +240,30 @@ function isBoolean(...args) {
189
240
  return args.some((elem) => elem.toLowerCase() === 'boolean');
190
241
  }
191
242
 
243
+ function tryCatch(fn) {
244
+ return function () {
245
+ try {
246
+ return fn.apply(fn, arguments);
247
+ }
248
+ catch (e) {
249
+ // TODO
250
+ console.error(e);
251
+ }
252
+ };
253
+ }
254
+
255
+ function getApiCallbacks(args) {
256
+ const apiCallbacks = {};
257
+ for (const name in args) {
258
+ const fn = args[name];
259
+ if (isFunction(fn)) {
260
+ apiCallbacks[name] = tryCatch(fn);
261
+ delete args[name];
262
+ }
263
+ }
264
+ return apiCallbacks;
265
+ }
266
+
192
267
  const HOOK_SUCCESS = 'success';
193
268
  const HOOK_FAIL = 'fail';
194
269
  const HOOK_COMPLETE = 'complete';
@@ -511,58 +586,7 @@ const EmitProtocol = [
511
586
  },
512
587
  ];
513
588
 
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();
589
+ const emitter = new E$1();
566
590
  const $on = defineSyncApi(API_ON, (name, callback) => {
567
591
  emitter.on(name, callback);
568
592
  return () => emitter.off(name, callback);
@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
584
608
  emitter.emit(name, ...args);
585
609
  }, EmitProtocol);
586
610
 
611
+ let cid = '';
612
+ /**
613
+ * @private
614
+ * @param args
615
+ */
616
+ function invokePushCallback(args) {
617
+ if (args.type === 'clientId') {
618
+ cid = args.cid;
619
+ invokeGetPushCidCallbacks(cid);
620
+ }
621
+ else if (args.type === 'pushMsg') {
622
+ onPushMessageCallbacks.forEach((callback) => {
623
+ callback({ data: args.message });
624
+ });
625
+ }
626
+ }
627
+ const getPushCidCallbacks = [];
628
+ function invokeGetPushCidCallbacks(cid) {
629
+ getPushCidCallbacks.forEach((callback) => {
630
+ callback(cid);
631
+ });
632
+ getPushCidCallbacks.length = 0;
633
+ }
634
+ function getPushCid(args) {
635
+ if (!isPlainObject(args)) {
636
+ args = {};
637
+ }
638
+ const { success, fail, complete } = getApiCallbacks(args);
639
+ const hasSuccess = isFunction(success);
640
+ const hasFail = isFunction(fail);
641
+ const hasComplete = isFunction(complete);
642
+ getPushCidCallbacks.push((cid) => {
643
+ let res;
644
+ if (cid) {
645
+ res = { errMsg: 'getPushCid:ok', cid };
646
+ hasSuccess && success(res);
647
+ }
648
+ else {
649
+ res = { errMsg: 'getPushCid:fail' };
650
+ hasFail && fail(res);
651
+ }
652
+ hasComplete && complete(res);
653
+ });
654
+ if (cid) {
655
+ Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
656
+ }
657
+ }
658
+ const onPushMessageCallbacks = [];
659
+ // 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
660
+ const onPushMessage = (fn) => {
661
+ if (onPushMessageCallbacks.indexOf(fn) === -1) {
662
+ onPushMessageCallbacks.push(fn);
663
+ }
664
+ };
665
+ const offPushMessage = (fn) => {
666
+ if (!fn) {
667
+ onPushMessageCallbacks.length = 0;
668
+ }
669
+ else {
670
+ const index = onPushMessageCallbacks.indexOf(fn);
671
+ if (index > -1) {
672
+ onPushMessageCallbacks.splice(index, 1);
673
+ }
674
+ }
675
+ };
676
+
587
677
  const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
588
678
  const CONTEXT_API_RE = /^create|Manager$/;
589
679
  // Context例外情况
@@ -772,6 +862,10 @@ const baseApis = {
772
862
  getLocale,
773
863
  setLocale,
774
864
  onLocaleChange,
865
+ getPushCid,
866
+ onPushMessage,
867
+ offPushMessage,
868
+ invokePushCallback,
775
869
  };
776
870
  function initUni(api, protocols) {
777
871
  const wrapper = initWrapper(protocols);
@@ -1,4 +1,4 @@
1
- import { isPlainObject, isArray, hasOwn, isFunction, extend, camelize, isObject } from '@vue/shared';
1
+ import { camelize, isPlainObject, isArray, hasOwn, isFunction, extend, isObject } from '@vue/shared';
2
2
  import { injectHook, ref, nextTick, findComponentPropsData, toRaw, updateProps, invalidateJob, getExposeProxy, pruneComponentPropsCache } from 'vue';
3
3
 
4
4
  const ON_READY$1 = 'onReady';
@@ -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 = [];
@@ -854,14 +861,10 @@ function initCreatePage(parseOptions) {
854
861
 
855
862
  const MPPage = Page;
856
863
  const MPComponent = Component;
857
- const customizeRE = /:/g;
858
- function customize(str) {
859
- return camelize(str.replace(customizeRE, '-'));
860
- }
861
864
  function initTriggerEvent(mpInstance) {
862
865
  const oldTriggerEvent = mpInstance.triggerEvent;
863
866
  mpInstance.triggerEvent = function (event, ...args) {
864
- return oldTriggerEvent.apply(mpInstance, [customize(event), ...args]);
867
+ return oldTriggerEvent.apply(mpInstance, [customizeEvent(event), ...args]);
865
868
  };
866
869
  }
867
870
  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-3031120220221001",
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-3031120220221001",
26
+ "@dcloudio/uni-mp-compiler": "3.0.0-alpha-3031120220221001",
27
+ "@dcloudio/uni-mp-vite": "3.0.0-alpha-3031120220221001",
28
+ "@dcloudio/uni-mp-vue": "3.0.0-alpha-3031120220221001",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3031120220221001",
30
+ "@vue/compiler-core": "3.2.31"
31
31
  }
32
32
  }