@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.1

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.
Files changed (150) hide show
  1. package/lib/index.js +30 -9
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -1,6 +1,6 @@
1
- import { useRef } from 'react'
2
- import { NativeSyntheticEvent } from 'react-native'
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
- return {
34
- ...event,
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
- ...(event.currentTarget || {}),
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
- { detail = {}, layoutRef }: { detail?: Record<string, unknown>; layoutRef: LayoutRef },
81
+ {
82
+ detail = {},
83
+ layoutRef
84
+ }: { detail?: Record<string, unknown>; layoutRef?: LayoutRef },
89
85
  props: Props = {}
90
86
  ) => {
91
- return {
92
- ...oe,
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
136
+ }
137
+ }
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
+ }
105
251
  }
106
252
  }
107
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,10 @@ const useInnerProps = (
130
287
 
131
288
  const propsRef = useRef<Record<string, any>>({})
132
289
  const eventConfig: { [key: string]: string[] } = {}
133
- const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false }
290
+ const config = rawConfig || {
291
+ layoutRef: { current: {} },
292
+ disableTap: false
293
+ }
134
294
  const removeProps = [
135
295
  'children',
136
296
  'enable-background',
@@ -143,170 +303,46 @@ const useInnerProps = (
143
303
  ...userRemoveProps
144
304
  ]
145
305
 
146
- propsRef.current = { ...props, ...additionalProps }
147
-
148
- for (const key in eventConfigMap) {
149
- if (propsRef.current[key]) {
150
- eventConfig[key] = eventConfigMap[key]
151
- }
152
- }
153
-
154
- if (!(Object.keys(eventConfig).length) || config.disableTouch) {
155
- return omit(propsRef.current, removeProps)
156
- }
306
+ propsRef.current = extendObject({}, props, additionalProps)
157
307
 
158
- function handleEmitEvent (
159
- events: string[],
160
- type: string,
161
- oe: NativeTouchEvent
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))
170
- }
171
- })
172
- }
308
+ let hashEventKey = ''
309
+ const rawEventKeys: Array<string> = []
173
310
 
174
- function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture') {
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
311
+ for (const key in eventConfigMap) {
312
+ if (hasOwn(propsRef.current, key)) {
313
+ eventConfig[key] = eventConfigMap[key].events
314
+ hashEventKey = hashEventKey + eventConfigMap[key].bitFlag
315
+ rawEventKeys.push(key)
183
316
  }
184
317
  }
185
318
 
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)
319
+ const events = useMemo(() => {
320
+ if (!rawEventKeys.length) {
321
+ return {}
208
322
  }
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
- }
218
-
219
- function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture') {
220
- // move event may not be triggered
221
- checkIsNeedPress(e, type)
222
- const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
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
323
+ const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
324
+ if (propsRef.current[key]) {
325
+ return acc.concat(eventConfig[key])
234
326
  }
235
- handleEmitEvent(currentTapEvent, 'tap', e)
236
- }
237
- }
327
+ return acc
328
+ }, [])
329
+ const finalEventKeys = [...new Set(transformedEventKeys)]
330
+ const events: Record<string, (e: NativeTouchEvent) => void> = {}
238
331
 
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
- })
332
+ touchEventList.forEach((item) => {
333
+ if (finalEventKeys.includes(item.eventName)) {
334
+ events[item.eventName] = (e: NativeTouchEvent) =>
335
+ item.handler(e, ref, propsRef, config)
336
+ }
337
+ })
304
338
 
305
- const rawEventKeys = Object.keys(eventConfig)
339
+ return events
340
+ }, [hashEventKey])
306
341
 
307
- return {
308
- ...events,
309
- ...omit(propsRef.current, [...rawEventKeys, ...removeProps])
310
- }
342
+ return extendObject(
343
+ {},
344
+ events,
345
+ omit(propsRef.current, [...rawEventKeys, ...removeProps])
346
+ )
311
347
  }
312
348
  export default useInnerProps