@tarojs/with-weapp 3.8.0-canary.0 → 4.0.0-alpha.2

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
  }
@@ -205,7 +186,6 @@
205
186
  return Object.prototype.toString.call(obj);
206
187
  }
207
188
 
208
- var _lifecycleMap;
209
189
  var TaroLifeCycles;
210
190
  (function (TaroLifeCycles) {
211
191
  TaroLifeCycles["WillMount"] = "componentWillMount";
@@ -214,16 +194,20 @@
214
194
  TaroLifeCycles["DidHide"] = "componentDidHide";
215
195
  TaroLifeCycles["WillUnmount"] = "componentWillUnmount";
216
196
  })(TaroLifeCycles || (TaroLifeCycles = {}));
217
- var lifecycleMap = (_lifecycleMap = {}, _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.WillMount, ['created']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidMount, ['attached']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidShow, ['onShow']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.DidHide, ['onHide']), _defineProperty__default["default"](_lifecycleMap, TaroLifeCycles.WillUnmount, ['detached', 'onUnload']), _lifecycleMap);
218
- var lifecycles = new Set(['ready']);
219
- for (var key in lifecycleMap) {
220
- var lifecycle = lifecycleMap[key];
221
- lifecycle.forEach(function (l) {
222
- return lifecycles.add(l);
223
- });
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));
224
208
  }
225
- var uniquePageLifecycle = ['onPullDownRefresh', 'onReachBottom', 'onShareAppMessage', 'onShareTimeline', 'onAddToFavorites', 'onPageScroll', 'onResize', 'onTabItemTap'];
226
- 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'];
227
211
 
228
212
  /**
229
213
  * Simple bind, faster than native
@@ -231,7 +215,7 @@
231
215
  function bind(fn /*: Function */, ctx /*: Object */) {
232
216
  if (!fn) return false;
233
217
  function boundFn(a) {
234
- var l /*: number */ = arguments.length;
218
+ const l /*: number */ = arguments.length;
235
219
  return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx);
236
220
  }
237
221
  // record original fn length
@@ -245,7 +229,7 @@
245
229
  if (!obj) {
246
230
  return defaultValue;
247
231
  }
248
- var props, prop;
232
+ let props, prop;
249
233
  if (Array.isArray(propsArg)) {
250
234
  props = propsArg.slice(0);
251
235
  }
@@ -253,7 +237,7 @@
253
237
  props = propsArg.replace(/\[(.+?)\]/g, '.$1');
254
238
  props = props.split('.');
255
239
  }
