@mpxjs/webpack-plugin 2.9.57 → 2.9.58
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 +29 -9
- package/lib/platform/template/wx/component-config/web-view.js +8 -0
- package/lib/react/index.js +0 -1
- package/lib/react/processStyles.js +14 -3
- package/lib/react/style-helper.js +6 -10
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +115 -0
- package/lib/runtime/components/react/dist/utils.js +1 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +171 -0
- package/lib/runtime/components/react/utils.ts +1 -1
- package/lib/runtime/transRpxStyle.js +1 -1
- package/lib/style-compiler/plugins/rpx.js +2 -2
- package/lib/style-compiler/plugins/vw.js +2 -2
- package/lib/template-compiler/compiler.js +40 -21
- package/package.json +3 -2
|
@@ -60,7 +60,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
60
60
|
default: 'default' // 不校验
|
|
61
61
|
}
|
|
62
62
|
// number 类型支持的单位(包含auto)
|
|
63
|
-
const numberRegExp = /^\s*((
|
|
63
|
+
const numberRegExp = /^\s*((-?\d+(\.\d+)?)(rpx|px|%)?)|(auto)\s*$/
|
|
64
64
|
// RN 不支持的颜色格式
|
|
65
65
|
const colorRegExp = /^\s*(lab|lch|oklab|oklch|color-mix|color|hwb|lch|light-dark).*$/
|
|
66
66
|
|
|
@@ -101,6 +101,26 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
101
101
|
borderStyle: ValueType.default,
|
|
102
102
|
borderColor: ValueType.color
|
|
103
103
|
},
|
|
104
|
+
'border-left': { // 仅支持 width | style | color 这种排序
|
|
105
|
+
borderLeftWidth: ValueType.number,
|
|
106
|
+
borderLeftStyle: ValueType.default,
|
|
107
|
+
borderLeftColor: ValueType.color
|
|
108
|
+
},
|
|
109
|
+
'border-right': { // 仅支持 width | style | color 这种排序
|
|
110
|
+
borderRightWidth: ValueType.number,
|
|
111
|
+
borderRightStyle: ValueType.default,
|
|
112
|
+
borderRightColor: ValueType.color
|
|
113
|
+
},
|
|
114
|
+
'border-top': { // 仅支持 width | style | color 这种排序
|
|
115
|
+
borderTopWidth: ValueType.number,
|
|
116
|
+
borderTopStyle: ValueType.default,
|
|
117
|
+
borderTopColor: ValueType.color
|
|
118
|
+
},
|
|
119
|
+
'border-bottom': { // 仅支持 width | style | color 这种排序
|
|
120
|
+
borderBottomWidth: ValueType.number,
|
|
121
|
+
borderBottomStyle: ValueType.default,
|
|
122
|
+
borderBottomColor: ValueType.color
|
|
123
|
+
},
|
|
104
124
|
'box-shadow': { // 仅支持 offset-x | offset-y | blur-radius | color 排序
|
|
105
125
|
'shadowOffset.width': ValueType.number,
|
|
106
126
|
'shadowOffset.height': ValueType.number,
|
|
@@ -220,7 +240,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
220
240
|
|
|
221
241
|
return {
|
|
222
242
|
prop,
|
|
223
|
-
value:
|
|
243
|
+
value: /^\s*-?\d+(\.\d+)?\s*$/.test(value) ? `${Math.round(value * 100)}%` : value
|
|
224
244
|
}
|
|
225
245
|
}
|
|
226
246
|
|
|
@@ -339,7 +359,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
339
359
|
supportedModes: ['ios', 'android'],
|
|
340
360
|
rules: [
|
|
341
361
|
{ // 背景相关属性的处理
|
|
342
|
-
test:
|
|
362
|
+
test: /^(background|background-image|background-color|background-size|background-repeat|background-position)$/,
|
|
343
363
|
ios: checkBackgroundImage,
|
|
344
364
|
android: checkBackgroundImage
|
|
345
365
|
},
|
|
@@ -372,7 +392,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
372
392
|
android: getAbbreviationAndroid
|
|
373
393
|
},
|
|
374
394
|
{
|
|
375
|
-
test:
|
|
395
|
+
test: /^(font-variant|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures)$/,
|
|
376
396
|
ios: getFontVariant,
|
|
377
397
|
android: getFontVariant
|
|
378
398
|
},
|
|
@@ -382,7 +402,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
382
402
|
android: getBorderRadius
|
|
383
403
|
},
|
|
384
404
|
{ // margin padding 内外边距的处理
|
|
385
|
-
test:
|
|
405
|
+
test: /^(margin|padding)$/,
|
|
386
406
|
ios: formatMargins,
|
|
387
407
|
android: formatMargins
|
|
388
408
|
},
|
|
@@ -398,13 +418,13 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
398
418
|
android: formatLineHeight
|
|
399
419
|
},
|
|
400
420
|
// 值类型校验放到最后
|
|
401
|
-
{ // color 颜色值校验
|
|
402
|
-
test:
|
|
421
|
+
{ // color 颜色值校验 color xx-color 等
|
|
422
|
+
test: /^(color|(.+-color))$/,
|
|
403
423
|
ios: checkCommonValue(ValueType.color),
|
|
404
424
|
android: checkCommonValue(ValueType.color)
|
|
405
425
|
},
|
|
406
|
-
{ // number 值校验
|
|
407
|
-
test:
|
|
426
|
+
{ // number 值校验 // width height xx-left xx-top 等
|
|
427
|
+
test: /^((width|height)|(.+-(left|right|top|bottom|radius|spacing|size)))$/,
|
|
408
428
|
ios: checkCommonValue(ValueType.number),
|
|
409
429
|
android: checkCommonValue(ValueType.number)
|
|
410
430
|
}
|
|
@@ -6,6 +6,14 @@ module.exports = function () {
|
|
|
6
6
|
web (tag, { el }) {
|
|
7
7
|
el.isBuiltIn = true
|
|
8
8
|
return 'mpx-web-view'
|
|
9
|
+
},
|
|
10
|
+
ios (tag, { el }) {
|
|
11
|
+
el.isBuiltIn = true
|
|
12
|
+
return 'mpx-web-view'
|
|
13
|
+
},
|
|
14
|
+
android (tag, { el }) {
|
|
15
|
+
el.isBuiltIn = true
|
|
16
|
+
return 'mpx-web-view'
|
|
9
17
|
}
|
|
10
18
|
}
|
|
11
19
|
}
|
package/lib/react/index.js
CHANGED
|
@@ -5,7 +5,6 @@ const shallowStringify = require('../utils/shallow-stringify')
|
|
|
5
5
|
|
|
6
6
|
module.exports = function (styles, {
|
|
7
7
|
loaderContext,
|
|
8
|
-
srcMode,
|
|
9
8
|
ctorType,
|
|
10
9
|
autoScope,
|
|
11
10
|
moduleId
|
|
@@ -14,7 +13,17 @@ module.exports = function (styles, {
|
|
|
14
13
|
let content = ''
|
|
15
14
|
let output = '/* styles */\n'
|
|
16
15
|
if (styles.length) {
|
|
17
|
-
const
|
|
16
|
+
const warn = (msg) => {
|
|
17
|
+
loaderContext.emitWarning(
|
|
18
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
const error = (msg) => {
|
|
22
|
+
loaderContext.emitError(
|
|
23
|
+
new Error('[style compiler][' + loaderContext.resource + ']: ' + msg)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
const { mode, srcMode } = loaderContext.getMpx()
|
|
18
27
|
async.eachOfSeries(styles, (style, i, callback) => {
|
|
19
28
|
const scoped = style.scoped || autoScope
|
|
20
29
|
const extraOptions = {
|
|
@@ -41,7 +50,9 @@ module.exports = function (styles, {
|
|
|
41
50
|
content,
|
|
42
51
|
filename: loaderContext.resourcePath,
|
|
43
52
|
mode,
|
|
44
|
-
srcMode
|
|
53
|
+
srcMode,
|
|
54
|
+
warn,
|
|
55
|
+
error
|
|
45
56
|
})
|
|
46
57
|
if (ctorType === 'app') {
|
|
47
58
|
output += `global.__getAppClassMap = function() {
|
|
@@ -2,10 +2,10 @@ const postcss = require('postcss')
|
|
|
2
2
|
const selectorParser = require('postcss-selector-parser')
|
|
3
3
|
const getRulesRunner = require('../platform/index')
|
|
4
4
|
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
5
|
-
const rpxRegExp = /^\s*(
|
|
6
|
-
const pxRegExp = /^\s*(
|
|
5
|
+
const rpxRegExp = /^\s*(-?\d+(\.\d+)?)rpx\s*$/
|
|
6
|
+
const pxRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
|
|
7
7
|
const cssPrefixExp = /^-(webkit|moz|ms|o)-/
|
|
8
|
-
function getClassMap ({ content, filename, mode, srcMode }) {
|
|
8
|
+
function getClassMap ({ content, filename, mode, srcMode, warn, error }) {
|
|
9
9
|
const classMap = {}
|
|
10
10
|
|
|
11
11
|
const root = postcss.parse(content, {
|
|
@@ -30,12 +30,8 @@ function getClassMap ({ content, filename, mode, srcMode }) {
|
|
|
30
30
|
srcMode,
|
|
31
31
|
type: 'style',
|
|
32
32
|
testKey: 'prop',
|
|
33
|
-
warn
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
error: (msg) => {
|
|
37
|
-
console.error('[style compiler error]: ' + msg)
|
|
38
|
-
}
|
|
33
|
+
warn,
|
|
34
|
+
error
|
|
39
35
|
})
|
|
40
36
|
|
|
41
37
|
root.walkRules(rule => {
|
|
@@ -70,7 +66,7 @@ function getClassMap ({ content, filename, mode, srcMode }) {
|
|
|
70
66
|
if (selector.nodes.length === 1 && selector.nodes[0].type === 'class') {
|
|
71
67
|
classMapKeys.push(selector.nodes[0].value)
|
|
72
68
|
} else {
|
|
73
|
-
|
|
69
|
+
error('Only single class selector is supported in react native mode temporarily.')
|
|
74
70
|
}
|
|
75
71
|
})
|
|
76
72
|
}).processSync(rule.selector)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { forwardRef, useEffect } from 'react';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { noop } from '@mpxjs/utils';
|
|
4
|
+
import { Portal } from '@ant-design/react-native';
|
|
5
|
+
import { getCustomEvent } from './getInnerListeners';
|
|
6
|
+
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { WebView } from 'react-native-webview';
|
|
9
|
+
import useNodesRef from './useNodesRef';
|
|
10
|
+
import { StyleSheet } from 'react-native';
|
|
11
|
+
const _WebView = forwardRef((props, ref) => {
|
|
12
|
+
const { src, bindmessage = noop, bindload = noop, binderror = noop } = props;
|
|
13
|
+
const defaultWebViewStyle = [
|
|
14
|
+
{
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
left: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
top: 0,
|
|
19
|
+
bottom: 0
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
const { nodeRef: webViewRef } = useNodesRef(props, ref, {
|
|
23
|
+
defaultStyle: StyleSheet.flatten([
|
|
24
|
+
...defaultWebViewStyle
|
|
25
|
+
])
|
|
26
|
+
});
|
|
27
|
+
const _messageList = [];
|
|
28
|
+
const handleUnload = () => {
|
|
29
|
+
// 这里是 WebView 销毁前执行的逻辑
|
|
30
|
+
bindmessage(getCustomEvent('messsage', {}, {
|
|
31
|
+
detail: {
|
|
32
|
+
data: _messageList
|
|
33
|
+
},
|
|
34
|
+
layoutRef: webViewRef
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
// 组件卸载时执行
|
|
39
|
+
return () => {
|
|
40
|
+
handleUnload();
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
const _load = function (res) {
|
|
44
|
+
const result = {
|
|
45
|
+
type: 'load',
|
|
46
|
+
timeStamp: res.timeStamp,
|
|
47
|
+
detail: {
|
|
48
|
+
src: res.nativeEvent?.url
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
bindload(result);
|
|
52
|
+
};
|
|
53
|
+
const _error = function (res) {
|
|
54
|
+
const result = {
|
|
55
|
+
type: 'error',
|
|
56
|
+
timeStamp: res.timeStamp,
|
|
57
|
+
detail: {
|
|
58
|
+
src: ''
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
binderror(result);
|
|
62
|
+
};
|
|
63
|
+
const _message = function (res) {
|
|
64
|
+
let data;
|
|
65
|
+
let asyncCallback;
|
|
66
|
+
const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab });
|
|
67
|
+
try {
|
|
68
|
+
const nativeEventData = res.nativeEvent?.data;
|
|
69
|
+
data = JSON.parse(nativeEventData);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
data = {};
|
|
73
|
+
}
|
|
74
|
+
const postData = data.payload || {};
|
|
75
|
+
switch (data.type) {
|
|
76
|
+
case 'postMessage':
|
|
77
|
+
_messageList.push(postData.data);
|
|
78
|
+
asyncCallback = Promise.resolve({
|
|
79
|
+
errMsg: 'invokeWebappApi:ok'
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
case 'navigateTo':
|
|
83
|
+
asyncCallback = navObj.navigateTo(postData);
|
|
84
|
+
break;
|
|
85
|
+
case 'navigateBack':
|
|
86
|
+
asyncCallback = navObj.navigateBack(postData);
|
|
87
|
+
break;
|
|
88
|
+
case 'redirectTo':
|
|
89
|
+
asyncCallback = navObj.redirectTo(postData);
|
|
90
|
+
break;
|
|
91
|
+
case 'switchTab':
|
|
92
|
+
asyncCallback = navObj.switchTab(postData);
|
|
93
|
+
break;
|
|
94
|
+
case 'reLaunch':
|
|
95
|
+
asyncCallback = navObj.reLaunch(postData);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
asyncCallback && asyncCallback.then((res) => {
|
|
99
|
+
if (webViewRef.current?.postMessage) {
|
|
100
|
+
const test = JSON.stringify({
|
|
101
|
+
type: data.type,
|
|
102
|
+
callbackId: data.callbackId,
|
|
103
|
+
result: res
|
|
104
|
+
});
|
|
105
|
+
webViewRef.current.postMessage(test);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
return (<Portal>
|
|
111
|
+
<WebView style={[...defaultWebViewStyle]} source={{ uri: src }} ref={webViewRef} onLoad={_load} onError={_error} onMessage={_message} javaScriptEnabled={true}></WebView>
|
|
112
|
+
</Portal>);
|
|
113
|
+
});
|
|
114
|
+
_WebView.displayName = 'mpx-web-view';
|
|
115
|
+
export default _WebView;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef, Children, isValidElement } from 'react';
|
|
2
2
|
import { StyleSheet } from 'react-native';
|
|
3
3
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/;
|
|
4
|
-
export const PERCENT_REGX =
|
|
4
|
+
export const PERCENT_REGX = /^\s*-?\d+(\.\d+)?%\s*$/;
|
|
5
5
|
const URL_REGEX = /url\(["']?(.*?)["']?\)/;
|
|
6
6
|
export function omit(obj, fields) {
|
|
7
7
|
const shallowCopy = Object.assign({}, obj);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { forwardRef, JSX, useRef, useEffect } from 'react'
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { noop } from '@mpxjs/utils'
|
|
4
|
+
import { Portal } from '@ant-design/react-native'
|
|
5
|
+
import { getCustomEvent } from './getInnerListeners'
|
|
6
|
+
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { WebView } from 'react-native-webview'
|
|
9
|
+
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
10
|
+
import { StyleSheet } from 'react-native'
|
|
11
|
+
|
|
12
|
+
type OnMessageCallbackEvent = {
|
|
13
|
+
detail: {
|
|
14
|
+
data: any[]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type CommonCallbackEvent = {
|
|
19
|
+
detail: {
|
|
20
|
+
src?: string
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface WebViewProps {
|
|
25
|
+
src: string
|
|
26
|
+
bindmessage?: (event: OnMessageCallbackEvent) => void
|
|
27
|
+
bindload?: (event: CommonCallbackEvent) => void
|
|
28
|
+
binderror?: (event: CommonCallbackEvent) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface PayloadData {
|
|
32
|
+
data?: Record<string, any>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type MessageData = {
|
|
36
|
+
payload?: PayloadData,
|
|
37
|
+
type?: string,
|
|
38
|
+
callbackId?: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface NativeEvent {
|
|
42
|
+
url: string,
|
|
43
|
+
data: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LoadRes {
|
|
47
|
+
timeStamp: string,
|
|
48
|
+
nativeEvent: NativeEvent
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface FormRef {
|
|
52
|
+
postMessage: (value: any) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element => {
|
|
56
|
+
const { src, bindmessage = noop, bindload = noop, binderror = noop } = props
|
|
57
|
+
|
|
58
|
+
const defaultWebViewStyle = [
|
|
59
|
+
{
|
|
60
|
+
position: 'absolute',
|
|
61
|
+
left: 0,
|
|
62
|
+
right: 0,
|
|
63
|
+
top: 0,
|
|
64
|
+
bottom: 0
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
const { nodeRef: webViewRef } = useNodesRef<WebView, WebViewProps>(props, ref, {
|
|
68
|
+
defaultStyle: StyleSheet.flatten([
|
|
69
|
+
...defaultWebViewStyle
|
|
70
|
+
])
|
|
71
|
+
})
|
|
72
|
+
const _messageList:any[] = []
|
|
73
|
+
const handleUnload = () => {
|
|
74
|
+
// 这里是 WebView 销毁前执行的逻辑
|
|
75
|
+
bindmessage(getCustomEvent('messsage', {}, {
|
|
76
|
+
detail: {
|
|
77
|
+
data: _messageList
|
|
78
|
+
},
|
|
79
|
+
layoutRef: webViewRef
|
|
80
|
+
}))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
// 组件卸载时执行
|
|
85
|
+
return () => {
|
|
86
|
+
handleUnload()
|
|
87
|
+
}
|
|
88
|
+
}, [])
|
|
89
|
+
const _load = function(res:LoadRes) {
|
|
90
|
+
const result = {
|
|
91
|
+
type: 'load',
|
|
92
|
+
timeStamp: res.timeStamp,
|
|
93
|
+
detail: {
|
|
94
|
+
src: res.nativeEvent?.url
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
bindload(result)
|
|
98
|
+
}
|
|
99
|
+
const _error = function(res:LoadRes) {
|
|
100
|
+
const result = {
|
|
101
|
+
type: 'error',
|
|
102
|
+
timeStamp: res.timeStamp,
|
|
103
|
+
detail: {
|
|
104
|
+
src: ''
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
binderror(result)
|
|
108
|
+
}
|
|
109
|
+
const _message = function(res:LoadRes) {
|
|
110
|
+
let data: MessageData
|
|
111
|
+
let asyncCallback
|
|
112
|
+
const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
|
|
113
|
+
try {
|
|
114
|
+
const nativeEventData = res.nativeEvent?.data
|
|
115
|
+
data = JSON.parse(nativeEventData)
|
|
116
|
+
} catch (e) {
|
|
117
|
+
data = {}
|
|
118
|
+
}
|
|
119
|
+
const postData:PayloadData = data.payload || {}
|
|
120
|
+
switch (data.type) {
|
|
121
|
+
case 'postMessage':
|
|
122
|
+
_messageList.push(postData.data)
|
|
123
|
+
asyncCallback = Promise.resolve({
|
|
124
|
+
errMsg: 'invokeWebappApi:ok'
|
|
125
|
+
})
|
|
126
|
+
break
|
|
127
|
+
case 'navigateTo':
|
|
128
|
+
asyncCallback = navObj.navigateTo(postData)
|
|
129
|
+
break
|
|
130
|
+
case 'navigateBack':
|
|
131
|
+
asyncCallback = navObj.navigateBack(postData)
|
|
132
|
+
break
|
|
133
|
+
case 'redirectTo':
|
|
134
|
+
asyncCallback = navObj.redirectTo(postData)
|
|
135
|
+
break
|
|
136
|
+
case 'switchTab':
|
|
137
|
+
asyncCallback = navObj.switchTab(postData)
|
|
138
|
+
break
|
|
139
|
+
case 'reLaunch':
|
|
140
|
+
asyncCallback = navObj.reLaunch(postData)
|
|
141
|
+
break
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
asyncCallback && asyncCallback.then((res: any) => {
|
|
145
|
+
if (webViewRef.current?.postMessage) {
|
|
146
|
+
const test = JSON.stringify({
|
|
147
|
+
type: data.type,
|
|
148
|
+
callbackId: data.callbackId,
|
|
149
|
+
result: res
|
|
150
|
+
})
|
|
151
|
+
webViewRef.current.postMessage(test)
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
// @ts-ignore
|
|
156
|
+
return(<Portal>
|
|
157
|
+
<WebView
|
|
158
|
+
style={[ ...defaultWebViewStyle ]}
|
|
159
|
+
source={{ uri: src }}
|
|
160
|
+
ref={webViewRef}
|
|
161
|
+
onLoad={_load}
|
|
162
|
+
onError={_error}
|
|
163
|
+
onMessage={_message}
|
|
164
|
+
javaScriptEnabled={true}
|
|
165
|
+
></WebView>
|
|
166
|
+
</Portal>)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
_WebView.displayName = 'mpx-web-view'
|
|
170
|
+
|
|
171
|
+
export default _WebView
|
|
@@ -3,7 +3,7 @@ import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'
|
|
|
3
3
|
|
|
4
4
|
export const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/
|
|
5
5
|
|
|
6
|
-
export const PERCENT_REGX =
|
|
6
|
+
export const PERCENT_REGX = /^\s*-?\d+(\.\d+)?%\s*$/
|
|
7
7
|
|
|
8
8
|
const URL_REGEX = /url\(["']?(.*?)["']?\)/
|
|
9
9
|
|
|
@@ -5,7 +5,7 @@ module.exports = function (style) {
|
|
|
5
5
|
}
|
|
6
6
|
const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
|
|
7
7
|
const parsedStyleObj = {}
|
|
8
|
-
const rpxRegExpG = /\b(
|
|
8
|
+
const rpxRegExpG = /\b(-?\d+(\.\d+)?)rpx\b/g
|
|
9
9
|
const parseStyleText = (cssText) => {
|
|
10
10
|
const listDelimiter = /;(?![^(]*\))/g
|
|
11
11
|
const propertyDelimiter = /:(.+)/
|
|
@@ -1121,12 +1121,12 @@ function getModelConfig (el, match) {
|
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
1124
|
-
function processEventReact (el
|
|
1124
|
+
function processEventReact (el) {
|
|
1125
1125
|
const eventConfigMap = {}
|
|
1126
1126
|
el.attrsList.forEach(function ({ name, value }) {
|
|
1127
1127
|
const parsedEvent = config[mode].event.parseEvent(name)
|
|
1128
1128
|
if (parsedEvent) {
|
|
1129
|
-
const type = parsedEvent.eventName
|
|
1129
|
+
const type = config[mode].event.getEvent(parsedEvent.eventName, parsedEvent.prefix)
|
|
1130
1130
|
const parsedFunc = parseFuncStr(value)
|
|
1131
1131
|
if (parsedFunc) {
|
|
1132
1132
|
if (!eventConfigMap[type]) {
|
|
@@ -1153,12 +1153,14 @@ function processEventReact (el, options, meta) {
|
|
|
1153
1153
|
// } else {
|
|
1154
1154
|
// stringifiedModelValue = stringify(modelValue)
|
|
1155
1155
|
// }
|
|
1156
|
-
|
|
1157
|
-
|
|
1156
|
+
// todo 未来可能需要支持类似modelEventPrefix这样的配置来声明model事件的绑定方式
|
|
1157
|
+
const modelEventType = config[mode].event.getEvent(modelEvent)
|
|
1158
|
+
if (!eventConfigMap[modelEventType]) {
|
|
1159
|
+
eventConfigMap[modelEventType] = {
|
|
1158
1160
|
configs: []
|
|
1159
1161
|
}
|
|
1160
1162
|
}
|
|
1161
|
-
eventConfigMap[
|
|
1163
|
+
eventConfigMap[modelEventType].configs.unshift({
|
|
1162
1164
|
hasArgs: true,
|
|
1163
1165
|
expStr: `[${stringify('__model')},${stringifiedModelValue},${stringify(eventIdentifier)},${stringify(modelValuePathArr)}${modelFilter ? `,${stringify(modelFilter)}` : ''}]`
|
|
1164
1166
|
})
|
|
@@ -1172,11 +1174,8 @@ function processEventReact (el, options, meta) {
|
|
|
1172
1174
|
}
|
|
1173
1175
|
|
|
1174
1176
|
// let wrapper
|
|
1175
|
-
|
|
1176
1177
|
for (const type in eventConfigMap) {
|
|
1177
1178
|
let { configs } = eventConfigMap[type]
|
|
1178
|
-
|
|
1179
|
-
let resultName
|
|
1180
1179
|
configs.forEach(({ name }) => {
|
|
1181
1180
|
if (name) {
|
|
1182
1181
|
// 清空原始事件绑定
|
|
@@ -1184,21 +1183,15 @@ function processEventReact (el, options, meta) {
|
|
|
1184
1183
|
do {
|
|
1185
1184
|
has = getAndRemoveAttr(el, name).has
|
|
1186
1185
|
} while (has)
|
|
1187
|
-
|
|
1188
|
-
if (!resultName) {
|
|
1189
|
-
// 清除修饰符
|
|
1190
|
-
resultName = name.replace(/\..*/, '')
|
|
1191
|
-
}
|
|
1192
1186
|
}
|
|
1193
1187
|
})
|
|
1194
1188
|
configs = configs.map((item) => {
|
|
1195
1189
|
return item.expStr
|
|
1196
1190
|
})
|
|
1197
|
-
const name = resultName || config[mode].event.getEvent(type)
|
|
1198
1191
|
const value = `{{(e)=>this.__invoke(e, [${configs}])}}`
|
|
1199
1192
|
addAttrs(el, [
|
|
1200
1193
|
{
|
|
1201
|
-
name,
|
|
1194
|
+
name: type,
|
|
1202
1195
|
value
|
|
1203
1196
|
}
|
|
1204
1197
|
])
|
|
@@ -1698,23 +1691,49 @@ function processFor (el) {
|
|
|
1698
1691
|
}
|
|
1699
1692
|
|
|
1700
1693
|
function processRefReact (el, meta) {
|
|
1701
|
-
const val = getAndRemoveAttr(el, config[mode].directive.ref)
|
|
1694
|
+
const { val, has } = getAndRemoveAttr(el, config[mode].directive.ref)
|
|
1695
|
+
|
|
1702
1696
|
// rn中只有内建组件能被作为node ref处理
|
|
1703
1697
|
const type = el.isBuiltIn ? 'node' : 'component'
|
|
1704
|
-
if (
|
|
1698
|
+
if (has) {
|
|
1705
1699
|
if (!meta.refs) {
|
|
1706
1700
|
meta.refs = []
|
|
1707
1701
|
}
|
|
1708
1702
|
const all = !!forScopes.length
|
|
1709
|
-
|
|
1703
|
+
const refConf = {
|
|
1710
1704
|
key: val,
|
|
1711
1705
|
all,
|
|
1712
1706
|
type
|
|
1713
|
-
}
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
if (!val) {
|
|
1710
|
+
refConf.key = `ref_rn_${++refId}`
|
|
1711
|
+
refConf.sKeys = []
|
|
1712
|
+
const rawId = el.attrsMap.id
|
|
1713
|
+
const rawClass = el.attrsMap.class
|
|
1714
|
+
const rawDynamicClass = el.attrsMap[config[mode].directive.dynamicClass]
|
|
1715
|
+
|
|
1716
|
+
meta.computed = meta.computed || []
|
|
1717
|
+
if (rawId) {
|
|
1718
|
+
const staticId = parseMustacheWithContext(rawId).result
|
|
1719
|
+
const computedIdKey = `_ri${refId}`
|
|
1720
|
+
refConf.sKeys.push({ key: computedIdKey, prefix: '#' })
|
|
1721
|
+
meta.computed.push(`${computedIdKey}() {\n return ${staticId}}`)
|
|
1722
|
+
}
|
|
1723
|
+
if (rawClass || rawDynamicClass) {
|
|
1724
|
+
const staticClass = parseMustacheWithContext(rawClass).result
|
|
1725
|
+
const dynamicClass = parseMustacheWithContext(rawDynamicClass).result
|
|
1726
|
+
const computedClassKey = `_rc${refId}`
|
|
1727
|
+
refConf.sKeys.push({ key: computedClassKey, prefix: '.' })
|
|
1728
|
+
meta.computed.push(`${computedClassKey}() {\n return this.__getClass(${staticClass}, ${dynamicClass})}`)
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
meta.refs.push(refConf)
|
|
1714
1733
|
|
|
1715
1734
|
addAttrs(el, [{
|
|
1716
1735
|
name: 'ref',
|
|
1717
|
-
value: `{{ this.__getRefVal('${
|
|
1736
|
+
value: `{{ this.__getRefVal('${refConf.key}') }}`
|
|
1718
1737
|
}])
|
|
1719
1738
|
}
|
|
1720
1739
|
}
|
|
@@ -2572,7 +2591,7 @@ function processElement (el, root, options, meta) {
|
|
|
2572
2591
|
processFor(el)
|
|
2573
2592
|
processRefReact(el, meta)
|
|
2574
2593
|
processStyleReact(el)
|
|
2575
|
-
processEventReact(el
|
|
2594
|
+
processEventReact(el)
|
|
2576
2595
|
processComponentIs(el, options)
|
|
2577
2596
|
processSlotReact(el)
|
|
2578
2597
|
processAttrs(el, options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.58",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"build": "rimraf ./lib/runtime/components/react/dist && tsc"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
+
"@ant-design/react-native": "^5.2.2",
|
|
83
84
|
"@types/babel-traverse": "^6.25.4",
|
|
84
85
|
"@types/babel-types": "^7.0.4",
|
|
85
86
|
"@types/react": "^18.2.79",
|
|
@@ -89,5 +90,5 @@
|
|
|
89
90
|
"engines": {
|
|
90
91
|
"node": ">=14.14.0"
|
|
91
92
|
},
|
|
92
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "49fe4c4bc46ff4bf87cd8adde37981d4b4134aa7"
|
|
93
94
|
}
|