@mpxjs/webpack-plugin 2.10.3 → 2.10.4

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 (103) hide show
  1. package/lib/config.js +2 -1
  2. package/lib/index.js +1 -1
  3. package/lib/platform/json/wx/index.js +6 -3
  4. package/lib/platform/style/wx/index.js +23 -12
  5. package/lib/platform/template/wx/component-config/button.js +19 -2
  6. package/lib/platform/template/wx/component-config/canvas.js +4 -0
  7. package/lib/platform/template/wx/component-config/checkbox-group.js +4 -0
  8. package/lib/platform/template/wx/component-config/checkbox.js +4 -0
  9. package/lib/platform/template/wx/component-config/cover-image.js +7 -1
  10. package/lib/platform/template/wx/component-config/cover-view.js +4 -0
  11. package/lib/platform/template/wx/component-config/fix-component-name.js +3 -2
  12. package/lib/platform/template/wx/component-config/form.js +7 -1
  13. package/lib/platform/template/wx/component-config/icon.js +4 -0
  14. package/lib/platform/template/wx/component-config/image.js +7 -1
  15. package/lib/platform/template/wx/component-config/input.js +18 -3
  16. package/lib/platform/template/wx/component-config/label.js +4 -0
  17. package/lib/platform/template/wx/component-config/movable-area.js +7 -1
  18. package/lib/platform/template/wx/component-config/movable-view.js +12 -3
  19. package/lib/platform/template/wx/component-config/navigator.js +4 -0
  20. package/lib/platform/template/wx/component-config/picker-view-column.js +4 -0
  21. package/lib/platform/template/wx/component-config/picker-view.js +7 -1
  22. package/lib/platform/template/wx/component-config/picker.js +7 -1
  23. package/lib/platform/template/wx/component-config/radio-group.js +4 -0
  24. package/lib/platform/template/wx/component-config/radio.js +4 -0
  25. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  26. package/lib/platform/template/wx/component-config/root-portal.js +4 -0
  27. package/lib/platform/template/wx/component-config/scroll-view.js +10 -2
  28. package/lib/platform/template/wx/component-config/swiper-item.js +7 -1
  29. package/lib/platform/template/wx/component-config/swiper.js +12 -3
  30. package/lib/platform/template/wx/component-config/switch.js +4 -0
  31. package/lib/platform/template/wx/component-config/text.js +24 -3
  32. package/lib/platform/template/wx/component-config/textarea.js +17 -2
  33. package/lib/platform/template/wx/component-config/unsupported.js +7 -0
  34. package/lib/platform/template/wx/component-config/video.js +10 -2
  35. package/lib/platform/template/wx/component-config/view.js +11 -1
  36. package/lib/platform/template/wx/component-config/web-view.js +4 -0
  37. package/lib/platform/template/wx/index.js +42 -75
  38. package/lib/react/processScript.js +1 -18
  39. package/lib/runtime/components/react/dist/event.config.js +1 -0
  40. package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
  41. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
  42. package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
  43. package/lib/runtime/components/react/dist/mpx-input.jsx +3 -6
  44. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
  45. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
  46. package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
  47. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +178 -96
  48. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
  49. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
  50. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
  51. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
  52. package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +3 -3
  53. package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
  54. package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
  55. package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
  56. package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
  57. package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
  58. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +192 -25
  59. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
  60. package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
  61. package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
  62. package/lib/runtime/components/react/dist/mpx-web-view.jsx +7 -4
  63. package/lib/runtime/components/react/dist/utils.jsx +2 -1
  64. package/lib/runtime/components/react/event.config.ts +2 -0
  65. package/lib/runtime/components/react/getInnerListeners.ts +28 -25
  66. package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
  67. package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
  68. package/lib/runtime/components/react/mpx-input.tsx +2 -6
  69. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
  70. package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
  71. package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
  72. package/lib/runtime/components/react/mpx-picker/index.tsx +239 -118
  73. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
  74. package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
  75. package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
  76. package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
  77. package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
  78. package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +7 -7
  79. package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
  80. package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
  81. package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
  82. package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
  83. package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
  84. package/lib/runtime/components/react/mpx-scroll-view.tsx +249 -43
  85. package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
  86. package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
  87. package/lib/runtime/components/react/mpx-video.tsx +2 -2
  88. package/lib/runtime/components/react/mpx-web-view.tsx +7 -4
  89. package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
  90. package/lib/runtime/components/react/types/global.d.ts +1 -1
  91. package/lib/runtime/components/react/utils.tsx +3 -2
  92. package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
  93. package/lib/runtime/components/web/mpx-input.vue +1 -1
  94. package/lib/runtime/stringify.wxs +2 -2
  95. package/lib/template-compiler/compiler.js +8 -8
  96. package/lib/utils/env.js +1 -1
  97. package/package.json +4 -5
  98. /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
  99. /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
  100. /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
  101. /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
  102. /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
  103. /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
