@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.0

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 (140) hide show
  1. package/lib/index.js +13 -8
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +35 -38
  4. package/lib/platform/template/wx/component-config/canvas.js +8 -0
  5. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  6. package/lib/platform/template/wx/component-config/index.js +1 -1
  7. package/lib/platform/template/wx/component-config/input.js +1 -1
  8. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  9. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  10. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  11. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  12. package/lib/react/processStyles.js +14 -4
  13. package/lib/react/processTemplate.js +3 -0
  14. package/lib/resolver/AddModePlugin.js +8 -8
  15. package/lib/runtime/components/react/context.ts +6 -0
  16. package/lib/runtime/components/react/dist/context.js +2 -0
  17. package/lib/runtime/components/react/dist/event.config.js +24 -24
  18. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
  19. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  20. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  21. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  22. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  23. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  29. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  30. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  31. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  32. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  33. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  34. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  35. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  36. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  37. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  38. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  39. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  40. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  41. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  42. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  44. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  45. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  46. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
  47. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  48. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  49. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  50. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  51. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  52. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  53. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  54. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  55. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  56. package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
  57. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  58. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  59. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  60. package/lib/runtime/components/react/dist/mpx-view.jsx +65 -61
  61. package/lib/runtime/components/react/dist/mpx-web-view.jsx +112 -35
  62. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  63. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  64. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  65. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  66. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -9
  67. package/lib/runtime/components/react/dist/utils.jsx +70 -23
  68. package/lib/runtime/components/react/event.config.ts +25 -26
  69. package/lib/runtime/components/react/getInnerListeners.ts +237 -199
  70. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  71. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  72. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  73. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  74. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  75. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  76. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  77. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  78. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  79. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  80. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  81. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  82. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  83. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  84. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  85. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  86. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  87. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  88. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  89. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  90. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  91. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  92. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  93. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  95. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  96. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  97. package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
  98. package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
  99. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  100. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  101. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  102. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  103. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  104. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  105. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  106. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  107. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  108. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  109. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  110. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  111. package/lib/runtime/components/react/mpx-view.tsx +92 -76
  112. package/lib/runtime/components/react/mpx-web-view.tsx +116 -54
  113. package/lib/runtime/components/react/pickerFaces.ts +104 -0
  114. package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
  115. package/lib/runtime/components/react/types/common.ts +2 -0
  116. package/lib/runtime/components/react/types/global.d.ts +5 -17
  117. package/lib/runtime/components/react/useAnimationHooks.ts +36 -11
  118. package/lib/runtime/components/react/utils.tsx +99 -28
  119. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  120. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  121. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  122. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  123. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  124. package/lib/runtime/optionProcessor.js +7 -38
  125. package/lib/runtime/utils.js +2 -0
  126. package/lib/style-compiler/plugins/scope-id.js +30 -2
  127. package/lib/template-compiler/bind-this.js +7 -2
  128. package/lib/template-compiler/compiler.js +79 -47
  129. package/lib/template-compiler/gen-node-react.js +3 -3
  130. package/lib/utils/pre-process-json.js +9 -5
  131. package/package.json +6 -4
  132. package/LICENSE +0 -433
  133. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  134. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  135. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  136. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  137. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  138. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  139. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  140. package/lib/runtime/components/web/event.js +0 -105
@@ -1,9 +1,19 @@
1
1
  import { View } from 'react-native'
