@mpxjs/webpack-plugin 2.9.70-alpha.0 → 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.
- package/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +0 -14
- package/lib/dependencies/ResolveDependency.js +0 -5
- package/lib/index.js +7 -38
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +0 -53
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +6 -2
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +1 -127
- package/lib/resolve-loader.js +1 -4
- package/lib/runtime/components/react/dist/getInnerListeners.js +5 -6
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +96 -107
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +26 -27
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +480 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +68 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +6 -3
- package/lib/runtime/components/react/dist/pickerFaces.js +6 -12
- package/lib/runtime/components/react/dist/{pickerViewOverlay.jsx → pickerOverlay.jsx} +3 -5
- package/lib/runtime/components/react/dist/useAnimationHooks.js +7 -8
- package/lib/runtime/components/react/dist/utils.jsx +89 -60
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +212 -169
- package/lib/runtime/components/react/mpx-button.tsx +9 -14
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +44 -46
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +15 -13
- package/lib/runtime/components/react/mpx-checkbox.tsx +20 -21
- package/lib/runtime/components/react/mpx-form.tsx +15 -20
- package/lib/runtime/components/react/mpx-icon.tsx +2 -2
- package/lib/runtime/components/react/mpx-image.tsx +87 -47
- package/lib/runtime/components/react/mpx-input.tsx +24 -32
- package/lib/runtime/components/react/mpx-label.tsx +12 -14
- package/lib/runtime/components/react/mpx-movable-area.tsx +10 -16
- package/lib/runtime/components/react/mpx-movable-view.tsx +20 -24
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-radio-group.tsx +13 -15
- package/lib/runtime/components/react/mpx-radio.tsx +19 -25
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +40 -41
- package/lib/runtime/components/react/mpx-switch.tsx +19 -15
- package/lib/runtime/components/react/mpx-text.tsx +8 -16
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +18 -20
- package/lib/runtime/components/react/mpx-web-view.tsx +94 -59
- package/lib/runtime/components/react/types/global.d.ts +2 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +91 -60
- package/lib/runtime/components/web/mpx-web-view.vue +34 -20
- package/lib/runtime/optionProcessor.js +0 -22
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/compiler.js +30 -26
- package/lib/utils/env.js +1 -6
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +4 -7
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +0 -39
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +0 -606
- package/lib/runtime/components/react/dist/pickerVIewContext.js +0 -9
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +0 -18
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -334
- package/lib/runtime/components/tenon/tenon-button.vue +0 -309
- package/lib/runtime/components/tenon/tenon-image.vue +0 -66
- package/lib/runtime/components/tenon/tenon-input.vue +0 -171
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -26
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -127
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -96
- package/lib/runtime/components/tenon/tenon-text.vue +0 -70
- package/lib/runtime/components/tenon/tenon-textarea.vue +0 -86
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/web/event.js +0 -105
- package/lib/runtime/optionProcessor.tenon.js +0 -84
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -117
- package/lib/tenon/processJSON.js +0 -352
- package/lib/tenon/processScript.js +0 -203
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -126
- package/lib/tenon/script-helper.js +0 -223
- package/lib/utils/get-relative-path.js +0 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef } from 'react'
|
|
1
|
+
import { useRef, useMemo, RefObject } from 'react'
|
|
2
2
|
import { hasOwn, collectDataset } from '@mpxjs/utils'
|
|
3
3
|
import { omit, extendObject } from './utils'
|
|
4
4
|
import eventConfigMap from './event.config'
|
|
@@ -20,24 +20,25 @@ 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
26
|
|
|
33
|
-
const currentTarget = extendObject(
|
|
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(
|
|
34
37
|
{},
|
|
35
|
-
event.
|
|
38
|
+
event.target,
|
|
36
39
|
{
|
|
37
|
-
id:
|
|
38
|
-
dataset: collectDataset(
|
|
39
|
-
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
40
|
-
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
40
|
+
id: pendingProps.parentId || pendingProps.nativeID || '',
|
|
41
|
+
dataset: collectDataset(pendingProps)
|
|
41
42
|
}
|
|
42
43
|
)
|
|
43
44
|
|
|
@@ -45,11 +46,12 @@ const getTouchEvent = (
|
|
|
45
46
|
type,
|
|
46
47
|
timeStamp: timestamp,
|
|
47
48
|
currentTarget,
|
|
49
|
+
target,
|
|
48
50
|
detail: {
|
|
49
51
|
x: pageX,
|
|
50
52
|
y: pageY
|
|
51
53
|
},
|
|
52
|
-
touches: touches.map(item => {
|
|
54
|
+
touches: touches.map((item) => {
|
|
53
55
|
return {
|
|
54
56
|
identifier: item.identifier,
|
|
55
57
|
pageX: item.pageX,
|
|
@@ -58,7 +60,7 @@ const getTouchEvent = (
|
|
|
58
60
|
clientY: item.locationY
|
|
59
61
|
}
|
|
60
62
|
}),
|
|
61
|
-
changedTouches: changedTouches.map(item => {
|
|
63
|
+
changedTouches: changedTouches.map((item) => {
|
|
62
64
|
return {
|
|
63
65
|
identifier: item.identifier,
|
|
64
66
|
pageX: item.pageX,
|
|
@@ -76,7 +78,10 @@ const getTouchEvent = (
|
|
|
76
78
|
export const getCustomEvent = (
|
|
77
79
|
type = '',
|
|
78
80
|
oe: any = {},
|
|
79
|
-
{
|
|
81
|
+
{
|
|
82
|
+
detail = {},
|
|
83
|
+
layoutRef
|
|
84
|
+
}: { detail?: Record<string, unknown>; layoutRef?: LayoutRef },
|
|
80
85
|
props: Props = {}
|
|
81
86
|
) => {
|
|
82
87
|
const targetInfo = extendObject({}, oe.target, {
|
|
@@ -95,6 +100,168 @@ export const getCustomEvent = (
|
|
|
95
100
|
})
|
|
96
101
|
}
|
|
97
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
|
+
}
|
|
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
|
+
|
|
98
265
|
const useInnerProps = (
|
|
99
266
|
props: Props = {},
|
|
100
267
|
additionalProps: AdditionalProps = {},
|
|
@@ -120,7 +287,10 @@ const useInnerProps = (
|
|
|
120
287
|
|
|
121
288
|
const propsRef = useRef<Record<string, any>>({})
|
|
122
289
|
const eventConfig: { [key: string]: string[] } = {}
|
|
123
|
-
const config = rawConfig || {
|
|
290
|
+
const config = rawConfig || {
|
|
291
|
+
layoutRef: { current: {} },
|
|
292
|
+
disableTap: false
|
|
293
|
+
}
|
|
124
294
|
const removeProps = [
|
|
125
295
|
'children',
|
|
126
296
|
'enable-background',
|
|
@@ -135,166 +305,39 @@ const useInnerProps = (
|
|
|
135
305
|
|
|
136
306
|
propsRef.current = extendObject({}, props, additionalProps)
|
|
137
307
|
|
|
308
|
+
let hashEventKey = ''
|
|
309
|
+
const rawEventKeys: Array<string> = []
|
|
310
|
+
|
|
138
311
|
for (const key in eventConfigMap) {
|
|
139
312
|
if (hasOwn(propsRef.current, key)) {
|
|
140
|
-
eventConfig[key] = eventConfigMap[key]
|
|
313
|
+
eventConfig[key] = eventConfigMap[key].events
|
|
314
|
+
hashEventKey = hashEventKey + eventConfigMap[key].bitFlag
|
|
315
|
+
rawEventKeys.push(key)
|
|
141
316
|
}
|
|
142
317
|
}
|
|
143
318
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
function handleEmitEvent (
|
|
149
|
-
events: string[],
|
|
150
|
-
type: string,
|
|
151
|
-
oe: NativeTouchEvent
|
|
152
|
-
) {
|
|
153
|
-
events.forEach(event => {
|
|
154
|
-
if (propsRef.current[event]) {
|
|
155
|
-
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event)
|
|
156
|
-
if (match) {
|
|
157
|
-
oe.stopPropagation()
|
|
158
|
-
}
|
|
159
|
-
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config))
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function checkIsNeedPress (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
165
|
-
const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 }
|
|
166
|
-
const nativeEvent = e.nativeEvent
|
|
167
|
-
const currentPageX = nativeEvent.changedTouches[0].pageX
|
|
168
|
-
const currentPageY = nativeEvent.changedTouches[0].pageY
|
|
169
|
-
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
170
|
-
ref.current.needPress[type] = false
|
|
171
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
|
|
172
|
-
ref.current.startTimer[type] = null
|
|
319
|
+
const events = useMemo(() => {
|
|
320
|
+
if (!rawEventKeys.length) {
|
|
321
|
+
return {}
|
|
173
322
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
e.persist()
|
|
178
|
-
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart']
|
|
179
|
-
const bubblePressEvent = ['catchlongpress', 'bindlongpress']
|
|
180
|
-
const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart']
|
|
181
|
-
const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress']
|
|
182
|
-
ref.current.startTimer[type] = null
|
|
183
|
-
ref.current.needPress[type] = true
|
|
184
|
-
const nativeEvent = e.nativeEvent
|
|
185
|
-
ref.current.mpxPressInfo.detail = {
|
|
186
|
-
x: nativeEvent.changedTouches[0].pageX,
|
|
187
|
-
y: nativeEvent.changedTouches[0].pageY
|
|
188
|
-
}
|
|
189
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
190
|
-
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent
|
|
191
|
-
handleEmitEvent(currentTouchEvent, 'touchstart', e)
|
|
192
|
-
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current
|
|
193
|
-
if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
|
|
194
|
-
ref.current.startTimer[type] = setTimeout(() => {
|
|
195
|
-
ref.current.needPress[type] = false
|
|
196
|
-
handleEmitEvent(currentPressEvent, 'longpress', e)
|
|
197
|
-
}, 350)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function handleTouchmove (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
202
|
-
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove']
|
|
203
|
-
const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove']
|
|
204
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
205
|
-
handleEmitEvent(currentTouchEvent, 'touchmove', e)
|
|
206
|
-
checkIsNeedPress(e, type)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function handleTouchend (e: NativeTouchEvent, type: 'bubble' | 'capture') {
|
|
210
|
-
// move event may not be triggered
|
|
211
|
-
checkIsNeedPress(e, type)
|
|
212
|
-
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend']
|
|
213
|
-
const bubbleTapEvent = ['catchtap', 'bindtap']
|
|
214
|
-
const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend']
|
|
215
|
-
const captureTapEvent = ['capture-catchtap', 'capture-bindtap']
|
|
216
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent
|
|
217
|
-
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent
|
|
218
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type] as SetTimeoutReturnType)
|
|
219
|
-
ref.current.startTimer[type] = null
|
|
220
|
-
handleEmitEvent(currentTouchEvent, 'touchend', e)
|
|
221
|
-
if (ref.current.needPress[type]) {
|
|
222
|
-
if (type === 'bubble' && config.disableTap) {
|
|
223
|
-
return
|
|
323
|
+
const transformedEventKeys = rawEventKeys.reduce((acc: string[], key) => {
|
|
324
|
+
if (propsRef.current[key]) {
|
|
325
|
+
return acc.concat(eventConfig[key])
|
|
224
326
|
}
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
327
|
+
return acc
|
|
328
|
+
}, [])
|
|
329
|
+
const finalEventKeys = [...new Set(transformedEventKeys)]
|
|
330
|
+
const events: Record<string, (e: NativeTouchEvent) => void> = {}
|
|
228
331
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
handleEmitEvent(currentTouchEvent, 'touchcancel', e)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const touchEventList = [{
|
|
239
|
-
eventName: 'onTouchStart',
|
|
240
|
-
handler: (e: NativeTouchEvent) => {
|
|
241
|
-
handleTouchstart(e, 'bubble')
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
eventName: 'onTouchMove',
|
|
245
|
-
handler: (e: NativeTouchEvent) => {
|
|
246
|
-
handleTouchmove(e, 'bubble')
|
|
247
|
-
}
|
|
248
|
-
}, {
|
|
249
|
-
eventName: 'onTouchEnd',
|
|
250
|
-
handler: (e: NativeTouchEvent) => {
|
|
251
|
-
handleTouchend(e, 'bubble')
|
|
252
|
-
}
|
|
253
|
-
}, {
|
|
254
|
-
eventName: 'onTouchCancel',
|
|
255
|
-
handler: (e: NativeTouchEvent) => {
|
|
256
|
-
handleTouchcancel(e, 'bubble')
|
|
257
|
-
}
|
|
258
|
-
}, {
|
|
259
|
-
eventName: 'onTouchStartCapture',
|
|
260
|
-
handler: (e: NativeTouchEvent) => {
|
|
261
|
-
handleTouchstart(e, 'capture')
|
|
262
|
-
}
|
|
263
|
-
}, {
|
|
264
|
-
eventName: 'onTouchMoveCapture',
|
|
265
|
-
handler: (e: NativeTouchEvent) => {
|
|
266
|
-
handleTouchmove(e, 'capture')
|
|
267
|
-
}
|
|
268
|
-
}, {
|
|
269
|
-
eventName: 'onTouchEndCapture',
|
|
270
|
-
handler: (e: NativeTouchEvent) => {
|
|
271
|
-
handleTouchend(e, 'capture')
|
|
272
|
-
}
|
|
273
|
-
}, {
|
|
274
|
-
eventName: 'onTouchCancelCapture',
|
|
275
|
-
handler: (e: NativeTouchEvent) => {
|
|
276
|
-
handleTouchcancel(e, 'capture')
|
|
277
|
-
}
|
|
278
|
-
}]
|
|
279
|
-
|
|
280
|
-
const events: Record<string, (e: NativeTouchEvent) => void> = {}
|
|
281
|
-
|
|
282
|
-
let transformedEventKeys: string[] = []
|
|
283
|
-
for (const key in eventConfig) {
|
|
284
|
-
if (propsRef.current[key]) {
|
|
285
|
-
transformedEventKeys = transformedEventKeys.concat(eventConfig[key])
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const finalEventKeys = [...new Set(transformedEventKeys)]
|
|
290
|
-
|
|
291
|
-
touchEventList.forEach(item => {
|
|
292
|
-
if (finalEventKeys.includes(item.eventName)) {
|
|
293
|
-
events[item.eventName] = item.handler
|
|
294
|
-
}
|
|
295
|
-
})
|
|
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
|
+
})
|
|
296
338
|
|
|
297
|
-
|
|
339
|
+
return events
|
|
340
|
+
}, [hashEventKey])
|
|
298
341
|
|
|
299
342
|
return extendObject(
|
|
300
343
|
{},
|
|
@@ -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,
|
|
@@ -442,21 +442,16 @@ const Button = forwardRef<HandlerRef<View, ButtonProps>, ButtonProps>((buttonPro
|
|
|
442
442
|
}
|
|
443
443
|
)
|
|
444
444
|
|
|
445
|
-
return (
|
|
446
|
-
|
|
447
|
-
|
|
445
|
+
return createElement(View, innerProps, loading && createElement(Loading, { alone: !children }),
|
|
446
|
+
wrapChildren(
|
|
447
|
+
props,
|
|
448
448
|
{
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
varContext: varContextRef.current,
|
|
454
|
-
textStyle,
|
|
455
|
-
textProps
|
|
456
|
-
}
|
|
457
|
-
)
|
|
449
|
+
hasVarDec,
|
|
450
|
+
varContext: varContextRef.current,
|
|
451
|
+
textStyle,
|
|
452
|
+
textProps
|
|
458
453
|
}
|
|
459
|
-
|
|
454
|
+
)
|
|
460
455
|
)
|
|
461
456
|
})
|
|
462
457
|
|
|
@@ -316,8 +316,7 @@ var handleError = function (err, message) {
|
|
|
316
316
|
document.removeEventListener('message', handleIncomingMessage);
|
|
317
317
|
};
|
|
318
318
|
|
|
319
|
-
function handleIncomingMessage(
|
|
320
|
-
var data = JSON.parse(e.data);
|
|
319
|
+
function handleIncomingMessage(data) {
|
|
321
320
|
if (Array.isArray(data)) {
|
|
322
321
|
for (var i = 0; i < data.length; i++) {
|
|
323
322
|
try {
|
|
@@ -335,8 +334,7 @@ function handleIncomingMessage(e) {
|
|
|
335
334
|
}
|
|
336
335
|
}
|
|
337
336
|
|
|
338
|
-
window.
|
|
339
|
-
document.addEventListener('message', handleIncomingMessage);
|
|
337
|
+
window.mpxWebviewMessageCallback = handleIncomingMessage
|
|
340
338
|
</script>
|
|
341
339
|
|
|
342
340
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* ✔ bindlongtap
|
|
10
10
|
* ✔ binderror
|
|
11
11
|
*/
|
|
12
|
-
import React, { useRef, useState, useCallback, useEffect, forwardRef, JSX, TouchEvent, MutableRefObject } from 'react'
|
|
12
|
+
import React, { createElement, useRef, useState, useCallback, useEffect, forwardRef, JSX, TouchEvent, MutableRefObject } from 'react'
|
|
13
13
|
import { View, Platform, StyleSheet, NativeSyntheticEvent } from 'react-native'
|
|
14
14
|
import { WebView } from 'react-native-webview'
|
|
15
15
|
import useNodesRef, { HandlerRef } from '../useNodesRef'
|
|
@@ -106,7 +106,11 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
|
|
|
106
106
|
useEffect(() => {
|
|
107
107
|
const webviewPostMessage = (message: WebviewMessage) => {
|
|
108
108
|
if (canvasRef.current.webview) {
|
|
109
|
-
|
|
109
|
+
const jsCode = `
|
|
110
|
+
window.mpxWebviewMessageCallback(${JSON.stringify(message)});
|
|
111
|
+
true;
|
|
112
|
+
`
|
|
113
|
+
canvasRef.current.webview.injectJavaScript(jsCode)
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
|
|
@@ -249,54 +253,48 @@ const _Canvas = forwardRef<HandlerRef<CanvasProps & View, CanvasProps>, CanvasPr
|
|
|
249
253
|
|
|
250
254
|
if (Platform.OS === 'android') {
|
|
251
255
|
const isAndroid9 = Platform.Version >= 28
|
|
252
|
-
return (
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (canvasRef.current) {
|
|
257
|
-
canvasRef.current.webview = element
|
|
258
|
-
}
|
|
259
|
-
}}
|
|
260
|
-
style={[
|
|
261
|
-
isAndroid9 ? stylesheet.webviewAndroid9 : stylesheet.webview,
|
|
262
|
-
{ height, width }
|
|
263
|
-
]}
|
|
264
|
-
source={{ html }}
|
|
265
|
-
originWhitelist={originWhitelist}
|
|
266
|
-
onMessage={onMessage}
|
|
267
|
-
onLoad={onLoad}
|
|
268
|
-
overScrollMode="never"
|
|
269
|
-
mixedContentMode="always"
|
|
270
|
-
scalesPageToFit={false}
|
|
271
|
-
javaScriptEnabled
|
|
272
|
-
domStorageEnabled
|
|
273
|
-
thirdPartyCookiesEnabled
|
|
274
|
-
allowUniversalAccessFromFileURLs
|
|
275
|
-
/>
|
|
276
|
-
</View>
|
|
277
|
-
)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return (
|
|
281
|
-
<View
|
|
282
|
-
{...innerProps}
|
|
283
|
-
>
|
|
284
|
-
<WebView
|
|
285
|
-
ref={(element) => {
|
|
256
|
+
return createElement(View, innerProps, createElement(
|
|
257
|
+
WebView,
|
|
258
|
+
{
|
|
259
|
+
ref: (element) => {
|
|
286
260
|
if (canvasRef.current) {
|
|
287
261
|
canvasRef.current.webview = element
|
|
288
262
|
}
|
|
289
|
-
}
|
|
290
|
-
style
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
263
|
+
},
|
|
264
|
+
style: [
|
|
265
|
+
isAndroid9 ? stylesheet.webviewAndroid9 : stylesheet.webview,
|
|
266
|
+
{ height, width }
|
|
267
|
+
],
|
|
268
|
+
source: { html },
|
|
269
|
+
originWhitelist: originWhitelist,
|
|
270
|
+
onMessage: onMessage,
|
|
271
|
+
onLoad: onLoad,
|
|
272
|
+
overScrollMode: 'never',
|
|
273
|
+
mixedContentMode: 'always',
|
|
274
|
+
scalesPageToFit: false,
|
|
275
|
+
javaScriptEnabled: true,
|
|
276
|
+
domStorageEnabled: true,
|
|
277
|
+
thirdPartyCookiesEnabled: true,
|
|
278
|
+
allowUniversalAccessFromFileURLs: true
|
|
279
|
+
})
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return createElement(View, innerProps, createElement(WebView, {
|
|
284
|
+
ref: (element) => {
|
|
285
|
+
if (canvasRef.current) {
|
|
286
|
+
canvasRef.current.webview = element
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
style: [stylesheet.webview, { height, width }],
|
|
290
|
+
source: { html },
|
|
291
|
+
originWhitelist: originWhitelist,
|
|
292
|
+
onMessage: onMessage,
|
|
293
|
+
onLoad: onLoad,
|
|
294
|
+
scrollEnabled: false
|
|
295
|
+
}))
|
|
299
296
|
})
|
|
297
|
+
|
|
300
298
|
_Canvas.displayName = 'mpxCanvas'
|
|
301
299
|
|
|
302
300
|
export default _Canvas
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
ReactNode,
|
|
9
9
|
useContext,
|
|
10
10
|
useMemo,
|
|
11
|
-
useEffect
|
|
11
|
+
useEffect,
|
|
12
|
+
createElement
|
|
12
13
|
} from 'react'
|
|
13
14
|
import {
|
|
14
15
|
View,
|
|
@@ -156,20 +157,21 @@ const CheckboxGroup = forwardRef<
|
|
|
156
157
|
notifyChange
|
|
157
158
|
}
|
|
158
159
|
}, [])
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
|
|
161
|
+
return createElement(
|
|
162
|
+
View,
|
|
163
|
+
innerProps,
|
|
164
|
+
createElement(
|
|
165
|
+
CheckboxGroupContext.Provider,
|
|
166
|
+
{ value: contextValue },
|
|
167
|
+
wrapChildren(
|
|
168
|
+
props,
|
|
162
169
|
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
hasVarDec,
|
|
167
|
-
varContext: varContextRef.current
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
+
hasVarDec,
|
|
171
|
+
varContext: varContextRef.current
|
|
170
172
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
)
|
|
174
|
+
)
|
|
173
175
|
)
|
|
174
176
|
})
|
|
175
177
|
|