@docusaurus/theme-common 2.0.0-beta.12faed89d → 2.0.0-beta.14

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 (156) hide show
  1. package/lib/{utils/useCollapsible.d.ts → components/Collapsible/index.d.ts} +10 -3
  2. package/lib/components/Collapsible/index.d.ts.map +1 -0
  3. package/lib/{utils/useCollapsible.js → components/Collapsible/index.js} +37 -14
  4. package/lib/components/Collapsible/index.js.map +1 -0
  5. package/lib/components/Details/index.d.ts +13 -0
  6. package/lib/components/Details/index.d.ts.map +1 -0
  7. package/lib/components/Details/index.js +65 -0
  8. package/lib/components/Details/index.js.map +1 -0
  9. package/lib/components/Details/styles.module.css +58 -0
  10. package/lib/index.d.ts +20 -5
  11. package/lib/index.d.ts.map +1 -0
  12. package/lib/index.js +15 -3
  13. package/lib/index.js.map +1 -0
  14. package/lib/utils/ThemeClassNames.d.ts +38 -12
  15. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  16. package/lib/utils/ThemeClassNames.js +38 -3
  17. package/lib/utils/ThemeClassNames.js.map +1 -0
  18. package/lib/utils/announcementBarUtils.d.ts +4 -3
  19. package/lib/utils/announcementBarUtils.d.ts.map +1 -0
  20. package/lib/utils/announcementBarUtils.js +15 -18
  21. package/lib/utils/announcementBarUtils.js.map +1 -0
  22. package/lib/utils/codeBlockUtils.d.ts +11 -0
  23. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  24. package/lib/utils/codeBlockUtils.js +120 -0
  25. package/lib/utils/codeBlockUtils.js.map +1 -0
  26. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +3 -2
  27. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -0
  28. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +3 -2
  29. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -0
  30. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +1 -0
  31. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -0
  32. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +2 -3
  33. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +1 -0
  34. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +12 -3
  35. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -0
  36. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +2 -2
  37. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -0
  38. package/lib/utils/docsUtils.d.ts +21 -0
  39. package/lib/utils/docsUtils.d.ts.map +1 -0
  40. package/lib/utils/docsUtils.js +107 -0
  41. package/lib/utils/docsUtils.js.map +1 -0
  42. package/lib/utils/generalUtils.d.ts +7 -0
  43. package/lib/utils/generalUtils.d.ts.map +1 -0
  44. package/lib/utils/generalUtils.js +3 -2
  45. package/lib/utils/generalUtils.js.map +1 -0
  46. package/lib/utils/historyUtils.d.ts +12 -0
  47. package/lib/utils/historyUtils.d.ts.map +1 -0
  48. package/lib/utils/historyUtils.js +40 -0
  49. package/lib/utils/historyUtils.js.map +1 -0
  50. package/lib/utils/jsUtils.d.ts +20 -0
  51. package/lib/utils/jsUtils.d.ts.map +1 -0
  52. package/lib/utils/jsUtils.js +26 -0
  53. package/lib/utils/jsUtils.js.map +1 -0
  54. package/lib/utils/mobileSecondaryMenu.d.ts +3 -2
  55. package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -0
  56. package/lib/utils/mobileSecondaryMenu.js +4 -4
  57. package/lib/utils/mobileSecondaryMenu.js.map +1 -0
  58. package/lib/utils/pathUtils.d.ts +1 -0
  59. package/lib/utils/pathUtils.d.ts.map +1 -0
  60. package/lib/utils/pathUtils.js +2 -3
  61. package/lib/utils/pathUtils.js.map +1 -0
  62. package/lib/utils/reactUtils.d.ts +10 -0
  63. package/lib/utils/reactUtils.d.ts.map +1 -0
  64. package/lib/utils/reactUtils.js +27 -0
  65. package/lib/utils/reactUtils.js.map +1 -0
  66. package/lib/utils/regexpUtils.d.ts +11 -0
  67. package/lib/utils/regexpUtils.d.ts.map +1 -0
  68. package/lib/utils/regexpUtils.js +17 -0
  69. package/lib/utils/regexpUtils.js.map +1 -0
  70. package/lib/utils/scrollUtils.d.ts +53 -0
  71. package/lib/utils/scrollUtils.d.ts.map +1 -0
  72. package/lib/utils/scrollUtils.js +136 -0
  73. package/lib/utils/scrollUtils.js.map +1 -0
  74. package/lib/utils/searchUtils.d.ts +1 -0
  75. package/lib/utils/searchUtils.d.ts.map +1 -0
  76. package/lib/utils/searchUtils.js +1 -0
  77. package/lib/utils/searchUtils.js.map +1 -0
  78. package/lib/utils/storageUtils.d.ts +5 -0
  79. package/lib/utils/storageUtils.d.ts.map +1 -0
  80. package/lib/utils/storageUtils.js +30 -3
  81. package/lib/utils/storageUtils.js.map +1 -0
  82. package/lib/utils/tagsUtils.d.ts +19 -0
  83. package/lib/utils/tagsUtils.d.ts.map +1 -0
  84. package/lib/utils/tagsUtils.js +34 -0
  85. package/lib/utils/tagsUtils.js.map +1 -0
  86. package/lib/utils/tocUtils.d.ts +16 -0
  87. package/lib/utils/tocUtils.d.ts.map +1 -0
  88. package/lib/utils/tocUtils.js +35 -0
  89. package/lib/utils/tocUtils.js.map +1 -0
  90. package/lib/utils/useAlternatePageUtils.d.ts +1 -0
  91. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  92. package/lib/utils/useAlternatePageUtils.js +1 -0
  93. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  94. package/lib/utils/useContextualSearchFilters.d.ts +12 -0
  95. package/lib/utils/useContextualSearchFilters.d.ts.map +1 -0
  96. package/lib/utils/useContextualSearchFilters.js +37 -0
  97. package/lib/utils/useContextualSearchFilters.js.map +1 -0
  98. package/{src/utils/docsUtils.ts → lib/utils/useLocalPathname.d.ts} +2 -5
  99. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  100. package/lib/utils/useLocalPathname.js +17 -0
  101. package/lib/utils/useLocalPathname.js.map +1 -0
  102. package/lib/utils/useLocationChange.d.ts +1 -0
  103. package/lib/utils/useLocationChange.d.ts.map +1 -0
  104. package/lib/utils/useLocationChange.js +10 -11
  105. package/lib/utils/useLocationChange.js.map +1 -0
  106. package/lib/utils/usePluralForm.d.ts +1 -0
  107. package/lib/utils/usePluralForm.d.ts.map +1 -0
  108. package/lib/utils/usePluralForm.js +2 -3
  109. package/lib/utils/usePluralForm.js.map +1 -0
  110. package/lib/utils/usePrevious.d.ts +1 -0
  111. package/lib/utils/usePrevious.d.ts.map +1 -0
  112. package/lib/utils/usePrevious.js +4 -2
  113. package/lib/utils/usePrevious.js.map +1 -0
  114. package/lib/utils/useTOCHighlight.d.ts +15 -0
  115. package/lib/utils/useTOCHighlight.d.ts.map +1 -0
  116. package/lib/utils/useTOCHighlight.js +125 -0
  117. package/lib/utils/useTOCHighlight.js.map +1 -0
  118. package/lib/utils/useThemeConfig.d.ts +32 -9
  119. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  120. package/lib/utils/useThemeConfig.js +1 -0
  121. package/lib/utils/useThemeConfig.js.map +1 -0
  122. package/package.json +18 -12
  123. package/src/{utils/useCollapsible.tsx → components/Collapsible/index.tsx} +70 -25
  124. package/src/components/Details/index.tsx +94 -0
  125. package/src/components/Details/styles.module.css +58 -0
  126. package/src/index.ts +56 -5
  127. package/src/types.d.ts +0 -2
  128. package/src/utils/ThemeClassNames.ts +43 -4
  129. package/src/utils/announcementBarUtils.tsx +20 -15
  130. package/src/utils/codeBlockUtils.ts +151 -0
  131. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +7 -6
  132. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +2 -3
  133. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +14 -14
  134. package/src/utils/docsUtils.tsx +185 -0
  135. package/src/utils/generalUtils.ts +3 -2
  136. package/src/utils/historyUtils.ts +50 -0
  137. package/src/utils/jsUtils.ts +33 -0
  138. package/src/utils/mobileSecondaryMenu.tsx +9 -6
  139. package/src/utils/pathUtils.ts +2 -3
  140. package/src/utils/reactUtils.tsx +34 -0
  141. package/src/utils/regexpUtils.ts +23 -0
  142. package/src/utils/scrollUtils.tsx +237 -0
  143. package/src/utils/storageUtils.ts +27 -4
  144. package/src/utils/tagsUtils.ts +48 -0
  145. package/src/utils/tocUtils.ts +55 -0
  146. package/src/utils/useContextualSearchFilters.ts +50 -0
  147. package/src/utils/useLocalPathname.ts +20 -0
  148. package/src/utils/useLocationChange.ts +10 -12
  149. package/src/utils/usePluralForm.ts +2 -3
  150. package/src/utils/usePrevious.ts +3 -2
  151. package/src/utils/useTOCHighlight.ts +179 -0
  152. package/src/utils/useThemeConfig.ts +34 -9
  153. package/lib/.tsbuildinfo +0 -1
  154. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  155. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  156. package/tsconfig.json +0 -10