256
- if (_typeof__default["default"](propsArg) === 'symbol') {
240
+ if (typeof propsArg === 'symbol') {
257
241
  props = [propsArg];
258
242
  }
259
243
  if (!Array.isArray(props)) {
@@ -276,14 +260,14 @@
276
260
  props = props.replace(/\[(.+?)\]/g, '.$1');
277
261
  props = props.split('.');
278
262
  }
279
- if (_typeof__default["default"](props) === 'symbol') {
263
+ if (typeof props === 'symbol') {
280
264
  props = [props];
281
265
  }
282
- var lastProp = props.pop();
266
+ const lastProp = props.pop();
283
267
  if (!lastProp) {
284
268
  return false;
285
269
  }
286
- var thisProp;
270
+ let thisProp;
287
271
  while (thisProp = props.shift()) {
288
272
  if (typeof obj[thisProp] === 'undefined') {
289
273
  obj[thisProp] = {};
@@ -291,12 +275,12 @@
291
275
  // 直接按路径修改 this.state 可能会导致 nextProps 也被修改
292
276
  // 因此按路径寻找时,每一层都复制一遍
293
277
  if (Array.isArray(obj[thisProp])) {
294
- obj[thisProp] = _toConsumableArray__default["default"](obj[thisProp]);
295
- } else if (_typeof__default["default"](obj[thisProp]) === 'object') {
278
+ obj[thisProp] = [...obj[thisProp]];
279
+ } else if (typeof obj[thisProp] === 'object') {
296
280
  obj[thisProp] = Object.assign({}, obj[thisProp]);
297
281
  }
298
282
  obj = obj[thisProp];
299
- if (!obj || _typeof__default["default"](obj) !== 'object') {
283
+ if (!obj || typeof obj !== 'object') {
300
284
  return false;
301
285
  }
302
286
  }
@@ -306,77 +290,149 @@
306
290
  function report(msg) {
307
291
  console.warn('[Taro Convert Warning] ' + msg);
308
292
  }
309
- 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 语法重构。']]);
310
294
  function flattenBehaviors(behavior, behaviorMap) {
311
295
  if (typeof behavior === 'string') {
312
- return report("\u4E0D\u652F\u6301\u4F7F\u7528\u5185\u7F6E Behavior: [".concat(behavior, "]"));
296
+ return report(`不支持使用内置 Behavior: [${behavior}]`);
313
297
  }
314
- var subBehaviors = behavior.behaviors;
298
+ const subBehaviors = behavior.behaviors;
315
299
  if (subBehaviors === null || subBehaviors === void 0 ? void 0 : subBehaviors.length) {
316
- subBehaviors.forEach(function (subBehavior) {
317
- return flattenBehaviors(subBehavior, behaviorMap);
318
- });
300
+ subBehaviors.forEach(subBehavior => flattenBehaviors(subBehavior, behaviorMap));
319
301
  }
320
- Object.keys(behavior).forEach(function (key) {
302
+ Object.keys(behavior).forEach(key => {
321
303
  // 不支持的属性
322
304
  if (nonsupport.has(key)) {
323
- var advise = nonsupport.get(key);
305
+ const advise = nonsupport.get(key);
324
306
  return report(advise);
325
307
  }
326
308
  if (behaviorMap.has(key)) {
327
- var list = behaviorMap.get(key);
328
- var value = behavior[key];
309
+ const list = behaviorMap.get(key);
310
+ const value = behavior[key];
329
311
  list.push(value);
330
312
  }
331
313
  });
332
314
  }
333
315
 
334
- 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; } } }; }
335
- 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); }
336
- 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; }
337
- 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); }; }
338
- 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; } }
316
+ /**
317
+ * 该模块仅存放 convert 转换时用到的工具函数或变量
318
+ */
319
+ const cacheOptions = {
320
+ cacheOptions: {},
321
+ setOptionsToCache: function (options) {
322
+ if (Object.keys(options).length !== 0) {
323
+ this.cacheOptions = options;
324
+ }
325
+ },
326
+ getOptionsFromCache: function () {
327
+ return this.cacheOptions;
328
+ }
329
+ };
330
+ function toCamelCase(s) {
331
+ let camel = '';
332
+ let nextCap = false;
333
+ for (let i = 0; i < s.length; i++) {
334
+ if (s[i] !== '-') {
335
+ camel += nextCap ? s[i].toUpperCase() : s[i];
336
+ nextCap = false;
337
+ } else {
338
+ nextCap = true;
339
+ }
340
+ }
341
+ return camel;
342
+ }
343
+ const convertToArray = function (value, fn) {
344
+ if (value instanceof Array) {
345
+ return value.map(fn);
346
+ } else if (typeof value === 'number') {
347
+ return Array.from({
348
+ length: value
349
+ }, (_, index) => index).map(fn);
350
+ } else if (typeof value === 'string') {
351
+ return Array.from(value).map(fn);
352
+ } else if (typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype) {
353
+ const result = Object.keys(value).map(item => {
354
+ return fn(value[item], item);
355
+ });
356
+ return result;
357
+ }
358
+ };
359
+ const getTarget = (target, Taro) => {
360
+ if (!target) {
361
+ return {
362
+ dataset: {}
363
+ };
364
+ }
365
+ if (Taro.getEnv() === Taro.ENV_TYPE.HARMONYHYBRID || Taro.getEnv() === Taro.ENV_TYPE.WEB) {
366
+ if (target.fullDataset) {
367
+ return {
368
+ dataset: target.fullDataset
369
+ };
370
+ }
371
+ const fullDataset = {};
372
+ // 获取元素的所有属性
373
+ const targetAttrKeys = Object.keys(target);
374
+ // 遍历所有属性
375
+ for (let i = 0; i < targetAttrKeys.length; i++) {
376
+ if (targetAttrKeys[i].startsWith('data-')) {
377
+ fullDataset[toCamelCase(targetAttrKeys[i].replace(/^data-/, '').toLowerCase())] = target[targetAttrKeys[i]];
378
+ }
379
+ }
380
+ target.fullDataset = fullDataset;
381
+ return {
382
+ dataset: fullDataset
383
+ };
384
+ }
385
+ return target;
386
+ };
387
+
339
388
  function defineGetter(component, key, getter) {
340
389
  Object.defineProperty(component, key, {
341
390
  enumerable: true,
342
391
  configurable: true,
343
- get: function get() {
392
+ get: () => {
344
393
  if (getter === 'props') {
345
394
  return component.props;
346
395
  }
347
- return Object.assign(Object.assign({}, component.state), component.props);
396
+ return component.state;
397
+ // return {
398
+ // ...component.state,
399
+ // ...component.props
400
+ // }
348
401
  }
349
402
  });
350
403
  }
404
+
405
+ function propToState(newValue, _oldValue, key) {
406
+ this.state[key] = newValue;
407
+ }
351
408
  function isFunction(o) {
352
409
  return typeof o === 'function';
353
410
  }
354
- function withWeapp(weappConf) {
355
- var isApp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
356
- 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) {
357
413
  report('withWeapp 请传入“App/页面/组件“的配置对象。如果原生写法使用了基类,请将基类组合后的配置对象传入,详情请参考文档。');
358
414
  }
359
- return function (ConnectComponent) {
415
+ return ConnectComponent => {
360
416
  var _a;
361
- var behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []]]);
362
- var behaviorProperties = {};
417
+ const behaviorMap = new Map([['properties', []], ['data', []], ['methods', []], ['created', []], ['attached', []], ['ready', []], ['detached', []], ['lifetimes', []]]);
418
+ const behaviorProperties = {};
363
419
  if ((_a = weappConf.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
364
- var behaviors = weappConf.behaviors;
365
- behaviors.forEach(function (behavior) {
366
- return flattenBehaviors(behavior, behaviorMap);
367
- });
368
- var propertiesList = behaviorMap.get('properties');
420
+ const {
421
+ behaviors
422
+ } = weappConf;
423
+ behaviors.forEach(behavior => flattenBehaviors(behavior, behaviorMap));
424
+ const propertiesList = behaviorMap.get('properties');
369
425
  if (propertiesList.length) {
370
- propertiesList.forEach(function (property) {
426
+ propertiesList.forEach(property => {
371
427
  Object.assign(behaviorProperties, property);
372
428
  });
373
- Object.keys(behaviorProperties).forEach(function (propName) {
374
- var propValue = behaviorProperties[propName];
429
+ Object.keys(behaviorProperties).forEach(propName => {
430
+ const propValue = behaviorProperties[propName];
375
431
  if (!weappConf.properties) {
376
432
  weappConf.properties = {};
377
433
  }
378
434
  if (!weappConf.properties.hasOwnProperty(propName)) {
379
- if (propValue && _typeof__default["default"](propValue) === 'object' && propValue.value) {
435
+ if (propValue && typeof propValue === 'object' && propValue.value) {
380
436
  propValue.value = clone(propValue.value);
381
437
  }
382
438
  weappConf.properties[propName] = propValue;
@@ -384,45 +440,38 @@
384
440
  });
385
441
  }
386
442
  }
387
- var BaseComponent = /*#__PURE__*/function (_ConnectComponent) {
388
- _inherits__default["default"](BaseComponent, _ConnectComponent);
389
- var _super = _createSuper(BaseComponent);
390
- function BaseComponent(props) {
391
- var _this;
392
- _classCallCheck__default["default"](this, BaseComponent);
393
- _this = _super.call(this, props);
394
- _this._observeProps = [];
443
+ class BaseComponent extends ConnectComponent {
444
+ constructor(props) {
445
+ super(props);
446
+ this._observeProps = [];
395
447
  // mixins 可以多次调用生命周期
396
- _this.willMounts = [];
397
- _this.didMounts = [];
398
- _this.didHides = [];
399
- _this.didShows = [];
400
- _this.willUnmounts = [];
401
- _this.eventDestroyList = [];
402
- _this.current = runtime.getCurrentInstance();
403
- _this.taroGlobalData = Object.create(null);
404
- _this.safeExecute = function (func) {
405
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
406
- args[_key - 1] = arguments[_key];
407
- }
408
- 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);
409
458
  };
410
- _this.setData = function (obj, callback) {
411
- var oldState;
412
- if (_this.observers && Object.keys(Object.keys(_this.observers))) {
413
- 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);
414
463
  }
415
- Object.keys(obj).forEach(function (key) {
416
- safeSet(_this.state, key, obj[key]);
464
+ Object.keys(obj).forEach(key => {
465
+ safeSet(this.state, key, obj[key]);
417
466
  });
418
- _this.setState(_this.state, function () {
419
- _this.triggerObservers(_this.state, oldState);
467
+ this.setState(this.state, () => {
468
+ this.triggerObservers(this.state, oldState);
420
469
  if (callback) {
421
- callback.call(_assertThisInitialized__default["default"](_this));
470
+ callback.call(this);
422
471
  }
423
472
  });
424
473
  };
425
- _this.triggerEvent = function (eventName, detail, options) {
474
+ this.triggerEvent = (eventName, detail, options) => {
426
475
  if (options) {
427
476
  report('triggerEvent 不支持事件选项。');
428
477
  }
@@ -432,521 +481,467 @@
432
481
  return match[1].toUpperCase();
433
482
  });
434
483
  }
435
- var props = _this.props;
436
- var dataset = {};
437
- for (var key in props) {
484
+ const props = this.props;
485
+ const dataset = {};
486
+ for (const key in props) {
438
487
  if (!key.startsWith('data-')) continue;
439
488
  dataset[key.replace(/^data-/, '')] = props[key];
440
489
  }
441
- var func = props["on".concat(eventName[0].toUpperCase()).concat(eventName.slice(1))];
490
+ const func = props[`on${eventName[0].toUpperCase()}${eventName.slice(1)}`];
442
491
  if (isFunction(func)) {
443
- func.call(_assertThisInitialized__default["default"](_this), {
492
+ func.call(this, {
444
493
  type: eventName,
445
- detail: detail,
494
+ detail,
446
495
  target: {
447
496
  id: props.id || '',
448
- dataset: dataset
497
+ dataset
449
498
  },
450
499
  currentTarget: {
451
500
  id: props.id || '',
452
- dataset: dataset
501
+ dataset
453
502
  }
454
503
  });
455
504
  }
456
505
  };
457
- _this.hasBehavior = _this.componentMethodsProxy('hasBehavior');
458
- _this.createSelectorQuery = _this.componentMethodsProxy('createSelectorQuery');
459
- _this.createIntersectionObserver = _this.componentMethodsProxy('createIntersectionObserver');
460
- _this.createMediaQueryObserver = _this.componentMethodsProxy('createMediaQueryObserver');
461
- _this.getRelationNodes = _this.componentMethodsProxy('getRelationNodes');
462
- _this.getTabBar = _this.componentMethodsProxy('getTabBar');
463
- _this.getPageId = _this.componentMethodsProxy('getPageId');
464
- _this.animate = _this.componentMethodsProxy('animate');
465
- _this.clearAnimation = _this.componentMethodsProxy('clearAnimation');
466
- _this.setUpdatePerformanceListener = _this.componentMethodsProxy('setUpdatePerformanceListener');
467
- _this.state = _this.state || {};
468
- _this.init(weappConf);
469
- defineGetter(_assertThisInitialized__default["default"](_this), 'data', 'state');
470
- defineGetter(_assertThisInitialized__default["default"](_this), 'properties', 'props');
471
- return _this;
472
- }
473
- _createClass__default["default"](BaseComponent, [{
474
- key: "initProps",
475
- value: function initProps(props) {
476
- for (var propKey in props) {
477
- if (props.hasOwnProperty(propKey)) {
478
- var propValue = props[propKey];
479
- // propValue 可能是 null, 构造函数, 对象
480
- if (propValue && !isFunction(propValue)) {
481
- if (propValue.observer) {
482
- this._observeProps.push({
483
- name: propKey,
484
- observer: propValue.observer
485
- });
486
- }
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');
520
+ }
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;
541
+ } else {
542
+ properties[propKey] = null;
543
+ }
544
+ } else if (typeof propValue === 'object') {
545
+ // propValue为对象时
546
+ properties[propKey] = propValue.value;
547
+ if (propValue.observer) {
548
+ observers.push(propValue.observer);
487
549
  }
550
+ } else {
551
+ properties[propKey] = null;
488
552
  }
553
+ this._observeProps.push({
554
+ name: propKey,
555
+ observers: observers
556
+ });
489
557
  }
490
558
  }
491
- }, {
492
- key: "init",
493
- value: function init(options) {
494
- var _this2 = this;
495
- var _a, _b, _c;
496
- // 处理 Behaviors
497
- if ((_a = options.behaviors) === null || _a === void 0 ? void 0 : _a.length) {
498
- var _iterator = _createForOfIteratorHelper(behaviorMap.entries()),
499
- _step;
500
- try {
501
- var _loop = function _loop() {
502
- var _step$value = _slicedToArray__default["default"](_step.value, 2),
503
- key = _step$value[0],
504
- list = _step$value[1];
505
- switch (key) {
506
- case 'created':
507
- case 'attached':
508
- case 'detached':
509
- case 'ready':
510
- list.forEach(function (fn) {
511
- return _this2.initLifeCycles(key, fn);
512
- });
513
- break;
514
- }
515
- };
516
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
517
- _loop();
518
- }
519
- } catch (err) {
520
- _iterator.e(err);
521
- } finally {
522
- _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;
523
573
  }
524
574
  }
525
- for (var confKey in options) {
526
- // 不支持的属性
527
- if (nonsupport.has(confKey)) {
528
- var advise = nonsupport.get(confKey);
529
- report(advise);
530
- }
531
- var confValue = options[confKey];
532
- switch (confKey) {
533
- case 'behaviors':
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);
592
+ }
593
+ } else {
594
+ this.state = Object.assign(Object.assign({}, confValue), this.state);
595
+ }
534
596
  break;
535
- case 'data':
536
- {
537
- if (isApp) {
538
- this[confKey] = confValue;
539
- if (!appOptions.includes(confKey)) {
540
- this.defineProperty(this.taroGlobalData, confKey, 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;
541
620
  }
542
- } else {
543
- this.state = Object.assign(Object.assign({}, confValue), this.state);
544
- }
621
+ case 'hide':
622
+ {
623
+ this.initLifeCycleListener('hide', cb);
624
+ break;
625
+ }
626
+ case 'resize':
627
+ {
628
+ report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
629
+ break;
630
+ }
631
+ }
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]) {
545
638
  break;
546
639
  }
547
- case 'properties':
548
- this.initProps(Object.assign(behaviorProperties, confValue));
549
- break;
550
- case 'methods':
551
- for (var key in confValue) {
552
- var method = confValue[key];
553
- this[key] = bind(method, this);
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);
554
646
  }
555
- break;
556
- case 'lifetimes':
557
- for (var _key2 in confValue) {
558
- this.initLifeCycles(_key2, confValue[_key2]);
647
+ // 原生页面和 Taro 页面中共计只能定义一次的生命周期
648
+ if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
649
+ report(`生命周期 ${confKey} 已在原生部分进行定义,React 部分的定义将不会被执行。`);
559
650
  }
560
- break;
561
- case 'pageLifetimes':
562
- for (var _key3 in confValue) {
563
- var cb = confValue[_key3];
564
- switch (_key3) {
565
- case 'show':
566
- {
567
- this.initLifeCycleListener('show', cb);
568
- break;
569
- }
570
- case 'hide':
571
- {
572
- this.initLifeCycleListener('hide', cb);
573
- break;
574
- }
575
- case 'resize':
576
- {
577
- report('不支持组件所在页面的生命周期 pageLifetimes.resize。');
578
- break;
579
- }
580
- }
651
+ } else {
652
+ this[confKey] = confValue;
653
+ if (isApp && !appOptions.includes(confKey)) {
654
+ this.defineProperty(this.taroGlobalData, confKey, this);
581
655
  }
656
+ }
657
+ break;
658
+ }
659
+ }
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;
582
688
  break;
583
- default:
584
- if (lifecycles.has(confKey)) {
585
- // 优先使用 lifetimes 中定义的生命周期
586
- if ((_b = options.lifetimes) === null || _b === void 0 ? void 0 : _b[confKey]) {
587
- break;
588
- }
589
- var lifecycle = options[confKey];
590
- this.initLifeCycles(confKey, lifecycle);
591
- } else if (isFunction(confValue)) {
592
- this[confKey] = bind(confValue, this);
593
- if (isApp && !appOptions.includes(confKey)) {
594
- this.defineProperty(this.taroGlobalData, confKey, this);
595
- }
596
- // 原生页面和 Taro 页面中共计只能定义一次的生命周期
597
- if (uniquePageLifecycle.includes(confKey) && ConnectComponent.prototype[confKey]) {
598
- 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"));
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);
599
697
  }
600
- } else {
601
- this[confKey] = confValue;
602
- if (isApp && !appOptions.includes(confKey)) {
603
- this.defineProperty(this.taroGlobalData, confKey, this);
698
+ });
699
+ break;
700
+ case 'lifetimes':
701
+ list.forEach(lifetimesObject => {
702
+ for (const key in lifetimesObject) {
703
+ this.initLifeCycles(key, lifetimesObject[key]);
604
704
  }
605
- }
705
+ });
606
706
  break;
607
707
  }
608
708
  }
609
- // 处理 Behaviors
610
- if ((_c = options.behaviors) === null || _c === void 0 ? void 0 : _c.length) {
611
- var behaviorData = {};
612
- var methods = {};
613
- var _iterator2 = _createForOfIteratorHelper(behaviorMap.entries()),
614
- _step2;
615
- try {
616
- var _loop2 = function _loop2() {
617
- var _step2$value = _slicedToArray__default["default"](_step2.value, 2),
618
- key = _step2$value[0],
619
- list = _step2$value[1];
620
- switch (key) {
621
- case 'data':
622
- [].concat(_toConsumableArray__default["default"](list), [_this2.state]).forEach(function (dataObject, index) {
623
- Object.keys(dataObject).forEach(function (dataKey) {
624
- var value = dataObject[dataKey];
625
- var preValue = behaviorData[dataKey];
626
- var valueType = _typeof__default["default"](value);
627
- var preValueType = _typeof__default["default"](preValue);
628
- if (valueType === 'object') {
629
- if (!value) {
630
- behaviorData[dataKey] = value;
631
- } else if (preValueType !== 'object' || !preValueType || Array.isArray(value)) {
632
- behaviorData[dataKey] = index === list.length ? value : clone(value);
633
- } else {
634
- var newVal = Object.assign({}, preValue, value);
635
- behaviorData[dataKey] = index === list.length ? newVal : clone(newVal);
636
- }
637
- } else {
638
- behaviorData[dataKey] = value;
639
- }
640
- });
641
- });
642
- _this2.state = behaviorData;
643
- break;
644
- case 'methods':
645
- list.forEach(function (methodsObject) {
646
- Object.assign(methods, methodsObject);
647
- });
648
- Object.keys(methods).forEach(function (methodName) {
649
- if (!_this2[methodName]) {
650
- var _method = methods[methodName];
651
- _this2[methodName] = bind(_method, _this2);
652
- }
653
- });
654
- break;
655
- default:
656
- break;
657
- }
658
- };
659
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
660
- _loop2();
661
- }
662
- } catch (err) {
663
- _iterator2.e(err);
664
- } finally {
665
- _iterator2.f();
666
- }
667
- }
668
709
  }
669
- }, {
670
- key: "initLifeCycles",
671
- value: function initLifeCycles(lifecycleName, lifecycle) {
672
- // 不支持的生命周期
673
- if (nonsupport.has(lifecycleName)) {
674
- var advise = nonsupport.get(lifecycleName);
675
- return report(advise);
676
- }
677
- if (lifecycleName === 'ready') {
678
- // 如果组件是延时渲染的,页面 onReady 的事件已经 emit 了,因此使用 componentDidMount + nextTick 模拟
679
- if (this.current.page.onReady.called) {
680
- this.didMounts.push(function () {
681
- var _this3 = this;
682
- for (var _len2 = arguments.length, args = new Array(_len2), _key4 = 0; _key4 < _len2; _key4++) {
683
- args[_key4] = arguments[_key4];
710
+ }
711
+ initLifeCycles(lifecycleName, lifecycle) {
712
+ // 不支持的生命周期
713
+ if (nonsupport.has(lifecycleName)) {
714
+ const advise = nonsupport.get(lifecycleName);
715
+ return report(advise);
716
+ }
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);
684
724
  }
685
- taro.nextTick(function () {
686
- if (isFunction(lifecycle)) {
687
- lifecycle.apply(_this3, args);
688
- }
689
- });
690
725
  });
691
- } else {
692
- this.initLifeCycleListener('ready', lifecycle);
693
- }
726
+ });
694
727
  } else {
695
- for (var lifecycleKey in lifecycleMap) {
696
- var cycleNames = lifecycleMap[lifecycleKey];
697
- if (cycleNames.indexOf(lifecycleName) !== -1) {
698
- switch (lifecycleKey) {
699
- case TaroLifeCycles.DidHide:
700
- this.didHides.push(lifecycle);
701
- break;
702
- case TaroLifeCycles.DidMount:
703
- this.didMounts.push(lifecycle);
704
- break;
705
- case TaroLifeCycles.DidShow:
706
- this.didShows.push(lifecycle);
707
- break;
708
- case TaroLifeCycles.WillMount:
709
- this.willMounts.push(lifecycle);
710
- break;
711
- case TaroLifeCycles.WillUnmount:
712
- this.willUnmounts.push(lifecycle);
713
- break;
714
- }
728
+ this.initLifeCycleListener('ready', lifecycle);
729
+ }
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;
715
750
  }
716
751
  }
717
752
  }