2
- import { LinearGradient, LinearGradientProps } from 'react-native-linear-gradient'
3
- import React, { forwardRef, useState, useRef, ReactElement, JSX } from 'react'
2
+ import React, { forwardRef, useState, useRef } from 'react'
4
3
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
5
- import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
6
- import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren } from './utils'
4
+ import useNodesRef, { HandlerRef } from './useNodesRef'
5
+ import {
6
+ useLayout,
7
+ splitProps,
8
+ splitStyle,
9
+ wrapChildren,
10
+ parseInlineStyle,
11
+ useTransformStyle,
12
+ useDebounceCallback,
13
+ useStableCallback,
14
+ extendObject
15
+ } from './utils'
16
+ import type { AnyFunc } from './types/common'
7
17
  /**
8
18
  * ✔ value
9
19
  * ✔ bindchange
@@ -18,9 +28,10 @@ import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout,
18
28
 
19
29
  interface PickerViewProps {
20
30
  children: React.ReactNode
21
- // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
31
+ // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
32
+ // 数字大于 picker-view-column 可选项长度时,选择最后一项。
22
33
  value?: Array<number>
23
- bindchange?: Function
34
+ bindchange?: AnyFunc
24
35
  style: {
25
36
  [key: string]: any
26
37
  }
@@ -48,27 +59,29 @@ const styles: { [key: string]: Object } = {
48
59
  justifyContent: 'space-around',
49
60
  overflow: 'hidden',
50
61
  alignItems: 'center'
51
- },
52
- maskTop: {
53
- position: 'absolute',
54
- width: 1000,
55
- zIndex: 100
56
- },
57
- maskBottom: {
58
- position: 'absolute',
59
- width: 1000,
60
- zIndex: 100
61
62
  }
62
63
  }
64
+
63
65
  const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProps>((props: PickerViewProps, ref) => {
64
- const { children, value = [], bindchange, style, 'enable-var': enableVar, 'external-var-context': externalVarContext } = props
66
+ const {
67
+ children,
68
+ value = [],
69
+ bindchange,
70
+ style,
71
+ 'enable-var': enableVar,
72
+ 'external-var-context': externalVarContext
73
+ } = props
74
+
65
75
  // indicatorStyle 需要转换为rn的style
66
76
  // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
67
77
  const indicatorStyle = parseInlineStyle(props['indicator-style'])
68
- const { height: indicatorH, width: indicatorW } = indicatorStyle
78
+ const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
79
+ const [pickMaxH, setPickMaxH] = useState(0)
69
80
  const nodeRef = useRef(null)
70
- useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
71
- // picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
81
+ const cloneRef = useRef(null)
82
+ const activeValueRef = useRef(value)
83
+ activeValueRef.current = value.slice()
84
+
72
85
  const {
73
86
  normalStyle,
74
87
  hasVarDec,
@@ -77,69 +90,91 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
77
90
  setWidth,
78
91
  setHeight
79
92
  } = useTransformStyle(style, { enableVar, externalVarContext })
80
- const { textStyle } = splitStyle(normalStyle)
81
- const { textProps } = splitProps(props)
93
+
94
+ useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {
95
+ style: normalStyle
96
+ })
97
+
82
98
  const {
83
99
  // 存储layout布局信息
84
100
  layoutRef,
85
101
  layoutProps,
86
102
  layoutStyle
87
103
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
104
+ const { textProps } = splitProps(props)
105
+ const { textStyle } = splitStyle(normalStyle)
88
106
 
89
- const isSetW = indicatorW !== undefined ? 1 : 0
90
- const cloneRef = useRef(null)
91
- const maskPos: PosType = {}
92
- let [pickH, setPickH] = useState(0)
93
- const itemH = pickH / 5
94
- if (normalStyle?.height && pickH && pickH !== normalStyle?.height) {
95
- maskPos.height = itemH * 2 + Math.ceil((normalStyle.height - pickH) / 2)
96
- } else {
97
- maskPos.height = itemH * 2
107
+ const onColumnItemRawHChange = (height: number) => {
108
+ if (height > pickMaxH) {
109
+ setPickMaxH(height)
110
+ }
98
111
  }
99
112
 
100
- const onColumnLayoutChange = (layoutConfig: PickerLayout) => {
101
- pickH = layoutConfig.height
102
- setPickH(layoutConfig.height)
113
+ const bindchangeDebounce = useDebounceCallback(useStableCallback(bindchange), 300)
114
+
115
+ const onSelectChange = (columnIndex: number, selectedIndex: number) => {
116
+ bindchangeDebounce.clear()
117
+ const activeValue = activeValueRef.current
118
+ activeValue[columnIndex] = selectedIndex
119
+ const eventData = getCustomEvent(
120
+ 'change',
121
+ {},
122
+ { detail: { value: activeValue, source: 'change' }, layoutRef }
123
+ )
124
+ bindchangeDebounce(eventData)
103
125
  }
104
126
 
105
- const onSelectChange = (columnIndex: number, selIndex: number) => {
106
- const changeValue = value.slice()
107
- changeValue[columnIndex] = selIndex
108
- const eventData = getCustomEvent('change', {}, { detail: { value: changeValue, source: 'change' }, layoutRef })
109
- bindchange && bindchange(eventData)
127
+ const onInitialChange = (value: number[]) => {
128
+ const eventData = getCustomEvent(
129
+ 'change',
130
+ {},
131
+ { detail: { value, source: 'change' }, layoutRef }
132
+ )
133
+ bindchange?.(eventData) // immediate
110
134
  }
111
135
 
112
- const innerProps = useInnerProps(props, {
113
- ref: nodeRef,
114
- style: {
115
- ...normalStyle,
116
- ...layoutStyle,
117
- position: 'relative',
118
- overflow: 'hidden'
119
- },
120
- ...layoutProps
121
- }, [
122
- 'enable-offset'
123
- ], { layoutRef })
124
-
125
- const cloneChild = (child: React.ReactNode, index: number) => {
126
- // const extraProps = index === 0 ? { getInnerLayout: getInnerLayout, innerProps } : {}
136
+ const innerProps = useInnerProps(
137
+ props,
138
+ extendObject({
139
+ ref: nodeRef,
140
+ style: extendObject(
141
+ {},
142
+ normalStyle,
143
+ layoutStyle,
144
+ {
145
+ position: 'relative',
146
+ overflow: 'hidden'
147
+ }
148
+ ),
149
+ layoutProps
150
+ }),
151
+ ['enable-offset'],
152
+ { layoutRef }
153
+ )
154
+
155
+ const renderColumn = (child: React.ReactElement, index: number, columnData: React.ReactNode[], initialIndex: number) => {
127
156
  const extraProps = {}
128
- const childProps = {
129
- ...(child as ReactElement)?.props,
130
- ref: cloneRef,
131
- prefix: index,
132
- key: 'pick-view' + index,
133
- wrapperStyle: {
134
- height: normalStyle?.height || 0,
135
- itemHeight: indicatorH || 0
157
+ const childProps = child?.props || {}
158
+ const wrappedProps = extendObject(
159
+ {},
160
+ childProps,
161
+ {
162
+ columnData,
163
+ ref: cloneRef,
164
+ columnIndex: index,
165
+ key: `pick-view-${index}`,
166
+ wrapperStyle: {
167
+ height: normalStyle?.height || 0,
168
+ itemHeight: indicatorH || 0
169
+ },
170
+ onColumnItemRawHChange,
171
+ onSelectChange: onSelectChange.bind(null, index),
172
+ initialIndex,
173
+ pickerOverlayStyle
136
174
  },
137
- onColumnLayoutChange,
138
- onSelectChange: onSelectChange.bind(null, index),
139
- selectedIndex: value?.[index] || 0,
140
- ...extraProps
141
- }
142
- const realElement = React.cloneElement(child as ReactElement, childProps)
175
+ extraProps
176
+ )
177
+ const realElement = React.cloneElement(child, wrappedProps)
143
178
  return wrapChildren(
144
179
  {
145
180
  children: realElement
@@ -153,69 +188,44 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
153
188
  )
154
189
  }
155
190
 
156
- const renderTopMask = () => {
157
- const linearProps: LinearGradientProps = {
158
- colors: ['rgba(255,255,255,0.8)', 'rgba(255,255,255,0.2)'],
159
- style: [
160
- styles.maskTop,
161
- {
162
- height: maskPos.height,
163
- top: 0,
164
- pointerEvents: 'none'
165
- }
166
- ]
167
- }
168
- return (<LinearGradient {...linearProps}/>)
191
+ const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
192
+ return Math.max(0, Math.min(value[index] || 0, data.length - 1))
169
193
  }
170
194
 
171
- const renderBottomMask = () => {
172
- const linearProps: LinearGradientProps = {
173
- colors: ['rgba(255,255,255,0.2)', 'rgba(255,255,255,0.8)'],
174
- style: [
175
- styles.maskBottom,
176
- {
177
- height: maskPos.height,
178
- bottom: 0,
179
- pointerEvents: 'none'
180
- }
181
- ]
195
+ const flatColumnChildren = (data: React.ReactElement) => {
196
+ const columnData = React.Children.toArray(data?.props?.children)
197
+ if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
198
+ // 只有一个 Fragment 嵌套情况
199
+ return React.Children.toArray(columnData[0].props.children)
182
200
  }
183
- return <LinearGradient {...linearProps}></LinearGradient>
201
+ return columnData
184
202
  }
185
203
 
186
- const renderLine = () => {
187
- return <View style={[{
188
- position: 'absolute',
189
- top: '50%',
190
- transform: [{ translateY: -(itemH / 2) }],
191
- height: itemH,
192
- borderTopWidth: 1,
193
- borderBottomWidth: 1,
194
- borderColor: '#f0f0f0',
195
- width: '100%',
196
- zIndex: 101
197
- }]}></View>
204
+ const renderPickerColumns = () => {
205
+ const columns = React.Children.toArray(children)
206
+ const renderColumns: React.ReactNode[] = []
207
+ const validValue: number[] = []
208
+ let isInvalid = false
209
+ columns.forEach((item: React.ReactElement, index) => {
210
+ const columnData = flatColumnChildren(item)
211
+ const validIndex = validateChildInitialIndex(index, columnData)
212
+ if (validIndex !== value[index]) {
213
+ isInvalid = true
214
+ }
215
+ validValue.push(validIndex)
216
+ renderColumns.push(renderColumn(item, index, columnData, validIndex))
217
+ })
218
+ isInvalid && onInitialChange(validValue)
219
+ return renderColumns
198
220
  }
199
221
 
200
- const renderSubChild = () => {
201
- if (Array.isArray(children)) {
202
- return children.map((item, index) => {
203
- return cloneChild(item, index)
204
- })
205
- } else {
206
- return cloneChild(children, 0)
207
- }
208
- }
209
- return (<View {...innerProps}>
210
- {renderTopMask()}
211
- <View style={[styles.wrapper]}>
212
- {renderSubChild()}
222
+ return (
223
+ <View {...innerProps}>
224
+ <View style={[styles.wrapper]}>{renderPickerColumns()}</View>
213
225
  </View>
214
- {renderBottomMask()}
215
- {!isSetW && renderLine()}
216
- </View>)
226
+ )
217
227
  })
218
228
 
219
- _PickerView.displayName = 'mpx-picker-view'
229
+ _PickerView.displayName = 'MpxPickerView'
220
230
 
221
231
  export default _PickerView
@@ -8,7 +8,8 @@ import {
8
8
  ReactNode,
9
9
  useContext,
10
10
  useMemo,
11
- useEffect
11
+ useEffect,
12
+ createElement
12
13
  } from 'react'
13
14
  import {
14
15
  View,
@@ -20,7 +21,7 @@ import { warn } from '@mpxjs/utils'
20
21
  import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
21
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
22
23
  import useNodesRef, { HandlerRef } from './useNodesRef'
23
- import { useLayout, useTransformStyle, wrapChildren } from './utils'
24
+ import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
24
25
 
25
26
  export interface RadioGroupProps {
26
27
  name: string
@@ -67,10 +68,7 @@ const radioGroup = forwardRef<
67
68
  flexWrap: 'wrap'
68
69
  }
69
70
 
70
- const styleObj = {
71
- ...defaultStyle,
72
- ...style
73
- }
71
+ const styleObj = extendObject({}, defaultStyle, style)
74
72
 
75
73
  const {
76
74
  hasSelfPercent,
@@ -82,7 +80,7 @@ const radioGroup = forwardRef<
82
80
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
83
81
 
84
82
  const nodeRef = useRef(null)
85
- useNodesRef(props, ref, nodeRef, { defaultStyle })
83
+ useNodesRef(props, ref, nodeRef, { style: normalStyle })
86
84
 
87
85
  const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
88
86
 
@@ -144,31 +142,30 @@ const radioGroup = forwardRef<
144
142
 
145
143
  const innerProps = useInnerProps(
146
144
  props,
147
- {
148
- ref: nodeRef,
149
- style: { ...normalStyle, ...layoutStyle },
150
- ...layoutProps
151
- },
152
- [],
145
+ extendObject(
146
+ {
147
+ ref: nodeRef,
148
+ style: extendObject({}, normalStyle, layoutStyle)
149
+ },
150
+ layoutProps
151
+ ),
152
+ ['name'],
153
153
  {
154
154
  layoutRef
155
155
  }
156
156
  )
157
157
 
158
- return (
159
- <View {...innerProps}>
160
- <RadioGroupContext.Provider value={contextValue}>
161
- {
162
- wrapChildren(
163
- props,
164
- {
165
- hasVarDec,
166
- varContext: varContextRef.current
167
- }
168
- )
169
- }
170
- </RadioGroupContext.Provider>
171
- </View>
158
+ return createElement(View, innerProps, createElement(
159
+ RadioGroupContext.Provider,
160
+ { value: contextValue },
161
+ wrapChildren(
162
+ props,
163
+ {
164
+ hasVarDec,
165
+ varContext: varContextRef.current
166
+ }
167
+ )
168
+ )
172
169
  )
173
170
  })
174
171
 
@@ -4,13 +4,13 @@
4
4
  * ✔ checked
5
5
  * ✔ color
6
6
  */
