@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.
Files changed (128) hide show
  1. package/Details.d.ts +14 -0
  2. package/lib/components/Collapsible/index.js +2 -2
  3. package/lib/components/Collapsible/index.js.map +1 -1
  4. package/lib/components/Details/index.d.ts.map +1 -1
  5. package/lib/components/Details/index.js +3 -2
  6. package/lib/components/Details/index.js.map +1 -1
  7. package/lib/components/Details/styles.module.css +4 -0
  8. package/lib/contexts/announcementBar.js +1 -1
  9. package/lib/contexts/colorMode.d.ts.map +1 -1
  10. package/lib/contexts/colorMode.js +34 -16
  11. package/lib/contexts/colorMode.js.map +1 -1
  12. package/lib/contexts/docsPreferredVersion.d.ts +5 -2
  13. package/lib/contexts/docsPreferredVersion.d.ts.map +1 -1
  14. package/lib/contexts/docsPreferredVersion.js +5 -2
  15. package/lib/contexts/docsPreferredVersion.js.map +1 -1
  16. package/lib/contexts/docsSidebar.d.ts +9 -3
  17. package/lib/contexts/docsSidebar.d.ts.map +1 -1
  18. package/lib/contexts/docsSidebar.js +7 -6
  19. package/lib/contexts/docsSidebar.js.map +1 -1
  20. package/lib/contexts/navbarMobileSidebar.js +5 -5
  21. package/lib/contexts/navbarMobileSidebar.js.map +1 -1
  22. package/lib/contexts/{navbarSecondaryMenu.d.ts → navbarSecondaryMenu/content.d.ts} +13 -14
  23. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
  24. package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
  25. package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
  26. package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
  27. package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
  28. package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
  29. package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
  30. package/lib/contexts/tabGroupChoice.d.ts.map +1 -1
  31. package/lib/contexts/tabGroupChoice.js.map +1 -1
  32. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  33. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  34. package/lib/hooks/useBackToTopButton.js +50 -0
  35. package/lib/hooks/useBackToTopButton.js.map +1 -0
  36. package/lib/hooks/useCodeWordWrap.d.ts +14 -0
  37. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  38. package/lib/hooks/useCodeWordWrap.js +41 -0
  39. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  40. package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
  41. package/lib/hooks/useHideableNavbar.js +1 -2
  42. package/lib/hooks/useHideableNavbar.js.map +1 -1
  43. package/lib/hooks/usePrismTheme.d.ts +2 -2
  44. package/lib/hooks/usePrismTheme.d.ts.map +1 -1
  45. package/lib/hooks/usePrismTheme.js +1 -2
  46. package/lib/hooks/usePrismTheme.js.map +1 -1
  47. package/lib/hooks/useSkipToContent.d.ts +25 -0
  48. package/lib/hooks/useSkipToContent.d.ts.map +1 -0
  49. package/lib/hooks/useSkipToContent.js +35 -0
  50. package/lib/hooks/useSkipToContent.js.map +1 -0
  51. package/lib/hooks/useTOCHighlight.js +3 -3
  52. package/lib/hooks/useTOCHighlight.js.map +1 -1
  53. package/lib/index.d.ts +9 -6
  54. package/lib/index.d.ts.map +1 -1
  55. package/lib/index.js +8 -5
  56. package/lib/index.js.map +1 -1
  57. package/lib/utils/codeBlockUtils.d.ts +42 -12
  58. package/lib/utils/codeBlockUtils.d.ts.map +1 -1
  59. package/lib/utils/codeBlockUtils.js +89 -58
  60. package/lib/utils/codeBlockUtils.js.map +1 -1
  61. package/lib/utils/docsUtils.d.ts +58 -0
  62. package/lib/utils/docsUtils.d.ts.map +1 -1
  63. package/lib/utils/docsUtils.js +109 -10
  64. package/lib/utils/docsUtils.js.map +1 -1
  65. package/lib/utils/metadataUtils.d.ts +2 -2
  66. package/lib/utils/metadataUtils.d.ts.map +1 -1
  67. package/lib/utils/navbarUtils.d.ts +2 -2
  68. package/lib/utils/navbarUtils.d.ts.map +1 -1
  69. package/lib/utils/navbarUtils.js +7 -5
  70. package/lib/utils/navbarUtils.js.map +1 -1
  71. package/lib/utils/routesUtils.d.ts +4 -4
  72. package/lib/utils/routesUtils.d.ts.map +1 -1
  73. package/lib/utils/routesUtils.js.map +1 -1
  74. package/lib/utils/scrollUtils.d.ts +24 -0
  75. package/lib/utils/scrollUtils.d.ts.map +1 -1
  76. package/lib/utils/scrollUtils.js +52 -0
  77. package/lib/utils/scrollUtils.js.map +1 -1
  78. package/lib/utils/searchUtils.d.ts.map +1 -1
  79. package/lib/utils/searchUtils.js +2 -0
  80. package/lib/utils/searchUtils.js.map +1 -1
  81. package/lib/utils/storageUtils.d.ts +2 -2
  82. package/lib/utils/storageUtils.d.ts.map +1 -1
  83. package/lib/utils/tagsUtils.d.ts +3 -7
  84. package/lib/utils/tagsUtils.d.ts.map +1 -1
  85. package/lib/utils/tagsUtils.js +2 -2
  86. package/lib/utils/tagsUtils.js.map +1 -1
  87. package/lib/utils/tocUtils.d.ts +2 -2
  88. package/lib/utils/tocUtils.d.ts.map +1 -1
  89. package/lib/utils/tocUtils.js +4 -4
  90. package/lib/utils/tocUtils.js.map +1 -1
  91. package/lib/utils/useThemeConfig.d.ts +7 -4
  92. package/lib/utils/useThemeConfig.d.ts.map +1 -1
  93. package/lib/utils/useThemeConfig.js.map +1 -1
  94. package/package.json +18 -10
  95. package/src/components/Collapsible/index.tsx +2 -2
  96. package/src/components/Details/index.tsx +4 -2
  97. package/src/components/Details/styles.module.css +4 -0
  98. package/src/contexts/announcementBar.tsx +1 -1
  99. package/src/contexts/colorMode.tsx +38 -15
  100. package/src/contexts/docsPreferredVersion.tsx +5 -2
  101. package/src/contexts/docsSidebar.tsx +17 -9
  102. package/src/contexts/navbarMobileSidebar.tsx +5 -5
  103. package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
  104. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  105. package/src/contexts/tabGroupChoice.tsx +6 -3
  106. package/src/hooks/useBackToTopButton.ts +73 -0
  107. package/src/hooks/useCodeWordWrap.ts +56 -0
  108. package/src/hooks/useHideableNavbar.ts +1 -3
  109. package/src/hooks/usePrismTheme.ts +3 -3
  110. package/src/hooks/useSkipToContent.ts +58 -0
  111. package/src/hooks/useTOCHighlight.ts +3 -3
  112. package/src/index.ts +12 -5
  113. package/src/utils/codeBlockUtils.ts +150 -66
  114. package/src/utils/docsUtils.tsx +163 -9
  115. package/src/utils/metadataUtils.tsx +2 -2
  116. package/src/utils/navbarUtils.tsx +11 -6
  117. package/src/utils/routesUtils.ts +7 -7
  118. package/src/utils/scrollUtils.tsx +74 -0
  119. package/src/utils/searchUtils.ts +2 -0
  120. package/src/utils/storageUtils.ts +2 -2
  121. package/src/utils/tagsUtils.ts +4 -9
  122. package/src/utils/tocUtils.ts +5 -5
  123. package/src/utils/useThemeConfig.ts +7 -4
  124. package/yarn-error.log +20199 -0
  125. package/lib/contexts/navbarSecondaryMenu.d.ts.map +0 -1
  126. package/lib/contexts/navbarSecondaryMenu.js +0 -93
  127. package/lib/contexts/navbarSecondaryMenu.js.map +0 -1
  128. 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
+ }
@@ -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 interface StorageSlot {
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,
@@ -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 TagsListItem = Readonly<{
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.name);
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.name.localeCompare(tag2.name),
45
+ tag1.label.localeCompare(tag2.label),
51
46
  );
52
47
  return {letter, tags: sortedTags};
53
48
  })
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import {useMemo} from 'react';
9
- import type {TOCItem} from '@docusaurus/types';
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
- // take the last seen index for each ancestor level. the highest
34
- // index will be the direct ancestor of the current heading.
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
- // mark that curr.level was last seen at the current index
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 parents)
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?: PrismTheme;
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