@tarojs/with-weapp 4.0.0-beta.1 → 4.0.0-beta.11

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,36 +1,20 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/defineProperty'), require('@babel/runtime/helpers/toConsumableArray'), require('@babel/runtime/helpers/slicedToArray'), require('@babel/runtime/helpers/classCallCheck'), require('@babel/runtime/helpers/createClass'), require('@babel/runtime/helpers/assertThisInitialized'), require('@babel/runtime/helpers/get'), require('@babel/runtime/helpers/inherits'), require('@babel/runtime/helpers/possibleConstructorReturn'), require('@babel/runtime/helpers/getPrototypeOf'), require('@babel/runtime/helpers/typeof'), require('@tarojs/runtime'), require('@tarojs/taro')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/defineProperty', '@babel/runtime/helpers/toConsumableArray', '@babel/runtime/helpers/slicedToArray', '@babel/runtime/helpers/classCallCheck', '@babel/runtime/helpers/createClass', '@babel/runtime/helpers/assertThisInitialized', '@babel/runtime/helpers/get', '@babel/runtime/helpers/inherits', '@babel/runtime/helpers/possibleConstructorReturn', '@babel/runtime/helpers/getPrototypeOf', '@babel/runtime/helpers/typeof', '@tarojs/runtime', '@tarojs/taro'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TaroWithWeapp = {}, global._defineProperty, global._toConsumableArray, global._slicedToArray, global._classCallCheck, global._createClass, global._assertThisInitialized, global._get, global._inherits, global._possibleConstructorReturn, global._getPrototypeOf, global._typeof, global.runtime, global.taro));
5
- })(this, (function (exports, _defineProperty, _toConsumableArray, _slicedToArray, _classCallCheck, _createClass, _assertThisInitialized, _get, _inherits, _possibleConstructorReturn, _getPrototypeOf, _typeof, runtime, taro) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tarojs/runtime'), require('@tarojs/taro')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tarojs/runtime', '@tarojs/taro'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TaroWithWeapp = {}, global.runtime, global.taro));
5
+ })(this, (function (exports, runtime, taro) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
10
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
11
- var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
12
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
13
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
14
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
15
- var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get);
16
- var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
17
- var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
18
- var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
19
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
20
-
21
- var json = JSON;
22
- var clone = function clone(obj) {
23
- return json.parse(stringify(obj));
24
- };
25
- var isArray = Array.isArray || function (x) {
7
+ const json = JSON;
8
+ const clone = obj => json.parse(stringify(obj));
9
+ const isArray = Array.isArray || function (x) {
26
10
  return {}.toString.call(x) === '[object Array]';
27
11
  };
28
- var objectKeys = Object.keys || function (obj) {
29
- var has = Object.prototype.hasOwnProperty || function () {
12
+ const objectKeys = Object.keys || function (obj) {
13
+ const has = Object.prototype.hasOwnProperty || function () {
30
14
  return true;
31
15
  };
32
- var keys = [];
33
- for (var key in obj) {
16
+ const keys = [];
17
+ for (const key in obj) {
34
18
  if (has.call(obj, key)) keys.push(key);
35
19
  }
36
20
  return keys;
@@ -40,20 +24,20 @@
40
24
  if (typeof opts === 'function') opts = {
41
25
  cmp: opts
42
26
  };
43
- var space = opts.space || '';
27
+ let space = opts.space || '';
44
28
  if (typeof space === 'number') space = Array(space + 1).join(' ');
45
- var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
46
- var replacer = opts.replacer || function (key, value) {
29
+ const cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
30
+ const replacer = opts.replacer || function (key, value) {
47
31
  return value;
48
32
  };
49
- var cmp = opts.cmp && function (f) {
33
+ const cmp = opts.cmp && function (f) {
50
34
  return function (node) {
51
35
  return function (a, b) {
52
- var aobj = {
36
+ const aobj = {
53
37
  key: a,
54
38
  value: node[a]
55
39
  };
56
- var bobj = {
40
+ const bobj = {
57
41
  key: b,
58
42
  value: node[b]
59
43
  };
@@ -61,10 +45,10 @@
61
45
  };
62
46
  };
63
47
  }(opts.cmp);
64
- var seen = [];
48
+ const seen = [];
65
49
  return function stringify(parent, key, node, level) {
66
- var indent = space ? '\n' + new Array(level + 1).join(space) : '';
67
- var colonSeparator = space ? ': ' : ':';
50
+ const indent = space ? '\n' + new Array(level + 1).join(space) : '';
51
+ const colonSeparator = space ? ': ' : ':';
68
52
  if (node && node.toJSON && typeof node.toJSON === 'function') {
69
53
  node = node.toJSON();
70
54
  }
@@ -72,13 +56,13 @@
72
56
  if (node === undefined) {
73
57
  return;
74
58
  }
75
- if (_typeof__default["default"](node) !== 'object' || node === null) {
59
+ if (typeof node !== 'object' || node === null) {
76
60
  return json.stringify(node);
77
61
  }
78
62
  if (isArray(node)) {
79
- var out = [];
80
- for (var i = 0; i < node.length; i++) {
81
- var item = stringify(node, i, node[i], level + 1) || json.stringify(null);
63
+ const out = [];
64
+ for (let i = 0; i < node.length; i++) {
65
+ const item = stringify(node, i, node[i], level + 1) || json.stringify(null);
82
66
  out.push(indent + space + item);
83
67
  }
84
68
  return '[' + out.join(',') + indent + ']';
@@ -87,17 +71,17 @@
87
71
  if (cycles) return json.stringify('__cycle__');
88
72
  throw new TypeError('Converting circular structure to JSON');
89
73
  } else seen.push(node);
90
- var keys = objectKeys(node).sort(cmp && cmp(node));
91
- var _out = [];
92
- for (var _i = 0; _i < keys.length; _i++) {
93
- var _key = keys[_i];
94
- var value = stringify(node, _key, node[_key], level + 1);
74
+ const keys = objectKeys(node).sort(cmp && cmp(node));
75
+ const out = [];
76
+ for (let i = 0; i < keys.length; i++) {
77
+ const key = keys[i];
78
+ const value = stringify(node, key, node[key], level + 1);
95
79
  if (!value) continue;
96
- var keyValue = json.stringify(_key) + colonSeparator + value;
97
- _out.push(indent + space + keyValue);
80
+ const keyValue = json.stringify(key) + colonSeparator + value;
81
+ out.push(indent + space + keyValue);
98
82
  }
99
83
  seen.splice(seen.indexOf(node), 1);
100
- return '{' + _out.join(',') + indent + '}';
84
+ return '{' + out.join(',') + indent + '}';
101
85
  }
102
86
  }({
103
87
  '': obj
@@ -105,23 +89,23 @@
105
89
  }
106
90
 
107
91
  /*eslint-disable*/
108
- var ARRAYTYPE = '[object Array]';
109
- var OBJECTTYPE = '[object Object]';
110
- var FUNCTIONTYPE = '[object Function]';
92
+ const ARRAYTYPE = '[object Array]';
93
+ const OBJECTTYPE = '[object Object]';
94
+ const FUNCTIONTYPE = '[object Function]';
111
95
  function diff(current, pre) {
112
- var result = {};
96
+ const result = {};
113
97
  syncKeys(current, pre);
114
98
  _diff(current, pre, '', result);
115
99
  return result;
116
100
  }
117
101
  function syncKeys(current, pre) {
118
102
  if (current === pre) return;
119
- var rootCurrentType = type(current);
120
- var rootPreType = type(pre);
103
+ const rootCurrentType = type(current);
104
+ const rootPreType = type(pre);
121
105
  if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
122
106
  // if(Object.keys(current).length >= Object.keys(pre).length){
123
- for (var key in pre) {
124
- var currentValue = current[key];
107
+ for (let key in pre) {
108
+ const currentValue = current[key];
125
109
  if (currentValue === undefined) {
126
110
  current[key] = null;
127
111
  } else {
@@ -131,7 +115,7 @@
131
115
  // }
132
116
  } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
133
117
  if (current.length >= pre.length) {
134
- pre.forEach(function (item, index) {
118
+ pre.forEach((item, index) => {
135
119
  syncKeys(current[index], item);
136
120
  });
137
121
  }
@@ -139,17 +123,17 @@
139
123
  }
140
124
  function _diff(current, pre, path, result) {
141
125
  if (current === pre) return;
142
- var rootCurrentType = type(current);
143
- var rootPreType = type(pre);
126
+ const rootCurrentType = type(current);
127
+ const rootPreType = type(pre);
144
128
  if (rootCurrentType == OBJECTTYPE) {
145
129
  if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length) {
146
130
  setResult(result, path, current);
147
131
  } else {
148
- var _loop = function _loop(key) {
149
- var currentValue = current[key];
150
- var preValue = pre[key];
151
- var currentType = type(currentValue);
152
- var preType = type(preValue);
132
+ for (let key in current) {
133
+ const currentValue = current[key];
134
+ const preValue = pre[key];
135
+ const currentType = type(currentValue);
136
+ const preType = type(preValue);
153
137
  if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
154
138
  if (currentValue != pre[key]) {
155
139
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
@@ -161,7 +145,7 @@
161
145
  if (currentValue.length < preValue.length) {
162
146
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
163
147
  } else {
164
- currentValue.forEach(function (item, index) {
148
+ currentValue.forEach((item, index) => {
165
149
  _diff(item, preValue[index], (path == '' ? '' : path + '.') + key + '[' + index + ']', result);
166
150
  });
167
151
  }
@@ -170,14 +154,11 @@
170
154
  if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) {
171
155
  setResult(result, (path == '' ? '' : path + '.') + key, currentValue);
172
156
  } else {
173
- for (var subKey in currentValue) {
157
+ for (let subKey in currentValue) {
174
158
  _diff(currentValue[subKey], preValue[subKey], (path == '' ? '' : path + '.') + key + '.' + subKey, result);
175
159
  }
176
160
  }
177
161
  }
178
- };
179
- for (var key in current) {
180
- _loop(key);
181
162
  }
182
163
  }
183
164
  } else if (rootCurrentType == ARRAYTYPE) {
@@ -187,7 +168,7 @@
187
168
  if (current.length < pre.length) {
188
169
  setResult(result, path, current);
189
170
  } else {
190
- current.forEach(function (item, index) {
171
+ current.forEach((item, index) => {
191
172
  _diff(item, pre[index], path + '[' + index + ']', result);
192
173
  });
193
174
  }
@@ -213,16 +194,20 @@
213
194
  TaroLifeCycles["DidHide"] = "componentDidHide";
214
195
  TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
215
196
  })(TaroLifeCycles || (TaroLifeCycles = {}));
216
- var lifecycleMap = _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, TaroLifeCycles.WillMount, ['created']), TaroLifeCycles.DidMount, ['attached']), TaroLifeCycles.DidShow, ['onShow']), TaroLifeCycles.DidHide, ['onHide']), TaroLifeCycles.WillUnmount, ['detached', 'onUnload']);
217
- var lifecycles = new Set(['ready']);
218
- for (var key in lifecycleMap) {
219
- var lifecycle = lifecycleMap[key];
220
- lifecycle.forEach(function (l) {
221
- return lifecycles.add(l);
222
- });
197
+ const lifecycleMap = {
198
+ [TaroLifeCycles.WillMount]: ['created'],
199
+ [TaroLifeCycles.DidMount]: ['attached'],
200
+ [TaroLifeCycles.DidShow]: ['onShow'],
201
+ [TaroLifeCycles.DidHide]: ['onHide'],
202
+ [TaroLifeCycles.WillUnmount]: ['detached', 'onUnload']
203
+ };
204
+ const lifecycles = new Set(['ready']);
205
+ for (const key in lifecycleMap) {
206
+ const lifecycle = lifecycleMap[key];
207
+ lifecycle.forEach(l => lifecycles.add(l));
223
208
  }
224
- var uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
225
- var appOptions = ['onLaunch', 'onShow', 'onHide', 'onError', 'onPageNotFound', 'onUnhandledRejection', 'onThemeChange'];
209
+ const uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
210
+ const appOptions = ['onLaunch', 'onShow', 'onHide', 'onError', 'onPageNotFound', 'onUnhandledRejection', 'onThemeChange'];
226
211
 
227
212
  /**
228
213
  * Simple bind, faster than native
@@ -230,7 +215,7 @@
230
215
  function bind(fn /*: Function */, ctx /*: Object */) {
231
216
  if (!fn) return false;
232
217
  function boundFn(a) {
233
- var l /*: number */ = arguments.length;
218
+ const l /*: number */ = arguments.length;
234
219
  return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
235
220
  }
236
221
  // record original fn length
@@ -244,7 +229,7 @@
244
229
  if (!obj) {
245
230
  return defaultValue;
246
231
  }
247
- var props, prop;
232
+ let props, prop;
248
233
  if (Array.isArray(propsArg)) {
249
234
  props = propsArg.slice(0);
250
235
  }
@@ -252,7 +237,7 @@
252
237
  props = propsArg.replace(/\[(.+?)\]/g, '.$1');
253
238
  props = props.split('.');
254
239
  }
255
- if (_typeof__default["default"](propsArg) === 'symbol') {
240
+ if (typeof propsArg === 'symbol') {
256
241
  props = [propsArg];
257
242
  }
258
243
  if (!Array.isArray(props)) {
@@ -275,14 +260,14 @@
275
260
  props = props.replace(/\[(.+?)\]/g, '.$1');
276
261
  props = props.split('.');
277
262
  }
278
- if (_typeof__default["default"](props) === 'symbol') {
263
+ if (typeof props === 'symbol') {
279
264
  props = [props];
280
265
  }
281
- var lastProp = props.pop();
266
+ const lastProp = props.pop();
282
267
  if (!lastProp) {
283
268
  return false;
284
269
  }
285
- var thisProp;
270
+ let thisProp;
286
271
  while (thisProp = props.shift()) {
287
272
  if (typeof obj[thisProp] === 'undefined') {
288
273
  obj[thisProp] = {};
@@ -290,12 +275,12 @@
290
275
  // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
291
276
  // 因此按路径寻找时,每一层都复制一遍
292
277
  if (Array.isArray(obj[thisProp])) {
293
- obj[thisProp] = _toConsumableArray__default["default"](obj[thisProp]);
294
- } else if (_typeof__default["default"](obj[thisProp]) === 'object') {
278
+ obj[thisProp] = [...obj[thisProp]];
279
+ } else if (typeof obj[thisProp] === 'object') {
295
280
  obj[thisProp] = Object.assign({}, obj[thisProp]);
296
281
  }
297
282
  obj = obj[thisProp];
298
- if (!obj || _typeof__default["default"](obj) !== 'object') {
283
+ if (!obj || typeof obj !== 'object') {
299
284
  return false;
300
285
  }
301
286
  }
@@ -305,26 +290,24 @@
305
290
  function report(msg) {
306
291
  console.warn('[Taro Convert Warning] ' + msg);
307
292
  }
308
- var nonsupport = new Map([['onError', '不支持 App 的 onError 生命周期方法。'], ['onPageNotFound', '不支持 App 的 onPageNotFound 生命周期方法。'], ['onUnhandledRejection', '不支持 App 的 onUnhandledRejection 生命周期方法。'], ['onThemeChange', '不支持 App 的 onThemeChange 生命周期方法。'], ['moved', '不支持自定义组件的 moved 生命周期。'], ['externalClasses', '不支持自定义组件的 externalClasses 功能。'], ['relations', '不支持自定义组件的 relations 功能。'], ['options', '不支持自定义组件的 options 功能。'], ['definitionFilter', '不支持自定义组件的 definitionFilter 功能。'], ['selectComponent', 'selectComponent 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectAllComponents', 'selectAllComponents 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectOwnerComponent', 'selectOwnerComponent 方法产生不到目标效果,请使用 React 语法重构。'], ['groupSetData', 'groupSetData 方法产生不到目标效果,请使用 React 语法重构。']]);
293
+ const nonsupport = new Map([['onError', '不支持 App 的 onError 生命周期方法。'], ['onPageNotFound', '不支持 App 的 onPageNotFound 生命周期方法。'], ['onUnhandledRejection', '不支持 App 的 onUnhandledRejection 生命周期方法。'], ['onThemeChange', '不支持 App 的 onThemeChange 生命周期方法。'], ['moved', '不支持自定义组件的 moved 生命周期。'], ['externalClasses', '不支持自定义组件的 externalClasses 功能。'], ['relations', '不支持自定义组件的 relations 功能。'], ['options', '不支持自定义组件的 options 功能。'], ['definitionFilter', '不支持自定义组件的 definitionFilter 功能。'], ['selectComponent', 'selectComponent 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectAllComponents', 'selectAllComponents 方法产生不到目标效果,请使用 React 的 ref 进行重构。'], ['selectOwnerComponent', 'selectOwnerComponent 方法产生不到目标效果,请使用 React 语法重构。'], ['groupSetData', 'groupSetData 方法产生不到目标效果,请使用 React 语法重构。']]);
309
294
  function flattenBehaviors(behavior, behaviorMap) {
310
295
  if (typeof behavior === 'string') {
311
- return report("\u4E0D\u652F\u6301\u4F7F\u7528\u5185\u7F6E Behavior: [".concat(behavior, "]"));
296
+ return report(`不支持使用内置 Behavior: [${behavior}]`);
312
297
  }
313
- var subBehaviors = behavior.behaviors;
298
+ const subBehaviors = behavior.behaviors;
314
299
  if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
315
- subBehaviors.forEach(function (subBehavior) {
316
- return flattenBehaviors(subBehavior, behaviorMap);
317
- });
300
+ subBehaviors.forEach(subBehavior => flattenBehaviors(subBehavior, behaviorMap));
318
301
  }
319
- Object.keys(behavior).forEach(function (key) {
302
+ Object.keys(behavior).forEach(key => {
320
303
  // 不支持的属性
321
304
  if (nonsupport.has(key)) {
322
- var advise = nonsupport.get(key);
305
+ const advise = nonsupport.get(key);
323
306
  return report(advise);
324
307
  }
325
308
  if (behaviorMap.has(key)) {
326
- var list = behaviorMap.get(key);
327
- var value = behavior[key];
309
+ const list = behaviorMap.get(key);
310
+ const value = behavior[key];
328
311
  list.push(value);
329
312
  }
330
313
  });
@@ -333,21 +316,21 @@
333
316
  /**
334
317
  * 该模块仅存放 convert 转换时用到的工具函数或变量
335
318
  */
336
- var cacheOptions = {
319
+ const cacheOptions = {
337
320
  cacheOptions: {},
338
- setOptionsToCache: function setOptionsToCache(options) {
321
+ setOptionsToCache: function (options) {
339
322
  if (Object.keys(options).length !== 0) {
340
323
  this.cacheOptions = options;
341
324
  }
342
325
  },
343
- getOptionsFromCache: function getOptionsFromCache() {
326
+ getOptionsFromCache: function () {
344
327
  return this.cacheOptions;
345
328
  }
346
329
  };
347
330
  function toCamelCase(s) {
348
- var camel = '';
349
- var nextCap = false;
350
- for (var i = 0; i < s.length; i++) {
331
+ let camel = '';
332
+ let nextCap = false;
333
+ for (let i = 0; i < s.length; i++) {
351
334
  if (s[i] !== '-') {
352
335
  camel += nextCap ? s[i].toUpperCase() : s[i];
353
336
  nextCap = false;
@@ -357,41 +340,39 @@
357
340
  }
358
341
  return camel;
359
342
  }
360
- var convertToArray = function convertToArray(value, fn) {
343
+ const convertToArray = function (value, fn) {
361
344
  if (value instanceof Array) {
362
345
  return value.map(fn);
363
346
  } else if (typeof value === 'number') {
364
347
  return Array.from({
365
348
  length: value
366
- }, function (_, index) {
367
- return index;
368
- }).map(fn);
349
+ }, (_, index) => index).map(fn);
369
350
  } else if (typeof value === 'string') {
370
351
  return Array.from(value).map(fn);
371
- } else if (_typeof__default["default"](value) === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
372
- var result = Object.keys(value).map(function (item) {
352
+ } else if (typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
353
+ const result = Object.keys(value).map(item => {
373
354
  return fn(value[item], item);
374
355
  });
375
356
  return result;
376
357
  }
377
358
  };
378
- var getTarget = function getTarget(target, Taro) {
359
+ const getTarget = (target, Taro) => {
379
360
  if (!target) {
380
361
  return {
381
362
  dataset: {}
382
363
  };
383
364
  }
384
- if (Taro.getEnv() === Taro.ENV_TYPE.MPHARMONY || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
365
+ if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
385
366
  if (target.fullDataset) {
386
367
  return {
387
368
  dataset: target.fullDataset
388
369
  };
389
370
  }
390
- var fullDataset = {};
371
+ const fullDataset = {};
391
372
  // 获取元素的所有属性
392
- var targetAttrKeys = Object.keys(target);
373
+ const targetAttrKeys = Object.keys(target);
393
374
  // 遍历所有属性
394
- for (var i = 0; i < targetAttrKeys.length; i++) {
375
+ for (let i = 0; i < targetAttrKeys.length; i++) {
395
376
  if (targetAttrKeys[i].startsWith('data-')) {
396
377
  fullDataset[toCamelCase(targetAttrKeys[i].replace(/^data-/, '').toLowerCase())] = target[targetAttrKeys[i]];
397
378
  }
@@ -404,16 +385,11 @@
404
385
  return target;
405
386
  };
406
387
 
407
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
408
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
409
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
410
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
411
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
412
388
  function defineGetter(component, key, getter) {
413
389
  Object.defineProperty(component, key, {
414
390
  enumerable: true,
415
391
  configurable: true,
416
- get: function get() {
392
+ get: () => {
417
393
  if (getter === 'props') {
418
394
  return component.props;
419
395
  }
@@ -425,38 +401,38 @@
425
401
  }
426
402
  });
427
403
  }
404
+
428
405
  function propToState(newValue, _oldValue, key) {
429
406
  this.state[key] = newValue;
430
407
  }
431
408
  function isFunction(o) {
432
409
  return typeof o === 'function';
433
410
  }
434
- function withWeapp(weappConf) {
435
- var isApp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
436
- if (_typeof__default["default"](weappConf) === 'object' && Object.keys(weappConf).length === 0) {
411
+ function withWeapp(weappConf, isApp = false) {
412
+ if (typeof weappConf === 'object' && Object.keys(weappConf).length === 0) {
437
413
  report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
438
414
  }
439
- return function (ConnectComponent) {
415
+ return ConnectComponent => {
440
416
  var _a;
441
- var behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
442
- var behaviorProperties = {};
417
+ const behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
418
+ const behaviorProperties = {};
443
419
  if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
444
- var behaviors = weappConf.behaviors;
445
- behaviors.forEach(function (behavior) {
446
- return flattenBehaviors(behavior, behaviorMap);
447
- });
448
- var propertiesList = behaviorMap.get('properties');
420
+ const {
421
+ behaviors
422
+ } = weappConf;
423
+ behaviors.forEach(behavior => flattenBehaviors(behavior, behaviorMap));
424
+ const propertiesList = behaviorMap.get('properties');
449
425
  if (propertiesList.length) {
450
- propertiesList.forEach(function (property) {
426
+ propertiesList.forEach(property => {
451
427
  Object.assign(behaviorProperties, property);
452
428
  });
453
- Object.keys(behaviorProperties).forEach(function (propName) {
454
- var propValue = behaviorProperties[propName];
429
+ Object.keys(behaviorProperties).forEach(propName => {
430
+ const propValue = behaviorProperties[propName];
455
431
  if (!weappConf.properties) {
456
432
  weappConf.properties = {};
457
433
  }
458
434
  if (!weappConf.properties.hasOwnProperty(propName)) {
459
- if (propValue && _typeof__default["default"](propValue) === 'object' && propValue.value) {
435
+ if (propValue && typeof propValue === 'object' && propValue.value) {
460
436
  propValue.value = clone(propValue.value);
461
437
  }
462
438
  weappConf.properties[propName] = propValue;
@@ -464,45 +440,38 @@
464
440
  });
465
441
  }
466
442
  }
467
- var BaseComponent = /*#__PURE__*/function (_ConnectComponent) {
468
- _inherits__default["default"](BaseComponent, _ConnectComponent);
469
- var _super = _createSuper(BaseComponent);
470
- function BaseComponent(props) {
471
- var _this;
472
- _classCallCheck__default["default"](this, BaseComponent);
473
- _this = _super.call(this, props);
474
- _this._observeProps = [];
443
+ class BaseComponent extends ConnectComponent {
444
+ constructor(props) {
445
+ super(props);
446
+ this._observeProps = [];
475
447
  // mixins 可以多次调用生命周期
476
- _this.willMounts = [];
477
- _this.didMounts = [];
478
- _this.didHides = [];
479
- _this.didShows = [];
480
- _this.willUnmounts = [];
481
- _this.eventDestroyList = [];
482
- _this.current = runtime.getCurrentInstance();
483
- _this.taroGlobalData = Object.create(null);
484
- _this.safeExecute = function (func) {
485
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
486
- args[_key - 1] = arguments[_key];
487
- }
488
- if (isFunction(func)) func.apply(_assertThisInitialized__default["default"](_this), args);
448
+ this.willMounts = [];
449
+ this.didMounts = [];
450
+ this.didHides = [];
451
+ this.didShows = [];
452
+ this.willUnmounts = [];
453
+ this.eventDestroyList = [];
454
+ this.current = runtime.getCurrentInstance();
455
+ this.taroGlobalData = Object.create(null);
456
+ this.safeExecute = (func, ...args) => {
457
+ if (isFunction(func)) func.apply(this, args);
489
458
  };
490
- _this.setData = function (obj, callback) {
491
- var oldState;
492
- if (_this.observers && Object.keys(Object.keys(_this.observers))) {
493
- oldState = clone(_this.state);
459
+ this.setData = (obj, callback) => {
460
+ let oldState;
461
+ if (this.observers && Object.keys(Object.keys(this.observers))) {
462
+ oldState = clone(this.state);
494
463
  }
495
- Object.keys(obj).forEach(function (key) {
496
- safeSet(_this.state, key, obj[key]);
464
+ Object.keys(obj).forEach(key => {
465
+ safeSet(this.state, key, obj[key]);
497
466
  });
498
- _this.setState(_this.state, function () {
499
- _this.triggerObservers(_this.state, oldState);
467
+ this.setState(this.state, () => {
468
+ this.triggerObservers(this.state, oldState);
500
469
  if (callback) {
501
- callback.call(_assertThisInitialized__default["default"](_this));
470
+ callback.call(this);
502
471
  }
503
472
  });
504
473
  };
505
- _this.triggerEvent = function (eventName, detail, options) {
474
+ this.triggerEvent = (eventName, detail, options) => {
506
475
  if (options) {
507
476
  report('triggerEvent 不支持事件选项。');
508
477
  }
@@ -512,561 +481,467 @@
512
481
  return match[1].toUpperCase();
513
482
  });
514
483
  }
515
- var props = _this.props;
516
- var dataset = {};
517
- for (var key in props) {
484
+ const props = this.props;
485
+ const dataset = {};
486
+ for (const key in props) {
518
487
  if (!key.startsWith('data-')) continue;
519
488
  dataset[key.replace(/^data-/, '')] = props[key];
520
489
  }
521
- var func = props["on".concat(eventName[0].toUpperCase()).concat(eventName.slice(1))];
490
+ const func = props[`on${eventName[0].toUpperCase()}${eventName.slice(1)}`];
522
491
  if (isFunction(func)) {
523
- func.call(_assertThisInitialized__default["default"](_this), {
492
+ func.call(this, {
524
493
  type: eventName,
525
- detail: detail,
494
+ detail,
526
495
  target: {
527
496
  id: props.id || '',
528
- dataset: dataset
497
+ dataset
529
498
  },
530
499
  currentTarget: {
531
500
  id: props.id || '',
532
- dataset: dataset
501
+ dataset
533
502
  }
534
503
  });
535
504
  }
536
505
  };
537
- _this.hasBehavior = _this.componentMethodsProxy('hasBehavior');
538
- _this.createSelectorQuery = _this.componentMethodsProxy('createSelectorQuery');
539
- _this.createIntersectionObserver = _this.componentMethodsProxy('createIntersectionObserver');
540
- _this.createMediaQueryObserver = _this.componentMethodsProxy('createMediaQueryObserver');
541
- _this.getRelationNodes = _this.componentMethodsProxy('getRelationNodes');
542
- _this.getTabBar = _this.componentMethodsProxy('getTabBar');
543
- _this.getPageId = _this.componentMethodsProxy('getPageId');
544
- _this.animate = _this.componentMethodsProxy('animate');
545
- _this.clearAnimation = _this.componentMethodsProxy('clearAnimation');
546
- _this.setUpdatePerformanceListener = _this.componentMethodsProxy('setUpdatePerformanceListener');
547
- _this.state = _this.state || {};
548
- _this.init(weappConf);
549
- defineGetter(_assertThisInitialized__default["default"](_this), 'data', 'state');
550
- defineGetter(_assertThisInitialized__default["default"](_this), 'properties', 'props');
551
- return _this;
506
+ this.hasBehavior = this.componentMethodsProxy('hasBehavior');
507
+ this.createSelectorQuery = this.componentMethodsProxy('createSelectorQuery');
508
+ this.createIntersectionObserver = this.componentMethodsProxy('createIntersectionObserver');
509
+ this.createMediaQueryObserver = this.componentMethodsProxy('createMediaQueryObserver');
510
+ this.getRelationNodes = this.componentMethodsProxy('getRelationNodes');
511
+ this.getTabBar = this.componentMethodsProxy('getTabBar');
512
+ this.getPageId = this.componentMethodsProxy('getPageId');
513
+ this.animate = this.componentMethodsProxy('animate');
514
+ this.clearAnimation = this.componentMethodsProxy('clearAnimation');
515
+ this.setUpdatePerformanceListener = this.componentMethodsProxy('setUpdatePerformanceListener');
516
+ this.state = this.state || {};
517
+ this.init(weappConf);
518
+ defineGetter(this, 'data', 'state');
519
+ defineGetter(this, 'properties', 'props');
552
520
  }
553
- _createClass__default["default"](BaseComponent, [{
554
- key: "initProps",
555
- value: function initProps(props) {
556
- var properties = {};
557
- for (var propKey in props) {
558
- if (props.hasOwnProperty(propKey)) {
559
- var propValue = props[propKey];
560
- // propValue 可能是 null, 构造函数, 对象
561
- var observers = [propToState];
562
- if (propValue === null || propValue === undefined) {
563
- // propValue为null、undefined情况
564
- properties[propKey] = null;
565
- } else if (isFunction(propValue)) {
566
- // propValue为Function,即Array、String、Boolean等情况时
567
- if (propValue.name === 'Array') {
568
- properties[propKey] = [];
569
- } else if (propValue.name === 'String') {
570
- properties[propKey] = '';
571
- } else if (propValue.name === 'Boolean') {
572
- properties[propKey] = false;
573
- } else if (propValue.name === 'Number') {
574
- properties[propKey] = 0;
575
- } else {
576
- properties[propKey] = null;
577
- }
578
- } else if (_typeof__default["default"](propValue) === 'object') {
579
- // propValue为对象时
580
- properties[propKey] = propValue.value;
581
- if (propValue.observer) {
582
- observers.push(propValue.observer);
583
- }
521
+ initProps(props) {
522
+ const properties = {};
523
+ for (const propKey in props) {
524
+ if (props.hasOwnProperty(propKey)) {
525
+ const propValue = props[propKey];
526
+ // propValue 可能是 null, 构造函数, 对象
527
+ const observers = [propToState];
528
+ if (propValue === null || propValue === undefined) {
529
+ // propValue为null、undefined情况
530
+ properties[propKey] = null;
531
+ } else if (isFunction(propValue)) {
532
+ // propValue为Function,即Array、String、Boolean等情况时
533
+ if (propValue.name === 'Array') {
534
+ properties[propKey] = [];
535
+ } else if (propValue.name === 'String') {
536
+ properties[propKey] = '';
537
+ } else if (propValue.name === 'Boolean') {
538
+ properties[propKey] = false;
539
+ } else if (propValue.name === 'Number') {
540
+ properties[propKey] = 0;
584
541
  } else {
585
542
  properties[propKey] = null;
586
543
  }
587
- this._observeProps.push({
588
- name: propKey,
589
- observers: observers
590
- });
544
+ } else if (typeof propValue === 'object') {
545
+ // propValue为对象时
546
+ properties[propKey] = propValue.value;
547
+ if (propValue.observer) {
548
+ observers.push(propValue.observer);
549
+ }
550
+ } else {
551
+ properties[propKey] = null;
591
552
  }
553
+ this._observeProps.push({
554
+ name: propKey,
555
+ observers: observers
556
+ });
592
557
  }
593
- this.state = Object.assign(Object.assign({}, properties), this.state);
594
558
  }
595
- }, {
596
- key: "init",
597
- value: function init(options) {
598
- var _this2 = this;
599
- var _a, _b, _c;
600
- // 处理 Behaviors
601
- if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
602
- var _iterator = _createForOfIteratorHelper(behaviorMap.entries()),
603
- _step;
604
- try {
605
- var _loop = function _loop() {
606
- var _step$value = _slicedToArray__default["default"](_step.value, 2),
607
- key = _step$value[0],
608
- list = _step$value[1];
609
- switch (key) {
610
- case 'created':
611
- case 'attached':
612
- case 'detached':
613
- case 'ready':
614
- list.forEach(function (fn) {
615
- return _this2.initLifeCycles(key, fn);
616
- });
617
- break;
618
- }
619
- };
620
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
621
- _loop();
622
- }
623
- } catch (err) {
624
- _iterator.e(err);
625
- } finally {
626
- _iterator.f();
559
+ this.state = Object.assign(Object.assign({}, properties), this.state);
560
+ }
561
+ init(options) {
562
+ var _a, _b, _c;
563
+ // 处理 Behaviors
564
+ if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
565
+ for (const [key, list] of behaviorMap.entries()) {
566
+ switch (key) {
567
+ case 'created':
568
+ case 'attached':
569
+ case 'detached':
570
+ case 'ready':
571
+ list.forEach(fn => this.initLifeCycles(key, fn));
572
+ break;
627
573
  }
628
574
  }
629
- for (var confKey in options) {
630
- // 不支持的属性
631
- if (nonsupport.has(confKey)) {
632
- var advise = nonsupport.get(confKey);
633
- report(advise);
634
- }
635
- var confValue = options[confKey];
636
- switch (confKey) {
637
- case 'behaviors':
638
- break;
639
- case 'data':
640
- {
641
- if (isApp) {
642
- this[confKey] = confValue;
643
- if (!appOptions.includes(confKey)) {
644
- this.defineProperty(this.taroGlobalData, confKey, this);
645
- }
646
- } else {
647
- this.state = Object.assign(Object.assign({}, confValue), this.state);
575
+ }
576
+ for (const confKey in options) {
577
+ // 不支持的属性
578
+ if (nonsupport.has(confKey)) {
579
+ const advise = nonsupport.get(confKey);
580
+ report(advise);
581
+ }
582
+ const confValue = options[confKey];
583
+ switch (confKey) {
584
+ case 'behaviors':
585
+ break;
586
+ case 'data':
587
+ {
588
+ if (isApp) {
589
+ this[confKey] = confValue;
590
+ if (!appOptions.includes(confKey)) {
591
+ this.defineProperty(this.taroGlobalData, confKey, this);
648
592
  }
649
- break;
593
+ } else {
594
+ this.state = Object.assign(Object.assign({}, confValue), this.state);
650
595
  }
651
- case 'properties':
652
- this.initProps(Object.assign(behaviorProperties, confValue));
653
596
  break;
654
- case 'methods':
655
- for (var key in confValue) {
656
- var method = confValue[key];
657
- this[key] = bind(method, this);
597
+ }
598
+ case 'properties':
599
+ this.initProps(Object.assign(behaviorProperties, confValue));
600
+ break;
601
+ case 'methods':
602
+ for (const key in confValue) {
603
+ const method = confValue[key];
604
+ this[key] = bind(method, this);
605
+ }
606
+ break;
607
+ case 'lifetimes':
608
+ for (const key in confValue) {
609
+ this.initLifeCycles(key, confValue[key]);
610
+ }
611
+ break;
612
+ case 'pageLifetimes':
613
+ for (const key in confValue) {
614
+ const cb = confValue[key];
615
+ switch (key) {
616
+ case 'show':
617
+ {
618
+ this.initLifeCycleListener('show', cb);
619
+ break;
620
+ }
621
+ case 'hide':
622
+ {
623
+ this.initLifeCycleListener('hide', cb);
624
+ break;
625
+ }
626
+ case 'resize':
627
+ {
628
+ report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
629
+ break;
630
+ }
658
631
  }
659
- break;
660
- case 'lifetimes':
661
- for (var _key2 in confValue) {
662
- this.initLifeCycles(_key2, confValue[_key2]);
632
+ }
633
+ break;
634
+ default:
635
+ if (lifecycles.has(confKey)) {
636
+ // 优先使用 lifetimes 中定义的生命周期
637
+ if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
638
+ break;
663
639
  }
664
- break;
665
- case 'pageLifetimes':
666
- for (var _key3 in confValue) {
667
- var cb = confValue[_key3];
668
- switch (_key3) {
669
- case 'show':
670
- {
671
- this.initLifeCycleListener('show', cb);
672
- break;
673
- }
674
- case 'hide':
675
- {
676
- this.initLifeCycleListener('hide', cb);
677
- break;
678
- }
679
- case 'resize':
680
- {
681
- report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
682
- break;
683
- }
684
- }
640
+ const lifecycle = options[confKey];
641
+ this.initLifeCycles(confKey, lifecycle);
642
+ } else if (isFunction(confValue)) {
643
+ this[confKey] = bind(confValue, this);
644
+ if (isApp && !appOptions.includes(confKey)) {
645
+ this.defineProperty(this.taroGlobalData, confKey, this);
685
646
  }
686
- break;
687
- default:
688
- if (lifecycles.has(confKey)) {
689
- // 优先使用 lifetimes 中定义的生命周期
690
- if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
691
- break;
692
- }
693
- var lifecycle = options[confKey];
694
- this.initLifeCycles(confKey, lifecycle);
695
- } else if (isFunction(confValue)) {
696
- this[confKey] = bind(confValue, this);
697
- if (isApp && !appOptions.includes(confKey)) {
698
- this.defineProperty(this.taroGlobalData, confKey, this);
699
- }
700
- // 原生页面和 Taro 页面中共计只能定义一次的生命周期
701
- if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
702
- report("\u751F\u547D\u5468\u671F ".concat(confKey, " \u5DF2\u5728\u539F\u751F\u90E8\u5206\u8FDB\u884C\u5B9A\u4E49\uFF0CReact \u90E8\u5206\u7684\u5B9A\u4E49\u5C06\u4E0D\u4F1A\u88AB\u6267\u884C\u3002"));
703
- }
704
- } else {
705
- this[confKey] = confValue;
706
- if (isApp && !appOptions.includes(confKey)) {
707
- this.defineProperty(this.taroGlobalData, confKey, this);
708
- }
647
+ // 原生页面和 Taro 页面中共计只能定义一次的生命周期
648
+ if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
649
+ report(`生命周期 ${confKey} 已在原生部分进行定义,React 部分的定义将不会被执行。`);
709
650
  }
710
- break;
711
- }
712
- }
713
- // 处理 Behaviors
714
- if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
715
- var behaviorData = {};
716
- var methods = {};
717
- var _iterator2 = _createForOfIteratorHelper(behaviorMap.entries()),
718
- _step2;
719
- try {
720
- var _loop2 = function _loop2() {
721
- var _step2$value = _slicedToArray__default["default"](_step2.value, 2),
722
- key = _step2$value[0],
723
- list = _step2$value[1];
724
- switch (key) {
725
- case 'data':
726
- [].concat(_toConsumableArray__default["default"](list), [_this2.state]).forEach(function (dataObject, index) {
727
- Object.keys(dataObject).forEach(function (dataKey) {
728
- var value = dataObject[dataKey];
729
- var preValue = behaviorData[dataKey];
730
- var valueType = _typeof__default["default"](value);
731
- var preValueType = _typeof__default["default"](preValue);
732
- if (valueType === 'object') {
733
- if (!value) {
734
- behaviorData[dataKey] = value;
735
- } else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
736
- behaviorData[dataKey] = index === list.length ? value : clone(value);
737
- } else {
738
- var newVal = Object.assign({}, preValue, value);
739
- behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
740
- }
741
- } else {
742
- behaviorData[dataKey] = value;
743
- }
744
- });
745
- });
746
- _this2.state = behaviorData;
747
- break;
748
- case 'methods':
749
- list.forEach(function (methodsObject) {
750
- Object.assign(methods, methodsObject);
751
- });
752
- Object.keys(methods).forEach(function (methodName) {
753
- if (!_this2[methodName]) {
754
- var _method = methods[methodName];
755
- _this2[methodName] = bind(_method, _this2);
756
- }
757
- });
758
- break;
759
- case 'lifetimes':
760
- list.forEach(function (lifetimesObject) {
761
- for (var _key4 in lifetimesObject) {
762
- _this2.initLifeCycles(_key4, lifetimesObject[_key4]);
763
- }
764
- });
765
- break;
766
- default:
767
- break;
651
+ } else {
652
+ this[confKey] = confValue;
653
+ if (isApp && !appOptions.includes(confKey)) {
654
+ this.defineProperty(this.taroGlobalData, confKey, this);
768
655
  }
769
- };
770
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
771
- _loop2();
772
656
  }
773
- } catch (err) {
774
- _iterator2.e(err);
775
- } finally {
776
- _iterator2.f();
777
- }
657
+ break;
778
658
  }
779
659
  }
780
- }, {
781
- key: "initLifeCycles",
782
- value: function initLifeCycles(lifecycleName, lifecycle) {
783
- // 不支持的生命周期
784
- if (nonsupport.has(lifecycleName)) {
785
- var advise = nonsupport.get(lifecycleName);
786
- return report(advise);
787
- }
788
- if (lifecycleName === 'ready') {
789
- // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
790
- if (this.current.page.onReady.called) {
791
- this.didMounts.push(function () {
792
- var _this3 = this;
793
- for (var _len2 = arguments.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
794
- args[_key5] = arguments[_key5];
795
- }
796
- taro.nextTick(function () {
797
- if (isFunction(lifecycle)) {
798
- lifecycle.apply(_this3, args);
660
+ // 处理 Behaviors
661
+ if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
662
+ const behaviorData = {};
663
+ const methods = {};
664
+ for (const [key, list] of behaviorMap.entries()) {
665
+ switch (key) {
666
+ case 'data':
667
+ [...list, this.state].forEach((dataObject, index) => {
668
+ Object.keys(dataObject).forEach(dataKey => {
669
+ const value = dataObject[dataKey];
670
+ const preValue = behaviorData[dataKey];
671
+ const valueType = typeof value;
672
+ const preValueType = typeof preValue;
673
+ if (valueType === 'object') {
674
+ if (!value) {
675
+ behaviorData[dataKey] = value;
676
+ } else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
677
+ behaviorData[dataKey] = index === list.length ? value : clone(value);
678
+ } else {
679
+ const newVal = Object.assign({}, preValue, value);
680
+ behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
681
+ }
682
+ } else {
683
+ behaviorData[dataKey] = value;
684
+ }
685
+ });
686
+ });
687
+ this.state = behaviorData;
688
+ break;
689
+ case 'methods':
690
+ list.forEach(methodsObject => {
691
+ Object.assign(methods, methodsObject);
692
+ });
693
+ Object.keys(methods).forEach(methodName => {
694
+ if (!this[methodName]) {
695
+ const method = methods[methodName];
696
+ this[methodName] = bind(method, this);
799
697
  }
800
698
  });
801
- });
802
- } else {
803
- this.initLifeCycleListener('ready', lifecycle);
804
- }
805
- } else {
806
- for (var lifecycleKey in lifecycleMap) {
807
- var cycleNames = lifecycleMap[lifecycleKey];
808
- if (cycleNames.indexOf(lifecycleName) !== -1) {
809
- switch (lifecycleKey) {
810
- case TaroLifeCycles.DidHide:
811
- this.didHides.push(lifecycle);
812
- break;
813
- case TaroLifeCycles.DidMount:
814
- this.didMounts.push(lifecycle);
815
- break;
816
- case TaroLifeCycles.DidShow:
817
- this.didShows.push(lifecycle);
818
- break;
819
- case TaroLifeCycles.WillMount:
820
- this.willMounts.push(lifecycle);
821
- break;
822
- case TaroLifeCycles.WillUnmount:
823
- this.willUnmounts.push(lifecycle);
824
- break;
825
- }
826
- }
699
+ break;
700
+ case 'lifetimes':
701
+ list.forEach(lifetimesObject => {
702
+ for (const key in lifetimesObject) {
703
+ this.initLifeCycles(key, lifetimesObject[key]);
704
+ }
705
+ });
706
+ break;
827
707
  }
828
708
  }
829
- // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
830
- if (!isFunction(this[lifecycleName])) {
831
- this[lifecycleName] = lifecycle;
832
- }
833
- }
834
- }, {
835
- key: "initLifeCycleListener",
836
- value: function initLifeCycleListener(name, cb) {
837
- // 组件的 ready、show、hide 需要利用页面事件触发
838
- var router = this.current.router;
839
- var lifecycleName = "on".concat(name[0].toUpperCase()).concat(name.slice(1));
840
- cb = cb.bind(this);
841
- (router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
842
- // unMount 时需要取消事件监听
843
- this.eventDestroyList.push(function () {
844
- return taro.eventCenter.off(router[lifecycleName], cb);
845
- });
846
709
  }
847
- }, {
848
- key: "executeLifeCycles",
849
- value: function executeLifeCycles(funcs) {
850
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key6 = 1; _key6 < _len3; _key6++) {
851
- args[_key6 - 1] = arguments[_key6];
852
- }
853
- for (var i = 0; i < funcs.length; i++) {
854
- var func = funcs[i];
855
- this.safeExecute.apply(this, [func].concat(args));
856
- }
710
+ }
711
+ initLifeCycles(lifecycleName, lifecycle) {
712
+ // 不支持的生命周期
713
+ if (nonsupport.has(lifecycleName)) {
714
+ const advise = nonsupport.get(lifecycleName);
715
+ return report(advise);
857
716
  }
858
- }, {
859
- key: "triggerPropertiesObservers",
860
- value: function triggerPropertiesObservers(prevProps, nextProps) {
861
- var _this4 = this;
862
- this._observeProps.forEach(function (_ref) {
863
- var key = _ref.name,
864
- observers = _ref.observers;
865
- var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
866
- var nextProp = nextProps[key];
867
- // 小程序是深比较不同之后才 trigger observer
868
- if (!isEqual(prop, nextProp)) {
869
- observers.forEach(function (observer) {
870
- if (typeof observer === 'string') {
871
- var ob = _this4[observer];
872
- if (isFunction(ob)) {
873
- ob.call(_this4, nextProp, prop, key);
874
- }
875
- } else if (isFunction(observer)) {
876
- observer.call(_this4, nextProp, prop, key);
717
+ if (lifecycleName === 'ready') {
718
+ // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
719
+ if (this.current.page.onReady.called) {
720
+ this.didMounts.push(function (...args) {
721
+ taro.nextTick(() => {
722
+ if (isFunction(lifecycle)) {
723
+ lifecycle.apply(this, args);
877
724
  }
878
725
  });
879
- }
880
- });
881
- }
882
- }, {
883
- key: "triggerObservers",
884
- value: function triggerObservers(current, prev) {
885
- var observers = this.observers;
886
- if (observers == null) {
887
- return;
888
- }
889
- if (Object.keys(observers).length === 0) {
890
- return;
891
- }
892
- var result = diff(current, prev);
893
- var resultKeys = Object.keys(result);
894
- if (resultKeys.length === 0) {
895
- return;
896
- }
897
- for (var observerKey in observers) {
898
- if (/\*\*/.test(observerKey)) {
899
- report('数据监听器 observers 不支持使用通配符 **。');
900
- continue;
901
- }
902
- var keys = observerKey.split(',').map(function (k) {
903
- return k.trim();
904
726
  });
905
- var isModified = false;
906
- for (var i = 0; i < keys.length; i++) {
907
- var key = keys[i];
908
- for (var j = 0; j < resultKeys.length; j++) {
909
- var resultKey = resultKeys[j];
910
- if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
911
- isModified = true;
912
- }
913
- }
914
- }
915
- if (isModified) {
916
- observers[observerKey].apply(this, keys.map(function (key) {
917
- return safeGet(current, key);
918
- }));
919
- }
727
+ } else {
728
+ this.initLifeCycleListener('ready', lifecycle);
920
729
  }
921
- }
922
- }, {
923
- key: "defineProperty",
924
- value: function defineProperty(target, key, data) {
925
- Object.defineProperty(target, key, {
926
- configurable: true,
927
- enumerable: true,
928
- set: function set(value) {
929
- data[key] = value;
930
- },
931
- get: function get() {
932
- return data[key];
730
+ } else {
731
+ for (const lifecycleKey in lifecycleMap) {
732
+ const cycleNames = lifecycleMap[lifecycleKey];
733
+ if (cycleNames.indexOf(lifecycleName) !== -1) {
734
+ switch (lifecycleKey) {
735
+ case TaroLifeCycles.DidHide:
736
+ this.didHides.push(lifecycle);
737
+ break;
738
+ case TaroLifeCycles.DidMount:
739
+ this.didMounts.push(lifecycle);
740
+ break;
741
+ case TaroLifeCycles.DidShow:
742
+ this.didShows.push(lifecycle);
743
+ break;
744
+ case TaroLifeCycles.WillMount:
745
+ this.willMounts.push(lifecycle);
746
+ break;
747
+ case TaroLifeCycles.WillUnmount:
748
+ this.willUnmounts.push(lifecycle);
749
+ break;
750
+ }
933
751
  }
934
- });
935
- }
936
- }, {
937
- key: "privateStopNoop",
938
- value: function privateStopNoop() {
939
- var e;
940
- var fn;
941
- if (arguments.length === 2) {
942
- fn = arguments.length <= 0 ? undefined : arguments[0];
943
- e = arguments.length <= 1 ? undefined : arguments[1];
944
- } else if (arguments.length === 1) {
945
- e = arguments.length <= 0 ? undefined : arguments[0];
946
752
  }
947
- if (e.type === 'touchmove') {
948
- report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
949
- }
950
- e.stopPropagation();
951
- isFunction(fn) && fn(e);
952
- }
953
- // ================ React 生命周期 ================
954
- }, {
955
- key: "componentWillMount",
956
- value: function componentWillMount() {
957
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillMount", this));
958
- this.executeLifeCycles(this.willMounts, this.current.router || {});
959
- this.triggerObservers(this.data, BaseComponent.defaultProps);
960
- this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
961
- }
962
- }, {
963
- key: "componentDidMount",
964
- value: function componentDidMount() {
965
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidMount", this));
966
- this.executeLifeCycles(this.didMounts);
967
- }
968
- }, {
969
- key: "componentWillUnmount",
970
- value: function componentWillUnmount() {
971
- this.eventDestroyList.forEach(function (fn) {
972
- return fn();
973
- });
974
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillUnmount", this));
975
- this.executeLifeCycles(this.willUnmounts);
976
753
  }
977
- }, {
978
- key: "componentDidHide",
979
- value: function componentDidHide() {
980
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidHide", this));
981
- this.executeLifeCycles(this.didHides);
754
+ // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
755
+ if (!isFunction(this[lifecycleName])) {
756
+ this[lifecycleName] = lifecycle;
982
757
  }
983
- }, {
984
- key: "componentDidShow",
985
- value: function componentDidShow() {
986
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidShow", this), this.current.router || {});
987
- this.executeLifeCycles(this.didShows, this.current.router || {});
988
- }
989
- }, {
990
- key: "componentWillReceiveProps",
991
- value: function componentWillReceiveProps(nextProps) {
992
- this.triggerObservers(nextProps, this.props);
993
- this.triggerPropertiesObservers(this.props, nextProps);
994
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillReceiveProps", this));
758
+ }
759
+ initLifeCycleListener(name, cb) {
760
+ // 组件的 ready、show、hide 需要利用页面事件触发
761
+ const {
762
+ router
763
+ } = this.current;
764
+ const lifecycleName = `on${name[0].toUpperCase()}${name.slice(1)}`;
765
+ cb = cb.bind(this);
766
+ (router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
767
+ // unMount 时需要取消事件监听
768
+ this.eventDestroyList.push(() => taro.eventCenter.off(router[lifecycleName], cb));
769
+ }
770
+ executeLifeCycles(funcs, ...args) {
771
+ for (let i = 0; i < funcs.length; i++) {
772
+ const func = funcs[i];
773
+ this.safeExecute(func, ...args);
995
774
  }
996
- // ================ 小程序 App, Page, Component 实例属性与方法 ================
997
- }, {
998
- key: "is",
999
- get: function get() {
1000
- return this.current.page.is;
775
+ }
776
+ triggerPropertiesObservers(prevProps, nextProps) {
777
+ this._observeProps.forEach(({
778
+ name: key,
779
+ observers
780
+ }) => {
781
+ const prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
782
+ const nextProp = nextProps[key];
783
+ // 小程序是深比较不同之后才 trigger observer
784
+ if (!isEqual(prop, nextProp)) {
785
+ observers.forEach(observer => {
786
+ if (typeof observer === 'string') {
787
+ const ob = this[observer];
788
+ if (isFunction(ob)) {
789
+ ob.call(this, nextProp, prop, key);
790
+ }
791
+ } else if (isFunction(observer)) {
792
+ observer.call(this, nextProp, prop, key);
793
+ }
794
+ });
795
+ }
796
+ });
797
+ }
798
+ triggerObservers(current, prev) {
799
+ const observers = this.observers;
800
+ if (observers == null) {
801
+ return;
1001
802
  }
1002
- }, {
1003
- key: "id",
1004
- get: function get() {
1005
- return this.current.page.id;
803
+ if (Object.keys(observers).length === 0) {
804
+ return;
1006
805
  }
1007
- }, {
1008
- key: "dataset",
1009
- get: function get() {
1010
- return this.current.page.dataset;
806
+ const result = diff(current, prev);
807
+ const resultKeys = Object.keys(result);
808
+ if (resultKeys.length === 0) {
809
+ return;
1011
810
  }
1012
- }, {
1013
- key: "componentMethodsProxy",
1014
- value: function componentMethodsProxy(method) {
1015
- var _this5 = this;
1016
- return function () {
1017
- var page = _this5.current.page;
1018
- if (page === null || page === void 0 ? void 0 : page[method]) {
1019
- return page[method].apply(page, arguments);
1020
- } else if (method === 'createSelectorQuery') {
1021
- return taro.createSelectorQuery();
1022
- } else if (method === 'createIntersectionObserver') {
1023
- // @ts-ignore
1024
- return taro.createIntersectionObserver.apply(void 0, arguments);
1025
- } else if (method === 'createMediaQueryObserver') {
1026
- return taro.createMediaQueryObserver();
1027
- } else {
1028
- console.error("page \u4E0B\u6CA1\u6709 ".concat(method, " \u65B9\u6CD5"));
811
+ for (const observerKey in observers) {
812
+ if (/\*\*/.test(observerKey)) {
813
+ report('数据监听器 observers 不支持使用通配符 **。');
814
+ continue;
815
+ }
816
+ const keys = observerKey.split(',').map(k => k.trim());
817
+ let isModified = false;
818
+ for (let i = 0; i < keys.length; i++) {
819
+ const key = keys[i];
820
+ for (let j = 0; j < resultKeys.length; j++) {
821
+ const resultKey = resultKeys[j];
822
+ if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
823
+ isModified = true;
824
+ }
1029
825
  }
1030
- };
1031
- }
1032
- }, {
1033
- key: "selectComponent",
1034
- value: function selectComponent() {
1035
- report(nonsupport.get('selectComponent'));
1036
- }
1037
- }, {
1038
- key: "selectAllComponents",
1039
- value: function selectAllComponents() {
1040
- report(nonsupport.get('selectAllComponents'));
826
+ }
827
+ if (isModified) {
828
+ observers[observerKey].apply(this, keys.map(key => safeGet(current, key)));
829
+ }
1041
830
  }
1042
- }, {
1043
- key: "selectOwnerComponent",
1044
- value: function selectOwnerComponent() {
1045
- report(nonsupport.get('selectOwnerComponent'));
831
+ }
832
+ defineProperty(target, key, data) {
833
+ Object.defineProperty(target, key, {
834
+ configurable: true,
835
+ enumerable: true,
836
+ set(value) {
837
+ data[key] = value;
838
+ },
839
+ get() {
840
+ return data[key];
841
+ }
842
+ });
843
+ }
844
+ privateStopNoop(...args) {
845
+ let e;
846
+ let fn;
847
+ if (args.length === 2) {
848
+ fn = args[0];
849
+ e = args[1];
850
+ } else if (args.length === 1) {
851
+ e = args[0];
1046
852
  }
1047
- }, {
1048
- key: "groupSetData",
1049
- value: function groupSetData() {
1050
- report(nonsupport.get('groupSetData'));
853
+ if (e.type === 'touchmove') {
854
+ report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
1051
855
  }
1052
- }]);
1053
- return BaseComponent;
1054
- }(ConnectComponent);
1055
- var props = weappConf.properties;
856
+ e.stopPropagation();
857
+ isFunction(fn) && fn(e);
858
+ }
859
+ // ================ React 生命周期 ================
860
+ componentWillMount() {
861
+ this.safeExecute(super.componentWillMount);
862
+ this.executeLifeCycles(this.willMounts, this.current.router || {});
863
+ this.triggerObservers(this.data, BaseComponent.defaultProps);
864
+ this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
865
+ }
866
+ componentDidMount() {
867
+ this.safeExecute(super.componentDidMount);
868
+ this.executeLifeCycles(this.didMounts);
869
+ }
870
+ componentWillUnmount() {
871
+ this.eventDestroyList.forEach(fn => fn());
872
+ this.safeExecute(super.componentWillUnmount);
873
+ this.executeLifeCycles(this.willUnmounts);
874
+ }
875
+ componentDidHide() {
876
+ this.safeExecute(super.componentDidHide);
877
+ this.executeLifeCycles(this.didHides);
878
+ }
879
+ componentDidShow() {
880
+ this.safeExecute(super.componentDidShow, this.current.router || {});
881
+ this.executeLifeCycles(this.didShows, this.current.router || {});
882
+ }
883
+ componentWillReceiveProps(nextProps) {
884
+ this.triggerObservers(nextProps, this.props);
885
+ this.triggerPropertiesObservers(this.props, nextProps);
886
+ this.safeExecute(super.componentWillReceiveProps);
887
+ }
888
+ // ================ 小程序 App, Page, Component 实例属性与方法 ================
889
+ get is() {
890
+ return this.current.page.is;
891
+ }
892
+ get id() {
893
+ return this.current.page.id;
894
+ }
895
+ get dataset() {
896
+ return this.current.page.dataset;
897
+ }
898
+ componentMethodsProxy(method) {
899
+ return (...args) => {
900
+ const page = this.current.page;
901
+ if (page === null || page === void 0 ? void 0 : page[method]) {
902
+ return page[method](...args);
903
+ } else if (method === 'createSelectorQuery') {
904
+ return taro.createSelectorQuery();
905
+ } else if (method === 'createIntersectionObserver') {
906
+ // @ts-ignore
907
+ return taro.createIntersectionObserver(...args);
908
+ } else if (method === 'createMediaQueryObserver') {
909
+ return taro.createMediaQueryObserver();
910
+ } else {
911
+ console.error(`page 下没有 ${method} 方法`);
912
+ }
913
+ };
914
+ }
915
+ selectComponent() {
916
+ report(nonsupport.get('selectComponent'));
917
+ }
918
+ selectAllComponents() {
919
+ report(nonsupport.get('selectAllComponents'));
920
+ }
921
+ selectOwnerComponent() {
922
+ report(nonsupport.get('selectOwnerComponent'));
923
+ }
924
+ groupSetData() {
925
+ report(nonsupport.get('groupSetData'));
926
+ }
927
+ }
928
+ const props = weappConf.properties;
1056
929
  if (props) {
1057
- for (var propKey in props) {
1058
- var propValue = props[propKey];
930
+ for (const propKey in props) {
931
+ const propValue = props[propKey];
1059
932
  if (propValue != null && !isFunction(propValue)) {
1060
933
  if (propValue.value !== undefined) {
1061
934
  // 如果是 null 也赋值到 defaultProps
1062
- BaseComponent.defaultProps = Object.assign(_defineProperty__default["default"]({}, propKey, propValue.value), BaseComponent.defaultProps);
935
+ BaseComponent.defaultProps = Object.assign({
936
+ [propKey]: propValue.value
937
+ }, BaseComponent.defaultProps);
1063
938
  }
1064
939
  }
1065
940
  }
1066
941
  }
1067
- var staticOptions = ['externalClasses', 'relations', 'options'];
1068
- staticOptions.forEach(function (option) {
1069
- var value = weappConf[option];
942
+ const staticOptions = ['externalClasses', 'relations', 'options'];
943
+ staticOptions.forEach(option => {
944
+ const value = weappConf[option];
1070
945
  if (value != null) {
1071
946
  BaseComponent[option] = value;
1072
947
  }