@tarojs/shared 3.5.0-beta.4 → 3.5.0-beta.5
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.
- package/dist/index.d.ts +252 -7
- package/dist/index.js +1123 -1137
- package/dist/index.js.map +1 -1
- package/dist/shared.esm.d.ts +252 -0
- package/dist/shared.esm.js +1123 -1123
- package/dist/shared.esm.js.map +1 -1
- package/dist/template.d.ts +112 -113
- package/dist/template.js +1111 -1111
- package/dist/template.js.map +1 -1
- package/package.json +6 -7
- package/dist/components.d.ts +0 -20
- package/dist/event-emitter.d.ts +0 -27
- package/dist/is.d.ts +0 -9
- package/dist/native-apis.d.ts +0 -16
- package/dist/runtime-hooks.d.ts +0 -119
- package/dist/shortcuts.d.ts +0 -10
- package/dist/utils.d.ts +0 -54
package/dist/shared.esm.js
CHANGED
|
@@ -1,1136 +1,1136 @@
|
|
|
1
|
-
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
2
|
-
const NO_DEFAULT_VALUE = '';
|
|
3
|
-
const DEFAULT_TRUE = '!0';
|
|
4
|
-
const DEFAULT_FALSE = '!1';
|
|
5
|
-
const touchEvents = {
|
|
6
|
-
bindTouchStart: NO_DEFAULT_VALUE,
|
|
7
|
-
bindTouchMove: NO_DEFAULT_VALUE,
|
|
8
|
-
bindTouchEnd: NO_DEFAULT_VALUE,
|
|
9
|
-
bindTouchCancel: NO_DEFAULT_VALUE,
|
|
10
|
-
bindLongTap: NO_DEFAULT_VALUE
|
|
11
|
-
};
|
|
12
|
-
const animation = {
|
|
13
|
-
animation: NO_DEFAULT_VALUE,
|
|
14
|
-
bindAnimationStart: NO_DEFAULT_VALUE,
|
|
15
|
-
bindAnimationIteration: NO_DEFAULT_VALUE,
|
|
16
|
-
bindAnimationEnd: NO_DEFAULT_VALUE,
|
|
17
|
-
bindTransitionEnd: NO_DEFAULT_VALUE
|
|
18
|
-
};
|
|
19
|
-
function singleQuote(s) {
|
|
20
|
-
return `'${s}'`;
|
|
21
|
-
}
|
|
22
|
-
const View = Object.assign(Object.assign({ 'hover-class': singleQuote('none'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '50', 'hover-stay-time': '400' }, touchEvents), animation);
|
|
23
|
-
const Icon = {
|
|
24
|
-
type: NO_DEFAULT_VALUE,
|
|
25
|
-
size: '23',
|
|
26
|
-
color: NO_DEFAULT_VALUE
|
|
27
|
-
};
|
|
28
|
-
const MapComp = Object.assign({ longitude: NO_DEFAULT_VALUE, latitude: NO_DEFAULT_VALUE, scale: '16', markers: DEFAULT_EMPTY_ARRAY, covers: NO_DEFAULT_VALUE, polyline: DEFAULT_EMPTY_ARRAY, circles: DEFAULT_EMPTY_ARRAY, controls: DEFAULT_EMPTY_ARRAY, 'include-points': DEFAULT_EMPTY_ARRAY, 'show-location': NO_DEFAULT_VALUE, 'layer-style': '1', bindMarkerTap: NO_DEFAULT_VALUE, bindControlTap: NO_DEFAULT_VALUE, bindCalloutTap: NO_DEFAULT_VALUE, bindUpdated: NO_DEFAULT_VALUE }, touchEvents);
|
|
29
|
-
const Progress = {
|
|
30
|
-
percent: NO_DEFAULT_VALUE,
|
|
31
|
-
'stroke-width': '6',
|
|
32
|
-
color: singleQuote('#09BB07'),
|
|
33
|
-
activeColor: singleQuote('#09BB07'),
|
|
34
|
-
backgroundColor: singleQuote('#EBEBEB'),
|
|
35
|
-
active: DEFAULT_FALSE,
|
|
36
|
-
'active-mode': singleQuote('backwards'),
|
|
37
|
-
'show-info': DEFAULT_FALSE
|
|
38
|
-
};
|
|
39
|
-
const RichText = {
|
|
40
|
-
nodes: DEFAULT_EMPTY_ARRAY
|
|
41
|
-
};
|
|
42
|
-
const Text = {
|
|
43
|
-
selectable: DEFAULT_FALSE,
|
|
44
|
-
space: NO_DEFAULT_VALUE,
|
|
45
|
-
decode: DEFAULT_FALSE
|
|
46
|
-
};
|
|
47
|
-
const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE }, touchEvents);
|
|
48
|
-
const Checkbox = {
|
|
49
|
-
value: NO_DEFAULT_VALUE,
|
|
50
|
-
disabled: NO_DEFAULT_VALUE,
|
|
51
|
-
checked: DEFAULT_FALSE,
|
|
52
|
-
color: singleQuote('#09BB07'),
|
|
53
|
-
name: NO_DEFAULT_VALUE
|
|
54
|
-
};
|
|
55
|
-
const CheckboxGroup = {
|
|
56
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
57
|
-
name: NO_DEFAULT_VALUE
|
|
58
|
-
};
|
|
59
|
-
const Form = {
|
|
60
|
-
'report-submit': DEFAULT_FALSE,
|
|
61
|
-
bindSubmit: NO_DEFAULT_VALUE,
|
|
62
|
-
bindReset: NO_DEFAULT_VALUE,
|
|
63
|
-
name: NO_DEFAULT_VALUE
|
|
64
|
-
};
|
|
65
|
-
const Input = {
|
|
66
|
-
value: NO_DEFAULT_VALUE,
|
|
67
|
-
type: singleQuote(NO_DEFAULT_VALUE),
|
|
68
|
-
password: DEFAULT_FALSE,
|
|
69
|
-
placeholder: NO_DEFAULT_VALUE,
|
|
70
|
-
'placeholder-style': NO_DEFAULT_VALUE,
|
|
71
|
-
'placeholder-class': singleQuote('input-placeholder'),
|
|
72
|
-
disabled: NO_DEFAULT_VALUE,
|
|
73
|
-
maxlength: '140',
|
|
74
|
-
'cursor-spacing': '0',
|
|
75
|
-
focus: DEFAULT_FALSE,
|
|
76
|
-
'confirm-type': singleQuote('done'),
|
|
77
|
-
'confirm-hold': DEFAULT_FALSE,
|
|
78
|
-
cursor: 'i.value.length',
|
|
79
|
-
'selection-start': '-1',
|
|
80
|
-
'selection-end': '-1',
|
|
81
|
-
bindInput: NO_DEFAULT_VALUE,
|
|
82
|
-
bindFocus: NO_DEFAULT_VALUE,
|
|
83
|
-
bindBlur: NO_DEFAULT_VALUE,
|
|
84
|
-
bindConfirm: NO_DEFAULT_VALUE,
|
|
85
|
-
name: NO_DEFAULT_VALUE
|
|
86
|
-
};
|
|
87
|
-
const Label = {
|
|
88
|
-
for: NO_DEFAULT_VALUE,
|
|
89
|
-
name: NO_DEFAULT_VALUE
|
|
90
|
-
};
|
|
91
|
-
const Picker = {
|
|
92
|
-
mode: singleQuote('selector'),
|
|
93
|
-
disabled: NO_DEFAULT_VALUE,
|
|
94
|
-
range: NO_DEFAULT_VALUE,
|
|
95
|
-
'range-key': NO_DEFAULT_VALUE,
|
|
96
|
-
value: NO_DEFAULT_VALUE,
|
|
97
|
-
start: NO_DEFAULT_VALUE,
|
|
98
|
-
end: NO_DEFAULT_VALUE,
|
|
99
|
-
fields: singleQuote('day'),
|
|
100
|
-
'custom-item': NO_DEFAULT_VALUE,
|
|
101
|
-
name: NO_DEFAULT_VALUE,
|
|
102
|
-
bindCancel: NO_DEFAULT_VALUE,
|
|
103
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
104
|
-
bindColumnChange: NO_DEFAULT_VALUE
|
|
105
|
-
};
|
|
106
|
-
const PickerView = {
|
|
107
|
-
value: NO_DEFAULT_VALUE,
|
|
108
|
-
'indicator-style': NO_DEFAULT_VALUE,
|
|
109
|
-
'indicator-class': NO_DEFAULT_VALUE,
|
|
110
|
-
'mask-style': NO_DEFAULT_VALUE,
|
|
111
|
-
'mask-class': NO_DEFAULT_VALUE,
|
|
112
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
113
|
-
name: NO_DEFAULT_VALUE
|
|
114
|
-
};
|
|
115
|
-
const PickerViewColumn = {
|
|
116
|
-
name: NO_DEFAULT_VALUE
|
|
117
|
-
};
|
|
118
|
-
const Radio = {
|
|
119
|
-
value: NO_DEFAULT_VALUE,
|
|
120
|
-
checked: DEFAULT_FALSE,
|
|
121
|
-
disabled: NO_DEFAULT_VALUE,
|
|
122
|
-
color: singleQuote('#09BB07'),
|
|
123
|
-
name: NO_DEFAULT_VALUE
|
|
124
|
-
};
|
|
125
|
-
const RadioGroup = {
|
|
126
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
127
|
-
name: NO_DEFAULT_VALUE
|
|
128
|
-
};
|
|
129
|
-
const Slider = {
|
|
130
|
-
min: '0',
|
|
131
|
-
max: '100',
|
|
132
|
-
step: '1',
|
|
133
|
-
disabled: NO_DEFAULT_VALUE,
|
|
134
|
-
value: '0',
|
|
135
|
-
activeColor: singleQuote('#1aad19'),
|
|
136
|
-
backgroundColor: singleQuote('#e9e9e9'),
|
|
137
|
-
'block-size': '28',
|
|
138
|
-
'block-color': singleQuote('#ffffff'),
|
|
139
|
-
'show-value': DEFAULT_FALSE,
|
|
140
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
141
|
-
bindChanging: NO_DEFAULT_VALUE,
|
|
142
|
-
name: NO_DEFAULT_VALUE
|
|
143
|
-
};
|
|
144
|
-
const Switch = {
|
|
145
|
-
checked: DEFAULT_FALSE,
|
|
146
|
-
disabled: NO_DEFAULT_VALUE,
|
|
147
|
-
type: singleQuote('switch'),
|
|
148
|
-
color: singleQuote('#04BE02'),
|
|
149
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
150
|
-
name: NO_DEFAULT_VALUE
|
|
151
|
-
};
|
|
152
|
-
const Textarea = {
|
|
153
|
-
value: NO_DEFAULT_VALUE,
|
|
154
|
-
placeholder: NO_DEFAULT_VALUE,
|
|
155
|
-
'placeholder-style': NO_DEFAULT_VALUE,
|
|
156
|
-
'placeholder-class': singleQuote('textarea-placeholder'),
|
|
157
|
-
disabled: NO_DEFAULT_VALUE,
|
|
158
|
-
maxlength: '140',
|
|
159
|
-
'auto-focus': DEFAULT_FALSE,
|
|
160
|
-
focus: DEFAULT_FALSE,
|
|
161
|
-
'auto-height': DEFAULT_FALSE,
|
|
162
|
-
fixed: DEFAULT_FALSE,
|
|
163
|
-
'cursor-spacing': '0',
|
|
164
|
-
cursor: '-1',
|
|
165
|
-
'selection-start': '-1',
|
|
166
|
-
'selection-end': '-1',
|
|
167
|
-
bindFocus: NO_DEFAULT_VALUE,
|
|
168
|
-
bindBlur: NO_DEFAULT_VALUE,
|
|
169
|
-
bindLineChange: NO_DEFAULT_VALUE,
|
|
170
|
-
bindInput: NO_DEFAULT_VALUE,
|
|
171
|
-
bindConfirm: NO_DEFAULT_VALUE,
|
|
172
|
-
name: NO_DEFAULT_VALUE
|
|
173
|
-
};
|
|
174
|
-
const CoverImage = {
|
|
175
|
-
src: NO_DEFAULT_VALUE,
|
|
176
|
-
bindLoad: 'eh',
|
|
177
|
-
bindError: 'eh'
|
|
178
|
-
};
|
|
179
|
-
const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
|
|
180
|
-
const MovableArea = {
|
|
181
|
-
'scale-area': DEFAULT_FALSE
|
|
182
|
-
};
|
|
183
|
-
const MovableView = Object.assign(Object.assign({ direction: 'none', inertia: DEFAULT_FALSE, 'out-of-bounds': DEFAULT_FALSE, x: NO_DEFAULT_VALUE, y: NO_DEFAULT_VALUE, damping: '20', friction: '2', disabled: NO_DEFAULT_VALUE, scale: DEFAULT_FALSE, 'scale-min': '0.5', 'scale-max': '10', 'scale-value': '1', bindChange: NO_DEFAULT_VALUE, bindScale: NO_DEFAULT_VALUE, bindHTouchMove: NO_DEFAULT_VALUE, bindVTouchMove: NO_DEFAULT_VALUE, width: singleQuote('10px'), height: singleQuote('10px') }, touchEvents), animation);
|
|
184
|
-
const ScrollView = Object.assign(Object.assign({ 'scroll-x': DEFAULT_FALSE, 'scroll-y': DEFAULT_FALSE, 'upper-threshold': '50', 'lower-threshold': '50', 'scroll-top': NO_DEFAULT_VALUE, 'scroll-left': NO_DEFAULT_VALUE, 'scroll-into-view': NO_DEFAULT_VALUE, 'scroll-with-animation': DEFAULT_FALSE, 'enable-back-to-top': DEFAULT_FALSE, bindScrollToUpper: NO_DEFAULT_VALUE, bindScrollToLower: NO_DEFAULT_VALUE, bindScroll: NO_DEFAULT_VALUE }, touchEvents), animation);
|
|
185
|
-
const Swiper = Object.assign({ 'indicator-dots': DEFAULT_FALSE, 'indicator-color': singleQuote('rgba(0, 0, 0, .3)'), 'indicator-active-color': singleQuote('#000000'), autoplay: DEFAULT_FALSE, current: '0', interval: '5000', duration: '500', circular: DEFAULT_FALSE, vertical: DEFAULT_FALSE, 'previous-margin': singleQuote('0px'), 'next-margin': singleQuote('0px'), 'display-multiple-items': '1', bindChange: NO_DEFAULT_VALUE, bindTransition: NO_DEFAULT_VALUE, bindAnimationFinish: NO_DEFAULT_VALUE }, touchEvents);
|
|
186
|
-
const SwiperItem = {
|
|
187
|
-
'item-id': NO_DEFAULT_VALUE
|
|
188
|
-
};
|
|
189
|
-
const Navigator = {
|
|
190
|
-
url: NO_DEFAULT_VALUE,
|
|
191
|
-
'open-type': singleQuote('navigate'),
|
|
192
|
-
delta: '1',
|
|
193
|
-
'hover-class': singleQuote('navigator-hover'),
|
|
194
|
-
'hover-stop-propagation': DEFAULT_FALSE,
|
|
195
|
-
'hover-start-time': '50',
|
|
196
|
-
'hover-stay-time': '600',
|
|
197
|
-
bindSuccess: NO_DEFAULT_VALUE,
|
|
198
|
-
bindFail: NO_DEFAULT_VALUE,
|
|
199
|
-
bindComplete: NO_DEFAULT_VALUE
|
|
200
|
-
};
|
|
201
|
-
const Audio = {
|
|
202
|
-
id: NO_DEFAULT_VALUE,
|
|
203
|
-
src: NO_DEFAULT_VALUE,
|
|
204
|
-
loop: DEFAULT_FALSE,
|
|
205
|
-
controls: DEFAULT_FALSE,
|
|
206
|
-
poster: NO_DEFAULT_VALUE,
|
|
207
|
-
name: NO_DEFAULT_VALUE,
|
|
208
|
-
author: NO_DEFAULT_VALUE,
|
|
209
|
-
bindError: NO_DEFAULT_VALUE,
|
|
210
|
-
bindPlay: NO_DEFAULT_VALUE,
|
|
211
|
-
bindPause: NO_DEFAULT_VALUE,
|
|
212
|
-
bindTimeUpdate: NO_DEFAULT_VALUE,
|
|
213
|
-
bindEnded: NO_DEFAULT_VALUE
|
|
214
|
-
};
|
|
215
|
-
const Camera = {
|
|
216
|
-
'device-position': singleQuote('back'),
|
|
217
|
-
flash: singleQuote('auto'),
|
|
218
|
-
bindStop: NO_DEFAULT_VALUE,
|
|
219
|
-
bindError: NO_DEFAULT_VALUE
|
|
220
|
-
};
|
|
221
|
-
const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
|
|
222
|
-
const LivePlayer = Object.assign({ src: NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, muted: DEFAULT_FALSE, orientation: singleQuote('vertical'), 'object-fit': singleQuote('contain'), 'background-mute': DEFAULT_FALSE, 'min-cache': '1', 'max-cache': '3', bindStateChange: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindNetStatus: NO_DEFAULT_VALUE }, animation);
|
|
223
|
-
const Video = Object.assign({ src: NO_DEFAULT_VALUE, duration: NO_DEFAULT_VALUE, controls: DEFAULT_TRUE, 'danmu-list': NO_DEFAULT_VALUE, 'danmu-btn': NO_DEFAULT_VALUE, 'enable-danmu': NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, loop: DEFAULT_FALSE, muted: DEFAULT_FALSE, 'initial-time': '0', 'page-gesture': DEFAULT_FALSE, direction: NO_DEFAULT_VALUE, 'show-progress': DEFAULT_TRUE, 'show-fullscreen-btn': DEFAULT_TRUE, 'show-play-btn': DEFAULT_TRUE, 'show-center-play-btn': DEFAULT_TRUE, 'enable-progress-gesture': DEFAULT_TRUE, 'object-fit': singleQuote('contain'), poster: NO_DEFAULT_VALUE, 'show-mute-btn': DEFAULT_FALSE, bindPlay: NO_DEFAULT_VALUE, bindPause: NO_DEFAULT_VALUE, bindEnded: NO_DEFAULT_VALUE, bindTimeUpdate: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindWaiting: NO_DEFAULT_VALUE, bindError: NO_DEFAULT_VALUE }, animation);
|
|
224
|
-
const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
|
|
225
|
-
const Ad = {
|
|
226
|
-
'unit-id': NO_DEFAULT_VALUE,
|
|
227
|
-
'ad-intervals': NO_DEFAULT_VALUE,
|
|
228
|
-
bindLoad: NO_DEFAULT_VALUE,
|
|
229
|
-
bindError: NO_DEFAULT_VALUE,
|
|
230
|
-
bindClose: NO_DEFAULT_VALUE
|
|
231
|
-
};
|
|
232
|
-
const WebView = {
|
|
233
|
-
src: NO_DEFAULT_VALUE,
|
|
234
|
-
bindMessage: NO_DEFAULT_VALUE,
|
|
235
|
-
bindLoad: NO_DEFAULT_VALUE,
|
|
236
|
-
bindError: NO_DEFAULT_VALUE
|
|
237
|
-
};
|
|
238
|
-
const Block = {};
|
|
239
|
-
// For Vue,因为 slot 标签被 vue 占用了
|
|
240
|
-
const SlotView = {
|
|
241
|
-
name: NO_DEFAULT_VALUE
|
|
242
|
-
};
|
|
243
|
-
// For React
|
|
244
|
-
// Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
|
|
245
|
-
// 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
|
|
246
|
-
// 不给 View 直接加 slot 属性的原因是性能损耗
|
|
247
|
-
const Slot = {
|
|
248
|
-
name: NO_DEFAULT_VALUE
|
|
249
|
-
};
|
|
250
|
-
const internalComponents = {
|
|
251
|
-
View,
|
|
252
|
-
Icon,
|
|
253
|
-
Progress,
|
|
254
|
-
RichText,
|
|
255
|
-
Text,
|
|
256
|
-
Button,
|
|
257
|
-
Checkbox,
|
|
258
|
-
CheckboxGroup,
|
|
259
|
-
Form,
|
|
260
|
-
Input,
|
|
261
|
-
Label,
|
|
262
|
-
Picker,
|
|
263
|
-
PickerView,
|
|
264
|
-
PickerViewColumn,
|
|
265
|
-
Radio,
|
|
266
|
-
RadioGroup,
|
|
267
|
-
Slider,
|
|
268
|
-
Switch,
|
|
269
|
-
CoverImage,
|
|
270
|
-
Textarea,
|
|
271
|
-
CoverView,
|
|
272
|
-
MovableArea,
|
|
273
|
-
MovableView,
|
|
274
|
-
ScrollView,
|
|
275
|
-
Swiper,
|
|
276
|
-
SwiperItem,
|
|
277
|
-
Navigator,
|
|
278
|
-
Audio,
|
|
279
|
-
Camera,
|
|
280
|
-
Image,
|
|
281
|
-
LivePlayer,
|
|
282
|
-
Video,
|
|
283
|
-
Canvas,
|
|
284
|
-
Ad,
|
|
285
|
-
WebView,
|
|
286
|
-
Block,
|
|
287
|
-
Map: MapComp,
|
|
288
|
-
Slot,
|
|
289
|
-
SlotView
|
|
290
|
-
};
|
|
291
|
-
const controlledComponent = new Set([
|
|
292
|
-
'input',
|
|
293
|
-
'checkbox',
|
|
294
|
-
'picker',
|
|
295
|
-
'picker-view',
|
|
296
|
-
'radio',
|
|
297
|
-
'slider',
|
|
298
|
-
'switch',
|
|
299
|
-
'textarea'
|
|
300
|
-
]);
|
|
301
|
-
const focusComponents = new Set([
|
|
302
|
-
'input',
|
|
303
|
-
'textarea'
|
|
304
|
-
]);
|
|
305
|
-
const voidElements = new Set([
|
|
306
|
-
'progress',
|
|
307
|
-
'icon',
|
|
308
|
-
'rich-text',
|
|
309
|
-
'input',
|
|
310
|
-
'textarea',
|
|
311
|
-
'slider',
|
|
312
|
-
'switch',
|
|
313
|
-
'audio',
|
|
314
|
-
'ad',
|
|
315
|
-
'official-account',
|
|
316
|
-
'open-data',
|
|
317
|
-
'navigation-bar'
|
|
318
|
-
]);
|
|
319
|
-
const nestElements = new Map([
|
|
320
|
-
['view', -1],
|
|
321
|
-
['catch-view', -1],
|
|
322
|
-
['cover-view', -1],
|
|
323
|
-
['static-view', -1],
|
|
324
|
-
['pure-view', -1],
|
|
325
|
-
['block', -1],
|
|
326
|
-
['text', -1],
|
|
327
|
-
['static-text', 6],
|
|
328
|
-
['slot', 8],
|
|
329
|
-
['slot-view', 8],
|
|
330
|
-
['label', 6],
|
|
331
|
-
['form', 4],
|
|
332
|
-
['scroll-view', 4],
|
|
333
|
-
['swiper', 4],
|
|
334
|
-
['swiper-item', 4]
|
|
1
|
+
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
2
|
+
const NO_DEFAULT_VALUE = '';
|
|
3
|
+
const DEFAULT_TRUE = '!0';
|
|
4
|
+
const DEFAULT_FALSE = '!1';
|
|
5
|
+
const touchEvents = {
|
|
6
|
+
bindTouchStart: NO_DEFAULT_VALUE,
|
|
7
|
+
bindTouchMove: NO_DEFAULT_VALUE,
|
|
8
|
+
bindTouchEnd: NO_DEFAULT_VALUE,
|
|
9
|
+
bindTouchCancel: NO_DEFAULT_VALUE,
|
|
10
|
+
bindLongTap: NO_DEFAULT_VALUE
|
|
11
|
+
};
|
|
12
|
+
const animation = {
|
|
13
|
+
animation: NO_DEFAULT_VALUE,
|
|
14
|
+
bindAnimationStart: NO_DEFAULT_VALUE,
|
|
15
|
+
bindAnimationIteration: NO_DEFAULT_VALUE,
|
|
16
|
+
bindAnimationEnd: NO_DEFAULT_VALUE,
|
|
17
|
+
bindTransitionEnd: NO_DEFAULT_VALUE
|
|
18
|
+
};
|
|
19
|
+
function singleQuote(s) {
|
|
20
|
+
return `'${s}'`;
|
|
21
|
+
}
|
|
22
|
+
const View = Object.assign(Object.assign({ 'hover-class': singleQuote('none'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '50', 'hover-stay-time': '400' }, touchEvents), animation);
|
|
23
|
+
const Icon = {
|
|
24
|
+
type: NO_DEFAULT_VALUE,
|
|
25
|
+
size: '23',
|
|
26
|
+
color: NO_DEFAULT_VALUE
|
|
27
|
+
};
|
|
28
|
+
const MapComp = Object.assign({ longitude: NO_DEFAULT_VALUE, latitude: NO_DEFAULT_VALUE, scale: '16', markers: DEFAULT_EMPTY_ARRAY, covers: NO_DEFAULT_VALUE, polyline: DEFAULT_EMPTY_ARRAY, circles: DEFAULT_EMPTY_ARRAY, controls: DEFAULT_EMPTY_ARRAY, 'include-points': DEFAULT_EMPTY_ARRAY, 'show-location': NO_DEFAULT_VALUE, 'layer-style': '1', bindMarkerTap: NO_DEFAULT_VALUE, bindControlTap: NO_DEFAULT_VALUE, bindCalloutTap: NO_DEFAULT_VALUE, bindUpdated: NO_DEFAULT_VALUE }, touchEvents);
|
|
29
|
+
const Progress = {
|
|
30
|
+
percent: NO_DEFAULT_VALUE,
|
|
31
|
+
'stroke-width': '6',
|
|
32
|
+
color: singleQuote('#09BB07'),
|
|
33
|
+
activeColor: singleQuote('#09BB07'),
|
|
34
|
+
backgroundColor: singleQuote('#EBEBEB'),
|
|
35
|
+
active: DEFAULT_FALSE,
|
|
36
|
+
'active-mode': singleQuote('backwards'),
|
|
37
|
+
'show-info': DEFAULT_FALSE
|
|
38
|
+
};
|
|
39
|
+
const RichText = {
|
|
40
|
+
nodes: DEFAULT_EMPTY_ARRAY
|
|
41
|
+
};
|
|
42
|
+
const Text = {
|
|
43
|
+
selectable: DEFAULT_FALSE,
|
|
44
|
+
space: NO_DEFAULT_VALUE,
|
|
45
|
+
decode: DEFAULT_FALSE
|
|
46
|
+
};
|
|
47
|
+
const Button = Object.assign({ size: singleQuote('default'), type: NO_DEFAULT_VALUE, plain: DEFAULT_FALSE, disabled: NO_DEFAULT_VALUE, loading: DEFAULT_FALSE, 'form-type': NO_DEFAULT_VALUE, 'open-type': NO_DEFAULT_VALUE, 'hover-class': singleQuote('button-hover'), 'hover-stop-propagation': DEFAULT_FALSE, 'hover-start-time': '20', 'hover-stay-time': '70', name: NO_DEFAULT_VALUE }, touchEvents);
|
|
48
|
+
const Checkbox = {
|
|
49
|
+
value: NO_DEFAULT_VALUE,
|
|
50
|
+
disabled: NO_DEFAULT_VALUE,
|
|
51
|
+
checked: DEFAULT_FALSE,
|
|
52
|
+
color: singleQuote('#09BB07'),
|
|
53
|
+
name: NO_DEFAULT_VALUE
|
|
54
|
+
};
|
|
55
|
+
const CheckboxGroup = {
|
|
56
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
57
|
+
name: NO_DEFAULT_VALUE
|
|
58
|
+
};
|
|
59
|
+
const Form = {
|
|
60
|
+
'report-submit': DEFAULT_FALSE,
|
|
61
|
+
bindSubmit: NO_DEFAULT_VALUE,
|
|
62
|
+
bindReset: NO_DEFAULT_VALUE,
|
|
63
|
+
name: NO_DEFAULT_VALUE
|
|
64
|
+
};
|
|
65
|
+
const Input = {
|
|
66
|
+
value: NO_DEFAULT_VALUE,
|
|
67
|
+
type: singleQuote(NO_DEFAULT_VALUE),
|
|
68
|
+
password: DEFAULT_FALSE,
|
|
69
|
+
placeholder: NO_DEFAULT_VALUE,
|
|
70
|
+
'placeholder-style': NO_DEFAULT_VALUE,
|
|
71
|
+
'placeholder-class': singleQuote('input-placeholder'),
|
|
72
|
+
disabled: NO_DEFAULT_VALUE,
|
|
73
|
+
maxlength: '140',
|
|
74
|
+
'cursor-spacing': '0',
|
|
75
|
+
focus: DEFAULT_FALSE,
|
|
76
|
+
'confirm-type': singleQuote('done'),
|
|
77
|
+
'confirm-hold': DEFAULT_FALSE,
|
|
78
|
+
cursor: 'i.value.length',
|
|
79
|
+
'selection-start': '-1',
|
|
80
|
+
'selection-end': '-1',
|
|
81
|
+
bindInput: NO_DEFAULT_VALUE,
|
|
82
|
+
bindFocus: NO_DEFAULT_VALUE,
|
|
83
|
+
bindBlur: NO_DEFAULT_VALUE,
|
|
84
|
+
bindConfirm: NO_DEFAULT_VALUE,
|
|
85
|
+
name: NO_DEFAULT_VALUE
|
|
86
|
+
};
|
|
87
|
+
const Label = {
|
|
88
|
+
for: NO_DEFAULT_VALUE,
|
|
89
|
+
name: NO_DEFAULT_VALUE
|
|
90
|
+
};
|
|
91
|
+
const Picker = {
|
|
92
|
+
mode: singleQuote('selector'),
|
|
93
|
+
disabled: NO_DEFAULT_VALUE,
|
|
94
|
+
range: NO_DEFAULT_VALUE,
|
|
95
|
+
'range-key': NO_DEFAULT_VALUE,
|
|
96
|
+
value: NO_DEFAULT_VALUE,
|
|
97
|
+
start: NO_DEFAULT_VALUE,
|
|
98
|
+
end: NO_DEFAULT_VALUE,
|
|
99
|
+
fields: singleQuote('day'),
|
|
100
|
+
'custom-item': NO_DEFAULT_VALUE,
|
|
101
|
+
name: NO_DEFAULT_VALUE,
|
|
102
|
+
bindCancel: NO_DEFAULT_VALUE,
|
|
103
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
104
|
+
bindColumnChange: NO_DEFAULT_VALUE
|
|
105
|
+
};
|
|
106
|
+
const PickerView = {
|
|
107
|
+
value: NO_DEFAULT_VALUE,
|
|
108
|
+
'indicator-style': NO_DEFAULT_VALUE,
|
|
109
|
+
'indicator-class': NO_DEFAULT_VALUE,
|
|
110
|
+
'mask-style': NO_DEFAULT_VALUE,
|
|
111
|
+
'mask-class': NO_DEFAULT_VALUE,
|
|
112
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
113
|
+
name: NO_DEFAULT_VALUE
|
|
114
|
+
};
|
|
115
|
+
const PickerViewColumn = {
|
|
116
|
+
name: NO_DEFAULT_VALUE
|
|
117
|
+
};
|
|
118
|
+
const Radio = {
|
|
119
|
+
value: NO_DEFAULT_VALUE,
|
|
120
|
+
checked: DEFAULT_FALSE,
|
|
121
|
+
disabled: NO_DEFAULT_VALUE,
|
|
122
|
+
color: singleQuote('#09BB07'),
|
|
123
|
+
name: NO_DEFAULT_VALUE
|
|
124
|
+
};
|
|
125
|
+
const RadioGroup = {
|
|
126
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
127
|
+
name: NO_DEFAULT_VALUE
|
|
128
|
+
};
|
|
129
|
+
const Slider = {
|
|
130
|
+
min: '0',
|
|
131
|
+
max: '100',
|
|
132
|
+
step: '1',
|
|
133
|
+
disabled: NO_DEFAULT_VALUE,
|
|
134
|
+
value: '0',
|
|
135
|
+
activeColor: singleQuote('#1aad19'),
|
|
136
|
+
backgroundColor: singleQuote('#e9e9e9'),
|
|
137
|
+
'block-size': '28',
|
|
138
|
+
'block-color': singleQuote('#ffffff'),
|
|
139
|
+
'show-value': DEFAULT_FALSE,
|
|
140
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
141
|
+
bindChanging: NO_DEFAULT_VALUE,
|
|
142
|
+
name: NO_DEFAULT_VALUE
|
|
143
|
+
};
|
|
144
|
+
const Switch = {
|
|
145
|
+
checked: DEFAULT_FALSE,
|
|
146
|
+
disabled: NO_DEFAULT_VALUE,
|
|
147
|
+
type: singleQuote('switch'),
|
|
148
|
+
color: singleQuote('#04BE02'),
|
|
149
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
150
|
+
name: NO_DEFAULT_VALUE
|
|
151
|
+
};
|
|
152
|
+
const Textarea = {
|
|
153
|
+
value: NO_DEFAULT_VALUE,
|
|
154
|
+
placeholder: NO_DEFAULT_VALUE,
|
|
155
|
+
'placeholder-style': NO_DEFAULT_VALUE,
|
|
156
|
+
'placeholder-class': singleQuote('textarea-placeholder'),
|
|
157
|
+
disabled: NO_DEFAULT_VALUE,
|
|
158
|
+
maxlength: '140',
|
|
159
|
+
'auto-focus': DEFAULT_FALSE,
|
|
160
|
+
focus: DEFAULT_FALSE,
|
|
161
|
+
'auto-height': DEFAULT_FALSE,
|
|
162
|
+
fixed: DEFAULT_FALSE,
|
|
163
|
+
'cursor-spacing': '0',
|
|
164
|
+
cursor: '-1',
|
|
165
|
+
'selection-start': '-1',
|
|
166
|
+
'selection-end': '-1',
|
|
167
|
+
bindFocus: NO_DEFAULT_VALUE,
|
|
168
|
+
bindBlur: NO_DEFAULT_VALUE,
|
|
169
|
+
bindLineChange: NO_DEFAULT_VALUE,
|
|
170
|
+
bindInput: NO_DEFAULT_VALUE,
|
|
171
|
+
bindConfirm: NO_DEFAULT_VALUE,
|
|
172
|
+
name: NO_DEFAULT_VALUE
|
|
173
|
+
};
|
|
174
|
+
const CoverImage = {
|
|
175
|
+
src: NO_DEFAULT_VALUE,
|
|
176
|
+
bindLoad: 'eh',
|
|
177
|
+
bindError: 'eh'
|
|
178
|
+
};
|
|
179
|
+
const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
|
|
180
|
+
const MovableArea = {
|
|
181
|
+
'scale-area': DEFAULT_FALSE
|
|
182
|
+
};
|
|
183
|
+
const MovableView = Object.assign(Object.assign({ direction: 'none', inertia: DEFAULT_FALSE, 'out-of-bounds': DEFAULT_FALSE, x: NO_DEFAULT_VALUE, y: NO_DEFAULT_VALUE, damping: '20', friction: '2', disabled: NO_DEFAULT_VALUE, scale: DEFAULT_FALSE, 'scale-min': '0.5', 'scale-max': '10', 'scale-value': '1', bindChange: NO_DEFAULT_VALUE, bindScale: NO_DEFAULT_VALUE, bindHTouchMove: NO_DEFAULT_VALUE, bindVTouchMove: NO_DEFAULT_VALUE, width: singleQuote('10px'), height: singleQuote('10px') }, touchEvents), animation);
|
|
184
|
+
const ScrollView = Object.assign(Object.assign({ 'scroll-x': DEFAULT_FALSE, 'scroll-y': DEFAULT_FALSE, 'upper-threshold': '50', 'lower-threshold': '50', 'scroll-top': NO_DEFAULT_VALUE, 'scroll-left': NO_DEFAULT_VALUE, 'scroll-into-view': NO_DEFAULT_VALUE, 'scroll-with-animation': DEFAULT_FALSE, 'enable-back-to-top': DEFAULT_FALSE, bindScrollToUpper: NO_DEFAULT_VALUE, bindScrollToLower: NO_DEFAULT_VALUE, bindScroll: NO_DEFAULT_VALUE }, touchEvents), animation);
|
|
185
|
+
const Swiper = Object.assign({ 'indicator-dots': DEFAULT_FALSE, 'indicator-color': singleQuote('rgba(0, 0, 0, .3)'), 'indicator-active-color': singleQuote('#000000'), autoplay: DEFAULT_FALSE, current: '0', interval: '5000', duration: '500', circular: DEFAULT_FALSE, vertical: DEFAULT_FALSE, 'previous-margin': singleQuote('0px'), 'next-margin': singleQuote('0px'), 'display-multiple-items': '1', bindChange: NO_DEFAULT_VALUE, bindTransition: NO_DEFAULT_VALUE, bindAnimationFinish: NO_DEFAULT_VALUE }, touchEvents);
|
|
186
|
+
const SwiperItem = {
|
|
187
|
+
'item-id': NO_DEFAULT_VALUE
|
|
188
|
+
};
|
|
189
|
+
const Navigator = {
|
|
190
|
+
url: NO_DEFAULT_VALUE,
|
|
191
|
+
'open-type': singleQuote('navigate'),
|
|
192
|
+
delta: '1',
|
|
193
|
+
'hover-class': singleQuote('navigator-hover'),
|
|
194
|
+
'hover-stop-propagation': DEFAULT_FALSE,
|
|
195
|
+
'hover-start-time': '50',
|
|
196
|
+
'hover-stay-time': '600',
|
|
197
|
+
bindSuccess: NO_DEFAULT_VALUE,
|
|
198
|
+
bindFail: NO_DEFAULT_VALUE,
|
|
199
|
+
bindComplete: NO_DEFAULT_VALUE
|
|
200
|
+
};
|
|
201
|
+
const Audio = {
|
|
202
|
+
id: NO_DEFAULT_VALUE,
|
|
203
|
+
src: NO_DEFAULT_VALUE,
|
|
204
|
+
loop: DEFAULT_FALSE,
|
|
205
|
+
controls: DEFAULT_FALSE,
|
|
206
|
+
poster: NO_DEFAULT_VALUE,
|
|
207
|
+
name: NO_DEFAULT_VALUE,
|
|
208
|
+
author: NO_DEFAULT_VALUE,
|
|
209
|
+
bindError: NO_DEFAULT_VALUE,
|
|
210
|
+
bindPlay: NO_DEFAULT_VALUE,
|
|
211
|
+
bindPause: NO_DEFAULT_VALUE,
|
|
212
|
+
bindTimeUpdate: NO_DEFAULT_VALUE,
|
|
213
|
+
bindEnded: NO_DEFAULT_VALUE
|
|
214
|
+
};
|
|
215
|
+
const Camera = {
|
|
216
|
+
'device-position': singleQuote('back'),
|
|
217
|
+
flash: singleQuote('auto'),
|
|
218
|
+
bindStop: NO_DEFAULT_VALUE,
|
|
219
|
+
bindError: NO_DEFAULT_VALUE
|
|
220
|
+
};
|
|
221
|
+
const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
|
|
222
|
+
const LivePlayer = Object.assign({ src: NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, muted: DEFAULT_FALSE, orientation: singleQuote('vertical'), 'object-fit': singleQuote('contain'), 'background-mute': DEFAULT_FALSE, 'min-cache': '1', 'max-cache': '3', bindStateChange: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindNetStatus: NO_DEFAULT_VALUE }, animation);
|
|
223
|
+
const Video = Object.assign({ src: NO_DEFAULT_VALUE, duration: NO_DEFAULT_VALUE, controls: DEFAULT_TRUE, 'danmu-list': NO_DEFAULT_VALUE, 'danmu-btn': NO_DEFAULT_VALUE, 'enable-danmu': NO_DEFAULT_VALUE, autoplay: DEFAULT_FALSE, loop: DEFAULT_FALSE, muted: DEFAULT_FALSE, 'initial-time': '0', 'page-gesture': DEFAULT_FALSE, direction: NO_DEFAULT_VALUE, 'show-progress': DEFAULT_TRUE, 'show-fullscreen-btn': DEFAULT_TRUE, 'show-play-btn': DEFAULT_TRUE, 'show-center-play-btn': DEFAULT_TRUE, 'enable-progress-gesture': DEFAULT_TRUE, 'object-fit': singleQuote('contain'), poster: NO_DEFAULT_VALUE, 'show-mute-btn': DEFAULT_FALSE, bindPlay: NO_DEFAULT_VALUE, bindPause: NO_DEFAULT_VALUE, bindEnded: NO_DEFAULT_VALUE, bindTimeUpdate: NO_DEFAULT_VALUE, bindFullScreenChange: NO_DEFAULT_VALUE, bindWaiting: NO_DEFAULT_VALUE, bindError: NO_DEFAULT_VALUE }, animation);
|
|
224
|
+
const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
|
|
225
|
+
const Ad = {
|
|
226
|
+
'unit-id': NO_DEFAULT_VALUE,
|
|
227
|
+
'ad-intervals': NO_DEFAULT_VALUE,
|
|
228
|
+
bindLoad: NO_DEFAULT_VALUE,
|
|
229
|
+
bindError: NO_DEFAULT_VALUE,
|
|
230
|
+
bindClose: NO_DEFAULT_VALUE
|
|
231
|
+
};
|
|
232
|
+
const WebView = {
|
|
233
|
+
src: NO_DEFAULT_VALUE,
|
|
234
|
+
bindMessage: NO_DEFAULT_VALUE,
|
|
235
|
+
bindLoad: NO_DEFAULT_VALUE,
|
|
236
|
+
bindError: NO_DEFAULT_VALUE
|
|
237
|
+
};
|
|
238
|
+
const Block = {};
|
|
239
|
+
// For Vue,因为 slot 标签被 vue 占用了
|
|
240
|
+
const SlotView = {
|
|
241
|
+
name: NO_DEFAULT_VALUE
|
|
242
|
+
};
|
|
243
|
+
// For React
|
|
244
|
+
// Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
|
|
245
|
+
// 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
|
|
246
|
+
// 不给 View 直接加 slot 属性的原因是性能损耗
|
|
247
|
+
const Slot = {
|
|
248
|
+
name: NO_DEFAULT_VALUE
|
|
249
|
+
};
|
|
250
|
+
const internalComponents = {
|
|
251
|
+
View,
|
|
252
|
+
Icon,
|
|
253
|
+
Progress,
|
|
254
|
+
RichText,
|
|
255
|
+
Text,
|
|
256
|
+
Button,
|
|
257
|
+
Checkbox,
|
|
258
|
+
CheckboxGroup,
|
|
259
|
+
Form,
|
|
260
|
+
Input,
|
|
261
|
+
Label,
|
|
262
|
+
Picker,
|
|
263
|
+
PickerView,
|
|
264
|
+
PickerViewColumn,
|
|
265
|
+
Radio,
|
|
266
|
+
RadioGroup,
|
|
267
|
+
Slider,
|
|
268
|
+
Switch,
|
|
269
|
+
CoverImage,
|
|
270
|
+
Textarea,
|
|
271
|
+
CoverView,
|
|
272
|
+
MovableArea,
|
|
273
|
+
MovableView,
|
|
274
|
+
ScrollView,
|
|
275
|
+
Swiper,
|
|
276
|
+
SwiperItem,
|
|
277
|
+
Navigator,
|
|
278
|
+
Audio,
|
|
279
|
+
Camera,
|
|
280
|
+
Image,
|
|
281
|
+
LivePlayer,
|
|
282
|
+
Video,
|
|
283
|
+
Canvas,
|
|
284
|
+
Ad,
|
|
285
|
+
WebView,
|
|
286
|
+
Block,
|
|
287
|
+
Map: MapComp,
|
|
288
|
+
Slot,
|
|
289
|
+
SlotView
|
|
290
|
+
};
|
|
291
|
+
const controlledComponent = new Set([
|
|
292
|
+
'input',
|
|
293
|
+
'checkbox',
|
|
294
|
+
'picker',
|
|
295
|
+
'picker-view',
|
|
296
|
+
'radio',
|
|
297
|
+
'slider',
|
|
298
|
+
'switch',
|
|
299
|
+
'textarea'
|
|
300
|
+
]);
|
|
301
|
+
const focusComponents = new Set([
|
|
302
|
+
'input',
|
|
303
|
+
'textarea'
|
|
304
|
+
]);
|
|
305
|
+
const voidElements = new Set([
|
|
306
|
+
'progress',
|
|
307
|
+
'icon',
|
|
308
|
+
'rich-text',
|
|
309
|
+
'input',
|
|
310
|
+
'textarea',
|
|
311
|
+
'slider',
|
|
312
|
+
'switch',
|
|
313
|
+
'audio',
|
|
314
|
+
'ad',
|
|
315
|
+
'official-account',
|
|
316
|
+
'open-data',
|
|
317
|
+
'navigation-bar'
|
|
318
|
+
]);
|
|
319
|
+
const nestElements = new Map([
|
|
320
|
+
['view', -1],
|
|
321
|
+
['catch-view', -1],
|
|
322
|
+
['cover-view', -1],
|
|
323
|
+
['static-view', -1],
|
|
324
|
+
['pure-view', -1],
|
|
325
|
+
['block', -1],
|
|
326
|
+
['text', -1],
|
|
327
|
+
['static-text', 6],
|
|
328
|
+
['slot', 8],
|
|
329
|
+
['slot-view', 8],
|
|
330
|
+
['label', 6],
|
|
331
|
+
['form', 4],
|
|
332
|
+
['scroll-view', 4],
|
|
333
|
+
['swiper', 4],
|
|
334
|
+
['swiper-item', 4]
|
|
335
335
|
]);
|
|
336
336
|
|
|
337
|
-
class Events {
|
|
338
|
-
constructor(opts) {
|
|
339
|
-
var _a;
|
|
340
|
-
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
341
|
-
}
|
|
342
|
-
on(eventName, callback, context) {
|
|
343
|
-
let event, node, tail, list;
|
|
344
|
-
if (!callback) {
|
|
345
|
-
return this;
|
|
346
|
-
}
|
|
347
|
-
eventName = eventName.split(Events.eventSplitter);
|
|
348
|
-
this.callbacks || (this.callbacks = {});
|
|
349
|
-
const calls = this.callbacks;
|
|
350
|
-
while ((event = eventName.shift())) {
|
|
351
|
-
list = calls[event];
|
|
352
|
-
node = list ? list.tail : {};
|
|
353
|
-
node.next = tail = {};
|
|
354
|
-
node.context = context;
|
|
355
|
-
node.callback = callback;
|
|
356
|
-
calls[event] = {
|
|
357
|
-
tail,
|
|
358
|
-
next: list ? list.next : node
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
return this;
|
|
362
|
-
}
|
|
363
|
-
once(events, callback, context) {
|
|
364
|
-
const wrapper = (...args) => {
|
|
365
|
-
callback.apply(this, args);
|
|
366
|
-
this.off(events, wrapper, context);
|
|
367
|
-
};
|
|
368
|
-
this.on(events, wrapper, context);
|
|
369
|
-
return this;
|
|
370
|
-
}
|
|
371
|
-
off(events, callback, context) {
|
|
372
|
-
let event, calls, node, tail, cb, ctx;
|
|
373
|
-
if (!(calls = this.callbacks)) {
|
|
374
|
-
return this;
|
|
375
|
-
}
|
|
376
|
-
if (!(events || callback || context)) {
|
|
377
|
-
delete this.callbacks;
|
|
378
|
-
return this;
|
|
379
|
-
}
|
|
380
|
-
events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
|
|
381
|
-
while ((event = events.shift())) {
|
|
382
|
-
node = calls[event];
|
|
383
|
-
delete calls[event];
|
|
384
|
-
if (!node || !(callback || context)) {
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
tail = node.tail;
|
|
388
|
-
while ((node = node.next) !== tail) {
|
|
389
|
-
cb = node.callback;
|
|
390
|
-
ctx = node.context;
|
|
391
|
-
if ((callback && cb !== callback) || (context && ctx !== context)) {
|
|
392
|
-
this.on(event, cb, ctx);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return this;
|
|
397
|
-
}
|
|
398
|
-
trigger(events) {
|
|
399
|
-
let event, node, calls, tail;
|
|
400
|
-
if (!(calls = this.callbacks)) {
|
|
401
|
-
return this;
|
|
402
|
-
}
|
|
403
|
-
events = events.split(Events.eventSplitter);
|
|
404
|
-
const rest = [].slice.call(arguments, 1);
|
|
405
|
-
while ((event = events.shift())) {
|
|
406
|
-
if ((node = calls[event])) {
|
|
407
|
-
tail = node.tail;
|
|
408
|
-
while ((node = node.next) !== tail) {
|
|
409
|
-
node.callback.apply(node.context || this, rest);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return this;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
337
|
+
class Events {
|
|
338
|
+
constructor(opts) {
|
|
339
|
+
var _a;
|
|
340
|
+
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
341
|
+
}
|
|
342
|
+
on(eventName, callback, context) {
|
|
343
|
+
let event, node, tail, list;
|
|
344
|
+
if (!callback) {
|
|
345
|
+
return this;
|
|
346
|
+
}
|
|
347
|
+
eventName = eventName.split(Events.eventSplitter);
|
|
348
|
+
this.callbacks || (this.callbacks = {});
|
|
349
|
+
const calls = this.callbacks;
|
|
350
|
+
while ((event = eventName.shift())) {
|
|
351
|
+
list = calls[event];
|
|
352
|
+
node = list ? list.tail : {};
|
|
353
|
+
node.next = tail = {};
|
|
354
|
+
node.context = context;
|
|
355
|
+
node.callback = callback;
|
|
356
|
+
calls[event] = {
|
|
357
|
+
tail,
|
|
358
|
+
next: list ? list.next : node
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return this;
|
|
362
|
+
}
|
|
363
|
+
once(events, callback, context) {
|
|
364
|
+
const wrapper = (...args) => {
|
|
365
|
+
callback.apply(this, args);
|
|
366
|
+
this.off(events, wrapper, context);
|
|
367
|
+
};
|
|
368
|
+
this.on(events, wrapper, context);
|
|
369
|
+
return this;
|
|
370
|
+
}
|
|
371
|
+
off(events, callback, context) {
|
|
372
|
+
let event, calls, node, tail, cb, ctx;
|
|
373
|
+
if (!(calls = this.callbacks)) {
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
if (!(events || callback || context)) {
|
|
377
|
+
delete this.callbacks;
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
|
|
381
|
+
while ((event = events.shift())) {
|
|
382
|
+
node = calls[event];
|
|
383
|
+
delete calls[event];
|
|
384
|
+
if (!node || !(callback || context)) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
tail = node.tail;
|
|
388
|
+
while ((node = node.next) !== tail) {
|
|
389
|
+
cb = node.callback;
|
|
390
|
+
ctx = node.context;
|
|
391
|
+
if ((callback && cb !== callback) || (context && ctx !== context)) {
|
|
392
|
+
this.on(event, cb, ctx);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return this;
|
|
397
|
+
}
|
|
398
|
+
trigger(events) {
|
|
399
|
+
let event, node, calls, tail;
|
|
400
|
+
if (!(calls = this.callbacks)) {
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
events = events.split(Events.eventSplitter);
|
|
404
|
+
const rest = [].slice.call(arguments, 1);
|
|
405
|
+
while ((event = events.shift())) {
|
|
406
|
+
if ((node = calls[event])) {
|
|
407
|
+
tail = node.tail;
|
|
408
|
+
while ((node = node.next) !== tail) {
|
|
409
|
+
node.callback.apply(node.context || this, rest);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return this;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
416
|
Events.eventSplitter = /\s+/;
|
|
417
417
|
|
|
418
|
-
function isString(o) {
|
|
419
|
-
return typeof o === 'string';
|
|
420
|
-
}
|
|
421
|
-
function isUndefined(o) {
|
|
422
|
-
return typeof o === 'undefined';
|
|
423
|
-
}
|
|
424
|
-
function isNull(o) {
|
|
425
|
-
return o === null;
|
|
426
|
-
}
|
|
427
|
-
function isObject(o) {
|
|
428
|
-
return o !== null && typeof o === 'object';
|
|
429
|
-
}
|
|
430
|
-
function isBoolean(o) {
|
|
431
|
-
return o === true || o === false;
|
|
432
|
-
}
|
|
433
|
-
function isFunction(o) {
|
|
434
|
-
return typeof o === 'function';
|
|
435
|
-
}
|
|
436
|
-
function isNumber(o) {
|
|
437
|
-
return typeof o === 'number';
|
|
438
|
-
}
|
|
439
|
-
function isBooleanStringLiteral(o) {
|
|
440
|
-
return o === 'true' || o === 'false';
|
|
441
|
-
}
|
|
418
|
+
function isString(o) {
|
|
419
|
+
return typeof o === 'string';
|
|
420
|
+
}
|
|
421
|
+
function isUndefined(o) {
|
|
422
|
+
return typeof o === 'undefined';
|
|
423
|
+
}
|
|
424
|
+
function isNull(o) {
|
|
425
|
+
return o === null;
|
|
426
|
+
}
|
|
427
|
+
function isObject(o) {
|
|
428
|
+
return o !== null && typeof o === 'object';
|
|
429
|
+
}
|
|
430
|
+
function isBoolean(o) {
|
|
431
|
+
return o === true || o === false;
|
|
432
|
+
}
|
|
433
|
+
function isFunction(o) {
|
|
434
|
+
return typeof o === 'function';
|
|
435
|
+
}
|
|
436
|
+
function isNumber(o) {
|
|
437
|
+
return typeof o === 'number';
|
|
438
|
+
}
|
|
439
|
+
function isBooleanStringLiteral(o) {
|
|
440
|
+
return o === 'true' || o === 'false';
|
|
441
|
+
}
|
|
442
442
|
const isArray = Array.isArray;
|
|
443
443
|
|
|
444
|
-
var HOOK_TYPE;
|
|
445
|
-
(function (HOOK_TYPE) {
|
|
446
|
-
HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
|
|
447
|
-
HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
|
|
448
|
-
HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
|
|
449
|
-
})(HOOK_TYPE || (HOOK_TYPE = {}));
|
|
450
|
-
const defaultMiniLifecycle = {
|
|
451
|
-
app: [
|
|
452
|
-
'onLaunch',
|
|
453
|
-
'onShow',
|
|
454
|
-
'onHide'
|
|
455
|
-
],
|
|
456
|
-
page: [
|
|
457
|
-
'onLoad',
|
|
458
|
-
'onUnload',
|
|
459
|
-
'onReady',
|
|
460
|
-
'onShow',
|
|
461
|
-
'onHide',
|
|
462
|
-
[
|
|
463
|
-
'onPullDownRefresh',
|
|
464
|
-
'onReachBottom',
|
|
465
|
-
'onPageScroll',
|
|
466
|
-
'onResize',
|
|
467
|
-
'onTabItemTap',
|
|
468
|
-
'onTitleClick',
|
|
469
|
-
'onOptionMenuClick',
|
|
470
|
-
'onPopMenuClick',
|
|
471
|
-
'onPullIntercept',
|
|
472
|
-
'onAddToFavorites'
|
|
473
|
-
]
|
|
474
|
-
]
|
|
475
|
-
};
|
|
476
|
-
function TaroHook(type, initial) {
|
|
477
|
-
return {
|
|
478
|
-
type,
|
|
479
|
-
initial: initial || null
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
class TaroHooks extends Events {
|
|
483
|
-
constructor(hooks, opts) {
|
|
484
|
-
super(opts);
|
|
485
|
-
this.hooks = hooks;
|
|
486
|
-
for (const hookName in hooks) {
|
|
487
|
-
const { initial } = hooks[hookName];
|
|
488
|
-
if (isFunction(initial)) {
|
|
489
|
-
this.on(hookName, initial);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
tapOneOrMany(hookName, callback) {
|
|
494
|
-
const list = isFunction(callback) ? [callback] : callback;
|
|
495
|
-
list.forEach(cb => this.on(hookName, cb));
|
|
496
|
-
}
|
|
497
|
-
tap(hookName, callback) {
|
|
498
|
-
const hooks = this.hooks;
|
|
499
|
-
const { type, initial } = hooks[hookName];
|
|
500
|
-
if (type === HOOK_TYPE.SINGLE) {
|
|
501
|
-
this.off(hookName);
|
|
502
|
-
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
initial && this.off(hookName, initial);
|
|
506
|
-
this.tapOneOrMany(hookName, callback);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
call(hookName, ...rest) {
|
|
510
|
-
var _a;
|
|
511
|
-
const hook = this.hooks[hookName];
|
|
512
|
-
if (!hook)
|
|
513
|
-
return;
|
|
514
|
-
const { type } = hook;
|
|
515
|
-
const calls = this.callbacks;
|
|
516
|
-
if (!calls)
|
|
517
|
-
return;
|
|
518
|
-
const list = calls[hookName];
|
|
519
|
-
if (list) {
|
|
520
|
-
const tail = list.tail;
|
|
521
|
-
let node = list.next;
|
|
522
|
-
let args = rest;
|
|
523
|
-
let res;
|
|
524
|
-
while (node !== tail) {
|
|
525
|
-
res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
|
|
526
|
-
if (type === HOOK_TYPE.WATERFALL) {
|
|
527
|
-
const params = [res];
|
|
528
|
-
args = params;
|
|
529
|
-
}
|
|
530
|
-
node = node.next;
|
|
531
|
-
}
|
|
532
|
-
return res;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
isExist(hookName) {
|
|
536
|
-
var _a;
|
|
537
|
-
return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
const hooks = new TaroHooks({
|
|
541
|
-
getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
|
|
542
|
-
getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
|
|
543
|
-
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
544
|
-
}),
|
|
545
|
-
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
546
|
-
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
547
|
-
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
548
|
-
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
549
|
-
/**
|
|
550
|
-
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
551
|
-
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
552
|
-
*/
|
|
553
|
-
const BUBBLE_EVENTS = new Set([
|
|
554
|
-
'touchstart',
|
|
555
|
-
'touchmove',
|
|
556
|
-
'touchcancel',
|
|
557
|
-
'touchend',
|
|
558
|
-
'touchforcechange',
|
|
559
|
-
'tap',
|
|
560
|
-
'longpress',
|
|
561
|
-
'longtap',
|
|
562
|
-
'transitionend',
|
|
563
|
-
'animationstart',
|
|
564
|
-
'animationiteration',
|
|
565
|
-
'animationend'
|
|
566
|
-
]);
|
|
567
|
-
return BUBBLE_EVENTS.has(eventName);
|
|
568
|
-
}),
|
|
569
|
-
getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
|
|
570
|
-
onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
|
|
571
|
-
batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
|
|
572
|
-
mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
|
|
573
|
-
modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
|
|
574
|
-
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
575
|
-
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
576
|
-
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
577
|
-
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
578
|
-
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
579
|
-
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
580
|
-
modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
581
|
-
modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
|
|
582
|
-
try {
|
|
583
|
-
// 有些小程序的事件对象的某些属性只读
|
|
584
|
-
this.call('modifyMpEvent', e);
|
|
585
|
-
}
|
|
586
|
-
catch (error) {
|
|
587
|
-
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
588
|
-
}
|
|
589
|
-
}),
|
|
590
|
-
modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
591
|
-
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
592
|
-
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
593
|
-
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
444
|
+
var HOOK_TYPE;
|
|
445
|
+
(function (HOOK_TYPE) {
|
|
446
|
+
HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
|
|
447
|
+
HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
|
|
448
|
+
HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
|
|
449
|
+
})(HOOK_TYPE || (HOOK_TYPE = {}));
|
|
450
|
+
const defaultMiniLifecycle = {
|
|
451
|
+
app: [
|
|
452
|
+
'onLaunch',
|
|
453
|
+
'onShow',
|
|
454
|
+
'onHide'
|
|
455
|
+
],
|
|
456
|
+
page: [
|
|
457
|
+
'onLoad',
|
|
458
|
+
'onUnload',
|
|
459
|
+
'onReady',
|
|
460
|
+
'onShow',
|
|
461
|
+
'onHide',
|
|
462
|
+
[
|
|
463
|
+
'onPullDownRefresh',
|
|
464
|
+
'onReachBottom',
|
|
465
|
+
'onPageScroll',
|
|
466
|
+
'onResize',
|
|
467
|
+
'onTabItemTap',
|
|
468
|
+
'onTitleClick',
|
|
469
|
+
'onOptionMenuClick',
|
|
470
|
+
'onPopMenuClick',
|
|
471
|
+
'onPullIntercept',
|
|
472
|
+
'onAddToFavorites'
|
|
473
|
+
]
|
|
474
|
+
]
|
|
475
|
+
};
|
|
476
|
+
function TaroHook(type, initial) {
|
|
477
|
+
return {
|
|
478
|
+
type,
|
|
479
|
+
initial: initial || null
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
class TaroHooks extends Events {
|
|
483
|
+
constructor(hooks, opts) {
|
|
484
|
+
super(opts);
|
|
485
|
+
this.hooks = hooks;
|
|
486
|
+
for (const hookName in hooks) {
|
|
487
|
+
const { initial } = hooks[hookName];
|
|
488
|
+
if (isFunction(initial)) {
|
|
489
|
+
this.on(hookName, initial);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
tapOneOrMany(hookName, callback) {
|
|
494
|
+
const list = isFunction(callback) ? [callback] : callback;
|
|
495
|
+
list.forEach(cb => this.on(hookName, cb));
|
|
496
|
+
}
|
|
497
|
+
tap(hookName, callback) {
|
|
498
|
+
const hooks = this.hooks;
|
|
499
|
+
const { type, initial } = hooks[hookName];
|
|
500
|
+
if (type === HOOK_TYPE.SINGLE) {
|
|
501
|
+
this.off(hookName);
|
|
502
|
+
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
initial && this.off(hookName, initial);
|
|
506
|
+
this.tapOneOrMany(hookName, callback);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
call(hookName, ...rest) {
|
|
510
|
+
var _a;
|
|
511
|
+
const hook = this.hooks[hookName];
|
|
512
|
+
if (!hook)
|
|
513
|
+
return;
|
|
514
|
+
const { type } = hook;
|
|
515
|
+
const calls = this.callbacks;
|
|
516
|
+
if (!calls)
|
|
517
|
+
return;
|
|
518
|
+
const list = calls[hookName];
|
|
519
|
+
if (list) {
|
|
520
|
+
const tail = list.tail;
|
|
521
|
+
let node = list.next;
|
|
522
|
+
let args = rest;
|
|
523
|
+
let res;
|
|
524
|
+
while (node !== tail) {
|
|
525
|
+
res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
|
|
526
|
+
if (type === HOOK_TYPE.WATERFALL) {
|
|
527
|
+
const params = [res];
|
|
528
|
+
args = params;
|
|
529
|
+
}
|
|
530
|
+
node = node.next;
|
|
531
|
+
}
|
|
532
|
+
return res;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
isExist(hookName) {
|
|
536
|
+
var _a;
|
|
537
|
+
return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const hooks = new TaroHooks({
|
|
541
|
+
getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
|
|
542
|
+
getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
|
|
543
|
+
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
544
|
+
}),
|
|
545
|
+
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
546
|
+
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
547
|
+
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
548
|
+
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
549
|
+
/**
|
|
550
|
+
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
551
|
+
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
552
|
+
*/
|
|
553
|
+
const BUBBLE_EVENTS = new Set([
|
|
554
|
+
'touchstart',
|
|
555
|
+
'touchmove',
|
|
556
|
+
'touchcancel',
|
|
557
|
+
'touchend',
|
|
558
|
+
'touchforcechange',
|
|
559
|
+
'tap',
|
|
560
|
+
'longpress',
|
|
561
|
+
'longtap',
|
|
562
|
+
'transitionend',
|
|
563
|
+
'animationstart',
|
|
564
|
+
'animationiteration',
|
|
565
|
+
'animationend'
|
|
566
|
+
]);
|
|
567
|
+
return BUBBLE_EVENTS.has(eventName);
|
|
568
|
+
}),
|
|
569
|
+
getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
|
|
570
|
+
onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
|
|
571
|
+
batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
|
|
572
|
+
mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
|
|
573
|
+
modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
|
|
574
|
+
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
575
|
+
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
576
|
+
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
577
|
+
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
578
|
+
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
579
|
+
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
580
|
+
modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
581
|
+
modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
|
|
582
|
+
try {
|
|
583
|
+
// 有些小程序的事件对象的某些属性只读
|
|
584
|
+
this.call('modifyMpEvent', e);
|
|
585
|
+
}
|
|
586
|
+
catch (error) {
|
|
587
|
+
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
588
|
+
}
|
|
589
|
+
}),
|
|
590
|
+
modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
591
|
+
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
592
|
+
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
593
|
+
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
594
594
|
});
|
|
595
595
|
|
|
596
|
-
const EMPTY_OBJ = {};
|
|
597
|
-
const EMPTY_ARR = [];
|
|
598
|
-
const noop = (..._) => { };
|
|
599
|
-
/**
|
|
600
|
-
* box creates a boxed value.
|
|
601
|
-
*
|
|
602
|
-
* @typeparam T Value type.
|
|
603
|
-
* @param v Value.
|
|
604
|
-
* @returns Boxed value.
|
|
605
|
-
*/
|
|
606
|
-
const box = (v) => ({ v });
|
|
607
|
-
/**
|
|
608
|
-
* box creates a boxed value.
|
|
609
|
-
*
|
|
610
|
-
* @typeparam T Value type.
|
|
611
|
-
* @param b Boxed value.
|
|
612
|
-
* @returns Value.
|
|
613
|
-
*/
|
|
614
|
-
const unbox = (b) => b.v;
|
|
615
|
-
function toDashed(s) {
|
|
616
|
-
return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
617
|
-
}
|
|
618
|
-
function toCamelCase(s) {
|
|
619
|
-
let camel = '';
|
|
620
|
-
let nextCap = false;
|
|
621
|
-
for (let i = 0; i < s.length; i++) {
|
|
622
|
-
if (s[i] !== '-') {
|
|
623
|
-
camel += nextCap ? s[i].toUpperCase() : s[i];
|
|
624
|
-
nextCap = false;
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
nextCap = true;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
return camel;
|
|
631
|
-
}
|
|
632
|
-
const toKebabCase = function (string) {
|
|
633
|
-
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
634
|
-
};
|
|
635
|
-
function capitalize(s) {
|
|
636
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
637
|
-
}
|
|
638
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
639
|
-
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
640
|
-
/**
|
|
641
|
-
* ensure takes a condition and throw a error if the condition fails,
|
|
642
|
-
* like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
|
|
643
|
-
* @param condition condition.
|
|
644
|
-
* @param msg error message.
|
|
645
|
-
*/
|
|
646
|
-
function ensure(condition, msg) {
|
|
647
|
-
if (!condition) {
|
|
648
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
649
|
-
const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
|
|
650
|
-
throw new Error(msg + reportIssue);
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
throw new Error(msg);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
function warn(condition, msg) {
|
|
658
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
659
|
-
if (condition) {
|
|
660
|
-
console.warn(`[taro warn] ${msg}`);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
function queryToJson(str) {
|
|
665
|
-
const dec = decodeURIComponent;
|
|
666
|
-
const qp = str.split('&');
|
|
667
|
-
const ret = {};
|
|
668
|
-
let name;
|
|
669
|
-
let val;
|
|
670
|
-
for (let i = 0, l = qp.length, item; i < l; ++i) {
|
|
671
|
-
item = qp[i];
|
|
672
|
-
if (item.length) {
|
|
673
|
-
const s = item.indexOf('=');
|
|
674
|
-
if (s < 0) {
|
|
675
|
-
name = dec(item);
|
|
676
|
-
val = '';
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
679
|
-
name = dec(item.slice(0, s));
|
|
680
|
-
val = dec(item.slice(s + 1));
|
|
681
|
-
}
|
|
682
|
-
if (typeof ret[name] === 'string') { // inline'd type check
|
|
683
|
-
ret[name] = [ret[name]];
|
|
684
|
-
}
|
|
685
|
-
if (Array.isArray(ret[name])) {
|
|
686
|
-
ret[name].push(val);
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
ret[name] = val;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
return ret; // Object
|
|
694
|
-
}
|
|
695
|
-
let _uniqueId = 1;
|
|
696
|
-
const _loadTime = (new Date()).getTime().toString();
|
|
697
|
-
function getUniqueKey() {
|
|
698
|
-
return _loadTime + (_uniqueId++);
|
|
699
|
-
}
|
|
700
|
-
const cacheData = {};
|
|
701
|
-
function cacheDataSet(key, val) {
|
|
702
|
-
cacheData[key] = val;
|
|
703
|
-
}
|
|
704
|
-
function cacheDataGet(key, delelteAfterGet) {
|
|
705
|
-
const temp = cacheData[key];
|
|
706
|
-
delelteAfterGet && delete cacheData[key];
|
|
707
|
-
return temp;
|
|
708
|
-
}
|
|
709
|
-
function cacheDataHas(key) {
|
|
710
|
-
return key in cacheData;
|
|
711
|
-
}
|
|
712
|
-
function mergeInternalComponents(components) {
|
|
713
|
-
Object.keys(components).forEach(name => {
|
|
714
|
-
if (name in internalComponents) {
|
|
715
|
-
Object.assign(internalComponents[name], components[name]);
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
internalComponents[name] = components[name];
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
return internalComponents;
|
|
722
|
-
}
|
|
723
|
-
function getComponentsAlias(origin) {
|
|
724
|
-
const mapping = {};
|
|
725
|
-
const viewAttrs = origin.View;
|
|
726
|
-
const extraList = {
|
|
727
|
-
'#text': {},
|
|
728
|
-
StaticView: viewAttrs,
|
|
729
|
-
StaticImage: origin.Image,
|
|
730
|
-
StaticText: origin.Text,
|
|
731
|
-
PureView: viewAttrs,
|
|
732
|
-
CatchView: viewAttrs
|
|
733
|
-
};
|
|
734
|
-
origin = Object.assign(Object.assign({}, origin), extraList);
|
|
735
|
-
Object.keys(origin)
|
|
736
|
-
.sort((a, b) => {
|
|
737
|
-
const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
|
|
738
|
-
if (reg.test(a)) {
|
|
739
|
-
return -1;
|
|
740
|
-
}
|
|
741
|
-
else if (reg.test(b)) {
|
|
742
|
-
return 1;
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
return a >= b ? 1 : -1;
|
|
746
|
-
}
|
|
747
|
-
})
|
|
748
|
-
.forEach((key, num) => {
|
|
749
|
-
const obj = {
|
|
750
|
-
_num: String(num)
|
|
751
|
-
};
|
|
752
|
-
Object.keys(origin[key])
|
|
753
|
-
.filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
|
|
754
|
-
.sort()
|
|
755
|
-
.forEach((attr, index) => {
|
|
756
|
-
obj[toCamelCase(attr)] = 'p' + index;
|
|
757
|
-
});
|
|
758
|
-
mapping[toDashed(key)] = obj;
|
|
759
|
-
});
|
|
760
|
-
return mapping;
|
|
761
|
-
}
|
|
762
|
-
function mergeReconciler(hostConfig, hooksForTest) {
|
|
763
|
-
const obj = hooksForTest || hooks;
|
|
764
|
-
const keys = Object.keys(hostConfig);
|
|
765
|
-
keys.forEach(key => {
|
|
766
|
-
obj.tap(key, hostConfig[key]);
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
function nonsupport(api) {
|
|
770
|
-
return function () {
|
|
771
|
-
console.warn(`小程序暂不支持 ${api}`);
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
function setUniqueKeyToRoute(key, obj) {
|
|
775
|
-
const routerParamsPrivateKey = '__key_';
|
|
776
|
-
const useDataCacheApis = [
|
|
777
|
-
'navigateTo',
|
|
778
|
-
'redirectTo',
|
|
779
|
-
'reLaunch',
|
|
780
|
-
'switchTab'
|
|
781
|
-
];
|
|
782
|
-
if (useDataCacheApis.indexOf(key) > -1) {
|
|
783
|
-
const url = obj.url = obj.url || '';
|
|
784
|
-
const hasMark = url.indexOf('?') > -1;
|
|
785
|
-
const cacheKey = getUniqueKey();
|
|
786
|
-
obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
function indent(str, size) {
|
|
790
|
-
return str.split('\n')
|
|
791
|
-
.map((line, index) => {
|
|
792
|
-
const indent = index === 0 ? '' : Array(size).fill(' ').join('');
|
|
793
|
-
return indent + line;
|
|
794
|
-
})
|
|
795
|
-
.join('\n');
|
|
596
|
+
const EMPTY_OBJ = {};
|
|
597
|
+
const EMPTY_ARR = [];
|
|
598
|
+
const noop = (..._) => { };
|
|
599
|
+
/**
|
|
600
|
+
* box creates a boxed value.
|
|
601
|
+
*
|
|
602
|
+
* @typeparam T Value type.
|
|
603
|
+
* @param v Value.
|
|
604
|
+
* @returns Boxed value.
|
|
605
|
+
*/
|
|
606
|
+
const box = (v) => ({ v });
|
|
607
|
+
/**
|
|
608
|
+
* box creates a boxed value.
|
|
609
|
+
*
|
|
610
|
+
* @typeparam T Value type.
|
|
611
|
+
* @param b Boxed value.
|
|
612
|
+
* @returns Value.
|
|
613
|
+
*/
|
|
614
|
+
const unbox = (b) => b.v;
|
|
615
|
+
function toDashed(s) {
|
|
616
|
+
return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
617
|
+
}
|
|
618
|
+
function toCamelCase(s) {
|
|
619
|
+
let camel = '';
|
|
620
|
+
let nextCap = false;
|
|
621
|
+
for (let i = 0; i < s.length; i++) {
|
|
622
|
+
if (s[i] !== '-') {
|
|
623
|
+
camel += nextCap ? s[i].toUpperCase() : s[i];
|
|
624
|
+
nextCap = false;
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
nextCap = true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return camel;
|
|
631
|
+
}
|
|
632
|
+
const toKebabCase = function (string) {
|
|
633
|
+
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
634
|
+
};
|
|
635
|
+
function capitalize(s) {
|
|
636
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
637
|
+
}
|
|
638
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
639
|
+
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
640
|
+
/**
|
|
641
|
+
* ensure takes a condition and throw a error if the condition fails,
|
|
642
|
+
* like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
|
|
643
|
+
* @param condition condition.
|
|
644
|
+
* @param msg error message.
|
|
645
|
+
*/
|
|
646
|
+
function ensure(condition, msg) {
|
|
647
|
+
if (!condition) {
|
|
648
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
649
|
+
const reportIssue = '\n如有疑问,请提交 issue 至:https://github.com/nervjs/taro/issues';
|
|
650
|
+
throw new Error(msg + reportIssue);
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
throw new Error(msg);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function warn(condition, msg) {
|
|
658
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
659
|
+
if (condition) {
|
|
660
|
+
console.warn(`[taro warn] ${msg}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function queryToJson(str) {
|
|
665
|
+
const dec = decodeURIComponent;
|
|
666
|
+
const qp = str.split('&');
|
|
667
|
+
const ret = {};
|
|
668
|
+
let name;
|
|
669
|
+
let val;
|
|
670
|
+
for (let i = 0, l = qp.length, item; i < l; ++i) {
|
|
671
|
+
item = qp[i];
|
|
672
|
+
if (item.length) {
|
|
673
|
+
const s = item.indexOf('=');
|
|
674
|
+
if (s < 0) {
|
|
675
|
+
name = dec(item);
|
|
676
|
+
val = '';
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
name = dec(item.slice(0, s));
|
|
680
|
+
val = dec(item.slice(s + 1));
|
|
681
|
+
}
|
|
682
|
+
if (typeof ret[name] === 'string') { // inline'd type check
|
|
683
|
+
ret[name] = [ret[name]];
|
|
684
|
+
}
|
|
685
|
+
if (Array.isArray(ret[name])) {
|
|
686
|
+
ret[name].push(val);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
ret[name] = val;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return ret; // Object
|
|
694
|
+
}
|
|
695
|
+
let _uniqueId = 1;
|
|
696
|
+
const _loadTime = (new Date()).getTime().toString();
|
|
697
|
+
function getUniqueKey() {
|
|
698
|
+
return _loadTime + (_uniqueId++);
|
|
699
|
+
}
|
|
700
|
+
const cacheData = {};
|
|
701
|
+
function cacheDataSet(key, val) {
|
|
702
|
+
cacheData[key] = val;
|
|
703
|
+
}
|
|
704
|
+
function cacheDataGet(key, delelteAfterGet) {
|
|
705
|
+
const temp = cacheData[key];
|
|
706
|
+
delelteAfterGet && delete cacheData[key];
|
|
707
|
+
return temp;
|
|
708
|
+
}
|
|
709
|
+
function cacheDataHas(key) {
|
|
710
|
+
return key in cacheData;
|
|
711
|
+
}
|
|
712
|
+
function mergeInternalComponents(components) {
|
|
713
|
+
Object.keys(components).forEach(name => {
|
|
714
|
+
if (name in internalComponents) {
|
|
715
|
+
Object.assign(internalComponents[name], components[name]);
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
internalComponents[name] = components[name];
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
return internalComponents;
|
|
722
|
+
}
|
|
723
|
+
function getComponentsAlias(origin) {
|
|
724
|
+
const mapping = {};
|
|
725
|
+
const viewAttrs = origin.View;
|
|
726
|
+
const extraList = {
|
|
727
|
+
'#text': {},
|
|
728
|
+
StaticView: viewAttrs,
|
|
729
|
+
StaticImage: origin.Image,
|
|
730
|
+
StaticText: origin.Text,
|
|
731
|
+
PureView: viewAttrs,
|
|
732
|
+
CatchView: viewAttrs
|
|
733
|
+
};
|
|
734
|
+
origin = Object.assign(Object.assign({}, origin), extraList);
|
|
735
|
+
Object.keys(origin)
|
|
736
|
+
.sort((a, b) => {
|
|
737
|
+
const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
|
|
738
|
+
if (reg.test(a)) {
|
|
739
|
+
return -1;
|
|
740
|
+
}
|
|
741
|
+
else if (reg.test(b)) {
|
|
742
|
+
return 1;
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
return a >= b ? 1 : -1;
|
|
746
|
+
}
|
|
747
|
+
})
|
|
748
|
+
.forEach((key, num) => {
|
|
749
|
+
const obj = {
|
|
750
|
+
_num: String(num)
|
|
751
|
+
};
|
|
752
|
+
Object.keys(origin[key])
|
|
753
|
+
.filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
|
|
754
|
+
.sort()
|
|
755
|
+
.forEach((attr, index) => {
|
|
756
|
+
obj[toCamelCase(attr)] = 'p' + index;
|
|
757
|
+
});
|
|
758
|
+
mapping[toDashed(key)] = obj;
|
|
759
|
+
});
|
|
760
|
+
return mapping;
|
|
761
|
+
}
|
|
762
|
+
function mergeReconciler(hostConfig, hooksForTest) {
|
|
763
|
+
const obj = hooksForTest || hooks;
|
|
764
|
+
const keys = Object.keys(hostConfig);
|
|
765
|
+
keys.forEach(key => {
|
|
766
|
+
obj.tap(key, hostConfig[key]);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
function nonsupport(api) {
|
|
770
|
+
return function () {
|
|
771
|
+
console.warn(`小程序暂不支持 ${api}`);
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
function setUniqueKeyToRoute(key, obj) {
|
|
775
|
+
const routerParamsPrivateKey = '__key_';
|
|
776
|
+
const useDataCacheApis = [
|
|
777
|
+
'navigateTo',
|
|
778
|
+
'redirectTo',
|
|
779
|
+
'reLaunch',
|
|
780
|
+
'switchTab'
|
|
781
|
+
];
|
|
782
|
+
if (useDataCacheApis.indexOf(key) > -1) {
|
|
783
|
+
const url = obj.url = obj.url || '';
|
|
784
|
+
const hasMark = url.indexOf('?') > -1;
|
|
785
|
+
const cacheKey = getUniqueKey();
|
|
786
|
+
obj.url += (hasMark ? '&' : '?') + `${routerParamsPrivateKey}=${cacheKey}`;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function indent(str, size) {
|
|
790
|
+
return str.split('\n')
|
|
791
|
+
.map((line, index) => {
|
|
792
|
+
const indent = index === 0 ? '' : Array(size).fill(' ').join('');
|
|
793
|
+
return indent + line;
|
|
794
|
+
})
|
|
795
|
+
.join('\n');
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
-
const needPromiseApis = new Set([
|
|
799
|
-
'addPhoneContact',
|
|
800
|
-
'authorize',
|
|
801
|
-
'canvasGetImageData',
|
|
802
|
-
'canvasPutImageData',
|
|
803
|
-
'canvasToTempFilePath',
|
|
804
|
-
'checkSession',
|
|
805
|
-
'chooseAddress',
|
|
806
|
-
'chooseImage',
|
|
807
|
-
'chooseInvoiceTitle',
|
|
808
|
-
'chooseLocation',
|
|
809
|
-
'chooseVideo',
|
|
810
|
-
'clearStorage',
|
|
811
|
-
'closeBLEConnection',
|
|
812
|
-
'closeBluetoothAdapter',
|
|
813
|
-
'closeSocket',
|
|
814
|
-
'compressImage',
|
|
815
|
-
'connectSocket',
|
|
816
|
-
'createBLEConnection',
|
|
817
|
-
'downloadFile',
|
|
818
|
-
'exitMiniProgram',
|
|
819
|
-
'getAvailableAudioSources',
|
|
820
|
-
'getBLEDeviceCharacteristics',
|
|
821
|
-
'getBLEDeviceServices',
|
|
822
|
-
'getBatteryInfo',
|
|
823
|
-
'getBeacons',
|
|
824
|
-
'getBluetoothAdapterState',
|
|
825
|
-
'getBluetoothDevices',
|
|
826
|
-
'getClipboardData',
|
|
827
|
-
'getConnectedBluetoothDevices',
|
|
828
|
-
'getConnectedWifi',
|
|
829
|
-
'getExtConfig',
|
|
830
|
-
'getFileInfo',
|
|
831
|
-
'getImageInfo',
|
|
832
|
-
'getLocation',
|
|
833
|
-
'getNetworkType',
|
|
834
|
-
'getSavedFileInfo',
|
|
835
|
-
'getSavedFileList',
|
|
836
|
-
'getScreenBrightness',
|
|
837
|
-
'getSetting',
|
|
838
|
-
'getStorage',
|
|
839
|
-
'getStorageInfo',
|
|
840
|
-
'getSystemInfo',
|
|
841
|
-
'getUserInfo',
|
|
842
|
-
'getWifiList',
|
|
843
|
-
'hideHomeButton',
|
|
844
|
-
'hideShareMenu',
|
|
845
|
-
'hideTabBar',
|
|
846
|
-
'hideTabBarRedDot',
|
|
847
|
-
'loadFontFace',
|
|
848
|
-
'login',
|
|
849
|
-
'makePhoneCall',
|
|
850
|
-
'navigateBack',
|
|
851
|
-
'navigateBackMiniProgram',
|
|
852
|
-
'navigateTo',
|
|
853
|
-
'navigateToBookshelf',
|
|
854
|
-
'navigateToMiniProgram',
|
|
855
|
-
'notifyBLECharacteristicValueChange',
|
|
856
|
-
'hideKeyboard',
|
|
857
|
-
'hideLoading',
|
|
858
|
-
'hideNavigationBarLoading',
|
|
859
|
-
'hideToast',
|
|
860
|
-
'openBluetoothAdapter',
|
|
861
|
-
'openDocument',
|
|
862
|
-
'openLocation',
|
|
863
|
-
'openSetting',
|
|
864
|
-
'pageScrollTo',
|
|
865
|
-
'previewImage',
|
|
866
|
-
'queryBookshelf',
|
|
867
|
-
'reLaunch',
|
|
868
|
-
'readBLECharacteristicValue',
|
|
869
|
-
'redirectTo',
|
|
870
|
-
'removeSavedFile',
|
|
871
|
-
'removeStorage',
|
|
872
|
-
'removeTabBarBadge',
|
|
873
|
-
'requestSubscribeMessage',
|
|
874
|
-
'saveFile',
|
|
875
|
-
'saveImageToPhotosAlbum',
|
|
876
|
-
'saveVideoToPhotosAlbum',
|
|
877
|
-
'scanCode',
|
|
878
|
-
'sendSocketMessage',
|
|
879
|
-
'setBackgroundColor',
|
|
880
|
-
'setBackgroundTextStyle',
|
|
881
|
-
'setClipboardData',
|
|
882
|
-
'setEnableDebug',
|
|
883
|
-
'setInnerAudioOption',
|
|
884
|
-
'setKeepScreenOn',
|
|
885
|
-
'setNavigationBarColor',
|
|
886
|
-
'setNavigationBarTitle',
|
|
887
|
-
'setScreenBrightness',
|
|
888
|
-
'setStorage',
|
|
889
|
-
'setTabBarBadge',
|
|
890
|
-
'setTabBarItem',
|
|
891
|
-
'setTabBarStyle',
|
|
892
|
-
'showActionSheet',
|
|
893
|
-
'showFavoriteGuide',
|
|
894
|
-
'showLoading',
|
|
895
|
-
'showModal',
|
|
896
|
-
'showShareMenu',
|
|
897
|
-
'showTabBar',
|
|
898
|
-
'showTabBarRedDot',
|
|
899
|
-
'showToast',
|
|
900
|
-
'startBeaconDiscovery',
|
|
901
|
-
'startBluetoothDevicesDiscovery',
|
|
902
|
-
'startDeviceMotionListening',
|
|
903
|
-
'startPullDownRefresh',
|
|
904
|
-
'stopBeaconDiscovery',
|
|
905
|
-
'stopBluetoothDevicesDiscovery',
|
|
906
|
-
'stopCompass',
|
|
907
|
-
'startCompass',
|
|
908
|
-
'startAccelerometer',
|
|
909
|
-
'stopAccelerometer',
|
|
910
|
-
'showNavigationBarLoading',
|
|
911
|
-
'stopDeviceMotionListening',
|
|
912
|
-
'stopPullDownRefresh',
|
|
913
|
-
'switchTab',
|
|
914
|
-
'uploadFile',
|
|
915
|
-
'vibrateLong',
|
|
916
|
-
'vibrateShort',
|
|
917
|
-
'writeBLECharacteristicValue'
|
|
918
|
-
]);
|
|
919
|
-
function getCanIUseWebp(taro) {
|
|
920
|
-
return function () {
|
|
921
|
-
var _a;
|
|
922
|
-
const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
|
|
923
|
-
if (!res) {
|
|
924
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
925
|
-
console.error('不支持 API canIUseWebp');
|
|
926
|
-
}
|
|
927
|
-
return false;
|
|
928
|
-
}
|
|
929
|
-
const { platform } = res;
|
|
930
|
-
const platformLower = platform.toLowerCase();
|
|
931
|
-
if (platformLower === 'android' || platformLower === 'devtools') {
|
|
932
|
-
return true;
|
|
933
|
-
}
|
|
934
|
-
return false;
|
|
935
|
-
};
|
|
936
|
-
}
|
|
937
|
-
function getNormalRequest(global) {
|
|
938
|
-
return function request(options) {
|
|
939
|
-
options = options
|
|
940
|
-
? (isString(options)
|
|
941
|
-
? { url: options }
|
|
942
|
-
: options)
|
|
943
|
-
: {};
|
|
944
|
-
const originSuccess = options.success;
|
|
945
|
-
const originFail = options.fail;
|
|
946
|
-
const originComplete = options.complete;
|
|
947
|
-
let requestTask;
|
|
948
|
-
const p = new Promise((resolve, reject) => {
|
|
949
|
-
options.success = res => {
|
|
950
|
-
originSuccess && originSuccess(res);
|
|
951
|
-
resolve(res);
|
|
952
|
-
};
|
|
953
|
-
options.fail = res => {
|
|
954
|
-
originFail && originFail(res);
|
|
955
|
-
reject(res);
|
|
956
|
-
};
|
|
957
|
-
options.complete = res => {
|
|
958
|
-
originComplete && originComplete(res);
|
|
959
|
-
};
|
|
960
|
-
requestTask = global.request(options);
|
|
961
|
-
});
|
|
962
|
-
equipTaskMethodsIntoPromise(requestTask, p);
|
|
963
|
-
p.abort = (cb) => {
|
|
964
|
-
cb && cb();
|
|
965
|
-
if (requestTask) {
|
|
966
|
-
requestTask.abort();
|
|
967
|
-
}
|
|
968
|
-
return p;
|
|
969
|
-
};
|
|
970
|
-
return p;
|
|
971
|
-
};
|
|
972
|
-
}
|
|
973
|
-
function processApis(taro, global, config = {}) {
|
|
974
|
-
const patchNeedPromiseApis = config.needPromiseApis || [];
|
|
975
|
-
const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
|
|
976
|
-
const preserved = [
|
|
977
|
-
'getEnv',
|
|
978
|
-
'interceptors',
|
|
979
|
-
'Current',
|
|
980
|
-
'getCurrentInstance',
|
|
981
|
-
'options',
|
|
982
|
-
'nextTick',
|
|
983
|
-
'eventCenter',
|
|
984
|
-
'Events',
|
|
985
|
-
'preload',
|
|
986
|
-
'webpackJsonp'
|
|
987
|
-
];
|
|
988
|
-
const apis = new Set(!config.isOnlyPromisify
|
|
989
|
-
? Object.keys(global).filter(api => preserved.indexOf(api) === -1)
|
|
990
|
-
: patchNeedPromiseApis);
|
|
991
|
-
if (config.modifyApis) {
|
|
992
|
-
config.modifyApis(apis);
|
|
993
|
-
}
|
|
994
|
-
apis.forEach(key => {
|
|
995
|
-
if (_needPromiseApis.has(key)) {
|
|
996
|
-
const originKey = key;
|
|
997
|
-
taro[originKey] = (options = {}, ...args) => {
|
|
998
|
-
let key = originKey;
|
|
999
|
-
// 第一个参数 options 为字符串,单独处理
|
|
1000
|
-
if (typeof options === 'string') {
|
|
1001
|
-
if (args.length) {
|
|
1002
|
-
return global[key](options, ...args);
|
|
1003
|
-
}
|
|
1004
|
-
return global[key](options);
|
|
1005
|
-
}
|
|
1006
|
-
// 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
|
|
1007
|
-
if (config.transformMeta) {
|
|
1008
|
-
const transformResult = config.transformMeta(key, options);
|
|
1009
|
-
key = transformResult.key;
|
|
1010
|
-
options = transformResult.options;
|
|
1011
|
-
// 新 key 可能不存在
|
|
1012
|
-
if (!global.hasOwnProperty(key)) {
|
|
1013
|
-
return nonsupport(key)();
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
let task = null;
|
|
1017
|
-
const obj = Object.assign({}, options);
|
|
1018
|
-
// 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
|
|
1019
|
-
setUniqueKeyToRoute(key, options);
|
|
1020
|
-
// Promise 化
|
|
1021
|
-
const p = new Promise((resolve, reject) => {
|
|
1022
|
-
obj.success = res => {
|
|
1023
|
-
var _a, _b;
|
|
1024
|
-
(_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
|
|
1025
|
-
(_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
1026
|
-
if (key === 'connectSocket') {
|
|
1027
|
-
resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
|
|
1028
|
-
}
|
|
1029
|
-
else {
|
|
1030
|
-
resolve(res);
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
obj.fail = res => {
|
|
1034
|
-
var _a;
|
|
1035
|
-
(_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
1036
|
-
reject(res);
|
|
1037
|
-
};
|
|
1038
|
-
obj.complete = res => {
|
|
1039
|
-
var _a;
|
|
1040
|
-
(_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
1041
|
-
};
|
|
1042
|
-
if (args.length) {
|
|
1043
|
-
task = global[key](obj, ...args);
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
task = global[key](obj);
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
// 给 promise 对象挂载属性
|
|
1050
|
-
if (['uploadFile', 'downloadFile'].includes(key)) {
|
|
1051
|
-
equipTaskMethodsIntoPromise(task, p);
|
|
1052
|
-
p.progress = cb => {
|
|
1053
|
-
task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
|
|
1054
|
-
return p;
|
|
1055
|
-
};
|
|
1056
|
-
p.abort = cb => {
|
|
1057
|
-
cb === null || cb === void 0 ? void 0 : cb();
|
|
1058
|
-
task === null || task === void 0 ? void 0 : task.abort();
|
|
1059
|
-
return p;
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
return p;
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
else {
|
|
1066
|
-
let platformKey = key;
|
|
1067
|
-
// 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
|
|
1068
|
-
if (config.transformMeta) {
|
|
1069
|
-
platformKey = config.transformMeta(key, {}).key;
|
|
1070
|
-
}
|
|
1071
|
-
// API 不存在
|
|
1072
|
-
if (!global.hasOwnProperty(platformKey)) {
|
|
1073
|
-
taro[key] = nonsupport(key);
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
if (isFunction(global[key])) {
|
|
1077
|
-
taro[key] = (...args) => {
|
|
1078
|
-
if (config.handleSyncApis) {
|
|
1079
|
-
return config.handleSyncApis(key, global, args);
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
return global[platformKey].apply(global, args);
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
else {
|
|
1087
|
-
taro[key] = global[platformKey];
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
!config.isOnlyPromisify && equipCommonApis(taro, global, config);
|
|
1092
|
-
}
|
|
1093
|
-
/**
|
|
1094
|
-
* 挂载常用 API
|
|
1095
|
-
* @param taro Taro 对象
|
|
1096
|
-
* @param global 小程序全局对象,如微信的 wx,支付宝的 my
|
|
1097
|
-
*/
|
|
1098
|
-
function equipCommonApis(taro, global, apis = {}) {
|
|
1099
|
-
taro.canIUseWebp = getCanIUseWebp(taro);
|
|
1100
|
-
taro.getCurrentPages = getCurrentPages || nonsupport('getCurrentPages');
|
|
1101
|
-
taro.getApp = getApp || nonsupport('getApp');
|
|
1102
|
-
taro.env = global.env || {};
|
|
1103
|
-
try {
|
|
1104
|
-
taro.requirePlugin = requirePlugin || nonsupport('requirePlugin');
|
|
1105
|
-
}
|
|
1106
|
-
catch (error) {
|
|
1107
|
-
taro.requirePlugin = nonsupport('requirePlugin');
|
|
1108
|
-
}
|
|
1109
|
-
// request & interceptors
|
|
1110
|
-
const request = apis.request || getNormalRequest(global);
|
|
1111
|
-
function taroInterceptor(chain) {
|
|
1112
|
-
return request(chain.requestParams);
|
|
1113
|
-
}
|
|
1114
|
-
const link = new taro.Link(taroInterceptor);
|
|
1115
|
-
taro.request = link.request.bind(link);
|
|
1116
|
-
taro.addInterceptor = link.addInterceptor.bind(link);
|
|
1117
|
-
taro.cleanInterceptors = link.cleanInterceptors.bind(link);
|
|
1118
|
-
taro.miniGlobal = taro.options.miniGlobal = global;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* 将Task对象中的方法挂载到promise对象中,适配小程序api原生返回结果
|
|
1122
|
-
* @param task Task对象 {RequestTask | DownloadTask | UploadTask}
|
|
1123
|
-
* @param promise Promise
|
|
1124
|
-
*/
|
|
1125
|
-
function equipTaskMethodsIntoPromise(task, promise) {
|
|
1126
|
-
if (!task || !promise)
|
|
1127
|
-
return;
|
|
1128
|
-
const taskMethods = ['abort', 'onHeadersReceived', 'offHeadersReceived', 'onProgressUpdate', 'offProgressUpdate', 'onChunkReceived', 'offChunkReceived'];
|
|
1129
|
-
task && taskMethods.forEach(method => {
|
|
1130
|
-
if (method in task) {
|
|
1131
|
-
promise[method] = task[method].bind(task);
|
|
1132
|
-
}
|
|
1133
|
-
});
|
|
798
|
+
const needPromiseApis = new Set([
|
|
799
|
+
'addPhoneContact',
|
|
800
|
+
'authorize',
|
|
801
|
+
'canvasGetImageData',
|
|
802
|
+
'canvasPutImageData',
|
|
803
|
+
'canvasToTempFilePath',
|
|
804
|
+
'checkSession',
|
|
805
|
+
'chooseAddress',
|
|
806
|
+
'chooseImage',
|
|
807
|
+
'chooseInvoiceTitle',
|
|
808
|
+
'chooseLocation',
|
|
809
|
+
'chooseVideo',
|
|
810
|
+
'clearStorage',
|
|
811
|
+
'closeBLEConnection',
|
|
812
|
+
'closeBluetoothAdapter',
|
|
813
|
+
'closeSocket',
|
|
814
|
+
'compressImage',
|
|
815
|
+
'connectSocket',
|
|
816
|
+
'createBLEConnection',
|
|
817
|
+
'downloadFile',
|
|
818
|
+
'exitMiniProgram',
|
|
819
|
+
'getAvailableAudioSources',
|
|
820
|
+
'getBLEDeviceCharacteristics',
|
|
821
|
+
'getBLEDeviceServices',
|
|
822
|
+
'getBatteryInfo',
|
|
823
|
+
'getBeacons',
|
|
824
|
+
'getBluetoothAdapterState',
|
|
825
|
+
'getBluetoothDevices',
|
|
826
|
+
'getClipboardData',
|
|
827
|
+
'getConnectedBluetoothDevices',
|
|
828
|
+
'getConnectedWifi',
|
|
829
|
+
'getExtConfig',
|
|
830
|
+
'getFileInfo',
|
|
831
|
+
'getImageInfo',
|
|
832
|
+
'getLocation',
|
|
833
|
+
'getNetworkType',
|
|
834
|
+
'getSavedFileInfo',
|
|
835
|
+
'getSavedFileList',
|
|
836
|
+
'getScreenBrightness',
|
|
837
|
+
'getSetting',
|
|
838
|
+
'getStorage',
|
|
839
|
+
'getStorageInfo',
|
|
840
|
+
'getSystemInfo',
|
|
841
|
+
'getUserInfo',
|
|
842
|
+
'getWifiList',
|
|
843
|
+
'hideHomeButton',
|
|
844
|
+
'hideShareMenu',
|
|
845
|
+
'hideTabBar',
|
|
846
|
+
'hideTabBarRedDot',
|
|
847
|
+
'loadFontFace',
|
|
848
|
+
'login',
|
|
849
|
+
'makePhoneCall',
|
|
850
|
+
'navigateBack',
|
|
851
|
+
'navigateBackMiniProgram',
|
|
852
|
+
'navigateTo',
|
|
853
|
+
'navigateToBookshelf',
|
|
854
|
+
'navigateToMiniProgram',
|
|
855
|
+
'notifyBLECharacteristicValueChange',
|
|
856
|
+
'hideKeyboard',
|
|
857
|
+
'hideLoading',
|
|
858
|
+
'hideNavigationBarLoading',
|
|
859
|
+
'hideToast',
|
|
860
|
+
'openBluetoothAdapter',
|
|
861
|
+
'openDocument',
|
|
862
|
+
'openLocation',
|
|
863
|
+
'openSetting',
|
|
864
|
+
'pageScrollTo',
|
|
865
|
+
'previewImage',
|
|
866
|
+
'queryBookshelf',
|
|
867
|
+
'reLaunch',
|
|
868
|
+
'readBLECharacteristicValue',
|
|
869
|
+
'redirectTo',
|
|
870
|
+
'removeSavedFile',
|
|
871
|
+
'removeStorage',
|
|
872
|
+
'removeTabBarBadge',
|
|
873
|
+
'requestSubscribeMessage',
|
|
874
|
+
'saveFile',
|
|
875
|
+
'saveImageToPhotosAlbum',
|
|
876
|
+
'saveVideoToPhotosAlbum',
|
|
877
|
+
'scanCode',
|
|
878
|
+
'sendSocketMessage',
|
|
879
|
+
'setBackgroundColor',
|
|
880
|
+
'setBackgroundTextStyle',
|
|
881
|
+
'setClipboardData',
|
|
882
|
+
'setEnableDebug',
|
|
883
|
+
'setInnerAudioOption',
|
|
884
|
+
'setKeepScreenOn',
|
|
885
|
+
'setNavigationBarColor',
|
|
886
|
+
'setNavigationBarTitle',
|
|
887
|
+
'setScreenBrightness',
|
|
888
|
+
'setStorage',
|
|
889
|
+
'setTabBarBadge',
|
|
890
|
+
'setTabBarItem',
|
|
891
|
+
'setTabBarStyle',
|
|
892
|
+
'showActionSheet',
|
|
893
|
+
'showFavoriteGuide',
|
|
894
|
+
'showLoading',
|
|
895
|
+
'showModal',
|
|
896
|
+
'showShareMenu',
|
|
897
|
+
'showTabBar',
|
|
898
|
+
'showTabBarRedDot',
|
|
899
|
+
'showToast',
|
|
900
|
+
'startBeaconDiscovery',
|
|
901
|
+
'startBluetoothDevicesDiscovery',
|
|
902
|
+
'startDeviceMotionListening',
|
|
903
|
+
'startPullDownRefresh',
|
|
904
|
+
'stopBeaconDiscovery',
|
|
905
|
+
'stopBluetoothDevicesDiscovery',
|
|
906
|
+
'stopCompass',
|
|
907
|
+
'startCompass',
|
|
908
|
+
'startAccelerometer',
|
|
909
|
+
'stopAccelerometer',
|
|
910
|
+
'showNavigationBarLoading',
|
|
911
|
+
'stopDeviceMotionListening',
|
|
912
|
+
'stopPullDownRefresh',
|
|
913
|
+
'switchTab',
|
|
914
|
+
'uploadFile',
|
|
915
|
+
'vibrateLong',
|
|
916
|
+
'vibrateShort',
|
|
917
|
+
'writeBLECharacteristicValue'
|
|
918
|
+
]);
|
|
919
|
+
function getCanIUseWebp(taro) {
|
|
920
|
+
return function () {
|
|
921
|
+
var _a;
|
|
922
|
+
const res = (_a = taro.getSystemInfoSync) === null || _a === void 0 ? void 0 : _a.call(taro);
|
|
923
|
+
if (!res) {
|
|
924
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
925
|
+
console.error('不支持 API canIUseWebp');
|
|
926
|
+
}
|
|
927
|
+
return false;
|
|
928
|
+
}
|
|
929
|
+
const { platform } = res;
|
|
930
|
+
const platformLower = platform.toLowerCase();
|
|
931
|
+
if (platformLower === 'android' || platformLower === 'devtools') {
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
return false;
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
function getNormalRequest(global) {
|
|
938
|
+
return function request(options) {
|
|
939
|
+
options = options
|
|
940
|
+
? (isString(options)
|
|
941
|
+
? { url: options }
|
|
942
|
+
: options)
|
|
943
|
+
: {};
|
|
944
|
+
const originSuccess = options.success;
|
|
945
|
+
const originFail = options.fail;
|
|
946
|
+
const originComplete = options.complete;
|
|
947
|
+
let requestTask;
|
|
948
|
+
const p = new Promise((resolve, reject) => {
|
|
949
|
+
options.success = res => {
|
|
950
|
+
originSuccess && originSuccess(res);
|
|
951
|
+
resolve(res);
|
|
952
|
+
};
|
|
953
|
+
options.fail = res => {
|
|
954
|
+
originFail && originFail(res);
|
|
955
|
+
reject(res);
|
|
956
|
+
};
|
|
957
|
+
options.complete = res => {
|
|
958
|
+
originComplete && originComplete(res);
|
|
959
|
+
};
|
|
960
|
+
requestTask = global.request(options);
|
|
961
|
+
});
|
|
962
|
+
equipTaskMethodsIntoPromise(requestTask, p);
|
|
963
|
+
p.abort = (cb) => {
|
|
964
|
+
cb && cb();
|
|
965
|
+
if (requestTask) {
|
|
966
|
+
requestTask.abort();
|
|
967
|
+
}
|
|
968
|
+
return p;
|
|
969
|
+
};
|
|
970
|
+
return p;
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function processApis(taro, global, config = {}) {
|
|
974
|
+
const patchNeedPromiseApis = config.needPromiseApis || [];
|
|
975
|
+
const _needPromiseApis = new Set([...patchNeedPromiseApis, ...needPromiseApis]);
|
|
976
|
+
const preserved = [
|
|
977
|
+
'getEnv',
|
|
978
|
+
'interceptors',
|
|
979
|
+
'Current',
|
|
980
|
+
'getCurrentInstance',
|
|
981
|
+
'options',
|
|
982
|
+
'nextTick',
|
|
983
|
+
'eventCenter',
|
|
984
|
+
'Events',
|
|
985
|
+
'preload',
|
|
986
|
+
'webpackJsonp'
|
|
987
|
+
];
|
|
988
|
+
const apis = new Set(!config.isOnlyPromisify
|
|
989
|
+
? Object.keys(global).filter(api => preserved.indexOf(api) === -1)
|
|
990
|
+
: patchNeedPromiseApis);
|
|
991
|
+
if (config.modifyApis) {
|
|
992
|
+
config.modifyApis(apis);
|
|
993
|
+
}
|
|
994
|
+
apis.forEach(key => {
|
|
995
|
+
if (_needPromiseApis.has(key)) {
|
|
996
|
+
const originKey = key;
|
|
997
|
+
taro[originKey] = (options = {}, ...args) => {
|
|
998
|
+
let key = originKey;
|
|
999
|
+
// 第一个参数 options 为字符串,单独处理
|
|
1000
|
+
if (typeof options === 'string') {
|
|
1001
|
+
if (args.length) {
|
|
1002
|
+
return global[key](options, ...args);
|
|
1003
|
+
}
|
|
1004
|
+
return global[key](options);
|
|
1005
|
+
}
|
|
1006
|
+
// 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
|
|
1007
|
+
if (config.transformMeta) {
|
|
1008
|
+
const transformResult = config.transformMeta(key, options);
|
|
1009
|
+
key = transformResult.key;
|
|
1010
|
+
options = transformResult.options;
|
|
1011
|
+
// 新 key 可能不存在
|
|
1012
|
+
if (!global.hasOwnProperty(key)) {
|
|
1013
|
+
return nonsupport(key)();
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
let task = null;
|
|
1017
|
+
const obj = Object.assign({}, options);
|
|
1018
|
+
// 为页面跳转相关的 API 设置一个随机数作为路由参数。为了给 runtime 区分页面。
|
|
1019
|
+
setUniqueKeyToRoute(key, options);
|
|
1020
|
+
// Promise 化
|
|
1021
|
+
const p = new Promise((resolve, reject) => {
|
|
1022
|
+
obj.success = res => {
|
|
1023
|
+
var _a, _b;
|
|
1024
|
+
(_a = config.modifyAsyncResult) === null || _a === void 0 ? void 0 : _a.call(config, key, res);
|
|
1025
|
+
(_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, res);
|
|
1026
|
+
if (key === 'connectSocket') {
|
|
1027
|
+
resolve(Promise.resolve().then(() => task ? Object.assign(task, res) : res));
|
|
1028
|
+
}
|
|
1029
|
+
else {
|
|
1030
|
+
resolve(res);
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
obj.fail = res => {
|
|
1034
|
+
var _a;
|
|
1035
|
+
(_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
1036
|
+
reject(res);
|
|
1037
|
+
};
|
|
1038
|
+
obj.complete = res => {
|
|
1039
|
+
var _a;
|
|
1040
|
+
(_a = options.complete) === null || _a === void 0 ? void 0 : _a.call(options, res);
|
|
1041
|
+
};
|
|
1042
|
+
if (args.length) {
|
|
1043
|
+
task = global[key](obj, ...args);
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
task = global[key](obj);
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
// 给 promise 对象挂载属性
|
|
1050
|
+
if (['uploadFile', 'downloadFile'].includes(key)) {
|
|
1051
|
+
equipTaskMethodsIntoPromise(task, p);
|
|
1052
|
+
p.progress = cb => {
|
|
1053
|
+
task === null || task === void 0 ? void 0 : task.onProgressUpdate(cb);
|
|
1054
|
+
return p;
|
|
1055
|
+
};
|
|
1056
|
+
p.abort = cb => {
|
|
1057
|
+
cb === null || cb === void 0 ? void 0 : cb();
|
|
1058
|
+
task === null || task === void 0 ? void 0 : task.abort();
|
|
1059
|
+
return p;
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
return p;
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
let platformKey = key;
|
|
1067
|
+
// 改变 key 或 option 字段,如需要把支付宝标准的字段对齐微信标准的字段
|
|
1068
|
+
if (config.transformMeta) {
|
|
1069
|
+
platformKey = config.transformMeta(key, {}).key;
|
|
1070
|
+
}
|
|
1071
|
+
// API 不存在
|
|
1072
|
+
if (!global.hasOwnProperty(platformKey)) {
|
|
1073
|
+
taro[key] = nonsupport(key);
|
|
1074
|
+
return;
|
|
1075
|
+
}
|
|
1076
|
+
if (isFunction(global[key])) {
|
|
1077
|
+
taro[key] = (...args) => {
|
|
1078
|
+
if (config.handleSyncApis) {
|
|
1079
|
+
return config.handleSyncApis(key, global, args);
|
|
1080
|
+
}
|
|
1081
|
+
else {
|
|
1082
|
+
return global[platformKey].apply(global, args);
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
else {
|
|
1087
|
+
taro[key] = global[platformKey];
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
!config.isOnlyPromisify && equipCommonApis(taro, global, config);
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* 挂载常用 API
|
|
1095
|
+
* @param taro Taro 对象
|
|
1096
|
+
* @param global 小程序全局对象,如微信的 wx,支付宝的 my
|
|
1097
|
+
*/
|
|
1098
|
+
function equipCommonApis(taro, global, apis = {}) {
|
|
1099
|
+
taro.canIUseWebp = getCanIUseWebp(taro);
|
|
1100
|
+
taro.getCurrentPages = getCurrentPages || nonsupport('getCurrentPages');
|
|
1101
|
+
taro.getApp = getApp || nonsupport('getApp');
|
|
1102
|
+
taro.env = global.env || {};
|
|
1103
|
+
try {
|
|
1104
|
+
taro.requirePlugin = requirePlugin || nonsupport('requirePlugin');
|
|
1105
|
+
}
|
|
1106
|
+
catch (error) {
|
|
1107
|
+
taro.requirePlugin = nonsupport('requirePlugin');
|
|
1108
|
+
}
|
|
1109
|
+
// request & interceptors
|
|
1110
|
+
const request = apis.request || getNormalRequest(global);
|
|
1111
|
+
function taroInterceptor(chain) {
|
|
1112
|
+
return request(chain.requestParams);
|
|
1113
|
+
}
|
|
1114
|
+
const link = new taro.Link(taroInterceptor);
|
|
1115
|
+
taro.request = link.request.bind(link);
|
|
1116
|
+
taro.addInterceptor = link.addInterceptor.bind(link);
|
|
1117
|
+
taro.cleanInterceptors = link.cleanInterceptors.bind(link);
|
|
1118
|
+
taro.miniGlobal = taro.options.miniGlobal = global;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* 将Task对象中的方法挂载到promise对象中,适配小程序api原生返回结果
|
|
1122
|
+
* @param task Task对象 {RequestTask | DownloadTask | UploadTask}
|
|
1123
|
+
* @param promise Promise
|
|
1124
|
+
*/
|
|
1125
|
+
function equipTaskMethodsIntoPromise(task, promise) {
|
|
1126
|
+
if (!task || !promise)
|
|
1127
|
+
return;
|
|
1128
|
+
const taskMethods = ['abort', 'onHeadersReceived', 'offHeadersReceived', 'onProgressUpdate', 'offProgressUpdate', 'onChunkReceived', 'offChunkReceived'];
|
|
1129
|
+
task && taskMethods.forEach(method => {
|
|
1130
|
+
if (method in task) {
|
|
1131
|
+
promise[method] = task[method].bind(task);
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
1134
|
}
|
|
1135
1135
|
|
|
1136
1136
|
export { EMPTY_ARR, EMPTY_OBJ, Events, HOOK_TYPE, TaroHook, TaroHooks, animation, box, cacheDataGet, cacheDataHas, cacheDataSet, capitalize, controlledComponent, ensure, focusComponents, getComponentsAlias, getUniqueKey, hasOwn, hooks, indent, internalComponents, isArray, isBoolean, isBooleanStringLiteral, isFunction, isNull, isNumber, isObject, isString, isUndefined, mergeInternalComponents, mergeReconciler, nestElements, nonsupport, noop, processApis, queryToJson, setUniqueKeyToRoute, singleQuote, toCamelCase, toDashed, toKebabCase, touchEvents, unbox, voidElements, warn };
|