@tarojs/shared 3.5.0-beta.4 → 3.5.0-beta.7
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/template.js
CHANGED
|
@@ -2,916 +2,916 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
6
|
-
const NO_DEFAULT_VALUE = '';
|
|
7
|
-
const DEFAULT_TRUE = '!0';
|
|
8
|
-
const DEFAULT_FALSE = '!1';
|
|
9
|
-
const touchEvents = {
|
|
10
|
-
bindTouchStart: NO_DEFAULT_VALUE,
|
|
11
|
-
bindTouchMove: NO_DEFAULT_VALUE,
|
|
12
|
-
bindTouchEnd: NO_DEFAULT_VALUE,
|
|
13
|
-
bindTouchCancel: NO_DEFAULT_VALUE,
|
|
14
|
-
bindLongTap: NO_DEFAULT_VALUE
|
|
15
|
-
};
|
|
16
|
-
const animation = {
|
|
17
|
-
animation: NO_DEFAULT_VALUE,
|
|
18
|
-
bindAnimationStart: NO_DEFAULT_VALUE,
|
|
19
|
-
bindAnimationIteration: NO_DEFAULT_VALUE,
|
|
20
|
-
bindAnimationEnd: NO_DEFAULT_VALUE,
|
|
21
|
-
bindTransitionEnd: NO_DEFAULT_VALUE
|
|
22
|
-
};
|
|
23
|
-
function singleQuote(s) {
|
|
24
|
-
return `'${s}'`;
|
|
25
|
-
}
|
|
26
|
-
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);
|
|
27
|
-
const Icon = {
|
|
28
|
-
type: NO_DEFAULT_VALUE,
|
|
29
|
-
size: '23',
|
|
30
|
-
color: NO_DEFAULT_VALUE
|
|
31
|
-
};
|
|
32
|
-
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);
|
|
33
|
-
const Progress = {
|
|
34
|
-
percent: NO_DEFAULT_VALUE,
|
|
35
|
-
'stroke-width': '6',
|
|
36
|
-
color: singleQuote('#09BB07'),
|
|
37
|
-
activeColor: singleQuote('#09BB07'),
|
|
38
|
-
backgroundColor: singleQuote('#EBEBEB'),
|
|
39
|
-
active: DEFAULT_FALSE,
|
|
40
|
-
'active-mode': singleQuote('backwards'),
|
|
41
|
-
'show-info': DEFAULT_FALSE
|
|
42
|
-
};
|
|
43
|
-
const RichText = {
|
|
44
|
-
nodes: DEFAULT_EMPTY_ARRAY
|
|
45
|
-
};
|
|
46
|
-
const Text = {
|
|
47
|
-
selectable: DEFAULT_FALSE,
|
|
48
|
-
space: NO_DEFAULT_VALUE,
|
|
49
|
-
decode: DEFAULT_FALSE
|
|
50
|
-
};
|
|
51
|
-
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);
|
|
52
|
-
const Checkbox = {
|
|
53
|
-
value: NO_DEFAULT_VALUE,
|
|
54
|
-
disabled: NO_DEFAULT_VALUE,
|
|
55
|
-
checked: DEFAULT_FALSE,
|
|
56
|
-
color: singleQuote('#09BB07'),
|
|
57
|
-
name: NO_DEFAULT_VALUE
|
|
58
|
-
};
|
|
59
|
-
const CheckboxGroup = {
|
|
60
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
61
|
-
name: NO_DEFAULT_VALUE
|
|
62
|
-
};
|
|
63
|
-
const Form = {
|
|
64
|
-
'report-submit': DEFAULT_FALSE,
|
|
65
|
-
bindSubmit: NO_DEFAULT_VALUE,
|
|
66
|
-
bindReset: NO_DEFAULT_VALUE,
|
|
67
|
-
name: NO_DEFAULT_VALUE
|
|
68
|
-
};
|
|
69
|
-
const Input = {
|
|
70
|
-
value: NO_DEFAULT_VALUE,
|
|
71
|
-
type: singleQuote(NO_DEFAULT_VALUE),
|
|
72
|
-
password: DEFAULT_FALSE,
|
|
73
|
-
placeholder: NO_DEFAULT_VALUE,
|
|
74
|
-
'placeholder-style': NO_DEFAULT_VALUE,
|
|
75
|
-
'placeholder-class': singleQuote('input-placeholder'),
|
|
76
|
-
disabled: NO_DEFAULT_VALUE,
|
|
77
|
-
maxlength: '140',
|
|
78
|
-
'cursor-spacing': '0',
|
|
79
|
-
focus: DEFAULT_FALSE,
|
|
80
|
-
'confirm-type': singleQuote('done'),
|
|
81
|
-
'confirm-hold': DEFAULT_FALSE,
|
|
82
|
-
cursor: 'i.value.length',
|
|
83
|
-
'selection-start': '-1',
|
|
84
|
-
'selection-end': '-1',
|
|
85
|
-
bindInput: NO_DEFAULT_VALUE,
|
|
86
|
-
bindFocus: NO_DEFAULT_VALUE,
|
|
87
|
-
bindBlur: NO_DEFAULT_VALUE,
|
|
88
|
-
bindConfirm: NO_DEFAULT_VALUE,
|
|
89
|
-
name: NO_DEFAULT_VALUE
|
|
90
|
-
};
|
|
91
|
-
const Label = {
|
|
92
|
-
for: NO_DEFAULT_VALUE,
|
|
93
|
-
name: NO_DEFAULT_VALUE
|
|
94
|
-
};
|
|
95
|
-
const Picker = {
|
|
96
|
-
mode: singleQuote('selector'),
|
|
97
|
-
disabled: NO_DEFAULT_VALUE,
|
|
98
|
-
range: NO_DEFAULT_VALUE,
|
|
99
|
-
'range-key': NO_DEFAULT_VALUE,
|
|
100
|
-
value: NO_DEFAULT_VALUE,
|
|
101
|
-
start: NO_DEFAULT_VALUE,
|
|
102
|
-
end: NO_DEFAULT_VALUE,
|
|
103
|
-
fields: singleQuote('day'),
|
|
104
|
-
'custom-item': NO_DEFAULT_VALUE,
|
|
105
|
-
name: NO_DEFAULT_VALUE,
|
|
106
|
-
bindCancel: NO_DEFAULT_VALUE,
|
|
107
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
108
|
-
bindColumnChange: NO_DEFAULT_VALUE
|
|
109
|
-
};
|
|
110
|
-
const PickerView = {
|
|
111
|
-
value: NO_DEFAULT_VALUE,
|
|
112
|
-
'indicator-style': NO_DEFAULT_VALUE,
|
|
113
|
-
'indicator-class': NO_DEFAULT_VALUE,
|
|
114
|
-
'mask-style': NO_DEFAULT_VALUE,
|
|
115
|
-
'mask-class': NO_DEFAULT_VALUE,
|
|
116
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
117
|
-
name: NO_DEFAULT_VALUE
|
|
118
|
-
};
|
|
119
|
-
const PickerViewColumn = {
|
|
120
|
-
name: NO_DEFAULT_VALUE
|
|
121
|
-
};
|
|
122
|
-
const Radio = {
|
|
123
|
-
value: NO_DEFAULT_VALUE,
|
|
124
|
-
checked: DEFAULT_FALSE,
|
|
125
|
-
disabled: NO_DEFAULT_VALUE,
|
|
126
|
-
color: singleQuote('#09BB07'),
|
|
127
|
-
name: NO_DEFAULT_VALUE
|
|
128
|
-
};
|
|
129
|
-
const RadioGroup = {
|
|
130
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
131
|
-
name: NO_DEFAULT_VALUE
|
|
132
|
-
};
|
|
133
|
-
const Slider = {
|
|
134
|
-
min: '0',
|
|
135
|
-
max: '100',
|
|
136
|
-
step: '1',
|
|
137
|
-
disabled: NO_DEFAULT_VALUE,
|
|
138
|
-
value: '0',
|
|
139
|
-
activeColor: singleQuote('#1aad19'),
|
|
140
|
-
backgroundColor: singleQuote('#e9e9e9'),
|
|
141
|
-
'block-size': '28',
|
|
142
|
-
'block-color': singleQuote('#ffffff'),
|
|
143
|
-
'show-value': DEFAULT_FALSE,
|
|
144
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
145
|
-
bindChanging: NO_DEFAULT_VALUE,
|
|
146
|
-
name: NO_DEFAULT_VALUE
|
|
147
|
-
};
|
|
148
|
-
const Switch = {
|
|
149
|
-
checked: DEFAULT_FALSE,
|
|
150
|
-
disabled: NO_DEFAULT_VALUE,
|
|
151
|
-
type: singleQuote('switch'),
|
|
152
|
-
color: singleQuote('#04BE02'),
|
|
153
|
-
bindChange: NO_DEFAULT_VALUE,
|
|
154
|
-
name: NO_DEFAULT_VALUE
|
|
155
|
-
};
|
|
156
|
-
const Textarea = {
|
|
157
|
-
value: NO_DEFAULT_VALUE,
|
|
158
|
-
placeholder: NO_DEFAULT_VALUE,
|
|
159
|
-
'placeholder-style': NO_DEFAULT_VALUE,
|
|
160
|
-
'placeholder-class': singleQuote('textarea-placeholder'),
|
|
161
|
-
disabled: NO_DEFAULT_VALUE,
|
|
162
|
-
maxlength: '140',
|
|
163
|
-
'auto-focus': DEFAULT_FALSE,
|
|
164
|
-
focus: DEFAULT_FALSE,
|
|
165
|
-
'auto-height': DEFAULT_FALSE,
|
|
166
|
-
fixed: DEFAULT_FALSE,
|
|
167
|
-
'cursor-spacing': '0',
|
|
168
|
-
cursor: '-1',
|
|
169
|
-
'selection-start': '-1',
|
|
170
|
-
'selection-end': '-1',
|
|
171
|
-
bindFocus: NO_DEFAULT_VALUE,
|
|
172
|
-
bindBlur: NO_DEFAULT_VALUE,
|
|
173
|
-
bindLineChange: NO_DEFAULT_VALUE,
|
|
174
|
-
bindInput: NO_DEFAULT_VALUE,
|
|
175
|
-
bindConfirm: NO_DEFAULT_VALUE,
|
|
176
|
-
name: NO_DEFAULT_VALUE
|
|
177
|
-
};
|
|
178
|
-
const CoverImage = {
|
|
179
|
-
src: NO_DEFAULT_VALUE,
|
|
180
|
-
bindLoad: 'eh',
|
|
181
|
-
bindError: 'eh'
|
|
182
|
-
};
|
|
183
|
-
const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
|
|
184
|
-
const MovableArea = {
|
|
185
|
-
'scale-area': DEFAULT_FALSE
|
|
186
|
-
};
|
|
187
|
-
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);
|
|
188
|
-
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);
|
|
189
|
-
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);
|
|
190
|
-
const SwiperItem = {
|
|
191
|
-
'item-id': NO_DEFAULT_VALUE
|
|
192
|
-
};
|
|
193
|
-
const Navigator = {
|
|
194
|
-
url: NO_DEFAULT_VALUE,
|
|
195
|
-
'open-type': singleQuote('navigate'),
|
|
196
|
-
delta: '1',
|
|
197
|
-
'hover-class': singleQuote('navigator-hover'),
|
|
198
|
-
'hover-stop-propagation': DEFAULT_FALSE,
|
|
199
|
-
'hover-start-time': '50',
|
|
200
|
-
'hover-stay-time': '600',
|
|
201
|
-
bindSuccess: NO_DEFAULT_VALUE,
|
|
202
|
-
bindFail: NO_DEFAULT_VALUE,
|
|
203
|
-
bindComplete: NO_DEFAULT_VALUE
|
|
204
|
-
};
|
|
205
|
-
const Audio = {
|
|
206
|
-
id: NO_DEFAULT_VALUE,
|
|
207
|
-
src: NO_DEFAULT_VALUE,
|
|
208
|
-
loop: DEFAULT_FALSE,
|
|
209
|
-
controls: DEFAULT_FALSE,
|
|
210
|
-
poster: NO_DEFAULT_VALUE,
|
|
211
|
-
name: NO_DEFAULT_VALUE,
|
|
212
|
-
author: NO_DEFAULT_VALUE,
|
|
213
|
-
bindError: NO_DEFAULT_VALUE,
|
|
214
|
-
bindPlay: NO_DEFAULT_VALUE,
|
|
215
|
-
bindPause: NO_DEFAULT_VALUE,
|
|
216
|
-
bindTimeUpdate: NO_DEFAULT_VALUE,
|
|
217
|
-
bindEnded: NO_DEFAULT_VALUE
|
|
218
|
-
};
|
|
219
|
-
const Camera = {
|
|
220
|
-
'device-position': singleQuote('back'),
|
|
221
|
-
flash: singleQuote('auto'),
|
|
222
|
-
bindStop: NO_DEFAULT_VALUE,
|
|
223
|
-
bindError: NO_DEFAULT_VALUE
|
|
224
|
-
};
|
|
225
|
-
const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
|
|
226
|
-
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);
|
|
227
|
-
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);
|
|
228
|
-
const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
|
|
229
|
-
const Ad = {
|
|
230
|
-
'unit-id': NO_DEFAULT_VALUE,
|
|
231
|
-
'ad-intervals': NO_DEFAULT_VALUE,
|
|
232
|
-
bindLoad: NO_DEFAULT_VALUE,
|
|
233
|
-
bindError: NO_DEFAULT_VALUE,
|
|
234
|
-
bindClose: NO_DEFAULT_VALUE
|
|
235
|
-
};
|
|
236
|
-
const WebView = {
|
|
237
|
-
src: NO_DEFAULT_VALUE,
|
|
238
|
-
bindMessage: NO_DEFAULT_VALUE,
|
|
239
|
-
bindLoad: NO_DEFAULT_VALUE,
|
|
240
|
-
bindError: NO_DEFAULT_VALUE
|
|
241
|
-
};
|
|
242
|
-
const Block = {};
|
|
243
|
-
// For Vue,因为 slot 标签被 vue 占用了
|
|
244
|
-
const SlotView = {
|
|
245
|
-
name: NO_DEFAULT_VALUE
|
|
246
|
-
};
|
|
247
|
-
// For React
|
|
248
|
-
// Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
|
|
249
|
-
// 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
|
|
250
|
-
// 不给 View 直接加 slot 属性的原因是性能损耗
|
|
251
|
-
const Slot = {
|
|
252
|
-
name: NO_DEFAULT_VALUE
|
|
253
|
-
};
|
|
254
|
-
const internalComponents = {
|
|
255
|
-
View,
|
|
256
|
-
Icon,
|
|
257
|
-
Progress,
|
|
258
|
-
RichText,
|
|
259
|
-
Text,
|
|
260
|
-
Button,
|
|
261
|
-
Checkbox,
|
|
262
|
-
CheckboxGroup,
|
|
263
|
-
Form,
|
|
264
|
-
Input,
|
|
265
|
-
Label,
|
|
266
|
-
Picker,
|
|
267
|
-
PickerView,
|
|
268
|
-
PickerViewColumn,
|
|
269
|
-
Radio,
|
|
270
|
-
RadioGroup,
|
|
271
|
-
Slider,
|
|
272
|
-
Switch,
|
|
273
|
-
CoverImage,
|
|
274
|
-
Textarea,
|
|
275
|
-
CoverView,
|
|
276
|
-
MovableArea,
|
|
277
|
-
MovableView,
|
|
278
|
-
ScrollView,
|
|
279
|
-
Swiper,
|
|
280
|
-
SwiperItem,
|
|
281
|
-
Navigator,
|
|
282
|
-
Audio,
|
|
283
|
-
Camera,
|
|
284
|
-
Image,
|
|
285
|
-
LivePlayer,
|
|
286
|
-
Video,
|
|
287
|
-
Canvas,
|
|
288
|
-
Ad,
|
|
289
|
-
WebView,
|
|
290
|
-
Block,
|
|
291
|
-
Map: MapComp,
|
|
292
|
-
Slot,
|
|
293
|
-
SlotView
|
|
294
|
-
};
|
|
295
|
-
const focusComponents = new Set([
|
|
296
|
-
'input',
|
|
297
|
-
'textarea'
|
|
298
|
-
]);
|
|
299
|
-
const voidElements = new Set([
|
|
300
|
-
'progress',
|
|
301
|
-
'icon',
|
|
302
|
-
'rich-text',
|
|
303
|
-
'input',
|
|
304
|
-
'textarea',
|
|
305
|
-
'slider',
|
|
306
|
-
'switch',
|
|
307
|
-
'audio',
|
|
308
|
-
'ad',
|
|
309
|
-
'official-account',
|
|
310
|
-
'open-data',
|
|
311
|
-
'navigation-bar'
|
|
312
|
-
]);
|
|
313
|
-
const nestElements = new Map([
|
|
314
|
-
['view', -1],
|
|
315
|
-
['catch-view', -1],
|
|
316
|
-
['cover-view', -1],
|
|
317
|
-
['static-view', -1],
|
|
318
|
-
['pure-view', -1],
|
|
319
|
-
['block', -1],
|
|
320
|
-
['text', -1],
|
|
321
|
-
['static-text', 6],
|
|
322
|
-
['slot', 8],
|
|
323
|
-
['slot-view', 8],
|
|
324
|
-
['label', 6],
|
|
325
|
-
['form', 4],
|
|
326
|
-
['scroll-view', 4],
|
|
327
|
-
['swiper', 4],
|
|
328
|
-
['swiper-item', 4]
|
|
5
|
+
const DEFAULT_EMPTY_ARRAY = '[]';
|
|
6
|
+
const NO_DEFAULT_VALUE = '';
|
|
7
|
+
const DEFAULT_TRUE = '!0';
|
|
8
|
+
const DEFAULT_FALSE = '!1';
|
|
9
|
+
const touchEvents = {
|
|
10
|
+
bindTouchStart: NO_DEFAULT_VALUE,
|
|
11
|
+
bindTouchMove: NO_DEFAULT_VALUE,
|
|
12
|
+
bindTouchEnd: NO_DEFAULT_VALUE,
|
|
13
|
+
bindTouchCancel: NO_DEFAULT_VALUE,
|
|
14
|
+
bindLongTap: NO_DEFAULT_VALUE
|
|
15
|
+
};
|
|
16
|
+
const animation = {
|
|
17
|
+
animation: NO_DEFAULT_VALUE,
|
|
18
|
+
bindAnimationStart: NO_DEFAULT_VALUE,
|
|
19
|
+
bindAnimationIteration: NO_DEFAULT_VALUE,
|
|
20
|
+
bindAnimationEnd: NO_DEFAULT_VALUE,
|
|
21
|
+
bindTransitionEnd: NO_DEFAULT_VALUE
|
|
22
|
+
};
|
|
23
|
+
function singleQuote(s) {
|
|
24
|
+
return `'${s}'`;
|
|
25
|
+
}
|
|
26
|
+
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);
|
|
27
|
+
const Icon = {
|
|
28
|
+
type: NO_DEFAULT_VALUE,
|
|
29
|
+
size: '23',
|
|
30
|
+
color: NO_DEFAULT_VALUE
|
|
31
|
+
};
|
|
32
|
+
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);
|
|
33
|
+
const Progress = {
|
|
34
|
+
percent: NO_DEFAULT_VALUE,
|
|
35
|
+
'stroke-width': '6',
|
|
36
|
+
color: singleQuote('#09BB07'),
|
|
37
|
+
activeColor: singleQuote('#09BB07'),
|
|
38
|
+
backgroundColor: singleQuote('#EBEBEB'),
|
|
39
|
+
active: DEFAULT_FALSE,
|
|
40
|
+
'active-mode': singleQuote('backwards'),
|
|
41
|
+
'show-info': DEFAULT_FALSE
|
|
42
|
+
};
|
|
43
|
+
const RichText = {
|
|
44
|
+
nodes: DEFAULT_EMPTY_ARRAY
|
|
45
|
+
};
|
|
46
|
+
const Text = {
|
|
47
|
+
selectable: DEFAULT_FALSE,
|
|
48
|
+
space: NO_DEFAULT_VALUE,
|
|
49
|
+
decode: DEFAULT_FALSE
|
|
50
|
+
};
|
|
51
|
+
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);
|
|
52
|
+
const Checkbox = {
|
|
53
|
+
value: NO_DEFAULT_VALUE,
|
|
54
|
+
disabled: NO_DEFAULT_VALUE,
|
|
55
|
+
checked: DEFAULT_FALSE,
|
|
56
|
+
color: singleQuote('#09BB07'),
|
|
57
|
+
name: NO_DEFAULT_VALUE
|
|
58
|
+
};
|
|
59
|
+
const CheckboxGroup = {
|
|
60
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
61
|
+
name: NO_DEFAULT_VALUE
|
|
62
|
+
};
|
|
63
|
+
const Form = {
|
|
64
|
+
'report-submit': DEFAULT_FALSE,
|
|
65
|
+
bindSubmit: NO_DEFAULT_VALUE,
|
|
66
|
+
bindReset: NO_DEFAULT_VALUE,
|
|
67
|
+
name: NO_DEFAULT_VALUE
|
|
68
|
+
};
|
|
69
|
+
const Input = {
|
|
70
|
+
value: NO_DEFAULT_VALUE,
|
|
71
|
+
type: singleQuote(NO_DEFAULT_VALUE),
|
|
72
|
+
password: DEFAULT_FALSE,
|
|
73
|
+
placeholder: NO_DEFAULT_VALUE,
|
|
74
|
+
'placeholder-style': NO_DEFAULT_VALUE,
|
|
75
|
+
'placeholder-class': singleQuote('input-placeholder'),
|
|
76
|
+
disabled: NO_DEFAULT_VALUE,
|
|
77
|
+
maxlength: '140',
|
|
78
|
+
'cursor-spacing': '0',
|
|
79
|
+
focus: DEFAULT_FALSE,
|
|
80
|
+
'confirm-type': singleQuote('done'),
|
|
81
|
+
'confirm-hold': DEFAULT_FALSE,
|
|
82
|
+
cursor: 'i.value.length',
|
|
83
|
+
'selection-start': '-1',
|
|
84
|
+
'selection-end': '-1',
|
|
85
|
+
bindInput: NO_DEFAULT_VALUE,
|
|
86
|
+
bindFocus: NO_DEFAULT_VALUE,
|
|
87
|
+
bindBlur: NO_DEFAULT_VALUE,
|
|
88
|
+
bindConfirm: NO_DEFAULT_VALUE,
|
|
89
|
+
name: NO_DEFAULT_VALUE
|
|
90
|
+
};
|
|
91
|
+
const Label = {
|
|
92
|
+
for: NO_DEFAULT_VALUE,
|
|
93
|
+
name: NO_DEFAULT_VALUE
|
|
94
|
+
};
|
|
95
|
+
const Picker = {
|
|
96
|
+
mode: singleQuote('selector'),
|
|
97
|
+
disabled: NO_DEFAULT_VALUE,
|
|
98
|
+
range: NO_DEFAULT_VALUE,
|
|
99
|
+
'range-key': NO_DEFAULT_VALUE,
|
|
100
|
+
value: NO_DEFAULT_VALUE,
|
|
101
|
+
start: NO_DEFAULT_VALUE,
|
|
102
|
+
end: NO_DEFAULT_VALUE,
|
|
103
|
+
fields: singleQuote('day'),
|
|
104
|
+
'custom-item': NO_DEFAULT_VALUE,
|
|
105
|
+
name: NO_DEFAULT_VALUE,
|
|
106
|
+
bindCancel: NO_DEFAULT_VALUE,
|
|
107
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
108
|
+
bindColumnChange: NO_DEFAULT_VALUE
|
|
109
|
+
};
|
|
110
|
+
const PickerView = {
|
|
111
|
+
value: NO_DEFAULT_VALUE,
|
|
112
|
+
'indicator-style': NO_DEFAULT_VALUE,
|
|
113
|
+
'indicator-class': NO_DEFAULT_VALUE,
|
|
114
|
+
'mask-style': NO_DEFAULT_VALUE,
|
|
115
|
+
'mask-class': NO_DEFAULT_VALUE,
|
|
116
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
117
|
+
name: NO_DEFAULT_VALUE
|
|
118
|
+
};
|
|
119
|
+
const PickerViewColumn = {
|
|
120
|
+
name: NO_DEFAULT_VALUE
|
|
121
|
+
};
|
|
122
|
+
const Radio = {
|
|
123
|
+
value: NO_DEFAULT_VALUE,
|
|
124
|
+
checked: DEFAULT_FALSE,
|
|
125
|
+
disabled: NO_DEFAULT_VALUE,
|
|
126
|
+
color: singleQuote('#09BB07'),
|
|
127
|
+
name: NO_DEFAULT_VALUE
|
|
128
|
+
};
|
|
129
|
+
const RadioGroup = {
|
|
130
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
131
|
+
name: NO_DEFAULT_VALUE
|
|
132
|
+
};
|
|
133
|
+
const Slider = {
|
|
134
|
+
min: '0',
|
|
135
|
+
max: '100',
|
|
136
|
+
step: '1',
|
|
137
|
+
disabled: NO_DEFAULT_VALUE,
|
|
138
|
+
value: '0',
|
|
139
|
+
activeColor: singleQuote('#1aad19'),
|
|
140
|
+
backgroundColor: singleQuote('#e9e9e9'),
|
|
141
|
+
'block-size': '28',
|
|
142
|
+
'block-color': singleQuote('#ffffff'),
|
|
143
|
+
'show-value': DEFAULT_FALSE,
|
|
144
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
145
|
+
bindChanging: NO_DEFAULT_VALUE,
|
|
146
|
+
name: NO_DEFAULT_VALUE
|
|
147
|
+
};
|
|
148
|
+
const Switch = {
|
|
149
|
+
checked: DEFAULT_FALSE,
|
|
150
|
+
disabled: NO_DEFAULT_VALUE,
|
|
151
|
+
type: singleQuote('switch'),
|
|
152
|
+
color: singleQuote('#04BE02'),
|
|
153
|
+
bindChange: NO_DEFAULT_VALUE,
|
|
154
|
+
name: NO_DEFAULT_VALUE
|
|
155
|
+
};
|
|
156
|
+
const Textarea = {
|
|
157
|
+
value: NO_DEFAULT_VALUE,
|
|
158
|
+
placeholder: NO_DEFAULT_VALUE,
|
|
159
|
+
'placeholder-style': NO_DEFAULT_VALUE,
|
|
160
|
+
'placeholder-class': singleQuote('textarea-placeholder'),
|
|
161
|
+
disabled: NO_DEFAULT_VALUE,
|
|
162
|
+
maxlength: '140',
|
|
163
|
+
'auto-focus': DEFAULT_FALSE,
|
|
164
|
+
focus: DEFAULT_FALSE,
|
|
165
|
+
'auto-height': DEFAULT_FALSE,
|
|
166
|
+
fixed: DEFAULT_FALSE,
|
|
167
|
+
'cursor-spacing': '0',
|
|
168
|
+
cursor: '-1',
|
|
169
|
+
'selection-start': '-1',
|
|
170
|
+
'selection-end': '-1',
|
|
171
|
+
bindFocus: NO_DEFAULT_VALUE,
|
|
172
|
+
bindBlur: NO_DEFAULT_VALUE,
|
|
173
|
+
bindLineChange: NO_DEFAULT_VALUE,
|
|
174
|
+
bindInput: NO_DEFAULT_VALUE,
|
|
175
|
+
bindConfirm: NO_DEFAULT_VALUE,
|
|
176
|
+
name: NO_DEFAULT_VALUE
|
|
177
|
+
};
|
|
178
|
+
const CoverImage = {
|
|
179
|
+
src: NO_DEFAULT_VALUE,
|
|
180
|
+
bindLoad: 'eh',
|
|
181
|
+
bindError: 'eh'
|
|
182
|
+
};
|
|
183
|
+
const CoverView = Object.assign({ 'scroll-top': DEFAULT_FALSE }, touchEvents);
|
|
184
|
+
const MovableArea = {
|
|
185
|
+
'scale-area': DEFAULT_FALSE
|
|
186
|
+
};
|
|
187
|
+
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);
|
|
188
|
+
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);
|
|
189
|
+
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);
|
|
190
|
+
const SwiperItem = {
|
|
191
|
+
'item-id': NO_DEFAULT_VALUE
|
|
192
|
+
};
|
|
193
|
+
const Navigator = {
|
|
194
|
+
url: NO_DEFAULT_VALUE,
|
|
195
|
+
'open-type': singleQuote('navigate'),
|
|
196
|
+
delta: '1',
|
|
197
|
+
'hover-class': singleQuote('navigator-hover'),
|
|
198
|
+
'hover-stop-propagation': DEFAULT_FALSE,
|
|
199
|
+
'hover-start-time': '50',
|
|
200
|
+
'hover-stay-time': '600',
|
|
201
|
+
bindSuccess: NO_DEFAULT_VALUE,
|
|
202
|
+
bindFail: NO_DEFAULT_VALUE,
|
|
203
|
+
bindComplete: NO_DEFAULT_VALUE
|
|
204
|
+
};
|
|
205
|
+
const Audio = {
|
|
206
|
+
id: NO_DEFAULT_VALUE,
|
|
207
|
+
src: NO_DEFAULT_VALUE,
|
|
208
|
+
loop: DEFAULT_FALSE,
|
|
209
|
+
controls: DEFAULT_FALSE,
|
|
210
|
+
poster: NO_DEFAULT_VALUE,
|
|
211
|
+
name: NO_DEFAULT_VALUE,
|
|
212
|
+
author: NO_DEFAULT_VALUE,
|
|
213
|
+
bindError: NO_DEFAULT_VALUE,
|
|
214
|
+
bindPlay: NO_DEFAULT_VALUE,
|
|
215
|
+
bindPause: NO_DEFAULT_VALUE,
|
|
216
|
+
bindTimeUpdate: NO_DEFAULT_VALUE,
|
|
217
|
+
bindEnded: NO_DEFAULT_VALUE
|
|
218
|
+
};
|
|
219
|
+
const Camera = {
|
|
220
|
+
'device-position': singleQuote('back'),
|
|
221
|
+
flash: singleQuote('auto'),
|
|
222
|
+
bindStop: NO_DEFAULT_VALUE,
|
|
223
|
+
bindError: NO_DEFAULT_VALUE
|
|
224
|
+
};
|
|
225
|
+
const Image = Object.assign({ src: NO_DEFAULT_VALUE, mode: singleQuote('scaleToFill'), 'lazy-load': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE, bindLoad: NO_DEFAULT_VALUE }, touchEvents);
|
|
226
|
+
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);
|
|
227
|
+
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);
|
|
228
|
+
const Canvas = Object.assign({ 'canvas-id': NO_DEFAULT_VALUE, 'disable-scroll': DEFAULT_FALSE, bindError: NO_DEFAULT_VALUE }, touchEvents);
|
|
229
|
+
const Ad = {
|
|
230
|
+
'unit-id': NO_DEFAULT_VALUE,
|
|
231
|
+
'ad-intervals': NO_DEFAULT_VALUE,
|
|
232
|
+
bindLoad: NO_DEFAULT_VALUE,
|
|
233
|
+
bindError: NO_DEFAULT_VALUE,
|
|
234
|
+
bindClose: NO_DEFAULT_VALUE
|
|
235
|
+
};
|
|
236
|
+
const WebView = {
|
|
237
|
+
src: NO_DEFAULT_VALUE,
|
|
238
|
+
bindMessage: NO_DEFAULT_VALUE,
|
|
239
|
+
bindLoad: NO_DEFAULT_VALUE,
|
|
240
|
+
bindError: NO_DEFAULT_VALUE
|
|
241
|
+
};
|
|
242
|
+
const Block = {};
|
|
243
|
+
// For Vue,因为 slot 标签被 vue 占用了
|
|
244
|
+
const SlotView = {
|
|
245
|
+
name: NO_DEFAULT_VALUE
|
|
246
|
+
};
|
|
247
|
+
// For React
|
|
248
|
+
// Slot 和 SlotView 最终都会编译成 <view slot={{ i.name }} />
|
|
249
|
+
// 因为 <slot name="{{ i.name }}" /> 适用性没有前者高(无法添加类和样式)
|
|
250
|
+
// 不给 View 直接加 slot 属性的原因是性能损耗
|
|
251
|
+
const Slot = {
|
|
252
|
+
name: NO_DEFAULT_VALUE
|
|
253
|
+
};
|
|
254
|
+
const internalComponents = {
|
|
255
|
+
View,
|
|
256
|
+
Icon,
|
|
257
|
+
Progress,
|
|
258
|
+
RichText,
|
|
259
|
+
Text,
|
|
260
|
+
Button,
|
|
261
|
+
Checkbox,
|
|
262
|
+
CheckboxGroup,
|
|
263
|
+
Form,
|
|
264
|
+
Input,
|
|
265
|
+
Label,
|
|
266
|
+
Picker,
|
|
267
|
+
PickerView,
|
|
268
|
+
PickerViewColumn,
|
|
269
|
+
Radio,
|
|
270
|
+
RadioGroup,
|
|
271
|
+
Slider,
|
|
272
|
+
Switch,
|
|
273
|
+
CoverImage,
|
|
274
|
+
Textarea,
|
|
275
|
+
CoverView,
|
|
276
|
+
MovableArea,
|
|
277
|
+
MovableView,
|
|
278
|
+
ScrollView,
|
|
279
|
+
Swiper,
|
|
280
|
+
SwiperItem,
|
|
281
|
+
Navigator,
|
|
282
|
+
Audio,
|
|
283
|
+
Camera,
|
|
284
|
+
Image,
|
|
285
|
+
LivePlayer,
|
|
286
|
+
Video,
|
|
287
|
+
Canvas,
|
|
288
|
+
Ad,
|
|
289
|
+
WebView,
|
|
290
|
+
Block,
|
|
291
|
+
Map: MapComp,
|
|
292
|
+
Slot,
|
|
293
|
+
SlotView
|
|
294
|
+
};
|
|
295
|
+
const focusComponents = new Set([
|
|
296
|
+
'input',
|
|
297
|
+
'textarea'
|
|
298
|
+
]);
|
|
299
|
+
const voidElements = new Set([
|
|
300
|
+
'progress',
|
|
301
|
+
'icon',
|
|
302
|
+
'rich-text',
|
|
303
|
+
'input',
|
|
304
|
+
'textarea',
|
|
305
|
+
'slider',
|
|
306
|
+
'switch',
|
|
307
|
+
'audio',
|
|
308
|
+
'ad',
|
|
309
|
+
'official-account',
|
|
310
|
+
'open-data',
|
|
311
|
+
'navigation-bar'
|
|
312
|
+
]);
|
|
313
|
+
const nestElements = new Map([
|
|
314
|
+
['view', -1],
|
|
315
|
+
['catch-view', -1],
|
|
316
|
+
['cover-view', -1],
|
|
317
|
+
['static-view', -1],
|
|
318
|
+
['pure-view', -1],
|
|
319
|
+
['block', -1],
|
|
320
|
+
['text', -1],
|
|
321
|
+
['static-text', 6],
|
|
322
|
+
['slot', 8],
|
|
323
|
+
['slot-view', 8],
|
|
324
|
+
['label', 6],
|
|
325
|
+
['form', 4],
|
|
326
|
+
['scroll-view', 4],
|
|
327
|
+
['swiper', 4],
|
|
328
|
+
['swiper-item', 4]
|
|
329
329
|
]);
|
|
330
330
|
|
|
331
|
-
function isString(o) {
|
|
332
|
-
return typeof o === 'string';
|
|
333
|
-
}
|
|
334
|
-
function isFunction(o) {
|
|
335
|
-
return typeof o === 'function';
|
|
336
|
-
}
|
|
337
|
-
function isNumber(o) {
|
|
338
|
-
return typeof o === 'number';
|
|
339
|
-
}
|
|
340
|
-
function isBooleanStringLiteral(o) {
|
|
341
|
-
return o === 'true' || o === 'false';
|
|
331
|
+
function isString(o) {
|
|
332
|
+
return typeof o === 'string';
|
|
333
|
+
}
|
|
334
|
+
function isFunction(o) {
|
|
335
|
+
return typeof o === 'function';
|
|
336
|
+
}
|
|
337
|
+
function isNumber(o) {
|
|
338
|
+
return typeof o === 'number';
|
|
339
|
+
}
|
|
340
|
+
function isBooleanStringLiteral(o) {
|
|
341
|
+
return o === 'true' || o === 'false';
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
-
class Events {
|
|
345
|
-
constructor(opts) {
|
|
346
|
-
var _a;
|
|
347
|
-
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
348
|
-
}
|
|
349
|
-
on(eventName, callback, context) {
|
|
350
|
-
let event, node, tail, list;
|
|
351
|
-
if (!callback) {
|
|
352
|
-
return this;
|
|
353
|
-
}
|
|
354
|
-
eventName = eventName.split(Events.eventSplitter);
|
|
355
|
-
this.callbacks || (this.callbacks = {});
|
|
356
|
-
const calls = this.callbacks;
|
|
357
|
-
while ((event = eventName.shift())) {
|
|
358
|
-
list = calls[event];
|
|
359
|
-
node = list ? list.tail : {};
|
|
360
|
-
node.next = tail = {};
|
|
361
|
-
node.context = context;
|
|
362
|
-
node.callback = callback;
|
|
363
|
-
calls[event] = {
|
|
364
|
-
tail,
|
|
365
|
-
next: list ? list.next : node
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
return this;
|
|
369
|
-
}
|
|
370
|
-
once(events, callback, context) {
|
|
371
|
-
const wrapper = (...args) => {
|
|
372
|
-
callback.apply(this, args);
|
|
373
|
-
this.off(events, wrapper, context);
|
|
374
|
-
};
|
|
375
|
-
this.on(events, wrapper, context);
|
|
376
|
-
return this;
|
|
377
|
-
}
|
|
378
|
-
off(events, callback, context) {
|
|
379
|
-
let event, calls, node, tail, cb, ctx;
|
|
380
|
-
if (!(calls = this.callbacks)) {
|
|
381
|
-
return this;
|
|
382
|
-
}
|
|
383
|
-
if (!(events || callback || context)) {
|
|
384
|
-
delete this.callbacks;
|
|
385
|
-
return this;
|
|
386
|
-
}
|
|
387
|
-
events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
|
|
388
|
-
while ((event = events.shift())) {
|
|
389
|
-
node = calls[event];
|
|
390
|
-
delete calls[event];
|
|
391
|
-
if (!node || !(callback || context)) {
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
tail = node.tail;
|
|
395
|
-
while ((node = node.next) !== tail) {
|
|
396
|
-
cb = node.callback;
|
|
397
|
-
ctx = node.context;
|
|
398
|
-
if ((callback && cb !== callback) || (context && ctx !== context)) {
|
|
399
|
-
this.on(event, cb, ctx);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return this;
|
|
404
|
-
}
|
|
405
|
-
trigger(events) {
|
|
406
|
-
let event, node, calls, tail;
|
|
407
|
-
if (!(calls = this.callbacks)) {
|
|
408
|
-
return this;
|
|
409
|
-
}
|
|
410
|
-
events = events.split(Events.eventSplitter);
|
|
411
|
-
const rest = [].slice.call(arguments, 1);
|
|
412
|
-
while ((event = events.shift())) {
|
|
413
|
-
if ((node = calls[event])) {
|
|
414
|
-
tail = node.tail;
|
|
415
|
-
while ((node = node.next) !== tail) {
|
|
416
|
-
node.callback.apply(node.context || this, rest);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return this;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
344
|
+
class Events {
|
|
345
|
+
constructor(opts) {
|
|
346
|
+
var _a;
|
|
347
|
+
this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
|
|
348
|
+
}
|
|
349
|
+
on(eventName, callback, context) {
|
|
350
|
+
let event, node, tail, list;
|
|
351
|
+
if (!callback) {
|
|
352
|
+
return this;
|
|
353
|
+
}
|
|
354
|
+
eventName = eventName.split(Events.eventSplitter);
|
|
355
|
+
this.callbacks || (this.callbacks = {});
|
|
356
|
+
const calls = this.callbacks;
|
|
357
|
+
while ((event = eventName.shift())) {
|
|
358
|
+
list = calls[event];
|
|
359
|
+
node = list ? list.tail : {};
|
|
360
|
+
node.next = tail = {};
|
|
361
|
+
node.context = context;
|
|
362
|
+
node.callback = callback;
|
|
363
|
+
calls[event] = {
|
|
364
|
+
tail,
|
|
365
|
+
next: list ? list.next : node
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
once(events, callback, context) {
|
|
371
|
+
const wrapper = (...args) => {
|
|
372
|
+
callback.apply(this, args);
|
|
373
|
+
this.off(events, wrapper, context);
|
|
374
|
+
};
|
|
375
|
+
this.on(events, wrapper, context);
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
off(events, callback, context) {
|
|
379
|
+
let event, calls, node, tail, cb, ctx;
|
|
380
|
+
if (!(calls = this.callbacks)) {
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
if (!(events || callback || context)) {
|
|
384
|
+
delete this.callbacks;
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
|
|
388
|
+
while ((event = events.shift())) {
|
|
389
|
+
node = calls[event];
|
|
390
|
+
delete calls[event];
|
|
391
|
+
if (!node || !(callback || context)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
tail = node.tail;
|
|
395
|
+
while ((node = node.next) !== tail) {
|
|
396
|
+
cb = node.callback;
|
|
397
|
+
ctx = node.context;
|
|
398
|
+
if ((callback && cb !== callback) || (context && ctx !== context)) {
|
|
399
|
+
this.on(event, cb, ctx);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
trigger(events) {
|
|
406
|
+
let event, node, calls, tail;
|
|
407
|
+
if (!(calls = this.callbacks)) {
|
|
408
|
+
return this;
|
|
409
|
+
}
|
|
410
|
+
events = events.split(Events.eventSplitter);
|
|
411
|
+
const rest = [].slice.call(arguments, 1);
|
|
412
|
+
while ((event = events.shift())) {
|
|
413
|
+
if ((node = calls[event])) {
|
|
414
|
+
tail = node.tail;
|
|
415
|
+
while ((node = node.next) !== tail) {
|
|
416
|
+
node.callback.apply(node.context || this, rest);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return this;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
423
|
Events.eventSplitter = /\s+/;
|
|
424
424
|
|
|
425
|
-
var HOOK_TYPE;
|
|
426
|
-
(function (HOOK_TYPE) {
|
|
427
|
-
HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
|
|
428
|
-
HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
|
|
429
|
-
HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
|
|
430
|
-
})(HOOK_TYPE || (HOOK_TYPE = {}));
|
|
431
|
-
const defaultMiniLifecycle = {
|
|
432
|
-
app: [
|
|
433
|
-
'onLaunch',
|
|
434
|
-
'onShow',
|
|
435
|
-
'onHide'
|
|
436
|
-
],
|
|
437
|
-
page: [
|
|
438
|
-
'onLoad',
|
|
439
|
-
'onUnload',
|
|
440
|
-
'onReady',
|
|
441
|
-
'onShow',
|
|
442
|
-
'onHide',
|
|
443
|
-
[
|
|
444
|
-
'onPullDownRefresh',
|
|
445
|
-
'onReachBottom',
|
|
446
|
-
'onPageScroll',
|
|
447
|
-
'onResize',
|
|
448
|
-
'onTabItemTap',
|
|
449
|
-
'onTitleClick',
|
|
450
|
-
'onOptionMenuClick',
|
|
451
|
-
'onPopMenuClick',
|
|
452
|
-
'onPullIntercept',
|
|
453
|
-
'onAddToFavorites'
|
|
454
|
-
]
|
|
455
|
-
]
|
|
456
|
-
};
|
|
457
|
-
function TaroHook(type, initial) {
|
|
458
|
-
return {
|
|
459
|
-
type,
|
|
460
|
-
initial: initial || null
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
class TaroHooks extends Events {
|
|
464
|
-
constructor(hooks, opts) {
|
|
465
|
-
super(opts);
|
|
466
|
-
this.hooks = hooks;
|
|
467
|
-
for (const hookName in hooks) {
|
|
468
|
-
const { initial } = hooks[hookName];
|
|
469
|
-
if (isFunction(initial)) {
|
|
470
|
-
this.on(hookName, initial);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
tapOneOrMany(hookName, callback) {
|
|
475
|
-
const list = isFunction(callback) ? [callback] : callback;
|
|
476
|
-
list.forEach(cb => this.on(hookName, cb));
|
|
477
|
-
}
|
|
478
|
-
tap(hookName, callback) {
|
|
479
|
-
const hooks = this.hooks;
|
|
480
|
-
const { type, initial } = hooks[hookName];
|
|
481
|
-
if (type === HOOK_TYPE.SINGLE) {
|
|
482
|
-
this.off(hookName);
|
|
483
|
-
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
initial && this.off(hookName, initial);
|
|
487
|
-
this.tapOneOrMany(hookName, callback);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
call(hookName, ...rest) {
|
|
491
|
-
var _a;
|
|
492
|
-
const hook = this.hooks[hookName];
|
|
493
|
-
if (!hook)
|
|
494
|
-
return;
|
|
495
|
-
const { type } = hook;
|
|
496
|
-
const calls = this.callbacks;
|
|
497
|
-
if (!calls)
|
|
498
|
-
return;
|
|
499
|
-
const list = calls[hookName];
|
|
500
|
-
if (list) {
|
|
501
|
-
const tail = list.tail;
|
|
502
|
-
let node = list.next;
|
|
503
|
-
let args = rest;
|
|
504
|
-
let res;
|
|
505
|
-
while (node !== tail) {
|
|
506
|
-
res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
|
|
507
|
-
if (type === HOOK_TYPE.WATERFALL) {
|
|
508
|
-
const params = [res];
|
|
509
|
-
args = params;
|
|
510
|
-
}
|
|
511
|
-
node = node.next;
|
|
512
|
-
}
|
|
513
|
-
return res;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
isExist(hookName) {
|
|
517
|
-
var _a;
|
|
518
|
-
return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
new TaroHooks({
|
|
522
|
-
getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
|
|
523
|
-
getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
|
|
524
|
-
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
525
|
-
}),
|
|
526
|
-
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
527
|
-
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
528
|
-
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
529
|
-
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
530
|
-
/**
|
|
531
|
-
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
532
|
-
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
533
|
-
*/
|
|
534
|
-
const BUBBLE_EVENTS = new Set([
|
|
535
|
-
'touchstart',
|
|
536
|
-
'touchmove',
|
|
537
|
-
'touchcancel',
|
|
538
|
-
'touchend',
|
|
539
|
-
'touchforcechange',
|
|
540
|
-
'tap',
|
|
541
|
-
'longpress',
|
|
542
|
-
'longtap',
|
|
543
|
-
'transitionend',
|
|
544
|
-
'animationstart',
|
|
545
|
-
'animationiteration',
|
|
546
|
-
'animationend'
|
|
547
|
-
]);
|
|
548
|
-
return BUBBLE_EVENTS.has(eventName);
|
|
549
|
-
}),
|
|
550
|
-
getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
|
|
551
|
-
onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
|
|
552
|
-
batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
|
|
553
|
-
mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
|
|
554
|
-
modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
|
|
555
|
-
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
556
|
-
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
557
|
-
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
558
|
-
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
559
|
-
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
560
|
-
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
561
|
-
modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
562
|
-
modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
|
|
563
|
-
try {
|
|
564
|
-
// 有些小程序的事件对象的某些属性只读
|
|
565
|
-
this.call('modifyMpEvent', e);
|
|
566
|
-
}
|
|
567
|
-
catch (error) {
|
|
568
|
-
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
569
|
-
}
|
|
570
|
-
}),
|
|
571
|
-
modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
572
|
-
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
573
|
-
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
574
|
-
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
425
|
+
var HOOK_TYPE;
|
|
426
|
+
(function (HOOK_TYPE) {
|
|
427
|
+
HOOK_TYPE[HOOK_TYPE["SINGLE"] = 0] = "SINGLE";
|
|
428
|
+
HOOK_TYPE[HOOK_TYPE["MULTI"] = 1] = "MULTI";
|
|
429
|
+
HOOK_TYPE[HOOK_TYPE["WATERFALL"] = 2] = "WATERFALL";
|
|
430
|
+
})(HOOK_TYPE || (HOOK_TYPE = {}));
|
|
431
|
+
const defaultMiniLifecycle = {
|
|
432
|
+
app: [
|
|
433
|
+
'onLaunch',
|
|
434
|
+
'onShow',
|
|
435
|
+
'onHide'
|
|
436
|
+
],
|
|
437
|
+
page: [
|
|
438
|
+
'onLoad',
|
|
439
|
+
'onUnload',
|
|
440
|
+
'onReady',
|
|
441
|
+
'onShow',
|
|
442
|
+
'onHide',
|
|
443
|
+
[
|
|
444
|
+
'onPullDownRefresh',
|
|
445
|
+
'onReachBottom',
|
|
446
|
+
'onPageScroll',
|
|
447
|
+
'onResize',
|
|
448
|
+
'onTabItemTap',
|
|
449
|
+
'onTitleClick',
|
|
450
|
+
'onOptionMenuClick',
|
|
451
|
+
'onPopMenuClick',
|
|
452
|
+
'onPullIntercept',
|
|
453
|
+
'onAddToFavorites'
|
|
454
|
+
]
|
|
455
|
+
]
|
|
456
|
+
};
|
|
457
|
+
function TaroHook(type, initial) {
|
|
458
|
+
return {
|
|
459
|
+
type,
|
|
460
|
+
initial: initial || null
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
class TaroHooks extends Events {
|
|
464
|
+
constructor(hooks, opts) {
|
|
465
|
+
super(opts);
|
|
466
|
+
this.hooks = hooks;
|
|
467
|
+
for (const hookName in hooks) {
|
|
468
|
+
const { initial } = hooks[hookName];
|
|
469
|
+
if (isFunction(initial)) {
|
|
470
|
+
this.on(hookName, initial);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
tapOneOrMany(hookName, callback) {
|
|
475
|
+
const list = isFunction(callback) ? [callback] : callback;
|
|
476
|
+
list.forEach(cb => this.on(hookName, cb));
|
|
477
|
+
}
|
|
478
|
+
tap(hookName, callback) {
|
|
479
|
+
const hooks = this.hooks;
|
|
480
|
+
const { type, initial } = hooks[hookName];
|
|
481
|
+
if (type === HOOK_TYPE.SINGLE) {
|
|
482
|
+
this.off(hookName);
|
|
483
|
+
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]);
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
initial && this.off(hookName, initial);
|
|
487
|
+
this.tapOneOrMany(hookName, callback);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
call(hookName, ...rest) {
|
|
491
|
+
var _a;
|
|
492
|
+
const hook = this.hooks[hookName];
|
|
493
|
+
if (!hook)
|
|
494
|
+
return;
|
|
495
|
+
const { type } = hook;
|
|
496
|
+
const calls = this.callbacks;
|
|
497
|
+
if (!calls)
|
|
498
|
+
return;
|
|
499
|
+
const list = calls[hookName];
|
|
500
|
+
if (list) {
|
|
501
|
+
const tail = list.tail;
|
|
502
|
+
let node = list.next;
|
|
503
|
+
let args = rest;
|
|
504
|
+
let res;
|
|
505
|
+
while (node !== tail) {
|
|
506
|
+
res = (_a = node.callback) === null || _a === void 0 ? void 0 : _a.apply(node.context || this, args);
|
|
507
|
+
if (type === HOOK_TYPE.WATERFALL) {
|
|
508
|
+
const params = [res];
|
|
509
|
+
args = params;
|
|
510
|
+
}
|
|
511
|
+
node = node.next;
|
|
512
|
+
}
|
|
513
|
+
return res;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
isExist(hookName) {
|
|
517
|
+
var _a;
|
|
518
|
+
return Boolean((_a = this.callbacks) === null || _a === void 0 ? void 0 : _a[hookName]);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
new TaroHooks({
|
|
522
|
+
getMiniLifecycle: TaroHook(HOOK_TYPE.SINGLE, defaultConfig => defaultConfig),
|
|
523
|
+
getMiniLifecycleImpl: TaroHook(HOOK_TYPE.SINGLE, function () {
|
|
524
|
+
return this.call('getMiniLifecycle', defaultMiniLifecycle);
|
|
525
|
+
}),
|
|
526
|
+
getLifecycle: TaroHook(HOOK_TYPE.SINGLE, (instance, lifecycle) => instance[lifecycle]),
|
|
527
|
+
getPathIndex: TaroHook(HOOK_TYPE.SINGLE, indexOfNode => `[${indexOfNode}]`),
|
|
528
|
+
getEventCenter: TaroHook(HOOK_TYPE.SINGLE, Events => new Events()),
|
|
529
|
+
isBubbleEvents: TaroHook(HOOK_TYPE.SINGLE, eventName => {
|
|
530
|
+
/**
|
|
531
|
+
* 支持冒泡的事件, 除 支付宝小程序外,其余的可冒泡事件都和微信保持一致
|
|
532
|
+
* 详见 见 https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html
|
|
533
|
+
*/
|
|
534
|
+
const BUBBLE_EVENTS = new Set([
|
|
535
|
+
'touchstart',
|
|
536
|
+
'touchmove',
|
|
537
|
+
'touchcancel',
|
|
538
|
+
'touchend',
|
|
539
|
+
'touchforcechange',
|
|
540
|
+
'tap',
|
|
541
|
+
'longpress',
|
|
542
|
+
'longtap',
|
|
543
|
+
'transitionend',
|
|
544
|
+
'animationstart',
|
|
545
|
+
'animationiteration',
|
|
546
|
+
'animationend'
|
|
547
|
+
]);
|
|
548
|
+
return BUBBLE_EVENTS.has(eventName);
|
|
549
|
+
}),
|
|
550
|
+
getSpecialNodes: TaroHook(HOOK_TYPE.SINGLE, () => ['view', 'text', 'image']),
|
|
551
|
+
onRemoveAttribute: TaroHook(HOOK_TYPE.SINGLE),
|
|
552
|
+
batchedEventUpdates: TaroHook(HOOK_TYPE.SINGLE),
|
|
553
|
+
mergePageInstance: TaroHook(HOOK_TYPE.SINGLE),
|
|
554
|
+
modifyPageObject: TaroHook(HOOK_TYPE.SINGLE),
|
|
555
|
+
createPullDownComponent: TaroHook(HOOK_TYPE.SINGLE),
|
|
556
|
+
getDOMNode: TaroHook(HOOK_TYPE.SINGLE),
|
|
557
|
+
modifyHydrateData: TaroHook(HOOK_TYPE.SINGLE),
|
|
558
|
+
modifySetAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
559
|
+
modifyRmAttrPayload: TaroHook(HOOK_TYPE.SINGLE),
|
|
560
|
+
onAddEvent: TaroHook(HOOK_TYPE.SINGLE),
|
|
561
|
+
modifyMpEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
562
|
+
modifyMpEventImpl: TaroHook(HOOK_TYPE.SINGLE, function (e) {
|
|
563
|
+
try {
|
|
564
|
+
// 有些小程序的事件对象的某些属性只读
|
|
565
|
+
this.call('modifyMpEvent', e);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
console.warn('[Taro modifyMpEvent hook Error]: ', error);
|
|
569
|
+
}
|
|
570
|
+
}),
|
|
571
|
+
modifyTaroEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
572
|
+
modifyDispatchEvent: TaroHook(HOOK_TYPE.MULTI),
|
|
573
|
+
initNativeApi: TaroHook(HOOK_TYPE.MULTI),
|
|
574
|
+
patchElement: TaroHook(HOOK_TYPE.MULTI)
|
|
575
575
|
});
|
|
576
576
|
|
|
577
|
-
function toDashed(s) {
|
|
578
|
-
return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
579
|
-
}
|
|
580
|
-
function toCamelCase(s) {
|
|
581
|
-
let camel = '';
|
|
582
|
-
let nextCap = false;
|
|
583
|
-
for (let i = 0; i < s.length; i++) {
|
|
584
|
-
if (s[i] !== '-') {
|
|
585
|
-
camel += nextCap ? s[i].toUpperCase() : s[i];
|
|
586
|
-
nextCap = false;
|
|
587
|
-
}
|
|
588
|
-
else {
|
|
589
|
-
nextCap = true;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
return camel;
|
|
593
|
-
}
|
|
594
|
-
const toKebabCase = function (string) {
|
|
595
|
-
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
596
|
-
};
|
|
597
|
-
function capitalize(s) {
|
|
598
|
-
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
599
|
-
}
|
|
600
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
601
|
-
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
602
|
-
(new Date()).getTime().toString();
|
|
603
|
-
function getComponentsAlias(origin) {
|
|
604
|
-
const mapping = {};
|
|
605
|
-
const viewAttrs = origin.View;
|
|
606
|
-
const extraList = {
|
|
607
|
-
'#text': {},
|
|
608
|
-
StaticView: viewAttrs,
|
|
609
|
-
StaticImage: origin.Image,
|
|
610
|
-
StaticText: origin.Text,
|
|
611
|
-
PureView: viewAttrs,
|
|
612
|
-
CatchView: viewAttrs
|
|
613
|
-
};
|
|
614
|
-
origin = Object.assign(Object.assign({}, origin), extraList);
|
|
615
|
-
Object.keys(origin)
|
|
616
|
-
.sort((a, b) => {
|
|
617
|
-
const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
|
|
618
|
-
if (reg.test(a)) {
|
|
619
|
-
return -1;
|
|
620
|
-
}
|
|
621
|
-
else if (reg.test(b)) {
|
|
622
|
-
return 1;
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
return a >= b ? 1 : -1;
|
|
626
|
-
}
|
|
627
|
-
})
|
|
628
|
-
.forEach((key, num) => {
|
|
629
|
-
const obj = {
|
|
630
|
-
_num: String(num)
|
|
631
|
-
};
|
|
632
|
-
Object.keys(origin[key])
|
|
633
|
-
.filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
|
|
634
|
-
.sort()
|
|
635
|
-
.forEach((attr, index) => {
|
|
636
|
-
obj[toCamelCase(attr)] = 'p' + index;
|
|
637
|
-
});
|
|
638
|
-
mapping[toDashed(key)] = obj;
|
|
639
|
-
});
|
|
640
|
-
return mapping;
|
|
641
|
-
}
|
|
642
|
-
function indent(str, size) {
|
|
643
|
-
return str.split('\n')
|
|
644
|
-
.map((line, index) => {
|
|
645
|
-
const indent = index === 0 ? '' : Array(size).fill(' ').join('');
|
|
646
|
-
return indent + line;
|
|
647
|
-
})
|
|
648
|
-
.join('\n');
|
|
577
|
+
function toDashed(s) {
|
|
578
|
+
return s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
579
|
+
}
|
|
580
|
+
function toCamelCase(s) {
|
|
581
|
+
let camel = '';
|
|
582
|
+
let nextCap = false;
|
|
583
|
+
for (let i = 0; i < s.length; i++) {
|
|
584
|
+
if (s[i] !== '-') {
|
|
585
|
+
camel += nextCap ? s[i].toUpperCase() : s[i];
|
|
586
|
+
nextCap = false;
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
nextCap = true;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return camel;
|
|
593
|
+
}
|
|
594
|
+
const toKebabCase = function (string) {
|
|
595
|
+
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
596
|
+
};
|
|
597
|
+
function capitalize(s) {
|
|
598
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
599
|
+
}
|
|
600
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
601
|
+
const hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
602
|
+
(new Date()).getTime().toString();
|
|
603
|
+
function getComponentsAlias(origin) {
|
|
604
|
+
const mapping = {};
|
|
605
|
+
const viewAttrs = origin.View;
|
|
606
|
+
const extraList = {
|
|
607
|
+
'#text': {},
|
|
608
|
+
StaticView: viewAttrs,
|
|
609
|
+
StaticImage: origin.Image,
|
|
610
|
+
StaticText: origin.Text,
|
|
611
|
+
PureView: viewAttrs,
|
|
612
|
+
CatchView: viewAttrs
|
|
613
|
+
};
|
|
614
|
+
origin = Object.assign(Object.assign({}, origin), extraList);
|
|
615
|
+
Object.keys(origin)
|
|
616
|
+
.sort((a, b) => {
|
|
617
|
+
const reg = /^(Static|Pure|Catch)*(View|Image|Text)$/;
|
|
618
|
+
if (reg.test(a)) {
|
|
619
|
+
return -1;
|
|
620
|
+
}
|
|
621
|
+
else if (reg.test(b)) {
|
|
622
|
+
return 1;
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
return a >= b ? 1 : -1;
|
|
626
|
+
}
|
|
627
|
+
})
|
|
628
|
+
.forEach((key, num) => {
|
|
629
|
+
const obj = {
|
|
630
|
+
_num: String(num)
|
|
631
|
+
};
|
|
632
|
+
Object.keys(origin[key])
|
|
633
|
+
.filter(attr => !(/^bind/.test(attr)) && !['focus', 'blur'].includes(attr))
|
|
634
|
+
.sort()
|
|
635
|
+
.forEach((attr, index) => {
|
|
636
|
+
obj[toCamelCase(attr)] = 'p' + index;
|
|
637
|
+
});
|
|
638
|
+
mapping[toDashed(key)] = obj;
|
|
639
|
+
});
|
|
640
|
+
return mapping;
|
|
641
|
+
}
|
|
642
|
+
function indent(str, size) {
|
|
643
|
+
return str.split('\n')
|
|
644
|
+
.map((line, index) => {
|
|
645
|
+
const indent = index === 0 ? '' : Array(size).fill(' ').join('');
|
|
646
|
+
return indent + line;
|
|
647
|
+
})
|
|
648
|
+
.join('\n');
|
|
649
649
|
}
|
|
650
650
|
|
|
651
|
-
/**
|
|
652
|
-
* 这里我们需要关心的小程序种类有两类:
|
|
653
|
-
* 1. 模板递归:
|
|
654
|
-
* - 支持:tmpl0 套 tmpl0
|
|
655
|
-
* - 不支持:这就使得我们必须生成多级的模板,tmpl0 套 tmpl1,tmpl1 套 tmpl2……
|
|
656
|
-
* 直到超过阈值 N (N = config.miniapp.baseLevel) tmplN 会套组件 comp,组件 comp 重新再套 tmpl0。
|
|
657
|
-
* 2. 小程序脚本语言(wxs, sjs, etc...):
|
|
658
|
-
* - 支持:可以在模板使用函数缩减模板大小或提高性能(存疑),例如判断一个值是不是假值(falsy value)。
|
|
659
|
-
* 将来或许会把数据序列化^1 的操作也放到小程序脚本语言里。
|
|
660
|
-
* - 不支持:使用纯 *xml 语法
|
|
661
|
-
*
|
|
662
|
-
* ^1: packages/taro-runtime/src/hydrate.ts
|
|
663
|
-
*/
|
|
664
|
-
const styles = {
|
|
665
|
-
style: `i.${"st" /* Style */}`,
|
|
666
|
-
class: `i.${"cl" /* Class */}`
|
|
667
|
-
};
|
|
668
|
-
const events = {
|
|
669
|
-
bindtap: 'eh'
|
|
670
|
-
};
|
|
671
|
-
const weixinAdapter = {
|
|
672
|
-
if: 'wx:if',
|
|
673
|
-
else: 'wx:else',
|
|
674
|
-
elseif: 'wx:elif',
|
|
675
|
-
for: 'wx:for',
|
|
676
|
-
forItem: 'wx:for-item',
|
|
677
|
-
forIndex: 'wx:for-index',
|
|
678
|
-
key: 'wx:key',
|
|
679
|
-
xs: 'wxs',
|
|
680
|
-
type: 'weapp'
|
|
681
|
-
};
|
|
682
|
-
class BaseTemplate {
|
|
683
|
-
constructor() {
|
|
684
|
-
this.exportExpr = 'module.exports =';
|
|
685
|
-
this.supportXS = false;
|
|
686
|
-
this.thirdPartyPatcher = {};
|
|
687
|
-
this.Adapter = weixinAdapter;
|
|
688
|
-
/** 组件列表 */
|
|
689
|
-
this.internalComponents = internalComponents;
|
|
690
|
-
/** 可以 focus 聚焦的组件 */
|
|
691
|
-
this.focusComponents = focusComponents;
|
|
692
|
-
/** 不需要渲染子节点的元素 */
|
|
693
|
-
this.voidElements = voidElements;
|
|
694
|
-
/** 可以递归调用自身的组件 */
|
|
695
|
-
this.nestElements = nestElements;
|
|
696
|
-
this.buildPageTemplate = (baseTempPath) => {
|
|
651
|
+
/**
|
|
652
|
+
* 这里我们需要关心的小程序种类有两类:
|
|
653
|
+
* 1. 模板递归:
|
|
654
|
+
* - 支持:tmpl0 套 tmpl0
|
|
655
|
+
* - 不支持:这就使得我们必须生成多级的模板,tmpl0 套 tmpl1,tmpl1 套 tmpl2……
|
|
656
|
+
* 直到超过阈值 N (N = config.miniapp.baseLevel) tmplN 会套组件 comp,组件 comp 重新再套 tmpl0。
|
|
657
|
+
* 2. 小程序脚本语言(wxs, sjs, etc...):
|
|
658
|
+
* - 支持:可以在模板使用函数缩减模板大小或提高性能(存疑),例如判断一个值是不是假值(falsy value)。
|
|
659
|
+
* 将来或许会把数据序列化^1 的操作也放到小程序脚本语言里。
|
|
660
|
+
* - 不支持:使用纯 *xml 语法
|
|
661
|
+
*
|
|
662
|
+
* ^1: packages/taro-runtime/src/hydrate.ts
|
|
663
|
+
*/
|
|
664
|
+
const styles = {
|
|
665
|
+
style: `i.${"st" /* Shortcuts.Style */}`,
|
|
666
|
+
class: `i.${"cl" /* Shortcuts.Class */}`
|
|
667
|
+
};
|
|
668
|
+
const events = {
|
|
669
|
+
bindtap: 'eh'
|
|
670
|
+
};
|
|
671
|
+
const weixinAdapter = {
|
|
672
|
+
if: 'wx:if',
|
|
673
|
+
else: 'wx:else',
|
|
674
|
+
elseif: 'wx:elif',
|
|
675
|
+
for: 'wx:for',
|
|
676
|
+
forItem: 'wx:for-item',
|
|
677
|
+
forIndex: 'wx:for-index',
|
|
678
|
+
key: 'wx:key',
|
|
679
|
+
xs: 'wxs',
|
|
680
|
+
type: 'weapp'
|
|
681
|
+
};
|
|
682
|
+
class BaseTemplate {
|
|
683
|
+
constructor() {
|
|
684
|
+
this.exportExpr = 'module.exports =';
|
|
685
|
+
this.supportXS = false;
|
|
686
|
+
this.thirdPartyPatcher = {};
|
|
687
|
+
this.Adapter = weixinAdapter;
|
|
688
|
+
/** 组件列表 */
|
|
689
|
+
this.internalComponents = internalComponents;
|
|
690
|
+
/** 可以 focus 聚焦的组件 */
|
|
691
|
+
this.focusComponents = focusComponents;
|
|
692
|
+
/** 不需要渲染子节点的元素 */
|
|
693
|
+
this.voidElements = voidElements;
|
|
694
|
+
/** 可以递归调用自身的组件 */
|
|
695
|
+
this.nestElements = nestElements;
|
|
696
|
+
this.buildPageTemplate = (baseTempPath) => {
|
|
697
697
|
const template = `<import src="${baseTempPath}"/>
|
|
698
|
-
<template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
|
|
699
|
-
return template;
|
|
700
|
-
};
|
|
701
|
-
this.buildBaseComponentTemplate = (ext) => {
|
|
702
|
-
const data = !this.isSupportRecursive && this.supportXS
|
|
703
|
-
? this.dataKeymap('i:i,l:l')
|
|
704
|
-
: this.dataKeymap('i:i');
|
|
698
|
+
<template is="taro_tmpl" data="{{${this.dataKeymap('root:root')}}}" />`;
|
|
699
|
+
return template;
|
|
700
|
+
};
|
|
701
|
+
this.buildBaseComponentTemplate = (ext) => {
|
|
702
|
+
const data = !this.isSupportRecursive && this.supportXS
|
|
703
|
+
? this.dataKeymap('i:i,l:l')
|
|
704
|
+
: this.dataKeymap('i:i');
|
|
705
705
|
return `<import src="./base${ext}" />
|
|
706
|
-
<template is="tmpl_0_${"container" /* Container */}" data="{{${data}}}" />`;
|
|
707
|
-
};
|
|
708
|
-
this.buildCustomComponentTemplate = (ext) => {
|
|
709
|
-
const Adapter = this.Adapter;
|
|
710
|
-
const data = !this.isSupportRecursive && this.supportXS
|
|
711
|
-
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
712
|
-
: this.dataKeymap('i:item');
|
|
706
|
+
<template is="tmpl_0_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
707
|
+
};
|
|
708
|
+
this.buildCustomComponentTemplate = (ext) => {
|
|
709
|
+
const Adapter = this.Adapter;
|
|
710
|
+
const data = !this.isSupportRecursive && this.supportXS
|
|
711
|
+
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
712
|
+
: this.dataKeymap('i:item');
|
|
713
713
|
return `<import src="./base${ext}" />
|
|
714
|
-
<block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
|
|
714
|
+
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
715
715
|
<template is="tmpl_0_container" data="{{${data}}}" />
|
|
716
|
-
</block>`;
|
|
717
|
-
};
|
|
718
|
-
this.buildXScript = () => {
|
|
716
|
+
</block>`;
|
|
717
|
+
};
|
|
718
|
+
this.buildXScript = () => {
|
|
719
719
|
return `${this.exportExpr} {
|
|
720
720
|
a: ${this.buildXSTmplName()},
|
|
721
721
|
b: function (a, b) {
|
|
722
722
|
return a === undefined ? b : a
|
|
723
723
|
},
|
|
724
|
-
c: ${this.buildXSTepFocus("nn" /* NodeName */)},
|
|
724
|
+
c: ${this.buildXSTepFocus("nn" /* Shortcuts.NodeName */)},
|
|
725
725
|
d: function (i, v) {
|
|
726
726
|
return i === undefined ? v : i
|
|
727
727
|
},
|
|
728
728
|
e: function (n) {
|
|
729
|
-
return 'tmpl_' + n + '_${"container" /* Container */}'
|
|
729
|
+
return 'tmpl_' + n + '_${"container" /* Shortcuts.Container */}'
|
|
730
730
|
},
|
|
731
731
|
${this.buildXSTmpExtra()}
|
|
732
|
-
}`;
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
buildAttribute(attrs, nodeName) {
|
|
736
|
-
return Object.keys(attrs)
|
|
737
|
-
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
738
|
-
.join('');
|
|
739
|
-
}
|
|
740
|
-
replacePropName(name, value, _componentName, _componentAlias) {
|
|
741
|
-
if (value === 'eh')
|
|
742
|
-
return name.toLowerCase();
|
|
743
|
-
return name;
|
|
744
|
-
}
|
|
745
|
-
createMiniComponents(components) {
|
|
746
|
-
const result = Object.create(null);
|
|
747
|
-
for (const key in components) {
|
|
748
|
-
if (hasOwn(components, key)) {
|
|
749
|
-
let component = components[key];
|
|
750
|
-
const compName = toDashed(key);
|
|
751
|
-
const newComp = Object.create(null);
|
|
752
|
-
const componentAlias = this.componentsAlias[compName];
|
|
753
|
-
if (isFunction(this.modifyCompProps)) {
|
|
754
|
-
component = this.modifyCompProps(compName, component);
|
|
755
|
-
}
|
|
756
|
-
for (let prop in component) {
|
|
757
|
-
if (hasOwn(component, prop)) {
|
|
758
|
-
let propValue = component[prop];
|
|
759
|
-
if (prop.startsWith('bind') || propValue === 'eh') {
|
|
760
|
-
propValue = 'eh';
|
|
761
|
-
}
|
|
762
|
-
else if (propValue === '') {
|
|
763
|
-
const propInCamelCase = toCamelCase(prop);
|
|
764
|
-
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
765
|
-
propValue = `i.${propAlias}`;
|
|
766
|
-
}
|
|
767
|
-
else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
|
|
768
|
-
const propInCamelCase = toCamelCase(prop);
|
|
769
|
-
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
770
|
-
propValue = this.supportXS
|
|
771
|
-
? `xs.b(i.${propAlias},${propValue})`
|
|
772
|
-
: `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
const propInCamelCase = toCamelCase(prop);
|
|
776
|
-
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
777
|
-
propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
|
|
778
|
-
}
|
|
779
|
-
prop = this.replacePropName(prop, propValue, compName, componentAlias);
|
|
780
|
-
newComp[prop] = propValue;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
if (compName !== 'block') {
|
|
784
|
-
Object.assign(newComp, styles, this.getEvents());
|
|
785
|
-
}
|
|
786
|
-
if (compName === 'swiper-item') {
|
|
787
|
-
delete newComp.style;
|
|
788
|
-
}
|
|
789
|
-
if (compName === 'view') {
|
|
790
|
-
const reg = /^(bind|on)(touchmove|TouchMove)$/;
|
|
791
|
-
const comp = Object.assign({}, newComp);
|
|
792
|
-
Object.keys(comp).forEach(originKey => {
|
|
793
|
-
if (!reg.test(originKey))
|
|
794
|
-
return;
|
|
795
|
-
const key = originKey.replace(reg, 'catch$2');
|
|
796
|
-
comp[key] = comp[originKey];
|
|
797
|
-
delete comp[originKey];
|
|
798
|
-
});
|
|
799
|
-
result['catch-view'] = comp;
|
|
800
|
-
}
|
|
801
|
-
if (compName === 'view' || compName === 'text' || compName === 'image') {
|
|
802
|
-
const comp = {};
|
|
803
|
-
Object.keys(newComp).forEach(key => {
|
|
804
|
-
const value = newComp[key];
|
|
805
|
-
if (value !== 'eh')
|
|
806
|
-
comp[key] = value;
|
|
807
|
-
});
|
|
808
|
-
result[`static-${compName}`] = comp;
|
|
809
|
-
if (compName === 'view') {
|
|
810
|
-
result['pure-view'] = {
|
|
811
|
-
style: comp.style,
|
|
812
|
-
class: comp.class
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
if (compName === 'slot' || compName === 'slot-view') {
|
|
817
|
-
result[compName] = Object.assign({ slot: 'i.name' }, styles);
|
|
818
|
-
}
|
|
819
|
-
else {
|
|
820
|
-
result[compName] = newComp;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return result;
|
|
825
|
-
}
|
|
826
|
-
buildBaseTemplate() {
|
|
827
|
-
const Adapter = this.Adapter;
|
|
828
|
-
const data = !this.isSupportRecursive && this.supportXS
|
|
829
|
-
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
830
|
-
: this.dataKeymap('i:item');
|
|
732
|
+
}`;
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
buildAttribute(attrs, nodeName) {
|
|
736
|
+
return Object.keys(attrs)
|
|
737
|
+
.map(k => `${k}="${k.startsWith('bind') || k.startsWith('on') || k.startsWith('catch') ? attrs[k] : `{${this.getAttrValue(attrs[k], k, nodeName)}}`}" `)
|
|
738
|
+
.join('');
|
|
739
|
+
}
|
|
740
|
+
replacePropName(name, value, _componentName, _componentAlias) {
|
|
741
|
+
if (value === 'eh')
|
|
742
|
+
return name.toLowerCase();
|
|
743
|
+
return name;
|
|
744
|
+
}
|
|
745
|
+
createMiniComponents(components) {
|
|
746
|
+
const result = Object.create(null);
|
|
747
|
+
for (const key in components) {
|
|
748
|
+
if (hasOwn(components, key)) {
|
|
749
|
+
let component = components[key];
|
|
750
|
+
const compName = toDashed(key);
|
|
751
|
+
const newComp = Object.create(null);
|
|
752
|
+
const componentAlias = this.componentsAlias[compName];
|
|
753
|
+
if (isFunction(this.modifyCompProps)) {
|
|
754
|
+
component = this.modifyCompProps(compName, component);
|
|
755
|
+
}
|
|
756
|
+
for (let prop in component) {
|
|
757
|
+
if (hasOwn(component, prop)) {
|
|
758
|
+
let propValue = component[prop];
|
|
759
|
+
if (prop.startsWith('bind') || propValue === 'eh') {
|
|
760
|
+
propValue = 'eh';
|
|
761
|
+
}
|
|
762
|
+
else if (propValue === '') {
|
|
763
|
+
const propInCamelCase = toCamelCase(prop);
|
|
764
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
765
|
+
propValue = `i.${propAlias}`;
|
|
766
|
+
}
|
|
767
|
+
else if (isBooleanStringLiteral(propValue) || isNumber(+propValue)) {
|
|
768
|
+
const propInCamelCase = toCamelCase(prop);
|
|
769
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
770
|
+
propValue = this.supportXS
|
|
771
|
+
? `xs.b(i.${propAlias},${propValue})`
|
|
772
|
+
: `i.${propAlias}===undefined?${propValue}:i.${propAlias}`;
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
const propInCamelCase = toCamelCase(prop);
|
|
776
|
+
const propAlias = componentAlias[propInCamelCase] || propInCamelCase;
|
|
777
|
+
propValue = `i.${propAlias}||${propValue || singleQuote('')}`;
|
|
778
|
+
}
|
|
779
|
+
prop = this.replacePropName(prop, propValue, compName, componentAlias);
|
|
780
|
+
newComp[prop] = propValue;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (compName !== 'block') {
|
|
784
|
+
Object.assign(newComp, styles, this.getEvents());
|
|
785
|
+
}
|
|
786
|
+
if (compName === 'swiper-item') {
|
|
787
|
+
delete newComp.style;
|
|
788
|
+
}
|
|
789
|
+
if (compName === 'view') {
|
|
790
|
+
const reg = /^(bind|on)(touchmove|TouchMove)$/;
|
|
791
|
+
const comp = Object.assign({}, newComp);
|
|
792
|
+
Object.keys(comp).forEach(originKey => {
|
|
793
|
+
if (!reg.test(originKey))
|
|
794
|
+
return;
|
|
795
|
+
const key = originKey.replace(reg, 'catch$2');
|
|
796
|
+
comp[key] = comp[originKey];
|
|
797
|
+
delete comp[originKey];
|
|
798
|
+
});
|
|
799
|
+
result['catch-view'] = comp;
|
|
800
|
+
}
|
|
801
|
+
if (compName === 'view' || compName === 'text' || compName === 'image') {
|
|
802
|
+
const comp = {};
|
|
803
|
+
Object.keys(newComp).forEach(key => {
|
|
804
|
+
const value = newComp[key];
|
|
805
|
+
if (value !== 'eh')
|
|
806
|
+
comp[key] = value;
|
|
807
|
+
});
|
|
808
|
+
result[`static-${compName}`] = comp;
|
|
809
|
+
if (compName === 'view') {
|
|
810
|
+
result['pure-view'] = {
|
|
811
|
+
style: comp.style,
|
|
812
|
+
class: comp.class
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (compName === 'slot' || compName === 'slot-view') {
|
|
817
|
+
result[compName] = Object.assign({ slot: 'i.name' }, styles);
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
result[compName] = newComp;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return result;
|
|
825
|
+
}
|
|
826
|
+
buildBaseTemplate() {
|
|
827
|
+
const Adapter = this.Adapter;
|
|
828
|
+
const data = !this.isSupportRecursive && this.supportXS
|
|
829
|
+
? `${this.dataKeymap('i:item,l:\'\'')}`
|
|
830
|
+
: this.dataKeymap('i:item');
|
|
831
831
|
return `${this.buildXsTemplate()}
|
|
832
832
|
<template name="taro_tmpl">
|
|
833
833
|
<block ${Adapter.for}="{{root.cn}}" ${Adapter.key}="sid">
|
|
834
|
-
<template is="tmpl_0_${"container" /* Container */}" data="{{${data}}}" />
|
|
834
|
+
<template is="tmpl_0_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />
|
|
835
835
|
</block>
|
|
836
836
|
</template>
|
|
837
|
-
`;
|
|
838
|
-
}
|
|
839
|
-
buildThirdPartyAttr(attrs, patcher = {}) {
|
|
840
|
-
return Array.from(attrs).reduce((str, attr) => {
|
|
841
|
-
if (attr.startsWith('@')) {
|
|
842
|
-
// vue2
|
|
843
|
-
let value = attr.slice(1);
|
|
844
|
-
if (value.indexOf('-') > -1) {
|
|
845
|
-
value = `:${value}`;
|
|
846
|
-
}
|
|
847
|
-
return str + `bind${value}="eh" `;
|
|
848
|
-
}
|
|
849
|
-
else if (attr.startsWith('bind')) {
|
|
850
|
-
return str + `${attr}="eh" `;
|
|
851
|
-
}
|
|
852
|
-
else if (attr.startsWith('on')) {
|
|
853
|
-
// react, vue3
|
|
854
|
-
let value = toKebabCase(attr.slice(2));
|
|
855
|
-
if (value.indexOf('-') > -1) {
|
|
856
|
-
// 兼容如 vant 某些组件的 bind:a-b 这类属性
|
|
857
|
-
value = `:${value}`;
|
|
858
|
-
}
|
|
859
|
-
return str + `bind${value}="eh" `;
|
|
860
|
-
}
|
|
861
|
-
else if (attr === 'class') {
|
|
862
|
-
return str + `class="{{i.${"cl" /* Class */}}}" `;
|
|
863
|
-
}
|
|
864
|
-
else if (attr === 'style') {
|
|
865
|
-
return str + `style="{{i.${"st" /* Style */}}}" `;
|
|
866
|
-
}
|
|
867
|
-
const patchValue = patcher[attr];
|
|
868
|
-
if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
|
|
869
|
-
const propValue = this.supportXS
|
|
870
|
-
? `xs.b(i.${toCamelCase(attr)},${patchValue})`
|
|
871
|
-
: `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
|
|
872
|
-
return str + `${attr}="{{${propValue}}}" `;
|
|
873
|
-
}
|
|
874
|
-
return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
|
|
875
|
-
}, '');
|
|
876
|
-
}
|
|
877
|
-
buildComponentTemplate(comp, level) {
|
|
878
|
-
return this.focusComponents.has(comp.nodeName)
|
|
879
|
-
? this.buildFocusComponentTemplte(comp, level)
|
|
880
|
-
: this.buildStandardComponentTemplate(comp, level);
|
|
881
|
-
}
|
|
882
|
-
getChildren(comp, level) {
|
|
883
|
-
const { isSupportRecursive, Adapter, supportXS } = this;
|
|
884
|
-
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
885
|
-
const data = !this.isSupportRecursive && supportXS
|
|
886
|
-
? `${this.dataKeymap('i:item,l:l')}`
|
|
887
|
-
: this.dataKeymap('i:item');
|
|
888
|
-
let child = supportXS
|
|
889
|
-
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
890
|
-
: `<template is="tmpl_${nextLevel}_${"container" /* Container */}" data="{{${data}}}" />`;
|
|
891
|
-
if (isFunction(this.modifyLoopBody)) {
|
|
892
|
-
child = this.modifyLoopBody(child, comp.nodeName);
|
|
893
|
-
}
|
|
894
|
-
let children = this.voidElements.has(comp.nodeName)
|
|
895
|
-
? ''
|
|
837
|
+
`;
|
|
838
|
+
}
|
|
839
|
+
buildThirdPartyAttr(attrs, patcher = {}) {
|
|
840
|
+
return Array.from(attrs).reduce((str, attr) => {
|
|
841
|
+
if (attr.startsWith('@')) {
|
|
842
|
+
// vue2
|
|
843
|
+
let value = attr.slice(1);
|
|
844
|
+
if (value.indexOf('-') > -1) {
|
|
845
|
+
value = `:${value}`;
|
|
846
|
+
}
|
|
847
|
+
return str + `bind${value}="eh" `;
|
|
848
|
+
}
|
|
849
|
+
else if (attr.startsWith('bind')) {
|
|
850
|
+
return str + `${attr}="eh" `;
|
|
851
|
+
}
|
|
852
|
+
else if (attr.startsWith('on')) {
|
|
853
|
+
// react, vue3
|
|
854
|
+
let value = toKebabCase(attr.slice(2));
|
|
855
|
+
if (value.indexOf('-') > -1) {
|
|
856
|
+
// 兼容如 vant 某些组件的 bind:a-b 这类属性
|
|
857
|
+
value = `:${value}`;
|
|
858
|
+
}
|
|
859
|
+
return str + `bind${value}="eh" `;
|
|
860
|
+
}
|
|
861
|
+
else if (attr === 'class') {
|
|
862
|
+
return str + `class="{{i.${"cl" /* Shortcuts.Class */}}}" `;
|
|
863
|
+
}
|
|
864
|
+
else if (attr === 'style') {
|
|
865
|
+
return str + `style="{{i.${"st" /* Shortcuts.Style */}}}" `;
|
|
866
|
+
}
|
|
867
|
+
const patchValue = patcher[attr];
|
|
868
|
+
if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
|
|
869
|
+
const propValue = this.supportXS
|
|
870
|
+
? `xs.b(i.${toCamelCase(attr)},${patchValue})`
|
|
871
|
+
: `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
|
|
872
|
+
return str + `${attr}="{{${propValue}}}" `;
|
|
873
|
+
}
|
|
874
|
+
return str + `${attr}="{{i.${toCamelCase(attr)}}}" `;
|
|
875
|
+
}, '');
|
|
876
|
+
}
|
|
877
|
+
buildComponentTemplate(comp, level) {
|
|
878
|
+
return this.focusComponents.has(comp.nodeName)
|
|
879
|
+
? this.buildFocusComponentTemplte(comp, level)
|
|
880
|
+
: this.buildStandardComponentTemplate(comp, level);
|
|
881
|
+
}
|
|
882
|
+
getChildren(comp, level) {
|
|
883
|
+
const { isSupportRecursive, Adapter, supportXS } = this;
|
|
884
|
+
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
885
|
+
const data = !this.isSupportRecursive && supportXS
|
|
886
|
+
? `${this.dataKeymap('i:item,l:l')}`
|
|
887
|
+
: this.dataKeymap('i:item');
|
|
888
|
+
let child = supportXS
|
|
889
|
+
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
890
|
+
: `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
891
|
+
if (isFunction(this.modifyLoopBody)) {
|
|
892
|
+
child = this.modifyLoopBody(child, comp.nodeName);
|
|
893
|
+
}
|
|
894
|
+
let children = this.voidElements.has(comp.nodeName)
|
|
895
|
+
? ''
|
|
896
896
|
: `
|
|
897
|
-
<block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
|
|
897
|
+
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
898
898
|
${indent(child, 6)}
|
|
899
899
|
</block>
|
|
900
|
-
`;
|
|
901
|
-
if (isFunction(this.modifyLoopContainer)) {
|
|
902
|
-
children = this.modifyLoopContainer(children, comp.nodeName);
|
|
903
|
-
}
|
|
904
|
-
return children;
|
|
905
|
-
}
|
|
906
|
-
buildFocusComponentTemplte(comp, level) {
|
|
907
|
-
const children = this.getChildren(comp, level);
|
|
908
|
-
const nodeName = comp.nodeName;
|
|
909
|
-
const nodeAlias = comp.nodeAlias;
|
|
910
|
-
const attrs = Object.assign({}, comp.attributes);
|
|
911
|
-
const templateName = this.supportXS
|
|
912
|
-
? `xs.c(i, 'tmpl_${level}_')`
|
|
913
|
-
: `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
|
|
914
|
-
delete attrs.focus;
|
|
900
|
+
`;
|
|
901
|
+
if (isFunction(this.modifyLoopContainer)) {
|
|
902
|
+
children = this.modifyLoopContainer(children, comp.nodeName);
|
|
903
|
+
}
|
|
904
|
+
return children;
|
|
905
|
+
}
|
|
906
|
+
buildFocusComponentTemplte(comp, level) {
|
|
907
|
+
const children = this.getChildren(comp, level);
|
|
908
|
+
const nodeName = comp.nodeName;
|
|
909
|
+
const nodeAlias = comp.nodeAlias;
|
|
910
|
+
const attrs = Object.assign({}, comp.attributes);
|
|
911
|
+
const templateName = this.supportXS
|
|
912
|
+
? `xs.c(i, 'tmpl_${level}_')`
|
|
913
|
+
: `i.focus ? 'tmpl_${level}_${nodeAlias}_focus' : 'tmpl_${level}_${nodeAlias}_blur'`;
|
|
914
|
+
delete attrs.focus;
|
|
915
915
|
let res = `
|
|
916
916
|
<template name="tmpl_${level}_${nodeAlias}">
|
|
917
917
|
<template is="{{${templateName}}}" data="{{${this.dataKeymap('i:i')}${children ? ',cid:cid' : ''}}}" />
|
|
@@ -924,260 +924,260 @@ class BaseTemplate {
|
|
|
924
924
|
<template name="tmpl_${level}_${nodeAlias}_blur">
|
|
925
925
|
<${nodeName} ${this.buildAttribute(attrs, nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
926
926
|
</template>
|
|
927
|
-
`;
|
|
928
|
-
if (isFunction(this.modifyTemplateResult)) {
|
|
929
|
-
res = this.modifyTemplateResult(res, nodeName, level, children);
|
|
930
|
-
}
|
|
931
|
-
return res;
|
|
932
|
-
}
|
|
933
|
-
buildStandardComponentTemplate(comp, level) {
|
|
934
|
-
const children = this.getChildren(comp, level);
|
|
935
|
-
const nodeAlias = comp.nodeAlias;
|
|
936
|
-
let nodeName = '';
|
|
937
|
-
switch (comp.nodeName) {
|
|
938
|
-
case 'slot':
|
|
939
|
-
case 'slot-view':
|
|
940
|
-
case 'catch-view':
|
|
941
|
-
case 'static-view':
|
|
942
|
-
case 'pure-view':
|
|
943
|
-
nodeName = 'view';
|
|
944
|
-
break;
|
|
945
|
-
case 'static-text':
|
|
946
|
-
nodeName = 'text';
|
|
947
|
-
break;
|
|
948
|
-
case 'static-image':
|
|
949
|
-
nodeName = 'image';
|
|
950
|
-
break;
|
|
951
|
-
default:
|
|
952
|
-
nodeName = comp.nodeName;
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
927
|
+
`;
|
|
928
|
+
if (isFunction(this.modifyTemplateResult)) {
|
|
929
|
+
res = this.modifyTemplateResult(res, nodeName, level, children);
|
|
930
|
+
}
|
|
931
|
+
return res;
|
|
932
|
+
}
|
|
933
|
+
buildStandardComponentTemplate(comp, level) {
|
|
934
|
+
const children = this.getChildren(comp, level);
|
|
935
|
+
const nodeAlias = comp.nodeAlias;
|
|
936
|
+
let nodeName = '';
|
|
937
|
+
switch (comp.nodeName) {
|
|
938
|
+
case 'slot':
|
|
939
|
+
case 'slot-view':
|
|
940
|
+
case 'catch-view':
|
|
941
|
+
case 'static-view':
|
|
942
|
+
case 'pure-view':
|
|
943
|
+
nodeName = 'view';
|
|
944
|
+
break;
|
|
945
|
+
case 'static-text':
|
|
946
|
+
nodeName = 'text';
|
|
947
|
+
break;
|
|
948
|
+
case 'static-image':
|
|
949
|
+
nodeName = 'image';
|
|
950
|
+
break;
|
|
951
|
+
default:
|
|
952
|
+
nodeName = comp.nodeName;
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
955
|
let res = `
|
|
956
956
|
<template name="tmpl_${level}_${nodeAlias}">
|
|
957
957
|
<${nodeName} ${this.buildAttribute(comp.attributes, comp.nodeName)} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">${children}</${nodeName}>
|
|
958
958
|
</template>
|
|
959
|
-
`;
|
|
960
|
-
if (isFunction(this.modifyTemplateResult)) {
|
|
961
|
-
res = this.modifyTemplateResult(res, comp.nodeName, level, children);
|
|
962
|
-
}
|
|
963
|
-
return res;
|
|
964
|
-
}
|
|
965
|
-
buildPlainTextTemplate(level) {
|
|
959
|
+
`;
|
|
960
|
+
if (isFunction(this.modifyTemplateResult)) {
|
|
961
|
+
res = this.modifyTemplateResult(res, comp.nodeName, level, children);
|
|
962
|
+
}
|
|
963
|
+
return res;
|
|
964
|
+
}
|
|
965
|
+
buildPlainTextTemplate(level) {
|
|
966
966
|
return `
|
|
967
967
|
<template name="tmpl_${level}_${this.componentsAlias['#text']._num}">
|
|
968
|
-
<block>{{i.${"v" /* Text */}}}</block>
|
|
968
|
+
<block>{{i.${"v" /* Shortcuts.Text */}}}</block>
|
|
969
969
|
</template>
|
|
970
|
-
`;
|
|
971
|
-
}
|
|
972
|
-
buildThirdPartyTemplate(level, componentConfig) {
|
|
973
|
-
const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
|
|
974
|
-
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
975
|
-
let template = '';
|
|
976
|
-
const data = !isSupportRecursive && supportXS
|
|
977
|
-
? `${this.dataKeymap('i:item,l:l')}`
|
|
978
|
-
: this.dataKeymap('i:item');
|
|
979
|
-
componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
|
|
980
|
-
if (compName === 'custom-wrapper') {
|
|
970
|
+
`;
|
|
971
|
+
}
|
|
972
|
+
buildThirdPartyTemplate(level, componentConfig) {
|
|
973
|
+
const { Adapter, isSupportRecursive, supportXS, nestElements } = this;
|
|
974
|
+
const nextLevel = isSupportRecursive ? 0 : level + 1;
|
|
975
|
+
let template = '';
|
|
976
|
+
const data = !isSupportRecursive && supportXS
|
|
977
|
+
? `${this.dataKeymap('i:item,l:l')}`
|
|
978
|
+
: this.dataKeymap('i:item');
|
|
979
|
+
componentConfig.thirdPartyComponents.forEach((attrs, compName) => {
|
|
980
|
+
if (compName === 'custom-wrapper') {
|
|
981
981
|
template += `
|
|
982
982
|
<template name="tmpl_${level}_${compName}">
|
|
983
983
|
<${compName} i="{{i}}" l="{{l}}" id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
|
|
984
984
|
</${compName}>
|
|
985
985
|
</template>
|
|
986
|
-
`;
|
|
987
|
-
}
|
|
988
|
-
else {
|
|
989
|
-
if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
|
|
990
|
-
return;
|
|
991
|
-
let child = supportXS
|
|
992
|
-
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
993
|
-
: `<template is="tmpl_${nextLevel}_${"container" /* Container */}" data="{{${data}}}" />`;
|
|
994
|
-
if (isFunction(this.modifyThirdPartyLoopBody)) {
|
|
995
|
-
child = this.modifyThirdPartyLoopBody(child, compName);
|
|
996
|
-
}
|
|
986
|
+
`;
|
|
987
|
+
}
|
|
988
|
+
else {
|
|
989
|
+
if (!isSupportRecursive && supportXS && nestElements.has(compName) && level + 1 > nestElements.get(compName))
|
|
990
|
+
return;
|
|
991
|
+
let child = supportXS
|
|
992
|
+
? `<template is="{{xs.e(${isSupportRecursive ? 0 : 'cid+1'})}}" data="{{${data}}}" />`
|
|
993
|
+
: `<template is="tmpl_${nextLevel}_${"container" /* Shortcuts.Container */}" data="{{${data}}}" />`;
|
|
994
|
+
if (isFunction(this.modifyThirdPartyLoopBody)) {
|
|
995
|
+
child = this.modifyThirdPartyLoopBody(child, compName);
|
|
996
|
+
}
|
|
997
997
|
template += `
|
|
998
998
|
<template name="tmpl_${level}_${compName}">
|
|
999
999
|
<${compName} ${this.buildThirdPartyAttr(attrs, this.thirdPartyPatcher[compName] || {})} id="{{i.uid||i.sid}}" data-sid="{{i.sid}}">
|
|
1000
|
-
<block ${Adapter.for}="{{i.${"cn" /* Childnodes */}}}" ${Adapter.key}="sid">
|
|
1000
|
+
<block ${Adapter.for}="{{i.${"cn" /* Shortcuts.Childnodes */}}}" ${Adapter.key}="sid">
|
|
1001
1001
|
${child}
|
|
1002
1002
|
</block>
|
|
1003
1003
|
</${compName}>
|
|
1004
1004
|
</template>
|
|
1005
|
-
`;
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
return template;
|
|
1009
|
-
}
|
|
1010
|
-
buildContainerTemplate(level, restart = false) {
|
|
1011
|
-
let tmpl = '';
|
|
1012
|
-
if (restart) {
|
|
1005
|
+
`;
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
return template;
|
|
1009
|
+
}
|
|
1010
|
+
buildContainerTemplate(level, restart = false) {
|
|
1011
|
+
let tmpl = '';
|
|
1012
|
+
if (restart) {
|
|
1013
1013
|
tmpl = `<block ${this.Adapter.if}="{{i.nn === '#text'}}">
|
|
1014
1014
|
<template is="tmpl_0_#text" data="{{i:i}}" />
|
|
1015
1015
|
</block>
|
|
1016
1016
|
<block ${this.Adapter.else}>
|
|
1017
1017
|
${!this.isSupportRecursive && this.supportXS ? '<comp i="{{i}}" l="{{l}}" />' : '<comp i="{{i}}" />'}
|
|
1018
|
-
</block>`;
|
|
1019
|
-
}
|
|
1020
|
-
else {
|
|
1021
|
-
const xs = !this.isSupportRecursive
|
|
1022
|
-
? `xs.a(${level}, i.${"nn" /* NodeName */}, l)`
|
|
1023
|
-
: `xs.a(${level}, i.${"nn" /* NodeName */})`;
|
|
1024
|
-
const data = !this.isSupportRecursive
|
|
1025
|
-
? `${this.dataKeymap(`i:i,cid:${level},l:xs.f(l,i.${"nn" /* NodeName */})`)}`
|
|
1026
|
-
: `${this.dataKeymap('i:i')}`;
|
|
1027
|
-
tmpl = this.supportXS
|
|
1028
|
-
? `<template is="{{${xs}}}" data="{{${data}}}" />`
|
|
1029
|
-
: `<template is="{{'tmpl_${level}_' + i.${"nn" /* NodeName */}}}" data="{{${this.dataKeymap('i:i')}}}" />`;
|
|
1030
|
-
}
|
|
1018
|
+
</block>`;
|
|
1019
|
+
}
|
|
1020
|
+
else {
|
|
1021
|
+
const xs = !this.isSupportRecursive
|
|
1022
|
+
? `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */}, l)`
|
|
1023
|
+
: `xs.a(${level}, i.${"nn" /* Shortcuts.NodeName */})`;
|
|
1024
|
+
const data = !this.isSupportRecursive
|
|
1025
|
+
? `${this.dataKeymap(`i:i,cid:${level},l:xs.f(l,i.${"nn" /* Shortcuts.NodeName */})`)}`
|
|
1026
|
+
: `${this.dataKeymap('i:i')}`;
|
|
1027
|
+
tmpl = this.supportXS
|
|
1028
|
+
? `<template is="{{${xs}}}" data="{{${data}}}" />`
|
|
1029
|
+
: `<template is="{{'tmpl_${level}_' + i.${"nn" /* Shortcuts.NodeName */}}}" data="{{${this.dataKeymap('i:i')}}}" />`;
|
|
1030
|
+
}
|
|
1031
1031
|
return `
|
|
1032
|
-
<template name="tmpl_${level}_${"container" /* Container */}">
|
|
1032
|
+
<template name="tmpl_${level}_${"container" /* Shortcuts.Container */}">
|
|
1033
1033
|
${tmpl}
|
|
1034
1034
|
</template>
|
|
1035
|
-
`;
|
|
1036
|
-
}
|
|
1037
|
-
dataKeymap(keymap) {
|
|
1038
|
-
return keymap;
|
|
1039
|
-
}
|
|
1040
|
-
getEvents() {
|
|
1041
|
-
return events;
|
|
1042
|
-
}
|
|
1043
|
-
getAttrValue(value, _key, _nodeName) {
|
|
1044
|
-
return `{${value}}`;
|
|
1045
|
-
}
|
|
1046
|
-
buildXsTemplate() {
|
|
1047
|
-
return '';
|
|
1048
|
-
}
|
|
1049
|
-
mergeComponents(ctx, patch) {
|
|
1050
|
-
ctx.helper.recursiveMerge(this.internalComponents, patch);
|
|
1051
|
-
}
|
|
1052
|
-
mergeThirdPartyComponents(patch) {
|
|
1053
|
-
this.thirdPartyPatcher = patch;
|
|
1054
|
-
}
|
|
1055
|
-
buildXSTmplName() {
|
|
1035
|
+
`;
|
|
1036
|
+
}
|
|
1037
|
+
dataKeymap(keymap) {
|
|
1038
|
+
return keymap;
|
|
1039
|
+
}
|
|
1040
|
+
getEvents() {
|
|
1041
|
+
return events;
|
|
1042
|
+
}
|
|
1043
|
+
getAttrValue(value, _key, _nodeName) {
|
|
1044
|
+
return `{${value}}`;
|
|
1045
|
+
}
|
|
1046
|
+
buildXsTemplate() {
|
|
1047
|
+
return '';
|
|
1048
|
+
}
|
|
1049
|
+
mergeComponents(ctx, patch) {
|
|
1050
|
+
ctx.helper.recursiveMerge(this.internalComponents, patch);
|
|
1051
|
+
}
|
|
1052
|
+
mergeThirdPartyComponents(patch) {
|
|
1053
|
+
this.thirdPartyPatcher = patch;
|
|
1054
|
+
}
|
|
1055
|
+
buildXSTmplName() {
|
|
1056
1056
|
return `function (l, n) {
|
|
1057
1057
|
return 'tmpl_' + l + '_' + n
|
|
1058
|
-
}`;
|
|
1059
|
-
}
|
|
1060
|
-
buildXSTepFocus(nn) {
|
|
1058
|
+
}`;
|
|
1059
|
+
}
|
|
1060
|
+
buildXSTepFocus(nn) {
|
|
1061
1061
|
return `function(i, prefix) {
|
|
1062
1062
|
var s = i.focus !== undefined ? 'focus' : 'blur'
|
|
1063
1063
|
return prefix + i.${nn} + '_' + s
|
|
1064
|
-
}`;
|
|
1065
|
-
}
|
|
1066
|
-
buildXSTmpExtra() {
|
|
1067
|
-
return '';
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
class RecursiveTemplate extends BaseTemplate {
|
|
1071
|
-
constructor() {
|
|
1072
|
-
super(...arguments);
|
|
1073
|
-
this.isSupportRecursive = true;
|
|
1074
|
-
this.buildTemplate = (componentConfig) => {
|
|
1075
|
-
let template = this.buildBaseTemplate();
|
|
1076
|
-
if (!this.miniComponents) {
|
|
1077
|
-
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1078
|
-
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1079
|
-
}
|
|
1080
|
-
const ZERO_FLOOR = 0;
|
|
1081
|
-
const components = Object.keys(this.miniComponents)
|
|
1082
|
-
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
1083
|
-
template = components.reduce((current, nodeName) => {
|
|
1084
|
-
const attributes = this.miniComponents[nodeName];
|
|
1085
|
-
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1086
|
-
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
|
|
1087
|
-
}, template);
|
|
1088
|
-
template += this.buildPlainTextTemplate(ZERO_FLOOR);
|
|
1089
|
-
template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
|
|
1090
|
-
template += this.buildContainerTemplate(ZERO_FLOOR);
|
|
1091
|
-
return template;
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
class UnRecursiveTemplate extends BaseTemplate {
|
|
1096
|
-
constructor() {
|
|
1097
|
-
super(...arguments);
|
|
1098
|
-
this.isSupportRecursive = false;
|
|
1099
|
-
this._baseLevel = 16;
|
|
1100
|
-
this.buildTemplate = (componentConfig) => {
|
|
1101
|
-
this.componentConfig = componentConfig;
|
|
1102
|
-
if (!this.miniComponents) {
|
|
1103
|
-
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1104
|
-
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1105
|
-
}
|
|
1106
|
-
const components = Object.keys(this.miniComponents)
|
|
1107
|
-
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
1108
|
-
let template = this.buildBaseTemplate();
|
|
1109
|
-
for (let i = 0; i < this.baseLevel; i++) {
|
|
1110
|
-
template += this.supportXS
|
|
1111
|
-
? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
|
|
1112
|
-
: this.buildFloor(i, components, this.baseLevel === i + 1);
|
|
1113
|
-
}
|
|
1114
|
-
return template;
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
set baseLevel(lv) {
|
|
1118
|
-
this._baseLevel = lv;
|
|
1119
|
-
}
|
|
1120
|
-
get baseLevel() {
|
|
1121
|
-
return this._baseLevel;
|
|
1122
|
-
}
|
|
1123
|
-
buildFloor(level, components, restart = false) {
|
|
1124
|
-
if (restart)
|
|
1125
|
-
return this.buildContainerTemplate(level, restart);
|
|
1126
|
-
let template = components.reduce((current, nodeName) => {
|
|
1127
|
-
const attributes = this.miniComponents[nodeName];
|
|
1128
|
-
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1129
|
-
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1130
|
-
}, '');
|
|
1131
|
-
template += this.buildPlainTextTemplate(level);
|
|
1132
|
-
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1133
|
-
template += this.buildContainerTemplate(level, restart);
|
|
1134
|
-
return template;
|
|
1135
|
-
}
|
|
1136
|
-
buildOptimizeFloor(level, components, restart = false) {
|
|
1137
|
-
if (restart)
|
|
1138
|
-
return this.buildContainerTemplate(level, restart);
|
|
1139
|
-
let template = components.reduce((current, nodeName) => {
|
|
1140
|
-
if (level !== 0) {
|
|
1141
|
-
if (!this.nestElements.has(nodeName)) {
|
|
1142
|
-
// 不可嵌套自身的组件只需输出一层模板
|
|
1143
|
-
return current;
|
|
1144
|
-
}
|
|
1145
|
-
else {
|
|
1146
|
-
// 部分可嵌套自身的组件实际上不会嵌套过深,这里按阈值限制层数
|
|
1147
|
-
const max = this.nestElements.get(nodeName);
|
|
1148
|
-
if (max > 0 && level >= max) {
|
|
1149
|
-
return current;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
const attributes = this.miniComponents[nodeName];
|
|
1154
|
-
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1155
|
-
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1156
|
-
}, '');
|
|
1157
|
-
if (level === 0)
|
|
1158
|
-
template += this.buildPlainTextTemplate(level);
|
|
1159
|
-
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1160
|
-
template += this.buildContainerTemplate(level);
|
|
1161
|
-
return template;
|
|
1162
|
-
}
|
|
1163
|
-
buildXSTmplName() {
|
|
1164
|
-
const isLoopComps = [
|
|
1165
|
-
...Array.from(this.nestElements.keys()),
|
|
1166
|
-
...Array.from(this.componentConfig.thirdPartyComponents.keys())
|
|
1167
|
-
];
|
|
1168
|
-
const isLoopCompsSet = new Set(isLoopComps);
|
|
1169
|
-
const hasMaxComps = [];
|
|
1170
|
-
this.nestElements.forEach((max, comp) => {
|
|
1171
|
-
if (max > 1) {
|
|
1172
|
-
hasMaxComps.push(comp);
|
|
1173
|
-
}
|
|
1174
|
-
else if (max === 1 && isLoopCompsSet.has(comp)) {
|
|
1175
|
-
isLoopCompsSet.delete(comp);
|
|
1176
|
-
}
|
|
1177
|
-
});
|
|
1178
|
-
const componentsAlias = this.componentsAlias;
|
|
1179
|
-
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1180
|
-
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1064
|
+
}`;
|
|
1065
|
+
}
|
|
1066
|
+
buildXSTmpExtra() {
|
|
1067
|
+
return '';
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
class RecursiveTemplate extends BaseTemplate {
|
|
1071
|
+
constructor() {
|
|
1072
|
+
super(...arguments);
|
|
1073
|
+
this.isSupportRecursive = true;
|
|
1074
|
+
this.buildTemplate = (componentConfig) => {
|
|
1075
|
+
let template = this.buildBaseTemplate();
|
|
1076
|
+
if (!this.miniComponents) {
|
|
1077
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1078
|
+
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1079
|
+
}
|
|
1080
|
+
const ZERO_FLOOR = 0;
|
|
1081
|
+
const components = Object.keys(this.miniComponents)
|
|
1082
|
+
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
1083
|
+
template = components.reduce((current, nodeName) => {
|
|
1084
|
+
const attributes = this.miniComponents[nodeName];
|
|
1085
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1086
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, ZERO_FLOOR);
|
|
1087
|
+
}, template);
|
|
1088
|
+
template += this.buildPlainTextTemplate(ZERO_FLOOR);
|
|
1089
|
+
template += this.buildThirdPartyTemplate(ZERO_FLOOR, componentConfig);
|
|
1090
|
+
template += this.buildContainerTemplate(ZERO_FLOOR);
|
|
1091
|
+
return template;
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
class UnRecursiveTemplate extends BaseTemplate {
|
|
1096
|
+
constructor() {
|
|
1097
|
+
super(...arguments);
|
|
1098
|
+
this.isSupportRecursive = false;
|
|
1099
|
+
this._baseLevel = 16;
|
|
1100
|
+
this.buildTemplate = (componentConfig) => {
|
|
1101
|
+
this.componentConfig = componentConfig;
|
|
1102
|
+
if (!this.miniComponents) {
|
|
1103
|
+
this.componentsAlias = getComponentsAlias(this.internalComponents);
|
|
1104
|
+
this.miniComponents = this.createMiniComponents(this.internalComponents);
|
|
1105
|
+
}
|
|
1106
|
+
const components = Object.keys(this.miniComponents)
|
|
1107
|
+
.filter(c => componentConfig.includes.size && !componentConfig.includeAll ? componentConfig.includes.has(c) : true);
|
|
1108
|
+
let template = this.buildBaseTemplate();
|
|
1109
|
+
for (let i = 0; i < this.baseLevel; i++) {
|
|
1110
|
+
template += this.supportXS
|
|
1111
|
+
? this.buildOptimizeFloor(i, components, this.baseLevel === i + 1)
|
|
1112
|
+
: this.buildFloor(i, components, this.baseLevel === i + 1);
|
|
1113
|
+
}
|
|
1114
|
+
return template;
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
set baseLevel(lv) {
|
|
1118
|
+
this._baseLevel = lv;
|
|
1119
|
+
}
|
|
1120
|
+
get baseLevel() {
|
|
1121
|
+
return this._baseLevel;
|
|
1122
|
+
}
|
|
1123
|
+
buildFloor(level, components, restart = false) {
|
|
1124
|
+
if (restart)
|
|
1125
|
+
return this.buildContainerTemplate(level, restart);
|
|
1126
|
+
let template = components.reduce((current, nodeName) => {
|
|
1127
|
+
const attributes = this.miniComponents[nodeName];
|
|
1128
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1129
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1130
|
+
}, '');
|
|
1131
|
+
template += this.buildPlainTextTemplate(level);
|
|
1132
|
+
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1133
|
+
template += this.buildContainerTemplate(level, restart);
|
|
1134
|
+
return template;
|
|
1135
|
+
}
|
|
1136
|
+
buildOptimizeFloor(level, components, restart = false) {
|
|
1137
|
+
if (restart)
|
|
1138
|
+
return this.buildContainerTemplate(level, restart);
|
|
1139
|
+
let template = components.reduce((current, nodeName) => {
|
|
1140
|
+
if (level !== 0) {
|
|
1141
|
+
if (!this.nestElements.has(nodeName)) {
|
|
1142
|
+
// 不可嵌套自身的组件只需输出一层模板
|
|
1143
|
+
return current;
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
// 部分可嵌套自身的组件实际上不会嵌套过深,这里按阈值限制层数
|
|
1147
|
+
const max = this.nestElements.get(nodeName);
|
|
1148
|
+
if (max > 0 && level >= max) {
|
|
1149
|
+
return current;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const attributes = this.miniComponents[nodeName];
|
|
1154
|
+
const nodeAlias = this.componentsAlias[nodeName]._num;
|
|
1155
|
+
return current + this.buildComponentTemplate({ nodeName, nodeAlias, attributes }, level);
|
|
1156
|
+
}, '');
|
|
1157
|
+
if (level === 0)
|
|
1158
|
+
template += this.buildPlainTextTemplate(level);
|
|
1159
|
+
template += this.buildThirdPartyTemplate(level, this.componentConfig);
|
|
1160
|
+
template += this.buildContainerTemplate(level);
|
|
1161
|
+
return template;
|
|
1162
|
+
}
|
|
1163
|
+
buildXSTmplName() {
|
|
1164
|
+
const isLoopComps = [
|
|
1165
|
+
...Array.from(this.nestElements.keys()),
|
|
1166
|
+
...Array.from(this.componentConfig.thirdPartyComponents.keys())
|
|
1167
|
+
];
|
|
1168
|
+
const isLoopCompsSet = new Set(isLoopComps);
|
|
1169
|
+
const hasMaxComps = [];
|
|
1170
|
+
this.nestElements.forEach((max, comp) => {
|
|
1171
|
+
if (max > 1) {
|
|
1172
|
+
hasMaxComps.push(comp);
|
|
1173
|
+
}
|
|
1174
|
+
else if (max === 1 && isLoopCompsSet.has(comp)) {
|
|
1175
|
+
isLoopCompsSet.delete(comp);
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
const componentsAlias = this.componentsAlias;
|
|
1179
|
+
const listA = Array.from(isLoopCompsSet).map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1180
|
+
const listB = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1181
1181
|
return `function (l, n, s) {
|
|
1182
1182
|
var a = ${JSON.stringify(listA)}
|
|
1183
1183
|
var b = ${JSON.stringify(listB)}
|
|
@@ -1193,16 +1193,16 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1193
1193
|
l = depth
|
|
1194
1194
|
}
|
|
1195
1195
|
return 'tmpl_' + l + '_' + n
|
|
1196
|
-
}`;
|
|
1197
|
-
}
|
|
1198
|
-
buildXSTmpExtra() {
|
|
1199
|
-
const hasMaxComps = [];
|
|
1200
|
-
this.nestElements.forEach((max, comp) => {
|
|
1201
|
-
if (max > 1)
|
|
1202
|
-
hasMaxComps.push(comp);
|
|
1203
|
-
});
|
|
1204
|
-
const componentsAlias = this.componentsAlias;
|
|
1205
|
-
const listA = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1196
|
+
}`;
|
|
1197
|
+
}
|
|
1198
|
+
buildXSTmpExtra() {
|
|
1199
|
+
const hasMaxComps = [];
|
|
1200
|
+
this.nestElements.forEach((max, comp) => {
|
|
1201
|
+
if (max > 1)
|
|
1202
|
+
hasMaxComps.push(comp);
|
|
1203
|
+
});
|
|
1204
|
+
const componentsAlias = this.componentsAlias;
|
|
1205
|
+
const listA = hasMaxComps.map(item => { var _a; return ((_a = componentsAlias[item]) === null || _a === void 0 ? void 0 : _a._num) || item; });
|
|
1206
1206
|
return `f: function (l, n) {
|
|
1207
1207
|
var b = ${JSON.stringify(listA)}
|
|
1208
1208
|
if (b.indexOf(n) > -1) {
|
|
@@ -1210,8 +1210,8 @@ class UnRecursiveTemplate extends BaseTemplate {
|
|
|
1210
1210
|
l += n
|
|
1211
1211
|
}
|
|
1212
1212
|
return l
|
|
1213
|
-
}`;
|
|
1214
|
-
}
|
|
1213
|
+
}`;
|
|
1214
|
+
}
|
|
1215
1215
|
}
|
|
1216
1216
|
|
|
1217
1217
|
exports.BaseTemplate = BaseTemplate;
|