7
- import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction } from 'react'
7
+ import { JSX, useRef, useState, forwardRef, useEffect, ReactNode, useContext, Dispatch, SetStateAction, createElement } from 'react'
8
8
  import { View, StyleSheet, ViewStyle, NativeSyntheticEvent } from 'react-native'
9
9
  import { warn } from '@mpxjs/utils'
10
10
  import { LabelContext, RadioGroupContext } from './context'
11
11
  import useInnerProps, { getCustomEvent } from './getInnerListeners'
12
12
  import useNodesRef, { HandlerRef } from './useNodesRef'
13
- import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
13
+ import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
14
14
  import Icon from './mpx-icon'
15
15
 
16
16
  export interface RadioProps {
@@ -27,7 +27,6 @@ export interface RadioProps {
27
27
  'parent-height'?: number;
28
28
  children: ReactNode
29
29
  bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
30
- catchtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
31
30
  }
32
31
 
33
32
  const styles = StyleSheet.create({
@@ -79,8 +78,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
79
78
  'parent-font-size': parentFontSize,
80
79
  'parent-width': parentWidth,
81
80
  'parent-height': parentHeight,
82
- bindtap,
83
- catchtap
81
+ bindtap
84
82
  } = props
85
83
 
86
84
  const [isChecked, setIsChecked] = useState<boolean>(!!checked)
@@ -91,16 +89,14 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
91
89
 
92
90
  const labelContext = useContext(LabelContext)
93
91
 
94
- const defaultStyle = {
95
- ...styles.wrapper,
96
- ...(isChecked && styles.wrapperChecked),
97
- ...(disabled && styles.wrapperDisabled)
98
- }
92
+ const defaultStyle = extendObject(
93
+ {},
94
+ styles.wrapper,
95
+ isChecked ? styles.wrapperChecked : {},
96
+ disabled ? styles.wrapperDisabled : {}
97
+ )
99
98
 
100
- const styleObj = {
101
- ...styles.container,
102
- ...style
103
- }
99
+ const styleObj = extendObject({}, styles.container, style)
104
100
 
105
101
  const onChange = (evt: NativeSyntheticEvent<TouchEvent>) => {
106
102
  if (disabled || isChecked) return
@@ -116,16 +112,10 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
116
112
  }
117
113
 
118
114
  const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
119
- if (disabled) return
120
115
  bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
121
116
  onChange(evt)
122
117
  }
123
118
 
124
- const catchTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
125
- if (disabled) return
126
- catchtap && catchtap(getCustomEvent('tap', evt, { layoutRef }, props))
127
- }
128
-
129
119
  const {
130
120
  hasSelfPercent,
131
121
  normalStyle,
@@ -135,7 +125,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
135
125
  setHeight
136
126
  } = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
