@docusaurus/core 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21

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 (222) hide show
  1. package/bin/beforeCli.mjs +140 -0
  2. package/bin/docusaurus.mjs +236 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +10 -8
  5. package/lib/client/.eslintrc.js +2 -4
  6. package/lib/client/App.d.ts +2 -3
  7. package/lib/client/App.js +31 -28
  8. package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
  9. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +24 -14
  10. package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
  11. package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
  12. package/lib/client/ClientLifecyclesDispatcher.js +39 -0
  13. package/lib/client/LinksCollector.d.ts +3 -3
  14. package/lib/client/LinksCollector.js +8 -13
  15. package/lib/client/PendingNavigation.d.ts +17 -3
  16. package/lib/client/PendingNavigation.js +41 -72
  17. package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
  18. package/lib/client/SiteMetadataDefaults.js +21 -0
  19. package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
  20. package/lib/client/browserContext.js +22 -0
  21. package/lib/client/clientEntry.js +14 -9
  22. package/lib/client/docusaurus.d.ts +12 -6
  23. package/lib/client/docusaurus.js +30 -43
  24. package/lib/client/docusaurusContext.d.ts +12 -0
  25. package/lib/client/docusaurusContext.js +25 -0
  26. package/lib/client/exports/BrowserOnly.d.ts +3 -5
  27. package/lib/client/exports/BrowserOnly.js +14 -8
  28. package/lib/client/exports/ComponentCreator.d.ts +6 -2
  29. package/lib/client/exports/ComponentCreator.js +75 -42
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +36 -0
  32. package/lib/client/exports/Head.d.ts +2 -3
  33. package/lib/client/exports/Head.js +3 -4
  34. package/lib/client/exports/Interpolate.d.ts +2 -2
  35. package/lib/client/exports/Interpolate.js +20 -49
  36. package/lib/client/exports/Link.d.ts +4 -10
  37. package/lib/client/exports/Link.js +38 -38
  38. package/lib/client/exports/Translate.d.ts +1 -1
  39. package/lib/client/exports/Translate.js +14 -9
  40. package/lib/client/exports/constants.js +1 -11
  41. package/lib/client/exports/isInternalUrl.js +1 -1
  42. package/lib/client/exports/renderRoutes.d.ts +1 -2
  43. package/lib/client/exports/renderRoutes.js +1 -2
  44. package/lib/client/exports/router.d.ts +1 -1
  45. package/lib/client/exports/router.js +1 -1
  46. package/lib/client/exports/useBaseUrl.js +11 -14
  47. package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
  48. package/lib/client/exports/useDocusaurusContext.js +3 -9
  49. package/lib/client/exports/useGlobalData.d.ts +4 -3
  50. package/lib/client/exports/useGlobalData.js +6 -13
  51. package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
  52. package/lib/client/exports/useIsBrowser.js +11 -0
  53. package/lib/client/exports/useRouteContext.d.ts +8 -0
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +12 -2
  56. package/lib/client/flat.js +19 -15
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +14 -10
  59. package/lib/client/prefetch.d.ts +1 -2
  60. package/lib/client/prefetch.js +12 -32
  61. package/lib/client/preload.d.ts +3 -4
  62. package/lib/client/preload.js +5 -12
  63. package/lib/client/routeContext.d.ts +13 -0
  64. package/lib/client/routeContext.js +31 -0
  65. package/lib/client/serverEntry.d.ts +10 -0
  66. package/lib/client/serverEntry.js +105 -146
  67. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  68. package/lib/client/theme-fallback/Error/index.js +45 -0
  69. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  70. package/lib/client/theme-fallback/Layout/index.js +2 -26
  71. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  72. package/lib/client/theme-fallback/Loading/index.js +50 -116
  73. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  74. package/lib/client/theme-fallback/NotFound/index.js +19 -18
  75. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  76. package/lib/client/theme-fallback/Root/index.js +2 -6
  77. package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
  78. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  79. package/lib/commands/build.d.ts +6 -2
  80. package/lib/commands/build.js +80 -64
  81. package/lib/commands/clear.d.ts +7 -1
  82. package/lib/commands/clear.js +32 -20
  83. package/lib/commands/deploy.d.ts +5 -2
  84. package/lib/commands/deploy.js +93 -81
  85. package/lib/commands/external.d.ts +2 -2
  86. package/lib/commands/external.js +6 -11
  87. package/lib/commands/serve.d.ts +8 -2
  88. package/lib/commands/serve.js +26 -27
  89. package/lib/commands/start.d.ts +9 -2
  90. package/lib/commands/start.js +106 -92
  91. package/lib/commands/swizzle/actions.d.ts +23 -0
  92. package/lib/commands/swizzle/actions.js +100 -0
  93. package/lib/commands/swizzle/common.d.ts +33 -0
  94. package/lib/commands/swizzle/common.js +56 -0
  95. package/lib/commands/swizzle/components.d.ts +29 -0
  96. package/lib/commands/swizzle/components.js +200 -0
  97. package/lib/commands/swizzle/config.d.ts +10 -0
  98. package/lib/commands/swizzle/config.js +84 -0
  99. package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
  100. package/lib/commands/swizzle/context.js +24 -0
  101. package/lib/commands/swizzle/index.d.ts +8 -0
  102. package/lib/commands/swizzle/index.js +116 -0
  103. package/lib/commands/swizzle/prompts.d.ts +12 -0
  104. package/lib/commands/swizzle/prompts.js +110 -0
  105. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  106. package/lib/commands/swizzle/tables.js +113 -0
  107. package/lib/commands/swizzle/themes.d.ts +20 -0
  108. package/lib/commands/swizzle/themes.js +106 -0
  109. package/lib/commands/writeHeadingIds.d.ts +2 -6
  110. package/lib/commands/writeHeadingIds.js +21 -81
  111. package/lib/commands/writeTranslations.d.ts +4 -5
  112. package/lib/commands/writeTranslations.js +39 -20
  113. package/lib/index.d.ts +9 -9
  114. package/lib/index.js +14 -14
  115. package/lib/server/brokenLinks.d.ts +4 -17
  116. package/lib/server/brokenLinks.js +67 -56
  117. package/lib/server/clientModules.d.ts +12 -0
  118. package/lib/server/clientModules.js +20 -0
  119. package/lib/server/config.d.ts +5 -2
  120. package/lib/server/config.js +29 -6
  121. package/lib/server/configValidation.d.ts +4 -4
  122. package/lib/server/configValidation.js +80 -38
  123. package/lib/server/getHostPort.d.ts +14 -0
  124. package/lib/server/getHostPort.js +79 -0
  125. package/lib/server/htmlTags.d.ts +12 -0
  126. package/lib/server/htmlTags.js +62 -0
  127. package/lib/server/i18n.d.ts +3 -13
  128. package/lib/server/i18n.js +19 -55
  129. package/lib/server/index.d.ts +28 -13
  130. package/lib/server/index.js +79 -163
  131. package/lib/server/plugins/configs.d.ts +51 -0
  132. package/lib/server/plugins/configs.js +101 -0
  133. package/lib/server/plugins/index.d.ts +9 -8
  134. package/lib/server/plugins/index.js +72 -135
  135. package/lib/server/plugins/init.d.ts +6 -5
  136. package/lib/server/plugins/init.js +44 -109
  137. package/lib/server/plugins/moduleShorthand.d.ts +9 -0
  138. package/lib/server/plugins/moduleShorthand.js +46 -0
  139. package/lib/server/plugins/pluginIds.d.ts +5 -1
  140. package/lib/server/plugins/pluginIds.js +12 -7
  141. package/lib/server/plugins/presets.d.ts +12 -0
  142. package/lib/server/plugins/presets.js +49 -0
  143. package/lib/server/plugins/routeConfig.d.ts +11 -0
  144. package/lib/server/plugins/routeConfig.js +54 -0
  145. package/lib/server/plugins/synthetic.d.ts +20 -0
  146. package/lib/server/plugins/synthetic.js +112 -0
  147. package/lib/server/routes.d.ts +39 -7
  148. package/lib/server/routes.js +185 -95
  149. package/lib/server/siteMetadata.d.ts +12 -0
  150. package/lib/server/siteMetadata.js +81 -0
  151. package/lib/server/translations/translations.d.ts +11 -14
  152. package/lib/server/translations/translations.js +36 -60
  153. package/lib/server/translations/translationsExtractor.d.ts +10 -4
  154. package/lib/server/translations/translationsExtractor.js +158 -122
  155. package/lib/server/utils.d.ts +9 -3
  156. package/lib/server/utils.js +7 -9
  157. package/lib/webpack/aliases/index.d.ts +34 -0
  158. package/lib/webpack/aliases/index.js +106 -0
  159. package/lib/webpack/base.d.ts +3 -4
  160. package/lib/webpack/base.js +45 -57
  161. package/lib/webpack/client.d.ts +3 -3
  162. package/lib/webpack/client.js +12 -19
  163. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  164. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  165. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
  166. package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
  167. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  168. package/lib/webpack/plugins/LogPlugin.js +4 -5
  169. package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
  170. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  171. package/lib/webpack/server.d.ts +5 -5
  172. package/lib/webpack/server.js +16 -12
  173. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  174. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  175. package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
  176. package/lib/webpack/utils.d.ts +15 -31
  177. package/lib/webpack/utils.js +61 -182
  178. package/package.json +82 -77
  179. package/bin/docusaurus.js +0 -325
  180. package/lib/.tsbuildinfo +0 -1
  181. package/lib/choosePort.js +0 -105
  182. package/lib/client/.tsbuildinfo +0 -1
  183. package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
  184. package/lib/client/client-lifecycles-dispatcher.js +0 -27
  185. package/lib/client/nprogress.css +0 -36
  186. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  187. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  188. package/lib/commands/commandUtils.d.ts +0 -3
  189. package/lib/commands/commandUtils.js +0 -21
  190. package/lib/commands/swizzle.d.ts +0 -9
  191. package/lib/commands/swizzle.js +0 -245
  192. package/lib/constants.d.ts +0 -18
  193. package/lib/constants.js +0 -23
  194. package/lib/server/client-modules/index.js +0 -14
  195. package/lib/server/duplicateRoutes.d.ts +0 -10
  196. package/lib/server/duplicateRoutes.js +0 -38
  197. package/lib/server/html-tags/htmlTags.js +0 -40
  198. package/lib/server/html-tags/index.d.ts +0 -9
  199. package/lib/server/html-tags/index.js +0 -43
  200. package/lib/server/loadSetup.d.ts +0 -9
  201. package/lib/server/loadSetup.js +0 -25
  202. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
  203. package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
  204. package/lib/server/presets/index.d.ts +0 -11
  205. package/lib/server/presets/index.js +0 -48
  206. package/lib/server/themes/alias.d.ts +0 -8
  207. package/lib/server/themes/alias.js +0 -40
  208. package/lib/server/themes/index.d.ts +0 -12
  209. package/lib/server/themes/index.js +0 -47
  210. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  211. package/lib/server/versions/__fixtures__/package.json +0 -3
  212. package/lib/server/versions/__tests/index.test.js +0 -25
  213. package/lib/server/versions/index.d.ts +0 -10
  214. package/lib/server/versions/index.js +0 -50
  215. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  216. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  217. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  218. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  219. package/lib/webpack/sharedModuleAliases.d.ts +0 -10
  220. package/lib/webpack/sharedModuleAliases.js +0 -18
  221. package/tsconfig.client.json +0 -13
  222. package/tsconfig.json +0 -13
