@docusaurus/core 2.0.0-beta.16 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +14 -12
- package/bin/docusaurus.mjs +41 -93
- package/lib/babel/preset.js +2 -2
- package/lib/client/.eslintrc.js +2 -3
- package/lib/client/App.d.ts +1 -1
- package/lib/client/App.js +15 -7
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → BaseUrlIssueBanner/index.d.ts} +10 -5
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +14 -9
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +34 -0
- package/lib/client/LinksCollector.d.ts +1 -1
- package/lib/client/LinksCollector.js +4 -5
- package/lib/client/PendingNavigation.d.ts +8 -17
- package/lib/client/PendingNavigation.js +39 -70
- package/lib/{server/loadSetup.d.ts → client/SiteMetadataDefaults.d.ts} +2 -2
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
- package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
- package/lib/client/clientEntry.js +3 -4
- package/lib/client/docusaurus.d.ts +5 -5
- package/lib/client/docusaurus.js +26 -33
- package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
- package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -4
- package/lib/client/exports/BrowserOnly.js +2 -2
- package/lib/client/exports/ComponentCreator.js +65 -40
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +4 -5
- package/lib/client/exports/Interpolate.d.ts +1 -1
- package/lib/client/exports/Interpolate.js +18 -41
- package/lib/client/exports/Link.d.ts +3 -15
- package/lib/client/exports/Link.js +24 -30
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +3 -3
- package/lib/client/exports/useBaseUrl.js +8 -9
- package/lib/client/exports/useDocusaurusContext.js +1 -1
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +5 -5
- package/lib/client/exports/useIsBrowser.js +1 -1
- package/lib/{server/client-modules/index.d.ts → client/exports/useRouteContext.d.ts} +2 -2
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +12 -5
- package/lib/client/normalizeLocation.js +13 -8
- package/lib/client/prefetch.js +10 -28
- package/lib/client/preload.d.ts +1 -3
- package/lib/client/preload.js +5 -11
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.js +19 -18
- package/lib/client/theme-fallback/Error/index.js +7 -1
- package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
- package/lib/client/theme-fallback/Layout/index.js +2 -17
- package/lib/client/theme-fallback/Loading/index.js +2 -0
- package/lib/client/theme-fallback/NotFound/index.js +13 -5
- package/lib/client/theme-fallback/Root/index.d.ts +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -1
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +48 -30
- package/lib/commands/clear.d.ts +1 -1
- package/lib/commands/clear.js +6 -5
- package/lib/commands/deploy.d.ts +5 -5
- package/lib/commands/deploy.js +21 -45
- package/lib/commands/external.d.ts +1 -1
- package/lib/commands/external.js +6 -11
- package/lib/commands/serve.d.ts +7 -2
- package/lib/commands/serve.js +18 -19
- package/lib/commands/start.d.ts +8 -2
- package/lib/commands/start.js +33 -30
- package/lib/commands/swizzle/actions.d.ts +2 -2
- package/lib/commands/swizzle/actions.js +10 -10
- package/lib/commands/swizzle/common.d.ts +3 -3
- package/lib/commands/swizzle/common.js +8 -9
- package/lib/commands/swizzle/components.js +48 -13
- package/lib/commands/swizzle/config.js +21 -15
- package/lib/commands/swizzle/context.js +6 -12
- package/lib/commands/swizzle/index.d.ts +2 -2
- package/lib/commands/swizzle/index.js +5 -4
- package/lib/commands/swizzle/prompts.js +2 -2
- package/lib/commands/swizzle/tables.js +10 -13
- package/lib/commands/swizzle/themes.js +9 -8
- package/lib/commands/writeHeadingIds.d.ts +2 -9
- package/lib/commands/writeHeadingIds.js +11 -69
- package/lib/commands/writeTranslations.d.ts +3 -4
- package/lib/commands/writeTranslations.js +10 -14
- package/lib/index.d.ts +9 -10
- package/lib/index.js +18 -19
- package/lib/server/brokenLinks.d.ts +3 -16
- package/lib/server/brokenLinks.js +37 -31
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +14 -9
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +39 -13
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/{choosePort.js → server/getHostPort.js} +24 -41
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +2 -11
- package/lib/server/i18n.js +7 -28
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +62 -229
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +65 -132
- package/lib/server/plugins/init.d.ts +6 -15
- package/lib/server/plugins/init.js +25 -83
- package/lib/server/{moduleShorthand.d.ts → plugins/moduleShorthand.d.ts} +0 -0
- package/lib/server/{moduleShorthand.js → plugins/moduleShorthand.js} +0 -0
- package/lib/server/plugins/pluginIds.d.ts +4 -0
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/{presets/index.js → plugins/presets.js} +21 -20
- package/lib/server/plugins/{applyRouteTrailingSlash.d.ts → routeConfig.d.ts} +3 -1
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +112 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +169 -102
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +5 -14
- package/lib/server/translations/translations.js +23 -39
- package/lib/server/translations/translationsExtractor.d.ts +2 -2
- package/lib/server/translations/translationsExtractor.js +16 -19
- package/lib/server/utils.js +1 -1
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +0 -1
- package/lib/webpack/base.js +12 -30
- package/lib/webpack/client.js +7 -8
- package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +2 -2
- package/lib/webpack/plugins/CleanWebpackPlugin.js +2 -2
- package/lib/webpack/plugins/LogPlugin.js +2 -2
- package/lib/webpack/plugins/WaitPlugin.d.ts +2 -2
- package/lib/webpack/plugins/WaitPlugin.js +3 -3
- package/lib/webpack/server.d.ts +2 -2
- package/lib/webpack/server.js +10 -8
- package/lib/webpack/utils.d.ts +9 -3
- package/lib/webpack/utils.js +20 -25
- package/package.json +38 -41
- package/lib/choosePort.d.ts +0 -11
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -9
- package/lib/client/client-lifecycles-dispatcher.js +0 -23
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/commandUtils.d.ts +0 -9
- package/lib/commands/commandUtils.js +0 -21
- package/lib/server/client-modules/index.js +0 -12
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -42
- package/lib/server/html-tags/htmlTags.js +0 -38
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/themes/alias.d.ts +0 -9
- package/lib/server/themes/alias.js +0 -48
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/index.d.ts +0 -9
- package/lib/server/versions/index.js +0 -51
|
@@ -4,20 +4,8 @@
|
|
|
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" />
|
|
7
8
|
import React from 'react';
|
|
8
|
-
import type
|
|
9
|
-
declare
|
|
10
|
-
interface Window {
|
|
11
|
-
docusaurus: typeof docusaurus;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
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" | "component" | "location" | "exact" | "sensitive" | "strict" | "id" | "dir" | "rel" | "href" | "type" | "key" | "isNavLink" | "className" | "to" | "innerRef" | "download" | "hrefLang" | "media" | "ping" | "target" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "lang" | "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>>;
|
|
9
|
+
import type { Props } from '@docusaurus/Link';
|
|
10
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<Props, "children" | "replace" | "slot" | "style" | "title" | "location" | "component" | "exact" | "sensitive" | "strict" | "type" | "key" | "id" | "lang" | "dir" | "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" | "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
11
|
export default _default;
|
|
@@ -19,7 +19,6 @@ import { applyTrailingSlash } from '@docusaurus/utils-common';
|
|
|
19
19
|
// like "introduction" to "/baseUrl/introduction" => bad behavior to fix
|
|
20
20
|
const shouldAddBaseUrlAutomatically = (to) => to.startsWith('/');
|
|
21
21
|
function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLinkCheck': noBrokenLinkCheck, autoAddBaseUrl = true, ...props }, forwardedRef) {
|
|
22
|
-
var _a;
|
|
23
22
|
const { siteConfig: { trailingSlash, baseUrl }, } = useDocusaurusContext();
|
|
24
23
|
const { withBaseUrl } = useBaseUrlUtils();
|
|
25
24
|
const linksCollector = useLinksCollector();
|
|
@@ -42,7 +41,7 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
42
41
|
// see https://github.com/facebook/docusaurus/issues/3309
|
|
43
42
|
// note: we want baseUrl to be appended (see issue for details)
|
|
44
43
|
// TODO read routes and automatically detect internal/external links?
|
|
45
|
-
const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed
|
|
44
|
+
const targetLinkWithoutPathnameProtocol = targetLinkUnprefixed?.replace('pathname://', '');
|
|
46
45
|
// TODO we should use ReactRouter basename feature instead!
|
|
47
46
|
// Automatically apply base url in links that start with /
|
|
48
47
|
let targetLink = typeof targetLinkWithoutPathnameProtocol !== 'undefined'
|
|
@@ -55,32 +54,27 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
55
54
|
const LinkComponent = (isNavLink ? NavLink : RRLink);
|
|
56
55
|
const IOSupported = ExecutionEnvironment.canUseIntersectionObserver;
|
|
57
56
|
const ioRef = useRef();
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (el === entry.target) {
|
|
62
|
-
// If element is in viewport, stop observing and run callback.
|
|
63
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
|
|
64
|
-
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
65
|
-
ioRef.current.unobserve(el);
|
|
66
|
-
ioRef.current.disconnect();
|
|
67
|
-
cb();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
// Add element to the observer.
|
|
73
|
-
ioRef.current.observe(el);
|
|
74
|
-
};
|
|
75
|
-
const handleRef = (ref) => {
|
|
76
|
-
innerRef.current = ref;
|
|
77
|
-
if (IOSupported && ref && isInternal) {
|
|
57
|
+
const handleRef = (el) => {
|
|
58
|
+
innerRef.current = el;
|
|
59
|
+
if (IOSupported && el && isInternal) {
|
|
78
60
|
// If IO supported and element reference found, set up Observer.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
83
75
|
});
|
|
76
|
+
// Add element to the observer.
|
|
77
|
+
ioRef.current.observe(el);
|
|
84
78
|
}
|
|
85
79
|
};
|
|
86
80
|
const onMouseEnter = () => {
|
|
@@ -103,16 +97,16 @@ function Link({ isNavLink, to, href, activeClassName, isActive, 'data-noBrokenLi
|
|
|
103
97
|
}
|
|
104
98
|
};
|
|
105
99
|
}, [ioRef, targetLink, IOSupported, isInternal]);
|
|
106
|
-
const isAnchorLink =
|
|
100
|
+
const isAnchorLink = targetLink?.startsWith('#') ?? false;
|
|
107
101
|
const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink;
|
|
108
|
-
if (
|
|
102
|
+
if (!isRegularHtmlLink && !noBrokenLinkCheck) {
|
|
109
103
|
linksCollector.collectLink(targetLink);
|
|
110
104
|
}
|
|
111
105
|
return isRegularHtmlLink ? (
|
|
112
106
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
113
107
|
<a ref={innerRef} href={targetLink} {...(targetLinkUnprefixed &&
|
|
114
|
-
!isInternal && { target: '_blank', rel: 'noopener noreferrer' })} {...props}/>) : (<LinkComponent {...props} onMouseEnter={onMouseEnter} innerRef={handleRef} to={targetLink
|
|
115
|
-
//
|
|
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
|
|
116
110
|
// element"
|
|
117
111
|
{...(isNavLink && { isActive, activeClassName })}/>);
|
|
118
112
|
}
|
|
@@ -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
|
-
|
|
8
|
+
/// <reference types="react" />
|
|
9
9
|
import { type InterpolateValues } from '@docusaurus/Interpolate';
|
|
10
10
|
import type { TranslateParam, TranslateProps } from '@docusaurus/Translate';
|
|
11
11
|
export declare function translate<Str extends string>({ message, id }: TranslateParam<Str>, values?: InterpolateValues<Str, string | number>): string;
|
|
12
|
-
export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>):
|
|
12
|
+
export default function Translate<Str extends string>({ children, id, values, }: TranslateProps<Str>): JSX.Element;
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import React from 'react';
|
|
7
8
|
import { interpolate } from '@docusaurus/Interpolate';
|
|
8
9
|
// Can't read it from context, due to exposing imperative API
|
|
9
10
|
import codeTranslations from '@generated/codeTranslations';
|
|
10
11
|
function getLocalizedMessage({ id, message, }) {
|
|
11
|
-
var _a, _b;
|
|
12
12
|
if (typeof id === 'undefined' && typeof message === 'undefined') {
|
|
13
13
|
throw new Error('Docusaurus translation declarations must have at least a translation id or a default translation message');
|
|
14
14
|
}
|
|
15
|
-
return
|
|
15
|
+
return codeTranslations[(id ?? message)] ?? message ?? id;
|
|
16
16
|
}
|
|
17
17
|
// Imperative translation API is useful for some edge-cases:
|
|
18
18
|
// - translating page titles (meta)
|
|
@@ -30,5 +30,5 @@ export default function Translate({ children, id, values, }) {
|
|
|
30
30
|
throw new Error('The Docusaurus <Translate> component only accept simple string values');
|
|
31
31
|
}
|
|
32
32
|
const localizedMessage = getLocalizedMessage({ message: children, id });
|
|
33
|
-
return interpolate(localizedMessage, values)
|
|
33
|
+
return <>{interpolate(localizedMessage, values)}</>;
|
|
34
34
|
}
|
|
@@ -7,20 +7,19 @@
|
|
|
7
7
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
8
8
|
import { hasProtocol } from './isInternalUrl';
|
|
9
9
|
function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolute = false } = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// it never makes sense to add a base url to a local anchor url
|
|
14
|
-
if (url.startsWith('#')) {
|
|
15
|
-
return url;
|
|
16
|
-
}
|
|
17
|
-
// it never makes sense to add a base url to an url with a protocol
|
|
18
|
-
if (hasProtocol(url)) {
|
|
10
|
+
// It never makes sense to add base url to a local anchor url, or one with a
|
|
11
|
+
// protocol
|
|
12
|
+
if (!url || url.startsWith('#') || hasProtocol(url)) {
|
|
19
13
|
return url;
|
|
20
14
|
}
|
|
21
15
|
if (forcePrependBaseUrl) {
|
|
22
16
|
return baseUrl + url.replace(/^\//, '');
|
|
23
17
|
}
|
|
18
|
+
// /baseUrl -> /baseUrl/
|
|
19
|
+
// https://github.com/facebook/docusaurus/issues/6315
|
|
20
|
+
if (url === baseUrl.replace(/\/$/, '')) {
|
|
21
|
+
return baseUrl;
|
|
22
|
+
}
|
|
24
23
|
// We should avoid adding the baseurl twice if it's already there
|
|
25
24
|
const shouldAddBaseUrl = !url.startsWith(baseUrl);
|
|
26
25
|
const basePath = shouldAddBaseUrl ? baseUrl + url.replace(/^\//, '') : url;
|
|
@@ -5,7 +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 '
|
|
8
|
+
import { Context } from '../docusaurusContext';
|
|
9
9
|
export default function useDocusaurusContext() {
|
|
10
10
|
return useContext(Context);
|
|
11
11
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export declare function
|
|
7
|
+
import type { GlobalData, UseDataOptions } from '@docusaurus/types';
|
|
8
|
+
export default function useGlobalData(): GlobalData;
|
|
9
|
+
export declare function useAllPluginInstancesData(pluginName: string, options?: UseDataOptions): GlobalData[string] | undefined;
|
|
10
|
+
export declare function usePluginData(pluginName: string, pluginId?: string, options?: UseDataOptions): GlobalData[string][string];
|
|
@@ -13,18 +13,18 @@ export default function useGlobalData() {
|
|
|
13
13
|
}
|
|
14
14
|
return globalData;
|
|
15
15
|
}
|
|
16
|
-
export function useAllPluginInstancesData(pluginName) {
|
|
16
|
+
export function useAllPluginInstancesData(pluginName, options = {}) {
|
|
17
17
|
const globalData = useGlobalData();
|
|
18
18
|
const pluginGlobalData = globalData[pluginName];
|
|
19
|
-
if (!pluginGlobalData) {
|
|
19
|
+
if (!pluginGlobalData && options.failfast) {
|
|
20
20
|
throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin.`);
|
|
21
21
|
}
|
|
22
22
|
return pluginGlobalData;
|
|
23
23
|
}
|
|
24
|
-
export function usePluginData(pluginName, pluginId = DEFAULT_PLUGIN_ID) {
|
|
24
|
+
export function usePluginData(pluginName, pluginId = DEFAULT_PLUGIN_ID, options = {}) {
|
|
25
25
|
const pluginGlobalData = useAllPluginInstancesData(pluginName);
|
|
26
|
-
const pluginInstanceGlobalData = pluginGlobalData[pluginId];
|
|
27
|
-
if (!pluginInstanceGlobalData) {
|
|
26
|
+
const pluginInstanceGlobalData = pluginGlobalData?.[pluginId];
|
|
27
|
+
if (!pluginInstanceGlobalData && options.failfast) {
|
|
28
28
|
throw new Error(`Docusaurus plugin global data not found for "${pluginName}" plugin with id "${pluginId}".`);
|
|
29
29
|
}
|
|
30
30
|
return pluginInstanceGlobalData;
|
|
@@ -5,7 +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 '
|
|
8
|
+
import { Context } from '../browserContext';
|
|
9
9
|
export default function useIsBrowser() {
|
|
10
10
|
return useContext(Context);
|
|
11
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
|
-
import type {
|
|
8
|
-
export default function
|
|
7
|
+
import type { PluginRouteContext } from '@docusaurus/types';
|
|
8
|
+
export default function useRouteContext(): PluginRouteContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { Context } from '../routeContext';
|
|
9
|
+
export default function useRouteContext() {
|
|
10
|
+
const context = React.useContext(Context);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error('Unexpected: no Docusaurus route context found');
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
package/lib/client/flat.d.ts
CHANGED
|
@@ -4,5 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type { ChunkNames } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Takes a tree, and flattens it into a map of keyPath -> value.
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* flat({ a: { b: 1 } }) === { "a.b": 1 };
|
|
13
|
+
* flat({ a: [1, 2] }) === { "a.0": 1, "a.1": 2 };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export default function flat(target: ChunkNames): {
|
|
17
|
+
[keyPath: string]: string;
|
|
18
|
+
};
|
package/lib/client/flat.js
CHANGED
|
@@ -5,21 +5,28 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
const isTree = (x) => typeof x === 'object' && !!x && Object.keys(x).length > 0;
|
|
8
|
+
/**
|
|
9
|
+
* Takes a tree, and flattens it into a map of keyPath -> value.
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* flat({ a: { b: 1 } }) === { "a.b": 1 };
|
|
13
|
+
* flat({ a: [1, 2] }) === { "a.0": 1, "a.1": 2 };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
8
16
|
export default function flat(target) {
|
|
9
17
|
const delimiter = '.';
|
|
10
18
|
const output = {};
|
|
11
|
-
function
|
|
12
|
-
Object.
|
|
13
|
-
const value = object[key];
|
|
19
|
+
function dfs(object, prefix) {
|
|
20
|
+
Object.entries(object).forEach(([key, value]) => {
|
|
14
21
|
const newKey = prefix ? `${prefix}${delimiter}${key}` : key;
|
|
15
22
|
if (isTree(value)) {
|
|
16
|
-
|
|
23
|
+
dfs(value, newKey);
|
|
17
24
|
}
|
|
18
25
|
else {
|
|
19
26
|
output[newKey] = value;
|
|
20
27
|
}
|
|
21
28
|
});
|
|
22
29
|
}
|
|
23
|
-
|
|
30
|
+
dfs(target);
|
|
24
31
|
return output;
|
|
25
32
|
}
|
|
@@ -4,21 +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 { matchRoutes } from 'react-router-config';
|
|
8
|
+
import routes from '@generated/routes';
|
|
7
9
|
// Memoize previously normalized pathnames.
|
|
8
|
-
const pathnames =
|
|
10
|
+
const pathnames = new Map();
|
|
9
11
|
export default function normalizeLocation(location) {
|
|
10
|
-
if (pathnames
|
|
12
|
+
if (pathnames.has(location.pathname)) {
|
|
11
13
|
return {
|
|
12
14
|
...location,
|
|
13
|
-
pathname: pathnames
|
|
15
|
+
pathname: pathnames.get(location.pathname),
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// If the location was registered with an `.html` extension, we don't strip it
|
|
19
|
+
// away, or it will render to a 404 page.
|
|
20
|
+
const matchedRoutes = matchRoutes(routes, location.pathname);
|
|
21
|
+
if (matchedRoutes.some(({ route }) => route.exact === true)) {
|
|
22
|
+
pathnames.set(location.pathname, location.pathname);
|
|
23
|
+
return location;
|
|
20
24
|
}
|
|
21
|
-
|
|
25
|
+
const pathname = location.pathname.trim().replace(/(?:\/index)?\.html$/, '') || '/';
|
|
26
|
+
pathnames.set(location.pathname, pathname);
|
|
22
27
|
return {
|
|
23
28
|
...location,
|
|
24
29
|
pathname,
|
package/lib/client/prefetch.js
CHANGED
|
@@ -4,20 +4,14 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
function
|
|
8
|
-
if (typeof document === 'undefined') {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
const fakeLink = document.createElement('link');
|
|
7
|
+
function supports(feature) {
|
|
12
8
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
9
|
+
const fakeLink = document.createElement('link');
|
|
10
|
+
return fakeLink.relList?.supports?.(feature);
|
|
16
11
|
}
|
|
17
12
|
catch (err) {
|
|
18
13
|
return false;
|
|
19
14
|
}
|
|
20
|
-
return false;
|
|
21
15
|
}
|
|
22
16
|
function linkPrefetchStrategy(url) {
|
|
23
17
|
return new Promise((resolve, reject) => {
|
|
@@ -28,11 +22,11 @@ function linkPrefetchStrategy(url) {
|
|
|
28
22
|
const link = document.createElement('link');
|
|
29
23
|
link.setAttribute('rel', 'prefetch');
|
|
30
24
|
link.setAttribute('href', url);
|
|
31
|
-
link.onload = resolve;
|
|
32
|
-
link.onerror = reject;
|
|
33
|
-
const parentElement = document.getElementsByTagName('head')[0]
|
|
34
|
-
document.getElementsByName('script')[0]
|
|
35
|
-
parentElement
|
|
25
|
+
link.onload = () => resolve();
|
|
26
|
+
link.onerror = () => reject();
|
|
27
|
+
const parentElement = document.getElementsByTagName('head')[0] ??
|
|
28
|
+
document.getElementsByName('script')[0]?.parentNode;
|
|
29
|
+
parentElement?.appendChild(link);
|
|
36
30
|
});
|
|
37
31
|
}
|
|
38
32
|
function xhrPrefetchStrategy(url) {
|
|
@@ -51,21 +45,9 @@ function xhrPrefetchStrategy(url) {
|
|
|
51
45
|
req.send(null);
|
|
52
46
|
});
|
|
53
47
|
}
|
|
54
|
-
const supportedPrefetchStrategy =
|
|
48
|
+
const supportedPrefetchStrategy = supports('prefetch')
|
|
55
49
|
? linkPrefetchStrategy
|
|
56
50
|
: xhrPrefetchStrategy;
|
|
57
|
-
const preFetched = {};
|
|
58
51
|
export default function prefetch(url) {
|
|
59
|
-
return
|
|
60
|
-
if (preFetched[url]) {
|
|
61
|
-
resolve();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
supportedPrefetchStrategy(url)
|
|
65
|
-
.then(() => {
|
|
66
|
-
resolve();
|
|
67
|
-
preFetched[url] = true;
|
|
68
|
-
})
|
|
69
|
-
.catch(() => { }); // 404s are logged to the console anyway.
|
|
70
|
-
});
|
|
52
|
+
return supportedPrefetchStrategy(url).catch(() => { }); // 404s are logged to the console anyway.
|
|
71
53
|
}
|
package/lib/client/preload.d.ts
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { type RouteConfig } from 'react-router-config';
|
|
8
7
|
/**
|
|
9
8
|
* Helper function to make sure all async components for that particular route
|
|
10
9
|
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
10
|
* screens.
|
|
12
11
|
*
|
|
13
|
-
* @param routes react-router-config
|
|
14
12
|
* @param pathname the route pathname, example: /docs/installation
|
|
15
13
|
* @returns Promise object represents whether pathname has been preloaded
|
|
16
14
|
*/
|
|
17
|
-
export default function preload(
|
|
15
|
+
export default function preload(pathname: string): Promise<void[]>;
|
package/lib/client/preload.js
CHANGED
|
@@ -4,25 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import routes from '@generated/routes';
|
|
7
8
|
import { matchRoutes } from 'react-router-config';
|
|
8
9
|
/**
|
|
9
10
|
* Helper function to make sure all async components for that particular route
|
|
10
11
|
* is preloaded before rendering. This is especially useful to avoid loading
|
|
11
12
|
* screens.
|
|
12
13
|
*
|
|
13
|
-
* @param routes react-router-config
|
|
14
14
|
* @param pathname the route pathname, example: /docs/installation
|
|
15
15
|
* @returns Promise object represents whether pathname has been preloaded
|
|
16
16
|
*/
|
|
17
|
-
export default function preload(
|
|
17
|
+
export default function preload(pathname) {
|
|
18
18
|
const matches = matchRoutes(routes, pathname);
|
|
19
|
-
return Promise.all(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (component && component.preload) {
|
|
23
|
-
// @ts-expect-error: checked above.
|
|
24
|
-
return component.preload();
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}));
|
|
19
|
+
return Promise.all(
|
|
20
|
+
// @ts-expect-error: ComponentCreator injected this method.
|
|
21
|
+
matches.map((match) => match.route.component?.preload?.()));
|
|
28
22
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactNode } from 'react';
|
|
8
|
+
import type { PluginRouteContext, RouteContext } from '@docusaurus/types';
|
|
9
|
+
export declare const Context: React.Context<PluginRouteContext | null>;
|
|
10
|
+
export declare function RouteContextProvider({ children, value, }: {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
value: PluginRouteContext | RouteContext | null;
|
|
13
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
|
+
export const Context = React.createContext(null);
|
|
9
|
+
function mergeContexts({ parent, value, }) {
|
|
10
|
+
if (!parent) {
|
|
11
|
+
if (!value) {
|
|
12
|
+
throw new Error('Unexpected: no Docusaurus route context found');
|
|
13
|
+
}
|
|
14
|
+
else if (!('plugin' in value)) {
|
|
15
|
+
throw new Error('Unexpected: Docusaurus topmost route context has no `plugin` attribute');
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
// TODO deep merge this
|
|
20
|
+
const data = { ...parent.data, ...value?.data };
|
|
21
|
+
return {
|
|
22
|
+
// Nested routes are not supposed to override plugin attribute
|
|
23
|
+
plugin: parent.plugin,
|
|
24
|
+
data,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function RouteContextProvider({ children, value, }) {
|
|
28
|
+
const parent = React.useContext(Context);
|
|
29
|
+
const mergedValue = useMemo(() => mergeContexts({ parent, value }), [parent, value]);
|
|
30
|
+
return <Context.Provider value={mergedValue}>{children}</Context.Provider>;
|
|
31
|
+
}
|
|
@@ -14,15 +14,13 @@ import Loadable from 'react-loadable';
|
|
|
14
14
|
import { minify } from 'html-minifier-terser';
|
|
15
15
|
import path from 'path';
|
|
16
16
|
import fs from 'fs-extra';
|
|
17
|
-
import routes from '@generated/routes';
|
|
18
17
|
import preload from './preload';
|
|
19
18
|
import App from './App';
|
|
20
|
-
import { createStatefulLinksCollector,
|
|
19
|
+
import { createStatefulLinksCollector, LinksCollectorProvider, } from './LinksCollector';
|
|
21
20
|
import logger from '@docusaurus/logger';
|
|
22
21
|
// eslint-disable-next-line no-restricted-imports
|
|
23
22
|
import _ from 'lodash';
|
|
24
|
-
|
|
25
|
-
const packageJson = require('../../package.json');
|
|
23
|
+
import { DOCUSAURUS_VERSION } from '@docusaurus/utils';
|
|
26
24
|
const getCompiledSSRTemplate = _.memoize((template) => eta.compile(template.trim(), {
|
|
27
25
|
rmWhitespace: true,
|
|
28
26
|
}));
|
|
@@ -39,7 +37,7 @@ export default async function render(locals) {
|
|
|
39
37
|
const isNotDefinedErrorRegex = /(?:window|document|localStorage|navigator|alert|location|buffer|self) is not defined/i;
|
|
40
38
|
if (isNotDefinedErrorRegex.test(err.message)) {
|
|
41
39
|
logger.info `It looks like you are using code that should run on the client-side only.
|
|
42
|
-
To get around it, try using code=${'<BrowserOnly>'} (
|
|
40
|
+
To get around it, try using code=${'<BrowserOnly>'} (url=${'https://docusaurus.io/docs/docusaurus-core/#browseronly'}) or code=${'ExecutionEnvironment'} (url=${'https://docusaurus.io/docs/docusaurus-core/#executionenvironment'}).
|
|
43
41
|
It might also require to wrap your client code in code=${'useEffect'} hook and/or import a third-party library dynamically (if any).`;
|
|
44
42
|
}
|
|
45
43
|
throw err;
|
|
@@ -47,19 +45,21 @@ It might also require to wrap your client code in code=${'useEffect'} hook and/o
|
|
|
47
45
|
}
|
|
48
46
|
// Renderer for static-site-generator-webpack-plugin (async rendering).
|
|
49
47
|
async function doRender(locals) {
|
|
50
|
-
const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, baseUrl, ssrTemplate, noIndex, } = locals;
|
|
48
|
+
const { routesLocation, headTags, preBodyTags, postBodyTags, onLinksCollected, onHeadTagsCollected, baseUrl, ssrTemplate, noIndex, } = locals;
|
|
51
49
|
const location = routesLocation[locals.path];
|
|
52
|
-
await preload(
|
|
50
|
+
await preload(location);
|
|
53
51
|
const modules = new Set();
|
|
54
|
-
const
|
|
52
|
+
const routerContext = {};
|
|
55
53
|
const helmetContext = {};
|
|
56
54
|
const linksCollector = createStatefulLinksCollector();
|
|
57
|
-
const appHtml = ReactDOMServer.renderToString(
|
|
55
|
+
const appHtml = ReactDOMServer.renderToString(
|
|
56
|
+
// @ts-expect-error: we are migrating away from react-loadable anyways
|
|
57
|
+
<Loadable.Capture report={(moduleName) => modules.add(moduleName)}>
|
|
58
58
|
<HelmetProvider context={helmetContext}>
|
|
59
|
-
<StaticRouter location={location} context={
|
|
60
|
-
<
|
|
59
|
+
<StaticRouter location={location} context={routerContext}>
|
|
60
|
+
<LinksCollectorProvider linksCollector={linksCollector}>
|
|
61
61
|
<App />
|
|
62
|
-
</
|
|
62
|
+
</LinksCollectorProvider>
|
|
63
63
|
</StaticRouter>
|
|
64
64
|
</HelmetProvider>
|
|
65
65
|
</Loadable.Capture>);
|
|
@@ -73,21 +73,22 @@ async function doRender(locals) {
|
|
|
73
73
|
helmet.link.toString(),
|
|
74
74
|
helmet.script.toString(),
|
|
75
75
|
];
|
|
76
|
+
onHeadTagsCollected(location, helmet);
|
|
76
77
|
const metaAttributes = metaStrings.filter(Boolean);
|
|
77
78
|
const { generatedFilesDir } = locals;
|
|
78
79
|
const manifestPath = path.join(generatedFilesDir, 'client-manifest.json');
|
|
79
|
-
const manifest =
|
|
80
|
+
const manifest = await fs.readJSON(manifestPath);
|
|
80
81
|
// Get all required assets for this particular page based on client
|
|
81
82
|
// manifest information.
|
|
82
83
|
const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
|
|
83
84
|
const bundles = getBundles(manifest, modulesToBeLoaded);
|
|
84
|
-
const stylesheets = (bundles.css
|
|
85
|
-
const scripts = (bundles.js
|
|
85
|
+
const stylesheets = (bundles.css ?? []).map((b) => b.file);
|
|
86
|
+
const scripts = (bundles.js ?? []).map((b) => b.file);
|
|
86
87
|
const renderedHtml = renderSSRTemplate(ssrTemplate, {
|
|
87
88
|
appHtml,
|
|
88
89
|
baseUrl,
|
|
89
|
-
htmlAttributes
|
|
90
|
-
bodyAttributes
|
|
90
|
+
htmlAttributes,
|
|
91
|
+
bodyAttributes,
|
|
91
92
|
headTags,
|
|
92
93
|
preBodyTags,
|
|
93
94
|
postBodyTags,
|
|
@@ -95,7 +96,7 @@ async function doRender(locals) {
|
|
|
95
96
|
scripts,
|
|
96
97
|
stylesheets,
|
|
97
98
|
noIndex,
|
|
98
|
-
version:
|
|
99
|
+
version: DOCUSAURUS_VERSION,
|
|
99
100
|
});
|
|
100
101
|
try {
|
|
101
102
|
// Minify html with https://github.com/DanielRuf/html-minifier-terser
|