@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
@@ -1,28 +1,53 @@
1
- import { View } from 'react-native'
1
+ import { View, LayoutChangeEvent } from 'react-native'
2
2
  import { ReactNode, forwardRef, useRef } from 'react'
3
3
  import useInnerProps from './getInnerListeners'
4
4
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
5
+ import { useTransformStyle, splitStyle, splitProps, wrapChildren, useLayout } from './utils'
5
6
 
6
7
  interface SwiperItemProps {
7
8
  'item-id'?: string;
8
9
  'enable-offset'?: boolean;
10
+ 'enable-var': boolean;
11
+ 'external-var-context'?: Record<string, any>;
12
+ 'parent-font-size'?: number;
13
+ 'parent-width'?: number;
14
+ 'parent-height'?: number;
9
15
  children?: ReactNode;
10
16
  style?: Object;
11
17
  }
12
18
 
13
19
  const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProps>((props: SwiperItemProps, ref) => {
14
- const { children, 'enable-offset': enableOffset, style } = props
15
- const layoutRef = useRef({})
20
+ const {
21
+ 'enable-offset': enableOffset,
22
+ 'enable-var': enableVar,
23
+ 'external-var-context': externalVarContext,
24
+ style
25
+ } = props
26
+
27
+ const { textProps } = splitProps(props)
16
28
  const { nodeRef } = useNodesRef(props, ref, {})
17
29
 
18
- const onLayout = () => {
19
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
20
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
21
- })
22
- }
30
+ const {
31
+ normalStyle,
32
+ hasVarDec,
33
+ varContextRef,
34
+ hasSelfPercent,
35
+ setWidth,
36
+ setHeight
37
+ } = useTransformStyle(style, { enableVar, externalVarContext })
38
+ const { textStyle, innerStyle } = splitStyle(normalStyle)
39
+
40
+ const {
41
+ // 存储layout布局信息
42
+ layoutRef,
43
+ layoutProps,
44
+ layoutStyle
45
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
23
46
 
24
47
  const innerProps = useInnerProps(props, {
25
- ...(enableOffset ? { onLayout } : {}),
48
+ style: { ...innerStyle, ...layoutStyle },
49
+ ref: nodeRef,
50
+ ...layoutProps
26
51
  }, [
27
52
  'children',
28
53
  'enable-offset'
@@ -30,15 +55,23 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
30
55
 
31
56
  return (
32
57
  <View
33
- ref={nodeRef}
34
58
  data-itemId={props['item-id']}
35
- style={[style]}
36
59
  {...innerProps}>
37
- {children}
60
+ {
61
+ wrapChildren(
62
+ props,
63
+ {
64
+ hasVarDec,
65
+ varContext: varContextRef.current,
66
+ textStyle,
67
+ textProps
68
+ }
69
+ )
70
+ }
38
71
  </View>
39
72
  )
40
73
  })
41
74
 
42
- _SwiperItem.displayName = 'mpx-swiper-item';
75
+ _SwiperItem.displayName = 'mpx-swiper-item'
43
76
 
44
77
  export default _SwiperItem
@@ -4,15 +4,15 @@
4
4
  * ✔ disabled
5
5
  * ✔ color
6
6
  */
7
- import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
8
- import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react';
7
+ import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent, LayoutChangeEvent } from 'react-native'
8
+ import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
9
+ import { warn } from '@mpxjs/utils'
9
10
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
10
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
11
12
 
12
13
  import CheckBox from './mpx-checkbox'
13
14
  import { FormContext, FormFieldValue } from './context'
14
-
15
- import { throwReactWarning } from './utils'
15
+ import { useTransformStyle, useLayout } from './utils'
16
16
 
