@mpxjs/webpack-plugin 2.10.2 → 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 +12 -0
- package/lib/platform/style/wx/index.js +6 -4
- 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 +4 -2
- package/lib/react/processTemplate.js +18 -3
- package/lib/react/script-helper.js +18 -4
- package/lib/runtime/components/react/dist/mpx-input.jsx +1 -11
- package/lib/runtime/components/react/dist/{KeyboardAvoidingView.jsx → mpx-keyboard-avoiding-view.jsx} +4 -3
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +1 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +10 -5
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +22 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +10 -5
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +46 -48
- package/lib/runtime/components/react/dist/utils.jsx +17 -7
- package/lib/runtime/components/react/mpx-input.tsx +1 -19
- package/lib/runtime/components/react/{KeyboardAvoidingView.tsx → mpx-keyboard-avoiding-view.tsx} +4 -2
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +1 -2
- package/lib/runtime/components/react/mpx-scroll-view.tsx +13 -4
- package/lib/runtime/components/react/mpx-simple-view.tsx +32 -0
- package/lib/runtime/components/react/mpx-view.tsx +17 -10
- package/lib/runtime/components/react/mpx-web-view.tsx +7 -7
- 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 -10
- package/lib/runtime/optionProcessor.js +3 -2
- package/lib/style-compiler/index.js +8 -6
- package/lib/template-compiler/compiler.js +20 -12
- package/lib/utils/match-condition.js +14 -8
- package/lib/web/processJSON.js +1 -3
- package/package.json +3 -3
|
@@ -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
|
|
|
@@ -291,12 +291,8 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
291
291
|
const normalStyleChangedRef = useRef(false)
|
|
292
292
|
let hasVarDec = false
|
|
293
293
|
let hasVarUse = false
|
|
294
|
-
let hasSelfPercent = false
|
|
295
294
|
const varKeyPaths: Array<Array<string>> = []
|
|
296
295
|
const unoVarKeyPaths: Array<Array<string>> = []
|
|
297
|
-
const percentKeyPaths: Array<Array<string>> = []
|
|
298
|
-
const calcKeyPaths: Array<Array<string>> = []
|
|
299
|
-
const envKeyPaths: Array<Array<string>> = []
|
|
300
296
|
const [width, setWidth] = useState(0)
|
|
301
297
|
const [height, setHeight] = useState(0)
|
|
302
298
|
const navigation = useNavigation()
|
|
@@ -359,6 +355,11 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
359
355
|
}
|
|
360
356
|
|
|
361
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>> = []
|
|
362
363
|
// transform can be memoized
|
|
363
364
|
function envVisitor ({ value, keyPath }: VisitorArg) {
|
|
364
365
|
if (envUseRegExp.test(value)) {
|
|
@@ -381,6 +382,13 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
384
|
|
|
385
|
+
function transformPosition (styleObj: Record<string, any>) {
|
|
386
|
+
if (styleObj.position === 'fixed') {
|
|
387
|
+
hasPositionFixed = true
|
|
388
|
+
styleObj.position = 'absolute'
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
384
392
|
// traverse env & calc & percent
|
|
385
393
|
traverseStyle(normalStyle, [envVisitor, percentVisitor, calcVisitor])
|
|
386
394
|
|
|
@@ -412,12 +420,15 @@ export function useTransformStyle (styleObj: Record<string, any> = {}, { enableV
|
|
|
412
420
|
}
|
|
413
421
|
}
|
|
414
422
|
})
|
|
423
|
+
// apply position
|
|
424
|
+
transformPosition(normalStyle)
|
|
415
425
|
// transform number enum stringify
|
|
416
426
|
transformStringify(normalStyle)
|
|
417
427
|
|
|
418
428
|
return {
|
|
419
429
|
normalStyle,
|
|
420
|
-
hasSelfPercent
|
|
430
|
+
hasSelfPercent,
|
|
431
|
+
hasPositionFixed
|
|
421
432
|
}
|
|
422
433
|
}, [normalStyleChangedRef.current, width, height, parentWidth, parentHeight, parentFontSize])
|
|
423
434
|
|
|
@@ -515,8 +526,8 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
515
526
|
hasLayoutRef.current = true
|
|
516
527
|
if (hasSelfPercent) {
|
|
517
528
|
const { width, height } = e?.nativeEvent?.layout || {}
|
|
518
|
-
setWidth(width || 0)
|
|
519
|
-
setHeight(height || 0)
|
|
529
|
+
setWidth && setWidth(width || 0)
|
|
530
|
+
setHeight && setHeight(height || 0)
|
|
520
531
|
}
|
|
521
532
|
if (enableOffset) {
|
|
522
533
|
nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
@@ -643,7 +654,7 @@ export function pickStyle (styleObj: Record<string, any> = {}, pickedKeys: Array
|
|
|
643
654
|
}, {})
|
|
644
655
|
}
|
|
645
656
|
|
|
646
|
-
export function useHover ({ enableHover, hoverStartTime, hoverStayTime, disabled }
|
|
657
|
+
export function useHover ({ enableHover, hoverStartTime, hoverStayTime, disabled }: { enableHover: boolean, hoverStartTime: number, hoverStayTime: number, disabled?: boolean }) {
|
|
647
658
|
const enableHoverRef = useRef(enableHover)
|
|
648
659
|
if (enableHoverRef.current !== enableHover) {
|
|
649
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 => {
|
|
@@ -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',
|
|
@@ -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"
|
|
@@ -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
|
}
|