@docusaurus/theme-common 2.4.1 → 3.0.0-beta.0

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 (130) hide show
  1. package/lib/components/Collapsible/index.d.ts +4 -4
  2. package/lib/components/Collapsible/index.d.ts.map +1 -1
  3. package/lib/components/Collapsible/index.js +4 -3
  4. package/lib/components/Collapsible/index.js.map +1 -1
  5. package/lib/components/Details/index.d.ts +1 -1
  6. package/lib/components/Details/index.d.ts.map +1 -1
  7. package/lib/components/Details/styles.module.css +5 -1
  8. package/lib/components/ThemedComponent/index.d.ts +32 -0
  9. package/lib/components/ThemedComponent/index.d.ts.map +1 -0
  10. package/lib/components/ThemedComponent/index.js +48 -0
  11. package/lib/components/ThemedComponent/index.js.map +1 -0
  12. package/lib/components/ThemedComponent/styles.module.css +26 -0
  13. package/lib/contexts/announcementBar.d.ts +1 -1
  14. package/lib/contexts/announcementBar.d.ts.map +1 -1
  15. package/lib/contexts/blogPost.d.ts +1 -1
  16. package/lib/contexts/blogPost.d.ts.map +1 -1
  17. package/lib/contexts/blogPost.js +3 -3
  18. package/lib/contexts/colorMode.d.ts +2 -2
  19. package/lib/contexts/colorMode.d.ts.map +1 -1
  20. package/lib/contexts/doc.d.ts +1 -1
  21. package/lib/contexts/doc.d.ts.map +1 -1
  22. package/lib/contexts/docSidebarItemsExpandedState.d.ts +1 -1
  23. package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -1
  24. package/lib/contexts/docsSidebar.d.ts +1 -1
  25. package/lib/contexts/docsSidebar.d.ts.map +1 -1
  26. package/lib/contexts/navbarMobileSidebar.d.ts +1 -1
  27. package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -1
  28. package/lib/contexts/navbarSecondaryMenu/content.d.ts +2 -2
  29. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -1
  30. package/lib/hooks/useMutationObserver.d.ts +1 -1
  31. package/lib/hooks/useMutationObserver.d.ts.map +1 -1
  32. package/lib/hooks/useTOCHighlight.d.ts +1 -1
  33. package/lib/hooks/useTOCHighlight.d.ts.map +1 -1
  34. package/lib/hooks/useWindowSize.d.ts +1 -1
  35. package/lib/hooks/useWindowSize.d.ts.map +1 -1
  36. package/lib/index.d.ts +4 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +4 -2
  39. package/lib/index.js.map +1 -1
  40. package/lib/internal.d.ts +3 -2
  41. package/lib/internal.d.ts.map +1 -1
  42. package/lib/internal.js +3 -2
  43. package/lib/internal.js.map +1 -1
  44. package/lib/utils/ThemeClassNames.d.ts +2 -1
  45. package/lib/utils/ThemeClassNames.d.ts.map +1 -1
  46. package/lib/utils/ThemeClassNames.js +4 -0
  47. package/lib/utils/ThemeClassNames.js.map +1 -1
  48. package/lib/utils/admonitionUtils.d.ts.map +1 -1
  49. package/lib/utils/admonitionUtils.js +5 -6
  50. package/lib/utils/admonitionUtils.js.map +1 -1
  51. package/lib/utils/blogUtils.d.ts +13 -0
  52. package/lib/utils/blogUtils.d.ts.map +1 -0
  53. package/lib/utils/blogUtils.js +24 -0
  54. package/lib/utils/blogUtils.js.map +1 -0
  55. package/lib/utils/codeBlockUtils.d.ts +1 -1
  56. package/lib/utils/codeBlockUtils.d.ts.map +1 -1
  57. package/lib/utils/codeBlockUtils.js +15 -2
  58. package/lib/utils/codeBlockUtils.js.map +1 -1
  59. package/lib/utils/docsUtils.d.ts +11 -5
  60. package/lib/utils/docsUtils.d.ts.map +1 -1
  61. package/lib/utils/docsUtils.js +40 -16
  62. package/lib/utils/docsUtils.js.map +1 -1
  63. package/lib/utils/errorBoundaryUtils.d.ts +3 -0
  64. package/lib/utils/errorBoundaryUtils.d.ts.map +1 -1
  65. package/lib/utils/errorBoundaryUtils.js +7 -0
  66. package/lib/utils/errorBoundaryUtils.js.map +1 -1
  67. package/lib/utils/errorBoundaryUtils.module.css +5 -0
  68. package/lib/utils/historyUtils.d.ts +1 -1
  69. package/lib/utils/historyUtils.d.ts.map +1 -1
  70. package/lib/utils/historyUtils.js +1 -3
  71. package/lib/utils/historyUtils.js.map +1 -1
  72. package/lib/utils/metadataUtils.d.ts +1 -1
  73. package/lib/utils/metadataUtils.d.ts.map +1 -1
  74. package/lib/utils/reactUtils.d.ts +2 -11
  75. package/lib/utils/reactUtils.d.ts.map +1 -1
  76. package/lib/utils/reactUtils.js +2 -13
  77. package/lib/utils/reactUtils.js.map +1 -1
  78. package/lib/utils/scrollUtils.d.ts +3 -3
  79. package/lib/utils/scrollUtils.d.ts.map +1 -1
  80. package/lib/utils/scrollUtils.js +3 -2
  81. package/lib/utils/scrollUtils.js.map +1 -1
  82. package/lib/utils/skipToContentUtils.d.ts +1 -1
  83. package/lib/utils/skipToContentUtils.d.ts.map +1 -1
  84. package/lib/utils/skipToContentUtils.js +1 -0
  85. package/lib/utils/skipToContentUtils.js.map +1 -1
  86. package/lib/utils/storageUtils.d.ts +2 -2
  87. package/lib/utils/storageUtils.d.ts.map +1 -1
  88. package/lib/utils/storageUtils.js +1 -3
  89. package/lib/utils/storageUtils.js.map +1 -1
  90. package/lib/utils/tabsUtils.d.ts +3 -2
  91. package/lib/utils/tabsUtils.d.ts.map +1 -1
  92. package/lib/utils/tabsUtils.js +10 -7
  93. package/lib/utils/tabsUtils.js.map +1 -1
  94. package/lib/utils/tagsUtils.d.ts +1 -1
  95. package/lib/utils/tagsUtils.d.ts.map +1 -1
  96. package/lib/utils/tocUtils.d.ts +1 -1
  97. package/lib/utils/tocUtils.d.ts.map +1 -1
  98. package/lib/utils/unlistedUtils.d.ts +11 -0
  99. package/lib/utils/unlistedUtils.d.ts.map +1 -0
  100. package/lib/utils/unlistedUtils.js +26 -0
  101. package/lib/utils/unlistedUtils.js.map +1 -0
  102. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
  103. package/lib/utils/useAlternatePageUtils.js +9 -2
  104. package/lib/utils/useAlternatePageUtils.js.map +1 -1
  105. package/lib/utils/useThemeConfig.d.ts +17 -17
  106. package/lib/utils/useThemeConfig.d.ts.map +1 -1
  107. package/package.json +15 -16
  108. package/src/components/Collapsible/index.tsx +3 -3
  109. package/src/components/Details/styles.module.css +5 -1
  110. package/src/components/ThemedComponent/index.tsx +77 -0
  111. package/src/components/ThemedComponent/styles.module.css +26 -0
  112. package/src/contexts/blogPost.tsx +3 -3
  113. package/src/contexts/colorMode.tsx +1 -1
  114. package/src/index.ts +9 -1
  115. package/src/internal.ts +7 -3
  116. package/src/utils/ThemeClassNames.ts +6 -2
  117. package/src/utils/admonitionUtils.tsx +9 -8
  118. package/src/utils/blogUtils.ts +32 -0
  119. package/src/utils/codeBlockUtils.ts +21 -2
  120. package/src/utils/docsUtils.tsx +57 -19
  121. package/src/utils/errorBoundaryUtils.module.css +5 -0
  122. package/src/utils/errorBoundaryUtils.tsx +15 -0
  123. package/src/utils/historyUtils.ts +1 -3
  124. package/src/utils/reactUtils.tsx +1 -15
  125. package/src/utils/scrollUtils.tsx +2 -2
  126. package/src/utils/skipToContentUtils.tsx +1 -0
  127. package/src/utils/storageUtils.ts +2 -4
  128. package/src/utils/tabsUtils.tsx +20 -18
  129. package/src/utils/unlistedUtils.tsx +39 -0
  130. package/src/utils/useAlternatePageUtils.ts +11 -2