@@ -4,8 +4,5 @@
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
-
8
- import {useAllDocsData} from '@theme/hooks/useDocs';
9
-
10
- // TODO not ideal, see also "useDocs"
11
- export const isDocsPluginEnabled: boolean = !!useAllDocsData;
7
+ export declare function useLocalPathname(): string;
8
+ //# sourceMappingURL=useLocalPathname.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalPathname.d.ts","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC"}
@@ -0,0 +1,17 @@
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8
+ import { useLocation } from '@docusaurus/router';
9
+ // Get the pathname of current route, without the optional site baseUrl
10
+ // - /docs/myDoc => /docs/myDoc
11
+ // - /baseUrl/docs/myDoc => /docs/myDoc
12
+ export function useLocalPathname() {
13
+ const { siteConfig: { baseUrl }, } = useDocusaurusContext();
14
+ const { pathname } = useLocation();
15
+ return pathname.replace(baseUrl, '/');
16
+ }
17
+ //# sourceMappingURL=useLocalPathname.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalPathname.js","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,uEAAuE;AACvE,+BAA+B;AAC/B,uCAAuC;AACvC,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAC,GACtB,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IACjC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC"}
@@ -12,3 +12,4 @@ declare type LocationChangeEvent = {
12
12
  declare type OnLocationChange = (locationChangeEvent: LocationChangeEvent) => void;
13
13
  export declare function useLocationChange(onLocationChange: OnLocationChange): void;
14
14
  export {};
15
+ //# sourceMappingURL=useLocationChange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocationChange.d.ts","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAI7C,aAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,aAAK,gBAAgB,GAAG,CAAC,mBAAmB,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAc1E"}
@@ -4,22 +4,21 @@
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 { useEffect, useRef } from 'react';
7
+ import { useEffect } from 'react';
8
8
  import { useLocation } from '@docusaurus/router';
9
9
  import { usePrevious } from './usePrevious';
10
+ import { useDynamicCallback } from './reactUtils';
10
11
  export function useLocationChange(onLocationChange) {
11
12
  const location = useLocation();
12
13
  const previousLocation = usePrevious(location);
13
- const isFirst = useRef(true);
14
+ const onLocationChangeDynamic = useDynamicCallback(onLocationChange);
14
15
  useEffect(() => {
15
- // Prevent first effect to trigger the listener on mount
16
- if (isFirst.current) {
17
- isFirst.current = false;
18
- return;
16
+ if (location !== previousLocation) {
17
+ onLocationChangeDynamic({
18
+ location,
19
+ previousLocation,
20
+ });
19
21
  }
20
- onLocationChange({
21
- location,
22
- previousLocation,
23
- });
24
- }, [location]);
22
+ }, [onLocationChangeDynamic, location, previousLocation]);
25
23
  }
