@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18

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 (200) hide show
  1. package/bin/beforeCli.mjs +133 -0
  2. package/bin/docusaurus.mjs +279 -0
  3. package/lib/babel/preset.d.ts +8 -3
  4. package/lib/babel/preset.js +8 -7
  5. package/lib/choosePort.js +31 -43
  6. package/lib/client/.eslintrc.js +0 -1
  7. package/lib/client/App.d.ts +1 -2
  8. package/lib/client/App.js +23 -24
  9. package/lib/client/LinksCollector.d.ts +3 -3
  10. package/lib/client/LinksCollector.js +7 -11
  11. package/lib/client/PendingNavigation.d.ts +24 -1
  12. package/lib/client/PendingNavigation.js +5 -7
  13. package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
  14. package/lib/client/SiteMetadataDefaults.js +19 -0
  15. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
  16. package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
  17. package/lib/client/browserContext.d.ts +11 -0
  18. package/lib/client/browserContext.js +22 -0
  19. package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
  20. package/lib/client/client-lifecycles-dispatcher.js +6 -10
  21. package/lib/client/clientEntry.js +13 -7
  22. package/lib/client/docusaurus.d.ts +6 -0
  23. package/lib/client/docusaurus.js +16 -25
  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 +2 -3
  27. package/lib/client/exports/BrowserOnly.js +14 -7
  28. package/lib/client/exports/ComponentCreator.d.ts +1 -2
  29. package/lib/client/exports/ComponentCreator.js +40 -19
  30. package/lib/client/exports/ErrorBoundary.d.ts +18 -0
  31. package/lib/client/exports/ErrorBoundary.js +35 -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 -26
  36. package/lib/client/exports/Link.d.ts +11 -5
  37. package/lib/client/exports/Link.js +31 -20
  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 +8 -5
  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 +4 -8
  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/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
  54. package/lib/client/exports/useRouteContext.js +15 -0
  55. package/lib/client/flat.d.ts +4 -2
  56. package/lib/client/flat.js +9 -13
  57. package/lib/client/normalizeLocation.d.ts +2 -5
  58. package/lib/client/normalizeLocation.js +2 -7
  59. package/lib/client/nprogress.css +2 -2
  60. package/lib/client/prefetch.d.ts +1 -2
  61. package/lib/client/prefetch.js +4 -6
  62. package/lib/client/preload.d.ts +3 -2
  63. package/lib/client/preload.js +5 -10
  64. package/lib/client/routeContext.d.ts +13 -0
  65. package/lib/client/routeContext.js +31 -0
  66. package/lib/client/serverEntry.d.ts +10 -0
  67. package/lib/client/serverEntry.js +90 -142
  68. package/lib/client/theme-fallback/Error/index.d.ts +10 -0
  69. package/lib/client/theme-fallback/Error/index.js +43 -0
  70. package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
  71. package/lib/client/theme-fallback/Layout/index.js +2 -26
  72. package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
  73. package/lib/client/theme-fallback/Loading/index.js +47 -115
  74. package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
  75. package/lib/client/theme-fallback/NotFound/index.js +17 -18
  76. package/lib/client/theme-fallback/Root/index.d.ts +10 -0
  77. package/lib/client/theme-fallback/Root/index.js +2 -6
  78. package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
  79. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  80. package/lib/commands/build.d.ts +1 -1
  81. package/lib/commands/build.js +50 -54
  82. package/lib/commands/clear.d.ts +6 -0
  83. package/lib/commands/clear.js +30 -19
  84. package/lib/commands/commandUtils.d.ts +7 -1
  85. package/lib/commands/commandUtils.js +7 -7
  86. package/lib/commands/deploy.d.ts +1 -1
  87. package/lib/commands/deploy.js +83 -66
  88. package/lib/commands/external.d.ts +2 -2
  89. package/lib/commands/external.js +4 -8
  90. package/lib/commands/serve.d.ts +1 -1
  91. package/lib/commands/serve.js +25 -12
  92. package/lib/commands/start.d.ts +1 -1
  93. package/lib/commands/start.js +96 -87
  94. package/lib/commands/swizzle/actions.d.ts +23 -0
  95. package/lib/commands/swizzle/actions.js +101 -0
  96. package/lib/commands/swizzle/common.d.ts +33 -0
  97. package/lib/commands/swizzle/common.js +56 -0
  98. package/lib/commands/swizzle/components.d.ts +29 -0
  99. package/lib/commands/swizzle/components.js +162 -0
  100. package/lib/commands/swizzle/config.d.ts +10 -0
  101. package/lib/commands/swizzle/config.js +80 -0
  102. package/lib/commands/swizzle/context.d.ts +8 -0
  103. package/lib/commands/swizzle/context.js +28 -0
  104. package/lib/commands/swizzle/index.d.ts +8 -0
  105. package/lib/commands/swizzle/index.js +115 -0
  106. package/lib/commands/swizzle/prompts.d.ts +12 -0
  107. package/lib/commands/swizzle/prompts.js +110 -0
  108. package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
  109. package/lib/commands/swizzle/tables.js +113 -0
  110. package/lib/commands/swizzle/themes.d.ts +20 -0
  111. package/lib/commands/swizzle/themes.js +106 -0
  112. package/lib/commands/writeHeadingIds.d.ts +2 -6
  113. package/lib/commands/writeHeadingIds.js +19 -76
  114. package/lib/commands/writeTranslations.d.ts +2 -2
  115. package/lib/commands/writeTranslations.js +37 -17
  116. package/lib/index.d.ts +10 -9
  117. package/lib/index.js +20 -19
  118. package/lib/server/brokenLinks.d.ts +4 -17
  119. package/lib/server/brokenLinks.js +64 -52
  120. package/lib/server/client-modules/index.d.ts +2 -2
  121. package/lib/server/client-modules/index.js +4 -3
  122. package/lib/server/config.d.ts +2 -2
  123. package/lib/server/config.js +8 -5
  124. package/lib/server/configValidation.d.ts +4 -2
  125. package/lib/server/configValidation.js +93 -37
  126. package/lib/server/duplicateRoutes.d.ts +1 -3
  127. package/lib/server/duplicateRoutes.js +17 -13
  128. package/lib/server/html-tags/htmlTags.js +7 -8
  129. package/lib/server/html-tags/index.d.ts +2 -3
  130. package/lib/server/html-tags/index.js +3 -4
  131. package/lib/server/i18n.d.ts +2 -3
  132. package/lib/server/i18n.js +27 -48
  133. package/lib/server/index.d.ts +9 -2
  134. package/lib/server/index.js +175 -96
  135. package/lib/server/moduleShorthand.d.ts +9 -0
  136. package/lib/server/moduleShorthand.js +46 -0
  137. package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
  138. package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
  139. package/lib/server/plugins/index.d.ts +4 -5
  140. package/lib/server/plugins/index.js +69 -45
  141. package/lib/server/plugins/init.d.ts +15 -5
  142. package/lib/server/plugins/init.js +68 -81
  143. package/lib/server/plugins/pluginIds.d.ts +2 -2
  144. package/lib/server/plugins/pluginIds.js +8 -5
  145. package/lib/server/presets/index.d.ts +3 -3
  146. package/lib/server/presets/index.js +16 -23
  147. package/lib/server/routes.d.ts +3 -5
  148. package/lib/server/routes.js +68 -36
  149. package/lib/server/themes/alias.d.ts +3 -2
  150. package/lib/server/themes/alias.js +24 -13
  151. package/lib/server/themes/index.d.ts +6 -2
  152. package/lib/server/themes/index.js +36 -24
  153. package/lib/server/translations/translations.d.ts +21 -17
  154. package/lib/server/translations/translations.js +33 -54
  155. package/lib/server/translations/translationsExtractor.d.ts +12 -5
  156. package/lib/server/translations/translationsExtractor.js +159 -121
  157. package/lib/server/utils.d.ts +9 -3
  158. package/lib/server/utils.js +7 -9
  159. package/lib/server/versions/index.d.ts +3 -4
  160. package/lib/server/versions/index.js +22 -24
  161. package/lib/webpack/base.d.ts +6 -4
  162. package/lib/webpack/base.js +51 -36
  163. package/lib/webpack/client.d.ts +3 -3
  164. package/lib/webpack/client.js +12 -19
  165. package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
  166. package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
  167. package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
  168. package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
  169. package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
  170. package/lib/webpack/plugins/LogPlugin.js +4 -5
  171. package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
  172. package/lib/webpack/plugins/WaitPlugin.js +1 -1
  173. package/lib/webpack/server.d.ts +3 -3
  174. package/lib/webpack/server.js +14 -7
  175. package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
  176. package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
  177. package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
  178. package/lib/webpack/utils.d.ts +15 -30
  179. package/lib/webpack/utils.js +57 -175
  180. package/package.json +77 -70
  181. package/bin/docusaurus.js +0 -326
  182. package/lib/.tsbuildinfo +0 -5732
  183. package/lib/client/.tsbuildinfo +0 -4171
  184. package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
  185. package/lib/commands/buildRemoteBranchUrl.js +0 -27
  186. package/lib/commands/swizzle.d.ts +0 -9
  187. package/lib/commands/swizzle.js +0 -245
  188. package/lib/constants.d.ts +0 -18
  189. package/lib/constants.js +0 -23
  190. package/lib/server/loadSetup.js +0 -25
  191. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  192. package/lib/server/versions/__fixtures__/package.json +0 -3
  193. package/lib/server/versions/__tests/index.test.js +0 -25
  194. package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
  195. package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
  196. package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
  197. package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
  198. package/lib/webpack/sharedModuleAliases.js +0 -18
  199. package/tsconfig.client.json +0 -13
  200. package/tsconfig.json +0 -13
