@docusaurus/theme-common 2.0.0-beta.21 → 2.0.0-beta.22
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/lib/contexts/blogPost.d.ts +33 -0
- package/lib/contexts/blogPost.d.ts.map +1 -0
- package/lib/contexts/blogPost.js +46 -0
- package/lib/contexts/blogPost.js.map +1 -0
- package/lib/contexts/doc.d.ts +30 -0
- package/lib/contexts/doc.d.ts.map +1 -0
- package/lib/contexts/doc.js +48 -0
- package/lib/contexts/doc.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +2 -3
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -1
- package/lib/contexts/docsPreferredVersion.js +1 -1
- package/lib/contexts/docsPreferredVersion.js.map +1 -1
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -1
- package/lib/contexts/navbarSecondaryMenu/content.js +3 -9
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -1
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -1
- package/lib/hooks/useCodeWordWrap.js +32 -6
- package/lib/hooks/useCodeWordWrap.js.map +1 -1
- package/lib/hooks/useMutationObserver.d.ts +4 -0
- package/lib/hooks/useMutationObserver.d.ts.map +1 -0
- package/lib/hooks/useMutationObserver.js +29 -0
- package/lib/hooks/useMutationObserver.js.map +1 -0
- package/lib/index.d.ts +9 -34
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +16 -34
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +41 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +52 -0
- package/lib/internal.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +5 -3
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +5 -3
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/docsUtils.js +1 -1
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/historyUtils.js +4 -4
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/reactUtils.d.ts +33 -6
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +39 -5
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/scrollUtils.js +2 -2
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/useLocationChange.js +2 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +8 -11
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +18 -11
- package/src/contexts/blogPost.tsx +80 -0
- package/src/contexts/doc.tsx +71 -0
- package/src/contexts/docsPreferredVersion.tsx +2 -2
- package/src/contexts/navbarSecondaryMenu/content.tsx +2 -12
- package/src/hooks/useCodeWordWrap.ts +50 -1
- package/src/hooks/useMutationObserver.ts +38 -0
- package/src/index.ts +28 -114
- package/src/internal.ts +122 -0
- package/src/utils/ThemeClassNames.ts +7 -4
- package/src/utils/docsUtils.tsx +1 -1
- package/src/utils/historyUtils.ts +5 -5
- package/src/utils/reactUtils.tsx +58 -5
- package/src/utils/scrollUtils.tsx +2 -2
- package/src/utils/useLocationChange.ts +2 -2
- package/src/utils/useThemeConfig.ts +8 -11
- package/Details.d.ts +0 -14
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
|
|
8
|
+
import React, {useMemo, type ReactNode, useContext} from 'react';
|
|
9
|
+
import {ReactContextError} from '../utils/reactUtils';
|
|
10
|
+
|
|
11
|
+
import type {PropBlogPostContent} from '@docusaurus/plugin-content-blog';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The React context value returned by the `useBlogPost()` hook.
|
|
15
|
+
* It contains useful data related to the currently browsed blog post.
|
|
16
|
+
*/
|
|
17
|
+
export type BlogPostContextValue = Pick<
|
|
18
|
+
PropBlogPostContent,
|
|
19
|
+
'metadata' | 'frontMatter' | 'assets' | 'toc'
|
|
20
|
+
> & {
|
|
21
|
+
readonly isBlogPostPage: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const Context = React.createContext<BlogPostContextValue | null>(null);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Note: we don't use `PropBlogPostContent` as context value on purpose. Metadata is
|
|
28
|
+
* currently stored inside the MDX component, but we may want to change that in
|
|
29
|
+
* the future.
|
|
30
|
+
*/
|
|
31
|
+
function useContextValue({
|
|
32
|
+
content,
|
|
33
|
+
isBlogPostPage,
|
|
34
|
+
}: {
|
|
35
|
+
content: PropBlogPostContent;
|
|
36
|
+
isBlogPostPage: boolean;
|
|
37
|
+
}): BlogPostContextValue {
|
|
38
|
+
return useMemo(
|
|
39
|
+
() => ({
|
|
40
|
+
metadata: content.metadata,
|
|
41
|
+
frontMatter: content.frontMatter,
|
|
42
|
+
assets: content.assets,
|
|
43
|
+
toc: content.toc,
|
|
44
|
+
isBlogPostPage,
|
|
45
|
+
}),
|
|
46
|
+
[content, isBlogPostPage],
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This is a very thin layer around the `content` received from the MDX loader.
|
|
52
|
+
* It provides metadata about the blog post to the children tree.
|
|
53
|
+
*/
|
|
54
|
+
export function BlogPostProvider({
|
|
55
|
+
children,
|
|
56
|
+
content,
|
|
57
|
+
isBlogPostPage = false,
|
|
58
|
+
}: {
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
content: PropBlogPostContent;
|
|
61
|
+
isBlogPostPage?: boolean;
|
|
62
|
+
}): JSX.Element {
|
|
63
|
+
const contextValue = useContextValue({content, isBlogPostPage});
|
|
64
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns the data of the currently browsed blog post. Gives access to
|
|
69
|
+
* front matter, metadata, TOC, etc.
|
|
70
|
+
* When swizzling a low-level component (e.g. the "Edit this page" link)
|
|
71
|
+
* and you need some extra metadata, you don't have to drill the props
|
|
72
|
+
* all the way through the component tree: simply use this hook instead.
|
|
73
|
+
*/
|
|
74
|
+
export function useBlogPost(): BlogPostContextValue {
|
|
75
|
+
const blogPost = useContext(Context);
|
|
76
|
+
if (blogPost === null) {
|
|
77
|
+
throw new ReactContextError('BlogPostProvider');
|
|
78
|
+
}
|
|
79
|
+
return blogPost;
|
|
80
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
|
|
8
|
+
import React, {useMemo, type ReactNode, useContext} from 'react';
|
|
9
|
+
import {ReactContextError} from '../utils/reactUtils';
|
|
10
|
+
import type {PropDocContent} from '@docusaurus/plugin-content-docs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The React context value returned by the `useDoc()` hook.
|
|
14
|
+
* It contains useful data related to the currently browsed doc.
|
|
15
|
+
*/
|
|
16
|
+
export type DocContextValue = Pick<
|
|
17
|
+
PropDocContent,
|
|
18
|
+
'metadata' | 'frontMatter' | 'toc' | 'assets' | 'contentTitle'
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
const Context = React.createContext<DocContextValue | null>(null);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Note: we don't use `PropDoc` as context value on purpose. Metadata is
|
|
25
|
+
* currently stored inside the MDX component, but we may want to change that in
|
|
26
|
+
* the future. This layer is a good opportunity to decouple storage from
|
|
27
|
+
* consuming API, potentially allowing us to provide metadata as both props and
|
|
28
|
+
* route context without duplicating the chunks in the future.
|
|
29
|
+
*/
|
|
30
|
+
function useContextValue(content: PropDocContent): DocContextValue {
|
|
31
|
+
return useMemo(
|
|
32
|
+
() => ({
|
|
33
|
+
metadata: content.metadata,
|
|
34
|
+
frontMatter: content.frontMatter,
|
|
35
|
+
assets: content.assets,
|
|
36
|
+
contentTitle: content.contentTitle,
|
|
37
|
+
toc: content.toc,
|
|
38
|
+
}),
|
|
39
|
+
[content],
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This is a very thin layer around the `content` received from the MDX loader.
|
|
45
|
+
* It provides metadata about the doc to the children tree.
|
|
46
|
+
*/
|
|
47
|
+
export function DocProvider({
|
|
48
|
+
children,
|
|
49
|
+
content,
|
|
50
|
+
}: {
|
|
51
|
+
children: ReactNode;
|
|
52
|
+
content: PropDocContent;
|
|
53
|
+
}): JSX.Element {
|
|
54
|
+
const contextValue = useContextValue(content);
|
|
55
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the data of the currently browsed doc. Gives access to the doc's MDX
|
|
60
|
+
* Component, front matter, metadata, TOC, etc. When swizzling a low-level
|
|
61
|
+
* component (e.g. the "Edit this page" link) and you need some extra metadata,
|
|
62
|
+
* you don't have to drill the props all the way through the component tree:
|
|
63
|
+
* simply use this hook instead.
|
|
64
|
+
*/
|
|
65
|
+
export function useDoc(): DocContextValue {
|
|
66
|
+
const doc = useContext(Context);
|
|
67
|
+
if (doc === null) {
|
|
68
|
+
throw new ReactContextError('DocProvider');
|
|
69
|
+
}
|
|
70
|
+
return doc;
|
|
71
|
+
}
|
|
@@ -175,7 +175,7 @@ function DocsPreferredVersionContextProviderUnsafe({
|
|
|
175
175
|
export function DocsPreferredVersionContextProvider({
|
|
176
176
|
children,
|
|
177
177
|
}: {
|
|
178
|
-
children:
|
|
178
|
+
children: ReactNode;
|
|
179
179
|
}): JSX.Element {
|
|
180
180
|
if (isDocsPluginEnabled) {
|
|
181
181
|
return (
|
|
@@ -184,7 +184,7 @@ export function DocsPreferredVersionContextProvider({
|
|
|
184
184
|
</DocsPreferredVersionContextProviderUnsafe>
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
|
-
return children
|
|
187
|
+
return <>{children}</>;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
function useDocsPreferredVersionContext(): ContextValue {
|
|
@@ -9,11 +9,10 @@ import React, {
|
|
|
9
9
|
useState,
|
|
10
10
|
useContext,
|
|
11
11
|
useEffect,
|
|
12
|
-
useMemo,
|
|
13
12
|
type ReactNode,
|
|
14
13
|
type ComponentType,
|
|
15
14
|
} from 'react';
|
|
16
|
-
import {ReactContextError} from '../../utils/reactUtils';
|
|
15
|
+
import {ReactContextError, useShallowMemoObject} from '../../utils/reactUtils';
|
|
17
16
|
|
|
18
17
|
// This context represents a "global layout store". A component (usually a
|
|
19
18
|
// layout component) can request filling this store through
|
|
@@ -61,15 +60,6 @@ export function useNavbarSecondaryMenuContent(): Content {
|
|
|
61
60
|
return value[0];
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
function useShallowMemoizedObject<O>(obj: O) {
|
|
65
|
-
return useMemo(
|
|
66
|
-
() => obj,
|
|
67
|
-
// Is this safe?
|
|
68
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
-
[...Object.keys(obj), ...Object.values(obj)],
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
63
|
/**
|
|
74
64
|
* This component renders nothing by itself, but it fills the placeholder in the
|
|
75
65
|
* generic secondary menu layout. This reduces coupling between the main layout
|
|
@@ -94,7 +84,7 @@ export function NavbarSecondaryMenuFiller<P extends object>({
|
|
|
94
84
|
const [, setContent] = context;
|
|
95
85
|
|
|
96
86
|
// To avoid useless context re-renders, props are memoized shallowly
|
|
97
|
-
const memoizedProps =
|
|
87
|
+
const memoizedProps = useShallowMemoObject(props);
|
|
98
88
|
|
|
99
89
|
useEffect(() => {
|
|
100
90
|
// @ts-expect-error: this context is hard to type
|
|
@@ -4,9 +4,53 @@
|
|
|
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
7
|
import type {RefObject} from 'react';
|
|
9
8
|
import {useState, useCallback, useEffect, useRef} from 'react';
|
|
9
|
+
import {useMutationObserver} from './useMutationObserver';
|
|
10
|
+
|
|
11
|
+
// Callback fires when the "hidden" attribute of a tabpanel changes
|
|
12
|
+
// See https://github.com/facebook/docusaurus/pull/7485
|
|
13
|
+
function useTabBecameVisibleCallback(
|
|
14
|
+
codeBlockRef: RefObject<HTMLPreElement>,
|
|
15
|
+
callback: () => void,
|
|
16
|
+
) {
|
|
17
|
+
const [hiddenTabElement, setHiddenTabElement] = useState<
|
|
18
|
+
Element | null | undefined
|
|
19
|
+
>();
|
|
20
|
+
|
|
21
|
+
const updateHiddenTabElement = useCallback(() => {
|
|
22
|
+
// No need to observe non-hidden tabs
|
|
23
|
+
// + we want to force a re-render when a tab becomes visible
|
|
24
|
+
setHiddenTabElement(
|
|
25
|
+
codeBlockRef.current?.closest('[role=tabpanel][hidden]'),
|
|
26
|
+
);
|
|
27
|
+
}, [codeBlockRef, setHiddenTabElement]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
updateHiddenTabElement();
|
|
31
|
+
}, [updateHiddenTabElement]);
|
|
32
|
+
|
|
33
|
+
useMutationObserver(
|
|
34
|
+
hiddenTabElement,
|
|
35
|
+
(mutations: MutationRecord[]) => {
|
|
36
|
+
mutations.forEach((mutation) => {
|
|
37
|
+
if (
|
|
38
|
+
mutation.type === 'attributes' &&
|
|
39
|
+
mutation.attributeName === 'hidden'
|
|
40
|
+
) {
|
|
41
|
+
callback();
|
|
42
|
+
updateHiddenTabElement();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
attributes: true,
|
|
48
|
+
characterData: false,
|
|
49
|
+
childList: false,
|
|
50
|
+
subtree: false,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
}
|
|
10
54
|
|
|
11
55
|
export function useCodeWordWrap(): {
|
|
12
56
|
readonly codeBlockRef: RefObject<HTMLPreElement>;
|
|
@@ -25,6 +69,9 @@ export function useCodeWordWrap(): {
|
|
|
25
69
|
codeElement.removeAttribute('style');
|
|
26
70
|
} else {
|
|
27
71
|
codeElement.style.whiteSpace = 'pre-wrap';
|
|
72
|
+
// When code wrap is enabled, we want to avoid a scrollbar in any case
|
|
73
|
+
// Ensure that very very long words/strings/tokens still wrap
|
|
74
|
+
codeElement.style.overflowWrap = 'anywhere';
|
|
28
75
|
}
|
|
29
76
|
|
|
30
77
|
setIsEnabled((value) => !value);
|
|
@@ -38,6 +85,8 @@ export function useCodeWordWrap(): {
|
|
|
38
85
|
setIsCodeScrollable(isScrollable);
|
|
39
86
|
}, [codeBlockRef]);
|
|
40
87
|
|
|
88
|
+
useTabBecameVisibleCallback(codeBlockRef, updateCodeIsScrollable);
|
|
89
|
+
|
|
41
90
|
useEffect(() => {
|
|
42
91
|
updateCodeIsScrollable();
|
|
43
92
|
}, [isEnabled, updateCodeIsScrollable]);
|
|
@@ -0,0 +1,38 @@
|
|
|
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 {useEffect} from 'react';
|
|
8
|
+
import {useEvent, useShallowMemoObject} from '../utils/reactUtils';
|
|
9
|
+
|
|
10
|
+
type Options = MutationObserverInit;
|
|
11
|
+
|
|
12
|
+
const DefaultOptions: Options = {
|
|
13
|
+
attributes: true,
|
|
14
|
+
characterData: true,
|
|
15
|
+
childList: true,
|
|
16
|
+
subtree: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function useMutationObserver(
|
|
20
|
+
target: Element | undefined | null,
|
|
21
|
+
callback: MutationCallback,
|
|
22
|
+
options: Options = DefaultOptions,
|
|
23
|
+
): void {
|
|
24
|
+
const stableCallback = useEvent(callback);
|
|
25
|
+
|
|
26
|
+
// MutationObserver options are not nested much
|
|
27
|
+
// so this should be to memo options in 99%
|
|
28
|
+
// TODO handle options.attributeFilter array
|
|
29
|
+
const stableOptions: Options = useShallowMemoObject(options);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const observer = new MutationObserver(stableCallback);
|
|
33
|
+
if (target) {
|
|
34
|
+
observer.observe(target, stableOptions);
|
|
35
|
+
}
|
|
36
|
+
return () => observer.disconnect();
|
|
37
|
+
}, [target, stableCallback, stableOptions]);
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/*
|
|
9
|
+
* APIs to document
|
|
10
|
+
*/
|
|
11
|
+
|
|
8
12
|
export {
|
|
9
13
|
useThemeConfig,
|
|
10
14
|
type ThemeConfig,
|
|
@@ -19,69 +23,42 @@ export {
|
|
|
19
23
|
type FooterLinkItem,
|
|
20
24
|
type ColorModeConfig,
|
|
21
25
|
} from './utils/useThemeConfig';
|
|
22
|
-
export {
|
|
23
|
-
DocSidebarItemsExpandedStateProvider,
|
|
24
|
-
useDocSidebarItemsExpandedState,
|
|
25
|
-
} from './contexts/docSidebarItemsExpandedState';
|
|
26
|
-
export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion';
|
|
27
|
-
export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';
|
|
28
26
|
|
|
29
27
|
export {createStorageSlot, listStorageKeys} from './utils/storageUtils';
|
|
30
28
|
|
|
31
|
-
export {
|
|
29
|
+
export {useContextualSearchFilters} from './utils/searchUtils';
|
|
32
30
|
|
|
33
|
-
export {
|
|
34
|
-
parseCodeBlockTitle,
|
|
35
|
-
parseLanguage,
|
|
36
|
-
parseLines,
|
|
37
|
-
containsLineNumbers,
|
|
38
|
-
getPrismCssVariables,
|
|
39
|
-
} from './utils/codeBlockUtils';
|
|
40
|
-
|
|
41
|
-
export {
|
|
42
|
-
docVersionSearchTag,
|
|
43
|
-
DEFAULT_SEARCH_TAG,
|
|
44
|
-
useContextualSearchFilters,
|
|
45
|
-
} from './utils/searchUtils';
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
isDocsPluginEnabled,
|
|
49
|
-
useDocById,
|
|
50
|
-
findSidebarCategory,
|
|
51
|
-
findFirstCategoryLink,
|
|
52
|
-
useCurrentSidebarCategory,
|
|
53
|
-
isActiveSidebarItem,
|
|
54
|
-
useSidebarBreadcrumbs,
|
|
55
|
-
useDocsVersionCandidates,
|
|
56
|
-
useLayoutDoc,
|
|
57
|
-
useLayoutDocsSidebar,
|
|
58
|
-
useDocRouteMetadata,
|
|
59
|
-
} from './utils/docsUtils';
|
|
60
|
-
|
|
61
|
-
export {useTitleFormatter} from './utils/generalUtils';
|
|
31
|
+
export {useCurrentSidebarCategory} from './utils/docsUtils';
|
|
62
32
|
|
|
63
33
|
export {usePluralForm} from './utils/usePluralForm';
|
|
64
34
|
|
|
65
|
-
export {useLocationChange} from './utils/useLocationChange';
|
|
66
|
-
|
|
67
35
|
export {useCollapsible, Collapsible} from './components/Collapsible';
|
|
68
36
|
|
|
37
|
+
export {ThemeClassNames} from './utils/ThemeClassNames';
|
|
38
|
+
|
|
69
39
|
export {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
40
|
+
useIsomorphicLayoutEffect,
|
|
41
|
+
useEvent,
|
|
42
|
+
usePrevious,
|
|
43
|
+
composeProviders,
|
|
44
|
+
ReactContextError,
|
|
45
|
+
} from './utils/reactUtils';
|
|
74
46
|
|
|
75
|
-
export {
|
|
47
|
+
export {PageMetadata, HtmlClassNameProvider} from './utils/metadataUtils';
|
|
76
48
|
|
|
77
|
-
export {
|
|
49
|
+
export {useColorMode, type ColorMode} from './contexts/colorMode';
|
|
78
50
|
|
|
79
51
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} from './contexts/
|
|
52
|
+
NavbarSecondaryMenuFiller,
|
|
53
|
+
type NavbarSecondaryMenuComponent,
|
|
54
|
+
} from './contexts/navbarSecondaryMenu/content';
|
|
83
55
|
|
|
84
|
-
export {
|
|
56
|
+
export {useWindowSize} from './hooks/useWindowSize';
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* APIs kept undocumented, on purpose
|
|
60
|
+
* Note: we still guarantee retro-compatibility on those
|
|
61
|
+
*/
|
|
85
62
|
|
|
86
63
|
export {
|
|
87
64
|
translateTagsPageTitle,
|
|
@@ -89,75 +66,12 @@ export {
|
|
|
89
66
|
type TagLetterEntry,
|
|
90
67
|
} from './utils/tagsUtils';
|
|
91
68
|
|
|
92
|
-
export {useHistoryPopHandler} from './utils/historyUtils';
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
useTOCHighlight,
|
|
96
|
-
type TOCHighlightConfig,
|
|
97
|
-
} from './hooks/useTOCHighlight';
|
|
98
|
-
|
|
99
|
-
export {
|
|
100
|
-
useFilteredAndTreeifiedTOC,
|
|
101
|
-
useTreeifiedTOC,
|
|
102
|
-
type TOCTreeNode,
|
|
103
|
-
} from './utils/tocUtils';
|
|
104
|
-
|
|
105
69
|
export {isMultiColumnFooterLinks} from './utils/footerUtils';
|
|
106
70
|
|
|
107
|
-
export {
|
|
108
|
-
ScrollControllerProvider,
|
|
109
|
-
useScrollController,
|
|
110
|
-
useScrollPosition,
|
|
111
|
-
useScrollPositionBlocker,
|
|
112
|
-
useSmoothScrollTo,
|
|
113
|
-
} from './utils/scrollUtils';
|
|
114
|
-
|
|
115
|
-
export {
|
|
116
|
-
useIsomorphicLayoutEffect,
|
|
117
|
-
useDynamicCallback,
|
|
118
|
-
usePrevious,
|
|
119
|
-
ReactContextError,
|
|
120
|
-
} from './utils/reactUtils';
|
|
121
|
-
|
|
122
71
|
export {isRegexpStringMatch} from './utils/regexpUtils';
|
|
123
72
|
|
|
124
|
-
export {
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
PageMetadata,
|
|
128
|
-
HtmlClassNameProvider,
|
|
129
|
-
PluginHtmlClassNameProvider,
|
|
130
|
-
} from './utils/metadataUtils';
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
useColorMode,
|
|
134
|
-
ColorModeProvider,
|
|
135
|
-
type ColorMode,
|
|
136
|
-
} from './contexts/colorMode';
|
|
137
|
-
|
|
138
|
-
export {splitNavbarItems, NavbarProvider} from './utils/navbarUtils';
|
|
139
|
-
|
|
140
|
-
export {
|
|
141
|
-
useTabGroupChoice,
|
|
142
|
-
TabGroupChoiceProvider,
|
|
143
|
-
} from './contexts/tabGroupChoice';
|
|
144
|
-
|
|
145
|
-
export {useNavbarMobileSidebar} from './contexts/navbarMobileSidebar';
|
|
146
|
-
export {
|
|
147
|
-
NavbarSecondaryMenuFiller,
|
|
148
|
-
type NavbarSecondaryMenuComponent,
|
|
149
|
-
} from './contexts/navbarSecondaryMenu/content';
|
|
150
|
-
export {useNavbarSecondaryMenu} from './contexts/navbarSecondaryMenu/display';
|
|
73
|
+
export {duplicates, uniq} from './utils/jsUtils';
|
|
151
74
|
|
|
152
|
-
export {useBackToTopButton} from './hooks/useBackToTopButton';
|
|
153
|
-
export {useHideableNavbar} from './hooks/useHideableNavbar';
|
|
154
|
-
export {
|
|
155
|
-
useKeyboardNavigation,
|
|
156
|
-
keyboardFocusedClassName,
|
|
157
|
-
} from './hooks/useKeyboardNavigation';
|
|
158
75
|
export {usePrismTheme} from './hooks/usePrismTheme';
|
|
159
|
-
|
|
160
|
-
export {
|
|
161
|
-
export {useSearchPage} from './hooks/useSearchPage';
|
|
162
|
-
export {useCodeWordWrap} from './hooks/useCodeWordWrap';
|
|
163
|
-
export {useSkipToContent} from './hooks/useSkipToContent';
|
|
76
|
+
|
|
77
|
+
export {useDocsPreferredVersion} from './contexts/docsPreferredVersion';
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
|
|
8
|
+
// This re-export permits to handle some level of retro-compatibility. Users
|
|
9
|
+
// might swizzle unsafe components and expose these internal imports. When we
|
|
10
|
+
// move an API from internal to public, former internal imports should keep
|
|
11
|
+
// working, so that the change doesn't become breaking.
|
|
12
|
+
//
|
|
13
|
+
// Important: this line is removed from build output with the
|
|
14
|
+
// "removeThemeInternalReexport" script for CI checks. This ensures that none of
|
|
15
|
+
// our internal code relies on this re-export and that we don't forget to
|
|
16
|
+
// migrate theme internal imports to public imports.
|
|
17
|
+
//
|
|
18
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
19
|
+
export * from './index';
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
DocSidebarItemsExpandedStateProvider,
|
|
23
|
+
useDocSidebarItemsExpandedState,
|
|
24
|
+
} from './contexts/docSidebarItemsExpandedState';
|
|
25
|
+
export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion';
|
|
26
|
+
export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';
|
|
27
|
+
|
|
28
|
+
export {DocProvider, useDoc, type DocContextValue} from './contexts/doc';
|
|
29
|
+
export {
|
|
30
|
+
BlogPostProvider,
|
|
31
|
+
useBlogPost,
|
|
32
|
+
type BlogPostContextValue,
|
|
33
|
+
} from './contexts/blogPost';
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
useDocsPreferredVersionByPluginId,
|
|
37
|
+
DocsPreferredVersionContextProvider,
|
|
38
|
+
} from './contexts/docsPreferredVersion';
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
AnnouncementBarProvider,
|
|
42
|
+
useAnnouncementBar,
|
|
43
|
+
} from './contexts/announcementBar';
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
useTabGroupChoice,
|
|
47
|
+
TabGroupChoiceProvider,
|
|
48
|
+
} from './contexts/tabGroupChoice';
|
|
49
|
+
|
|
50
|
+
export {useNavbarMobileSidebar} from './contexts/navbarMobileSidebar';
|
|
51
|
+
export {useNavbarSecondaryMenu} from './contexts/navbarSecondaryMenu/display';
|
|
52
|
+
|
|
53
|
+
export {ColorModeProvider} from './contexts/colorMode';
|
|
54
|
+
|
|
55
|
+
export {useAlternatePageUtils} from './utils/useAlternatePageUtils';
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
parseCodeBlockTitle,
|
|
59
|
+
parseLanguage,
|
|
60
|
+
parseLines,
|
|
61
|
+
containsLineNumbers,
|
|
62
|
+
} from './utils/codeBlockUtils';
|
|
63
|
+
|
|
64
|
+
export {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './utils/searchUtils';
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
isDocsPluginEnabled,
|
|
68
|
+
useDocById,
|
|
69
|
+
findSidebarCategory,
|
|
70
|
+
findFirstCategoryLink,
|
|
71
|
+
isActiveSidebarItem,
|
|
72
|
+
useSidebarBreadcrumbs,
|
|
73
|
+
useDocsVersionCandidates,
|
|
74
|
+
useLayoutDoc,
|
|
75
|
+
useLayoutDocsSidebar,
|
|
76
|
+
useDocRouteMetadata,
|
|
77
|
+
} from './utils/docsUtils';
|
|
78
|
+
|
|
79
|
+
export {useTitleFormatter} from './utils/generalUtils';
|
|
80
|
+
|
|
81
|
+
export {useLocationChange} from './utils/useLocationChange';
|
|
82
|
+
|
|
83
|
+
export {useLocalPathname} from './utils/useLocalPathname';
|
|
84
|
+
|
|
85
|
+
export {useHistoryPopHandler} from './utils/historyUtils';
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
useFilteredAndTreeifiedTOC,
|
|
89
|
+
useTreeifiedTOC,
|
|
90
|
+
type TOCTreeNode,
|
|
91
|
+
} from './utils/tocUtils';
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
ScrollControllerProvider,
|
|
95
|
+
useScrollController,
|
|
96
|
+
useScrollPosition,
|
|
97
|
+
useScrollPositionBlocker,
|
|
98
|
+
useSmoothScrollTo,
|
|
99
|
+
} from './utils/scrollUtils';
|
|
100
|
+
|
|
101
|
+
export {useHomePageRoute, isSamePath} from './utils/routesUtils';
|
|
102
|
+
|
|
103
|
+
export {PluginHtmlClassNameProvider} from './utils/metadataUtils';
|
|
104
|
+
|
|
105
|
+
export {splitNavbarItems, NavbarProvider} from './utils/navbarUtils';
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
useTOCHighlight,
|
|
109
|
+
type TOCHighlightConfig,
|
|
110
|
+
} from './hooks/useTOCHighlight';
|
|
111
|
+
|
|
112
|
+
export {useHideableNavbar} from './hooks/useHideableNavbar';
|
|
113
|
+
export {
|
|
114
|
+
useKeyboardNavigation,
|
|
115
|
+
keyboardFocusedClassName,
|
|
116
|
+
} from './hooks/useKeyboardNavigation';
|
|
117
|
+
export {useLockBodyScroll} from './hooks/useLockBodyScroll';
|
|
118
|
+
export {useSearchPage} from './hooks/useSearchPage';
|
|
119
|
+
export {useCodeWordWrap} from './hooks/useCodeWordWrap';
|
|
120
|
+
export {useSkipToContent} from './hooks/useSkipToContent';
|
|
121
|
+
export {getPrismCssVariables} from './utils/codeBlockUtils';
|
|
122
|
+
export {useBackToTopButton} from './hooks/useBackToTopButton';
|
|
@@ -31,19 +31,22 @@ export const ThemeClassNames = {
|
|
|
31
31
|
docsPages: 'docs-wrapper',
|
|
32
32
|
mdxPages: 'mdx-wrapper',
|
|
33
33
|
},
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
|
|
37
|
-
*/
|
|
38
34
|
common: {
|
|
39
35
|
editThisPage: 'theme-edit-this-page',
|
|
40
36
|
lastUpdated: 'theme-last-updated',
|
|
41
37
|
backToTopButton: 'theme-back-to-top-button',
|
|
42
38
|
codeBlock: 'theme-code-block',
|
|
39
|
+
admonition: 'theme-admonition',
|
|
40
|
+
admonitionType: (type: 'note' | 'tip' | 'danger' | 'info' | 'caution') =>
|
|
41
|
+
`theme-admonition-${type}`,
|
|
43
42
|
},
|
|
44
43
|
layout: {
|
|
45
44
|
// TODO add other stable classNames here
|
|
46
45
|
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
|
|
49
|
+
*/
|
|
47
50
|
docs: {
|
|
48
51
|
docVersionBanner: 'theme-doc-version-banner',
|
|
49
52
|
docVersionBadge: 'theme-doc-version-badge',
|
package/src/utils/docsUtils.tsx
CHANGED
|
@@ -324,7 +324,7 @@ export function useDocRouteMetadata({
|
|
|
324
324
|
? versionMetadata.docsSidebars[sidebarName]
|
|
325
325
|
: undefined;
|
|
326
326
|
|
|
327
|
-
const docElement = renderRoutes(docRoutes
|
|
327
|
+
const docElement = renderRoutes(docRoutes);
|
|
328
328
|
|
|
329
329
|
return {
|
|
330
330
|
docElement,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {useEffect} from 'react';
|
|
9
9
|
import {useHistory} from '@docusaurus/router';
|
|
10
|
-
import {
|
|
10
|
+
import {useEvent} from './reactUtils';
|
|
11
11
|
import type {Location, Action} from 'history';
|
|
12
12
|
|
|
13
13
|
type HistoryBlockHandler = (location: Location, action: Action) => void | false;
|
|
@@ -18,12 +18,12 @@ type HistoryBlockHandler = (location: Location, action: Action) => void | false;
|
|
|
18
18
|
* will be blocked/cancelled.
|
|
19
19
|
*/
|
|
20
20
|
function useHistoryActionHandler(handler: HistoryBlockHandler): void {
|
|
21
|
-
const
|
|
22
|
-
const stableHandler =
|
|
21
|
+
const history = useHistory();
|
|
22
|
+
const stableHandler = useEvent(handler);
|
|
23
23
|
useEffect(
|
|
24
24
|
// See https://github.com/remix-run/history/blob/main/docs/blocking-transitions.md
|
|
25
|
-
() => block((location, action) => stableHandler(location, action)),
|
|
26
|
-
[
|
|
25
|
+
() => history.block((location, action) => stableHandler(location, action)),
|
|
26
|
+
[history, stableHandler],
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|