@mpxjs/webpack-plugin 2.9.62 → 2.9.65

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 (95) hide show
  1. package/lib/config.js +38 -10
  2. package/lib/index.js +1 -3
  3. package/lib/platform/style/wx/index.js +115 -66
  4. package/lib/platform/template/wx/index.js +12 -8
  5. package/lib/react/processStyles.js +1 -0
  6. package/lib/react/processTemplate.js +2 -3
  7. package/lib/react/style-helper.js +9 -7
  8. package/lib/runtime/components/react/context.ts +9 -7
  9. package/lib/runtime/components/react/dist/context.js +1 -0
  10. package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
  11. package/lib/runtime/components/react/dist/mpx-button.jsx +53 -74
  12. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +20 -18
  13. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -42
  14. package/lib/runtime/components/react/dist/mpx-form.jsx +18 -15
  15. package/lib/runtime/components/react/dist/mpx-icon.jsx +15 -17
  16. package/lib/runtime/components/react/dist/mpx-image/index.jsx +36 -34
  17. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
  18. package/lib/runtime/components/react/dist/mpx-input.jsx +36 -31
  19. package/lib/runtime/components/react/dist/mpx-label.jsx +30 -37
  20. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +15 -19
  21. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +10 -9
  22. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
  23. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -10
  24. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +9 -5
  25. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +13 -8
  26. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +3 -2
  27. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +22 -20
  28. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +103 -10
  29. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +149 -54
  30. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +20 -18
  31. package/lib/runtime/components/react/dist/mpx-radio.jsx +29 -43
  32. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
  33. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +36 -27
  34. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +141 -75
  35. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +16 -7
  36. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +20 -11
  37. package/lib/runtime/components/react/dist/mpx-switch.jsx +18 -14
  38. package/lib/runtime/components/react/dist/mpx-text.jsx +20 -35
  39. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
  40. package/lib/runtime/components/react/dist/mpx-view.jsx +296 -210
  41. package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -7
  42. package/lib/runtime/components/react/dist/parser.js +218 -0
  43. package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
  44. package/lib/runtime/components/react/dist/utils.jsx +445 -0
  45. package/lib/runtime/components/react/getInnerListeners.ts +18 -8
  46. package/lib/runtime/components/react/mpx-button.tsx +83 -91
  47. package/lib/runtime/components/react/mpx-checkbox-group.tsx +50 -43
  48. package/lib/runtime/components/react/mpx-checkbox.tsx +56 -64
  49. package/lib/runtime/components/react/mpx-form.tsx +51 -22
  50. package/lib/runtime/components/react/mpx-icon.tsx +31 -27
  51. package/lib/runtime/components/react/mpx-image/index.tsx +54 -47
  52. package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
  53. package/lib/runtime/components/react/mpx-input.tsx +59 -38
  54. package/lib/runtime/components/react/mpx-label.tsx +55 -59
  55. package/lib/runtime/components/react/mpx-movable-area.tsx +40 -25
  56. package/lib/runtime/components/react/mpx-movable-view.tsx +29 -29
  57. package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
  58. package/lib/runtime/components/react/mpx-picker/date.tsx +4 -4
  59. package/lib/runtime/components/react/mpx-picker/index.tsx +12 -11
  60. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +17 -13
  61. package/lib/runtime/components/react/mpx-picker/region.tsx +23 -19
  62. package/lib/runtime/components/react/mpx-picker/selector.tsx +7 -7
  63. package/lib/runtime/components/react/mpx-picker/time.tsx +29 -31
  64. package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
  65. package/lib/runtime/components/react/mpx-picker-view-column.tsx +149 -20
  66. package/lib/runtime/components/react/mpx-picker-view.tsx +180 -63
  67. package/lib/runtime/components/react/mpx-radio-group.tsx +51 -47
  68. package/lib/runtime/components/react/mpx-radio.tsx +57 -72
  69. package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
  70. package/lib/runtime/components/react/mpx-scroll-view.tsx +136 -104
  71. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +175 -96
  72. package/lib/runtime/components/react/mpx-swiper/index.tsx +21 -9
  73. package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
  74. package/lib/runtime/components/react/mpx-swiper-item.tsx +48 -14
  75. package/lib/runtime/components/react/mpx-switch.tsx +46 -24
  76. package/lib/runtime/components/react/mpx-text.tsx +38 -45
  77. package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
  78. package/lib/runtime/components/react/mpx-view.tsx +401 -241
  79. package/lib/runtime/components/react/mpx-web-view.tsx +22 -22
  80. package/lib/runtime/components/react/parser.ts +245 -0
  81. package/lib/runtime/components/react/types/common.ts +4 -4
  82. package/lib/runtime/components/react/types/global.d.ts +24 -2
  83. package/lib/runtime/components/react/useNodesRef.ts +1 -7
  84. package/lib/runtime/components/react/utils.tsx +524 -0
  85. package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
  86. package/lib/style-compiler/index.js +5 -4
  87. package/lib/template-compiler/compiler.js +133 -161
  88. package/lib/template-compiler/gen-node-react.js +1 -3
  89. package/lib/utils/const.js +2 -1
  90. package/lib/web/processStyles.js +2 -1
  91. package/lib/web/processTemplate.js +2 -3
  92. package/lib/wxml/loader.js +1 -1
  93. package/package.json +7 -4
  94. package/lib/runtime/components/react/dist/utils.js +0 -148
  95. package/lib/runtime/components/react/utils.ts +0 -170
