diff --git a/packages/docusaurus-mdx-loader/src/types.d.ts b/packages/docusaurus-mdx-loader/deps.d.ts similarity index 65% rename from packages/docusaurus-mdx-loader/src/types.d.ts rename to packages/docusaurus-mdx-loader/deps.d.ts index 9de9ebab64..f54cac9f35 100644 --- a/packages/docusaurus-mdx-loader/src/types.d.ts +++ b/packages/docusaurus-mdx-loader/deps.d.ts @@ -5,20 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -declare module '@docusaurus/mdx-loader' { - import type {Plugin} from 'unified'; - - export type RemarkOrRehypePlugin = - // eslint-disable-next-line @typescript-eslint/no-explicit-any - [Plugin, Record] | Plugin; - export type RemarkAndRehypePluginOptions = { - remarkPlugins: RemarkOrRehypePlugin[]; - rehypePlugins: RemarkOrRehypePlugin[]; - beforeDefaultRemarkPlugins: RemarkOrRehypePlugin[]; - beforeDefaultRehypePlugins: RemarkOrRehypePlugin[]; - }; -} - // TODO Types provided by MDX 2.0 https://github.com/mdx-js/mdx/blob/main/packages/mdx/types/index.d.ts declare module '@mdx-js/mdx' { import type {Processor} from 'unified'; diff --git a/packages/docusaurus-mdx-loader/package.json b/packages/docusaurus-mdx-loader/package.json index 25ee47fa79..49f537ea10 100644 --- a/packages/docusaurus-mdx-loader/package.json +++ b/packages/docusaurus-mdx-loader/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.9", "description": "Docusaurus Loader for MDX", "main": "lib/index.js", - "types": "src/types.d.ts", + "types": "src/mdx-loader.d.ts", "publishConfig": { "access": "public" }, diff --git a/packages/docusaurus-mdx-loader/src/mdx-loader.d.ts b/packages/docusaurus-mdx-loader/src/mdx-loader.d.ts new file mode 100644 index 0000000000..99d781b436 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/mdx-loader.d.ts @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import type {Plugin} from 'unified'; + +export type RemarkOrRehypePlugin = + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [Plugin, Record] | Plugin; +export type RemarkAndRehypePluginOptions = { + remarkPlugins: RemarkOrRehypePlugin[]; + rehypePlugins: RemarkOrRehypePlugin[]; + beforeDefaultRemarkPlugins: RemarkOrRehypePlugin[]; + beforeDefaultRehypePlugins: RemarkOrRehypePlugin[]; +}; diff --git a/packages/docusaurus-mdx-loader/tsconfig.json b/packages/docusaurus-mdx-loader/tsconfig.json index c85b6f7893..f5902ba108 100644 --- a/packages/docusaurus-mdx-loader/tsconfig.json +++ b/packages/docusaurus-mdx-loader/tsconfig.json @@ -5,6 +5,5 @@ "tsBuildInfoFile": "./lib/.tsbuildinfo", "rootDir": "src", "outDir": "lib" - }, - "include": ["src/"] + } } diff --git a/packages/docusaurus-plugin-content-blog/types.d.ts b/packages/docusaurus-plugin-content-blog/deps.d.ts similarity index 100% rename from packages/docusaurus-plugin-content-blog/types.d.ts rename to packages/docusaurus-plugin-content-blog/deps.d.ts diff --git a/packages/docusaurus-plugin-content-docs/types.d.ts b/packages/docusaurus-plugin-content-docs/deps.d.ts similarity index 100% rename from packages/docusaurus-plugin-content-docs/types.d.ts rename to packages/docusaurus-plugin-content-docs/deps.d.ts diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index 74970360ec..a87e639f11 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -51,7 +51,7 @@ import { } from './translations'; import chalk from 'chalk'; import {getVersionTags} from './tags'; -import {PropTagsListPage} from '@docusaurus/plugin-content-docs-types'; +import type {PropTagsListPage} from '@docusaurus/plugin-content-docs'; export default function pluginContentDocs( context: LoadContext, diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index d856c18da0..1a5f310435 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -8,10 +8,6 @@ declare module '@docusaurus/plugin-content-docs' { export type Options = Partial; export type SidebarsConfig = import('./sidebars/types').SidebarsConfig; -} - -// TODO public api surface types should rather be exposed as "@docusaurus/plugin-content-docs" -declare module '@docusaurus/plugin-content-docs-types' { export type VersionBanner = import('./types').VersionBanner; type GlobalDataVersion = import('./types').GlobalVersion; type GlobalDataDoc = import('./types').GlobalDoc; @@ -60,7 +56,7 @@ declare module '@docusaurus/plugin-content-docs-types' { declare module '@theme/DocItem' { import type {TOCItem} from '@docusaurus/types'; - import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types'; + import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; export type DocumentRoute = { readonly component: () => JSX.Element; @@ -122,14 +118,14 @@ declare module '@theme/DocItemFooter' { } declare module '@theme/DocTagsListPage' { - import type {PropTagsListPage} from '@docusaurus/plugin-content-docs-types'; + import type {PropTagsListPage} from '@docusaurus/plugin-content-docs'; export interface Props extends PropTagsListPage {} export default function DocTagsListPage(props: Props): JSX.Element; } declare module '@theme/DocTagDocListPage' { - import type {PropTagDocList} from '@docusaurus/plugin-content-docs-types'; + import type {PropTagDocList} from '@docusaurus/plugin-content-docs'; export interface Props { readonly tag: PropTagDocList; @@ -138,7 +134,7 @@ declare module '@theme/DocTagDocListPage' { } declare module '@theme/DocVersionBanner' { - import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types'; + import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; export interface Props { readonly versionMetadata: PropVersionMetadata; @@ -149,7 +145,7 @@ declare module '@theme/DocVersionBanner' { } declare module '@theme/DocPage' { - import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types'; + import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; import type {DocumentRoute} from '@theme/DocItem'; export interface Props { diff --git a/packages/docusaurus-plugin-content-docs/src/props.ts b/packages/docusaurus-plugin-content-docs/src/props.ts index d02342d44f..4c45d7f451 100644 --- a/packages/docusaurus-plugin-content-docs/src/props.ts +++ b/packages/docusaurus-plugin-content-docs/src/props.ts @@ -17,7 +17,7 @@ import type { PropSidebarItem, PropTagDocList, PropTagDocListDoc, -} from '@docusaurus/plugin-content-docs-types'; +} from '@docusaurus/plugin-content-docs'; import {compact, keyBy, mapValues} from 'lodash'; export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars { diff --git a/packages/docusaurus-plugin-debug/package.json b/packages/docusaurus-plugin-debug/package.json index 4a4d357de0..2cefc20714 100644 --- a/packages/docusaurus-plugin-debug/package.json +++ b/packages/docusaurus-plugin-debug/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.9", "description": "Debug plugin for Docusaurus.", "main": "lib/index.js", - "types": "src/types.d.ts", + "types": "src/plugin-debug.d.ts", "scripts": { "build": "tsc && node copyUntypedFiles.js", "watch": "node copyUntypedFiles.js && tsc --watch" diff --git a/packages/docusaurus-plugin-debug/src/types.d.ts b/packages/docusaurus-plugin-debug/src/plugin-debug.d.ts similarity index 100% rename from packages/docusaurus-plugin-debug/src/types.d.ts rename to packages/docusaurus-plugin-debug/src/plugin-debug.d.ts diff --git a/packages/docusaurus-plugin-google-gtag/src/types.d.ts b/packages/docusaurus-plugin-google-gtag/src/types.d.ts index 6e58d2ecb8..980a785d26 100644 --- a/packages/docusaurus-plugin-google-gtag/src/types.d.ts +++ b/packages/docusaurus-plugin-google-gtag/src/types.d.ts @@ -5,10 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -/* eslint-disable camelcase */ /// interface Window { + /* eslint-disable camelcase */ gtag: ( command: string, fields: string, @@ -18,4 +18,5 @@ interface Window { page_path?: string; }, ) => void; + /* eslint-enable camelcase */ } diff --git a/packages/docusaurus-utils/src/types.d.ts b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts similarity index 62% rename from packages/docusaurus-utils/src/types.d.ts rename to packages/docusaurus-plugin-ideal-image/src/deps.d.ts index 79a7896f34..cd4f47b6a7 100644 --- a/packages/docusaurus-utils/src/types.d.ts +++ b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts @@ -5,6 +5,4 @@ * LICENSE file in the root directory of this source tree. */ -declare module 'resolve-pathname' { - export default function resolvePathname(to: string, from?: string): string; -} +declare module '@endiliey/react-ideal-image'; diff --git a/packages/docusaurus-plugin-ideal-image/src/plugin-ideal-image.d.ts b/packages/docusaurus-plugin-ideal-image/src/plugin-ideal-image.d.ts index 6e2a3eff21..87fe545796 100644 --- a/packages/docusaurus-plugin-ideal-image/src/plugin-ideal-image.d.ts +++ b/packages/docusaurus-plugin-ideal-image/src/plugin-ideal-image.d.ts @@ -46,5 +46,3 @@ declare module '@theme/IdealImage' { } export default function IdealImage(props: Props): JSX.Element; } - -declare module '@endiliey/react-ideal-image'; diff --git a/packages/docusaurus-theme-classic/package.json b/packages/docusaurus-theme-classic/package.json index 13b7dc4dbc..c4e4e8a5b5 100644 --- a/packages/docusaurus-theme-classic/package.json +++ b/packages/docusaurus-theme-classic/package.json @@ -3,7 +3,7 @@ "version": "2.0.0-beta.9", "description": "Classic theme for Docusaurus", "main": "lib/index.js", - "types": "src/types.d.ts", + "types": "src/theme-classic.d.ts", "publishConfig": { "access": "public" }, @@ -30,7 +30,6 @@ "@docusaurus/theme-common": "2.0.0-beta.9", "@docusaurus/types": "2.0.0-beta.9", "@docusaurus/utils": "2.0.0-beta.9", - "@docusaurus/utils-common": "2.0.0-beta.9", "@docusaurus/utils-validation": "2.0.0-beta.9", "@mdx-js/mdx": "^1.6.21", "@mdx-js/react": "^1.6.21", diff --git a/packages/docusaurus-theme-classic/src/deps.d.ts b/packages/docusaurus-theme-classic/src/deps.d.ts new file mode 100644 index 0000000000..8a6a9f1eb2 --- /dev/null +++ b/packages/docusaurus-theme-classic/src/deps.d.ts @@ -0,0 +1,13 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +declare module 'prism-react-renderer/prism' { + import type * as PrismNamespace from 'prismjs'; + + const Prism: typeof PrismNamespace; + export default Prism; +} diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts new file mode 100644 index 0000000000..20e068fc41 --- /dev/null +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -0,0 +1,805 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +declare module '@docusaurus/theme-classic' { + export type Options = Partial; +} + +declare module '@theme/AnnouncementBar' { + const AnnouncementBar: () => JSX.Element | null; + export default AnnouncementBar; +} + +declare module '@theme/BackToTopButton' { + export default function BackToTopButton(): JSX.Element; +} + +declare module '@theme/BlogListPaginator' { + import type {Metadata} from '@theme/BlogListPage'; + + export interface Props { + readonly metadata: Metadata; + } + + const BlogListPaginator: (props: Props) => JSX.Element; + export default BlogListPaginator; +} + +declare module '@theme/BlogPostItem' { + import type {FrontMatter, Assets, Metadata} from '@theme/BlogPostPage'; + + export interface Props { + readonly frontMatter: FrontMatter; + readonly assets: Assets; + readonly metadata: Metadata; + readonly truncated?: string | boolean; + readonly isBlogPostPage?: boolean; + readonly children: JSX.Element; + } + + const BlogPostItem: (props: Props) => JSX.Element; + export default BlogPostItem; +} + +declare module '@theme/BlogPostAuthor' { + import type {Metadata} from '@theme/BlogPostPage'; + + export interface Props { + readonly author: Metadata['authors'][number]; + } + + export default function BlogPostAuthor(props: Props): JSX.Element; +} + +declare module '@theme/BlogPostAuthors' { + import type {Metadata, Assets} from '@theme/BlogPostPage'; + + export interface Props { + readonly authors: Metadata['authors']; + readonly assets: Assets; + } + + export default function BlogPostAuthors(props: Props): JSX.Element; +} + +declare module '@theme/BlogPostPaginator' { + type Item = {readonly title: string; readonly permalink: string}; + + export interface Props { + readonly nextItem?: Item; + readonly prevItem?: Item; + } + + const BlogPostPaginator: (props: Props) => JSX.Element; + export default BlogPostPaginator; +} + +declare module '@theme/BlogLayout' { + import type {ReactNode} from 'react'; + import type {Props as LayoutProps} from '@theme/Layout'; + import type {BlogSidebar} from '@theme/BlogSidebar'; + + export interface Props extends LayoutProps { + readonly sidebar?: BlogSidebar; + readonly toc?: ReactNode; + } + + const BlogLayout: (props: Props) => JSX.Element; + export default BlogLayout; +} + +declare module '@theme/CodeBlock' { + import {ReactElement} from 'react'; + + export interface Props { + readonly children: string | ReactElement; + readonly className?: string; + readonly metastring?: string; + readonly title?: string; + } + + const CodeBlock: (props: Props) => JSX.Element; + export default CodeBlock; +} + +declare module '@theme/DocPaginator' { + type PageInfo = {readonly permalink: string; readonly title: string}; + + export interface Props { + readonly metadata: {readonly previous?: PageInfo; readonly next?: PageInfo}; + } + + const DocPaginator: (props: Props) => JSX.Element; + export default DocPaginator; +} + +declare module '@theme/DocSidebar' { + import type {PropSidebarItem} from '@docusaurus/plugin-content-docs'; + + export interface Props { + readonly path: string; + readonly sidebar: readonly PropSidebarItem[]; + readonly onCollapse: () => void; + readonly isHidden: boolean; + // MobileSecondaryFilter expects Record + readonly [key: string]: unknown; + } + + const DocSidebar: (props: Props) => JSX.Element; + export default DocSidebar; +} + +declare module '@theme/DocSidebarItem' { + import type {PropSidebarItem} from '@docusaurus/plugin-content-docs'; + + type DocSidebarPropsBase = { + readonly activePath: string; + readonly onItemClick?: () => void; + readonly level: number; + readonly tabIndex?: number; + }; + + export interface Props extends DocSidebarPropsBase { + readonly item: PropSidebarItem; + } + const DocSidebarItem: (props: Props) => JSX.Element; + export default DocSidebarItem; + + export type DocSidebarItemsProps = DocSidebarPropsBase & { + readonly items: readonly PropSidebarItem[]; + }; + export const DocSidebarItems: (props: DocSidebarItemsProps) => JSX.Element; +} + +declare module '@theme/DocVersionSuggestions' { + const DocVersionSuggestions: () => JSX.Element; + export default DocVersionSuggestions; +} + +declare module '@theme/EditThisPage' { + export interface Props { + readonly editUrl: string; + } + const EditThisPage: (props: Props) => JSX.Element; + export default EditThisPage; +} + +declare module '@theme/ErrorPageContent' { + import ErrorComponent from '@theme/Error'; + + const ErrorPageContent: typeof ErrorComponent; + export default ErrorPageContent; +} + +declare module '@theme/Footer' { + const Footer: () => JSX.Element | null; + export default Footer; +} + +declare module '@theme/Heading' { + import type {ComponentProps} from 'react'; + + export type HeadingType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; + export interface Props extends ComponentProps {} + + const Heading: (Tag: HeadingType) => (props: Props) => JSX.Element; + export default Heading; + export const MainHeading: (props: Props) => JSX.Element; +} + +declare module '@theme/hooks/useHideableNavbar' { + export type useHideableNavbarReturns = { + readonly navbarRef: (node: HTMLElement | null) => void; + readonly isNavbarVisible: boolean; + }; + + const useHideableNavbar: (hideOnScroll: boolean) => useHideableNavbarReturns; + export default useHideableNavbar; +} + +declare module '@theme/hooks/useLocationHash' { + import type {Dispatch, SetStateAction} from 'react'; + + export type useLocationHashReturns = readonly [ + string, + Dispatch>, + ]; + + const useLocationHash: (initialHash: string) => useLocationHashReturns; + export default useLocationHash; +} + +declare module '@theme/hooks/useLockBodyScroll' { + const useLockBodyScroll: (lock?: boolean) => void; + export default useLockBodyScroll; +} + +declare module '@theme/hooks/usePrismTheme' { + import defaultTheme from 'prism-react-renderer/themes/palenight'; + + const usePrismTheme: () => typeof defaultTheme; + export default usePrismTheme; +} + +declare module '@theme/hooks/useTabGroupChoice' { + export type useTabGroupChoiceReturns = { + readonly tabGroupChoices: {readonly [groupId: string]: string}; + readonly setTabGroupChoices: (groupId: string, newChoice: string) => void; + }; + + const useTabGroupChoice: () => useTabGroupChoiceReturns; + export default useTabGroupChoice; +} + +declare module '@theme/hooks/useTheme' { + export type useThemeReturns = { + readonly isDarkTheme: boolean; + readonly setLightTheme: () => void; + readonly setDarkTheme: () => void; + }; + + const useTheme: () => useThemeReturns; + export default useTheme; +} + +declare module '@theme/hooks/useThemeContext' { + export type ThemeContextProps = { + isDarkTheme: boolean; + setLightTheme: () => void; + setDarkTheme: () => void; + }; + + export default function useThemeContext(): ThemeContextProps; +} + +declare module '@theme/hooks/useUserPreferencesContext' { + export type UserPreferencesContextProps = { + tabGroupChoices: {readonly [groupId: string]: string}; + setTabGroupChoices: (groupId: string, newChoice: string) => void; + }; + + export default function useUserPreferencesContext(): UserPreferencesContextProps; +} + +declare module '@theme/hooks/useWindowSize' { + export const windowSizes: { + desktop: 'desktop'; + mobile: 'mobile'; + ssr: 'ssr'; + }; + + export type WindowSize = keyof typeof windowSizes; + + export default function useWindowSize(): WindowSize; +} + +declare module '@theme/hooks/useKeyboardNavigation' { + const useKeyboardNavigation: () => void; + + export default useKeyboardNavigation; +} + +declare module '@theme/Layout' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + readonly title?: string; + readonly noFooter?: boolean; + readonly description?: string; + readonly image?: string; + readonly keywords?: string | string[]; + readonly permalink?: string; + readonly wrapperClassName?: string; + readonly pageClassName?: string; + readonly searchMetadata?: { + readonly version?: string; + readonly tag?: string; + }; + } + + const Layout: (props: Props) => JSX.Element; + export default Layout; +} + +declare module '@theme/LayoutHead' { + import type {Props as LayoutProps} from '@theme/Layout'; + + export interface Props extends Omit {} + + const LayoutHead: (props: Props) => JSX.Element; + export default LayoutHead; +} + +declare module '@theme/SearchMetadata' { + export interface Props { + readonly locale?: string; + readonly version?: string; + readonly tag?: string; + } + + const SearchMetadata: (props: Props) => JSX.Element; + export default SearchMetadata; +} + +declare module '@theme/LastUpdated' { + export interface Props { + readonly lastUpdatedAt?: number; + readonly formattedLastUpdatedAt?: string; + readonly lastUpdatedBy?: string; + } + + const LastUpdated: (props: Props) => JSX.Element; + export default LastUpdated; +} + +declare module '@theme/SkipToContent' { + const SkipToContent: () => JSX.Element; + export default SkipToContent; +} + +declare module '@theme/MDXComponents' { + import type {ComponentProps} from 'react'; + import type CodeBlock from '@theme/CodeBlock'; + import type Head from '@docusaurus/Head'; + + export type MDXComponentsObject = { + readonly head: typeof Head; + readonly code: typeof CodeBlock; + readonly a: (props: ComponentProps<'a'>) => JSX.Element; + readonly pre: typeof CodeBlock; + readonly details: (props: ComponentProps<'details'>) => JSX.Element; + readonly h1: (props: ComponentProps<'h1'>) => JSX.Element; + readonly h2: (props: ComponentProps<'h2'>) => JSX.Element; + readonly h3: (props: ComponentProps<'h3'>) => JSX.Element; + readonly h4: (props: ComponentProps<'h4'>) => JSX.Element; + readonly h5: (props: ComponentProps<'h5'>) => JSX.Element; + readonly h6: (props: ComponentProps<'h6'>) => JSX.Element; + }; + + const MDXComponents: MDXComponentsObject; + export default MDXComponents; +} + +declare module '@theme/Navbar' { + const Navbar: () => JSX.Element; + export default Navbar; +} + +declare module '@theme/NavbarItem/DefaultNavbarItem' { + import type {ReactNode} from 'react'; + import type {LinkProps} from '@docusaurus/Link'; + + export type NavLinkProps = LinkProps & { + readonly activeBasePath?: string; + readonly activeBaseRegex?: string; + readonly exact?: boolean; + readonly label?: ReactNode; + readonly prependBaseUrlToHref?: string; + }; + + export type DesktopOrMobileNavBarItemProps = NavLinkProps & { + readonly isDropdownItem?: boolean; + readonly className?: string; + readonly position?: 'left' | 'right'; + }; + + export interface Props extends DesktopOrMobileNavBarItemProps { + readonly mobile?: boolean; + } + + export const NavLink: (props: NavLinkProps) => JSX.Element; + + const DefaultNavbarItem: (props: Props) => JSX.Element; + export default DefaultNavbarItem; +} + +declare module '@theme/NavbarItem/DropdownNavbarItem' { + import type {NavLinkProps} from '@theme/NavbarItem/DefaultNavbarItem'; + import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; + + export type DesktopOrMobileNavBarItemProps = NavLinkProps & { + readonly position?: 'left' | 'right'; + readonly items: readonly LinkLikeNavbarItemProps[]; + readonly className?: string; + }; + + export interface Props extends DesktopOrMobileNavBarItemProps { + readonly mobile?: boolean; + } + + const DropdownNavbarItem: (props: Props) => JSX.Element; + export default DropdownNavbarItem; +} + +declare module '@theme/NavbarItem/SearchNavbarItem' { + export interface Props { + readonly mobile?: boolean; + } + + const SearchNavbarItem: (props: Props) => JSX.Element; + export default SearchNavbarItem; +} + +declare module '@theme/NavbarItem/LocaleDropdownNavbarItem' { + import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; + import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; + + export interface Props extends DropdownNavbarItemProps { + readonly dropdownItemsBefore: LinkLikeNavbarItemProps[]; + readonly dropdownItemsAfter: LinkLikeNavbarItemProps[]; + } + + const LocaleDropdownNavbarItem: (props: Props) => JSX.Element; + export default LocaleDropdownNavbarItem; +} + +declare module '@theme/NavbarItem/DocsVersionDropdownNavbarItem' { + import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; + import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; + + export interface Props extends DropdownNavbarItemProps { + readonly docsPluginId?: string; + readonly dropdownActiveClassDisabled?: boolean; + readonly dropdownItemsBefore: LinkLikeNavbarItemProps[]; + readonly dropdownItemsAfter: LinkLikeNavbarItemProps[]; + } + + const DocsVersionDropdownNavbarItem: (props: Props) => JSX.Element; + export default DocsVersionDropdownNavbarItem; +} + +declare module '@theme/NavbarItem/DocsVersionNavbarItem' { + import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; + + export interface Props extends DefaultNavbarItemProps { + readonly docsPluginId?: string; + } + + const DocsVersionNavbarItem: (props: Props) => JSX.Element; + export default DocsVersionNavbarItem; +} + +declare module '@theme/NavbarItem/DocNavbarItem' { + import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; + + export interface Props extends DefaultNavbarItemProps { + readonly docId: string; + readonly docsPluginId?: string; + } + + const DocsSidebarNavbarItem: (props: Props) => JSX.Element; + export default DocsSidebarNavbarItem; +} + +declare module '@theme/NavbarItem' { + import type {ComponentProps} from 'react'; + import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; + import type {Props as DocNavbarItemProps} from '@theme/NavbarItem/DocNavbarItem'; + import type {Props as DocsVersionNavbarItemProps} from '@theme/NavbarItem/DocsVersionNavbarItem'; + import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; + import type {Props as DocsVersionDropdownNavbarItemProps} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; + import type {Props as LocaleDropdownNavbarItemProps} from '@theme/NavbarItem/LocaleDropdownNavbarItem'; + import type {Props as SearchNavbarItemProps} from '@theme/NavbarItem/SearchNavbarItem'; + + export type LinkLikeNavbarItemProps = + | ({readonly type?: 'default'} & DefaultNavbarItemProps) + | ({readonly type: 'doc'} & DocNavbarItemProps) + | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps); + + export type Props = ComponentProps<'a'> & { + readonly position?: 'left' | 'right'; + } & ( + | LinkLikeNavbarItemProps + | ({readonly type?: 'dropdown'} & DropdownNavbarItemProps) + | ({ + readonly type: 'docsVersionDropdown'; + } & DocsVersionDropdownNavbarItemProps) + | ({readonly type: 'localeDropdown'} & LocaleDropdownNavbarItemProps) + | ({ + readonly type: 'search'; + } & SearchNavbarItemProps) + ); + + export type Types = Props['type']; + + const NavbarItem: (props: Props) => JSX.Element; + export default NavbarItem; +} + +declare module '@theme/SearchBar' { + export default function SearchBar(): JSX.Element; +} + +declare module '@theme/TabItem' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + readonly value: string; + readonly default?: boolean; + readonly label?: string; + readonly hidden?: boolean; + readonly className?: string; + } + + const TabItem: (props: Props) => JSX.Element; + export default TabItem; +} + +declare module '@theme/Tabs' { + import type {ReactElement} from 'react'; + import type {Props as TabItemProps} from '@theme/TabItem'; + + export interface Props { + readonly lazy?: boolean; + readonly block?: boolean; + readonly children: readonly ReactElement[]; + readonly defaultValue?: string | null; + readonly values?: readonly {value: string; label?: string}[]; + readonly groupId?: string; + readonly className?: string; + } + + const Tabs: (props: Props) => JSX.Element; + export default Tabs; +} + +declare module '@theme/ThemedImage' { + import type {ComponentProps} from 'react'; + + export interface Props extends Omit, 'src'> { + readonly sources: { + readonly light: string; + readonly dark: string; + }; + } + + const ThemedImage: (props: Props) => JSX.Element; + export default ThemedImage; +} + +declare module '@theme/Details' { + import {Details, DetailsProps} from '@docusaurus/theme-common'; + + export interface Props extends DetailsProps {} + export default Details; +} + +declare module '@theme/ThemeProvider' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + } + + const ThemeProvider: (props: Props) => JSX.Element; + export default ThemeProvider; +} + +declare module '@theme/TOCItems' { + import type {TOCItem} from '@docusaurus/types'; + + export type TOCItemsProps = { + readonly toc: readonly TOCItem[]; + readonly minHeadingLevel?: number; + readonly maxHeadingLevel?: number; + readonly className?: string; + readonly linkClassName?: string | null; + readonly linkActiveClassName?: string; + }; + + export default function TOCItems(props: TOCItemsProps): JSX.Element; +} + +declare module '@theme/TOC' { + import type {TOCItem} from '@docusaurus/types'; + + // minHeadingLevel only exists as a per-doc option, + // and won't have a default set by Joi. See TOC, TOCInline, + // TOCCollapsible for examples + export type TOCProps = { + readonly toc: readonly TOCItem[]; + readonly minHeadingLevel?: number; + readonly maxHeadingLevel?: number; + readonly className?: string; + }; + + export type TOCHeadingsProps = { + readonly toc: readonly TOCItem[]; + readonly minHeadingLevel?: number; + readonly maxHeadingLevel?: number; + }; + + export const TOCHeadings: (props: TOCHeadingsProps) => JSX.Element; + + const TOC: (props: TOCProps) => JSX.Element; + export default TOC; +} + +declare module '@theme/TOCInline' { + import type {TOCItem} from '@docusaurus/types'; + + export type TOCInlineProps = { + readonly toc: readonly TOCItem[]; + readonly minHeadingLevel?: number; + readonly maxHeadingLevel?: number; + }; + + const TOCInline: (props: TOCInlineProps) => JSX.Element; + export default TOCInline; +} + +declare module '@theme/TOCCollapsible' { + import type {TOCItem} from '@docusaurus/types'; + + export type TOCCollapsibleProps = { + readonly className?: string; + readonly minHeadingLevel?: number; + readonly maxHeadingLevel?: number; + readonly toc: readonly TOCItem[]; + }; + + const TOCCollapsible: (props: TOCCollapsibleProps) => JSX.Element; + export default TOCCollapsible; +} + +declare module '@theme/Toggle' { + import type {SyntheticEvent} from 'react'; + + export interface Props { + readonly className?: string; + readonly checked: boolean; + readonly onChange: (e: SyntheticEvent) => void; + } + + const Toggle: (props: Props) => JSX.Element; + export default Toggle; +} + +declare module '@theme/UserPreferencesProvider' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + } + + const UserPreferencesProvider: (props: Props) => JSX.Element; + export default UserPreferencesProvider; +} + +declare module '@theme/LayoutProviders' { + import type {ReactNode} from 'react'; + + export interface Props { + readonly children: ReactNode; + } + + const LayoutProviders: (props: Props) => JSX.Element; + export default LayoutProviders; +} + +declare module '@theme/ThemeContext' { + import type {Context} from 'react'; + import type {ThemeContextProps} from '@theme/hooks/useThemeContext'; + + const ThemeContext: Context; + export default ThemeContext; +} + +declare module '@theme/UserPreferencesContext' { + import type {Context} from 'react'; + import type {UserPreferencesContextProps} from '@theme/hooks/useUserPreferencesContext'; + + const UserPreferencesContext: Context< + UserPreferencesContextProps | undefined + >; + export default UserPreferencesContext; +} + +declare module '@theme/Logo' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'a'> { + readonly imageClassName?: string; + readonly titleClassName?: string; + } + + const Logo: (props: Props) => JSX.Element; + export default Logo; +} + +declare module '@theme/IconArrow' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconArrow: (props: Props) => JSX.Element; + export default IconArrow; +} + +declare module '@theme/IconEdit' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconEdit: (props: Props) => JSX.Element; + export default IconEdit; +} + +declare module '@theme/IconMenu' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconMenu: (props: Props) => JSX.Element; + export default IconMenu; +} + +declare module '@theme/IconClose' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconClose: (props: Props) => JSX.Element; + export default IconClose; +} + +declare module '@theme/IconLanguage' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconLanguage: (props: Props) => JSX.Element; + export default IconLanguage; +} + +declare module '@theme/IconExternalLink' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'svg'> {} + + const IconExternalLink: (props: Props) => JSX.Element; + export default IconExternalLink; +} + +declare module '@theme/TagsListByLetter' { + export type TagsListItem = Readonly<{ + name: string; + permalink: string; + count: number; + }>; + export interface Props { + readonly tags: readonly TagsListItem[]; + } + export default function TagsListByLetter(props: Props): JSX.Element; +} + +declare module '@theme/TagsListInline' { + export type Tag = Readonly<{label: string; permalink: string}>; + export interface Props { + readonly tags: readonly Tag[]; + } + export default function TagsListInline(props: Props): JSX.Element; +} + +declare module '@theme/Tag' { + import type {TagsListItem} from '@theme/TagsListByLetter'; + import type {Optional} from 'utility-types'; + + export interface Props extends Optional {} + + export default function Tag(props: Props): JSX.Element; +} + +declare module '@theme/prism-include-languages' { + import type * as PrismNamespace from 'prismjs'; + + export default function prismIncludeLanguages( + PrismObject: typeof PrismNamespace, + ): void; +} diff --git a/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx index 6c66c5f651..478de29c64 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocPage/index.tsx @@ -9,7 +9,7 @@ import React, {ReactNode, useState, useCallback} from 'react'; import {MDXProvider} from '@mdx-js/react'; import renderRoutes from '@docusaurus/renderRoutes'; -import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs-types'; +import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; import Layout from '@theme/Layout'; import DocSidebar from '@theme/DocSidebar'; import MDXComponents from '@theme/MDXComponents'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/index.tsx index 59a2d2a330..4bded1fc41 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/index.tsx @@ -22,7 +22,7 @@ import type {Props, DocSidebarItemsProps} from '@theme/DocSidebarItem'; import type { PropSidebarItemCategory, PropSidebarItemLink, -} from '@docusaurus/plugin-content-docs-types'; +} from '@docusaurus/plugin-content-docs'; import styles from './styles.module.css'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocTagDocListPage/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocTagDocListPage/index.tsx index 1021a19805..23025464b6 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocTagDocListPage/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocTagDocListPage/index.tsx @@ -10,7 +10,7 @@ import React from 'react'; import Layout from '@theme/Layout'; import Link from '@docusaurus/Link'; import {ThemeClassNames, usePluralForm} from '@docusaurus/theme-common'; -import type {PropTagDocListDoc} from '@docusaurus/plugin-content-docs-types'; +import type {PropTagDocListDoc} from '@docusaurus/plugin-content-docs'; import Translate, {translate} from '@docusaurus/Translate'; import type {Props} from '@theme/DocTagDocListPage'; diff --git a/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx index 4456585e04..11eff4b0c4 100644 --- a/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/DocVersionBanner/index.tsx @@ -21,7 +21,7 @@ import { import type {Props} from '@theme/DocVersionBanner'; import clsx from 'clsx'; -import type {VersionBanner} from '@docusaurus/plugin-content-docs-types'; +import type {VersionBanner} from '@docusaurus/plugin-content-docs'; type BannerLabelComponentProps = { siteTitle: string; diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx index 30d0b15a6e..895efb3b77 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocNavbarItem.tsx @@ -11,9 +11,8 @@ import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs'; import clsx from 'clsx'; import {getInfimaActiveClassName} from './index'; import type {Props} from '@theme/NavbarItem/DocNavbarItem'; -import {useDocsPreferredVersion} from '@docusaurus/theme-common'; -import {uniq} from '@docusaurus/utils-common'; -import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs-types'; +import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common'; +import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs'; function getDocInVersions(versions: GlobalDataVersion[], docId: string) { const allDocs = versions.flatMap((version) => version.docs); diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx index 537fd32e8a..83803b843e 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx @@ -16,7 +16,7 @@ import { import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; import {useDocsPreferredVersion} from '@docusaurus/theme-common'; import {translate} from '@docusaurus/Translate'; -import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs-types'; +import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs'; const getVersionMainDoc = (version: GlobalDataVersion) => version.docs.find((doc) => doc.id === version.mainDocId)!; diff --git a/packages/docusaurus-theme-classic/src/types.d.ts b/packages/docusaurus-theme-classic/src/types.d.ts index e009a75d28..db5e128fd3 100644 --- a/packages/docusaurus-theme-classic/src/types.d.ts +++ b/packages/docusaurus-theme-classic/src/types.d.ts @@ -9,809 +9,3 @@ /// /// /// - -declare module '@docusaurus/theme-classic' { - export type Options = Partial; -} - -declare module '@theme/AnnouncementBar' { - const AnnouncementBar: () => JSX.Element | null; - export default AnnouncementBar; -} - -declare module '@theme/BackToTopButton' { - export default function BackToTopButton(): JSX.Element; -} - -declare module '@theme/BlogListPaginator' { - import type {Metadata} from '@theme/BlogListPage'; - - export interface Props { - readonly metadata: Metadata; - } - - const BlogListPaginator: (props: Props) => JSX.Element; - export default BlogListPaginator; -} - -declare module '@theme/BlogPostItem' { - import type {FrontMatter, Assets, Metadata} from '@theme/BlogPostPage'; - - export interface Props { - readonly frontMatter: FrontMatter; - readonly assets: Assets; - readonly metadata: Metadata; - readonly truncated?: string | boolean; - readonly isBlogPostPage?: boolean; - readonly children: JSX.Element; - } - - const BlogPostItem: (props: Props) => JSX.Element; - export default BlogPostItem; -} - -declare module '@theme/BlogPostAuthor' { - import type {Metadata} from '@theme/BlogPostPage'; - - export interface Props { - readonly author: Metadata['authors'][number]; - } - - export default function BlogPostAuthor(props: Props): JSX.Element; -} - -declare module '@theme/BlogPostAuthors' { - import type {Metadata, Assets} from '@theme/BlogPostPage'; - - export interface Props { - readonly authors: Metadata['authors']; - readonly assets: Assets; - } - - export default function BlogPostAuthors(props: Props): JSX.Element; -} - -declare module '@theme/BlogPostPaginator' { - type Item = {readonly title: string; readonly permalink: string}; - - export interface Props { - readonly nextItem?: Item; - readonly prevItem?: Item; - } - - const BlogPostPaginator: (props: Props) => JSX.Element; - export default BlogPostPaginator; -} - -declare module '@theme/BlogLayout' { - import type {ReactNode} from 'react'; - import type {Props as LayoutProps} from '@theme/Layout'; - import type {BlogSidebar} from '@theme/BlogSidebar'; - - export interface Props extends LayoutProps { - readonly sidebar?: BlogSidebar; - readonly toc?: ReactNode; - } - - const BlogLayout: (props: Props) => JSX.Element; - export default BlogLayout; -} - -declare module '@theme/CodeBlock' { - import {ReactElement} from 'react'; - - export interface Props { - readonly children: string | ReactElement; - readonly className?: string; - readonly metastring?: string; - readonly title?: string; - } - - const CodeBlock: (props: Props) => JSX.Element; - export default CodeBlock; -} - -declare module '@theme/DocPaginator' { - type PageInfo = {readonly permalink: string; readonly title: string}; - - export interface Props { - readonly metadata: {readonly previous?: PageInfo; readonly next?: PageInfo}; - } - - const DocPaginator: (props: Props) => JSX.Element; - export default DocPaginator; -} - -declare module '@theme/DocSidebar' { - import type {PropSidebarItem} from '@docusaurus/plugin-content-docs-types'; - - export interface Props { - readonly path: string; - readonly sidebar: readonly PropSidebarItem[]; - readonly onCollapse: () => void; - readonly isHidden: boolean; - // MobileSecondaryFilter expects Record - readonly [key: string]: unknown; - } - - const DocSidebar: (props: Props) => JSX.Element; - export default DocSidebar; -} - -declare module '@theme/DocSidebarItem' { - import type {PropSidebarItem} from '@docusaurus/plugin-content-docs-types'; - - type DocSidebarPropsBase = { - readonly activePath: string; - readonly onItemClick?: () => void; - readonly level: number; - readonly tabIndex?: number; - }; - - export interface Props extends DocSidebarPropsBase { - readonly item: PropSidebarItem; - } - const DocSidebarItem: (props: Props) => JSX.Element; - export default DocSidebarItem; - - export type DocSidebarItemsProps = DocSidebarPropsBase & { - readonly items: readonly PropSidebarItem[]; - }; - export const DocSidebarItems: (props: DocSidebarItemsProps) => JSX.Element; -} - -declare module '@theme/DocVersionSuggestions' { - const DocVersionSuggestions: () => JSX.Element; - export default DocVersionSuggestions; -} - -declare module '@theme/EditThisPage' { - export interface Props { - readonly editUrl: string; - } - const EditThisPage: (props: Props) => JSX.Element; - export default EditThisPage; -} - -declare module '@theme/ErrorPageContent' { - import ErrorComponent from '@theme/Error'; - - const ErrorPageContent: typeof ErrorComponent; - export default ErrorPageContent; -} - -declare module '@theme/Footer' { - const Footer: () => JSX.Element | null; - export default Footer; -} - -declare module '@theme/Heading' { - import type {ComponentProps} from 'react'; - - export type HeadingType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; - export interface Props extends ComponentProps {} - - const Heading: (Tag: HeadingType) => (props: Props) => JSX.Element; - export default Heading; - export const MainHeading: (props: Props) => JSX.Element; -} - -declare module '@theme/hooks/useHideableNavbar' { - export type useHideableNavbarReturns = { - readonly navbarRef: (node: HTMLElement | null) => void; - readonly isNavbarVisible: boolean; - }; - - const useHideableNavbar: (hideOnScroll: boolean) => useHideableNavbarReturns; - export default useHideableNavbar; -} - -declare module '@theme/hooks/useLocationHash' { - import type {Dispatch, SetStateAction} from 'react'; - - export type useLocationHashReturns = readonly [ - string, - Dispatch>, - ]; - - const useLocationHash: (initialHash: string) => useLocationHashReturns; - export default useLocationHash; -} - -declare module '@theme/hooks/useLockBodyScroll' { - const useLockBodyScroll: (lock?: boolean) => void; - export default useLockBodyScroll; -} - -declare module '@theme/hooks/usePrismTheme' { - import defaultTheme from 'prism-react-renderer/themes/palenight'; - - const usePrismTheme: () => typeof defaultTheme; - export default usePrismTheme; -} - -declare module '@theme/hooks/useTabGroupChoice' { - export type useTabGroupChoiceReturns = { - readonly tabGroupChoices: {readonly [groupId: string]: string}; - readonly setTabGroupChoices: (groupId: string, newChoice: string) => void; - }; - - const useTabGroupChoice: () => useTabGroupChoiceReturns; - export default useTabGroupChoice; -} - -declare module '@theme/hooks/useTheme' { - export type useThemeReturns = { - readonly isDarkTheme: boolean; - readonly setLightTheme: () => void; - readonly setDarkTheme: () => void; - }; - - const useTheme: () => useThemeReturns; - export default useTheme; -} - -declare module '@theme/hooks/useThemeContext' { - export type ThemeContextProps = { - isDarkTheme: boolean; - setLightTheme: () => void; - setDarkTheme: () => void; - }; - - export default function useThemeContext(): ThemeContextProps; -} - -declare module '@theme/hooks/useUserPreferencesContext' { - export type UserPreferencesContextProps = { - tabGroupChoices: {readonly [groupId: string]: string}; - setTabGroupChoices: (groupId: string, newChoice: string) => void; - }; - - export default function useUserPreferencesContext(): UserPreferencesContextProps; -} - -declare module '@theme/hooks/useWindowSize' { - export const windowSizes: { - desktop: 'desktop'; - mobile: 'mobile'; - ssr: 'ssr'; - }; - - export type WindowSize = keyof typeof windowSizes; - - export default function useWindowSize(): WindowSize; -} - -declare module '@theme/hooks/useKeyboardNavigation' { - const useKeyboardNavigation: () => void; - - export default useKeyboardNavigation; -} - -declare module '@theme/Layout' { - import type {ReactNode} from 'react'; - - export interface Props { - readonly children: ReactNode; - readonly title?: string; - readonly noFooter?: boolean; - readonly description?: string; - readonly image?: string; - readonly keywords?: string | string[]; - readonly permalink?: string; - readonly wrapperClassName?: string; - readonly pageClassName?: string; - readonly searchMetadata?: { - readonly version?: string; - readonly tag?: string; - }; - } - - const Layout: (props: Props) => JSX.Element; - export default Layout; -} - -declare module '@theme/LayoutHead' { - import type {Props as LayoutProps} from '@theme/Layout'; - - export interface Props extends Omit {} - - const LayoutHead: (props: Props) => JSX.Element; - export default LayoutHead; -} - -declare module '@theme/SearchMetadata' { - export interface Props { - readonly locale?: string; - readonly version?: string; - readonly tag?: string; - } - - const SearchMetadata: (props: Props) => JSX.Element; - export default SearchMetadata; -} - -declare module '@theme/LastUpdated' { - export interface Props { - readonly lastUpdatedAt?: number; - readonly formattedLastUpdatedAt?: string; - readonly lastUpdatedBy?: string; - } - - const LastUpdated: (props: Props) => JSX.Element; - export default LastUpdated; -} - -declare module '@theme/SkipToContent' { - const SkipToContent: () => JSX.Element; - export default SkipToContent; -} - -declare module '@theme/MDXComponents' { - import type {ComponentProps} from 'react'; - import type CodeBlock from '@theme/CodeBlock'; - import type Head from '@docusaurus/Head'; - - export type MDXComponentsObject = { - readonly head: typeof Head; - readonly code: typeof CodeBlock; - readonly a: (props: ComponentProps<'a'>) => JSX.Element; - readonly pre: typeof CodeBlock; - readonly details: (props: ComponentProps<'details'>) => JSX.Element; - readonly h1: (props: ComponentProps<'h1'>) => JSX.Element; - readonly h2: (props: ComponentProps<'h2'>) => JSX.Element; - readonly h3: (props: ComponentProps<'h3'>) => JSX.Element; - readonly h4: (props: ComponentProps<'h4'>) => JSX.Element; - readonly h5: (props: ComponentProps<'h5'>) => JSX.Element; - readonly h6: (props: ComponentProps<'h6'>) => JSX.Element; - }; - - const MDXComponents: MDXComponentsObject; - export default MDXComponents; -} - -declare module '@theme/Navbar' { - const Navbar: () => JSX.Element; - export default Navbar; -} - -declare module '@theme/NavbarItem/DefaultNavbarItem' { - import type {ReactNode} from 'react'; - import type {LinkProps} from '@docusaurus/Link'; - - export type NavLinkProps = LinkProps & { - readonly activeBasePath?: string; - readonly activeBaseRegex?: string; - readonly exact?: boolean; - readonly label?: ReactNode; - readonly prependBaseUrlToHref?: string; - }; - - export type DesktopOrMobileNavBarItemProps = NavLinkProps & { - readonly isDropdownItem?: boolean; - readonly className?: string; - readonly position?: 'left' | 'right'; - }; - - export interface Props extends DesktopOrMobileNavBarItemProps { - readonly mobile?: boolean; - } - - export const NavLink: (props: NavLinkProps) => JSX.Element; - - const DefaultNavbarItem: (props: Props) => JSX.Element; - export default DefaultNavbarItem; -} - -declare module '@theme/NavbarItem/DropdownNavbarItem' { - import type {NavLinkProps} from '@theme/NavbarItem/DefaultNavbarItem'; - import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; - - export type DesktopOrMobileNavBarItemProps = NavLinkProps & { - readonly position?: 'left' | 'right'; - readonly items: readonly LinkLikeNavbarItemProps[]; - readonly className?: string; - }; - - export interface Props extends DesktopOrMobileNavBarItemProps { - readonly mobile?: boolean; - } - - const DropdownNavbarItem: (props: Props) => JSX.Element; - export default DropdownNavbarItem; -} - -declare module '@theme/NavbarItem/SearchNavbarItem' { - export interface Props { - readonly mobile?: boolean; - } - - const SearchNavbarItem: (props: Props) => JSX.Element; - export default SearchNavbarItem; -} - -declare module '@theme/NavbarItem/LocaleDropdownNavbarItem' { - import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; - import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; - - export interface Props extends DropdownNavbarItemProps { - readonly dropdownItemsBefore: LinkLikeNavbarItemProps[]; - readonly dropdownItemsAfter: LinkLikeNavbarItemProps[]; - } - - const LocaleDropdownNavbarItem: (props: Props) => JSX.Element; - export default LocaleDropdownNavbarItem; -} - -declare module '@theme/NavbarItem/DocsVersionDropdownNavbarItem' { - import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; - import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem'; - - export interface Props extends DropdownNavbarItemProps { - readonly docsPluginId?: string; - readonly dropdownActiveClassDisabled?: boolean; - readonly dropdownItemsBefore: LinkLikeNavbarItemProps[]; - readonly dropdownItemsAfter: LinkLikeNavbarItemProps[]; - } - - const DocsVersionDropdownNavbarItem: (props: Props) => JSX.Element; - export default DocsVersionDropdownNavbarItem; -} - -declare module '@theme/NavbarItem/DocsVersionNavbarItem' { - import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; - - export interface Props extends DefaultNavbarItemProps { - readonly docsPluginId?: string; - } - - const DocsVersionNavbarItem: (props: Props) => JSX.Element; - export default DocsVersionNavbarItem; -} - -declare module '@theme/NavbarItem/DocNavbarItem' { - import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; - - export interface Props extends DefaultNavbarItemProps { - readonly docId: string; - readonly docsPluginId?: string; - } - - const DocsSidebarNavbarItem: (props: Props) => JSX.Element; - export default DocsSidebarNavbarItem; -} - -declare module '@theme/NavbarItem' { - import type {ComponentProps} from 'react'; - import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem'; - import type {Props as DocNavbarItemProps} from '@theme/NavbarItem/DocNavbarItem'; - import type {Props as DocsVersionNavbarItemProps} from '@theme/NavbarItem/DocsVersionNavbarItem'; - import type {Props as DropdownNavbarItemProps} from '@theme/NavbarItem/DropdownNavbarItem'; - import type {Props as DocsVersionDropdownNavbarItemProps} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem'; - import type {Props as LocaleDropdownNavbarItemProps} from '@theme/NavbarItem/LocaleDropdownNavbarItem'; - import type {Props as SearchNavbarItemProps} from '@theme/NavbarItem/SearchNavbarItem'; - - export type LinkLikeNavbarItemProps = - | ({readonly type?: 'default'} & DefaultNavbarItemProps) - | ({readonly type: 'doc'} & DocNavbarItemProps) - | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps); - - export type Props = ComponentProps<'a'> & { - readonly position?: 'left' | 'right'; - } & ( - | LinkLikeNavbarItemProps - | ({readonly type?: 'dropdown'} & DropdownNavbarItemProps) - | ({ - readonly type: 'docsVersionDropdown'; - } & DocsVersionDropdownNavbarItemProps) - | ({readonly type: 'localeDropdown'} & LocaleDropdownNavbarItemProps) - | ({ - readonly type: 'search'; - } & SearchNavbarItemProps) - ); - - export type Types = Props['type']; - - const NavbarItem: (props: Props) => JSX.Element; - export default NavbarItem; -} - -declare module '@theme/SearchBar' { - export default function SearchBar(): JSX.Element; -} - -declare module '@theme/TabItem' { - import type {ReactNode} from 'react'; - - export interface Props { - readonly children: ReactNode; - readonly value: string; - readonly default?: boolean; - readonly label?: string; - readonly hidden?: boolean; - readonly className?: string; - } - - const TabItem: (props: Props) => JSX.Element; - export default TabItem; -} - -declare module '@theme/Tabs' { - import type {ReactElement} from 'react'; - import type {Props as TabItemProps} from '@theme/TabItem'; - - export interface Props { - readonly lazy?: boolean; - readonly block?: boolean; - readonly children: readonly ReactElement[]; - readonly defaultValue?: string | null; - readonly values?: readonly {value: string; label?: string}[]; - readonly groupId?: string; - readonly className?: string; - } - - const Tabs: (props: Props) => JSX.Element; - export default Tabs; -} - -declare module '@theme/ThemedImage' { - import type {ComponentProps} from 'react'; - - export interface Props extends Omit, 'src'> { - readonly sources: { - readonly light: string; - readonly dark: string; - }; - } - - const ThemedImage: (props: Props) => JSX.Element; - export default ThemedImage; -} - -declare module '@theme/Details' { - import {Details, DetailsProps} from '@docusaurus/theme-common'; - - export interface Props extends DetailsProps {} - export default Details; -} - -declare module '@theme/ThemeProvider' { - import type {ReactNode} from 'react'; - - export interface Props { - readonly children: ReactNode; - } - - const ThemeProvider: (props: Props) => JSX.Element; - export default ThemeProvider; -} - -declare module '@theme/TOCItems' { - import type {TOCItem} from '@docusaurus/types'; - - export type TOCItemsProps = { - readonly toc: readonly TOCItem[]; - readonly minHeadingLevel?: number; - readonly maxHeadingLevel?: number; - readonly className?: string; - readonly linkClassName?: string | null; - readonly linkActiveClassName?: string; - }; - - export default function TOCItems(props: TOCItemsProps): JSX.Element; -} - -declare module '@theme/TOC' { - import type {TOCItem} from '@docusaurus/types'; - - // minHeadingLevel only exists as a per-doc option, - // and won't have a default set by Joi. See TOC, TOCInline, - // TOCCollapsible for examples - export type TOCProps = { - readonly toc: readonly TOCItem[]; - readonly minHeadingLevel?: number; - readonly maxHeadingLevel?: number; - readonly className?: string; - }; - - export type TOCHeadingsProps = { - readonly toc: readonly TOCItem[]; - readonly minHeadingLevel?: number; - readonly maxHeadingLevel?: number; - }; - - export const TOCHeadings: (props: TOCHeadingsProps) => JSX.Element; - - const TOC: (props: TOCProps) => JSX.Element; - export default TOC; -} - -declare module '@theme/TOCInline' { - import type {TOCItem} from '@docusaurus/types'; - - export type TOCInlineProps = { - readonly toc: readonly TOCItem[]; - readonly minHeadingLevel?: number; - readonly maxHeadingLevel?: number; - }; - - const TOCInline: (props: TOCInlineProps) => JSX.Element; - export default TOCInline; -} - -declare module '@theme/TOCCollapsible' { - import type {TOCItem} from '@docusaurus/types'; - - export type TOCCollapsibleProps = { - readonly className?: string; - readonly minHeadingLevel?: number; - readonly maxHeadingLevel?: number; - readonly toc: readonly TOCItem[]; - }; - - const TOCCollapsible: (props: TOCCollapsibleProps) => JSX.Element; - export default TOCCollapsible; -} - -declare module '@theme/Toggle' { - import type {SyntheticEvent} from 'react'; - - export interface Props { - readonly className?: string; - readonly checked: boolean; - readonly onChange: (e: SyntheticEvent) => void; - } - - const Toggle: (props: Props) => JSX.Element; - export default Toggle; -} - -declare module '@theme/UserPreferencesProvider' { - import type {ReactNode} from 'react'; - - export interface Props { - readonly children: ReactNode; - } - - const UserPreferencesProvider: (props: Props) => JSX.Element; - export default UserPreferencesProvider; -} - -declare module '@theme/LayoutProviders' { - import type {ReactNode} from 'react'; - - export interface Props { - readonly children: ReactNode; - } - - const LayoutProviders: (props: Props) => JSX.Element; - export default LayoutProviders; -} - -declare module '@theme/ThemeContext' { - import type {Context} from 'react'; - import type {ThemeContextProps} from '@theme/hooks/useThemeContext'; - - const ThemeContext: Context; - export default ThemeContext; -} - -declare module '@theme/UserPreferencesContext' { - import type {Context} from 'react'; - import type {UserPreferencesContextProps} from '@theme/hooks/useUserPreferencesContext'; - - const UserPreferencesContext: Context< - UserPreferencesContextProps | undefined - >; - export default UserPreferencesContext; -} - -declare module '@theme/Logo' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'a'> { - readonly imageClassName?: string; - readonly titleClassName?: string; - } - - const Logo: (props: Props) => JSX.Element; - export default Logo; -} - -declare module '@theme/IconArrow' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconArrow: (props: Props) => JSX.Element; - export default IconArrow; -} - -declare module '@theme/IconEdit' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconEdit: (props: Props) => JSX.Element; - export default IconEdit; -} - -declare module '@theme/IconMenu' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconMenu: (props: Props) => JSX.Element; - export default IconMenu; -} - -declare module '@theme/IconClose' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconClose: (props: Props) => JSX.Element; - export default IconClose; -} - -declare module '@theme/IconLanguage' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconLanguage: (props: Props) => JSX.Element; - export default IconLanguage; -} - -declare module '@theme/IconExternalLink' { - import type {ComponentProps} from 'react'; - - export interface Props extends ComponentProps<'svg'> {} - - const IconExternalLink: (props: Props) => JSX.Element; - export default IconExternalLink; -} - -declare module '@theme/TagsListByLetter' { - export type TagsListItem = Readonly<{ - name: string; - permalink: string; - count: number; - }>; - export interface Props { - readonly tags: readonly TagsListItem[]; - } - export default function TagsListByLetter(props: Props): JSX.Element; -} - -declare module '@theme/TagsListInline' { - export type Tag = Readonly<{label: string; permalink: string}>; - export interface Props { - readonly tags: readonly Tag[]; - } - export default function TagsListInline(props: Props): JSX.Element; -} - -declare module '@theme/Tag' { - import type {TagsListItem} from '@theme/TagsListByLetter'; - import type {Optional} from 'utility-types'; - - export interface Props extends Optional {} - - export default function Tag(props: Props): JSX.Element; -} - -declare module '@theme/prism-include-languages' { - import type * as PrismNamespace from 'prismjs'; - - export default function prismIncludeLanguages( - PrismObject: typeof PrismNamespace, - ): void; -} - -declare module 'prism-react-renderer/prism' { - import type * as PrismNamespace from 'prismjs'; - - const Prism: typeof PrismNamespace; - export default Prism; -} diff --git a/packages/docusaurus-theme-common/src/index.ts b/packages/docusaurus-theme-common/src/index.ts index ca3d83f491..e1bb425c61 100644 --- a/packages/docusaurus-theme-common/src/index.ts +++ b/packages/docusaurus-theme-common/src/index.ts @@ -63,7 +63,7 @@ export { useDocsPreferredVersionByPluginId, } from './utils/docsPreferredVersion/useDocsPreferredVersion'; -export {duplicates} from './utils/jsUtils'; +export {duplicates, uniq} from './utils/jsUtils'; export {DocsPreferredVersionContextProvider} from './utils/docsPreferredVersion/DocsPreferredVersionProvider'; diff --git a/packages/docusaurus-utils-common/src/__tests__/uniq.test.ts b/packages/docusaurus-theme-common/src/utils/__tests__/jsUtils.test.ts similarity index 96% rename from packages/docusaurus-utils-common/src/__tests__/uniq.test.ts rename to packages/docusaurus-theme-common/src/utils/__tests__/jsUtils.test.ts index c6ab0e2aae..1040cc459f 100644 --- a/packages/docusaurus-utils-common/src/__tests__/uniq.test.ts +++ b/packages/docusaurus-theme-common/src/utils/__tests__/jsUtils.test.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import uniq from '../uniq'; +import {uniq} from '../jsUtils'; describe('uniq', () => { test('remove duplicate primitives', () => { diff --git a/packages/docusaurus-theme-common/src/utils/jsUtils.ts b/packages/docusaurus-theme-common/src/utils/jsUtils.ts index bbb3e58919..bcd41b3dc4 100644 --- a/packages/docusaurus-theme-common/src/utils/jsUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/jsUtils.ts @@ -21,3 +21,13 @@ export function duplicates( (v, vIndex) => arr.findIndex((u) => comparator(u, v)) !== vIndex, ); } + +/** + * Remove duplicate array items (similar to _.uniq) + * @param arr The array. + * @returns An array with duplicate elements removed by reference comparison. + */ +export function uniq(arr: T[]): T[] { + // Note: had problems with [...new Set()]: https://github.com/facebook/docusaurus/issues/4972#issuecomment-863895061 + return Array.from(new Set(arr)); +} diff --git a/packages/docusaurus-theme-live-codeblock/src/types.d.ts b/packages/docusaurus-theme-live-codeblock/src/deps.d.ts similarity index 100% rename from packages/docusaurus-theme-live-codeblock/src/types.d.ts rename to packages/docusaurus-theme-live-codeblock/src/deps.d.ts diff --git a/packages/docusaurus-utils-common/src/applyTrailingSlash.tsx b/packages/docusaurus-utils-common/src/applyTrailingSlash.ts similarity index 100% rename from packages/docusaurus-utils-common/src/applyTrailingSlash.tsx rename to packages/docusaurus-utils-common/src/applyTrailingSlash.ts diff --git a/packages/docusaurus-utils-common/src/index.ts b/packages/docusaurus-utils-common/src/index.ts index 9ef62d068e..204a13ebf5 100644 --- a/packages/docusaurus-utils-common/src/index.ts +++ b/packages/docusaurus-utils-common/src/index.ts @@ -7,5 +7,3 @@ export {default as applyTrailingSlash} from './applyTrailingSlash'; export type {ApplyTrailingSlashParams} from './applyTrailingSlash'; - -export {default as uniq} from './uniq'; diff --git a/packages/docusaurus-utils-common/src/uniq.ts b/packages/docusaurus-utils-common/src/uniq.ts deleted file mode 100644 index d65aa1d538..0000000000 --- a/packages/docusaurus-utils-common/src/uniq.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// Remove duplicate array items (similar to _.uniq) -export default function uniq(array: T[]): T[] { - // Note: had problems with [...new Set()]: https://github.com/facebook/docusaurus/issues/4972#issuecomment-863895061 - return Array.from(new Set(array)); -} diff --git a/packages/docusaurus-utils/src/dependencies.d.ts b/packages/docusaurus-utils/src/deps.d.ts similarity index 72% rename from packages/docusaurus-utils/src/dependencies.d.ts rename to packages/docusaurus-utils/src/deps.d.ts index 05f37c5549..0a591d14db 100644 --- a/packages/docusaurus-utils/src/dependencies.d.ts +++ b/packages/docusaurus-utils/src/deps.d.ts @@ -5,7 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -// Dependencies with missing typedefs +declare module 'resolve-pathname' { + export default function resolvePathname(to: string, from?: string): string; +} declare module '@mdx-js/runtime'; declare module 'remark-mdx-remove-imports'; diff --git a/packages/docusaurus/src/types.d.ts b/packages/docusaurus/src/deps.d.ts similarity index 100% rename from packages/docusaurus/src/types.d.ts rename to packages/docusaurus/src/deps.d.ts