@docusaurus/core 2.0.0-beta.15d451942 → 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.
Files changed (191) hide show
  1. package/bin/beforeCli.mjs +136 -0
  2. package/bin/docusaurus.mjs +280 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +32 -41
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +19 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +5 -9
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  14. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  15. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  16. package/lib/client/client-lifecycles-dispatcher.js +5 -9
  17. package/lib/client/clientEntry.js +11 -5
  18. package/lib/client/docusaurus.d.ts +6 -0
  19. package/lib/client/docusaurus.js +17 -23
  20. package/lib/client/exports/BrowserOnly.d.ts +2 -3
  21. package/lib/client/exports/BrowserOnly.js +14 -7
  22. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  23. package/lib/client/exports/ComponentCreator.js +7 -6
  24. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  25. package/lib/client/exports/ErrorBoundary.js +36 -0
  26. package/lib/client/exports/Head.d.ts +2 -3
  27. package/lib/client/exports/Head.js +3 -4
  28. package/lib/client/exports/Interpolate.d.ts +1 -1
  29. package/lib/client/exports/Interpolate.js +15 -21
  30. package/lib/client/exports/Link.d.ts +11 -5
  31. package/lib/client/exports/Link.js +29 -17
  32. package/lib/client/exports/Translate.d.ts +3 -3
  33. package/lib/client/exports/Translate.js +15 -10
  34. package/lib/client/exports/browserContext.d.ts +11 -0
  35. package/lib/client/exports/browserContext.js +22 -0
  36. package/lib/client/exports/constants.js +1 -11
  37. package/lib/client/exports/docusaurusContext.d.ts +12 -0
  38. package/lib/client/exports/docusaurusContext.js +25 -0
  39. package/lib/client/exports/isInternalUrl.js +1 -1
  40. package/lib/client/exports/renderRoutes.d.ts +1 -2
  41. package/lib/client/exports/renderRoutes.js +1 -2
  42. package/lib/client/exports/router.d.ts +1 -1
  43. package/lib/client/exports/router.js +1 -1
  44. package/lib/client/exports/useBaseUrl.js +3 -5
  45. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  46. package/lib/client/exports/useDocusaurusContext.js +3 -9
  47. package/lib/client/exports/useGlobalData.js +4 -8
  48. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  49. package/lib/client/exports/useIsBrowser.js +11 -0
  50. package/lib/client/flat.d.ts +2 -2
  51. package/lib/client/flat.js +8 -11
  52. package/lib/client/normalizeLocation.d.ts +2 -5
  53. package/lib/client/normalizeLocation.js +1 -2
  54. package/lib/client/nprogress.css +2 -2
  55. package/lib/client/prefetch.d.ts +1 -2
  56. package/lib/client/prefetch.js +1 -3
  57. package/lib/client/preload.d.ts +3 -2
  58. package/lib/client/preload.js +2 -1
  59. package/lib/client/serverEntry.d.ts +10 -0
  60. package/lib/client/serverEntry.js +90 -142
  61. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  62. package/lib/client/theme-fallback/Error/index.js +39 -0
  63. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  64. package/lib/client/theme-fallback/Layout/index.js +10 -19
  65. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  66. package/lib/client/theme-fallback/Loading/index.js +47 -115
  67. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  68. package/lib/client/theme-fallback/NotFound/index.js +9 -16
  69. package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
  70. package/lib/client/theme-fallback/Root/index.js +2 -7
  71. package/lib/commands/build.d.ts +1 -1
  72. package/lib/commands/build.js +59 -61
  73. package/lib/commands/clear.d.ts +6 -0
  74. package/lib/commands/clear.js +32 -21
  75. package/lib/commands/commandUtils.d.ts +7 -1
  76. package/lib/commands/commandUtils.js +7 -7
  77. package/lib/commands/deploy.d.ts +4 -1
  78. package/lib/commands/deploy.js +115 -71
  79. package/lib/commands/external.d.ts +2 -2
  80. package/lib/commands/external.js +4 -4
  81. package/lib/commands/serve.d.ts +1 -1
  82. package/lib/commands/serve.js +30 -16
  83. package/lib/commands/start.d.ts +1 -1
  84. package/lib/commands/start.js +100 -89
  85. package/lib/commands/swizzle/actions.d.ts +23 -0
  86. package/lib/commands/swizzle/actions.js +102 -0
  87. package/lib/commands/swizzle/common.d.ts +33 -0
  88. package/lib/commands/swizzle/common.js +57 -0
  89. package/lib/commands/swizzle/components.d.ts +29 -0
  90. package/lib/commands/swizzle/components.js +165 -0
  91. package/lib/commands/swizzle/config.d.ts +10 -0
  92. package/lib/commands/swizzle/config.js +77 -0
  93. package/lib/{client/exports → commands/swizzle}/context.d.ts +2 -4
  94. package/lib/commands/swizzle/context.js +30 -0
  95. package/lib/commands/swizzle/index.d.ts +8 -0
  96. package/lib/commands/swizzle/index.js +115 -0
  97. package/lib/commands/swizzle/prompts.d.ts +12 -0
  98. package/lib/commands/swizzle/prompts.js +110 -0
  99. package/lib/commands/swizzle/tables.d.ts +9 -0
  100. package/lib/commands/swizzle/tables.js +116 -0
  101. package/lib/commands/swizzle/themes.d.ts +20 -0
  102. package/lib/commands/swizzle/themes.js +105 -0
  103. package/lib/commands/writeHeadingIds.d.ts +9 -6
  104. package/lib/commands/writeHeadingIds.js +44 -46
  105. package/lib/commands/writeTranslations.d.ts +2 -2
  106. package/lib/commands/writeTranslations.js +36 -14
  107. package/lib/index.d.ts +10 -9
  108. package/lib/index.js +20 -19
  109. package/lib/server/brokenLinks.d.ts +1 -1
  110. package/lib/server/brokenLinks.js +38 -33
  111. package/lib/server/client-modules/index.d.ts +1 -1
  112. package/lib/server/client-modules/index.js +1 -3
  113. package/lib/server/config.d.ts +2 -2
  114. package/lib/server/config.js +10 -7
  115. package/lib/server/configValidation.d.ts +4 -2
  116. package/lib/server/configValidation.js +63 -32
  117. package/lib/server/duplicateRoutes.d.ts +1 -1
  118. package/lib/server/duplicateRoutes.js +10 -6
  119. package/lib/server/html-tags/htmlTags.js +8 -9
  120. package/lib/server/html-tags/index.d.ts +2 -2
  121. package/lib/server/html-tags/index.js +3 -3
  122. package/lib/server/i18n.d.ts +1 -2
  123. package/lib/server/i18n.js +31 -46
  124. package/lib/server/index.d.ts +9 -2
  125. package/lib/server/index.js +165 -87
  126. package/lib/server/loadSetup.d.ts +2 -3
  127. package/lib/server/loadSetup.js +5 -5
  128. package/lib/server/moduleShorthand.d.ts +9 -0
  129. package/lib/server/moduleShorthand.js +46 -0
  130. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
  131. package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
  132. package/lib/server/plugins/index.d.ts +3 -4
  133. package/lib/server/plugins/index.js +53 -37
  134. package/lib/server/plugins/init.d.ts +11 -5
  135. package/lib/server/plugins/init.js +40 -47
  136. package/lib/server/plugins/pluginIds.d.ts +2 -2
  137. package/lib/server/plugins/pluginIds.js +8 -5
  138. package/lib/server/presets/index.d.ts +3 -3
  139. package/lib/server/presets/index.js +14 -14
  140. package/lib/server/routes.d.ts +1 -1
  141. package/lib/server/routes.js +51 -28
  142. package/lib/server/themes/alias.d.ts +3 -2
  143. package/lib/server/themes/alias.js +24 -15
  144. package/lib/server/themes/index.d.ts +6 -2
  145. package/lib/server/themes/index.js +36 -24
  146. package/lib/server/translations/translations.d.ts +10 -5
  147. package/lib/server/translations/translations.js +27 -35
  148. package/lib/server/translations/translationsExtractor.d.ts +9 -4
  149. package/lib/server/translations/translationsExtractor.js +160 -119
  150. package/lib/server/utils.d.ts +9 -3
  151. package/lib/server/utils.js +8 -10
  152. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  153. package/lib/server/versions/index.d.ts +3 -4
  154. package/lib/server/versions/index.js +22 -21
  155. package/lib/webpack/base.d.ts +4 -4
  156. package/lib/webpack/base.js +54 -38
  157. package/lib/webpack/client.d.ts +3 -3
  158. package/lib/webpack/client.js +15 -21
  159. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  160. package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
  161. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  162. package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
  163. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  164. package/lib/webpack/plugins/LogPlugin.js +5 -6
  165. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  166. package/lib/webpack/plugins/WaitPlugin.js +4 -4
  167. package/lib/webpack/server.d.ts +3 -3
  168. package/lib/webpack/server.js +18 -11
  169. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  170. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  171. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  172. package/lib/webpack/utils.d.ts +9 -30
  173. package/lib/webpack/utils.js +58 -171
  174. package/package.json +76 -69
  175. package/bin/docusaurus.js +0 -326
  176. package/lib/.tsbuildinfo +0 -5732
  177. package/lib/client/.tsbuildinfo +0 -4171
  178. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  179. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  180. package/lib/commands/swizzle.d.ts +0 -9
  181. package/lib/commands/swizzle.js +0 -245
  182. package/lib/constants.d.ts +0 -18
  183. package/lib/constants.js +0 -23
  184. package/lib/server/versions/__tests/index.test.js +0 -25
  185. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  186. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  187. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  188. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  189. package/lib/webpack/sharedModuleAliases.js +0 -18
  190. package/tsconfig.client.json +0 -13
  191. package/tsconfig.json +0 -13
