@docusaurus/plugin-content-docs 0.0.0-4853 → 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-4853",
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-4853",
28
- "@docusaurus/logger": "0.0.0-4853",
29
- "@docusaurus/mdx-loader": "0.0.0-4853",
30
- "@docusaurus/utils": "0.0.0-4853",
31
- "@docusaurus/utils-validation": "0.0.0-4853",
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-4853",
44
- "@docusaurus/types": "0.0.0-4853",
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": "4b716dd2a6d3cbe3516aac8ca20e7f9c61504f46"
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
+ }
@@ -554,56 +554,18 @@ declare module '@theme/DocBreadcrumbs' {
554
554
 
555
555
  declare module '@theme/DocPage' {
556
556
  import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
557
- import type {DocumentRoute} from '@theme/DocItem';
557
+ import type {RouteConfigComponentProps} from 'react-router-config';
558
+ import type {Required} from 'utility-types';
558
559
 
559
- export interface Props {
560
- readonly location: {readonly pathname: string};
560
+ export interface Props extends Required<RouteConfigComponentProps, 'route'> {
561
561
  readonly versionMetadata: PropVersionMetadata;
562
- readonly route: {
563
- readonly path: string;
564
- readonly component: () => JSX.Element;
565
- readonly routes: DocumentRoute[];
566
- };
567
562
  }
568
563
 
569
564
  export default function DocPage(props: Props): JSX.Element;
570
565
  }
571
566
 
572
- declare module '@theme/DocPage/Layout' {
573
- import type {ReactNode} from 'react';
574
-
575
- export interface Props {
576
- children: ReactNode;
577
- }
578
-
579
- export default function DocPageLayout(props: Props): JSX.Element;
580
- }
581
-
582
- declare module '@theme/DocPage/Layout/Aside' {
583
- import type {Dispatch, SetStateAction} from 'react';
584
- import type {PropSidebar} from '@docusaurus/plugin-content-docs';
585
-
586
- export interface Props {
587
- sidebar: PropSidebar;
588
- hiddenSidebarContainer: boolean;
589
- setHiddenSidebarContainer: Dispatch<SetStateAction<boolean>>;
590
- }
591
-
592
- export default function DocPageLayoutAside(props: Props): JSX.Element;
593
- }
594
-
595
- declare module '@theme/DocPage/Layout/Main' {
596
- import type {ReactNode} from 'react';
597
-
598
- export interface Props {
599
- hiddenSidebarContainer: boolean;
600
- children: ReactNode;
601
- }
602
-
603
- export default function DocPageLayoutMain(props: Props): JSX.Element;
604
- }
605
-
606
- // 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
607
569
  declare module '@docusaurus/plugin-content-docs/client' {
608
570
  import type {UseDataOptions} from '@docusaurus/types';
609
571
 
@@ -617,6 +579,11 @@ declare module '@docusaurus/plugin-content-docs/client' {
617
579
  alternateDocVersions: {[versionName: string]: GlobalDoc};
618
580
  };
619
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
+ */
620
587
  id: string;
621
588
  path: string;
622
589
  sidebar: string | undefined;
@@ -627,7 +594,8 @@ declare module '@docusaurus/plugin-content-docs/client' {
627
594
  label: string;
628
595
  isLast: boolean;
629
596
  path: string;
630
- 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;
631
599
  docs: GlobalDoc[];
632
600
  sidebars?: {[sidebarId: string]: GlobalSidebar};
633
601
  };
@@ -645,9 +613,9 @@ declare module '@docusaurus/plugin-content-docs/client' {
645
613
  breadcrumbs: boolean;
646
614
  };
647
615
  export type DocVersionSuggestions = {
648
- // suggest the latest version
616
+ /** suggest the latest version */
649
617
  latestVersionSuggestion: GlobalVersion;
650
- // suggest the same doc, in latest version (if exist)
618
+ /** suggest the same doc, in latest version (if exist) */
651
619
  latestDocSuggestion?: GlobalDoc;
652
620
  };
653
621
 
@@ -661,12 +629,20 @@ declare module '@docusaurus/plugin-content-docs/client' {
661
629
  ) =>
662
630
  | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
663
631
  | undefined;
632
+ /** Versions are returned ordered (most recent first). */
664
633
  export const useVersions: (pluginId?: string) => GlobalVersion[];
665
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
+ */
666
639
  export const useActiveVersion: (
667
640
  pluginId?: string,
668
641
  ) => GlobalVersion | undefined;
669
642
  export const useActiveDocContext: (pluginId?: string) => ActiveDocContext;
643
+ /**
644
+ * Useful to say "hey, you are not on the latest docs version, please switch"
645
+ */
670
646
  export const useDocVersionSuggestions: (
671
647
  pluginId?: string,
672
648
  ) => DocVersionSuggestions;