@docusaurus/theme-common 2.1.0 → 2.3.0

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 (54) hide show
  1. package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
  2. package/lib/hooks/useHideableNavbar.js +6 -1
  3. package/lib/hooks/useHideableNavbar.js.map +1 -1
  4. package/lib/hooks/useSearchPage.d.ts.map +1 -1
  5. package/lib/hooks/useSearchPage.js +4 -2
  6. package/lib/hooks/useSearchPage.js.map +1 -1
  7. package/lib/index.d.ts +3 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.js +3 -1
  10. package/lib/index.js.map +1 -1
  11. package/lib/internal.d.ts +3 -3
  12. package/lib/internal.d.ts.map +1 -1
  13. package/lib/internal.js +2 -3
  14. package/lib/internal.js.map +1 -1
  15. package/lib/utils/admonitionUtils.d.ts +12 -0
  16. package/lib/utils/admonitionUtils.d.ts.map +1 -0
  17. package/lib/utils/admonitionUtils.js +33 -0
  18. package/lib/utils/admonitionUtils.js.map +1 -0
  19. package/lib/utils/historyUtils.d.ts +12 -1
  20. package/lib/utils/historyUtils.d.ts.map +1 -1
  21. package/lib/utils/historyUtils.js +23 -0
  22. package/lib/utils/historyUtils.js.map +1 -1
  23. package/lib/utils/skipToContentUtils.d.ts +17 -0
  24. package/lib/utils/skipToContentUtils.d.ts.map +1 -0
  25. package/lib/utils/skipToContentUtils.js +71 -0
  26. package/lib/utils/skipToContentUtils.js.map +1 -0
  27. package/lib/utils/storageUtils.d.ts +4 -0
  28. package/lib/utils/storageUtils.d.ts.map +1 -1
  29. package/lib/utils/storageUtils.js +70 -7
  30. package/lib/utils/storageUtils.js.map +1 -1
  31. package/lib/utils/tabsUtils.d.ts +46 -0
  32. package/lib/utils/tabsUtils.d.ts.map +1 -0
  33. package/lib/utils/tabsUtils.js +151 -0
  34. package/lib/utils/tabsUtils.js.map +1 -0
  35. package/package.json +11 -10
  36. package/src/hooks/useHideableNavbar.ts +7 -1
  37. package/src/hooks/useSearchPage.ts +10 -5
  38. package/src/index.ts +12 -1
  39. package/src/internal.ts +7 -6
  40. package/src/utils/admonitionUtils.tsx +43 -0
  41. package/src/utils/historyUtils.ts +29 -1
  42. package/src/utils/skipToContentUtils.tsx +103 -0
  43. package/src/utils/storageUtils.ts +108 -7
  44. package/src/utils/tabsUtils.tsx +266 -0
  45. package/lib/contexts/tabGroupChoice.d.ts +0 -21
  46. package/lib/contexts/tabGroupChoice.d.ts.map +0 -1
  47. package/lib/contexts/tabGroupChoice.js +0 -49
  48. package/lib/contexts/tabGroupChoice.js.map +0 -1
  49. package/lib/hooks/useSkipToContent.d.ts +0 -25
  50. package/lib/hooks/useSkipToContent.d.ts.map +0 -1
  51. package/lib/hooks/useSkipToContent.js +0 -35
  52. package/lib/hooks/useSkipToContent.js.map +0 -1
  53. package/src/contexts/tabGroupChoice.tsx +0 -85
  54. package/src/hooks/useSkipToContent.ts +0 -58
@@ -1,58 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import type React from 'react';
9
- import {useCallback, useRef} from 'react';
10
- import {useHistory} from '@docusaurus/router';
11
- import {useLocationChange} from '../utils/useLocationChange';
12
- import {ThemeClassNames} from '../utils/ThemeClassNames';
13
-
14
- function programmaticFocus(el: HTMLElement) {
15
- el.setAttribute('tabindex', '-1');
16
- el.focus();
17
- el.removeAttribute('tabindex');
18
- }
19
-
20
- /** This hook wires the logic for a skip-to-content link. */
21
- export function useSkipToContent(): {
22
- /**
23
- * The ref to the container. On page transition, the container will be focused
24
- * so that keyboard navigators can instantly interact with the link and jump
25
- * to content. **Note:** the type is `RefObject<HTMLDivElement>` only because
26
- * the typing for refs don't reflect that the `ref` prop is contravariant, so
27
- * using `HTMLElement` causes type-checking to fail. You can plug the ref into
28
- * any HTML element, as long as it can be focused.
29
- */
30
- containerRef: React.RefObject<HTMLDivElement>;
31
- /**
32
- * Callback fired when the skip to content link has been interacted with. It
33
- * will programmatically focus the main content.
34
- */
35
- handleSkip: (e: React.MouseEvent<HTMLAnchorElement>) => void;
36
- } {
37
- const containerRef = useRef<HTMLDivElement>(null);
38
- const {action} = useHistory();
39
- const handleSkip = useCallback((e: React.MouseEvent<HTMLAnchorElement>) => {
40
- e.preventDefault();
41
-
42
- const targetElement: HTMLElement | null =
43
- document.querySelector('main:first-of-type') ??
44
- document.querySelector(`.${ThemeClassNames.wrapper.main}`);
45
-
46
- if (targetElement) {
47
- programmaticFocus(targetElement);
48
- }
49
- }, []);
50
-
51
- useLocationChange(({location}) => {
52
- if (containerRef.current && !location.hash && action === 'PUSH') {
53
- programmaticFocus(containerRef.current);
54
- }
55
- });
56
-
57
- return {containerRef, handleSkip};
58
- }