@mpxjs/webpack-plugin 2.9.59 → 2.9.62
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/platform/style/wx/index.js +314 -254
- package/lib/platform/template/wx/component-config/checkbox-group.js +8 -0
- package/lib/platform/template/wx/component-config/checkbox.js +8 -0
- package/lib/platform/template/wx/component-config/cover-image.js +15 -0
- package/lib/platform/template/wx/component-config/cover-view.js +9 -0
- package/lib/platform/template/wx/component-config/form.js +13 -1
- package/lib/platform/template/wx/component-config/icon.js +8 -0
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/label.js +15 -0
- package/lib/platform/template/wx/component-config/movable-area.js +18 -1
- package/lib/platform/template/wx/component-config/movable-view.js +18 -1
- package/lib/platform/template/wx/component-config/navigator.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +8 -0
- package/lib/platform/template/wx/component-config/picker-view.js +18 -2
- package/lib/platform/template/wx/component-config/picker.js +14 -1
- package/lib/platform/template/wx/component-config/radio-group.js +8 -0
- package/lib/platform/template/wx/component-config/radio.js +8 -0
- package/lib/platform/template/wx/component-config/root-portal.js +15 -0
- package/lib/platform/template/wx/component-config/switch.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -3
- package/lib/react/processScript.js +2 -0
- package/lib/runtime/components/react/context.ts +38 -0
- package/lib/runtime/components/react/dist/context.js +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +22 -11
- package/lib/runtime/components/react/dist/mpx-button.jsx +67 -45
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +81 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +152 -0
- package/lib/runtime/components/react/dist/mpx-form.jsx +59 -0
- package/lib/runtime/components/react/dist/mpx-icon.jsx +51 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +17 -22
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +38 -16
- package/lib/runtime/components/react/dist/mpx-label.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +46 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +346 -0
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +35 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +69 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +138 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +139 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +90 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.js +6099 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +244 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +15 -0
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +68 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +79 -0
- package/lib/runtime/components/react/dist/mpx-radio.jsx +169 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +66 -50
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +206 -147
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +9 -7
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-switch.jsx +76 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +7 -19
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +326 -96
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +9 -15
- package/lib/runtime/components/react/dist/types/common.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +3 -8
- package/lib/runtime/components/react/dist/utils.js +82 -14
- package/lib/runtime/components/react/getInnerListeners.ts +25 -13
- package/lib/runtime/components/react/mpx-button.tsx +87 -67
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +147 -0
- package/lib/runtime/components/react/mpx-checkbox.tsx +245 -0
- package/lib/runtime/components/react/mpx-form.tsx +89 -0
- package/lib/runtime/components/react/mpx-icon.tsx +103 -0
- package/lib/runtime/components/react/mpx-image/index.tsx +20 -32
- package/lib/runtime/components/react/mpx-image/svg.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +54 -26
- package/lib/runtime/components/react/mpx-label.tsx +115 -0
- package/lib/runtime/components/react/mpx-movable-area.tsx +67 -0
- package/lib/runtime/components/react/mpx-movable-view.tsx +425 -0
- package/lib/runtime/components/react/mpx-navigator.tsx +67 -0
- package/lib/runtime/components/react/mpx-picker/date.tsx +83 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +153 -0
- package/lib/runtime/components/react/mpx-picker/region.tsx +104 -0
- package/lib/runtime/components/react/mpx-picker/regionData.ts +6101 -0
- package/lib/runtime/components/react/mpx-picker/selector.tsx +92 -0
- package/lib/runtime/components/react/mpx-picker/time.tsx +274 -0
- package/lib/runtime/components/react/mpx-picker/type.ts +107 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +28 -0
- package/lib/runtime/components/react/mpx-picker-view.tsx +104 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +147 -0
- package/lib/runtime/components/react/mpx-radio.tsx +246 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +25 -0
- package/lib/runtime/components/react/mpx-scroll-view.tsx +82 -58
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +203 -156
- package/lib/runtime/components/react/mpx-swiper/index.tsx +12 -13
- package/lib/runtime/components/react/mpx-swiper/type.ts +11 -4
- package/lib/runtime/components/react/mpx-swiper-item.tsx +5 -3
- package/lib/runtime/components/react/mpx-switch.tsx +127 -0
- package/lib/runtime/components/react/mpx-text.tsx +52 -68
- package/lib/runtime/components/react/mpx-textarea.tsx +2 -2
- package/lib/runtime/components/react/mpx-view.tsx +373 -140
- package/lib/runtime/components/react/mpx-web-view.tsx +24 -28
- package/lib/runtime/components/react/types/common.ts +12 -0
- package/lib/runtime/components/react/types/getInnerListeners.ts +2 -1
- package/lib/runtime/components/react/types/global.d.ts +4 -0
- package/lib/runtime/components/react/useNodesRef.ts +3 -8
- package/lib/runtime/components/react/utils.ts +93 -15
- package/lib/runtime/optionProcessor.js +19 -17
- package/lib/template-compiler/compiler.js +56 -41
- package/lib/template-compiler/gen-node-react.js +7 -7
- package/package.json +6 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ✔ checked
|
|
3
|
+
* ✔ type
|
|
4
|
+
* ✔ disabled
|
|
5
|
+
* ✔ color
|
|
6
|
+
*/
|
|
7
|
+
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
8
|
+
import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react';
|
|
9
|
+
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
10
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
11
|
+
|
|
12
|
+
import CheckBox from './mpx-checkbox'
|
|
13
|
+
import { FormContext, FormFieldValue } from './context'
|
|
14
|
+
|
|
15
|
+
import { throwReactWarning } from './utils'
|
|
16
|
+
|
|
17
|
+
interface _SwitchProps extends SwitchProps {
|
|
18
|
+
style?: ViewStyle
|
|
19
|
+
name?: string
|
|
20
|
+
checked?: boolean
|
|
21
|
+
type: 'switch' | 'checkbox'
|
|
22
|
+
disabled: boolean
|
|
23
|
+
color: string
|
|
24
|
+
'enable-offset'?: boolean
|
|
25
|
+
bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
26
|
+
catchchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((props, ref): JSX.Element => {
|
|
30
|
+
const {
|
|
31
|
+
style = {},
|
|
32
|
+
checked = false,
|
|
33
|
+
type = 'switch',
|
|
34
|
+
disabled = false,
|
|
35
|
+
color = '#04BE02',
|
|
36
|
+
'enable-offset': enableOffset,
|
|
37
|
+
bindchange,
|
|
38
|
+
catchchange,
|
|
39
|
+
} = props
|
|
40
|
+
|
|
41
|
+
const [isChecked, setIsChecked] = useState<boolean>(checked)
|
|
42
|
+
|
|
43
|
+
const layoutRef = useRef({})
|
|
44
|
+
|
|
45
|
+
const changeHandler = bindchange || catchchange
|
|
46
|
+
|
|
47
|
+
let formValuesMap: Map<string, FormFieldValue> | undefined
|
|
48
|
+
|
|
49
|
+
const formContext = useContext(FormContext)
|
|
50
|
+
|
|
51
|
+
if (formContext) {
|
|
52
|
+
formValuesMap = formContext.formValuesMap
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
setIsChecked(checked)
|
|
57
|
+
}, [checked])
|
|
58
|
+
|
|
59
|
+
const { nodeRef } = useNodesRef<Switch, _SwitchProps>(props, ref)
|
|
60
|
+
|
|
61
|
+
const onChange = (evt: NativeSyntheticEvent<TouchEvent> | boolean, { checked }: { checked?: boolean } = {}) => {
|
|
62
|
+
if (type === 'switch') {
|
|
63
|
+
setIsChecked(evt as boolean)
|
|
64
|
+
changeHandler && changeHandler(getCustomEvent('change', {}, { layoutRef, detail: { value: evt } }, props))
|
|
65
|
+
} else {
|
|
66
|
+
setIsChecked(checked as boolean)
|
|
67
|
+
changeHandler && changeHandler(getCustomEvent('change', evt, { layoutRef, detail: { value: checked } }, props))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const resetValue = () => {
|
|
72
|
+
setIsChecked(false)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const getValue = () => {
|
|
76
|
+
return isChecked
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (formValuesMap) {
|
|
80
|
+
if (!props.name) {
|
|
81
|
+
throwReactWarning('[Mpx runtime warn]: If a form component is used, the name attribute is required.')
|
|
82
|
+
} else {
|
|
83
|
+
formValuesMap.set(props.name, { getValue, resetValue })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const onLayout = () => {
|
|
88
|
+
nodeRef.current?.measure?.((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
89
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
const innerProps = useInnerProps(props, {
|
|
93
|
+
ref: nodeRef,
|
|
94
|
+
...enableOffset ? { onLayout } : {},
|
|
95
|
+
...!disabled ? { [type === 'switch' ? 'onValueChange' : '_onChange']: onChange } : {}
|
|
96
|
+
}, [
|
|
97
|
+
'style',
|
|
98
|
+
'checked',
|
|
99
|
+
'disabled',
|
|
100
|
+
'type',
|
|
101
|
+
'color'
|
|
102
|
+
], {
|
|
103
|
+
layoutRef
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
if (type === 'checkbox') {
|
|
107
|
+
return <CheckBox
|
|
108
|
+
{...innerProps}
|
|
109
|
+
color={color}
|
|
110
|
+
style={style}
|
|
111
|
+
checked={isChecked}
|
|
112
|
+
/>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (<Switch
|
|
116
|
+
{...innerProps}
|
|
117
|
+
style={style}
|
|
118
|
+
value={isChecked}
|
|
119
|
+
trackColor={{ false: "#FFF", true: color }}
|
|
120
|
+
thumbColor={isChecked ? "#FFF" : "#f4f3f4"}
|
|
121
|
+
ios_backgroundColor="#FFF"
|
|
122
|
+
/>)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
_Switch.displayName = 'mpx-switch'
|
|
126
|
+
|
|
127
|
+
export default _Switch
|
|
@@ -4,13 +4,11 @@
|
|
|
4
4
|
* ✘ space
|
|
5
5
|
* ✘ decode
|
|
6
6
|
*/
|
|
7
|
-
import { Text, TextStyle, TextProps
|
|
8
|
-
import { useRef, useEffect, forwardRef, ReactNode,
|
|
7
|
+
import { Text, TextStyle, TextProps } from 'react-native'
|
|
8
|
+
import { useRef, useEffect, forwardRef, ReactNode, JSX } from 'react'
|
|
9
9
|
import useInnerProps from './getInnerListeners'
|
|
10
|
-
// @ts-ignore
|
|
11
10
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
12
|
-
import {
|
|
13
|
-
|
|
11
|
+
import { transformTextStyle, DEFAULT_STYLE } from './utils'
|
|
14
12
|
|
|
15
13
|
interface _TextProps extends TextProps {
|
|
16
14
|
style?: TextStyle
|
|
@@ -22,83 +20,69 @@ interface _TextProps extends TextProps {
|
|
|
22
20
|
['disable-default-style']?: boolean
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
const DEFAULT_STYLE = {
|
|
26
|
-
fontSize: 16
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const transformStyle = (styleObj: TextStyle) => {
|
|
30
|
-
let { lineHeight } = styleObj
|
|
31
|
-
if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
|
|
32
|
-
lineHeight = (parseFloat(lineHeight)/100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize)
|
|
33
|
-
styleObj.lineHeight = lineHeight
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
23
|
const _Text = forwardRef<HandlerRef<Text, _TextProps>, _TextProps>((props, ref): JSX.Element => {
|
|
38
24
|
const {
|
|
39
|
-
style =
|
|
25
|
+
style = {},
|
|
40
26
|
children,
|
|
41
27
|
selectable,
|
|
42
28
|
'enable-offset': enableOffset,
|
|
43
29
|
'user-select': userSelect,
|
|
44
30
|
'disable-default-style': disableDefaultStyle = false,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const layoutRef = useRef({})
|
|
31
|
+
} = props
|
|
48
32
|
|
|
49
|
-
|
|
33
|
+
const layoutRef = useRef({})
|
|
50
34
|
|
|
51
|
-
|
|
35
|
+
let defaultStyle = {}
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref, {
|
|
59
|
-
defaultStyle
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const innerProps = useInnerProps(props, {
|
|
63
|
-
ref: nodeRef
|
|
64
|
-
}, [
|
|
65
|
-
'style',
|
|
66
|
-
'children',
|
|
67
|
-
'selectable',
|
|
68
|
-
'user-select',
|
|
69
|
-
'useInherit',
|
|
70
|
-
'enable-offset'
|
|
71
|
-
], {
|
|
72
|
-
layoutRef
|
|
73
|
-
})
|
|
37
|
+
if (!disableDefaultStyle) {
|
|
38
|
+
defaultStyle = DEFAULT_STYLE
|
|
39
|
+
transformTextStyle(style)
|
|
40
|
+
}
|
|
74
41
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
42
|
+
const { nodeRef } = useNodesRef<Text, _TextProps>(props, ref, {
|
|
43
|
+
defaultStyle
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const innerProps = useInnerProps(props, {
|
|
47
|
+
ref: nodeRef
|
|
48
|
+
}, [
|
|
49
|
+
'style',
|
|
50
|
+
'children',
|
|
51
|
+
'selectable',
|
|
52
|
+
'user-select',
|
|
53
|
+
'useInherit',
|
|
54
|
+
'enable-offset'
|
|
55
|
+
], {
|
|
56
|
+
layoutRef
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
let measureTimeout: ReturnType<typeof setTimeout> | null = null
|
|
61
|
+
if (enableOffset) {
|
|
62
|
+
measureTimeout = setTimeout(() => {
|
|
63
|
+
nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
64
|
+
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
82
65
|
})
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
66
|
+
})
|
|
67
|
+
return () => {
|
|
68
|
+
if (measureTimeout) {
|
|
69
|
+
clearTimeout(measureTimeout)
|
|
70
|
+
measureTimeout = null
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
73
|
+
}
|
|
74
|
+
}, [])
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Text
|
|
79
|
+
style={{ ...defaultStyle, ...style }}
|
|
80
|
+
selectable={!!selectable || !!userSelect}
|
|
81
|
+
{...innerProps}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</Text>
|
|
85
|
+
)
|
|
102
86
|
})
|
|
103
87
|
|
|
104
88
|
_Text.displayName = 'mpx-text'
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* ✘ show-confirm-bar
|
|
10
10
|
* ✔ bindlinechange: No `heightRpx` info.
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import { JSX, forwardRef } from 'react'
|
|
13
13
|
import { Keyboard, TextInput } from 'react-native'
|
|
14
14
|
import Input, { InputProps, PrivateInputProps } from './mpx-input'
|
|
15
15
|
import { omit } from './utils'
|
|
@@ -21,7 +21,7 @@ export type TextareProps = Omit<
|
|
|
21
21
|
>
|
|
22
22
|
|
|
23
23
|
const Textarea = forwardRef<HandlerRef<TextInput, TextareProps>, TextareProps>(
|
|
24
|
-
(props, ref):
|
|
24
|
+
(props, ref): JSX.Element => {
|
|
25
25
|
const restProps = omit(props, [
|
|
26
26
|
'ref',
|
|
27
27
|
'type',
|