@mpxjs/webpack-plugin 2.9.69 → 2.9.70

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 (111) hide show
  1. package/lib/parser.js +1 -1
  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/fix-component-name.js +15 -12
  5. package/lib/platform/template/wx/component-config/index.js +1 -1
  6. package/lib/platform/template/wx/component-config/input.js +1 -1
  7. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  8. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  9. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/processTemplate.js +3 -0
  12. package/lib/runtime/components/react/context.ts +4 -0
  13. package/lib/runtime/components/react/dist/context.js +1 -0
  14. package/lib/runtime/components/react/dist/event.config.js +24 -24
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  16. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  17. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
  19. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  20. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  21. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  22. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  23. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  25. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  26. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  27. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  28. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  29. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  30. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  31. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  32. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  34. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
  36. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
  37. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  38. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  39. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  40. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  41. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  42. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  43. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
  45. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  48. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
  52. package/lib/runtime/components/react/dist/utils.jsx +107 -82
  53. package/lib/runtime/components/react/event.config.ts +25 -26
  54. package/lib/runtime/components/react/getInnerListeners.ts +238 -188
  55. package/lib/runtime/components/react/mpx-button.tsx +64 -50
  56. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  61. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  62. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  63. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  64. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  65. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  66. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  67. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  68. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  70. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  71. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  72. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  73. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  74. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  75. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  76. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  77. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  78. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  79. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  80. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  81. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  82. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  83. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  84. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  85. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  87. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  88. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  89. package/lib/runtime/components/react/mpx-view.tsx +55 -65
  90. package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
  91. package/lib/runtime/components/react/types/global.d.ts +3 -17
  92. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  93. package/lib/runtime/components/react/utils.tsx +113 -82
  94. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  95. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  96. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  97. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  98. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  99. package/lib/runtime/optionProcessor.js +7 -38
  100. package/lib/runtime/utils.js +2 -0
  101. package/lib/style-compiler/plugins/scope-id.js +30 -2
  102. package/lib/template-compiler/bind-this.js +7 -2
  103. package/lib/template-compiler/compiler.js +77 -46
  104. package/lib/template-compiler/gen-node-react.js +2 -2
  105. package/lib/utils/pre-process-json.js +9 -5
  106. package/package.json +5 -4
  107. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  108. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  109. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  110. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  111. package/lib/runtime/components/web/event.js +0 -105
