@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +13 -8
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +35 -38
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddModePlugin.js +8 -8
- package/lib/runtime/components/react/context.ts +6 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +70 -23
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +237 -199
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
- package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +92 -76
- package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +5 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
- package/lib/runtime/components/react/utils.tsx +99 -28
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +79 -47
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useRef } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import { omit } from './utils'
|
|
1
|
+
import { useRef, useMemo, RefObject } from 'react'
|
|
2
|
+
import { hasOwn, collectDataset } from '@mpxjs/utils'
|
|
3
|
+
import { omit, extendObject } from './utils'
|
|
4
4
|
import eventConfigMap from './event.config'
|
|
5
5
|
import {
|
|
6
6
|
Props,
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
UseInnerPropsConfig,
|
|
10
10
|
InnerRef,
|
|
11
11
|
SetTimeoutReturnType,
|
|
12
|
-
DataSetType,
|
|
13
12
|
LayoutRef,
|
|
14
13
|
NativeTouchEvent
|
|
15
14
|
} from './types/getInnerListeners'
|
|
@@ -21,31 +20,38 @@ const getTouchEvent = (
|
|
|
21
20
|
config: UseInnerPropsConfig
|
|
22
21
|
) => {
|
|
23
22
|
const nativeEvent = event.nativeEvent
|
|
24
|
-
const {
|
|
25
|
-
timestamp,
|
|
26
|
-
pageX,
|
|
27
|
-
pageY,
|
|
28
|
-
touches,
|
|
29
|
-
changedTouches
|
|
30
|
-
} = nativeEvent
|
|
23
|
+
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent
|
|
31
24
|
const { id } = props
|
|
32
25
|
const { layoutRef } = config
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
|
|
27
|
+
const currentTarget = extendObject({}, event.currentTarget, {
|
|
28
|
+
id: id || '',
|
|
29
|
+
dataset: collectDataset(props),
|
|
30
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
31
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const pendingProps = (event as any)._targetInst?.pendingProps || {}
|
|
35
|
+
|
|
36
|
+
const target = extendObject(
|
|
37
|
+
{},
|
|
38
|
+
event.target,
|
|
39
|
+
{
|
|
40
|
+
id: pendingProps.parentId || pendingProps.nativeID || '',
|
|
41
|
+
dataset: collectDataset(pendingProps)
|
|
42
|
+
}
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return extendObject({}, event, {
|
|
35
46
|
type,
|
|
36
47
|
timeStamp: timestamp,
|
|
37
|
-
currentTarget
|
|
38
|
-
|
|
39
|
-
id: id || '',
|
|
40
|
-
dataset: getDataSet(props),
|
|
41
|
-
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
42
|
-
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
43
|
-
},
|
|
48
|
+
currentTarget,
|
|
49
|
+
target,
|
|
44
50
|
detail: {
|
|
45
51
|
x: pageX,
|
|
46
52
|
y: pageY
|
|
47
53
|
},
|
|
48
|
-
touches: touches.map(item => {
|
|
54
|
+
touches: touches.map((item) => {
|
|
49
55
|
return {
|
|
50
56
|
identifier: item.identifier,
|
|
51
57
|
pageX: item.pageX,
|
|
@@ -54,7 +60,7 @@ const getTouchEvent = (
|
|
|
54
60
|
clientY: item.locationY
|
|
55
61
|
}
|
|
56
62
|
}),
|
|
57
|
-
changedTouches: changedTouches.map(item => {
|
|
63
|
+
changedTouches: changedTouches.map((item) => {
|
|
58
64
|
return {
|
|
59
65
|
identifier: item.identifier,
|
|
60
66
|
pageX: item.pageX,
|
|
@@ -66,45 +72,196 @@ const getTouchEvent = (
|
|
|
66
72
|
persist: event.persist,
|
|
67
73
|
stopPropagation: event.stopPropagation,
|
|
68
74
|
preventDefault: event.preventDefault
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const getDataSet = (props: Record<string, any>) => {
|
|
73
|
-
const result: DataSetType = {}
|
|
74
|
-
|
|
75
|
-
for (const key in props) {
|
|
76
|
-
if (key.indexOf('data-') === 0) {
|
|
77
|
-
const newKey = key.substr(5)
|
|
78
|
-
result[newKey] = props[key]
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return result
|
|
75
|
+
})
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
export const getCustomEvent = (
|
|
86
79
|
type = '',
|
|
87
80
|
oe: any = {},
|
|
88
|
-
{
|
|
81
|
+
{
|
|
82
|
+
detail = {},
|
|
83
|
+
layoutRef
|
|
84
|
+
}: { detail?: Record<string, unknown>; layoutRef?: LayoutRef },
|
|
89
85
|
props: Props = {}
|
|
90
86
|
) => {
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
const targetInfo = extendObject({}, oe.target, {
|
|
88
|
+
id: props.id || '',
|
|
89
|
+
dataset: collectDataset(props),
|
|
90
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
91
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
92
|
+
})
|
|
93
|
+
return extendObject({}, oe, {
|
|
93
94
|
type,
|
|
94
95
|
detail,
|
|
95
|
-
target:
|
|
96
|
-
...(oe.target || {}),
|
|
97
|
-
id: props.id || '',
|
|
98
|
-
dataset: getDataSet(props),
|
|
99
|
-
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
100
|
-
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
101
|
-
},
|
|
96
|
+
target: targetInfo,
|
|
102
97
|
persist: oe.persist,
|
|
103
98
|
stopPropagation: oe.stopPropagation,
|
|
104
99
|
preventDefault: oe.preventDefault
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleEmitEvent (
|
|
104
|
+
events: string[],
|
|
105
|
+
type: string,
|
|
106
|
+
oe: NativeTouchEvent,
|
|
107
|
+
propsRef: Record<string, any>,
|
|
108
|
+
config: UseInnerPropsConfig
|
|
109
|
+
) {
|
|
110
|
+
events.forEach((event) => {
|
|
111
|
+
if (propsRef.current[event]) {
|
|
112
|
+
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event)
|
|
113
|
+
if (match) {
|
|
114
|
+
oe.stopPropagation()
|
|
115
|
+
}
|
|
116
|
+
propsRef.current[event](
|
|
117
|
+
getTouchEvent(type, oe, propsRef.current, config)
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>) {
|
|
124
|
+
const tapDetailInfo = ref.current!.mpxPressInfo.detail || { x: 0, y: 0 }
|
|
125
|
+
const nativeEvent = e.nativeEvent
|
|
126
|
+
const currentPageX = nativeEvent.changedTouches[0].pageX
|
|
127
|
+
const currentPageY = nativeEvent.changedTouches[0].pageY
|
|
128
|
+
if (
|
|
129
|
+
Math.abs(currentPageX - tapDetailInfo.x) > 1 ||
|
|
130
|
+
Math.abs(currentPageY - tapDetailInfo.y) > 1
|
|
131
|
+
) {
|
|
132
|
+
ref.current!.needPress[type] = false
|
|
133
|
+
ref.current!.startTimer[type] &&
|
|
134
|
+
clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
|
|
135
|
+
ref.current!.startTimer[type] = null
|
|
105
136
|
}
|
|
106
137
|
}
|
|
107
138
|
|
|
139
|
+
function handleTouchstart (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig) {
|
|
140
|
+
e.persist()
|
|
141
|
+
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
|
|
142
|
+
const bubblePressEvent = ['catchlongpress', 'bindlongpress']
|
|
143
|
+
const captureTouchEvent = [
|
|
144
|
+
'capture-catchtouchstart',
|
|
145
|
+
'capture-bindtouchstart'
|
|
146
|
+
]
|
|
147
|
+
const capturePressEvent = [
|
|
148
|
+
'capture-catchlongpress',
|
|
149
|
+
'capture-bindlongpress'
|
|
150
|
+
]
|
|
151
|
+
ref.current!.startTimer[type] = null
|
|
152
|
+
ref.current!.needPress[type] = true
|
|
153
|
+
const nativeEvent = e.nativeEvent
|
|
154
|
+
ref.current!.mpxPressInfo.detail = {
|
|
155
|
+
x: nativeEvent.changedTouches[0].pageX,
|
|
156
|
+
y: nativeEvent.changedTouches[0].pageY
|
|
157
|
+
}
|
|
158
|
+
const currentTouchEvent =
|
|
159
|
+
type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
160
|
+
const currentPressEvent =
|
|
161
|
+
type === 'bubble' ? bubblePressEvent : capturePressEvent
|
|
162
|
+
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config)
|
|
163
|
+
const {
|
|
164
|
+
catchlongpress,
|
|
165
|
+
bindlongpress,
|
|
166
|
+
'capture-catchlongpress': captureCatchlongpress,
|
|
167
|
+
'capture-bindlongpress': captureBindlongpress
|
|
168
|
+
} = propsRef.current
|
|
169
|
+
if (
|
|
170
|
+
catchlongpress ||
|
|
171
|
+
bindlongpress ||
|
|
172
|
+
captureCatchlongpress ||
|
|
173
|
+
captureBindlongpress
|
|
174
|
+
) {
|
|
175
|
+
ref.current!.startTimer[type] = setTimeout(() => {
|
|
176
|
+
ref.current!.needPress[type] = false
|
|
177
|
+
handleEmitEvent(currentPressEvent, 'longpress', e, propsRef, config)
|
|
178
|
+
}, 350)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig) {
|
|
183
|
+
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
|
|
184
|
+
const captureTouchEvent = [
|
|
185
|
+
'capture-catchtouchmove',
|
|
186
|
+
'capture-bindtouchmove'
|
|
187
|
+
]
|
|
188
|
+
const currentTouchEvent =
|
|
189
|
+
type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
190
|
+
handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config)
|
|
191
|
+
checkIsNeedPress(e, type, ref)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture', ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig) {
|
|
195
|
+
// move event may not be triggered
|
|
196
|
+
checkIsNeedPress(e, type, ref)
|
|
197
|
+
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
|
|
198
|
+
const bubbleTapEvent = ['catchtap', 'bindtap']
|
|
199
|
+
const captureTouchEvent = [
|
|
200
|
+
'capture-catchtouchend',
|
|
201
|
+
'capture-bindtouchend'
|
|
202
|
+
]
|
|
203
|
+
const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
|
|
204
|
+
const currentTouchEvent =
|
|
205
|
+
type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
206
|
+
const currentTapEvent =
|
|
207
|
+
type === 'bubble' ? bubbleTapEvent : captureTapEvent
|
|
208
|
+
ref.current!.startTimer[type] &&
|
|
209
|
+
clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
|
|
210
|
+
ref.current!.startTimer[type] = null
|
|
211
|
+
handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config)
|
|
212
|
+
if (ref.current!.needPress[type]) {
|
|
213
|
+
if (type === 'bubble' && config.disableTap) {
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
handleEmitEvent(currentTapEvent, 'tap', e, propsRef, config)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function handleTouchcancel (
|
|
221
|
+
e: NativeTouchEvent,
|
|
222
|
+
type: 'bubble' | 'capture',
|
|
223
|
+
ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig
|
|
224
|
+
) {
|
|
225
|
+
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
|
|
226
|
+
const captureTouchEvent = [
|
|
227
|
+
'capture-catchtouchcancel',
|
|
228
|
+
'capture-bindtouchcancel'
|
|
229
|
+
]
|
|
230
|
+
const currentTouchEvent =
|
|
231
|
+
type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
232
|
+
ref.current!.startTimer[type] &&
|
|
233
|
+
clearTimeout(ref.current!.startTimer[type] as SetTimeoutReturnType)
|
|
234
|
+
ref.current!.startTimer[type] = null
|
|
235
|
+
handleEmitEvent(currentTouchEvent, 'touchcancel', e, propsRef, config)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function createTouchEventHandler (eventName: 'onTouchStart'|'onTouchMove'|'onTouchEnd'|'onTouchCancel', type: 'bubble' | 'capture') {
|
|
239
|
+
return (e: NativeTouchEvent, ref: RefObject<InnerRef>, propsRef: Record<string, any>, config: UseInnerPropsConfig) => {
|
|
240
|
+
const handlerMap = {
|
|
241
|
+
onTouchStart: handleTouchstart,
|
|
242
|
+
onTouchMove: handleTouchmove,
|
|
243
|
+
onTouchEnd: handleTouchend,
|
|
244
|
+
onTouchCancel: handleTouchcancel
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const handler = handlerMap[eventName]
|
|
248
|
+
if (handler) {
|
|
249
|
+
handler(e, type, ref, propsRef, config)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const touchEventList = [
|
|
255
|
+
{ eventName: 'onTouchStart', handler: createTouchEventHandler('onTouchStart', 'bubble') },
|
|
256
|
+
{ eventName: 'onTouchMove', handler: createTouchEventHandler('onTouchMove', 'bubble') },
|
|
257
|
+
{ eventName: 'onTouchEnd', handler: createTouchEventHandler('onTouchEnd', 'bubble') },
|
|
258
|
+
{ eventName: 'onTouchCancel', handler: createTouchEventHandler('onTouchCancel', 'bubble') },
|
|
259
|
+
{ eventName: 'onTouchStartCapture', handler: createTouchEventHandler('onTouchStart', 'capture') },
|
|
260
|
+
{ eventName: 'onTouchMoveCapture', handler: createTouchEventHandler('onTouchMove', 'capture') },
|
|
261
|
+
{ eventName: 'onTouchEndCapture', handler: createTouchEventHandler('onTouchEnd', 'capture') },
|
|
262
|
+
{ eventName: 'onTouchCancelCapture', handler: createTouchEventHandler('onTouchCancel', 'capture') }
|
|
263
|
+
]
|
|
264
|
+
|
|
108
265
|
const useInnerProps = (
|
|
109
266
|
props: Props = {},
|
|
110
267
|
additionalProps: AdditionalProps = {},
|
|
@@ -130,7 +287,11 @@ const useInnerProps = (
|
|
|
130
287
|
|
|
131
288
|
const propsRef = useRef<Record<string, any>>({})
|
|
132
289
|
const eventConfig: { [key: string]: string[] } = {}
|
|
133
|
-
const config = rawConfig || {
|
|
290
|
+
const config = rawConfig || {
|
|
291
|
+
layoutRef: { current: {} },
|
|
292
|
+
disableTouch: false,
|
|
293
|
+
disableTap: false
|
|
294
|
+
}
|
|
134
295
|
const removeProps = [
|
|
135
296
|
'children',
|
|
136
297
|
'enable-background',
|
|
@@ -143,170 +304,47 @@ const useInnerProps = (
|
|
|
143
304
|
...userRemoveProps
|
|
144
305
|
]
|
|
145
306
|
|
|
146
|
-
propsRef.current = {
|
|
307
|
+
propsRef.current = extendObject({}, props, additionalProps)
|
|
308
|
+
|
|
309
|
+
let hashEventKey = ''
|
|
310
|
+
const rawEventKeys: Array<string> = []
|
|
147
311
|
|
|
148
312
|
for (const key in eventConfigMap) {
|
|
149
|
-
if (propsRef.current
|
|
150
|
-
eventConfig[key] = eventConfigMap[key]
|
|
313
|
+
if (hasOwn(propsRef.current, key)) {
|
|
314
|
+
eventConfig[key] = eventConfigMap[key].events
|
|
315
|
+
hashEventKey = hashEventKey + eventConfigMap[key].bitFlag
|
|
316
|
+
rawEventKeys.push(key)
|
|
151
317
|
}
|
|
152
318
|
}
|
|
153
319
|
|
|
154
|
-
if (!
|
|
320
|
+
if (!rawEventKeys.length || config.disableTouch) {
|
|
155
321
|
return omit(propsRef.current, removeProps)
|
|
156
322
|
}
|
|
157
323
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
) {
|
|
163
|
-
events.forEach(event => {
|
|
164
|
-
if (propsRef.current[event]) {
|
|
165
|
-
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event)
|
|
166
|
-
if (match) {
|
|
167
|
-
oe.stopPropagation()
|
|
168
|
-
}
|
|
169
|
-
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config))
|
|
324
|
+
const events = useMemo(() => {
|
|
325
|
+
const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
|
|
326
|
+
if (propsRef.current[key]) {
|
|
327
|
+
return acc.concat(eventConfig[key])
|
|
170
328
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 }
|
|
176
|
-
const nativeEvent = e.nativeEvent
|
|
177
|
-
const currentPageX = nativeEvent.changedTouches[0].pageX
|
|
178
|
-
const currentPageY = nativeEvent.changedTouches[0].pageY
|
|
179
|
-
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
180
|
-
ref.current.needPress[type] = false
|
|
181
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
|
|
182
|
-
ref.current.startTimer[type] = null
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function handleTouchstart (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
187
|
-
e.persist()
|
|
188
|
-
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
|
|
189
|
-
const bubblePressEvent = ['catchlongpress', 'bindlongpress']
|
|
190
|
-
const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart']
|
|
191
|
-
const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress']
|
|
192
|
-
ref.current.startTimer[type] = null
|
|
193
|
-
ref.current.needPress[type] = true
|
|
194
|
-
const nativeEvent = e.nativeEvent
|
|
195
|
-
ref.current.mpxPressInfo.detail = {
|
|
196
|
-
x: nativeEvent.changedTouches[0].pageX,
|
|
197
|
-
y: nativeEvent.changedTouches[0].pageY
|
|
198
|
-
}
|
|
199
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
200
|
-
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent
|
|
201
|
-
handleEmitEvent(currentTouchEvent, 'touchstart', e)
|
|
202
|
-
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current
|
|
203
|
-
if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
|
|
204
|
-
ref.current.startTimer[type] = setTimeout(() => {
|
|
205
|
-
ref.current.needPress[type] = false
|
|
206
|
-
handleEmitEvent(currentPressEvent, 'longpress', e)
|
|
207
|
-
}, 350)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
212
|
-
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
|
|
213
|
-
const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove']
|
|
214
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
215
|
-
handleEmitEvent(currentTouchEvent, 'touchmove', e)
|
|
216
|
-
checkIsNeedPress(e, type)
|
|
217
|
-
}
|
|
329
|
+
return acc
|
|
330
|
+
}, [])
|
|
331
|
+
const finalEventKeys = [...new Set(transformedEventKeys)]
|
|
332
|
+
const events: Record<string, (e: NativeTouchEvent) => void> = {}
|
|
218
333
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const bubbleTapEvent = ['catchtap', 'bindtap']
|
|
224
|
-
const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend']
|
|
225
|
-
const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
|
|
226
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
227
|
-
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent
|
|
228
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
|
|
229
|
-
ref.current.startTimer[type] = null
|
|
230
|
-
handleEmitEvent(currentTouchEvent, 'touchend', e)
|
|
231
|
-
if (ref.current.needPress[type]) {
|
|
232
|
-
if (type === 'bubble' && config.disableTap) {
|
|
233
|
-
return
|
|
334
|
+
touchEventList.forEach((item) => {
|
|
335
|
+
if (finalEventKeys.includes(item.eventName)) {
|
|
336
|
+
events[item.eventName] = (e: NativeTouchEvent) =>
|
|
337
|
+
item.handler(e, ref, propsRef, config)
|
|
234
338
|
}
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function handleTouchcancel (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
240
|
-
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
|
|
241
|
-
const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel']
|
|
242
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
243
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
|
|
244
|
-
ref.current.startTimer[type] = null
|
|
245
|
-
handleEmitEvent(currentTouchEvent, 'touchcancel', e)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const touchEventList = [{
|
|
249
|
-
eventName: 'onTouchStart',
|
|
250
|
-
handler: (e: NativeTouchEvent) => {
|
|
251
|
-
handleTouchstart(e, 'bubble')
|
|
252
|
-
}
|
|
253
|
-
}, {
|
|
254
|
-
eventName: 'onTouchMove',
|
|
255
|
-
handler: (e: NativeTouchEvent) => {
|
|
256
|
-
handleTouchmove(e, 'bubble')
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
eventName: 'onTouchEnd',
|
|
260
|
-
handler: (e: NativeTouchEvent) => {
|
|
261
|
-
handleTouchend(e, 'bubble')
|
|
262
|
-
}
|
|
263
|
-
}, {
|
|
264
|
-
eventName: 'onTouchCancel',
|
|
265
|
-
handler: (e: NativeTouchEvent) => {
|
|
266
|
-
handleTouchcancel(e, 'bubble')
|
|
267
|
-
}
|
|
268
|
-
}, {
|
|
269
|
-
eventName: 'onTouchStartCapture',
|
|
270
|
-
handler: (e: NativeTouchEvent) => {
|
|
271
|
-
handleTouchstart(e, 'capture')
|
|
272
|
-
}
|
|
273
|
-
}, {
|
|
274
|
-
eventName: 'onTouchMoveCapture',
|
|
275
|
-
handler: (e: NativeTouchEvent) => {
|
|
276
|
-
handleTouchmove(e, 'capture')
|
|
277
|
-
}
|
|
278
|
-
}, {
|
|
279
|
-
eventName: 'onTouchEndCapture',
|
|
280
|
-
handler: (e: NativeTouchEvent) => {
|
|
281
|
-
handleTouchend(e, 'capture')
|
|
282
|
-
}
|
|
283
|
-
}, {
|
|
284
|
-
eventName: 'onTouchCancelCapture',
|
|
285
|
-
handler: (e: NativeTouchEvent) => {
|
|
286
|
-
handleTouchcancel(e, 'capture')
|
|
287
|
-
}
|
|
288
|
-
}]
|
|
289
|
-
|
|
290
|
-
const events: Record<string, (e: NativeTouchEvent) => void> = {}
|
|
291
|
-
|
|
292
|
-
const transformedEventKeys: string[] = []
|
|
293
|
-
for (const key in eventConfig) {
|
|
294
|
-
transformedEventKeys.push(...eventConfig[key])
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const finalEventKeys = [...new Set(transformedEventKeys)]
|
|
298
|
-
|
|
299
|
-
touchEventList.forEach(item => {
|
|
300
|
-
if (finalEventKeys.includes(item.eventName)) {
|
|
301
|
-
events[item.eventName] = item.handler
|
|
302
|
-
}
|
|
303
|
-
})
|
|
339
|
+
})
|
|
304
340
|
|
|
305
|
-
|
|
341
|
+
return events
|
|
342
|
+
}, [hashEventKey])
|
|
306
343
|
|
|
307
|
-
return
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
344
|
+
return extendObject(
|
|
345
|
+
{},
|
|
346
|
+
events,
|
|
347
|
+
omit(propsRef.current, [...rawEventKeys, ...removeProps])
|
|
348
|
+
)
|
|
311
349
|
}
|
|
312
350
|
export default useInnerProps
|