@mpxjs/webpack-plugin 2.9.62 → 2.9.64

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 (86) hide show
  1. package/lib/index.js +1 -3
  2. package/lib/platform/style/wx/index.js +67 -53
  3. package/lib/react/processStyles.js +1 -0
  4. package/lib/react/processTemplate.js +2 -3
  5. package/lib/react/style-helper.js +12 -7
  6. package/lib/runtime/components/react/context.ts +9 -7
  7. package/lib/runtime/components/react/dist/context.js +1 -0
  8. package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
  9. package/lib/runtime/components/react/dist/mpx-button.jsx +52 -74
  10. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +19 -18
  11. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +28 -41
  12. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -14
  13. package/lib/runtime/components/react/dist/mpx-icon.jsx +14 -17
  14. package/lib/runtime/components/react/dist/mpx-image/index.jsx +34 -33
  15. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
  16. package/lib/runtime/components/react/dist/mpx-input.jsx +35 -31
  17. package/lib/runtime/components/react/dist/mpx-label.jsx +29 -37
  18. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -18
  19. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -8
  20. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +9 -9
  21. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +7 -4
  22. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +11 -7
  23. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +1 -1
  24. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +18 -18
  25. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +102 -10
  26. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +147 -53
  27. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +19 -18
  28. package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
  29. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
  30. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +33 -26
  31. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +139 -74
  32. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +14 -6
  33. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
  34. package/lib/runtime/components/react/dist/mpx-switch.jsx +17 -14
  35. package/lib/runtime/components/react/dist/mpx-text.jsx +19 -35
  36. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  37. package/lib/runtime/components/react/dist/mpx-view.jsx +284 -209
  38. package/lib/runtime/components/react/dist/mpx-web-view.jsx +8 -5
  39. package/lib/runtime/components/react/dist/parser.js +218 -0
  40. package/lib/runtime/components/react/dist/utils.jsx +433 -0
  41. package/lib/runtime/components/react/getInnerListeners.ts +18 -8
  42. package/lib/runtime/components/react/mpx-button.tsx +81 -91
  43. package/lib/runtime/components/react/mpx-checkbox-group.tsx +48 -43
  44. package/lib/runtime/components/react/mpx-checkbox.tsx +52 -63
  45. package/lib/runtime/components/react/mpx-form.tsx +49 -21
  46. package/lib/runtime/components/react/mpx-icon.tsx +30 -27
  47. package/lib/runtime/components/react/mpx-image/index.tsx +52 -46
  48. package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
  49. package/lib/runtime/components/react/mpx-input.tsx +58 -38
  50. package/lib/runtime/components/react/mpx-label.tsx +54 -59
  51. package/lib/runtime/components/react/mpx-movable-area.tsx +38 -24
  52. package/lib/runtime/components/react/mpx-movable-view.tsx +27 -28
  53. package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
  54. package/lib/runtime/components/react/mpx-picker/date.tsx +2 -3
  55. package/lib/runtime/components/react/mpx-picker/index.tsx +10 -10
  56. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +15 -12
  57. package/lib/runtime/components/react/mpx-picker/region.tsx +21 -18
  58. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -6
  59. package/lib/runtime/components/react/mpx-picker/time.tsx +25 -29
  60. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  61. package/lib/runtime/components/react/mpx-picker-view-column.tsx +148 -20
  62. package/lib/runtime/components/react/mpx-picker-view.tsx +179 -63
  63. package/lib/runtime/components/react/mpx-radio-group.tsx +50 -47
  64. package/lib/runtime/components/react/mpx-radio.tsx +56 -72
  65. package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
  66. package/lib/runtime/components/react/mpx-scroll-view.tsx +133 -103
  67. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +174 -96
  68. package/lib/runtime/components/react/mpx-swiper/index.tsx +18 -9
  69. package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
  70. package/lib/runtime/components/react/mpx-swiper-item.tsx +46 -13
  71. package/lib/runtime/components/react/mpx-switch.tsx +44 -23
  72. package/lib/runtime/components/react/mpx-text.tsx +37 -45
  73. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  74. package/lib/runtime/components/react/mpx-view.tsx +388 -240
  75. package/lib/runtime/components/react/mpx-web-view.tsx +19 -20
  76. package/lib/runtime/components/react/parser.ts +245 -0
  77. package/lib/runtime/components/react/types/common.ts +4 -4
  78. package/lib/runtime/components/react/types/global.d.ts +14 -2
  79. package/lib/runtime/components/react/useNodesRef.ts +1 -2
  80. package/lib/runtime/components/react/utils.tsx +505 -0
  81. package/lib/template-compiler/compiler.js +28 -20
  82. package/lib/template-compiler/gen-node-react.js +1 -3
  83. package/lib/web/processStyles.js +2 -5
  84. package/package.json +6 -4
  85. package/lib/runtime/components/react/dist/utils.js +0 -148
  86. package/lib/runtime/components/react/utils.ts +0 -170