@@ -1,6 +1,6 @@
1
- import { useRef } from 'react'
2
- import { collectDataset } from '@mpxjs/utils'
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,
@@ -20,31 +20,38 @@ const getTouchEvent = (
20
20
  config: UseInnerPropsConfig
21
21
  ) => {
22
22
  const nativeEvent = event.nativeEvent
23
- const {
24
- timestamp,
25
- pageX,
26
- pageY,
27
- touches,
28
- changedTouches
29
- } = nativeEvent
23
+ const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent
30
24
  const { id } = props
31
25
  const { layoutRef } = config
32
- return {
33
- ...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, {
34
46
  type,
35
47
  timeStamp: timestamp,
36
- currentTarget: {
37
- ...(event.currentTarget || {}),
38
- id: id || '',
39
- dataset: collectDataset(props),
40
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
41
- offsetTop: layoutRef?.current?.offsetTop || 0
42
- },
48
+ currentTarget,
49
+ target,
43
50
  detail: {
44
51
  x: pageX,
45
52
  y: pageY
46
53
  },
47
- touches: touches.map(item => {
54
+ touches: touches.map((item) => {
48
55
  return {
49
56
  identifier: item.identifier,
50
57
  pageX: item.pageX,
@@ -53,7 +60,7 @@ const getTouchEvent = (
53
60
  clientY: item.locationY
54
61
  }
55
62
  }),
56
- changedTouches: changedTouches.map(item => {
63
+ changedTouches: changedTouches.map((item) => {
57
64
  return {
58
65
  identifier: item.identifier,
59
66
  pageX: item.pageX,
@@ -65,32 +72,196 @@ const getTouchEvent = (
65
72
  persist: event.persist,
66
73
  stopPropagation: event.stopPropagation,
67
74
  preventDefault: event.preventDefault
68
- }
75
+ })
69
76
  }
70
77
 
71
78
  export const getCustomEvent = (
72
79
  type = '',
73
80
  oe: any = {},
74
- { detail = {}, layoutRef }: { detail?: Record<string, unknown>; layoutRef: LayoutRef },
81
+ {
82
+ detail = {},
83
+ layoutRef
84
+ }: { detail?: Record<string, unknown>; layoutRef?: LayoutRef },
75
85
  props: Props = {}
76
86
  ) => {
77
- return {
78
- ...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, {
79
94
  type,
80
95
  detail,
81
- target: {
82
- ...(oe.target || {}),
83
- id: props.id || '',
84
- dataset: collectDataset(props),
85
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
86
- offsetTop: layoutRef?.current?.offsetTop || 0
87
- },
96
+ target: targetInfo,
88
97
  persist: oe.persist,
89
98
  stopPropagation: oe.stopPropagation,
90
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) > 3 ||
130
+ Math.abs(currentPageY - tapDetailInfo.y) > 3
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
+ }
91
251
  }
92
252
  }
93
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
+
94
265
  const useInnerProps = (
95
266
  props: Props = {},
96
267
  additionalProps: AdditionalProps = {},
@@ -116,7 +287,10 @@ const useInnerProps = (
116
287
 
117
288
  const propsRef = useRef<Record<string, any>>({})
118
289
  const eventConfig: { [key: string]: string[] } = {}
119
- const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false }
290
+ const config = rawConfig || {
291
+ layoutRef: { current: {} },
292
+ disableTap: false
293
+ }
120
294
  const removeProps = [
121
295
  'children',
122
296
  'enable-background',
@@ -129,170 +303,46 @@ const useInnerProps = (
129
303
  ...userRemoveProps
130
304
  ]
131
305
 
132
- propsRef.current = { ...props, ...additionalProps }
133
-
134
- for (const key in eventConfigMap) {
135
- if (propsRef.current[key]) {
136
- eventConfig[key] = eventConfigMap[key]
137
- }
138
- }
139
-
140
- if (!(Object.keys(eventConfig).length) || config.disableTouch) {
141
- return omit(propsRef.current, removeProps)
142
- }
306
+ propsRef.current = extendObject({}, props, additionalProps)
143
307
 
144
- function handleEmitEvent (
145
- events: string[],
146
- type: string,
147
- oe: NativeTouchEvent
148
- ) {
149
- events.forEach(event => {
150
- if (propsRef.current[event]) {
151
- const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event)
152
- if (match) {
153
- oe.stopPropagation()
154
- }
155
- propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config))
156
- }
157
- })
158
- }
308
+ let hashEventKey = ''
309
+ const rawEventKeys: Array<string> = []
159
310
 
160
- function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture') {
161
- const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 }
162
- const nativeEvent = e.nativeEvent
163
- const currentPageX = nativeEvent.changedTouches[0].pageX
164
- const currentPageY = nativeEvent.changedTouches[0].pageY
165
- if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
166
- ref.current.needPress[type] = false
167
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
168
- 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)
169
316
  }
170
317
  }
171
318
 
172
- function handleTouchstart (e: NativeTouchEvent, type: 'bubble' | 'capture') {
173
- e.persist()
174
- const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
175
- const bubblePressEvent = ['catchlongpress', 'bindlongpress']
176
- const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart']
177
- const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress']
178
- ref.current.startTimer[type] = null
179
- ref.current.needPress[type] = true
180
- const nativeEvent = e.nativeEvent
181
- ref.current.mpxPressInfo.detail = {
182
- x: nativeEvent.changedTouches[0].pageX,
183
- y: nativeEvent.changedTouches[0].pageY
319
+ const events = useMemo(() => {
320
+ if (!rawEventKeys.length) {
321
+ return {}
184
322
  }
185
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
186
- const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent
187
- handleEmitEvent(currentTouchEvent, 'touchstart', e)
188
- const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current
189
- if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
190
- ref.current.startTimer[type] = setTimeout(() => {
191
- ref.current.needPress[type] = false
192
- handleEmitEvent(currentPressEvent, 'longpress', e)
193
- }, 350)
194
- }
195
- }
196
-
197
- function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture') {
198
- const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
199
- const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove']
200
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
201
- handleEmitEvent(currentTouchEvent, 'touchmove', e)
202
- checkIsNeedPress(e, type)
203
- }
204
-
205
- function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture') {
206
- // move event may not be triggered
207
- checkIsNeedPress(e, type)
208
- const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
209
- const bubbleTapEvent = ['catchtap', 'bindtap']
210
- const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend']
211
- const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
212
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
213
- const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent
214
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
215
- ref.current.startTimer[type] = null
216
- handleEmitEvent(currentTouchEvent, 'touchend', e)
217
- if (ref.current.needPress[type]) {
218
- if (type === 'bubble' && config.disableTap) {
219
- return
323
+ const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
324
+ if (propsRef.current[key]) {
325
+ return acc.concat(eventConfig[key])
220
326
  }
221
- handleEmitEvent(currentTapEvent, 'tap', e)
222
- }
223
- }
224
-
225
- function handleTouchcancel (e: NativeTouchEvent, type: 'bubble' | 'capture') {
226
- const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel']
227
- const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel']
228
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
229
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
230
- ref.current.startTimer[type] = null
231
- handleEmitEvent(currentTouchEvent, 'touchcancel', e)
232
- }
233
-
234
- const touchEventList = [{
235
- eventName: 'onTouchStart',
236
- handler: (e: NativeTouchEvent) => {
237
- handleTouchstart(e, 'bubble')
238
- }
239
- }, {
240
- eventName: 'onTouchMove',
241
- handler: (e: NativeTouchEvent) => {
242
- handleTouchmove(e, 'bubble')
243
- }
244
- }, {
245
- eventName: 'onTouchEnd',
246
- handler: (e: NativeTouchEvent) => {
247
- handleTouchend(e, 'bubble')
248
- }
249
- }, {
250
- eventName: 'onTouchCancel',
251
- handler: (e: NativeTouchEvent) => {
252
- handleTouchcancel(e, 'bubble')
253
- }
254
- }, {
255
- eventName: 'onTouchStartCapture',
256
- handler: (e: NativeTouchEvent) => {
257
- handleTouchstart(e, 'capture')
258
- }
259
- }, {
260
- eventName: 'onTouchMoveCapture',
261
- handler: (e: NativeTouchEvent) => {
262
- handleTouchmove(e, 'capture')
263
- }
264
- }, {
265
- eventName: 'onTouchEndCapture',
266
- handler: (e: NativeTouchEvent) => {
267
- handleTouchend(e, 'capture')
268
- }
269
- }, {
270
- eventName: 'onTouchCancelCapture',
271
- handler: (e: NativeTouchEvent) => {
272
- handleTouchcancel(e, 'capture')
273
- }
274
- }]
275
-
276
- const events: Record<string, (e: NativeTouchEvent) => void> = {}
277
-
278
- const transformedEventKeys: string[] = []
279
- for (const key in eventConfig) {
280
- transformedEventKeys.push(...eventConfig[key])
281
- }
282
-
283
- const finalEventKeys = [...new Set(transformedEventKeys)]
327
+ return acc
328
+ }, [])
329
+ const finalEventKeys = [...new Set(transformedEventKeys)]
330
+ const events: Record<string, (e: NativeTouchEvent) => void> = {}
284
331
 
285
- touchEventList.forEach(item => {
286
- if (finalEventKeys.includes(item.eventName)) {
287
- events[item.eventName] = item.handler
288
- }
289
- })
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
+ })
290
338
 