@@ -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, Object.assign({}, 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,53 @@
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';
7
+ import React, { isValidElement } from 'react';
8
8
  /*
9
9
  Minimal implementation of a React interpolate component.
10
10
  We don't ship a markdown parser nor a feature-complete i18n library on purpose.
11
11
  More details here: https://github.com/facebook/docusaurus/pull/4295
12
12
  */
13
- const ValueRegexp = /{\w+}/g;
13
+ const ValueRegexp = /\{\w+\}/g;
14
14
  const ValueFoundMarker = '{}'; // does not care much
15
15
  export function interpolate(text, values) {
16
16
  const elements = [];
17
17
  const processedText = text.replace(ValueRegexp, (match) => {
18
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];
19
+ const key = match.substring(1, match.length - 1);
20
+ const value = values?.[key];
21
21
  if (typeof value !== 'undefined') {
22
- const element = React.isValidElement(value)
22
+ const element = isValidElement(value)
23
23
  ? value
24
24
  : // For non-React elements: basic primitive->string conversion
25
25
  String(value);
26
26
  elements.push(element);
27
27
  return ValueFoundMarker;
28
28
  }
29
- else {
30
- return match; // no match? add warning?
31
- }
29
+ return match; // no match? add warning?
32
30
  });
33
31
  // No interpolation to be done: just return the text
34
32
  if (elements.length === 0) {
35
33
  return text;
36
34
  }
37
35
  // Basic string interpolation: returns interpolated string
38
- else if (elements.every((el) => typeof el === 'string')) {
36
+ if (elements.every((el) => typeof el === 'string')) {
39
37
  return processedText
40
38
  .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
- }, '');
39
+ .reduce((str, value, index) => str.concat(value).concat(elements[index] ?? ''), '');
45
40
  }