@@ -4,22 +4,27 @@
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
+ import useDocusaurusContext from './useDocusaurusContext';
9
10
  import isInternalUrl from './isInternalUrl';
10
11
  import ExecutionEnvironment from './ExecutionEnvironment';
11
12
  import { useLinksCollector } from '../LinksCollector';
12
13
  import { useBaseUrlUtils } from './useBaseUrl';
14
+ import { applyTrailingSlash } from '@docusaurus/utils-common';
13
15
  // TODO all this wouldn't be necessary if we used ReactRouter basename feature
14
16
  // We don't automatically add base urls to all links,
15
17
  // only the "safe" ones, starting with / (like /docs/introduction)
16
18
  // this is because useBaseUrl() actually transforms relative links
17
19
  // like "introduction" to "/baseUrl/introduction" => bad behavior to fix
18
20
  const shouldAddBaseUrlAutomatically = (to) => to.startsWith('/');
19
- 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) {
20
22
  var _a;
23
+ const { siteConfig: { trailingSlash, baseUrl }, } = useDocusaurusContext();
21
24
  const { withBaseUrl } = useBaseUrlUtils();
22
25
  const linksCollector = useLinksCollector();
26
+ const innerRef = useRef(null);
27
+ useImperativeHandle(forwardedRef, () => innerRef.current);
23
28
  // IMPORTANT: using to or href should not change anything
24
29
  // For example, MDX links will ALWAYS give us the href props
25
30
  // Using one prop or the other should not be used to distinguish
@@ -40,33 +45,37 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
40
45
  const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed === null || targetLinkUnprefixed === void 0 ? void 0 : targetLinkUnprefixed.replace('pathname://', '');
41
46
  // TODO we should use ReactRouter basename feature instead!
42
47
  // Automatically apply base url in links that start with /
43
- const targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
48
+ let targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
44
49
  ? maybeAddBaseUrl(targetLinkWithoutPathnameProtocol)
45
50
  : undefined;
51
+ if (targetLink && isInternal) {
52
+ targetLink = applyTrailingSlash(targetLink, { trailingSlash, baseUrl });
53
+ }
46
54
  const preloaded = useRef(false);
47
- const LinkComponent = isNavLink ? NavLink : RRLink;
55
+ const LinkComponent = (isNavLink ? NavLink : RRLink);
48
56
  const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
49
- let io;
57
+ const ioRef = useRef();
50
58
  const handleIntersection = (el, cb) => {
51
- io = new window.IntersectionObserver((entries) => {
59
+ ioRef.current = new window.IntersectionObserver((entries) => {
52
60
  entries.forEach((entry) => {
53
61
  if (el === entry.target) {
54
- // If element is in viewport, stop listening/observing and run callback.
62
+ // If element is in viewport, stop observing and run callback.
55
63
  // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
56
64
  if (entry.isIntersecting || entry.intersectionRatio > 0) {
57
- io.unobserve(el);
58
- io.disconnect();
65
+ ioRef.current.unobserve(el);
66
+ ioRef.current.disconnect();
59
67
  cb();
60
68
  }
61
69
  }
62
70
  });
63
71
  });
64
72
  // Add element to the observer.
65
- io.observe(el);
73
+ ioRef.current.observe(el);
66
74
  };
67
75
  const handleRef = (ref) => {
76
+ innerRef.current = ref;
68
77
  if (IOSupported && ref && isInternal) {
69
- // If IO supported and element reference found, setup Observer functionality.
78
+ // If IO supported and element reference found, set up Observer.
70
79
  handleIntersection(ref, () => {
71
80
  if (targetLink != null) {
72
81
  window.docusaurus.prefetch(targetLink);
@@ -89,11 +98,11 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
89
98
  }
90
99
  // When unmounting, stop intersection observer from watching.
91
100
  return () => {
92
- if (IOSupported && io) {
93
- io.disconnect();
101
+ if (IOSupported && ioRef.current) {
102
+ ioRef.current.disconnect();
94
103
  }
95
104
  };
96
- }, [targetLink, IOSupported, isInternal]);
105
+ }, [ioRef, targetLink, IOSupported, isInternal]);
97
106
  const isAnchorLink = (_a = targetLink === null || targetLink === void 0 ? void 0 : targetLink.startsWith('#')) !== null && _a !== void 0 ? _a : false;
98
107
  const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink;
99
108
  if (targetLink && isInternal && !isAnchorLink && !noBrokenLinkCheck) {
@@ -101,7 +110,10 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
101
110
  }
102
111
  return isRegularHtmlLink ? (
103
112
  // eslint-disable-next-line jsx-a11y/anchor-has-content
104
- React.createElement("a", Object.assign({ href: targetLink }, (targetLinkUnprefixed &&
105
- !isInternal && { target: '_blank', rel: 'noopener noreferrer' }), props))) : (React.createElement(LinkComponent, Object.assign({}, props, { onMouseEnter: onMouseEnter, innerRef: handleRef, to: targetLink || '' }, (isNavLink && { isActive, activeClassName }))));
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 })}/>);
106
118
  }
