@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
@@ -1,28 +1,54 @@
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({})
16
- const { nodeRef } = useNodesRef(props, ref, {})
20
+ const {
21
+ 'enable-offset': enableOffset,
22
+ 'enable-var': enableVar,
23
+ 'external-var-context': externalVarContext,
24
+ style
25
+ } = props
17
26
 
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
- }
27
+ const { textProps } = splitProps(props)
28
+ const nodeRef = useRef(null)
29
+ useNodesRef(props, ref, nodeRef, {})
30
+
31
+ const {
32
+ normalStyle,
33
+ hasVarDec,
34
+ varContextRef,
35
+ hasSelfPercent,
36
+ setWidth,
37
+ setHeight
38
+ } = useTransformStyle(style, { enableVar, externalVarContext })
39
+ const { textStyle, innerStyle } = splitStyle(normalStyle)
40
+
41
+ const {
42
+ // 存储layout布局信息
43
+ layoutRef,
44
+ layoutProps,
45
+ layoutStyle
46
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
23
47
 
24
48
  const innerProps = useInnerProps(props, {
25
- ...(enableOffset ? { onLayout } : {}),
49
+ style: { ...innerStyle, ...layoutStyle },
50
+ ref: nodeRef,
51
+ ...layoutProps
26
52
  }, [
27
53
  'children',
28
54
  'enable-offset'
@@ -30,15 +56,23 @@ const _SwiperItem = forwardRef<HandlerRef<View, SwiperItemProps>, SwiperItemProp
30
56
 
31
57
  return (
32
58
  <View
33
- ref={nodeRef}
34
59
  data-itemId={props['item-id']}
35
- style={[style]}
36
60
  {...innerProps}>
37
- {children}
61
+ {
62
+ wrapChildren(
63
+ props,
64
+ {
65
+ hasVarDec,
66
+ varContext: varContextRef.current,
67
+ textStyle,
68
+ textProps
69
+ }
70
+ )
71
+ }
38
72
  </View>
39
73
  )
40
74
  })
41
75
 
42
- _SwiperItem.displayName = 'mpx-swiper-item';
76
+ _SwiperItem.displayName = 'mpx-swiper-item'
43
77
 
44
78
  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,11 +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
- const { nodeRef } = useNodesRef<Switch, _SwitchProps>(props, ref)
79
+ const nodeRef = useRef(null)
80
+ useNodesRef<Switch, _SwitchProps>(props, ref, nodeRef)
81
+
82
+ const {
83
+ layoutRef,
84
+ layoutStyle,
85
+ layoutProps
86
+ } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
60
87
 
61
88
  const onChange = (evt: NativeSyntheticEvent<TouchEvent> | boolean, { checked }: { checked?: boolean } = {}) => {
62
89
  if (type === 'switch') {
@@ -78,23 +105,18 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
78
105
 
79
106
  if (formValuesMap) {
80
107
  if (!props.name) {
81
- throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
108
+ warn('If a form component is used, the name attribute is required.')
82
109
  } else {
83
110
  formValuesMap.set(props.name, { getValue, resetValue })
84
111
  }
85
112
  }
86
113
 
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
114
  const innerProps = useInnerProps(props, {
93
115
  ref: nodeRef,
94
- ...enableOffset ? { onLayout } : {},
116
+ style: { ...normalStyle, ...layoutStyle },
117
+ ...layoutProps,
95
118
  ...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
96
119
  }, [
97
- 'style',
98
120
  'checked',
99
121
  'disabled',
100
122
  'type',
@@ -107,19 +129,19 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
107
129
  return <CheckBox
108
130
  {...innerProps}
109
131
  color={color}
110
- style={style}
132
+ style={normalStyle}
111
133
  checked={isChecked}
112
134
  />
113
135
  }
114
136
 
115
- return (<Switch
137
+ return <Switch
116
138
  {...innerProps}
117
- style={style}
139
+ style={normalStyle}
118
140
  value={isChecked}
119
- trackColor={{ false: "#FFF", true: color }}
120
- thumbColor={isChecked ? "#FFF" : "#f4f3f4"}
141
+ trackColor={{ false: '#FFF', true: color }}
142
+ thumbColor={isChecked ? '#FFF' : '#f4f3f4'}
121
143
  ios_backgroundColor="#FFF"
122
- />)
144
+ />
123
145
  })
124
146
 
125
147
  _Switch.displayName = 'mpx-switch'
@@ -5,82 +5,75 @@
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 = useRef(null)
52
+ useNodesRef<Text, _TextProps>(props, ref, nodeRef)
53
+
46
54
  const innerProps = useInnerProps(props, {
47
- ref: nodeRef
55
+ ref: nodeRef,
56
+ style: normalStyle,
57
+ selectable: !!selectable || !!userSelect
48
58
  }, [
49
- 'style',
50
- 'children',
51
- 'selectable',
52
- 'user-select',
53
- 'useInherit',
54
- 'enable-offset'
59
+ 'user-select'
55
60
  ], {
56
61
  layoutRef
57
62
  })
58
63
 
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
64
  return (
78
65
  <Text
79
- style={{ ...defaultStyle, ...style }}
80
- selectable={!!selectable || !!userSelect}
81
66
  {...innerProps}
82
67
  >
83
- {children}
68
+ {
69
+ wrapChildren(
70
+ props,
71
+ {
72
+ hasVarDec,
73
+ varContext: varContextRef.current
74
+ }
75
+ )
76
+ }
84
77
  </Text>
85
78
  )
86
79
  })
@@ -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