@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.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.
Files changed (140) hide show
  1. package/lib/index.js +13 -8
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +35 -38
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  9. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  10. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  11. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  12. package/lib/react/processStyles.js +14 -4
  13. package/lib/react/processTemplate.js +3 -0
  14. package/lib/resolver/AddModePlugin.js +8 -8
  15. package/lib/runtime/components/react/context.ts +6 -0
  16. package/lib/runtime/components/react/dist/context.js +2 -0
  17. package/lib/runtime/components/react/dist/event.config.js +24 -24
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  20. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  21. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  22. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  29. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  30. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  31. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  32. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  33. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  34. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  35. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  36. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  37. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  38. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  39. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  41. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  44. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  47. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  48. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  49. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  50. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  51. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  52. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  53. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  54. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  56. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  57. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  58. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  59. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  60. package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
  61. package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
  62. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  63. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  64. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  65. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  66. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  67. package/lib/runtime/components/react/dist/utils.jsx +70 -23
  68. package/lib/runtime/components/react/event.config.ts +25 -26
  69. package/lib/runtime/components/react/getInnerListeners.ts +237 -199
  70. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  71. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  72. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  73. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  74. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  75. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  76. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  77. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  78. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  79. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  80. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  81. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  82. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  83. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  84. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  85. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  86. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  87. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  88. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  89. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  90. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  91. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  92. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  93. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  95. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  96. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  97. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  98. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  99. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  100. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  101. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  102. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  103. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  104. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  105. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  106. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  107. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  108. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  109. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  110. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  111. package/lib/runtime/components/react/mpx-view.tsx +92 -76
  112. package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
  113. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  114. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  115. package/lib/runtime/components/react/types/common.ts +2 -0
  116. package/lib/runtime/components/react/types/global.d.ts +5 -17
  117. package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
  118. package/lib/runtime/components/react/utils.tsx +99 -28
  119. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  120. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  121. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  122. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  123. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  124. package/lib/runtime/optionProcessor.js +7 -38
  125. package/lib/runtime/utils.js +2 -0
  126. package/lib/style-compiler/plugins/scope-id.js +30 -2
  127. package/lib/template-compiler/bind-this.js +7 -2
  128. package/lib/template-compiler/compiler.js +79 -47
  129. package/lib/template-compiler/gen-node-react.js +3 -3
  130. package/lib/utils/pre-process-json.js +9 -5
  131. package/package.json +6 -4
  132. package/LICENSE +0 -433
  133. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  134. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  135. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  136. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  137. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  138. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  139. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  140. package/lib/runtime/components/web/event.js +0 -105
@@ -1,27 +1,33 @@
1
- import { useRef } from 'react';
2
- import { omit } from './utils';
1
+ import { useRef, useMemo } from 'react';
2
+ import { hasOwn, collectDataset } from '@mpxjs/utils';
3
+ import { omit, extendObject } from './utils';
3
4
  import eventConfigMap from './event.config';
