@docusaurus/plugin-content-docs 0.0.0-4851 → 0.0.0-4855

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.
@@ -10,6 +10,6 @@ export declare function getActivePlugin(allPluginData: {
10
10
  [pluginId: string]: GlobalPluginData;
11
11
  }, pathname: string, options?: UseDataOptions): ActivePlugin | undefined;
12
12
  export declare const getLatestVersion: (data: GlobalPluginData) => GlobalVersion;
13
- export declare const getActiveVersion: (data: GlobalPluginData, pathname: string) => GlobalVersion | undefined;
14
- export declare const getActiveDocContext: (data: GlobalPluginData, pathname: string) => ActiveDocContext;
15
- export declare const getDocVersionSuggestions: (data: GlobalPluginData, pathname: string) => DocVersionSuggestions;
13
+ export declare function getActiveVersion(data: GlobalPluginData, pathname: string): GlobalVersion | undefined;
14
+ export declare function getActiveDocContext(data: GlobalPluginData, pathname: string): ActiveDocContext;
15
+ export declare function getDocVersionSuggestions(data: GlobalPluginData, pathname: string): DocVersionSuggestions;
@@ -34,9 +34,7 @@ function getActivePlugin(allPluginData, pathname, options = {}) {
34
34
  exports.getActivePlugin = getActivePlugin;
35
35
  const getLatestVersion = (data) => data.versions.find((version) => version.isLast);
36
36
  exports.getLatestVersion = getLatestVersion;
37
- // Note: return undefined on doc-unrelated pages,
38
- // because there's no version currently considered as active
39
- const getActiveVersion = (data, pathname) => {
37
+ function getActiveVersion(data, pathname) {
40
38
  const lastVersion = (0, exports.getLatestVersion)(data);
41
39
  // Last version is a route like /docs/*,
42
40
  // we need to match it last or it would match /docs/version-1.0/* as well
@@ -49,10 +47,10 @@ const getActiveVersion = (data, pathname) => {
49
47
  exact: false,
50
48
  strict: false,
51
49
  }));
52
- };
50
+ }
53
51
  exports.getActiveVersion = getActiveVersion;
