@mpxjs/webpack-plugin 2.9.69 → 2.9.70-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/ResolveDependency.js +5 -0
  5. package/lib/index.js +38 -7
  6. package/lib/json-compiler/helper.js +3 -3
  7. package/lib/loader.js +52 -0
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +5 -1
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  14. package/lib/platform/template/wx/component-config/switch.js +4 -0
  15. package/lib/platform/template/wx/component-config/text.js +4 -0
  16. package/lib/platform/template/wx/component-config/textarea.js +6 -1
  17. package/lib/platform/template/wx/component-config/view.js +4 -0
  18. package/lib/platform/template/wx/index.js +127 -1
  19. package/lib/react/processTemplate.js +3 -0
  20. package/lib/resolve-loader.js +4 -1
  21. package/lib/runtime/components/react/context.ts +4 -0
  22. package/lib/runtime/components/react/dist/context.js +5 -0
  23. package/lib/runtime/components/react/dist/event.config.js +24 -24
  24. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  25. package/lib/runtime/components/react/dist/locale-provider.jsx +15 -0
  26. package/lib/runtime/components/react/dist/mpx-button.jsx +39 -74
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +30 -12
  28. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  29. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  30. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  31. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  32. package/lib/runtime/components/react/dist/mpx-image.jsx +295 -0
  33. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  34. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  35. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  36. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  37. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  38. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  39. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  40. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  41. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -14
  44. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +126 -112
  46. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +32 -29
  47. package/lib/runtime/components/react/dist/mpx-portal/portal-consumer.jsx +23 -0
  48. package/lib/runtime/components/react/dist/mpx-portal/portal-host.jsx +124 -0
  49. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +40 -0
  50. package/lib/runtime/components/react/dist/mpx-portal.jsx +12 -0
  51. package/lib/runtime/components/react/dist/mpx-provider.jsx +31 -0
  52. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  53. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  54. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  55. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  56. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
  57. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +62 -47
  58. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  59. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  60. package/lib/runtime/components/react/dist/mpx-swiper.jsx +613 -0
  61. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  62. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  63. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  64. package/lib/runtime/components/react/dist/mpx-view.jsx +37 -89
  65. package/lib/runtime/components/react/dist/mpx-web-view.jsx +205 -46
  66. package/lib/runtime/components/react/dist/pickerFaces.js +12 -6
  67. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  68. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  69. package/lib/runtime/components/react/dist/{pickerOverlay.jsx → pickerViewOverlay.jsx} +5 -3
  70. package/lib/runtime/components/react/dist/useAnimationHooks.js +50 -12
  71. package/lib/runtime/components/react/dist/utils.jsx +83 -28
  72. package/lib/runtime/components/react/getInnerListeners.ts +35 -28
  73. package/lib/runtime/components/react/mpx-button.tsx +55 -36
  74. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  75. package/lib/runtime/components/react/mpx-checkbox-group.tsx +13 -12
  76. package/lib/runtime/components/react/mpx-checkbox.tsx +28 -28
  77. package/lib/runtime/components/react/mpx-form.tsx +10 -8
  78. package/lib/runtime/components/react/mpx-icon.tsx +10 -15
  79. package/lib/runtime/components/react/mpx-image.tsx +396 -0
  80. package/lib/runtime/components/react/mpx-input.tsx +61 -33
  81. package/lib/runtime/components/react/mpx-label.tsx +14 -13
  82. package/lib/runtime/components/react/mpx-movable-area.tsx +8 -7
  83. package/lib/runtime/components/react/mpx-movable-view.tsx +1 -1
  84. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  85. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  87. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  88. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  89. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  90. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  91. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  92. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  93. package/lib/runtime/components/react/mpx-radio-group.tsx +11 -12
  94. package/lib/runtime/components/react/mpx-radio.tsx +26 -29
  95. package/lib/runtime/components/react/mpx-scroll-view.tsx +32 -30
  96. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  97. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  98. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  99. package/lib/runtime/components/react/mpx-switch.tsx +10 -8
  100. package/lib/runtime/components/react/mpx-text.tsx +6 -2
  101. package/lib/runtime/components/react/mpx-view.tsx +37 -45
  102. package/lib/runtime/components/react/mpx-web-view.tsx +25 -15
  103. package/lib/runtime/components/react/types/global.d.ts +1 -16
  104. package/lib/runtime/components/react/utils.tsx +24 -24
  105. package/lib/runtime/components/tenon/getInnerListeners.js +334 -0
  106. package/lib/runtime/components/tenon/tenon-button.vue +309 -0
  107. package/lib/runtime/components/tenon/tenon-image.vue +66 -0
  108. package/lib/runtime/components/tenon/tenon-input.vue +171 -0
  109. package/lib/runtime/components/tenon/tenon-rich-text.vue +26 -0
  110. package/lib/runtime/components/tenon/tenon-scroll-view.vue +127 -0
  111. package/lib/runtime/components/tenon/tenon-switch.vue +96 -0
  112. package/lib/runtime/components/tenon/tenon-text.vue +70 -0
  113. package/lib/runtime/components/tenon/tenon-textarea.vue +86 -0
  114. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  115. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  116. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  117. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  118. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  119. package/lib/runtime/components/web/mpx-web-view.vue +162 -162
  120. package/lib/runtime/optionProcessor.js +7 -16
  121. package/lib/runtime/optionProcessor.tenon.js +84 -0
  122. package/lib/runtime/utils.js +2 -0
  123. package/lib/style-compiler/index.js +1 -1
  124. package/lib/style-compiler/plugins/hm.js +20 -0
  125. package/lib/template-compiler/bind-this.js +7 -2
  126. package/lib/template-compiler/compiler.js +67 -40
  127. package/lib/template-compiler/gen-node-react.js +2 -2
  128. package/lib/tenon/index.js +112 -0
  129. package/lib/tenon/processJSON.js +352 -0
  130. package/lib/tenon/processScript.js +198 -0
  131. package/lib/tenon/processStyles.js +21 -0
  132. package/lib/tenon/processTemplate.js +125 -0
  133. package/lib/tenon/script-helper.js +223 -0
  134. package/lib/utils/env.js +6 -1
  135. package/lib/utils/get-relative-path.js +25 -0
  136. package/package.json +7 -3
  137. package/LICENSE +0 -433
  138. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  139. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  140. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  141. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  142. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  143. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  144. 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)