@@ -12,9 +12,9 @@ import React, {
12
12
  useMemo,
13
13
  type ReactNode,
14
14
  type ReactElement,
15
- useLayoutEffect,
16
15
  } from 'react';
17
16
  import {useHistory} from '@docusaurus/router';
17
+ import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
18
18
  import {useQueryStringValue} from '@docusaurus/theme-common/internal';
19
19
  import {duplicates, useStorageSlot} from '../index';
20
20
 
@@ -61,25 +61,27 @@ function isTabItem(
61
61
  return !!props && typeof props === 'object' && 'value' in props;
62
62
  }
63
63
 
64
- function ensureValidChildren(children: TabsProps['children']) {
65
- return (React.Children.map(children, (child) => {
66
- // Pass falsy values through: allow conditionally not rendering a tab
67
- if (!child || (isValidElement(child) && isTabItem(child))) {
68
- return child;
69
- }
70
- // child.type.name will give non-sensical values in prod because of
71
- // minification, but we assume it won't throw in prod.
72
- throw new Error(
73
- `Docusaurus error: Bad <Tabs> child <${
74
- // @ts-expect-error: guarding against unexpected cases
75
- typeof child.type === 'string' ? child.type : child.type.name
76
- }>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`,
77
- );
78
- })?.filter(Boolean) ?? []) as ReactElement<TabItemProps>[];
64
+ export function sanitizeTabsChildren(children: TabsProps['children']) {
65
+ return (React.Children.toArray(children)
66
+ .filter((child) => child !== '\n')
67
+ .map((child) => {
68
+ if (!child || (isValidElement(child) && isTabItem(child))) {
69
+ return child;
70
+ }
71
+ // child.type.name will give non-sensical values in prod because of
72
+ // minification, but we assume it won't throw in prod.
73
+ throw new Error(
74
+ `Docusaurus error: Bad <Tabs> child <${
75
+ // @ts-expect-error: guarding against unexpected cases
76
+ typeof child.type === 'string' ? child.type : child.type.name
77
+ }>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`,
78
+ );
79
+ })
80
+ ?.filter(Boolean) ?? []) as ReactElement<TabItemProps>[];
79
81
  }
80
82
 
81
83
  function extractChildrenTabValues(children: TabsProps['children']): TabValue[] {
82
- return ensureValidChildren(children).map(
84
+ return sanitizeTabsChildren(children).map(
83
85
  ({props: {value, label, attributes, default: isDefault}}) => ({
84
86
  value,
85
87
  label,
@@ -250,7 +252,7 @@ export function useTabs(props: TabsProps): {
250
252
  })();
251
253
  // Sync in a layout/sync effect is important, for useScrollPositionBlocker
252
254
  // See https://github.com/facebook/docusaurus/issues/8625
253
- useLayoutEffect(() => {
255
+ useIsomorphicLayoutEffect(() => {
254
256
  if (valueToSync) {
255
257
  setSelectedValue(valueToSync);
256
258
  }
@@ -0,0 +1,39 @@
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 from 'react';
9
+ import Translate from '@docusaurus/Translate';
10
+ import Head from '@docusaurus/Head';
11
+
12
+ export function UnlistedBannerTitle(): JSX.Element {
13
+ return (
14
+ <Translate
15
+ id="theme.unlistedContent.title"
16
+ description="The unlisted content banner title">
17
+ Unlisted page
18
+ </Translate>
19
+ );
20
+ }
21
+
22
+ export function UnlistedBannerMessage(): JSX.Element {
23
+ return (
24
+ <Translate
25
+ id="theme.unlistedContent.message"
26
+ description="The unlisted content banner message">
27
+ This page is unlisted. Search engines will not index it, and only users
28
+ having a direct link can access it.
29
+ </Translate>
30
+ );
31
+ }
32
+
33
+ export function UnlistedMetadata(): JSX.Element {
34
+ return (
35
+ <Head>
36
+ <meta name="robots" content="noindex, nofollow" />
37
+ </Head>
38
+ );
39
+ }
@@ -7,6 +7,7 @@
7
7
 
8
8
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
9
  import {useLocation} from '@docusaurus/router';
10
+ import {applyTrailingSlash} from '@docusaurus/utils-common';
10
11
 
11
12
  /**
12
13
  * Permits to obtain the url of the current page in another locale, useful to
@@ -35,17 +36,25 @@ export function useAlternatePageUtils(): {
35
36
  }) => string;
36
37
  } {
37
38
  const {
38
- siteConfig: {baseUrl, url},
39
+ siteConfig: {baseUrl, url, trailingSlash},
39
40
  i18n: {defaultLocale, currentLocale},
40
41
  } = useDocusaurusContext();
42
+
43
+ // TODO using useLocation().pathname is not a super idea
44
+ // See https://github.com/facebook/docusaurus/issues/9170
41
45
  const {pathname} = useLocation();
42
46
 
47
+ const canonicalPathname = applyTrailingSlash(pathname, {
48
+ trailingSlash,
49
+ baseUrl,
50
+ });
51
+
43
52
  const baseUrlUnlocalized =
44
53
  currentLocale === defaultLocale
45
54
  ? baseUrl
46
55
  : baseUrl.replace(`/${currentLocale}/`, '/');
47
56
 
48
- const pathnameSuffix = pathname.replace(baseUrl, '');
57
+ const pathnameSuffix = canonicalPathname.replace(baseUrl, '');
49
58
 
50
59
  function getLocalizedBaseUrl(locale: string) {
51
60
  return locale === defaultLocale