@mpxjs/webpack-plugin 2.9.56 → 2.9.58
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/lib/platform/style/wx/index.js +29 -9
- package/lib/platform/template/wx/component-config/web-view.js +8 -0
- package/lib/react/index.js +0 -1
- package/lib/react/processStyles.js +14 -3
- package/lib/react/style-helper.js +6 -10
- package/lib/runtime/base.styl +27 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +230 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +270 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +229 -0
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +6 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +203 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +294 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +353 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +57 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +25 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +67 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +27 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +307 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +115 -0
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +25 -0
- package/lib/runtime/components/react/dist/utils.js +80 -0
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +1 -2
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +171 -0
- package/lib/runtime/components/react/{getInnerListeners.type.ts → types/getInnerListeners.ts} +2 -2
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/components/react/utils.ts +1 -1
- package/lib/runtime/optionProcessor.js +27 -1
- package/lib/runtime/transRpxStyle.js +1 -1
- package/lib/style-compiler/plugins/rpx.js +2 -2
- package/lib/style-compiler/plugins/vw.js +2 -2
- package/lib/template-compiler/compiler.js +104 -42
- package/lib/web/processTemplate.js +1 -1
- package/package.json +8 -4
|
@@ -60,7 +60,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
60
60
|
default: 'default' // 不校验
|
|
61
61
|
}
|
|
62
62
|
// number 类型支持的单位(包含auto)
|
|
63
|
-
const numberRegExp = /^\s*((
|
|
63
|
+
const numberRegExp = /^\s*((-?\d+(\.\d+)?)(rpx|px|%)?)|(auto)\s*$/
|
|
64
64
|
// RN 不支持的颜色格式
|
|
65
65
|
const colorRegExp = /^\s*(lab|lch|oklab|oklch|color-mix|color|hwb|lch|light-dark).*$/
|
|
66
66
|
|
|
@@ -101,6 +101,26 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
101
101
|
borderStyle: ValueType.default,
|
|
102
102
|
borderColor: ValueType.color
|
|
103
103
|
},
|
|
104
|
+
'border-left': { // 仅支持 width | style | color 这种排序
|
|
105
|
+
borderLeftWidth: ValueType.number,
|
|
106
|
+
borderLeftStyle: ValueType.default,
|
|
107
|
+
borderLeftColor: ValueType.color
|
|
108
|
+
},
|
|
109
|
+
'border-right': { // 仅支持 width | style | color 这种排序
|
|
110
|
+
borderRightWidth: ValueType.number,
|
|
111
|
+
borderRightStyle: ValueType.default,
|
|
112
|
+
borderRightColor: ValueType.color
|
|
113
|
+
},
|
|
114
|
+
'border-top': { // 仅支持 width | style | color 这种排序
|
|
115
|
+
borderTopWidth: ValueType.number,
|
|
116
|
+
borderTopStyle: ValueType.default,
|
|
117
|
+
borderTopColor: ValueType.color
|
|
118
|
+
},
|
|
119
|
+
'border-bottom': { // 仅支持 width | style | color 这种排序
|
|
120
|
+
borderBottomWidth: ValueType.number,
|
|
121
|
+
borderBottomStyle: ValueType.default,
|
|
122
|
+
borderBottomColor: ValueType.color
|
|
123
|
+
},
|
|
104
124
|
'box-shadow': { // 仅支持 offset-x | offset-y | blur-radius | color 排序
|
|
105
125
|
'shadowOffset.width': ValueType.number,
|
|
106
126
|
'shadowOffset.height': ValueType.number,
|
|
@@ -220,7 +240,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
220
240
|
|
|
221
241
|
return {
|
|
222
242
|
prop,
|
|
223
|
-
value:
|
|
243
|
+
value: /^\s*-?\d+(\.\d+)?\s*$/.test(value) ? `${Math.round(value * 100)}%` : value
|
|
224
244
|
}
|
|
225
245
|
}
|
|
226
246
|
|
|
@@ -339,7 +359,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
339
359
|
supportedModes: ['ios', 'android'],
|
|
340
360
|
rules: [
|
|
341
361
|
{ // 背景相关属性的处理
|
|
342
|
-
test:
|
|
362
|
+
test: /^(background|background-image|background-color|background-size|background-repeat|background-position)$/,
|
|
343
363
|
ios: checkBackgroundImage,
|
|
344
364
|
android: checkBackgroundImage
|
|
345
365
|
},
|
|
@@ -372,7 +392,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
372
392
|
android: getAbbreviationAndroid
|
|
373
393
|
},
|
|
374
394
|
{
|
|
375
|
-
test:
|
|
395
|
+
test: /^(font-variant|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures)$/,
|
|
376
396
|
ios: getFontVariant,
|
|
377
397
|
android: getFontVariant
|
|
378
398
|
},
|
|
@@ -382,7 +402,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
382
402
|
android: getBorderRadius
|
|
383
403
|
},
|
|
384
404
|
{ // margin padding 内外边距的处理
|
|
385
|
-
test:
|
|
405
|
+
test: /^(margin|padding)$/,
|
|
386
406
|
ios: formatMargins,
|
|
387
407
|
android: formatMargins
|
|
388
408
|
},
|
|
@@ -398,13 +418,13 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
398
418
|
android: formatLineHeight
|
|
399
419
|
},
|
|
400
420
|
// 值类型校验放到最后
|
|
401
|
-
{ // color 颜色值校验
|
|
402
|
-
test:
|
|
421
|
+
{ // color 颜色值校验 color xx-color 等
|
|
422
|
+
test: /^(color|(.+-color))$/,
|
|
403
423
|
ios: checkCommonValue(ValueType.color),
|
|
404
424
|
android: checkCommonValue(ValueType.color)
|
|
405
425
|
},
|
|
406
|
-
{ // number 值校验
|
|
407
|
-
test:
|
|
426
|
+
{ // number 值校验 // width height xx-left xx-top 等
|
|
427
|
+
test: /^((width|height)|(.+-(left|right|top|bottom|radius|spacing|size)))$/,
|
|
408
428
|
ios: checkCommonValue(ValueType.number),
|
|
409
429
|
android: checkCommonValue(ValueType.number)
|
|
410
430
|
}
|
|
@@ -6,6 +6,14 @@ module.exports = function () {
|
|
|
6
6
|
web (tag, { el }) {
|
|
7
7
|
el.isBuiltIn = true
|
|
8
8
|
return 'mpx-web-view'
|
|
9
|
+
},
|
|
10
|
+
ios (tag, { el }) {
|
|
11
|
+
el.isBuiltIn = true
|
|
12
|
+
return 'mpx-web-view'
|
|
13
|
+
},
|
|
14
|
+
android (tag, { el }) {
|
|
15
|
+
el.isBuiltIn = true
|
|
16
|
+
return 'mpx-web-view'
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
19
|
}
|
package/lib/react/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const shallowStringify = require('../utils/shallow-stringify')
|
|
|
5
5
|
|
|
6
6
|
module.exports = function (styles, {
|
|
7
7
|
loaderContext,
|
|
8
|
-
srcMode,
|
|
9
8
|
ctorType,
|
|
10
9
|
autoScope,
|
|
11
10
|
moduleId
|
|
@@ -14,7 +13,17 @@ module.exports = function (styles, {
|
|
|
14
13
|
let content = ''
|
|
15
14
|
let output = '/* styles */\n'
|
|
16
15
|
if (styles.length) {
|
|
17
|
-
const
|
|
16
|
+
const warn = (msg) => {
|
|
17
|
+
loaderContext.emitWarning(
|
|
18
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
const error = (msg) => {
|
|
22
|
+
loaderContext.emitError(
|
|
23
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
const { mode, srcMode } = loaderContext.getMpx()
|
|
18
27
|
async.eachOfSeries(styles, (style, i, callback) => {
|
|
19
28
|
const scoped = style.scoped || autoScope
|
|
20
29
|
const extraOptions = {
|
|
@@ -41,7 +50,9 @@ module.exports = function (styles, {
|
|
|
41
50
|
content,
|
|
42
51
|
filename: loaderContext.resourcePath,
|
|
43
52
|
mode,
|
|
44
|
-
srcMode
|
|
53
|
+
srcMode,
|
|
54
|
+
warn,
|
|
55
|
+
error
|
|
45
56
|
})
|
|
46
57
|
if (ctorType === 'app') {
|
|
47
58
|
output += `global.__getAppClassMap = function() {
|
|
@@ -2,10 +2,10 @@ const postcss = require('postcss')
|
|
|
2
2
|
const selectorParser = require('postcss-selector-parser')
|
|
3
3
|
const getRulesRunner = require('../platform/index')
|
|
4
4
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
5
|
-
const rpxRegExp = /^\s*(
|
|
6
|
-
const pxRegExp = /^\s*(
|
|
5
|
+
const rpxRegExp = /^\s*(-?\d+(\.\d+)?)rpx\s*$/
|
|
6
|
+
const pxRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
|
|
7
7
|
const cssPrefixExp = /^-(webkit|moz|ms|o)-/
|
|
8
|
-
function getClassMap ({ content, filename, mode, srcMode }) {
|
|
8
|
+
function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
|
|
9
9
|
const classMap = {}
|
|
10
10
|
|
|
11
11
|
const root = postcss.parse(content, {
|
|
@@ -30,12 +30,8 @@ function getClassMap ({ content, filename, mode, srcMode }) {
|
|
|
30
30
|
srcMode,
|
|
31
31
|
type: 'style',
|
|
32
32
|
testKey: 'prop',
|
|
33
|
-
warn
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
error: (msg) => {
|
|
37
|
-
console.error('[style compiler error]: ' + msg)
|
|
38
|
-
}
|
|
33
|
+
warn,
|
|
34
|
+
error
|
|
39
35
|
})
|
|
40
36
|
|
|
41
37
|
root.walkRules(rule => {
|
|
@@ -70,7 +66,7 @@ function getClassMap ({ content, filename, mode, srcMode }) {
|
|
|
70
66
|
if (selector.nodes.length === 1 && selector.nodes[0].type === 'class') {
|
|
71
67
|
classMapKeys.push(selector.nodes[0].value)
|
|
72
68
|
} else {
|
|
73
|
-
|
|
69
|
+
error('Only single class selector is supported in react native mode temporarily.')
|
|
74
70
|
}
|
|
75
71
|
})
|
|
76
72
|
}).processSync(rule.selector)
|
package/lib/runtime/base.styl
CHANGED
|
@@ -128,3 +128,30 @@ page {
|
|
|
128
128
|
font-family "weui"
|
|
129
129
|
src url('data:application/octet-stream;base64,AAEAAAALAIAAAwAwR1NVQrD+s+0AAAE4AAAAQk9TLzJAKEx+AAABfAAAAFZjbWFw65cFHQAAAhwAAAJQZ2x5ZvCRR/EAAASUAAAKtGhlYWQLKIN9AAAA4AAAADZoaGVhCCwD+gAAALwAAAAkaG10eEJo//8AAAHUAAAASGxvY2EYqhW6AAAEbAAAACZtYXhwASEAVQAAARgAAAAgbmFtZeNcHtgAAA9IAAAB5nBvc3T6bLhLAAARMAAAAOYAAQAAA+gAAABaA+j/////A+kAAQAAAAAAAAAAAAAAAAAAABIAAQAAAAEAACkCj3dfDzz1AAsD6AAAAADUER9XAAAAANQRH1f//wAAA+kD6gAAAAgAAgAAAAAAAAABAAAAEgBJAAUAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKAB4ALAABREZMVAAIAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAAAAQOwAZAABQAIAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA6gHqEQPoAAAAWg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AASAQIBAwEEAQUBBgEHAQgBCQEKAQsBDAENAQ4BDwEQAREBEgETAAZjaXJjbGUIZG93bmxvYWQEaW5mbwxzYWZlX3N1Y2Nlc3MJc2FmZV93YXJuB3N1Y2Nlc3MOc3VjY2Vzcy1jaXJjbGURc3VjY2Vzcy1uby1jaXJjbGUHd2FpdGluZw53YWl0aW5nLWNpcmNsZQR3YXJuC2luZm8tY2lyY2xlBmNhbmNlbAZzZWFyY2gFY2xlYXIEYmFjawZkZWxldGUAAAAA') format('truetype')
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
.mpx-slide-left-enter {
|
|
133
|
+
transform: translateX(100%)
|
|
134
|
+
}
|
|
135
|
+
.mpx-slide-left-enter-active {
|
|
136
|
+
transition: transform 0.3s;
|
|
137
|
+
position: absolute;
|
|
138
|
+
top: 0;
|
|
139
|
+
right: 0;
|
|
140
|
+
left: 0;
|
|
141
|
+
bottom: 0;
|
|
142
|
+
z-index: 100;
|
|
143
|
+
}
|
|
144
|
+
.mpx-slide-left-leave-active {
|
|
145
|
+
transition: transform 0.2s
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.mpx-slide-right-leave-active {
|
|
149
|
+
position: absolute;
|
|
150
|
+
z-index: 100;
|
|
151
|
+
top: 0;
|
|
152
|
+
right: 0;
|
|
153
|
+
left: 0;
|
|
154
|
+
bottom: 0;
|
|
155
|
+
transform: translateX(100%);
|
|
156
|
+
transition: transform 0.3s
|
|
157
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const eventConfigMap = {
|
|
2
|
+
bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
3
|
+
bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
4
|
+
bindtouchstart: ['onTouchStart'],
|
|
5
|
+
bindtouchmove: ['onTouchMove'],
|
|
6
|
+
bindtouchend: ['onTouchEnd'],
|
|
7
|
+
bindtouchcancel: ['onTouchCancel'],
|
|
8
|
+
catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
9
|
+
catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
10
|
+
catchtouchstart: ['onTouchStart'],
|
|
11
|
+
catchtouchmove: ['onTouchMove'],
|
|
12
|
+
catchtouchend: ['onTouchEnd'],
|
|
13
|
+
catchtouchcancel: ['onTouchCancel'],
|
|
14
|
+
'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
15
|
+
'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
16
|
+
'capture-bindtouchstart': ['onTouchStartCapture'],
|
|
17
|
+
'capture-bindtouchmove': ['onTouchMoveCapture'],
|
|
18
|
+
'capture-bindtouchend': ['onTouchEndCapture'],
|
|
19
|
+
'capture-bindtouchcancel': ['onTouchCancelCapture'],
|
|
20
|
+
'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
21
|
+
'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
22
|
+
'capture-catchtouchstart': ['onTouchStartCapture'],
|
|
23
|
+
'capture-catchtouchmove': ['onTouchMoveCapture'],
|
|
24
|
+
'capture-catchtouchend': ['onTouchEndCapture'],
|
|
25
|
+
'capture-catchtouchcancel': ['onTouchCancelCapture']
|
|
26
|
+
};
|
|
27
|
+
export default eventConfigMap;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { omit } from './utils';
|
|
3
|
+
import eventConfigMap from './event.config';
|
|
4
|
+
const getTouchEvent = (type, event, props, config) => {
|
|
5
|
+
const nativeEvent = event.nativeEvent;
|
|
6
|
+
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent;
|
|
7
|
+
const { id } = props;
|
|
8
|
+
const { layoutRef } = config;
|
|
9
|
+
return {
|
|
10
|
+
...event,
|
|
11
|
+
type,
|
|
12
|
+
timeStamp: timestamp,
|
|
13
|
+
target: {
|
|
14
|
+
...(event.target || {}),
|
|
15
|
+
id: id || '',
|
|
16
|
+
dataset: getDataSet(props),
|
|
17
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
18
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
19
|
+
},
|
|
20
|
+
detail: {
|
|
21
|
+
x: pageX,
|
|
22
|
+
y: pageY
|
|
23
|
+
},
|
|
24
|
+
touches: touches.map(item => {
|
|
25
|
+
return {
|
|
26
|
+
identifier: item.identifier,
|
|
27
|
+
pageX: item.pageX,
|
|
28
|
+
pageY: item.pageY,
|
|
29
|
+
clientX: item.locationX,
|
|
30
|
+
clientY: item.locationY
|
|
31
|
+
};
|
|
32
|
+
}),
|
|
33
|
+
changedTouches: changedTouches.map(item => {
|
|
34
|
+
return {
|
|
35
|
+
identifier: item.identifier,
|
|
36
|
+
pageX: item.pageX,
|
|
37
|
+
pageY: item.pageY,
|
|
38
|
+
clientX: item.locationX,
|
|
39
|
+
clientY: item.locationY
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
persist: event.persist,
|
|
43
|
+
stopPropagation: event.stopPropagation,
|
|
44
|
+
preventDefault: event.preventDefault
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const getDataSet = (props) => {
|
|
48
|
+
const result = {};
|
|
49
|
+
for (const key in props) {
|
|
50
|
+
if (key.indexOf('data-') === 0) {
|
|
51
|
+
const newKey = key.substr(5);
|
|
52
|
+
result[newKey] = props[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
|
|
58
|
+
return {
|
|
59
|
+
...oe,
|
|
60
|
+
type,
|
|
61
|
+
detail,
|
|
62
|
+
target: {
|
|
63
|
+
...(oe.target || {}),
|
|
64
|
+
id: props.id || '',
|
|
65
|
+
dataset: getDataSet(props),
|
|
66
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
67
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const useInnerProps = (props = {}, additionalProps = {}, removeProps = [], rawConfig) => {
|
|
72
|
+
const ref = useRef({
|
|
73
|
+
startTimer: {
|
|
74
|
+
bubble: null,
|
|
75
|
+
capture: null
|
|
76
|
+
},
|
|
77
|
+
needPress: {
|
|
78
|
+
bubble: false,
|
|
79
|
+
capture: false
|
|
80
|
+
},
|
|
81
|
+
mpxPressInfo: {
|
|
82
|
+
detail: {
|
|
83
|
+
x: 0,
|
|
84
|
+
y: 0
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const propsRef = useRef({});
|
|
89
|
+
const eventConfig = {};
|
|
90
|
+
const config = rawConfig || {};
|
|
91
|
+
propsRef.current = { ...props, ...additionalProps };
|
|
92
|
+
for (const key in eventConfigMap) {
|
|
93
|
+
if (propsRef.current[key]) {
|
|
94
|
+
eventConfig[key] = eventConfigMap[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!(Object.keys(eventConfig).length) || config.disableTouch) {
|
|
98
|
+
return omit(propsRef.current, removeProps);
|
|
99
|
+
}
|
|
100
|
+
function handleEmitEvent(events, type, oe) {
|
|
101
|
+
events.forEach(event => {
|
|
102
|
+
if (propsRef.current[event]) {
|
|
103
|
+
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
104
|
+
if (match) {
|
|
105
|
+
oe.stopPropagation();
|
|
106
|
+
}
|
|
107
|
+
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function handleTouchstart(e, type) {
|
|
112
|
+
e.persist();
|
|
113
|
+
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
|
|
114
|
+
const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
|
|
115
|
+
const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart'];
|
|
116
|
+
const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress'];
|
|
117
|
+
ref.current.startTimer[type] = null;
|
|
118
|
+
ref.current.needPress[type] = true;
|
|
119
|
+
const nativeEvent = e.nativeEvent;
|
|
120
|
+
ref.current.mpxPressInfo.detail = {
|
|
121
|
+
x: nativeEvent.changedTouches[0].pageX,
|
|
122
|
+
y: nativeEvent.changedTouches[0].pageY
|
|
123
|
+
};
|
|
124
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
125
|
+
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
126
|
+
handleEmitEvent(currentTouchEvent, 'touchstart', e);
|
|
127
|
+
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
|
|
128
|
+
if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
|
|
129
|
+
ref.current.startTimer[type] = setTimeout(() => {
|
|
130
|
+
ref.current.needPress[type] = false;
|
|
131
|
+
handleEmitEvent(currentPressEvent, 'longpress', e);
|
|
132
|
+
}, 350);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function handleTouchmove(e, type) {
|
|
136
|
+
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
|
|
137
|
+
const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove'];
|
|
138
|
+
const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 };
|
|
139
|
+
const nativeEvent = e.nativeEvent;
|
|
140
|
+
const currentPageX = nativeEvent.changedTouches[0].pageX;
|
|
141
|
+
const currentPageY = nativeEvent.changedTouches[0].pageY;
|
|
142
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
143
|
+
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
144
|
+
ref.current.needPress[type] = false;
|
|
145
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
146
|
+
ref.current.startTimer[type] = null;
|
|
147
|
+
}
|
|
148
|
+
handleEmitEvent(currentTouchEvent, 'touchmove', e);
|
|
149
|
+
}
|
|
150
|
+
function handleTouchend(e, type) {
|
|
151
|
+
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
|
|
152
|
+
const bubbleTapEvent = ['catchtap', 'bindtap'];
|
|
153
|
+
const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend'];
|
|
154
|
+
const captureTapEvent = ['capture-catchtap', 'capture-bindtap'];
|
|
155
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
156
|
+
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent;
|
|
157
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
158
|
+
ref.current.startTimer[type] = null;
|
|
159
|
+
handleEmitEvent(currentTouchEvent, 'touchend', e);
|
|
160
|
+
if (ref.current.needPress[type]) {
|
|
161
|
+
handleEmitEvent(currentTapEvent, 'tap', e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function handleTouchcancel(e, type) {
|
|
165
|
+
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
|
|
166
|
+
const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel'];
|
|
167
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
168
|
+
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
169
|
+
ref.current.startTimer[type] = null;
|
|
170
|
+
handleEmitEvent(currentTouchEvent, 'touchcancel', e);
|
|
171
|
+
}
|
|
172
|
+
const touchEventList = [{
|
|
173
|
+
eventName: 'onTouchStart',
|
|
174
|
+
handler: (e) => {
|
|
175
|
+
handleTouchstart(e, 'bubble');
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
eventName: 'onTouchMove',
|
|
179
|
+
handler: (e) => {
|
|
180
|
+
handleTouchmove(e, 'bubble');
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
eventName: 'onTouchEnd',
|
|
184
|
+
handler: (e) => {
|
|
185
|
+
handleTouchend(e, 'bubble');
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
eventName: 'onTouchCancel',
|
|
189
|
+
handler: (e) => {
|
|
190
|
+
handleTouchcancel(e, 'bubble');
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
eventName: 'onTouchStartCapture',
|
|
194
|
+
handler: (e) => {
|
|
195
|
+
handleTouchstart(e, 'capture');
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
eventName: 'onTouchMoveCapture',
|
|
199
|
+
handler: (e) => {
|
|
200
|
+
handleTouchmove(e, 'capture');
|
|
201
|
+
}
|
|
202
|
+
}, {
|
|
203
|
+
eventName: 'onTouchEndCapture',
|
|
204
|
+
handler: (e) => {
|
|
205
|
+
handleTouchend(e, 'capture');
|
|
206
|
+
}
|
|
207
|
+
}, {
|
|
208
|
+
eventName: 'onTouchCancelCapture',
|
|
209
|
+
handler: (e) => {
|
|
210
|
+
handleTouchcancel(e, 'capture');
|
|
211
|
+
}
|
|
212
|
+
}];
|
|
213
|
+
const events = {};
|
|
214
|
+
const transformedEventKeys = [];
|
|
215
|
+
for (const key in eventConfig) {
|
|
216
|
+
transformedEventKeys.push(...eventConfig[key]);
|
|
217
|
+
}
|
|
218
|
+
const finalEventKeys = [...new Set(transformedEventKeys)];
|
|
219
|
+
touchEventList.forEach(item => {
|
|
220
|
+
if (finalEventKeys.includes(item.eventName)) {
|
|
221
|
+
events[item.eventName] = item.handler;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
const rawEventKeys = Object.keys(eventConfig);
|
|
225
|
+
return {
|
|
226
|
+
...events,
|
|
227
|
+
...omit(propsRef.current, [...rawEventKeys, ...removeProps])
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
export default useInnerProps;
|