4
5
  const getTouchEvent = (type, event, props, config) => {
5
6
  const nativeEvent = event.nativeEvent;
6
7
  const { timestamp, pageX, pageY, touches, changedTouches } = nativeEvent;
7
8
  const { id } = props;
8
9
  const { layoutRef } = config;
9
- return {
10
- ...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, {
11
22
  type,
12
23
  timeStamp: timestamp,
13
- currentTarget: {
14
- ...(event.currentTarget || {}),
15
- id: id || '',
16
- dataset: getDataSet(props),
17
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
18
- offsetTop: layoutRef?.current?.offsetTop || 0
19
- },
24
+ currentTarget,
25
+ target,
20
26
  detail: {
21
27
  x: pageX,
22
28
  y: pageY
23
29
  },
24
- touches: touches.map(item => {
30
+ touches: touches.map((item) => {
25
31
  return {
26
32
  identifier: item.identifier,
27
33
  pageX: item.pageX,
@@ -30,7 +36,7 @@ const getTouchEvent = (type, event, props, config) => {
30
36
  clientY: item.locationY
31
37
  };
32
38
  }),
33
- changedTouches: changedTouches.map(item => {
39
+ changedTouches: changedTouches.map((item) => {
34
40
  return {
35
41
  identifier: item.identifier,
36
42
  pageX: item.pageX,
@@ -42,35 +48,150 @@ const getTouchEvent = (type, event, props, config) => {
42
48
  persist: event.persist,
43
49
  stopPropagation: event.stopPropagation,
44
50
  preventDefault: event.preventDefault
45
- };
46
- };
47
- export const getDataSet = (props) => {
48
- const result = {};
49
- for (const key in props) {
50
- if (key.indexOf('data-') === 0) {
51
- const newKey = key.substr(5);
52
- result[newKey] = props[key];
53
- }
54
- }
55
- return result;
51
+ });
56
52
  };
57
53
  export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, props = {}) => {
58
- return {
59
- ...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, {
60
61
  type,
61
62
  detail,
62
- target: {
63
- ...(oe.target || {}),
64
- id: props.id || '',
65
- dataset: getDataSet(props),
66
- offsetLeft: layoutRef?.current?.offsetLeft || 0,
67
- offsetTop: layoutRef?.current?.offsetTop || 0
68
- },
63
+ target: targetInfo,
69
64
  persist: oe.persist,
70
65
  stopPropagation: oe.stopPropagation,
71
66
  preventDefault: oe.preventDefault
72
- };
67
+ });
73
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
+ ];
74
195
  const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], rawConfig) => {
75
196
  const ref = useRef({
76
197
  startTimer: {
@@ -90,7 +211,11 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
90
211
  });
91
212
  const propsRef = useRef({});
92
213
  const eventConfig = {};
93
- const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false };
214
+ const config = rawConfig || {
215
+ layoutRef: { current: {} },
216
+ disableTouch: false,
217
+ disableTap: false
218
+ };
94
219
  const removeProps = [
95
220
  'children',
96
221
  'enable-background',
@@ -102,151 +227,35 @@ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], r
102
227
  'parent-height',
103
228
  ...userRemoveProps
104
229
  ];
105
- propsRef.current = { ...props, ...additionalProps };
230
+ propsRef.current = extendObject({}, props, additionalProps);
231
+ let hashEventKey = '';
232
+ const rawEventKeys = [];
106
233
  for (const key in eventConfigMap) {
107
- if (propsRef.current[key]) {
108
- 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);
109
238
  }
110
239
  }
111
- if (!(Object.keys(eventConfig).length) || config.disableTouch) {
240
+ if (!rawEventKeys.length || config.disableTouch) {
112
241
  return omit(propsRef.current, removeProps);
113
242
  }
114
- function handleEmitEvent(events, type, oe) {
115
- events.forEach(event => {
116
- if (propsRef.current[event]) {
117
- const match = /^(catch|capture-catch):?(.*?)(?:\.(.*))?$/.exec(event);
118
- if (match) {
119
- oe.stopPropagation();
120
- }
121
- 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]);
122
247
  }
123
- });
124
- }
125
- function checkIsNeedPress(e, type) {
126
- const tapDetailInfo = ref.current.mpxPressInfo.detail || { x: 0, y: 0 };
127
- const nativeEvent = e.nativeEvent;
128
- const currentPageX = nativeEvent.changedTouches[0].pageX;
129
- const currentPageY = nativeEvent.changedTouches[0].pageY;
130
- if (Math.abs(currentPageX - tapDetailInfo.x) > 1 || Math.abs(currentPageY - tapDetailInfo.y) > 1) {
131
- ref.current.needPress[type] = false;
132
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
133
- ref.current.startTimer[type] = null;
134
- }
135
- }
136
- function handleTouchstart(e, type) {
137
- e.persist();
138
- const bubbleTouchEvent = ['catchtouchstart', 'bindtouchstart'];
139
- const bubblePressEvent = ['catchlongpress', 'bindlongpress'];
140
- const captureTouchEvent = ['capture-catchtouchstart', 'capture-bindtouchstart'];
141
- const capturePressEvent = ['capture-catchlongpress', 'capture-bindlongpress'];
142
- ref.current.startTimer[type] = null;
143
- ref.current.needPress[type] = true;
144
- const nativeEvent = e.nativeEvent;
145
- ref.current.mpxPressInfo.detail = {
146
- x: nativeEvent.changedTouches[0].pageX,
147
- y: nativeEvent.changedTouches[0].pageY
148
- };
149
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
150
- const currentPressEvent = type === 'bubble' ? bubblePressEvent : capturePressEvent;
151
- handleEmitEvent(currentTouchEvent, 'touchstart', e);
152
- const { catchlongpress, bindlongpress, 'capture-catchlongpress': captureCatchlongpress, 'capture-bindlongpress': captureBindlongpress } = propsRef.current;
153
- if (catchlongpress || bindlongpress || captureCatchlongpress || captureBindlongpress) {
154
- ref.current.startTimer[type] = setTimeout(() => {
155
- ref.current.needPress[type] = false;
156
- handleEmitEvent(currentPressEvent, 'longpress', e);
157
- }, 350);
158
- }
159
- }
160
- function handleTouchmove(e, type) {
161
- const bubbleTouchEvent = ['catchtouchmove', 'bindtouchmove'];
162
- const captureTouchEvent = ['capture-catchtouchmove', 'capture-bindtouchmove'];
163
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
164
- handleEmitEvent(currentTouchEvent, 'touchmove', e);
165
- checkIsNeedPress(e, type);
166
- }
167
- function handleTouchend(e, type) {
168
- // move event may not be triggered
169
- checkIsNeedPress(e, type);
170
- const bubbleTouchEvent = ['catchtouchend', 'bindtouchend'];
171
- const bubbleTapEvent = ['catchtap', 'bindtap'];
172
- const captureTouchEvent = ['capture-catchtouchend', 'capture-bindtouchend'];
173
- const captureTapEvent = ['capture-catchtap', 'capture-bindtap'];
174
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
175
- const currentTapEvent = type === 'bubble' ? bubbleTapEvent : captureTapEvent;
176
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
177
- ref.current.startTimer[type] = null;
178
- handleEmitEvent(currentTouchEvent, 'touchend', e);
179
- if (ref.current.needPress[type]) {
180
- if (type === 'bubble' && config.disableTap) {
181
- return;
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);
182
255
  }
183
- handleEmitEvent(currentTapEvent, 'tap', e);
184
- }
185
- }
186
- function handleTouchcancel(e, type) {
187
- const bubbleTouchEvent = ['catchtouchcancel', 'bindtouchcancel'];
188
- const captureTouchEvent = ['capture-catchtouchcancel', 'capture-bindtouchcancel'];
189
- const currentTouchEvent = type === 'bubble' ? bubbleTouchEvent : captureTouchEvent;
190
- ref.current.startTimer[type] && clearTimeout(ref.current.startTimer[type]);
191
- ref.current.startTimer[type] = null;
192
- handleEmitEvent(currentTouchEvent, 'touchcancel', e);
193
- }
194
- const touchEventList = [{
195
- eventName: 'onTouchStart',
196
- handler: (e) => {
197
- handleTouchstart(e, 'bubble');
198
- }
199
- }, {
200
- eventName: 'onTouchMove',
201
- handler: (e) => {
202
- handleTouchmove(e, 'bubble');
203
- }
204
- }, {
205
- eventName: 'onTouchEnd',
206
- handler: (e) => {
207
- handleTouchend(e, 'bubble');
208
- }
209
- }, {
210
- eventName: 'onTouchCancel',
211
- handler: (e) => {
212
- handleTouchcancel(e, 'bubble');
213
- }
214
- }, {
215
- eventName: 'onTouchStartCapture',
216
- handler: (e) => {
217
- handleTouchstart(e, 'capture');
218
- }
219
- }, {
220
- eventName: 'onTouchMoveCapture',
221
- handler: (e) => {
222
- handleTouchmove(e, 'capture');
223
- }
224
- }, {
225
- eventName: 'onTouchEndCapture',
226
- handler: (e) => {
227
- handleTouchend(e, 'capture');
228
- }
229
- }, {
230
- eventName: 'onTouchCancelCapture',
231
- handler: (e) => {
232
- handleTouchcancel(e, 'capture');
233
- }
234
- }];
235
- const events = {};
236
- const transformedEventKeys = [];
237
- for (const key in eventConfig) {
238
- transformedEventKeys.push(...eventConfig[key]);
239
- }
240
- const finalEventKeys = [...new Set(transformedEventKeys)];
241
- touchEventList.forEach(item => {
242
- if (finalEventKeys.includes(item.eventName)) {
243
- events[item.eventName] = item.handler;
244
- }
245
- });
246
- const rawEventKeys = Object.keys(eventConfig);
247
- return {
248
- ...events,
249
- ...omit(propsRef.current, [...rawEventKeys, ...removeProps])
250
- };
256
+ });
257
+ return events;
258
+ }, [hashEventKey]);
259
+ return extendObject({}, events, omit(propsRef.current, [...rawEventKeys, ...removeProps]));
251
260
  };