@@ -4,12 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { useRef, useState, forwardRef, useEffect, useContext } from 'react';
8
- import { View, Text, StyleSheet } from 'react-native';
7
+ import { useState, forwardRef, useEffect, useContext } from 'react';
8
+ import { View, StyleSheet } from 'react-native';
9
+ import { warn } from '@mpxjs/utils';
9
10
  import { LabelContext, RadioGroupContext } from './context';
10
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
12
  import useNodesRef from './useNodesRef';
12
- import { every, splitStyle, splitProps, isText, throwReactWarning } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
13
14
  import Icon from './mpx-icon';
14
15
  const styles = StyleSheet.create({
15
16
  container: {
@@ -44,26 +45,22 @@ const styles = StyleSheet.create({
44
45
  opacity: 1
45
46
  }
46
47
  });
47
- const Radio = forwardRef((props, ref) => {
48
- const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-offset': enableOffset, children, bindtap, catchtap, } = props;
49
- const layoutRef = useRef({});
48
+ const Radio = forwardRef((radioProps, ref) => {
49
+ const { textProps, innerProps: props = {} } = splitProps(radioProps);
50
+ const { value = '', disabled = false, checked = false, color = '#09BB07', style = [], 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindtap, catchtap } = props;
50
51
  const [isChecked, setIsChecked] = useState(!!checked);
51
52
  const groupContext = useContext(RadioGroupContext);
52
53
  let groupValue;
53
54
  let notifyChange;
54
55
  const labelContext = useContext(LabelContext);
55
- const { textStyle, imageStyle, innerStyle } = splitStyle(style);
56
- if (imageStyle) {
57
- throwReactWarning('[Mpx runtime warn]: Radio does not support background image-related styles!');
58
- }
59
56
  const defaultStyle = {
60
57
  ...styles.wrapper,
61
58
  ...(isChecked && styles.wrapperChecked),
62
- ...(disabled && styles.wrapperDisabled),
59
+ ...(disabled && styles.wrapperDisabled)
63
60
  };
64
- const viewStyle = {
65
- ...defaultStyle,
66
- ...innerStyle
61
+ const styleObj = {
62
+ ...styles.container,
63
+ ...style
67
64
  };
68
65
  const onChange = (evt) => {
69
66
  if (disabled || isChecked)
@@ -90,33 +87,16 @@ const Radio = forwardRef((props, ref) => {
90
87
  return;
91
88
  catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
92
89
  };
90
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
91
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
92
+ if (backgroundStyle) {
93
+ warn('Radio does not support background image-related styles!');
94
+ }
93
95
  const { nodeRef } = useNodesRef(props, ref, {
94
96
  defaultStyle,
95
97
  change: onChange
96
98
  });
97
- const onLayout = () => {
98
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
99
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
100
- });
101
- };
102
- const wrapChildren = (children, textStyle) => {
103
- if (!children)
104
- return children;
105
- const { textProps } = splitProps(props);
106
- if (every(children, (child) => isText(child))) {
107
- if (textStyle || textProps) {
108
- children = <Text key='radioTextWrap' style={textStyle || {}} {...(textProps || {})}>
109
- {children}
110
- </Text>;
111
- }
112
- }
113
- else {
114
- if (textStyle) {
115
- throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Radio is Text node!');
116
- }
117
- }
118
- return children;
119
- };
99
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
120
100
  if (groupContext) {
121
101
  groupValue = groupContext.groupValue;
122
102
  notifyChange = groupContext.notifyChange;
@@ -126,11 +106,11 @@ const Radio = forwardRef((props, ref) => {
126
106
  }
127
107
  const innerProps = useInnerProps(props, {
128
108
  ref: nodeRef,
129
- style: styles.container,
109
+ style: { ...innerStyle, ...layoutStyle },
110
+ ...layoutProps,
130
111
  bindtap: onTap,
131
- catchtap: catchTap,
132
- ...(enableOffset ? { onLayout } : {})
133
- }, ['enable-offset'], {
112
+ catchtap: catchTap
113
+ }, [], {
134
114
  layoutRef
135
115
  });
136
116
  useEffect(() => {
@@ -155,14 +135,19 @@ const Radio = forwardRef((props, ref) => {
155
135
  }
156
136
  }, [checked]);
157
137
  return (<View {...innerProps}>
158
- <View style={viewStyle}>
138
+ <View style={defaultStyle}>
159
139
  <Icon type='success' size={24} color={disabled ? '#E1E1E1' : color} style={{
160
140
  ...styles.icon,
161
141
  ...(isChecked && styles.iconChecked),
162
142
  ...(disabled && styles.iconDisabled)
163
143
  }}/>
164
144
  </View>
165
- {wrapChildren(children, textStyle)}
145
+ {wrapChildren(props, {
146
+ hasVarDec,
147
+ varContext: varContextRef.current,
148
+ textStyle,
149
+ textProps
150
+ })}
166
151
  </View>);
167
152
  });
168
153
  Radio.displayName = 'mpx-radio';
@@ -1,11 +1,15 @@
1
1
  import { Portal } from '@ant-design/react-native';
2
+ import { warn } from '@mpxjs/utils';
2
3
  const _RootPortal = (props) => {
3
4
  const { children, enable = true } = props;
4
- return enable ? (
5
- // @ts-ignore
6
- <Portal>
5
+ if (props.style) {
6
+ warn('The root-portal component does not support the style prop.');
7
+ }
8
+ return enable
9
+ ? <Portal>
7
10
  {children}
8
- </Portal>) : (<>{children}</>);
11
+ </Portal>
12
+ : <>{children}</>;
9
13
  };
10
14
  _RootPortal.displayName = 'mpx-root-portal';
11
15
  export default _RootPortal;
@@ -34,26 +34,29 @@
34
34
  import { ScrollView } from 'react-native-gesture-handler';
35
35
  import { RefreshControl } from 'react-native';
36
36
  import { useRef, useState, useEffect, forwardRef } from 'react';
37
+ import { warn } from '@mpxjs/utils';
37
38
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
38
39
  import useNodesRef from './useNodesRef';
39
- import { throwReactWarning } from './utils';
40
- const _ScrollView = forwardRef((props = {}, ref) => {
41
- const { children, enhanced = false, bounces = true, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'enable-offset': enableOffset, 'show-scrollbar': showScrollbar = true } = props;
40
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren } from './utils';
41
+ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
42
+ const { textProps, innerProps: props = {} } = splitProps(scrollViewProps);
43
+ const { enhanced = false, bounces = true, style = {}, 'scroll-x': scrollX = false, 'scroll-y': scrollY = false, 'enable-back-to-top': enableBackToTop = false, 'paging-enabled': pagingEnabled = false, 'upper-threshold': upperThreshold = 50, 'lower-threshold': lowerThreshold = 50, 'scroll-with-animation': scrollWithAnimation, 'refresher-enabled': refresherEnabled, 'refresher-default-style': refresherDefaultStyle, 'refresher-background': refresherBackground, 'show-scrollbar': showScrollbar = true, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
42
44
  const [refreshing, setRefreshing] = useState(true);
43
45
  const snapScrollTop = useRef(0);
44
46
  const snapScrollLeft = useRef(0);
45
- const layoutRef = useRef({});
46
47
  const scrollOptions = useRef({
47
48
  contentLength: 0,
48
49
  offset: 0,
49
50
  scrollLeft: 0,
50
51
  scrollTop: 0,
51
- visibleLength: 0,
52
+ visibleLength: 0
52
53
  });
53
54
  const scrollEventThrottle = 50;
54
55
  const hasCallScrollToUpper = useRef(true);
55
56
  const hasCallScrollToLower = useRef(false);
56
57
  const initialTimeout = useRef(null);
58
+ const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
59
+ const { textStyle, innerStyle } = splitStyle(normalStyle);
57
60
  const { nodeRef: scrollViewRef } = useNodesRef(props, ref, {
58
61
  scrollOffset: scrollOptions,
59
62
  node: {
@@ -66,8 +69,9 @@ const _ScrollView = forwardRef((props = {}, ref) => {
66
69
  scrollTo: scrollToOffset
67
70
  }
68
71
  });
72
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout });
69
73
  if (scrollX && scrollY) {
70
- throwReactWarning('[Mpx runtime warn]: scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
74
+ warn('scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion');
71
75
  }
72
76
  useEffect(() => {
73
77
  if (snapScrollTop.current !== props['scroll-top'] ||
@@ -100,7 +104,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
100
104
  if (!hasCallScrollToUpper.current) {
101
105
  bindscrolltoupper(getCustomEvent('scrolltoupper', e, {
102
106
  detail: {
103
- direction: scrollX ? 'left' : 'top',
107
+ direction: scrollX ? 'left' : 'top'
104
108
  },
105
109
  layoutRef
106
110
  }, props));
@@ -120,7 +124,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
120
124
  hasCallScrollToLower.current = true;
121
125
  bindscrolltolower(getCustomEvent('scrolltolower', e, {
122
126
  detail: {
123
- direction: scrollX ? 'right' : 'botttom',
127
+ direction: scrollX ? 'right' : 'botttom'
124
128
  },
125
129
  layoutRef
126
130
  }, props));
@@ -134,12 +138,8 @@ const _ScrollView = forwardRef((props = {}, ref) => {
134
138
  scrollOptions.current.contentLength = selectLength({ height, width });
135
139
  }
136
140
  function onLayout(e) {
137
- scrollOptions.current.visibleLength = selectLength(e.nativeEvent.layout);
138
- if (enableOffset) {
139
- scrollViewRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
140
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
141
- });
142
- }
141
+ const layout = e.nativeEvent.layout || {};
142
+ scrollOptions.current.visibleLength = selectLength(layout);
143
143
  }
144
144
  function updateScrollOptions(e, position) {
145
145
  const visibleLength = selectLength(e.nativeEvent.layoutMeasurement);
@@ -151,7 +151,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
151
151
  offset,
152
152
  scrollLeft: position.scrollLeft,
153
153
  scrollTop: position.scrollTop,
154
- visibleLength,
154
+ visibleLength
155
155
  };
156
156
  }
157
157
  function onScroll(e) {
@@ -166,7 +166,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
166
166
  scrollHeight,
167
167
  scrollWidth,
168
168
  deltaX: scrollLeft - scrollOptions.current.scrollLeft,
169
- deltaY: scrollTop - scrollOptions.current.scrollTop,
169
+ deltaY: scrollTop - scrollOptions.current.scrollTop
170
170
  },
171
171
  layoutRef
172
172
  }, props));
@@ -210,7 +210,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
210
210
  binddragstart(getCustomEvent('dragstart', e, {
211
211
  detail: {
212
212
  scrollLeft: scrollOptions.current.scrollLeft,
213
- scrollTop: scrollOptions.current.scrollTop,
213
+ scrollTop: scrollOptions.current.scrollTop
214
214
  },
215
215
  layoutRef
216
216
  }, props));
@@ -224,7 +224,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
224
224
  binddragging(getCustomEvent('dragging', e, {
225
225
  detail: {
226
226
  scrollLeft: scrollOptions.current.scrollLeft || 0,
227
- scrollTop: scrollOptions.current.scrollTop || 0,
227
+ scrollTop: scrollOptions.current.scrollTop || 0
228
228
  },
229
229
  layoutRef
230
230
  }, props));
@@ -249,6 +249,7 @@ const _ScrollView = forwardRef((props = {}, ref) => {
249
249
  }
250
250
  }
251
251
  let scrollAdditionalProps = {
252
+ style: { ...innerStyle, ...layoutStyle },
252
253
  pinchGestureEnabled: false,
253
254
  horizontal: scrollX && !scrollY,
254
255
  scrollEventThrottle: scrollEventThrottle,
@@ -261,19 +262,18 @@ const _ScrollView = forwardRef((props = {}, ref) => {
261
262
  onContentSizeChange: onContentSizeChange,
262
263
  bindtouchstart: onScrollTouchStart,
263
264
  bindtouchmove: onScrollTouchMove,
264
- onLayout,
265
265
  onScrollEndDrag,
266
- onMomentumScrollEnd: onScrollEnd
266
+ onMomentumScrollEnd: onScrollEnd,
267
+ ...layoutProps
267
268
  };
268
269
  if (enhanced) {
269
270
  scrollAdditionalProps = {
270
271
  ...scrollAdditionalProps,
271
272
  bounces,
272
- pagingEnabled,
273
+ pagingEnabled
273
274
  };
274
275
  }
275
276
  const innerProps = useInnerProps(props, scrollAdditionalProps, [
276
- 'enable-offset',
277
277
  'scroll-x',
278
278
  'scroll-y',
279
279
  'enable-back-to-top',
@@ -299,11 +299,18 @@ const _ScrollView = forwardRef((props = {}, ref) => {
299
299
  'bindrefresherrefresh'
300
300
  ], { layoutRef });
301
301
  const refreshColor = {
302
- 'black': ['#000'],
303
- 'white': ['#fff']
302
+ black: ['#000'],
303
+ white: ['#fff']
304
304
  };
305
- return (<ScrollView {...innerProps} refreshControl={refresherEnabled ? (<RefreshControl progressBackgroundColor={refresherBackground} refreshing={refreshing} onRefresh={onRefresh} {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}/>) : undefined}>
306
- {children}
305
+ return (<ScrollView {...innerProps} refreshControl={refresherEnabled
306
+ ? (<RefreshControl progressBackgroundColor={refresherBackground} refreshing={refreshing} onRefresh={onRefresh} {...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}/>)
307
+ : undefined}>
308
+ {wrapChildren(props, {
309
+ hasVarDec,
310
+ varContext: varContextRef.current,
311
+ textStyle,
312
+ textProps
313
+ })}
307
314
  </ScrollView>);
308
315
  });
309
316
  _ScrollView.displayName = 'mpx-scroll-view';