@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/ResolveDependency.js +5 -0
- package/lib/index.js +38 -7
- package/lib/json-compiler/helper.js +3 -3
- package/lib/loader.js +53 -0
- package/lib/platform/template/wx/component-config/button.js +14 -2
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +5 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +6 -1
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +127 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolve-loader.js +4 -1
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -165
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +110 -97
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +29 -44
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
- package/lib/runtime/components/react/dist/utils.jsx +20 -24
- package/lib/runtime/components/react/getInnerListeners.ts +35 -28
- package/lib/runtime/components/react/mpx-button.tsx +55 -36
- package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
- package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
- package/lib/runtime/components/react/mpx-form.tsx +10 -8
- package/lib/runtime/components/react/mpx-icon.tsx +10 -15
- package/lib/runtime/components/react/mpx-image.tsx +396 -0
- package/lib/runtime/components/react/mpx-input.tsx +61 -33
- package/lib/runtime/components/react/mpx-label.tsx +14 -13
- package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
- package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
- package/lib/runtime/components/react/mpx-radio.tsx +26 -29
- package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +10 -8
- package/lib/runtime/components/react/mpx-text.tsx +6 -2
- package/lib/runtime/components/react/mpx-view.tsx +37 -45
- package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
- package/lib/runtime/components/react/types/global.d.ts +1 -16
- package/lib/runtime/components/react/utils.tsx +24 -24
- package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
- package/lib/runtime/components/tenon/tenon-button.vue +309 -0
- package/lib/runtime/components/tenon/tenon-image.vue +66 -0
- package/lib/runtime/components/tenon/tenon-input.vue +171 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
- package/lib/runtime/components/tenon/tenon-text.vue +70 -0
- package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +162 -162
- package/lib/runtime/optionProcessor.js +7 -16
- package/lib/runtime/optionProcessor.tenon.js +84 -0
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/hm.js +20 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +67 -40
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/tenon/index.js +117 -0
- package/lib/tenon/processJSON.js +352 -0
- package/lib/tenon/processScript.js +203 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +126 -0
- package/lib/tenon/script-helper.js +223 -0
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-relative-path.js +25 -0
- package/package.json +7 -3
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
|
@@ -5,6 +5,8 @@ export type LabelContextValue = MutableRefObject<{
|
|
|
5
5
|
triggerChange: (evt: NativeSyntheticEvent<TouchEvent>) => void
|
|
6
6
|
}>
|
|
7
7
|
|
|
8
|
+
export type KeyboardAvoidContextValue = (enabled: boolean) => void
|
|
9
|
+
|
|
8
10
|
export interface GroupValue {
|
|
9
11
|
[key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>> }
|
|
10
12
|
}
|
|
@@ -48,3 +50,5 @@ export const VarContext = createContext({})
|
|
|
48
50
|
export const IntersectionObserverContext = createContext<IntersectionObserver | null>(null)
|
|
49
51
|
|
|
50
52
|
export const RouteContext = createContext<number | null>(null)
|
|
53
|
+
|
|
54
|
+
export const KeyboardAvoidContext = createContext<KeyboardAvoidContextValue | null>(null)
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
const eventConfigMap = {
|
|
2
|
-
bindtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
3
|
-
bindlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
4
|
-
bindtouchstart: ['onTouchStart'],
|
|
5
|
-
bindtouchmove: ['onTouchMove'],
|
|
6
|
-
bindtouchend: ['onTouchEnd'],
|
|
7
|
-
bindtouchcancel: ['onTouchCancel'],
|
|
8
|
-
catchtap: ['onTouchStart', 'onTouchMove', 'onTouchEnd'],
|
|
9
|
-
catchlongpress: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'],
|
|
10
|
-
catchtouchstart: ['onTouchStart'],
|
|
11
|
-
catchtouchmove: ['onTouchMove'],
|
|
12
|
-
catchtouchend: ['onTouchEnd'],
|
|
13
|
-
catchtouchcancel: ['onTouchCancel'],
|
|
14
|
-
'capture-bindtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
15
|
-
'capture-bindlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
16
|
-
'capture-bindtouchstart': ['onTouchStartCapture'],
|
|
17
|
-
'capture-bindtouchmove': ['onTouchMoveCapture'],
|
|
18
|
-
'capture-bindtouchend': ['onTouchEndCapture'],
|
|
19
|
-
'capture-bindtouchcancel': ['onTouchCancelCapture'],
|
|
20
|
-
'capture-catchtap': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'],
|
|
21
|
-
'capture-catchlongpress': ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'],
|
|
22
|
-
'capture-catchtouchstart': ['onTouchStartCapture'],
|
|
23
|
-
'capture-catchtouchmove': ['onTouchMoveCapture'],
|
|
24
|
-
'capture-catchtouchend': ['onTouchEndCapture'],
|
|
25
|
-
'capture-catchtouchcancel': ['onTouchCancelCapture']
|
|
2
|
+
bindtap: { bitFlag: '0', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
|
|
3
|
+
bindlongpress: { bitFlag: '1', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
|
|
4
|
+
bindtouchstart: { bitFlag: '2', events: ['onTouchStart'] },
|
|
5
|
+
bindtouchmove: { bitFlag: '3', events: ['onTouchMove'] },
|
|
6
|
+
bindtouchend: { bitFlag: '4', events: ['onTouchEnd'] },
|
|
7
|
+
bindtouchcancel: { bitFlag: '5', events: ['onTouchCancel'] },
|
|
8
|
+
catchtap: { bitFlag: '6', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd'] },
|
|
9
|
+
catchlongpress: { bitFlag: '7', events: ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] },
|
|
10
|
+
catchtouchstart: { bitFlag: '8', events: ['onTouchStart'] },
|
|
11
|
+
catchtouchmove: { bitFlag: '9', events: ['onTouchMove'] },
|
|
12
|
+
catchtouchend: { bitFlag: 'a', events: ['onTouchEnd'] },
|
|
13
|
+
catchtouchcancel: { bitFlag: 'b', events: ['onTouchCancel'] },
|
|
14
|
+
'capture-bindtap': { bitFlag: 'c', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
|
|
15
|
+
'capture-bindlongpress': { bitFlag: 'd', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
|
|
16
|
+
'capture-bindtouchstart': { bitFlag: 'e', events: ['onTouchStartCapture'] },
|
|
17
|
+
'capture-bindtouchmove': { bitFlag: 'f', events: ['onTouchMoveCapture'] },
|
|
18
|
+
'capture-bindtouchend': { bitFlag: 'g', events: ['onTouchEndCapture'] },
|
|
19
|
+
'capture-bindtouchcancel': { bitFlag: 'h', events: ['onTouchCancelCapture'] },
|
|
20
|
+
'capture-catchtap': { bitFlag: 'i', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture'] },
|
|
21
|
+
'capture-catchlongpress': { bitFlag: 'j', events: ['onTouchStartCapture', 'onTouchMoveCapture', 'onTouchEndCapture', 'onTouchCancelCapture'] },
|
|
22
|
+
'capture-catchtouchstart': { bitFlag: 'k', events: ['onTouchStartCapture'] },
|
|
23
|
+
'capture-catchtouchmove': { bitFlag: 'l', events: ['onTouchMoveCapture'] },
|
|
24
|
+
'capture-catchtouchend': { bitFlag: 'm', events: ['onTouchEndCapture'] },
|
|
25
|
+
'capture-catchtouchcancel': { bitFlag: 'n', events: ['onTouchCancelCapture'] }
|
|
26
26
|
};
|
|
27
27
|
export default eventConfigMap;
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
2
|
-
import { collectDataset } from '@mpxjs/utils';
|
|
3
|
-
import { omit } from './utils';
|
|
1
|
+
import { useRef, useMemo } from 'react';
|
|
2
|
+
import { hasOwn, collectDataset } from '@mpxjs/utils';
|
|
3
|
+
import { omit, extendObject } from './utils';
|
|
4
4
|
import eventConfigMap from './event.config';
|
|
5
5
|
const getTouchEvent = (type, event, props, config) => {
|
|
6
6
|
const nativeEvent = event.nativeEvent;
|
|
7
7
|
const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent;
|
|
8
8
|
const { id } = props;
|
|
9
9
|
const { layoutRef } = config;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const currentTarget = extendObject({}, event.currentTarget, {
|
|
11
|
+
id: id || '',
|
|
12
|
+
dataset: collectDataset(props),
|
|
13
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
14
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
15
|
+
});
|
|
16
|
+
const pendingProps = event._targetInst?.pendingProps || {};
|
|
17
|
+
const target = extendObject({}, event.target, {
|
|
18
|
+
id: pendingProps.parentId || pendingProps.nativeID || '',
|
|
19
|
+
dataset: collectDataset(pendingProps)
|
|
20
|
+
});
|
|
21
|
+
return extendObject({}, event, {
|
|
12
22
|
type,
|
|
13
23
|
timeStamp: timestamp,
|
|
14
|
-
currentTarget
|
|
15
|
-
|
|
16
|
-
id: id || '',
|
|
17
|
-
dataset: collectDataset(props),
|
|
18
|
-
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
19
|
-
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
20
|
-
},
|
|
24
|
+
currentTarget,
|
|
25
|
+
target,
|
|
21
26
|
detail: {
|
|
22
27
|
x: pageX,
|
|
23
28
|
y: pageY
|
|
24
29
|
},
|
|
25
|
-
touches: touches.map(item => {
|
|
30
|
+
touches: touches.map((item) => {
|
|
26
31
|
return {
|
|
27
32
|
identifier: item.identifier,
|
|
28
33
|
pageX: item.pageX,
|
|
@@ -31,7 +36,7 @@ const getTouchEvent = (type, event, props, config) => {
|
|
|
31
36
|
clientY: item.locationY
|
|
32
37
|
};
|
|
33
38
|
}),
|
|
34
|
-
changedTouches: changedTouches.map(item => {
|
|
39
|
+
changedTouches: changedTouches.map((item) => {
|
|
35
40
|
return {
|
|
36
41
|
identifier: item.identifier,
|
|
37
42
|
pageX: item.pageX,
|
|
@@ -43,25 +48,150 @@ const getTouchEvent = (type, event, props, config) => {
|
|
|
43
48
|
persist: event.persist,
|
|
44
49
|
stopPropagation: event.stopPropagation,
|
|
45
50
|
preventDefault: event.preventDefault
|
|
46
|
-
};
|
|
51
|
+
});
|
|
47
52
|
};
|
|
48
53
|
export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
const targetInfo = extendObject({}, oe.target, {
|
|
55
|
+
id: props.id || '',
|
|
56
|
+
dataset: collectDataset(props),
|
|
57
|
+
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
58
|
+
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
59
|
+
});
|
|
60
|
+
return extendObject({}, oe, {
|
|
51
61
|
type,
|
|
52
62
|
detail,
|
|
53
|
-
target:
|
|
54
|
-
...(oe.target || {}),
|
|
55
|
-
id: props.id || '',
|
|
56
|
-
dataset: collectDataset(props),
|
|
57
|
-
offsetLeft: layoutRef?.current?.offsetLeft || 0,
|
|
58
|
-
offsetTop: layoutRef?.current?.offsetTop || 0
|
|
59
|
-
},
|
|
63
|
+
target: targetInfo,
|
|
60
64
|
persist: oe.persist,
|
|
61
65
|
stopPropagation: oe.stopPropagation,
|
|
62
66
|
preventDefault: oe.preventDefault
|
|
63
|
-
};
|
|
67
|
+
});
|
|
64
68
|
};
|
|
69
|
+
function handleEmitEvent(events, type, oe, propsRef, config) {
|
|
70
|
+
events.forEach((event) => {
|
|
71
|
+
if (propsRef.current[event]) {
|
|
72
|
+
const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
|
|
73
|
+
if (match) {
|
|
74
|
+
oe.stopPropagation();
|
|
75
|
+
}
|
|
76
|
+
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function checkIsNeedPress(e, type, ref) {
|
|
81
|
+
const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 };
|
|
82
|
+
const nativeEvent = e.nativeEvent;
|
|
83
|
+
const currentPageX = nativeEvent.changedTouches[0].pageX;
|
|
84
|
+
const currentPageY = nativeEvent.changedTouches[0].pageY;
|
|
85
|
+
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 ||
|
|
86
|
+
Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
87
|
+
ref.current.needPress[type] = false;
|
|
88
|
+
ref.current.startTimer[type] &&
|
|
89
|
+
clearTimeout(ref.current.startTimer[type]);
|
|
90
|
+
ref.current.startTimer[type] = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function handleTouchstart(e, type, ref, propsRef, config) {
|
|
94
|
+
e.persist();
|
|
95
|
+
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
|
|
96
|
+
const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
|
|
97
|
+
const captureTouchEvent = [
|
|
98
|
+
'capture-catchtouchstart',
|
|
99
|
+
'capture-bindtouchstart'
|
|
100
|
+
];
|
|
101
|
+
const capturePressEvent = [
|
|
102
|
+
'capture-catchlongpress',
|
|
103
|
+
'capture-bindlongpress'
|
|
104
|
+
];
|
|
105
|
+
ref.current.startTimer[type] = null;
|
|
106
|
+
ref.current.needPress[type] = true;
|
|
107
|
+
const nativeEvent = e.nativeEvent;
|
|
108
|
+
ref.current.mpxPressInfo.detail = {
|
|
109
|
+
x: nativeEvent.changedTouches[0].pageX,
|
|
110
|
+
y: nativeEvent.changedTouches[0].pageY
|
|
111
|
+
};
|
|
112
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
113
|
+
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
114
|
+
handleEmitEvent(currentTouchEvent, 'touchstart', e, propsRef, config);
|
|
115
|
+
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
|
|
116
|
+
if (catchlongpress ||
|
|
117
|
+
bindlongpress ||
|
|
118
|
+
captureCatchlongpress ||
|
|
119
|
+
captureBindlongpress) {
|
|
120
|
+
ref.current.startTimer[type] = setTimeout(() => {
|
|
121
|
+
ref.current.needPress[type] = false;
|
|
122
|
+
handleEmitEvent(currentPressEvent, 'longpress', e, propsRef, config);
|
|
123
|
+
}, 350);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function handleTouchmove(e, type, ref, propsRef, config) {
|
|
127
|
+
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
|
|
128
|
+
const captureTouchEvent = [
|
|
129
|
+
'capture-catchtouchmove',
|
|
130
|
+
'capture-bindtouchmove'
|
|
131
|
+
];
|
|
132
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
133
|
+
handleEmitEvent(currentTouchEvent, 'touchmove', e, propsRef, config);
|
|
134
|
+
checkIsNeedPress(e, type, ref);
|
|
135
|
+
}
|
|
136
|
+
function handleTouchend(e, type, ref, propsRef, config) {
|
|
137
|
+
// move event may not be triggered
|
|
138
|
+
checkIsNeedPress(e, type, ref);
|
|
139
|
+
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
|
|
140
|
+
const bubbleTapEvent = ['catchtap', 'bindtap'];
|
|
141
|
+
const captureTouchEvent = [
|
|
142
|
+
'capture-catchtouchend',
|
|
143
|
+
'capture-bindtouchend'
|
|
144
|
+
];
|
|
145
|
+
const captureTapEvent = ['capture-catchtap', 'capture-bindtap'];
|
|
146
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
147
|
+
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent;
|
|
148
|
+
ref.current.startTimer[type] &&
|
|
149
|
+
clearTimeout(ref.current.startTimer[type]);
|
|
150
|
+
ref.current.startTimer[type] = null;
|
|
151
|
+
handleEmitEvent(currentTouchEvent, 'touchend', e, propsRef, config);
|
|
152
|
+
if (ref.current.needPress[type]) {
|
|
153
|
+
if (type === 'bubble' && config.disableTap) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
handleEmitEvent(currentTapEvent, 'tap', e, propsRef, config);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function handleTouchcancel(e, type, ref, propsRef, config) {
|
|
160
|
+
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
|
|
161
|
+
const captureTouchEvent = [
|
|
162
|
+
'capture-catchtouchcancel',
|
|
163
|
+
'capture-bindtouchcancel'
|
|
164
|
+
];
|
|
165
|
+
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
166
|
+
ref.current.startTimer[type] &&
|
|
167
|
+
clearTimeout(ref.current.startTimer[type]);
|
|
168
|
+
ref.current.startTimer[type] = null;
|
|
169
|
+
handleEmitEvent(currentTouchEvent, 'touchcancel', e, propsRef, config);
|
|
170
|
+
}
|
|
171
|
+
function createTouchEventHandler(eventName, type) {
|
|
172
|
+
return (e, ref, propsRef, config) => {
|
|
173
|
+
const handlerMap = {
|
|
174
|
+
onTouchStart: handleTouchstart,
|
|
175
|
+
onTouchMove: handleTouchmove,
|
|
176
|
+
onTouchEnd: handleTouchend,
|
|
177
|
+
onTouchCancel: handleTouchcancel
|
|
178
|
+
};
|
|
179
|
+
const handler = handlerMap[eventName];
|
|
180
|
+
if (handler) {
|
|
181
|
+
handler(e, type, ref, propsRef, config);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const touchEventList = [
|
|
186
|
+
{ eventName: 'onTouchStart', handler: createTouchEventHandler('onTouchStart', 'bubble') },
|
|
187
|
+
{ eventName: 'onTouchMove', handler: createTouchEventHandler('onTouchMove', 'bubble') },
|
|
188
|
+
{ eventName: 'onTouchEnd', handler: createTouchEventHandler('onTouchEnd', 'bubble') },
|
|
189
|
+
{ eventName: 'onTouchCancel', handler: createTouchEventHandler('onTouchCancel', 'bubble') },
|
|
190
|
+
{ eventName: 'onTouchStartCapture', handler: createTouchEventHandler('onTouchStart', 'capture') },
|
|
191
|
+
{ eventName: 'onTouchMoveCapture', handler: createTouchEventHandler('onTouchMove', 'capture') },
|
|
192
|
+
{ eventName: 'onTouchEndCapture', handler: createTouchEventHandler('onTouchEnd', 'capture') },
|
|
193
|
+
{ eventName: 'onTouchCancelCapture', handler: createTouchEventHandler('onTouchCancel', 'capture') }
|
|
194
|
+
];
|
|
65
195
|
const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], rawConfig) => {
|
|
66
196
|
const ref = useRef({
|
|
67
197
|
startTimer: {
|
|
@@ -81,7 +211,11 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
81
211
|
});
|
|
82
212
|
const propsRef = useRef({});
|
|
83
213
|
const eventConfig = {};
|
|
84
|
-
const config = rawConfig || {
|
|
214
|
+
const config = rawConfig || {
|
|
215
|
+
layoutRef: { current: {} },
|
|
216
|
+
disableTouch: false,
|
|
217
|
+
disableTap: false
|
|
218
|
+
};
|
|
85
219
|
const removeProps = [
|
|
86
220
|
'children',
|
|
87
221
|
'enable-background',
|
|
@@ -93,151 +227,35 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
|
|
|
93
227
|
'parent-height',
|
|
94
228
|
...userRemoveProps
|
|
95
229
|
];
|
|
96
|
-
propsRef.current = {
|
|
230
|
+
propsRef.current = extendObject({}, props, additionalProps);
|
|
231
|
+
let hashEventKey = '';
|
|
232
|
+
const rawEventKeys = [];
|
|
97
233
|
for (const key in eventConfigMap) {
|
|
98
|
-
if (propsRef.current
|
|
99
|
-
eventConfig[key] = eventConfigMap[key];
|
|
234
|
+
if (hasOwn(propsRef.current, key)) {
|
|
235
|
+
eventConfig[key] = eventConfigMap[key].events;
|
|
236
|
+
hashEventKey = hashEventKey + eventConfigMap[key].bitFlag;
|
|
237
|
+
rawEventKeys.push(key);
|
|
100
238
|
}
|
|
101
239
|
}
|
|
102
|
-
if (!
|
|
240
|
+
if (!rawEventKeys.length || config.disableTouch) {
|
|
103
241
|
return omit(propsRef.current, removeProps);
|
|
104
242
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (propsRef.current[
|
|
108
|
-
|
|
109
|
-
if (match) {
|
|
110
|
-
oe.stopPropagation();
|
|
111
|
-
}
|
|
112
|
-
propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
|
|
243
|
+
const events = useMemo(() => {
|
|
244
|
+
const transformedEventKeys = rawEventKeys.reduce((acc, key) => {
|
|
245
|
+
if (propsRef.current[key]) {
|
|
246
|
+
return acc.concat(eventConfig[key]);
|
|
113
247
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
|
|
122
|
-
ref.current.needPress[type] = false;
|
|
123
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
124
|
-
ref.current.startTimer[type] = null;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function handleTouchstart(e, type) {
|
|
128
|
-
e.persist();
|
|
129
|
-
const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
|
|
130
|
-
const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
|
|
131
|
-
const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart'];
|
|
132
|
-
const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress'];
|
|
133
|
-
ref.current.startTimer[type] = null;
|
|
134
|
-
ref.current.needPress[type] = true;
|
|
135
|
-
const nativeEvent = e.nativeEvent;
|
|
136
|
-
ref.current.mpxPressInfo.detail = {
|
|
137
|
-
x: nativeEvent.changedTouches[0].pageX,
|
|
138
|
-
y: nativeEvent.changedTouches[0].pageY
|
|
139
|
-
};
|
|
140
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
141
|
-
const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
|
|
142
|
-
handleEmitEvent(currentTouchEvent, 'touchstart', e);
|
|
143
|
-
const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
|
|
144
|
-
if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
|
|
145
|
-
ref.current.startTimer[type] = setTimeout(() => {
|
|
146
|
-
ref.current.needPress[type] = false;
|
|
147
|
-
handleEmitEvent(currentPressEvent, 'longpress', e);
|
|
148
|
-
}, 350);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function handleTouchmove(e, type) {
|
|
152
|
-
const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
|
|
153
|
-
const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove'];
|
|
154
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
155
|
-
handleEmitEvent(currentTouchEvent, 'touchmove', e);
|
|
156
|
-
checkIsNeedPress(e, type);
|
|
157
|
-
}
|
|
158
|
-
function handleTouchend(e, type) {
|
|
159
|
-
// move event may not be triggered
|
|
160
|
-
checkIsNeedPress(e, type);
|
|
161
|
-
const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
|
|
162
|
-
const bubbleTapEvent = ['catchtap', 'bindtap'];
|
|
163
|
-
const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend'];
|
|
164
|
-
const captureTapEvent = ['capture-catchtap', 'capture-bindtap'];
|
|
165
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
166
|
-
const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent;
|
|
167
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
168
|
-
ref.current.startTimer[type] = null;
|
|
169
|
-
handleEmitEvent(currentTouchEvent, 'touchend', e);
|
|
170
|
-
if (ref.current.needPress[type]) {
|
|
171
|
-
if (type === 'bubble' && config.disableTap) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
handleEmitEvent(currentTapEvent, 'tap', e);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function handleTouchcancel(e, type) {
|
|
178
|
-
const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
|
|
179
|
-
const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel'];
|
|
180
|
-
const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
|
|
181
|
-
ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
|
|
182
|
-
ref.current.startTimer[type] = null;
|
|
183
|
-
handleEmitEvent(currentTouchEvent, 'touchcancel', e);
|
|
184
|
-
}
|
|
185
|
-
const touchEventList = [{
|
|
186
|
-
eventName: 'onTouchStart',
|
|
187
|
-
handler: (e) => {
|
|
188
|
-
handleTouchstart(e, 'bubble');
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
eventName: 'onTouchMove',
|
|
192
|
-
handler: (e) => {
|
|
193
|
-
handleTouchmove(e, 'bubble');
|
|
194
|
-
}
|
|
195
|
-
}, {
|
|
196
|
-
eventName: 'onTouchEnd',
|
|
197
|
-
handler: (e) => {
|
|
198
|
-
handleTouchend(e, 'bubble');
|
|
199
|
-
}
|
|
200
|
-
}, {
|
|
201
|
-
eventName: 'onTouchCancel',
|
|
202
|
-
handler: (e) => {
|
|
203
|
-
handleTouchcancel(e, 'bubble');
|
|
204
|
-
}
|
|
205
|
-
}, {
|
|
206
|
-
eventName: 'onTouchStartCapture',
|
|
207
|
-
handler: (e) => {
|
|
208
|
-
handleTouchstart(e, 'capture');
|
|
209
|
-
}
|
|
210
|
-
}, {
|
|
211
|
-
eventName: 'onTouchMoveCapture',
|
|
212
|
-
handler: (e) => {
|
|
213
|
-
handleTouchmove(e, 'capture');
|
|
248
|
+
return acc;
|
|
249
|
+
}, []);
|
|
250
|
+
const finalEventKeys = [...new Set(transformedEventKeys)];
|
|
251
|
+
const events = {};
|
|
252
|
+
touchEventList.forEach((item) => {
|
|
253
|
+
if (finalEventKeys.includes(item.eventName)) {
|
|
254
|
+
events[item.eventName] = (e) => item.handler(e, ref, propsRef, config);
|
|
214
255
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
}, {
|
|
221
|
-
eventName: 'onTouchCancelCapture',
|
|
222
|
-
handler: (e) => {
|
|
223
|
-
handleTouchcancel(e, 'capture');
|
|
224
|
-
}
|
|
225
|
-
}];
|
|
226
|
-
const events = {};
|
|
227
|
-
const transformedEventKeys = [];
|
|
228
|
-
for (const key in eventConfig) {
|
|
229
|
-
transformedEventKeys.push(...eventConfig[key]);
|
|
230
|
-
}
|
|
231
|
-
const finalEventKeys = [...new Set(transformedEventKeys)];
|
|
232
|
-
touchEventList.forEach(item => {
|
|
233
|
-
if (finalEventKeys.includes(item.eventName)) {
|
|
234
|
-
events[item.eventName] = item.handler;
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
const rawEventKeys = Object.keys(eventConfig);
|
|
238
|
-
return {
|
|
239
|
-
...events,
|
|
240
|
-
...omit(propsRef.current, [...rawEventKeys, ...removeProps])
|
|
241
|
-
};
|
|
256
|
+
});
|
|
257
|
+
return events;
|
|
258
|
+
}, [hashEventKey]);
|
|
259
|
+
return extendObject({}, events, omit(propsRef.current, [...rawEventKeys, ...removeProps]));
|
|
242
260
|
};
|
|
243
261
|
export default useInnerProps;
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
* ✘ bindagreeprivacyauthorization
|
|
35
35
|
* ✔ bindtap
|
|
36
36
|
*/
|
|
37
|
-
import { useEffect, useRef, useState, forwardRef, useContext } from 'react';
|
|
37
|
+
import { createElement, useEffect, useRef, useState, forwardRef, useContext } from 'react';
|
|
38
38
|
import { View, StyleSheet, Animated, Easing } from 'react-native';
|
|
39
39
|
import { warn } from '@mpxjs/utils';
|
|
40
|
-
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
|
|
40
|
+
import { getCurrentPage, splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils';
|
|
41
41
|
import useInnerProps, { getCustomEvent } from './getInnerListeners';
|
|
42
42
|
import useNodesRef from './useNodesRef';
|
|
43
43
|
import { RouteContext, FormContext } from './context';
|
|
@@ -120,11 +120,10 @@ const Loading = ({ alone = false }) => {
|
|
|
120
120
|
animation.stop();
|
|
121
121
|
};
|
|
122
122
|
}, []);
|
|
123
|
-
const loadingStyle = {
|
|
124
|
-
...styles.loading,
|
|
123
|
+
const loadingStyle = extendObject({}, styles.loading, {
|
|
125
124
|
transform: [{ rotate }],
|
|
126
125
|
marginRight: alone ? 0 : 5
|
|
127
|
-
};
|
|
126
|
+
});
|
|
128
127
|
return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }}/>;
|
|
129
128
|
};
|
|
130
129
|
const Button = forwardRef((buttonProps, ref) => {
|
|
@@ -167,30 +166,15 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
167
166
|
borderColor: plain ? plainBorderColor : normalBorderColor,
|
|
168
167
|
backgroundColor: plain ? 'transparent' : normalBackgroundColor
|
|
169
168
|
};
|
|
170
|
-
const defaultViewStyle = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
};
|
|
175
|
-
const defaultTextStyle = {
|
|
176
|
-
...styles.text,
|
|
177
|
-
...(isMiniSize && styles.textMini),
|
|
178
|
-
color: plain ? plainTextColor : normalTextColor
|
|
179
|
-
};
|
|
180
|
-
const defaultStyle = {
|
|
181
|
-
...defaultViewStyle,
|
|
182
|
-
...defaultTextStyle
|
|
183
|
-
};
|
|
184
|
-
const styleObj = {
|
|
185
|
-
...defaultStyle,
|
|
186
|
-
...style,
|
|
187
|
-
...(applyHoverEffect && hoverStyle)
|
|
188
|
-
};
|
|
169
|
+
const defaultViewStyle = extendObject({}, styles.button, isMiniSize ? styles.buttonMini : null, viewStyle);
|
|
170
|
+
const defaultTextStyle = extendObject({}, styles.text, isMiniSize ? styles.textMini : {}, { color: plain ? plainTextColor : normalTextColor });
|
|
171
|
+
const defaultStyle = extendObject({}, defaultViewStyle, defaultTextStyle);
|
|
172
|
+
const styleObj = extendObject({}, defaultStyle, style, applyHoverEffect ? hoverStyle : {});
|
|
189
173
|
const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
|
|
190
174
|
const nodeRef = useRef(null);
|
|
191
|
-
useNodesRef(props, ref, nodeRef, {
|
|
175
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle });
|
|
192
176
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
|
|
193
|
-
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
|
|
177
|
+
const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
|
|
194
178
|
if (backgroundStyle) {
|
|
195
179
|
warn('Button does not support background image-related styles!');
|
|
196
180
|
}
|
|
@@ -281,26 +265,35 @@ const Button = forwardRef((buttonProps, ref) => {
|
|
|
281
265
|
handleOpenTypeEvent(evt);
|
|
282
266
|
handleFormTypeFn();
|
|
283
267
|
};
|
|
284
|
-
const innerProps = useInnerProps(props, {
|
|
268
|
+
const innerProps = useInnerProps(props, extendObject({
|
|
285
269
|
ref: nodeRef,
|
|
286
|
-
style: {
|
|
287
|
-
|
|
288
|
-
bindtouchstart: onTouchStart,
|
|
289
|
-
bindtouchend: onTouchEnd,
|
|
290
|
-
bindtap: onTap
|
|
291
|
-
}, [
|
|
270
|
+
style: extendObject({}, innerStyle, layoutStyle)
|
|
271
|
+
}, layoutProps, {
|
|
272
|
+
bindtouchstart: (bindtouchstart || !disabled) && onTouchStart,
|
|
273
|
+
bindtouchend: (bindtouchend || !disabled) && onTouchEnd,
|
|
274
|
+
bindtap: !disabled && onTap
|
|
275
|
+
}), [
|
|
276
|
+
'disabled',
|
|
277
|
+
'size',
|
|
278
|
+
'type',
|
|
279
|
+
'plain',
|
|
280
|
+
'loading',
|
|
281
|
+
'hover-class',
|
|
282
|
+
'hover-style',
|
|
283
|
+
'hover-start-time',
|
|
284
|
+
'hover-stay-time',
|
|
285
|
+
'open-type',
|
|
286
|
+
'form-type'
|
|
287
|
+
], {
|
|
292
288
|
layoutRef,
|
|
293
289
|
disableTap: disabled
|
|
294
290
|
});
|
|
295
|
-
return (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
textProps
|
|
302
|
-
})}
|
|
303
|
-
</View>);
|
|
291
|
+
return createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props, {
|
|
292
|
+
hasVarDec,
|
|
293
|
+
varContext: varContextRef.current,
|
|
294
|
+
textStyle,
|
|
295
|
+
textProps
|
|
296
|
+
}));
|
|
304
297
|
});
|
|
305
298
|
Button.displayName = 'MpxButton';
|
|
306
299
|
export default Button;
|