@mpxjs/core 2.9.26 → 2.9.32
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.32",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
48
|
},
|
|
49
49
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "61ac5a85a2b75304d8b989d4291b4f606f50d82f"
|
|
51
51
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { noop,
|
|
1
|
+
import { BEFORECREATE, BEFOREUPDATE } from '../../core/innerLifecycle'
|
|
2
|
+
import { noop, getEnvObj } from '@mpxjs/utils'
|
|
3
3
|
|
|
4
4
|
const envObj = getEnvObj()
|
|
5
5
|
|
|
@@ -39,6 +39,11 @@ export default function getRefsMixin () {
|
|
|
39
39
|
this.__refCacheMap = new Map()
|
|
40
40
|
this.__asyncRefCacheMap = new Map()
|
|
41
41
|
this.__getRefs()
|
|
42
|
+
|
|
43
|
+
if (__mpx_mode__ === 'ali') {
|
|
44
|
+
this._originCreateSelectorQuery = this.createSelectorQuery
|
|
45
|
+
this.createSelectorQuery = this._createSelectorQuery
|
|
46
|
+
}
|
|
42
47
|
},
|
|
43
48
|
[BEFOREUPDATE] () {
|
|
44
49
|
this.__refCacheMap.clear()
|
|
@@ -82,22 +87,14 @@ export default function getRefsMixin () {
|
|
|
82
87
|
return {
|
|
83
88
|
mpxCid: this.__mpxProxy.uid
|
|
84
89
|
}
|
|
85
|
-
},
|
|
86
|
-
[CREATED] () {
|
|
87
|
-
this.__updateRef()
|
|
88
|
-
},
|
|
89
|
-
[UNMOUNTED] () {
|
|
90
|
-
// 销毁ref
|
|
91
|
-
this.__updateRef(true)
|
|
92
90
|
}
|
|
93
91
|
})
|
|
94
92
|
|
|
95
93
|
const proxyMethods = ['boundingClientRect', 'scrollOffset']
|
|
96
94
|
|
|
97
95
|
Object.assign(refsMixin.methods, {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const selectorQuery = envObj.createSelectorQuery(...args)
|
|
96
|
+
_createSelectorQuery (...args) {
|
|
97
|
+
const selectorQuery = this._originCreateSelectorQuery(...args)
|
|
101
98
|
const cbs = []
|
|
102
99
|
|
|
103
100
|
proxyMethods.forEach((name) => {
|
|
@@ -118,61 +115,14 @@ export default function getRefsMixin () {
|
|
|
118
115
|
}
|
|
119
116
|
return originalExec.call(this, cb)
|
|
120
117
|
}
|
|
118
|
+
|
|
121
119
|
return selectorQuery
|
|
122
120
|
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return envObj.createIntersectionObserver(...args)
|
|
126
|
-
},
|
|
127
|
-
selectComponent (selector, all) {
|
|
128
|
-
const children = this.__children__ || []
|
|
129
|
-
const result = []
|
|
130
|
-
for (const child of children) {
|
|
131
|
-
if (child.identifiers.indexOf(selector) > -1) {
|
|
132
|
-
result.push(child.component)
|
|
133
|
-
if (!all) {
|
|
134
|
-
break
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (selector.lastIndexOf('.') > 0) {
|
|
139
|
-
const location = this.__mpxProxy.options.mpxFileResource
|
|
140
|
-
error('The selectComponent or selectAllComponents only supports the single selector, a composed selector is not supported.', location)
|
|
141
|
-
}
|
|
142
|
-
return all ? result : result[0]
|
|
121
|
+
selectComponent (selector) {
|
|
122
|
+
return this.$selectComponent(selector)
|
|
143
123
|
},
|
|
144
124
|
selectAllComponents (selector) {
|
|
145
|
-
return this
|
|
146
|
-
},
|
|
147
|
-
__updateRef (destroyed) {
|
|
148
|
-
this.triggerEvent && this.triggerEvent('updateRef', {
|
|
149
|
-
component: this,
|
|
150
|
-
destroyed
|
|
151
|
-
})
|
|
152
|
-
},
|
|
153
|
-
__handleUpdateRef (e) {
|
|
154
|
-
if (!this.__children__) {
|
|
155
|
-
this.__children__ = []
|
|
156
|
-
}
|
|
157
|
-
const component = e.detail.component
|
|
158
|
-
const destroyed = e.detail.destroyed
|
|
159
|
-
const className = component.props.className || component.className
|
|
160
|
-
const identifiers = className
|
|
161
|
-
? className.trim().split(/\s+/).map(item => {
|
|
162
|
-
return `.${item}`
|
|
163
|
-
})
|
|
164
|
-
: []
|
|
165
|
-
if (component.props.id) {
|
|
166
|
-
identifiers.push(`#${component.props.id}`)
|
|
167
|
-
}
|
|
168
|
-
if (destroyed) {
|
|
169
|
-
this.__children__ = this.__children__.filter(item => item.component !== component)
|
|
170
|
-
} else {
|
|
171
|
-
this.__children__.push({
|
|
172
|
-
component,
|
|
173
|
-
identifiers
|
|
174
|
-
})
|
|
175
|
-
}
|
|
125
|
+
return this.$selectAllComponents(selector)
|
|
176
126
|
}
|
|
177
127
|
})
|
|
178
128
|
}
|
|
@@ -6,36 +6,39 @@ function getEl (ref) {
|
|
|
6
6
|
if (ref && ref.$options && ref.$options.__mpxBuiltIn) return ref.$el
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function processRefs (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
function processRefs (target) {
|
|
10
|
+
const refs = target.$refs
|
|
11
|
+
if (refs) {
|
|
12
|
+
Object.keys(refs).forEach((key) => {
|
|
13
|
+
const matched = /^__mpx_ref_(.+)__$/.exec(key)
|
|
14
|
+
const rKey = matched && matched[1]
|
|
15
|
+
if (rKey) {
|
|
16
|
+
const ref = refs[key]
|
|
17
|
+
if (Array.isArray(ref)) {
|
|
18
|
+
if (getEl(ref[0])) {
|
|
19
|
+
refs[rKey] = createSelectorQuery().in(target).selectAll(ref.map(getEl))
|
|
20
|
+
} else {
|
|
21
|
+
refs[rKey] = ref
|
|
22
|
+
}
|
|
18
23
|
} else {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
refs[rKey] = ref
|
|
24
|
+
if (getEl(ref)) {
|
|
25
|
+
refs[rKey] = createSelectorQuery().in(target).select(getEl(ref))
|
|
26
|
+
} else {
|
|
27
|
+
refs[rKey] = ref
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export default function getRefsMixin () {
|
|
33
36
|
return {
|
|
34
37
|
[BEFOREMOUNT] () {
|
|
35
|
-
processRefs(this
|
|
38
|
+
processRefs(this)
|
|
36
39
|
},
|
|
37
40
|
[UPDATED] () {
|
|
38
|
-
processRefs(this
|
|
41
|
+
processRefs(this)
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -1,181 +1,12 @@
|
|
|
1
|
-
import { isObject } from '@mpxjs/utils'
|
|
2
1
|
import { BEFORECREATE, MOUNTED, BEFOREUNMOUNT } from '../../core/innerLifecycle'
|
|
3
2
|
|
|
4
|
-
const targets = []
|
|
5
|
-
let curTarget = null
|
|
6
|
-
|
|
7
|
-
function pushTarget (cur) {
|
|
8
|
-
targets.push(curTarget)
|
|
9
|
-
curTarget = cur
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function popTarget () {
|
|
13
|
-
curTarget = targets.pop()
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function parsePath (path, absolute) {
|
|
17
|
-
if (path.indexOf('/') === 0) {
|
|
18
|
-
return path
|
|
19
|
-
}
|
|
20
|
-
const dirs = absolute.split('/').slice(0, -1)
|
|
21
|
-
let relatives = path.split('/')
|
|
22
|
-
relatives = relatives.filter(path => {
|
|
23
|
-
if (path === '..') {
|
|
24
|
-
dirs.pop()
|
|
25
|
-
return false
|
|
26
|
-
} else {
|
|
27
|
-
return path !== '.'
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
return dirs.concat(relatives).join('/')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function transferPath (relations, base) {
|
|
34
|
-
const newRelations = {}
|
|
35
|
-
Object.keys(relations).forEach(key => {
|
|
36
|
-
newRelations[parsePath(key, base)] = relations[key]
|
|
37
|
-
})
|
|
38
|
-
return newRelations
|
|
39
|
-
}
|
|
40
|
-
|
|
41
3
|
const relationTypeMap = {
|
|
42
4
|
parent: 'child',
|
|
43
5
|
ancestor: 'descendant'
|
|
44
6
|
}
|
|
45
7
|
|
|
46
8
|
export default function relationsMixin (mixinType) {
|
|
47
|
-
if (__mpx_mode__ === '
|
|
48
|
-
return {
|
|
49
|
-
methods: {
|
|
50
|
-
getRelationNodes (path) {
|
|
51
|
-
const realPath = parsePath(path, this.is)
|
|
52
|
-
return (this.$relationNodesMap && this.$relationNodesMap[realPath]) || []
|
|
53
|
-
},
|
|
54
|
-
mpxCollectChildComponent (children, list) {
|
|
55
|
-
if (this.$mpxRelations) {
|
|
56
|
-
children.forEach(child => {
|
|
57
|
-
if (child && child.props) {
|
|
58
|
-
if (child.props.$isCustomComponent) {
|
|
59
|
-
// 只有relations中声明为后代的节点才能被作为有效子节点
|
|
60
|
-
const relation = this.$mpxRelations[child.type.displayName]
|
|
61
|
-
if (relation && (relation.type === 'child' || relation.type === 'descendant')) {
|
|
62
|
-
child.props.$mpxIsSlot = true
|
|
63
|
-
list.push(child)
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
const children = child.props.children
|
|
67
|
-
if (isObject(children)) {
|
|
68
|
-
const slotChildren = Array.isArray(children) ? children : [children]
|
|
69
|
-
this.mpxCollectChildComponent(slotChildren, list)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
mpxSlotNotify () {
|
|
77
|
-
if (this.mpxSlotLinkNum < this.mpxSlotChildren.length) {
|
|
78
|
-
this.mpxSlotLinkNum++
|
|
79
|
-
if (this.mpxSlotLinkNum === this.mpxSlotChildren.length) {
|
|
80
|
-
popTarget()
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
mpxExecAllRelations (type) {
|
|
85
|
-
this.mpxRelationContexts.forEach(context => {
|
|
86
|
-
context.mpxExecRelation(this, type)
|
|
87
|
-
this.mpxExecRelation(context, type)
|
|
88
|
-
})
|
|
89
|
-
},
|
|
90
|
-
mpxExecRelation (target, type) {
|
|
91
|
-
this.mpxCacheRelationNode(target, type)
|
|
92
|
-
const relations = this.$mpxRelations || {}
|
|
93
|
-
const path = target.is
|
|
94
|
-
if (relations[path]) {
|
|
95
|
-
typeof relations[path][type] === 'function' && relations[path][type].call(this, target)
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
mpxCacheRelationNode (target, type) {
|
|
99
|
-
const path = target.is
|
|
100
|
-
const nodes = this.$relationNodesMap[path] || []
|
|
101
|
-
if (type === 'linked') {
|
|
102
|
-
nodes.push(target)
|
|
103
|
-
} else {
|
|
104
|
-
const index = nodes.indexOf(target)
|
|
105
|
-
index > -1 && nodes.splice(index, 1)
|
|
106
|
-
}
|
|
107
|
-
this.$relationNodesMap[path] = nodes
|
|
108
|
-
},
|
|
109
|
-
mpxGetRelation (child) {
|
|
110
|
-
const parentRelations = this.$mpxRelations || {}
|
|
111
|
-
const childRelations = child.$mpxRelations || {}
|
|
112
|
-
if (parentRelations[child.is] && childRelations[this.is]) {
|
|
113
|
-
const parentType = parentRelations[child.is].type
|
|
114
|
-
const childType = childRelations[this.is].type
|
|
115
|
-
return {
|
|
116
|
-
parentType,
|
|
117
|
-
childType
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
mpxPropagateFindRelation (child) {
|
|
122
|
-
let cur = this
|
|
123
|
-
const contexts = []
|
|
124
|
-
let depth = 1
|
|
125
|
-
// 向上查找所有可能匹配的父级relation上下文
|
|
126
|
-
while (cur) {
|
|
127
|
-
const relations = cur.mpxGetRelation(child)
|
|
128
|
-
if (relations) {
|
|
129
|
-
if ((relations.parentType === 'child' && relations.childType === 'parent' && depth === 1) ||
|
|
130
|
-
(relations.parentType === 'descendant' && relations.childType === 'ancestor')) {
|
|
131
|
-
contexts.push(cur)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
cur = cur.mpxSlotParent
|
|
135
|
-
depth++
|
|
136
|
-
}
|
|
137
|
-
return contexts
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
onInit () {
|
|
141
|
-
const options = this.__mpxProxy.options
|
|
142
|
-
if (options.relations) {
|
|
143
|
-
this.$mpxRelations = transferPath(options.relations, this.is)
|
|
144
|
-
this.$relationNodesMap = {}
|
|
145
|
-
}
|
|
146
|
-
if (curTarget && this.props.$mpxIsSlot) {
|
|
147
|
-
this.mpxSlotParent = curTarget // slot 父级
|
|
148
|
-
if (this.$mpxRelations) {
|
|
149
|
-
const contexts = curTarget.mpxPropagateFindRelation(this) // relation 父级|祖先
|
|
150
|
-
if (contexts) {
|
|
151
|
-
this.mpxRelationContexts = contexts
|
|
152
|
-
this.mpxExecAllRelations('linked')
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
deriveDataFromProps (nextProps) {
|
|
158
|
-
this.mpxSlotParent && this.mpxSlotParent.mpxSlotNotify() // 通知slot父级,确保父级能执行popTarget
|
|
159
|
-
const slots = nextProps.$slots || {}
|
|
160
|
-
const slotKeys = Object.keys(slots)
|
|
161
|
-
if (slotKeys.length) {
|
|
162
|
-
this.mpxSlotChildren = []
|
|
163
|
-
this.mpxSlotLinkNum = 0
|
|
164
|
-
slotKeys.forEach(key => {
|
|
165
|
-
this.mpxCollectChildComponent(slots[key], this.mpxSlotChildren)
|
|
166
|
-
})
|
|
167
|
-
if (this.mpxSlotChildren.length) {
|
|
168
|
-
pushTarget(this)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
didUnmount () {
|
|
173
|
-
if (this.mpxRelationContexts) {
|
|
174
|
-
this.mpxExecAllRelations('unlinked')
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
} else if (__mpx_mode__ === 'web' && mixinType === 'component') {
|
|
9
|
+
if (__mpx_mode__ === 'web' && mixinType === 'component') {
|
|
179
10
|
return {
|
|
180
11
|
[BEFORECREATE] () {
|
|
181
12
|
this.__mpxRelations = {}
|