@mpxjs/webpack-plugin 2.9.62 → 2.9.64
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/index.js +1 -3
- package/lib/platform/style/wx/index.js +67 -53
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +9 -7
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +52 -74
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +28 -41
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -14
- package/lib/runtime/components/react/dist/mpx-icon.jsx +14 -17
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +34 -33
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +35 -31
- package/lib/runtime/components/react/dist/mpx-label.jsx +29 -37
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -18
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -8
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +9 -9
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +11 -7
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +18 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +102 -10
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +147 -53
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +33 -26
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +139 -74
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +14 -6
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +17 -14
- package/lib/runtime/components/react/dist/mpx-text.jsx +19 -35
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +284 -209
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +8 -5
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +18 -8
- package/lib/runtime/components/react/mpx-button.tsx +81 -91
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +48 -43
- package/lib/runtime/components/react/mpx-checkbox.tsx +52 -63
- package/lib/runtime/components/react/mpx-form.tsx +49 -21
- package/lib/runtime/components/react/mpx-icon.tsx +30 -27
- package/lib/runtime/components/react/mpx-image/index.tsx +52 -46
- package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
- package/lib/runtime/components/react/mpx-input.tsx +58 -38
- package/lib/runtime/components/react/mpx-label.tsx +54 -59
- package/lib/runtime/components/react/mpx-movable-area.tsx +38 -24
- package/lib/runtime/components/react/mpx-movable-view.tsx +27 -28
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker/date.tsx +2 -3
- package/lib/runtime/components/react/mpx-picker/index.tsx +10 -10
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +15 -12
- package/lib/runtime/components/react/mpx-picker/region.tsx +21 -18
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -6
- package/lib/runtime/components/react/mpx-picker/time.tsx +25 -29
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +148 -20
- package/lib/runtime/components/react/mpx-picker-view.tsx +179 -63
- package/lib/runtime/components/react/mpx-radio-group.tsx +50 -47
- package/lib/runtime/components/react/mpx-radio.tsx +56 -72
- package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +133 -103
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +174 -96
- package/lib/runtime/components/react/mpx-swiper/index.tsx +18 -9
- package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +46 -13
- package/lib/runtime/components/react/mpx-switch.tsx +44 -23
- package/lib/runtime/components/react/mpx-text.tsx +37 -45
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +388 -240
- package/lib/runtime/components/react/mpx-web-view.tsx +19 -20
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +4 -4
- package/lib/runtime/components/react/types/global.d.ts +14 -2
- package/lib/runtime/components/react/useNodesRef.ts +1 -2
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/template-compiler/compiler.js +28 -20
- package/lib/template-compiler/gen-node-react.js +1 -3
- package/lib/web/processStyles.js +2 -5
- package/package.json +6 -4
- package/lib/runtime/components/react/dist/utils.js +0 -148
- package/lib/runtime/components/react/utils.ts +0 -170
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, isValidElement } from 'react';
|
|
2
|
-
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
3
|
-
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
4
|
-
export const IMAGE_STYLE_REGEX = /^background(Image|Size|Repeat|Position)$/;
|
|
5
|
-
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/;
|
|
6
|
-
export const DEFAULT_STYLE = {
|
|
7
|
-
fontSize: 16
|
|
8
|
-
};
|
|
9
|
-
const URL_REGEX = /url\(["']?(.*?)["']?\)/;
|
|
10
|
-
export function omit(obj, fields) {
|
|
11
|
-
const shallowCopy = Object.assign({}, obj);
|
|
12
|
-
for (let i = 0; i < fields.length; i += 1) {
|
|
13
|
-
const key = fields[i];
|
|
14
|
-
delete shallowCopy[key];
|
|
15
|
-
}
|
|
16
|
-
return shallowCopy;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
|
|
20
|
-
*/
|
|
21
|
-
export const useUpdateEffect = (effect, deps) => {
|
|
22
|
-
const isMounted = useRef(false);
|
|
23
|
-
// for react-refresh
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
return () => {
|
|
26
|
-
isMounted.current = false;
|
|
27
|
-
};
|
|
28
|
-
}, []);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (!isMounted.current) {
|
|
31
|
-
isMounted.current = true;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return effect();
|
|
35
|
-
}
|
|
36
|
-
}, deps);
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* 解析行内样式
|
|
40
|
-
* @param inlineStyle
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
export const parseInlineStyle = (inlineStyle = '') => {
|
|
44
|
-
return inlineStyle.split(';').reduce((styleObj, style) => {
|
|
45
|
-
const [k, v, ...rest] = style.split(':');
|
|
46
|
-
if (rest.length || !v || !k)
|
|
47
|
-
return styleObj;
|
|
48
|
-
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase());
|
|
49
|
-
return Object.assign(styleObj, { [key]: v.trim() });
|
|
50
|
-
}, {});
|
|
51
|
-
};
|
|
52
|
-
export const parseUrl = (cssUrl = '') => {
|
|
53
|
-
if (!cssUrl)
|
|
54
|
-
return;
|
|
55
|
-
const match = cssUrl.match(URL_REGEX);
|
|
56
|
-
return match?.[1];
|
|
57
|
-
};
|
|
58
|
-
export const getRestProps = (transferProps = {}, originProps = {}, deletePropsKey = []) => {
|
|
59
|
-
return {
|
|
60
|
-
...transferProps,
|
|
61
|
-
...omit(originProps, deletePropsKey)
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
export const isText = (ele) => {
|
|
65
|
-
if (isValidElement(ele)) {
|
|
66
|
-
const displayName = ele.type?.displayName;
|
|
67
|
-
return displayName === 'mpx-text' || displayName === 'Text';
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
};
|
|
71
|
-
export const isEmbedded = (ele) => {
|
|
72
|
-
if (isValidElement(ele)) {
|
|
73
|
-
const displayName = ele.type?.displayName;
|
|
74
|
-
return displayName && ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName);
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
};
|
|
78
|
-
export function every(children, callback) {
|
|
79
|
-
const childrenArray = Array.isArray(children) ? children : [children];
|
|
80
|
-
return childrenArray.every((child) => callback(child));
|
|
81
|
-
}
|
|
82
|
-
export function groupBy(obj, callback, group = {}) {
|
|
83
|
-
let groupKey = '';
|
|
84
|
-
for (let key in obj) {
|
|
85
|
-
if (obj.hasOwnProperty(key)) { // 确保处理对象自身的属性
|
|
86
|
-
let val = obj[key];
|
|
87
|
-
groupKey = callback(key, val);
|
|
88
|
-
if (!group[groupKey]) {
|
|
89
|
-
group[groupKey] = {};
|
|
90
|
-
}
|
|
91
|
-
group[groupKey][key] = val;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return group;
|
|
95
|
-
}
|
|
96
|
-
export const normalizeStyle = (style = {}) => {
|
|
97
|
-
const { borderRadius } = style;
|
|
98
|
-
if (borderRadius && PERCENT_REGEX.test(borderRadius)) {
|
|
99
|
-
style.borderTopLeftRadius = borderRadius;
|
|
100
|
-
style.borderBottomLeftRadius = borderRadius;
|
|
101
|
-
style.borderBottomRightRadius = borderRadius;
|
|
102
|
-
style.borderTopRightRadius = borderRadius;
|
|
103
|
-
delete style.borderRadius;
|
|
104
|
-
}
|
|
105
|
-
['backgroundSize', 'backgroundPosition'].forEach(name => {
|
|
106
|
-
if (style[name] && typeof style[name] === 'string') {
|
|
107
|
-
if (style[name].trim()) {
|
|
108
|
-
style[name] = style[name].split(' ');
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return style;
|
|
113
|
-
};
|
|
114
|
-
export function splitStyle(styles) {
|
|
115
|
-
return groupBy(styles, (key) => {
|
|
116
|
-
if (TEXT_STYLE_REGEX.test(key)) {
|
|
117
|
-
return 'textStyle';
|
|
118
|
-
}
|
|
119
|
-
else if (IMAGE_STYLE_REGEX.test(key)) {
|
|
120
|
-
return 'imageStyle';
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return 'innerStyle';
|
|
124
|
-
}
|
|
125
|
-
}, {});
|
|
126
|
-
}
|
|
127
|
-
export function splitProps(props) {
|
|
128
|
-
return groupBy(props, (key) => {
|
|
129
|
-
if (TEXT_PROPS_REGEX.test(key)) {
|
|
130
|
-
return 'textProps';
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
return 'innerProps';
|
|
134
|
-
}
|
|
135
|
-
}, {});
|
|
136
|
-
}
|
|
137
|
-
export const throwReactWarning = (message) => {
|
|
138
|
-
setTimeout(() => {
|
|
139
|
-
console.warn(message);
|
|
140
|
-
}, 0);
|
|
141
|
-
};
|
|
142
|
-
export const transformTextStyle = (styleObj) => {
|
|
143
|
-
let { lineHeight } = styleObj;
|
|
144
|
-
if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
|
|
145
|
-
lineHeight = (parseFloat(lineHeight) / 100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize);
|
|
146
|
-
styleObj.lineHeight = lineHeight;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, ReactNode, FunctionComponent, isValidElement } from 'react'
|
|
2
|
-
import { ExtendedViewStyle } from './types/common'
|
|
3
|
-
import { TextStyle } from 'react-native'
|
|
4
|
-
|
|
5
|
-
type GroupData = Record<string, Record<string, any>>
|
|
6
|
-
|
|
7
|
-
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
|
|
8
|
-
|
|
9
|
-
export const PERCENT_REGEX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
10
|
-
|
|
11
|
-
export const IMAGE_STYLE_REGEX = /^background(Image|Size|Repeat|Position)$/
|
|
12
|
-
|
|
13
|
-
export const TEXT_PROPS_REGEX = /ellipsizeMode|numberOfLines/
|
|
14
|
-
|
|
15
|
-
export const DEFAULT_STYLE = {
|
|
16
|
-
fontSize: 16
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const URL_REGEX = /url\(["']?(.*?)["']?\)/
|
|
20
|
-
|
|
21
|
-
export function omit<T, K extends string>(obj: T, fields: K[]): Omit<T, K> {
|
|
22
|
-
const shallowCopy: any = Object.assign({}, obj)
|
|
23
|
-
for (let i = 0; i < fields.length; i += 1) {
|
|
24
|
-
const key = fields[i]
|
|
25
|
-
delete shallowCopy[key]
|
|
26
|
-
}
|
|
27
|
-
return shallowCopy
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 用法等同于 useEffect,但是会忽略首次执行,只在依赖更新时执行
|
|
32
|
-
*/
|
|
33
|
-
export const useUpdateEffect = (effect: any, deps: any) => {
|
|
34
|
-
const isMounted = useRef(false)
|
|
35
|
-
|
|
36
|
-
// for react-refresh
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
return () => {
|
|
39
|
-
isMounted.current = false
|
|
40
|
-
}
|
|
41
|
-
}, [])
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (!isMounted.current) {
|
|
45
|
-
isMounted.current = true
|
|
46
|
-
} else {
|
|
47
|
-
return effect()
|
|
48
|
-
}
|
|
49
|
-
}, deps)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 解析行内样式
|
|
54
|
-
* @param inlineStyle
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
|
|
58
|
-
return inlineStyle.split(';').reduce((styleObj, style) => {
|
|
59
|
-
const [k, v, ...rest] = style.split(':')
|
|
60
|
-
if (rest.length || !v || !k) return styleObj
|
|
61
|
-
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
|
|
62
|
-
return Object.assign(styleObj, { [key]: v.trim() })
|
|
63
|
-
}, {})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const parseUrl = (cssUrl: string = '') => {
|
|
67
|
-
if (!cssUrl) return
|
|
68
|
-
|
|
69
|
-
const match = cssUrl.match(URL_REGEX)
|
|
70
|
-
|
|
71
|
-
return match?.[1]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const getRestProps = (transferProps: any = {}, originProps: any = {}, deletePropsKey: any = []) => {
|
|
75
|
-
return {
|
|
76
|
-
...transferProps,
|
|
77
|
-
...omit(originProps, deletePropsKey)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const isText = (ele: ReactNode) => {
|
|
82
|
-
if (isValidElement(ele)) {
|
|
83
|
-
const displayName = (ele.type as FunctionComponent)?.displayName
|
|
84
|
-
return displayName === 'mpx-text' || displayName === 'Text'
|
|
85
|
-
}
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const isEmbedded = (ele: ReactNode) => {
|
|
90
|
-
if (isValidElement(ele)) {
|
|
91
|
-
const displayName = (ele.type as FunctionComponent)?.displayName
|
|
92
|
-
return displayName && ['mpx-checkbox', 'mpx-radio', 'mpx-switch'].includes(displayName)
|
|
93
|
-
}
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function every(children: ReactNode, callback: (children: ReactNode) => boolean ) {
|
|
98
|
-
const childrenArray = Array.isArray(children) ? children : [children];
|
|
99
|
-
return childrenArray.every((child) => callback(child as ReactNode))
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function groupBy(obj: Record<string, any>, callback: (key: string, val: string) => string, group:GroupData = {}):GroupData {
|
|
103
|
-
let groupKey = ''
|
|
104
|
-
for (let key in obj) {
|
|
105
|
-
if (obj.hasOwnProperty(key)) { // 确保处理对象自身的属性
|
|
106
|
-
let val: string = obj[key] as string
|
|
107
|
-
groupKey = callback(key, val)
|
|
108
|
-
if (!group[groupKey]) {
|
|
109
|
-
group[groupKey] = {}
|
|
110
|
-
}
|
|
111
|
-
group[groupKey][key] = val
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return group
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const normalizeStyle = (style: ExtendedViewStyle = {}) => {
|
|
118
|
-
const { borderRadius } = style
|
|
119
|
-
if (borderRadius && PERCENT_REGEX.test(borderRadius as string)) {
|
|
120
|
-
style.borderTopLeftRadius = borderRadius
|
|
121
|
-
style.borderBottomLeftRadius = borderRadius
|
|
122
|
-
style.borderBottomRightRadius = borderRadius
|
|
123
|
-
style.borderTopRightRadius = borderRadius
|
|
124
|
-
delete style.borderRadius
|
|
125
|
-
}
|
|
126
|
-
['backgroundSize', 'backgroundPosition'].forEach(name => {
|
|
127
|
-
if (style[name] && typeof style[name] === 'string') {
|
|
128
|
-
if (style[name].trim()) {
|
|
129
|
-
style[name] = style[name].split(' ')
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
return style
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function splitStyle<T extends Record<string, any>>(styles: T) {
|
|
137
|
-
return groupBy(styles, (key) => {
|
|
138
|
-
if (TEXT_STYLE_REGEX.test(key)) {
|
|
139
|
-
return 'textStyle'
|
|
140
|
-
} else if (IMAGE_STYLE_REGEX.test(key)) {
|
|
141
|
-
return 'imageStyle'
|
|
142
|
-
} else {
|
|
143
|
-
return 'innerStyle'
|
|
144
|
-
}
|
|
145
|
-
}, {})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function splitProps<T extends Record<string, any>>(props: T) {
|
|
149
|
-
return groupBy(props, (key) => {
|
|
150
|
-
if (TEXT_PROPS_REGEX.test(key)) {
|
|
151
|
-
return 'textProps'
|
|
152
|
-
} else {
|
|
153
|
-
return 'innerProps'
|
|
154
|
-
}
|
|
155
|
-
}, {})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export const throwReactWarning = (message: string) => {
|
|
159
|
-
setTimeout(() => {
|
|
160
|
-
console.warn(message)
|
|
161
|
-
}, 0)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export const transformTextStyle = (styleObj: TextStyle) => {
|
|
165
|
-
let { lineHeight } = styleObj
|
|
166
|
-
if (typeof lineHeight === 'string' && PERCENT_REGEX.test(lineHeight)) {
|
|
167
|
-
lineHeight = (parseFloat(lineHeight) / 100) * (styleObj.fontSize || DEFAULT_STYLE.fontSize)
|
|
168
|
-
styleObj.lineHeight = lineHeight
|
|
169
|
-
}
|
|
170
|
-
}
|