mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-10 23:02:56 +02:00
refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type (#7080)
* refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type * fix
This commit is contained in:
parent
ce2b631455
commit
24c205a835
38 changed files with 145 additions and 138 deletions
|
@ -13,11 +13,11 @@ import {ReactContextError} from '../utils/reactUtils';
|
|||
// Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
|
||||
const EmptyContext: unique symbol = Symbol('EmptyContext');
|
||||
|
||||
type SidebarContextValue = {name: string; items: PropSidebar};
|
||||
type ContextValue = {name: string; items: PropSidebar};
|
||||
|
||||
const Context = React.createContext<
|
||||
SidebarContextValue | null | typeof EmptyContext
|
||||
>(EmptyContext);
|
||||
const Context = React.createContext<ContextValue | null | typeof EmptyContext>(
|
||||
EmptyContext,
|
||||
);
|
||||
|
||||
/**
|
||||
* Provide the current sidebar to your children.
|
||||
|
@ -31,7 +31,7 @@ export function DocsSidebarProvider({
|
|||
name: string | undefined;
|
||||
items: PropSidebar | undefined;
|
||||
}): JSX.Element {
|
||||
const stableValue: SidebarContextValue | null = useMemo(
|
||||
const stableValue: ContextValue | null = useMemo(
|
||||
() =>
|
||||
name && items
|
||||
? {
|
||||
|
@ -45,9 +45,9 @@ export function DocsSidebarProvider({
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the sidebar data that's currently displayed, or `null` if there isn't one
|
||||
* Gets the sidebar that's currently displayed, or `null` if there isn't one
|
||||
*/
|
||||
export function useDocsSidebar(): SidebarContextValue | null {
|
||||
export function useDocsSidebar(): ContextValue | null {
|
||||
const value = useContext(Context);
|
||||
if (value === EmptyContext) {
|
||||
throw new ReactContextError('DocsSidebarProvider');
|
||||
|
|
|
@ -220,8 +220,9 @@ export function useDocsVersionCandidates(
|
|||
|
||||
/**
|
||||
* The layout components, like navbar items, must be able to work on all pages,
|
||||
* even on non-doc ones. This hook would always return a sidebar to be linked
|
||||
* to. See also {@link useDocsVersionCandidates} for how this selection is done.
|
||||
* even on non-doc ones where there's no version context, so a sidebar ID could
|
||||
* be ambiguous. This hook would always return a sidebar to be linked to. See
|
||||
* also {@link useDocsVersionCandidates} for how this selection is done.
|
||||
*
|
||||
* @throws This hook throws if a sidebar with said ID is not found.
|
||||
*/
|
||||
|
@ -252,8 +253,9 @@ export function useLayoutDocsSidebar(
|
|||
|
||||
/**
|
||||
* The layout components, like navbar items, must be able to work on all pages,
|
||||
* even on non-doc ones. This hook would always return a doc to be linked
|
||||
* to. See also {@link useDocsVersionCandidates} for how this selection is done.
|
||||
* even on non-doc ones where there's no version context, so a doc ID could be
|
||||
* ambiguous. This hook would always return a doc to be linked to. See also
|
||||
* {@link useDocsVersionCandidates} for how this selection is done.
|
||||
*
|
||||
* @throws This hook throws if a doc with said ID is not found.
|
||||
*/
|
||||
|
|
|
@ -12,13 +12,13 @@ import useRouteContext from '@docusaurus/useRouteContext';
|
|||
import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
|
||||
import {useTitleFormatter} from './generalUtils';
|
||||
|
||||
interface PageMetadataProps {
|
||||
type PageMetadataProps = {
|
||||
readonly title?: string;
|
||||
readonly description?: string;
|
||||
readonly keywords?: readonly string[] | string;
|
||||
readonly image?: string;
|
||||
readonly children?: ReactNode;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper component to manipulate page metadata and override site defaults.
|
||||
|
|
|
@ -54,11 +54,11 @@ Possible reasons: running Docusaurus in an iframe, in an incognito browser sessi
|
|||
}
|
||||
|
||||
// Convenient storage interface for a single storage key
|
||||
export interface StorageSlot {
|
||||
export type StorageSlot = {
|
||||
get: () => string | null;
|
||||
set: (value: string) => void;
|
||||
del: () => void;
|
||||
}
|
||||
};
|
||||
|
||||
const NoopStorageSlot: StorageSlot = {
|
||||
get: () => null,
|
||||
|
|
|
@ -101,7 +101,7 @@ function filterTOC({
|
|||
* to ensure that weird TOC structures preserve their semantics. For example, an
|
||||
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
|
||||
* min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
|
||||
* the two headings and they are not parents)
|
||||
* the two headings and they are not parent-children)
|
||||
*/
|
||||
export function useFilteredAndTreeifiedTOC({
|
||||
toc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue