@mpxjs/webpack-plugin 2.9.66 → 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.
- package/lib/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +29 -8
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +24 -18
- package/lib/platform/style/wx/index.js +49 -47
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +5 -2
- package/lib/resolver/AddModePlugin.js +20 -7
- package/lib/runtime/components/react/context.ts +6 -0
- package/lib/runtime/components/react/dist/context.js +2 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -174
- package/lib/runtime/components/react/dist/mpx-button.jsx +78 -50
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +41 -34
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -39
- package/lib/runtime/components/react/dist/mpx-form.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-icon.jsx +9 -17
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +95 -62
- package/lib/runtime/components/react/dist/mpx-label.jsx +24 -28
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +20 -30
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +377 -293
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +3 -5
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +160 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +39 -34
- package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +7 -5
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +77 -51
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +606 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +28 -11
- package/lib/runtime/components/react/dist/mpx-text.jsx +12 -11
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +9 -4
- package/lib/runtime/components/react/dist/mpx-view.jsx +66 -62
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +113 -36
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +126 -12
- package/lib/runtime/components/react/dist/utils.jsx +80 -24
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +237 -198
- package/lib/runtime/components/react/mpx-button.tsx +105 -58
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +77 -51
- package/lib/runtime/components/react/mpx-checkbox.tsx +49 -50
- package/lib/runtime/components/react/mpx-form.tsx +62 -57
- package/lib/runtime/components/react/mpx-icon.tsx +13 -18
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +139 -117
- package/lib/runtime/components/react/mpx-label.tsx +36 -34
- package/lib/runtime/components/react/mpx-movable-area.tsx +26 -39
- package/lib/runtime/components/react/mpx-movable-view.tsx +455 -337
- package/lib/runtime/components/react/mpx-navigator.tsx +3 -9
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +236 -104
- package/lib/runtime/components/react/mpx-picker-view.tsx +132 -122
- package/lib/runtime/components/react/mpx-radio-group.tsx +77 -54
- package/lib/runtime/components/react/mpx-radio.tsx +46 -55
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +4 -6
- package/lib/runtime/components/react/mpx-scroll-view.tsx +122 -76
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +6 -4
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +4 -3
- package/lib/runtime/components/react/mpx-switch.tsx +39 -25
- package/lib/runtime/components/react/mpx-text.tsx +15 -19
- package/lib/runtime/components/react/mpx-textarea.tsx +12 -11
- package/lib/runtime/components/react/mpx-view.tsx +93 -77
- package/lib/runtime/components/react/mpx-web-view.tsx +117 -55
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +5 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +127 -18
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +113 -27
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +31 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +118 -56
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +117 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -346
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
|
31
|
+
// 初始的defaultValue数组中的数字依次表示 picker-view 内的 picker-view-column 选择的第几项(下标从 0 开始),
|
|
32
|
+
// 数字大于 picker-view-column 可选项长度时,选择最后一项。
|
|
22
33
|
value?: Array<number>
|
|
23
|
-
bindchange?:
|
|
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 {
|
|
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,
|
|
78
|
+
const { height: indicatorH, ...pickerOverlayStyle } = indicatorStyle
|
|
79
|
+
const [pickMaxH, setPickMaxH] = useState(0)
|
|
69
80
|
const nodeRef = useRef(null)
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
|
157
|
-
|
|
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
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
|
201
|
+
return columnData
|
|
184
202
|
}
|
|
185
203
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
215
|
-
{!isSetW && renderLine()}
|
|
216
|
-
</View>)
|
|
226
|
+
)
|
|
217
227
|
})
|
|
218
228
|
|
|
219
|
-
_PickerView.displayName = '
|
|
229
|
+
_PickerView.displayName = 'MpxPickerView'
|
|
220
230
|
|
|
221
231
|
export default _PickerView
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✔ bindchange
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
JSX,
|
|
6
|
+
useRef,
|
|
7
|
+
forwardRef,
|
|
8
|
+
ReactNode,
|
|
9
|
+
useContext,
|
|
10
|
+
useMemo,
|
|
11
|
+
useEffect,
|
|
12
|
+
createElement
|
|
13
|
+
} from 'react'
|
|
14
|
+
import {
|
|
15
|
+
View,
|
|
16
|
+
NativeSyntheticEvent,
|
|
17
|
+
ViewStyle
|
|
18
|
+
} from 'react-native'
|
|
6
19
|
import { warn } from '@mpxjs/utils'
|
|
20
|
+
|
|
7
21
|
import { FormContext, FormFieldValue, RadioGroupContext, GroupValue } from './context'
|
|
8
22
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
9
23
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
10
|
-
import { useLayout, useTransformStyle, wrapChildren } from './utils'
|
|
24
|
+
import { useLayout, useTransformStyle, wrapChildren, extendObject } from './utils'
|
|
11
25
|
|
|
12
26
|
export interface RadioGroupProps {
|
|
13
27
|
name: string
|
|
@@ -32,10 +46,13 @@ const radioGroup = forwardRef<
|
|
|
32
46
|
'external-var-context': externalVarContext,
|
|
33
47
|
'parent-font-size': parentFontSize,
|
|
34
48
|
'parent-width': parentWidth,
|
|
35
|
-
'parent-height': parentHeight
|
|
36
|
-
bindchange
|
|
49
|
+
'parent-height': parentHeight
|
|
37
50
|
} = props
|
|
38
51
|
|
|
52
|
+
const propsRef = useRef<any>({})
|
|
53
|
+
|
|
54
|
+
propsRef.current = props
|
|
55
|
+
|
|
39
56
|
const formContext = useContext(FormContext)
|
|
40
57
|
|
|
41
58
|
let formValuesMap: Map<string, FormFieldValue> | undefined
|
|
@@ -51,10 +68,7 @@ const radioGroup = forwardRef<
|
|
|
51
68
|
flexWrap: 'wrap'
|
|
52
69
|
}
|
|
53
70
|
|
|
54
|
-
const styleObj = {
|
|
55
|
-
...defaultStyle,
|
|
56
|
-
...style
|
|
57
|
-
}
|
|
71
|
+
const styleObj = extendObject({}, defaultStyle, style)
|
|
58
72
|
|
|
59
73
|
const {
|
|
60
74
|
hasSelfPercent,
|
|
@@ -66,11 +80,11 @@ const radioGroup = forwardRef<
|
|
|
66
80
|
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
67
81
|
|
|
68
82
|
const nodeRef = useRef(null)
|
|
69
|
-
useNodesRef(props, ref, nodeRef, {
|
|
83
|
+
useNodesRef(props, ref, nodeRef, { style: normalStyle })
|
|
70
84
|
|
|
71
85
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
72
86
|
|
|
73
|
-
const
|
|
87
|
+
const getValue = (): string | undefined => {
|
|
74
88
|
for (const key in groupValue) {
|
|
75
89
|
if (groupValue[key].checked) {
|
|
76
90
|
return key
|
|
@@ -78,10 +92,6 @@ const radioGroup = forwardRef<
|
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
const getValue = () => {
|
|
82
|
-
return getSelectionValue()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
95
|
const resetValue = () => {
|
|
86
96
|
Object.keys(groupValue).forEach((key) => {
|
|
87
97
|
groupValue[key].checked = false
|
|
@@ -96,56 +106,69 @@ const radioGroup = forwardRef<
|
|
|
96
106
|
formValuesMap.set(props.name, { getValue, resetValue })
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
return () => {
|
|
111
|
+
if (formValuesMap && props.name) {
|
|
112
|
+
formValuesMap.delete(props.name)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, [])
|
|
116
|
+
|
|
117
|
+
const contextValue = useMemo(() => {
|
|
118
|
+
const notifyChange = (
|
|
119
|
+
evt: NativeSyntheticEvent<TouchEvent>
|
|
120
|
+
) => {
|
|
121
|
+
const { bindchange } = propsRef.current
|
|
122
|
+
bindchange &&
|
|
123
|
+
bindchange(
|
|
124
|
+
getCustomEvent(
|
|
125
|
+
'tap',
|
|
126
|
+
evt,
|
|
127
|
+
{
|
|
128
|
+
layoutRef,
|
|
129
|
+
detail: {
|
|
130
|
+
value: getValue()
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
propsRef.current
|
|
134
|
+
)
|
|
115
135
|
)
|
|
116
|
-
|
|
117
|
-
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
groupValue,
|
|
139
|
+
notifyChange
|
|
140
|
+
}
|
|
141
|
+
}, [])
|
|
118
142
|
|
|
119
143
|
const innerProps = useInnerProps(
|
|
120
144
|
props,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
extendObject(
|
|
146
|
+
{
|
|
147
|
+
ref: nodeRef,
|
|
148
|
+
style: extendObject({}, normalStyle, layoutStyle)
|
|
149
|
+
},
|
|
150
|
+
layoutProps
|
|
151
|
+
),
|
|
152
|
+
['name'],
|
|
127
153
|
{
|
|
128
154
|
layoutRef
|
|
129
155
|
}
|
|
130
156
|
)
|
|
131
157
|
|
|
132
|
-
return (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
</RadioGroupContext.Provider>
|
|
145
|
-
</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
|
+
)
|
|
146
169
|
)
|
|
147
170
|
})
|
|
148
171
|
|
|
149
|
-
radioGroup.displayName = '
|
|
172
|
+
radioGroup.displayName = 'MpxRadioGroup'
|
|
150
173
|
|
|
151
174
|
export default radioGroup
|
|
@@ -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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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,36 +193,30 @@ const Radio = forwardRef<HandlerRef<View, RadioProps>, RadioProps>(
|
|
|
196
193
|
}
|
|
197
194
|
}, [checked])
|
|
198
195
|
|
|
199
|
-
return (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
varContext: varContextRef.current,
|
|
219
|
-
textStyle,
|
|
220
|
-
textProps
|
|
221
|
-
}
|
|
222
|
-
)
|
|
210
|
+
hasVarDec,
|
|
211
|
+
varContext: varContextRef.current,
|
|
212
|
+
textStyle,
|
|
213
|
+
textProps
|
|
223
214
|
}
|
|
224
|
-
|
|
215
|
+
)
|
|
225
216
|
)
|
|
226
217
|
}
|
|
227
218
|
)
|
|
228
219
|
|
|
229
|
-
Radio.displayName = '
|
|
220
|
+
Radio.displayName = 'MpxRadio'
|
|
230
221
|
|
|
231
222
|
export default Radio
|