@@ -6,72 +6,105 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import Loadable from 'react-loadable';
9
- import Loading from '@theme/Loading';
10
9
  import routesChunkNames from '@generated/routesChunkNames';
11
10
  import registry from '@generated/registry';
11
+ import Loading from '@theme/Loading';
12
12
  import flat from '../flat';
13
- function ComponentCreator(path, hash) {
13
+ import { RouteContextProvider } from '../routeContext';
14
+ export default function ComponentCreator(path, hash) {
14
15
  // 404 page
15
16
  if (path === '*') {
16
17
  return Loadable({
17
18
  loading: Loading,
18
19
  loader: () => import('@theme/NotFound'),
20
+ modules: ['@theme/NotFound'],
21
+ webpack: () => [require.resolveWeak('@theme/NotFound')],
22
+ render(loaded, props) {
23
+ const NotFound = loaded.default;
24
+ return (<RouteContextProvider
25
+ // Do we want a better name than native-default?
26
+ value={{ plugin: { name: 'native', id: 'default' } }}>
27
+ <NotFound {...props}/>
28
+ </RouteContextProvider>);
29
+ },
19
30
  });
20
31
  }
21
- const chunkNamesKey = `${path}-${hash}`;
22
- const chunkNames = routesChunkNames[chunkNamesKey];
23
- const optsModules = [];
32
+ const chunkNames = routesChunkNames[`${path}-${hash}`];
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const loader = {};
35
+ const modules = [];
24
36
  const optsWebpack = [];
25
- const optsLoader = {};
26
- /* Prepare opts data that react-loadable needs
27
- https://github.com/jamiebuilds/react-loadable#declaring-which-modules-are-being-loaded
28
- Example:
29
- - optsLoader:
30
- {
31
- component: () => import('./Pages.js'),
32
- content.foo: () => import('./doc1.md'),
33
- }
34
- - optsModules: ['./Pages.js', './doc1.md']
35
- - optsWebpack: [require.resolveWeak('./Pages.js'), require.resolveWeak('./doc1.md')]
36
- */
37
+ // A map from prop names to chunk names.
38
+ // e.g. Suppose the plugin added this as route:
39
+ // { __comp: "...", prop: { foo: "..." }, items: ["...", "..."] }
40
+ // It will become:
41
+ // { __comp: "...", "prop.foo": "...", "items.0": "...", "items.1": ... }
42
+ // Loadable.Map will _map_ over `loader` and load each key.
37
43
  const flatChunkNames = flat(chunkNames);
38
- Object.keys(flatChunkNames).forEach((key) => {
39
- const chunkRegistry = registry[flatChunkNames[key]];
44
+ Object.entries(flatChunkNames).forEach(([keyPath, chunkName]) => {
45
+ const chunkRegistry = registry[chunkName];
40
46
  if (chunkRegistry) {
41
- /* eslint-disable prefer-destructuring */
42
- optsLoader[key] = chunkRegistry[0];
43
- optsModules.push(chunkRegistry[1]);
47
+ // eslint-disable-next-line prefer-destructuring
48
+ loader[keyPath] = chunkRegistry[0];
49
+ modules.push(chunkRegistry[1]);
44
50
  optsWebpack.push(chunkRegistry[2]);
45
- /* eslint-enable prefer-destructuring */
46
51
  }
47
52
  });
48
53
  return Loadable.Map({
49
54
  loading: Loading,
50
- loader: optsLoader,
51
- modules: optsModules,
55
+ loader,
56
+ modules,
52
57
  webpack: () => optsWebpack,
53
- render: (loaded, props) => {
54
- // Clone the original object since we don't want to alter the original.
58
+ render(loaded, props) {
59
+ // `loaded` will be a map from key path (as returned from the flattened
60
+ // chunk names) to the modules loaded from the loaders. We now have to
61
+ // restore the chunk names' previous shape from this flat record.
62
+ // We do so by taking advantage of the existing `chunkNames` and replacing
63
+ // each chunk name with its loaded module, so we don't create another
64
+ // object from scratch.
55
65
  const loadedModules = JSON.parse(JSON.stringify(chunkNames));
56
- Object.keys(loaded).forEach((key) => {
57
- let val = loadedModules;
58
- const keyPath = key.split('.');
59
- for (let i = 0; i < keyPath.length - 1; i += 1) {
60
- val = val[keyPath[i]];
66
+ Object.entries(loaded).forEach(([keyPath, loadedModule]) => {
67
+ // JSON modules are also loaded as `{ default: ... }` (`import()`
68
+ // semantics) but we just want to pass the actual value to props.
69
+ const chunk = loadedModule.default;
70
+ // One loaded chunk can only be one of two things: a module (props) or a
71
+ // component. Modules are always JSON, so `default` always exists. This
72
+ // could only happen with a user-defined component.
73
+ if (!chunk) {
74
+ throw new Error(`The page component at ${path} doesn't have a default export. This makes it impossible to render anything. Consider default-exporting a React component.`);
61
75
  }
62
- val[keyPath[keyPath.length - 1]] = loaded[key].default;
63
- const nonDefaultKeys = Object.keys(loaded[key]).filter((k) => k !== 'default');
64
- if (nonDefaultKeys && nonDefaultKeys.length) {
65
- nonDefaultKeys.forEach((nonDefaultKey) => {
66
- val[keyPath[keyPath.length - 1]][nonDefaultKey] =
67
- loaded[key][nonDefaultKey];
76
+ // A module can be a primitive, for example, if the user stored a string
77
+ // as a prop. However, there seems to be a bug with swc-loader's CJS
78
+ // logic, in that it would load a JSON module with content "foo" as
79
+ // `{ default: "foo", 0: "f", 1: "o", 2: "o" }`. Just to be safe, we
80
+ // first make sure that the chunk is non-primitive.
81
+ if (typeof chunk === 'object' || typeof chunk === 'function') {
82
+ Object.keys(loadedModule)
83
+ .filter((k) => k !== 'default')
84
+ .forEach((nonDefaultKey) => {
85
+ chunk[nonDefaultKey] =
86
+ loadedModule[nonDefaultKey];
68
87
  });
69
88
  }
89
+ // We now have this chunk prepared. Go down the key path and replace the
90
+ // chunk name with the actual chunk.
91
+ let val = loadedModules;
92
+ const keyPaths = keyPath.split('.');
93
+ keyPaths.slice(0, -1).forEach((k) => {
94
+ val = val[k];
95
+ });
96
+ val[keyPaths[keyPaths.length - 1]] = chunk;
70
97
  });
71
- const Component = loadedModules.component;
72
- delete loadedModules.component;
73
- return React.createElement(Component, { ...loadedModules, ...props });
98
+ /* eslint-disable no-underscore-dangle */
99
+ const Component = loadedModules.__comp;
100
+ delete loadedModules.__comp;
101
+ const routeContext = loadedModules.__context;
102
+ delete loadedModules.__context;
103
+ /* eslint-enable no-underscore-dangle */
104
+ // Is there any way to put this RouteContextProvider upper in the tree?
105
+ return (<RouteContextProvider value={routeContext}>
106
+ <Component {...loadedModules} {...props}/>
107
+ </RouteContextProvider>);
74
108
  },
75
109
  });
76
110
  }
77
- export default ComponentCreator;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /// <reference types="@docusaurus/module-type-aliases" />
8
+ import React, { type ReactNode } from 'react';
9
+ import type { Props } from '@docusaurus/ErrorBoundary';
10
+ declare type State = {
11
+ error: Error | null;
12
+ };
13
+ export default class ErrorBoundary extends React.Component<Props, State> {
14
+ constructor(props: Props);
15
+ componentDidCatch(error: Error): void;
16
+ render(): ReactNode;
17
+ }
18
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
+ import ThemeError from '@theme/Error';
10
+ const DefaultFallback = (params) => (<ThemeError {...params}/>);
11
+ export default class ErrorBoundary extends React.Component {
12
+ constructor(props) {
13
+ super(props);
14
+ this.state = { error: null };
15
+ }
16
+ componentDidCatch(error) {
17
+ // Catch errors in any components below and re-render with error message
18
+ if (ExecutionEnvironment.canUseDOM) {
19
+ this.setState({ error });
20
+ }
21
+ }
22
+ render() {
23
+ const { children } = this.props;
24
+ const { error } = this.state;
25
+ if (error) {
26
+ const fallbackParams = {
27
+ error,
28
+ tryAgain: () => this.setState({ error: null }),
29
+ };
30
+ const fallback = this.props.fallback ?? DefaultFallback;
31
+ return fallback(fallbackParams);
32
+ }
33
+ // See https://github.com/facebook/docusaurus/issues/6337#issuecomment-1012913647
34
+ return children ?? null;
35
+ }
36
+ }
@@ -6,6 +6,5 @@
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
8
  /// <reference types="react" />
9
- import type { HeadProps } from '@docusaurus/Head';
10
- declare function Head(props: HeadProps): JSX.Element;
11
- export default Head;
9
+ import type { Props } from '@docusaurus/Head';
10
+ export default function Head(props: Props): JSX.Element;
@@ -5,8 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import { Helmet } from 'react-helmet';
9
- function Head(props) {
10
- return React.createElement(Helmet, { ...props });
8
+ import { Helmet } from 'react-helmet-async';
9
+ export default function Head(props) {
10
+ return <Helmet {...props}/>;
11
11
  }
12
- export default Head;
@@ -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
- import { ReactNode } from 'react';
8
+ import { type ReactNode } from 'react';
9
9
  import type { InterpolateProps, InterpolateValues } from '@docusaurus/Interpolate';
10
10
  export declare function interpolate<Str extends string>(text: Str, values?: InterpolateValues<Str, string | number>): string;
11
11
  export declare function interpolate<Str extends string, Value extends ReactNode>(text: Str, values?: InterpolateValues<Str, Value>): ReactNode;
12
- export default function Interpolate<Str extends string>({ children, values, }: InterpolateProps<Str>): ReactNode;
12
+ export default function Interpolate<Str extends string>({ children, values, }: InterpolateProps<Str>): JSX.Element;
@@ -4,59 +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 React from 'react';
8
- /*
9
- Minimal implementation of a React interpolate component.
10
- We don't ship a markdown parser nor a feature-complete i18n library on purpose.
11
- More details here: https://github.com/facebook/docusaurus/pull/4295
12
- */
13
- const ValueRegexp = /{\w+}/g;
14
- const ValueFoundMarker = '{}'; // does not care much
7
+ import React, { isValidElement } from 'react';
15
8
  export function interpolate(text, values) {
16
- const elements = [];
17
- const processedText = text.replace(ValueRegexp, (match) => {
18
- // remove {{ and }} around the placeholder
19
- const key = match.substr(1, match.length - 2);
20
- const value = values === null || values === void 0 ? void 0 : values[key];
21
- if (typeof value !== 'undefined') {
22
- const element = React.isValidElement(value)
23
- ? value
24
- : // For non-React elements: basic primitive->string conversion
25
- String(value);
26
- elements.push(element);
27
- return ValueFoundMarker;
28
- }
29
- else {
30
- return match; // no match? add warning?
9
+ // eslint-disable-next-line prefer-named-capture-group
10
+ const segments = text.split(/(\{\w+\})/).map((seg, index) => {
11
+ // Odd indices (1, 3, 5...) of the segments are (potentially) interpolatable
12
+ if (index % 2 === 1) {
13
+ const value = values?.[seg.slice(1, -1)];
14
+ if (value !== undefined) {
15
+ return value;
16
+ }
17
+ // No match: add warning? There's no way to "escape" interpolation though
31
18
  }
19
+ return seg;
32
20
  });
33
- // No interpolation to be done: just return the text
34
- if (elements.length === 0) {
35
- return text;
36
- }
37
- // Basic string interpolation: returns interpolated string
38
- else if (elements.every((el) => typeof el === 'string')) {
39
- return processedText
40
- .split(ValueFoundMarker)
41
- .reduce((str, value, index) => {
42
- var _a;
43
- return str.concat(value).concat((_a = elements[index]) !== null && _a !== void 0 ? _a : '');
44
- }, '');
45
- }
46
- // JSX interpolation: returns ReactNode
47
- else {
48
- return processedText
49
- .split(ValueFoundMarker)
50
- .reduce((array, value, index) => {
51
- return [
52
- ...array,
53
- React.createElement(React.Fragment, { key: index },
54
- value,
55
- elements[index]),
56
- ];
57
- }, []);
21
+ if (segments.some((seg) => isValidElement(seg))) {
22
+ return segments
23
+ .map((seg, index) => isValidElement(seg) ? React.cloneElement(seg, { key: index }) : seg)
24
+ .filter((seg) => seg !== '');
58
25
  }
26
+ return segments.join('');
59
27
  }
60
28
  export default function Interpolate({ children, values, }) {
61
- return interpolate(children, values);
29
+ if (typeof children !== 'string') {
30
+ throw new Error(`The Docusaurus <Interpolate> component only accept simple string values. Received: ${isValidElement(children) ? 'React element' : typeof children}`);
31
+ }
32
+ return <>{interpolate(children, values)}</>;
62
33
  }
@@ -5,13 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
- /// <reference types="react" />
9
- import type { LinkProps } from '@docusaurus/Link';
10
- import type docusaurus from '../docusaurus';
11
- declare global {
12
- interface Window {
13
- docusaurus: typeof docusaurus;
14
- }
15
- }
16
- declare function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl, ...props }: LinkProps): JSX.Element;
17
- export default Link;
8
+ import React from 'react';
9
+ import type { Props } from '@docusaurus/Link';
10
+ declare const _default: React.ForwardRefExoticComponent<Pick<Props, "location" | "children" | "replace" | "slot" | "style" | "title" | "component" | "exact" | "sensitive" | "strict" | "type" | "key" | "id" | "lang" | "dir" | "property" | "rel" | "href" | "isNavLink" | "className" | "to" | "innerRef" | "download" | "hrefLang" | "media" | "ping" | "target" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "activeClassName" | "activeStyle" | "isActive" | "data-noBrokenLinkCheck" | "autoAddBaseUrl"> & React.RefAttributes<HTMLAnchorElement>>;
11
+ export default _default;
@@ -4,25 +4,26 @@
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 { applyTrailingSlash } from '@docusaurus/utils-common';
9
10
  import useDocusaurusContext from './useDocusaurusContext';
10
11
  import isInternalUrl from './isInternalUrl';
11
12
  import ExecutionEnvironment from './ExecutionEnvironment';
12
13
  import { useLinksCollector } from '../LinksCollector';
13
14
  import { useBaseUrlUtils } from './useBaseUrl';
14
- import { applyTrailingSlash } from '@docusaurus/utils-common';
15
15
  // TODO all this wouldn't be necessary if we used ReactRouter basename feature
16
16
  // We don't automatically add base urls to all links,
17
17
  // only the "safe" ones, starting with / (like /docs/introduction)
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 === null || targetLinkUnprefixed === void 0 ? void 0 : targetLinkUnprefixed.replace('pathname://', '');
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,34 +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
- let io;
56
- const handleIntersection = (el, cb) => {
57
- io = new window.IntersectionObserver((entries) => {
58
- entries.forEach((entry) => {
59
- if (el === entry.target) {
60
- // If element is in viewport, stop listening/observing and run callback.
61
- // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
62
- if (entry.isIntersecting || entry.intersectionRatio > 0) {
63
- io.unobserve(el);
64
- io.disconnect();
65
- cb();
56
+ const ioRef = useRef();
57
+ const handleRef = (el) => {
58
+ innerRef.current = el;
59
+ if (IOSupported && el && isInternal) {
60
+ // If IO supported and element reference found, set up Observer.
61
+ ioRef.current = new window.IntersectionObserver((entries) => {
62
+ entries.forEach((entry) => {
63
+ if (el === entry.target) {
64
+ // If element is in viewport, stop observing and run callback.
65
+ // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
66
+ if (entry.isIntersecting || entry.intersectionRatio > 0) {
67
+ ioRef.current.unobserve(el);
68
+ ioRef.current.disconnect();
69
+ if (targetLink != null) {
70
+ window.docusaurus.prefetch(targetLink);
71
+ }
72
+ }
66
73
  }
67
- }
68
- });
69
- });
70
- // Add element to the observer.
71
- io.observe(el);
72
- };
73
- const handleRef = (ref) => {
74
- if (IOSupported && ref && isInternal) {
75
- // If IO supported and element reference found, setup Observer functionality.
76
- handleIntersection(ref, () => {
77
- if (targetLink != null) {
78
- window.docusaurus.prefetch(targetLink);
79
- }
74
+ });
80
75
  });
76
+ // Add element to the observer.
77
+ ioRef.current.observe(el);
81
78
  }
82
79
  };
83
80
  const onMouseEnter = () => {
@@ -95,19 +92,22 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
95
92
  }
96
93
  // When unmounting, stop intersection observer from watching.
97
94
  return () => {
98
- if (IOSupported && io) {
99
- io.disconnect();
95
+ if (IOSupported && ioRef.current) {
96
+ ioRef.current.disconnect();
100
97
  }
101
98
  };
102
- }, [targetLink, IOSupported, isInternal]);
103
- const isAnchorLink = (_a = targetLink === null || targetLink === void 0 ? void 0 : targetLink.startsWith('#')) !== null && _a !== void 0 ? _a : false;
99
+ }, [ioRef, targetLink, IOSupported, isInternal]);
100
+ const isAnchorLink = targetLink?.startsWith('#') ?? false;
104
101
  const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink;
105
- if (targetLink && isInternal && !isAnchorLink && !noBrokenLinkCheck) {
102
+ if (!isRegularHtmlLink && !noBrokenLinkCheck) {
106
103
  linksCollector.collectLink(targetLink);
107
104
  }
108
105
  return isRegularHtmlLink ? (
109
106
  // eslint-disable-next-line jsx-a11y/anchor-has-content
110
- React.createElement("a", { href: targetLink, ...(targetLinkUnprefixed &&
111
- !isInternal && { target: '_blank', rel: 'noopener noreferrer' }), ...props })) : (React.createElement(LinkComponent, { ...props, onMouseEnter: onMouseEnter, innerRef: handleRef, to: targetLink || '', ...(isNavLink && { isActive, activeClassName }) }));
107
+ <a ref={innerRef} href={targetLink} {...(targetLinkUnprefixed &&
108
+ !isInternal && { target: '_blank', rel: 'noopener noreferrer' })} {...props}/>) : (<LinkComponent {...props} onMouseEnter={onMouseEnter} innerRef={handleRef} to={targetLink}
109
+ // Avoid "React does not recognize the `activeClassName` prop on a DOM
110
+ // element"
111
+ {...(isNavLink && { isActive, activeClassName })}/>);
112
112
  }
113
- export default Link;
113
+ export default React.forwardRef(Link);
@@ -6,7 +6,7 @@
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
8
  /// <reference types="react" />
9
- import { InterpolateValues } from '@docusaurus/Interpolate';
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
12
  export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>): JSX.Element;
@@ -5,25 +5,30 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import Interpolate, { interpolate, } from '@docusaurus/Interpolate';
8
+ import { interpolate } from '@docusaurus/Interpolate';
9
9
  // Can't read it from context, due to exposing imperative API
10
10
  import codeTranslations from '@generated/codeTranslations';
11
11
  function getLocalizedMessage({ id, message, }) {
12
- var _a;
13
- return (_a = codeTranslations[id !== null && id !== void 0 ? id : message]) !== null && _a !== void 0 ? _a : message;
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 codeTranslations[(id ?? message)] ?? message ?? 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
  }
@@ -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';
@@ -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);
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';