@shuvi/platform-web 0.0.1-rc.34 → 1.0.0-rc.2
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/esm/shared/appTypes.d.ts +15 -0
- package/esm/shared/appTypes.js +1 -0
- package/esm/shared/configTypes.d.ts +14 -0
- package/esm/shared/configTypes.js +1 -0
- package/esm/shared/index.d.ts +5 -0
- package/esm/shared/index.js +5 -0
- package/esm/shared/renderTypes.d.ts +44 -0
- package/esm/shared/renderTypes.js +1 -0
- package/esm/shared/routeTypes.d.ts +47 -0
- package/esm/shared/routeTypes.js +1 -0
- package/esm/shared/serverTypes.d.ts +6 -0
- package/esm/shared/serverTypes.js +1 -0
- package/esm/shuvi-app/app/client.d.ts +2 -0
- package/esm/shuvi-app/app/client.js +125 -0
- package/esm/shuvi-app/app/server.d.ts +2 -0
- package/esm/shuvi-app/app/server.js +67 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.js +2 -1
- package/esm/shuvi-app/entry/client/app.d.ts +2 -0
- package/esm/shuvi-app/entry/client/app.js +57 -0
- package/esm/shuvi-app/entry/client/index.d.ts +2 -0
- package/esm/shuvi-app/entry/client/index.js +12 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.js +2 -2
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.prod.d.ts +0 -0
- package/esm/shuvi-app/entry/client/run.prod.js +3 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/setup-env.d.ts +1 -1
- package/esm/shuvi-app/entry/client/setup-env.js +17 -0
- package/esm/shuvi-app/entry/server/index.d.ts +6 -0
- package/esm/shuvi-app/entry/server/index.js +7 -0
- package/esm/shuvi-app/react/AppComponent.d.ts +4 -0
- package/esm/shuvi-app/react/AppComponent.jsx +6 -0
- package/esm/shuvi-app/react/AppContainer.d.ts +6 -0
- package/esm/shuvi-app/react/AppContainer.jsx +23 -0
- package/esm/shuvi-app/react/Error.d.ts +5 -0
- package/esm/shuvi-app/react/Error.jsx +38 -0
- package/esm/shuvi-app/react/ErrorBoundary.d.ts +16 -0
- package/esm/shuvi-app/react/ErrorBoundary.jsx +25 -0
- package/esm/shuvi-app/react/ErrorPage.d.ts +5 -0
- package/esm/shuvi-app/react/ErrorPage.jsx +7 -0
- package/esm/shuvi-app/react/Link.d.ts +7 -0
- package/esm/shuvi-app/react/Link.jsx +115 -0
- package/esm/shuvi-app/react/applicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/applicationContext.jsx +10 -0
- package/esm/shuvi-app/react/dynamic.d.ts +31 -0
- package/esm/shuvi-app/react/dynamic.jsx +62 -0
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/getRoutes.js +31 -0
- package/esm/shuvi-app/react/head/head-manager-context.d.ts +2 -0
- package/esm/shuvi-app/react/head/head-manager-context.js +2 -0
- package/esm/shuvi-app/react/head/head-manager.d.ts +10 -0
- package/esm/shuvi-app/react/head/head-manager.js +93 -0
- package/esm/shuvi-app/react/head/head.d.ts +33 -0
- package/esm/shuvi-app/react/head/head.jsx +178 -0
- package/esm/shuvi-app/react/head/index.d.ts +4 -0
- package/esm/shuvi-app/react/head/index.js +4 -0
- package/esm/shuvi-app/react/head/side-effect.d.ts +30 -0
- package/esm/shuvi-app/react/head/side-effect.jsx +44 -0
- package/esm/shuvi-app/react/head/types.d.ts +15 -0
- package/esm/shuvi-app/react/head/types.js +1 -0
- package/esm/shuvi-app/react/index.d.ts +4 -0
- package/esm/shuvi-app/react/index.js +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.d.ts +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.jsx +9 -0
- package/esm/shuvi-app/react/loadable/index.d.ts +2 -0
- package/esm/shuvi-app/react/loadable/index.js +2 -0
- package/esm/shuvi-app/react/loadable/loadable-context.d.ts +4 -0
- package/esm/shuvi-app/react/loadable/loadable-context.js +3 -0
- package/esm/shuvi-app/react/loadable/loadable.d.ts +30 -0
- package/esm/shuvi-app/react/loadable/loadable.js +277 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +8 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +2 -0
- package/esm/shuvi-app/react/redox-react/runtime.js +16 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.d.ts +5 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.js +5 -0
- package/esm/shuvi-app/react/types.d.ts +14 -0
- package/esm/shuvi-app/react/types.js +1 -0
- package/esm/shuvi-app/react/useLoaderData.d.ts +2 -0
- package/esm/shuvi-app/react/useLoaderData.js +27 -0
- package/esm/shuvi-app/react/utils/getDisplayName.d.ts +2 -0
- package/esm/shuvi-app/react/utils/getDisplayName.js +3 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.d.ts +2 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.js +20 -0
- package/esm/shuvi-app/react/utils/useIntersection.d.ts +8 -0
- package/esm/shuvi-app/react/utils/useIntersection.jsx +91 -0
- package/esm/shuvi-app/react/view/ReactView.client.d.ts +5 -0
- package/esm/shuvi-app/react/view/ReactView.client.jsx +64 -0
- package/esm/shuvi-app/react/view/ReactView.server.d.ts +4 -0
- package/esm/shuvi-app/react/view/ReactView.server.jsx +109 -0
- package/esm/shuvi-app/react/view/clientView.d.ts +3 -0
- package/esm/shuvi-app/react/view/clientView.js +2 -0
- package/esm/shuvi-app/react/view/index.d.ts +2 -0
- package/esm/shuvi-app/react/view/index.js +7 -0
- package/esm/shuvi-app/react/view/render-action.d.ts +10 -0
- package/esm/shuvi-app/react/view/render-action.js +29 -0
- package/esm/shuvi-app/react/view/serverView.d.ts +3 -0
- package/esm/shuvi-app/react/view/serverView.js +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.js +3 -0
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +4 -0
- package/esm/shuvi-app/shuvi-runtime-index.js +2 -0
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +6 -0
- package/esm/shuvi-app/shuvi-runtime-server.js +1 -0
- package/lib/node/features/custom-server/index.d.ts +4 -0
- package/lib/node/features/custom-server/index.js +9 -0
- package/lib/node/features/custom-server/server.d.ts +2 -0
- package/lib/node/features/custom-server/server.js +28 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +51 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +237 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.d.ts +7 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.js +35 -0
- package/lib/node/features/filesystem-routes/api/index.d.ts +3 -0
- package/lib/node/features/filesystem-routes/api/index.js +7 -0
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/api/middleware.js +44 -0
- package/lib/node/features/filesystem-routes/hooks.d.ts +3 -0
- package/lib/node/features/filesystem-routes/hooks.js +6 -0
- package/lib/node/features/filesystem-routes/index.d.ts +20 -0
- package/lib/node/features/filesystem-routes/index.js +180 -0
- package/lib/node/features/filesystem-routes/middleware/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/index.js +7 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.js +42 -0
- package/lib/node/features/filesystem-routes/middleware/routes.d.ts +9 -0
- package/lib/node/features/filesystem-routes/middleware/routes.js +34 -0
- package/lib/node/features/filesystem-routes/page/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/page/index.js +21 -0
- package/lib/node/features/filesystem-routes/page/routes.d.ts +8 -0
- package/lib/node/features/filesystem-routes/page/routes.js +83 -0
- package/lib/node/features/filesystem-routes/page/store.d.ts +3 -0
- package/lib/node/features/filesystem-routes/page/store.js +10 -0
- package/lib/node/features/html-render/index.d.ts +19 -0
- package/lib/node/features/html-render/index.js +28 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +13 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.js +56 -0
- package/lib/node/features/html-render/lib/index.d.ts +4 -0
- package/lib/node/features/html-render/lib/index.js +23 -0
- package/lib/node/features/html-render/lib/pageLoader.d.ts +1 -0
- package/lib/node/features/html-render/lib/pageLoader.js +42 -0
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +6 -0
- package/lib/node/features/html-render/lib/renderToHTML.js +81 -0
- package/lib/node/features/html-render/lib/renderer/base.d.ts +17 -0
- package/lib/node/features/html-render/lib/renderer/base.js +70 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.d.ts +4 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.js +70 -0
- package/lib/node/features/html-render/lib/renderer/index.d.ts +15 -0
- package/lib/node/features/html-render/lib/renderer/index.js +48 -0
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/spa.js +26 -0
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/ssr.js +70 -0
- package/lib/node/features/html-render/lib/renderer/types.d.ts +20 -0
- package/lib/node/features/html-render/lib/renderer/types.js +2 -0
- package/lib/node/features/html-render/lib/viewTemplate.d.ts +5 -0
- package/lib/node/features/html-render/lib/viewTemplate.js +37 -0
- package/lib/node/features/html-render/server.d.ts +2 -0
- package/lib/node/features/html-render/server.js +9 -0
- package/lib/node/features/html-render/serverHooks.d.ts +10 -0
- package/lib/node/features/html-render/serverHooks.js +13 -0
- package/lib/node/features/html-render/shuvi-app.d.ts +6 -0
- package/lib/node/features/html-render/shuvi-app.js +2 -0
- package/lib/node/features/index.d.ts +32 -0
- package/lib/node/features/index.js +25 -0
- package/lib/node/features/main/buildHtml.d.ts +8 -0
- package/lib/node/features/main/buildHtml.js +64 -0
- package/lib/node/features/main/generateResource.d.ts +3 -0
- package/lib/node/features/main/generateResource.js +56 -0
- package/lib/node/features/main/index.d.ts +3 -0
- package/lib/node/features/main/index.js +82 -0
- package/lib/node/features/middlewares.d.ts +4 -0
- package/lib/node/features/middlewares.js +23 -0
- package/lib/node/features/model/index.d.ts +21 -0
- package/lib/node/features/model/index.js +54 -0
- package/lib/node/features/model/runtime.d.ts +13 -0
- package/lib/node/features/model/runtime.js +47 -0
- package/lib/node/features/model/server.d.ts +3 -0
- package/lib/node/features/model/server.js +12 -0
- package/lib/node/features/model/shuvi-app.d.ts +6 -0
- package/lib/node/features/model/shuvi-app.js +2 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.d.ts +1 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.js +7 -0
- package/lib/node/features/on-demand-compile-page/index.d.ts +15 -0
- package/lib/node/features/on-demand-compile-page/index.js +36 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +11 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +104 -0
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.js +38 -0
- package/lib/{paths.d.ts → node/paths.d.ts} +1 -2
- package/lib/node/paths.js +36 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +42 -0
- package/lib/node/shuvi-type-extensions-node.js +3 -0
- package/lib/node/targets/react/bundler/index.d.ts +16 -0
- package/lib/node/targets/react/bundler/index.js +102 -0
- package/lib/node/targets/react/index.d.ts +32 -0
- package/lib/node/targets/react/index.js +28 -0
- package/lib/node/targets/react/redox-react/index.d.ts +18 -0
- package/lib/node/targets/react/redox-react/index.js +50 -0
- package/lib/shared/appTypes.d.ts +15 -0
- package/lib/shared/appTypes.js +2 -0
- package/lib/shared/configTypes.d.ts +14 -0
- package/lib/shared/configTypes.js +2 -0
- package/lib/shared/index.d.ts +5 -0
- package/lib/shared/index.js +21 -0
- package/lib/shared/renderTypes.d.ts +44 -0
- package/lib/shared/renderTypes.js +2 -0
- package/lib/shared/routeTypes.d.ts +47 -0
- package/lib/shared/routeTypes.js +2 -0
- package/lib/shared/serverTypes.d.ts +6 -0
- package/lib/shared/serverTypes.js +2 -0
- package/package.json +78 -15
- package/shuvi-type-extensions-node.d.ts +2 -0
- package/shuvi-type-extensions-runtime.d.ts +36 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -44
- package/lib/paths.js +0 -7
- package/shuvi-app/application/client/create-application-factory.d.ts +0 -3
- package/shuvi-app/application/client/create-application-factory.js +0 -70
- package/shuvi-app/application/client/create-application-history-browser.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-browser.js +0 -3
- package/shuvi-app/application/client/create-application-history-hash.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-hash.js +0 -3
- package/shuvi-app/application/client/create-application-history-memory.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-memory.js +0 -3
- package/shuvi-app/application/server/create-application-spa.d.ts +0 -2
- package/shuvi-app/application/server/create-application-spa.js +0 -8
- package/shuvi-app/application/server/create-application.d.ts +0 -2
- package/shuvi-app/application/server/create-application.js +0 -25
- package/shuvi-app/entry/client/index.d.ts +0 -1
- package/shuvi-app/entry/client/index.js +0 -11
- package/shuvi-app/entry/client/run.prod.js +0 -3
- package/shuvi-app/entry/client/setup-app.d.ts +0 -3
- package/shuvi-app/entry/client/setup-app.js +0 -38
- package/shuvi-app/entry/client/setup-env.js +0 -27
- package/shuvi-app/entry/server/index.d.ts +0 -6
- package/shuvi-app/entry/server/index.js +0 -7
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { SideEffectProps, HeadState } from './types';
|
|
3
|
+
declare const _default: () => {
|
|
4
|
+
new (props: any): {
|
|
5
|
+
componentDidMount(): void;
|
|
6
|
+
componentDidUpdate(): void;
|
|
7
|
+
componentWillUnmount(): void;
|
|
8
|
+
render(): React.ReactNode;
|
|
9
|
+
context: unknown;
|
|
10
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<React.PropsWithChildren<SideEffectProps>>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
11
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
12
|
+
readonly props: Readonly<React.PropsWithChildren<SideEffectProps>>;
|
|
13
|
+
state: Readonly<{}>;
|
|
14
|
+
refs: {
|
|
15
|
+
[key: string]: React.ReactInstance;
|
|
16
|
+
};
|
|
17
|
+
shouldComponentUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
18
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
19
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<React.PropsWithChildren<SideEffectProps>>, prevState: Readonly<{}>): any;
|
|
20
|
+
componentWillMount?(): void;
|
|
21
|
+
UNSAFE_componentWillMount?(): void;
|
|
22
|
+
componentWillReceiveProps?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextContext: any): void;
|
|
23
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextContext: any): void;
|
|
24
|
+
componentWillUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): void;
|
|
25
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<React.PropsWithChildren<SideEffectProps>>, nextState: Readonly<{}>, nextContext: any): void;
|
|
26
|
+
};
|
|
27
|
+
rewind(): HeadState | undefined;
|
|
28
|
+
contextType?: React.Context<any> | undefined;
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Based on https://github.com/zeit/next.js
|
|
2
|
+
// License: https://github.com/zeit/next.js/blob/977bf8d9ebd2845241b8689317f36e4e487f39d0/license.md
|
|
3
|
+
import { Component } from 'react';
|
|
4
|
+
const isServer = typeof window === 'undefined';
|
|
5
|
+
export default () => {
|
|
6
|
+
const mountedInstances = new Set();
|
|
7
|
+
let state;
|
|
8
|
+
function emitChange(component) {
|
|
9
|
+
state = component.props.reduceComponentsToState([...mountedInstances], component.props);
|
|
10
|
+
if (component.props.handleStateChange) {
|
|
11
|
+
component.props.handleStateChange(state);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return class extends Component {
|
|
15
|
+
// Used when server rendering
|
|
16
|
+
static rewind() {
|
|
17
|
+
const recordedState = state;
|
|
18
|
+
state = undefined;
|
|
19
|
+
mountedInstances.clear();
|
|
20
|
+
return recordedState;
|
|
21
|
+
}
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props);
|
|
24
|
+
if (isServer) {
|
|
25
|
+
mountedInstances.add(this);
|
|
26
|
+
emitChange(this);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
componentDidMount() {
|
|
30
|
+
mountedInstances.add(this);
|
|
31
|
+
emitChange(this);
|
|
32
|
+
}
|
|
33
|
+
componentDidUpdate() {
|
|
34
|
+
emitChange(this);
|
|
35
|
+
}
|
|
36
|
+
componentWillUnmount() {
|
|
37
|
+
mountedInstances.delete(this);
|
|
38
|
+
emitChange(this);
|
|
39
|
+
}
|
|
40
|
+
render() {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IHtmlTag } from '../types';
|
|
3
|
+
export declare type SideEffectProps = {
|
|
4
|
+
reduceComponentsToState: <T>(components: Array<React.ReactElement<any>>, props: T) => HeadState;
|
|
5
|
+
handleStateChange?: (state: HeadState) => void;
|
|
6
|
+
};
|
|
7
|
+
export interface HeadElement {
|
|
8
|
+
type: string;
|
|
9
|
+
props: {
|
|
10
|
+
[name: string]: any;
|
|
11
|
+
children?: string | string[];
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare type HeadState = IHtmlTag[];
|
|
15
|
+
export declare type HeadItem = IHtmlTag;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import dynamic from './dynamic';
|
|
3
|
+
export function loadRouteComponent(loader, options) {
|
|
4
|
+
const DynamicComp = dynamic(() => loader().then(mod => {
|
|
5
|
+
const comp = mod.default || mod;
|
|
6
|
+
return comp;
|
|
7
|
+
}), options);
|
|
8
|
+
return DynamicComp;
|
|
9
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@copyright (c) 2017-present James Kyle <me@thejameskyle.com>
|
|
3
|
+
MIT License
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
a copy of this software and associated documentation files (the
|
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
10
|
+
the following conditions:
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
20
|
+
*/
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
declare type Options = any;
|
|
23
|
+
declare function Loadable<P>(opts: Options): React.ComponentType<P>;
|
|
24
|
+
declare namespace Loadable {
|
|
25
|
+
var Map: typeof LoadableMap;
|
|
26
|
+
var preloadAll: () => Promise<void>;
|
|
27
|
+
var preloadReady: (ids?: (string | number)[]) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
declare function LoadableMap<P>(opts: Options): React.ComponentType<P>;
|
|
30
|
+
export default Loadable;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
@copyright (c) 2017-present James Kyle <me@thejameskyle.com>
|
|
4
|
+
MIT License
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
|
21
|
+
*/
|
|
22
|
+
// https://github.com/jamiebuilds/react-loadable/blob/v5.5.0/src/index.js
|
|
23
|
+
// Modified to be compatible with webpack 4 / Next.js
|
|
24
|
+
// Modified to be compatible with shuvi.js
|
|
25
|
+
import * as React from 'react';
|
|
26
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
27
|
+
import { LoadableContext } from './loadable-context';
|
|
28
|
+
const ALL_INITIALIZERS = [];
|
|
29
|
+
const READY_INITIALIZERS = [];
|
|
30
|
+
let initialized = false;
|
|
31
|
+
function load(loader) {
|
|
32
|
+
let promise = loader();
|
|
33
|
+
let state = {
|
|
34
|
+
loading: true,
|
|
35
|
+
loaded: null,
|
|
36
|
+
error: null
|
|
37
|
+
};
|
|
38
|
+
state.promise = promise
|
|
39
|
+
.then(loaded => {
|
|
40
|
+
state.loading = false;
|
|
41
|
+
state.loaded = loaded;
|
|
42
|
+
return loaded;
|
|
43
|
+
})
|
|
44
|
+
.catch(err => {
|
|
45
|
+
state.loading = false;
|
|
46
|
+
state.error = err;
|
|
47
|
+
throw err;
|
|
48
|
+
});
|
|
49
|
+
return state;
|
|
50
|
+
}
|
|
51
|
+
function loadMap(obj) {
|
|
52
|
+
let state = {
|
|
53
|
+
loading: false,
|
|
54
|
+
loaded: {},
|
|
55
|
+
error: null
|
|
56
|
+
};
|
|
57
|
+
let promises = [];
|
|
58
|
+
try {
|
|
59
|
+
Object.keys(obj).forEach(key => {
|
|
60
|
+
let result = load(obj[key]);
|
|
61
|
+
if (!result.loading) {
|
|
62
|
+
state.loaded[key] = result.loaded;
|
|
63
|
+
state.error = result.error;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
state.loading = true;
|
|
67
|
+
}
|
|
68
|
+
promises.push(result.promise);
|
|
69
|
+
result.promise
|
|
70
|
+
.then(res => {
|
|
71
|
+
state.loaded[key] = res;
|
|
72
|
+
})
|
|
73
|
+
.catch(err => {
|
|
74
|
+
state.error = err;
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
state.error = err;
|
|
80
|
+
}
|
|
81
|
+
state.promise = Promise.all(promises)
|
|
82
|
+
.then(res => {
|
|
83
|
+
state.loading = false;
|
|
84
|
+
return res;
|
|
85
|
+
})
|
|
86
|
+
.catch(err => {
|
|
87
|
+
state.loading = false;
|
|
88
|
+
throw err;
|
|
89
|
+
});
|
|
90
|
+
return state;
|
|
91
|
+
}
|
|
92
|
+
function resolve(obj) {
|
|
93
|
+
return obj && obj.__esModule ? obj.default : obj;
|
|
94
|
+
}
|
|
95
|
+
function render(loaded, props) {
|
|
96
|
+
return React.createElement(resolve(loaded), props);
|
|
97
|
+
}
|
|
98
|
+
function createLoadableComponent(loadFn, options) {
|
|
99
|
+
let opts = Object.assign({
|
|
100
|
+
loader: null,
|
|
101
|
+
loading: null,
|
|
102
|
+
delay: 200,
|
|
103
|
+
timeout: null,
|
|
104
|
+
render: render,
|
|
105
|
+
webpack: null,
|
|
106
|
+
modules: null
|
|
107
|
+
}, options);
|
|
108
|
+
let subscription = null;
|
|
109
|
+
function init() {
|
|
110
|
+
if (!subscription) {
|
|
111
|
+
const sub = new LoadableSubscription(loadFn, opts);
|
|
112
|
+
subscription = {
|
|
113
|
+
getCurrentValue: sub.getCurrentValue.bind(sub),
|
|
114
|
+
subscribe: sub.subscribe.bind(sub),
|
|
115
|
+
retry: sub.retry.bind(sub),
|
|
116
|
+
promise: sub.promise.bind(sub)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return subscription.promise();
|
|
120
|
+
}
|
|
121
|
+
// Server only
|
|
122
|
+
if (typeof window === 'undefined') {
|
|
123
|
+
ALL_INITIALIZERS.push(init);
|
|
124
|
+
}
|
|
125
|
+
// Client only
|
|
126
|
+
if (!initialized &&
|
|
127
|
+
typeof window !== 'undefined' &&
|
|
128
|
+
typeof opts.webpack === 'function') {
|
|
129
|
+
const moduleIds = opts.webpack();
|
|
130
|
+
READY_INITIALIZERS.push(ids => {
|
|
131
|
+
for (const moduleId of moduleIds) {
|
|
132
|
+
if (ids.indexOf(moduleId) !== -1) {
|
|
133
|
+
return init();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const LoadableComponent = React.forwardRef((props, ref) => {
|
|
139
|
+
init();
|
|
140
|
+
const context = React.useContext(LoadableContext);
|
|
141
|
+
const state = useSyncExternalStore(subscription.subscribe, subscription.getCurrentValue, subscription.getCurrentValue);
|
|
142
|
+
React.useImperativeHandle(ref, () => ({
|
|
143
|
+
retry: subscription.retry
|
|
144
|
+
}), []);
|
|
145
|
+
if (context && Array.isArray(opts.modules)) {
|
|
146
|
+
opts.modules.forEach(moduleName => {
|
|
147
|
+
context(moduleName);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return React.useMemo(() => {
|
|
151
|
+
if (state.loading || state.error) {
|
|
152
|
+
return React.createElement(opts.loading, {
|
|
153
|
+
isLoading: state.loading,
|
|
154
|
+
pastDelay: state.pastDelay,
|
|
155
|
+
timedOut: state.timedOut,
|
|
156
|
+
error: state.error,
|
|
157
|
+
retry: subscription.retry
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else if (state.loaded) {
|
|
161
|
+
return opts.render(state.loaded, props);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}, [props, state]);
|
|
167
|
+
});
|
|
168
|
+
LoadableComponent.preload = () => init();
|
|
169
|
+
LoadableComponent.displayName = 'LoadableComponent';
|
|
170
|
+
return LoadableComponent;
|
|
171
|
+
}
|
|
172
|
+
class LoadableSubscription {
|
|
173
|
+
constructor(loadFn, opts) {
|
|
174
|
+
this._loadFn = loadFn;
|
|
175
|
+
this._opts = opts;
|
|
176
|
+
this._callbacks = new Set();
|
|
177
|
+
this._delay = null;
|
|
178
|
+
this._timeout = null;
|
|
179
|
+
this.retry();
|
|
180
|
+
}
|
|
181
|
+
promise() {
|
|
182
|
+
return this._res.promise;
|
|
183
|
+
}
|
|
184
|
+
retry() {
|
|
185
|
+
this._clearTimeouts();
|
|
186
|
+
this._res = this._loadFn(this._opts.loader);
|
|
187
|
+
this._state = {
|
|
188
|
+
pastDelay: false,
|
|
189
|
+
timedOut: false
|
|
190
|
+
};
|
|
191
|
+
const { _res: res, _opts: opts } = this;
|
|
192
|
+
if (res.loading) {
|
|
193
|
+
if (typeof opts.delay === 'number') {
|
|
194
|
+
if (opts.delay === 0) {
|
|
195
|
+
this._state.pastDelay = true;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this._delay = setTimeout(() => {
|
|
199
|
+
this._update({
|
|
200
|
+
pastDelay: true
|
|
201
|
+
});
|
|
202
|
+
}, opts.delay);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (typeof opts.timeout === 'number') {
|
|
206
|
+
this._timeout = setTimeout(() => {
|
|
207
|
+
this._update({ timedOut: true });
|
|
208
|
+
}, opts.timeout);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
this._res.promise
|
|
212
|
+
.then(() => {
|
|
213
|
+
this._update({});
|
|
214
|
+
this._clearTimeouts();
|
|
215
|
+
})
|
|
216
|
+
.catch(_err => {
|
|
217
|
+
this._update({});
|
|
218
|
+
this._clearTimeouts();
|
|
219
|
+
});
|
|
220
|
+
this._update({});
|
|
221
|
+
}
|
|
222
|
+
_update(partial) {
|
|
223
|
+
this._state = Object.assign(Object.assign(Object.assign({}, this._state), { error: this._res.error, loaded: this._res.loaded, loading: this._res.loading }), partial);
|
|
224
|
+
this._callbacks.forEach(callback => callback());
|
|
225
|
+
}
|
|
226
|
+
_clearTimeouts() {
|
|
227
|
+
clearTimeout(this._delay);
|
|
228
|
+
clearTimeout(this._timeout);
|
|
229
|
+
}
|
|
230
|
+
getCurrentValue() {
|
|
231
|
+
return this._state;
|
|
232
|
+
}
|
|
233
|
+
subscribe(callback) {
|
|
234
|
+
this._callbacks.add(callback);
|
|
235
|
+
return () => {
|
|
236
|
+
this._callbacks.delete(callback);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function Loadable(opts) {
|
|
241
|
+
return createLoadableComponent(load, opts);
|
|
242
|
+
}
|
|
243
|
+
function LoadableMap(opts) {
|
|
244
|
+
if (typeof opts.render !== 'function') {
|
|
245
|
+
throw new Error('LoadableMap requires a `render(loaded, props)` function');
|
|
246
|
+
}
|
|
247
|
+
return createLoadableComponent(loadMap, opts);
|
|
248
|
+
}
|
|
249
|
+
Loadable.Map = LoadableMap;
|
|
250
|
+
function flushInitializers(initializers, ids) {
|
|
251
|
+
let promises = [];
|
|
252
|
+
while (initializers.length) {
|
|
253
|
+
let init = initializers.pop();
|
|
254
|
+
promises.push(init(ids));
|
|
255
|
+
}
|
|
256
|
+
return Promise.all(promises).then(() => {
|
|
257
|
+
if (initializers.length) {
|
|
258
|
+
return flushInitializers(initializers, ids);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
Loadable.preloadAll = () => {
|
|
263
|
+
return new Promise((resolveInitializers, reject) => {
|
|
264
|
+
flushInitializers(ALL_INITIALIZERS).then(resolveInitializers, reject);
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
Loadable.preloadReady = (ids = []) => {
|
|
268
|
+
return new Promise(resolvePreload => {
|
|
269
|
+
const res = () => {
|
|
270
|
+
initialized = true;
|
|
271
|
+
return resolvePreload();
|
|
272
|
+
};
|
|
273
|
+
// We always will resolve, errors should be handled within loading UIs.
|
|
274
|
+
flushInitializers(READY_INITIALIZERS, ids).then(res, res);
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
export default Loadable;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RedoxRoot } from '@shuvi/redox-react';
|
|
3
|
+
export const RedoxWrapper = (App, appContext) => {
|
|
4
|
+
function RedoxAppWrapper(appProps) {
|
|
5
|
+
return (<RedoxRoot storeManager={appContext.storeManager}>
|
|
6
|
+
<App {...appProps}/>
|
|
7
|
+
</RedoxRoot>);
|
|
8
|
+
}
|
|
9
|
+
RedoxAppWrapper.displayName = 'RedoxAppWrapper';
|
|
10
|
+
return RedoxAppWrapper;
|
|
11
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { createRuntimePlugin } from '@shuvi/platform-shared/shared';
|
|
11
|
+
import { RedoxWrapper } from './RedoxWrapper';
|
|
12
|
+
export default createRuntimePlugin({
|
|
13
|
+
appComponent: (App, appContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
return RedoxWrapper(App, appContext);
|
|
15
|
+
})
|
|
16
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IAppState } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { IHtmlTag, IViewClient, IViewServer } from '../../shared';
|
|
3
|
+
export { IHtmlTag };
|
|
4
|
+
export declare type IReactAppData = {
|
|
5
|
+
appProps?: Record<string, any>;
|
|
6
|
+
errorProps?: {
|
|
7
|
+
notFound: boolean;
|
|
8
|
+
};
|
|
9
|
+
dynamicIds?: Array<string | number>;
|
|
10
|
+
appState?: IAppState;
|
|
11
|
+
loadersData: any;
|
|
12
|
+
};
|
|
13
|
+
export declare type IReactServerView = IViewServer<IReactAppData>;
|
|
14
|
+
export declare type IReactClientView = IViewClient<IReactAppData>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useMatchedRoute } from '@shuvi/router-react';
|
|
2
|
+
import { getLoaderManager } from '@shuvi/platform-shared/shared';
|
|
3
|
+
import { useRef, useEffect, useReducer } from 'react';
|
|
4
|
+
export const noLoaderMessage = 'Warning: no loader found. Please make sure the page component where `useLoaderData` is called has a `loader` export.';
|
|
5
|
+
export const useLoaderData = () => {
|
|
6
|
+
var _a;
|
|
7
|
+
const currentMatch = useMatchedRoute();
|
|
8
|
+
const loaderManager = getLoaderManager();
|
|
9
|
+
const id = (_a = currentMatch.route) === null || _a === void 0 ? void 0 : _a.id;
|
|
10
|
+
const data = loaderManager.getData(id);
|
|
11
|
+
if (data === null) {
|
|
12
|
+
throw Error(noLoaderMessage);
|
|
13
|
+
}
|
|
14
|
+
const dataRef = useRef(data);
|
|
15
|
+
const [_, forceUpdate] = useReducer(state => state * -1, 1);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const cancel = loaderManager.subscribe(() => {
|
|
18
|
+
const newData = loaderManager.getData(id);
|
|
19
|
+
if (newData !== data) {
|
|
20
|
+
dataRef.current = newData;
|
|
21
|
+
forceUpdate();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return cancel;
|
|
25
|
+
}, []);
|
|
26
|
+
return dataRef.current;
|
|
27
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const requestIdleCallback: ((callback: IdleRequestCallback, options?: IdleRequestOptions | undefined) => number) & typeof globalThis.requestIdleCallback;
|
|
2
|
+
export declare const cancelIdleCallback: ((handle: number) => void) & typeof globalThis.cancelIdleCallback;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const requestIdleCallback = (typeof self !== 'undefined' &&
|
|
2
|
+
self.requestIdleCallback &&
|
|
3
|
+
self.requestIdleCallback.bind(window)) ||
|
|
4
|
+
function (cb) {
|
|
5
|
+
let start = Date.now();
|
|
6
|
+
return setTimeout(function () {
|
|
7
|
+
cb({
|
|
8
|
+
didTimeout: false,
|
|
9
|
+
timeRemaining: function () {
|
|
10
|
+
return Math.max(0, 50 - (Date.now() - start));
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}, 1);
|
|
14
|
+
};
|
|
15
|
+
export const cancelIdleCallback = (typeof self !== 'undefined' &&
|
|
16
|
+
self.cancelIdleCallback &&
|
|
17
|
+
self.cancelIdleCallback.bind(window)) ||
|
|
18
|
+
function (id) {
|
|
19
|
+
return clearTimeout(id);
|
|
20
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare type UseIntersection = {
|
|
3
|
+
rootRef?: React.RefObject<HTMLElement>;
|
|
4
|
+
rootMargin?: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export default function useIntersection<T extends Element>({ rootRef, rootMargin, disabled }: UseIntersection): [(element: T | null) => void, boolean, () => void];
|
|
8
|
+
export {};
|