137
127
 
138
- const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
128
+ const { textStyle, backgroundStyle, innerStyle = {} } = splitStyle(normalStyle)
139
129
 
140
130
  if (backgroundStyle) {
141
131
  warn('Radio does not support background image-related styles!')
@@ -143,7 +133,7 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
143
133
 
144
134
  const nodeRef = useRef(null)
145
135
  useNodesRef(props, ref, nodeRef, {
146
- defaultStyle,
136
+ style: extendObject({}, defaultStyle, normalStyle),
147
137
  change: onChange
148
138
  })
149
139
 
@@ -160,14 +150,21 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
160
150
 
161
151
  const innerProps = useInnerProps(
162
152
  props,
163
- {
164
- ref: nodeRef,
165
- style: { ...innerStyle, ...layoutStyle },
166
- ...layoutProps,
167
- bindtap: onTap,
168
- catchtap: catchTap
169
- },
170
- [],
153
+ extendObject(
154
+ {
155
+ ref: nodeRef,
156
+ style: extendObject({}, innerStyle, layoutStyle)
157
+ },
158
+ layoutProps,
159
+ {
160
+ bindtap: !disabled && onTap
161
+ }
162
+ ),
163
+ [
164
+ 'value',
165
+ 'disabled',
166
+ 'checked'
167
+ ],
171
168
  {
172
169
  layoutRef
173
170
  }
@@ -196,32 +193,26 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
196
193
  }
197
194
  }, [checked])