54
- const getActiveDocContext = (data, pathname) => {
55
- const activeVersion = (0, exports.getActiveVersion)(data, pathname);
52
+ function getActiveDocContext(data, pathname) {
53
+ const activeVersion = getActiveVersion(data, pathname);
56
54
  const activeDoc = activeVersion?.docs.find((doc) => !!(0, router_1.matchPath)(pathname, {
57
55
  path: doc.path,
58
56
  exact: true,
@@ -77,12 +75,12 @@ const getActiveDocContext = (data, pathname) => {
77
75
  activeDoc,
78
76
  alternateDocVersions: alternateVersionDocs,
79
77
  };
80
- };
78
+ }
81
79
  exports.getActiveDocContext = getActiveDocContext;
82
- const getDocVersionSuggestions = (data, pathname) => {
80
+ function getDocVersionSuggestions(data, pathname) {
83
81
  const latestVersion = (0, exports.getLatestVersion)(data);
84
- const activeDocContext = (0, exports.getActiveDocContext)(data, pathname);
82
+ const activeDocContext = getActiveDocContext(data, pathname);
85
83
  const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
86
84
  return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
87
- };
85
+ }
88
86
  exports.getDocVersionSuggestions = getDocVersionSuggestions;
@@ -10,13 +10,13 @@ export declare const useAllDocsData: () => {
10
10
  [pluginId: string]: GlobalPluginData;
11
11
  };
12
12
  export declare const useDocsData: (pluginId: string | undefined) => GlobalPluginData;
13
- export declare const useActivePlugin: (options?: UseDataOptions) => ActivePlugin | undefined;
14
- export declare const useActivePluginAndVersion: (options?: UseDataOptions) => {
13
+ export declare function useActivePlugin(options?: UseDataOptions): ActivePlugin | undefined;
14
+ export declare function useActivePluginAndVersion(options?: UseDataOptions): {
15
15
  activePlugin: ActivePlugin;
16
16
  activeVersion: GlobalVersion | undefined;
17
17
  } | undefined;
18
- export declare const useVersions: (pluginId: string | undefined) => GlobalVersion[];
19
- export declare const useLatestVersion: (pluginId: string | undefined) => GlobalVersion;
20
- export declare const useActiveVersion: (pluginId: string | undefined) => GlobalVersion | undefined;
21
- export declare const useActiveDocContext: (pluginId: string | undefined) => ActiveDocContext;
22
- export declare const useDocVersionSuggestions: (pluginId: string | undefined) => DocVersionSuggestions;
18
+ export declare function useVersions(pluginId: string | undefined): GlobalVersion[];
19
+ export declare function useLatestVersion(pluginId: string | undefined): GlobalVersion;
20
+ export declare function useActiveVersion(pluginId: string | undefined): GlobalVersion | undefined;
21
+ export declare function useActiveDocContext(pluginId: string | undefined): ActiveDocContext;
22
+ export declare function useDocVersionSuggestions(pluginId: string | undefined): DocVersionSuggestions;
@@ -23,54 +23,50 @@ const useDocsData = (pluginId) => (0, useGlobalData_1.usePluginData)('docusaurus
23
23
  });
24
24
  exports.useDocsData = useDocsData;
25
25
  // TODO this feature should be provided by docusaurus core
26
- const useActivePlugin = (options = {}) => {
26
+ function useActivePlugin(options = {}) {
27
27
  const data = (0, exports.useAllDocsData)();
28
28
  const { pathname } = (0, router_1.useLocation)();
29
29
  return (0, docsClientUtils_1.getActivePlugin)(data, pathname, options);
30
- };
30
+ }
31
31
  exports.useActivePlugin = useActivePlugin;
32
- const useActivePluginAndVersion = (options = {}) => {
33
- const activePlugin = (0, exports.useActivePlugin)(options);
32
+ function useActivePluginAndVersion(options = {}) {
33
+ const activePlugin = useActivePlugin(options);
34
34
  const { pathname } = (0, router_1.useLocation)();
35
- if (activePlugin) {
36
- const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
37
- return {
38
- activePlugin,
39
- activeVersion,
40
- };
35
+ if (!activePlugin) {
36
+ return undefined;
41
37
  }
42
- return undefined;
43
- };
38
+ const activeVersion = (0, docsClientUtils_1.getActiveVersion)(activePlugin.pluginData, pathname);
39
+ return {
40
+ activePlugin,
41
+ activeVersion,
42
+ };
43
+ }
44
44
  exports.useActivePluginAndVersion = useActivePluginAndVersion;
45
- // versions are returned ordered (most recent first)
46
- const useVersions = (pluginId) => {
45
+ function useVersions(pluginId) {
47
46
  const data = (0, exports.useDocsData)(pluginId);
48
47
  return data.versions;
49
- };
48
+ }
50
49
  exports.useVersions = useVersions;
51
- const useLatestVersion = (pluginId) => {
50
+ function useLatestVersion(pluginId) {
52
51
  const data = (0, exports.useDocsData)(pluginId);
53
52
  return (0, docsClientUtils_1.getLatestVersion)(data);
54
- };
53
+ }
55
54
  exports.useLatestVersion = useLatestVersion;
56
- // Note: return undefined on doc-unrelated pages,
57
- // because there's no version currently considered as active
58
- const useActiveVersion = (pluginId) => {
55
+ function useActiveVersion(pluginId) {
59
56
  const data = (0, exports.useDocsData)(pluginId);
60
57
  const { pathname } = (0, router_1.useLocation)();
61
58
  return (0, docsClientUtils_1.getActiveVersion)(data, pathname);
62
- };
59
+ }
63
60
  exports.useActiveVersion = useActiveVersion;
64
- const useActiveDocContext = (pluginId) => {
61
+ function useActiveDocContext(pluginId) {
65
62
  const data = (0, exports.useDocsData)(pluginId);
66
63
  const { pathname } = (0, router_1.useLocation)();
67
64
  return (0, docsClientUtils_1.getActiveDocContext)(data, pathname);
68
- };
65
+ }
69
66
  exports.useActiveDocContext = useActiveDocContext;
70
- // Useful to say "hey, you are not on the latest docs version, please switch"
71
- const useDocVersionSuggestions = (pluginId) => {
67
+ function useDocVersionSuggestions(pluginId) {
72
68
  const data = (0, exports.useDocsData)(pluginId);
73
69
  const { pathname } = (0, router_1.useLocation)();
74
70
  return (0, docsClientUtils_1.getDocVersionSuggestions)(data, pathname);
75
- };
71
+ }
76
72
  exports.useDocVersionSuggestions = useDocVersionSuggestions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4851",
3
+ "version": "0.0.0-4855",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@docusaurus/core": "0.0.0-4851",
28
- "@docusaurus/logger": "0.0.0-4851",
29
- "@docusaurus/mdx-loader": "0.0.0-4851",
30
- "@docusaurus/utils": "0.0.0-4851",
31
- "@docusaurus/utils-validation": "0.0.0-4851",
27
+ "@docusaurus/core": "0.0.0-4855",
28
+ "@docusaurus/logger": "0.0.0-4855",
29
+ "@docusaurus/mdx-loader": "0.0.0-4855",
30
+ "@docusaurus/utils": "0.0.0-4855",
31
+ "@docusaurus/utils-validation": "0.0.0-4855",
32
32
  "combine-promises": "^1.1.0",
33
33
  "fs-extra": "^10.0.1",
34
34
  "import-fresh": "^3.3.0",
@@ -40,8 +40,8 @@
40
40
  "webpack": "^5.72.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@docusaurus/module-type-aliases": "0.0.0-4851",
44
- "@docusaurus/types": "0.0.0-4851",
43
+ "@docusaurus/module-type-aliases": "0.0.0-4855",
44
+ "@docusaurus/types": "0.0.0-4855",
45
45
  "@types/js-yaml": "^4.0.5",
46
46
  "@types/picomatch": "^2.3.0",
47
47
  "commander": "^5.1.0",
@@ -57,5 +57,5 @@
57
57
  "engines": {
58
58
  "node": ">=14"
59
59
  },
60
- "gitHead": "c87ae506757fe2a8d020ceb773fdcb1fc4fd3a38"
60
+ "gitHead": "9cfea8db2f22d348706de240a56303bb257d16b6"
61
61
  }
@@ -59,12 +59,10 @@ export function getActivePlugin(
59
59
  export const getLatestVersion = (data: GlobalPluginData): GlobalVersion =>
60
60
  data.versions.find((version) => version.isLast)!;
61
61
 
62
- // Note: return undefined on doc-unrelated pages,
63
- // because there's no version currently considered as active
64
- export const getActiveVersion = (
62
+ export function getActiveVersion(
65
63
  data: GlobalPluginData,
66
64
  pathname: string,
67
- ): GlobalVersion | undefined => {
65
+ ): GlobalVersion | undefined {
68
66
  const lastVersion = getLatestVersion(data);
69
67
  // Last version is a route like /docs/*,
70
68
  // we need to match it last or it would match /docs/version-1.0/* as well
@@ -80,12 +78,12 @@ export const getActiveVersion = (
80
78
  strict: false,
81
79
  }),
82
80
  );
83
- };
81
+ }
84
82
 
85
- export const getActiveDocContext = (
83
+ export function getActiveDocContext(
86
84
  data: GlobalPluginData,
87
85
  pathname: string,
88
- ): ActiveDocContext => {
86
+ ): ActiveDocContext {
89
87
  const activeVersion = getActiveVersion(data, pathname);
90
88
  const activeDoc = activeVersion?.docs.find(
91
89
  (doc) =>
@@ -119,15 +117,15 @@ export const getActiveDocContext = (
119
117
  activeDoc,
120
118
  alternateDocVersions: alternateVersionDocs,
121
119
  };
122
- };
120
+ }
123
121
 
124
- export const getDocVersionSuggestions = (
122
+ export function getDocVersionSuggestions(
125
123
  data: GlobalPluginData,
126
124
  pathname: string,
127
- ): DocVersionSuggestions => {
125
+ ): DocVersionSuggestions {
128
126
  const latestVersion = getLatestVersion(data);
129
127
  const activeDocContext = getActiveDocContext(data, pathname);
130
128
  const latestDocSuggestion: GlobalDoc | undefined =
131
129
  activeDocContext?.alternateDocVersions[latestVersion.name];
132
130
  return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
133
- };
131
+ }
@@ -43,67 +43,61 @@ export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
43
43
  }) as GlobalPluginData;
44
44
 
45
45
  // TODO this feature should be provided by docusaurus core
46
- export const useActivePlugin = (
46
+ export function useActivePlugin(
47
47
  options: UseDataOptions = {},
48
- ): ActivePlugin | undefined => {
48
+ ): ActivePlugin | undefined {
49
49
  const data = useAllDocsData();
50
50
  const {pathname} = useLocation();
51
51
  return getActivePlugin(data, pathname, options);
52
- };
52
+ }
53
53
 
54
- export const useActivePluginAndVersion = (
54
+ export function useActivePluginAndVersion(
55
55
  options: UseDataOptions = {},
56
56
  ):
57
- | undefined
58
- | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined} => {
57
+ | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
58
+ | undefined {
59
59
  const activePlugin = useActivePlugin(options);
60
60
  const {pathname} = useLocation();
61
- if (activePlugin) {
62
- const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
63
- return {
64
- activePlugin,
65
- activeVersion,
66
- };
61
+ if (!activePlugin) {
62
+ return undefined;
67
63
  }
68
- return undefined;
69
- };
64
+ const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
65
+ return {
66
+ activePlugin,
67
+ activeVersion,
68
+ };
69
+ }
70
70
 
71
- // versions are returned ordered (most recent first)
72
- export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
71
+ export function useVersions(pluginId: string | undefined): GlobalVersion[] {
73
72
  const data = useDocsData(pluginId);
74
73
  return data.versions;
75
- };
74
+ }
76
75
 
77
- export const useLatestVersion = (
78
- pluginId: string | undefined,
79
- ): GlobalVersion => {
76
+ export function useLatestVersion(pluginId: string | undefined): GlobalVersion {
80
77
  const data = useDocsData(pluginId);
81
78
  return getLatestVersion(data);
82
- };
79
+ }
83
80
 
84
- // Note: return undefined on doc-unrelated pages,
85
- // because there's no version currently considered as active
86
- export const useActiveVersion = (
81
+ export function useActiveVersion(
87
82
  pluginId: string | undefined,
88
- ): GlobalVersion | undefined => {
83
+ ): GlobalVersion | undefined {
89
84
  const data = useDocsData(pluginId);
90
85
  const {pathname} = useLocation();
91
86
  return getActiveVersion(data, pathname);
92
- };
87
+ }
93
88
 
94
- export const useActiveDocContext = (
89
+ export function useActiveDocContext(
95
90
  pluginId: string | undefined,
96
- ): ActiveDocContext => {
91
+ ): ActiveDocContext {
97
92
  const data = useDocsData(pluginId);
98
93
  const {pathname} = useLocation();
99
94
  return getActiveDocContext(data, pathname);
100
- };
95
+ }
101
96
 
102
- // Useful to say "hey, you are not on the latest docs version, please switch"
103
- export const useDocVersionSuggestions = (
97
+ export function useDocVersionSuggestions(
104
98
  pluginId: string | undefined,
105
- ): DocVersionSuggestions => {
99
+ ): DocVersionSuggestions {
106
100
  const data = useDocsData(pluginId);
107
101
  const {pathname} = useLocation();
108
102
  return getDocVersionSuggestions(data, pathname);
109
- };
103
+ }
@@ -496,7 +496,7 @@ declare module '@docusaurus/plugin-content-docs' {
496
496
  }
497
497
 
498
498
  declare module '@theme/DocItem' {
499
- import type {TOCItem} from '@docusaurus/types';
499
+ import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
500
500
  import type {
501
501
  PropVersionMetadata,
502
502
  Assets,
@@ -514,14 +514,7 @@ declare module '@theme/DocItem' {
514
514
  export interface Props {
515
515
  readonly route: DocumentRoute;
516
516
  readonly versionMetadata: PropVersionMetadata;
517
- readonly content: {
518
- readonly frontMatter: DocFrontMatter;
519
- readonly metadata: DocMetadata;
520
- readonly toc: readonly TOCItem[];
521
- readonly contentTitle: string | undefined;
522
- readonly assets: Assets;
523
- (): JSX.Element;
524
- };
517
+ readonly content: LoadedMDXContent<DocFrontMatter, DocMetadata, Assets>;
525
518
  }
526
519
 
527
520
  export default function DocItem(props: Props): JSX.Element;
@@ -561,56 +554,18 @@ declare module '@theme/DocBreadcrumbs' {
561
554
 
562
555
  declare module '@theme/DocPage' {
563
556
  import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
564
- import type {DocumentRoute} from '@theme/DocItem';
557
+ import type {RouteConfigComponentProps} from 'react-router-config';
558
+ import type {Required} from 'utility-types';
565
559
 
566
- export interface Props {
567
- readonly location: {readonly pathname: string};
560
+ export interface Props extends Required<RouteConfigComponentProps, 'route'> {
568
561
  readonly versionMetadata: PropVersionMetadata;
569
- readonly route: {
570
- readonly path: string;
571
- readonly component: () => JSX.Element;
572
- readonly routes: DocumentRoute[];
573
- };
574
562
  }
575
563
 
576
564
  export default function DocPage(props: Props): JSX.Element;
577
565
  }
578
566
 
579
- declare module '@theme/DocPage/Layout' {
580
- import type {ReactNode} from 'react';
581
-
582
- export interface Props {
583
- children: ReactNode;
584
- }
585
-
586
- export default function DocPageLayout(props: Props): JSX.Element;
587
- }
588
-
589
- declare module '@theme/DocPage/Layout/Aside' {
590
- import type {Dispatch, SetStateAction} from 'react';
591
- import type {PropSidebar} from '@docusaurus/plugin-content-docs';
592
-
593
- export interface Props {
594
- sidebar: PropSidebar;
595
- hiddenSidebarContainer: boolean;
596
- setHiddenSidebarContainer: Dispatch<SetStateAction<boolean>>;
597
- }
598
-
599
- export default function DocPageLayoutAside(props: Props): JSX.Element;
600
- }
601
-
602
- declare module '@theme/DocPage/Layout/Main' {
603
- import type {ReactNode} from 'react';
604
-
605
- export interface Props {
606
- hiddenSidebarContainer: boolean;
607
- children: ReactNode;
608
- }
609
-
610
- export default function DocPageLayoutMain(props: Props): JSX.Element;
611
- }
612
-
613
- // TODO until TS supports exports field... hope it's in 4.6
567
+ // TODO TS only supports reading `exports` in 4.7. We will need to merge the
568
+ // type defs (and JSDoc) here with the implementation after that
614
569
  declare module '@docusaurus/plugin-content-docs/client' {
615
570
  import type {UseDataOptions} from '@docusaurus/types';
616
571
 
@@ -624,6 +579,11 @@ declare module '@docusaurus/plugin-content-docs/client' {
624
579
  alternateDocVersions: {[versionName: string]: GlobalDoc};
625
580
  };
626
581
  export type GlobalDoc = {
582
+ /**
583
+ * For generated index pages, this is the `slug`, **not** `permalink`
584
+ * (without base URL). Because slugs have leading slashes but IDs don't,
585
+ * there won't be clashes.
586
+ */
627
587
  id: string;
628
588
  path: string;
629
589
  sidebar: string | undefined;
@@ -634,7 +594,8 @@ declare module '@docusaurus/plugin-content-docs/client' {
634
594
  label: string;
635
595
  isLast: boolean;
636
596
  path: string;
637
- mainDocId: string; // home doc (if docs homepage configured), or first doc
597
+ /** The doc with `slug: /`, or first doc in first sidebar */
598
+ mainDocId: string;
638
599
  docs: GlobalDoc[];
639
600
  sidebars?: {[sidebarId: string]: GlobalSidebar};
640
601
  };
@@ -652,9 +613,9 @@ declare module '@docusaurus/plugin-content-docs/client' {
652
613
  breadcrumbs: boolean;
653
614
  };
654
615
  export type DocVersionSuggestions = {
655
- // suggest the latest version
616
+ /** suggest the latest version */
656
617
  latestVersionSuggestion: GlobalVersion;
657
- // suggest the same doc, in latest version (if exist)
618
+ /** suggest the same doc, in latest version (if exist) */
658
619
  latestDocSuggestion?: GlobalDoc;
659
620
  };
660
621
 
@@ -668,12 +629,20 @@ declare module '@docusaurus/plugin-content-docs/client' {
668
629
  ) =>
669
630
  | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
670
631
  | undefined;
632
+ /** Versions are returned ordered (most recent first). */
671
633
  export const useVersions: (pluginId?: string) => GlobalVersion[];
672
634
  export const useLatestVersion: (pluginId?: string) => GlobalVersion;
635
+ /**
636
+ * Returns `undefined` on doc-unrelated pages, because there's no version
637
+ * currently considered as active.
638
+ */
673
639
  export const useActiveVersion: (
674
640
  pluginId?: string,
675
641
  ) => GlobalVersion | undefined;
676
642
  export const useActiveDocContext: (pluginId?: string) => ActiveDocContext;
643
+ /**
644
+ * Useful to say "hey, you are not on the latest docs version, please switch"
645
+ */
677
646
  export const useDocVersionSuggestions: (
678
647
  pluginId?: string,
679
648
  ) => DocVersionSuggestions;