@mpxjs/core 2.7.52 → 2.8.0-beta.2
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 +342 -27
- package/package.json +10 -5
- package/src/convertor/convertor.js +2 -2
- package/src/convertor/mergeLifecycle.js +4 -4
- package/src/convertor/wxToAli.js +3 -4
- package/src/convertor/wxToSwan.js +2 -2
- package/src/convertor/wxToTt.js +1 -10
- package/src/convertor/wxToWeb.js +14 -7
- package/src/core/implement.js +2 -2
- package/src/core/injectMixins.js +1 -1
- package/src/core/innerLifecycle.js +15 -2
- package/src/core/mergeOptions.js +11 -5
- package/src/core/proxy.js +343 -229
- package/src/core/transferOptions.js +5 -2
- package/src/helper/const.js +10 -0
- package/src/index.js +73 -147
- package/src/observer/array.js +12 -17
- package/src/observer/computed.js +27 -56
- package/src/observer/dep.js +1 -1
- package/src/observer/effect.js +113 -0
- package/src/observer/effectScope.js +109 -0
- package/src/observer/{index.js → reactive.js} +74 -70
- package/src/observer/ref.js +97 -0
- package/src/observer/scheduler.js +171 -56
- package/src/observer/watch.js +163 -39
- package/src/platform/builtInMixins/i18nMixin.js +238 -31
- package/src/platform/builtInMixins/pageScrollMixin.web.js +4 -5
- package/src/platform/builtInMixins/pageStatusMixin.js +76 -54
- package/src/platform/builtInMixins/pageStatusMixin.web.js +35 -22
- package/src/platform/builtInMixins/proxyEventMixin.js +40 -22
- package/src/platform/builtInMixins/proxyEventMixin.web.js +16 -24
- package/src/platform/builtInMixins/refsMixin.js +82 -73
- package/src/platform/builtInMixins/refsMixin.web.js +0 -47
- package/src/platform/builtInMixins/relationsMixin.js +10 -9
- package/src/platform/builtInMixins/renderHelperMixin.js +1 -1
- package/src/platform/builtInMixins/showMixin.js +1 -1
- package/src/platform/createApp.js +5 -5
- package/src/platform/export/api.js +23 -0
- package/src/platform/export/api.web.js +26 -0
- package/src/platform/export/index.js +45 -0
- package/src/platform/export/index.web.js +36 -0
- package/src/platform/index.js +1 -5
- package/src/platform/patch/ali/getDefaultOptions.js +33 -31
- package/src/platform/patch/ali/lifecycle.js +21 -13
- package/src/platform/patch/builtInKeysMap.js +2 -1
- package/src/platform/patch/index.js +4 -9
- package/src/platform/patch/swan/getDefaultOptions.js +3 -3
- package/src/platform/patch/swan/lifecycle.js +17 -14
- package/src/platform/patch/web/getDefaultOptions.js +40 -16
- package/src/platform/patch/web/lifecycle.js +6 -3
- package/src/platform/patch/wx/getDefaultOptions.js +38 -31
- package/src/platform/patch/wx/lifecycle.js +18 -11
- package/src/runtime/createFactory.js +6 -2
- package/src/vue.web.js +3 -0
- package/src/vuePlugin.js +31 -0
- package/src/core/createStore.js +0 -241
- package/src/core/mapStore.js +0 -94
- package/src/helper/env.js +0 -20
- package/src/helper/getByPath.js +0 -127
- package/src/helper/log.js +0 -31
- package/src/helper/utils.js +0 -652
- package/src/observer/watcher.js +0 -244
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CREATED,
|
|
3
|
+
ONHIDE,
|
|
4
|
+
ONSHOW,
|
|
5
|
+
ONLOAD
|
|
6
|
+
} from '../../core/innerLifecycle'
|
|
7
|
+
import { isFunction, isBrowser } from '@mpxjs/utils'
|
|
3
8
|
|
|
4
9
|
let systemInfo = {}
|
|
5
10
|
|
|
6
11
|
let count = 0
|
|
7
12
|
|
|
8
13
|
function getCurrentPageInstance () {
|
|
9
|
-
|
|
14
|
+
const vnode = global.__mpxRouter && global.__mpxRouter.__mpxActiveVnode
|
|
10
15
|
let pageInstance
|
|
11
16
|
if (vnode && vnode.componentInstance) {
|
|
12
17
|
pageInstance = vnode.tag.endsWith('mpx-tab-bar-container') ? vnode.componentInstance.$children[1] : vnode.componentInstance
|
|
@@ -33,14 +38,12 @@ function onResize () {
|
|
|
33
38
|
|
|
34
39
|
if (_t) {
|
|
35
40
|
_t.mpxPageStatus = `resize${count++}`
|
|
36
|
-
|
|
37
|
-
_t.onResize(systemInfo)
|
|
38
|
-
}
|
|
41
|
+
isFunction(_t.onResize) && _t.onResize(systemInfo)
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
// listen resize
|
|
43
|
-
if (
|
|
46
|
+
if (isBrowser) {
|
|
44
47
|
window.addEventListener('resize', onResize)
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -52,31 +55,41 @@ export default function pageStatusMixin (mixinType) {
|
|
|
52
55
|
},
|
|
53
56
|
activated () {
|
|
54
57
|
this.mpxPageStatus = 'show'
|
|
55
|
-
this.
|
|
58
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
56
59
|
},
|
|
57
60
|
deactivated () {
|
|
58
61
|
this.mpxPageStatus = 'hide'
|
|
59
|
-
this.
|
|
62
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
63
|
+
},
|
|
64
|
+
created () {
|
|
65
|
+
// onLoad应该在用户声明周期CREATED后再执行,故此处使用原生created声明周期来触发onLoad
|
|
66
|
+
const query = (global.__mpxRouter && global.__mpxRouter.currentRoute && global.__mpxRouter.currentRoute.query) || {}
|
|
67
|
+
this.__mpxProxy.callHook(ONLOAD, [query])
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
return {
|
|
64
72
|
[CREATED] () {
|
|
65
|
-
|
|
66
|
-
if (!pageInstance)
|
|
67
|
-
|
|
68
|
-
() => pageInstance.mpxPageStatus,
|
|
69
|
-
status => {
|
|
73
|
+
const pageInstance = getCurrentPageInstance()
|
|
74
|
+
if (!pageInstance) {
|
|
75
|
+
this.$watch(() => pageInstance.mpxPageStatus, status => {
|
|
70
76
|
if (!status) return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (status === 'show') this.__mpxProxy.callHook(ONSHOW)
|
|
78
|
+
if (status === 'hide') this.__mpxProxy.callHook(ONHIDE)
|
|
79
|
+
const pageLifetimes = this.__mpxProxy.options.pageLifetimes
|
|
80
|
+
if (pageLifetimes) {
|
|
81
|
+
if (/^resize/.test(status) && isFunction(pageLifetimes.resize)) {
|
|
82
|
+
// resize
|
|
83
|
+
pageLifetimes.resize.call(this, systemInfo)
|
|
84
|
+
} else if (isFunction(pageLifetimes[status])) {
|
|
85
|
+
// show & hide
|
|
86
|
+
pageLifetimes[status].call(this)
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
89
|
+
}, {
|
|
90
|
+
sync: true
|
|
91
|
+
})
|
|
92
|
+
}
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
}
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import { setByPath,
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { setByPath, error, hasOwn } from '@mpxjs/utils'
|
|
2
|
+
import Mpx from '../../index'
|
|
3
|
+
|
|
4
|
+
const datasetReg = /^data-(.+)$/
|
|
5
|
+
|
|
6
|
+
function collectDataset (props) {
|
|
7
|
+
const dataset = {}
|
|
8
|
+
for (const key in props) {
|
|
9
|
+
if (hasOwn(props, key)) {
|
|
10
|
+
const matched = datasetReg.exec(key)
|
|
11
|
+
if (matched) {
|
|
12
|
+
dataset[matched[1]] = props[key]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return dataset
|
|
17
|
+
}
|
|
4
18
|
|
|
5
19
|
export default function proxyEventMixin () {
|
|
6
20
|
const methods = {
|
|
7
21
|
__invoke ($event) {
|
|
8
|
-
if (typeof
|
|
22
|
+
if (typeof Mpx.config.proxyEventHandler === 'function') {
|
|
9
23
|
try {
|
|
10
|
-
|
|
24
|
+
Mpx.config.proxyEventHandler($event)
|
|
11
25
|
} catch (e) {
|
|
12
26
|
}
|
|
13
27
|
}
|
|
28
|
+
const location = this.__mpxProxy.options.mpxFileResource
|
|
14
29
|
const type = $event.type
|
|
15
30
|
const emitMode = $event.detail && $event.detail.mpxEmit
|
|
16
31
|
if (!type) {
|
|
17
|
-
|
|
32
|
+
error('Event object must have [type] property!', location)
|
|
33
|
+
return
|
|
18
34
|
}
|
|
19
35
|
let fallbackType = ''
|
|
20
36
|
if (type === 'begin' || type === 'end') {
|
|
@@ -25,7 +41,8 @@ export default function proxyEventMixin () {
|
|
|
25
41
|
}
|
|
26
42
|
const target = $event.currentTarget || $event.target
|
|
27
43
|
if (!target) {
|
|
28
|
-
|
|
44
|
+
error(`[${type}] event object must have [currentTarget/target] property!`, location)
|
|
45
|
+
return
|
|
29
46
|
}
|
|
30
47
|
const eventConfigs = target.dataset.eventconfigs || {}
|
|
31
48
|
const curEventConfig = eventConfigs[type] || eventConfigs[fallbackType] || []
|
|
@@ -36,24 +53,25 @@ export default function proxyEventMixin () {
|
|
|
36
53
|
$event = $event.detail.data
|
|
37
54
|
}
|
|
38
55
|
if (callbackName) {
|
|
39
|
-
const params = item.length > 1
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
const params = item.length > 1
|
|
57
|
+
? item.slice(1).map(item => {
|
|
58
|
+
// 暂不支持$event.xxx的写法
|
|
59
|
+
// if (/^\$event/.test(item)) {
|
|
60
|
+
// this.__mpxTempEvent = $event
|
|
61
|
+
// const value = getByPath(this, item.replace('$event', '__mpxTempEvent'))
|
|
62
|
+
// // 删除临时变量
|
|
63
|
+
// delete this.__mpxTempEvent
|
|
64
|
+
// return value
|
|
65
|
+
if (item === '__mpx_event__') {
|
|
66
|
+
return $event
|
|
67
|
+
} else {
|
|
68
|
+
return item
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
: [$event]
|
|
53
72
|
if (typeof this[callbackName] === 'function') {
|
|
54
73
|
returnedValue = this[callbackName].apply(this, params)
|
|
55
74
|
} else {
|
|
56
|
-
const location = this.__mpxProxy && this.__mpxProxy.options.mpxFileResource
|
|
57
75
|
error(`Instance property [${callbackName}] is not function, please check.`, location)
|
|
58
76
|
}
|
|
59
77
|
}
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
import { setByPath } from '
|
|
1
|
+
import { setByPath } from '@mpxjs/utils'
|
|
2
2
|
|
|
3
3
|
export default function proxyEventMixin () {
|
|
4
|
-
const methods = {
|
|
5
|
-
triggerEvent (eventName, eventDetail) {
|
|
6
|
-
return this.$emit(eventName, {
|
|
7
|
-
type: eventName,
|
|
8
|
-
detail: eventDetail
|
|
9
|
-
})
|
|
10
|
-
},
|
|
11
|
-
__model (expr, $event, valuePath = ['value'], filterMethod) {
|
|
12
|
-
const innerFilter = {
|
|
13
|
-
trim: val => typeof val === 'string' && val.trim()
|
|
14
|
-
}
|
|
15
|
-
const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
|
|
16
|
-
const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
|
|
17
|
-
setByPath(this, expr, value)
|
|
18
|
-
},
|
|
19
|
-
getOpenerEventChannel () {
|
|
20
|
-
const router = global.__mpxRouter
|
|
21
|
-
const eventChannel = router && router.__mpxAction && router.__mpxAction.eventChannel
|
|
22
|
-
return eventChannel
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
4
|
return {
|
|
27
5
|
beforeCreate () {
|
|
28
6
|
const modelEvent = this.$attrs.mpxModelEvent
|
|
@@ -32,6 +10,20 @@ export default function proxyEventMixin () {
|
|
|
32
10
|
})
|
|
33
11
|
}
|
|
34
12
|
},
|
|
35
|
-
methods
|
|
13
|
+
methods: {
|
|
14
|
+
__model (expr, $event, valuePath = ['value'], filterMethod) {
|
|
15
|
+
const innerFilter = {
|
|
16
|
+
trim: val => typeof val === 'string' && val.trim()
|
|
17
|
+
}
|
|
18
|
+
const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
|
|
19
|
+
const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
|
|
20
|
+
setByPath(this, expr, value)
|
|
21
|
+
},
|
|
22
|
+
getOpenerEventChannel () {
|
|
23
|
+
const router = global.__mpxRouter
|
|
24
|
+
const eventChannel = router && router.__mpxAction && router.__mpxAction.eventChannel
|
|
25
|
+
return eventChannel
|
|
26
|
+
}
|
|
27
|
+
}
|
|
36
28
|
}
|
|
37
29
|
}
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { noop } from '
|
|
3
|
-
import { error } from '../../helper/log'
|
|
4
|
-
import { getEnvObj } from '../../helper/env'
|
|
1
|
+
import { CREATED, BEFOREMOUNT, BEFOREUPDATE, UNMOUNTED } from '../../core/innerLifecycle'
|
|
2
|
+
import { noop, error, getEnvObj } from '@mpxjs/utils'
|
|
5
3
|
|
|
6
4
|
const envObj = getEnvObj()
|
|
7
5
|
|
|
8
|
-
const setNodeRef = function (target, ref
|
|
6
|
+
const setNodeRef = function (target, ref) {
|
|
9
7
|
Object.defineProperty(target.$refs, ref.key, {
|
|
10
8
|
enumerable: true,
|
|
11
9
|
configurable: true,
|
|
12
10
|
get () {
|
|
13
|
-
|
|
11
|
+
// for nodes, every time being accessed, returns as a new selector.
|
|
12
|
+
return target.__getRefNode(ref)
|
|
14
13
|
}
|
|
15
14
|
})
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
const setComponentRef = function (target, ref,
|
|
17
|
+
const setComponentRef = function (target, ref, isAsync) {
|
|
19
18
|
let cacheRef = null
|
|
20
|
-
const targetRefs = isAsync ? target.$asyncRefs : target.$refs
|
|
19
|
+
const targetRefs = isAsync ? (target.$asyncRefs || (target.$asyncRefs = {})) : target.$refs
|
|
21
20
|
Object.defineProperty(targetRefs, ref.key, {
|
|
22
21
|
enumerable: true,
|
|
23
22
|
configurable: true,
|
|
24
23
|
get () {
|
|
25
|
-
// wx由于分包异步化的存在,每次访问refs都需要重新执行
|
|
24
|
+
// wx由于分包异步化的存在,每次访问refs都需要重新执行selectComponent,避免一直拿到缓存中的placeholder
|
|
26
25
|
if (__mpx_mode__ === 'wx' || !cacheRef) {
|
|
27
|
-
return (cacheRef =
|
|
26
|
+
return (cacheRef = target.__getRefNode(ref, isAsync))
|
|
28
27
|
}
|
|
29
28
|
return cacheRef
|
|
30
29
|
}
|
|
@@ -32,13 +31,69 @@ const setComponentRef = function (target, ref, context, isAsync) {
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export default function getRefsMixin () {
|
|
35
|
-
|
|
34
|
+
const refsMixin = {
|
|
35
|
+
[BEFOREMOUNT] () {
|
|
36
|
+
this.__getRefs()
|
|
37
|
+
},
|
|
38
|
+
[BEFOREUPDATE] () {
|
|
39
|
+
this.__getRefs()
|
|
40
|
+
},
|
|
41
|
+
methods: {
|
|
42
|
+
__getRefs () {
|
|
43
|
+
if (this.__getRefsData) {
|
|
44
|
+
const refs = this.__getRefsData()
|
|
45
|
+
|
|
46
|
+
refs.forEach(ref => {
|
|
47
|
+
const setRef = ref.type === 'node' ? setNodeRef : setComponentRef
|
|
48
|
+
setRef(this, ref)
|
|
49
|
+
|
|
50
|
+
if (__mpx_mode__ === 'tt' && ref.type === 'component') {
|
|
51
|
+
setComponentRef(this, ref, true)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
__getRefNode (ref, isAsync) {
|
|
57
|
+
if (!ref) return
|
|
58
|
+
const selector = ref.selector.replace(/{{mpxCid}}/g, this.__mpxProxy.uid)
|
|
59
|
+
if (ref.type === 'node') {
|
|
60
|
+
const query = this.createSelectorQuery ? this.createSelectorQuery() : envObj.createSelectorQuery()
|
|
61
|
+
return query && (ref.all ? query.selectAll(selector) : query.select(selector))
|
|
62
|
+
} else if (ref.type === 'component') {
|
|
63
|
+
if (isAsync) {
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
ref.all ? this.selectAllComponents(selector, resolve) : this.selectComponent(selector, resolve)
|
|
66
|
+
})
|
|
67
|
+
} else {
|
|
68
|
+
return ref.all ? this.selectAllComponents(selector) : this.selectComponent(selector)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
36
75
|
if (__mpx_mode__ === 'ali') {
|
|
76
|
+
Object.assign(refsMixin, {
|
|
77
|
+
data () {
|
|
78
|
+
return {
|
|
79
|
+
mpxCid: this.__mpxProxy.uid
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
[CREATED] () {
|
|
83
|
+
this.__updateRef()
|
|
84
|
+
},
|
|
85
|
+
[UNMOUNTED] () {
|
|
86
|
+
// 销毁ref
|
|
87
|
+
this.__updateRef(true)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
|
|
37
91
|
const proxyMethods = ['boundingClientRect', 'scrollOffset']
|
|
38
92
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
93
|
+
Object.assign(refsMixin.methods, {
|
|
94
|
+
// todo 支付宝基础库升级至2.7.4以上可去除
|
|
95
|
+
createSelectorQuery (...args) {
|
|
96
|
+
const selectorQuery = envObj.createSelectorQuery(...args)
|
|
42
97
|
const cbs = []
|
|
43
98
|
proxyMethods.forEach((name) => {
|
|
44
99
|
const originalMethod = selectorQuery[name]
|
|
@@ -52,7 +107,7 @@ export default function getRefsMixin () {
|
|
|
52
107
|
selectorQuery.exec = function (originalCb = noop) {
|
|
53
108
|
const cb = function (results) {
|
|
54
109
|
results.forEach((item, index) => {
|
|
55
|
-
cbs[index]
|
|
110
|
+
cbs[index](item)
|
|
56
111
|
})
|
|
57
112
|
originalCb(results)
|
|
58
113
|
}
|
|
@@ -60,6 +115,10 @@ export default function getRefsMixin () {
|
|
|
60
115
|
}
|
|
61
116
|
return selectorQuery
|
|
62
117
|
},
|
|
118
|
+
// todo 支付宝基础库升级至2.7.4以上可去除
|
|
119
|
+
createIntersectionObserver (...args) {
|
|
120
|
+
return envObj.createIntersectionObserver(...args)
|
|
121
|
+
},
|
|
63
122
|
selectComponent (selector, all) {
|
|
64
123
|
const children = this.__children__ || []
|
|
65
124
|
const result = []
|
|
@@ -72,7 +131,7 @@ export default function getRefsMixin () {
|
|
|
72
131
|
}
|
|
73
132
|
}
|
|
74
133
|
if (selector.lastIndexOf('.') > 0) {
|
|
75
|
-
const location = this.__mpxProxy
|
|
134
|
+
const location = this.__mpxProxy.options.mpxFileResource
|
|
76
135
|
error('The selectComponent or selectAllComponents only supports the single selector, a composed selector is not supported.', location)
|
|
77
136
|
}
|
|
78
137
|
return all ? result : result[0]
|
|
@@ -93,9 +152,11 @@ export default function getRefsMixin () {
|
|
|
93
152
|
const component = e.detail.component
|
|
94
153
|
const destroyed = e.detail.destroyed
|
|
95
154
|
const className = component.props.className || component.className
|
|
96
|
-
const identifiers = className
|
|
97
|
-
|
|
98
|
-
|
|
155
|
+
const identifiers = className
|
|
156
|
+
? className.trim().split(/\s+/).map(item => {
|
|
157
|
+
return `.${item}`
|
|
158
|
+
})
|
|
159
|
+
: []
|
|
99
160
|
if (component.props.id) {
|
|
100
161
|
identifiers.push(`#${component.props.id}`)
|
|
101
162
|
}
|
|
@@ -108,60 +169,8 @@ export default function getRefsMixin () {
|
|
|
108
169
|
})
|
|
109
170
|
}
|
|
110
171
|
}
|
|
111
|
-
}
|
|
172
|
+
})
|
|
112
173
|
}
|
|
113
|
-
return {
|
|
114
|
-
[BEFORECREATE] () {
|
|
115
|
-
this.$refs = {}
|
|
116
|
-
if (__mpx_mode__ === 'tt') {
|
|
117
|
-
this.$asyncRefs = {}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
[CREATED] () {
|
|
121
|
-
this.__updateRef && this.__updateRef()
|
|
122
|
-
},
|
|
123
|
-
[BEFOREMOUNT] () {
|
|
124
|
-
this.__getRefs()
|
|
125
|
-
},
|
|
126
|
-
[UPDATED] () {
|
|
127
|
-
this.__getRefs()
|
|
128
|
-
},
|
|
129
|
-
[DESTROYED] () {
|
|
130
|
-
// 销毁ref
|
|
131
|
-
this.__updateRef && this.__updateRef(true)
|
|
132
|
-
},
|
|
133
|
-
methods: {
|
|
134
|
-
...aliMethods,
|
|
135
|
-
__getRefs () {
|
|
136
|
-
if (this.__getRefsData) {
|
|
137
|
-
const refs = this.__getRefsData()
|
|
138
174
|
|
|
139
|
-
|
|
140
|
-
const setRef = ref.type === 'node' ? setNodeRef : setComponentRef
|
|
141
|
-
setRef(this, ref, this)
|
|
142
|
-
|
|
143
|
-
if (__mpx_mode__ === 'tt' && ref.type === 'component') {
|
|
144
|
-
setComponentRef(this, ref, this, true)
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
__getRefNode (ref, isAsync) {
|
|
150
|
-
if (!ref) return
|
|
151
|
-
let selector = ref.selector.replace(/{{mpxCid}}/g, this.mpxCid)
|
|
152
|
-
if (ref.type === 'node') {
|
|
153
|
-
const query = this.createSelectorQuery ? this.createSelectorQuery() : envObj.createSelectorQuery()
|
|
154
|
-
return query && (ref.all ? query.selectAll(selector) : query.select(selector))
|
|
155
|
-
} else if (ref.type === 'component') {
|
|
156
|
-
if (isAsync) {
|
|
157
|
-
return new Promise((resolve) => {
|
|
158
|
-
ref.all ? this.selectAllComponents(selector, resolve) : this.selectComponent(selector, resolve)
|
|
159
|
-
})
|
|
160
|
-
} else {
|
|
161
|
-
return ref.all ? this.selectAllComponents(selector) : this.selectComponent(selector)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
175
|
+
return refsMixin
|
|
167
176
|
}
|
|
@@ -1,33 +1,6 @@
|
|
|
1
1
|
import { BEFOREMOUNT, UPDATED } from '../../core/innerLifecycle'
|
|
2
|
-
import { error } from '../../helper/log'
|
|
3
2
|
import * as webApi from '@mpxjs/api-proxy/src/web/api'
|
|
4
3
|
|
|
5
|
-
function getIdentifier (vnode) {
|
|
6
|
-
let identifier = ''
|
|
7
|
-
if (vnode && vnode.data) {
|
|
8
|
-
if (vnode.data.attrs && vnode.data.attrs.id) identifier += `#${vnode.data.attrs.id}`
|
|
9
|
-
if (vnode.data.staticClass) identifier += `.${vnode.data.staticClass.split(' ').join('.')}`
|
|
10
|
-
}
|
|
11
|
-
return identifier
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function walkChildren (vm, selector, context, result, all) {
|
|
15
|
-
if (vm.$children && vm.$children.length) {
|
|
16
|
-
for (let i = 0; i < vm.$children.length; i++) {
|
|
17
|
-
const child = vm.$children[i]
|
|
18
|
-
if (child.$vnode.context === context && !child.$options.__mpxBuiltIn) {
|
|
19
|
-
const identifier = getIdentifier(child.$vnode)
|
|
20
|
-
// todo 这里暂时只支持静态类,且只支持单个选择器,更复杂的需求建议用refs实现
|
|
21
|
-
if (identifier.indexOf(selector) > -1) {
|
|
22
|
-
result.push(child)
|
|
23
|
-
if (!all) return
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
walkChildren(child, selector, context, result, all)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
4
|
function getEl (ref) {
|
|
32
5
|
if (ref && ref.nodeType === 1) return ref
|
|
33
6
|
if (ref && ref.$options && ref.$options.__mpxBuiltIn) return ref.$el
|
|
@@ -63,26 +36,6 @@ export default function getRefsMixin () {
|
|
|
63
36
|
},
|
|
64
37
|
[UPDATED] () {
|
|
65
38
|
processRefs(this.$refs || {})
|
|
66
|
-
},
|
|
67
|
-
methods: {
|
|
68
|
-
createSelectorQuery () {
|
|
69
|
-
return webApi.createSelectorQuery().in(this)
|
|
70
|
-
},
|
|
71
|
-
createIntersectionObserver (component, options) {
|
|
72
|
-
return webApi.createIntersectionObserver(component, options)
|
|
73
|
-
},
|
|
74
|
-
selectComponent (selector, all) {
|
|
75
|
-
const result = []
|
|
76
|
-
walkChildren(this, selector, this, result, all)
|
|
77
|
-
if (selector.lastIndexOf('.') > 0) {
|
|
78
|
-
const location = this.__mpxProxy && this.__mpxProxy.options.mpxFileResource
|
|
79
|
-
error('The selectComponent or selectAllComponents only supports the single selector, a composed selector is not supported.', location)
|
|
80
|
-
}
|
|
81
|
-
return all ? result : result[0]
|
|
82
|
-
},
|
|
83
|
-
selectAllComponents (selector) {
|
|
84
|
-
return this.selectComponent(selector, true)
|
|
85
|
-
}
|
|
86
39
|
}
|
|
87
40
|
}
|
|
88
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isObject } from '
|
|
2
|
-
import { CREATED, MOUNTED } from '../../core/innerLifecycle'
|
|
1
|
+
import { isObject } from '@mpxjs/utils'
|
|
2
|
+
import { CREATED, MOUNTED, BEFOREUNMOUNT } from '../../core/innerLifecycle'
|
|
3
3
|
|
|
4
4
|
const targets = []
|
|
5
5
|
let curTarget = null
|
|
@@ -57,7 +57,7 @@ export default function relationsMixin (mixinType) {
|
|
|
57
57
|
if (child && child.props) {
|
|
58
58
|
if (child.props.$isCustomComponent) {
|
|
59
59
|
// 只有relations中声明为后代的节点才能被作为有效子节点
|
|
60
|
-
|
|
60
|
+
const relation = this.$mpxRelations[child.type.displayName]
|
|
61
61
|
if (relation && (relation.type === 'child' || relation.type === 'descendant')) {
|
|
62
62
|
child.props.$mpxIsSlot = true
|
|
63
63
|
list.push(child)
|
|
@@ -120,7 +120,7 @@ export default function relationsMixin (mixinType) {
|
|
|
120
120
|
},
|
|
121
121
|
mpxPropagateFindRelation (child) {
|
|
122
122
|
let cur = this
|
|
123
|
-
|
|
123
|
+
const contexts = []
|
|
124
124
|
let depth = 1
|
|
125
125
|
// 向上查找所有可能匹配的父级relation上下文
|
|
126
126
|
while (cur) {
|
|
@@ -138,8 +138,9 @@ export default function relationsMixin (mixinType) {
|
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
onInit () {
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
const options = this.__mpxProxy.options
|
|
142
|
+
if (options.relations) {
|
|
143
|
+
this.$mpxRelations = transferPath(options.relations, this.is)
|
|
143
144
|
this.$relationNodesMap = {}
|
|
144
145
|
}
|
|
145
146
|
if (curTarget && this.props.$mpxIsSlot) {
|
|
@@ -183,12 +184,12 @@ export default function relationsMixin (mixinType) {
|
|
|
183
184
|
this.__mpxCollectRelations()
|
|
184
185
|
this.__mpxExecRelations('linked')
|
|
185
186
|
},
|
|
186
|
-
|
|
187
|
+
[BEFOREUNMOUNT] () {
|
|
187
188
|
this.__mpxExecRelations('unlinked')
|
|
188
189
|
},
|
|
189
190
|
methods: {
|
|
190
191
|
__mpxCollectRelations () {
|
|
191
|
-
const relations = this
|
|
192
|
+
const relations = this.__mpxProxy.options.relations
|
|
192
193
|
if (!relations) return
|
|
193
194
|
Object.keys(relations).forEach(path => {
|
|
194
195
|
const relation = relations[path]
|
|
@@ -208,7 +209,7 @@ export default function relationsMixin (mixinType) {
|
|
|
208
209
|
|
|
209
210
|
// 当前组件在target的slots当中
|
|
210
211
|
if ((type === 'parent' || type === 'ancestor') && target.$vnode.context === this.$vnode.context) {
|
|
211
|
-
const targetRelation = target
|
|
212
|
+
const targetRelation = target?.__mpxProxy.options.relations?.[this.$options.componentPath]
|
|
212
213
|
if (
|
|
213
214
|
targetRelation &&
|
|
214
215
|
targetRelation.type === relationTypeMap[type] &&
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import transferOptions from '../core/transferOptions'
|
|
2
2
|
import mergeOptions from '../core/mergeOptions'
|
|
3
3
|
import builtInKeysMap from './patch/builtInKeysMap'
|
|
4
|
-
import { makeMap, spreadProp } from '
|
|
4
|
+
import { makeMap, spreadProp } from '@mpxjs/utils'
|
|
5
5
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
6
|
-
import
|
|
6
|
+
import Mpx from '../index'
|
|
7
7
|
|
|
8
8
|
const webAppHooksMap = makeMap(webLifecycle.LIFECYCLE.APP_HOOKS)
|
|
9
9
|
|
|
@@ -26,14 +26,14 @@ export default function createApp (option, config = {}) {
|
|
|
26
26
|
// 在App中挂载mpx对象供周边工具访问,如e2e测试
|
|
27
27
|
const builtInMixins = [{
|
|
28
28
|
getMpx () {
|
|
29
|
-
return
|
|
29
|
+
return Mpx
|
|
30
30
|
}
|
|
31
31
|
}]
|
|
32
32
|
const appData = {}
|
|
33
33
|
if (__mpx_mode__ === 'web') {
|
|
34
34
|
builtInMixins.push({
|
|
35
35
|
created () {
|
|
36
|
-
Object.assign(this,
|
|
36
|
+
Object.assign(this, Mpx.prototype)
|
|
37
37
|
Object.assign(this, appData)
|
|
38
38
|
const current = (global.__mpxRouter && global.__mpxRouter.currentRoute) || {}
|
|
39
39
|
const options = {
|
|
@@ -64,7 +64,7 @@ export default function createApp (option, config = {}) {
|
|
|
64
64
|
} else {
|
|
65
65
|
builtInMixins.push({
|
|
66
66
|
onLaunch () {
|
|
67
|
-
Object.assign(this,
|
|
67
|
+
Object.assign(this, Mpx.prototype)
|
|
68
68
|
}
|
|
69
69
|
})
|
|
70
70
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { set, del, reactive } from '../../observer/reactive'
|
|
2
|
+
import { watch } from '../../observer/watch'
|
|
3
|
+
import { injectMixins } from '../../core/injectMixins'
|
|
4
|
+
|
|
5
|
+
const APIs = {
|
|
6
|
+
injectMixins,
|
|
7
|
+
mixin: injectMixins,
|
|
8
|
+
observable: reactive,
|
|
9
|
+
watch,
|
|
10
|
+
// use,
|
|
11
|
+
set,
|
|
12
|
+
delete: del
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const InstanceAPIs = {
|
|
16
|
+
$set: set,
|
|
17
|
+
$delete: del
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
APIs,
|
|
22
|
+
InstanceAPIs
|
|
23
|
+
}
|