24
+ //# sourceMappingURL=useLocationChange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocationChange.js","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAShD,MAAM,UAAU,iBAAiB,CAAC,gBAAkC;IAClE,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,KAAK,gBAAgB,EAAE;YACjC,uBAAuB,CAAC;gBACtB,QAAQ;gBACR,gBAAgB;aACjB,CAAC,CAAC;SACJ;IACH,CAAC,EAAE,CAAC,uBAAuB,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -7,3 +7,4 @@
7
7
  export declare function usePluralForm(): {
8
8
  selectMessage: (count: number, pluralMessages: string) => string;
9
9
  };
10
+ //# sourceMappingURL=usePluralForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwGH,wBAAgB,aAAa,IAAI;IAC/B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE,CAMA"}
@@ -87,8 +87,7 @@ function selectPluralMessage(pluralMessages, count, localePluralForms) {
87
87
  export function usePluralForm() {
88
88
  const localePluralForm = useLocalePluralForms();
89
89
  return {
90
- selectMessage: (count, pluralMessages) => {
91
- return selectPluralMessage(pluralMessages, count, localePluralForm);
92
- },
90
+ selectMessage: (count, pluralMessages) => selectPluralMessage(pluralMessages, count, localePluralForm),
93
91
  };
94
92
  }
93
+ //# sourceMappingURL=usePluralForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePluralForm.js","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,6DAA6D;AAC7D,mEAAmE;AACnE,qEAAqE;AACrE,MAAM,kBAAkB,GAA0B;IAChD,MAAM;IACN,KAAK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,EAAE,KAAK,EAAE,gBAAgB,CAAC;KAC/D,CAAC;AACJ,CAAC"}
@@ -5,3 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export declare function usePrevious<T>(value: T): T | undefined;
8
+ //# sourceMappingURL=usePrevious.d.ts.map
@@ -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"}
@@ -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, useEffect } from 'react';
7
+ import { useRef } from 'react';
8
+ import { useIsomorphicLayoutEffect } from './reactUtils';
8
9
  export function usePrevious(value) {
9
10
  const ref = useRef();
10
- useEffect(() => {
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,15 @@
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
+ declare function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
14
+ export default useTOCHighlight;
15
+ //# 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;AA6GH,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,iBAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAuDrE;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,125 @@
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 parent (normally the link text) rect boundaries instead
14
+ function getVisibleBoundingClientRect(element) {
15
+ const rect = element.getBoundingClientRect();
16
+ const hasNoHeight = rect.top === rect.bottom;
17
+ if (hasNoHeight) {
18
+ return getVisibleBoundingClientRect(element.parentNode);
19
+ }
20
+ return rect;
21
+ }
22
+ // Considering we divide viewport into 2 zones of each 50vh
23
+ // This returns true if an element is in the first zone (ie, appear in viewport, near the top)
24
+ function isInViewportTopHalf(boundingRect) {
25
+ return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
26
+ }
27
+ function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
28
+ const selectors = [];
29
+ for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
30
+ selectors.push(`h${i}.anchor`);
31
+ }
32
+ return Array.from(document.querySelectorAll(selectors.join()));
33
+ }
34
+ function getActiveAnchor(anchors, { anchorTopOffset, }) {
35
+ var _a;
36
+ // Naming is hard
37
+ // The "nextVisibleAnchor" is the first anchor that appear under the viewport top boundary
38
+ // Note: it does not mean this anchor is visible yet, but if user continues scrolling down, it will be the first to become visible
39
+ const nextVisibleAnchor = anchors.find((anchor) => {
40
+ const boundingRect = getVisibleBoundingClientRect(anchor);
41
+ return boundingRect.top >= anchorTopOffset;
42
+ });
43
+ if (nextVisibleAnchor) {
44
+ const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
45
+ // If anchor is in the top half of the viewport: it is the one we consider "active"
46
+ // (unless it's too close to the top and and soon to be scrolled outside viewport)
47
+ if (isInViewportTopHalf(boundingRect)) {
48
+ return nextVisibleAnchor;
49
+ }
50
+ // If anchor is in the bottom half of the viewport, or under the viewport, we consider the active anchor is the previous one
51
+ // This is because the main text appearing in the user screen mostly belong to the previous anchor
52
+ else {
53
+ // Returns null for the first anchor, see https://github.com/facebook/docusaurus/issues/5318
54
+ return (_a = anchors[anchors.indexOf(nextVisibleAnchor) - 1]) !== null && _a !== void 0 ? _a : null;
55
+ }
56
+ }
57
+ // no anchor under viewport top? (ie we are at the bottom of the page)
58
+ // => highlight the last anchor found
59
+ else {
60
+ return anchors[anchors.length - 1];
61
+ }
62
+ }
63
+ function getLinkAnchorValue(link) {
64
+ return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
65
+ }
66
+ function getLinks(linkClassName) {
67
+ return Array.from(document.getElementsByClassName(linkClassName));
68
+ }
69
+ function getNavbarHeight() {
70
+ // Not ideal to obtain actual height this way
71
+ // Using TS ! (not ?) because otherwise a bad selector would be un-noticed
72
+ return document.querySelector('.navbar').clientHeight;
73
+ }
74
+ function useAnchorTopOffsetRef() {
75
+ const anchorTopOffsetRef = useRef(0);
76
+ const { navbar: { hideOnScroll }, } = useThemeConfig();
77
+ useEffect(() => {
78
+ anchorTopOffsetRef.current = hideOnScroll ? 0 : getNavbarHeight();
79
+ }, [hideOnScroll]);
80
+ return anchorTopOffsetRef;
81
+ }
82
+ function useTOCHighlight(config) {
83
+ const lastActiveLinkRef = useRef(undefined);
84
+ const anchorTopOffsetRef = useAnchorTopOffsetRef();
85
+ useEffect(() => {
86
+ if (!config) {
87
+ // no-op, highlighting is disabled
88
+ return () => { };
89
+ }
90
+ const { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, } = config;
91
+ function updateLinkActiveClass(link, active) {
92
+ var _a;
93
+ if (active) {
94
+ if (lastActiveLinkRef.current && lastActiveLinkRef.current !== link) {
95
+ (_a = lastActiveLinkRef.current) === null || _a === void 0 ? void 0 : _a.classList.remove(linkActiveClassName);
96
+ }
97
+ link.classList.add(linkActiveClassName);
98
+ lastActiveLinkRef.current = link;
99
+ }
100
+ else {
101
+ link.classList.remove(linkActiveClassName);
102
+ }
103
+ }
104
+ function updateActiveLink() {
105
+ const links = getLinks(linkClassName);
106
+ const anchors = getAnchors({ minHeadingLevel, maxHeadingLevel });
107
+ const activeAnchor = getActiveAnchor(anchors, {
108
+ anchorTopOffset: anchorTopOffsetRef.current,
109
+ });
110
+ const activeLink = links.find((link) => activeAnchor && activeAnchor.id === getLinkAnchorValue(link));
111
+ links.forEach((link) => {
112
+ updateLinkActiveClass(link, link === activeLink);
113
+ });
114
+ }
115
+ document.addEventListener('scroll', updateActiveLink);
116
+ document.addEventListener('resize', updateActiveLink);
117
+ updateActiveLink();
118
+ return () => {
119
+ document.removeEventListener('scroll', updateActiveLink);
120
+ document.removeEventListener('resize', updateActiveLink);
121
+ };
122
+ }, [config, anchorTopOffsetRef]);
123
+ }
124
+ export default useTOCHighlight;
125
+ //# 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,uIAAuI;AACvI,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,2DAA2D;AAC3D,8FAA8F;AAC9F,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,EAClB,eAAe,EACf,eAAe,GAIhB;IACC,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,eAAe,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1D,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAChC;IAED,OAAO,KAAK,CAAC,IAAI,CACf,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAC3B,CAAC;AACrB,CAAC;AAED,SAAS,eAAe,CACtB,OAAsB,EACtB,EACE,eAAe,GAGhB;;IAED,iBAAiB;IACjB,0FAA0F;IAC1F,kIAAkI;IAClI,MA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,OAAO,EAAE;gBAC5C,eAAe,EAAE,kBAAkB,CAAC,OAAO;aAC5C,CAAC,CAAC;YACH,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAC3B,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,IAAI,YAAY,CAAC,EAAE,KAAK,kBAAkB,CAAC,IAAI,CAAC,CACvE,CAAC;YAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrB,qBAAqB,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACtD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAEtD,gBAAgB,EAAE,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,eAAe,eAAe,CAAC"}
@@ -1,15 +1,24 @@
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
+ */
1
7
  import { PrismTheme } from 'prism-react-renderer';
2
8
  import { CSSProperties } from 'react';
9
+ import { DeepPartial } from 'utility-types';
3
10
  export declare type DocsVersionPersistence = 'localStorage' | 'none';
4
11
  export declare type NavbarItem = {
5
12
  type?: string | undefined;
6
13
  items?: NavbarItem[];
7
14
  label?: string;
8
15
  position?: 'left' | 'right';
9
- };
16
+ } & Record<string, unknown>;
10
17
  export declare type NavbarLogo = {
11
18
  src: string;
12
19
  srcDark?: string;
20
+ width?: string | number;
21
+ height?: string | number;
13
22
  href?: string;
14
23
  target?: string;
15
24
  alt?: string;
@@ -52,20 +61,31 @@ export declare type FooterLinkItem = {
52
61
  html?: string;
53
62
  prependBaseUrlToHref?: string;
54
63
  };
55
- export declare type FooterLinks = {
56
- title?: string;
57
- items: FooterLinkItem[];
58
- };
59
- export declare type Footer = {
64
+ export declare type FooterBase = {
60
65
  style: 'light' | 'dark';
61
66
  logo?: {
62
67
  alt?: string;
63
68
  src?: string;
64
69
  srcDark?: string;
70
+ width?: string | number;
71
+ height?: string | number;
65
72
  href?: string;
66
73
  };
67
74
  copyright?: string;
68
- links: FooterLinks[];
75
+ };
76
+ export declare type MultiColumnFooter = FooterBase & {
77
+ links: Array<{
78
+ title: string | null;
79
+ items: FooterLinkItem[];
80
+ }>;
81
+ };
82
+ export declare type SimpleFooter = FooterBase & {
83
+ links: FooterLinkItem[];
84
+ };
85
+ export declare type Footer = MultiColumnFooter | SimpleFooter;
86
+ export declare type TableOfContents = {
87
+ minHeadingLevel: number;
88
+ maxHeadingLevel: number;
69
89
  };
70
90
  export declare type ThemeConfig = {
71
91
  docs: {
@@ -77,8 +97,11 @@ export declare type ThemeConfig = {
77
97
  prism: PrismConfig;
78
98
  footer?: Footer;
79
99
  hideableSidebar: boolean;
80
- image: string;
81
- metadatas: Array<Record<string, string>>;
100
+ image?: string;
101
+ metadata: Array<Record<string, string>>;
82
102
  sidebarCollapsible: boolean;
103
+ tableOfContents: TableOfContents;
83
104
  };
105
+ export declare type UserThemeConfig = DeepPartial<ThemeConfig>;
84
106
  export declare function useThemeConfig(): ThemeConfig;
107
+ //# sourceMappingURL=useThemeConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,E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AEF,oBAAY,MAAM,GAAG,iBAAiB,GAAG,YAAY,CAAC;AAEtD,oBAAY,eAAe,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,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"}
@@ -8,3 +8,4 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8
8
  export function useThemeConfig() {
9
9
  return useDocusaurusContext().siteConfig.themeConfig;
10
10
  }
11
+ //# sourceMappingURL=useThemeConfig.js.map
@@ -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;AA8HpE,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.12faed89d",
3
+ "version": "2.0.0-beta.14",
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.js && tsc",
9
+ "watch": "node copyUntypedFiles.js && tsc --watch"
10
10
  },
11
11
  "publishConfig": {
12
12
  "access": "public"
@@ -18,15 +18,21 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "2.0.0-beta.12faed89d",
22
- "@docusaurus/plugin-content-blog": "2.0.0-beta.12faed89d",
23
- "@docusaurus/plugin-content-docs": "2.0.0-beta.12faed89d",
24
- "@docusaurus/plugin-content-pages": "2.0.0-beta.12faed89d",
25
- "@docusaurus/types": "2.0.0-beta.12faed89d",
26
- "tslib": "^2.1.0"
21
+ "@docusaurus/plugin-content-blog": "2.0.0-beta.14",
22
+ "@docusaurus/plugin-content-docs": "2.0.0-beta.14",
23
+ "@docusaurus/plugin-content-pages": "2.0.0-beta.14",
24
+ "clsx": "^1.1.1",
25
+ "fs-extra": "^10.0.0",
26
+ "parse-numeric-range": "^1.3.0",
27
+ "tslib": "^2.3.1",
28
+ "utility-types": "^3.10.0"
27
29
  },
28
30
  "devDependencies": {
29
- "@docusaurus/module-type-aliases": "2.0.0-beta.12faed89d"
31
+ "@docusaurus/core": "2.0.0-beta.14",
32
+ "@docusaurus/module-type-aliases": "2.0.0-beta.14",
33
+ "@docusaurus/types": "2.0.0-beta.14",
34
+ "@testing-library/react-hooks": "^7.0.2",
35
+ "lodash": "^4.17.20"
30
36
  },
31
37
  "peerDependencies": {
32
38
  "prism-react-renderer": "^1.2.1",
@@ -34,7 +40,7 @@
34
40
  "react-dom": "^16.8.4 || ^17.0.0"
35
41
  },
36
42
  "engines": {
37
- "node": ">=12.13.0"
43
+ "node": ">=14"
38
44
  },
39
- "gitHead": "1430dbacfbe9da59a17ce395ed29bdbddaf90049"
45
+ "gitHead": "c4824a8937d8f1aa0806667749cbc74058e2b294"
40
46
  }
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
8
9
  import React, {
9
10
  useState,
10
11
  useEffect,
@@ -14,6 +15,7 @@ import React, {
14
15
  Dispatch,
15
16
  SetStateAction,
16
17
  ReactNode,
18
+ useLayoutEffect,
17
19
  } from 'react';
18
20
 
19
21
  const DefaultAnimationEasing = 'ease-in-out';
@@ -118,7 +120,7 @@ function useCollapseAnimation({
118
120
 
119
121
  el.style.willChange = 'height';
120
122
 
121
- function startAnimation(): () => void {
123
+ function startAnimation() {
122
124
  const animationFrame = requestAnimationFrame(() => {
123
125
  // When collapsing
124
126
  if (collapsed) {
@@ -146,52 +148,95 @@ function useCollapseAnimation({
146
148
  }
147
149
 
148
150
  type CollapsibleElementType = React.ElementType<
149
- Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd'>
151
+ Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
150
152
  >;
151
153
 
152
- export function Collapsible({
154
+ // Prevent hydration layout shift before anims are handled imperatively with JS
155
+ function getSSRStyle(collapsed: boolean) {
156
+ if (ExecutionEnvironment.canUseDOM) {
157
+ return undefined;
158
+ }
159
+ return collapsed ? CollapsedStyles : ExpandedStyles;
160
+ }
161
+
162
+ type CollapsibleBaseProps = {
163
+ as?: CollapsibleElementType;
164
+ collapsed: boolean;
165
+ children: ReactNode;
166
+ animation?: CollapsibleAnimationConfig;
167
+ onCollapseTransitionEnd?: (collapsed: boolean) => void;
168
+ className?: string;
169
+
170
+ // This is mostly useful for details/summary component where ssrStyle is not needed (as details are hidden natively)
171
+ // and can mess-up with the default native behavior of the browser when JS fails to load or is disabled
172
+ disableSSRStyle?: boolean;
173
+ };
174
+
175
+ function CollapsibleBase({
153
176
  as: As = 'div',
154
177
  collapsed,
155
178
  children,
156
179
  animation,
180
+ onCollapseTransitionEnd,
157
181
  className,
158
- }: {
159
- as?: CollapsibleElementType; // TODO better typing, allow any html element (keyof JSX.IntrinsicElement => not working)
160
- collapsed: boolean;
161
- children: ReactNode;
162
- animation?: CollapsibleAnimationConfig;
163
- className?: string;
164
- }) {
182
+ disableSSRStyle,
183
+ }: CollapsibleBaseProps) {
165
184
  // any because TS is a pain for HTML element refs, see https://twitter.com/sebastienlorber/status/1412784677795110914
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
166
186
  const collapsibleRef = useRef<any>(null);
167
187
 
168
188
  useCollapseAnimation({collapsibleRef, collapsed, animation});
169
189
 
170
190
  return (
171
191
  <As
172
- // @ts-expect-error: see https://twitter.com/sebastienlorber/status/1412784677795110914
192
+ // @ts-expect-error: the "too complicated type" is produced from "CollapsibleElementType" being a huge union
173
193
  ref={collapsibleRef}
174
- onTransitionEnd={(e) => {
194
+ style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
195
+ onTransitionEnd={(e: React.TransitionEvent) => {
175
196
  if (e.propertyName !== 'height') {
176
197
  return;
177
198
  }
178
199
 
179
- const el = collapsibleRef.current!;
180
- const currentCollapsibleElementHeight = el.style.height;
181
-
182
- if (
183
- !collapsed &&
184
- parseInt(currentCollapsibleElementHeight, 10) === el.scrollHeight
185
- ) {
186
- applyCollapsedStyle(el, false);
187
- }
188
-
189
- if (currentCollapsibleElementHeight === CollapsedStyles.height) {
190
- applyCollapsedStyle(el, true);
191
- }
200
+ applyCollapsedStyle(collapsibleRef.current!, collapsed);
201
+ onCollapseTransitionEnd?.(collapsed);
192
202
  }}
193
203
  className={className}>
194
204
  {children}
195
205
  </As>
196
206
  );
197
207
  }
208
+
209
+ function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
210
+ const [mounted, setMounted] = useState(!collapsed);
211
+
212
+ useLayoutEffect(() => {
213
+ if (!collapsed) {
214
+ setMounted(true);
215
+ }
216
+ }, [collapsed]);
217
+
218
+ // lazyCollapsed updated in effect so that the first expansion transition can work
219
+ const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
220
+ useLayoutEffect(() => {
221
+ if (mounted) {
222
+ setLazyCollapsed(collapsed);
223
+ }
224
+ }, [mounted, collapsed]);
225
+
226
+ return mounted ? (
227
+ <CollapsibleBase {...props} collapsed={lazyCollapsed} />
228
+ ) : null;
229
+ }
230
+
231
+ type CollapsibleProps = CollapsibleBaseProps & {
232
+ // Lazy allows to delay the rendering when collapsed => it will render children only after hydration, on first expansion
233
+ // Required prop: it forces to think if content should be server-rendered or not!
234
+ // This has perf impact on the SSR output and html file sizes
235
+ // See https://github.com/facebook/docusaurus/issues/4753
236
+ lazy: boolean;
237
+ };
238
+
239
+ export function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
240
+ const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
241
+ return <Comp {...props} />;
242
+ }