718
- // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
719
- if (!isFunction(this[lifecycleName])) {
720
- this[lifecycleName] = lifecycle;
721
- }
722
753
  }
723
- }, {
724
- key: "initLifeCycleListener",
725
- value: function initLifeCycleListener(name, cb) {
726
- // 组件的 ready、show、hide 需要利用页面事件触发
727
- var router = this.current.router;
728
- var lifecycleName = "on".concat(name[0].toUpperCase()).concat(name.slice(1));
729
- cb = cb.bind(this);
730
- (router === null || router === void 0 ? void 0 : router[lifecycleName]) && taro.eventCenter.on(router[lifecycleName], cb);
731
- // unMount 时需要取消事件监听
732
- this.eventDestroyList.push(function () {
733
- return taro.eventCenter.off(router[lifecycleName], cb);
734
- });
754
+ // mixins 不会覆盖已经设置的生命周期,加入到 this 是为了形如 this.created() 的调用
755
+ if (!isFunction(this[lifecycleName])) {
756
+ this[lifecycleName] = lifecycle;
735
757
  }
736
- }, {
737
- key: "executeLifeCycles",
738
- value: function executeLifeCycles(funcs) {
739
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key5 = 1; _key5 < _len3; _key5++) {
740
- args[_key5 - 1] = arguments[_key5];
741
- }
742
- for (var i = 0; i < funcs.length; i++) {
743
- var func = funcs[i];
744
- this.safeExecute.apply(this, [func].concat(args));
745
- }
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);
746
774
  }