107
- export default Link;
119
+ 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
- /// <reference types="react" />
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>): JSX.Element;
12
+ export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>): ReactNode;
@@ -4,26 +4,31 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React from 'react';
8
- import 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
- var _a;
13
- return (_a = codeTranslations[id !== null && id !== void 0 ? id : message]) !== null && _a !== void 0 ? _a : message;
11
+ var _a, _b;
12
+ if (typeof id === 'undefined' && typeof message === 'undefined') {
13
+ throw new Error('Docusaurus translation declarations must have at least a translation id or a default translation message');
14
+ }
15
+ return (_b = (_a = codeTranslations[(id !== null && id !== void 0 ? id : message)]) !== null && _a !== void 0 ? _a : message) !== null && _b !== void 0 ? _b : id;
14
16
  }
15
17
  // Imperative translation API is useful for some edge-cases:
16
18
  // - translating page titles (meta)
17
19
  // - translating string props (input placeholders, image alt, aria labels...)
18
20
  export function translate({ message, id }, values) {
19
- var _a;
20
- const localizedMessage = (_a = getLocalizedMessage({ message, id })) !== null && _a !== void 0 ? _a : message;
21
+ const localizedMessage = getLocalizedMessage({ message, id });
21
22
  return interpolate(localizedMessage, values);
22
23
  }
