@mpxjs/webpack-plugin 2.9.69 → 2.9.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/lib/parser.js +1 -1
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  5. package/lib/platform/template/wx/component-config/index.js +1 -1
  6. package/lib/platform/template/wx/component-config/input.js +1 -1
  7. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  8. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  9. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/processTemplate.js +3 -0
  12. package/lib/runtime/components/react/context.ts +4 -0
  13. package/lib/runtime/components/react/dist/context.js +1 -0
  14. package/lib/runtime/components/react/dist/event.config.js +24 -24
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  16. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  17. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
  19. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  20. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  21. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  22. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  23. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  25. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  26. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  27. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  28. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  29. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  30. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  31. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  32. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  34. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
  36. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
  37. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  38. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  39. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  40. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  41. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  42. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  43. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
  45. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  48. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
  52. package/lib/runtime/components/react/dist/utils.jsx +107 -82
  53. package/lib/runtime/components/react/event.config.ts +25 -26
  54. package/lib/runtime/components/react/getInnerListeners.ts +238 -188
  55. package/lib/runtime/components/react/mpx-button.tsx +64 -50
  56. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  61. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  62. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  63. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  64. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  65. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  66. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  67. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  68. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  70. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  71. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  72. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  73. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  74. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  75. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  76. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  77. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  78. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  79. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  80. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  81. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  82. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  83. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  84. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  85. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  87. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  88. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  89. package/lib/runtime/components/react/mpx-view.tsx +55 -65
  90. package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
  91. package/lib/runtime/components/react/types/global.d.ts +3 -17
  92. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  93. package/lib/runtime/components/react/utils.tsx +113 -82
  94. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  95. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  96. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  97. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  98. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  99. package/lib/runtime/optionProcessor.js +7 -38
  100. package/lib/runtime/utils.js +2 -0
  101. package/lib/style-compiler/plugins/scope-id.js +30 -2
  102. package/lib/template-compiler/bind-this.js +7 -2
  103. package/lib/template-compiler/compiler.js +77 -46
  104. package/lib/template-compiler/gen-node-react.js +2 -2
  105. package/lib/utils/pre-process-json.js +9 -5
  106. package/package.json +5 -4
  107. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  108. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  109. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  110. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  111. package/lib/runtime/components/web/event.js +0 -105