747
- }, {
748
- key: "triggerPropertiesObservers",
749
- value: function triggerPropertiesObservers(prevProps, nextProps) {
750
- var _this4 = this;
751
- this._observeProps.forEach(function (_ref) {
752
- var key = _ref.name,
753
- observer = _ref.observer;
754
- var prop = prevProps === null || prevProps === void 0 ? void 0 : prevProps[key];
755
- var nextProp = nextProps[key];
756
- // 小程序是深比较不同之后才 trigger observer
757
- if (!isEqual(prop, nextProp)) {
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 => {
758
786
  if (typeof observer === 'string') {
759
- var ob = _this4[observer];
787
+ const ob = this[observer];
760
788
  if (isFunction(ob)) {
761
- ob.call(_this4, nextProp, prop, key);
789
+ ob.call(this, nextProp, prop, key);
762
790
  }
763
791
  } else if (isFunction(observer)) {
764
- observer.call(_this4, nextProp, prop, key);
792
+ observer.call(this, nextProp, prop, key);
765
793
  }
766
- }
767
- });
768
- }
769
- }, {
770
- key: "triggerObservers",
771
- value: function triggerObservers(current, prev) {
772
- var observers = this.observers;
773
- if (observers == null) {
774
- return;
775
- }
776
- if (Object.keys(observers).length === 0) {
777
- return;
778
- }
779
- var result = diff(current, prev);
780
- var resultKeys = Object.keys(result);
781
- if (resultKeys.length === 0) {
782
- return;
783
- }
784
- for (var observerKey in observers) {
785
- if (/\*\*/.test(observerKey)) {
786
- report('数据监听器 observers 不支持使用通配符 **。');
787
- continue;
788
- }
789
- var keys = observerKey.split(',').map(function (k) {
790
- return k.trim();
791
794
  });
792
- var isModified = false;
793
- for (var i = 0; i < keys.length; i++) {
794
- var key = keys[i];
795
- for (var j = 0; j < resultKeys.length; j++) {
796
- var resultKey = resultKeys[j];
797
- if (resultKey.startsWith(key) || key.startsWith(resultKey) && key.endsWith(']')) {
798
- isModified = true;
799
- }
800
- }
801
- }
802
- if (isModified) {
803
- observers[observerKey].apply(this, keys.map(function (key) {
804
- return safeGet(current, key);
805
- }));
806
- }
807
- }
808
- }
809
- }, {
810
- key: "defineProperty",
811
- value: function defineProperty(target, key, data) {
812
- Object.defineProperty(target, key, {
813
- configurable: true,
814
- enumerable: true,
815
- set: function set(value) {
816
- data[key] = value;
817
- },
818
- get: function get() {
819
- return data[key];
820
- }
821
- });
822
- }
823
- }, {
824
- key: "privateStopNoop",
825
- value: function privateStopNoop() {
826
- var e;
827
- var fn;
828
- if (arguments.length === 2) {
829
- fn = arguments.length <= 0 ? undefined : arguments[0];
830
- e = arguments.length <= 1 ? undefined : arguments[1];
831
- } else if (arguments.length === 1) {
832
- e = arguments.length <= 0 ? undefined : arguments[0];
833
795
  }
834
- if (e.type === 'touchmove') {
835
- report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
836
- }
837
- e.stopPropagation();
838
- isFunction(fn) && fn(e);
839
- }
840
- // ================ React 生命周期 ================
841
- }, {
842
- key: "componentWillMount",
843
- value: function componentWillMount() {
844
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillMount", this));
845
- this.executeLifeCycles(this.willMounts, this.current.router || {});
846
- this.triggerObservers(this.data, BaseComponent.defaultProps);
847
- this.triggerPropertiesObservers(BaseComponent.defaultProps, this.props);
848
- }
849
- }, {
850
- key: "componentDidMount",
851
- value: function componentDidMount() {
852
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidMount", this));
853
- this.executeLifeCycles(this.didMounts);
854
- }
855
- }, {
856
- key: "componentWillUnmount",
857
- value: function componentWillUnmount() {
858
- this.eventDestroyList.forEach(function (fn) {
859
- return fn();
860
- });
861
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillUnmount", this));
862
- this.executeLifeCycles(this.willUnmounts);
863
- }
864
- }, {
865
- key: "componentDidHide",
866
- value: function componentDidHide() {
867
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidHide", this));
868
- this.executeLifeCycles(this.didHides);
869
- }
870
- }, {
871
- key: "componentDidShow",
872
- value: function componentDidShow() {
873
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentDidShow", this), this.current.router || {});
874
- this.executeLifeCycles(this.didShows, this.current.router || {});
875
- }
876
- }, {
877
- key: "componentWillReceiveProps",
878
- value: function componentWillReceiveProps(nextProps) {
879
- this.triggerObservers(nextProps, this.props);
880
- this.triggerPropertiesObservers(this.props, nextProps);
881
- this.safeExecute(_get__default["default"](_getPrototypeOf__default["default"](BaseComponent.prototype), "componentWillReceiveProps", this));
882
- }
883
- // ================ 小程序 App, Page, Component 实例属性与方法 ================
884
- }, {
885
- key: "is",
886
- get: function get() {
887
- return this.current.page.is;
796
+ });
797
+ }
798
+ triggerObservers(current, prev) {
799
+ const observers = this.observers;
800
+ if (observers == null) {
801
+ return;
888
802
  }
889
- }, {
890
- key: "id",
891
- get: function get() {
892
- return this.current.page.id;
803
+ if (Object.keys(observers).length === 0) {
804
+ return;
893
805
  }
894
- }, {
895
- key: "dataset",
896
- get: function get() {
897
- return this.current.page.dataset;
806
+ const result = diff(current, prev);
807
+ const resultKeys = Object.keys(result);
808
+ if (resultKeys.length === 0) {
809
+ return;
898
810
  }
899
- }, {
900
- key: "componentMethodsProxy",
901
- value: function componentMethodsProxy(method) {
902
- var _this5 = this;
903
- return function () {
904
- var page = _this5.current.page;
905
- if (page === null || page === void 0 ? void 0 : page[method]) {
906
- return page[method].apply(page, arguments);
907
- } else {
908
- 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
+ }
909
825
  }
910
- };
911
- }
912
- }, {
913
- key: "selectComponent",
914
- value: function selectComponent() {
915
- report(nonsupport.get('selectComponent'));
916
- }
917
- }, {
918
- key: "selectAllComponents",
919
- value: function selectAllComponents() {
920
- report(nonsupport.get('selectAllComponents'));
826
+ }
827
+ if (isModified) {
828
+ observers[observerKey].apply(this, keys.map(key => safeGet(current, key)));
829
+ }
921
830
  }
922
- }, {
923
- key: "selectOwnerComponent",
924
- value: function selectOwnerComponent() {
925
- 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];
926
852
  }
