@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
|
@@ -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,12 @@ 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 }) {
|
|
22
|
-
var _a;
|
|
21
|
+
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }, forwardedRef) {
|
|
23
22
|
const { siteConfig: { trailingSlash, baseUrl }, } = useDocusaurusContext();
|
|
24
23
|
const { withBaseUrl } = useBaseUrlUtils();
|
|
25
24
|
const linksCollector = useLinksCollector();
|
|
25
|
+
const innerRef = useRef(null);
|
|
26
|
+
useImperativeHandle(forwardedRef, () => innerRef.current);
|
|
26
27
|
// IMPORTANT: using to or href should not change anything
|
|
27
28
|
// For example, MDX links will ALWAYS give us the href props
|
|
28
29
|
// Using one prop or the other should not be used to distinguish
|
|
@@ -40,7 +41,7 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
40
41
|
// see https://github.com/facebook/docusaurus/issues/3309
|
|
41
42
|
// note: we want baseUrl to be appended (see issue for details)
|
|
42
43
|
// TODO read routes and automatically detect internal/external links?
|
|
43
|
-
const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed
|
|
44
|
+
const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed?.replace('pathname://', '');
|
|
44
45
|
// TODO we should use ReactRouter basename feature instead!
|
|
45
46
|
// Automatically apply base url in links that start with /
|
|
46
47
|
let targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
|
|
@@ -50,29 +51,30 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
50
51
|
targetLink = applyTrailingSlash(targetLink, { trailingSlash, baseUrl });
|
|
51
52
|
}
|
|
52
53
|
const preloaded = useRef(false);
|
|
53
|
-
const LinkComponent = isNavLink ? NavLink : RRLink;
|
|
54
|
+
const LinkComponent = (isNavLink ? NavLink : RRLink);
|
|
54
55
|
const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
|
|
55
|
-
|
|
56
|
+
const ioRef = useRef();
|
|
56
57
|
const handleIntersection = (el, cb) => {
|
|
57
|
-
|
|
58
|
+
ioRef.current = new window.IntersectionObserver((entries) => {
|
|
58
59
|
entries.forEach((entry) => {
|
|
59
60
|
if (el === entry.target) {
|
|
60
|
-
// If element is in viewport, stop
|
|
61
|
+
// If element is in viewport, stop observing and run callback.
|
|
61
62
|
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
|
|
62
63
|
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
ioRef.current.unobserve(el);
|
|
65
|
+
ioRef.current.disconnect();
|
|
65
66
|
cb();
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
70
|
});
|
|
70
71
|
// Add element to the observer.
|
|
71
|
-
|
|
72
|
+
ioRef.current.observe(el);
|
|
72
73
|
};
|
|
73
74
|
const handleRef = (ref) => {
|
|
75
|
+
innerRef.current = ref;
|
|
74
76
|
if (IOSupported && ref && isInternal) {
|
|
75
|
-
// If IO supported and element reference found,
|
|
77
|
+
// If IO supported and element reference found, set up Observer.
|
|
76
78
|
handleIntersection(ref, () => {
|
|
77
79
|
if (targetLink != null) {
|
|
78
80
|
window.docusaurus.prefetch(targetLink);
|
|
@@ -95,19 +97,22 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
95
97
|
}
|
|
96
98
|
// When unmounting, stop intersection observer from watching.
|
|
97
99
|
return () => {
|
|
98
|
-
if (IOSupported &&
|
|
99
|
-
|
|
100
|
+
if (IOSupported && ioRef.current) {
|
|
101
|
+
ioRef.current.disconnect();
|
|
100
102
|
}
|
|
101
103
|
};
|
|
102
|
-
}, [targetLink, IOSupported, isInternal]);
|
|
103
|
-
const isAnchorLink =
|
|
104
|
+
}, [ioRef, targetLink, IOSupported, isInternal]);
|
|
105
|
+
const isAnchorLink = targetLink?.startsWith('#') ?? false;
|
|
104
106
|
const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink;
|
|
105
107
|
if (targetLink && isInternal && !isAnchorLink && !noBrokenLinkCheck) {
|
|
106
108
|
linksCollector.collectLink(targetLink);
|
|
107
109
|
}
|
|
108
110
|
return isRegularHtmlLink ? (
|
|
109
111
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
<a ref={innerRef} href={targetLink} {...(targetLinkUnprefixed &&
|
|
113
|
+
!isInternal && { target: '_blank', rel: 'noopener noreferrer' })} {...props}/>) : (<LinkComponent {...props} onMouseEnter={onMouseEnter} innerRef={handleRef} to={targetLink || ''}
|
|
114
|
+
// avoid "React does not recognize the `activeClassName` prop on a DOM
|
|
115
|
+
// element"
|
|
116
|
+
{...(isNavLink && { isActive, activeClassName })}/>);
|
|
112
117
|
}
|
|
113
|
-
export default Link;
|
|
118
|
+
export default React.forwardRef(Link);
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
8
|
-
|
|
9
|
-
import { InterpolateValues } from '@docusaurus/Interpolate';
|
|
8
|
+
import type { ReactNode } from 'react';
|
|
9
|
+
import { type InterpolateValues } from '@docusaurus/Interpolate';
|
|
10
10
|
import type { TranslateParam, TranslateProps } from '@docusaurus/Translate';
|
|
11
11
|
export declare function translate<Str extends string>({ message, id }: TranslateParam<Str>, values?: InterpolateValues<Str, string | number>): string;
|
|
12
|
-
export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>):
|
|
12
|
+
export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>): ReactNode;
|
|
@@ -4,26 +4,30 @@
|
|
|
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
|
|
8
|
-
import Interpolate, { interpolate, } from '@docusaurus/Interpolate';
|
|
7
|
+
import { interpolate } from '@docusaurus/Interpolate';
|
|
9
8
|
// Can't read it from context, due to exposing imperative API
|
|
10
9
|
import codeTranslations from '@generated/codeTranslations';
|
|
11
10
|
function getLocalizedMessage({ id, message, }) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (typeof id === 'undefined' && typeof message === 'undefined') {
|
|
12
|
+
throw new Error('Docusaurus translation declarations must have at least a translation id or a default translation message');
|
|
13
|
+
}
|
|
14
|
+
return codeTranslations[(id ?? message)] ?? message ?? id;
|
|
14
15
|
}
|
|
15
16
|
// Imperative translation API is useful for some edge-cases:
|
|
16
17
|
// - translating page titles (meta)
|
|
17
18
|
// - translating string props (input placeholders, image alt, aria labels...)
|
|
18
19
|
export function translate({ message, id }, values) {
|
|
19
|
-
|
|
20
|
-
const localizedMessage = (_a = getLocalizedMessage({ message, id })) !== null && _a !== void 0 ? _a : message;
|
|
20
|
+
const localizedMessage = getLocalizedMessage({ message, id });
|
|
21
21
|
return interpolate(localizedMessage, values);
|
|
22
22
|
}
|
|
23
23
|
// Maybe we'll want to improve this component with additional features
|
|
24
|
-
// Like toggling a translation mode that adds a little translation button near
|
|
24
|
+
// Like toggling a translation mode that adds a little translation button near
|
|
25
|
+
// the text?
|
|
25
26
|
export default function Translate({ children, id, values, }) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (children && typeof children !== 'string') {
|
|
28
|
+
console.warn('Illegal <Translate> children', children);
|
|
29
|
+
throw new Error('The Docusaurus <Translate> component only accept simple string values');
|
|
30
|
+
}
|
|
31
|
+
const localizedMessage = getLocalizedMessage({ message: children, id });
|
|
32
|
+
return interpolate(localizedMessage, values);
|
|
29
33
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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, { type ReactNode } from 'react';
|
|
8
|
+
export declare const Context: React.Context<boolean>;
|
|
9
|
+
export declare function BrowserContextProvider({ children, }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
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, { useEffect, useState } from 'react';
|
|
8
|
+
// Encapsulate the logic to avoid React hydration problems
|
|
9
|
+
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
10
|
+
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
+
// isBrowser is set to true only after a successful hydration
|
|
12
|
+
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
+
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
14
|
+
// re-rendering after a successful hydration
|
|
15
|
+
export const Context = React.createContext(false);
|
|
16
|
+
export function BrowserContextProvider({ children, }) {
|
|
17
|
+
const [isBrowser, setIsBrowser] = useState(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
setIsBrowser(true);
|
|
20
|
+
}, []);
|
|
21
|
+
return <Context.Provider value={isBrowser}>{children}</Context.Provider>;
|
|
22
|
+
}
|
|
@@ -4,15 +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
|
-
|
|
8
|
-
// eslint-disable-next-line no-restricted-imports
|
|
9
|
-
export {
|
|
10
|
-
// constants were only available on node
|
|
11
|
-
// this makes some useful constants available to frontend/themes too
|
|
12
|
-
// import {DEFAULT_PLUGIN_ID} '@docusaurus/constants'
|
|
13
|
-
DEFAULT_PLUGIN_ID,
|
|
14
|
-
} from '../../constants';
|
|
15
|
-
*/
|
|
16
|
-
// Not duplicating the constants seems to produce
|
|
17
|
-
// weird TS compilation side-effects
|
|
7
|
+
// Constants used on the client-side: duplicated from server-side code
|
|
18
8
|
export const DEFAULT_PLUGIN_ID = 'default';
|
|
@@ -0,0 +1,12 @@
|
|
|
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, { type ReactNode } from 'react';
|
|
8
|
+
import type { DocusaurusContext } from '@docusaurus/types';
|
|
9
|
+
export declare const Context: React.Context<DocusaurusContext>;
|
|
10
|
+
export declare function DocusaurusContextProvider({ children, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 siteConfig from '@generated/docusaurus.config';
|
|
9
|
+
import globalData from '@generated/globalData';
|
|
10
|
+
import i18n from '@generated/i18n';
|
|
11
|
+
import codeTranslations from '@generated/codeTranslations';
|
|
12
|
+
import siteMetadata from '@generated/site-metadata';
|
|
13
|
+
// Static value on purpose: don't make it dynamic!
|
|
14
|
+
// Using context is still useful for testability reasons.
|
|
15
|
+
const contextValue = {
|
|
16
|
+
siteConfig,
|
|
17
|
+
siteMetadata,
|
|
18
|
+
globalData,
|
|
19
|
+
i18n,
|
|
20
|
+
codeTranslations,
|
|
21
|
+
};
|
|
22
|
+
export const Context = React.createContext(contextValue);
|
|
23
|
+
export function DocusaurusContextProvider({ children, }) {
|
|
24
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
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';
|
|
@@ -19,7 +19,7 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
|
|
|
19
19
|
return url;
|
|
20
20
|
}
|
|
21
21
|
if (forcePrependBaseUrl) {
|
|
22
|
-
return baseUrl + url;
|
|
22
|
+
return baseUrl + url.replace(/^\//, '');
|
|
23
23
|
}
|
|
24
24
|
// We should avoid adding the baseurl twice if it's already there
|
|
25
25
|
const shouldAddBaseUrl = !url.startsWith(baseUrl);
|
|
@@ -27,11 +27,9 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
|
|
|
27
27
|
return absolute ? siteUrl + basePath : basePath;
|
|
28
28
|
}
|
|
29
29
|
export function useBaseUrlUtils() {
|
|
30
|
-
const { siteConfig: { baseUrl
|
|
30
|
+
const { siteConfig: { baseUrl, url: siteUrl }, } = useDocusaurusContext();
|
|
31
31
|
return {
|
|
32
|
-
withBaseUrl: (url, options) =>
|
|
33
|
-
return addBaseUrl(siteUrl, baseUrl, url, options);
|
|
34
|
-
},
|
|
32
|
+
withBaseUrl: (url, options) => addBaseUrl(siteUrl, baseUrl, url, options),
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
export default function useBaseUrl(url, options = {}) {
|
|
@@ -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 { DocusaurusContext } from '@docusaurus/types';
|
|
8
|
-
|
|
9
|
-
export default useDocusaurusContext;
|
|
7
|
+
import type { DocusaurusContext } from '@docusaurus/types';
|
|
8
|
+
export default function useDocusaurusContext(): DocusaurusContext;
|
|
@@ -5,13 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { useContext } from 'react';
|
|
8
|
-
import
|
|
9
|
-
function useDocusaurusContext() {
|
|
10
|
-
|
|
11
|
-
if (docusaurusContext === null) {
|
|
12
|
-
// should not happen normally
|
|
13
|
-
throw new Error('Docusaurus context not provided.');
|
|
14
|
-
}
|
|
15
|
-
return docusaurusContext;
|
|
8
|
+
import { Context } from './docusaurusContext';
|
|
9
|
+
export default function useDocusaurusContext() {
|
|
10
|
+
return useContext(Context);
|
|
16
11
|
}
|
|
17
|
-
export default useDocusaurusContext;
|
|
@@ -5,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
8
|
-
|
|
9
|
-
// if we import something from outside the /client folder,
|
|
10
|
-
// the tsc directory structure is affected
|
|
11
|
-
// import {DEFAULT_PLUGIN_ID} from '../../constants';
|
|
12
|
-
const DEFAULT_PLUGIN_ID = 'default';
|
|
8
|
+
import { DEFAULT_PLUGIN_ID } from './constants';
|
|
13
9
|
export default function useGlobalData() {
|
|
14
10
|
const { globalData } = useDocusaurusContext();
|
|
15
11
|
if (!globalData) {
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { useContext } from 'react';
|
|
8
|
+
import { Context } from './browserContext';
|
|
9
|
+
export default function useIsBrowser() {
|
|
10
|
+
return useContext(Context);
|
|
11
|
+
}
|
package/lib/client/flat.d.ts
CHANGED
|
@@ -4,5 +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
|
-
|
|
8
|
-
export default flat
|
|
7
|
+
import type { RouteChunksTree } from '@docusaurus/types';
|
|
8
|
+
export default function flat(target: RouteChunksTree): Record<string, string>;
|
package/lib/client/flat.js
CHANGED
|
@@ -4,25 +4,22 @@
|
|
|
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
|
-
function flat(target) {
|
|
7
|
+
const isTree = (x) => typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
|
8
|
+
export default function flat(target) {
|
|
10
9
|
const delimiter = '.';
|
|
11
10
|
const output = {};
|
|
12
|
-
function step(object,
|
|
11
|
+
function step(object, prefix) {
|
|
13
12
|
Object.keys(object).forEach((key) => {
|
|
14
13
|
const value = object[key];
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const newKey = prev ? prev + delimiter + key : key;
|
|
18
|
-
if (isObject && Object.keys(value).length) {
|
|
14
|
+
const newKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
15
|
+
if (isTree(value)) {
|
|
19
16
|
step(value, newKey);
|
|
20
|
-
return;
|
|
21
17
|
}
|
|
22
|
-
|
|
18
|
+
else {
|
|
19
|
+
output[newKey] = value;
|
|
20
|
+
}
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
23
|
step(target);
|
|
26
24
|
return output;
|
|
27
25
|
}
|
|
28
|
-
export default flat;
|
|
@@ -4,8 +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
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
declare function normalizeLocation<T extends Location>(location: T): T;
|
|
11
|
-
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/nprogress.css
CHANGED
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
|
|
28
28
|
#nprogress .peg {
|
|
29
29
|
position: absolute;
|
|
30
|
-
right:
|
|
30
|
+
right: 0;
|
|
31
31
|
width: 100px;
|
|
32
32
|
height: 100%;
|
|
33
33
|
box-shadow: 0 0 10px #29d, 0 0 5px #29d;
|
|
34
34
|
opacity: 1;
|
|
35
|
-
transform: rotate(3deg) translate(
|
|
35
|
+
transform: rotate(3deg) translate(0, -4px);
|
|
36
36
|
}
|
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();
|
|
@@ -66,8 +66,6 @@ function prefetch(url) {
|
|
|
66
66
|
resolve();
|
|
67
67
|
preFetched[url] = true;
|
|
68
68
|
})
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
70
69
|
.catch(() => { }); // 404s are logged to the console anyway.
|
|
71
70
|
});
|
|
72
71
|
}
|
|
73
|
-
export default prefetch;
|
package/lib/client/preload.d.ts
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
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 { RouteConfig } from 'react-router-config';
|
|
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
|
|
@@ -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
|
+
import type { Locals } from '@slorber/static-site-generator-webpack-plugin';
|
|
8
|
+
export default function render(locals: Locals & {
|
|
9
|
+
path: string;
|
|
10
|
+
}): Promise<string>;
|