@mpxjs/core 2.9.0-beta.1 → 2.9.0-beta.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/@types/index.d.ts +24 -10
- package/package.json +3 -3
- package/src/core/injectMixins.js +1 -1
- package/src/core/proxy.js +10 -5
- package/src/index.js +7 -1
- package/src/platform/builtInMixins/pageRouteMixin.js +13 -0
- package/src/platform/builtInMixins/proxyEventMixin.js +22 -17
- package/src/platform/builtInMixins/proxyEventMixin.web.js +5 -4
- package/src/platform/builtInMixins/refsMixin.web.js +1 -1
- package/src/platform/export/index.web.js +2 -2
- package/src/vuePlugin.js +33 -6
package/@types/index.d.ts
CHANGED
|
@@ -31,18 +31,22 @@ type ArrayType<T extends any[]> = T extends Array<infer R> ? R : never;
|
|
|
31
31
|
// Mpx types
|
|
32
32
|
type Data = object | (() => object)
|
|
33
33
|
|
|
34
|
-
type
|
|
34
|
+
type PropConstructor<T = any> = {
|
|
35
|
+
new (...args: any[]): T & {};
|
|
36
|
+
} | {
|
|
37
|
+
(): T;
|
|
38
|
+
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
type: PropType
|
|
38
|
-
optionalTypes?: Array<PropType>
|
|
39
|
-
value?: any
|
|
40
|
+
export type PropType<T> = PropConstructor<T>
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
type FullPropType<T> = {
|
|
43
|
+
type: PropType<T>;
|
|
44
|
+
value?: T;
|
|
45
|
+
optionalTypes?: PropType<T>[];
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
interface Properties {
|
|
45
|
-
[key: string]: WechatMiniprogram.Component.AllProperty
|
|
49
|
+
[key: string]: WechatMiniprogram.Component.AllProperty | PropType<any> | FullPropType<any>
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
interface Methods {
|
|
@@ -78,8 +82,12 @@ type PropValueType<Def> = Def extends {
|
|
|
78
82
|
}
|
|
79
83
|
? T
|
|
80
84
|
: Def extends (...args: any[]) => infer T
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
? T
|
|
86
|
+
: Def extends FullPropType<infer T>
|
|
87
|
+
? T
|
|
88
|
+
: Def extends PropType<infer T>
|
|
89
|
+
? T
|
|
90
|
+
: any;
|
|
83
91
|
|
|
84
92
|
type GetPropsType<T> = {
|
|
85
93
|
readonly [K in keyof T]: PropValueType<T[K]>
|
|
@@ -242,6 +250,11 @@ interface AnyConstructor {
|
|
|
242
250
|
prototype: any
|
|
243
251
|
}
|
|
244
252
|
|
|
253
|
+
interface WebviewConfig {
|
|
254
|
+
hostWhitelists?: Array<string>
|
|
255
|
+
apiImplementations?: object
|
|
256
|
+
}
|
|
257
|
+
|
|
245
258
|
interface MpxConfig {
|
|
246
259
|
useStrictDiff: boolean
|
|
247
260
|
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
|
|
@@ -251,7 +264,8 @@ interface MpxConfig {
|
|
|
251
264
|
proxyEventHandler: (e: Event) => any | null
|
|
252
265
|
setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => any | null
|
|
253
266
|
forceFlushSync: boolean,
|
|
254
|
-
webRouteConfig: object
|
|
267
|
+
webRouteConfig: object,
|
|
268
|
+
webviewConfig?: WebviewConfig
|
|
255
269
|
}
|
|
256
270
|
|
|
257
271
|
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.9.0-beta.
|
|
3
|
+
"version": "2.9.0-beta.3",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.9.0-beta.
|
|
22
|
+
"@mpxjs/utils": "^2.9.0-beta.3",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
25
25
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
48
|
},
|
|
49
49
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "521f0cec1231962f9c071c8b70499772a0a81fda"
|
|
51
51
|
}
|
package/src/core/injectMixins.js
CHANGED
package/src/core/proxy.js
CHANGED
|
@@ -26,7 +26,8 @@ import {
|
|
|
26
26
|
getFirstKey,
|
|
27
27
|
callWithErrorHandling,
|
|
28
28
|
warn,
|
|
29
|
-
error
|
|
29
|
+
error,
|
|
30
|
+
getEnvObj
|
|
30
31
|
} from '@mpxjs/utils'
|
|
31
32
|
import {
|
|
32
33
|
BEFORECREATE,
|
|
@@ -46,6 +47,8 @@ import {
|
|
|
46
47
|
|
|
47
48
|
let uid = 0
|
|
48
49
|
|
|
50
|
+
const envObj = getEnvObj()
|
|
51
|
+
|
|
49
52
|
class RenderTask {
|
|
50
53
|
resolved = false
|
|
51
54
|
|
|
@@ -236,14 +239,14 @@ export default class MpxProxy {
|
|
|
236
239
|
const setupResult = callWithErrorHandling(setup, this, 'setup function', [
|
|
237
240
|
this.props,
|
|
238
241
|
{
|
|
239
|
-
triggerEvent: this.target.triggerEvent.bind(this.target),
|
|
242
|
+
triggerEvent: this.target.triggerEvent ? this.target.triggerEvent.bind(this.target) : noop,
|
|
240
243
|
refs: this.target.$refs,
|
|
241
244
|
asyncRefs: this.target.$asyncRefs,
|
|
242
245
|
forceUpdate: this.forceUpdate.bind(this),
|
|
243
246
|
selectComponent: this.target.selectComponent.bind(this.target),
|
|
244
247
|
selectAllComponents: this.target.selectAllComponents.bind(this.target),
|
|
245
|
-
createSelectorQuery: this.target.createSelectorQuery.bind(this.target),
|
|
246
|
-
createIntersectionObserver: this.target.createIntersectionObserver.bind(this.target)
|
|
248
|
+
createSelectorQuery: this.target.createSelectorQuery ? this.target.createSelectorQuery.bind(this.target) : envObj.createSelectorQuery.bind(envObj),
|
|
249
|
+
createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj)
|
|
247
250
|
}
|
|
248
251
|
])
|
|
249
252
|
if (!isObject(setupResult)) {
|
|
@@ -605,7 +608,9 @@ export default class MpxProxy {
|
|
|
605
608
|
|
|
606
609
|
export let currentInstance = null
|
|
607
610
|
|
|
608
|
-
export const getCurrentInstance = () =>
|
|
611
|
+
export const getCurrentInstance = () => {
|
|
612
|
+
return currentInstance && { proxy: currentInstance?.target }
|
|
613
|
+
}
|
|
609
614
|
|
|
610
615
|
export const setCurrentInstance = (instance) => {
|
|
611
616
|
currentInstance = instance
|
package/src/index.js
CHANGED
|
@@ -137,7 +137,13 @@ Mpx.config = {
|
|
|
137
137
|
proxyEventHandler: null,
|
|
138
138
|
setDataHandler: null,
|
|
139
139
|
forceFlushSync: false,
|
|
140
|
-
webRouteConfig: {}
|
|
140
|
+
webRouteConfig: {},
|
|
141
|
+
/*
|
|
142
|
+
支持两个属性
|
|
143
|
+
hostWhitelists Array 类型 支持h5域名白名单安全校验
|
|
144
|
+
apiImplementations webview JSSDK接口 例如getlocation
|
|
145
|
+
*/
|
|
146
|
+
webviewConfig: {}
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
global.__mpx = Mpx
|
|
@@ -4,6 +4,19 @@ export default function pageRouteMixin (mixinType) {
|
|
|
4
4
|
return {
|
|
5
5
|
beforeCreate () {
|
|
6
6
|
this.route = this.$options.__mpxPageRoute || ''
|
|
7
|
+
},
|
|
8
|
+
methods: {
|
|
9
|
+
getOpenerEventChannel () {
|
|
10
|
+
const router = global.__mpxRouter
|
|
11
|
+
const eventChannel = router && router.eventChannelMap[this.route]
|
|
12
|
+
return eventChannel || {}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
methods: {
|
|
19
|
+
getOpenerEventChannel () {
|
|
7
20
|
}
|
|
8
21
|
}
|
|
9
22
|
}
|
|
@@ -89,29 +89,34 @@ export default function proxyEventMixin () {
|
|
|
89
89
|
}
|
|
90
90
|
if (__mpx_mode__ === 'ali') {
|
|
91
91
|
Object.assign(methods, {
|
|
92
|
-
triggerEvent (eventName, eventDetail) {
|
|
92
|
+
triggerEvent (eventName, eventDetail, e) {
|
|
93
93
|
const handlerName = eventName.replace(/^./, matched => matched.toUpperCase()).replace(/-([a-z])/g, (match, p1) => p1.toUpperCase())
|
|
94
94
|
const handler = this.props && (this.props['on' + handlerName] || this.props['catch' + handlerName])
|
|
95
95
|
if (handler && typeof handler === 'function') {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
id,
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
detail: eventDetail
|
|
96
|
+
let eventObj = {}
|
|
97
|
+
if (e) {
|
|
98
|
+
e.detail = Object.assign(e.detail, eventDetail)
|
|
99
|
+
eventObj = e
|
|
100
|
+
} else {
|
|
101
|
+
const dataset = collectDataset(this.props)
|
|
102
|
+
const id = this.props.id || ''
|
|
103
|
+
const timeStamp = +new Date()
|
|
104
|
+
eventObj = {
|
|
105
|
+
type: eventName,
|
|
106
|
+
timeStamp,
|
|
107
|
+
target: { id, dataset, targetDataset: dataset },
|
|
108
|
+
currentTarget: { id, dataset },
|
|
109
|
+
detail: eventDetail
|
|
110
|
+
}
|
|
112
111
|
}
|
|
113
112
|
handler.call(this, eventObj)
|
|
114
113
|
}
|
|
114
|
+
},
|
|
115
|
+
__proxyEvent (e) {
|
|
116
|
+
const eventName = e.type
|
|
117
|
+
// 保持和微信一致
|
|
118
|
+
e.target = e.currentTarget
|
|
119
|
+
this.triggerEvent(eventName, {}, e)
|
|
115
120
|
}
|
|
116
121
|
})
|
|
117
122
|
}
|
|
@@ -19,10 +19,11 @@ export default function proxyEventMixin () {
|
|
|
19
19
|
const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
|
|
20
20
|
setByPath(this, expr, value)
|
|
21
21
|
},
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
__proxyEvent (e) {
|
|
23
|
+
const type = e.type
|
|
24
|
+
// 保持和微信一致 target 和 currentTarget 相同
|
|
25
|
+
e.target = e.currentTarget
|
|
26
|
+
this.triggerEvent(type, {}, e)
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -8,7 +8,7 @@ function getEl (ref) {
|
|
|
8
8
|
|
|
9
9
|
function processRefs (refs) {
|
|
10
10
|
Object.keys(refs).forEach((key) => {
|
|
11
|
-
const matched = /^__mpx_ref_(
|
|
11
|
+
const matched = /^__mpx_ref_(.+)__$/.exec(key)
|
|
12
12
|
const rKey = matched && matched[1]
|
|
13
13
|
if (rKey) {
|
|
14
14
|
const ref = refs[key]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
effectScope as vueEffectScope,
|
|
3
|
-
getCurrentScope as
|
|
3
|
+
getCurrentScope as vueGetCurrentScope,
|
|
4
4
|
onScopeDispose
|
|
5
5
|
} from 'vue'
|
|
6
6
|
|
|
@@ -42,7 +42,7 @@ const fixEffectScope = (scope) => {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
|
|
45
|
-
const getCurrentScope = () => fixEffectScope(
|
|
45
|
+
const getCurrentScope = () => fixEffectScope(vueGetCurrentScope())
|
|
46
46
|
|
|
47
47
|
export {
|
|
48
48
|
// effectScope
|
package/src/vuePlugin.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
|
-
import { walkChildren, parseSelector, error } from '@mpxjs/utils'
|
|
1
|
+
import { walkChildren, parseSelector, error, hasOwn } from '@mpxjs/utils'
|
|
2
2
|
import * as webApi from '@mpxjs/api-proxy/src/web/api'
|
|
3
|
+
const datasetReg = /^data-(.+)$/
|
|
4
|
+
|
|
5
|
+
function collectDataset (attrs) {
|
|
6
|
+
const dataset = {}
|
|
7
|
+
for (const key in attrs) {
|
|
8
|
+
if (hasOwn(attrs, key)) {
|
|
9
|
+
const matched = datasetReg.exec(key)
|
|
10
|
+
if (matched) {
|
|
11
|
+
dataset[matched[1]] = attrs[key]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return dataset
|
|
16
|
+
}
|
|
3
17
|
|
|
4
18
|
export default function install (Vue) {
|
|
5
|
-
Vue.prototype.triggerEvent = function (eventName, eventDetail) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
detail
|
|
9
|
-
|
|
19
|
+
Vue.prototype.triggerEvent = function (eventName, eventDetail, e) {
|
|
20
|
+
let eventObj = {}
|
|
21
|
+
if (e) {
|
|
22
|
+
e.detail = Object.assign(e.detail, eventDetail)
|
|
23
|
+
eventObj = e
|
|
24
|
+
} else {
|
|
25
|
+
const dataset = collectDataset(this.$attrs)
|
|
26
|
+
const id = this.$attrs.id || ''
|
|
27
|
+
const timeStamp = +new Date()
|
|
28
|
+
eventObj = {
|
|
29
|
+
type: eventName,
|
|
30
|
+
timeStamp,
|
|
31
|
+
target: { id, dataset, targetDataset: dataset },
|
|
32
|
+
currentTarget: { id, dataset },
|
|
33
|
+
detail: eventDetail
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return this.$emit(eventName, eventObj)
|
|
10
37
|
}
|
|
11
38
|
Vue.prototype.selectComponent = function (selector, all) {
|
|
12
39
|
const result = []
|