@tarojs/with-weapp 4.0.0-canary.8 → 4.0.0

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