252
261
  export default useInnerProps;
@@ -34,13 +34,13 @@
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 { 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
- import { FormContext } from './context';
43
+ import { RouteContext, FormContext } from './context';
44
44
  const LOADING_IMAGE_URI = 'data:image/png;base64,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';
45
45
  const TypeColorMap = {
46
46
  default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
@@ -78,6 +78,8 @@ const styles = StyleSheet.create({
78
78
  }
79
79
  });
80
80
  const getOpenTypeEvent = (openType) => {
81
+ if (!openType)
82
+ return;
81
83
  if (!global.__mpx?.config?.rnConfig) {
82
84
  warn('Environment not supported');
83
85
  return;
@@ -94,6 +96,11 @@ const getOpenTypeEvent = (openType) => {
94
96
  }
95
97
  return event;
96
98
  };
99
+ const timer = (data, time = 3000) => new Promise((resolve) => {
100
+ setTimeout(() => {
101
+ resolve(data);
102
+ }, time);
103
+ });
97
104
  const Loading = ({ alone = false }) => {
98
105
  const image = useRef(new Animated.Value(0)).current;
99
106
  const rotate = image.interpolate({
@@ -113,16 +120,16 @@ const Loading = ({ alone = false }) => {
113
120
  animation.stop();
114
121
  };
115
122
  }, []);
116
- const loadingStyle = {
117
- ...styles.loading,
123
+ const loadingStyle = extendObject({}, styles.loading, {
118
124
  transform: [{ rotate }],
119
125
  marginRight: alone ? 0 : 5
120
- };
126
+ });
121
127
  return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }}/>;
122
128
  };
