@docusaurus/core 2.0.0-beta.fc64c12e4 → 2.0.0
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/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +81 -118
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +18 -51
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +38 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +11 -10
- package/lib/client/exports/constants.js +1 -11
- 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 +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -13
- 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/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +108 -146
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +94 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +107 -102
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -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 +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -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 +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -137
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +166 -99
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +7 -1
- package/lib/server/utils.js +7 -8
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +45 -57
- 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 +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +30 -29
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +21 -12
- 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 +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/beforeCli.js +0 -103
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- 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/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -39
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- 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.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -7,19 +7,18 @@
|
|
|
7
7
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
8
8
|
import { hasProtocol } from './isInternalUrl';
|
|
9
9
|
function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolute = false } = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// it never makes sense to add a base url to a local anchor url
|
|
14
|
-
if (url.startsWith('#')) {
|
|
15
|
-
return url;
|
|
16
|
-
}
|
|
17
|
-
// it never makes sense to add a base url to an url with a protocol
|
|
18
|
-
if (hasProtocol(url)) {
|
|
10
|
+
// It never makes sense to add base url to a local anchor url, or one with a
|
|
11
|
+
// protocol
|
|
12
|
+
if (!url || url.startsWith('#') || hasProtocol(url)) {
|
|
19
13
|
return url;
|
|
20
14
|
}
|
|
21
15
|
if (forcePrependBaseUrl) {
|
|
22
|
-
return baseUrl + url;
|
|
16
|
+
return baseUrl + url.replace(/^\//, '');
|
|
17
|
+
}
|
|
18
|
+
// /baseUrl -> /baseUrl/
|
|
19
|
+
// https://github.com/facebook/docusaurus/issues/6315
|
|
20
|
+
if (url === baseUrl.replace(/\/$/, '')) {
|
|
21
|
+
return baseUrl;
|
|
23
22
|
}
|
|
24
23
|
// We should avoid adding the baseurl twice if it's already there
|
|
25
24
|
const shouldAddBaseUrl = !url.startsWith(baseUrl);
|
|
@@ -27,11 +26,9 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
|
|
|
27
26
|
return absolute ? siteUrl + basePath : basePath;
|
|
28
27
|
}
|
|
29
28
|
export function useBaseUrlUtils() {
|
|
30
|
-
const { siteConfig: { baseUrl
|
|
29
|
+
const { siteConfig: { baseUrl, url: siteUrl }, } = useDocusaurusContext();
|
|
31
30
|
return {
|
|
32
|
-
withBaseUrl: (url, options) =>
|
|
33
|
-
return addBaseUrl(siteUrl, baseUrl, url, options);
|
|
34
|
-
},
|
|
31
|
+
withBaseUrl: (url, options) => addBaseUrl(siteUrl, baseUrl, url, options),
|
|
35
32
|
};
|
|
36
33
|
}
|
|
37
34
|
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;
|
|
@@ -4,6 +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
|
-
|
|
8
|
-
export
|
|
9
|
-
export declare function
|
|
7
|
+
import type { GlobalData, UseDataOptions } from '@docusaurus/types';
|
|
8
|
+
export default function useGlobalData(): GlobalData;
|
|
9
|
+
export declare function useAllPluginInstancesData(pluginName: string, options?: UseDataOptions): GlobalData[string] | undefined;
|
|
10
|
+
export declare function usePluginData(pluginName: string, pluginId?: string, options?: UseDataOptions): GlobalData[string][string];
|
|
@@ -5,30 +5,23 @@
|
|
|
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
|
-
if (!globalData) {
|
|
16
|
-
throw new Error('Docusaurus global data not found.');
|
|
17
|
-
}
|
|
18
11
|
return globalData;
|
|
19
12
|
}
|
|
20
|
-
export function useAllPluginInstancesData(pluginName) {
|
|
13
|
+
export function useAllPluginInstancesData(pluginName, options = {}) {
|
|
21
14
|
const globalData = useGlobalData();
|
|
22
15
|
const pluginGlobalData = globalData[pluginName];
|
|
23
|
-
if (!pluginGlobalData) {
|
|
16
|
+
if (!pluginGlobalData && options.failfast) {
|
|
24
17
|
throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin.`);
|
|
25
18
|
}
|
|
26
19
|
return pluginGlobalData;
|
|
27
20
|
}
|
|
28
|
-
export function usePluginData(pluginName, pluginId = DEFAULT_PLUGIN_ID) {
|
|
21
|
+
export function usePluginData(pluginName, pluginId = DEFAULT_PLUGIN_ID, options = {}) {
|
|
29
22
|
const pluginGlobalData = useAllPluginInstancesData(pluginName);
|
|
30
|
-
const pluginInstanceGlobalData = pluginGlobalData[pluginId];
|
|
31
|
-
if (!pluginInstanceGlobalData) {
|
|
23
|
+
const pluginInstanceGlobalData = pluginGlobalData?.[pluginId];
|
|
24
|
+
if (!pluginInstanceGlobalData && options.failfast) {
|
|
32
25
|
throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin with id "${pluginId}".`);
|
|
33
26
|
}
|
|
34
27
|
return pluginInstanceGlobalData;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 { PluginRouteContext } from '@docusaurus/types';
|
|
8
|
+
export default function useRouteContext(): PluginRouteContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { Context } from '../routeContext';
|
|
9
|
+
export default function useRouteContext() {
|
|
10
|
+
const context = React.useContext(Context);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('Unexpected: no Docusaurus route context found');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
package/lib/client/flat.d.ts
CHANGED
|
@@ -4,5 +4,15 @@
|
|
|
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
|
-
|
|
7
|
+
import type { ChunkNames } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Takes a tree, and flattens it into a map of keyPath -> value.
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* flat({ a: { b: 1 } }) === { "a.b": 1 };
|
|
13
|
+
* flat({ a: [1, 2] }) === { "a.0": 1, "a.1": 2 };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export default function flat(target: ChunkNames): {
|
|
17
|
+
[keyPath: string]: string;
|
|
18
|
+
};
|
package/lib/client/flat.js
CHANGED
|
@@ -4,25 +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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const isTree = (x) => typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
|
8
|
+
/**
|
|
9
|
+
* Takes a tree, and flattens it into a map of keyPath -> value.
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* flat({ a: { b: 1 } }) === { "a.b": 1 };
|
|
13
|
+
* flat({ a: [1, 2] }) === { "a.0": 1, "a.1": 2 };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export default function flat(target) {
|
|
10
17
|
const delimiter = '.';
|
|
11
18
|
const output = {};
|
|
12
|
-
function
|
|
13
|
-
Object.
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
19
|
+
function dfs(object, prefix) {
|
|
20
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
21
|
+
const newKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
22
|
+
if (isTree(value)) {
|
|
23
|
+
dfs(value, newKey);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
output[newKey] = value;
|
|
21
27
|
}
|
|
22
|
-
output[newKey] = value;
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
dfs(target);
|
|
26
31
|
return output;
|
|
27
32
|
}
|
|
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;
|
|
@@ -4,24 +4,28 @@
|
|
|
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 { matchRoutes } from 'react-router-config';
|
|
8
|
+
import routes from '@generated/routes';
|
|
7
9
|
// Memoize previously normalized pathnames.
|
|
8
|
-
const pathnames =
|
|
9
|
-
function normalizeLocation(location) {
|
|
10
|
-
if (pathnames
|
|
10
|
+
const pathnames = new Map();
|
|
11
|
+
export default function normalizeLocation(location) {
|
|
12
|
+
if (pathnames.has(location.pathname)) {
|
|
11
13
|
return {
|
|
12
14
|
...location,
|
|
13
|
-
pathname: pathnames
|
|
15
|
+
pathname: pathnames.get(location.pathname),
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// If the location was registered with an `.html` extension, we don't strip it
|
|
19
|
+
// away, or it will render to a 404 page.
|
|
20
|
+
const matchedRoutes = matchRoutes(routes, location.pathname);
|
|
21
|
+
if (matchedRoutes.some(({ route }) => route.exact === true)) {
|
|
22
|
+
pathnames.set(location.pathname, location.pathname);
|
|
23
|
+
return location;
|
|
20
24
|
}
|
|
21
|
-
|
|
25
|
+
const pathname = location.pathname.trim().replace(/(?:\/index)?\.html$/, '') || '/';
|
|
26
|
+
pathnames.set(location.pathname, pathname);
|
|
22
27
|
return {
|
|
23
28
|
...location,
|
|
24
29
|
pathname,
|
|
25
30
|
};
|
|
26
31
|
}
|
|
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
|
@@ -4,20 +4,14 @@
|
|
|
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
|
-
function
|
|
8
|
-
if (typeof document === 'undefined') {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const fakeLink = document.createElement('link');
|
|
7
|
+
function supports(feature) {
|
|
12
8
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
const fakeLink = document.createElement('link');
|
|
10
|
+
return fakeLink.relList.supports(feature);
|
|
16
11
|
}
|
|
17
|
-
catch
|
|
12
|
+
catch {
|
|
18
13
|
return false;
|
|
19
14
|
}
|
|
20
|
-
return false;
|
|
21
15
|
}
|
|
22
16
|
function linkPrefetchStrategy(url) {
|
|
23
17
|
return new Promise((resolve, reject) => {
|
|
@@ -28,11 +22,11 @@ function linkPrefetchStrategy(url) {
|
|
|
28
22
|
const link = document.createElement('link');
|
|
29
23
|
link.setAttribute('rel', 'prefetch');
|
|
30
24
|
link.setAttribute('href', url);
|
|
31
|
-
link.onload = resolve;
|
|
32
|
-
link.onerror = reject;
|
|
33
|
-
const parentElement = document.getElementsByTagName('head')[0]
|
|
34
|
-
document.getElementsByName('script')[0]
|
|
35
|
-
parentElement
|
|
25
|
+
link.onload = () => resolve();
|
|
26
|
+
link.onerror = () => reject();
|
|
27
|
+
const parentElement = document.getElementsByTagName('head')[0] ??
|
|
28
|
+
document.getElementsByName('script')[0]?.parentNode;
|
|
29
|
+
parentElement?.appendChild(link);
|
|
36
30
|
});
|
|
37
31
|
}
|
|
38
32
|
function xhrPrefetchStrategy(url) {
|
|
@@ -51,23 +45,9 @@ function xhrPrefetchStrategy(url) {
|
|
|
51
45
|
req.send(null);
|
|
52
46
|
});
|
|
53
47
|
}
|
|
54
|
-
const supportedPrefetchStrategy =
|
|
48
|
+
const supportedPrefetchStrategy = supports('prefetch')
|
|
55
49
|
? linkPrefetchStrategy
|
|
56
50
|
: xhrPrefetchStrategy;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return new Promise((resolve) => {
|
|
60
|
-
if (preFetched[url]) {
|
|
61
|
-
resolve();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
supportedPrefetchStrategy(url)
|
|
65
|
-
.then(() => {
|
|
66
|
-
resolve();
|
|
67
|
-
preFetched[url] = true;
|
|
68
|
-
})
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
70
|
-
.catch(() => { }); // 404s are logged to the console anyway.
|
|
71
|
-
});
|
|
51
|
+
export default function prefetch(url) {
|
|
52
|
+
return supportedPrefetchStrategy(url).catch(() => { }); // 404s are logged to the console anyway.
|
|
72
53
|
}
|
|
73
|
-
export default prefetch;
|
package/lib/client/preload.d.ts
CHANGED
|
@@ -4,13 +4,12 @@
|
|
|
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';
|
|
8
7
|
/**
|
|
9
8
|
* Helper function to make sure all async components for that particular route
|
|
10
|
-
* is preloaded before rendering. This is especially useful to avoid loading
|
|
9
|
+
* is preloaded before rendering. This is especially useful to avoid loading
|
|
10
|
+
* screens.
|
|
11
11
|
*
|
|
12
|
-
* @param routes react-router-config
|
|
13
12
|
* @param pathname the route pathname, example: /docs/installation
|
|
14
13
|
* @returns Promise object represents whether pathname has been preloaded
|
|
15
14
|
*/
|
|
16
|
-
export default function preload(
|
|
15
|
+
export default function preload(pathname: string): Promise<void[]>;
|
package/lib/client/preload.js
CHANGED
|
@@ -4,24 +4,17 @@
|
|
|
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 routes from '@generated/routes';
|
|
7
8
|
import { matchRoutes } from 'react-router-config';
|
|
8
9
|
/**
|
|
9
10
|
* Helper function to make sure all async components for that particular route
|
|
10
|
-
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
|
+
* is preloaded before rendering. This is especially useful to avoid loading
|
|
12
|
+
* screens.
|
|
11
13
|
*
|
|
12
|
-
* @param routes react-router-config
|
|
13
14
|
* @param pathname the route pathname, example: /docs/installation
|
|
14
15
|
* @returns Promise object represents whether pathname has been preloaded
|
|
15
16
|
*/
|
|
16
|
-
export default function preload(
|
|
17
|
+
export default function preload(pathname) {
|
|
17
18
|
const matches = matchRoutes(routes, pathname);
|
|
18
|
-
return Promise.all(matches.map((match) =>
|
|
19
|
-
const { component } = match.route;
|
|
20
|
-
// @ts-expect-error: ComponentCreator injected this method.
|
|
21
|
-
if (component && component.preload) {
|
|
22
|
-
// @ts-expect-error: checked above.
|
|
23
|
-
return component.preload();
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
}));
|
|
19
|
+
return Promise.all(matches.map((match) => match.route.component.preload?.()));
|
|
27
20
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { PluginRouteContext, RouteContext } from '@docusaurus/types';
|
|
9
|
+
export declare const Context: React.Context<PluginRouteContext | null>;
|
|
10
|
+
export declare function RouteContextProvider({ children, value, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
value: PluginRouteContext | RouteContext | null;
|
|
13
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
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, { useMemo } from 'react';
|
|
8
|
+
export const Context = React.createContext(null);
|
|
9
|
+
function mergeContexts({ parent, value, }) {
|
|
10
|
+
if (!parent) {
|
|
11
|
+
if (!value) {
|
|
12
|
+
throw new Error('Unexpected: no Docusaurus route context found');
|
|
13
|
+
}
|
|
14
|
+
else if (!('plugin' in value)) {
|
|
15
|
+
throw new Error('Unexpected: Docusaurus topmost route context has no `plugin` attribute');
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
// TODO deep merge this
|
|
20
|
+
const data = { ...parent.data, ...value?.data };
|
|
21
|
+
return {
|
|
22
|
+
// Nested routes are not supposed to override plugin attribute
|
|
23
|
+
plugin: parent.plugin,
|
|
24
|
+
data,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function RouteContextProvider({ children, value, }) {
|
|
28
|
+
const parent = React.useContext(Context);
|
|
29
|
+
const mergedValue = useMemo(() => mergeContexts({ parent, value }), [parent, value]);
|
|
30
|
+
return <Context.Provider value={mergedValue}>{children}</Context.Provider>;
|
|
31
|
+
}
|
|
@@ -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>;
|