@mpxjs/webpack-plugin 2.10.7-beta.1 → 2.10.7-beta.10
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/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/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,81 +0,0 @@
|
|
|
1
|
-
import { useState, ComponentType, useEffect, useCallback, useRef } from 'react'
|
|
2
|
-
import { DefaultFallback, DefaultLoading, PageWrapper } from './AsyncContainer'
|
|
3
|
-
import type { DefaultFallbackProps } from './AsyncContainer'
|
|
4
|
-
|
|
5
|
-
const asyncChunkMap = new Map()
|
|
6
|
-
|
|
7
|
-
interface props {
|
|
8
|
-
type: 'component' | 'page'
|
|
9
|
-
chunkName: string
|
|
10
|
-
request: string
|
|
11
|
-
props: any,
|
|
12
|
-
loading: ComponentType<unknown>
|
|
13
|
-
fallback: ComponentType<unknown>
|
|
14
|
-
getChildren: () => Promise<unknown>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const AsyncSuspense: React.FC<props> = ({ type, props, chunkName, request, loading, fallback, getChildren }) => {
|
|
18
|
-
const [status, setStatus] = useState('pending')
|
|
19
|
-
const loaded = asyncChunkMap.has(request)
|
|
20
|
-
const [, setKey] = useState(0)
|
|
21
|
-
const chunkPromise = useRef<null | Promise<unknown>>(null)
|
|
22
|
-
|
|
23
|
-
const reloadPage = useCallback(() => {
|
|
24
|
-
setKey((preV) => preV + 1)
|
|
25
|
-
console.log('[mpxAsyncSuspense]: reload page')
|
|
26
|
-
setStatus('pending')
|
|
27
|
-
}, [])
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (!loaded && status === 'pending') {
|
|
31
|
-
// todo 清楚副作用?
|
|
32
|
-
console.log('the current :', chunkPromise.current)
|
|
33
|
-
chunkPromise.current!
|
|
34
|
-
.then((m: any) => {
|
|
35
|
-
console.log('[mpxAsyncSuspense]: load sucess')
|
|
36
|
-
asyncChunkMap.set(request, m.__esModule ? m.default : m)
|
|
37
|
-
setStatus('loaded')
|
|
38
|
-
})
|
|
39
|
-
.catch((e) => {
|
|
40
|
-
if (type === 'component') {
|
|
41
|
-
console.log(11111, e)
|
|
42
|
-
global.onLazyLoadError({
|
|
43
|
-
type: 'subpackage',
|
|
44
|
-
subpackage: [chunkName],
|
|
45
|
-
errMsg: `loadSubpackage: ${e.type}`
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
console.log('[mpxAsyncSuspense]: load eror', e)
|
|
49
|
-
chunkPromise.current = null
|
|
50
|
-
setStatus('error')
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
if (loaded) {
|
|
56
|
-
const Comp = asyncChunkMap.get(request)
|
|
57
|
-
return <Comp {...props}></Comp>
|
|
58
|
-
} else if (status === 'error') {
|
|
59
|
-
console.log('the status is:', status)
|
|
60
|
-
if (type === 'page') {
|
|
61
|
-
const Fallback = fallback as ComponentType<DefaultFallbackProps> || DefaultFallback
|
|
62
|
-
return <><PageWrapper><Fallback onReload={reloadPage}></Fallback></PageWrapper></>
|
|
63
|
-
} else {
|
|
64
|
-
const Fallback = loading
|
|
65
|
-
return <Fallback {...props}></Fallback>
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
if (!chunkPromise.current) {
|
|
69
|
-
chunkPromise.current = getChildren()
|
|
70
|
-
}
|
|
71
|
-
if (type === 'page') {
|
|
72
|
-
const Fallback = loading || DefaultLoading
|
|
73
|
-
return <PageWrapper><Fallback /></PageWrapper>
|
|
74
|
-
} else {
|
|
75
|
-
const Fallback = loading
|
|
76
|
-
return <Fallback {...props}></Fallback>
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export default AsyncSuspense
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef } from 'react';
|
|
2
|
-
import { DefaultFallback, DefaultLoading, PageWrapper } from './AsyncContainer';
|
|
3
|
-
const asyncChunkMap = new Map();
|
|
4
|
-
const AsyncSuspense = ({ type, props, chunkName, request, loading, fallback, getChildren }) => {
|
|
5
|
-
const [status, setStatus] = useState('pending');
|
|
6
|
-
const loaded = asyncChunkMap.has(request);
|
|
7
|
-
const [, setKey] = useState(0);
|
|
8
|
-
const chunkPromise = useRef(null);
|
|
9
|
-
const reloadPage = useCallback(() => {
|
|
10
|
-
setKey((preV) => preV + 1);
|
|
11
|
-
console.log('[mpxAsyncSuspense]: reload page');
|
|
12
|
-
setStatus('pending');
|
|
13
|
-
}, []);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (!loaded && status === 'pending') {
|
|
16
|
-
// todo 清楚副作用?
|
|
17
|
-
console.log('the current :', chunkPromise.current);
|
|
18
|
-
chunkPromise.current
|
|
19
|
-
.then((m) => {
|
|
20
|
-
console.log('[mpxAsyncSuspense]: load sucess');
|
|
21
|
-
asyncChunkMap.set(request, m.__esModule ? m.default : m);
|
|
22
|
-
setStatus('loaded');
|
|
23
|
-
})
|
|
24
|
-
.catch((e) => {
|
|
25
|
-
if (type === 'component') {
|
|
26
|
-
console.log(11111, e);
|
|
27
|
-
global.onLazyLoadError({
|
|
28
|
-
type: 'subpackage',
|
|
29
|
-
subpackage: [chunkName],
|
|
30
|
-
errMsg: `loadSubpackage: ${e.type}`
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
console.log('[mpxAsyncSuspense]: load eror', e);
|
|
34
|
-
chunkPromise.current = null;
|
|
35
|
-
setStatus('error');
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (loaded) {
|
|
40
|
-
const Comp = asyncChunkMap.get(request);
|
|
41
|
-
return <Comp {...props}></Comp>;
|
|
42
|
-
}
|
|
43
|
-
else if (status === 'error') {
|
|
44
|
-
console.log('the status is:', status);
|
|
45
|
-
if (type === 'page') {
|
|
46
|
-
const Fallback = fallback || DefaultFallback;
|
|
47
|
-
return <><PageWrapper><Fallback onReload={reloadPage}></Fallback></PageWrapper></>;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const Fallback = loading;
|
|
51
|
-
return <Fallback {...props}></Fallback>;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
if (!chunkPromise.current) {
|
|
56
|
-
chunkPromise.current = getChildren();
|
|
57
|
-
}
|
|
58
|
-
if (type === 'page') {
|
|
59
|
-
const Fallback = loading || DefaultLoading;
|
|
60
|
-
return <PageWrapper><Fallback /></PageWrapper>;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const Fallback = loading;
|
|
64
|
-
return <Fallback {...props}></Fallback>;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export default AsyncSuspense;
|