123
129
  const Button = forwardRef((buttonProps, ref) => {
124
130
  const { textProps, innerProps: props = {} } = splitProps(buttonProps);
125
131
  const { size = 'default', type = 'default', plain = false, disabled = false, loading = false, 'hover-class': hoverClass, 'hover-style': hoverStyle = {}, 'hover-start-time': hoverStartTime = 20, 'hover-stay-time': hoverStayTime = 70, 'open-type': openType, 'form-type': formType, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, style = {}, children, bindgetuserinfo, bindtap, bindtouchstart, bindtouchend } = props;
132
+ const pageId = useContext(RouteContext);
126
133
  const formContext = useContext(FormContext);
127
134
  let submitFn;
128
135
  let resetFn;
@@ -159,44 +166,56 @@ const Button = forwardRef((buttonProps, ref) => {
159
166
  borderColor: plain ? plainBorderColor : normalBorderColor,
160
167
  backgroundColor: plain ? 'transparent' : normalBackgroundColor
161
168
  };
162
- const defaultViewStyle = {
163
- ...styles.button,
164
- ...(isMiniSize && styles.buttonMini),
165
- ...viewStyle
166
- };
167
- const defaultTextStyle = {
168
- ...styles.text,
169
- ...(isMiniSize && styles.textMini),
170
- color: plain ? plainTextColor : normalTextColor
171
- };
172
- const defaultStyle = {
173
- ...defaultViewStyle,
174
- ...defaultTextStyle
175
- };
176
- const styleObj = {
177
- ...defaultStyle,
178
- ...style,
179
- ...(applyHoverEffect && hoverStyle)
180
- };
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 : {});
181
173
  const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
182
174
  const nodeRef = useRef(null);
183
- useNodesRef(props, ref, nodeRef, { defaultStyle });
175
+ useNodesRef(props, ref, nodeRef, { style: normalStyle });
184
176
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
185
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
177
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle);
186
178
  if (backgroundStyle) {
187
179
  warn('Button does not support background image-related styles!');
188
180
  }
189
181
  const handleOpenTypeEvent = (evt) => {
190
- if (!openType)
191
- return;
192
182
  const handleEvent = getOpenTypeEvent(openType);
183
+ if (!handleEvent)
184
+ return;
193
185
  if (openType === 'share') {
194
- handleEvent && handleEvent({
186
+ const currentPage = getCurrentPage(pageId);
187
+ const event = {
195
188
  from: 'button',
196
- target: getCustomEvent('tap', evt, { layoutRef }, props).target
197
- });
189
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target,
190
+ webViewUrl: currentPage?.__webViewUrl
191
+ };
192
+ if (currentPage) {
193
+ const defaultMessage = {
194
+ title: global.__mpx.config.rnConfig.projectName || 'AwesomeProject',
195
+ path: currentPage.route || ''
196
+ };
197
+ if (currentPage.onShareAppMessage) {
198
+ const { promise, ...message } = currentPage.onShareAppMessage(event) || {};
199
+ if (promise) {
200
+ Promise.race([Promise.resolve(promise), timer(message)])
201
+ .then((msg) => {
202
+ handleEvent(Object.assign({}, defaultMessage, msg));
203
+ });
204
+ }
205
+ else {
206
+ handleEvent(Object.assign({}, defaultMessage, message));
207
+ }
208
+ }
209
+ else {
210
+ handleEvent(defaultMessage);
211
+ }
212
+ }
213
+ else {
214
+ warn('Current page not found');
215
+ // Todo handleEvent(event)
216
+ }
198
217
  }
199
- if (openType === 'getUserInfo' && handleEvent && bindgetuserinfo) {
218
+ if (openType === 'getUserInfo' && bindgetuserinfo) {
200
219
  Promise.resolve(handleEvent)
201
220
  .then((userInfo) => {
202
221
  if (typeof userInfo === 'object') {
@@ -246,26 +265,35 @@ const Button = forwardRef((buttonProps, ref) => {
246
265
  handleOpenTypeEvent(evt);
247
266
  handleFormTypeFn();
248
267
  };
249
- const innerProps = useInnerProps(props, {
268
+ const innerProps = useInnerProps(props, extendObject({
250
269
  ref: nodeRef,
251
- style: { ...innerStyle, ...layoutStyle },
252
- ...layoutProps,
253
- bindtouchstart: onTouchStart,
254
- bindtouchend: onTouchEnd,
255
- bindtap: onTap
256
- }, [], {
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
+ ], {
257
288
  layoutRef,
258
289
  disableTap: disabled
259
290
  });
260
- return (<View {...innerProps}>
261
- {loading && <Loading alone={!children}/>}
262
- {wrapChildren(props, {
263
- hasVarDec,
264
- varContext: varContextRef.current,
265
- textStyle,
266
- textProps
267
- })}
268
- </View>);
291
+ return createElement(View, innerProps, loading && createElement(Loading, { alone: !children }), wrapChildren(props, {
292
+ hasVarDec,
293
+ varContext: varContextRef.current,
294
+ textStyle,
295
+ textProps
296
+ }));
269
297
  });
270
298
  Button.displayName = 'MpxButton';
271
299
  export default Button;
@@ -0,0 +1,60 @@
1
+ import { warn } from '@mpxjs/utils';
2
+ export default class Bus {
3
+ _paused = false;
4
+ _messageListeners = {};
5
+ _queue = [];
6
+ _send;
7
+ _timeoutId = null;
8
+ constructor(send) {
9
+ this._send = send;
10
+ }
11
+ post(message) {
12
+ return new Promise((resolve) => {
13
+ if (message.type !== 'set' && message.id) {
14
+ this._messageListeners[message.id] = resolve;
15
+ }
16
+ if (!this._paused) {
17
+ this._queue.push(message);
18
+ this.startBatching();
19
+ }
20
+ else {
21
+ this._queue.push(message);
22
+ }
23
+ });
24
+ }
25
+ handle(message) {
26
+ if (!message.id)
27
+ return;
28
+ const handler = this._messageListeners[message.id];
29
+ delete this._messageListeners[message.id];
30
+ if (handler) {
31
+ handler(message);
32
+ }
33
+ else {
34
+ warn(`Received unexpected message: ${message}`);
35
+ }
36
+ }
37
+ pause() {
38
+ this._paused = true;
39
+ }
40
+ resume() {
41
+ this._paused = false;
42
+ this._send(this._queue);
43
+ this._queue = [];
44
+ }
45
+ startBatching() {
46
+ if (this._timeoutId)
47
+ return;
48
+ this._timeoutId = setTimeout(() => {
49
+ this._send(this._queue);
50
+ this._queue = [];
51
+ this._timeoutId = null;
52
+ }, 16);
53
+ }
54
+ clearBatchingTimeout() {
55
+ if (this._timeoutId) {
56
+ clearTimeout(this._timeoutId);
57
+ this._timeoutId = null;
58
+ }
59
+ }
60
+ }