@docusaurus/plugin-content-docs 0.0.0-4547 → 0.0.0-4551

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.
@@ -1,108 +0,0 @@
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 {useLocation} from '@docusaurus/router';
9
- import useGlobalData, {
10
- // useAllPluginInstancesData,
11
- usePluginData,
12
- } from '@docusaurus/useGlobalData';
13
-
14
- import {
15
- getActivePlugin,
16
- getLatestVersion,
17
- getActiveVersion,
18
- getActiveDocContext,
19
- getDocVersionSuggestions,
20
- } from './docsClientUtils';
21
- import type {
22
- GlobalPluginData,
23
- GlobalVersion,
24
- ActivePlugin,
25
- ActiveDocContext,
26
- DocVersionSuggestions,
27
- GetActivePluginOptions,
28
- } from '@docusaurus/plugin-content-docs/client';
29
-
30
- // Important to use a constant object to avoid React useEffect executions etc.
31
- // see https://github.com/facebook/docusaurus/issues/5089
32
- const StableEmptyObject = {};
33
-
34
- // Not using useAllPluginInstancesData() because in blog-only mode, docs hooks
35
- // are still used by the theme. We need a fail-safe fallback when the docs
36
- // plugin is not in use
37
- export const useAllDocsData = (): Record<string, GlobalPluginData> =>
38
- // useAllPluginInstancesData('docusaurus-plugin-content-docs');
39
- useGlobalData()['docusaurus-plugin-content-docs'] ?? StableEmptyObject;
40
-
41
- export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
42
- usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
43
-
44
- // TODO this feature should be provided by docusaurus core
45
- export const useActivePlugin = (
46
- options: GetActivePluginOptions = {},
47
- ): ActivePlugin | undefined => {
48
- const data = useAllDocsData();
49
- const {pathname} = useLocation();
50
- return getActivePlugin(data, pathname, options);
51
- };
52
-
53
- export const useActivePluginAndVersion = (
54
- options: GetActivePluginOptions = {},
55
- ):
56
- | undefined
57
- | {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined} => {
58
- const activePlugin = useActivePlugin(options);
59
- const {pathname} = useLocation();
60
- if (activePlugin) {
61
- const activeVersion = getActiveVersion(activePlugin.pluginData, pathname);
62
- return {
63
- activePlugin,
64
- activeVersion,
65
- };
66
- }
67
- return undefined;
68
- };
69
-
70
- // versions are returned ordered (most recent first)
71
- export const useVersions = (pluginId: string | undefined): GlobalVersion[] => {
72
- const data = useDocsData(pluginId);
73
- return data.versions;
74
- };
75
-
76
- export const useLatestVersion = (
77
- pluginId: string | undefined,
78
- ): GlobalVersion => {
79
- const data = useDocsData(pluginId);
80
- return getLatestVersion(data);
81
- };
82
-
83
- // Note: return undefined on doc-unrelated pages,
84
- // because there's no version currently considered as active
85
- export const useActiveVersion = (
86
- pluginId: string | undefined,
87
- ): GlobalVersion | undefined => {
88
- const data = useDocsData(pluginId);
89
- const {pathname} = useLocation();
90
- return getActiveVersion(data, pathname);
91
- };
92
-
93
- export const useActiveDocContext = (
94
- pluginId: string | undefined,
95
- ): ActiveDocContext => {
96
- const data = useDocsData(pluginId);
97
- const {pathname} = useLocation();
98
- return getActiveDocContext(data, pathname);
99
- };
100
-
101
- // Useful to say "hey, you are not on the latest docs version, please switch"
102
- export const useDocVersionSuggestions = (
103
- pluginId: string | undefined,
104
- ): DocVersionSuggestions => {
105
- const data = useDocsData(pluginId);
106
- const {pathname} = useLocation();
107
- return getDocVersionSuggestions(data, pathname);
108
- };