@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.
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +6 -1
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +4 -2
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +3 -3
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +2 -3
- package/lib/internal.js.map +1 -1
- package/lib/utils/admonitionUtils.d.ts +12 -0
- package/lib/utils/admonitionUtils.d.ts.map +1 -0
- package/lib/utils/admonitionUtils.js +33 -0
- package/lib/utils/admonitionUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +12 -1
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +23 -0
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/skipToContentUtils.d.ts +17 -0
- package/lib/utils/skipToContentUtils.d.ts.map +1 -0
- package/lib/utils/skipToContentUtils.js +71 -0
- package/lib/utils/skipToContentUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +4 -0
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +70 -7
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tabsUtils.d.ts +46 -0
- package/lib/utils/tabsUtils.d.ts.map +1 -0
- package/lib/utils/tabsUtils.js +151 -0
- package/lib/utils/tabsUtils.js.map +1 -0
- package/package.json +11 -10
- package/src/hooks/useHideableNavbar.ts +7 -1
- package/src/hooks/useSearchPage.ts +10 -5
- package/src/index.ts +12 -1
- package/src/internal.ts +7 -6
- package/src/utils/admonitionUtils.tsx +43 -0
- package/src/utils/historyUtils.ts +29 -1
- package/src/utils/skipToContentUtils.tsx +103 -0
- package/src/utils/storageUtils.ts +108 -7
- package/src/utils/tabsUtils.tsx +266 -0
- package/lib/contexts/tabGroupChoice.d.ts +0 -21
- package/lib/contexts/tabGroupChoice.d.ts.map +0 -1
- package/lib/contexts/tabGroupChoice.js +0 -49
- package/lib/contexts/tabGroupChoice.js.map +0 -1
- package/lib/hooks/useSkipToContent.d.ts +0 -25
- package/lib/hooks/useSkipToContent.d.ts.map +0 -1
- package/lib/hooks/useSkipToContent.js +0 -35
- package/lib/hooks/useSkipToContent.js.map +0 -1
- package/src/contexts/tabGroupChoice.tsx +0 -85
- 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
|
-
}
|