@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
@@ -5,18 +5,12 @@
5
5
  * ✔ color
6
6
  */
7
7
  import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
8
- import {
9
- View,
10
- Text,
11
- StyleSheet,
12
- ViewStyle,
13
- NativeSyntheticEvent,
14
- TextStyle
15
- } from 'react-native'
8
+ import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } from 'react-native'
9
+ import { warn } from '@mpxjs/utils'
16
10
  import { LabelContext, RadioGroupContext } from './context'
17
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
18
12
  import useNodesRef, { HandlerRef } from './useNodesRef'
19
- import { every, splitStyle, splitProps, isText, throwReactWarning } from './utils'
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
20
14
  import Icon from './mpx-icon'
21
15
 
22
16
  export interface RadioProps {
@@ -26,6 +20,11 @@ export interface RadioProps {
26
20
  color?: string
27
21
  style?: ViewStyle & Record<string, any>
28
22
  'enable-offset'?: boolean
23
+ 'enable-var'?: boolean
24
+ 'external-var-context'?: Record<string, any>
25
+ 'parent-font-size'?: number;
26
+ 'parent-width'?: number;
27
+ 'parent-height'?: number;
29
28
  children: ReactNode
30
29
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
31
30
  catchtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
@@ -66,44 +65,41 @@ const styles = StyleSheet.create({
66
65
  })
67
66
 
68
67
  const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
69
- (props, ref): JSX.Element => {
68
+ (radioProps, ref): JSX.Element => {
69
+ const { textProps, innerProps: props = {} } = splitProps(radioProps)
70
+
70
71
  const {
71
72
  value = '',
72
73
  disabled = false,
73
74
  checked = false,
74
75
  color = '#09BB07',
75
76
  style = [],
76
- 'enable-offset': enableOffset,
77
- children,
77
+ 'enable-var': enableVar,
78
+ 'external-var-context': externalVarContext,
79
+ 'parent-font-size': parentFontSize,
80
+ 'parent-width': parentWidth,
81
+ 'parent-height': parentHeight,
78
82
  bindtap,
79
- catchtap,
83
+ catchtap
80
84
  } = props
81
85
 
82
- const layoutRef = useRef({})
83
-
84
86
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
85
87
 
86
88
  const groupContext = useContext(RadioGroupContext)
87
- let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>>; } } | undefined;
88
- let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined;
89
+ let groupValue: { [key: string]: { checked: boolean; setValue: Dispatch<SetStateAction<boolean>>; } } | undefined
90
+ let notifyChange: (evt: NativeSyntheticEvent<TouchEvent>) => void | undefined
89
91
 
90
92
  const labelContext = useContext(LabelContext)
91
93
 
92
- const { textStyle, imageStyle, innerStyle } = splitStyle(style)
93
-
94
- if (imageStyle) {
95
- throwReactWarning('[Mpx runtime warn]: Radio does not support background image-related styles!')
96
- }
97
-
98
94
  const defaultStyle = {
99
95
  ...styles.wrapper,
100
96
  ...(isChecked && styles.wrapperChecked),
101
- ...(disabled && styles.wrapperDisabled),
97
+ ...(disabled && styles.wrapperDisabled)
102
98
  }
103
99
 
104
- const viewStyle = {
105
- ...defaultStyle,
106
- ...innerStyle
100
+ const styleObj = {
101
+ ...styles.container,
102
+ ...style
107
103
  }
108
104
 
109
105
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
@@ -130,49 +126,28 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
130
126
  catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
131
127
  }
132
128
 
133
- const { nodeRef } = useNodesRef(props, ref, {
129
+ const {
130
+ hasSelfPercent,
131
+ normalStyle,
132
+ hasVarDec,
133
+ varContextRef,
134
+ setWidth,
135
+ setHeight
136
+ } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
137
+
138
+ const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
139
+
140
+ if (backgroundStyle) {
141
+ warn('Radio does not support background image-related styles!')
142
+ }
143
+
144
+ const nodeRef = useRef(null)
145
+ useNodesRef(props, ref, nodeRef, {
134
146
  defaultStyle,
135
147
  change: onChange
136
148
  })
137
149
 
138
- const onLayout = () => {
139
- nodeRef.current?.measure(
140
- (
141
- x: number,
142
- y: number,
143
- width: number,
144
- height: number,
145
- offsetLeft: number,
146
- offsetTop: number
147
- ) => {
148
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
149
- }
150
- )
151
- }
152
-
153
- const wrapChildren = (
154
- children: ReactNode,
155
- textStyle?: TextStyle
156
- ) => {
157
- if (!children) return children
158
- const { textProps } = splitProps(props)
159
-
160
- if (every(children, (child) => isText(child))) {
161
- if (textStyle || textProps) {
162
- children = <Text key='radioTextWrap' style={textStyle || {}} {...(textProps || {})}>
163
- {children}
164
- </Text>
165
- }
166
- } else {
167
- if (textStyle) {
168
- throwReactWarning(
169
- '[Mpx runtime warn]: Text style will be ignored unless every child of the Radio is Text node!'
170
- )
171
- }
172
- }
173
-
174
- return children
175
- }
150
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
176
151
 
177
152
  if (groupContext) {
178
153
  groupValue = groupContext.groupValue
@@ -187,12 +162,12 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
187
162
  props,
188
163
  {
189
164
  ref: nodeRef,
190
- style: styles.container,
165
+ style: { ...innerStyle, ...layoutStyle },
166
+ ...layoutProps,
191
167
  bindtap: onTap,
192
- catchtap: catchTap,
193
- ...(enableOffset ? { onLayout } : {})
168
+ catchtap: catchTap
194
169
  },
195
- ['enable-offset'],
170
+ [],
196
171
  {
197
172
  layoutRef
198
173
  }
@@ -223,7 +198,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
223
198
 
224
199
  return (
225
200
  <View {...innerProps}>
226
- <View style={viewStyle}>
201
+ <View style={defaultStyle}>
227
202
  <Icon
228
203
  type='success'
229
204
  size={24}
@@ -235,7 +210,17 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
235
210
  }}
236
211
  />
237
212
  </View>
238
- {wrapChildren(children, textStyle)}
213
+ {
214
+ wrapChildren(
215
+ props,
216
+ {
217
+ hasVarDec,
218
+ varContext: varContextRef.current,
219
+ textStyle,
220
+ textProps
221
+ }
222
+ )
223
+ }
239
224
  </View>
240
225
  )
241
226
  }
@@ -3,23 +3,25 @@
3
3
  */
4
4
  import { ReactNode } from 'react'
5
5
  import { Portal } from '@ant-design/react-native'
6
-
6
+ import { warn } from '@mpxjs/utils'
7
7
  interface RootPortalProps {
8
8
  enable?: boolean
9
9
  children: ReactNode
10
+ [x: string]: any
10
11
  }
12
+
11
13
  const _RootPortal = (props: RootPortalProps) => {
12
14
  const { children, enable = true } = props
13
- return enable ? (
14
- // @ts-ignore
15
- <Portal>
15
+ if (props.style) {
16
+ warn('The root-portal component does not support the style prop.')
17
+ }
18
+ return enable
19
+ ? <Portal>
16
20
  {children}
17
21
  </Portal>
18
- ) : (
19
- <>{children}</>
20
- );
22
+ : <>{children}</>
21
23
  }
22
24
 
23
25
  _RootPortal.displayName = 'mpx-root-portal'
24
26
 
25
- export default _RootPortal
27
+ export default _RootPortal