@mpxjs/core 2.9.39 → 2.9.41-react.0
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/package.json +37 -3
- package/src/convertor/convertor.js +4 -1
- package/src/convertor/getConvertMode.js +3 -1
- package/src/convertor/wxToReact.js +31 -0
- package/src/core/proxy.js +27 -5
- package/src/core/transferOptions.js +9 -1
- package/src/{vuePlugin.js → external/vuePlugin.js} +1 -1
- package/src/index.js +6 -2
- package/src/platform/builtInMixins/directiveHelperMixin.android.js +2 -0
- package/src/platform/builtInMixins/directiveHelperMixin.ios.js +15 -0
- package/src/platform/builtInMixins/directiveHelperMixin.js +3 -0
- package/src/platform/builtInMixins/index.js +12 -2
- package/src/platform/builtInMixins/proxyEventMixin.android.js +2 -0
- package/src/platform/builtInMixins/proxyEventMixin.ios.js +49 -0
- package/src/platform/builtInMixins/proxyEventMixin.js +0 -11
- package/src/platform/builtInMixins/refsMixin.android.js +2 -0
- package/src/platform/builtInMixins/refsMixin.ios.js +311 -0
- package/src/platform/builtInMixins/styleHelperMixin.android.js +2 -0
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +141 -0
- package/src/platform/builtInMixins/styleHelperMixin.js +3 -0
- package/src/platform/createApp.android.js +2 -0
- package/src/platform/createApp.ios.js +103 -0
- package/src/platform/createApp.js +3 -5
- package/src/platform/export/api.web.js +1 -1
- package/src/platform/patch/ali/getDefaultOptions.js +4 -4
- package/src/platform/patch/index.js +9 -6
- package/src/platform/patch/react/getDefaultOptions.android.js +1 -0
- package/src/platform/patch/react/getDefaultOptions.ios.js +270 -0
- package/src/platform/patch/react/getDefaultOptions.js +1 -0
- package/src/platform/patch/swan/getDefaultOptions.js +1 -1
- package/src/platform/patch/web/getDefaultOptions.js +13 -3
- package/src/platform/patch/wx/getDefaultOptions.js +1 -1
- /package/src/{vue.js → external/vue.js} +0 -0
- /package/src/{vue.web.js → external/vue.web.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.41-react.0",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,18 +19,52 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.9.
|
|
22
|
+
"@mpxjs/utils": "^2.9.41-react.0",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@mpxjs/api-proxy": "^2.9.0",
|
|
28
28
|
"@mpxjs/store": "^2.9.0",
|
|
29
|
+
"@react-navigation/native": "^6.1.17",
|
|
30
|
+
"@react-navigation/native-stack": "^6.9.26",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"react-native": "^0.74.3",
|
|
33
|
+
"react-native-root-siblings": "^5.0.1",
|
|
29
34
|
"vue": "^2.7.10",
|
|
30
35
|
"vue-demi": "^0.14.6",
|
|
31
36
|
"vue-i18n": "^8.27.2",
|
|
32
37
|
"vue-i18n-bridge": "^9.2.2"
|
|
33
38
|
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"vue": {
|
|
41
|
+
"optional": true
|
|
42
|
+
},
|
|
43
|
+
"vue-demi": {
|
|
44
|
+
"optional": true
|
|
45
|
+
},
|
|
46
|
+
"vue-i18n": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"vue-i18n-bridge": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"react": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"react-native": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"@react-navigation/native": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"@react-navigation/native-stack": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"react-native-root-siblings": {
|
|
65
|
+
"optional": true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
34
68
|
"publishConfig": {
|
|
35
69
|
"registry": "https://registry.npmjs.org",
|
|
36
70
|
"access": "public"
|
|
@@ -47,5 +81,5 @@
|
|
|
47
81
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
82
|
},
|
|
49
83
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "1c9ae7527a257fad98f5536114e63415cea54271"
|
|
51
85
|
}
|
|
@@ -11,6 +11,7 @@ import wxToQqRule from './wxToQq'
|
|
|
11
11
|
import wxToTtRule from './wxToTt'
|
|
12
12
|
import wxToDdRule from './wxToDd'
|
|
13
13
|
import wxToJdRule from './wxToJd'
|
|
14
|
+
import wxToReactRule from './wxToReact'
|
|
14
15
|
|
|
15
16
|
// 根据当前环境获取的默认生命周期信息
|
|
16
17
|
let lifecycleInfo
|
|
@@ -55,7 +56,9 @@ const rulesMap = {
|
|
|
55
56
|
wxToQq: { ...defaultConvertRule, ...wxToQqRule },
|
|
56
57
|
wxToTt: { ...defaultConvertRule, ...wxToTtRule },
|
|
57
58
|
wxToDd: { ...defaultConvertRule, ...wxToDdRule },
|
|
58
|
-
wxToJd: { ...defaultConvertRule, ...wxToJdRule }
|
|
59
|
+
wxToJd: { ...defaultConvertRule, ...wxToJdRule },
|
|
60
|
+
wxToIos: { ...defaultConvertRule, ...wxToReactRule },
|
|
61
|
+
wxToAndroid: { ...defaultConvertRule, ...wxToReactRule }
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
export function getConvertRule (convertMode) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
error,
|
|
3
|
+
isDev
|
|
4
|
+
} from '@mpxjs/utils'
|
|
5
|
+
import { implemented } from '../core/implement'
|
|
6
|
+
|
|
7
|
+
// 暂不支持的wx选项,后期需要各种花式支持
|
|
8
|
+
const unsupported = ['relations', 'moved', 'definitionFilter', 'onShareAppMessage', 'options', 'behaviors', 'externalClasses']
|
|
9
|
+
|
|
10
|
+
function convertErrorDesc (key) {
|
|
11
|
+
error(`Options.${key} is not supported in runtime conversion from wx to react native.`, global.currentResource)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function notSupportTip (options) {
|
|
15
|
+
unsupported.forEach(key => {
|
|
16
|
+
if (options[key]) {
|
|
17
|
+
if (!implemented[key]) {
|
|
18
|
+
isDev && convertErrorDesc(key)
|
|
19
|
+
delete options[key]
|
|
20
|
+
} else if (implemented[key].remove) {
|
|
21
|
+
delete options[key]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
convert (options) {
|
|
29
|
+
notSupportTip(options)
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/core/proxy.js
CHANGED
|
@@ -27,7 +27,8 @@ import {
|
|
|
27
27
|
callWithErrorHandling,
|
|
28
28
|
warn,
|
|
29
29
|
error,
|
|
30
|
-
getEnvObj
|
|
30
|
+
getEnvObj,
|
|
31
|
+
isReact
|
|
31
32
|
} from '@mpxjs/utils'
|
|
32
33
|
import {
|
|
33
34
|
BEFORECREATE,
|
|
@@ -128,6 +129,8 @@ export default class MpxProxy {
|
|
|
128
129
|
this.forceUpdateAll = false
|
|
129
130
|
this.currentRenderTask = null
|
|
130
131
|
this.propsUpdatedFlag = false
|
|
132
|
+
// react专用,正确触发updated钩子
|
|
133
|
+
this.pendingUpdatedFlag = false
|
|
131
134
|
}
|
|
132
135
|
this.initApi()
|
|
133
136
|
}
|
|
@@ -150,7 +153,7 @@ export default class MpxProxy {
|
|
|
150
153
|
this.state = CREATED
|
|
151
154
|
this.callHook(CREATED)
|
|
152
155
|
|
|
153
|
-
if (__mpx_mode__ !== 'web') {
|
|
156
|
+
if (__mpx_mode__ !== 'web' && !isReact) {
|
|
154
157
|
this.initRender()
|
|
155
158
|
}
|
|
156
159
|
|
|
@@ -172,9 +175,9 @@ export default class MpxProxy {
|
|
|
172
175
|
|
|
173
176
|
mounted () {
|
|
174
177
|
if (this.state === CREATED) {
|
|
175
|
-
this.state = MOUNTED
|
|
176
178
|
// 用于处理refs等前置工作
|
|
177
179
|
this.callHook(BEFOREMOUNT)
|
|
180
|
+
this.state = MOUNTED
|
|
178
181
|
this.callHook(MOUNTED)
|
|
179
182
|
this.currentRenderTask && this.currentRenderTask.resolve()
|
|
180
183
|
}
|
|
@@ -199,8 +202,8 @@ export default class MpxProxy {
|
|
|
199
202
|
this.callHook(BEFOREUNMOUNT)
|
|
200
203
|
this.scope?.stop()
|
|
201
204
|
if (this.update) this.update.active = false
|
|
202
|
-
this.callHook(UNMOUNTED)
|
|
203
205
|
this.state = UNMOUNTED
|
|
206
|
+
this.callHook(UNMOUNTED)
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
isUnmounted () {
|
|
@@ -236,7 +239,12 @@ export default class MpxProxy {
|
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
initProps () {
|
|
239
|
-
|
|
242
|
+
if (isReact) {
|
|
243
|
+
// react模式下props内部对象透传无需深clone,依赖对象深层的数据响应触发子组件更新
|
|
244
|
+
this.props = this.target.__getProps()
|
|
245
|
+
} else {
|
|
246
|
+
this.props = diffAndCloneA(this.target.__getProps(this.options)).clone
|
|
247
|
+
}
|
|
240
248
|
reactive(this.props)
|
|
241
249
|
proxy(this.target, this.props, undefined, false, this.createProxyConflictHandler('props'))
|
|
242
250
|
}
|
|
@@ -642,6 +650,20 @@ export default class MpxProxy {
|
|
|
642
650
|
this.forceUpdateAll = true
|
|
643
651
|
}
|
|
644
652
|
|
|
653
|
+
if (isReact) {
|
|
654
|
+
// rn中不需要setdata
|
|
655
|
+
this.forceUpdateData = {}
|
|
656
|
+
this.forceUpdateAll = false
|
|
657
|
+
if (this.update) {
|
|
658
|
+
options.sync ? this.update() : queueJob(this.update)
|
|
659
|
+
}
|
|
660
|
+
if (callback) {
|
|
661
|
+
callback = callback.bind(this.target)
|
|
662
|
+
options.sync ? callback() : nextTick(callback)
|
|
663
|
+
}
|
|
664
|
+
return
|
|
665
|
+
}
|
|
666
|
+
|
|
645
667
|
if (this.effect) {
|
|
646
668
|
options.sync ? this.effect.run() : this.effect.update()
|
|
647
669
|
} else {
|
|
@@ -7,6 +7,10 @@ export default function transferOptions (options, type, needConvert = true) {
|
|
|
7
7
|
let currentInject
|
|
8
8
|
if (global.currentInject && global.currentInject.moduleId === global.currentModuleId) {
|
|
9
9
|
currentInject = global.currentInject
|
|
10
|
+
} else {
|
|
11
|
+
currentInject = {
|
|
12
|
+
moduleId: global.currentModuleId
|
|
13
|
+
}
|
|
10
14
|
}
|
|
11
15
|
// 文件编译路径
|
|
12
16
|
options.mpxFileResource = global.currentResource
|
|
@@ -18,8 +22,12 @@ export default function transferOptions (options, type, needConvert = true) {
|
|
|
18
22
|
// 编译计算属性注入
|
|
19
23
|
options.computed = Object.assign({}, currentInject.injectComputed, options.computed)
|
|
20
24
|
}
|
|
25
|
+
if (currentInject && currentInject.injectMethods) {
|
|
26
|
+
// 编译methods注入
|
|
27
|
+
options.methods = Object.assign({}, currentInject.injectMethods, options.methods)
|
|
28
|
+
}
|
|
21
29
|
if (currentInject && currentInject.injectOptions) {
|
|
22
|
-
// 编译
|
|
30
|
+
// 编译options注入,优先微信中的单独配置
|
|
23
31
|
options.options = Object.assign({}, currentInject.injectOptions, options.options)
|
|
24
32
|
}
|
|
25
33
|
if (currentInject && currentInject.pageEvents) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { walkChildren, parseSelector, error, hasOwn, collectDataset } from '@mpxjs/utils'
|
|
2
2
|
import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
|
|
3
3
|
import { EffectScope } from 'vue'
|
|
4
|
-
import { PausedState } from '
|
|
4
|
+
import { PausedState } from '../helper/const'
|
|
5
5
|
|
|
6
6
|
const hackEffectScope = () => {
|
|
7
7
|
EffectScope.prototype.pause = function () {
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Vue from './vue'
|
|
1
|
+
import Vue from './external/vue'
|
|
2
2
|
import { error, diffAndCloneA, hasOwn, makeMap } from '@mpxjs/utils'
|
|
3
3
|
import { APIs, InstanceAPIs } from './platform/export/api'
|
|
4
4
|
|
|
@@ -145,7 +145,11 @@ Mpx.config = {
|
|
|
145
145
|
hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
146
146
|
apiImplementations webview JSSDK接口 例如getlocation
|
|
147
147
|
*/
|
|
148
|
-
webviewConfig: {}
|
|
148
|
+
webviewConfig: {},
|
|
149
|
+
/**
|
|
150
|
+
* react-native 相关配置,用于挂载事件等,如 onShareAppMessage
|
|
151
|
+
*/
|
|
152
|
+
rnConfig: {}
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
global.__mpx = Mpx
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { warn, type } from '@mpxjs/utils'
|
|
2
|
+
export default function directiveHelperMixin () {
|
|
3
|
+
return {
|
|
4
|
+
methods: {
|
|
5
|
+
__getWxKey (item, key) {
|
|
6
|
+
const value = key === '*this' ? item : item[key]
|
|
7
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
8
|
+
return value
|
|
9
|
+
} else {
|
|
10
|
+
warn(`wx:key's value should return a string or a number, received: ${type(value)}`, this.__mpxProxy.options.mpxFileResource)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -11,10 +11,20 @@ import componentGenericsMixin from './componentGenericsMixin'
|
|
|
11
11
|
import getTabBarMixin from './getTabBarMixin'
|
|
12
12
|
import pageRouteMixin from './pageRouteMixin'
|
|
13
13
|
import { dynamicRefsMixin, dynamicRenderHelperMixin, dynamicSlotMixin } from '../../dynamic/dynamicRenderMixin'
|
|
14
|
+
import styleHelperMixin from './styleHelperMixin'
|
|
15
|
+
import directiveHelperMixin from './directiveHelperMixin'
|
|
16
|
+
import { isReact } from '@mpxjs/utils'
|
|
14
17
|
|
|
15
18
|
export default function getBuiltInMixins (options, type) {
|
|
16
|
-
let bulitInMixins
|
|
17
|
-
if (
|
|
19
|
+
let bulitInMixins
|
|
20
|
+
if (isReact) {
|
|
21
|
+
bulitInMixins = [
|
|
22
|
+
proxyEventMixin(),
|
|
23
|
+
directiveHelperMixin(),
|
|
24
|
+
styleHelperMixin(type),
|
|
25
|
+
refsMixin()
|
|
26
|
+
]
|
|
27
|
+
} else if (__mpx_mode__ === 'web') {
|
|
18
28
|
bulitInMixins = [
|
|
19
29
|
proxyEventMixin(),
|
|
20
30
|
refsMixin(),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { error } from '@mpxjs/utils'
|
|
2
|
+
import Mpx from '../../index'
|
|
3
|
+
|
|
4
|
+
export default function proxyEventMixin () {
|
|
5
|
+
const methods = {
|
|
6
|
+
__invoke (rawEvent, eventConfig = []) {
|
|
7
|
+
if (typeof Mpx.config.proxyEventHandler === 'function') {
|
|
8
|
+
try {
|
|
9
|
+
Mpx.config.proxyEventHandler(rawEvent)
|
|
10
|
+
} catch (e) {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const location = this.__mpxProxy.options.mpxFileResource
|
|
14
|
+
|
|
15
|
+
let returnedValue
|
|
16
|
+
eventConfig.forEach((item) => {
|
|
17
|
+
const callbackName = item[0]
|
|
18
|
+
if (callbackName) {
|
|
19
|
+
const params = item.length > 1
|
|
20
|
+
? item.slice(1).map(item => {
|
|
21
|
+
if (item === '__mpx_event__') {
|
|
22
|
+
return rawEvent
|
|
23
|
+
} else {
|
|
24
|
+
return item
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
: [rawEvent]
|
|
28
|
+
if (typeof this[callbackName] === 'function') {
|
|
29
|
+
returnedValue = this[callbackName].apply(this, params)
|
|
30
|
+
} else {
|
|
31
|
+
error(`Instance property [${callbackName}] is not function, please check.`, location)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
return returnedValue
|
|
36
|
+
}
|
|
37
|
+
// __model (expr, $event, valuePath = ['value'], filterMethod) {
|
|
38
|
+
// const innerFilter = {
|
|
39
|
+
// trim: val => typeof val === 'string' && val.trim()
|
|
40
|
+
// }
|
|
41
|
+
// const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
|
|
42
|
+
// const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' ? this[filterMethod](originValue) : originValue) : originValue
|
|
43
|
+
// setByPath(this, expr, value)
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
methods
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -18,7 +18,6 @@ export default function proxyEventMixin () {
|
|
|
18
18
|
}
|
|
19
19
|
const location = this.__mpxProxy.options.mpxFileResource
|
|
20
20
|
const type = $event.type
|
|
21
|
-
const emitMode = $event.detail && $event.detail.mpxEmit
|
|
22
21
|
if (!type) {
|
|
23
22
|
error('Event object must have [type] property!', location)
|
|
24
23
|
return
|
|
@@ -45,19 +44,9 @@ export default function proxyEventMixin () {
|
|
|
45
44
|
let returnedValue
|
|
46
45
|
curEventConfig.forEach((item) => {
|
|
47
46
|
const callbackName = item[0]
|
|
48
|
-
if (emitMode) {
|
|
49
|
-
$event = $event.detail.data
|
|
50
|
-
}
|
|
51
47
|
if (callbackName) {
|
|
52
48
|
const params = item.length > 1
|
|
53
49
|
? item.slice(1).map(item => {
|
|
54
|
-
// 暂不支持$event.xxx的写法
|
|
55
|
-
// if (/^\$event/.test(item)) {
|
|
56
|
-
// this.__mpxTempEvent = $event
|
|
57
|
-
// const value = getByPath(this, item.replace('$event', '__mpxTempEvent'))
|
|
58
|
-
// // 删除临时变量
|
|
59
|
-
// delete this.__mpxTempEvent
|
|
60
|
-
// return value
|
|
61
50
|
if (item === '__mpx_event__') {
|
|
62
51
|
return $event
|
|
63
52
|
} else {
|