@mpxjs/webpack-plugin 2.10.1 → 2.10.3
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/RecordPageConfigsMapDependency.js +45 -0
- package/lib/index.js +23 -1
- package/lib/platform/style/wx/index.js +6 -4
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/view.js +12 -2
- package/lib/react/index.js +0 -1
- package/lib/react/processJSON.js +13 -2
- package/lib/react/processScript.js +7 -4
- package/lib/react/processTemplate.js +18 -3
- package/lib/react/script-helper.js +18 -4
- package/lib/runtime/components/react/context.ts +3 -4
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -54
- package/lib/runtime/components/react/dist/{KeyboardAvoidingView.jsx → mpx-keyboard-avoiding-view.jsx} +23 -12
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +1 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +16 -8
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +22 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +6 -6
- package/lib/runtime/components/react/dist/mpx-view.jsx +10 -5
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +6 -5
- package/lib/runtime/components/react/dist/useAnimationHooks.js +46 -48
- package/lib/runtime/components/react/dist/utils.jsx +17 -21
- package/lib/runtime/components/react/mpx-image.tsx +2 -2
- package/lib/runtime/components/react/mpx-input.tsx +66 -72
- package/lib/runtime/components/react/{KeyboardAvoidingView.tsx → mpx-keyboard-avoiding-view.tsx} +32 -18
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +1 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +21 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +32 -0
- package/lib/runtime/components/react/mpx-textarea.tsx +10 -6
- package/lib/runtime/components/react/mpx-view.tsx +17 -10
- package/lib/runtime/components/react/mpx-web-view.tsx +12 -10
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +1 -1
- package/lib/runtime/components/react/useAnimationHooks.ts +46 -48
- package/lib/runtime/components/react/utils.tsx +21 -24
- package/lib/runtime/optionProcessor.js +3 -2
- package/lib/style-compiler/index.js +8 -6
- package/lib/template-compiler/compiler.js +22 -14
- package/lib/utils/match-condition.js +14 -8
- package/lib/web/processJSON.js +1 -3
- package/package.json +4 -4
|
@@ -89,7 +89,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
89
89
|
button: 'Reload'
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
const currentErrorText = errorText[(mpx.i18n
|
|
92
|
+
const currentErrorText = errorText[(mpx.i18n?.locale as LanguageCode) || 'zh-CN']
|
|
93
93
|
|
|
94
94
|
if (props.style) {
|
|
95
95
|
warn('The web-view component does not support the style prop.')
|
|
@@ -103,11 +103,11 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
103
103
|
const statusCode = useRef<string|number>('')
|
|
104
104
|
const [isLoaded, setIsLoaded] = useState<boolean>(true)
|
|
105
105
|
const defaultWebViewStyle = {
|
|
106
|
-
position: 'absolute' as
|
|
107
|
-
left: 0
|
|
108
|
-
right: 0
|
|
109
|
-
top: 0
|
|
110
|
-
bottom: 0
|
|
106
|
+
position: 'absolute' as const,
|
|
107
|
+
left: 0,
|
|
108
|
+
right: 0,
|
|
109
|
+
top: 0,
|
|
110
|
+
bottom: 0
|
|
111
111
|
}
|
|
112
112
|
const canGoBack = useRef<boolean>(false)
|
|
113
113
|
const isNavigateBack = useRef<boolean>(false)
|
|
@@ -207,8 +207,8 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
207
207
|
switch (type) {
|
|
208
208
|
case 'setTitle':
|
|
209
209
|
{ // case下不允许直接声明,包个块解决该问题
|
|
210
|
-
const title = postData._documentTitle
|
|
211
|
-
if (title) {
|
|
210
|
+
const title = postData._documentTitle?.trim()
|
|
211
|
+
if (title !== undefined) {
|
|
212
212
|
navigation && navigation.setOptions({ title })
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -303,6 +303,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
303
303
|
}
|
|
304
304
|
const onLoadEnd = function (res: WebViewEvent) {
|
|
305
305
|
if (__mpx_mode__ === 'android') {
|
|
306
|
+
res.persist()
|
|
306
307
|
setTimeout(() => {
|
|
307
308
|
onLoadEndHandle(res)
|
|
308
309
|
}, 0)
|
|
@@ -328,7 +329,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
328
329
|
}
|
|
329
330
|
|
|
330
331
|
return (
|
|
331
|
-
<Portal
|
|
332
|
+
<Portal>
|
|
332
333
|
{pageLoadErr
|
|
333
334
|
? (
|
|
334
335
|
<View style={[styles.loadErrorContext, defaultWebViewStyle]}>
|
|
@@ -338,6 +339,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
338
339
|
)
|
|
339
340
|
: (<WebView
|
|
340
341
|
style={ defaultWebViewStyle }
|
|
342
|
+
pointerEvents={ isLoaded ? 'auto' : 'none' }
|
|
341
343
|
source={{ uri: src }}
|
|
342
344
|
ref={webViewRef}
|
|
343
345
|
javaScriptEnabled={true}
|
|
@@ -349,7 +351,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
349
351
|
onHttpError={onHttpError}
|
|
350
352
|
onError={onError}
|
|
351
353
|
onLoadStart={onLoadStart}
|
|
352
|
-
allowsBackForwardNavigationGestures={
|
|
354
|
+
allowsBackForwardNavigationGestures={true}
|
|
353
355
|
></WebView>)}
|
|
354
356
|
</Portal>
|
|
355
357
|
)
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
WithTimingConfig,
|
|
14
14
|
AnimationCallback
|
|
15
15
|
} from 'react-native-reanimated'
|
|
16
|
-
import { error } from '@mpxjs/utils'
|
|
16
|
+
import { error, hasOwn } from '@mpxjs/utils'
|
|
17
17
|
import { ExtendedViewStyle } from './types/common'
|
|
18
18
|
import type { _ViewProps } from './mpx-view'
|
|
19
19
|
|
|
@@ -50,20 +50,20 @@ const EasingKey = {
|
|
|
50
50
|
const TransformInitial: ExtendedViewStyle = {
|
|
51
51
|
// matrix: 0,
|
|
52
52
|
// matrix3d: 0,
|
|
53
|
-
rotate: '0deg',
|
|
53
|
+
// rotate: '0deg',
|
|
54
54
|
rotateX: '0deg',
|
|
55
55
|
rotateY: '0deg',
|
|
56
56
|
rotateZ: '0deg',
|
|
57
57
|
// rotate3d:[0,0,0]
|
|
58
|
-
scale: 1,
|
|
58
|
+
// scale: 1,
|
|
59
59
|
// scale3d: [1, 1, 1],
|
|
60
60
|
scaleX: 1,
|
|
61
61
|
scaleY: 1,
|
|
62
62
|
// scaleZ: 1,
|
|
63
|
-
skew: 0,
|
|
63
|
+
// skew: 0,
|
|
64
64
|
skewX: '0deg',
|
|
65
65
|
skewY: '0deg',
|
|
66
|
-
translate: 0,
|
|
66
|
+
// translate: 0,
|
|
67
67
|
// translate3d: 0,
|
|
68
68
|
translateX: 0,
|
|
69
69
|
translateY: 0
|
|
@@ -127,23 +127,23 @@ const parseTransform = (transformStr: string) => {
|
|
|
127
127
|
case 'skewX':
|
|
128
128
|
case 'skewY':
|
|
129
129
|
case 'perspective':
|
|
130
|
+
// rotate 处理成 rotateZ
|
|
131
|
+
key = key === 'rotate' ? 'rotateZ' : key
|
|
130
132
|
// 单个值处理
|
|
131
133
|
transform.push({ [key]: global.__formatValue(val) })
|
|
132
134
|
break
|
|
133
135
|
case 'matrix':
|
|
134
|
-
case 'matrix3d':
|
|
135
136
|
transform.push({ [key]: parseValues(val, ',').map(val => +val) })
|
|
136
137
|
break
|
|
137
138
|
case 'translate':
|
|
138
139
|
case 'scale':
|
|
139
140
|
case 'skew':
|
|
140
|
-
case 'rotate3d': // x y z angle
|
|
141
141
|
case 'translate3d': // x y 支持 z不支持
|
|
142
142
|
case 'scale3d': // x y 支持 z不支持
|
|
143
143
|
{
|
|
144
144
|
// 2 个以上的值处理
|
|
145
145
|
key = key.replace('3d', '')
|
|
146
|
-
const vals = parseValues(val, ',').splice(0,
|
|
146
|
+
const vals = parseValues(val, ',').splice(0, 3)
|
|
147
147
|
// scale(.5) === scaleX(.5) scaleY(.5)
|
|
148
148
|
if (vals.length === 1 && key === 'scale') {
|
|
149
149
|
vals.push(vals[0])
|
|
@@ -167,6 +167,14 @@ const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
|
|
|
167
167
|
})
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
// transform 数组转对象
|
|
171
|
+
function getTransformObj (transforms: { [propName: string]: string | number }[]) {
|
|
172
|
+
'worklet'
|
|
173
|
+
return transforms.reduce((transformObj, item) => {
|
|
174
|
+
return Object.assign(transformObj, item)
|
|
175
|
+
}, {} as { [propName: string]: string | number })
|
|
176
|
+
}
|
|
177
|
+
|
|
170
178
|
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean }) {
|
|
171
179
|
const { style = {}, animation, enableAnimation } = props
|
|
172
180
|
|
|
@@ -187,7 +195,9 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
187
195
|
// 记录动画key的style样式值 没有的话设置为false
|
|
188
196
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
189
197
|
const animatedKeys = useRef({} as {[propName: keyof ExtendedViewStyle]: boolean})
|
|
190
|
-
//
|
|
198
|
+
// 记录上次style map
|
|
199
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
200
|
+
const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string})
|
|
191
201
|
// ** 全量 style prop sharedValue
|
|
192
202
|
// 不能做增量的原因:
|
|
193
203
|
// 1 尝试用 useRef,但 useAnimatedStyle 访问后的 ref 不能在增加新的值,被冻结
|
|
@@ -200,6 +210,12 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
200
210
|
return valMap
|
|
201
211
|
}, {} as { [propName: keyof ExtendedViewStyle]: SharedValue<string|number> })
|
|
202
212
|
}, [])
|
|
213
|
+
// ** style更新同步
|
|
214
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
// style 更新后同步更新 lastStyleRef & shareValMap
|
|
217
|
+
updateStyleVal()
|
|
218
|
+
}, [style])
|
|
203
219
|
// ** 获取动画样式prop & 驱动动画
|
|
204
220
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
205
221
|
useEffect(() => {
|
|
@@ -211,16 +227,6 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
211
227
|
// 驱动动画
|
|
212
228
|
createAnimation(keys)
|
|
213
229
|
}, [id])
|
|
214
|
-
// 同步style更新
|
|
215
|
-
// useEffect(() => {
|
|
216
|
-
// Object.keys(animatedKeys.current).forEach(key => {
|
|
217
|
-
// const originVal = getOriginalStyleVal(key, isTransform(key))
|
|
218
|
-
// if (originVal && animatedKeys.current[key] !== originVal) {
|
|
219
|
-
// animatedKeys.current[key] = originVal
|
|
220
|
-
// shareValMap[key].value = originVal
|
|
221
|
-
// }
|
|
222
|
-
// })
|
|
223
|
-
// }, [style])
|
|
224
230
|
// ** 清空动画
|
|
225
231
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
226
232
|
useEffect(() => {
|
|
@@ -230,7 +236,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
230
236
|
})
|
|
231
237
|
}
|
|
232
238
|
}, [])
|
|
233
|
-
// 根据 animation action 创建&驱动动画
|
|
239
|
+
// 根据 animation action 创建&驱动动画
|
|
234
240
|
function createAnimation (animatedKeys: string[] = []) {
|
|
235
241
|
const actions = animation?.actions || []
|
|
236
242
|
const sequence = {} as { [propName: keyof ExtendedViewStyle]: (string|number)[] }
|
|
@@ -286,6 +292,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
286
292
|
: withTiming(value, { duration, easing })
|
|
287
293
|
return delay ? withDelay(delay, animation) : animation
|
|
288
294
|
}
|
|
295
|
+
// 获取样式初始值(prop style or 默认值)
|
|
289
296
|
function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
290
297
|
if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
291
298
|
let initialVal = InitialValue[key]
|
|
@@ -297,38 +304,19 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
297
304
|
}
|
|
298
305
|
return originalStyle[key] === undefined ? InitialValue[key] : originalStyle[key]
|
|
299
306
|
}
|
|
300
|
-
// 从 prop style 中获取样式初始值 没有为undefined
|
|
301
|
-
// function getOriginalStyleVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
302
|
-
// if (isTransform && Array.isArray(originalStyle.transform)) {
|
|
303
|
-
// let initialVal = undefined // InitialValue[key]
|
|
304
|
-
// // 仅支持 { transform: [{rotateX: '45deg'}, {rotateZ: '0.785398rad'}] } 格式的初始样式
|
|
305
|
-
// originalStyle.transform.forEach(item => {
|
|
306
|
-
// if (item[key] !== undefined) initialVal = item[key]
|
|
307
|
-
// })
|
|
308
|
-
// return initialVal
|
|
309
|
-
// }
|
|
310
|
-
// return originalStyle[key] // === undefined ? InitialValue[key] : originalStyle[key]
|
|
311
|
-
// }
|
|
312
|
-
// 获取动画shareVal初始值(prop style or 默认值)
|
|
313
|
-
// function getInitialVal (key: keyof ExtendedViewStyle, isTransform = false) {
|
|
314
|
-
// const originalVal = getOriginalStyleVal(key, isTransform)
|
|
315
|
-
// return originalVal === undefined ? InitialValue[key] : originalStyle[key]
|
|
316
|
-
// }
|
|
317
307
|
// 循环 animation actions 获取所有有动画的 style prop name
|
|
318
308
|
function getAnimatedStyleKeys () {
|
|
319
309
|
return (animation?.actions || []).reduce((keyMap, action) => {
|
|
320
310
|
const { rules, transform } = action
|
|
321
311
|
const ruleArr = [...rules.keys(), ...transform.keys()]
|
|
322
312
|
ruleArr.forEach(key => {
|
|
323
|
-
// const originalVal = getOriginalStyleVal(key, isTransform(key))
|
|
324
|
-
// if (!keyMap[key]) keyMap[key] = originalVal === undefined ? false : originalVal
|
|
325
313
|
if (!keyMap[key]) keyMap[key] = true
|
|
326
314
|
})
|
|
327
315
|
return keyMap
|
|
328
316
|
}, animatedKeys.current)
|
|
329
317
|
}
|
|
330
318
|
// animated key transform 格式化
|
|
331
|
-
function formatAnimatedKeys (keys: string[]
|
|
319
|
+
function formatAnimatedKeys (keys: string[]) {
|
|
332
320
|
const animatedKeys = [] as (string|string[])[]
|
|
333
321
|
const transforms = [] as string[]
|
|
334
322
|
keys.forEach(key => {
|
|
@@ -341,13 +329,23 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
341
329
|
if (transforms.length) animatedKeys.push(transforms)
|
|
342
330
|
return animatedKeys
|
|
343
331
|
}
|
|
344
|
-
//
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
332
|
+
// 设置 lastShareValRef & shareValMap
|
|
333
|
+
function updateStyleVal () {
|
|
334
|
+
Object.entries(originalStyle).forEach(([key, value]) => {
|
|
335
|
+
if (key === 'transform') {
|
|
336
|
+
Object.entries(getTransformObj(value)).forEach(([key, value]) => {
|
|
337
|
+
if (value !== lastStyleRef.current[key]) {
|
|
338
|
+
lastStyleRef.current[key] = value
|
|
339
|
+
shareValMap[key].value = value
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
} else if (hasOwn(shareValMap, key)) {
|
|
343
|
+
if (value !== lastStyleRef.current[key]) {
|
|
344
|
+
lastStyleRef.current[key] = value
|
|
345
|
+
shareValMap[key].value = value
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
})
|
|
351
349
|
}
|
|
352
350
|
// ** 生成动画样式
|
|
353
351
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
@@ -356,7 +354,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
356
354
|
return animatedStyleKeys.value.reduce((styles, key) => {
|
|
357
355
|
// console.info('getAnimationStyles', key, shareValMap[key].value)
|
|
358
356
|
if (Array.isArray(key)) {
|
|
359
|
-
const transformStyle = getTransformObj()
|
|
357
|
+
const transformStyle = getTransformObj(originalStyle.transform || [])
|
|
360
358
|
key.forEach((transformKey) => {
|
|
361
359
|
transformStyle[transformKey] = shareValMap[transformKey].value
|
|
362
360
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useEffect, useCallback, useMemo, useRef, ReactNode, ReactElement, isValidElement, useContext, useState, Dispatch, SetStateAction, Children, cloneElement } from 'react'
|
|
2
|
-
import { LayoutChangeEvent, TextStyle, ImageProps, Image
|
|
2
|
+
import { LayoutChangeEvent, TextStyle, ImageProps, Image } from 'react-native'
|
|
3
3
|
import { isObject, isFunction, isNumber, hasOwn, diffAndCloneA, error, warn } from '@mpxjs/utils'
|
|
4
4
|
import { VarContext, ScrollViewContext, RouteContext } from './context'
|
|
5
5
|
import { ExpressionParser, parseFunc, ReplaceSource } from './parser'
|
|
6
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
7
7
|
import FastImage, { FastImageProps } from '@d11/react-native-fast-image'
|
|
8
|
-
import type { AnyFunc, ExtendedFunctionComponent
|
|
8
|
+
import type { AnyFunc, ExtendedFunctionComponent } from './types/common'
|
|
9
9
|
import { runOnJS } from 'react-native-reanimated'
|
|
10
10
|
import { Gesture } from 'react-native-gesture-handler'
|
|
11
11
|
|
|
@@ -80,20 +80,6 @@ export const useUpdateEffect = (effect: any, deps: any) => {
|
|
|
80
80
|
}, deps)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* 解析行内样式
|
|
85
|
-
* @param inlineStyle
|
|
86
|
-
* @returns
|
|
87
|
-
*/
|
|
88
|
-
export const parseInlineStyle = (inlineStyle = ''): Record<string, string> => {
|
|
89
|
-
return inlineStyle.split(';').reduce((styleObj, style) => {
|
|
90
|
-
const [k, v, ...rest] = style.split(':')
|
|
91
|
-
if (rest.length || !v || !k) return styleObj
|
|
92
|
-
const key = k.trim().replace(/-./g, c => c.substring(1).toUpperCase())
|
|
93
|
-
return extendObject(styleObj, { [key]: global.__formatValue(v.trim()) })
|
|
94
|
-
}, {})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
83
|
export const parseUrl = (cssUrl = '') => {
|
|
98
84
|
if (!cssUrl) return
|
|
99
85
|
const match = cssUrl.match(URL_REGEX)
|
|
@@ -305,12 +291,8 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
305
291
|
const normalStyleChangedRef = useRef(false)
|
|
306
292
|
let hasVarDec = false
|
|
307
293
|
let hasVarUse = false
|
|
308
|
-
let hasSelfPercent = false
|
|
309
294
|
const varKeyPaths: Array<Array<string>> = []
|
|
310
295
|
const unoVarKeyPaths: Array<Array<string>> = []
|
|
311
|
-
const percentKeyPaths: Array<Array<string>> = []
|
|
312
|
-
const calcKeyPaths: Array<Array<string>> = []
|
|
313
|
-
const envKeyPaths: Array<Array<string>> = []
|
|
314
296
|
const [width, setWidth] = useState(0)
|
|
315
297
|
const [height, setHeight] = useState(0)
|
|
316
298
|
const navigation = useNavigation()
|
|
@@ -373,6 +355,11 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
373
355
|
}
|
|
374
356
|
|
|
375
357
|
const memoResult = useMemo(() => {
|
|
358
|
+
let hasSelfPercent = false
|
|
359
|
+
let hasPositionFixed = false
|
|
360
|
+
const percentKeyPaths: Array<Array<string>> = []
|
|
361
|
+
const calcKeyPaths: Array<Array<string>> = []
|
|
362
|
+
const envKeyPaths: Array<Array<string>> = []
|
|
376
363
|
// transform can be memoized
|
|
377
364
|
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
378
365
|
if (envUseRegExp.test(value)) {
|
|
@@ -395,6 +382,13 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
395
382
|
}
|
|
396
383
|
}
|
|
397
384
|
|
|
385
|
+
function transformPosition (styleObj: Record<string, any>) {
|
|
386
|
+
if (styleObj.position === 'fixed') {
|
|
387
|
+
hasPositionFixed = true
|
|
388
|
+
styleObj.position = 'absolute'
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
398
392
|
// traverse env & calc & percent
|
|
399
393
|
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor])
|
|
400
394
|
|
|
@@ -426,12 +420,15 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
426
420
|
}
|
|
427
421
|
}
|
|
428
422
|
})
|
|
423
|
+
// apply position
|
|
424
|
+
transformPosition(normalStyle)
|
|
429
425
|
// transform number enum stringify
|
|
430
426
|
transformStringify(normalStyle)
|
|
431
427
|
|
|
432
428
|
return {
|
|
433
429
|
normalStyle,
|
|
434
|
-
hasSelfPercent
|
|
430
|
+
hasSelfPercent,
|
|
431
|
+
hasPositionFixed
|
|
435
432
|
}
|
|
436
433
|
}, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize])
|
|
437
434
|
|
|
@@ -529,8 +526,8 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
529
526
|
hasLayoutRef.current = true
|
|
530
527
|
if (hasSelfPercent) {
|
|
531
528
|
const { width, height } = e?.nativeEvent?.layout || {}
|
|
532
|
-
setWidth(width || 0)
|
|
533
|
-
setHeight(height || 0)
|
|
529
|
+
setWidth && setWidth(width || 0)
|
|
530
|
+
setHeight && setHeight(height || 0)
|
|
534
531
|
}
|
|
535
532
|
if (enableOffset) {
|
|
536
533
|
nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
@@ -657,7 +654,7 @@ export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array
|
|
|
657
654
|
}, {})
|
|
658
655
|
}
|
|
659
656
|
|
|
660
|
-
export function useHover ({ enableHover, hoverStartTime, hoverStayTime, disabled }
|
|
657
|
+
export function useHover ({ enableHover, hoverStartTime, hoverStayTime, disabled }: { enableHover: boolean, hoverStartTime: number, hoverStayTime: number, disabled?: boolean }) {
|
|
661
658
|
const enableHoverRef = useRef(enableHover)
|
|
662
659
|
if (enableHoverRef.current !== enableHover) {
|
|
663
660
|
error('[Mpx runtime error]: hover-class use should be stable in the component lifecycle.')
|
|
@@ -2,6 +2,7 @@ import { hasOwn, isEmptyObject, extend } from './utils'
|
|
|
2
2
|
import { isBrowser } from './env'
|
|
3
3
|
import transRpxStyle from './transRpxStyle'
|
|
4
4
|
import animation from './animation'
|
|
5
|
+
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
5
6
|
|
|
6
7
|
export function processComponentOption (
|
|
7
8
|
{
|
|
@@ -45,12 +46,12 @@ registered in parent context!`)
|
|
|
45
46
|
option.props.generichash = String
|
|
46
47
|
Object.keys(componentGenerics).forEach((genericName) => {
|
|
47
48
|
if (componentGenerics[genericName].default) {
|
|
48
|
-
option.props[`generic${genericName}`] = {
|
|
49
|
+
option.props[`generic${dash2hump(genericName)}`] = {
|
|
49
50
|
type: String,
|
|
50
51
|
default: `${genericName}default`
|
|
51
52
|
}
|
|
52
53
|
} else {
|
|
53
|
-
option.props[`generic${genericName}`] = String
|
|
54
|
+
option.props[`generic${dash2hump(genericName)}`] = String
|
|
54
55
|
}
|
|
55
56
|
})
|
|
56
57
|
}
|
|
@@ -37,6 +37,7 @@ module.exports = function (css, map) {
|
|
|
37
37
|
const inlineConfig = Object.assign({}, mpx.postcssInlineConfig, { defs, inlineConfigFile: path.join(mpx.projectRoot, 'vue.config.js') })
|
|
38
38
|
loadPostcssConfig(this, inlineConfig).then(config => {
|
|
39
39
|
const plugins = [] // init with trim plugin
|
|
40
|
+
const postPlugins = []
|
|
40
41
|
const options = Object.assign(
|
|
41
42
|
{
|
|
42
43
|
to: this.resourcePath,
|
|
@@ -77,9 +78,6 @@ module.exports = function (css, map) {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
if (mpx.mode === 'web') {
|
|
81
|
-
plugins.push(vw({ transRpxFn }))
|
|
82
|
-
}
|
|
83
81
|
// source map
|
|
84
82
|
if (this.sourceMap && !options.map) {
|
|
85
83
|
options.map = {
|
|
@@ -89,13 +87,17 @@ module.exports = function (css, map) {
|
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
const finalPlugins = config.prePlugins.concat(plugins, config.plugins)
|
|
93
|
-
|
|
94
90
|
const cssList = []
|
|
95
91
|
if (runtimeCompile) {
|
|
96
|
-
|
|
92
|
+
postPlugins.push(cssArrayList(cssList))
|
|
97
93
|
}
|
|
98
94
|
|
|
95
|
+
if (mpx.mode === 'web') {
|
|
96
|
+
postPlugins.push(vw({ transRpxFn }))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const finalPlugins = config.prePlugins.concat(plugins, config.plugins, postPlugins)
|
|
100
|
+
|
|
99
101
|
return postcss(finalPlugins)
|
|
100
102
|
.process(css, options)
|
|
101
103
|
.then(result => {
|
|
@@ -38,7 +38,7 @@ const endTag = new RegExp(('^<\\/' + qnameCapture + '[^>]*>'))
|
|
|
38
38
|
const doctype = /^<!DOCTYPE [^>]+>/i
|
|
39
39
|
const comment = /^<!--/
|
|
40
40
|
const conditionalComment = /^<!\[/
|
|
41
|
-
const specialClassReg = /^mpx-((cover-)?view|button|navigator|picker-view)$/
|
|
41
|
+
const specialClassReg = /^mpx-((cover-)?view|button|navigator|picker-view|input|textarea)$/
|
|
42
42
|
let IS_REGEX_CAPTURING_BROKEN = false
|
|
43
43
|
'x'.replace(/x(.)?/g, function (m, g) {
|
|
44
44
|
IS_REGEX_CAPTURING_BROKEN = g === ''
|
|
@@ -118,6 +118,7 @@ let processingTemplate = false
|
|
|
118
118
|
const rulesResultMap = new Map()
|
|
119
119
|
let usingComponents = []
|
|
120
120
|
let usingComponentsInfo = {}
|
|
121
|
+
let componentGenerics = {}
|
|
121
122
|
|
|
122
123
|
function updateForScopesMap () {
|
|
123
124
|
forScopesMap = {}
|
|
@@ -634,6 +635,7 @@ function parse (template, options) {
|
|
|
634
635
|
hasOptionalChaining = false
|
|
635
636
|
processingTemplate = false
|
|
636
637
|
rulesResultMap.clear()
|
|
638
|
+
componentGenerics = options.componentGenerics || {}
|
|
637
639
|
|
|
638
640
|
if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo)
|
|
639
641
|
usingComponents = Object.keys(options.usingComponentsInfo)
|
|
@@ -942,32 +944,37 @@ function stringify (str) {
|
|
|
942
944
|
|
|
943
945
|
const genericRE = /^generic:(.+)$/
|
|
944
946
|
|
|
945
|
-
function
|
|
946
|
-
if (
|
|
947
|
+
function processComponentGenerics (el, meta) {
|
|
948
|
+
if (componentGenerics && componentGenerics[el.tag]) {
|
|
947
949
|
const generic = dash2hump(el.tag)
|
|
948
950
|
el.tag = 'component'
|
|
949
951
|
addAttrs(el, [{
|
|
950
|
-
name: ':is',
|
|
951
|
-
value: `generic${generic}`
|
|
952
|
+
name: isWeb(mode) ? ':is' : 'is',
|
|
953
|
+
value: isWeb(mode) ? `generic${generic}` : `{{generic${generic}}}`
|
|
952
954
|
}])
|
|
953
955
|
}
|
|
954
956
|
|
|
955
957
|
let hasGeneric = false
|
|
956
|
-
|
|
957
958
|
const genericHash = moduleId
|
|
959
|
+
const genericAttrs = []
|
|
958
960
|
|
|
959
961
|
el.attrsList.forEach((attr) => {
|
|
960
962
|
if (genericRE.test(attr.name)) {
|
|
961
|
-
|
|
962
|
-
addAttrs(el, [{
|
|
963
|
-
name: attr.name.replace(':', ''),
|
|
964
|
-
value: attr.value
|
|
965
|
-
}])
|
|
963
|
+
genericAttrs.push(attr)
|
|
966
964
|
hasGeneric = true
|
|
967
965
|
addGenericInfo(meta, genericHash, attr.value)
|
|
968
966
|
}
|
|
969
967
|
})
|
|
970
968
|
|
|
969
|
+
// 统一处理所有的generic:属性
|
|
970
|
+
genericAttrs.forEach((attr) => {
|
|
971
|
+
getAndRemoveAttr(el, attr.name)
|
|
972
|
+
addAttrs(el, [{
|
|
973
|
+
name: attr.name.replace(':', ''),
|
|
974
|
+
value: attr.value
|
|
975
|
+
}])
|
|
976
|
+
})
|
|
977
|
+
|
|
971
978
|
if (hasGeneric) {
|
|
972
979
|
addAttrs(el, [{
|
|
973
980
|
name: 'generichash',
|
|
@@ -1104,7 +1111,7 @@ function processStyleReact (el, options) {
|
|
|
1104
1111
|
}
|
|
1105
1112
|
|
|
1106
1113
|
if (specialClassReg.test(el.tag)) {
|
|
1107
|
-
const staticClassNames = ['hover', 'indicator', 'mask']
|
|
1114
|
+
const staticClassNames = ['hover', 'indicator', 'mask', 'placeholder']
|
|
1108
1115
|
staticClassNames.forEach((className) => {
|
|
1109
1116
|
let staticClass = el.attrsMap[className + '-class'] || ''
|
|
1110
1117
|
let staticStyle = getAndRemoveAttr(el, className + '-style').val || ''
|
|
@@ -2253,7 +2260,7 @@ function isRealNode (el) {
|
|
|
2253
2260
|
}
|
|
2254
2261
|
|
|
2255
2262
|
function isComponentNode (el) {
|
|
2256
|
-
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
|
|
2263
|
+
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component' || componentGenerics[el.tag]
|
|
2257
2264
|
}
|
|
2258
2265
|
|
|
2259
2266
|
function getComponentInfo (el) {
|
|
@@ -2706,7 +2713,7 @@ function processElement (el, root, options, meta) {
|
|
|
2706
2713
|
processEventWeb(el)
|
|
2707
2714
|
// processWebExternalClassesHack(el, options)
|
|
2708
2715
|
processExternalClasses(el, options)
|
|
2709
|
-
|
|
2716
|
+
processComponentGenerics(el, meta)
|
|
2710
2717
|
return
|
|
2711
2718
|
}
|
|
2712
2719
|
|
|
@@ -2721,6 +2728,7 @@ function processElement (el, root, options, meta) {
|
|
|
2721
2728
|
if (!pass) {
|
|
2722
2729
|
processStyleReact(el, options)
|
|
2723
2730
|
processEventReact(el, options)
|
|
2731
|
+
processComponentGenerics(el, meta)
|
|
2724
2732
|
processComponentIs(el, options)
|
|
2725
2733
|
processSlotReact(el, meta)
|
|
2726
2734
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const toPosix = require('./to-posix')
|
|
2
|
+
|
|
1
3
|
const orMatcher = items => {
|
|
2
4
|
return str => {
|
|
3
5
|
for (let i = 0; i < items.length; i++) {
|
|
@@ -33,16 +35,20 @@ const normalizeCondition = (condition) => {
|
|
|
33
35
|
|
|
34
36
|
// 匹配规则为include匹配到且未被exclude匹配到的资源为true,其余资源全部为false,如果需要实现不传include为全部匹配的话可以将include的默认值设置为()=>true进行传入
|
|
35
37
|
const matchCondition = (resourcePath, condition = {}) => {
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const posixResourcePath = toPosix(resourcePath)
|
|
39
|
+
const checkPath = (path) => {
|
|
40
|
+
let matched = false
|
|
41
|
+
const includeMatcher = condition.include && normalizeCondition(condition.include)
|
|
42
|
+
const excludeMatcher = condition.exclude && normalizeCondition(condition.exclude)
|
|
43
|
+
if (includeMatcher?.(path)) matched = true
|
|
44
|
+
if (excludeMatcher?.(path)) matched = false
|
|
45
|
+
return matched
|
|
41
46
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
47
|
+
if (checkPath(resourcePath)) return true
|
|
48
|
+
if (posixResourcePath !== resourcePath) {
|
|
49
|
+
return checkPath(posixResourcePath)
|
|
44
50
|
}
|
|
45
|
-
return
|
|
51
|
+
return false
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
module.exports = {
|
package/lib/web/processJSON.js
CHANGED
|
@@ -79,8 +79,6 @@ module.exports = function (jsonContent, {
|
|
|
79
79
|
})
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const isApp = ctorType === 'app'
|
|
83
|
-
|
|
84
82
|
if (!jsonContent) {
|
|
85
83
|
return callback()
|
|
86
84
|
}
|
|
@@ -100,7 +98,7 @@ module.exports = function (jsonContent, {
|
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
if (
|
|
101
|
+
if (ctorType !== 'app') {
|
|
104
102
|
rulesRunnerOptions.mainKey = ctorType
|
|
105
103
|
}
|
|
106
104
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.3",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@better-scroll/wheel": "^2.5.1",
|
|
29
29
|
"@better-scroll/zoom": "^2.5.1",
|
|
30
30
|
"@mpxjs/template-engine": "^2.8.7",
|
|
31
|
-
"@mpxjs/utils": "^2.10.
|
|
31
|
+
"@mpxjs/utils": "^2.10.2",
|
|
32
32
|
"acorn": "^8.11.3",
|
|
33
33
|
"acorn-walk": "^7.2.0",
|
|
34
34
|
"async": "^2.6.0",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@ant-design/react-native": "^5.2.2",
|
|
86
86
|
"@d11/react-native-fast-image": "^8.6.12",
|
|
87
|
-
"@mpxjs/api-proxy": "^2.10.
|
|
87
|
+
"@mpxjs/api-proxy": "^2.10.3",
|
|
88
88
|
"@types/babel-traverse": "^6.25.4",
|
|
89
89
|
"@types/babel-types": "^7.0.4",
|
|
90
90
|
"@types/react": "^18.2.79",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"engines": {
|
|
102
102
|
"node": ">=14.14.0"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "043c9bc770ce9cc11f865bab67f46849ff573728"
|
|
105
105
|
}
|