46
41
  // 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
- }, []);
58
- }
42
+ return processedText.split(ValueFoundMarker).reduce((array, value, index) => [
43
+ ...array,
44
+ <React.Fragment key={index}>
45
+ {value}
46
+ {elements[index]}
47
+ </React.Fragment>,
48
+ ], []);
59
49
  }
60
50
  export default function Interpolate({ children, values, }) {
61
- return interpolate(children, values);
51
+ if (typeof children !== 'string') {
52
+ console.warn('Illegal <Interpolate> children', children);
53
+ throw new Error('The Docusaurus <Interpolate> component only accept simple string values');
54
+ }
55
+ return <>{interpolate(children, values)}</>;
62
56
  }
@@ -4,14 +4,20 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- /// <reference types="@docusaurus/module-type-aliases" />
8
- /// <reference types="react" />
9
- import type { LinkProps } from '@docusaurus/Link';
7
+ import React from 'react';
10
8
  import type docusaurus from '../docusaurus';
11
9
  declare global {
12
10
  interface Window {
13
11
  docusaurus: typeof docusaurus;
14
12
  }
15
13
  }
16
- declare function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl, ...props }: LinkProps): JSX.Element;
17
- export default Link;
14
+ declare const _default: React.ForwardRefExoticComponent<Pick<Partial<import("react-router-dom").NavLinkProps<unknown>> & React.ClassAttributes<HTMLAnchorElement> & React.AnchorHTMLAttributes<HTMLAnchorElement> & {
15
+ readonly className?: string | undefined;
16
+ readonly style?: React.CSSProperties | undefined;
17
+ readonly isNavLink?: boolean | undefined;
18
+ readonly to?: string | undefined;
19
+ readonly href?: string | undefined;
20
+ readonly autoAddBaseUrl?: boolean | undefined;
21
+ readonly 'data-noBrokenLinkCheck'?: boolean | undefined;
22
+ }, "children" | "replace" | "slot" | "style" | "title" | "location" | "component" | "exact" | "sensitive" | "strict" | "id" | "lang" | "dir" | "rel" | "href" | "key" | "type" | "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" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "activeClassName" | "activeStyle" | "isActive" | "data-noBrokenLinkCheck" | "autoAddBaseUrl"> & React.RefAttributes<HTMLAnchorElement>>;
23
+ export default _default;
@@ -4,22 +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 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 }) {
20
- var _a;
21
+ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }, forwardedRef) {
22
+ const { siteConfig: { trailingSlash, baseUrl }, } = useDocusaurusContext();
21
23
  const { withBaseUrl } = useBaseUrlUtils();
22
24
  const linksCollector = useLinksCollector();
25
+ const innerRef = useRef(null);
26
+ useImperativeHandle(forwardedRef, () => innerRef.current);
23
27
  // IMPORTANT: using to or href should not change anything
24
28
  // For example, MDX links will ALWAYS give us the href props
25
29
  // Using one prop or the other should not be used to distinguish
@@ -37,36 +41,40 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
37
41
  // see https://github.com/facebook/docusaurus/issues/3309
38
42
  // note: we want baseUrl to be appended (see issue for details)
39
43
  // TODO read routes and automatically detect internal/external links?
40
- const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed === null || targetLinkUnprefixed === void 0 ? void 0 : targetLinkUnprefixed.replace('pathname://', '');
44
+ const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed?.replace('pathname://', '');
41
45
  // TODO we should use ReactRouter basename feature instead!
42
46
  // Automatically apply base url in links that start with /
43
- const targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
47
+ let targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
44
48
  ? maybeAddBaseUrl(targetLinkWithoutPathnameProtocol)
45
49
  : undefined;
50
+ if (targetLink && isInternal) {
51
+ targetLink = applyTrailingSlash(targetLink, { trailingSlash, baseUrl });
52
+ }
46
53
  const preloaded = useRef(false);
47
- const LinkComponent = isNavLink ? NavLink : RRLink;
54
+ const LinkComponent = (isNavLink ? NavLink : RRLink);
48
55
  const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
49
- let io;
56
+ const ioRef = useRef();
50
57
  const handleIntersection = (el, cb) => {
51
- io = new window.IntersectionObserver((entries) => {
58
+ ioRef.current = new window.IntersectionObserver((entries) => {
52
59
  entries.forEach((entry) => {
53
60
  if (el === entry.target) {
54
- // If element is in viewport, stop listening/observing and run callback.
61
+ // If element is in viewport, stop observing and run callback.
55
62
  // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
56
63
  if (entry.isIntersecting || entry.intersectionRatio > 0) {
57
- io.unobserve(el);
58
- io.disconnect();
64
+ ioRef.current.unobserve(el);
65
+ ioRef.current.disconnect();
59
66
  cb();
60
67
  }
61
68
  }
62
69
  });
63
70
  });
64
71
  // Add element to the observer.
65
- io.observe(el);
72
+ ioRef.current.observe(el);
66
73
  };
67
74
  const handleRef = (ref) => {
75
+ innerRef.current = ref;
68
76
  if (IOSupported && ref && isInternal) {
69
- // If IO supported and element reference found, setup Observer functionality.
77
+ // If IO supported and element reference found, set up Observer.
70
78
  handleIntersection(ref, () => {
71
79
  if (targetLink != null) {
72
80
  window.docusaurus.prefetch(targetLink);
@@ -89,19 +97,22 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
89
97
  }
90
98
  // When unmounting, stop intersection observer from watching.
91
99
  return () => {
92
- if (IOSupported && io) {
93
- io.disconnect();
100
+ if (IOSupported && ioRef.current) {
101
+ ioRef.current.disconnect();
94
102
  }
95
103
  };
96
- }, [targetLink, IOSupported, isInternal]);
97
- const isAnchorLink = (_a = targetLink === null || targetLink === void 0 ? void 0 : targetLink.startsWith('#')) !== null && _a !== void 0 ? _a : false;
104
+ }, [ioRef, targetLink, IOSupported, isInternal]);
105
+ const isAnchorLink = targetLink?.startsWith('#') ?? false;
98
106
  const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink;
99
107
  if (targetLink && isInternal && !isAnchorLink && !noBrokenLinkCheck) {
100
108
  linksCollector.collectLink(targetLink);
101
109
  }
102
110
  return isRegularHtmlLink ? (
103
111
  // 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 }))));
112
+ <a ref={innerRef} href={targetLink} {...(targetLinkUnprefixed &&
113
+ !isInternal && { target: '_blank', rel: 'noopener noreferrer' })} {...props}/>) : (<LinkComponent {...props} onMouseEnter={onMouseEnter} innerRef={handleRef} to={targetLink}
114
+ // avoid "React does not recognize the `activeClassName` prop on a DOM
115
+ // element"
116
+ {...(isNavLink && { isActive, activeClassName })}/>);
106
117
  }
107
- export default Link;
118
+ 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) === 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,12 @@ 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
+ }
24
+ // /baseUrl -> /baseUrl/
25
+ // https://github.com/facebook/docusaurus/issues/6315
26
+ if (url === baseUrl.replace(/\/$/, '')) {
27
+ return baseUrl;
23
28
  }
24
29
  // We should avoid adding the baseurl twice if it's already there
25
30
  const shouldAddBaseUrl = !url.startsWith(baseUrl);
@@ -27,11 +32,9 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
27
32
  return absolute ? siteUrl + basePath : basePath;
28
33
  }