17
17
  interface _SwitchProps extends SwitchProps {
18
18
  style?: ViewStyle
@@ -21,7 +21,11 @@ interface _SwitchProps extends SwitchProps {
21
21
  type: 'switch' | 'checkbox'
22
22
  disabled: boolean
23
23
  color: string
24
- 'enable-offset'?: boolean
24
+ 'enable-var'?: boolean
25
+ 'parent-font-size'?: number
26
+ 'parent-width'?: number
27
+ 'parent-height'?: number
28
+ 'external-var-context'?: Record<string, any>
25
29
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
26
30
  catchchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
27
31
  }
@@ -33,15 +37,18 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
33
37
  type = 'switch',
34
38
  disabled = false,
35
39
  color = '#04BE02',
36
- 'enable-offset': enableOffset,
40
+ 'enable-var': enableVar,
41
+ 'external-var-context': externalVarContext,
42
+ 'parent-font-size': parentFontSize,
43
+ 'parent-width': parentWidth,
44
+ 'parent-height': parentHeight,
45
+
37
46
  bindchange,
38
- catchchange,
47
+ catchchange
39
48
  } = props
40
49
 
41
50
  const [isChecked, setIsChecked] = useState<boolean>(checked)
42
51
 
43
- const layoutRef = useRef({})
44
-
45
52
  const changeHandler = bindchange || catchchange
46
53
 
47
54
  let formValuesMap: Map<string, FormFieldValue> | undefined
@@ -52,12 +59,31 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
52
59
  formValuesMap = formContext.formValuesMap
53
60
  }
54
61
 
62
+ const {
63
+ normalStyle,
64
+ hasSelfPercent,
65
+ setWidth,
66
+ setHeight
67
+ } = useTransformStyle(style, {
68
+ enableVar,
69
+ externalVarContext,
70
+ parentFontSize,
71
+ parentWidth,
72
+ parentHeight
73
+ })
74
+
55
75
  useEffect(() => {
56
76
  setIsChecked(checked)
57
77
  }, [checked])
58
78
 
59
79
  const { nodeRef } = useNodesRef<Switch, _SwitchProps>(props, ref)
60
80
 
