@docusaurus/theme-common 2.0.0-beta.ff31de0ff → 2.0.1
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/components/Collapsible/index.d.ts +64 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +150 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +17 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +76 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +62 -0
- package/lib/contexts/announcementBar.d.ts +22 -0
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/contexts/announcementBar.js +72 -0
- package/lib/contexts/announcementBar.js.map +1 -0
- 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/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -0
- package/lib/contexts/colorMode.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/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.js +28 -0
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +30 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +130 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +50 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
- package/lib/contexts/tabGroupChoice.d.ts +21 -0
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/contexts/tabGroupChoice.js +49 -0
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +67 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +17 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +60 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +39 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +12 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +20 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- 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/hooks/usePrismTheme.d.ts +13 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +21 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +25 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +43 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/hooks/useTOCHighlight.js +130 -0
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +28 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +59 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +16 -11
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +23 -10
- package/lib/index.js.map +1 -0
- 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 +49 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +47 -4
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +63 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +159 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +91 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +217 -1
- package/lib/utils/docsUtils.js.map +1 -0
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +11 -1
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +9 -5
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +17 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +38 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +70 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +36 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +69 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +98 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +12 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +18 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +26 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +54 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +83 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +200 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +13 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +37 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +15 -7
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +58 -25
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +18 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +36 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +36 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +84 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +21 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +9 -4
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +13 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +19 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +17 -0
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +31 -0
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +12 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +36 -37
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +56 -27
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +4 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +35 -13
- package/src/components/Collapsible/index.tsx +263 -0
- package/src/components/Details/index.tsx +109 -0
- package/src/components/Details/styles.module.css +62 -0
- package/src/contexts/announcementBar.tsx +119 -0
- package/src/contexts/blogPost.tsx +80 -0
- package/src/contexts/colorMode.tsx +198 -0
- package/src/contexts/doc.tsx +71 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +251 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +100 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/contexts/tabGroupChoice.tsx +85 -0
- package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +105 -0
- package/src/hooks/useHideableNavbar.ts +75 -0
- package/src/hooks/useKeyboardNavigation.ts +45 -0
- package/src/hooks/useLockBodyScroll.ts +21 -0
- package/src/hooks/useMutationObserver.ts +38 -0
- package/src/hooks/usePrismTheme.ts +24 -0
- package/src/hooks/useSearchPage.ts +79 -0
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/hooks/useTOCHighlight.ts +189 -0
- package/src/hooks/useWindowSize.ts +72 -0
- package/src/index.ts +55 -23
- package/src/internal.ts +122 -0
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +54 -5
- package/src/utils/codeBlockUtils.ts +241 -2
- package/src/utils/docsUtils.tsx +334 -0
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +9 -5
- package/src/utils/historyUtils.ts +45 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +129 -0
- package/src/utils/regexpUtils.ts +24 -0
- package/src/utils/routesUtils.ts +75 -0
- package/src/utils/scrollUtils.tsx +304 -0
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +59 -26
- package/src/utils/tagsUtils.ts +50 -0
- package/src/utils/tocUtils.ts +119 -0
- package/src/utils/useAlternatePageUtils.ts +28 -7
- package/src/utils/useLocalPathname.ts +22 -0
- package/src/utils/useLocationChange.ts +41 -0
- package/src/utils/usePluralForm.ts +53 -39
- package/src/utils/useThemeConfig.ts +55 -29
- package/lib/.tsbuildinfo +0 -4115
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/pathUtils.js +0 -13
- package/lib/utils/useChangeRoute.js +0 -18
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
- package/src/utils/docsUtils.ts +0 -11
- package/src/utils/pathUtils.ts +0 -17
- package/src/utils/useChangeRoute.ts +0 -21
- package/tsconfig.json +0 -10
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';
|
package/src/types.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/* eslint-disable import/no-duplicates */
|
|
9
|
-
/* eslint-disable spaced-comment */
|
|
10
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
11
9
|
/// <reference types="@docusaurus/plugin-content-blog" />
|
|
12
10
|
/// <reference types="@docusaurus/plugin-content-docs" />
|
|
@@ -5,20 +5,69 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
//
|
|
8
|
+
// Please do not modify the classnames! This is a breaking change, and annoying
|
|
9
|
+
// for users!
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* These class names are used to style page layouts in Docusaurus, meant to be
|
|
13
|
+
* targeted by user-provided custom CSS selectors.
|
|
14
|
+
*/
|
|
9
15
|
export const ThemeClassNames = {
|
|
10
16
|
page: {
|
|
11
17
|
blogListPage: 'blog-list-page',
|
|
12
18
|
blogPostPage: 'blog-post-page',
|
|
13
19
|
blogTagsListPage: 'blog-tags-list-page',
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
blogTagPostListPage: 'blog-tags-post-list-page',
|
|
21
|
+
|
|
22
|
+
docsDocPage: 'docs-doc-page',
|
|
23
|
+
docsTagsListPage: 'docs-tags-list-page',
|
|
24
|
+
docsTagDocListPage: 'docs-tags-doc-list-page',
|
|
25
|
+
|
|
16
26
|
mdxPage: 'mdx-page',
|
|
17
27
|
},
|
|
18
28
|
wrapper: {
|
|
19
29
|
main: 'main-wrapper',
|
|
20
30
|
blogPages: 'blog-wrapper',
|
|
21
|
-
|
|
31
|
+
docsPages: 'docs-wrapper',
|
|
22
32
|
mdxPages: 'mdx-wrapper',
|
|
23
33
|
},
|
|
24
|
-
|
|
34
|
+
common: {
|
|
35
|
+
editThisPage: 'theme-edit-this-page',
|
|
36
|
+
lastUpdated: 'theme-last-updated',
|
|
37
|
+
backToTopButton: 'theme-back-to-top-button',
|
|
38
|
+
codeBlock: 'theme-code-block',
|
|
39
|
+
admonition: 'theme-admonition',
|
|
40
|
+
admonitionType: (type: 'note' | 'tip' | 'danger' | 'info' | 'caution') =>
|
|
41
|
+
`theme-admonition-${type}`,
|
|
42
|
+
},
|
|
43
|
+
layout: {
|
|
44
|
+
// TODO add other stable classNames here
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
|
|
49
|
+
*/
|
|
50
|
+
docs: {
|
|
51
|
+
docVersionBanner: 'theme-doc-version-banner',
|
|
52
|
+
docVersionBadge: 'theme-doc-version-badge',
|
|
53
|
+
docBreadcrumbs: 'theme-doc-breadcrumbs',
|
|
54
|
+
docMarkdown: 'theme-doc-markdown',
|
|
55
|
+
docTocMobile: 'theme-doc-toc-mobile',
|
|
56
|
+
docTocDesktop: 'theme-doc-toc-desktop',
|
|
57
|
+
docFooter: 'theme-doc-footer',
|
|
58
|
+
docFooterTagsRow: 'theme-doc-footer-tags-row',
|
|
59
|
+
docFooterEditMetaRow: 'theme-doc-footer-edit-meta-row',
|
|
60
|
+
docSidebarContainer: 'theme-doc-sidebar-container',
|
|
61
|
+
docSidebarMenu: 'theme-doc-sidebar-menu',
|
|
62
|
+
docSidebarItemCategory: 'theme-doc-sidebar-item-category',
|
|
63
|
+
docSidebarItemLink: 'theme-doc-sidebar-item-link',
|
|
64
|
+
docSidebarItemCategoryLevel: (level: number) =>
|
|
65
|
+
`theme-doc-sidebar-item-category-level-${level}` as const,
|
|
66
|
+
docSidebarItemLinkLevel: (level: number) =>
|
|
67
|
+
`theme-doc-sidebar-item-link-level-${level}` as const,
|
|
68
|
+
// TODO add other stable classNames here
|
|
69
|
+
},
|
|
70
|
+
blog: {
|
|
71
|
+
// TODO add other stable classNames here
|
|
72
|
+
},
|
|
73
|
+
} as const;
|
|
@@ -5,8 +5,247 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import type {CSSProperties} from 'react';
|
|
9
|
+
import rangeParser from 'parse-numeric-range';
|
|
10
|
+
import type {PrismTheme} from 'prism-react-renderer';
|
|
11
|
+
|
|
12
|
+
const codeBlockTitleRegex = /title=(?<quote>["'])(?<title>.*?)\1/;
|
|
13
|
+
const metastringLinesRangeRegex = /\{(?<range>[\d,-]+)\}/;
|
|
14
|
+
|
|
15
|
+
// Supported types of highlight comments
|
|
16
|
+
const commentPatterns = {
|
|
17
|
+
js: {start: '\\/\\/', end: ''},
|
|
18
|
+
jsBlock: {start: '\\/\\*', end: '\\*\\/'},
|
|
19
|
+
jsx: {start: '\\{\\s*\\/\\*', end: '\\*\\/\\s*\\}'},
|
|
20
|
+
bash: {start: '#', end: ''},
|
|
21
|
+
html: {start: '<!--', end: '-->'},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type CommentType = keyof typeof commentPatterns;
|
|
25
|
+
|
|
26
|
+
export type MagicCommentConfig = {
|
|
27
|
+
className: string;
|
|
28
|
+
line?: string;
|
|
29
|
+
block?: {start: string; end: string};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function getCommentPattern(
|
|
33
|
+
languages: CommentType[],
|
|
34
|
+
magicCommentDirectives: MagicCommentConfig[],
|
|
35
|
+
) {
|
|
36
|
+
// To be more reliable, the opening and closing comment must match
|
|
37
|
+
const commentPattern = languages
|
|
38
|
+
.map((lang) => {
|
|
39
|
+
const {start, end} = commentPatterns[lang];
|
|
40
|
+
return `(?:${start}\\s*(${magicCommentDirectives
|
|
41
|
+
.flatMap((d) => [d.line, d.block?.start, d.block?.end].filter(Boolean))
|
|
42
|
+
.join('|')})\\s*${end})`;
|
|
43
|
+
})
|
|
44
|
+
.join('|');
|
|
45
|
+
// White space is allowed, but otherwise it should be on it's own line
|
|
46
|
+
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Select comment styles based on language
|
|
51
|
+
*/
|
|
52
|
+
function getAllMagicCommentDirectiveStyles(
|
|
53
|
+
lang: string,
|
|
54
|
+
magicCommentDirectives: MagicCommentConfig[],
|
|
55
|
+
) {
|
|
56
|
+
switch (lang) {
|
|
57
|
+
case 'js':
|
|
58
|
+
case 'javascript':
|
|
59
|
+
case 'ts':
|
|
60
|
+
case 'typescript':
|
|
61
|
+
return getCommentPattern(['js', 'jsBlock'], magicCommentDirectives);
|
|
62
|
+
|
|
63
|
+
case 'jsx':
|
|
64
|
+
case 'tsx':
|
|
65
|
+
return getCommentPattern(
|
|
66
|
+
['js', 'jsBlock', 'jsx'],
|
|
67
|
+
magicCommentDirectives,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
case 'html':
|
|
71
|
+
return getCommentPattern(
|
|
72
|
+
['js', 'jsBlock', 'html'],
|
|
73
|
+
magicCommentDirectives,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
case 'python':
|
|
77
|
+
case 'py':
|
|
78
|
+
case 'bash':
|
|
79
|
+
return getCommentPattern(['bash'], magicCommentDirectives);
|
|
80
|
+
|
|
81
|
+
case 'markdown':
|
|
82
|
+
case 'md':
|
|
83
|
+
// Text uses HTML, front matter uses bash
|
|
84
|
+
return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives);
|
|
85
|
+
|
|
86
|
+
default:
|
|
87
|
+
// All comment types
|
|
88
|
+
return getCommentPattern(
|
|
89
|
+
Object.keys(commentPatterns) as CommentType[],
|
|
90
|
+
magicCommentDirectives,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
9
94
|
|
|
10
95
|
export function parseCodeBlockTitle(metastring?: string): string {
|
|
11
|
-
return metastring?.match(codeBlockTitleRegex)?.
|
|
96
|
+
return metastring?.match(codeBlockTitleRegex)?.groups!.title ?? '';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function containsLineNumbers(metastring?: string): boolean {
|
|
100
|
+
return Boolean(metastring?.includes('showLineNumbers'));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Gets the language name from the class name (set by MDX).
|
|
105
|
+
* e.g. `"language-javascript"` => `"javascript"`.
|
|
106
|
+
* Returns undefined if there is no language class name.
|
|
107
|
+
*/
|
|
108
|
+
export function parseLanguage(className: string): string | undefined {
|
|
109
|
+
const languageClassName = className
|
|
110
|
+
.split(' ')
|
|
111
|
+
.find((str) => str.startsWith('language-'));
|
|
112
|
+
return languageClassName?.replace(/language-/, '');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parses the code content, strips away any magic comments, and returns the
|
|
117
|
+
* clean content and the highlighted lines marked by the comments or metastring.
|
|
118
|
+
*
|
|
119
|
+
* If the metastring contains a range, the `content` will be returned as-is
|
|
120
|
+
* without any parsing. The returned `lineClassNames` will be a map from that
|
|
121
|
+
* number range to the first magic comment config entry (which _should_ be for
|
|
122
|
+
* line highlight directives.)
|
|
123
|
+
*
|
|
124
|
+
* @param content The raw code with magic comments. Trailing newline will be
|
|
125
|
+
* trimmed upfront.
|
|
126
|
+
* @param options Options for parsing behavior.
|
|
127
|
+
*/
|
|
128
|
+
export function parseLines(
|
|
129
|
+
content: string,
|
|
130
|
+
options: {
|
|
131
|
+
/**
|
|
132
|
+
* The full metastring, as received from MDX. Line ranges declared here
|
|
133
|
+
* start at 1.
|
|
134
|
+
*/
|
|
135
|
+
metastring: string | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Language of the code block, used to determine which kinds of magic
|
|
138
|
+
* comment styles to enable.
|
|
139
|
+
*/
|
|
140
|
+
language: string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Magic comment types that we should try to parse. Each entry would
|
|
143
|
+
* correspond to one class name to apply to each line.
|
|
144
|
+
*/
|
|
145
|
+
magicComments: MagicCommentConfig[];
|
|
146
|
+
},
|
|
147
|
+
): {
|
|
148
|
+
/**
|
|
149
|
+
* The highlighted lines, 0-indexed. e.g. `{ 0: ["highlight", "sample"] }`
|
|
150
|
+
* means the 1st line should have `highlight` and `sample` as class names.
|
|
151
|
+
*/
|
|
152
|
+
lineClassNames: {[lineIndex: number]: string[]};
|
|
153
|
+
/**
|
|
154
|
+
* If there's number range declared in the metastring, the code block is
|
|
155
|
+
* returned as-is (no parsing); otherwise, this is the clean code with all
|
|
156
|
+
* magic comments stripped away.
|
|
157
|
+
*/
|
|
158
|
+
code: string;
|
|
159
|
+
} {
|
|
160
|
+
let code = content.replace(/\n$/, '');
|
|
161
|
+
const {language, magicComments, metastring} = options;
|
|
162
|
+
// Highlighted lines specified in props: don't parse the content
|
|
163
|
+
if (metastring && metastringLinesRangeRegex.test(metastring)) {
|
|
164
|
+
const linesRange = metastring.match(metastringLinesRangeRegex)!.groups!
|
|
165
|
+
.range!;
|
|
166
|
+
if (magicComments.length === 0) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`A highlight range has been given in code block's metastring (\`\`\` ${metastring}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const metastringRangeClassName = magicComments[0]!.className;
|
|
172
|
+
const lines = rangeParser(linesRange)
|
|
173
|
+
.filter((n) => n > 0)
|
|
174
|
+
.map((n) => [n - 1, [metastringRangeClassName]] as [number, string[]]);
|
|
175
|
+
return {lineClassNames: Object.fromEntries(lines), code};
|
|
176
|
+
}
|
|
177
|
+
if (language === undefined) {
|
|
178
|
+
return {lineClassNames: {}, code};
|
|
179
|
+
}
|
|
180
|
+
const directiveRegex = getAllMagicCommentDirectiveStyles(
|
|
181
|
+
language,
|
|
182
|
+
magicComments,
|
|
183
|
+
);
|
|
184
|
+
// Go through line by line
|
|
185
|
+
const lines = code.split('\n');
|
|
186
|
+
const blocks = Object.fromEntries(
|
|
187
|
+
magicComments.map((d) => [d.className, {start: 0, range: ''}]),
|
|
188
|
+
);
|
|
189
|
+
const lineToClassName: {[comment: string]: string} = Object.fromEntries(
|
|
190
|
+
magicComments
|
|
191
|
+
.filter((d) => d.line)
|
|
192
|
+
.map(({className, line}) => [line!, className] as [string, string]),
|
|
193
|
+
);
|
|
194
|
+
const blockStartToClassName: {[comment: string]: string} = Object.fromEntries(
|
|
195
|
+
magicComments
|
|
196
|
+
.filter((d) => d.block)
|
|
197
|
+
.map(({className, block}) => [block!.start, className]),
|
|
198
|
+
);
|
|
199
|
+
const blockEndToClassName: {[comment: string]: string} = Object.fromEntries(
|
|
200
|
+
magicComments
|
|
201
|
+
.filter((d) => d.block)
|
|
202
|
+
.map(({className, block}) => [block!.end, className]),
|
|
203
|
+
);
|
|
204
|
+
for (let lineNumber = 0; lineNumber < lines.length; ) {
|
|
205
|
+
const line = lines[lineNumber]!;
|
|
206
|
+
const match = line.match(directiveRegex);
|
|
207
|
+
if (!match) {
|
|
208
|
+
// Lines without directives are unchanged
|
|
209
|
+
lineNumber += 1;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const directive = match
|
|
213
|
+
.slice(1)
|
|
214
|
+
.find((item: string | undefined) => item !== undefined)!;
|
|
215
|
+
if (lineToClassName[directive]) {
|
|
216
|
+
blocks[lineToClassName[directive]!]!.range += `${lineNumber},`;
|
|
217
|
+
} else if (blockStartToClassName[directive]) {
|
|
218
|
+
blocks[blockStartToClassName[directive]!]!.start = lineNumber;
|
|
219
|
+
} else if (blockEndToClassName[directive]) {
|
|
220
|
+
blocks[blockEndToClassName[directive]!]!.range += `${
|
|
221
|
+
blocks[blockEndToClassName[directive]!]!.start
|
|
222
|
+
}-${lineNumber - 1},`;
|
|
223
|
+
}
|
|
224
|
+
lines.splice(lineNumber, 1);
|
|
225
|
+
}
|
|
226
|
+
code = lines.join('\n');
|
|
227
|
+
const lineClassNames: {[lineIndex: number]: string[]} = {};
|
|
228
|
+
Object.entries(blocks).forEach(([className, {range}]) => {
|
|
229
|
+
rangeParser(range).forEach((l) => {
|
|
230
|
+
lineClassNames[l] ??= [];
|
|
231
|
+
lineClassNames[l]!.push(className);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
return {lineClassNames, code};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties {
|
|
238
|
+
const mapping: {[name: keyof PrismTheme['plain']]: string} = {
|
|
239
|
+
color: '--prism-color',
|
|
240
|
+
backgroundColor: '--prism-background-color',
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const properties: {[key: string]: string} = {};
|
|
244
|
+
Object.entries(prismTheme.plain).forEach(([key, value]) => {
|
|
245
|
+
const varName = mapping[key];
|
|
246
|
+
if (varName && typeof value === 'string') {
|
|
247
|
+
properties[varName] = value;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return properties;
|
|
12
251
|
}
|