23
24
  // Maybe we'll want to improve this component with additional features
24
- // Like toggling a translation mode that adds a little translation button near the text?
25
+ // Like toggling a translation mode that adds a little translation button near
26
+ // the text?
25
27
  export default function Translate({ children, id, values, }) {
26
- var _a;
27
- const localizedMessage = (_a = getLocalizedMessage({ message: children, id })) !== null && _a !== void 0 ? _a : children;
28
- return React.createElement(Interpolate, { values: values }, localizedMessage);
28
+ if (children && typeof children !== 'string') {
29
+ console.warn('Illegal <Translate> children', children);
30
+ throw new Error('The Docusaurus <Translate> component only accept simple string values');
31
+ }
32
+ const localizedMessage = getLocalizedMessage({ message: children, id });
33
+ return interpolate(localizedMessage, values);
29
34
  }
@@ -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 /^(\w*:|\/\/)/.test(url) === true;
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
- import { renderRoutes } from 'react-router-config';
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
- import { renderRoutes } from 'react-router-config';
8
- export default renderRoutes;
7
+ export { renderRoutes as default } from 'react-router-config';
@@ -4,4 +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
- export * from 'react-router-dom';
7
+ export { useHistory, useLocation, Redirect, matchPath } from 'react-router-dom';
@@ -4,4 +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
- export * from 'react-router-dom';
7
+ export { useHistory, useLocation, Redirect, matchPath } from 'react-router-dom';
@@ -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 = '/', url: siteUrl } = {}, } = useDocusaurusContext();
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
- declare function useDocusaurusContext(): DocusaurusContext;
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 context from './context';
9
- function useDocusaurusContext() {
10
- const docusaurusContext = useContext(context);
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,15 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import useDocusaurusContext from './useDocusaurusContext';
8
- // TODO annoying constant duplication
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) {
16
- throw new Error('Docusaurus global data not found');
12
+ throw new Error('Docusaurus global data not found.');
17
13
  }
