@docusaurus/theme-classic 0.0.0-4812 → 0.0.0-4813
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/theme-classic.d.ts +8 -1
- package/lib-next/theme/NavbarItem/DocNavbarItem.js +7 -29
- package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +10 -42
- package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +25 -29
- package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +2 -9
- package/lib-next/theme/NavbarItem/LocaleDropdownNavbarItem/index.js +2 -7
- package/lib-next/theme/NavbarItem/utils.js +2 -1
- package/package.json +13 -13
- package/src/theme/NavbarItem/DocNavbarItem.tsx +7 -32
- package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +9 -49
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +26 -33
- package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +3 -10
- package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +2 -6
- package/src/theme/NavbarItem/utils.ts +5 -2
- package/src/theme-classic.d.ts +8 -1
package/lib/theme-classic.d.ts
CHANGED
|
@@ -780,7 +780,14 @@ declare module '@theme/NavbarItem' {
|
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
declare module '@theme/NavbarItem/utils' {
|
|
783
|
-
|
|
783
|
+
/**
|
|
784
|
+
* On desktop and mobile, we would apply different class names for dropdown
|
|
785
|
+
* items.
|
|
786
|
+
* @see https://github.com/facebook/docusaurus/pull/5431
|
|
787
|
+
*/
|
|
788
|
+
export function getInfimaActiveClassName(
|
|
789
|
+
mobile?: boolean,
|
|
790
|
+
): `${'menu' | 'navbar'}__link--active`;
|
|
784
791
|
}
|
|
785
792
|
|
|
786
793
|
declare module '@theme/PaginatorNavLink' {
|
|
@@ -6,50 +6,28 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
|
-
import {
|
|
10
|
-
useLatestVersion,
|
|
11
|
-
useActiveDocContext,
|
|
12
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
9
|
+
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
|
|
13
10
|
import clsx from 'clsx';
|
|
14
11
|
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
function getDocInVersions(versions, docId) {
|
|
18
|
-
const allDocs = versions.flatMap((version) => version.docs);
|
|
19
|
-
const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
|
|
20
|
-
|
|
21
|
-
if (!doc) {
|
|
22
|
-
const docIds = allDocs.map((versionDoc) => versionDoc.id).join('\n- ');
|
|
23
|
-
throw new Error(`DocNavbarItem: couldn't find any doc with id "${docId}" in version${
|
|
24
|
-
versions.length ? 's' : ''
|
|
25
|
-
} ${versions.map((version) => version.name).join(', ')}".
|
|
26
|
-
Available doc ids are:\n- ${docIds}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return doc;
|
|
30
|
-
}
|
|
31
|
-
|
|
12
|
+
import {useLayoutDoc} from '@docusaurus/theme-common';
|
|
32
13
|
export default function DocNavbarItem({
|
|
33
14
|
docId,
|
|
34
15
|
label: staticLabel,
|
|
35
16
|
docsPluginId,
|
|
36
17
|
...props
|
|
37
18
|
}) {
|
|
38
|
-
const {
|
|
39
|
-
const
|
|
40
|
-
const latestVersion = useLatestVersion(docsPluginId); // Versions used to look for the doc to link to, ordered + no duplicate
|
|
41
|
-
|
|
42
|
-
const versions = uniq(
|
|
43
|
-
[activeVersion, preferredVersion, latestVersion].filter(Boolean),
|
|
44
|
-
);
|
|
45
|
-
const doc = getDocInVersions(versions, docId);
|
|
19
|
+
const {activeDoc} = useActiveDocContext(docsPluginId);
|
|
20
|
+
const doc = useLayoutDoc(docId, docsPluginId);
|
|
46
21
|
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
|
|
47
22
|
return (
|
|
48
23
|
<DefaultNavbarItem
|
|
49
24
|
exact
|
|
50
25
|
{...props}
|
|
51
26
|
className={clsx(props.className, {
|
|
27
|
+
// Do not make the item active if the active doc doesn't have sidebar.
|
|
52
28
|
[activeDocInfimaClassName]:
|
|
29
|
+
// If `activeDoc === doc` react-router will make it active anyways,
|
|
30
|
+
// regardless of the existence of a sidebar
|
|
53
31
|
activeDoc?.sidebar && activeDoc.sidebar === doc.sidebar,
|
|
54
32
|
})}
|
|
55
33
|
activeClassName={activeDocInfimaClassName}
|
|
@@ -6,57 +6,25 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
|
-
import {
|
|
10
|
-
useLatestVersion,
|
|
11
|
-
useActiveDocContext,
|
|
12
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
9
|
+
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
|
|
13
10
|
import clsx from 'clsx';
|
|
14
11
|
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
function getSidebarLink(versions, sidebarId) {
|
|
18
|
-
const allSidebars = versions
|
|
19
|
-
.flatMap((version) => {
|
|
20
|
-
if (version.sidebars) {
|
|
21
|
-
return Object.entries(version.sidebars);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
})
|
|
26
|
-
.filter((sidebarItem) => !!sidebarItem);
|
|
27
|
-
const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
|
|
28
|
-
|
|
29
|
-
if (!sidebarEntry) {
|
|
30
|
-
throw new Error(`DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
|
|
31
|
-
versions.length ? 's' : ''
|
|
32
|
-
} ${versions.map((version) => version.name).join(', ')}".
|
|
33
|
-
Available sidebar ids are:
|
|
34
|
-
- ${Object.keys(allSidebars).join('\n- ')}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!sidebarEntry[1].link) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return sidebarEntry[1].link;
|
|
44
|
-
}
|
|
45
|
-
|
|
12
|
+
import {useLayoutDocsSidebar} from '@docusaurus/theme-common';
|
|
46
13
|
export default function DocSidebarNavbarItem({
|
|
47
14
|
sidebarId,
|
|
48
15
|
label,
|
|
49
16
|
docsPluginId,
|
|
50
17
|
...props
|
|
51
18
|
}) {
|
|
52
|
-
const {
|
|
53
|
-
const
|
|
54
|
-
|
|
19
|
+
const {activeDoc} = useActiveDocContext(docsPluginId);
|
|
20
|
+
const sidebarLink = useLayoutDocsSidebar(sidebarId, docsPluginId).link;
|
|
21
|
+
|
|
22
|
+
if (!sidebarLink) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`DocSidebarNavbarItem: Sidebar with ID "${sidebarId}" doesn't have anything to be linked to.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
55
27
|
|
|
56
|
-
const versions = uniq(
|
|
57
|
-
[activeVersion, preferredVersion, latestVersion].filter(Boolean),
|
|
58
|
-
);
|
|
59
|
-
const sidebarLink = getSidebarLink(versions, sidebarId);
|
|
60
28
|
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
|
|
61
29
|
return (
|
|
62
30
|
<DefaultNavbarItem
|
|
@@ -9,10 +9,12 @@ import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
|
9
9
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
10
10
|
import {
|
|
11
11
|
useVersions,
|
|
12
|
-
useLatestVersion,
|
|
13
12
|
useActiveDocContext,
|
|
14
13
|
} from '@docusaurus/plugin-content-docs/client';
|
|
15
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
useDocsPreferredVersion,
|
|
16
|
+
useDocsVersionCandidates,
|
|
17
|
+
} from '@docusaurus/theme-common';
|
|
16
18
|
import {translate} from '@docusaurus/Translate';
|
|
17
19
|
|
|
18
20
|
const getVersionMainDoc = (version) =>
|
|
@@ -28,33 +30,27 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
28
30
|
}) {
|
|
29
31
|
const activeDocContext = useActiveDocContext(docsPluginId);
|
|
30
32
|
const versions = useVersions(docsPluginId);
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const items = getItems();
|
|
56
|
-
const dropdownVersion =
|
|
57
|
-
activeDocContext.activeVersion ?? preferredVersion ?? latestVersion; // Mobile dropdown is handled a bit differently
|
|
33
|
+
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
|
|
34
|
+
const versionLinks = versions.map((version) => {
|
|
35
|
+
// We try to link to the same doc, in another version
|
|
36
|
+
// When not possible, fallback to the "main doc" of the version
|
|
37
|
+
const versionDoc =
|
|
38
|
+
activeDocContext?.alternateDocVersions[version.name] ??
|
|
39
|
+
getVersionMainDoc(version);
|
|
40
|
+
return {
|
|
41
|
+
isNavLink: true,
|
|
42
|
+
label: version.label,
|
|
43
|
+
to: versionDoc.path,
|
|
44
|
+
isActive: () => version === activeDocContext?.activeVersion,
|
|
45
|
+
onClick: () => savePreferredVersionName(version.name),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
const items = [
|
|
49
|
+
...dropdownItemsBefore,
|
|
50
|
+
...versionLinks,
|
|
51
|
+
...dropdownItemsAfter,
|
|
52
|
+
];
|
|
53
|
+
const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0]; // Mobile dropdown is handled a bit differently
|
|
58
54
|
|
|
59
55
|
const dropdownLabel =
|
|
60
56
|
mobile && items.length > 1
|
|
@@ -6,11 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
|
-
import {
|
|
10
|
-
useActiveVersion,
|
|
11
|
-
useLatestVersion,
|
|
12
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
13
|
-
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
|
9
|
+
import {useDocsVersionCandidates} from '@docusaurus/theme-common';
|
|
14
10
|
|
|
15
11
|
const getVersionMainDoc = (version) =>
|
|
16
12
|
version.docs.find((doc) => doc.id === version.mainDocId);
|
|
@@ -21,10 +17,7 @@ export default function DocsVersionNavbarItem({
|
|
|
21
17
|
docsPluginId,
|
|
22
18
|
...props
|
|
23
19
|
}) {
|
|
24
|
-
const
|
|
25
|
-
const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
|
|
26
|
-
const latestVersion = useLatestVersion(docsPluginId);
|
|
27
|
-
const version = activeVersion ?? preferredVersion ?? latestVersion;
|
|
20
|
+
const version = useDocsVersionCandidates(docsPluginId)[0];
|
|
28
21
|
const label = staticLabel ?? version.label;
|
|
29
22
|
const path = staticTo ?? getVersionMainDoc(version).path;
|
|
30
23
|
return <DefaultNavbarItem {...props} label={label} to={path} />;
|
|
@@ -21,11 +21,6 @@ export default function LocaleDropdownNavbarItem({
|
|
|
21
21
|
i18n: {currentLocale, locales, localeConfigs},
|
|
22
22
|
} = useDocusaurusContext();
|
|
23
23
|
const alternatePageUtils = useAlternatePageUtils();
|
|
24
|
-
|
|
25
|
-
function getLocaleLabel(locale) {
|
|
26
|
-
return localeConfigs[locale].label;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
24
|
const localeItems = locales.map((locale) => {
|
|
30
25
|
const to = `pathname://${alternatePageUtils.createUrl({
|
|
31
26
|
locale,
|
|
@@ -33,7 +28,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
33
28
|
})}`;
|
|
34
29
|
return {
|
|
35
30
|
isNavLink: true,
|
|
36
|
-
label:
|
|
31
|
+
label: localeConfigs[locale].label,
|
|
37
32
|
to,
|
|
38
33
|
target: '_self',
|
|
39
34
|
autoAddBaseUrl: false,
|
|
@@ -48,7 +43,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
48
43
|
id: 'theme.navbar.mobileLanguageDropdown.label',
|
|
49
44
|
description: 'The label for the mobile language switcher dropdown',
|
|
50
45
|
})
|
|
51
|
-
:
|
|
46
|
+
: localeConfigs[currentLocale].label;
|
|
52
47
|
return (
|
|
53
48
|
<DropdownNavbarItem
|
|
54
49
|
{...props}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
/* eslint-disable import/no-named-export */
|
|
8
9
|
export const getInfimaActiveClassName = (mobile) =>
|
|
9
10
|
mobile ? 'menu__link--active' : 'navbar__link--active';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4813",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "0.0.0-
|
|
25
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
28
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
24
|
+
"@docusaurus/core": "0.0.0-4813",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4813",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4813",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4813",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4813",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4813",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4813",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4813",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4813",
|
|
33
33
|
"@mdx-js/react": "^1.6.22",
|
|
34
34
|
"clsx": "^1.1.1",
|
|
35
35
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"rtlcss": "^3.5.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
46
|
-
"@docusaurus/types": "0.0.0-
|
|
45
|
+
"@docusaurus/module-type-aliases": "0.0.0-4813",
|
|
46
|
+
"@docusaurus/types": "0.0.0-4813",
|
|
47
47
|
"@types/mdx-js__react": "^1.5.5",
|
|
48
48
|
"@types/prismjs": "^1.26.0",
|
|
49
49
|
"@types/rtlcss": "^3.1.3",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=14"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "6b8435cb317c3cc6dba4d4085ea9365fd699b8c0"
|
|
63
63
|
}
|
|
@@ -7,30 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
10
|
-
import {
|
|
11
|
-
useLatestVersion,
|
|
12
|
-
useActiveDocContext,
|
|
13
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
10
|
+
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
|
|
14
11
|
import clsx from 'clsx';
|
|
15
12
|
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
16
13
|
import type {Props} from '@theme/NavbarItem/DocNavbarItem';
|
|
17
|
-
import {
|
|
18
|
-
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
|
19
|
-
|
|
20
|
-
function getDocInVersions(versions: GlobalVersion[], docId: string) {
|
|
21
|
-
const allDocs = versions.flatMap((version) => version.docs);
|
|
22
|
-
const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
|
|
23
|
-
if (!doc) {
|
|
24
|
-
const docIds = allDocs.map((versionDoc) => versionDoc.id).join('\n- ');
|
|
25
|
-
throw new Error(
|
|
26
|
-
`DocNavbarItem: couldn't find any doc with id "${docId}" in version${
|
|
27
|
-
versions.length ? 's' : ''
|
|
28
|
-
} ${versions.map((version) => version.name).join(', ')}".
|
|
29
|
-
Available doc ids are:\n- ${docIds}`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
return doc;
|
|
33
|
-
}
|
|
14
|
+
import {useLayoutDoc} from '@docusaurus/theme-common';
|
|
34
15
|
|
|
35
16
|
export default function DocNavbarItem({
|
|
36
17
|
docId,
|
|
@@ -38,17 +19,8 @@ export default function DocNavbarItem({
|
|
|
38
19
|
docsPluginId,
|
|
39
20
|
...props
|
|
40
21
|
}: Props): JSX.Element {
|
|
41
|
-
const {
|
|
42
|
-
const
|
|
43
|
-
const latestVersion = useLatestVersion(docsPluginId);
|
|
44
|
-
|
|
45
|
-
// Versions used to look for the doc to link to, ordered + no duplicate
|
|
46
|
-
const versions = uniq(
|
|
47
|
-
[activeVersion, preferredVersion, latestVersion].filter(
|
|
48
|
-
Boolean,
|
|
49
|
-
) as GlobalVersion[],
|
|
50
|
-
);
|
|
51
|
-
const doc = getDocInVersions(versions, docId);
|
|
22
|
+
const {activeDoc} = useActiveDocContext(docsPluginId);
|
|
23
|
+
const doc = useLayoutDoc(docId, docsPluginId);
|
|
52
24
|
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
|
|
53
25
|
|
|
54
26
|
return (
|
|
@@ -57,6 +29,9 @@ export default function DocNavbarItem({
|
|
|
57
29
|
{...props}
|
|
58
30
|
className={clsx(props.className, {
|
|
59
31
|
[activeDocInfimaClassName]:
|
|
32
|
+
// Do not make the item active if the active doc doesn't have sidebar.
|
|
33
|
+
// If `activeDoc === doc` react-router will make it active anyways,
|
|
34
|
+
// regardless of the existence of a sidebar
|
|
60
35
|
activeDoc?.sidebar && activeDoc.sidebar === doc.sidebar,
|
|
61
36
|
})}
|
|
62
37
|
activeClassName={activeDocInfimaClassName}
|
|
@@ -7,48 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
10
|
-
import {
|
|
11
|
-
useLatestVersion,
|
|
12
|
-
useActiveDocContext,
|
|
13
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
10
|
+
import {useActiveDocContext} from '@docusaurus/plugin-content-docs/client';
|
|
14
11
|
import clsx from 'clsx';
|
|
15
12
|
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
16
|
-
import {
|
|
13
|
+
import {useLayoutDocsSidebar} from '@docusaurus/theme-common';
|
|
17
14
|
|
|
18
15
|
import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
19
|
-
import type {
|
|
20
|
-
GlobalVersion,
|
|
21
|
-
GlobalSidebar,
|
|
22
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
23
|
-
|
|
24
|
-
function getSidebarLink(versions: GlobalVersion[], sidebarId: string) {
|
|
25
|
-
const allSidebars = versions
|
|
26
|
-
.flatMap((version) => {
|
|
27
|
-
if (version.sidebars) {
|
|
28
|
-
return Object.entries(version.sidebars);
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
})
|
|
32
|
-
.filter(
|
|
33
|
-
(sidebarItem): sidebarItem is [string, GlobalSidebar] => !!sidebarItem,
|
|
34
|
-
);
|
|
35
|
-
const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
|
|
36
|
-
if (!sidebarEntry) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
|
|
39
|
-
versions.length ? 's' : ''
|
|
40
|
-
} ${versions.map((version) => version.name).join(', ')}".
|
|
41
|
-
Available sidebar ids are:
|
|
42
|
-
- ${Object.keys(allSidebars).join('\n- ')}`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
if (!sidebarEntry[1].link) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
`DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return sidebarEntry[1].link;
|
|
51
|
-
}
|
|
52
16
|
|
|
53
17
|
export default function DocSidebarNavbarItem({
|
|
54
18
|
sidebarId,
|
|
@@ -56,17 +20,13 @@ export default function DocSidebarNavbarItem({
|
|
|
56
20
|
docsPluginId,
|
|
57
21
|
...props
|
|
58
22
|
}: Props): JSX.Element {
|
|
59
|
-
const {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Boolean,
|
|
67
|
-
) as GlobalVersion[],
|
|
68
|
-
);
|
|
69
|
-
const sidebarLink = getSidebarLink(versions, sidebarId);
|
|
23
|
+
const {activeDoc} = useActiveDocContext(docsPluginId);
|
|
24
|
+
const sidebarLink = useLayoutDocsSidebar(sidebarId, docsPluginId).link;
|
|
25
|
+
if (!sidebarLink) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`DocSidebarNavbarItem: Sidebar with ID "${sidebarId}" doesn't have anything to be linked to.`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
70
30
|
const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
|
|
71
31
|
|
|
72
32
|
return (
|
|
@@ -10,14 +10,15 @@ import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
|
10
10
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
11
11
|
import {
|
|
12
12
|
useVersions,
|
|
13
|
-
useLatestVersion,
|
|
14
13
|
useActiveDocContext,
|
|
15
14
|
} from '@docusaurus/plugin-content-docs/client';
|
|
16
|
-
import
|
|
17
|
-
|
|
15
|
+
import {
|
|
16
|
+
useDocsPreferredVersion,
|
|
17
|
+
useDocsVersionCandidates,
|
|
18
|
+
} from '@docusaurus/theme-common';
|
|
18
19
|
import {translate} from '@docusaurus/Translate';
|
|
19
20
|
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
|
20
|
-
import type {
|
|
21
|
+
import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
21
22
|
|
|
22
23
|
const getVersionMainDoc = (version: GlobalVersion) =>
|
|
23
24
|
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
@@ -32,36 +33,28 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
32
33
|
}: Props): JSX.Element {
|
|
33
34
|
const activeDocContext = useActiveDocContext(docsPluginId);
|
|
34
35
|
const versions = useVersions(docsPluginId);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const items = getItems();
|
|
36
|
+
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
|
|
37
|
+
const versionLinks = versions.map((version) => {
|
|
38
|
+
// We try to link to the same doc, in another version
|
|
39
|
+
// When not possible, fallback to the "main doc" of the version
|
|
40
|
+
const versionDoc =
|
|
41
|
+
activeDocContext?.alternateDocVersions[version.name] ??
|
|
42
|
+
getVersionMainDoc(version);
|
|
43
|
+
return {
|
|
44
|
+
isNavLink: true,
|
|
45
|
+
label: version.label,
|
|
46
|
+
to: versionDoc.path,
|
|
47
|
+
isActive: () => version === activeDocContext?.activeVersion,
|
|
48
|
+
onClick: () => savePreferredVersionName(version.name),
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const items = [
|
|
52
|
+
...dropdownItemsBefore,
|
|
53
|
+
...versionLinks,
|
|
54
|
+
...dropdownItemsAfter,
|
|
55
|
+
];
|
|
62
56
|
|
|
63
|
-
const dropdownVersion =
|
|
64
|
-
activeDocContext.activeVersion ?? preferredVersion ?? latestVersion;
|
|
57
|
+
const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0];
|
|
65
58
|
|
|
66
59
|
// Mobile dropdown is handled a bit differently
|
|
67
60
|
const dropdownLabel =
|
|
@@ -7,13 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
useLatestVersion,
|
|
13
|
-
type GlobalVersion,
|
|
14
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
10
|
+
import {useDocsVersionCandidates} from '@docusaurus/theme-common';
|
|
11
|
+
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
|
15
12
|
import type {Props} from '@theme/NavbarItem/DocsVersionNavbarItem';
|
|
16
|
-
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
|
17
13
|
|
|
18
14
|
const getVersionMainDoc = (version: GlobalVersion) =>
|
|
19
15
|
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
|
@@ -24,10 +20,7 @@ export default function DocsVersionNavbarItem({
|
|
|
24
20
|
docsPluginId,
|
|
25
21
|
...props
|
|
26
22
|
}: Props): JSX.Element {
|
|
27
|
-
const
|
|
28
|
-
const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
|
|
29
|
-
const latestVersion = useLatestVersion(docsPluginId);
|
|
30
|
-
const version = activeVersion ?? preferredVersion ?? latestVersion;
|
|
23
|
+
const version = useDocsVersionCandidates(docsPluginId)[0];
|
|
31
24
|
const label = staticLabel ?? version.label;
|
|
32
25
|
const path = staticTo ?? getVersionMainDoc(version).path;
|
|
33
26
|
return <DefaultNavbarItem {...props} label={label} to={path} />;
|
|
@@ -27,10 +27,6 @@ export default function LocaleDropdownNavbarItem({
|
|
|
27
27
|
} = useDocusaurusContext();
|
|
28
28
|
const alternatePageUtils = useAlternatePageUtils();
|
|
29
29
|
|
|
30
|
-
function getLocaleLabel(locale: string) {
|
|
31
|
-
return localeConfigs[locale]!.label;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
30
|
const localeItems = locales.map((locale): LinkLikeNavbarItemProps => {
|
|
35
31
|
const to = `pathname://${alternatePageUtils.createUrl({
|
|
36
32
|
locale,
|
|
@@ -38,7 +34,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
38
34
|
})}`;
|
|
39
35
|
return {
|
|
40
36
|
isNavLink: true,
|
|
41
|
-
label:
|
|
37
|
+
label: localeConfigs[locale]!.label,
|
|
42
38
|
to,
|
|
43
39
|
target: '_self',
|
|
44
40
|
autoAddBaseUrl: false,
|
|
@@ -55,7 +51,7 @@ export default function LocaleDropdownNavbarItem({
|
|
|
55
51
|
id: 'theme.navbar.mobileLanguageDropdown.label',
|
|
56
52
|
description: 'The label for the mobile language switcher dropdown',
|
|
57
53
|
})
|
|
58
|
-
:
|
|
54
|
+
: localeConfigs[currentLocale]!.label;
|
|
59
55
|
|
|
60
56
|
return (
|
|
61
57
|
<DropdownNavbarItem
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/* eslint-disable import/no-named-export */
|
|
9
|
+
|
|
10
|
+
export const getInfimaActiveClassName = (
|
|
11
|
+
mobile?: boolean,
|
|
12
|
+
): `${'menu' | 'navbar'}__link--active` =>
|
|
10
13
|
mobile ? 'menu__link--active' : 'navbar__link--active';
|
package/src/theme-classic.d.ts
CHANGED
|
@@ -780,7 +780,14 @@ declare module '@theme/NavbarItem' {
|
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
declare module '@theme/NavbarItem/utils' {
|
|
783
|
-
|
|
783
|
+
/**
|
|
784
|
+
* On desktop and mobile, we would apply different class names for dropdown
|
|
785
|
+
* items.
|
|
786
|
+
* @see https://github.com/facebook/docusaurus/pull/5431
|
|
787
|
+
*/
|
|
788
|
+
export function getInfimaActiveClassName(
|
|
789
|
+
mobile?: boolean,
|
|
790
|
+
): `${'menu' | 'navbar'}__link--active`;
|
|
784
791
|
}
|
|
785
792
|
|
|
786
793
|
declare module '@theme/PaginatorNavLink' {
|