@mpxjs/core 2.9.69 → 2.9.70
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 +7 -3
- package/src/convertor/convertor.js +11 -32
- package/src/convertor/wxToAli.js +3 -3
- package/src/convertor/wxToSwan.js +3 -3
- package/src/convertor/wxToWeb.js +3 -3
- package/src/core/proxy.js +18 -12
- package/src/dynamic/dynamicRenderMixin.js +2 -2
- package/src/index.js +3 -14
- package/src/observer/reactive.js +5 -4
- package/src/observer/ref.js +3 -2
- package/src/observer/scheduler.js +4 -0
- package/src/observer/watch.js +5 -4
- package/src/platform/builtInMixins/directiveHelperMixin.ios.js +4 -1
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +7 -4
- package/src/platform/createApp.ios.js +45 -33
- package/src/platform/createApp.js +7 -9
- package/src/platform/env/event.js +108 -0
- package/src/platform/env/index.ios.js +51 -0
- package/src/platform/env/index.js +8 -0
- package/src/platform/env/index.web.js +48 -0
- package/src/{external → platform/env}/vuePlugin.js +1 -1
- package/src/platform/export/index.js +1 -1
- package/src/platform/patch/{ali/getDefaultOptions.js → getDefaultOptions.ali.js} +3 -3
- package/src/platform/patch/{react/getDefaultOptions.ios.js → getDefaultOptions.ios.js} +263 -192
- package/src/platform/patch/{wx/getDefaultOptions.js → getDefaultOptions.js} +11 -5
- package/src/platform/patch/{web/getDefaultOptions.js → getDefaultOptions.web.js} +5 -5
- package/src/platform/patch/index.js +4 -21
- package/src/platform/patch/{ali/lifecycle.js → lifecycle/index.ali.js} +2 -0
- package/src/platform/patch/lifecycle/index.js +1 -0
- package/src/platform/patch/{swan/lifecycle.js → lifecycle/index.swan.js} +2 -0
- package/src/platform/patch/{web/lifecycle.js → lifecycle/index.web.js} +4 -0
- package/src/platform/patch/{wx/lifecycle.js → lifecycle/index.wx.js} +2 -0
- package/src/external/vue.js +0 -1
- package/src/external/vue.web.js +0 -6
- package/src/platform/patch/react/getDefaultOptions.js +0 -1
- package/src/platform/patch/swan/getDefaultOptions.js +0 -34
- /package/src/platform/export/{apiInject.js → inject.js} +0 -0
- /package/src/platform/export/{apiInject.web.js → inject.web.js} +0 -0
|
@@ -3,11 +3,11 @@ import mergeOptions from '../core/mergeOptions'
|
|
|
3
3
|
import builtInKeysMap from './patch/builtInKeysMap'
|
|
4
4
|
import { makeMap, spreadProp, isBrowser } from '@mpxjs/utils'
|
|
5
5
|
import { mergeLifecycle } from '../convertor/mergeLifecycle'
|
|
6
|
-
import
|
|
6
|
+
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
|
|
7
7
|
import Mpx from '../index'
|
|
8
|
-
import { initAppProvides } from './export/
|
|
8
|
+
import { initAppProvides } from './export/inject'
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)
|
|
11
11
|
|
|
12
12
|
function filterOptions (options, appData) {
|
|
13
13
|
const newOptions = {}
|
|
@@ -15,7 +15,7 @@ function filterOptions (options, appData) {
|
|
|
15
15
|
if (builtInKeysMap[key]) {
|
|
16
16
|
return
|
|
17
17
|
}
|
|
18
|
-
if (__mpx_mode__ === 'web' && !
|
|
18
|
+
if (__mpx_mode__ === 'web' && !appHooksMap[key] && key !== 'provide') {
|
|
19
19
|
appData[key] = options[key]
|
|
20
20
|
} else {
|
|
21
21
|
newOptions[key] = options[key]
|
|
@@ -47,11 +47,6 @@ export default function createApp (option, config = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
global.__mpxEnterOptions = options
|
|
49
49
|
this.$options.onLaunch && this.$options.onLaunch.call(this, options)
|
|
50
|
-
global.__mpxAppCbs = global.__mpxAppCbs || {
|
|
51
|
-
show: [],
|
|
52
|
-
hide: [],
|
|
53
|
-
error: []
|
|
54
|
-
}
|
|
55
50
|
if (isBrowser) {
|
|
56
51
|
if (this.$options.onShow) {
|
|
57
52
|
this.$options.onShow.call(this, options)
|
|
@@ -63,6 +58,9 @@ export default function createApp (option, config = {}) {
|
|
|
63
58
|
if (this.$options.onError) {
|
|
64
59
|
global.__mpxAppCbs.error.push(this.$options.onError.bind(this))
|
|
65
60
|
}
|
|
61
|
+
if (this.$options.onUnhandledRejection) {
|
|
62
|
+
global.__mpxAppCbs.rejection.push(this.$options.onUnhandledRejection.bind(this))
|
|
63
|
+
}
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isBrowser } from '@mpxjs/utils'
|
|
2
|
+
|
|
3
|
+
function extendEvent (e, extendObj = {}) {
|
|
4
|
+
Object.keys(extendObj).forEach((key) => {
|
|
5
|
+
Object.defineProperty(e, key, {
|
|
6
|
+
value: extendObj[key],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true
|
|
10
|
+
})
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function MpxEvent (layer) {
|
|
15
|
+
this.targetElement = null
|
|
16
|
+
this.touches = []
|
|
17
|
+
this.touchStartX = 0
|
|
18
|
+
this.touchStartY = 0
|
|
19
|
+
this.startTimer = null
|
|
20
|
+
this.needTap = true
|
|
21
|
+
this.isTouchDevice = document && ('ontouchstart' in document.documentElement)
|
|
22
|
+
|
|
23
|
+
this.onTouchStart = (event) => {
|
|
24
|
+
if (event.targetTouches?.length > 1) {
|
|
25
|
+
return true
|
|
26
|
+
}
|
|
27
|
+
this.touches = event.targetTouches
|
|
28
|
+
this.targetElement = event.target
|
|
29
|
+
this.needTap = true
|
|
30
|
+
this.startTimer = null
|
|
31
|
+
this.touchStartX = this.touches[0].pageX
|
|
32
|
+
this.touchStartY = this.touches[0].pageY
|
|
33
|
+
this.startTimer = setTimeout(() => {
|
|
34
|
+
this.needTap = false
|
|
35
|
+
this.sendEvent(this.targetElement, 'longpress', event)
|
|
36
|
+
this.sendEvent(this.targetElement, 'longtap', event)
|
|
37
|
+
}, 350)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.onTouchMove = (event) => {
|
|
41
|
+
const touch = event.changedTouches[0]
|
|
42
|
+
if (Math.abs(touch.pageX - this.touchStartX) > 1 || Math.abs(touch.pageY - this.touchStartY) > 1) {
|
|
43
|
+
this.needTap = false
|
|
44
|
+
this.startTimer && clearTimeout(this.startTimer)
|
|
45
|
+
this.startTimer = null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.onTouchEnd = (event) => {
|
|
50
|
+
if (event.targetTouches?.length > 1) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
this.startTimer && clearTimeout(this.startTimer)
|
|
54
|
+
this.startTimer = null
|
|
55
|
+
if (this.needTap) {
|
|
56
|
+
this.sendEvent(this.targetElement, 'tap', event)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.onClick = (event) => {
|
|
61
|
+
this.targetElement = event.target
|
|
62
|
+
this.sendEvent(this.targetElement, 'tap', event)
|
|
63
|
+
}
|
|
64
|
+
this.sendEvent = (targetElement, type, event) => {
|
|
65
|
+
const touchEvent = new CustomEvent(type, {
|
|
66
|
+
bubbles: true,
|
|
67
|
+
cancelable: true
|
|
68
|
+
})
|
|
69
|
+
const changedTouches = event.changedTouches || []
|
|
70
|
+
extendEvent(touchEvent, {
|
|
71
|
+
timeStamp: event.timeStamp,
|
|
72
|
+
changedTouches,
|
|
73
|
+
touches: changedTouches,
|
|
74
|
+
detail: {
|
|
75
|
+
// pc端点击事件可能没有changedTouches,所以直接从 event中取
|
|
76
|
+
x: changedTouches[0]?.pageX || event.pageX || 0,
|
|
77
|
+
y: changedTouches[0]?.pageY || event.pageY || 0
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
targetElement && targetElement.dispatchEvent(touchEvent)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.addListener = () => {
|
|
84
|
+
if (this.isTouchDevice) {
|
|
85
|
+
layer.addEventListener('touchstart', this.onTouchStart, true)
|
|
86
|
+
layer.addEventListener('touchmove', this.onTouchMove, true)
|
|
87
|
+
layer.addEventListener('touchend', this.onTouchEnd, true)
|
|
88
|
+
} else {
|
|
89
|
+
layer.addEventListener('click', this.onClick, true)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.addListener()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function initEvent () {
|
|
96
|
+
if (isBrowser && !global.__mpxCreatedEvent) {
|
|
97
|
+
global.__mpxCreatedEvent = true
|
|
98
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
99
|
+
// eslint-disable-next-line no-new
|
|
100
|
+
new MpxEvent(document.body)
|
|
101
|
+
} else {
|
|
102
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
103
|
+
// eslint-disable-next-line no-new
|
|
104
|
+
new MpxEvent(document.body)
|
|
105
|
+
}, false)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createI18n } from '../builtInMixins/i18nMixin'
|
|
2
|
+
|
|
3
|
+
export function init (Mpx) {
|
|
4
|
+
global.__mpx = Mpx
|
|
5
|
+
global.__mpxAppCbs = global.__mpxAppCbs || {
|
|
6
|
+
show: [],
|
|
7
|
+
hide: [],
|
|
8
|
+
error: [],
|
|
9
|
+
rejection: []
|
|
10
|
+
}
|
|
11
|
+
if (global.i18n) {
|
|
12
|
+
Mpx.i18n = createI18n(global.i18n)
|
|
13
|
+
}
|
|
14
|
+
initGlobalErrorHandling()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function initGlobalErrorHandling () {
|
|
18
|
+
if (global.ErrorUtils) {
|
|
19
|
+
const defaultHandler = global.ErrorUtils.getGlobalHandler()
|
|
20
|
+
global.ErrorUtils.setGlobalHandler((error, isFatal) => {
|
|
21
|
+
if (global.__mpxAppCbs && global.__mpxAppCbs.error && global.__mpxAppCbs.error.length) {
|
|
22
|
+
global.__mpxAppCbs.error.forEach((cb) => {
|
|
23
|
+
cb(error)
|
|
24
|
+
})
|
|
25
|
+
} else if (defaultHandler) {
|
|
26
|
+
defaultHandler(error, isFatal)
|
|
27
|
+
} else {
|
|
28
|
+
console.error(`${error.name}: ${error.message}\n`)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const rejectionTrackingOptions = {
|
|
34
|
+
allRejections: true,
|
|
35
|
+
onUnhandled (id, error) {
|
|
36
|
+
if (global.__mpxAppCbs && global.__mpxAppCbs.rejection && global.__mpxAppCbs.rejection.length) {
|
|
37
|
+
global.__mpxAppCbs.rejection.forEach((cb) => {
|
|
38
|
+
cb(error, id)
|
|
39
|
+
})
|
|
40
|
+
} else {
|
|
41
|
+
console.warn(`UNHANDLED PROMISE REJECTION (id: ${id}): ${error}\n`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (global?.HermesInternal?.hasPromise?.()) {
|
|
47
|
+
global.HermesInternal?.enablePromiseRejectionTracker?.(rejectionTrackingOptions)
|
|
48
|
+
} else {
|
|
49
|
+
require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Vue from 'vue'
|
|
2
|
+
import install from './vuePlugin'
|
|
3
|
+
import { isBrowser, error, warn } from '@mpxjs/utils'
|
|
4
|
+
import { initEvent } from './event'
|
|
5
|
+
|
|
6
|
+
export function init (Mpx) {
|
|
7
|
+
global.__mpx = Mpx
|
|
8
|
+
global.__mpxAppCbs = global.__mpxAppCbs || {
|
|
9
|
+
show: [],
|
|
10
|
+
hide: [],
|
|
11
|
+
error: [],
|
|
12
|
+
rejection: []
|
|
13
|
+
}
|
|
14
|
+
Mpx.__vue = Vue
|
|
15
|
+
Vue.use(install)
|
|
16
|
+
initEvent()
|
|
17
|
+
initGlobalErrorHandling()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function initGlobalErrorHandling () {
|
|
21
|
+
Vue.config.errorHandler = (e, vm, info) => {
|
|
22
|
+
error(`Unhandled error occurs${info ? ` during execution of [${info}]` : ''}!`, vm?.__mpxProxy?.options.mpxFileResource, e)
|
|
23
|
+
}
|
|
24
|
+
Vue.config.warnHandler = (msg, vm, trace) => {
|
|
25
|
+
warn(msg, vm?.__mpxProxy?.options.mpxFileResource, trace)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isBrowser) {
|
|
29
|
+
window.addEventListener('error', (event) => {
|
|
30
|
+
if (global.__mpxAppCbs && global.__mpxAppCbs.error && global.__mpxAppCbs.error.length) {
|
|
31
|
+
global.__mpxAppCbs.error.forEach((cb) => {
|
|
32
|
+
cb(event.error)
|
|
33
|
+
})
|
|
34
|
+
} else {
|
|
35
|
+
console.error(`${event.type}: ${event.message}\n`)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
39
|
+
if (global.__mpxAppCbs && global.__mpxAppCbs.rejection && global.__mpxAppCbs.rejection.length) {
|
|
40
|
+
global.__mpxAppCbs.rejection.forEach((cb) => {
|
|
41
|
+
cb(event.reason, event.promise)
|
|
42
|
+
})
|
|
43
|
+
} else {
|
|
44
|
+
console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}\n`)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -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 () {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import MpxProxy from '
|
|
2
|
-
import builtInKeysMap from '
|
|
3
|
-
import mergeOptions from '
|
|
1
|
+
import MpxProxy from '../../core/proxy'
|
|
2
|
+
import builtInKeysMap from './builtInKeysMap'
|
|
3
|
+
import mergeOptions from '../../core/mergeOptions'
|
|
4
4
|
import { error, diffAndCloneA, hasOwn, noop, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
|
|
5
5
|
|
|
6
6
|
function transformApiForProxy (context, currentInject) {
|