198
195
 
199
- return (
200
- <View {...innerProps}>
201
- <View style={defaultStyle}>
202
- <Icon
203
- type='success'
204
- size={24}
205
- color={disabled ? '#E1E1E1' : color}
206
- style={{
207
- ...styles.icon,
208
- ...(isChecked && styles.iconChecked),
209
- ...(disabled && styles.iconDisabled)
210
- }}
211
- />
212
- </View>
196
+ return createElement(View, innerProps,
197
+ createElement(
198
+ View,
199
+ { style: defaultStyle },
200
+ createElement(Icon, {
201
+ type: 'success',
202
+ size: 24,
203
+ color: disabled ? '#E1E1E1' : color,
204
+ style: extendObject({}, styles.icon, isChecked && styles.iconChecked, disabled && styles.iconDisabled)
205
+ })
206
+ ),
207
+ wrapChildren(
208
+ props,
213
209
  {
214
- wrapChildren(
215
- props,
216
- {
217
- hasVarDec,
218
- varContext: varContextRef.current,
219
- textStyle,
220
- textProps
221
- }
222
- )
210
+ hasVarDec,
211
+ varContext: varContextRef.current,
212
+ textStyle,
213
+ textProps
223
214
  }
224
- </View>
215
+ )
225
216
  )
226
217
  }
227
218
  )
@@ -0,0 +1,40 @@
1
+
2
+ export const generateHTML = (html: string) => {
3
+ return `<html><head>
4
+ <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no" name="viewport">
5
+ <style>
6
+ html {
7
+ -ms-content-zooming: none;
8
+ -ms-touch-action: pan-x pan-y;
9
+ }
10
+ body {
11
+ position: fixed;
12
+ top: 0;
13
+ right: 0;
14
+ bottom: 0;
15
+ left: 0;
16
+ overflow: hidden;
17
+ }
18
+ html,body {
19
+ margin: 0;
20
+ padding: 0;
21
+ }
22
+ * {
23
+ user-select: none;
24
+ -ms-user-select: none;
25
+ -moz-user-select: none;
26
+ -webkit-user-select: none;
27
+ }
28
+ </style>
29
+ </head>
30
+ <body><div id="rich-text">${html}</div>
31
+ <script>
32
+ function sendHeight() {
33
+ const dom = document.getElementById('rich-text')
34
+ window.ReactNativeWebView.postMessage(dom.scrollHeight);
35
+ }
36
+ window.onload = sendHeight;
37
+ </script>
38
+ </body
39
+ ></html>`
40
+ }