@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.
- package/lib/components/Collapsible/index.d.ts +4 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +4 -3
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +1 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/styles.module.css +5 -1
- package/lib/components/ThemedComponent/index.d.ts +32 -0
- package/lib/components/ThemedComponent/index.d.ts.map +1 -0
- package/lib/components/ThemedComponent/index.js +48 -0
- package/lib/components/ThemedComponent/index.js.map +1 -0
- package/lib/components/ThemedComponent/styles.module.css +26 -0
- package/lib/contexts/announcementBar.d.ts +1 -1
- package/lib/contexts/announcementBar.d.ts.map +1 -1
- package/lib/contexts/blogPost.d.ts +1 -1
- package/lib/contexts/blogPost.d.ts.map +1 -1
- package/lib/contexts/blogPost.js +3 -3
- package/lib/contexts/colorMode.d.ts +2 -2
- package/lib/contexts/colorMode.d.ts.map +1 -1
- package/lib/contexts/doc.d.ts +1 -1
- package/lib/contexts/doc.d.ts.map +1 -1
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +1 -1
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -1
- package/lib/contexts/docsSidebar.d.ts +1 -1
- package/lib/contexts/docsSidebar.d.ts.map +1 -1
- package/lib/contexts/navbarMobileSidebar.d.ts +1 -1
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -1
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +2 -2
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -1
- package/lib/hooks/useMutationObserver.d.ts +1 -1
- package/lib/hooks/useMutationObserver.d.ts.map +1 -1
- package/lib/hooks/useTOCHighlight.d.ts +1 -1
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.d.ts +1 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +3 -2
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +3 -2
- package/lib/internal.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +2 -1
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +4 -0
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/admonitionUtils.d.ts.map +1 -1
- package/lib/utils/admonitionUtils.js +5 -6
- package/lib/utils/admonitionUtils.js.map +1 -1
- package/lib/utils/blogUtils.d.ts +13 -0
- package/lib/utils/blogUtils.d.ts.map +1 -0
- package/lib/utils/blogUtils.js +24 -0
- package/lib/utils/blogUtils.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +1 -1
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +15 -2
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +11 -5
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +40 -16
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/errorBoundaryUtils.d.ts +3 -0
- package/lib/utils/errorBoundaryUtils.d.ts.map +1 -1
- package/lib/utils/errorBoundaryUtils.js +7 -0
- package/lib/utils/errorBoundaryUtils.js.map +1 -1
- package/lib/utils/errorBoundaryUtils.module.css +5 -0
- package/lib/utils/historyUtils.d.ts +1 -1
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +1 -3
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/metadataUtils.d.ts +1 -1
- package/lib/utils/metadataUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.d.ts +2 -11
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +2 -13
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +3 -3
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +3 -2
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/skipToContentUtils.d.ts +1 -1
- package/lib/utils/skipToContentUtils.d.ts.map +1 -1
- package/lib/utils/skipToContentUtils.js +1 -0
- package/lib/utils/skipToContentUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +2 -2
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +1 -3
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tabsUtils.d.ts +3 -2
- package/lib/utils/tabsUtils.d.ts.map +1 -1
- package/lib/utils/tabsUtils.js +10 -7
- package/lib/utils/tabsUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +1 -1
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.d.ts +1 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/unlistedUtils.d.ts +11 -0
- package/lib/utils/unlistedUtils.d.ts.map +1 -0
- package/lib/utils/unlistedUtils.js +26 -0
- package/lib/utils/unlistedUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +9 -2
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +17 -17
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/components/Collapsible/index.tsx +3 -3
- package/src/components/Details/styles.module.css +5 -1
- package/src/components/ThemedComponent/index.tsx +77 -0
- package/src/components/ThemedComponent/styles.module.css +26 -0
- package/src/contexts/blogPost.tsx +3 -3
- package/src/contexts/colorMode.tsx +1 -1
- package/src/index.ts +9 -1
- package/src/internal.ts +7 -3
- package/src/utils/ThemeClassNames.ts +6 -2
- package/src/utils/admonitionUtils.tsx +9 -8
- package/src/utils/blogUtils.ts +32 -0
- package/src/utils/codeBlockUtils.ts +21 -2
- package/src/utils/docsUtils.tsx +57 -19
- package/src/utils/errorBoundaryUtils.module.css +5 -0
- package/src/utils/errorBoundaryUtils.tsx +15 -0
- package/src/utils/historyUtils.ts +1 -3
- package/src/utils/reactUtils.tsx +1 -15
- package/src/utils/scrollUtils.tsx +2 -2
- package/src/utils/skipToContentUtils.tsx +1 -0
- package/src/utils/storageUtils.ts +2 -4
- package/src/utils/tabsUtils.tsx +20 -18
- package/src/utils/unlistedUtils.tsx +39 -0
- package/src/utils/useAlternatePageUtils.ts +11 -2
package/src/utils/tabsUtils.tsx
CHANGED
|
@@ -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
|
|
65
|
-
return (React.Children.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
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
|
-
|
|
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 =
|
|
57
|
+
const pathnameSuffix = canonicalPathname.replace(baseUrl, '');
|
|
49
58
|
|
|
50
59
|
function getLocalizedBaseUrl(locale: string) {
|
|
51
60
|
return locale === defaultLocale
|