291
- const rawEventKeys = Object.keys(eventConfig)
339
+ return events
340
+ }, [hashEventKey])
292
341
 
293
- return {
294
- ...events,
295
- ...omit(propsRef.current, [...rawEventKeys, ...removeProps])
296
- }
342
+ return extendObject(
343
+ {},
344
+ events,
345
+ omit(propsRef.current, [...rawEventKeys, ...removeProps])
346
+ )
297
347
  }
298
348
  export default useInnerProps
@@ -34,7 +34,7 @@
34
34
  * ✘ bindagreeprivacyauthorization
35
35
  * ✔ bindtap
36
36
  */
37
- import { useEffect, useRef, useState, ReactNode, forwardRef, useContext, JSX } from 'react'
37
+ import { createElement, useEffect, useRef, useState, ReactNode, forwardRef, useContext, JSX } from 'react'
38
38
  import {
39
39
  View,
40
40
  StyleSheet,
@@ -45,7 +45,7 @@ import {
45
45
  NativeSyntheticEvent
46
46
  } from 'react-native'
47
47
  import { warn } from '@mpxjs/utils'
48
- import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
48
+ import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
49
49
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
50
50
  import useNodesRef, { HandlerRef } from './useNodesRef'
51
51
  import { RouteContext, FormContext } from './context'
@@ -181,11 +181,14 @@ const Loading = ({ alone = false }: { alone: boolean }): JSX.Element => {
181
181
  }
182
182
  }, [])
183
183
 
184
- const loadingStyle = {
185
- ...styles.loading,
186
- transform: [{ rotate }],
187
- marginRight: alone ? 0 : 5
188
- }
184
+ const loadingStyle = extendObject(
185
+ {},
186
+ styles.loading,
187
+ {
188
+ transform: [{ rotate }],
189
+ marginRight: alone ? 0 : 5
190
+ }
191
+ )
189
192
 
