@docusaurus/core 2.0.0-beta.15 → 2.0.0-beta.16
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} +62 -40
- package/lib/babel/preset.d.ts +1 -2
- package/lib/babel/preset.js +5 -4
- package/lib/choosePort.js +22 -30
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +13 -8
- package/lib/client/LinksCollector.js +1 -1
- package/lib/client/PendingNavigation.d.ts +4 -4
- package/lib/client/PendingNavigation.js +4 -6
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -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 +5 -7
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.js +6 -4
- package/lib/client/exports/BrowserOnly.d.ts +1 -2
- package/lib/client/exports/BrowserOnly.js +2 -3
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +1 -2
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.js +9 -12
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +13 -7
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +3 -2
- package/lib/client/exports/docusaurusContext.js +1 -1
- 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/useDocusaurusContext.d.ts +1 -2
- package/lib/client/exports/useDocusaurusContext.js +1 -2
- package/lib/client/flat.d.ts +1 -2
- package/lib/client/flat.js +1 -2
- package/lib/client/normalizeLocation.d.ts +2 -3
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -2
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +23 -19
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +21 -29
- 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 +46 -114
- package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -5
- package/lib/commands/build.js +33 -34
- package/lib/commands/clear.js +23 -11
- package/lib/commands/deploy.js +12 -11
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +3 -2
- package/lib/commands/start.js +4 -4
- 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 +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- 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/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +13 -14
- package/lib/commands/writeTranslations.js +10 -7
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.js +30 -20
- package/lib/server/config.js +1 -1
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +32 -23
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/html-tags/htmlTags.js +1 -2
- package/lib/server/i18n.d.ts +0 -1
- package/lib/server/i18n.js +16 -26
- package/lib/server/index.d.ts +1 -1
- package/lib/server/index.js +17 -15
- package/lib/server/loadSetup.d.ts +1 -2
- package/lib/server/loadSetup.js +2 -2
- package/lib/server/moduleShorthand.js +1 -1
- package/lib/server/plugins/index.js +9 -9
- package/lib/server/plugins/init.d.ts +11 -1
- package/lib/server/plugins/init.js +23 -28
- package/lib/server/plugins/pluginIds.js +4 -3
- package/lib/server/presets/index.d.ts +2 -2
- package/lib/server/presets/index.js +3 -3
- package/lib/server/routes.js +13 -7
- package/lib/server/themes/alias.d.ts +1 -1
- package/lib/server/themes/alias.js +5 -6
- package/lib/server/themes/index.d.ts +2 -2
- package/lib/server/themes/index.js +10 -9
- package/lib/server/translations/translations.js +10 -11
- package/lib/server/translations/translationsExtractor.js +20 -19
- package/lib/server/versions/index.d.ts +2 -3
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +2 -2
- package/lib/webpack/base.js +30 -22
- package/lib/webpack/client.d.ts +1 -1
- package/lib/webpack/client.js +7 -4
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
- package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
- package/lib/webpack/server.d.ts +1 -1
- package/lib/webpack/server.js +6 -5
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +17 -37
- package/package.json +56 -56
- package/bin/beforeCli.js +0 -124
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -236
- package/lib/server/versions/__tests/index.test.js +0 -26
|
@@ -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) {
|
package/lib/client/docusaurus.js
CHANGED
|
@@ -23,7 +23,7 @@ const canPreload = (routePath) => !isSlowConnection() && !loaded[routePath];
|
|
|
23
23
|
// Remove the last part containing the route hash
|
|
24
24
|
// input: /blog/2018/12/14/Happy-First-Birthday-Slash-fe9
|
|
25
25
|
// output: /blog/2018/12/14/Happy-First-Birthday-Slash
|
|
26
|
-
const removeRouteNameHash = (str) => str.replace(
|
|
26
|
+
const removeRouteNameHash = (str) => str.replace(/-[^-]+$/, '');
|
|
27
27
|
const getChunkNamesToLoad = (path) => Object.entries(routesChunkNames)
|
|
28
28
|
.filter(([routeNameWithHash]) => removeRouteNameHash(routeNameWithHash) === path)
|
|
29
29
|
.flatMap(([, routeChunks]) =>
|
|
@@ -41,11 +41,13 @@ const docusaurus = {
|
|
|
41
41
|
const chunkNamesNeeded = matches.flatMap((match) => getChunkNamesToLoad(match.route.path));
|
|
42
42
|
// Prefetch all webpack chunk assets file needed.
|
|
43
43
|
chunkNamesNeeded.forEach((chunkName) => {
|
|
44
|
-
// "__webpack_require__.gca" is a custom function provided by
|
|
45
|
-
// Pass it the chunkName or chunkId you want to load and
|
|
44
|
+
// "__webpack_require__.gca" is a custom function provided by
|
|
45
|
+
// ChunkAssetPlugin. Pass it the chunkName or chunkId you want to load and
|
|
46
|
+
// it will return the URL for that chunk.
|
|
46
47
|
// eslint-disable-next-line camelcase
|
|
47
48
|
const chunkAsset = __webpack_require__.gca(chunkName);
|
|
48
|
-
// In some cases, webpack might decide to optimize further & hence the
|
|
49
|
+
// In some cases, webpack might decide to optimize further & hence the
|
|
50
|
+
// chunk assets are merged to another chunk/previous chunk.
|
|
49
51
|
// Hence, we can safely filter it out/don't need to load it.
|
|
50
52
|
if (chunkAsset && !/undefined/.test(chunkAsset)) {
|
|
51
53
|
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
|
-
|
|
8
|
+
export default function BrowserOnly({ children, fallback, }: {
|
|
9
9
|
children: () => JSX.Element;
|
|
10
10
|
fallback?: JSX.Element;
|
|
11
11
|
}): JSX.Element | null;
|
|
12
|
-
export default BrowserOnly;
|
|
@@ -8,7 +8,7 @@ import React, { isValidElement } from 'react';
|
|
|
8
8
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
9
9
|
// Similar comp to the one described here:
|
|
10
10
|
// https://www.joshwcomeau.com/react/the-perils-of-rehydration/#abstractions
|
|
11
|
-
function BrowserOnly({ children, fallback, }) {
|
|
11
|
+
export default function BrowserOnly({ children, fallback, }) {
|
|
12
12
|
const isBrowser = useIsBrowser();
|
|
13
13
|
if (isBrowser) {
|
|
14
14
|
if (typeof children !== 'function' &&
|
|
@@ -16,8 +16,7 @@ function BrowserOnly({ children, fallback, }) {
|
|
|
16
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
17
|
Current type: ${isValidElement(children) ? 'React element' : typeof children}`);
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return <>{children()}</>;
|
|
20
20
|
}
|
|
21
21
|
return fallback || null;
|
|
22
22
|
}
|
|
23
|
-
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;
|
|
@@ -10,9 +10,9 @@ import type { Props } from '@docusaurus/ErrorBoundary';
|
|
|
10
10
|
interface State {
|
|
11
11
|
error: Error | null;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
export default class ErrorBoundary extends React.Component<Props, State> {
|
|
14
14
|
constructor(props: Props);
|
|
15
15
|
componentDidCatch(error: Error): void;
|
|
16
16
|
render(): ReactNode;
|
|
17
17
|
}
|
|
18
|
-
export
|
|
18
|
+
export {};
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
9
|
import DefaultFallback from '@theme/Error';
|
|
10
|
-
class ErrorBoundary extends React.Component {
|
|
10
|
+
export default class ErrorBoundary extends React.Component {
|
|
11
11
|
constructor(props) {
|
|
12
12
|
super(props);
|
|
13
13
|
this.state = { error: null };
|
|
@@ -34,4 +34,3 @@ class ErrorBoundary extends React.Component {
|
|
|
34
34
|
null);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export default ErrorBoundary;
|
|
@@ -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;
|
|
@@ -26,29 +26,26 @@ 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
39
|
.reduce((str, value, index) => { var _a; return str.concat(value).concat((_a = elements[index]) !== null && _a !== void 0 ? _a : ''); }, '');
|
|
42
40
|
}
|
|
43
41
|
// JSX interpolation: returns ReactNode
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
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
|
+
], []);
|
|
52
49
|
}
|
|
53
50
|
export default function Interpolate({ children, values, }) {
|
|
54
51
|
if (typeof children !== 'string') {
|
|
@@ -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;
|
|
@@ -4,7 +4,7 @@
|
|
|
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, { useEffect, useRef } from 'react';
|
|
7
|
+
import React, { useEffect, useImperativeHandle, useRef, } from 'react';
|
|
8
8
|
import { NavLink, Link as RRLink } from 'react-router-dom';
|
|
9
9
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
10
10
|
import isInternalUrl from './isInternalUrl';
|
|
@@ -18,11 +18,13 @@ import { applyTrailingSlash } from '@docusaurus/utils-common';
|
|
|
18
18
|
// this is because useBaseUrl() actually transforms relative links
|
|
19
19
|
// like "introduction" to "/baseUrl/introduction" => bad behavior to fix
|
|
20
20
|
const shouldAddBaseUrlAutomatically = (to) => to.startsWith('/');
|
|
21
|
-
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }) {
|
|
21
|
+
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }, forwardedRef) {
|
|
22
22
|
var _a;
|
|
23
23
|
const { siteConfig: { trailingSlash, baseUrl }, } = useDocusaurusContext();
|
|
24
24
|
const { withBaseUrl } = useBaseUrlUtils();
|
|
25
25
|
const linksCollector = useLinksCollector();
|
|
26
|
+
const innerRef = useRef(null);
|
|
27
|
+
useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
26
28
|
// IMPORTANT: using to or href should not change anything
|
|
27
29
|
// For example, MDX links will ALWAYS give us the href props
|
|
28
30
|
// Using one prop or the other should not be used to distinguish
|
|
@@ -57,7 +59,7 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
57
59
|
ioRef.current = new window.IntersectionObserver((entries) => {
|
|
58
60
|
entries.forEach((entry) => {
|
|
59
61
|
if (el === entry.target) {
|
|
60
|
-
// If element is in viewport, stop
|
|
62
|
+
// If element is in viewport, stop observing and run callback.
|
|
61
63
|
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
|
|
62
64
|
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
63
65
|
ioRef.current.unobserve(el);
|
|
@@ -71,8 +73,9 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
71
73
|
ioRef.current.observe(el);
|
|
72
74
|
};
|
|
73
75
|
const handleRef = (ref) => {
|
|
76
|
+
innerRef.current = ref;
|
|
74
77
|
if (IOSupported && ref && isInternal) {
|
|
75
|
-
// If IO supported and element reference found,
|
|
78
|
+
// If IO supported and element reference found, set up Observer.
|
|
76
79
|
handleIntersection(ref, () => {
|
|
77
80
|
if (targetLink != null) {
|
|
78
81
|
window.docusaurus.prefetch(targetLink);
|
|
@@ -107,7 +110,10 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
107
110
|
}
|
|
108
111
|
return isRegularHtmlLink ? (
|
|
109
112
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
<a ref={innerRef} href={targetLink} {...(targetLinkUnprefixed &&
|
|
114
|
+
!isInternal && { target: '_blank', rel: 'noopener noreferrer' })} {...props}/>) : (<LinkComponent {...props} onMouseEnter={onMouseEnter} innerRef={handleRef} to={targetLink || ''}
|
|
115
|
+
// avoid "React does not recognize the `activeClassName` prop on a DOM
|
|
116
|
+
// element"
|
|
117
|
+
{...(isNavLink && { isActive, activeClassName })}/>);
|
|
112
118
|
}
|
|
113
|
-
export default Link;
|
|
119
|
+
export default React.forwardRef(Link);
|
|
@@ -22,7 +22,8 @@ export function translate({ message, id }, values) {
|
|
|
22
22
|
return interpolate(localizedMessage, values);
|
|
23
23
|
}
|
|
24
24
|
// Maybe we'll want to improve this component with additional features
|
|
25
|
-
// Like toggling a translation mode that adds a little translation button near
|
|
25
|
+
// Like toggling a translation mode that adds a little translation button near
|
|
26
|
+
// the text?
|
|
26
27
|
export default function Translate({ children, id, values, }) {
|
|
27
28
|
if (children && typeof children !== 'string') {
|
|
28
29
|
console.warn('Illegal <Translate> children', children);
|
|
@@ -10,12 +10,13 @@ import React, { useEffect, useState } from 'react';
|
|
|
10
10
|
// On first client-side render, we need to render exactly as the server rendered
|
|
11
11
|
// isBrowser is set to true only after a successful hydration
|
|
12
12
|
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
-
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
13
|
+
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
14
|
+
// re-rendering after a successful hydration
|
|
14
15
|
export const Context = React.createContext(false);
|
|
15
16
|
export function BrowserContextProvider({ children, }) {
|
|
16
17
|
const [isBrowser, setIsBrowser] = useState(false);
|
|
17
18
|
useEffect(() => {
|
|
18
19
|
setIsBrowser(true);
|
|
19
20
|
}, []);
|
|
20
|
-
return
|
|
21
|
+
return <Context.Provider value={isBrowser}>{children}</Context.Provider>;
|
|
21
22
|
}
|
|
@@ -21,5 +21,5 @@ const contextValue = {
|
|
|
21
21
|
};
|
|
22
22
|
export const Context = React.createContext(contextValue);
|
|
23
23
|
export function DocusaurusContextProvider({ children, }) {
|
|
24
|
-
return
|
|
24
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
25
25
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export function hasProtocol(url) {
|
|
8
|
-
return /^(
|
|
8
|
+
return /^(?:\w*:|\/\/)/.test(url) === true;
|
|
9
9
|
}
|
|
10
10
|
export default function isInternalUrl(url) {
|
|
11
11
|
return typeof url !== 'undefined' && !hasProtocol(url);
|
|
@@ -4,5 +4,4 @@
|
|
|
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
|
-
export default renderRoutes;
|
|
7
|
+
export { renderRoutes as default } from 'react-router-config';
|
|
@@ -4,5 +4,4 @@
|
|
|
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
|
-
export default renderRoutes;
|
|
7
|
+
export { renderRoutes as default } from 'react-router-config';
|
|
@@ -5,5 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { DocusaurusContext } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
export default useDocusaurusContext;
|
|
8
|
+
export default function useDocusaurusContext(): DocusaurusContext;
|
package/lib/client/flat.d.ts
CHANGED
|
@@ -5,5 +5,4 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { RouteChunksTree } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
export default flat;
|
|
8
|
+
export default function flat(target: RouteChunksTree): Record<string, string>;
|
package/lib/client/flat.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
const isTree = (x) => typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
|
8
|
-
function flat(target) {
|
|
8
|
+
export default function flat(target) {
|
|
9
9
|
const delimiter = '.';
|
|
10
10
|
const output = {};
|
|
11
11
|
function step(object, prefix) {
|
|
@@ -23,4 +23,3 @@ function flat(target) {
|
|
|
23
23
|
step(target);
|
|
24
24
|
return output;
|
|
25
25
|
}
|
|
26
|
-
export default flat;
|
|
@@ -4,6 +4,5 @@
|
|
|
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 type { Location } from '
|
|
8
|
-
|
|
9
|
-
export default normalizeLocation;
|
|
7
|
+
import type { Location } from 'history';
|
|
8
|
+
export default function normalizeLocation<T extends Location>(location: T): T;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
// Memoize previously normalized pathnames.
|
|
8
8
|
const pathnames = {};
|
|
9
|
-
function normalizeLocation(location) {
|
|
9
|
+
export default function normalizeLocation(location) {
|
|
10
10
|
if (pathnames[location.pathname]) {
|
|
11
11
|
return {
|
|
12
12
|
...location,
|
|
@@ -24,4 +24,3 @@ function normalizeLocation(location) {
|
|
|
24
24
|
pathname,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
export default normalizeLocation;
|
package/lib/client/prefetch.d.ts
CHANGED
|
@@ -4,5 +4,4 @@
|
|
|
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
|
-
export default prefetch;
|
|
7
|
+
export default function prefetch(url: string): Promise<void>;
|
package/lib/client/prefetch.js
CHANGED
|
@@ -55,7 +55,7 @@ const supportedPrefetchStrategy = support('prefetch')
|
|
|
55
55
|
? linkPrefetchStrategy
|
|
56
56
|
: xhrPrefetchStrategy;
|
|
57
57
|
const preFetched = {};
|
|
58
|
-
function prefetch(url) {
|
|
58
|
+
export default function prefetch(url) {
|
|
59
59
|
return new Promise((resolve) => {
|
|
60
60
|
if (preFetched[url]) {
|
|
61
61
|
resolve();
|
|
@@ -69,4 +69,3 @@ function prefetch(url) {
|
|
|
69
69
|
.catch(() => { }); // 404s are logged to the console anyway.
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
export default prefetch;
|
package/lib/client/preload.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { type RouteConfig } from 'react-router-config';
|
|
8
8
|
/**
|
|
9
9
|
* Helper function to make sure all async components for that particular route
|
|
10
|
-
* is preloaded before rendering. This is especially useful to avoid loading
|
|
10
|
+
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
|
+
* screens.
|
|
11
12
|
*
|
|
12
13
|
* @param routes react-router-config
|
|
13
14
|
* @param pathname the route pathname, example: /docs/installation
|
package/lib/client/preload.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { matchRoutes } from 'react-router-config';
|
|
8
8
|
/**
|
|
9
9
|
* Helper function to make sure all async components for that particular route
|
|
10
|
-
* is preloaded before rendering. This is especially useful to avoid loading
|
|
10
|
+
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
|
+
* screens.
|
|
11
12
|
*
|
|
12
13
|
* @param routes react-router-config
|
|
13
14
|
* @param pathname the route pathname, example: /docs/installation
|
|
@@ -8,7 +8,7 @@ import * as eta from 'eta';
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import { StaticRouter } from 'react-router-dom';
|
|
10
10
|
import ReactDOMServer from 'react-dom/server';
|
|
11
|
-
import {
|
|
11
|
+
import { HelmetProvider } from 'react-helmet-async';
|
|
12
12
|
import { getBundles } from 'react-loadable-ssr-addon-v5-slorber';
|
|
13
13
|
import Loadable from 'react-loadable';
|
|
14
14
|
import { minify } from 'html-minifier-terser';
|
|
@@ -20,10 +20,10 @@ import App from './App';
|
|
|
20
20
|
import { createStatefulLinksCollector, ProvideLinksCollector, } from './LinksCollector';
|
|
21
21
|
import logger from '@docusaurus/logger';
|
|
22
22
|
// eslint-disable-next-line no-restricted-imports
|
|
23
|
-
import
|
|
23
|
+
import _ from 'lodash';
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
25
25
|
const packageJson = require('../../package.json');
|
|
26
|
-
const getCompiledSSRTemplate = memoize((template) => eta.compile(template.trim(), {
|
|
26
|
+
const getCompiledSSRTemplate = _.memoize((template) => eta.compile(template.trim(), {
|
|
27
27
|
rmWhitespace: true,
|
|
28
28
|
}));
|
|
29
29
|
function renderSSRTemplate(ssrTemplate, data) {
|
|
@@ -34,32 +34,37 @@ export default async function render(locals) {
|
|
|
34
34
|
try {
|
|
35
35
|
return await doRender(locals);
|
|
36
36
|
}
|
|
37
|
-
catch (
|
|
38
|
-
logger.error `Docusaurus
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (isNotDefinedErrorRegex.test(e.message)) {
|
|
37
|
+
catch (err) {
|
|
38
|
+
logger.error `Docusaurus server-side rendering could not render static page with path path=${locals.path}.`;
|
|
39
|
+
const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
|
|
40
|
+
if (isNotDefinedErrorRegex.test(err.message)) {
|
|
42
41
|
logger.info `It looks like you are using code that should run on the client-side only.
|
|
43
42
|
To get around it, try using code=${'<BrowserOnly>'} (path=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (path=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
|
|
44
43
|
It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
|
|
45
44
|
}
|
|
46
|
-
throw
|
|
45
|
+
throw err;
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
// Renderer for static-site-generator-webpack-plugin (async rendering
|
|
48
|
+
// Renderer for static-site-generator-webpack-plugin (async rendering).
|
|
50
49
|
async function doRender(locals) {
|
|
51
50
|
const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, baseUrl, ssrTemplate, noIndex, } = locals;
|
|
52
51
|
const location = routesLocation[locals.path];
|
|
53
52
|
await preload(routes, location);
|
|
54
53
|
const modules = new Set();
|
|
55
54
|
const context = {};
|
|
55
|
+
const helmetContext = {};
|
|
56
56
|
const linksCollector = createStatefulLinksCollector();
|
|
57
|
-
const appHtml = ReactDOMServer.renderToString(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
const appHtml = ReactDOMServer.renderToString(<Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
|
|
58
|
+
<HelmetProvider context={helmetContext}>
|
|
59
|
+
<StaticRouter location={location} context={context}>
|
|
60
|
+
<ProvideLinksCollector linksCollector={linksCollector}>
|
|
61
|
+
<App />
|
|
62
|
+
</ProvideLinksCollector>
|
|
63
|
+
</StaticRouter>
|
|
64
|
+
</HelmetProvider>
|
|
65
|
+
</Loadable.Capture>);
|
|
61
66
|
onLinksCollected(location, linksCollector.getCollectedLinks());
|
|
62
|
-
const helmet =
|
|
67
|
+
const { helmet } = helmetContext;
|
|
63
68
|
const htmlAttributes = helmet.htmlAttributes.toString();
|
|
64
69
|
const bodyAttributes = helmet.bodyAttributes.toString();
|
|
65
70
|
const metaStrings = [
|
|
@@ -104,9 +109,8 @@ async function doRender(locals) {
|
|
|
104
109
|
minifyJS: true,
|
|
105
110
|
});
|
|
106
111
|
}
|
|
107
|
-
catch (
|
|
108
|
-
logger.error `Minification of page path=${locals.path} failed
|
|
109
|
-
|
|
110
|
-
throw e;
|
|
112
|
+
catch (err) {
|
|
113
|
+
logger.error `Minification of page path=${locals.path} failed.`;
|
|
114
|
+
throw err;
|
|
111
115
|
}
|
|
112
116
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
/// <reference types="react" />
|
|
9
|
+
import type { Props } from '@theme/Error';
|
|
10
|
+
export default function Error({ error, tryAgain }: Props): JSX.Element;
|