@mpxjs/webpack-plugin 2.9.56 → 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/base.styl +27 -0
- package/lib/runtime/components/react/dist/event.config.js +27 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +230 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +270 -0
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +229 -0
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +6 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +203 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +294 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +353 -0
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +57 -0
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +1 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +25 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +67 -0
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +27 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +307 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +115 -0
- package/lib/runtime/components/react/dist/types/getInnerListeners.js +1 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +25 -0
- package/lib/runtime/components/react/dist/utils.js +80 -0
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-button.tsx +1 -2
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +171 -0
- package/lib/runtime/components/react/{getInnerListeners.type.ts → types/getInnerListeners.ts} +2 -2
- package/lib/runtime/components/react/types/global.d.ts +15 -0
- package/lib/runtime/components/react/utils.ts +1 -1
- package/lib/runtime/optionProcessor.js +27 -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 +104 -42
- package/lib/web/processTemplate.js +1 -1
- package/package.json +8 -4
|
@@ -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
|
package/lib/runtime/components/react/{getInnerListeners.type.ts → types/getInnerListeners.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MutableRefObject } from 'react'
|
|
2
2
|
import { NativeSyntheticEvent } from 'react-native'
|
|
3
3
|
|
|
4
|
-
type LayoutRef =
|
|
4
|
+
type LayoutRef = MutableRefObject<any>
|
|
5
5
|
|
|
6
6
|
type SetTimeoutReturnType = ReturnType<typeof setTimeout>
|
|
7
7
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare module 'react-native-svg/css' {
|
|
2
|
+
import type { ImageSourcePropType, StyleProp, ImageStyle } from 'react-native'
|
|
3
|
+
import type { SvgProps as SvgCssUriProps } from 'react-native-svg'
|
|
4
|
+
|
|
5
|
+
export const SvgCssUri: React.ComponentType<SvgCssUriProps & { uri?: string }>
|
|
6
|
+
|
|
7
|
+
export interface WithLocalSvgProps {
|
|
8
|
+
asset: ImageSourcePropType
|
|
9
|
+
style?: StyleProp<ImageStyle>
|
|
10
|
+
width?: string | number
|
|
11
|
+
height?: string | number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const WithLocalSvg: React.ComponentType<WithLocalSvgProps>
|
|
15
|
+
}
|
|
@@ -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
|
|
|
@@ -75,7 +75,32 @@ registered in parent context!`)
|
|
|
75
75
|
if (outputPath) {
|
|
76
76
|
option.componentPath = '/' + outputPath
|
|
77
77
|
}
|
|
78
|
+
if (ctorType === 'app') {
|
|
79
|
+
option.data = function () {
|
|
80
|
+
return {
|
|
81
|
+
transitionName: ''
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
option.watch = {
|
|
85
|
+
$route: {
|
|
86
|
+
handler () {
|
|
87
|
+
const actionType = global.__mpxRouter.currentActionType
|
|
78
88
|
|
|
89
|
+
switch (actionType) {
|
|
90
|
+
case 'to':
|
|
91
|
+
this.transitionName = 'mpx-slide-left'
|
|
92
|
+
break
|
|
93
|
+
case 'back':
|
|
94
|
+
this.transitionName = 'mpx-slide-right'
|
|
95
|
+
break
|
|
96
|
+
default:
|
|
97
|
+
this.transitionName = ''
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
immediate: true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
79
104
|
return option
|
|
80
105
|
}
|
|
81
106
|
|
|
@@ -160,6 +185,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
160
185
|
global.__mpxRouter.needCache = null
|
|
161
186
|
global.__mpxRouter.needRemove = []
|
|
162
187
|
global.__mpxRouter.eventChannelMap = {}
|
|
188
|
+
global.__mpxRouter.currentActionType = null
|
|
163
189
|
// 处理reLaunch中传递的url并非首页时的replace逻辑
|
|
164
190
|
global.__mpxRouter.beforeEach(function (to, from, next) {
|
|
165
191
|
let action = global.__mpxRouter.__mpxAction
|
|
@@ -178,7 +204,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
178
204
|
}
|
|
179
205
|
}
|
|
180
206
|
}
|
|
181
|
-
|
|
207
|
+
global.__mpxRouter.currentActionType = action.type
|
|
182
208
|
const pageInRoutes = routes.some(item => item.path === to.path)
|
|
183
209
|
if (!pageInRoutes) {
|
|
184
210
|
if (stack.length < 1) {
|
|
@@ -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 = /:(.+)/
|
|
@@ -1094,12 +1094,39 @@ function processStyleReact (el) {
|
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
1096
|
|
|
1097
|
-
function
|
|
1097
|
+
function getModelConfig (el, match) {
|
|
1098
|
+
const modelProp = getAndRemoveAttr(el, config[mode].directive.modelProp).val || config[mode].event.defaultModelProp
|
|
1099
|
+
const modelEvent = getAndRemoveAttr(el, config[mode].directive.modelEvent).val || config[mode].event.defaultModelEvent
|
|
1100
|
+
const modelValuePathRaw = getAndRemoveAttr(el, config[mode].directive.modelValuePath).val
|
|
1101
|
+
const modelValuePath = modelValuePathRaw === undefined ? config[mode].event.defaultModelValuePath : modelValuePathRaw
|
|
1102
|
+
const modelFilter = getAndRemoveAttr(el, config[mode].directive.modelFilter).val
|
|
1103
|
+
let modelValuePathArr
|
|
1104
|
+
try {
|
|
1105
|
+
modelValuePathArr = JSON5.parse(modelValuePath)
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
if (modelValuePath === '') {
|
|
1108
|
+
modelValuePathArr = []
|
|
1109
|
+
} else {
|
|
1110
|
+
modelValuePathArr = modelValuePath.split('.')
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
const modelValue = match[1].trim()
|
|
1114
|
+
const stringifiedModelValue = stringifyWithResolveComputed(modelValue)
|
|
1115
|
+
return {
|
|
1116
|
+
modelProp,
|
|
1117
|
+
modelEvent,
|
|
1118
|
+
modelFilter,
|
|
1119
|
+
modelValuePathArr,
|
|
1120
|
+
stringifiedModelValue
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function processEventReact (el) {
|
|
1098
1125
|
const eventConfigMap = {}
|
|
1099
1126
|
el.attrsList.forEach(function ({ name, value }) {
|
|
1100
1127
|
const parsedEvent = config[mode].event.parseEvent(name)
|
|
1101
1128
|
if (parsedEvent) {
|
|
1102
|
-
const type = parsedEvent.eventName
|
|
1129
|
+
const type = config[mode].event.getEvent(parsedEvent.eventName, parsedEvent.prefix)
|
|
1103
1130
|
const parsedFunc = parseFuncStr(value)
|
|
1104
1131
|
if (parsedFunc) {
|
|
1105
1132
|
if (!eventConfigMap[type]) {
|
|
@@ -1112,12 +1139,43 @@ function processEventReact (el, options, meta) {
|
|
|
1112
1139
|
}
|
|
1113
1140
|
})
|
|
1114
1141
|
|
|
1115
|
-
|
|
1142
|
+
const modelExp = getAndRemoveAttr(el, config[mode].directive.model).val
|
|
1143
|
+
if (modelExp) {
|
|
1144
|
+
const match = tagRE.exec(modelExp)
|
|
1145
|
+
if (match) {
|
|
1146
|
+
const { modelProp, modelEvent, modelFilter, modelValuePathArr, stringifiedModelValue } = getModelConfig(el, match)
|
|
1147
|
+
if (!isValidIdentifierStr(modelEvent)) {
|
|
1148
|
+
warn$1(`EventName ${modelEvent} which is used in ${config[mode].directive.model} must be a valid identifier!`)
|
|
1149
|
+
return
|
|
1150
|
+
}
|
|
1151
|
+
// if (forScopes.length) {
|
|
1152
|
+
// stringifiedModelValue = stringifyWithResolveComputed(modelValue)
|
|
1153
|
+
// } else {
|
|
1154
|
+
// stringifiedModelValue = stringify(modelValue)
|
|
1155
|
+
// }
|
|
1156
|
+
// todo 未来可能需要支持类似modelEventPrefix这样的配置来声明model事件的绑定方式
|
|
1157
|
+
const modelEventType = config[mode].event.getEvent(modelEvent)
|
|
1158
|
+
if (!eventConfigMap[modelEventType]) {
|
|
1159
|
+
eventConfigMap[modelEventType] = {
|
|
1160
|
+
configs: []
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
eventConfigMap[modelEventType].configs.unshift({
|
|
1164
|
+
hasArgs: true,
|
|
1165
|
+
expStr: `[${stringify('__model')},${stringifiedModelValue},${stringify(eventIdentifier)},${stringify(modelValuePathArr)}${modelFilter ? `,${stringify(modelFilter)}` : ''}]`
|
|
1166
|
+
})
|
|
1167
|
+
addAttrs(el, [
|
|
1168
|
+
{
|
|
1169
|
+
name: modelProp,
|
|
1170
|
+
value: modelExp
|
|
1171
|
+
}
|
|
1172
|
+
])
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1116
1175
|
|
|
1176
|
+
// let wrapper
|
|
1117
1177
|
for (const type in eventConfigMap) {
|
|
1118
1178
|
let { configs } = eventConfigMap[type]
|
|
1119
|
-
|
|
1120
|
-
let resultName
|
|
1121
1179
|
configs.forEach(({ name }) => {
|
|
1122
1180
|
if (name) {
|
|
1123
1181
|
// 清空原始事件绑定
|
|
@@ -1125,21 +1183,15 @@ function processEventReact (el, options, meta) {
|
|
|
1125
1183
|
do {
|
|
1126
1184
|
has = getAndRemoveAttr(el, name).has
|
|
1127
1185
|
} while (has)
|
|
1128
|
-
|
|
1129
|
-
if (!resultName) {
|
|
1130
|
-
// 清除修饰符
|
|
1131
|
-
resultName = name.replace(/\..*/, '')
|
|
1132
|
-
}
|
|
1133
1186
|
}
|
|
1134
1187
|
})
|
|
1135
1188
|
configs = configs.map((item) => {
|
|
1136
1189
|
return item.expStr
|
|
1137
1190
|
})
|
|
1138
|
-
const name = resultName || config[mode].event.getEvent(type)
|
|
1139
1191
|
const value = `{{(e)=>this.__invoke(e, [${configs}])}}`
|
|
1140
1192
|
addAttrs(el, [
|
|
1141
1193
|
{
|
|
1142
|
-
name,
|
|
1194
|
+
name: type,
|
|
1143
1195
|
value
|
|
1144
1196
|
}
|
|
1145
1197
|
])
|
|
@@ -1166,12 +1218,12 @@ function processEventReact (el, options, meta) {
|
|
|
1166
1218
|
// }
|
|
1167
1219
|
}
|
|
1168
1220
|
|
|
1169
|
-
if (wrapper) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
}
|
|
1221
|
+
// if (wrapper) {
|
|
1222
|
+
// replaceNode(el, wrapper, true)
|
|
1223
|
+
// addChild(wrapper, el)
|
|
1224
|
+
// processAttrs(wrapper, options)
|
|
1225
|
+
// postMoveBaseDirective(wrapper, el)
|
|
1226
|
+
// }
|
|
1175
1227
|
}
|
|
1176
1228
|
|
|
1177
1229
|
function processEvent (el, options) {
|
|
@@ -1204,27 +1256,11 @@ function processEvent (el, options) {
|
|
|
1204
1256
|
if (modelExp) {
|
|
1205
1257
|
const match = tagRE.exec(modelExp)
|
|
1206
1258
|
if (match) {
|
|
1207
|
-
const modelProp =
|
|
1208
|
-
const modelEvent = getAndRemoveAttr(el, config[mode].directive.modelEvent).val || config[mode].event.defaultModelEvent
|
|
1209
|
-
const modelValuePathRaw = getAndRemoveAttr(el, config[mode].directive.modelValuePath).val
|
|
1210
|
-
const modelValuePath = modelValuePathRaw === undefined ? config[mode].event.defaultModelValuePath : modelValuePathRaw
|
|
1211
|
-
const modelFilter = getAndRemoveAttr(el, config[mode].directive.modelFilter).val
|
|
1212
|
-
let modelValuePathArr
|
|
1213
|
-
try {
|
|
1214
|
-
modelValuePathArr = JSON5.parse(modelValuePath)
|
|
1215
|
-
} catch (e) {
|
|
1216
|
-
if (modelValuePath === '') {
|
|
1217
|
-
modelValuePathArr = []
|
|
1218
|
-
} else {
|
|
1219
|
-
modelValuePathArr = modelValuePath.split('.')
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1259
|
+
const { modelProp, modelEvent, modelFilter, modelValuePathArr, stringifiedModelValue } = getModelConfig(el, match)
|
|
1222
1260
|
if (!isValidIdentifierStr(modelEvent)) {
|
|
1223
1261
|
warn$1(`EventName ${modelEvent} which is used in ${config[mode].directive.model} must be a valid identifier!`)
|
|
1224
1262
|
return
|
|
1225
1263
|
}
|
|
1226
|
-
const modelValue = match[1].trim()
|
|
1227
|
-
const stringifiedModelValue = stringifyWithResolveComputed(modelValue)
|
|
1228
1264
|
// if (forScopes.length) {
|
|
1229
1265
|
// stringifiedModelValue = stringifyWithResolveComputed(modelValue)
|
|
1230
1266
|
// } else {
|
|
@@ -1655,23 +1691,49 @@ function processFor (el) {
|
|
|
1655
1691
|
}
|
|
1656
1692
|
|
|
1657
1693
|
function processRefReact (el, meta) {
|
|
1658
|
-
const val = getAndRemoveAttr(el, config[mode].directive.ref)
|
|
1694
|
+
const { val, has } = getAndRemoveAttr(el, config[mode].directive.ref)
|
|
1695
|
+
|
|
1659
1696
|
// rn中只有内建组件能被作为node ref处理
|
|
1660
1697
|
const type = el.isBuiltIn ? 'node' : 'component'
|
|
1661
|
-
if (
|
|
1698
|
+
if (has) {
|
|
1662
1699
|
if (!meta.refs) {
|
|
1663
1700
|
meta.refs = []
|
|
1664
1701
|
}
|
|
1665
1702
|
const all = !!forScopes.length
|
|
1666
|
-
|
|
1703
|
+
const refConf = {
|
|
1667
1704
|
key: val,
|
|
1668
1705
|
all,
|
|
1669
1706
|
type
|
|
1670
|
-
}
|
|
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)
|
|
1671
1733
|
|
|
1672
1734
|
addAttrs(el, [{
|
|
1673
1735
|
name: 'ref',
|
|
1674
|
-
value: `{{ this.__getRefVal('${
|
|
1736
|
+
value: `{{ this.__getRefVal('${refConf.key}') }}`
|
|
1675
1737
|
}])
|
|
1676
1738
|
}
|
|
1677
1739
|
}
|
|
@@ -2173,7 +2235,7 @@ function processBuiltInComponents (el, meta) {
|
|
|
2173
2235
|
const tag = el.tag
|
|
2174
2236
|
if (!meta.builtInComponentsMap[tag]) {
|
|
2175
2237
|
if (isReact(mode)) {
|
|
2176
|
-
meta.builtInComponentsMap[tag] = `${builtInComponentsPrefix}/react/${tag}`
|
|
2238
|
+
meta.builtInComponentsMap[tag] = `${builtInComponentsPrefix}/react/dist/${tag}`
|
|
2177
2239
|
} else {
|
|
2178
2240
|
meta.builtInComponentsMap[tag] = `${builtInComponentsPrefix}/${mode}/${tag}`
|
|
2179
2241
|
}
|
|
@@ -2529,7 +2591,7 @@ function processElement (el, root, options, meta) {
|
|
|
2529
2591
|
processFor(el)
|
|
2530
2592
|
processRefReact(el, meta)
|
|
2531
2593
|
processStyleReact(el)
|
|
2532
|
-
processEventReact(el
|
|
2594
|
+
processEventReact(el)
|
|
2533
2595
|
processComponentIs(el, options)
|
|
2534
2596
|
processSlotReact(el)
|
|
2535
2597
|
processAttrs(el, options)
|
|
@@ -38,7 +38,7 @@ module.exports = function (template, {
|
|
|
38
38
|
const idName = (el && el.match(/#(.*)/) && el.match(/#(.*)/)[1]) || 'app'
|
|
39
39
|
template = {
|
|
40
40
|
tag: 'template',
|
|
41
|
-
content: `<div id="${idName}"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></div>`
|
|
41
|
+
content: `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
|
|
42
42
|
}
|
|
43
43
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
44
44
|
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
|
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"
|
|
@@ -76,15 +76,19 @@
|
|
|
76
76
|
"url": "https://github.com/didi/mpx/issues"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
|
-
"test": "jest"
|
|
79
|
+
"test": "jest",
|
|
80
|
+
"build": "rimraf ./lib/runtime/components/react/dist && tsc"
|
|
80
81
|
},
|
|
81
82
|
"devDependencies": {
|
|
83
|
+
"@ant-design/react-native": "^5.2.2",
|
|
82
84
|
"@types/babel-traverse": "^6.25.4",
|
|
83
85
|
"@types/babel-types": "^7.0.4",
|
|
84
|
-
"@types/react": "^18.2.79"
|
|
86
|
+
"@types/react": "^18.2.79",
|
|
87
|
+
"react-native": "^0.74.5",
|
|
88
|
+
"rimraf": "^6.0.1"
|
|
85
89
|
},
|
|
86
90
|
"engines": {
|
|
87
91
|
"node": ">=14.14.0"
|
|
88
92
|
},
|
|
89
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "49fe4c4bc46ff4bf87cd8adde37981d4b4134aa7"
|
|
90
94
|
}
|