@@ -8,3 +8,8 @@ export const PickerContext = createContext(null);
8
8
  export const VarContext = createContext({});
9
9
  export const IntersectionObserverContext = createContext(null);
10
10
  export const RouteContext = createContext(null);
11
+ export const SwiperContext = createContext({});
12
+ export const KeyboardAvoidContext = createContext(null);
13
+ export const ScrollViewContext = createContext({ gestureRef: null });
14
+ export const PortalContext = createContext(null);
15
+ export const PortalManagerContext = createContext(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
- return {
11
- ...event,
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
- ...(event.currentTarget || {}),
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
- return {
50
- ...oe,
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) > 3 ||
86
+ Math.abs(currentPageY - tapDetailInfo.y) > 3) {
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,10 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
81
211
  });
82
212
  const propsRef = useRef({});
83
213
  const eventConfig = {};
84
- const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false };
214
+ const config = rawConfig || {
215
+ layoutRef: { current: {} },
216
+ disableTap: false
217
+ };
85
218
  const removeProps = [
86
219
  'children',
87
220
  'enable-background',
@@ -93,151 +226,35 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
93
226
  'parent-height',
94
227
  ...userRemoveProps
95
228
  ];
96
- propsRef.current = { ...props, ...additionalProps };
229
+ propsRef.current = extendObject({}, props, additionalProps);
230
+ let hashEventKey = '';
231
+ const rawEventKeys = [];
97
232
  for (const key in eventConfigMap) {
98
- if (propsRef.current[key]) {
99
- eventConfig[key] = eventConfigMap[key];
233
+ if (hasOwn(propsRef.current, key)) {
234
+ eventConfig[key] = eventConfigMap[key].events;
235
+ hashEventKey = hashEventKey + eventConfigMap[key].bitFlag;
236
+ rawEventKeys.push(key);
100
237
  }
101
238
  }
102
- if (!(Object.keys(eventConfig).length) || config.disableTouch) {
103
- return omit(propsRef.current, removeProps);
104
- }
105
- function handleEmitEvent(events, type, oe) {
106
- events.forEach(event => {
107
- if (propsRef.current[event]) {
108
- const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
109
- if (match) {
110
- oe.stopPropagation();
111
- }
112
- propsRef.current[event](getTouchEvent(type, oe, propsRef.current, config));
113
- }
114
- });
115
- }
116
- function checkIsNeedPress(e, type) {
117
- const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 };
118
- const nativeEvent = e.nativeEvent;
119
- const currentPageX = nativeEvent.changedTouches[0].pageX;
120
- const currentPageY = nativeEvent.changedTouches[0].pageY;
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);
239
+ const events = useMemo(() => {
240
+ if (!rawEventKeys.length) {
241
+ return {};
175
242
  }
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');
243
+ const transformedEventKeys = rawEventKeys.reduce((acc, key) => {
244
+ if (propsRef.current[key]) {
245
+ return acc.concat(eventConfig[key]);
209
246
  }
210
- }, {
211
- eventName: 'onTouchMoveCapture',
212
- handler: (e) => {
213
- handleTouchmove(e, 'capture');
247
+ return acc;
248
+ }, []);
249
+ const finalEventKeys = [...new Set(transformedEventKeys)];
250
+ const events = {};
251
+ touchEventList.forEach((item) => {
252
+ if (finalEventKeys.includes(item.eventName)) {
253
+ events[item.eventName] = (e) => item.handler(e, ref, propsRef, config);
214
254
  }
215
- }, {
216
- eventName: 'onTouchEndCapture',
217
- handler: (e) => {
218
- handleTouchend(e, 'capture');
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
- };
255
+ });
256
+ return events;
257
+ }, [hashEventKey]);
258
+ return extendObject({}, events, omit(propsRef.current, [...rawEventKeys, ...removeProps]));
242
259
  };
243
260
  export default useInnerProps;
@@ -0,0 +1,15 @@
1
+ import { createContext, useMemo, memo } from 'react';
2
+ import { extendObject } from './utils';
3
+ export const LocaleContext = createContext(undefined);
4
+ const LocaleProvider = (props) => {
5
+ const locale = useMemo(() => {
6
+ return {
7
+ antLocale: extendObject({}, props.locale, { exist: true })
8
+ };
9
+ }, [props.locale]);
10
+ return (<LocaleContext.Provider value={locale}>
11
+ {props.children}
12
+ </LocaleContext.Provider>);
13
+ };
14
+ LocaleProvider.displayName = 'LocaleProvider';
15
+ export default memo(LocaleProvider);