81
+ const {
82
+ layoutRef,
83
+ layoutStyle,
84
+ layoutProps
85
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
86
+
61
87
  const onChange = (evt: NativeSyntheticEvent<TouchEvent> | boolean, { checked }: { checked?: boolean } = {}) => {
62
88
  if (type === 'switch') {
63
89
  setIsChecked(evt as boolean)
@@ -78,23 +104,18 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
78
104
 
79
105
  if (formValuesMap) {
80
106
  if (!props.name) {
81
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
107
+ warn('If a form component is used, the name attribute is required.')
82
108
  } else {
83
109
  formValuesMap.set(props.name, { getValue, resetValue })
84
110
  }
85
111
  }
86
112
 
87
- const onLayout = () => {
88
- nodeRef.current?.measure?.((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
89
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
90
- })
91
- }
92
113
  const innerProps = useInnerProps(props, {
93
114
  ref: nodeRef,
94
- ...enableOffset ? { onLayout } : {},
115
+ style: { ...normalStyle, ...layoutStyle },
116
+ ...layoutProps,
95
117
  ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
96
118
  }, [
97
- 'style',
98
119
  'checked',
99
120
  'disabled',
100
121
  'type',
@@ -107,19 +128,19 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
107
128
  return <CheckBox
108
129
  {...innerProps}
109
130
  color={color}
110
- style={style}
131
+ style={normalStyle}
111
132
  checked={isChecked}
112
133
  />
113
134
  }
114
135
 
115
- return (<Switch
136
+ return <Switch
116
137
  {...innerProps}
117
- style={style}
138
+ style={normalStyle}
118
139
  value={isChecked}
119
- trackColor={{ false: "#FFF", true: color }}
120
- thumbColor={isChecked ? "#FFF" : "#f4f3f4"}
140
+ trackColor={{ false: '#FFF', true: color }}
141
+ thumbColor={isChecked ? '#FFF' : '#f4f3f4'}
121
142
  ios_backgroundColor="#FFF"
122
- />)
143
+ />
123
144
  })
124
145
 
125
146
  _Switch.displayName = 'mpx-switch'
@@ -5,82 +5,74 @@
5
5
  * ✘ decode
6
6
  */
7
7
  import { Text, TextStyle, TextProps } from 'react-native'
8
- import { useRef, useEffect, forwardRef, ReactNode, JSX } from 'react'
8
+ import { useRef, forwardRef, ReactNode, JSX } from 'react'
9
9
  import useInnerProps from './getInnerListeners'
10
10
  import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
11
- import { transformTextStyle, DEFAULT_STYLE } from './utils'
11
+ import { useTransformStyle, wrapChildren } from './utils'
12
12
 
13
13
  interface _TextProps extends TextProps {
14
14
  style?: TextStyle
15
15
  children?: ReactNode
16
16
  selectable?: boolean
17
- 'enable-offset'?: boolean
18
17
  'user-select'?: boolean
19
- userSelect?: boolean
20
- ['disable-default-style']?: boolean
18
+ 'enable-var'?: boolean
19
+ 'external-var-context'?: Record<string, any>
20
+ 'parent-font-size'?: number
21
+ 'parent-width'?: number
22
+ 'parent-height'?: number
21
23
  }
22
24
 
23
25
  const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
24
26
  const {
25
27
  style = {},
26
- children,
27
28
  selectable,
28
- 'enable-offset': enableOffset,
29
+ 'enable-var': enableVar,
30
+ 'external-var-context': externalVarContext,
29
31
  'user-select': userSelect,
30
- 'disable-default-style': disableDefaultStyle = false,
32
+ 'parent-font-size': parentFontSize,
33
+ 'parent-width': parentWidth,
34
+ 'parent-height': parentHeight
31
35
  } = props
32
36
 
33
37
  const layoutRef = useRef({})
34
38
 
35
- let defaultStyle = {}
36
-
37
- if (!disableDefaultStyle) {
38
- defaultStyle = DEFAULT_STYLE
39
- transformTextStyle(style)
40
- }
41
-
42
- const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref, {
43
- defaultStyle
39
+ const {
40
+ normalStyle,
41
+ hasVarDec,
42
+ varContextRef
43
+ } = useTransformStyle(style, {
44
+ enableVar,
45
+ externalVarContext,
46
+ parentFontSize,
47
+ parentWidth,
48
+ parentHeight
44
49
  })
45
50
 
51
+ const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref)
52
+
46
53
  const innerProps = useInnerProps(props, {
47
- ref: nodeRef
54
+ ref: nodeRef,
55
+ style: normalStyle,
56
+ selectable: !!selectable || !!userSelect
48
57
  }, [
49
- 'style',
50
- 'children',
51
- 'selectable',
52
- 'user-select',
53
- 'useInherit',
54
- 'enable-offset'
58
+ 'user-select'
55
59
  ], {
56
60
  layoutRef
57
61
  })
58
62
 
59
- useEffect(() => {
60
- let measureTimeout: ReturnType<typeof setTimeout> | null = null
61
- if (enableOffset) {
62
- measureTimeout = setTimeout(() => {
63
- nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
64
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
65
- })
66
- })
67
- return () => {
68
- if (measureTimeout) {
69
- clearTimeout(measureTimeout)
70
- measureTimeout = null
71
- }
72
- }
73
- }
74
- }, [])
75
-
76
-
77
63
  return (
78
64
  <Text
79
- style={{ ...defaultStyle, ...style }}
80
- selectable={!!selectable || !!userSelect}
81
65
  {...innerProps}
82
66
  >
83
- {children}
67
+ {
68
+ wrapChildren(
69
+ props,
70
+ {
71
+ hasVarDec,
72
+ varContext: varContextRef.current
73
+ }
74
+ )
75
+ }
84
76
  </Text>
85
77
  )
86
78
  })
@@ -27,7 +27,7 @@ const Textarea = forwardRef<HandlerRef<TextInput, TextareProps>, TextareProps>(
27
27
  'type',
28
28
  'password',
29
29
  'multiline',
30
- 'confirm-hold',
30
+ 'confirm-hold'
31
31
  ])
32
32
  return (
33
33
  <Input