@@ -1,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;
@@ -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
- ...styles.button,
172
- ...(isMiniSize && styles.buttonMini),
173
- ...viewStyle
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, { defaultStyle });
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: { ...innerStyle, ...layoutStyle },
287
- ...layoutProps,
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 (<View {...innerProps}>
296
- {loading && <Loading alone={!children}/>}
297
- {wrapChildren(props, {
298
- hasVarDec,
299
- varContext: varContextRef.current,
300
- textStyle,
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;
@@ -316,8 +316,7 @@ var handleError = function (err, message) {
316
316
  document.removeEventListener('message', handleIncomingMessage);
317
317
  };
318
318
 
319
- function handleIncomingMessage(e) {
320
- var data = JSON.parse(e.data);
319
+ function handleIncomingMessage(data) {
321
320
  if (Array.isArray(data)) {
322
321
  for (var i = 0; i < data.length; i++) {
323
322
  try {
@@ -335,8 +334,7 @@ function handleIncomingMessage(e) {
335
334
  }
336
335
  }
337
336
 
338
- window.addEventListener('message', handleIncomingMessage);
339
- document.addEventListener('message', handleIncomingMessage);
337
+ window.mpxWebviewMessageCallback = handleIncomingMessage
340
338
  </script>
341
339
 
342
340
 
@@ -9,7 +9,7 @@
9
9
  * ✔ bindlongtap
10
10
  * ✔ binderror
11
11
  */
12
- import React, { useRef, useState, useCallback, useEffect, forwardRef } from 'react';
12
+ import { createElement, useRef, useState, useCallback, useEffect, forwardRef } from 'react';
13
13
  import { View, Platform, StyleSheet } from 'react-native';
14
14
  import { WebView } from 'react-native-webview';
15
15
  import useNodesRef from '../useNodesRef';
@@ -41,7 +41,7 @@ const _Canvas = forwardRef((props = {}, ref) => {
41
41
  const { style = {}, originWhitelist = ['*'], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
42
42
  const [isLoaded, setIsLoaded] = useState(false);
43
43
  const nodeRef = useRef(null);
44
- const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(extendObject(style, stylesheet.container), {
44
+ const { normalStyle, hasSelfPercent, setWidth, setHeight } = useTransformStyle(extendObject({}, style, stylesheet.container), {
45
45
  enableVar,
46
46
  externalVarContext,
47
47
  parentFontSize,
@@ -58,7 +58,7 @@ const _Canvas = forwardRef((props = {}, ref) => {
58
58
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
59
59
  const innerProps = useInnerProps(props, {
60
60
  ref: nodeRef,
61
- style: extendObject(normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 }),
61
+ style: extendObject({}, normalStyle, layoutStyle, { opacity: isLoaded ? 1 : 0 }),
62
62
  ...layoutProps
63
63
  }, [], {
64
64
  layoutRef
@@ -69,7 +69,11 @@ const _Canvas = forwardRef((props = {}, ref) => {
69
69
  useEffect(() => {
70
70
  const webviewPostMessage = (message) => {
71
71
  if (canvasRef.current.webview) {
72
- canvasRef.current.webview.postMessage(JSON.stringify(message));
72
+ const jsCode = `
73
+ window.mpxWebviewMessageCallback(${JSON.stringify(message)});
74
+ true;
75
+ `;
76
+ canvasRef.current.webview.injectJavaScript(jsCode);
73
77
  }
74
78
  };
75
79
  // 设置bus
@@ -191,24 +195,42 @@ const _Canvas = forwardRef((props = {}, ref) => {
191
195
  });
192
196
  if (Platform.OS === 'android') {
193
197
  const isAndroid9 = Platform.Version >= 28;
194
- return (<View {...innerProps}>
195
- <WebView ref={(element) => {
198
+ return createElement(View, innerProps, createElement(WebView, {
199
+ ref: (element) => {
196
200
  if (canvasRef.current) {
197
201
  canvasRef.current.webview = element;
198
202
  }
199
- }} style={[
203
+ },
204
+ style: [
200
205
  isAndroid9 ? stylesheet.webviewAndroid9 : stylesheet.webview,
201
206
  { height, width }
202
- ]} source={{ html }} originWhitelist={originWhitelist} onMessage={onMessage} onLoad={onLoad} overScrollMode="never" mixedContentMode="always" scalesPageToFit={false} javaScriptEnabled domStorageEnabled thirdPartyCookiesEnabled allowUniversalAccessFromFileURLs/>
203
- </View>);
207
+ ],
208
+ source: { html },
209
+ originWhitelist: originWhitelist,
210
+ onMessage: onMessage,
211
+ onLoad: onLoad,
212
+ overScrollMode: 'never',
213
+ mixedContentMode: 'always',
214
+ scalesPageToFit: false,
215
+ javaScriptEnabled: true,
216
+ domStorageEnabled: true,
217
+ thirdPartyCookiesEnabled: true,
218
+ allowUniversalAccessFromFileURLs: true
219
+ }));
204
220
  }
205
- return (<View {...innerProps}>
206
- <WebView ref={(element) => {
221
+ return createElement(View, innerProps, createElement(WebView, {
222
+ ref: (element) => {
207
223
  if (canvasRef.current) {
208
224
  canvasRef.current.webview = element;
209
225
  }
210
- }} style={[stylesheet.webview, { height, width }]} source={{ html }} originWhitelist={originWhitelist} onMessage={onMessage} onLoad={onLoad} scrollEnabled={false}/>
211
- </View>);
226
+ },
227
+ style: [stylesheet.webview, { height, width }],
228
+ source: { html },
229
+ originWhitelist: originWhitelist,
230
+ onMessage: onMessage,
231
+ onLoad: onLoad,
232
+ scrollEnabled: false
233
+ }));
212
234
  });
213
235
  _Canvas.displayName = 'mpxCanvas';
214
236
  export default _Canvas;