@mpxjs/webpack-plugin 2.9.70-alpha.0 → 2.9.71
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/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +0 -14
- package/lib/dependencies/ResolveDependency.js +0 -5
- package/lib/index.js +7 -38
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +0 -53
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/picker-view.js +1 -5
- package/lib/platform/template/wx/component-config/rich-text.js +6 -2
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -5
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +1 -131
- package/lib/resolve-loader.js +1 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +39 -37
- package/lib/runtime/components/react/dist/mpx-button.jsx +16 -44
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +93 -58
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +10 -14
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +94 -81
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +19 -16
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +10 -11
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +11 -4
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +31 -8
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +435 -371
- package/lib/runtime/components/react/dist/mpx-view.jsx +18 -53
- package/lib/runtime/components/react/dist/pickerFaces.js +3 -8
- package/lib/runtime/components/react/dist/pickerVIewContext.js +5 -0
- package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerViewIndicator.jsx} +6 -6
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +27 -10
- package/lib/runtime/components/react/dist/utils.jsx +162 -70
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +236 -182
- package/lib/runtime/components/react/mpx-button.tsx +27 -69
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
- package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
- package/lib/runtime/components/react/mpx-form.tsx +15 -20
- package/lib/runtime/components/react/mpx-icon.tsx +2 -2
- package/lib/runtime/components/react/mpx-image.tsx +87 -47
- package/lib/runtime/components/react/mpx-input.tsx +24 -32
- package/lib/runtime/components/react/mpx-label.tsx +12 -14
- package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
- package/lib/runtime/components/react/mpx-movable-view.tsx +133 -92
- package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +76 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +206 -183
- package/lib/runtime/components/react/mpx-picker-view.tsx +49 -48
- package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
- package/lib/runtime/components/react/mpx-radio.tsx +19 -25
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +53 -43
- package/lib/runtime/components/react/mpx-swiper-item.tsx +45 -11
- package/lib/runtime/components/react/mpx-swiper.tsx +742 -0
- package/lib/runtime/components/react/mpx-switch.tsx +19 -15
- package/lib/runtime/components/react/mpx-text.tsx +8 -16
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +28 -77
- package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
- package/lib/runtime/components/react/pickerFaces.ts +10 -7
- package/lib/runtime/components/react/pickerVIewContext.ts +27 -0
- package/lib/runtime/components/react/pickerViewIndicator.tsx +34 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/types/{getInnerListeners.ts → getInnerListeners.d.ts} +4 -5
- package/lib/runtime/components/react/types/global.d.ts +12 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +60 -15
- package/lib/runtime/components/react/utils.tsx +175 -71
- package/lib/runtime/components/web/mpx-checkbox.vue +1 -1
- package/lib/runtime/components/web/mpx-picker-view-column.vue +9 -4
- package/lib/runtime/components/web/mpx-web-view.vue +34 -20
- package/lib/runtime/optionProcessor.js +0 -22
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/compiler.js +91 -39
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +9 -5
- package/lib/wxss/loader.js +15 -2
- package/package.json +4 -7
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/runtime/components/react/dist/types/common.js +0 -1
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +0 -1
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -527
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/react/pickerOverlay.tsx +0 -32
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
- package/lib/runtime/components/tenon/tenon-button.vue +0 -309
- package/lib/runtime/components/tenon/tenon-image.vue +0 -66
- package/lib/runtime/components/tenon/tenon-input.vue +0 -171
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
- package/lib/runtime/components/tenon/tenon-text.vue +0 -70
- package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/web/event.js +0 -105
- package/lib/runtime/optionProcessor.tenon.js +0 -84
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -117
- package/lib/tenon/processJSON.js +0 -352
- package/lib/tenon/processScript.js +0 -203
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -126
- package/lib/tenon/script-helper.js +0 -223
- package/lib/utils/get-relative-path.js +0 -25
- /package/lib/runtime/components/react/types/{common.ts → common.d.ts} +0 -0
|
@@ -9,7 +9,7 @@ const { dash2hump } = require('../../../utils/hump-dash')
|
|
|
9
9
|
|
|
10
10
|
module.exports = function getSpec ({ warn, error }) {
|
|
11
11
|
const spec = {
|
|
12
|
-
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android'
|
|
12
|
+
supportedModes: ['ali', 'swan', 'qq', 'tt', 'web', 'qa', 'jd', 'dd', 'ios', 'android'],
|
|
13
13
|
// props预处理
|
|
14
14
|
preProps: [],
|
|
15
15
|
// props后处理
|
|
@@ -28,15 +28,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
28
28
|
value: parsed.result
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
tenon ({ name, value }) {
|
|
33
|
-
const parsed = parseMustacheWithContext(value)
|
|
34
|
-
if (parsed.hasBinding) {
|
|
35
|
-
return {
|
|
36
|
-
name: name === 'animation' ? 'v-' + name : ':' + name,
|
|
37
|
-
value: parsed.result
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
31
|
}
|
|
41
32
|
}
|
|
42
33
|
],
|
|
@@ -99,16 +90,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
99
90
|
name: 'v-for',
|
|
100
91
|
value: `(${itemName}, ${indexName}) in ${parsed.result}`
|
|
101
92
|
}
|
|
102
|
-
},
|
|
103
|
-
tenon ({ value }, { el }) {
|
|
104
|
-
const parsed = parseMustacheWithContext(value)
|
|
105
|
-
const attrsMap = el.attrsMap
|
|
106
|
-
const itemName = attrsMap['wx:for-item'] || 'item'
|
|
107
|
-
const indexName = attrsMap['wx:for-index'] || 'index'
|
|
108
|
-
return {
|
|
109
|
-
name: 'v-for',
|
|
110
|
-
value: `(${itemName}, ${indexName}) in ${parsed.result}`
|
|
111
|
-
}
|
|
112
93
|
}
|
|
113
94
|
},
|
|
114
95
|
{
|
|
@@ -134,25 +115,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
134
115
|
name: ':key',
|
|
135
116
|
value
|
|
136
117
|
}
|
|
137
|
-
},
|
|
138
|
-
tenon ({ value }, { el }) {
|
|
139
|
-
// vue的template中不能包含key,对应于小程序中的block
|
|
140
|
-
if (el.tag === 'block') return false
|
|
141
|
-
const itemName = el.attrsMap['wx:for-item'] || 'item'
|
|
142
|
-
const keyName = value
|
|
143
|
-
if (value === '*this') {
|
|
144
|
-
value = itemName
|
|
145
|
-
} else {
|
|
146
|
-
if (isValidIdentifierStr(keyName)) {
|
|
147
|
-
value = `${itemName}.${keyName}`
|
|
148
|
-
} else {
|
|
149
|
-
value = `${itemName}['${keyName}']`
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
name: ':key',
|
|
154
|
-
value
|
|
155
|
-
}
|
|
156
118
|
}
|
|
157
119
|
},
|
|
158
120
|
{
|
|
@@ -163,9 +125,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
163
125
|
},
|
|
164
126
|
web () {
|
|
165
127
|
return false
|
|
166
|
-
},
|
|
167
|
-
tenon () {
|
|
168
|
-
return false
|
|
169
128
|
}
|
|
170
129
|
},
|
|
171
130
|
{
|
|
@@ -208,49 +167,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
208
167
|
}
|
|
209
168
|
]
|
|
210
169
|
}
|
|
211
|
-
},
|
|
212
|
-
tenon ({ value }, { el }) {
|
|
213
|
-
el.hasEvent = true
|
|
214
|
-
const attrsMap = el.attrsMap
|
|
215
|
-
const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
|
|
216
|
-
const stringify = JSON.stringify
|
|
217
|
-
const match = tagRE.exec(value)
|
|
218
|
-
if (match) {
|
|
219
|
-
const modelProp = attrsMap['wx:model-prop'] || 'value'
|
|
220
|
-
const modelEvent = attrsMap['wx:model-event'] || 'input'
|
|
221
|
-
const modelValuePathRaw = attrsMap['wx:model-value-path']
|
|
222
|
-
const modelValuePath = modelValuePathRaw === undefined ? 'value' : modelValuePathRaw
|
|
223
|
-
const modelFilter = attrsMap['wx:model-filter']
|
|
224
|
-
let modelValuePathArr
|
|
225
|
-
try {
|
|
226
|
-
modelValuePathArr = JSON5.parse(modelValuePath)
|
|
227
|
-
} catch (e) {
|
|
228
|
-
if (modelValuePath === '') {
|
|
229
|
-
modelValuePathArr = []
|
|
230
|
-
} else {
|
|
231
|
-
modelValuePathArr = modelValuePath.split('.')
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
const modelValue = match[1].trim()
|
|
235
|
-
return [
|
|
236
|
-
{
|
|
237
|
-
name: ':' + modelProp,
|
|
238
|
-
value: modelValue
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
name: 'mpxModelEvent',
|
|
242
|
-
value: modelEvent
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
name: 'mpxModelEventId',
|
|
246
|
-
value: Math.random().toString(36).slice(3, 11)
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
name: '@mpxModel',
|
|
250
|
-
value: `__model(${stringifyWithResolveComputed(modelValue)}, $event, ${stringify(modelValuePathArr)}, ${stringify(modelFilter)})`
|
|
251
|
-
}
|
|
252
|
-
]
|
|
253
|
-
}
|
|
254
170
|
}
|
|
255
171
|
},
|
|
256
172
|
{
|
|
@@ -267,12 +183,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
267
183
|
name: 'ref',
|
|
268
184
|
value: `__mpx_ref_${value}__`
|
|
269
185
|
}
|
|
270
|
-
},
|
|
271
|
-
tenon ({ value }) {
|
|
272
|
-
return {
|
|
273
|
-
name: 'ref',
|
|
274
|
-
value: `${value}`
|
|
275
|
-
}
|
|
276
186
|
}
|
|
277
187
|
},
|
|
278
188
|
{
|
|
@@ -322,14 +232,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
322
232
|
value: classBinding[0]
|
|
323
233
|
}
|
|
324
234
|
}
|
|
325
|
-
},
|
|
326
|
-
tenon ({ name, value }) {
|
|
327
|
-
const dir = this.test.exec(name)[1]
|
|
328
|
-
const parsed = parseMustacheWithContext(value)
|
|
329
|
-
return {
|
|
330
|
-
name: ':' + dir,
|
|
331
|
-
value: parsed.result
|
|
332
|
-
}
|
|
333
235
|
}
|
|
334
236
|
},
|
|
335
237
|
// 通用指令
|
|
@@ -387,17 +289,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
387
289
|
name: 'v-' + dir,
|
|
388
290
|
value: parsed.result
|
|
389
291
|
}
|
|
390
|
-
},
|
|
391
|
-
tenon ({ name, value }) {
|
|
392
|
-
let dir = this.test.exec(name)[1]
|
|
393
|
-
const parsed = parseMustacheWithContext(value)
|
|
394
|
-
if (dir === 'elif') {
|
|
395
|
-
dir = 'else-if'
|
|
396
|
-
}
|
|
397
|
-
return {
|
|
398
|
-
name: 'v-' + dir,
|
|
399
|
-
value: parsed.result
|
|
400
|
-
}
|
|
401
292
|
}
|
|
402
293
|
},
|
|
403
294
|
// 事件
|
|
@@ -493,10 +384,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
493
384
|
}
|
|
494
385
|
},
|
|
495
386
|
web ({ name, value }, { eventRules, el, usingComponents }) {
|
|
496
|
-
const parsed = parseMustacheWithContext(value)
|
|
497
|
-
if (parsed.hasBinding) {
|
|
498
|
-
value = '__invokeHandler(' + parsed.result + ', $event)'
|
|
499
|
-
}
|
|
500
387
|
const match = this.test.exec(name)
|
|
501
388
|
const prefix = match[1]
|
|
502
389
|
const eventName = match[2]
|
|
@@ -541,23 +428,6 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
541
428
|
name: rPrefix + rEventName + meta.modifierStr,
|
|
542
429
|
value
|
|
543
430
|
}
|
|
544
|
-
},
|
|
545
|
-
tenon ({ name, value }, { eventRules, el }) {
|
|
546
|
-
const match = this.test.exec(name)
|
|
547
|
-
const prefix = match[1]
|
|
548
|
-
const eventName = match[2]
|
|
549
|
-
const modifierStr = match[3] || ''
|
|
550
|
-
const meta = {
|
|
551
|
-
modifierStr
|
|
552
|
-
}
|
|
553
|
-
// 记录event监听信息用于后续判断是否需要使用内置基础组件
|
|
554
|
-
el.hasEvent = true
|
|
555
|
-
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'web', meta })
|
|
556
|
-
const rEventName = runRules(eventRules, eventName, { mode: 'web' })
|
|
557
|
-
return {
|
|
558
|
-
name: rPrefix + rEventName + meta.modifierStr,
|
|
559
|
-
value
|
|
560
|
-
}
|
|
561
431
|
}
|
|
562
432
|
},
|
|
563
433
|
// 无障碍
|
package/lib/resolve-loader.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
module.exports = function () {
|
|
2
|
-
return `
|
|
3
|
-
var currentURL = global.currentPagePath
|
|
4
|
-
var getRelativePath = require('@mpxjs/webpack-plugin/lib/utils/get-relative-path').getRelativePath
|
|
5
|
-
module.exports = __mpx_resolve_path__(${JSON.stringify(this.resource)})`
|
|
2
|
+
return `module.exports = __mpx_resolve_path__(${JSON.stringify(this.resource)})`
|
|
6
3
|
}
|
|
@@ -33,6 +33,10 @@ export interface IntersectionObserver {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export interface ScrollViewContextValue {
|
|
37
|
+
gestureRef: React.RefObject<any> | null
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
export const MovableAreaContext = createContext({ width: 0, height: 0 })
|
|
37
41
|
|
|
38
42
|
export const FormContext = createContext<FormContextValue | null>(null)
|
|
@@ -51,4 +55,8 @@ export const IntersectionObserverContext = createContext<IntersectionObserver |
|
|
|
51
55
|
|
|
52
56
|
export const RouteContext = createContext<number | null>(null)
|
|
53
57
|
|
|
58
|
+
export const SwiperContext = createContext({})
|
|
59
|
+
|
|
54
60
|
export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
|
|
61
|
+
|
|
62
|
+
export const ScrollViewContext = createContext<ScrollViewContextValue>({ gestureRef: null })
|
|
@@ -8,4 +8,6 @@ export const PickerContext = createContext(null);
|
|
|
8
8
|
export const VarContext = createContext({});
|
|
9
9
|
export const IntersectionObserverContext = createContext(null);
|
|
10
10
|
export const RouteContext = createContext(null);
|
|
11
|
+
export const SwiperContext = createContext({});
|
|
11
12
|
export const KeyboardAvoidContext = createContext(null);
|
|
13
|
+
export const ScrollViewContext = createContext({ gestureRef: null });
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
2
|
import { hasOwn, collectDataset } from '@mpxjs/utils';
|
|
3
|
+
import { useNavigation } from '@react-navigation/native';
|
|
3
4
|
import { omit, extendObject } from './utils';
|
|
4
5
|
import eventConfigMap from './event.config';
|
|
5
|
-
const
|
|
6
|
+
const globalEventState = {
|
|
7
|
+
needPress: true
|
|
8
|
+
};
|
|
9
|
+
const getTouchEvent = (type, event, props, config, navigation) => {
|
|
10
|
+
const { y: navigationY = 0 } = navigation?.layout || {};
|
|
6
11
|
const nativeEvent = event.nativeEvent;
|
|
7
12
|
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent;
|
|
8
13
|
const { id } = props;
|
|
@@ -25,24 +30,24 @@ const getTouchEvent = (type, event, props, config) => {
|
|
|
25
30
|
target,
|
|
26
31
|
detail: {
|
|
27
32
|
x: pageX,
|
|
28
|
-
y: pageY
|
|
33
|
+
y: pageY - navigationY
|
|
29
34
|
},
|
|
30
35
|
touches: touches.map((item) => {
|
|
31
36
|
return {
|
|
32
37
|
identifier: item.identifier,
|
|
33
38
|
pageX: item.pageX,
|
|
34
|
-
pageY: item.pageY,
|
|
35
|
-
clientX: item.
|
|
36
|
-
clientY: item.
|
|
39
|
+
pageY: item.pageY - navigationY,
|
|
40
|
+
clientX: item.pageX,
|
|
41
|
+
clientY: item.pageY - navigationY
|
|
37
42
|
};
|
|
38
43
|
}),
|
|
39
44
|
changedTouches: changedTouches.map((item) => {
|
|
40
45
|
return {
|
|
41
46
|
identifier: item.identifier,
|
|
42
47
|
pageX: item.pageX,
|
|
43
|
-
pageY: item.pageY,
|
|
44
|
-
clientX: item.
|
|
45
|
-
clientY: item.
|
|
48
|
+
pageY: item.pageY - navigationY,
|
|
49
|
+
clientX: item.pageX,
|
|
50
|
+
clientY: item.pageY - navigationY
|
|
46
51
|
};
|
|
47
52
|
}),
|
|
48
53
|
persist: event.persist,
|
|
@@ -66,14 +71,14 @@ export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, p
|
|
|
66
71
|
preventDefault: oe.preventDefault
|
|
67
72
|
});
|
|
68
73
|
};
|
|
69
|
-
function handleEmitEvent(events, type, oe, propsRef, config) {
|
|
74
|
+
function handleEmitEvent(events, type, oe, propsRef, config, navigation) {
|
|
70
75
|
events.forEach((event) => {
|
|
71
76
|
if (propsRef.current[event]) {
|
|
72
77
|
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
73
78
|
if (match) {
|
|
74
79
|
oe.stopPropagation();
|
|
75
80
|
}
|
|
76
|
-
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
|
|
81
|
+
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config, navigation));
|
|
77
82
|
}
|
|
78
83
|
});
|
|
79
84
|
}
|
|
@@ -82,15 +87,15 @@ function checkIsNeedPress(e, type, ref) {
|
|
|
82
87
|
const nativeEvent = e.nativeEvent;
|
|
83
88
|
const currentPageX = nativeEvent.changedTouches[0].pageX;
|
|
84
89
|
const currentPageY = nativeEvent.changedTouches[0].pageY;
|
|
85
|
-
if (Math.abs(currentPageX - tapDetailInfo.x) >
|
|
86
|
-
Math.abs(currentPageY - tapDetailInfo.y) >
|
|
87
|
-
|
|
90
|
+
if (Math.abs(currentPageX - tapDetailInfo.x) > 3 ||
|
|
91
|
+
Math.abs(currentPageY - tapDetailInfo.y) > 3) {
|
|
92
|
+
globalEventState.needPress = false;
|
|
88
93
|
ref.current.startTimer[type] &&
|
|
89
94
|
clearTimeout(ref.current.startTimer[type]);
|
|
90
95
|
ref.current.startTimer[type] = null;
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
|
-
function handleTouchstart(e, type, ref, propsRef, config) {
|
|
98
|
+
function handleTouchstart(e, type, ref, propsRef, config, navigation) {
|
|
94
99
|
e.persist();
|
|
95
100
|
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
|
|
96
101
|
const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
|
|
@@ -103,7 +108,7 @@ function handleTouchstart(e, type, ref, propsRef, config) {
|
|
|
103
108
|
'capture-bindlongpress'
|
|
104
109
|
];
|
|
105
110
|
ref.current.startTimer[type] = null;
|
|
106
|
-
|
|
111
|
+
globalEventState.needPress = true;
|
|
107
112
|
const nativeEvent = e.nativeEvent;
|
|
108
113
|
ref.current.mpxPressInfo.detail = {
|
|
109
114
|
x: nativeEvent.changedTouches[0].pageX,
|
|
@@ -111,29 +116,30 @@ function handleTouchstart(e, type, ref, propsRef, config) {
|
|
|
111
116
|
};
|
|
112
117
|
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
113
118
|
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
114
|
-
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config);
|
|
119
|
+
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config, navigation);
|
|
115
120
|
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
|
|
116
121
|
if (catchlongpress ||
|
|
117
122
|
bindlongpress ||
|
|
118
123
|
captureCatchlongpress ||
|
|
119
124
|
captureBindlongpress) {
|
|
120
125
|
ref.current.startTimer[type] = setTimeout(() => {
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
// 只要触发过longpress, 全局就不再触发tap
|
|
127
|
+
globalEventState.needPress = false;
|
|
128
|
+
handleEmitEvent(currentPressEvent, 'longpress', e, propsRef, config, navigation);
|
|
123
129
|
}, 350);
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
|
-
function handleTouchmove(e, type, ref, propsRef, config) {
|
|
132
|
+
function handleTouchmove(e, type, ref, propsRef, config, navigation) {
|
|
127
133
|
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
|
|
128
134
|
const captureTouchEvent = [
|
|
129
135
|
'capture-catchtouchmove',
|
|
130
136
|
'capture-bindtouchmove'
|
|
131
137
|
];
|
|
132
138
|
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
133
|
-
handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config);
|
|
139
|
+
handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config, navigation);
|
|
134
140
|
checkIsNeedPress(e, type, ref);
|
|
135
141
|
}
|
|
136
|
-
function handleTouchend(e, type, ref, propsRef, config) {
|
|
142
|
+
function handleTouchend(e, type, ref, propsRef, config, navigation) {
|
|
137
143
|
// move event may not be triggered
|
|
138
144
|
checkIsNeedPress(e, type, ref);
|
|
139
145
|
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
|
|
@@ -148,15 +154,15 @@ function handleTouchend(e, type, ref, propsRef, config) {
|
|
|
148
154
|
ref.current.startTimer[type] &&
|
|
149
155
|
clearTimeout(ref.current.startTimer[type]);
|
|
150
156
|
ref.current.startTimer[type] = null;
|
|
151
|
-
handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config);
|
|
152
|
-
if (
|
|
157
|
+
handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config, navigation);
|
|
158
|
+
if (globalEventState.needPress) {
|
|
153
159
|
if (type === 'bubble' && config.disableTap) {
|
|
154
160
|
return;
|
|
155
161
|
}
|
|
156
|
-
handleEmitEvent(currentTapEvent, 'tap', e, propsRef, config);
|
|
162
|
+
handleEmitEvent(currentTapEvent, 'tap', e, propsRef, config, navigation);
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
|
-
function handleTouchcancel(e, type, ref, propsRef, config) {
|
|
165
|
+
function handleTouchcancel(e, type, ref, propsRef, config, navigation) {
|
|
160
166
|
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
|
|
161
167
|
const captureTouchEvent = [
|
|
162
168
|
'capture-catchtouchcancel',
|
|
@@ -166,10 +172,10 @@ function handleTouchcancel(e, type, ref, propsRef, config) {
|
|
|
166
172
|
ref.current.startTimer[type] &&
|
|
167
173
|
clearTimeout(ref.current.startTimer[type]);
|
|
168
174
|
ref.current.startTimer[type] = null;
|
|
169
|
-
handleEmitEvent(currentTouchEvent, 'touchcancel', e, propsRef, config);
|
|
175
|
+
handleEmitEvent(currentTouchEvent, 'touchcancel', e, propsRef, config, navigation);
|
|
170
176
|
}
|
|
171
177
|
function createTouchEventHandler(eventName, type) {
|
|
172
|
-
return (e, ref, propsRef, config) => {
|
|
178
|
+
return (e, ref, propsRef, config, navigation) => {
|
|
173
179
|
const handlerMap = {
|
|
174
180
|
onTouchStart: handleTouchstart,
|
|
175
181
|
onTouchMove: handleTouchmove,
|
|
@@ -178,7 +184,7 @@ function createTouchEventHandler(eventName, type) {
|
|
|
178
184
|
};
|
|
179
185
|
const handler = handlerMap[eventName];
|
|
180
186
|
if (handler) {
|
|
181
|
-
handler(e, type, ref, propsRef, config);
|
|
187
|
+
handler(e, type, ref, propsRef, config, navigation);
|
|
182
188
|
}
|
|
183
189
|
};
|
|
184
190
|
}
|
|
@@ -198,10 +204,6 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
198
204
|
bubble: null,
|
|
199
205
|
capture: null
|
|
200
206
|
},
|
|
201
|
-
needPress: {
|
|
202
|
-
bubble: false,
|
|
203
|
-
capture: false
|
|
204
|
-
},
|
|
205
207
|
mpxPressInfo: {
|
|
206
208
|
detail: {
|
|
207
209
|
x: 0,
|
|
@@ -213,9 +215,9 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
213
215
|
const eventConfig = {};
|
|
214
216
|
const config = rawConfig || {
|
|
215
217
|
layoutRef: { current: {} },
|
|
216
|
-
disableTouch: false,
|
|
217
218
|
disableTap: false
|
|
218
219
|
};
|
|
220
|
+
const navigation = useNavigation();
|
|
219
221
|
const removeProps = [
|
|
220
222
|
'children',
|
|
221
223
|
'enable-background',
|
|
@@ -237,10 +239,10 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
237
239
|
rawEventKeys.push(key);
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
|
-
if (!rawEventKeys.length || config.disableTouch) {
|
|
241
|
-
return omit(propsRef.current, removeProps);
|
|
242
|
-
}
|
|
243
242
|
const events = useMemo(() => {
|
|
243
|
+
if (!rawEventKeys.length) {
|
|
244
|
+
return {};
|
|
245
|
+
}
|
|
244
246
|
const transformedEventKeys = rawEventKeys.reduce((acc, key) => {
|
|
245
247
|
if (propsRef.current[key]) {
|
|
246
248
|
return acc.concat(eventConfig[key]);
|
|
@@ -251,7 +253,7 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
251
253
|
const events = {};
|
|
252
254
|
touchEventList.forEach((item) => {
|
|
253
255
|
if (finalEventKeys.includes(item.eventName)) {
|
|
254
|
-
events[item.eventName] = (e) => item.handler(e, ref, propsRef, config);
|
|
256
|
+
events[item.eventName] = (e) => item.handler(e, ref, propsRef, config, navigation);
|
|
255
257
|
}
|
|
256
258
|
});
|
|
257
259
|
return events;
|
|
@@ -34,10 +34,11 @@
|
|
|
34
34
|
* ✘ bindagreeprivacyauthorization
|
|
35
35
|
* ✔ bindtap
|
|
36
36
|
*/
|
|
37
|
-
import { createElement, useEffect, useRef,
|
|
37
|
+
import { createElement, useEffect, useRef, forwardRef, useContext } from 'react';
|
|
38
38
|
import { View, StyleSheet, Animated, Easing } from 'react-native';
|
|
39
39
|
import { warn } from '@mpxjs/utils';
|
|
40
|
-
import {
|
|
40
|
+
import { GestureDetector } from 'react-native-gesture-handler';
|
|
41
|
+
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject, useHover } from './utils';
|
|
41
42
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
42
43
|
import useNodesRef from './useNodesRef';
|
|
43
44
|
import { RouteContext, FormContext } from './context';
|
|
@@ -128,38 +129,34 @@ const Loading = ({ alone = false }) => {
|
|
|
128
129
|
};
|
|
129
130
|
const Button = forwardRef((buttonProps, ref) => {
|
|
130
131
|
const { textProps, innerProps: props = {} } = splitProps(buttonProps);
|
|
131
|
-
const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap
|
|
132
|
+
const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap } = props;
|
|
132
133
|
const pageId = useContext(RouteContext);
|
|
133
134
|
const formContext = useContext(FormContext);
|
|
135
|
+
const enableHover = hoverClass !== 'none';
|
|
136
|
+
const { isHover, gesture } = useHover({ enableHover, hoverStartTime, hoverStayTime, disabled });
|
|
134
137
|
let submitFn;
|
|
135
138
|
let resetFn;
|
|
136
139
|
if (formContext) {
|
|
137
140
|
submitFn = formContext.submit;
|
|
138
141
|
resetFn = formContext.reset;
|
|
139
142
|
}
|
|
140
|
-
const refs = useRef({
|
|
141
|
-
hoverStartTimer: undefined,
|
|
142
|
-
hoverStayTimer: undefined
|
|
143
|
-
});
|
|
144
|
-
const [isHover, setIsHover] = useState(false);
|
|
145
143
|
const isMiniSize = size === 'mini';
|
|
146
|
-
const applyHoverEffect = isHover && hoverClass !== 'none';
|
|
147
144
|
const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type];
|
|
148
|
-
const normalBackgroundColor = disabled ? disabledColor :
|
|
145
|
+
const normalBackgroundColor = disabled ? disabledColor : isHover || loading ? hoverColor : color;
|
|
149
146
|
const plainBorderColor = disabled
|
|
150
147
|
? 'rgba(0, 0, 0, .2)'
|
|
151
|
-
:
|
|
148
|
+
: isHover
|
|
152
149
|
? `rgba(${plainColor},.6)`
|
|
153
150
|
: `rgb(${plainColor})`;
|
|
154
151
|
const normalBorderColor = type === 'default' ? 'rgba(0, 0, 0, .2)' : normalBackgroundColor;
|
|
155
152
|
const plainTextColor = disabled
|
|
156
153
|
? 'rgba(0, 0, 0, .2)'
|
|
157
|
-
:
|
|
154
|
+
: isHover
|
|
158
155
|
? `rgba(${plainColor}, .6)`
|
|
159
156
|
: `rgb(${plainColor})`;
|
|
160
157
|
const normalTextColor = type === 'default'
|
|
161
|
-
? `rgba(0, 0, 0, ${disabled ? 0.3 :
|
|
162
|
-
: `rgba(255 ,255 ,255 , ${disabled ||
|
|
158
|
+
? `rgba(0, 0, 0, ${disabled ? 0.3 : isHover || loading ? 0.6 : 1})`
|
|
159
|
+
: `rgba(255 ,255 ,255 , ${disabled || isHover || loading ? 0.6 : 1})`;
|
|
163
160
|
const viewStyle = {
|
|
164
161
|
borderWidth: 1,
|
|
165
162
|
borderStyle: 'solid',
|
|
@@ -169,7 +166,7 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
169
166
|
const defaultViewStyle = extendObject({}, styles.button, isMiniSize ? styles.buttonMini : null, viewStyle);
|
|
170
167
|
const defaultTextStyle = extendObject({}, styles.text, isMiniSize ? styles.textMini : {}, { color: plain ? plainTextColor : normalTextColor });
|
|
171
168
|
const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle);
|
|
172
|
-
const styleObj = extendObject({}, defaultStyle, style,
|
|
169
|
+
const styleObj = extendObject({}, defaultStyle, style, isHover ? hoverStyle : {});
|
|
173
170
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
174
171
|
const nodeRef = useRef(null);
|
|
175
172
|
useNodesRef(props, ref, nodeRef, { style: normalStyle });
|
|
@@ -224,32 +221,6 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
224
221
|
});
|
|
225
222
|
}
|
|
226
223
|
};
|
|
227
|
-
const setStayTimer = () => {
|
|
228
|
-
clearTimeout(refs.current.hoverStayTimer);
|
|
229
|
-
refs.current.hoverStayTimer = setTimeout(() => {
|
|
230
|
-
setIsHover(false);
|
|
231
|
-
clearTimeout(refs.current.hoverStayTimer);
|
|
232
|
-
}, hoverStayTime);
|
|
233
|
-
};
|
|
234
|
-
const setStartTimer = () => {
|
|
235
|
-
clearTimeout(refs.current.hoverStartTimer);
|
|
236
|
-
refs.current.hoverStartTimer = setTimeout(() => {
|
|
237
|
-
setIsHover(true);
|
|
238
|
-
clearTimeout(refs.current.hoverStartTimer);
|
|
239
|
-
}, hoverStartTime);
|
|
240
|
-
};
|
|
241
|
-
const onTouchStart = (evt) => {
|
|
242
|
-
bindtouchstart && bindtouchstart(evt);
|
|
243
|
-
if (disabled)
|
|
244
|
-
return;
|
|
245
|
-
setStartTimer();
|
|
246
|
-
};
|
|
247
|
-
const onTouchEnd = (evt) => {
|
|
248
|
-
bindtouchend && bindtouchend(evt);
|
|
249
|
-
if (disabled)
|
|
250
|
-
return;
|
|
251
|
-
setStayTimer();
|
|
252
|
-
};
|
|
253
224
|
const handleFormTypeFn = () => {
|
|
254
225
|
if (formType === 'submit') {
|
|
255
226
|
submitFn && submitFn();
|
|
@@ -269,8 +240,6 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
269
240
|
ref: nodeRef,
|
|
270
241
|
style: extendObject({}, innerStyle, layoutStyle)
|
|
271
242
|
}, layoutProps, {
|
|
272
|
-
bindtouchstart: (bindtouchstart || !disabled) && onTouchStart,
|
|
273
|
-
bindtouchend: (bindtouchend || !disabled) && onTouchEnd,
|
|
274
243
|
bindtap: !disabled && onTap
|
|
275
244
|
}), [
|
|
276
245
|
'disabled',
|
|
@@ -288,12 +257,15 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
288
257
|
layoutRef,
|
|
289
258
|
disableTap: disabled
|
|
290
259
|
});
|
|
291
|
-
|
|
260
|
+
const baseButton = createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props, {
|
|
292
261
|
hasVarDec,
|
|
293
262
|
varContext: varContextRef.current,
|
|
294
263
|
textStyle,
|
|
295
264
|
textProps
|
|
296
265
|
}));
|
|
266
|
+
return enableHover
|
|
267
|
+
? createElement(GestureDetector, { gesture: gesture }, baseButton)
|
|
268
|
+
: baseButton;
|
|
297
269
|
});
|
|
298
270
|
Button.displayName = 'MpxButton';
|
|
299
271
|
export default Button;
|
|
@@ -316,8 +316,7 @@ var handleError = function (err, message) {
|
|
|
316
316
|
document.removeEventListener('message', handleIncomingMessage);
|
|
317
317
|
};
|
|
318
318
|
|
|
319
|
-
function handleIncomingMessage(
|
|
320
|
-
var data = JSON.parse(e.data);
|
|
319
|
+
function handleIncomingMessage(data) {
|
|
321
320
|
if (Array.isArray(data)) {
|
|
322
321
|
for (var i = 0; i < data.length; i++) {
|
|
323
322
|
try {
|
|
@@ -335,8 +334,7 @@ function handleIncomingMessage(e) {
|
|
|
335
334
|
}
|
|
336
335
|
}
|
|
337
336
|
|
|
338
|
-
window.
|
|
339
|
-
document.addEventListener('message', handleIncomingMessage);
|
|
337
|
+
window.mpxWebviewMessageCallback = handleIncomingMessage
|
|
340
338
|
</script>
|
|
341
339
|
|
|
342
340
|
|
|
@@ -69,7 +69,11 @@ const _Canvas = forwardRef((props = {}, ref) => {
|
|
|
69
69
|
useEffect(() => {
|
|
70
70
|
const webviewPostMessage = (message) => {
|
|
71
71
|
if (canvasRef.current.webview) {
|
|
72
|
-
|
|
72
|
+
const jsCode = `
|
|
73
|
+
window.mpxWebviewMessageCallback(${JSON.stringify(message)});
|
|
74
|
+
true;
|
|
75
|
+
`;
|
|
76
|
+
canvasRef.current.webview.injectJavaScript(jsCode);
|
|
73
77
|
}
|
|
74
78
|
};
|
|
75
79
|
// 设置bus
|