@@ -1,268 +1,151 @@
1
- import { View, Text, Modal, TouchableWithoutFeedback } from 'react-native'
2
- import Portal from '../mpx-portal/index'
3
- import { PickerView } from '@ant-design/react-native'
4
- import React, { forwardRef, useState, useRef, useEffect } from 'react'
5
- import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
1
+ import React, { forwardRef, useRef, useState, useEffect, useImperativeHandle } from 'react'
2
+ import { StyleSheet, Text, View } from 'react-native'
3
+ import { warn } from '@mpxjs/utils'
6
4
  import { TimeProps } from './type'
7
-
8
- // 可见应用窗口的大小。
9
- // const { height: dHeight, width: dWidth } = Dimensions.get('window');
10
- // modal属性: {"height": 298.33331298828125, "offsetLeft": 0, "offsetTop": 513.6666870117188, "width": 375, "x": 0, "y": 513.6666870117188}
11
- // const { height: sHeight, width: sWidth } = Dimensions.get('screen');
12
- // 设备屏幕的大小。 screen
13
- const styles: { [key: string]: Object } = {
14
- showModal: {
15
- backgroundColor: 'black',
16
- opacity: 0.5,
17
- width: '100%',
18
- height: '100%'
19
- },
20
- hideModal: {
21
- opacity: 1,
22
- height: 0
23
- },
24
- modal: {
25
- backgroundColor: 'black',
26
- opacity: 0.5
27
- },
28
- centeredView: {
29
- position: 'absolute',
30
- bottom: 0,
31
- width: '100%',
32
- overflow: 'scroll'
33
- },
34
- btnLine: {
35
- width: '100%',
36
- flex: 1,
37
- flexDirection: 'row',
38
- justifyContent: 'space-between',
39
- borderColor: 20,
40
- borderBottomWidth: 1,
41
- backgroundColor: 'white',
42
- paddingLeft: 40,
43
- paddingRight: 40
5
+ import MpxPickerView from '../mpx-picker-view'
6
+ import MpxPickerViewColumn from '../mpx-picker-view-column'
7
+ import { HandlerRef } from '../useNodesRef'
8
+ import { useUpdateEffect } from '../utils'
9
+
10
+ const styles = StyleSheet.create({
11
+ pickerContainer: {
12
+ width: 120,
13
+ height: 240,
14
+ alignSelf: 'center',
15
+ paddingHorizontal: 10,
16
+ borderTopLeftRadius: 10,
17
+ borderTopRightRadius: 10
44
18
  },
45
- cancel: {
46
- height: 50,
47
- display: 'flex',
48
- justifyContent: 'center'
19
+ pickerIndicator: {
20
+ height: 45
49
21
  },
50
- ok: {
51
- height: 50,
52
- display: 'flex',
53
- justifyContent: 'center'
54
- },
55
- btntext: {
56
- color: '#0ae',
57
- fontSize: 18
22
+ pickerItem: {
23
+ fontSize: 20,
24
+ lineHeight: 45,
25
+ textAlign: 'center'
58
26
  }
59
- }
27
+ })
60
28
 
61
- function formatStrToInt (timestr: string) {
62
- const [start, end] = timestr.split(':')
63
- return [parseInt(start), parseInt(end)]
64
- }
65
- // [9, 59] to 09:59
66
- function formatStr (arr: any[]) {
67
- let [hour, minute] = arr
68
- if (hour < 10) {
69
- hour = '0' + hour
70
- }
71
- if (minute < 10) {
72
- minute = '0' + minute
73
- }
74
- return hour + ':' + minute
75
- }
29
+ type Hour = number
30
+ type Minute = number
31
+ type TimeArray = [Hour, Minute]
76
32
 
77
- function generateMinute () {
78
- const arrMinute: any[] = []
79
- for (let i = 0; i <= 59; i++) {
80
- const obj = {
81
- label: toSingleStr(i),
82
- value: i,
83
- children: []
84
- }
85
- arrMinute.push(obj)
33
+ const time2Array = (time: string, defaultValue: TimeArray = [0, 0]): TimeArray => {
34
+ if (typeof time !== 'string') {
35
+ warn('[mpx runtime warn]: mpx-picker prop time must be a string')
36
+ return defaultValue
86
37
  }
87
- return arrMinute
38
+ let [hour = 0, minute = 0] = time.split(':').map(Number)
39
+ hour = Math.min(Math.max(hour, 0), 23)
40
+ minute = Math.min(Math.max(minute, 0), 59)
41
+ return [hour, minute]
88
42
  }
89
- function generateColumns (): any[] {
90
- const pickData: any[] = []
91
- for (let i = 0; i <= 23; i++) {
92
- const obj = {
93
- label: toSingleStr(i),
94
- value: i,
95
- children: generateMinute()
96
- }
97
- pickData.push(obj)
98
- }
99
43
 
100
- return pickData
44
+ const time2String = (time: TimeArray): string => {
45
+ return time.map(i => i.toString().padStart(2, '0')).join(':')
101
46
  }
102
47
 
103
- function toSingleStr (str: number) {
104
- return str < 10 ? '0' + str : str
48
+ const time2Minutes = (time: TimeArray): number => {
49
+ return time[0] * 60 + time[1]
105
50
  }
106
51
 
107
- function toStr (time: string): string {
108
- const [hour, minute]: any = formatStrToInt(time)
109
- const newHour = toSingleStr(hour)
110
- const newMinute = toSingleStr(minute)
111
- return '' + newHour + newMinute
52
+ const calibrateTime = (
53
+ time: string | TimeArray,
54
+ start: string | TimeArray = [0, 0],
55
+ end: string | TimeArray = [23, 59]
56
+ ): TimeArray => {
57
+ time = typeof time === 'string' ? time2Array(time) : time
58
+ start = typeof start === 'string' ? time2Array(start) : start
59
+ end = typeof end === 'string' ? time2Array(end) : end
60
+ const current = time2Minutes(time)
61
+ if (current < time2Minutes(start)) {
62
+ return start
63
+ } else if (current > time2Minutes(end)) {
64
+ return end
65
+ } else {
66
+ return time
67
+ }
112
68
  }
113
69
 
114
- function checkSelectedIsValid (strStart: string, strEnd: string, selected: number[]): boolean {
115
- const strSel = '' + toSingleStr(selected[0]) + toSingleStr(selected[1])
116
- if (strSel < strStart || strSel > strEnd) return false
117
- return true
118
- }
119
- /**
120
- * [{label:'', value: '', key: '', children: []}]
121
- label: string | ReactNode
122
- value: string | number
123
- key?: string | number
124
- children?: PickerColumnItem[]
125
- */
126
- // start="02:10" end = 23:01
70
+ const hoursRange = Array.from({ length: 24 }, (_, i) => i.toString().padStart(2, '0'))
71
+ const minutesRange = Array.from({ length: 60 }, (_, i) => i.toString().padStart(2, '0'))
127
72
 
128
- const _TimePicker = forwardRef<HandlerRef<View, TimeProps>, TimeProps>((props: TimeProps, ref): React.JSX.Element => {
129
- const { children, start, end, value, bindchange, bindcancel, style } = props
130
- const defaultProps = {
131
- start: '00:10',
132
- end: '23:59'
133
- }
134
- const defaultValue = formatStrToInt(value)
135
- const [timevalue, setTimeValue] = useState(defaultValue)
136
- // 存储layout布局信息
137
- const layoutRef = useRef({})
138
- const viewRef = useRef<View>(null)
139
- const nodeRef = useRef<View>(null)
140
- useNodesRef<View, TimeProps>(props, ref, nodeRef, { style })
141
- // 存储modal的布局信息
142
- const modalLayoutRef = useRef({})
143
- const modalRef = useRef<View>(null)
144
- const [visible, setVisible] = useState(false)
145
- const columnData = generateColumns()
146
- const [data, setData] = useState(columnData)
147
- const [offsetTop, setOffsetTop] = useState(0)
148
- const strStart = toStr(start)
149
- const strEnd = toStr(end)
73
+ const PickerTime = forwardRef<
74
+ HandlerRef<View, TimeProps>,
75
+ TimeProps
76
+ >((props: TimeProps, ref): React.JSX.Element => {
77
+ const { value = '00:00', start = '00:00', end = '23:59', bindchange } = props
150
78
 
151
- useEffect(() => {
152
- const newColumnData = generateColumns()
153
- setData(newColumnData)
154
- }, [start, end])
79
+ const nodeRef = useRef(null)
80
+ const timerRef = useRef<NodeJS.Timeout | null>(null)
81
+ const startArray = time2Array(start)
82
+ const endArray = time2Array(end, [23, 59])
83
+ const [formatValue, setFormatValue] = useState<TimeArray>(calibrateTime(value, startArray, endArray))
155
84
 
156
- useEffect(() => {
157
- if (value) {
158
- const nValue = formatStrToInt(value)
159
- nValue && setTimeValue(nValue)
160
- }
161
- }, [value])
162
-
163
- // console.log('---------------visible---', visible, JSON.stringify(columnData))
164
- const handleModalStatus = (status: boolean) => {
165
- setVisible(status)
85
+ const updateValue = (value = '00:00') => {
86
+ const calibratedValue = calibrateTime(value, startArray, endArray)
87
+ setFormatValue(calibratedValue)
166
88
  }
167
- const handleConfirm = () => {
168
- handleModalStatus(false)
169
- bindchange && bindchange({
170
- detail: {
171
- value: formatStr(timevalue)
89
+
90
+ const _props = useRef(props)
91
+ _props.current = props
92
+ useImperativeHandle(ref, () => ({
93
+ updateValue,
94
+ getNodeInstance: () => ({
95
+ props: _props,
96
+ nodeRef,
97
+ instance: {
98
+ style: {}
172
99
  }
173
100
  })
174
- }
101
+ }))
175
102
 
176
- const handleCancel = () => {
177
- handleModalStatus(false)
178
- bindcancel && bindcancel()
179
- }
180
-
181
- const handleChildClick = () => {
182
- handleModalStatus(true)
183
- }
184
-
185
- const handlePickChange = (date: number[]): void => {
186
- // 不是有效的值
187
- if (!checkSelectedIsValid(strStart, strEnd, date)) {
188
- setTimeValue(timevalue)
189
- } else {
190
- // [9, 13]
191
- setTimeValue(date)
103
+ useEffect(() => {
104
+ return () => {
105
+ timerRef.current && clearTimeout(timerRef.current)
192
106
  }
193
- }
107
+ }, [])
194
108
 
195
- const onElementLayout = () => {
196
- viewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
197
- layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
198
- props.getInnerLayout && props.getInnerLayout(layoutRef)
199
- })
200
- }
109
+ useUpdateEffect(() => {
110
+ const calibratedValue = calibrateTime(value, startArray, endArray)
111
+ setFormatValue(calibratedValue)
112
+ }, [value])
201
113
 
202
- const onModalLayout = () => {
203
- modalRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
204
- modalLayoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
205
- setOffsetTop(offsetTop)
206
- })
207
- }
114
+ const onChange = (e: { detail: { value: TimeArray } }) => {
115
+ const { value } = e.detail
116
+ const calibratedValue = calibrateTime(value, startArray, endArray)
117
+ bindchange?.({ detail: { value: time2String(calibratedValue) } })
208
118
 
209
- const renderModalChildren = () => {
210
- const pickerProps = {
211
- ref: nodeRef,
212
- data,
213
- value: timevalue,
214
- defaultValue: timevalue,
215
- cols: 2,
216
- onChange: handlePickChange
119
+ if (value[0] !== formatValue[0] || value[1] !== formatValue[1]) {
120
+ setFormatValue(value)
217
121
  }
218
- return (
219
- <View style={styles.centeredView} ref={modalRef} onLayout={onModalLayout}>
220
- <View style={styles.btnLine}>
221
- <View style={styles.cancel}>
222
- <TouchableWithoutFeedback onPress={handleCancel}>
223
- <Text style={styles.btntext}>取消</Text>
224
- </TouchableWithoutFeedback>
225
- </View>
226
- <View style={styles.ok}>
227
- <TouchableWithoutFeedback onPress={handleConfirm}>
228
- <Text style={styles.btntext}>确定</Text>
229
- </TouchableWithoutFeedback>
230
- </View>
231
- </View>
232
- <PickerView {...pickerProps}></PickerView>
233
- </View>
234
- )
235
- }
236
-
237
- const renderChildren = () => {
238
- const touchProps = {
239
- onLayout: onElementLayout,
240
- ref: viewRef
122
+ if (value[0] !== calibratedValue[0] || value[1] !== calibratedValue[1]) {
123
+ timerRef.current && clearTimeout(timerRef.current)
124
+ timerRef.current = setTimeout(() => setFormatValue(calibratedValue))
241
125
  }
242
- return <View>
243
- <TouchableWithoutFeedback onPress={handleChildClick}>
244
- <View {...touchProps}>{children}</View>
245
- </TouchableWithoutFeedback>
246
- </View>
247
126
  }
248
127
 
249
- // Animated.View
250
- return (<>
251
- <Portal>
252
- <View style={visible ? styles.showModal : styles.hideModal}>
253
- <Modal
254
- animationType="slide"
255
- transparent={true}
256
- visible={visible}
257
- >
258
- {renderModalChildren()}
259
- </Modal>
260
- </View>
261
- </Portal>
262
- {renderChildren()}
263
- </>)
128
+ return (
129
+ <MpxPickerView
130
+ style={styles.pickerContainer}
131
+ indicator-style={styles.pickerIndicator}
132
+ value={formatValue}
133
+ bindchange={onChange}
134
+ >
135
+ {/* @ts-expect-error ignore */}
136
+ <MpxPickerViewColumn key='hour'>
137
+ {hoursRange.map((item, index) => (
138
+ <Text key={index} style={styles.pickerItem}>{item}</Text>
139
+ ))}
140
+ </MpxPickerViewColumn>
141
+ {/* @ts-expect-error ignore */}
142
+ <MpxPickerViewColumn key='minute'>
143
+ {minutesRange.map((item, index) => (
144
+ <Text key={index} style={styles.pickerItem}>{item}</Text>
145
+ ))}
146
+ </MpxPickerViewColumn>
147
+ </MpxPickerView>)
264
148
  })
265
149
 
266
- _TimePicker.displayName = 'mpx-picker-time'
267
-
268
- export default _TimePicker
150
+ PickerTime.displayName = 'MpxPickerTime'
151
+ export default PickerTime
@@ -1,112 +1,126 @@
1
- import { ReactNode } from 'react'
2
- import { PickerValue } from '@ant-design/react-native'
1
+ import React from 'react'
3
2
 
3
+ export const enum PickerMode {
4
+ SELECTOR = 'selector',
5
+ MULTI_SELECTOR = 'multiSelector',
6
+ TIME = 'time',
7
+ DATE = 'date',
8
+ REGION = 'region',
9
+ }
10
+
11
+ export type PickerValue = number
4
12
  export type Obj = Record<string, any>
5
- export type SelectorProps = {
6
- mode: string
7
- // 表示选择了 range 中的第几个(下标从 0 开始)
8
- value: PickerValue
13
+ export type RangeItem = Obj | number | string
14
+ export type TimeValue = `${number}-${number}-${number}` | ''
15
+
16
+ /** 通用属性 */
17
+ export interface BasePickerProps {
18
+ /** --- 小程序属性 --- */
19
+ /** 选择器类型, 默认值 selector */
20
+ mode?: PickerMode
21
+ /** 是否禁用, 默认值 false */
9
22
  disabled?: boolean
10
- children: ReactNode
23
+ /** 点击取消按钮时触发 */
11
24
  bindcancel?: Function
12
- bindchange: Function
13
- // mode 为 selector 或 multiSelector 时,range 有效
14
- range: Array<number|string|Obj>
15
- // range 是一个 Object Array 时,通过 range-key 来指定 Object 中 key 的值作为选择器《显示内容》 对象中的属性
16
- 'range-key': string
17
- getInnerLayout: Function
25
+ /** 头部标题 */
26
+ 'header-text'?: string
27
+ /** --- 内部组件属性 --- */
28
+ /** 作为表单组件时的名称 */
29
+ name?: string
18
30
  style?: Record<string, any>
19
- // bindcolumnchange?: Function
31
+ children?: React.ReactNode
32
+ range?: RangeItem[]
33
+ ref?: any
20
34
  }
21
35
 
22
- export type MultiSelectorProps = {
23
- mode: string
24
- // 表示选择了 range 中的第几个(下标从 0 开始)
25
- value: Array<number>
26
- disabled?: boolean
27
- children: ReactNode
28
- bindcancel?: Function
29
- bindchange: Function
36
+ export interface SelectorProps extends BasePickerProps {
37
+ mode: PickerMode.SELECTOR
38
+ /** 默认值 0 */
39
+ value?: number
40
+ /** 默认值 [] */
41
+ range?: RangeItem[]
42
+ 'range-key'?: string
43
+ /** 点击确认按钮后触发 change 事件, event.detail = {value} */
44
+ bindchange?: Function
45
+ }
46
+
47
+ export interface MultiSelectorProps extends BasePickerProps {
48
+ mode: PickerMode.MULTI_SELECTOR
49
+ /** 默认值 [] */
50
+ value?: number[]
51
+ range?: RangeItem[]
52
+ 'range-key'?: string
53
+ bindchange?: Function
30
54
  bindcolumnchange?: Function
31
- // mode 为 selector 或 multiSelector 时,range 有效
32
- range: Array<Array<any>>
33
- // 当 range 是一个 Object Array 时,通过 range-key 来指定 Object 中 key 的值作为选择器《显示内容》 对象中的属性
34
- 'range-key': string
35
- getInnerLayout: Function
36
- style?: Record<string, any>
37
55
  }
38
56
 
39
- export type TimeProps = {
40
- mode: string
41
- // 表示选择了 range 中的第几个(下标从 0 开始)
42
- value: string
43
- disabled?: boolean
44
- children: ReactNode
45
- bindcancel?: Function
46
- bindchange: Function
47
- start: string
48
- end: string
49
- getInnerLayout: Function
50
- style?: Record<string, any>
57
+ export interface TimeProps extends BasePickerProps {
58
+ mode: PickerMode.TIME
59
+ /** 表示选中的时间,格式为"hh:mm" */
60
+ value?: string
61
+ start?: string
62
+ end?: string
63
+ bindchange?: Function
51
64
  }
52
65
 
53
- export type DateProps = {
54
- mode: string
55
- // 表示选择了 range 中的第几个(下标从 0 开始)
56
- value: string
66
+ export interface DateProps extends BasePickerProps {
67
+ mode: PickerMode.DATE
68
+ /** 默认值 '' */
69
+ value?: TimeValue
70
+ start?: TimeValue
71
+ end?: TimeValue
72
+ /** 有效值 year,month,day,表示选择器的粒度 */
57
73
  fields?: 'day' | 'month' | 'year'
58
- disabled?: boolean
59
- children: ReactNode
60
- bindcancel?: Function
61
- bindchange: Function
62
- start: string
63
- end: string
64
- getInnerLayout: Function
65
- style?: Record<string, any>
74
+ bindchange?: Function
66
75
  }
67
76
 
68
- export type RegionProps = {
69
- mode: string
70
- // 表示选择了 range 中的第几个(下标从 0 开始)
71
- value: Array<string>
72
- level: 'province' | 'city' | 'region' | 'sub-district'
77
+ export interface RegionProps extends BasePickerProps {
78
+ mode: PickerMode.REGION
79
+ /** 表示选中的省市区,默认选中每一列的第一个值, 默认值 [] */
80
+ value?: string[]
81
+ /** 默认值 region */
82
+ level?: 'province' | 'city' | 'region' | 'sub-district'
83
+ /** 可为每一列的顶部添加一个自定义的项 */
73
84
  'custom-item'?: string
74
- disabled?: boolean
75
- children: ReactNode
76
- bindcancel?: Function
77
- bindchange: Function
78
- getInnerLayout: Function
79
- style?: Record<string, any>
85
+ /** value 改变时触发 change 事件, event.detail = {value, code, postcode},
86
+ * 其中字段 code 是统计用区划代码, postcode 是邮政编码 */
87
+ bindchange?: Function
80
88
  }
81
89
 
82
- export type RegionObj = {
90
+ export interface RegionObj {
83
91
  value: string
84
92
  code: string
85
93
  postcode?: string
86
94
  children?: RegionObj[]
87
95
  }
88
96
 
89
- export type PickerData = {
97
+ export interface PickerData {
90
98
  value: string
91
99
  label: string
92
- children?: Array<Object>
100
+ children?: Object[]
93
101
  }
94
102
 
95
- export type EventType = {
103
+ export interface EventType {
96
104
  detail: {
97
105
  value: PickerValue[]
98
106
  }
99
107
  }
100
108
 
101
- export type LayoutType = {
109
+ export interface LayoutType {
102
110
  nativeEvent: {
103
111
  layout: Obj
104
112
  }
105
113
  }
106
114
 
107
- type FormType = {
115
+ export interface FormType {
108
116
  name: string
109
117
  }
110
118
 
111
- export type PickerProps = SelectorProps & MultiSelectorProps & TimeProps & DateProps & RegionProps & FormType
112
- export type ValueType = string | number | Array<number> | Array<string>
119
+ export type PickerProps =
120
+ | SelectorProps
121
+ | MultiSelectorProps
122
+ | TimeProps
123
+ | DateProps
124
+ | RegionProps
125
+
126
+ export type LanguageCode = 'zh-CN' | 'en-US'
@@ -1,7 +1,7 @@
1
1
  import { View } from 'react-native'
2
2
  import React, { forwardRef, useRef } from 'react'
3
- import useInnerProps, { getCustomEvent } from './getInnerListeners'
4
- import useNodesRef, { HandlerRef } from './useNodesRef'
3
+ import useInnerProps, { getCustomEvent } from '../getInnerListeners'
4
+ import useNodesRef, { HandlerRef } from '../useNodesRef'
5
5
  import {
6
6
  useLayout,
7
7
  splitProps,
@@ -9,9 +9,9 @@ import {
9
9
  wrapChildren,
10
10
  useTransformStyle,
11
11
  extendObject
12
- } from './utils'
12
+ } from '../utils'
13
13
  import { PickerViewStyleContext } from './pickerVIewContext'
14
- import type { AnyFunc } from './types/common'
14
+ import type { AnyFunc } from '../types/common'
15
15
  /**
16
16
  * ✔ value
17
17
  * ✔ bindchange
@@ -29,14 +29,14 @@ interface PickerViewProps {
29
29
  children: React.ReactNode
30
30
  value?: Array<number>
31
31
  bindchange?: AnyFunc
32
- style: {
32
+ style?: {
33
33
  [key: string]: any
34
34
  }
35
35
  'indicator-style'?: Record<string, any>,
36
36
  'mask-style'?: Record<string, any>,
37
- 'enable-var': boolean
37
+ 'enable-var'?: boolean
38
38
  'external-var-context'?: Record<string, any>,
39
- 'enable-offset': boolean
39
+ 'enable-offset'?: boolean
40
40
  }
41
41
 
42
42
  interface PickerLayout {