feat(preset-classic, content-docs/client): JSDoc (#7148)

* refactor: add JSDoc for preset-classic, content-docs/client

* fix
This commit is contained in:
Joshua Chen 2022-04-11 09:36:30 +08:00 committed by GitHub
parent 25ba91fd4d
commit f4ab7c65ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 139 additions and 111 deletions

View file

@ -554,56 +554,18 @@ declare module '@theme/DocBreadcrumbs' {
declare module '@theme/DocPage' {
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
import type {DocumentRoute} from '@theme/DocItem';
import type {RouteConfigComponentProps} from 'react-router-config';
import type {Required} from 'utility-types';
export interface Props {
readonly location: {readonly pathname: string};
export interface Props extends Required<RouteConfigComponentProps, 'route'> {
readonly versionMetadata: PropVersionMetadata;
readonly route: {
readonly path: string;
readonly component: () => JSX.Element;
readonly routes: DocumentRoute[];
};
}
export default function DocPage(props: Props): JSX.Element;
}
declare module '@theme/DocPage/Layout' {
import type {ReactNode} from 'react';
export interface Props {
children: ReactNode;
}
export default function DocPageLayout(props: Props): JSX.Element;
}
declare module '@theme/DocPage/Layout/Aside' {
import type {Dispatch, SetStateAction} from 'react';
import type {PropSidebar} from '@docusaurus/plugin-content-docs';
export interface Props {
sidebar: PropSidebar;
hiddenSidebarContainer: boolean;
setHiddenSidebarContainer: Dispatch<SetStateAction<boolean>>;
}
export default function DocPageLayoutAside(props: Props): JSX.Element;
}
declare module '@theme/DocPage/Layout/Main' {
import type {ReactNode} from 'react';
export interface Props {
hiddenSidebarContainer: boolean;
children: ReactNode;
}
export default function DocPageLayoutMain(props: Props): JSX.Element;
}
// TODO until TS supports exports field... hope it's in 4.6
// TODO TS only supports reading `exports` in 4.7. We will need to merge the
// type defs (and JSDoc) here with the implementation after that
declare module '@docusaurus/plugin-content-docs/client' {
import type {UseDataOptions} from '@docusaurus/types';
@ -617,6 +579,11 @@ declare module '@docusaurus/plugin-content-docs/client' {
alternateDocVersions: {[versionName: string]: GlobalDoc};
};
export type GlobalDoc = {
/**
* For generated index pages, this is the `slug`, **not** `permalink`
* (without base URL). Because slugs have leading slashes but IDs don't,
* there won't be clashes.
*/
id: string;
path: string;
sidebar: string | undefined;
@ -627,7 +594,8 @@ declare module '@docusaurus/plugin-content-docs/client' {
label: string;
isLast: boolean;
path: string;
mainDocId: string; // home doc (if docs homepage configured), or first doc
/** The doc with `slug: /`, or first doc in first sidebar */
mainDocId: string;
docs: GlobalDoc[];
sidebars?: {[sidebarId: string]: GlobalSidebar};
};
@ -645,9 +613,9 @@ declare module '@docusaurus/plugin-content-docs/client' {
breadcrumbs: boolean;
};
export type DocVersionSuggestions = {
// suggest the latest version
/** suggest the latest version */
latestVersionSuggestion: GlobalVersion;
// suggest the same doc, in latest version (if exist)
/** suggest the same doc, in latest version (if exist) */
latestDocSuggestion?: GlobalDoc;
};
@ -661,12 +629,20 @@ declare module '@docusaurus/plugin-content-docs/client' {
) =>
| {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
| undefined;
/** Versions are returned ordered (most recent first). */
export const useVersions: (pluginId?: string) => GlobalVersion[];
export const useLatestVersion: (pluginId?: string) => GlobalVersion;
/**
* Returns `undefined` on doc-unrelated pages, because there's no version
* currently considered as active.
*/
export const useActiveVersion: (
pluginId?: string,
) => GlobalVersion | undefined;
export const useActiveDocContext: (pluginId?: string) => ActiveDocContext;
/**
* Useful to say "hey, you are not on the latest docs version, please switch"
*/
export const useDocVersionSuggestions: (
pluginId?: string,
) => DocVersionSuggestions;