@mpxjs/webpack-plugin 2.9.67 → 2.9.69-beta.1
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/lib/index.js +30 -9
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/movable-view.js +8 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +1 -1
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processStyles.js +14 -4
- package/lib/react/processTemplate.js +3 -0
- package/lib/resolver/AddEnvPlugin.js +1 -0
- package/lib/resolver/AddModePlugin.js +9 -8
- package/lib/runtime/components/react/context.ts +14 -0
- package/lib/runtime/components/react/dist/context.js +4 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -175
- package/lib/runtime/components/react/dist/mpx-button.jsx +77 -49
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +232 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +14 -14
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column-item.jsx +39 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +171 -88
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +80 -121
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +62 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +53 -42
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +28 -9
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +608 -0
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +67 -94
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +152 -37
- package/lib/runtime/components/react/dist/pickerFaces.js +81 -0
- package/lib/runtime/components/react/dist/pickerVIewContext.js +9 -0
- package/lib/runtime/components/react/dist/pickerViewMask.jsx +18 -0
- package/lib/runtime/components/react/dist/pickerViewOverlay.jsx +23 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +36 -10
- package/lib/runtime/components/react/dist/utils.jsx +129 -24
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -202
- package/lib/runtime/components/react/mpx-button.tsx +104 -57
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +296 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +22 -26
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column-item.tsx +88 -0
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +276 -112
- package/lib/runtime/components/react/mpx-picker-view.tsx +137 -129
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +115 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +83 -73
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +41 -12
- package/lib/runtime/components/react/mpx-swiper.tsx +690 -0
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +93 -117
- package/lib/runtime/components/react/mpx-web-view.tsx +162 -56
- package/lib/runtime/components/react/pickerFaces.ts +112 -0
- package/lib/runtime/components/react/pickerVIewContext.ts +18 -0
- package/lib/runtime/components/react/pickerViewMask.tsx +30 -0
- package/lib/runtime/components/react/pickerViewOverlay.tsx +34 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +7 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +37 -12
- package/lib/runtime/components/react/utils.tsx +169 -29
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/index.js +3 -4
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/style-compiler/strip-conditional-loader.js +118 -0
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +66 -39
- package/lib/template-compiler/gen-node-react.js +3 -3
- package/package.json +6 -4
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +0 -478
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +0 -68
- package/lib/runtime/components/react/dist/mpx-swiper/type.js +0 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +0 -525
- package/lib/runtime/components/react/mpx-swiper/index.tsx +0 -80
- package/lib/runtime/components/react/mpx-swiper/type.ts +0 -87
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -3,184 +3,198 @@
|
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
import { getCustomEvent } from './getInnerListeners'
|
|
7
|
+
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
8
|
+
import { extend, isFunction } from '@mpxjs/utils'
|
|
9
|
+
|
|
10
|
+
const navObj = promisify({ redirectTo, navigateTo, navigateBack, reLaunch, switchTab })
|
|
11
|
+
const eventLoad = 'load'
|
|
12
|
+
const eventError = 'error'
|
|
13
|
+
const eventMessage = 'message'
|
|
14
|
+
const mpx = global.__mpx
|
|
15
|
+
export default {
|
|
16
|
+
props: {
|
|
17
|
+
src: {
|
|
18
|
+
type: String
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
computed: {
|
|
22
|
+
host () {
|
|
23
|
+
let host = this.src.split('/')
|
|
24
|
+
if (host[2]) {
|
|
25
|
+
host = host[0] + '//' + host[2]
|
|
26
|
+
} else {
|
|
27
|
+
host = ''
|
|
17
28
|
}
|
|
29
|
+
return host
|
|
18
30
|
},
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
host = ''
|
|
26
|
-
}
|
|
27
|
-
return host
|
|
28
|
-
},
|
|
29
|
-
currentUrl () {
|
|
30
|
-
if (!this.src) return ''
|
|
31
|
-
const hostValidate = this.hostValidate(this.host)
|
|
32
|
-
if (!hostValidate) {
|
|
33
|
-
console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
|
|
34
|
-
return ''
|
|
35
|
-
}
|
|
36
|
-
let src
|
|
37
|
-
const srcQueryIndex = this.src.indexOf('?')
|
|
38
|
-
// webview与被打开页面通过_uid确定关联关系
|
|
39
|
-
if (srcQueryIndex > -1) {
|
|
40
|
-
src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
|
|
41
|
-
} else {
|
|
42
|
-
src = `${this.src}?mpx_webview_id=${this._uid}`
|
|
43
|
-
}
|
|
44
|
-
return src
|
|
45
|
-
},
|
|
46
|
-
loadData () {
|
|
47
|
-
return {
|
|
48
|
-
src: this.host,
|
|
49
|
-
fullUrl: this.src
|
|
50
|
-
}
|
|
31
|
+
currentUrl () {
|
|
32
|
+
if (!this.src) return ''
|
|
33
|
+
const hostValidate = this.hostValidate(this.host)
|
|
34
|
+
if (!hostValidate) {
|
|
35
|
+
console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
|
|
36
|
+
return ''
|
|
51
37
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
errMsg: 'web-view load failed due to not in domain list'
|
|
60
|
-
}, this))
|
|
61
|
-
} else {
|
|
62
|
-
this.$nextTick(() => {
|
|
63
|
-
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
|
|
64
|
-
this.mpxIframe = this.$refs.mpxIframe
|
|
65
|
-
this.mpxIframe.addEventListener('load', (event) => {
|
|
66
|
-
this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
immediate: true
|
|
38
|
+
let src
|
|
39
|
+
const srcQueryIndex = this.src.indexOf('?')
|
|
40
|
+
// webview与被打开页面通过_uid确定关联关系
|
|
41
|
+
if (srcQueryIndex > -1) {
|
|
42
|
+
src = `${this.src.substring(0, srcQueryIndex + 1)}mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
|
|
43
|
+
} else {
|
|
44
|
+
src = `${this.src}?mpx_webview_id=${this._uid}`
|
|
73
45
|
}
|
|
46
|
+
return src
|
|
74
47
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
window.addEventListener('message', this.messageCallback)
|
|
80
|
-
},
|
|
81
|
-
deactivated () {
|
|
82
|
-
if (!this.messageList.length) {
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
let data = {
|
|
86
|
-
type: 'message',
|
|
87
|
-
data: this.messageList
|
|
48
|
+
loadData () {
|
|
49
|
+
return {
|
|
50
|
+
src: this.host,
|
|
51
|
+
fullUrl: this.src
|
|
88
52
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
watch: {
|
|
56
|
+
currentUrl: {
|
|
57
|
+
handler (value) {
|
|
58
|
+
if (!value) {
|
|
59
|
+
this.$emit(eventError, getCustomEvent(eventError, extend({
|
|
60
|
+
errMsg: 'web-view load failed due to not in domain list'
|
|
61
|
+
}, this.loadData), this))
|
|
62
|
+
} else {
|
|
63
|
+
this.$nextTick(() => {
|
|
64
|
+
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
|
|
65
|
+
this.mpxIframe = this.$refs.mpxIframe
|
|
66
|
+
this.mpxIframe.addEventListener('load', () => {
|
|
67
|
+
this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
immediate: true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
beforeCreate () {
|
|
77
|
+
this.messageList = []
|
|
78
|
+
},
|
|
79
|
+
mounted () {
|
|
80
|
+
window.addEventListener('message', this.messageCallback)
|
|
81
|
+
},
|
|
82
|
+
deactivated () {
|
|
83
|
+
if (!this.messageList.length) {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
let data = {
|
|
87
|
+
type: 'message',
|
|
88
|
+
data: this.messageList
|
|
89
|
+
}
|
|
90
|
+
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
91
|
+
},
|
|
92
|
+
destroyed () {
|
|
93
|
+
window.removeEventListener('message', this.messageCallback)
|
|
94
|
+
if (!this.messageList.length) {
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
let data = {
|
|
98
|
+
type: 'message',
|
|
99
|
+
data: this.messageList
|
|
100
|
+
}
|
|
101
|
+
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
102
|
+
},
|
|
103
|
+
methods: {
|
|
104
|
+
messageCallback (event) {
|
|
105
|
+
const hostValidate = this.hostValidate(event.origin)
|
|
106
|
+
let data = {}
|
|
107
|
+
try {
|
|
108
|
+
const eventData = event.data
|
|
109
|
+
data = typeof eventData === 'string' ? JSON.parse(eventData) : eventData
|
|
110
|
+
} catch(e){}
|
|
111
|
+
// 判断number类型,防止undefined导致触发return逻辑
|
|
112
|
+
if (data.clientUid !== undefined && +data.clientUid !== this._uid) {
|
|
94
113
|
return
|
|
95
114
|
}
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
|
|
115
|
+
let value = data.payload
|
|
116
|
+
const args = data.args
|
|
117
|
+
const params = Array.isArray(args) ? args : [value]
|
|
118
|
+
if (!hostValidate) {
|
|
119
|
+
return
|
|
99
120
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
break
|
|
134
|
-
case 'reLaunch':
|
|
135
|
-
asyncCallback = navObj.reLaunch(value)
|
|
136
|
-
break
|
|
137
|
-
case 'getLocation':
|
|
138
|
-
const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
|
|
139
|
-
if (getLocation) {
|
|
140
|
-
asyncCallback = getLocation()
|
|
121
|
+
let asyncCallback = null
|
|
122
|
+
const type = data.type
|
|
123
|
+
switch (type) {
|
|
124
|
+
case 'postMessage':
|
|
125
|
+
let data = {
|
|
126
|
+
type: 'message',
|
|
127
|
+
data: params[0]?.data
|
|
128
|
+
}
|
|
129
|
+
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
130
|
+
asyncCallback = Promise.resolve({
|
|
131
|
+
errMsg: 'invokeWebappApi:ok'
|
|
132
|
+
})
|
|
133
|
+
break
|
|
134
|
+
case 'navigateTo':
|
|
135
|
+
asyncCallback = navObj.navigateTo(...params)
|
|
136
|
+
break
|
|
137
|
+
case 'navigateBack':
|
|
138
|
+
asyncCallback = navObj.navigateBack(...params)
|
|
139
|
+
break
|
|
140
|
+
case 'redirectTo':
|
|
141
|
+
asyncCallback = navObj.redirectTo(...params)
|
|
142
|
+
break
|
|
143
|
+
case 'switchTab':
|
|
144
|
+
asyncCallback = navObj.switchTab(...params)
|
|
145
|
+
break
|
|
146
|
+
case 'reLaunch':
|
|
147
|
+
asyncCallback = navObj.reLaunch(...params)
|
|
148
|
+
break
|
|
149
|
+
default:
|
|
150
|
+
if (type) {
|
|
151
|
+
const implement = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
|
|
152
|
+
if (isFunction(implement)) {
|
|
153
|
+
asyncCallback = Promise.resolve(implement(...params))
|
|
141
154
|
} else {
|
|
142
155
|
asyncCallback = Promise.reject({
|
|
143
|
-
errMsg:
|
|
156
|
+
errMsg: `未在apiImplementations中配置${type}方法`
|
|
144
157
|
})
|
|
145
158
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
}
|
|
160
|
+
break
|
|
161
|
+
}
|
|
162
|
+
asyncCallback && asyncCallback.then((res) => {
|
|
163
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
164
|
+
type: type,
|
|
165
|
+
callbackId: data.callbackId,
|
|
166
|
+
result: res
|
|
167
|
+
}, event.origin)
|
|
168
|
+
}).catch((error) => {
|
|
169
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
170
|
+
type: type,
|
|
171
|
+
callbackId: data.callbackId,
|
|
172
|
+
error
|
|
173
|
+
}, event.origin)
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
hostValidate (host) {
|
|
177
|
+
const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
|
|
178
|
+
if (hostWhitelists.length) {
|
|
179
|
+
return hostWhitelists.some((item) => {
|
|
180
|
+
return host.endsWith(item)
|
|
160
181
|
})
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
|
|
164
|
-
if (hostWhitelists.length) {
|
|
165
|
-
return hostWhitelists.some((item) => {
|
|
166
|
-
return host.endsWith(item)
|
|
167
|
-
})
|
|
168
|
-
} else {
|
|
169
|
-
return true
|
|
170
|
-
}
|
|
182
|
+
} else {
|
|
183
|
+
return true
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
186
|
}
|
|
187
|
+
}
|
|
174
188
|
</script>
|
|
175
189
|
|
|
176
190
|
<style>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
</style>
|
|
191
|
+
.mpx-iframe {
|
|
192
|
+
width: 100%;
|
|
193
|
+
height: 100%;
|
|
194
|
+
position: absolute;
|
|
195
|
+
left: 0;
|
|
196
|
+
top: 0;
|
|
197
|
+
right: 0;
|
|
198
|
+
bottom: 0;
|
|
199
|
+
}
|
|
200
|
+
</style>
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { hasOwn, isEmptyObject } from './utils'
|
|
1
|
+
import { hasOwn, isEmptyObject, extend } from './utils'
|
|
2
2
|
import { isBrowser } from './env'
|
|
3
3
|
import transRpxStyle from './transRpxStyle'
|
|
4
4
|
import animation from './animation'
|
|
5
|
-
import { createEvent } from './components/web/event'
|
|
6
|
-
|
|
7
|
-
createEvent()
|
|
8
5
|
|
|
9
6
|
export function processComponentOption (
|
|
10
7
|
{
|
|
@@ -59,7 +56,7 @@ registered in parent context!`)
|
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
if (ctorType === 'page') {
|
|
62
|
-
option.__mpxPageConfig =
|
|
59
|
+
option.__mpxPageConfig = extend({}, global.__mpxPageConfig, pageConfig)
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
if (!hasApp) {
|
|
@@ -109,7 +106,7 @@ registered in parent context!`)
|
|
|
109
106
|
export function getComponent (component, extendOptions) {
|
|
110
107
|
component = component.__esModule ? component.default : component
|
|
111
108
|
// eslint-disable-next-line
|
|
112
|
-
if (extendOptions)
|
|
109
|
+
if (extendOptions) extend(component, extendOptions)
|
|
113
110
|
return component
|
|
114
111
|
}
|
|
115
112
|
|
|
@@ -164,10 +161,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
164
161
|
})
|
|
165
162
|
}
|
|
166
163
|
const webRouteConfig = global.__mpx.config.webConfig.routeConfig || global.__mpx.config.webRouteConfig
|
|
167
|
-
global.__mpxRouter = option.router = new VueRouter({
|
|
168
|
-
...webRouteConfig,
|
|
169
|
-
routes: routes
|
|
170
|
-
})
|
|
164
|
+
global.__mpxRouter = option.router = new VueRouter(extend({ routes }, webRouteConfig))
|
|
171
165
|
let mpxStackPath = []
|
|
172
166
|
if (isBrowser) {
|
|
173
167
|
// 解决webview被刷新导致路由栈丢失后产生错乱问题
|
|
@@ -312,25 +306,6 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
312
306
|
})
|
|
313
307
|
// 处理visibilitychange时触发当前活跃页面组件的onshow/onhide
|
|
314
308
|
if (isBrowser) {
|
|
315
|
-
const errorHandler = function (args, fromVue) {
|
|
316
|
-
if (global.__mpxAppCbs && global.__mpxAppCbs.error && global.__mpxAppCbs.error.length) {
|
|
317
|
-
global.__mpxAppCbs.error.forEach((cb) => {
|
|
318
|
-
cb.apply(null, args)
|
|
319
|
-
})
|
|
320
|
-
console.error(...args)
|
|
321
|
-
} else if (fromVue) {
|
|
322
|
-
throw args[0]
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
Vue.config.errorHandler = (...args) => {
|
|
326
|
-
return errorHandler(args, true)
|
|
327
|
-
}
|
|
328
|
-
window.addEventListener('error', (event) => {
|
|
329
|
-
return errorHandler([event.error, event])
|
|
330
|
-
})
|
|
331
|
-
window.addEventListener('unhandledrejection', (event) => {
|
|
332
|
-
return errorHandler([event.reason, event])
|
|
333
|
-
})
|
|
334
309
|
document.addEventListener('visibilitychange', function () {
|
|
335
310
|
const vnode = global.__mpxRouter && global.__mpxRouter.__mpxActiveVnode
|
|
336
311
|
if (vnode && vnode.componentInstance) {
|
|
@@ -365,7 +340,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
365
340
|
|
|
366
341
|
if (App.onAppInit) {
|
|
367
342
|
global.__mpxAppInit = true
|
|
368
|
-
|
|
343
|
+
extend(option, App.onAppInit() || {})
|
|
369
344
|
global.__mpxAppInit = false
|
|
370
345
|
}
|
|
371
346
|
|
|
@@ -374,14 +349,8 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
374
349
|
option.pinia = global.__mpxPinia
|
|
375
350
|
}
|
|
376
351
|
|
|
377
|
-
const app = new Vue({
|
|
378
|
-
|
|
379
|
-
render: (h) => h(App)
|
|
380
|
-
})
|
|
381
|
-
return {
|
|
382
|
-
app,
|
|
383
|
-
...option
|
|
384
|
-
}
|
|
352
|
+
const app = new Vue(extend(option, { render: (h) => h(App) }))
|
|
353
|
+
return extend({ app }, option)
|
|
385
354
|
}
|
|
386
355
|
|
|
387
356
|
export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
|
package/lib/runtime/utils.js
CHANGED
|
@@ -4,7 +4,6 @@ const loadPostcssConfig = require('./load-postcss-config')
|
|
|
4
4
|
const { MPX_ROOT_VIEW, MPX_DISABLE_EXTRACTOR_CACHE } = require('../utils/const')
|
|
5
5
|
const rpx = require('./plugins/rpx')
|
|
6
6
|
const vw = require('./plugins/vw')
|
|
7
|
-
const pluginCondStrip = require('./plugins/conditional-strip')
|
|
8
7
|
const scopeId = require('./plugins/scope-id')
|
|
9
8
|
const transSpecial = require('./plugins/trans-special')
|
|
10
9
|
const cssArrayList = require('./plugins/css-array-list')
|
|
@@ -58,9 +57,9 @@ module.exports = function (css, map) {
|
|
|
58
57
|
plugins.push(transSpecial({ id }))
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
plugins.push(pluginCondStrip({
|
|
62
|
-
|
|
63
|
-
}))
|
|
60
|
+
// plugins.push(pluginCondStrip({
|
|
61
|
+
// defs
|
|
62
|
+
// }))
|
|
64
63
|
|
|
65
64
|
for (const item of transRpxRules) {
|
|
66
65
|
const {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
2
|
// scope-id
|
|
3
|
-
|
|
3
|
+
function isSpaceCombinator (node) {
|
|
4
|
+
return node.type === 'combinator' && /^\s+$/.test(node.value)
|
|
5
|
+
}
|
|
4
6
|
module.exports = ({ id }) => {
|
|
5
7
|
return {
|
|
6
8
|
postcssPlugin: 'scope-id',
|
|
@@ -31,10 +33,36 @@ module.exports = ({ id }) => {
|
|
|
31
33
|
n.spaces.before = n.spaces.after = ''
|
|
32
34
|
return false
|
|
33
35
|
}
|
|
36
|
+
if (n.type === 'pseudo' && n.value === ':deep') {
|
|
37
|
+
if (n.nodes.length) {
|
|
38
|
+
let last = n
|
|
39
|
+
n.nodes[0].each((ss) => {
|
|
40
|
+
selector.insertAfter(last, ss)
|
|
41
|
+
last = ss
|
|
42
|
+
})
|
|
43
|
+
const prev = n.prev()
|
|
44
|
+
if (!prev || !isSpaceCombinator(prev)) {
|
|
45
|
+
selector.insertAfter(
|
|
46
|
+
n,
|
|
47
|
+
selectorParser.combinator({
|
|
48
|
+
value: ' '
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
n.remove()
|
|
53
|
+
} else {
|
|
54
|
+
const prev = n.prev()
|
|
55
|
+
if (prev && isSpaceCombinator(prev)) {
|
|
56
|
+
prev.remove()
|
|
57
|
+
}
|
|
58
|
+
n.remove()
|
|
59
|
+
}
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
34
62
|
// /deep/ alias for >>>, since >>> doesn't work in SASS
|
|
35
63
|
if (n.type === 'tag' && n.value === '/deep/') {
|
|
36
64
|
const prev = n.prev()
|
|
37
|
-
if (prev && prev
|
|
65
|
+
if (prev && isSpaceCombinator(prev)) {
|
|
38
66
|
prev.remove()
|
|
39
67
|
}
|
|
40
68
|
n.remove()
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const MagicString = require('magic-string')
|
|
2
|
+
|
|
3
|
+
function cssConditionalStrip (cssContent, defs) {
|
|
4
|
+
const ms = new MagicString(cssContent)
|
|
5
|
+
|
|
6
|
+
// 正则匹配 @mpx-if, @mpx-elif, @mpx-else, @mpx-endif 的模式
|
|
7
|
+
const ifPattern = /\/\*\s*@mpx-if\s*\((.*?)\)\s*\*\//gs
|
|
8
|
+
const elifPattern = /\/\*\s*@mpx-elif\s*\((.*?)\)\s*\*\//gs
|
|
9
|
+
const elsePattern = /\/\*\s*@mpx-else\s*\*\//gs
|
|
10
|
+
const endifPattern = /\/\*\s*@mpx-endif\s*\*\//gs
|
|
11
|
+
|
|
12
|
+
function evaluateCondition (condition) {
|
|
13
|
+
// 替换变量
|
|
14
|
+
for (const key in defs) {
|
|
15
|
+
condition = condition.replace(new RegExp(`\\b${key}\\b`, 'g'), JSON.stringify(defs[key]))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 解析条件表达式
|
|
19
|
+
try {
|
|
20
|
+
// eslint-disable-next-line no-new-func
|
|
21
|
+
return Function('"use strict";return (' + condition + ')')()
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new Error(`Failed to evaluate condition: ${condition}`)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let currentStart = 0
|
|
28
|
+
function processCondition (start, end, condition) {
|
|
29
|
+
const conditionResult = evaluateCondition(condition)
|
|
30
|
+
let hasElse = false
|
|
31
|
+
let elseStart = -1
|
|
32
|
+
let elseLen = 0
|
|
33
|
+
currentStart = end + 1
|
|
34
|
+
|
|
35
|
+
while (currentStart < ms.original.length) {
|
|
36
|
+
elsePattern.lastIndex = currentStart
|
|
37
|
+
const elseMatch = elsePattern.exec(ms.original)
|
|
38
|
+
if (elseMatch) {
|
|
39
|
+
elseLen = elseMatch[0].length
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ifPattern.lastIndex = currentStart
|
|
43
|
+
const ifMatch = ifPattern.exec(ms.original)
|
|
44
|
+
|
|
45
|
+
elifPattern.lastIndex = currentStart
|
|
46
|
+
const elseIfMatch = elifPattern.exec(ms.original)
|
|
47
|
+
|
|
48
|
+
endifPattern.lastIndex = currentStart
|
|
49
|
+
const endifMatch = endifPattern.exec(ms.original)
|
|
50
|
+
|
|
51
|
+
const nextIf = ifMatch ? ifMatch.index : Infinity
|
|
52
|
+
const nextElseIf = elseIfMatch ? elseIfMatch.index : Infinity
|
|
53
|
+
const nextElse = elseMatch ? elseMatch.index : Infinity
|
|
54
|
+
const nextEndif = endifMatch ? endifMatch.index : Infinity
|
|
55
|
+
|
|
56
|
+
const nextMarker = Math.min(nextIf, nextElseIf, nextElse, nextEndif)
|
|
57
|
+
|
|
58
|
+
if (nextMarker === Infinity) break
|
|
59
|
+
|
|
60
|
+
if (nextMarker === nextElse) {
|
|
61
|
+
// 处理 @mpx-else
|
|
62
|
+
hasElse = true
|
|
63
|
+
elseStart = nextElse
|
|
64
|
+
currentStart = elseMatch.index + elseLen
|
|
65
|
+
ms.remove(elseStart, elseStart + elseLen) // 移除 @mpx-else 注释
|
|
66
|
+
} else if (nextMarker === nextElseIf) {
|
|
67
|
+
// 处理 @mpx-elif
|
|
68
|
+
if (!conditionResult) {
|
|
69
|
+
// 前边的if为false,则直接移除前边代码
|
|
70
|
+
ms.remove(start, nextElseIf)
|
|
71
|
+
}
|
|
72
|
+
currentStart = nextElseIf + elseIfMatch[0].length
|
|
73
|
+
ms.remove(nextElseIf, nextElseIf + elseIfMatch[0].length) // 移除 @mpx-elif 注释
|
|
74
|
+
processCondition(nextElseIf, nextElseIf + elseIfMatch[0].length, elseIfMatch[1])
|
|
75
|
+
} else if (nextMarker === nextIf) {
|
|
76
|
+
// 处理嵌套的 @mpx-if
|
|
77
|
+
// 如果遇到了新的 @mpx-if,则递归处理
|
|
78
|
+
currentStart = nextIf + ifMatch[0].length
|
|
79
|
+
ms.remove(nextIf, nextIf + ifMatch[0].length) // 移除 @mpx-if 注释
|
|
80
|
+
processCondition(nextIf, nextIf + ifMatch[0].length, ifMatch[1])
|
|
81
|
+
} else if (nextMarker === nextEndif) {
|
|
82
|
+
// 处理 @mpx-endif block块
|
|
83
|
+
if (conditionResult && hasElse) {
|
|
84
|
+
// 移除 @mpx-else 至 @mpx-endif 代码
|
|
85
|
+
ms.remove(elseStart, endifMatch.index + endifMatch[0].length)
|
|
86
|
+
} else if (!conditionResult && hasElse) {
|
|
87
|
+
ms.remove(start, elseStart + elseLen)
|
|
88
|
+
} else if (!conditionResult) {
|
|
89
|
+
ms.remove(start, endifMatch.index + endifMatch[0].length)
|
|
90
|
+
}
|
|
91
|
+
ms.remove(endifMatch.index, endifMatch.index + endifMatch[0].length) // 移除 @mpx-endif 注释
|
|
92
|
+
currentStart = endifMatch.index + endifMatch[0].length
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
// 兜底更新当前开始位置
|
|
96
|
+
if (currentStart < nextMarker) {
|
|
97
|
+
currentStart = nextMarker + 1
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let match
|
|
103
|
+
while ((match = ifPattern.exec(ms.original)) !== null) {
|
|
104
|
+
processCondition(match.index, ifPattern.lastIndex, match[1])
|
|
105
|
+
// 移除匹配到的 @mpx-if 注释
|
|
106
|
+
ms.remove(match.index, match.index + match[0].length)
|
|
107
|
+
ifPattern.lastIndex = currentStart
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return ms.toString()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = function (css) {
|
|
114
|
+
this.cacheable()
|
|
115
|
+
const mpx = this.getMpx()
|
|
116
|
+
const defs = mpx.defs
|
|
117
|
+
return cssConditionalStrip(css, defs)
|
|
118
|
+
}
|
|
@@ -264,7 +264,8 @@ module.exports = {
|
|
|
264
264
|
transform (code, {
|
|
265
265
|
needCollect = false,
|
|
266
266
|
renderReduce = false,
|
|
267
|
-
ignoreMap = {}
|
|
267
|
+
ignoreMap = {},
|
|
268
|
+
customBindThis
|
|
268
269
|
} = {}) {
|
|
269
270
|
const ast = babylon.parse(code, {
|
|
270
271
|
plugins: [
|
|
@@ -420,7 +421,11 @@ module.exports = {
|
|
|
420
421
|
if (isProps) {
|
|
421
422
|
propKeySet.add(name)
|
|
422
423
|
}
|
|
423
|
-
|
|
424
|
+
if (typeof customBindThis === 'function') {
|
|
425
|
+
customBindThis(path, t)
|
|
426
|
+
} else {
|
|
427
|
+
path.replaceWith(t.memberExpression(t.thisExpression(), path.node))
|
|
428
|
+
}
|
|
424
429
|
}
|
|
425
430
|
delete path.needBind
|
|
426
431
|
}
|