@docusaurus/theme-classic 0.0.0-5993 → 0.0.0-5994

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.
@@ -15,8 +15,17 @@ import {translate} from '@docusaurus/Translate';
15
15
  import {useLocation} from '@docusaurus/router';
16
16
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
17
17
  import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
18
- const getVersionMainDoc = (version) =>
19
- version.docs.find((doc) => doc.id === version.mainDocId);
18
+ function getVersionMainDoc(version) {
19
+ return version.docs.find((doc) => doc.id === version.mainDocId);
20
+ }
21
+ function getVersionTargetDoc(version, activeDocContext) {
22
+ // We try to link to the same doc, in another version
23
+ // When not possible, fallback to the "main doc" of the version
24
+ return (
25
+ activeDocContext.alternateDocVersions[version.name] ??
26
+ getVersionMainDoc(version)
27
+ );
28
+ }
20
29
  export default function DocsVersionDropdownNavbarItem({
21
30
  mobile,
22
31
  docsPluginId,
@@ -29,23 +38,19 @@ export default function DocsVersionDropdownNavbarItem({
29
38
  const activeDocContext = useActiveDocContext(docsPluginId);
30
39
  const versions = useVersions(docsPluginId);
31
40
  const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
32
- const versionLinks = versions.map((version) => {
33
- // We try to link to the same doc, in another version
34
- // When not possible, fallback to the "main doc" of the version
35
- const versionDoc =
36
- activeDocContext.alternateDocVersions[version.name] ??
37
- getVersionMainDoc(version);
41
+ function versionToLink(version) {
42
+ const targetDoc = getVersionTargetDoc(version, activeDocContext);
38
43
  return {
39
44
  label: version.label,
40
45
  // preserve ?search#hash suffix on version switches
41
- to: `${versionDoc.path}${search}${hash}`,
46
+ to: `${targetDoc.path}${search}${hash}`,
42
47
  isActive: () => version === activeDocContext.activeVersion,
43
48
  onClick: () => savePreferredVersionName(version.name),
44
49
  };
45
- });
50
+ }
46
51
  const items = [
47
52
  ...dropdownItemsBefore,
48
- ...versionLinks,
53
+ ...versions.map(versionToLink),
49
54
  ...dropdownItemsAfter,
50
55
  ];
51
56
  const dropdownVersion = useDocsVersionCandidates(docsPluginId)[0];
@@ -62,7 +67,7 @@ export default function DocsVersionDropdownNavbarItem({
62
67
  const dropdownTo =
63
68
  mobile && items.length > 1
64
69
  ? undefined
65
- : getVersionMainDoc(dropdownVersion).path;
70
+ : getVersionTargetDoc(dropdownVersion, activeDocContext).path;
66
71
  // We don't want to render a version dropdown with 0 or 1 item. If we build
67
72
  // the site with a single docs version (onlyIncludeVersions: ['1.0.0']),
68
73
  // We'd rather render a button instead of a dropdown
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-5993",
3
+ "version": "0.0.0-5994",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -20,18 +20,18 @@
20
20
  "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@docusaurus/core": "0.0.0-5993",
24
- "@docusaurus/mdx-loader": "0.0.0-5993",
25
- "@docusaurus/module-type-aliases": "0.0.0-5993",
26
- "@docusaurus/plugin-content-blog": "0.0.0-5993",
27
- "@docusaurus/plugin-content-docs": "0.0.0-5993",
28
- "@docusaurus/plugin-content-pages": "0.0.0-5993",
29
- "@docusaurus/theme-common": "0.0.0-5993",
30
- "@docusaurus/theme-translations": "0.0.0-5993",
31
- "@docusaurus/types": "0.0.0-5993",
32
- "@docusaurus/utils": "0.0.0-5993",
33
- "@docusaurus/utils-common": "0.0.0-5993",
34
- "@docusaurus/utils-validation": "0.0.0-5993",
23
+ "@docusaurus/core": "0.0.0-5994",
24
+ "@docusaurus/mdx-loader": "0.0.0-5994",
25
+ "@docusaurus/module-type-aliases": "0.0.0-5994",
26
+ "@docusaurus/plugin-content-blog": "0.0.0-5994",
27
+ "@docusaurus/plugin-content-docs": "0.0.0-5994",
28
+ "@docusaurus/plugin-content-pages": "0.0.0-5994",
29
+ "@docusaurus/theme-common": "0.0.0-5994",
30
+ "@docusaurus/theme-translations": "0.0.0-5994",
31
+ "@docusaurus/types": "0.0.0-5994",
32
+ "@docusaurus/utils": "0.0.0-5994",
33
+ "@docusaurus/utils-common": "0.0.0-5994",
34
+ "@docusaurus/utils-validation": "0.0.0-5994",
35
35
  "@mdx-js/react": "^3.0.0",
36
36
  "clsx": "^2.0.0",
37
37
  "copy-text-to-clipboard": "^3.2.0",
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=18.0"
63
63
  },
64
- "gitHead": "0ad0160fc910803276cb4b5fe34254b7ec372bd4"
64
+ "gitHead": "4905b76b4b39c2f102bbc78d018933f57ea39b78"
65
65
  }
@@ -17,10 +17,28 @@ import {useLocation} from '@docusaurus/router';
17
17
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
18
18
  import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
19
19
  import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
20
- import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
20
+ import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
21
+ import type {
22
+ GlobalVersion,
23
+ GlobalDoc,
24
+ ActiveDocContext,
25
+ } from '@docusaurus/plugin-content-docs/client';
21
26
 
22
- const getVersionMainDoc = (version: GlobalVersion) =>
23
- version.docs.find((doc) => doc.id === version.mainDocId)!;
27
+ function getVersionMainDoc(version: GlobalVersion): GlobalDoc {
28
+ return version.docs.find((doc) => doc.id === version.mainDocId)!;
29
+ }
30
+
31
+ function getVersionTargetDoc(
32
+ version: GlobalVersion,
33
+ activeDocContext: ActiveDocContext,
34
+ ): GlobalDoc {
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
+ return (
38
+ activeDocContext.alternateDocVersions[version.name] ??
39
+ getVersionMainDoc(version)
40
+ );
41
+ }
24
42
 
25
43
  export default function DocsVersionDropdownNavbarItem({
26
44
  mobile,
@@ -34,23 +52,21 @@ export default function DocsVersionDropdownNavbarItem({
34
52
  const activeDocContext = useActiveDocContext(docsPluginId);
35
53
  const versions = useVersions(docsPluginId);
36
54
  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);
55
+
56
+ function versionToLink(version: GlobalVersion): LinkLikeNavbarItemProps {
57
+ const targetDoc = getVersionTargetDoc(version, activeDocContext);
43
58
  return {
44
59
  label: version.label,
45
60
  // preserve ?search#hash suffix on version switches
46
- to: `${versionDoc.path}${search}${hash}`,
61
+ to: `${targetDoc.path}${search}${hash}`,
47
62
  isActive: () => version === activeDocContext.activeVersion,
48
63
  onClick: () => savePreferredVersionName(version.name),
49
64
  };
50
- });
51
- const items = [
65
+ }
66
+
67
+ const items: LinkLikeNavbarItemProps[] = [
52
68
  ...dropdownItemsBefore,
53
- ...versionLinks,
69
+ ...versions.map(versionToLink),
54
70
  ...dropdownItemsAfter,
55
71
  ];
56
72
 
@@ -69,7 +85,7 @@ export default function DocsVersionDropdownNavbarItem({
69
85
  const dropdownTo =
70
86
  mobile && items.length > 1
71
87
  ? undefined
72
- : getVersionMainDoc(dropdownVersion).path;
88
+ : getVersionTargetDoc(dropdownVersion, activeDocContext).path;
73
89
 
74
90
  // We don't want to render a version dropdown with 0 or 1 item. If we build
75
91
  // the site with a single docs version (onlyIncludeVersions: ['1.0.0']),