18
14
  return globalData;
19
15
  }
@@ -21,7 +17,7 @@ export function useAllPluginInstancesData(pluginName) {
21
17
  const globalData = useGlobalData();
22
18
  const pluginGlobalData = globalData[pluginName];
23
19
  if (!pluginGlobalData) {
24
- throw new Error(`Docusaurus plugin global data not found for pluginName=${pluginName}`);
20
+ throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin.`);
25
21
  }
26
22
  return pluginGlobalData;
27
23
  }
@@ -29,7 +25,7 @@ export function usePluginData(pluginName, pluginId = DEFAULT_PLUGIN_ID) {
29
25
  const pluginGlobalData = useAllPluginInstancesData(pluginName);
30
26
  const pluginInstanceGlobalData = pluginGlobalData[pluginId];
31
27
  if (!pluginInstanceGlobalData) {
32
- throw new Error(`Docusaurus plugin global data not found for pluginName=${pluginName} and pluginId=${pluginId}`);
28
+ throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin with id "${pluginId}".`);
33
29
  }
34
30
  return pluginInstanceGlobalData;
35
31
  }
@@ -4,4 +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
- export {};
7
+ export default function useIsBrowser(): boolean;
@@ -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
+ }
@@ -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
- declare function flat(target: unknown): Record<string, any>;
8
- export default flat;
7
+ import type { RouteChunksTree } from '@docusaurus/types';
8
+ export default function flat(target: RouteChunksTree): Record<string, string>;
@@ -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
- // Too dynamic
8
- /* eslint-disable @typescript-eslint/no-explicit-any */
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, prev) {
11
+ function step(object, prefix) {
13
12
  Object.keys(object).forEach((key) => {
14
13
  const value = object[key];
15
- const type = typeof value;
16
- const isObject = type === 'object' && !!value;
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
- output[newKey] = value;
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
- declare type Location = {
8
- pathname: string;
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;
@@ -27,10 +27,10 @@
27
27
 
28
28
  #nprogress .peg {
29
29
  position: absolute;
30
- right: 0px;
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(0px, -4px);
35
+ transform: rotate(3deg) translate(0, -4px);
36
36
  }
@@ -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
- declare function prefetch(url: string): Promise<void>;
8
- export default prefetch;
7
+ export default function prefetch(url: string): Promise<void>;
@@ -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;
@@ -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 screens.
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
@@ -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 screens.
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>;