@docusaurus/theme-common 0.0.0-6001 → 0.0.0-6004

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.
Files changed (47) hide show
  1. package/lib/index.d.ts +3 -3
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +16 -3
  4. package/lib/index.js.map +1 -1
  5. package/lib/internal.d.ts +1 -7
  6. package/lib/internal.d.ts.map +1 -1
  7. package/lib/internal.js +1 -7
  8. package/lib/internal.js.map +1 -1
  9. package/lib/utils/searchUtils.d.ts +0 -13
  10. package/lib/utils/searchUtils.d.ts.map +1 -1
  11. package/lib/utils/searchUtils.js +0 -39
  12. package/lib/utils/searchUtils.js.map +1 -1
  13. package/package.json +9 -10
  14. package/src/index.ts +23 -9
  15. package/src/internal.ts +1 -30
  16. package/src/types.d.ts +0 -1
  17. package/src/utils/searchUtils.ts +0 -58
  18. package/lib/contexts/doc.d.ts +0 -30
  19. package/lib/contexts/doc.d.ts.map +0 -1
  20. package/lib/contexts/doc.js +0 -48
  21. package/lib/contexts/doc.js.map +0 -1
  22. package/lib/contexts/docSidebarItemsExpandedState.d.ts +0 -31
  23. package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +0 -1
  24. package/lib/contexts/docSidebarItemsExpandedState.js +0 -28
  25. package/lib/contexts/docSidebarItemsExpandedState.js.map +0 -1
  26. package/lib/contexts/docsPreferredVersion.d.ts +0 -30
  27. package/lib/contexts/docsPreferredVersion.d.ts.map +0 -1
  28. package/lib/contexts/docsPreferredVersion.js +0 -130
  29. package/lib/contexts/docsPreferredVersion.js.map +0 -1
  30. package/lib/contexts/docsSidebar.d.ts +0 -26
  31. package/lib/contexts/docsSidebar.d.ts.map +0 -1
  32. package/lib/contexts/docsSidebar.js +0 -30
  33. package/lib/contexts/docsSidebar.js.map +0 -1
  34. package/lib/contexts/docsVersion.d.ts +0 -20
  35. package/lib/contexts/docsVersion.d.ts.map +0 -1
  36. package/lib/contexts/docsVersion.js +0 -26
  37. package/lib/contexts/docsVersion.js.map +0 -1
  38. package/lib/utils/docsUtils.d.ts +0 -108
  39. package/lib/utils/docsUtils.d.ts.map +0 -1
  40. package/lib/utils/docsUtils.js +0 -276
  41. package/lib/utils/docsUtils.js.map +0 -1
  42. package/src/contexts/doc.tsx +0 -71
  43. package/src/contexts/docSidebarItemsExpandedState.tsx +0 -55
  44. package/src/contexts/docsPreferredVersion.tsx +0 -251
  45. package/src/contexts/docsSidebar.tsx +0 -50
  46. package/src/contexts/docsVersion.tsx +0 -36
  47. package/src/utils/docsUtils.tsx +0 -418
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsPreferredVersion.d.ts","sourceRoot":"","sources":["../../src/contexts/docsPreferredVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAC;AAsJhD;;;GAGG;AACH,wBAAgB,mCAAmC,CAAC,EAClD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CASd;AAUD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,MAAM,GAAG,SAA6B,GAC/C;IACD,gBAAgB,EAAE,aAAa,GAAG,IAAI,CAAC;IACvC,wBAAwB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD,CAmBA;AAED,wBAAgB,iCAAiC,IAAI;IACnD,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;CAC1C,CAkBA"}
@@ -1,130 +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
- import React, { useContext, useEffect, useMemo, useState, useCallback, } from 'react';
8
- import { useAllDocsData, useDocsData, } from '@docusaurus/plugin-content-docs/client';
9
- import { DEFAULT_PLUGIN_ID } from '@docusaurus/constants';
10
- import { useThemeConfig, } from '../utils/useThemeConfig';
11
- import { isDocsPluginEnabled } from '../utils/docsUtils';
12
- import { ReactContextError } from '../utils/reactUtils';
13
- import { createStorageSlot } from '../utils/storageUtils';
14
- const storageKey = (pluginId) => `docs-preferred-version-${pluginId}`;
15
- const DocsPreferredVersionStorage = {
16
- save: (pluginId, persistence, versionName) => {
17
- createStorageSlot(storageKey(pluginId), { persistence }).set(versionName);
18
- },
19
- read: (pluginId, persistence) => createStorageSlot(storageKey(pluginId), { persistence }).get(),
20
- clear: (pluginId, persistence) => {
21
- createStorageSlot(storageKey(pluginId), { persistence }).del();
22
- },
23
- };
24
- /**
25
- * Initial state is always null as we can't read local storage from node SSR
26
- */
27
- const getInitialState = (pluginIds) => Object.fromEntries(pluginIds.map((id) => [id, { preferredVersionName: null }]));
28
- /**
29
- * Read storage for all docs plugins, assigning each doc plugin a preferred
30
- * version (if found)
31
- */
32
- function readStorageState({ pluginIds, versionPersistence, allDocsData, }) {
33
- /**
34
- * The storage value we read might be stale, and belong to a version that does
35
- * not exist in the site anymore. In such case, we remove the storage value to
36
- * avoid downstream errors.
37
- */
38
- function restorePluginState(pluginId) {
39
- const preferredVersionNameUnsafe = DocsPreferredVersionStorage.read(pluginId, versionPersistence);
40
- const pluginData = allDocsData[pluginId];
41
- const versionExists = pluginData.versions.some((version) => version.name === preferredVersionNameUnsafe);
42
- if (versionExists) {
43
- return { preferredVersionName: preferredVersionNameUnsafe };
44
- }
45
- DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
46
- return { preferredVersionName: null };
47
- }
48
- return Object.fromEntries(pluginIds.map((id) => [id, restorePluginState(id)]));
49
- }
50
- function useVersionPersistence() {
51
- return useThemeConfig().docs.versionPersistence;
52
- }
53
- const Context = React.createContext(null);
54
- function useContextValue() {
55
- const allDocsData = useAllDocsData();
56
- const versionPersistence = useVersionPersistence();
57
- const pluginIds = useMemo(() => Object.keys(allDocsData), [allDocsData]);
58
- // Initial state is empty, as we can't read browser storage in node/SSR
59
- const [state, setState] = useState(() => getInitialState(pluginIds));
60
- // On mount, we set the state read from browser storage
61
- useEffect(() => {
62
- setState(readStorageState({ allDocsData, versionPersistence, pluginIds }));
63
- }, [allDocsData, versionPersistence, pluginIds]);
64
- // The API that we expose to consumer hooks (memo for constant object)
65
- const api = useMemo(() => {
66
- function savePreferredVersion(pluginId, versionName) {
67
- DocsPreferredVersionStorage.save(pluginId, versionPersistence, versionName);
68
- setState((s) => ({
69
- ...s,
70
- [pluginId]: { preferredVersionName: versionName },
71
- }));
72
- }
73
- return {
74
- savePreferredVersion,
75
- };
76
- }, [versionPersistence]);
77
- return [state, api];
78
- }
79
- function DocsPreferredVersionContextProviderUnsafe({ children, }) {
80
- const value = useContextValue();
81
- return <Context.Provider value={value}>{children}</Context.Provider>;
82
- }
83
- /**
84
- * This is a maybe-layer. If the docs plugin is not enabled, this provider is a
85
- * simple pass-through.
86
- */
87
- export function DocsPreferredVersionContextProvider({ children, }) {
88
- if (isDocsPluginEnabled) {
89
- return (<DocsPreferredVersionContextProviderUnsafe>
90
- {children}
91
- </DocsPreferredVersionContextProviderUnsafe>);
92
- }
93
- return <>{children}</>;
94
- }
95
- function useDocsPreferredVersionContext() {
96
- const value = useContext(Context);
97
- if (!value) {
98
- throw new ReactContextError('DocsPreferredVersionContextProvider');
99
- }
100
- return value;
101
- }
102
- /**
103
- * Returns a read-write interface to a plugin's preferred version. The
104
- * "preferred version" is defined as the last version that the user visited.
105
- * For example, if a user is using v3, even when v4 is later published, the user
106
- * would still be browsing v3 docs when she opens the website next time. Note,
107
- * the `preferredVersion` attribute will always be `null` before mount.
108
- */
109
- export function useDocsPreferredVersion(pluginId = DEFAULT_PLUGIN_ID) {
110
- const docsData = useDocsData(pluginId);
111
- const [state, api] = useDocsPreferredVersionContext();
112
- const { preferredVersionName } = state[pluginId];
113
- const preferredVersion = docsData.versions.find((version) => version.name === preferredVersionName) ?? null;
114
- const savePreferredVersionName = useCallback((versionName) => {
115
- api.savePreferredVersion(pluginId, versionName);
116
- }, [api, pluginId]);
117
- return { preferredVersion, savePreferredVersionName };
118
- }
119
- export function useDocsPreferredVersionByPluginId() {
120
- const allDocsData = useAllDocsData();
121
- const [state] = useDocsPreferredVersionContext();
122
- function getPluginIdPreferredVersion(pluginId) {
123
- const docsData = allDocsData[pluginId];
124
- const { preferredVersionName } = state[pluginId];
125
- return (docsData.versions.find((version) => version.name === preferredVersionName) ?? null);
126
- }
127
- const pluginIds = Object.keys(allDocsData);
128
- return Object.fromEntries(pluginIds.map((id) => [id, getPluginIdPreferredVersion(id)]));
129
- }
130
- //# sourceMappingURL=docsPreferredVersion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsPreferredVersion.js","sourceRoot":"","sources":["../../src/contexts/docsPreferredVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,WAAW,GAEZ,MAAM,OAAO,CAAC;AACf,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AAExD,MAAM,UAAU,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAE9E,MAAM,2BAA2B,GAAG;IAClC,IAAI,EAAE,CACJ,QAAgB,EAChB,WAAmC,EACnC,WAAmB,EACb,EAAE;QACR,iBAAiB,CAAC,UAAU,CAAC,QAAQ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,CAAC,QAAQ,CAAC,IAAI,CACpB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB,CACnD,IAAI,IAAI,CAAC;IAEZ,MAAM,wBAAwB,GAAG,WAAW,CAC1C,CAAC,WAAmB,EAAE,EAAE;QACtB,GAAG,CAAC,oBAAoB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,CAAC,CAChB,CAAC;IAEF,OAAO,EAAC,gBAAgB,EAAE,wBAAwB,EAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,iCAAiC;IAG/C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,CAAC,KAAK,CAAC,GAAG,8BAA8B,EAAE,CAAC;IAEjD,SAAS,2BAA2B,CAAC,QAAgB;QACnD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAE,CAAC;QACxC,MAAM,EAAC,oBAAoB,EAAC,GAAG,KAAK,CAAC,QAAQ,CAAE,CAAC;QAEhD,OAAO,CACL,QAAQ,CAAC,QAAQ,CAAC,IAAI,CACpB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB,CACnD,IAAI,IAAI,CACV,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC,WAAW,CACvB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC,CAC7D,CAAC;AACJ,CAAC"}
@@ -1,26 +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
- import { type ReactNode } from 'react';
8
- import type { PropSidebar } from '@docusaurus/plugin-content-docs';
9
- type ContextValue = {
10
- name: string;
11
- items: PropSidebar;
12
- };
13
- /**
14
- * Provide the current sidebar to your children.
15
- */
16
- export declare function DocsSidebarProvider({ children, name, items, }: {
17
- children: ReactNode;
18
- name: string | undefined;
19
- items: PropSidebar | undefined;
20
- }): JSX.Element;
21
- /**
22
- * Gets the sidebar that's currently displayed, or `null` if there isn't one
23
- */
24
- export declare function useDocsSidebar(): ContextValue | null;
25
- export {};
26
- //# sourceMappingURL=docsSidebar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsSidebar.d.ts","sourceRoot":"","sources":["../../src/contexts/docsSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAsB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAEjE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAMjE,KAAK,YAAY,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAC,CAAC;AAMvD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,IAAI,EACJ,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;CAChC,GAAG,GAAG,CAAC,OAAO,CAMd;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,YAAY,GAAG,IAAI,CAMpD"}
@@ -1,30 +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
- import React, { useMemo, useContext } from 'react';
8
- import { ReactContextError } from '../utils/reactUtils';
9
- // Using a Symbol because null is a valid context value (a doc with no sidebar)
10
- // Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
11
- const EmptyContext = Symbol('EmptyContext');
12
- const Context = React.createContext(EmptyContext);
13
- /**
14
- * Provide the current sidebar to your children.
15
- */
16
- export function DocsSidebarProvider({ children, name, items, }) {
17
- const stableValue = useMemo(() => (name && items ? { name, items } : null), [name, items]);
18
- return <Context.Provider value={stableValue}>{children}</Context.Provider>;
19
- }
20
- /**
21
- * Gets the sidebar that's currently displayed, or `null` if there isn't one
22
- */
23
- export function useDocsSidebar() {
24
- const value = useContext(Context);
25
- if (value === EmptyContext) {
26
- throw new ReactContextError('DocsSidebarProvider');
27
- }
28
- return value;
29
- }
30
- //# sourceMappingURL=docsSidebar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsSidebar.js","sourceRoot":"","sources":["../../src/contexts/docsSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAC,OAAO,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAC;AACjE,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAGtD,+EAA+E;AAC/E,6FAA6F;AAC7F,MAAM,YAAY,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAI3D,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CACjC,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,IAAI,EACJ,KAAK,GAKN;IACC,MAAM,WAAW,GAAwB,OAAO,CAC9C,GAAG,EAAE,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAC5C,CAAC,IAAI,EAAE,KAAK,CAAC,CACd,CAAC;IACF,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QAC3B,MAAM,IAAI,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,20 +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
- import { type ReactNode } from 'react';
8
- import type { PropVersionMetadata } from '@docusaurus/plugin-content-docs';
9
- /**
10
- * Provide the current version's metadata to your children.
11
- */
12
- export declare function DocsVersionProvider({ children, version, }: {
13
- children: ReactNode;
14
- version: PropVersionMetadata | null;
15
- }): JSX.Element;
16
- /**
17
- * Gets the version metadata of the current doc page.
18
- */
19
- export declare function useDocsVersion(): PropVersionMetadata;
20
- //# sourceMappingURL=docsVersion.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsVersion.d.ts","sourceRoot":"","sources":["../../src/contexts/docsVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAC,KAAK,SAAS,EAAa,MAAM,OAAO,CAAC;AAExD,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AAIzE;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACrC,GAAG,GAAG,CAAC,OAAO,CAEd;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,mBAAmB,CAMpD"}
@@ -1,26 +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
- import React, { useContext } from 'react';
8
- import { ReactContextError } from '../utils/reactUtils';
9
- const Context = React.createContext(null);
10
- /**
11
- * Provide the current version's metadata to your children.
12
- */
13
- export function DocsVersionProvider({ children, version, }) {
14
- return <Context.Provider value={version}>{children}</Context.Provider>;
15
- }
16
- /**
17
- * Gets the version metadata of the current doc page.
18
- */
19
- export function useDocsVersion() {
20
- const version = useContext(Context);
21
- if (version === null) {
22
- throw new ReactContextError('DocsVersionProvider');
23
- }
24
- return version;
25
- }
26
- //# sourceMappingURL=docsVersion.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsVersion.js","sourceRoot":"","sources":["../../src/contexts/docsVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAC,MAAM,OAAO,CAAC;AACxD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAGtD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA6B,IAAI,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,OAAO,GAIR;IACC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -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
- import { type GlobalVersion, type GlobalSidebar, type GlobalDoc } from '@docusaurus/plugin-content-docs/client';
8
- import type { Props as DocRootProps } from '@theme/DocRoot';
9
- import type { PropSidebar, PropSidebarItem, PropSidebarItemCategory, PropVersionDoc, PropSidebarBreadcrumbsItem } from '@docusaurus/plugin-content-docs';
10
- export declare const isDocsPluginEnabled: boolean;
11
- /**
12
- * A null-safe way to access a doc's data by ID in the active version.
13
- */
14
- export declare function useDocById(id: string): PropVersionDoc;
15
- /**
16
- * A null-safe way to access a doc's data by ID in the active version.
17
- */
18
- export declare function useDocById(id: string | undefined): PropVersionDoc | undefined;
19
- /**
20
- * Pure function, similar to `Array#find`, but works on the sidebar tree.
21
- */
22
- export declare function findSidebarCategory(sidebar: PropSidebar, predicate: (category: PropSidebarItemCategory) => boolean): PropSidebarItemCategory | undefined;
23
- /**
24
- * Best effort to assign a link to a sidebar category. If the category doesn't
25
- * have a link itself, we link to the first sub item with a link.
26
- */
27
- export declare function findFirstSidebarItemCategoryLink(item: PropSidebarItemCategory): string | undefined;
28
- /**
29
- * Best effort to assign a link to a sidebar item.
30
- */
31
- export declare function findFirstSidebarItemLink(item: PropSidebarItem): string | undefined;
32
- /**
33
- * Gets the category associated with the current location. Should only be used
34
- * on category index pages.
35
- */
36
- export declare function useCurrentSidebarCategory(): PropSidebarItemCategory;
37
- /**
38
- * Checks if a sidebar item should be active, based on the active path.
39
- */
40
- export declare function isActiveSidebarItem(item: PropSidebarItem, activePath: string): boolean;
41
- export declare function isVisibleSidebarItem(item: PropSidebarItem, activePath: string): boolean;
42
- export declare function useVisibleSidebarItems(items: readonly PropSidebarItem[], activePath: string): PropSidebarItem[];
43
- /**
44
- * Gets the breadcrumbs of the current doc page, based on its sidebar location.
45
- * Returns `null` if there's no sidebar or breadcrumbs are disabled.
46
- */
47
- export declare function useSidebarBreadcrumbs(): PropSidebarBreadcrumbsItem[] | null;
48
- /**
49
- * "Version candidates" are mostly useful for the layout components, which must
50
- * be able to work on all pages. For example, if a user has `{ type: "doc",
51
- * docId: "intro" }` as a navbar item, which version does that refer to? We
52
- * believe that it could refer to at most three version candidates:
53
- *
54
- * 1. The **active version**, the one that the user is currently browsing. See
55
- * {@link useActiveDocContext}.
56
- * 2. The **preferred version**, the one that the user last visited. See
57
- * {@link useDocsPreferredVersion}.
58
- * 3. The **latest version**, the "default". See {@link useLatestVersion}.
59
- *
60
- * @param docsPluginId The plugin ID to get versions from.
61
- * @returns An array of 1~3 versions with priorities defined above, guaranteed
62
- * to be unique and non-sparse. Will be memoized, hence stable for deps array.
63
- */
64
- export declare function useDocsVersionCandidates(docsPluginId?: string): [GlobalVersion, ...GlobalVersion[]];
65
- /**
66
- * The layout components, like navbar items, must be able to work on all pages,
67
- * even on non-doc ones where there's no version context, so a sidebar ID could
68
- * be ambiguous. This hook would always return a sidebar to be linked to. See
69
- * also {@link useDocsVersionCandidates} for how this selection is done.
70
- *
71
- * @throws This hook throws if a sidebar with said ID is not found.
72
- */
73
- export declare function useLayoutDocsSidebar(sidebarId: string, docsPluginId?: string): GlobalSidebar;
74
- /**
75
- * The layout components, like navbar items, must be able to work on all pages,
76
- * even on non-doc ones where there's no version context, so a doc ID could be
77
- * ambiguous. This hook would always return a doc to be linked to. See also
78
- * {@link useDocsVersionCandidates} for how this selection is done.
79
- *
80
- * @throws This hook throws if a doc with said ID is not found.
81
- */
82
- export declare function useLayoutDoc(docId: string, docsPluginId?: string): GlobalDoc | null;
83
- /**
84
- * The docs plugin creates nested routes, with the top-level route providing the
85
- * version metadata, and the subroutes creating individual doc pages. This hook
86
- * will match the current location against all known sub-routes.
87
- *
88
- * @param props The props received by `@theme/DocRoot`
89
- * @returns The data of the relevant document at the current location, or `null`
90
- * if no document associated with the current location can be found.
91
- */
92
- export declare function useDocRootMetadata({ route }: DocRootProps): null | {
93
- /** The element that should be rendered at the current location. */
94
- docElement: JSX.Element;
95
- /**
96
- * The name of the sidebar associated with the current doc. `sidebarName` and
97
- * `sidebarItems` correspond to the value of {@link useDocsSidebar}.
98
- */
99
- sidebarName: string | undefined;
100
- /** The items of the sidebar associated with the current doc. */
101
- sidebarItems: PropSidebar | undefined;
102
- };
103
- /**
104
- * Filter items we don't want to display on the doc card list view
105
- * @param items
106
- */
107
- export declare function filterDocCardListItems(items: PropSidebarItem[]): PropSidebarItem[];
108
- //# sourceMappingURL=docsUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/docsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAC,KAAK,IAAI,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAM1D,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,cAAc,EACd,0BAA0B,EAC3B,MAAM,iCAAiC,CAAC;AAGzC,eAAO,MAAM,mBAAmB,EAAE,OAA0B,CAAC;AAE7D;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,cAAc,CAAC;AACvD;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC;AAa/E;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,CAAC,QAAQ,EAAE,uBAAuB,KAAK,OAAO,GACxD,uBAAuB,GAAG,SAAS,CAarC;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,uBAAuB,GAC5B,MAAM,GAAG,SAAS,CAYpB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,eAAe,GACpB,MAAM,GAAG,SAAS,CASpB;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,uBAAuB,CAkBnE;AASD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAaT;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAaT;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,UAAU,EAAE,MAAM,GACjB,eAAe,EAAE,CAKnB;AAmDD;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,EAAE,GAAG,IAAI,CAQ3E;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,CAAC,EAAE,MAAM,GACpB,CAAC,aAAa,EAAE,GAAG,aAAa,EAAE,CAAC,CAWrC;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,aAAa,CAoBf;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS,GAAG,IAAI,CAuBlB;AAGD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,EAAC,KAAK,EAAC,EAAE,YAAY,GAAG,IAAI,GAAG;IAChE,mEAAmE;IACnE,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC;IACxB;;;OAGG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,gEAAgE;IAChE,YAAY,EAAE,WAAW,GAAG,SAAS,CAAC;CACvC,CAyBA;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,eAAe,EAAE,GACvB,eAAe,EAAE,CAQnB"}
@@ -1,276 +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
- import { useMemo } from 'react';
8
- import { matchPath, useLocation } from '@docusaurus/router';
9
- import renderRoutes from '@docusaurus/renderRoutes';
10
- import { useAllDocsData, useActivePlugin, useActiveDocContext, useLatestVersion, } from '@docusaurus/plugin-content-docs/client';
11
- import { useDocsPreferredVersion } from '../contexts/docsPreferredVersion';
12
- import { useDocsVersion } from '../contexts/docsVersion';
13
- import { useDocsSidebar } from '../contexts/docsSidebar';
14
- import { uniq } from './jsUtils';
15
- import { isSamePath } from './routesUtils';
16
- // TODO not ideal, see also "useDocs"
17
- export const isDocsPluginEnabled = !!useAllDocsData;
18
- export function useDocById(id) {
19
- const version = useDocsVersion();
20
- if (!id) {
21
- return undefined;
22
- }
23
- const doc = version.docs[id];
24
- if (!doc) {
25
- throw new Error(`no version doc found by id=${id}`);
26
- }
27
- return doc;
28
- }
29
- /**
30
- * Pure function, similar to `Array#find`, but works on the sidebar tree.
31
- */
32
- export function findSidebarCategory(sidebar, predicate) {
33
- for (const item of sidebar) {
34
- if (item.type === 'category') {
35
- if (predicate(item)) {
36
- return item;
37
- }
38
- const subItem = findSidebarCategory(item.items, predicate);
39
- if (subItem) {
40
- return subItem;
41
- }
42
- }
43
- }
44
- return undefined;
45
- }
46
- /**
47
- * Best effort to assign a link to a sidebar category. If the category doesn't
48
- * have a link itself, we link to the first sub item with a link.
49
- */
50
- export function findFirstSidebarItemCategoryLink(item) {
51
- if (item.href && !item.linkUnlisted) {
52
- return item.href;
53
- }
54
- for (const subItem of item.items) {
55
- const link = findFirstSidebarItemLink(subItem);
56
- if (link) {
57
- return link;
58
- }
59
- }
60
- return undefined;
61
- }
62
- /**
63
- * Best effort to assign a link to a sidebar item.
64
- */
65
- export function findFirstSidebarItemLink(item) {
66
- if (item.type === 'link' && !item.unlisted) {
67
- return item.href;
68
- }
69
- if (item.type === 'category') {
70
- return findFirstSidebarItemCategoryLink(item);
71
- }
72
- // Other items types, like "html"
73
- return undefined;
74
- }
75
- /**
76
- * Gets the category associated with the current location. Should only be used
77
- * on category index pages.
78
- */
79
- export function useCurrentSidebarCategory() {
80
- const { pathname } = useLocation();
81
- const sidebar = useDocsSidebar();
82
- if (!sidebar) {
83
- throw new Error('Unexpected: cant find current sidebar in context');
84
- }
85
- const categoryBreadcrumbs = getSidebarBreadcrumbs({
86
- sidebarItems: sidebar.items,
87
- pathname,
88
- onlyCategories: true,
89
- });
90
- const deepestCategory = categoryBreadcrumbs.slice(-1)[0];
91
- if (!deepestCategory) {
92
- throw new Error(`${pathname} is not associated with a category. useCurrentSidebarCategory() should only be used on category index pages.`);
93
- }
94
- return deepestCategory;
95
- }
96
- const isActive = (testedPath, activePath) => typeof testedPath !== 'undefined' && isSamePath(testedPath, activePath);
97
- const containsActiveSidebarItem = (items, activePath) => items.some((subItem) => isActiveSidebarItem(subItem, activePath));
98
- /**
99
- * Checks if a sidebar item should be active, based on the active path.
100
- */
101
- export function isActiveSidebarItem(item, activePath) {
102
- if (item.type === 'link') {
103
- return isActive(item.href, activePath);
104
- }
105
- if (item.type === 'category') {
106
- return (isActive(item.href, activePath) ||
107
- containsActiveSidebarItem(item.items, activePath));
108
- }
109
- return false;
110
- }
111
- export function isVisibleSidebarItem(item, activePath) {
112
- switch (item.type) {
113
- case 'category':
114
- return (isActiveSidebarItem(item, activePath) ||
115
- item.items.some((subItem) => isVisibleSidebarItem(subItem, activePath)));
116
- case 'link':
117
- // An unlisted item remains visible if it is active
118
- return !item.unlisted || isActiveSidebarItem(item, activePath);
119
- default:
120
- return true;
121
- }
122
- }
123
- export function useVisibleSidebarItems(items, activePath) {
124
- return useMemo(() => items.filter((item) => isVisibleSidebarItem(item, activePath)), [items, activePath]);
125
- }
126
- /**
127
- * Get the sidebar the breadcrumbs for a given pathname
128
- * Ordered from top to bottom
129
- */
130
- function getSidebarBreadcrumbs({ sidebarItems, pathname, onlyCategories = false, }) {
131
- const breadcrumbs = [];
132
- function extract(items) {
133
- for (const item of items) {
134
- if ((item.type === 'category' &&
135
- (isSamePath(item.href, pathname) || extract(item.items))) ||
136
- (item.type === 'link' && isSamePath(item.href, pathname))) {
137
- const filtered = onlyCategories && item.type !== 'category';
138
- if (!filtered) {
139
- breadcrumbs.unshift(item);
140
- }
141
- return true;
142
- }
143
- }
144
- return false;
145
- }
146
- extract(sidebarItems);
147
- return breadcrumbs;
148
- }
149
- /**
150
- * Gets the breadcrumbs of the current doc page, based on its sidebar location.
151
- * Returns `null` if there's no sidebar or breadcrumbs are disabled.
152
- */
153
- export function useSidebarBreadcrumbs() {
154
- const sidebar = useDocsSidebar();
155
- const { pathname } = useLocation();
156
- const breadcrumbsOption = useActivePlugin()?.pluginData.breadcrumbs;
157
- if (breadcrumbsOption === false || !sidebar) {
158
- return null;
159
- }
160
- return getSidebarBreadcrumbs({ sidebarItems: sidebar.items, pathname });
161
- }
162
- /**
163
- * "Version candidates" are mostly useful for the layout components, which must
164
- * be able to work on all pages. For example, if a user has `{ type: "doc",
165
- * docId: "intro" }` as a navbar item, which version does that refer to? We
166
- * believe that it could refer to at most three version candidates:
167
- *
168
- * 1. The **active version**, the one that the user is currently browsing. See
169
- * {@link useActiveDocContext}.
170
- * 2. The **preferred version**, the one that the user last visited. See
171
- * {@link useDocsPreferredVersion}.
172
- * 3. The **latest version**, the "default". See {@link useLatestVersion}.
173
- *
174
- * @param docsPluginId The plugin ID to get versions from.
175
- * @returns An array of 1~3 versions with priorities defined above, guaranteed
176
- * to be unique and non-sparse. Will be memoized, hence stable for deps array.
177
- */
178
- export function useDocsVersionCandidates(docsPluginId) {
179
- const { activeVersion } = useActiveDocContext(docsPluginId);
180
- const { preferredVersion } = useDocsPreferredVersion(docsPluginId);
181
- const latestVersion = useLatestVersion(docsPluginId);
182
- return useMemo(() => uniq([activeVersion, preferredVersion, latestVersion].filter(Boolean)), [activeVersion, preferredVersion, latestVersion]);
183
- }
184
- /**
185
- * The layout components, like navbar items, must be able to work on all pages,
186
- * even on non-doc ones where there's no version context, so a sidebar ID could
187
- * be ambiguous. This hook would always return a sidebar to be linked to. See
188
- * also {@link useDocsVersionCandidates} for how this selection is done.
189
- *
190
- * @throws This hook throws if a sidebar with said ID is not found.
191
- */
192
- export function useLayoutDocsSidebar(sidebarId, docsPluginId) {
193
- const versions = useDocsVersionCandidates(docsPluginId);
194
- return useMemo(() => {
195
- const allSidebars = versions.flatMap((version) => version.sidebars ? Object.entries(version.sidebars) : []);
196
- const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
197
- if (!sidebarEntry) {
198
- throw new Error(`Can't find any sidebar with id "${sidebarId}" in version${versions.length > 1 ? 's' : ''} ${versions.map((version) => version.name).join(', ')}".
199
- Available sidebar ids are:
200
- - ${allSidebars.map((entry) => entry[0]).join('\n- ')}`);
201
- }
202
- return sidebarEntry[1];
203
- }, [sidebarId, versions]);
204
- }
205
- /**
206
- * The layout components, like navbar items, must be able to work on all pages,
207
- * even on non-doc ones where there's no version context, so a doc ID could be
208
- * ambiguous. This hook would always return a doc to be linked to. See also
209
- * {@link useDocsVersionCandidates} for how this selection is done.
210
- *
211
- * @throws This hook throws if a doc with said ID is not found.
212
- */
213
- export function useLayoutDoc(docId, docsPluginId) {
214
- const versions = useDocsVersionCandidates(docsPluginId);
215
- return useMemo(() => {
216
- const allDocs = versions.flatMap((version) => version.docs);
217
- const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
218
- if (!doc) {
219
- const isDraft = versions
220
- .flatMap((version) => version.draftIds)
221
- .includes(docId);
222
- // Drafts should be silently filtered instead of throwing
223
- if (isDraft) {
224
- return null;
225
- }
226
- throw new Error(`Couldn't find any doc with id "${docId}" in version${versions.length > 1 ? 's' : ''} "${versions.map((version) => version.name).join(', ')}".
227
- Available doc ids are:
228
- - ${uniq(allDocs.map((versionDoc) => versionDoc.id)).join('\n- ')}`);
229
- }
230
- return doc;
231
- }, [docId, versions]);
232
- }
233
- // TODO later read version/route directly from context
234
- /**
235
- * The docs plugin creates nested routes, with the top-level route providing the
236
- * version metadata, and the subroutes creating individual doc pages. This hook
237
- * will match the current location against all known sub-routes.
238
- *
239
- * @param props The props received by `@theme/DocRoot`
240
- * @returns The data of the relevant document at the current location, or `null`
241
- * if no document associated with the current location can be found.
242
- */
243
- export function useDocRootMetadata({ route }) {
244
- const location = useLocation();
245
- const versionMetadata = useDocsVersion();
246
- const docRoutes = route.routes;
247
- const currentDocRoute = docRoutes.find((docRoute) => matchPath(location.pathname, docRoute));
248
- if (!currentDocRoute) {
249
- return null;
250
- }
251
- // For now, the sidebarName is added as route config: not ideal!
252
- const sidebarName = currentDocRoute.sidebar;
253
- const sidebarItems = sidebarName
254
- ? versionMetadata.docsSidebars[sidebarName]
255
- : undefined;
256
- const docElement = renderRoutes(docRoutes);
257
- return {
258
- docElement,
259
- sidebarName,
260
- sidebarItems,
261
- };
262
- }
263
- /**
264
- * Filter items we don't want to display on the doc card list view
265
- * @param items
266
- */
267
- export function filterDocCardListItems(items) {
268
- return items.filter((item) => {
269
- const canHaveLink = item.type === 'category' || item.type === 'link';
270
- if (canHaveLink) {
271
- return !!findFirstSidebarItemLink(item);
272
- }
273
- return true;
274
- });
275
- }
276
- //# sourceMappingURL=docsUtils.js.map