29
34
  export function useBaseUrlUtils() {
30
- const { siteConfig: { baseUrl = '/', url: siteUrl } = {}, } = useDocusaurusContext();
35
+ const { siteConfig: { baseUrl, url: siteUrl }, } = useDocusaurusContext();
31
36
  return {
32
- withBaseUrl: (url, options) => {
33
- return addBaseUrl(siteUrl, baseUrl, url, options);
34
- },
37
+ withBaseUrl: (url, options) => addBaseUrl(siteUrl, baseUrl, url, options),
35
38
  };
36
39
  }
37
40
  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;
@@ -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
- export default function useGlobalData(): Record<string, unknown>;
8
- export declare function useAllPluginInstancesData<T = unknown>(pluginName: string): Record<string, T>;
9
- export declare function usePluginData<T = unknown>(pluginName: string, pluginId?: string): T;
7
+ import type { GlobalData } from '@docusaurus/types';
8
+ export default function useGlobalData(): GlobalData;
9
+ export declare function useAllPluginInstancesData(pluginName: string): GlobalData[string];
10
+ export declare function usePluginData(pluginName: string, pluginId?: string): GlobalData[string][string];
@@ -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,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 { Props } from '@docusaurus/types';
8
- declare const loadSetup: (name: string) => Promise<Props>;
9
- export default loadSetup;
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
+ }
@@ -4,5 +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
- 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): {
9
+ [keyPath: string]: string;
10
+ };
@@ -4,25 +4,21 @@
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) {
13
- Object.keys(object).forEach((key) => {
14
- 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) {
11
+ function step(object, prefix) {
12
+ Object.entries(object).forEach(([key, value]) => {
13
+ const newKey = prefix ? `${prefix}${delimiter}${key}` : key;
14
+ if (isTree(value)) {
19
15
  step(value, newKey);
20
- return;
21
16
  }
22
- output[newKey] = value;
17
+ else {
18
+ output[newKey] = value;
19
+ }
23
20
  });
24
21
  }
25
22
  step(target);
26
23
  return output;
27
24
  }
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,22 +6,17 @@
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,
13
13
  pathname: pathnames[location.pathname],
14
14
  };
15
15
  }
16
- let pathname = location.pathname || '/';
17
- pathname = pathname.trim().replace(/\/index\.html$/, '');
18
- if (pathname === '') {
19
- pathname = '/';
20
- }
16
+ const pathname = location.pathname.trim().replace(/\/index\.html$/, '') || '/';
21
17
  pathnames[location.pathname] = pathname;
22
18
  return {
23
19
  ...location,
24
20
  pathname,
25
21
  };
26
22
  }
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>;