927
- }, {
928
- key: "groupSetData",
929
- value: function groupSetData() {
930
- report(nonsupport.get('groupSetData'));
853
+ if (e.type === 'touchmove') {
854
+ report('catchtouchmove 转换后只能停止回调函数的冒泡,不能阻止滚动穿透。如要阻止滚动穿透,可以手动给编译后的 View 组件加上 catchMove 属性');
931
855
  }
932
- }]);
933
- return BaseComponent;
934
- }(ConnectComponent);
935
- 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;
936
929
  if (props) {
937
- for (var propKey in props) {
938
- var propValue = props[propKey];
930
+ for (const propKey in props) {
931
+ const propValue = props[propKey];
939
932
  if (propValue != null && !isFunction(propValue)) {
940
933
  if (propValue.value !== undefined) {
941
934
  // 如果是 null 也赋值到 defaultProps
942
- BaseComponent.defaultProps = Object.assign(_defineProperty__default["default"]({}, propKey, propValue.value), BaseComponent.defaultProps);
935
+ BaseComponent.defaultProps = Object.assign({
936
+ [propKey]: propValue.value
937
+ }, BaseComponent.defaultProps);
943
938
  }
944
939
  }
945
940
  }
946
941
  }
947
- var staticOptions = ['externalClasses', 'relations', 'options'];
948
- staticOptions.forEach(function (option) {
949
- var value = weappConf[option];
942
+ const staticOptions = ['externalClasses', 'relations', 'options'];
943
+ staticOptions.forEach(option => {
944
+ const value = weappConf[option];
950
945
  if (value != null) {
951
946
  BaseComponent[option] = value;
952
947
  }
@@ -955,7 +950,10 @@
955
950
  };
956
951
  }
957
952
 
953
+ exports.cacheOptions = cacheOptions;
954
+ exports.convertToArray = convertToArray;
958
955
  exports["default"] = withWeapp;
956
+ exports.getTarget = getTarget;
959
957
 
960
958
  Object.defineProperty(exports, '__esModule', { value: true });
961
959