@mpxjs/core 2.7.37 → 2.7.47
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
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.47",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"miniprogram-api-typings": "^3.0.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
+
"@mpxjs/api-proxy": "^2.7.44",
|
|
26
27
|
"vue": "^2.6.10",
|
|
27
28
|
"vue-i18n": "^8.15.3"
|
|
28
29
|
},
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"url": "https://github.com/didi/mpx/issues"
|
|
42
43
|
},
|
|
43
44
|
"sideEffects": false,
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "05354d5750021d76f4bf0ae2a4ab73fb2f8ef83b"
|
|
45
46
|
}
|
|
@@ -43,8 +43,18 @@ export default function pageStatusMixin (mixinType) {
|
|
|
43
43
|
currentPage = this.$page
|
|
44
44
|
} else {
|
|
45
45
|
const pages = getCurrentPages()
|
|
46
|
-
|
|
46
|
+
if (typeof this.getPageId === 'function') {
|
|
47
|
+
const currentPageId = this.getPageId()
|
|
48
|
+
for (let page of pages) {
|
|
49
|
+
if (typeof page.getPageId === 'function' && currentPageId === page.getPageId()) {
|
|
50
|
+
currentPage = page
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
currentPage = currentPage || pages[pages.length - 1]
|
|
47
56
|
}
|
|
57
|
+
|
|
48
58
|
if (currentPage) {
|
|
49
59
|
this.$watch(() => currentPage.mpxPageStatus, (val) => {
|
|
50
60
|
if (val) {
|
|
@@ -70,13 +70,10 @@ export default function proxyEventMixin () {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
if (__mpx_mode__ === 'ali') {
|
|
73
|
-
const getHandler = (eventName, props) => {
|
|
74
|
-
const handlerName = eventName.replace(/^./, matched => matched.toUpperCase()).replace(/-([a-z])/g, (match, p1) => p1.toUpperCase())
|
|
75
|
-
return props && (props['on' + handlerName] || props['catch' + handlerName])
|
|
76
|
-
}
|
|
77
73
|
Object.assign(methods, {
|
|
78
74
|
triggerEvent (eventName, eventDetail) {
|
|
79
|
-
const
|
|
75
|
+
const handlerName = eventName.replace(/^./, matched => matched.toUpperCase()).replace(/-([a-z])/g, (match, p1) => p1.toUpperCase())
|
|
76
|
+
const handler = this.props && (this.props['on' + handlerName] || this.props['catch' + handlerName])
|
|
80
77
|
if (handler && typeof handler === 'function') {
|
|
81
78
|
const dataset = collectDataset(this.props)
|
|
82
79
|
const id = this.props.id || ''
|
|
@@ -95,31 +92,6 @@ export default function proxyEventMixin () {
|
|
|
95
92
|
},
|
|
96
93
|
detail: eventDetail
|
|
97
94
|
}
|
|
98
|
-
handler.call(this, eventObj)
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
__proxyEvent (e) {
|
|
102
|
-
const type = e.type
|
|
103
|
-
const handler = getHandler(type, this.props)
|
|
104
|
-
|
|
105
|
-
if (handler && typeof handler === 'function') {
|
|
106
|
-
const dataset = collectDataset(this.props)
|
|
107
|
-
const id = this.props.id || ''
|
|
108
|
-
const targetData = Object.assign({}, e.target || {}, {
|
|
109
|
-
id,
|
|
110
|
-
dataset
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
const currentTargetData = Object.assign({}, e.currentTarget || {}, {
|
|
114
|
-
id,
|
|
115
|
-
dataset
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
const eventObj = Object.assign({}, e, {
|
|
119
|
-
target: targetData,
|
|
120
|
-
currentTarget: currentTargetData
|
|
121
|
-
})
|
|
122
|
-
|
|
123
95
|
handler.call(this, eventObj)
|
|
124
96
|
}
|
|
125
97
|
}
|
|
@@ -1,245 +1,6 @@
|
|
|
1
1
|
import { BEFOREMOUNT, UPDATED } from '../../core/innerLifecycle'
|
|
2
2
|
import { error } from '../../helper/log'
|
|
3
|
-
|
|
4
|
-
class SelectQuery {
|
|
5
|
-
constructor () {
|
|
6
|
-
this._component = null
|
|
7
|
-
this._queue = []
|
|
8
|
-
this._queueCb = []
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
in (component) {
|
|
12
|
-
this._component = component
|
|
13
|
-
return this
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
select (selector) {
|
|
17
|
-
if (typeof selector === 'string') {
|
|
18
|
-
selector = selector.replace('>>>', '>')
|
|
19
|
-
}
|
|
20
|
-
return new NodesRef(selector, this, true)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
selectAll (selector) {
|
|
24
|
-
if (typeof selector === 'string') {
|
|
25
|
-
selector = selector.replace('>>>', '>')
|
|
26
|
-
}
|
|
27
|
-
return new NodesRef(selector, this, false)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
selectViewport () {
|
|
31
|
-
return new NodesRef('html', this, true)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
exec (callback) {
|
|
35
|
-
const res = []
|
|
36
|
-
const handleFields = this._handleFields
|
|
37
|
-
const queueCb = this._queueCb
|
|
38
|
-
this._queue.forEach(item => {
|
|
39
|
-
const { selector, component, single, fields } = item
|
|
40
|
-
|
|
41
|
-
let curComponent = document
|
|
42
|
-
|
|
43
|
-
if (component && component.$el) {
|
|
44
|
-
curComponent = component.$el
|
|
45
|
-
} else if (component && component.nodeType === 1) {
|
|
46
|
-
curComponent = component
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (this._isEl(selector)) {
|
|
50
|
-
if (single) {
|
|
51
|
-
res.push(handleFields(fields, selector, null))
|
|
52
|
-
} else {
|
|
53
|
-
res.push(selector.map(el => handleFields(fields, el, null)))
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
const selectSelf =
|
|
57
|
-
curComponent === document
|
|
58
|
-
? false
|
|
59
|
-
: Array
|
|
60
|
-
.from(curComponent.parentNode.querySelectorAll(selector))
|
|
61
|
-
.every(item => item === curComponent)
|
|
62
|
-
|
|
63
|
-
if (single) {
|
|
64
|
-
const el = selectSelf ? curComponent : curComponent.querySelector(selector)
|
|
65
|
-
res.push(handleFields(fields, el, selector))
|
|
66
|
-
} else {
|
|
67
|
-
const els = selectSelf
|
|
68
|
-
? [curComponent]
|
|
69
|
-
: Array.from(curComponent.querySelectorAll(selector))
|
|
70
|
-
const elsArr = els.map(el => handleFields(fields, el, null))
|
|
71
|
-
res.push(elsArr)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
res.forEach((item, idx) => {
|
|
76
|
-
typeof queueCb[idx] === 'function' && queueCb[idx].call(this, item)
|
|
77
|
-
})
|
|
78
|
-
typeof callback === 'function' && callback.call(this, res)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
_handleFields (fields, el, selector) {
|
|
82
|
-
const { id, dataset, rect, size, scrollOffset, properties = [], computedStyle = [], node } = fields
|
|
83
|
-
const { left, right, top, bottom, width, height } = el.getBoundingClientRect()
|
|
84
|
-
|
|
85
|
-
const res = {}
|
|
86
|
-
const isViewport = selector === 'html'
|
|
87
|
-
if (id) res.id = el.id
|
|
88
|
-
if (dataset) res.dataset = Object.assign({}, el.dataset)
|
|
89
|
-
if (rect) {
|
|
90
|
-
if (isViewport) {
|
|
91
|
-
res.left = 0
|
|
92
|
-
res.right = 0
|
|
93
|
-
res.top = 0
|
|
94
|
-
res.bottom = 0
|
|
95
|
-
} else {
|
|
96
|
-
res.left = left
|
|
97
|
-
res.right = right
|
|
98
|
-
res.top = top
|
|
99
|
-
res.bottom = bottom
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (size) {
|
|
103
|
-
if (isViewport) {
|
|
104
|
-
res.width = el.clientWidth
|
|
105
|
-
res.height = el.clientHeight
|
|
106
|
-
} else {
|
|
107
|
-
res.width = width
|
|
108
|
-
res.height = height
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// 添加获取节点信息
|
|
112
|
-
if (node) {
|
|
113
|
-
res.node = el
|
|
114
|
-
if (isCanvas(el)) {
|
|
115
|
-
// 避免lint检查报错
|
|
116
|
-
el.createImage = function () {
|
|
117
|
-
return new Image() // eslint-disable-line
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
el.createPath2D = function (path) {
|
|
121
|
-
return window.Path2D(path)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
el.requestAnimationFrame = function (callback) {
|
|
125
|
-
return window.requestAnimationFrame(callback)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
el.cancelAnimationFrame = function (requestID) {
|
|
129
|
-
return window.cancelAnimationFrame(requestID)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const rawGetContext = el.getContext
|
|
133
|
-
el.getContext = function (...args) {
|
|
134
|
-
const context = rawGetContext.apply(this, args)
|
|
135
|
-
// 如果实例方法有变动,可以在这里进行处理
|
|
136
|
-
return context
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (scrollOffset) {
|
|
141
|
-
res.scrollLeft = el.scrollLeft
|
|
142
|
-
res.scrollTop = el.scrollTop
|
|
143
|
-
}
|
|
144
|
-
properties.forEach(prop => {
|
|
145
|
-
const attr = el.getAttribute(prop)
|
|
146
|
-
if (attr) {
|
|
147
|
-
res[prop] = attr
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
if (computedStyle.length) {
|
|
151
|
-
const styles = window.getComputedStyle(el)
|
|
152
|
-
computedStyle.forEach(style => {
|
|
153
|
-
const midLineStyle = style.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`)
|
|
154
|
-
const value = styles.getPropertyValue(midLineStyle)
|
|
155
|
-
if (value) {
|
|
156
|
-
res[style] = value
|
|
157
|
-
}
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
return res
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
_push (selector, component, single, fields, callback) {
|
|
164
|
-
this._queue.push({
|
|
165
|
-
component,
|
|
166
|
-
selector,
|
|
167
|
-
single,
|
|
168
|
-
fields
|
|
169
|
-
})
|
|
170
|
-
this._queueCb.push(callback)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
_isEl (selector) {
|
|
174
|
-
if (Array.isArray(selector)) return this._isEl(selector[0])
|
|
175
|
-
return selector && selector.nodeType === 1
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
class NodesRef {
|
|
180
|
-
constructor (selector, selectorQuery, single) {
|
|
181
|
-
this._selector = selector
|
|
182
|
-
this._selectorQuery = selectorQuery
|
|
183
|
-
this._component = selectorQuery._component
|
|
184
|
-
this._single = single
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
boundingClientRect (callback) {
|
|
188
|
-
this._selectorQuery._push(
|
|
189
|
-
this._selector,
|
|
190
|
-
this._component,
|
|
191
|
-
this._single,
|
|
192
|
-
{
|
|
193
|
-
id: true,
|
|
194
|
-
dataset: true,
|
|
195
|
-
rect: true,
|
|
196
|
-
size: true
|
|
197
|
-
},
|
|
198
|
-
callback
|
|
199
|
-
)
|
|
200
|
-
return this._selectorQuery
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
scrollOffset (callback) {
|
|
204
|
-
this._selectorQuery._push(
|
|
205
|
-
this._selector,
|
|
206
|
-
this._component,
|
|
207
|
-
this._single,
|
|
208
|
-
{
|
|
209
|
-
id: true,
|
|
210
|
-
dataset: true,
|
|
211
|
-
scrollOffset: true
|
|
212
|
-
},
|
|
213
|
-
callback
|
|
214
|
-
)
|
|
215
|
-
return this._selectorQuery
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
fields (fields, callback) {
|
|
219
|
-
this._selectorQuery._push(
|
|
220
|
-
this._selector,
|
|
221
|
-
this._component,
|
|
222
|
-
this._single,
|
|
223
|
-
fields,
|
|
224
|
-
callback
|
|
225
|
-
)
|
|
226
|
-
return this._selectorQuery
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// 获取Node节点实例
|
|
230
|
-
node (callback) {
|
|
231
|
-
this._selectorQuery._push(
|
|
232
|
-
this._selector,
|
|
233
|
-
this._component,
|
|
234
|
-
this._single,
|
|
235
|
-
{
|
|
236
|
-
node: true
|
|
237
|
-
},
|
|
238
|
-
callback
|
|
239
|
-
)
|
|
240
|
-
return this._selectorQuery
|
|
241
|
-
}
|
|
242
|
-
}
|
|
3
|
+
import * as webApi from '@mpxjs/api-proxy/src/web/api'
|
|
243
4
|
|
|
244
5
|
function getIdentifier (vnode) {
|
|
245
6
|
let identifier = ''
|
|
@@ -280,13 +41,13 @@ function processRefs (refs) {
|
|
|
280
41
|
const ref = refs[key]
|
|
281
42
|
if (Array.isArray(ref)) {
|
|
282
43
|
if (getEl(ref[0])) {
|
|
283
|
-
refs[rKey] =
|
|
44
|
+
refs[rKey] = webApi.createSelectorQuery().in(this).selectAll(ref.map(getEl))
|
|
284
45
|
} else {
|
|
285
46
|
refs[rKey] = ref
|
|
286
47
|
}
|
|
287
48
|
} else {
|
|
288
49
|
if (getEl(ref)) {
|
|
289
|
-
refs[rKey] =
|
|
50
|
+
refs[rKey] = webApi.createSelectorQuery().in(this).select(getEl(ref))
|
|
290
51
|
} else {
|
|
291
52
|
refs[rKey] = ref
|
|
292
53
|
}
|
|
@@ -305,7 +66,10 @@ export default function getRefsMixin () {
|
|
|
305
66
|
},
|
|
306
67
|
methods: {
|
|
307
68
|
createSelectorQuery () {
|
|
308
|
-
return
|
|
69
|
+
return webApi.createSelectorQuery().in(this)
|
|
70
|
+
},
|
|
71
|
+
createIntersectionObserver (component, options) {
|
|
72
|
+
return webApi.createIntersectionObserver(component, options)
|
|
309
73
|
},
|
|
310
74
|
selectComponent (selector, all) {
|
|
311
75
|
const result = []
|
|
@@ -322,8 +86,3 @@ export default function getRefsMixin () {
|
|
|
322
86
|
}
|
|
323
87
|
}
|
|
324
88
|
}
|
|
325
|
-
|
|
326
|
-
// 判断是不是canvas元素
|
|
327
|
-
function isCanvas (el) {
|
|
328
|
-
return el.nodeName && el.nodeName.toLowerCase() === 'canvas'
|
|
329
|
-
}
|