@docusaurus/theme-common 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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.
- package/lib/components/Collapsible/index.d.ts +36 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +143 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +12 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +66 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +58 -0
- package/{src/utils/docsUtils.ts → lib/hooks/styles.css} +3 -4
- package/lib/hooks/useHideableNavbar.d.ts +13 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +59 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +10 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +31 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +8 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +16 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +9 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +18 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +14 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +42 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +15 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +56 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +32 -3
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +26 -2
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +40 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +41 -3
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/announcementBarUtils.d.ts +6 -5
- package/lib/utils/announcementBarUtils.d.ts.map +1 -0
- package/lib/utils/announcementBarUtils.js +20 -21
- package/lib/utils/announcementBarUtils.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +10 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +125 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/colorModeUtils.d.ts +18 -0
- package/lib/utils/colorModeUtils.d.ts.map +1 -0
- package/lib/utils/colorModeUtils.js +107 -0
- package/lib/utils/colorModeUtils.js.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts +17 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.js +23 -0
- package/lib/utils/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +3 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +9 -11
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +2 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +2 -3
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +12 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +3 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +26 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +136 -1
- package/lib/utils/docsUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +7 -0
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +3 -2
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +23 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +41 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- package/lib/utils/mobileSecondaryMenu.d.ts +21 -0
- package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -0
- package/lib/utils/mobileSecondaryMenu.js +51 -0
- package/lib/utils/mobileSecondaryMenu.js.map +1 -0
- package/lib/utils/pathUtils.d.ts +1 -0
- package/lib/utils/pathUtils.d.ts.map +1 -0
- package/lib/utils/pathUtils.js +5 -4
- package/lib/utils/pathUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +31 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +43 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +11 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +17 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +14 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +41 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +53 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +135 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +1 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +1 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +5 -0
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +39 -14
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts +19 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.js +55 -0
- package/lib/utils/tabGroupChoiceUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +19 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +33 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +20 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +73 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +3 -1
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useContextualSearchFilters.d.ts +12 -0
- package/lib/utils/useContextualSearchFilters.d.ts.map +1 -0
- package/lib/utils/useContextualSearchFilters.js +36 -0
- package/lib/utils/useContextualSearchFilters.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +8 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +17 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +2 -1
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +12 -10
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +1 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +28 -24
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/usePrevious.d.ts +1 -0
- package/lib/utils/usePrevious.d.ts.map +1 -0
- package/lib/utils/usePrevious.js +4 -2
- package/lib/utils/usePrevious.js.map +1 -0
- package/lib/utils/useTOCHighlight.d.ts +14 -0
- package/lib/utils/useTOCHighlight.d.ts.map +1 -0
- package/lib/utils/useTOCHighlight.js +126 -0
- package/lib/utils/useTOCHighlight.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +35 -17
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +1 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +19 -13
- package/src/components/Collapsible/index.tsx +247 -0
- package/src/components/Details/index.tsx +102 -0
- package/src/components/Details/styles.module.css +58 -0
- package/src/hooks/styles.css +10 -0
- package/src/hooks/useHideableNavbar.ts +77 -0
- package/src/hooks/useKeyboardNavigation.ts +37 -0
- package/src/hooks/useLockBodyScroll.ts +18 -0
- package/src/hooks/usePrismTheme.ts +20 -0
- package/src/hooks/useSearchPage.ts +66 -0
- package/src/hooks/useWindowSize.ts +70 -0
- package/src/index.ts +95 -3
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +46 -4
- package/src/utils/announcementBarUtils.tsx +27 -22
- package/src/utils/codeBlockUtils.ts +153 -2
- package/src/utils/colorModeUtils.tsx +158 -0
- package/src/utils/docSidebarItemsExpandedState.tsx +40 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +17 -16
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +3 -4
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +18 -14
- package/src/utils/docsUtils.tsx +231 -0
- package/src/utils/generalUtils.ts +3 -2
- package/src/utils/historyUtils.ts +51 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/mobileSecondaryMenu.tsx +114 -0
- package/src/utils/pathUtils.ts +6 -4
- package/src/utils/reactUtils.tsx +53 -0
- package/src/utils/regexpUtils.ts +23 -0
- package/src/utils/routesUtils.ts +56 -0
- package/src/utils/scrollUtils.tsx +235 -0
- package/src/utils/storageUtils.ts +37 -12
- package/src/utils/tabGroupChoiceUtils.tsx +89 -0
- package/src/utils/tagsUtils.ts +48 -0
- package/src/utils/tocUtils.ts +108 -0
- package/src/utils/useAlternatePageUtils.ts +4 -3
- package/src/utils/useContextualSearchFilters.ts +53 -0
- package/src/utils/useLocalPathname.ts +20 -0
- package/src/utils/useLocationChange.ts +13 -11
- package/src/utils/usePluralForm.ts +31 -26
- package/src/utils/usePrevious.ts +3 -2
- package/src/utils/useTOCHighlight.ts +183 -0
- package/src/utils/useThemeConfig.ts +37 -17
- package/lib/.tsbuildinfo +0 -1
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/tsconfig.json +0 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrevious.d.ts","sourceRoot":"","sources":["../../src/utils/usePrevious.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAQtD"}
|
package/lib/utils/usePrevious.js
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import { useRef
|
|
7
|
+
import { useRef } from 'react';
|
|
8
|
+
import { useIsomorphicLayoutEffect } from './reactUtils';
|
|
8
9
|
export function usePrevious(value) {
|
|
9
10
|
const ref = useRef();
|
|
10
|
-
|
|
11
|
+
useIsomorphicLayoutEffect(() => {
|
|
11
12
|
ref.current = value;
|
|
12
13
|
});
|
|
13
14
|
return ref.current;
|
|
14
15
|
}
|
|
16
|
+
//# sourceMappingURL=usePrevious.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../src/utils/usePrevious.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAC,yBAAyB,EAAC,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,MAAM,GAAG,GAAG,MAAM,EAAK,CAAC;IAExB,yBAAyB,CAAC,GAAG,EAAE;QAC7B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export declare type TOCHighlightConfig = {
|
|
8
|
+
linkClassName: string;
|
|
9
|
+
linkActiveClassName: string;
|
|
10
|
+
minHeadingLevel: number;
|
|
11
|
+
maxHeadingLevel: number;
|
|
12
|
+
};
|
|
13
|
+
export default function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
|
|
14
|
+
//# sourceMappingURL=useTOCHighlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH,oBAAY,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GACrC,IAAI,CAwDN"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { useEffect, useRef } from 'react';
|
|
8
|
+
import { useThemeConfig } from './useThemeConfig';
|
|
9
|
+
/*
|
|
10
|
+
TODO make the hardcoded theme-classic classnames configurable
|
|
11
|
+
(or add them to ThemeClassNames?)
|
|
12
|
+
*/
|
|
13
|
+
// If the anchor has no height and is just a "marker" in the dom; we'll use the
|
|
14
|
+
// parent (normally the link text) rect boundaries instead
|
|
15
|
+
function getVisibleBoundingClientRect(element) {
|
|
16
|
+
const rect = element.getBoundingClientRect();
|
|
17
|
+
const hasNoHeight = rect.top === rect.bottom;
|
|
18
|
+
if (hasNoHeight) {
|
|
19
|
+
return getVisibleBoundingClientRect(element.parentNode);
|
|
20
|
+
}
|
|
21
|
+
return rect;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Considering we divide viewport into 2 zones of each 50vh, this returns true
|
|
25
|
+
* if an element is in the first zone (ie, appear in viewport, near the top)
|
|
26
|
+
*/
|
|
27
|
+
function isInViewportTopHalf(boundingRect) {
|
|
28
|
+
return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
|
|
29
|
+
}
|
|
30
|
+
function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
|
|
31
|
+
const selectors = [];
|
|
32
|
+
for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
|
|
33
|
+
selectors.push(`h${i}.anchor`);
|
|
34
|
+
}
|
|
35
|
+
return Array.from(document.querySelectorAll(selectors.join()));
|
|
36
|
+
}
|
|
37
|
+
function getActiveAnchor(anchors, { anchorTopOffset, }) {
|
|
38
|
+
// Naming is hard: The "nextVisibleAnchor" is the first anchor that appear
|
|
39
|
+
// under the viewport top boundary. It does not mean this anchor is visible
|
|
40
|
+
// yet, but if user continues scrolling down, it will be the first to become
|
|
41
|
+
// visible
|
|
42
|
+
const nextVisibleAnchor = anchors.find((anchor) => {
|
|
43
|
+
const boundingRect = getVisibleBoundingClientRect(anchor);
|
|
44
|
+
return boundingRect.top >= anchorTopOffset;
|
|
45
|
+
});
|
|
46
|
+
if (nextVisibleAnchor) {
|
|
47
|
+
const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
|
|
48
|
+
// If anchor is in the top half of the viewport: it is the one we consider
|
|
49
|
+
// "active" (unless it's too close to the top and and soon to be scrolled
|
|
50
|
+
// outside viewport)
|
|
51
|
+
if (isInViewportTopHalf(boundingRect)) {
|
|
52
|
+
return nextVisibleAnchor;
|
|
53
|
+
}
|
|
54
|
+
// If anchor is in the bottom half of the viewport, or under the viewport,
|
|
55
|
+
// we consider the active anchor is the previous one. This is because the
|
|
56
|
+
// main text appearing in the user screen mostly belong to the previous
|
|
57
|
+
// anchor. Returns null for the first anchor, see
|
|
58
|
+
// https://github.com/facebook/docusaurus/issues/5318
|
|
59
|
+
return anchors[anchors.indexOf(nextVisibleAnchor) - 1] ?? null;
|
|
60
|
+
}
|
|
61
|
+
// no anchor under viewport top? (ie we are at the bottom of the page)
|
|
62
|
+
// => highlight the last anchor found
|
|
63
|
+
return anchors[anchors.length - 1];
|
|
64
|
+
}
|
|
65
|
+
function getLinkAnchorValue(link) {
|
|
66
|
+
return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
|
|
67
|
+
}
|
|
68
|
+
function getLinks(linkClassName) {
|
|
69
|
+
return Array.from(document.getElementsByClassName(linkClassName));
|
|
70
|
+
}
|
|
71
|
+
function getNavbarHeight() {
|
|
72
|
+
// Not ideal to obtain actual height this way
|
|
73
|
+
// Using TS ! (not ?) because otherwise a bad selector would be un-noticed
|
|
74
|
+
return document.querySelector('.navbar').clientHeight;
|
|
75
|
+
}
|
|
76
|
+
function useAnchorTopOffsetRef() {
|
|
77
|
+
const anchorTopOffsetRef = useRef(0);
|
|
78
|
+
const { navbar: { hideOnScroll }, } = useThemeConfig();
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
anchorTopOffsetRef.current = hideOnScroll ? 0 : getNavbarHeight();
|
|
81
|
+
}, [hideOnScroll]);
|
|
82
|
+
return anchorTopOffsetRef;
|
|
83
|
+
}
|
|
84
|
+
export default function useTOCHighlight(config) {
|
|
85
|
+
const lastActiveLinkRef = useRef(undefined);
|
|
86
|
+
const anchorTopOffsetRef = useAnchorTopOffsetRef();
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!config) {
|
|
89
|
+
// no-op, highlighting is disabled
|
|
90
|
+
return () => { };
|
|
91
|
+
}
|
|
92
|
+
const { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, } = config;
|
|
93
|
+
function updateLinkActiveClass(link, active) {
|
|
94
|
+
if (active) {
|
|
95
|
+
if (lastActiveLinkRef.current && lastActiveLinkRef.current !== link) {
|
|
96
|
+
lastActiveLinkRef.current?.classList.remove(linkActiveClassName);
|
|
97
|
+
}
|
|
98
|
+
link.classList.add(linkActiveClassName);
|
|
99
|
+
lastActiveLinkRef.current = link;
|
|
100
|
+
// link.scrollIntoView({block: 'nearest'});
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
link.classList.remove(linkActiveClassName);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function updateActiveLink() {
|
|
107
|
+
const links = getLinks(linkClassName);
|
|
108
|
+
const anchors = getAnchors({ minHeadingLevel, maxHeadingLevel });
|
|
109
|
+
const activeAnchor = getActiveAnchor(anchors, {
|
|
110
|
+
anchorTopOffset: anchorTopOffsetRef.current,
|
|
111
|
+
});
|
|
112
|
+
const activeLink = links.find((link) => activeAnchor && activeAnchor.id === getLinkAnchorValue(link));
|
|
113
|
+
links.forEach((link) => {
|
|
114
|
+
updateLinkActiveClass(link, link === activeLink);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
document.addEventListener('scroll', updateActiveLink);
|
|
118
|
+
document.addEventListener('resize', updateActiveLink);
|
|
119
|
+
updateActiveLink();
|
|
120
|
+
return () => {
|
|
121
|
+
document.removeEventListener('scroll', updateActiveLink);
|
|
122
|
+
document.removeEventListener('resize', updateActiveLink);
|
|
123
|
+
};
|
|
124
|
+
}, [config, anchorTopOffsetRef]);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=useTOCHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;GAGG;AAEH,+EAA+E;AAC/E,0DAA0D;AAC1D,SAAS,4BAA4B,CAAC,OAAoB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,4BAA4B,CAAC,OAAO,CAAC,UAAyB,CAAC,CAAC;KACxE;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,YAAqB;IAChD,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,EA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E,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { PrismTheme } from 'prism-react-renderer';
|
|
8
|
+
import type { DeepPartial } from 'utility-types';
|
|
3
9
|
export declare type DocsVersionPersistence = 'localStorage' | 'none';
|
|
4
10
|
export declare type NavbarItem = {
|
|
5
11
|
type?: string | undefined;
|
|
6
12
|
items?: NavbarItem[];
|
|
7
13
|
label?: string;
|
|
8
14
|
position?: 'left' | 'right';
|
|
9
|
-
}
|
|
15
|
+
} & Record<string, unknown>;
|
|
10
16
|
export declare type NavbarLogo = {
|
|
11
17
|
src: string;
|
|
12
18
|
srcDark?: string;
|
|
19
|
+
width?: string | number;
|
|
20
|
+
height?: string | number;
|
|
13
21
|
href?: string;
|
|
14
22
|
target?: string;
|
|
15
23
|
alt?: string;
|
|
@@ -25,12 +33,6 @@ export declare type ColorModeConfig = {
|
|
|
25
33
|
defaultMode: 'light' | 'dark';
|
|
26
34
|
disableSwitch: boolean;
|
|
27
35
|
respectPrefersColorScheme: boolean;
|
|
28
|
-
switchConfig: {
|
|
29
|
-
darkIcon: string;
|
|
30
|
-
darkIconStyle: CSSProperties;
|
|
31
|
-
lightIcon: string;
|
|
32
|
-
lightIconStyle: CSSProperties;
|
|
33
|
-
};
|
|
34
36
|
};
|
|
35
37
|
export declare type AnnouncementBarConfig = {
|
|
36
38
|
id: string;
|
|
@@ -52,20 +54,31 @@ export declare type FooterLinkItem = {
|
|
|
52
54
|
html?: string;
|
|
53
55
|
prependBaseUrlToHref?: string;
|
|
54
56
|
};
|
|
55
|
-
export declare type
|
|
56
|
-
title?: string;
|
|
57
|
-
items: FooterLinkItem[];
|
|
58
|
-
};
|
|
59
|
-
export declare type Footer = {
|
|
57
|
+
export declare type FooterBase = {
|
|
60
58
|
style: 'light' | 'dark';
|
|
61
59
|
logo?: {
|
|
62
60
|
alt?: string;
|
|
63
61
|
src?: string;
|
|
64
62
|
srcDark?: string;
|
|
63
|
+
width?: string | number;
|
|
64
|
+
height?: string | number;
|
|
65
65
|
href?: string;
|
|
66
66
|
};
|
|
67
67
|
copyright?: string;
|
|
68
|
-
|
|
68
|
+
};
|
|
69
|
+
export declare type MultiColumnFooter = FooterBase & {
|
|
70
|
+
links: Array<{
|
|
71
|
+
title: string | null;
|
|
72
|
+
items: FooterLinkItem[];
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
export declare type SimpleFooter = FooterBase & {
|
|
76
|
+
links: FooterLinkItem[];
|
|
77
|
+
};
|
|
78
|
+
export declare type Footer = MultiColumnFooter | SimpleFooter;
|
|
79
|
+
export declare type TableOfContents = {
|
|
80
|
+
minHeadingLevel: number;
|
|
81
|
+
maxHeadingLevel: number;
|
|
69
82
|
};
|
|
70
83
|
export declare type ThemeConfig = {
|
|
71
84
|
docs: {
|
|
@@ -77,7 +90,12 @@ export declare type ThemeConfig = {
|
|
|
77
90
|
prism: PrismConfig;
|
|
78
91
|
footer?: Footer;
|
|
79
92
|
hideableSidebar: boolean;
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
autoCollapseSidebarCategories: boolean;
|
|
94
|
+
image?: string;
|
|
95
|
+
metadata: Array<Record<string, string>>;
|
|
96
|
+
sidebarCollapsible: boolean;
|
|
97
|
+
tableOfContents: TableOfContents;
|
|
82
98
|
};
|
|
99
|
+
export declare type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
83
100
|
export declare function useThemeConfig(): ThemeConfig;
|
|
101
|
+
//# sourceMappingURL=useThemeConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources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,GAAG;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAGF,oBAAY,WAAW,GAAG;IACxB,IAAI,EAAE;QACJ,kBAAkB,EAAE,sBAAsB,CAAC;KAC5C,CAAC;IAOF,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;IAC3B,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;IACzB,6BAA6B,EAAE,OAAO,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAGF,oBAAY,eAAe,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;AAEvD,wBAAgB,cAAc,IAAI,WAAW,CAE5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useThemeConfig.js","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAwHpE,MAAM,UAAU,cAAc;IAC5B,OAAO,oBAAoB,EAAE,CAAC,UAAU,CAAC,WAA0B,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.17",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"watch": "tsc --watch"
|
|
8
|
+
"build": "node copyUntypedFiles.mjs && tsc",
|
|
9
|
+
"watch": "node copyUntypedFiles.mjs && tsc --watch"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
@@ -18,23 +18,29 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"@docusaurus/plugin-content-blog": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/plugin-content-docs": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/plugin-content-pages": "2.0.0-beta.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
21
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.17",
|
|
22
|
+
"@docusaurus/plugin-content-blog": "2.0.0-beta.17",
|
|
23
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.17",
|
|
24
|
+
"@docusaurus/plugin-content-pages": "2.0.0-beta.17",
|
|
25
|
+
"clsx": "^1.1.1",
|
|
26
|
+
"parse-numeric-range": "^1.3.0",
|
|
27
|
+
"prism-react-renderer": "^1.3.1",
|
|
28
|
+
"tslib": "^2.3.1",
|
|
29
|
+
"utility-types": "^3.10.0"
|
|
27
30
|
},
|
|
28
31
|
"devDependencies": {
|
|
29
|
-
"@docusaurus/
|
|
32
|
+
"@docusaurus/core": "2.0.0-beta.17",
|
|
33
|
+
"@docusaurus/types": "2.0.0-beta.17",
|
|
34
|
+
"@testing-library/react-hooks": "^7.0.2",
|
|
35
|
+
"fs-extra": "^10.0.1",
|
|
36
|
+
"lodash": "^4.17.21"
|
|
30
37
|
},
|
|
31
38
|
"peerDependencies": {
|
|
32
|
-
"prism-react-renderer": "^1.2.1",
|
|
33
39
|
"react": "^16.8.4 || ^17.0.0",
|
|
34
40
|
"react-dom": "^16.8.4 || ^17.0.0"
|
|
35
41
|
},
|
|
36
42
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
43
|
+
"node": ">=14"
|
|
38
44
|
},
|
|
39
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
|
|
40
46
|
}
|
|
@@ -0,0 +1,247 @@
|
|
|
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 ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
|
+
import React, {
|
|
10
|
+
useState,
|
|
11
|
+
useEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useCallback,
|
|
14
|
+
type RefObject,
|
|
15
|
+
type Dispatch,
|
|
16
|
+
type SetStateAction,
|
|
17
|
+
type ReactNode,
|
|
18
|
+
useLayoutEffect,
|
|
19
|
+
} from 'react';
|
|
20
|
+
|
|
21
|
+
const DefaultAnimationEasing = 'ease-in-out';
|
|
22
|
+
|
|
23
|
+
export type UseCollapsibleConfig = {
|
|
24
|
+
initialState: boolean | (() => boolean);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type UseCollapsibleReturns = {
|
|
28
|
+
collapsed: boolean;
|
|
29
|
+
setCollapsed: Dispatch<SetStateAction<boolean>>;
|
|
30
|
+
toggleCollapsed: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// This hook just define the state
|
|
34
|
+
export function useCollapsible({
|
|
35
|
+
initialState,
|
|
36
|
+
}: UseCollapsibleConfig): UseCollapsibleReturns {
|
|
37
|
+
const [collapsed, setCollapsed] = useState(initialState ?? false);
|
|
38
|
+
|
|
39
|
+
const toggleCollapsed = useCallback(() => {
|
|
40
|
+
setCollapsed((expanded) => !expanded);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
collapsed,
|
|
45
|
+
setCollapsed,
|
|
46
|
+
toggleCollapsed,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CollapsedStyles = {
|
|
51
|
+
display: 'none',
|
|
52
|
+
overflow: 'hidden',
|
|
53
|
+
height: '0px',
|
|
54
|
+
} as const;
|
|
55
|
+
|
|
56
|
+
const ExpandedStyles = {
|
|
57
|
+
display: 'block',
|
|
58
|
+
overflow: 'visible',
|
|
59
|
+
height: 'auto',
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
function applyCollapsedStyle(el: HTMLElement, collapsed: boolean) {
|
|
63
|
+
const collapsedStyles = collapsed ? CollapsedStyles : ExpandedStyles;
|
|
64
|
+
el.style.display = collapsedStyles.display;
|
|
65
|
+
el.style.overflow = collapsedStyles.overflow;
|
|
66
|
+
el.style.height = collapsedStyles.height;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
Lex111: Dynamic transition duration is used in Material design, this technique
|
|
71
|
+
is good for a large number of items.
|
|
72
|
+
https://material.io/archive/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
|
|
73
|
+
https://github.com/mui-org/material-ui/blob/e724d98eba018e55e1a684236a2037e24bcf050c/packages/material-ui/src/styles/createTransitions.js#L40-L43
|
|
74
|
+
*/
|
|
75
|
+
function getAutoHeightDuration(height: number) {
|
|
76
|
+
const constant = height / 36;
|
|
77
|
+
return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type CollapsibleAnimationConfig = {
|
|
81
|
+
duration?: number;
|
|
82
|
+
easing?: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
function useCollapseAnimation({
|
|
86
|
+
collapsibleRef,
|
|
87
|
+
collapsed,
|
|
88
|
+
animation,
|
|
89
|
+
}: {
|
|
90
|
+
collapsibleRef: RefObject<HTMLElement>;
|
|
91
|
+
collapsed: boolean;
|
|
92
|
+
animation?: CollapsibleAnimationConfig;
|
|
93
|
+
}) {
|
|
94
|
+
const mounted = useRef(false);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const el = collapsibleRef.current!;
|
|
98
|
+
|
|
99
|
+
function getTransitionStyles() {
|
|
100
|
+
const height = el.scrollHeight;
|
|
101
|
+
const duration = animation?.duration ?? getAutoHeightDuration(height);
|
|
102
|
+
const easing = animation?.easing ?? DefaultAnimationEasing;
|
|
103
|
+
return {
|
|
104
|
+
transition: `height ${duration}ms ${easing}`,
|
|
105
|
+
height: `${height}px`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function applyTransitionStyles() {
|
|
110
|
+
const transitionStyles = getTransitionStyles();
|
|
111
|
+
el.style.transition = transitionStyles.transition;
|
|
112
|
+
el.style.height = transitionStyles.height;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// On mount, we just apply styles, no animated transition
|
|
116
|
+
if (!mounted.current) {
|
|
117
|
+
applyCollapsedStyle(el, collapsed);
|
|
118
|
+
mounted.current = true;
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
el.style.willChange = 'height';
|
|
123
|
+
|
|
124
|
+
function startAnimation() {
|
|
125
|
+
const animationFrame = requestAnimationFrame(() => {
|
|
126
|
+
// When collapsing
|
|
127
|
+
if (collapsed) {
|
|
128
|
+
applyTransitionStyles();
|
|
129
|
+
|
|
130
|
+
requestAnimationFrame(() => {
|
|
131
|
+
el.style.height = CollapsedStyles.height;
|
|
132
|
+
el.style.overflow = CollapsedStyles.overflow;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// When expanding
|
|
136
|
+
else {
|
|
137
|
+
el.style.display = 'block';
|
|
138
|
+
requestAnimationFrame(() => {
|
|
139
|
+
applyTransitionStyles();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return () => cancelAnimationFrame(animationFrame);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return startAnimation();
|
|
148
|
+
}, [collapsibleRef, collapsed, animation]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type CollapsibleElementType = React.ElementType<
|
|
152
|
+
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
|
|
153
|
+
>;
|
|
154
|
+
|
|
155
|
+
// Prevent hydration layout shift before animations are handled imperatively
|
|
156
|
+
// with JS
|
|
157
|
+
function getSSRStyle(collapsed: boolean) {
|
|
158
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
return collapsed ? CollapsedStyles : ExpandedStyles;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
type CollapsibleBaseProps = {
|
|
165
|
+
as?: CollapsibleElementType;
|
|
166
|
+
collapsed: boolean;
|
|
167
|
+
children: ReactNode;
|
|
168
|
+
animation?: CollapsibleAnimationConfig;
|
|
169
|
+
onCollapseTransitionEnd?: (collapsed: boolean) => void;
|
|
170
|
+
className?: string;
|
|
171
|
+
|
|
172
|
+
// This is mostly useful for details/summary component where ssrStyle is not
|
|
173
|
+
// needed (as details are hidden natively) and can mess up with the default
|
|
174
|
+
// native behavior of the browser when JS fails to load or is disabled
|
|
175
|
+
disableSSRStyle?: boolean;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function CollapsibleBase({
|
|
179
|
+
as: As = 'div',
|
|
180
|
+
collapsed,
|
|
181
|
+
children,
|
|
182
|
+
animation,
|
|
183
|
+
onCollapseTransitionEnd,
|
|
184
|
+
className,
|
|
185
|
+
disableSSRStyle,
|
|
186
|
+
}: CollapsibleBaseProps) {
|
|
187
|
+
// any because TS is a pain for HTML element refs, see https://twitter.com/sebastienlorber/status/1412784677795110914
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
|
+
const collapsibleRef = useRef<any>(null);
|
|
190
|
+
|
|
191
|
+
useCollapseAnimation({collapsibleRef, collapsed, animation});
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<As
|
|
195
|
+
// @ts-expect-error: the "too complicated type" is produced from
|
|
196
|
+
// "CollapsibleElementType" being a huge union
|
|
197
|
+
ref={collapsibleRef}
|
|
198
|
+
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
|
199
|
+
onTransitionEnd={(e: React.TransitionEvent) => {
|
|
200
|
+
if (e.propertyName !== 'height') {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
applyCollapsedStyle(collapsibleRef.current!, collapsed);
|
|
205
|
+
onCollapseTransitionEnd?.(collapsed);
|
|
206
|
+
}}
|
|
207
|
+
className={className}>
|
|
208
|
+
{children}
|
|
209
|
+
</As>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
214
|
+
const [mounted, setMounted] = useState(!collapsed);
|
|
215
|
+
|
|
216
|
+
useLayoutEffect(() => {
|
|
217
|
+
if (!collapsed) {
|
|
218
|
+
setMounted(true);
|
|
219
|
+
}
|
|
220
|
+
}, [collapsed]);
|
|
221
|
+
|
|
222
|
+
// lazyCollapsed updated in effect so that first expansion transition can work
|
|
223
|
+
const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
|
|
224
|
+
useLayoutEffect(() => {
|
|
225
|
+
if (mounted) {
|
|
226
|
+
setLazyCollapsed(collapsed);
|
|
227
|
+
}
|
|
228
|
+
}, [mounted, collapsed]);
|
|
229
|
+
|
|
230
|
+
return mounted ? (
|
|
231
|
+
<CollapsibleBase {...props} collapsed={lazyCollapsed} />
|
|
232
|
+
) : null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
type CollapsibleProps = CollapsibleBaseProps & {
|
|
236
|
+
// Lazy allows to delay the rendering when collapsed => it will render
|
|
237
|
+
// children only after hydration, on first expansion
|
|
238
|
+
// Required prop: it forces to think if content should be server-rendered
|
|
239
|
+
// or not! This has perf impact on the SSR output and html file sizes
|
|
240
|
+
// See https://github.com/facebook/docusaurus/issues/4753
|
|
241
|
+
lazy: boolean;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
|
|
245
|
+
const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
|
|
246
|
+
return <Comp {...props} />;
|
|
247
|
+
}
|