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

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 (150) hide show
  1. package/lib/index.js +30 -9
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  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/movable-view.js +8 -1
  9. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  10. package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
  11. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  12. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  13. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  14. package/lib/react/processStyles.js +14 -4
  15. package/lib/react/processTemplate.js +3 -0
  16. package/lib/resolver/AddEnvPlugin.js +1 -0
  17. package/lib/resolver/AddModePlugin.js +9 -8
  18. package/lib/runtime/components/react/context.ts +14 -0
  19. package/lib/runtime/components/react/dist/context.js +4 -0
  20. package/lib/runtime/components/react/dist/event.config.js +24 -24
  21. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
  22. package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
  23. package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
  24. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
  25. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
  26. package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
  27. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
  28. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
  29. package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
  30. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
  31. package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
  32. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  33. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  34. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  35. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  36. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  37. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  38. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  39. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  40. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
  41. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  42. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  43. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  44. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  46. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  47. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  48. package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
  49. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
  50. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
  51. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  52. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  53. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  54. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
  55. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  56. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
  57. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  58. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
  59. package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
  60. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  61. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  62. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  63. package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
  64. package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
  65. package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
  66. package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
  67. package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
  68. package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
  69. package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
  70. package/lib/runtime/components/react/dist/utils.jsx +129 -24
  71. package/lib/runtime/components/react/event.config.ts +25 -26
  72. package/lib/runtime/components/react/getInnerListeners.ts +238 -202
  73. package/lib/runtime/components/react/mpx-button.tsx +104 -57
  74. package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
  75. package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
  76. package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
  77. package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
  78. package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
  79. package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
  80. package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
  81. package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
  82. package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
  83. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  84. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  85. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  86. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  87. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  88. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  89. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  90. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  91. package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
  92. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  93. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  94. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  95. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  96. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  97. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  98. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  99. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  100. package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
  101. package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
  102. package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
  103. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  104. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  105. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  106. package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
  107. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  108. package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
  109. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  110. package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
  111. package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
  112. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  113. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  114. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  115. package/lib/runtime/components/react/mpx-view.tsx +93 -117
  116. package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
  117. package/lib/runtime/components/react/pickerFaces.ts +112 -0
  118. package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
  119. package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
  120. package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
  121. package/lib/runtime/components/react/types/common.ts +2 -0
  122. package/lib/runtime/components/react/types/global.d.ts +7 -17
  123. package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
  124. package/lib/runtime/components/react/utils.tsx +169 -29
  125. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  126. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  127. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  128. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  129. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  130. package/lib/runtime/optionProcessor.js +7 -38
  131. package/lib/runtime/utils.js +2 -0
  132. package/lib/style-compiler/index.js +3 -4
  133. package/lib/style-compiler/plugins/scope-id.js +30 -2
  134. package/lib/style-compiler/strip-conditional-loader.js +118 -0
  135. package/lib/template-compiler/bind-this.js +7 -2
  136. package/lib/template-compiler/compiler.js +66 -39
  137. package/lib/template-compiler/gen-node-react.js +3 -3
  138. package/package.json +6 -4
  139. package/LICENSE +0 -433
  140. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  141. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  142. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
  143. package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
  144. package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
  145. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  146. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  147. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
  148. package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
  149. package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
  150. package/lib/runtime/components/web/event.js +0 -105
@@ -1,9 +1,17 @@
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, 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
+ extendObject
13
+ } from './utils'
14
+ import type { AnyFunc } from './types/common'
7
15
  /**
8
16
  * ✔ value
9
17
  * ✔ bindchange
@@ -11,20 +19,21 @@ import { parseInlineStyle, useTransformStyle, splitStyle, splitProps, useLayout,
11
19
  * ✘ bindpickend
12
20
  * ✘ mask-class
13
21
  * ✔ indicator-style: 优先级indicator-style.height > pick-view-column中的子元素设置的height
22
+ * WebView Only:
14
23
  * ✘ indicator-class
15
- * mask-style
24
+ * mask-style
16
25
  * ✘ immediate-change
17
26
  */
18
27
 
19
28
  interface PickerViewProps {
20
29
  children: React.ReactNode
21
- // 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),数字大于 picker-view-column 可选项长度时,选择最后一项。
22
30
  value?: Array<number>
23
- bindchange?: Function
31
+ bindchange?: AnyFunc
24
32
  style: {
25
33
  [key: string]: any
26
34
  }
27
35
  'indicator-style'?: string
36
+ 'mask-style'?: string
28
37
  'enable-var': boolean
29
38
  'external-var-context'?: Record<string, any>,
30
39
  'enable-offset': boolean
@@ -48,27 +57,31 @@ const styles: { [key: string]: Object } = {
48
57
  justifyContent: 'space-around',
49
58
  overflow: 'hidden',
50
59
  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
60
  }
62
61
  }
62
+
63
+ const DefaultPickerItemH = 36
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
65
- // indicatorStyle 需要转换为rn的style
66
- // 微信设置到pick-view上上设置的normalStyle如border等需要转换成RN的style然后进行透传
66
+ const {
67
+ children,
68
+ value = [],
69
+ bindchange,
70
+ style,
71
+ 'enable-var': enableVar,
72
+ 'external-var-context': externalVarContext
73
+ } = props
67
74
  const indicatorStyle = parseInlineStyle(props['indicator-style'])
68
- const { height: indicatorH, width: indicatorW } = indicatorStyle
75
+ const pickerMaskStyle = parseInlineStyle(props['mask-style'])
76
+ const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
69
77
  const nodeRef = useRef(null)