@@ -2,8 +2,10 @@ const postcss = require('postcss')
2
2
  const selectorParser = require('postcss-selector-parser')
3
3
  const getRulesRunner = require('../platform/index')
4
4
  const dash2hump = require('../utils/hump-dash').dash2hump
5
- const rpxRegExp = /^\s*(-?\d+(\.\d+)?)rpx\s*$/
6
- const pxRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
5
+ const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh)\s*$/
6
+ const numberRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
7
+ const hairlineRegExp = /^\s*hairlineWidth\s*$/
8
+ const varRegExp = /^--/
7
9
  const cssPrefixExp = /^-(webkit|moz|ms|o)-/
8
10
  function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
9
11
  const classMap = {}
@@ -15,11 +17,11 @@ function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
15
17
  function formatValue (value) {
16
18
  let matched
17
19
  let needStringify = true
18
- if ((matched = pxRegExp.exec(value))) {
20
+ if ((matched = numberRegExp.exec(value))) {
19
21
  value = matched[1]
20
22
  needStringify = false
21
- } else if ((matched = rpxRegExp.exec(value))) {
22
- value = `this.__rpx(${matched[1]})`
23
+ } else if (unitRegExp.test(value) || hairlineRegExp.test(value)) {
24
+ value = `global.__formatValue(${JSON.stringify(value)})`
23
25
  needStringify = false
24
26
  }
25
27
  return needStringify ? JSON.stringify(value) : value
@@ -38,13 +40,13 @@ function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
38
40
  const classMapValue = {}
39
41
  rule.walkDecls(({ prop, value }) => {
40
42
  if (cssPrefixExp.test(prop) || cssPrefixExp.test(value)) return
41
- let newData = rulesRunner({ prop, value })
43
+ let newData = rulesRunner({ prop, value, selector: rule.selector })
42
44
  if (!newData) return
43
45
  if (!Array.isArray(newData)) {
44
46
  newData = [newData]
45
47
  }
46
48
  newData.forEach(item => {
47
- prop = dash2hump(item.prop)
49
+ prop = varRegExp.test(item.prop) ? item.prop : dash2hump(item.prop)
48
50
  value = item.value
49
51
  if (Array.isArray(value)) {
50
52
  value = value.map(val => {
@@ -1,4 +1,4 @@
1
- import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react';
1
+ import { createContext, Dispatch, MutableRefObject, SetStateAction } from 'react'
2
2
  import { NativeSyntheticEvent } from 'react-native'
3
3
 
4
4
  export type LabelContextValue = MutableRefObject<{
@@ -15,14 +15,14 @@ export interface GroupContextValue {
15
15
  }
16
16
 
17
17
  export interface FormFieldValue {
18
- getValue: () => any;
19
- resetValue: ({ newVal, type }: { newVal?: any; type?: string }) => void;
18
+ getValue: () => any
19
+ resetValue: ({ newVal, type }: { newVal?: any; type?: string }) => void
20
20
  }
21
21
 
22
22
  export interface FormContextValue {
23
- formValuesMap: Map<string, FormFieldValue>;
24
- submit: () => void;
25
- reset: () => void;
23
+ formValuesMap: Map<string, FormFieldValue>
24
+ submit: () => void
25
+ reset: () => void
26
26
  }
27
27
 
28
28
  export const MovableAreaContext = createContext({ width: 0, height: 0 })
@@ -35,4 +35,6 @@ export const RadioGroupContext = createContext<GroupContextValue | null>(null)
35
35
 
36
36
  export const LabelContext = createContext<LabelContextValue | null>(null)
37
37
 
38
- export const PickerContext = createContext(null)
38
+ export const PickerContext = createContext(null)
39
+
40
+ export const VarContext = createContext({})
@@ -5,3 +5,4 @@ export const CheckboxGroupContext = createContext(null);
5
5
  export const RadioGroupContext = createContext(null);
6
6
  export const LabelContext = createContext(null);
7
7
  export const PickerContext = createContext(null);
8
+ export const VarContext = createContext({});
@@ -71,7 +71,7 @@ export const getCustomEvent = (type = '', oe = {}, { detail = {}, layoutRef }, p
71
71
  preventDefault: oe.preventDefault
72
72
  };
73
73
  };
74
- const useInnerProps = (props = {}, additionalProps = {}, removeProps = [], rawConfig) => {
74
+ const useInnerProps = (props = {}, additionalProps = {}, userRemoveProps = [], rawConfig) => {
75
75
  const ref = useRef({
76
76
  startTimer: {
77
77
  bubble: null,
@@ -91,6 +91,17 @@ const useInnerProps = (props = {}, additionalProps = {}, removeProps = [], rawCo
91
91
  const propsRef = useRef({});
92
92
  const eventConfig = {};
93
93
  const config = rawConfig || { layoutRef: { current: {} }, disableTouch: false, disableTap: false };
94
+ const removeProps = [
95
+ 'children',
96
+ 'enable-background',
97
+ 'enable-offset',
98
+ 'enable-var',
99
+ 'external-var-context',
100
+ 'parent-font-size',
101
+ 'parent-width',
102
+ 'parent-height',
103
+ ...userRemoveProps
104
+ ];
94
105
  propsRef.current = { ...props, ...additionalProps };
95
106
  for (const key in eventConfigMap) {
96
107
  if (propsRef.current[key]) {
@@ -35,21 +35,21 @@
35
35
  * ✔ bindtap
36
36
  */
37
37
  import { useEffect, useRef, useState, forwardRef, useContext } from 'react';
38
- import { View, Text, StyleSheet, Animated, Easing, } from 'react-native';
39
- import { splitStyle, isText, every, splitProps, throwReactWarning, transformTextStyle } from './utils';
38
+ import { View, StyleSheet, Animated, Easing } from 'react-native';
39
+ import { warn } from '@mpxjs/utils';
40
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
40
41
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
41
42
  import useNodesRef from './useNodesRef';
42
43
  import { FormContext } from './context';
43
- import { isEmptyObject } from '@mpxjs/utils';
44
44
  const LOADING_IMAGE_URI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAB8hJREFUeJztnVtsFFUch6ltUYrEAi0Qo40xChGM+oAGI0EEKl4QfDVI9AkqqQZ4IVA1RSIvJlwUWwqJUokGKMVYwHJTq4mGuA+SxpJYggJSSgMpVFOtvbh+J84mk+3smXN2znZm2fNLvoQH5uQ/v4+Z2Z3dHUaNsrGxsbGxsbGxsbGxsbGxsTGSrq6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qQPwUxXiAiFH/SRssLozkY94iLtXKxTyRAXeekFNqCQMuiXCBEX/8jc9Mx4KHurz9Hh+yDlIEJEKHyTz1GSGw9SpuxpMCCR0SneKPqtY0BIEXRKhIgj6F4jOx3lUHadz9Gh9DD+oEJEKHyZz1Fy8z+Mn8KPS2Qo/3cVJoSIUHpMIqQ5rZ3MplD6TokQ5f/QxaCQRyVCAt/UjHyca4jXrRKt/83GlBARiq/xkPEn3KOzTtaG8p+FLkfEX7AOtL6bZVhIAbwJ/zgyLkFkP2KOZEwKsTEQKyRi0b39bjMCofhTHjI8n/1uMwI5rvERro2NjY2NjY2NjY2NjY2NjY1+/gNWA2LIOT/TRAAAAABJRU5ErkJggg==';
45
45
  const TypeColorMap = {
46
46
  default: ['#F8F8F8', '#DEDEDE', '35,35,35', '#F7F7F7'],
47
47
  primary: ['#1AAD19', '#179B16', '26,173,25', '#9ED99D'],
48
- warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89'],
48
+ warn: ['#E64340', '#CE3C39', '230,67,64', '#EC8B89']
49
49
  };
50
50
  const OpenTypeEventsMap = new Map([
51
51
  ['share', 'onShareAppMessage'],
52
- ['getUserInfo', 'onUserInfo'],
52
+ ['getUserInfo', 'onUserInfo']
53
53
  ]);
54
54
  const styles = StyleSheet.create({
55
55
  button: {
@@ -63,35 +63,33 @@ const styles = StyleSheet.create({
63
63
  marginHorizontal: 'auto' // 按钮默认居中
64
64
  },
65
65
  buttonMini: {
66
- height: 30,
66
+ height: 30
67
67
  },
68
68
  text: {
69
69
  fontSize: 18,
70
- color: '#000000',
70
+ color: '#000000'
71
71
  },
72
72
  textMini: {
73
- fontSize: 13,
73
+ fontSize: 13
74
74
  },
75
75
  loading: {
76
76
  width: 20,
77
- height: 20,
78
- },
77
+ height: 20
78
+ }
79
79
  });
80
80
  const getOpenTypeEvent = (openType) => {
81
- // @ts-ignore
82
- if (!global?.__mpx?.config?.rnConfig) {
83
- throwReactWarning('[Mpx runtime warn]: Environment not supported');
81
+ if (!global.__mpx?.config?.rnConfig) {
82
+ warn('Environment not supported');
84
83
  return;
85
84
  }
86
85
  const eventName = OpenTypeEventsMap.get(openType);
87
86
  if (!eventName) {
88
- throwReactWarning(`[Mpx runtime warn]: open-type not support ${openType}`);
87
+ warn(`open-type not support ${openType}`);
89
88
  return;
90
89
  }
91
- // @ts-ignore
92
- const event = global.__mpx.config.rnConfig?.openTypeHandler?.[eventName];
90
+ const event = global.__mpx.config.rnConfig.openTypeHandler?.[eventName];
93
91
  if (!event) {
94
- throwReactWarning(`[Mpx runtime warn]: Unregistered ${eventName} event`);
92
+ warn(`Unregistered ${eventName} event`);
95
93
  return;
96
94
  }
97
95
  return event;
@@ -100,7 +98,7 @@ const Loading = ({ alone = false }) => {
100
98
  const image = useRef(new Animated.Value(0)).current;
101
99
  const rotate = image.interpolate({
102
100
  inputRange: [0, 1],
103
- outputRange: ['0deg', '360deg'],
101
+ outputRange: ['0deg', '360deg']
104
102
  });
105
103
  useEffect(() => {
106
104
  const animation = Animated.loop(Animated.timing(image, {
@@ -108,23 +106,23 @@ const Loading = ({ alone = false }) => {
108
106
  duration: 1000,
109
107
  easing: Easing.linear,
110
108
  useNativeDriver: true,
111
- isInteraction: false,
109
+ isInteraction: false
112
110
  }));
113
111
  animation.start();
114
112
  return () => {
115
113
  animation.stop();
116
114
  };
117
- // eslint-disable-next-line react-hooks/exhaustive-deps
118
115
  }, []);
119
116
  const loadingStyle = {
120
117
  ...styles.loading,
121
118
  transform: [{ rotate }],
122
- marginRight: alone ? 0 : 5,
119
+ marginRight: alone ? 0 : 5
123
120
  };
124
121
  return <Animated.Image testID="loading" style={loadingStyle} source={{ uri: LOADING_IMAGE_URI }}/>;
125
122
  };
126
- const Button = forwardRef((props, ref) => {
127
- 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, 'enable-offset': enableOffset, 'form-type': formType, style = {}, children, bindgetuserinfo, bindtap, bindtouchstart, bindtouchend, } = props;
123
+ const Button = forwardRef((buttonProps, ref) => {
124
+ const { textProps, innerProps: props = {} } = splitProps(buttonProps);
125
+ 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;
128
126
  const formContext = useContext(FormContext);
129
127
  let submitFn;
130
128
  let resetFn;
@@ -134,17 +132,11 @@ const Button = forwardRef((props, ref) => {
134
132
  }
135
133
  const refs = useRef({
136
134
  hoverStartTimer: undefined,
137
- hoverStayTimer: undefined,
135
+ hoverStayTimer: undefined
138
136
  });
139
- const layoutRef = useRef({});
140
137
  const [isHover, setIsHover] = useState(false);
141
138
  const isMiniSize = size === 'mini';
142
139
  const applyHoverEffect = isHover && hoverClass !== 'none';
143
- const { textStyle, imageStyle, innerStyle } = splitStyle(style);
144
- const { textStyle: hoverTextStyle, imageStyle: hoverImageStyle, innerStyle: hoverInnerStyle } = splitStyle(hoverStyle);
145
- if (imageStyle || hoverImageStyle) {
146
- throwReactWarning('[Mpx runtime warn]: Button does not support background image-related styles!');
147
- }
148
140
  const [color, hoverColor, plainColor, disabledColor] = TypeColorMap[type];
149
141
  const normalBackgroundColor = disabled ? disabledColor : applyHoverEffect || loading ? hoverColor : color;
150
142
  const plainBorderColor = disabled
@@ -165,18 +157,35 @@ const Button = forwardRef((props, ref) => {
165
157
  borderWidth: 1,
166
158
  borderStyle: 'solid',
167
159
  borderColor: plain ? plainBorderColor : normalBorderColor,
168
- backgroundColor: plain ? 'transparent' : normalBackgroundColor,
160
+ backgroundColor: plain ? 'transparent' : normalBackgroundColor
169
161
  };
170
162
  const defaultViewStyle = {
171
163
  ...styles.button,
172
164
  ...(isMiniSize && styles.buttonMini),
173
- ...viewStyle,
165
+ ...viewStyle
174
166
  };
175
167
  const defaultTextStyle = {
176
168
  ...styles.text,
177
169
  ...(isMiniSize && styles.textMini),
178
- color: plain ? plainTextColor : normalTextColor,
170
+ color: plain ? plainTextColor : normalTextColor
179
171
  };
172
+ const defaultStyle = {
173
+ ...defaultViewStyle,
174
+ ...defaultTextStyle
175
+ };
176
+ const styleObj = {
177
+ ...defaultStyle,
178
+ ...style,
179
+ ...(applyHoverEffect && hoverStyle)
180
+ };
181
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
182
+ const nodeRef = useRef(null);
183
+ useNodesRef(props, ref, nodeRef, { defaultStyle });
184
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
185
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
186
+ if (backgroundStyle) {
187
+ warn('Button does not support background image-related styles!');
188
+ }
180
189
  const handleOpenTypeEvent = (evt) => {
181
190
  if (!openType)
182
191
  return;
@@ -184,7 +193,7 @@ const Button = forwardRef((props, ref) => {
184
193
  if (openType === 'share') {
185
194
  handleEvent && handleEvent({
186
195
  from: 'button',
187
- target: getCustomEvent('tap', evt, { layoutRef }, props).target,
196
+ target: getCustomEvent('tap', evt, { layoutRef }, props).target
188
197
  });
189
198
  }
190
199
  if (openType === 'getUserInfo' && handleEvent && bindgetuserinfo) {
@@ -237,54 +246,24 @@ const Button = forwardRef((props, ref) => {
237
246
  handleOpenTypeEvent(evt);
238
247
  handleFormTypeFn();
239
248
  };
240
- function wrapChildren(children, defaultTextStyle, textStyle) {
241
- if (!children)
242
- return children;
243
- const hasTextStyle = !isEmptyObject(textStyle);
244
- const { textProps } = splitProps(props);
245
- if (every(children, (child) => isText(child))) {
246
- transformTextStyle(textStyle);
247
- children = <Text key='buttonTextWrap' style={{ ...defaultTextStyle, ...textStyle }} {...(textProps || {})}>{children}</Text>;
248
- }
249
- else {
250
- if (hasTextStyle)
251
- throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Button is Text node!');
252
- }
253
- return children;
254
- }
255
- const { nodeRef } = useNodesRef(props, ref, {
256
- defaultStyle: {
257
- ...defaultViewStyle,
258
- ...defaultTextStyle,
259
- ...textStyle
260
- }
261
- });
262
- const onLayout = () => {
263
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
264
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
265
- });
266
- };
267
249
  const innerProps = useInnerProps(props, {
268
250
  ref: nodeRef,
251
+ style: { ...innerStyle, ...layoutStyle },
252
+ ...layoutProps,
269
253
  bindtouchstart: onTouchStart,
270
254
  bindtouchend: onTouchEnd,
271
- bindtap: onTap,
272
- ...(enableOffset ? { onLayout } : {}),
273
- }, [
274
- 'enable-offset'
275
- ], {
255
+ bindtap: onTap
256
+ }, [], {
276
257
  layoutRef,
277
258
  disableTap: disabled
278
259
  });
279
- return (<View {...innerProps} style={{
280
- ...defaultViewStyle,
281
- ...innerStyle,
282
- ...(applyHoverEffect && hoverInnerStyle),
283
- }}>
260
+ return (<View {...innerProps}>
284
261
  {loading && <Loading alone={!children}/>}
285
- {wrapChildren(children, defaultTextStyle, {
286
- ...textStyle,
287
- ...(applyHoverEffect && hoverTextStyle),
262
+ {wrapChildren(props, {
263
+ hasVarDec,
264
+ varContext: varContextRef.current,
265
+ textStyle,
266
+ textProps
288
267
  })}
289
268
  </View>);
290
269
  });
@@ -3,13 +3,13 @@
3
3
  */
4
4
  import { useRef, forwardRef, useContext } from 'react';
5
5
  import { View } from 'react-native';
6
+ import { warn } from '@mpxjs/utils';
6
7
  import { FormContext, CheckboxGroupContext } from './context';
7
8
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
8
9
  import useNodesRef from './useNodesRef';
9
- import { throwReactWarning } from './utils';
10
+ import { useLayout, useTransformStyle, wrapChildren } from './utils';
10
11
  const CheckboxGroup = forwardRef((props, ref) => {
11
- const { style = {}, 'enable-offset': enableOffset, children, bindchange } = props;
12
- const layoutRef = useRef({});
12
+ const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, bindchange } = props;
13
13
  const formContext = useContext(FormContext);
14
14
  let formValuesMap;
15
15
  if (formContext) {
@@ -18,20 +18,19 @@ const CheckboxGroup = forwardRef((props, ref) => {
18
18
  const groupValue = useRef({}).current;
19
19
  const defaultStyle = {
20
20
  flexDirection: 'row',
21
- flexWrap: 'wrap',
22
- ...style
21
+ flexWrap: 'wrap'
23
22
  };
24
- const { nodeRef } = useNodesRef(props, ref, {
25
- defaultStyle
26
- });
27
- const onLayout = () => {
28
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
29
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
30
- });
23
+ const styleObj = {
24
+ ...defaultStyle,
25
+ ...style
31
26
  };
27
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
28
+ const nodeRef = useRef(null);
29
+ useNodesRef(props, ref, nodeRef, { defaultStyle });
30
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
32
31
  const getSelectionValue = () => {
33
32
  const arr = [];
34
- for (let key in groupValue) {
33
+ for (const key in groupValue) {
35
34
  if (groupValue[key].checked) {
36
35
  arr.push(key);
37
36
  }
@@ -49,7 +48,7 @@ const CheckboxGroup = forwardRef((props, ref) => {
49
48
  };
50
49
  if (formValuesMap) {
51
50
  if (!props.name) {
52
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.');
51
+ warn('If a form component is used, the name attribute is required.');
53
52
  }
54
53
  else {
55
54
  formValuesMap.set(props.name, { getValue, resetValue });
@@ -66,14 +65,17 @@ const CheckboxGroup = forwardRef((props, ref) => {
66
65
  };
67
66
  const innerProps = useInnerProps(props, {
68
67
  ref: nodeRef,
69
- style: defaultStyle,
70
- ...(enableOffset ? { onLayout } : {})
71
- }, ['enable-offset'], {
68
+ style: { ...normalStyle, ...layoutStyle },
69
+ ...layoutProps
70
+ }, [], {
72
71
  layoutRef
73
72
  });
74
73
  return (<View {...innerProps}>
75
74
  <CheckboxGroupContext.Provider value={{ groupValue, notifyChange }}>
76
- {children}
75
+ {wrapChildren(props, {
76
+ hasVarDec,
77
+ varContext: varContextRef.current
78
+ })}
77
79
  </CheckboxGroupContext.Provider>
78
80
  </View>);
79
81
  });
@@ -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, useRef, forwardRef, useEffect, useContext } from 'react';
8
+ import { View, StyleSheet } from 'react-native';
9
+ import { warn } from '@mpxjs/utils';
9
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
10
11
  import useNodesRef from './useNodesRef';
11
12
  import Icon from './mpx-icon';
12
- import { every, splitStyle, isText, splitProps, throwReactWarning } from './utils';
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils';
13
14
  import { CheckboxGroupContext, LabelContext } from './context';
14
15
  const styles = StyleSheet.create({
15
16
  container: {
@@ -37,24 +38,20 @@ const styles = StyleSheet.create({
37
38
  opacity: 1
38
39
  }
39
40
  });
40
- const Checkbox = forwardRef((props, ref) => {
41
- const { value = '', disabled = false, checked = false, color = '#09BB07', style = {}, 'enable-offset': enableOffset, children, bindtap, catchtap, } = props;
42
- const layoutRef = useRef({});
41
+ const Checkbox = forwardRef((checkboxProps, ref) => {
42
+ const { textProps, innerProps: props = {} } = splitProps(checkboxProps);
43
+ 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;
43
44
  const [isChecked, setIsChecked] = useState(!!checked);
44
- const { textStyle, imageStyle, innerStyle } = splitStyle(style);
45
- if (imageStyle) {
46
- throwReactWarning('[Mpx runtime warn]: Checkbox does not support background image-related styles!');
47
- }
48
45
  const groupContext = useContext(CheckboxGroupContext);
49
46
  let groupValue;
50
47
  let notifyChange;
51
48
  const defaultStyle = {
52
49
  ...styles.wrapper,
53
- ...(disabled && styles.wrapperDisabled),
50
+ ...(disabled && styles.wrapperDisabled)
54
51
  };
55
- const viewStyle = {
56
- ...defaultStyle,
57
- ...innerStyle
52
+ const styleObj = {
53
+ ...styles.container,
54
+ ...style
58
55
  };
59
56
  const onChange = (evt) => {
60
57
  if (disabled)
@@ -78,31 +75,17 @@ const Checkbox = forwardRef((props, ref) => {
78
75
  catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props));
79
76
  onChange(evt);
80
77
  };
81
- const { nodeRef } = useNodesRef(props, ref, {
78
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
79
+ const nodeRef = useRef(null);
80
+ useNodesRef(props, ref, nodeRef, {
82
81
  defaultStyle,
83
82
  change: onChange
84
83
  });
85
- const onLayout = () => {
86
- nodeRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
87
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
88
- });
89
- };
90
- const wrapChildren = (children, textStyle) => {
91
- if (!children)
92
- return children;
93
- const { textProps } = splitProps(props);
94
- if (every(children, (child) => isText(child))) {
95
- if (textStyle || textProps) {
96
- children = <Text key='checkboxTextWrap' style={textStyle || {}} {...(textProps || {})}>{children}</Text>;
97
- }
98
- }
99
- else {
100
- if (textStyle) {
101
- throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Checkbox is Text node!');
102
- }
103
- }
104
- return children;
105
- };
84
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef });
85
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle);
86
+ if (backgroundStyle) {
87
+ warn('Checkbox does not support background image-related styles!');
88
+ }
106
89
  const labelContext = useContext(LabelContext);
107
90
  if (groupContext) {
108
91
  groupValue = groupContext.groupValue;
@@ -113,11 +96,11 @@ const Checkbox = forwardRef((props, ref) => {
113
96
  }
114
97
  const innerProps = useInnerProps(props, {
115
98
  ref: nodeRef,
116
- style: styles.container,
99
+ style: { ...innerStyle, ...layoutStyle },
100
+ ...layoutProps,
117
101
  bindtap: onTap,
118
- catchtap: catchTap,
119
- ...(enableOffset ? { onLayout } : {})
120
- }, ['enable-offset'], {
102
+ catchtap: catchTap
103
+ }, [], {
121
104
  layoutRef
122
105
  });
123
106
  useEffect(() => {
@@ -142,10 +125,15 @@ const Checkbox = forwardRef((props, ref) => {
142
125
  }
143
126
  }, [checked]);
144
127
  return (<View {...innerProps}>
145
- <View style={viewStyle}>
128
+ <View style={defaultStyle}>
146
129
  <Icon type='success_no_circle' size={18} color={disabled ? '#ADADAD' : color} style={isChecked ? styles.iconChecked : styles.icon}/>
147
130
  </View>
148
- {wrapChildren(children, textStyle)}
131
+ {wrapChildren(props, {
132
+ hasVarDec,
133
+ varContext: varContextRef.current,
134
+ textStyle,
135
+ textProps
136
+ })}
149
137
  </View>);
150
138
  });
151
139
  Checkbox.displayName = 'mpx-checkbox';
@@ -9,20 +9,20 @@ import { useRef, forwardRef } from 'react';
9
9
  import useNodesRef from './useNodesRef';
10
10
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
11
11
  import { FormContext } from './context';
12
- const _Form = forwardRef((props, ref) => {
13
- const { children, style } = props;
14
- const layoutRef = useRef({});
12
+ import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils';
13
+ const _Form = forwardRef((fromProps, ref) => {
14
+ const { textProps, innerProps: props = {} } = splitProps(fromProps);
15
15
  const formValuesMap = useRef(new Map()).current;
16
- const { nodeRef: formRef } = useNodesRef(props, ref);
17
- const onLayout = (e) => {
18
- formRef.current?.measure((x, y, width, height, offsetLeft, offsetTop) => {
19
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop };
20
- });
21
- };
16
+ const { style, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props;
17
+ const { hasSelfPercent, normalStyle, hasVarDec, varContextRef, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
18
+ const { textStyle, innerStyle } = splitStyle(normalStyle);
19
+ const formRef = useRef(null);
20
+ useNodesRef(props, ref, formRef);
21
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef });
22
22
  const submit = () => {
23
23
  const { bindsubmit } = props;
24
24
  const formValue = {};
25
- for (let name of formValuesMap.keys()) {
25
+ for (const name of formValuesMap.keys()) {
26
26
  if (formValuesMap.get(name).getValue) {
27
27
  formValue[name] = formValuesMap.get(name).getValue();
28
28
  }
@@ -40,18 +40,21 @@ const _Form = forwardRef((props, ref) => {
40
40
  formValuesMap.forEach(item => item.resetValue());
41
41
  };
42
42
  const innerProps = useInnerProps(props, {
43
+ style: { ...innerStyle, ...layoutStyle },
43
44
  ref: formRef,
44
- style,
45
- onLayout
45
+ ...layoutProps
46
46
  }, [
47
- 'children',
48
- 'style',
49
47
  'bindsubmit',
50
48
  'bindreset'
51
49
  ], { layoutRef });
52
50
  return (<View {...innerProps}>
53
51
  <FormContext.Provider value={{ formValuesMap, submit, reset }}>
54
- {children}
52
+ {wrapChildren(props, {
53
+ hasVarDec,
54
+ varContext: varContextRef.current,
55
+ textStyle,
56
+ textProps
57
+ })}
55
58
  </FormContext.Provider>
56
59
  </View>);
57
60
  });