@docusaurus/core 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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/bin/beforeCli.mjs +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +63 -108
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +29 -38
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +13 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +16 -22
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +24 -19
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +14 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +6 -6
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +102 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +3 -3
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +13 -19
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +93 -83
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/{server/loadSetup.d.ts → commands/swizzle/context.d.ts} +2 -3
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +103 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +41 -43
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +35 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +57 -38
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +7 -4
- package/lib/server/configValidation.d.ts +2 -2
- package/lib/server/configValidation.js +43 -28
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +2 -4
- package/lib/server/html-tags/index.d.ts +1 -1
- package/lib/server/html-tags/index.js +1 -1
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +32 -46
- package/lib/server/index.d.ts +2 -2
- package/lib/server/index.js +147 -68
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +2 -2
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +2 -2
- package/lib/server/plugins/index.js +34 -35
- package/lib/server/plugins/init.d.ts +12 -2
- package/lib/server/plugins/init.js +48 -58
- package/lib/server/plugins/pluginIds.d.ts +1 -1
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +12 -13
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +50 -29
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +22 -14
- package/lib/server/themes/index.d.ts +3 -3
- package/lib/server/themes/index.js +26 -26
- package/lib/server/translations/translations.d.ts +7 -1
- package/lib/server/translations/translations.js +30 -45
- package/lib/server/translations/translationsExtractor.d.ts +9 -3
- package/lib/server/translations/translationsExtractor.js +159 -120
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +38 -33
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +8 -14
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +9 -8
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +7 -29
- package/lib/webpack/utils.js +54 -171
- package/package.json +74 -69
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -12,9 +12,7 @@ export const createStatefulLinksCollector = () => {
|
|
|
12
12
|
collectLink: (link) => {
|
|
13
13
|
allLinks.add(link);
|
|
14
14
|
},
|
|
15
|
-
getCollectedLinks: () =>
|
|
16
|
-
return [...allLinks];
|
|
17
|
-
},
|
|
15
|
+
getCollectedLinks: () => [...allLinks],
|
|
18
16
|
};
|
|
19
17
|
};
|
|
20
18
|
const Context = createContext({
|
|
@@ -23,9 +21,7 @@ const Context = createContext({
|
|
|
23
21
|
// we only use the broken links checker server-side
|
|
24
22
|
},
|
|
25
23
|
});
|
|
26
|
-
export const useLinksCollector = () =>
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return React.createElement(Context.Provider, { value: linksCollector }, children);
|
|
31
|
-
};
|
|
24
|
+
export const useLinksCollector = () => useContext(Context);
|
|
25
|
+
export function ProvideLinksCollector({ children, linksCollector, }) {
|
|
26
|
+
return <Context.Provider value={linksCollector}>{children}</Context.Provider>;
|
|
27
|
+
}
|
|
@@ -4,6 +4,29 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { type RouteComponentProps } from 'react-router-dom';
|
|
10
|
+
import type { RouteConfig } from 'react-router-config';
|
|
11
|
+
import type { Location } from 'history';
|
|
7
12
|
import './nprogress.css';
|
|
8
|
-
|
|
13
|
+
interface Props extends RouteComponentProps {
|
|
14
|
+
readonly routes: RouteConfig[];
|
|
15
|
+
readonly delay: number;
|
|
16
|
+
readonly location: Location;
|
|
17
|
+
}
|
|
18
|
+
interface State {
|
|
19
|
+
nextRouteHasLoaded: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare class PendingNavigation extends React.Component<Props, State> {
|
|
22
|
+
previousLocation: Location | null;
|
|
23
|
+
progressBarTimeout: NodeJS.Timeout | null;
|
|
24
|
+
constructor(props: Props);
|
|
25
|
+
shouldComponentUpdate(nextProps: Props, nextState: State): boolean;
|
|
26
|
+
private clearProgressBarTimeout;
|
|
27
|
+
private startProgressBar;
|
|
28
|
+
private stopProgressBar;
|
|
29
|
+
render(): JSX.Element;
|
|
30
|
+
}
|
|
31
|
+
declare const _default: React.ComponentClass<Pick<Props, "routes" | "delay">, any> & import("react-router").WithRouterStatics<typeof PendingNavigation>;
|
|
9
32
|
export default _default;
|
|
@@ -26,9 +26,9 @@ class PendingNavigation extends React.Component {
|
|
|
26
26
|
// is done loading.
|
|
27
27
|
shouldComponentUpdate(nextProps, nextState) {
|
|
28
28
|
const routeDidChange = nextProps.location !== this.props.location;
|
|
29
|
-
const { routes, delay
|
|
30
|
-
// If `routeDidChange` is true, means the router is trying to navigate to a
|
|
31
|
-
// route. We will preload the new route.
|
|
29
|
+
const { routes, delay } = this.props;
|
|
30
|
+
// If `routeDidChange` is true, means the router is trying to navigate to a
|
|
31
|
+
// new route. We will preload the new route.
|
|
32
32
|
if (routeDidChange) {
|
|
33
33
|
const nextLocation = normalizeLocation(nextProps.location);
|
|
34
34
|
this.startProgressBar(delay);
|
|
@@ -46,9 +46,7 @@ class PendingNavigation extends React.Component {
|
|
|
46
46
|
});
|
|
47
47
|
// Route has loaded, we can reset previousLocation.
|
|
48
48
|
this.previousLocation = null;
|
|
49
|
-
this.setState({
|
|
50
|
-
nextRouteHasLoaded: true,
|
|
51
|
-
}, this.stopProgressBar);
|
|
49
|
+
this.setState({ nextRouteHasLoaded: true }, this.stopProgressBar);
|
|
52
50
|
const { hash } = nextLocation;
|
|
53
51
|
if (!hash) {
|
|
54
52
|
window.scrollTo(0, 0);
|
|
@@ -92,7 +90,7 @@ class PendingNavigation extends React.Component {
|
|
|
92
90
|
}
|
|
93
91
|
render() {
|
|
94
92
|
const { children, location } = this.props;
|
|
95
|
-
return (
|
|
93
|
+
return (<Route location={normalizeLocation(location)} render={() => children}/>);
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
export default withRouter(PendingNavigation);
|
|
@@ -6,4 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="react" />
|
|
8
8
|
import './styles.module.css';
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
__DOCUSAURUS_INSERT_BASEURL_BANNER: boolean;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* We want to help the users with a bad baseUrl configuration (very common
|
|
16
|
+
* error) Help message is inlined, and hidden if JS or CSS is able to load
|
|
17
|
+
* Note: it might create false positives (ie network failures): not a big deal
|
|
18
|
+
* Note: we only inline this for the homepage to avoid polluting all the site's
|
|
19
|
+
* pages
|
|
20
|
+
* @see https://github.com/facebook/docusaurus/pull/3621
|
|
21
|
+
*/
|
|
9
22
|
export default function BaseUrlIssueBanner(): JSX.Element | null;
|
|
@@ -67,21 +67,26 @@ function BaseUrlIssueBannerEnabled() {
|
|
|
67
67
|
useLayoutEffect(() => {
|
|
68
68
|
window[InsertBannerWindowAttribute] = false;
|
|
69
69
|
}, []);
|
|
70
|
-
return (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
return (<>
|
|
71
|
+
{!ExecutionEnvironment.canUseDOM && (<Head>
|
|
72
|
+
<script>{createInlineScript(baseUrl)}</script>
|
|
73
|
+
</Head>)}
|
|
74
|
+
<div id={BannerContainerId}/>
|
|
75
|
+
</>);
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
/**
|
|
78
|
+
* We want to help the users with a bad baseUrl configuration (very common
|
|
79
|
+
* error) Help message is inlined, and hidden if JS or CSS is able to load
|
|
80
|
+
* Note: it might create false positives (ie network failures): not a big deal
|
|
81
|
+
* Note: we only inline this for the homepage to avoid polluting all the site's
|
|
82
|
+
* pages
|
|
83
|
+
* @see https://github.com/facebook/docusaurus/pull/3621
|
|
84
|
+
*/
|
|
80
85
|
export default function BaseUrlIssueBanner() {
|
|
81
86
|
const { siteConfig: { baseUrl, baseUrlIssueBanner }, } = useDocusaurusContext();
|
|
82
87
|
const { pathname } = useLocation();
|
|
83
88
|
// returns true for the homepage during SRR
|
|
84
89
|
const isHomePage = pathname === baseUrl;
|
|
85
90
|
const enabled = baseUrlIssueBanner && isHomePage;
|
|
86
|
-
return enabled ?
|
|
91
|
+
return enabled ? <BaseUrlIssueBannerEnabled /> : null;
|
|
87
92
|
}
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onRouteUpdateDelayed: (...args: any) => void;
|
|
10
|
-
}
|
|
11
|
-
declare const clientLifecyclesDispatchers: Dispatchers;
|
|
7
|
+
import type { ClientModule } from '@docusaurus/types';
|
|
8
|
+
declare const clientLifecyclesDispatchers: Required<ClientModule>;
|
|
12
9
|
export default clientLifecyclesDispatchers;
|
|
@@ -4,24 +4,20 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
// too dynamic
|
|
8
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
7
|
import clientModules from '@generated/client-modules';
|
|
10
|
-
function dispatchLifecycleAction(lifecycleAction,
|
|
8
|
+
function dispatchLifecycleAction(lifecycleAction, args) {
|
|
11
9
|
clientModules.forEach((clientModule) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
lifecycleFunction(...args);
|
|
16
|
-
}
|
|
10
|
+
const lifecycleFunction = (clientModule?.default?.[lifecycleAction] ??
|
|
11
|
+
clientModule[lifecycleAction]);
|
|
12
|
+
lifecycleFunction?.(...args);
|
|
17
13
|
});
|
|
18
14
|
}
|
|
19
15
|
const clientLifecyclesDispatchers = {
|
|
20
16
|
onRouteUpdate(...args) {
|
|
21
|
-
dispatchLifecycleAction('onRouteUpdate',
|
|
17
|
+
dispatchLifecycleAction('onRouteUpdate', args);
|
|
22
18
|
},
|
|
23
19
|
onRouteUpdateDelayed(...args) {
|
|
24
|
-
dispatchLifecycleAction('onRouteUpdateDelayed',
|
|
20
|
+
dispatchLifecycleAction('onRouteUpdateDelayed', args);
|
|
25
21
|
},
|
|
26
22
|
};
|
|
27
23
|
export default clientLifecyclesDispatchers;
|
|
@@ -7,21 +7,27 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { hydrate, render } from 'react-dom';
|
|
9
9
|
import { BrowserRouter } from 'react-router-dom';
|
|
10
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
10
11
|
import routes from '@generated/routes';
|
|
11
12
|
import ExecutionEnvironment from './exports/ExecutionEnvironment';
|
|
12
13
|
import App from './App';
|
|
13
14
|
import preload from './preload';
|
|
14
15
|
import docusaurus from './docusaurus';
|
|
15
|
-
// Client-side render (e.g: running in browser) to become single-page
|
|
16
|
+
// Client-side render (e.g: running in browser) to become single-page
|
|
17
|
+
// application (SPA).
|
|
16
18
|
if (ExecutionEnvironment.canUseDOM) {
|
|
17
19
|
window.docusaurus = docusaurus;
|
|
18
|
-
// For production, attempt to hydrate existing markup for performant
|
|
20
|
+
// For production, attempt to hydrate existing markup for performant
|
|
21
|
+
// first-load experience.
|
|
19
22
|
// For development, there is no existing markup so we had to render it.
|
|
20
|
-
//
|
|
23
|
+
// We also preload async component to avoid first-load loading screen.
|
|
21
24
|
const renderMethod = process.env.NODE_ENV === 'production' ? hydrate : render;
|
|
22
25
|
preload(routes, window.location.pathname).then(() => {
|
|
23
|
-
renderMethod(
|
|
24
|
-
|
|
26
|
+
renderMethod(<HelmetProvider>
|
|
27
|
+
<BrowserRouter>
|
|
28
|
+
<App />
|
|
29
|
+
</BrowserRouter>
|
|
30
|
+
</HelmetProvider>, document.getElementById('__docusaurus'));
|
|
25
31
|
});
|
|
26
32
|
// Webpack Hot Module Replacement API
|
|
27
33
|
if (module.hot) {
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
1
7
|
declare global {
|
|
2
8
|
const __webpack_require__: {
|
|
3
9
|
gca: (name: string) => string;
|
package/lib/client/docusaurus.js
CHANGED
|
@@ -12,31 +12,20 @@ import preloadHelper from './preload';
|
|
|
12
12
|
import flat from './flat';
|
|
13
13
|
const fetched = {};
|
|
14
14
|
const loaded = {};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if ((navigator.connection.effectiveType || ``).indexOf(`2g`) !== -1 &&
|
|
19
|
-
navigator.connection.saveData) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
15
|
+
// If user is on slow or constrained connection.
|
|
16
|
+
const isSlowConnection = () => navigator.connection?.effectiveType.includes('2g') &&
|
|
17
|
+
navigator.connection?.saveData;
|
|
25
18
|
const canPrefetch = (routePath) => !isSlowConnection() && !loaded[routePath] && !fetched[routePath];
|
|
26
19
|
const canPreload = (routePath) => !isSlowConnection() && !loaded[routePath];
|
|
27
|
-
const flatten = (arrays) => Array.prototype.concat.apply([], arrays);
|
|
28
20
|
// Remove the last part containing the route hash
|
|
29
21
|
// input: /blog/2018/12/14/Happy-First-Birthday-Slash-fe9
|
|
30
22
|
// output: /blog/2018/12/14/Happy-First-Birthday-Slash
|
|
31
|
-
const removeRouteNameHash = (str) => str.replace(
|
|
32
|
-
const getChunkNamesToLoad = (path) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return Object.values(flat(routeChunks));
|
|
38
|
-
}));
|
|
39
|
-
};
|
|
23
|
+
const removeRouteNameHash = (str) => str.replace(/-[^-]+$/, '');
|
|
24
|
+
const getChunkNamesToLoad = (path) => Object.entries(routesChunkNames)
|
|
25
|
+
.filter(([routeNameWithHash]) => removeRouteNameHash(routeNameWithHash) === path)
|
|
26
|
+
.flatMap(([, routeChunks]) =>
|
|
27
|
+
// flat() is useful for nested chunk names, it's not like array.flat()
|
|
28
|
+
Object.values(flat(routeChunks)));
|
|
40
29
|
const docusaurus = {
|
|
41
30
|
prefetch: (routePath) => {
|
|
42
31
|
if (!canPrefetch(routePath)) {
|
|
@@ -46,14 +35,16 @@ const docusaurus = {
|
|
|
46
35
|
fetched[routePath] = true;
|
|
47
36
|
// Find all webpack chunk names needed.
|
|
48
37
|
const matches = matchRoutes(routes, routePath);
|
|
49
|
-
const chunkNamesNeeded =
|
|
38
|
+
const chunkNamesNeeded = matches.flatMap((match) => getChunkNamesToLoad(match.route.path));
|
|
50
39
|
// Prefetch all webpack chunk assets file needed.
|
|
51
40
|
chunkNamesNeeded.forEach((chunkName) => {
|
|
52
|
-
// "__webpack_require__.gca" is a custom function provided by
|
|
53
|
-
// Pass it the chunkName or chunkId you want to load and
|
|
54
|
-
//
|
|
41
|
+
// "__webpack_require__.gca" is a custom function provided by
|
|
42
|
+
// ChunkAssetPlugin. Pass it the chunkName or chunkId you want to load and
|
|
43
|
+
// it will return the URL for that chunk.
|
|
44
|
+
// eslint-disable-next-line camelcase
|
|
55
45
|
const chunkAsset = __webpack_require__.gca(chunkName);
|
|
56
|
-
// In some cases, webpack might decide to optimize further & hence the
|
|
46
|
+
// In some cases, webpack might decide to optimize further & hence the
|
|
47
|
+
// chunk assets are merged to another chunk/previous chunk.
|
|
57
48
|
// Hence, we can safely filter it out/don't need to load it.
|
|
58
49
|
if (chunkAsset && !/undefined/.test(chunkAsset)) {
|
|
59
50
|
prefetchHelper(chunkAsset);
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="react" />
|
|
8
|
-
|
|
9
|
-
children
|
|
8
|
+
export default function BrowserOnly({ children, fallback, }: {
|
|
9
|
+
children: () => JSX.Element;
|
|
10
10
|
fallback?: JSX.Element;
|
|
11
11
|
}): JSX.Element | null;
|
|
12
|
-
export default BrowserOnly;
|
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import React, { isValidElement } from 'react';
|
|
8
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
9
|
+
// Similar comp to the one described here:
|
|
10
|
+
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/#abstractions
|
|
11
|
+
export default function BrowserOnly({ children, fallback, }) {
|
|
12
|
+
const isBrowser = useIsBrowser();
|
|
13
|
+
if (isBrowser) {
|
|
14
|
+
if (typeof children !== 'function' &&
|
|
15
|
+
process.env.NODE_ENV === 'development') {
|
|
16
|
+
throw new Error(`Docusaurus error: The children of <BrowserOnly> must be a "render function", e.g. <BrowserOnly>{() => <span>{window.location.href}</span>}</BrowserOnly>.
|
|
17
|
+
Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
|
|
18
|
+
}
|
|
19
|
+
return <>{children()}</>;
|
|
13
20
|
}
|
|
14
21
|
return fallback || null;
|
|
15
22
|
}
|
|
16
|
-
export default BrowserOnly;
|
|
@@ -5,5 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import Loadable from 'react-loadable';
|
|
8
|
-
|
|
9
|
-
export default ComponentCreator;
|
|
8
|
+
export default function ComponentCreator(path: string, hash: string): ReturnType<typeof Loadable>;
|
|
@@ -10,7 +10,7 @@ import Loading from '@theme/Loading';
|
|
|
10
10
|
import routesChunkNames from '@generated/routesChunkNames';
|
|
11
11
|
import registry from '@generated/registry';
|
|
12
12
|
import flat from '../flat';
|
|
13
|
-
function ComponentCreator(path, hash) {
|
|
13
|
+
export default function ComponentCreator(path, hash) {
|
|
14
14
|
// 404 page
|
|
15
15
|
if (path === '*') {
|
|
16
16
|
return Loadable({
|
|
@@ -32,17 +32,19 @@ function ComponentCreator(path, hash) {
|
|
|
32
32
|
content.foo: () => import('./doc1.md'),
|
|
33
33
|
}
|
|
34
34
|
- optsModules: ['./Pages.js', './doc1.md']
|
|
35
|
-
- optsWebpack: [
|
|
35
|
+
- optsWebpack: [
|
|
36
|
+
require.resolveWeak('./Pages.js'),
|
|
37
|
+
require.resolveWeak('./doc1.md'),
|
|
38
|
+
]
|
|
36
39
|
*/
|
|
37
40
|
const flatChunkNames = flat(chunkNames);
|
|
38
41
|
Object.keys(flatChunkNames).forEach((key) => {
|
|
39
42
|
const chunkRegistry = registry[flatChunkNames[key]];
|
|
40
43
|
if (chunkRegistry) {
|
|
41
|
-
|
|
44
|
+
// eslint-disable-next-line prefer-destructuring
|
|
42
45
|
optsLoader[key] = chunkRegistry[0];
|
|
43
46
|
optsModules.push(chunkRegistry[1]);
|
|
44
47
|
optsWebpack.push(chunkRegistry[2]);
|
|
45
|
-
/* eslint-enable prefer-destructuring */
|
|
46
48
|
}
|
|
47
49
|
});
|
|
48
50
|
return Loadable.Map({
|
|
@@ -70,8 +72,7 @@ function ComponentCreator(path, hash) {
|
|
|
70
72
|
});
|
|
71
73
|
const Component = loadedModules.component;
|
|
72
74
|
delete loadedModules.component;
|
|
73
|
-
return
|
|
75
|
+
return <Component {...loadedModules} {...props}/>;
|
|
74
76
|
},
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
|
-
export default ComponentCreator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="@docusaurus/module-type-aliases" />
|
|
8
|
+
import React, { type ReactNode } from 'react';
|
|
9
|
+
import type { Props } from '@docusaurus/ErrorBoundary';
|
|
10
|
+
interface State {
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
export default class ErrorBoundary extends React.Component<Props, State> {
|
|
14
|
+
constructor(props: Props);
|
|
15
|
+
componentDidCatch(error: Error): void;
|
|
16
|
+
render(): ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
|
+
import DefaultFallback from '@theme/Error';
|
|
10
|
+
export default class ErrorBoundary extends React.Component {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.state = { error: null };
|
|
14
|
+
}
|
|
15
|
+
componentDidCatch(error) {
|
|
16
|
+
// Catch errors in any components below and re-render with error message
|
|
17
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
18
|
+
this.setState({ error });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
const { children } = this.props;
|
|
23
|
+
const { error } = this.state;
|
|
24
|
+
if (error) {
|
|
25
|
+
const fallback = this.props.fallback ?? DefaultFallback;
|
|
26
|
+
return fallback({
|
|
27
|
+
error,
|
|
28
|
+
tryAgain: () => this.setState({ error: null }),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return (children ??
|
|
32
|
+
// See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
|
|
33
|
+
null);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -6,6 +6,5 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
8
8
|
/// <reference types="react" />
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
export default Head;
|
|
9
|
+
import type { Props } from '@docusaurus/Head';
|
|
10
|
+
export default function Head(props: Props): JSX.Element;
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import { Helmet } from 'react-helmet';
|
|
9
|
-
function Head(props) {
|
|
10
|
-
return
|
|
8
|
+
import { Helmet } from 'react-helmet-async';
|
|
9
|
+
export default function Head(props) {
|
|
10
|
+
return <Helmet {...props}/>;
|
|
11
11
|
}
|
|
12
|
-
export default Head;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
8
|
-
import { ReactNode } from 'react';
|
|
8
|
+
import { type ReactNode } from 'react';
|
|
9
9
|
import type { InterpolateProps, InterpolateValues } from '@docusaurus/Interpolate';
|
|
10
10
|
export declare function interpolate<Str extends string>(text: Str, values?: InterpolateValues<Str, string | number>): string;
|
|
11
11
|
export declare function interpolate<Str extends string, Value extends ReactNode>(text: Str, values?: InterpolateValues<Str, Value>): ReactNode;
|
|
@@ -16,8 +16,8 @@ export function interpolate(text, values) {
|
|
|
16
16
|
const elements = [];
|
|
17
17
|
const processedText = text.replace(ValueRegexp, (match) => {
|
|
18
18
|
// remove {{ and }} around the placeholder
|
|
19
|
-
const key = match.
|
|
20
|
-
const value = values
|
|
19
|
+
const key = match.substring(1, match.length - 1);
|
|
20
|
+
const value = values?.[key];
|
|
21
21
|
if (typeof value !== 'undefined') {
|
|
22
22
|
const element = React.isValidElement(value)
|
|
23
23
|
? value
|
|
@@ -26,37 +26,31 @@ export function interpolate(text, values) {
|
|
|
26
26
|
elements.push(element);
|
|
27
27
|
return ValueFoundMarker;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
return match; // no match? add warning?
|
|
31
|
-
}
|
|
29
|
+
return match; // no match? add warning?
|
|
32
30
|
});
|
|
33
31
|
// No interpolation to be done: just return the text
|
|
34
32
|
if (elements.length === 0) {
|
|
35
33
|
return text;
|
|
36
34
|
}
|
|
37
35
|
// Basic string interpolation: returns interpolated string
|
|
38
|
-
|
|
36
|
+
if (elements.every((el) => typeof el === 'string')) {
|
|
39
37
|
return processedText
|
|
40
38
|
.split(ValueFoundMarker)
|
|
41
|
-
.reduce((str, value, index) =>
|
|
42
|
-
var _a;
|
|
43
|
-
return str.concat(value).concat((_a = elements[index]) !== null && _a !== void 0 ? _a : '');
|
|
44
|
-
}, '');
|
|
39
|
+
.reduce((str, value, index) => str.concat(value).concat(elements[index] ?? ''), '');
|
|
45
40
|
}
|
|
46
41
|
// JSX interpolation: returns ReactNode
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
value,
|
|
55
|
-
elements[index]),
|
|
56
|
-
];
|
|
57
|
-
}, []);
|
|
58
|
-
}
|
|
42
|
+
return processedText.split(ValueFoundMarker).reduce((array, value, index) => [
|
|
43
|
+
...array,
|
|
44
|
+
<React.Fragment key={index}>
|
|
45
|
+
{value}
|
|
46
|
+
{elements[index]}
|
|
47
|
+
</React.Fragment>,
|
|
48
|
+
], []);
|
|
59
49
|
}
|
|
60
50
|
export default function Interpolate({ children, values, }) {
|
|
51
|
+
if (typeof children !== 'string') {
|
|
52
|
+
console.warn('Illegal <Interpolate> children', children);
|
|
53
|
+
throw new Error('The Docusaurus <Interpolate> component only accept simple string values');
|
|
54
|
+
}
|
|
61
55
|
return interpolate(children, values);
|
|
62
56
|
}
|
|
@@ -4,14 +4,20 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
/// <reference types="react" />
|
|
9
|
-
import type { LinkProps } from '@docusaurus/Link';
|
|
7
|
+
import React from 'react';
|
|
10
8
|
import type docusaurus from '../docusaurus';
|
|
11
9
|
declare global {
|
|
12
10
|
interface Window {
|
|
13
11
|
docusaurus: typeof docusaurus;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
declare
|
|
17
|
-
|
|
14
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<Partial<import("react-router-dom").NavLinkProps<unknown>> & React.ClassAttributes<HTMLAnchorElement> & React.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
15
|
+
readonly className?: string | undefined;
|
|
16
|
+
readonly style?: React.CSSProperties | undefined;
|
|
17
|
+
readonly isNavLink?: boolean | undefined;
|
|
18
|
+
readonly to?: string | undefined;
|
|
19
|
+
readonly href?: string | undefined;
|
|
20
|
+
readonly autoAddBaseUrl?: boolean | undefined;
|
|
21
|
+
readonly 'data-noBrokenLinkCheck'?: boolean | undefined;
|
|
22
|
+
}, "children" | "replace" | "slot" | "style" | "title" | "component" | "location" | "exact" | "sensitive" | "strict" | "id" | "dir" | "rel" | "href" | "type" | "key" | "isNavLink" | "className" | "to" | "innerRef" | "download" | "hrefLang" | "media" | "ping" | "target" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "activeClassName" | "activeStyle" | "isActive" | "data-noBrokenLinkCheck" | "autoAddBaseUrl"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
23
|
+
export default _default;
|