@docusaurus/theme-common 2.0.0-beta.18 → 2.0.0-beta.19
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/Details.d.ts +14 -0
- package/lib/components/Collapsible/index.js +2 -2
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +3 -2
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -0
- package/lib/contexts/announcementBar.js +1 -1
- package/lib/contexts/colorMode.d.ts.map +1 -1
- package/lib/contexts/colorMode.js +34 -16
- package/lib/contexts/colorMode.js.map +1 -1
- package/lib/contexts/docsPreferredVersion.d.ts +5 -2
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -1
- package/lib/contexts/docsPreferredVersion.js +5 -2
- package/lib/contexts/docsPreferredVersion.js.map +1 -1
- package/lib/contexts/docsSidebar.d.ts +9 -3
- package/lib/contexts/docsSidebar.d.ts.map +1 -1
- package/lib/contexts/docsSidebar.js +7 -6
- package/lib/contexts/docsSidebar.js.map +1 -1
- package/lib/contexts/navbarMobileSidebar.js +5 -5
- package/lib/contexts/navbarMobileSidebar.js.map +1 -1
- package/lib/contexts/{navbarSecondaryMenu.d.ts → navbarSecondaryMenu/content.d.ts} +13 -14
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -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.map +1 -1
- package/lib/contexts/tabGroupChoice.js.map +1 -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 +41 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +1 -2
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +2 -2
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +1 -2
- package/lib/hooks/usePrismTheme.js.map +1 -1
- 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.js +3 -3
- package/lib/hooks/useTOCHighlight.js.map +1 -1
- package/lib/index.d.ts +9 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -5
- package/lib/index.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +42 -12
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +89 -58
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +58 -0
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +109 -10
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/metadataUtils.d.ts +2 -2
- package/lib/utils/metadataUtils.d.ts.map +1 -1
- package/lib/utils/navbarUtils.d.ts +2 -2
- package/lib/utils/navbarUtils.d.ts.map +1 -1
- package/lib/utils/navbarUtils.js +7 -5
- package/lib/utils/navbarUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +4 -4
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +24 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +52 -0
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +2 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +2 -2
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.d.ts +3 -7
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +2 -2
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +2 -2
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +4 -4
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +7 -4
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +18 -10
- package/src/components/Collapsible/index.tsx +2 -2
- package/src/components/Details/index.tsx +4 -2
- package/src/components/Details/styles.module.css +4 -0
- package/src/contexts/announcementBar.tsx +1 -1
- package/src/contexts/colorMode.tsx +38 -15
- package/src/contexts/docsPreferredVersion.tsx +5 -2
- package/src/contexts/docsSidebar.tsx +17 -9
- package/src/contexts/navbarMobileSidebar.tsx +5 -5
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/contexts/tabGroupChoice.tsx +6 -3
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +1 -3
- package/src/hooks/usePrismTheme.ts +3 -3
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/hooks/useTOCHighlight.ts +3 -3
- package/src/index.ts +12 -5
- package/src/utils/codeBlockUtils.ts +150 -66
- package/src/utils/docsUtils.tsx +163 -9
- package/src/utils/metadataUtils.tsx +2 -2
- package/src/utils/navbarUtils.tsx +11 -6
- package/src/utils/routesUtils.ts +7 -7
- package/src/utils/scrollUtils.tsx +74 -0
- package/src/utils/searchUtils.ts +2 -0
- package/src/utils/storageUtils.ts +2 -2
- package/src/utils/tagsUtils.ts +4 -9
- package/src/utils/tocUtils.ts +5 -5
- package/src/utils/useThemeConfig.ts +7 -4
- package/yarn-error.log +20199 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts.map +0 -1
- package/lib/contexts/navbarSecondaryMenu.js +0 -93
- package/lib/contexts/navbarSecondaryMenu.js.map +0 -1
- package/src/contexts/navbarSecondaryMenu.tsx +0 -170
|
@@ -16,6 +16,7 @@ import React, {
|
|
|
16
16
|
} from 'react';
|
|
17
17
|
import {useDynamicCallback, ReactContextError} from './reactUtils';
|
|
18
18
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
19
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
19
20
|
|
|
20
21
|
type ScrollController = {
|
|
21
22
|
/** A boolean ref tracking whether scroll events are enabled. */
|
|
@@ -232,3 +233,76 @@ export function useScrollPositionBlocker(): {
|
|
|
232
233
|
blockElementScrollPositionUntilNextRender,
|
|
233
234
|
};
|
|
234
235
|
}
|
|
236
|
+
|
|
237
|
+
type CancelScrollTop = () => void;
|
|
238
|
+
|
|
239
|
+
function smoothScrollNative(top: number): CancelScrollTop {
|
|
240
|
+
window.scrollTo({top, behavior: 'smooth'});
|
|
241
|
+
return () => {
|
|
242
|
+
// Nothing to cancel, it's natively cancelled if user tries to scroll down
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function smoothScrollPolyfill(top: number): CancelScrollTop {
|
|
247
|
+
let raf: number | null = null;
|
|
248
|
+
const isUpScroll = document.documentElement.scrollTop > top;
|
|
249
|
+
function rafRecursion() {
|
|
250
|
+
const currentScroll = document.documentElement.scrollTop;
|
|
251
|
+
if (
|
|
252
|
+
(isUpScroll && currentScroll > top) ||
|
|
253
|
+
(!isUpScroll && currentScroll < top)
|
|
254
|
+
) {
|
|
255
|
+
raf = requestAnimationFrame(rafRecursion);
|
|
256
|
+
window.scrollTo(0, Math.floor((currentScroll - top) * 0.85) + top);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
rafRecursion();
|
|
260
|
+
|
|
261
|
+
// Break the recursion. Prevents the user from "fighting" against that
|
|
262
|
+
// recursion producing a weird UX
|
|
263
|
+
return () => raf && cancelAnimationFrame(raf);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* A "smart polyfill" of `window.scrollTo({ top, behavior: "smooth" })`.
|
|
268
|
+
* This currently always uses a polyfilled implementation unless
|
|
269
|
+
* `scroll-behavior: smooth` has been set in CSS, because native support
|
|
270
|
+
* detection for scroll behavior seems unreliable.
|
|
271
|
+
*
|
|
272
|
+
* This hook does not do anything by itself: it returns a start and a stop
|
|
273
|
+
* handle. You can execute either handle at any time.
|
|
274
|
+
*/
|
|
275
|
+
export function useSmoothScrollTo(): {
|
|
276
|
+
/**
|
|
277
|
+
* Start the scroll.
|
|
278
|
+
*
|
|
279
|
+
* @param top The final scroll top position.
|
|
280
|
+
*/
|
|
281
|
+
startScroll: (top: number) => void;
|
|
282
|
+
/**
|
|
283
|
+
* A cancel function, because the non-native smooth scroll-top
|
|
284
|
+
* implementation must be interrupted if user scrolls down. If there's no
|
|
285
|
+
* existing animation or the scroll is using native behavior, this is a no-op.
|
|
286
|
+
*/
|
|
287
|
+
cancelScroll: CancelScrollTop;
|
|
288
|
+
} {
|
|
289
|
+
const cancelRef = useRef<CancelScrollTop | null>(null);
|
|
290
|
+
const isBrowser = useIsBrowser();
|
|
291
|
+
// Not all have support for smooth scrolling (particularly Safari mobile iOS)
|
|
292
|
+
// TODO proper detection is currently unreliable!
|
|
293
|
+
// see https://github.com/wessberg/scroll-behavior-polyfill/issues/16
|
|
294
|
+
// For now, we only use native scroll behavior if smooth is already set,
|
|
295
|
+
// because otherwise the polyfill produces a weird UX when both CSS and JS try
|
|
296
|
+
// to scroll a page, and they cancel each other.
|
|
297
|
+
const supportsNativeSmoothScrolling =
|
|
298
|
+
isBrowser &&
|
|
299
|
+
getComputedStyle(document.documentElement).scrollBehavior === 'smooth';
|
|
300
|
+
return {
|
|
301
|
+
startScroll: (top: number) => {
|
|
302
|
+
cancelRef.current = supportsNativeSmoothScrolling
|
|
303
|
+
? smoothScrollNative(top)
|
|
304
|
+
: smoothScrollPolyfill(top);
|
|
305
|
+
},
|
|
306
|
+
cancelScroll: () => cancelRef.current?.(),
|
|
307
|
+
};
|
|
308
|
+
}
|
package/src/utils/searchUtils.ts
CHANGED
|
@@ -35,6 +35,8 @@ export function useContextualSearchFilters(): {locale: string; tags: string[]} {
|
|
|
35
35
|
const activePluginAndVersion = useActivePluginAndVersion();
|
|
36
36
|
const docsPreferredVersionByPluginId = useDocsPreferredVersionByPluginId();
|
|
37
37
|
|
|
38
|
+
// This can't use more specialized hooks because we are mapping over all
|
|
39
|
+
// plugin instances.
|
|
38
40
|
function getDocPluginTags(pluginId: string) {
|
|
39
41
|
const activeVersion =
|
|
40
42
|
activePluginAndVersion?.activePlugin?.pluginId === pluginId
|
|
@@ -54,11 +54,11 @@ Possible reasons: running Docusaurus in an iframe, in an incognito browser sessi
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Convenient storage interface for a single storage key
|
|
57
|
-
export
|
|
57
|
+
export type StorageSlot = {
|
|
58
58
|
get: () => string | null;
|
|
59
59
|
set: (value: string) => void;
|
|
60
60
|
del: () => void;
|
|
61
|
-
}
|
|
61
|
+
};
|
|
62
62
|
|
|
63
63
|
const NoopStorageSlot: StorageSlot = {
|
|
64
64
|
get: () => null,
|
package/src/utils/tagsUtils.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {translate} from '@docusaurus/Translate';
|
|
9
|
+
import type {TagsListItem} from '@docusaurus/utils';
|
|
9
10
|
|
|
10
11
|
export const translateTagsPageTitle = (): string =>
|
|
11
12
|
translate({
|
|
@@ -14,13 +15,7 @@ export const translateTagsPageTitle = (): string =>
|
|
|
14
15
|
description: 'The title of the tag list page',
|
|
15
16
|
});
|
|
16
17
|
|
|
17
|
-
export type
|
|
18
|
-
name: string;
|
|
19
|
-
permalink: string;
|
|
20
|
-
count: number;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export type TagLetterEntry = Readonly<{letter: string; tags: TagsListItem[]}>;
|
|
18
|
+
export type TagLetterEntry = {letter: string; tags: TagsListItem[]};
|
|
24
19
|
|
|
25
20
|
function getTagLetter(tag: string): string {
|
|
26
21
|
return tag[0]!.toUpperCase();
|
|
@@ -35,7 +30,7 @@ export function listTagsByLetters(
|
|
|
35
30
|
): TagLetterEntry[] {
|
|
36
31
|
const groups: {[initial: string]: TagsListItem[]} = {};
|
|
37
32
|
Object.values(tags).forEach((tag) => {
|
|
38
|
-
const initial = getTagLetter(tag.
|
|
33
|
+
const initial = getTagLetter(tag.label);
|
|
39
34
|
groups[initial] ??= [];
|
|
40
35
|
groups[initial]!.push(tag);
|
|
41
36
|
});
|
|
@@ -47,7 +42,7 @@ export function listTagsByLetters(
|
|
|
47
42
|
.map(([letter, letterTags]) => {
|
|
48
43
|
// Sort tags inside a letter
|
|
49
44
|
const sortedTags = letterTags.sort((tag1, tag2) =>
|
|
50
|
-
tag1.
|
|
45
|
+
tag1.label.localeCompare(tag2.label),
|
|
51
46
|
);
|
|
52
47
|
return {letter, tags: sortedTags};
|
|
53
48
|
})
|
package/src/utils/tocUtils.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {useMemo} from 'react';
|
|
9
|
-
import type {TOCItem} from '@docusaurus/
|
|
9
|
+
import type {TOCItem} from '@docusaurus/mdx-loader';
|
|
10
10
|
|
|
11
11
|
export type TOCTreeNode = {
|
|
12
12
|
readonly value: string;
|
|
@@ -30,11 +30,11 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
|
|
|
30
30
|
const prevIndexForLevel = Array(7).fill(-1);
|
|
31
31
|
|
|
32
32
|
headings.forEach((curr, currIndex) => {
|
|
33
|
-
//
|
|
34
|
-
//
|
|
33
|
+
// Take the last seen index for each ancestor level. the highest index will
|
|
34
|
+
// be the direct ancestor of the current heading.
|
|
35
35
|
const ancestorLevelIndexes = prevIndexForLevel.slice(2, curr.level);
|
|
36
36
|
curr.parentIndex = Math.max(...ancestorLevelIndexes);
|
|
37
|
-
//
|
|
37
|
+
// Mark that curr.level was last seen at the current index.
|
|
38
38
|
prevIndexForLevel[curr.level] = currIndex;
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -101,7 +101,7 @@ function filterTOC({
|
|
|
101
101
|
* to ensure that weird TOC structures preserve their semantics. For example, an
|
|
102
102
|
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
|
|
103
103
|
* min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
|
|
104
|
-
* the two headings and they are not
|
|
104
|
+
* the two headings and they are not parent-children)
|
|
105
105
|
*/
|
|
106
106
|
export function useFilteredAndTreeifiedTOC({
|
|
107
107
|
toc,
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
9
|
import type {PrismTheme} from 'prism-react-renderer';
|
|
10
10
|
import type {DeepPartial} from 'utility-types';
|
|
11
|
+
import type {MagicCommentConfig} from './codeBlockUtils';
|
|
11
12
|
|
|
12
13
|
export type DocsVersionPersistence = 'localStorage' | 'none';
|
|
13
14
|
|
|
@@ -53,10 +54,11 @@ export type AnnouncementBarConfig = {
|
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
export type PrismConfig = {
|
|
56
|
-
theme
|
|
57
|
+
theme: PrismTheme;
|
|
57
58
|
darkTheme?: PrismTheme;
|
|
58
59
|
defaultLanguage?: string;
|
|
59
60
|
additionalLanguages: string[];
|
|
61
|
+
magicComments: MagicCommentConfig[];
|
|
60
62
|
};
|
|
61
63
|
|
|
62
64
|
export type FooterLinkItem = {
|
|
@@ -104,6 +106,10 @@ export type TableOfContents = {
|
|
|
104
106
|
export type ThemeConfig = {
|
|
105
107
|
docs: {
|
|
106
108
|
versionPersistence: DocsVersionPersistence;
|
|
109
|
+
sidebar: {
|
|
110
|
+
hideable: boolean;
|
|
111
|
+
autoCollapseCategories: boolean;
|
|
112
|
+
};
|
|
107
113
|
};
|
|
108
114
|
|
|
109
115
|
// TODO we should complete this theme config type over time
|
|
@@ -116,11 +122,8 @@ export type ThemeConfig = {
|
|
|
116
122
|
announcementBar?: AnnouncementBarConfig;
|
|
117
123
|
prism: PrismConfig;
|
|
118
124
|
footer?: Footer;
|
|
119
|
-
hideableSidebar: boolean;
|
|
120
|
-
autoCollapseSidebarCategories: boolean;
|
|
121
125
|
image?: string;
|
|
122
126
|
metadata: Array<{[key: string]: string}>;
|
|
123
|
-
sidebarCollapsible: boolean;
|
|
124
127
|
tableOfContents: TableOfContents;
|
|
125
128
|
};
|
|
126
129
|
|