70
- useNodesRef<View, PickerViewProps>(props, ref, nodeRef, {})
71
- // picker-view 设置的color等textStyle,在小程序上的表现是可以继承到最内层的text样式, 但是RN内部column是slot无法设置, 需要业务自己在column内的元素上设置
78
+ const cloneRef = useRef(null)
79
+ const activeValueRef = useRef(value)
80
+ activeValueRef.current = value.slice()
81
+ const snapActiveValueRef = useRef<number[] | null>(null)
82
+
83
+ console.log('[mpx-picker-view] value=', value, Date.now())
84
+
72
85
  const {
73
86
  normalStyle,
74
87
  hasVarDec,
@@ -77,69 +90,90 @@ 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
- // 存储layout布局信息
84
99
  layoutRef,
85
100
  layoutProps,
86
101
  layoutStyle
87
102
  } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: nodeRef })
103
+ const { textProps } = splitProps(props)
104
+ const { textStyle } = splitStyle(normalStyle)
88
105
 
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
106
+ const onSelectChange = (columnIndex: number, selectedIndex: number) => {
107
+ const activeValue = activeValueRef.current
108
+ activeValue[columnIndex] = selectedIndex
109
+ console.log('[mpx-picker-view], onSelectChange ---> columnIndex=', columnIndex, 'selectedIndex=', selectedIndex, 'activeValue=', activeValue)
110
+ const eventData = getCustomEvent(
111
+ 'change',
112
+ {},
113
+ { detail: { value: activeValue, source: 'change' }, layoutRef }
114
+ )
115
+ bindchange?.(eventData)
116
+ snapActiveValueRef.current = activeValueRef.current
98
117
  }
99
118
 
100
- const onColumnLayoutChange = (layoutConfig: PickerLayout) => {
101
- pickH = layoutConfig.height
102
- setPickH(layoutConfig.height)
119
+ const hasDiff = (a: number[] = [], b: number[]) => {
120
+ return a.some((v, i) => v !== b[i])
103
121
  }
104
122
 
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)
123
+ const onInitialChange = (isInvalid: boolean, value: number[]) => {
124
+ if (isInvalid || !snapActiveValueRef.current || hasDiff(snapActiveValueRef.current, value)) {
125
+ console.log('[mpx-picker-view], onInitialChange ===> value=', value)
126
+ const eventData = getCustomEvent(
127
+ 'change',
128
+ {},
129
+ { detail: { value, source: 'change' }, layoutRef }
130
+ )
131
+ bindchange?.(eventData)
132
+ snapActiveValueRef.current = value.slice()
133
+ }
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 } : {}
127
- 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
136
- },
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)
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) => {
156
+ const childProps = child?.props || {}
157
+ const wrappedProps = extendObject(
158
+ {},
159
+ childProps,
160
+ {
161
+ columnData,
162
+ ref: cloneRef,
163
+ columnIndex: index,
164
+ key: `pick-view-${index}`,
165
+ wrapperStyle: {
166
+ height: normalStyle?.height || DefaultPickerItemH,
167
+ itemHeight: indicatorH || DefaultPickerItemH
168
+ },
169
+ columnStyle: normalStyle,
170
+ onSelectChange: onSelectChange.bind(null, index),
171
+ initialIndex,
172
+ pickerOverlayStyle,
173
+ pickerMaskStyle
174
+ }
175
+ )
176
+ const realElement = React.cloneElement(child, wrappedProps)
143
177
  return wrapChildren(
144
178
  {
145
179
  children: realElement
@@ -153,69 +187,43 @@ const _PickerView = forwardRef<HandlerRef<View, PickerViewProps>, PickerViewProp
153
187
  )
154
188
  }
155
189
 
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}/>)
190
+ const validateChildInitialIndex = (index: number, data: React.ReactNode[]) => {
191
+ return Math.max(0, Math.min(value[index] || 0, data.length - 1))
169
192
  }
170
193
 
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
- ]
194
+ const flatColumnChildren = (data: React.ReactElement) => {
195
+ const columnData = React.Children.toArray(data?.props?.children)
196
+ if (columnData.length === 1 && React.isValidElement(columnData[0]) && columnData[0].type === React.Fragment) {
197
+ // 只有一个 Fragment 嵌套情况
198
+ return React.Children.toArray(columnData[0].props.children)
182
199
  }
183
- return <LinearGradient {...linearProps}></LinearGradient>
200
+ return columnData
184
201
  }
185
202
 
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>
203
+ const renderPickerColumns = () => {
204
+ const columns = React.Children.toArray(children)
205
+ const renderColumns: React.ReactNode[] = []
206
+ const validValue: number[] = []
207
+ let isInvalid = false
208
+ columns.forEach((item: React.ReactElement, index) => {
209
+ const columnData = flatColumnChildren(item)
210
+ const validIndex = validateChildInitialIndex(index, columnData)
211
+ if (validIndex !== value[index]) {
212
+ isInvalid = true
213
+ }
214
+ validValue.push(validIndex)
215
+ renderColumns.push(renderColumn(item, index, columnData, validIndex))
216
+ })
217
+ onInitialChange(isInvalid, validValue)
218
+ return renderColumns
198
219
  }
199
220
 
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()}
221
+ return (
222
+ <View {...innerProps}>
223
+ <View style={[styles.wrapper]}>{renderPickerColumns()}</View>
213
224
  </View>
214
- {renderBottomMask()}
215
- {!isSetW && renderLine()}
216
- </View>)
225
+ )
217
226
  })
218
227
 
219
- _PickerView.displayName = 'mpx-picker-view'
220
-
228
+ _PickerView.displayName = 'MpxPickerView'
221
229
  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
+ }