@mpxjs/webpack-plugin 2.10.7-beta.1 → 2.10.7-beta.11
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/dependencies/RecordPageConfigsMapDependency.js +1 -1
- package/lib/file-loader.js +1 -1
- package/lib/index.js +78 -86
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +25 -43
- package/lib/platform/style/wx/index.js +7 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/movable-view.js +1 -10
- package/lib/platform/template/wx/index.js +1 -2
- package/lib/react/index.js +1 -3
- package/lib/react/processJSON.js +11 -66
- package/lib/react/processScript.js +3 -4
- package/lib/react/script-helper.js +18 -92
- package/lib/runtime/components/react/AsyncContainer.tsx +7 -35
- package/lib/runtime/components/react/context.ts +12 -2
- package/lib/runtime/components/react/dist/AsyncContainer.jsx +4 -23
- package/lib/runtime/components/react/dist/context.js +1 -1
- package/lib/runtime/components/react/dist/getInnerListeners.js +1 -1
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +63 -9
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +308 -63
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +15 -10
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +28 -14
- package/lib/runtime/components/react/dist/useAnimationHooks.js +87 -2
- package/lib/runtime/components/react/dist/utils.jsx +2 -13
- package/lib/runtime/components/react/getInnerListeners.ts +1 -1
- package/lib/runtime/components/react/mpx-movable-area.tsx +98 -11
- package/lib/runtime/components/react/mpx-movable-view.tsx +358 -64
- package/lib/runtime/components/react/mpx-scroll-view.tsx +16 -9
- package/lib/runtime/components/react/mpx-sticky-header.tsx +3 -1
- package/lib/runtime/components/react/mpx-web-view.tsx +33 -13
- package/lib/runtime/components/react/types/global.d.ts +0 -15
- package/lib/runtime/components/react/useAnimationHooks.ts +85 -2
- package/lib/runtime/components/react/utils.tsx +2 -13
- package/lib/runtime/components/web/mpx-scroll-view.vue +4 -7
- package/lib/runtime/components/web/mpx-sticky-header.vue +39 -31
- package/lib/runtime/optionProcessor.js +6 -2
- package/lib/script-setup-compiler/index.js +27 -5
- package/lib/template-compiler/bind-this.js +2 -1
- package/lib/template-compiler/compiler.js +4 -3
- package/lib/utils/dom-tag-config.js +3 -17
- package/lib/web/processTemplate.js +1 -1
- package/lib/web/script-helper.js +1 -1
- package/package.json +2 -2
- package/lib/react/LoadAsyncChunkModule.js +0 -68
- package/lib/runtime/components/react/AsyncSuspense.tsx +0 -81
- package/lib/runtime/components/react/dist/AsyncSuspense.jsx +0 -68
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { forwardRef, useRef, useContext, useMemo, useState } from 'react'
|
|
1
|
+
import { forwardRef, useRef, useContext, useMemo, useState, useCallback, useEffect } from 'react'
|
|
2
2
|
import { warn, isFunction } from '@mpxjs/utils'
|
|
3
3
|
import Portal from './mpx-portal/index'
|
|
4
|
-
import { usePreventRemove, PreventRemoveEvent } from '@react-navigation/native'
|
|
5
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
6
5
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
7
6
|
import { WebView } from 'react-native-webview'
|
|
@@ -76,6 +75,7 @@ const styles = StyleSheet.create({
|
|
|
76
75
|
borderRadius: 10
|
|
77
76
|
}
|
|
78
77
|
})
|
|
78
|
+
|
|
79
79
|
const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((props, ref): JSX.Element | null => {
|
|
80
80
|
const { src, bindmessage, bindload, binderror } = props
|
|
81
81
|
const mpx = global.__mpx
|
|
@@ -100,8 +100,8 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
100
100
|
const webViewRef = useRef<WebView>(null)
|
|
101
101
|
const fristLoaded = useRef<boolean>(false)
|
|
102
102
|
const isLoadError = useRef<boolean>(false)
|
|
103
|
-
const isNavigateBack = useRef<boolean>(false)
|
|
104
103
|
const statusCode = useRef<string|number>('')
|
|
104
|
+
const [isLoaded, setIsLoaded] = useState<boolean>(true)
|
|
105
105
|
const defaultWebViewStyle = {
|
|
106
106
|
position: 'absolute' as const,
|
|
107
107
|
left: 0,
|
|
@@ -109,18 +109,30 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
109
109
|
top: 0,
|
|
110
110
|
bottom: 0
|
|
111
111
|
}
|
|
112
|
+
const canGoBack = useRef<boolean>(false)
|
|
113
|
+
const isNavigateBack = useRef<boolean>(false)
|
|
112
114
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
usePreventRemove(isIntercept, (event: PreventRemoveEvent) => {
|
|
116
|
-
const { data } = event
|
|
117
|
-
if (isNavigateBack.current) {
|
|
118
|
-
navigation?.dispatch(data.action)
|
|
119
|
-
} else {
|
|
115
|
+
const beforeRemoveHandle = (e: Event) => {
|
|
116
|
+
if (canGoBack.current && !isNavigateBack.current) {
|
|
120
117
|
webViewRef.current?.goBack()
|
|
118
|
+
e.preventDefault()
|
|
121
119
|
}
|
|
122
120
|
isNavigateBack.current = false
|
|
123
|
-
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const navigation = useNavigation()
|
|
124
|
+
|
|
125
|
+
// useEffect(() => {
|
|
126
|
+
// let beforeRemoveSubscription:any
|
|
127
|
+
// if (__mpx_mode__ !== 'ios') {
|
|
128
|
+
// beforeRemoveSubscription = navigation?.addListener?.('beforeRemove', beforeRemoveHandle)
|
|
129
|
+
// }
|
|
130
|
+
// return () => {
|
|
131
|
+
// if (isFunction(beforeRemoveSubscription)) {
|
|
132
|
+
// beforeRemoveSubscription()
|
|
133
|
+
// }
|
|
134
|
+
// }
|
|
135
|
+
// }, [])
|
|
124
136
|
|
|
125
137
|
useNodesRef<WebView, WebViewProps>(props, ref, webViewRef, {
|
|
126
138
|
style: defaultWebViewStyle
|
|
@@ -171,14 +183,14 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
171
183
|
}
|
|
172
184
|
const _changeUrl = function (navState: WebViewNavigation) {
|
|
173
185
|
if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑
|
|
186
|
+
canGoBack.current = navState.canGoBack
|
|
174
187
|
currentPage.__webViewUrl = navState.url
|
|
175
|
-
setIsIntercept(navState.canGoBack)
|
|
176
188
|
}
|
|
177
189
|
}
|
|
178
190
|
|
|
179
191
|
const _onLoadProgress = function (event: WebViewProgressEvent) {
|
|
180
192
|
if (__mpx_mode__ !== 'ios') {
|
|
181
|
-
|
|
193
|
+
canGoBack.current = event.nativeEvent.canGoBack
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
196
|
const _message = function (res: WebViewMessageEvent) {
|
|
@@ -267,6 +279,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
267
279
|
}
|
|
268
280
|
const onLoadEndHandle = function (res: WebViewEvent) {
|
|
269
281
|
fristLoaded.current = true
|
|
282
|
+
setIsLoaded(true)
|
|
270
283
|
const src = res.nativeEvent?.url
|
|
271
284
|
if (isLoadError.current) {
|
|
272
285
|
isLoadError.current = false
|
|
@@ -312,6 +325,11 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
312
325
|
setPageLoadErr(true)
|
|
313
326
|
}
|
|
314
327
|
}
|
|
328
|
+
const onLoadStart = function () {
|
|
329
|
+
if (!fristLoaded.current) {
|
|
330
|
+
setIsLoaded(false)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
315
333
|
|
|
316
334
|
return (
|
|
317
335
|
<Portal>
|
|
@@ -324,6 +342,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
324
342
|
)
|
|
325
343
|
: (<WebView
|
|
326
344
|
style={ defaultWebViewStyle }
|
|
345
|
+
pointerEvents={ isLoaded ? 'auto' : 'none' }
|
|
327
346
|
source={{ uri: src }}
|
|
328
347
|
ref={webViewRef}
|
|
329
348
|
javaScriptEnabled={true}
|
|
@@ -334,6 +353,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
334
353
|
onLoadEnd={onLoadEnd}
|
|
335
354
|
onHttpError={onHttpError}
|
|
336
355
|
onError={onError}
|
|
356
|
+
onLoadStart={onLoadStart}
|
|
337
357
|
allowsBackForwardNavigationGestures={true}
|
|
338
358
|
></WebView>)}
|
|
339
359
|
</Portal>
|
|
@@ -42,21 +42,6 @@ declare let global: {
|
|
|
42
42
|
|
|
43
43
|
declare module '@react-navigation/native' {
|
|
44
44
|
export function useNavigation (): Record<string, any>
|
|
45
|
-
export function usePreventRemove(
|
|
46
|
-
enabled: boolean,
|
|
47
|
-
callback: (e: { data: { action: any } }) => void
|
|
48
|
-
): void;
|
|
49
|
-
export interface PreventRemoveEvent {
|
|
50
|
-
data: {
|
|
51
|
-
action: NavigationAction;
|
|
52
|
-
route: {
|
|
53
|
-
key: string;
|
|
54
|
-
name: string;
|
|
55
|
-
params?: unknown;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
preventDefault(): void;
|
|
59
|
-
}
|
|
60
45
|
}
|
|
61
46
|
|
|
62
47
|
declare module '*.png'
|
|
@@ -84,6 +84,88 @@ const InitialValue: ExtendedViewStyle = Object.assign({
|
|
|
84
84
|
const TransformOrigin = 'transformOrigin'
|
|
85
85
|
// transform
|
|
86
86
|
const isTransform = (key: string) => Object.keys(TransformInitial).includes(key)
|
|
87
|
+
// 多value解析
|
|
88
|
+
const parseValues = (str: string, char = ' ') => {
|
|
89
|
+
let stack = 0
|
|
90
|
+
let temp = ''
|
|
91
|
+
const result = []
|
|
92
|
+
for (let i = 0; i < str.length; i++) {
|
|
93
|
+
if (str[i] === '(') {
|
|
94
|
+
stack++
|
|
95
|
+
} else if (str[i] === ')') {
|
|
96
|
+
stack--
|
|
97
|
+
}
|
|
98
|
+
// 非括号内 或者 非分隔字符且非空
|
|
99
|
+
if (stack !== 0 || (str[i] !== char && str[i] !== ' ')) {
|
|
100
|
+
temp += str[i]
|
|
101
|
+
}
|
|
102
|
+
if ((stack === 0 && str[i] === char) || i === str.length - 1) {
|
|
103
|
+
result.push(temp)
|
|
104
|
+
temp = ''
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result
|
|
108
|
+
}
|
|
109
|
+
// parse string transform, eg: transform: 'rotateX(45deg) rotateZ(0.785398rad)'
|
|
110
|
+
const parseTransform = (transformStr: string) => {
|
|
111
|
+
const values = parseValues(transformStr)
|
|
112
|
+
const transform: {[propName: string]: string|number|number[]}[] = []
|
|
113
|
+
values.forEach(item => {
|
|
114
|
+
const match = item.match(/([/\w]+)\((.+)\)/)
|
|
115
|
+
if (match && match.length >= 3) {
|
|
116
|
+
let key = match[1]
|
|
117
|
+
const val = match[2]
|
|
118
|
+
switch (key) {
|
|
119
|
+
case 'translateX':
|
|
120
|
+
case 'translateY':
|
|
121
|
+
case 'scaleX':
|
|
122
|
+
case 'scaleY':
|
|
123
|
+
case 'rotateX':
|
|
124
|
+
case 'rotateY':
|
|
125
|
+
case 'rotateZ':
|
|
126
|
+
case 'rotate':
|
|
127
|
+
case 'skewX':
|
|
128
|
+
case 'skewY':
|
|
129
|
+
case 'perspective':
|
|
130
|
+
// rotate 处理成 rotateZ
|
|
131
|
+
key = key === 'rotate' ? 'rotateZ' : key
|
|
132
|
+
// 单个值处理
|
|
133
|
+
transform.push({ [key]: global.__formatValue(val) })
|
|
134
|
+
break
|
|
135
|
+
case 'matrix':
|
|
136
|
+
transform.push({ [key]: parseValues(val, ',').map(val => +val) })
|
|
137
|
+
break
|
|
138
|
+
case 'translate':
|
|
139
|
+
case 'scale':
|
|
140
|
+
case 'skew':
|
|
141
|
+
case 'translate3d': // x y 支持 z不支持
|
|
142
|
+
case 'scale3d': // x y 支持 z不支持
|
|
143
|
+
{
|
|
144
|
+
// 2 个以上的值处理
|
|
145
|
+
key = key.replace('3d', '')
|
|
146
|
+
const vals = parseValues(val, ',').splice(0, 3)
|
|
147
|
+
// scale(.5) === scaleX(.5) scaleY(.5)
|
|
148
|
+
if (vals.length === 1 && key === 'scale') {
|
|
149
|
+
vals.push(vals[0])
|
|
150
|
+
}
|
|
151
|
+
const xyz = ['X', 'Y', 'Z']
|
|
152
|
+
transform.push(...vals.map((v, index) => {
|
|
153
|
+
return { [`${key}${xyz[index] || ''}`]: global.__formatValue(v.trim()) }
|
|
154
|
+
}))
|
|
155
|
+
break
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
return transform
|
|
161
|
+
}
|
|
162
|
+
// format style
|
|
163
|
+
const formatStyle = (style: ExtendedViewStyle): ExtendedViewStyle => {
|
|
164
|
+
if (!style.transform || Array.isArray(style.transform)) return style
|
|
165
|
+
return Object.assign({}, style, {
|
|
166
|
+
transform: parseTransform(style.transform)
|
|
167
|
+
})
|
|
168
|
+
}
|
|
87
169
|
|
|
88
170
|
// transform 数组转对象
|
|
89
171
|
function getTransformObj (transforms: { [propName: string]: string | number }[]) {
|
|
@@ -94,7 +176,7 @@ function getTransformObj (transforms: { [propName: string]: string | number }[])
|
|
|
94
176
|
}
|
|
95
177
|
|
|
96
178
|
export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAnimation?: boolean, layoutRef: MutableRefObject<any>, transitionend?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void }) {
|
|
97
|
-
const { style
|
|
179
|
+
const { style = {}, animation, enableAnimation, transitionend, layoutRef } = props
|
|
98
180
|
const enableStyleAnimation = enableAnimation || !!animation
|
|
99
181
|
const enableAnimationRef = useRef(enableStyleAnimation)
|
|
100
182
|
if (enableAnimationRef.current !== enableStyleAnimation) {
|
|
@@ -103,6 +185,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
103
185
|
|
|
104
186
|
if (!enableAnimationRef.current) return { enableStyleAnimation: false }
|
|
105
187
|
|
|
188
|
+
const originalStyle = formatStyle(style)
|
|
106
189
|
// id 标识
|
|
107
190
|
const id = animation?.id || -1
|
|
108
191
|
// 有动画样式的 style key
|
|
@@ -131,7 +214,7 @@ export default function useAnimationHooks<T, P> (props: _ViewProps & { enableAni
|
|
|
131
214
|
useEffect(() => {
|
|
132
215
|
// style 更新后同步更新 lastStyleRef & shareValMap
|
|
133
216
|
updateStyleVal()
|
|
134
|
-
}, [
|
|
217
|
+
}, [style])
|
|
135
218
|
// ** 获取动画样式prop & 驱动动画
|
|
136
219
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
137
220
|
useEffect(() => {
|
|
@@ -617,19 +617,8 @@ export const useLayout = ({ props, hasSelfPercent, setWidth, setHeight, onLayout
|
|
|
617
617
|
}
|
|
618
618
|
if (enableOffset) {
|
|
619
619
|
nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
620
|
-
const {
|
|
621
|
-
layoutRef.current = {
|
|
622
|
-
x,
|
|
623
|
-
y: y - navigationY,
|
|
624
|
-
width,
|
|
625
|
-
height,
|
|
626
|
-
offsetLeft,
|
|
627
|
-
offsetTop: offsetTop - navigationY,
|
|
628
|
-
_x: x,
|
|
629
|
-
_y: y,
|
|
630
|
-
_offsetLeft: offsetLeft,
|
|
631
|
-
_offsetTop: offsetTop
|
|
632
|
-
}
|
|
620
|
+
const { top: navigationY = 0 } = navigation?.layout || {}
|
|
621
|
+
layoutRef.current = { x, y: y - navigationY, width, height, offsetLeft, offsetTop: offsetTop - navigationY }
|
|
633
622
|
})
|
|
634
623
|
}
|
|
635
624
|
onLayout && onLayout(e)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { computed } from 'vue'
|
|
2
3
|
import getInnerListeners, { getCustomEvent } from './getInnerListeners'
|
|
3
4
|
import { processSize } from '../../utils'
|
|
4
5
|
import BScroll from '@better-scroll/core'
|
|
@@ -60,12 +61,8 @@
|
|
|
60
61
|
},
|
|
61
62
|
provide () {
|
|
62
63
|
return {
|
|
63
|
-
scrollOffset:
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
refreshVersion: {
|
|
67
|
-
get: () => this.refreshVersion
|
|
68
|
-
}
|
|
64
|
+
scrollOffset: computed(() => -this.lastY || 0),
|
|
65
|
+
refreshVersion: computed(() => this.refreshVersion || 0)
|
|
69
66
|
}
|
|
70
67
|
},
|
|
71
68
|
data () {
|
|
@@ -342,7 +339,6 @@
|
|
|
342
339
|
const scrollWrapperHeight = wrapper?.clientHeight || 0
|
|
343
340
|
if (wrapper) {
|
|
344
341
|
const computedStyle = getComputedStyle(wrapper)
|
|
345
|
-
this.refreshVersion = this.refreshVersion + 1
|
|
346
342
|
// 考虑子元素样式可能会设置100%,如果直接继承 scrollContent 的样式可能会有问题
|
|
347
343
|
// 所以使用 wrapper 作为 innerWrapper 的宽高参考依据
|
|
348
344
|
this.$refs.innerWrapper.style.width = `${scrollWrapperWidth - parseInt(computedStyle.paddingLeft) - parseInt(computedStyle.paddingRight)}px`
|
|
@@ -408,6 +404,7 @@
|
|
|
408
404
|
this.lastContentHeight = scrollContentHeight
|
|
409
405
|
this.lastWrapperWidth = scrollWrapperWidth
|
|
410
406
|
this.lastWrapperHeight = scrollWrapperHeight
|
|
407
|
+
this.refreshVersion++
|
|
411
408
|
if (this.bs) this.bs.refresh()
|
|
412
409
|
}
|
|
413
410
|
},
|
|
@@ -6,10 +6,11 @@ import { getCustomEvent } from './getInnerListeners'
|
|
|
6
6
|
name: 'mpx-sticky-header',
|
|
7
7
|
inject: ['scrollOffset', 'refreshVersion'],
|
|
8
8
|
props: {
|
|
9
|
-
|
|
9
|
+
offsetTop: {
|
|
10
10
|
type: Number,
|
|
11
11
|
default: 0
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
padding: Array
|
|
13
14
|
},
|
|
14
15
|
data() {
|
|
15
16
|
return {
|
|
@@ -17,16 +18,8 @@ import { getCustomEvent } from './getInnerListeners'
|
|
|
17
18
|
isStickOnTop: false
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
|
-
computed: {
|
|
21
|
-
_scrollOffset() {
|
|
22
|
-
return -this.scrollOffset?.get() || 0
|
|
23
|
-
},
|
|
24
|
-
_refreshVersion() {
|
|
25
|
-
return this.refreshVersion?.get() || 0
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
21
|
watch: {
|
|
29
|
-
|
|
22
|
+
scrollOffset: {
|
|
30
23
|
handler(newScrollOffset) {
|
|
31
24
|
const newIsStickOnTop = newScrollOffset > this.headerTop
|
|
32
25
|
if (newIsStickOnTop !== this.isStickOnTop) {
|
|
@@ -35,19 +28,25 @@ import { getCustomEvent } from './getInnerListeners'
|
|
|
35
28
|
isStickOnTop: newIsStickOnTop
|
|
36
29
|
}, this))
|
|
37
30
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (this.isStickOnTop) {
|
|
41
|
-
stickyHeader.style.transform = `translateY(${newScrollOffset - this.headerTop + this.offsetTop}px)`
|
|
42
|
-
} else {
|
|
43
|
-
stickyHeader.style.transform = 'none'
|
|
44
|
-
}
|
|
31
|
+
|
|
32
|
+
this.setTransformStyle()
|
|
45
33
|
},
|
|
46
34
|
immediate: true
|
|
47
35
|
},
|
|
48
|
-
|
|
36
|
+
refreshVersion: {
|
|
49
37
|
handler() {
|
|
50
|
-
|
|
38
|
+
this.setHeaderTop()
|
|
39
|
+
this.setTransformStyle()
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
mounted() {
|
|
44
|
+
this.setPaddingStyle()
|
|
45
|
+
this.setHeaderTop()
|
|
46
|
+
},
|
|
47
|
+
methods: {
|
|
48
|
+
setHeaderTop () {
|
|
49
|
+
const parentElement = this.$el.parentElement
|
|
51
50
|
if (!parentElement) return
|
|
52
51
|
|
|
53
52
|
const parentClass = parentElement.className || ''
|
|
@@ -58,20 +57,29 @@ import { getCustomEvent } from './getInnerListeners'
|
|
|
58
57
|
warn('sticky-header only supports being a direct child of a scroll-view or sticky-section component.')
|
|
59
58
|
return
|
|
60
59
|
}
|
|
61
|
-
|
|
62
60
|
this.headerTop = isStickySection
|
|
63
61
|
? this.$el.offsetTop + parentElement.offsetTop
|
|
64
62
|
: this.$el.offsetTop
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
},
|
|
64
|
+
setPaddingStyle() {
|
|
65
|
+
const stickyHeader = this.$refs.stickyHeader
|
|
66
|
+
if (!stickyHeader) return
|
|
67
|
+
|
|
68
|
+
if (this.padding && Array.isArray(this.padding)) {
|
|
69
|
+
const [top = 0, right = 0, bottom = 0, left = 0] = this.padding
|
|
70
|
+
stickyHeader.style.padding = `${top}px ${right}px ${bottom}px ${left}px`
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
setTransformStyle () {
|
|
74
|
+
const stickyHeader = this.$refs.stickyHeader
|
|
75
|
+
if (!stickyHeader) return
|
|
76
|
+
|
|
77
|
+
// 设置 transform
|
|
78
|
+
if (this.scrollOffset > this.headerTop) {
|
|
79
|
+
stickyHeader.style.transform = `translateY(${this.scrollOffset - this.headerTop + this.offsetTop}px)`
|
|
80
|
+
} else {
|
|
81
|
+
stickyHeader.style.transform = 'none'
|
|
82
|
+
}
|
|
75
83
|
}
|
|
76
84
|
},
|
|
77
85
|
render(h) {
|
|
@@ -74,12 +74,16 @@ registered in parent context!`)
|
|
|
74
74
|
option.componentPath = '/' + outputPath
|
|
75
75
|
}
|
|
76
76
|
if (ctorType === 'app') {
|
|
77
|
+
const webConfig = Object.assign({}, { disablePageTransition: true }, global.__mpx.config.webConfig)
|
|
78
|
+
const disablePageTransition = !!webConfig.disablePageTransition
|
|
77
79
|
option.data = function () {
|
|
78
80
|
return {
|
|
79
|
-
transitionName: ''
|
|
81
|
+
transitionName: '',
|
|
82
|
+
disablePageTransition: disablePageTransition
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
|
|
86
|
+
if (!disablePageTransition) {
|
|
83
87
|
option.watch = {
|
|
84
88
|
$route: {
|
|
85
89
|
handler () {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const babylon = require('@babel/parser')
|
|
2
2
|
const MagicString = require('magic-string')
|
|
3
|
+
const { SourceMapConsumer, SourceMapGenerator } = require('source-map')
|
|
3
4
|
const traverse = require('@babel/traverse').default
|
|
4
5
|
const t = require('@babel/types')
|
|
5
6
|
const formatCodeFrame = require('@babel/code-frame')
|
|
@@ -625,7 +626,12 @@ function compileScriptSetup (
|
|
|
625
626
|
_s.appendRight(endOffset, '})')
|
|
626
627
|
|
|
627
628
|
return {
|
|
628
|
-
content: _s.toString()
|
|
629
|
+
content: _s.toString(),
|
|
630
|
+
map: _s.generateMap({
|
|
631
|
+
source: filePath,
|
|
632
|
+
hires: true,
|
|
633
|
+
includeContent: true
|
|
634
|
+
})
|
|
629
635
|
}
|
|
630
636
|
}
|
|
631
637
|
|
|
@@ -1165,14 +1171,30 @@ function getCtor (ctorType) {
|
|
|
1165
1171
|
return ctor
|
|
1166
1172
|
}
|
|
1167
1173
|
|
|
1168
|
-
module.exports = function (content) {
|
|
1174
|
+
module.exports = async function (content, sourceMap) {
|
|
1169
1175
|
const { queryObj } = parseRequest(this.resource)
|
|
1170
1176
|
const { ctorType, lang } = queryObj
|
|
1171
1177
|
const filePath = this.resourcePath
|
|
1172
|
-
const
|
|
1178
|
+
const callback = this.async()
|
|
1179
|
+
let finalSourceMap = null
|
|
1180
|
+
const {
|
|
1181
|
+
content: callbackContent,
|
|
1182
|
+
map
|
|
1183
|
+
} = compileScriptSetup({
|
|
1173
1184
|
content,
|
|
1174
1185
|
lang
|
|
1175
1186
|
}, ctorType, filePath)
|
|
1176
|
-
|
|
1177
|
-
|
|
1187
|
+
finalSourceMap = map
|
|
1188
|
+
if (sourceMap) {
|
|
1189
|
+
const compiledMapConsumer = await new SourceMapConsumer(map)
|
|
1190
|
+
const compiledMapGenerator = SourceMapGenerator.fromSourceMap(compiledMapConsumer)
|
|
1191
|
+
|
|
1192
|
+
const originalConsumer = await new SourceMapConsumer(sourceMap)
|
|
1193
|
+
compiledMapGenerator.applySourceMap(
|
|
1194
|
+
originalConsumer,
|
|
1195
|
+
filePath // 需要确保与原始映射的source路径一致
|
|
1196
|
+
)
|
|
1197
|
+
finalSourceMap = compiledMapGenerator.toJSON()
|
|
1198
|
+
}
|
|
1199
|
+
callback(null, callbackContent, finalSourceMap)
|
|
1178
1200
|
}
|
|
@@ -2,6 +2,7 @@ const babylon = require('@babel/parser')
|
|
|
2
2
|
const traverse = require('@babel/traverse').default
|
|
3
3
|
const t = require('@babel/types')
|
|
4
4
|
const generate = require('@babel/generator').default
|
|
5
|
+
const isValidIdentifierStr = require('../utils/is-valid-identifier-str')
|
|
5
6
|
|
|
6
7
|
const names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
|
|
7
8
|
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
|
|
@@ -41,7 +42,7 @@ function getCollectPath (path) {
|
|
|
41
42
|
if (current.node.computed) {
|
|
42
43
|
if (t.isLiteral(current.node.property)) {
|
|
43
44
|
if (t.isStringLiteral(current.node.property)) {
|
|
44
|
-
if (dangerousKeyMap[current.node.property.value]) {
|
|
45
|
+
if (dangerousKeyMap[current.node.property.value] || !isValidIdentifierStr(current.node.property.value)) {
|
|
45
46
|
break
|
|
46
47
|
}
|
|
47
48
|
keyPath += `.${current.node.property.value}`
|
|
@@ -180,7 +180,7 @@ const i18nModuleName = '_i'
|
|
|
180
180
|
const stringifyWxsPath = '~' + normalize.lib('runtime/stringify.wxs')
|
|
181
181
|
const stringifyModuleName = '_s'
|
|
182
182
|
const optionalChainWxsPath = '~' + normalize.lib('runtime/oc.wxs')
|
|
183
|
-
const optionalChainWxsName = '
|
|
183
|
+
const optionalChainWxsName = '_o'
|
|
184
184
|
|
|
185
185
|
const tagRES = /(\{\{(?:.|\n|\r)+?\}\})(?!})/
|
|
186
186
|
const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
|
|
@@ -581,7 +581,8 @@ function parseComponent (content, options) {
|
|
|
581
581
|
let text = content.slice(currentBlock.start, currentBlock.end)
|
|
582
582
|
// pad content so that linters and pre-processors can output correct
|
|
583
583
|
// line numbers in errors and warnings
|
|
584
|
-
|
|
584
|
+
// stylus编译遇到大量空行时会出现栈溢出,故针对stylus不走pad
|
|
585
|
+
if (options.pad && !(currentBlock.tag === 'style' && currentBlock.lang === 'stylus')) {
|
|
585
586
|
text = padContent(currentBlock, options.pad) + text
|
|
586
587
|
}
|
|
587
588
|
currentBlock.content = text
|
|
@@ -1849,7 +1850,7 @@ function processRefReact (el, meta) {
|
|
|
1849
1850
|
}])
|
|
1850
1851
|
}
|
|
1851
1852
|
|
|
1852
|
-
if (el.tag === 'mpx-scroll-view'
|
|
1853
|
+
if (el.tag === 'mpx-scroll-view') {
|
|
1853
1854
|
addAttrs(el, [
|
|
1854
1855
|
{
|
|
1855
1856
|
name: '__selectRef',
|
|
@@ -72,7 +72,7 @@ const isNativeMiniTag = makeMap(
|
|
|
72
72
|
* 是否为mpx内置组件
|
|
73
73
|
* collected from packages/webpack-plugin/lib/runtime/components/web/
|
|
74
74
|
*/
|
|
75
|
-
const
|
|
75
|
+
const isBuildInTag = makeMap(
|
|
76
76
|
'mpx-image,mpx-picker-view,mpx-slider,mpx-textarea,mpx-input,mpx-picker,' +
|
|
77
77
|
'mpx-swiper-item,mpx-video,mpx-button,mpx-keep-alive,mpx-progress,' +
|
|
78
78
|
'mpx-swiper,mpx-view,mpx-checkbox-group,mpx-movable-area,mpx-radio-group,' +
|
|
@@ -81,19 +81,6 @@ const isBuildInWebTag = makeMap(
|
|
|
81
81
|
'mpx-icon,mpx-picker-view-column,mpx-scroll-view,mpx-text'
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* 是否为mpx2rn内置组件
|
|
86
|
-
*/
|
|
87
|
-
const isBuildInReactTag = makeMap(
|
|
88
|
-
'mpx-web-view,mpx-view,mpx-video,mpx-textarea,mpx-text,mpx-switch,' +
|
|
89
|
-
'mpx-swiper,mpx-swiper-item,mpx-simple-view,mpx-simple-text,mpx-scroll-view,' +
|
|
90
|
-
'mpx-root-portal,mpx-radio,mpx-radio-group,mpx-navigator,mpx-movable-view,' +
|
|
91
|
-
'mpx-movable-area,mpx-label,mpx-keyboard-avoiding-view,mpx-input,mpx-inline-text,' +
|
|
92
|
-
'mpx-image,mpx-form,mpx-checkbox,mpx-checkbox-group,mpx-button,' +
|
|
93
|
-
'mpx-rich-text,mpx-portal,mpx-popup,mpx-picker-view-column,mpx-picker-view,mpx-picker,' +
|
|
94
|
-
'mpx-icon,mpx-canvas'
|
|
95
|
-
)
|
|
96
|
-
|
|
97
84
|
const isSpace = makeMap('ensp,emsp,nbsp')
|
|
98
85
|
|
|
99
86
|
const isContWidth = makeMap('col,colgroup,img,table,td,th,tr')
|
|
@@ -118,12 +105,11 @@ module.exports = {
|
|
|
118
105
|
isVoidTag,
|
|
119
106
|
isNonPhrasingTag,
|
|
120
107
|
isRichTextTag,
|
|
121
|
-
|
|
108
|
+
isBuildInTag,
|
|
122
109
|
isUnaryTag,
|
|
123
110
|
isSpace,
|
|
124
111
|
isContWidth,
|
|
125
112
|
isContHeight,
|
|
126
113
|
isNativeMiniTag,
|
|
127
|
-
isContConRow
|
|
128
|
-
isBuildInReactTag
|
|
114
|
+
isContConRow
|
|
129
115
|
}
|
|
@@ -39,7 +39,7 @@ module.exports = function (template, {
|
|
|
39
39
|
const idName = (el && el.match(/#(.*)/) && el.match(/#(.*)/)[1]) || 'app'
|
|
40
40
|
template = {
|
|
41
41
|
tag: 'template',
|
|
42
|
-
content: `<div id="${idName}"><transition :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition></div>`
|
|
42
|
+
content: `<div id="${idName}"><transition v-if="!disablePageTransition" :name="transitionName"><mpx-keep-alive><router-view></router-view></mpx-keep-alive></transition><mpx-keep-alive v-else><router-view></router-view></mpx-keep-alive></div>`
|
|
43
43
|
}
|
|
44
44
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
45
45
|
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
|
package/lib/web/script-helper.js
CHANGED
|
@@ -13,7 +13,7 @@ function stringifyRequest (loaderContext, request) {
|
|
|
13
13
|
|
|
14
14
|
function getAsyncChunkName (chunkName) {
|
|
15
15
|
if (chunkName && typeof chunkName !== 'boolean') {
|
|
16
|
-
return `/* webpackChunkName: "${chunkName}
|
|
16
|
+
return `/* webpackChunkName: "${chunkName}" */`
|
|
17
17
|
}
|
|
18
18
|
return ''
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.7-beta.
|
|
3
|
+
"version": "2.10.7-beta.11",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@better-scroll/wheel": "^2.5.1",
|
|
29
29
|
"@better-scroll/zoom": "^2.5.1",
|
|
30
30
|
"@mpxjs/template-engine": "^2.8.7",
|
|
31
|
-
"@mpxjs/utils": "^2.10.
|
|
31
|
+
"@mpxjs/utils": "^2.10.6 | ^2.10.6-beta.1",
|
|
32
32
|
"acorn": "^8.11.3",
|
|
33
33
|
"acorn-walk": "^7.2.0",
|
|
34
34
|
"async": "^2.6.0",
|