190
193
  return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }} />
191
194
  }
@@ -274,28 +277,28 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
274
277
  backgroundColor: plain ? 'transparent' : normalBackgroundColor
275
278
  }
276
279
 
277
- const defaultViewStyle = {
278
- ...styles.button,
279
- ...(isMiniSize && styles.buttonMini),
280
- ...viewStyle
281
- }
280
+ const defaultViewStyle = extendObject(
281
+ {},
282
+ styles.button,
283
+ isMiniSize ? styles.buttonMini : null,
284
+ viewStyle
285
+ )
282
286
 
283
- const defaultTextStyle = {
284
- ...styles.text,
285
- ...(isMiniSize && styles.textMini),
286
- color: plain ? plainTextColor : normalTextColor
287
- }
287
+ const defaultTextStyle = extendObject(
288
+ {},
289
+ styles.text,
290
+ isMiniSize ? styles.textMini : {},
291
+ { color: plain ? plainTextColor : normalTextColor }
292
+ )
288
293
 
289
- const defaultStyle = {
290
- ...defaultViewStyle,
291
- ...defaultTextStyle
292
- }
294
+ const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle)
293
295
 
294
- const styleObj = {
295
- ...defaultStyle,
296
- ...style,
297
- ...(applyHoverEffect && hoverStyle)
298
- }
296
+ const styleObj = extendObject(
297
+ {},
298
+ defaultStyle,
299
+ style,
300
+ applyHoverEffect ? hoverStyle : {}
301
+ )
299
302
 
300
303
  const {
301
304
  hasSelfPercent,
@@ -308,11 +311,11 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
308
311
 
309
312
  const nodeRef = useRef(null)
310
313
 
311
- useNodesRef(props, ref, nodeRef, { defaultStyle })
314
+ useNodesRef(props, ref, nodeRef, { style: normalStyle })
312
315
 
313
316
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
314
317
 
315
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
318
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
316
319
 
317
320
  if (backgroundStyle) {
318
321
  warn('Button does not support background image-related styles!')
@@ -408,36 +411,47 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
408
411
 
409
412
  const innerProps = useInnerProps(
410
413
  props,
411
- {
412
- ref: nodeRef,
413
- style: { ...innerStyle, ...layoutStyle },
414
- ...layoutProps,
415
- bindtouchstart: onTouchStart,
416
- bindtouchend: onTouchEnd,
417
- bindtap: onTap
418
- },
419
- [],
414
+ extendObject(
415
+ {
416
+ ref: nodeRef,
417
+ style: extendObject({}, innerStyle, layoutStyle)
418
+ },
419
+ layoutProps,
420
+ {
421
+ bindtouchstart: (bindtouchstart || !disabled) && onTouchStart,
422
+ bindtouchend: (bindtouchend || !disabled) && onTouchEnd,
423
+ bindtap: !disabled && onTap
424
+ }
425
+ ),
426
+ [
427
+ 'disabled',
428
+ 'size',
429
+ 'type',
430
+ 'plain',
431
+ 'loading',
432
+ 'hover-class',
433
+ 'hover-style',
434
+ 'hover-start-time',
435
+ 'hover-stay-time',
436
+ 'open-type',
437
+ 'form-type'
438
+ ],
420
439
  {
421
440
  layoutRef,
422
441
  disableTap: disabled
423
442
  }
424
443
  )
425
444
 
426
- return (
427
- <View {...innerProps}>
428
- {loading && <Loading alone={!children} />}
445
+ return createElement(View, innerProps, loading && createElement(Loading, { alone: !children }),
446
+ wrapChildren(
447
+ props,
429
448
  {
430
- wrapChildren(
431
- props,
432
- {
433
- hasVarDec,
434
- varContext: varContextRef.current,
435
- textStyle,
436
- textProps
437
- }
438
- )
449
+ hasVarDec,
450
+ varContext: varContextRef.current,
451
+ textStyle,
452
+ textProps
439
453
  }
440
- </View>
454
+ )
441
455
  )
442
456
  })
443
457
 
@@ -316,8 +316,7 @@ var handleError = function (err, message) {
316
316
  document.removeEventListener('message', handleIncomingMessage);
317
317
  };
318
318
 
319
- function handleIncomingMessage(e) {
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.addEventListener('message', handleIncomingMessage);
339
- document.addEventListener('message', handleIncomingMessage);
337
+ window.mpxWebviewMessageCallback = handleIncomingMessage
340
338
  </script>
341
339
 
342
340