mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 10:22:30 +02:00
refactor(core): convert theme-fallback to TS (#6511)
* refactor(core): convert theme-fallback to TS * add missing type * fix snapshot
This commit is contained in:
parent
e77dda07c0
commit
8f69f633e6
9 changed files with 33 additions and 23 deletions
2
packages/docusaurus-types/src/index.d.ts
vendored
2
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -27,7 +27,7 @@ export interface DocusaurusConfig {
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
baseUrlIssueBanner: boolean;
|
baseUrlIssueBanner: boolean;
|
||||||
favicon?: string;
|
favicon?: string;
|
||||||
tagline?: string;
|
tagline: string;
|
||||||
title: string;
|
title: string;
|
||||||
url: string;
|
url: string;
|
||||||
// trailingSlash undefined = legacy retrocompatible behavior => /file => /file/index.html
|
// trailingSlash undefined = legacy retrocompatible behavior => /file => /file/index.html
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
||||||
|
import type {Props} from '@theme/Error';
|
||||||
|
|
||||||
function ErrorDisplay({error, tryAgain}) {
|
function ErrorDisplay({error, tryAgain}: Props): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
@ -30,7 +31,7 @@ function ErrorDisplay({error, tryAgain}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Error({error, tryAgain}) {
|
function Error({error, tryAgain}: Props): JSX.Element {
|
||||||
// We wrap the error in its own error boundary because the layout can actually throw too...
|
// We wrap the error in its own error boundary because the layout can actually throw too...
|
||||||
// Only the ErrorDisplay component is simple enough to be considered safe to never throw
|
// Only the ErrorDisplay component is simple enough to be considered safe to never throw
|
||||||
return (
|
return (
|
|
@ -9,12 +9,12 @@ import React from 'react';
|
||||||
import Head from '@docusaurus/Head';
|
import Head from '@docusaurus/Head';
|
||||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||||
import useBaseUrl from '@docusaurus/useBaseUrl';
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
||||||
|
import type {Props} from '@theme/Layout';
|
||||||
|
|
||||||
function Layout(props) {
|
function Layout({children, title, description}: Props): JSX.Element {
|
||||||
const context = useDocusaurusContext();
|
const context = useDocusaurusContext();
|
||||||
const {siteConfig = {}} = context;
|
const {siteConfig} = context;
|
||||||
const {favicon, tagline = '', title: defaultTitle} = siteConfig;
|
const {favicon, tagline, title: defaultTitle} = siteConfig;
|
||||||
const {children, title, description} = props;
|
|
||||||
const faviconUrl = useBaseUrl(favicon);
|
const faviconUrl = useBaseUrl(favicon);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
|
@ -6,13 +6,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import type {LoadingComponentProps} from 'react-loadable';
|
||||||
|
|
||||||
export default function Loading({error, retry, pastDelay}) {
|
export default function Loading({
|
||||||
|
error,
|
||||||
|
retry,
|
||||||
|
pastDelay,
|
||||||
|
}: LoadingComponentProps): JSX.Element | null {
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
align: 'center',
|
textAlign: 'center',
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
backgroundColor: '#fa383e',
|
backgroundColor: '#fa383e',
|
||||||
borderColor: '#fa383e',
|
borderColor: '#fa383e',
|
|
@ -8,7 +8,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
|
|
||||||
function NotFound() {
|
function NotFound(): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Layout title="Page Not Found">
|
<Layout title="Page Not Found">
|
||||||
<div
|
<div
|
|
@ -5,6 +5,8 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import type {ReactNode} from 'react';
|
||||||
|
|
||||||
// Wrapper at the very top of the app, that is applied constantly
|
// Wrapper at the very top of the app, that is applied constantly
|
||||||
// and does not depend on current route (unlike the layout)
|
// and does not depend on current route (unlike the layout)
|
||||||
//
|
//
|
||||||
|
@ -12,7 +14,7 @@
|
||||||
// and these providers won't reset state when we navigate
|
// and these providers won't reset state when we navigate
|
||||||
//
|
//
|
||||||
// See https://github.com/facebook/docusaurus/issues/3919
|
// See https://github.com/facebook/docusaurus/issues/3919
|
||||||
function Root({children}) {
|
function Root({children}: {children: ReactNode}): ReactNode {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ export const DEFAULT_CONFIG: Pick<
|
||||||
| 'themeConfig'
|
| 'themeConfig'
|
||||||
| 'titleDelimiter'
|
| 'titleDelimiter'
|
||||||
| 'noIndex'
|
| 'noIndex'
|
||||||
|
| 'tagline'
|
||||||
| 'baseUrlIssueBanner'
|
| 'baseUrlIssueBanner'
|
||||||
| 'staticDirectories'
|
| 'staticDirectories'
|
||||||
> = {
|
> = {
|
||||||
|
@ -51,6 +52,7 @@ export const DEFAULT_CONFIG: Pick<
|
||||||
themeConfig: {},
|
themeConfig: {},
|
||||||
titleDelimiter: '|',
|
titleDelimiter: '|',
|
||||||
noIndex: false,
|
noIndex: false,
|
||||||
|
tagline: '',
|
||||||
baseUrlIssueBanner: true,
|
baseUrlIssueBanner: true,
|
||||||
staticDirectories: [STATIC_DIR_NAME],
|
staticDirectories: [STATIC_DIR_NAME],
|
||||||
};
|
};
|
||||||
|
@ -192,7 +194,7 @@ export const ConfigSchema = Joi.object({
|
||||||
}).unknown(),
|
}).unknown(),
|
||||||
),
|
),
|
||||||
clientModules: Joi.array().items(Joi.string()),
|
clientModules: Joi.array().items(Joi.string()),
|
||||||
tagline: Joi.string().allow(''),
|
tagline: Joi.string().allow('').default(DEFAULT_CONFIG.tagline),
|
||||||
titleDelimiter: Joi.string().default('|'),
|
titleDelimiter: Joi.string().default('|'),
|
||||||
noIndex: Joi.bool().default(false),
|
noIndex: Joi.bool().default(false),
|
||||||
webpack: Joi.object({
|
webpack: Joi.object({
|
||||||
|
|
|
@ -24,23 +24,23 @@ Object {
|
||||||
"@generated": "../../../../../../..",
|
"@generated": "../../../../../../..",
|
||||||
"@site": "",
|
"@site": "",
|
||||||
"@theme-init/PluginThemeComponentEnhanced": "pluginThemeFolder/PluginThemeComponentEnhanced.js",
|
"@theme-init/PluginThemeComponentEnhanced": "pluginThemeFolder/PluginThemeComponentEnhanced.js",
|
||||||
"@theme-original/Error": "../../../../client/theme-fallback/Error/index.js",
|
"@theme-original/Error": "../../../../client/theme-fallback/Error/index.tsx",
|
||||||
"@theme-original/Layout": "../../../../client/theme-fallback/Layout/index.js",
|
"@theme-original/Layout": "../../../../client/theme-fallback/Layout/index.tsx",
|
||||||
"@theme-original/Loading": "../../../../client/theme-fallback/Loading/index.js",
|
"@theme-original/Loading": "../../../../client/theme-fallback/Loading/index.tsx",
|
||||||
"@theme-original/NotFound": "../../../../client/theme-fallback/NotFound/index.js",
|
"@theme-original/NotFound": "../../../../client/theme-fallback/NotFound/index.tsx",
|
||||||
"@theme-original/PluginThemeComponent1": "pluginThemeFolder/PluginThemeComponent1.js",
|
"@theme-original/PluginThemeComponent1": "pluginThemeFolder/PluginThemeComponent1.js",
|
||||||
"@theme-original/PluginThemeComponentEnhanced": "secondPluginThemeFolder/PluginThemeComponentEnhanced.js",
|
"@theme-original/PluginThemeComponentEnhanced": "secondPluginThemeFolder/PluginThemeComponentEnhanced.js",
|
||||||
"@theme-original/PluginThemeComponentOverriddenByUser": "pluginThemeFolder/PluginThemeComponentOverriddenByUser.js",
|
"@theme-original/PluginThemeComponentOverriddenByUser": "pluginThemeFolder/PluginThemeComponentOverriddenByUser.js",
|
||||||
"@theme-original/Root": "../../../../client/theme-fallback/Root/index.js",
|
"@theme-original/Root": "../../../../client/theme-fallback/Root/index.tsx",
|
||||||
"@theme-original/subfolder/PluginThemeComponent2": "pluginThemeFolder/subfolder/PluginThemeComponent2.js",
|
"@theme-original/subfolder/PluginThemeComponent2": "pluginThemeFolder/subfolder/PluginThemeComponent2.js",
|
||||||
"@theme/Error": "../../../../client/theme-fallback/Error/index.js",
|
"@theme/Error": "../../../../client/theme-fallback/Error/index.tsx",
|
||||||
"@theme/Layout": "../../../../client/theme-fallback/Layout/index.js",
|
"@theme/Layout": "../../../../client/theme-fallback/Layout/index.tsx",
|
||||||
"@theme/Loading": "../../../../client/theme-fallback/Loading/index.js",
|
"@theme/Loading": "../../../../client/theme-fallback/Loading/index.tsx",
|
||||||
"@theme/NotFound": "../../../../client/theme-fallback/NotFound/index.js",
|
"@theme/NotFound": "../../../../client/theme-fallback/NotFound/index.tsx",
|
||||||
"@theme/PluginThemeComponent1": "pluginThemeFolder/PluginThemeComponent1.js",
|
"@theme/PluginThemeComponent1": "pluginThemeFolder/PluginThemeComponent1.js",
|
||||||
"@theme/PluginThemeComponentEnhanced": "src/theme/PluginThemeComponentEnhanced.js",
|
"@theme/PluginThemeComponentEnhanced": "src/theme/PluginThemeComponentEnhanced.js",
|
||||||
"@theme/PluginThemeComponentOverriddenByUser": "src/theme/PluginThemeComponentOverriddenByUser.js",
|
"@theme/PluginThemeComponentOverriddenByUser": "src/theme/PluginThemeComponentOverriddenByUser.js",
|
||||||
"@theme/Root": "../../../../client/theme-fallback/Root/index.js",
|
"@theme/Root": "../../../../client/theme-fallback/Root/index.tsx",
|
||||||
"@theme/UserThemeComponent1": "src/theme/UserThemeComponent1.js",
|
"@theme/UserThemeComponent1": "src/theme/UserThemeComponent1.js",
|
||||||
"@theme/subfolder/PluginThemeComponent2": "pluginThemeFolder/subfolder/PluginThemeComponent2.js",
|
"@theme/subfolder/PluginThemeComponent2": "pluginThemeFolder/subfolder/PluginThemeComponent2.js",
|
||||||
"@theme/subfolder/UserThemeComponent2": "src/theme/subfolder/UserThemeComponent2.js",
|
"@theme/subfolder/UserThemeComponent2": "src/theme/subfolder/UserThemeComponent2.js",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"tsBuildInfoFile": "./lib/client/.tsbuildinfo",
|
"tsBuildInfoFile": "./lib/client/.tsbuildinfo",
|
||||||
"rootDir": "src/client",
|
"rootDir": "src/client",
|
||||||
"outDir": "lib/client",
|
"outDir": "lib/client",
|
||||||
"jsx": "react"
|
"jsx": "react-native"
|
||||||
},
|
},
|
||||||
"include": ["src/client", "src/deps.d.ts"]
|
"include": ["src/client", "src/deps.d.ts"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue