This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
body:not(.navigation-with-keyboard) *:not(input):focus {
outline: none;
}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/** Wires the logic for the back to top button. */
export declare function useBackToTopButton({ threshold, }: {
/**
* The minimum vertical scroll position, above which a scroll-up would not
* cause `shown` to become `true`. This is because BTT is only useful if the
* user is far down the page.
*/
threshold: number;
}): {
/**
* Whether the button should be displayed. We only show if the user has
* scrolled up and is on a vertical position greater than `threshold`.
*/
shown: boolean;
/**
* A (memoized) handle for starting the scroll, which you can directly plug
* into the props.
*/
scrollToTop: () => void;
};
//# sourceMappingURL=useBackToTopButton.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBackToTopButton.d.ts","sourceRoot":"","sources":["../../src/hooks/useBackToTopButton.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,kDAAkD;AAClD,wBAAgB,kBAAkB,CAAC,EACjC,SAAS,GACV,EAAE;IACD;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG;IACF;;;OAGG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAwCA"}

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useRef, useState } from 'react';
import { useScrollPosition, useSmoothScrollTo } from '../utils/scrollUtils';
import { useLocationChange } from '../utils/useLocationChange';
/** Wires the logic for the back to top button. */
export function useBackToTopButton({ threshold, }) {
const [shown, setShown] = useState(false);
const isFocusedAnchor = useRef(false);
const { startScroll, cancelScroll } = useSmoothScrollTo();
useScrollPosition(({ scrollY: scrollTop }, lastPosition) => {
const lastScrollTop = lastPosition?.scrollY;
// Component is just being mounted. Not really a scroll event from the user.
// Ignore it.
if (!lastScrollTop) {
return;
}
if (isFocusedAnchor.current) {
// This scroll position change is triggered by navigating to an anchor.
// Ignore it.
isFocusedAnchor.current = false;
}
else if (scrollTop >= lastScrollTop) {
// The user has scrolled down to "fight against" the animation. Cancel any
// animation under progress.
cancelScroll();
setShown(false);
}
else if (scrollTop < threshold) {
// Scrolled to the minimum position; hide the button.
setShown(false);
}
else if (scrollTop + window.innerHeight <
document.documentElement.scrollHeight) {
setShown(true);
}
});
useLocationChange((locationChangeEvent) => {
if (locationChangeEvent.location.hash) {
isFocusedAnchor.current = true;
setShown(false);
}
});
return { shown, scrollToTop: () => startScroll(0) };
}
//# sourceMappingURL=useBackToTopButton.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useBackToTopButton.js","sourceRoot":"","sources":["../../src/hooks/useBackToTopButton.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAE7D,kDAAkD;AAClD,MAAM,UAAU,kBAAkB,CAAC,EACjC,SAAS,GAQV;IAYC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,EAAC,WAAW,EAAE,YAAY,EAAC,GAAG,iBAAiB,EAAE,CAAC;IAExD,iBAAiB,CAAC,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,EAAE,YAAY,EAAE,EAAE;QACvD,MAAM,aAAa,GAAG,YAAY,EAAE,OAAO,CAAC;QAC5C,4EAA4E;QAC5E,aAAa;QACb,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO;SACR;QACD,IAAI,eAAe,CAAC,OAAO,EAAE;YAC3B,uEAAuE;YACvE,aAAa;YACb,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC;SACjC;aAAM,IAAI,SAAS,IAAI,aAAa,EAAE;YACrC,0EAA0E;YAC1E,4BAA4B;YAC5B,YAAY,EAAE,CAAC;YACf,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;aAAM,IAAI,SAAS,GAAG,SAAS,EAAE;YAChC,qDAAqD;YACrD,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;aAAM,IACL,SAAS,GAAG,MAAM,CAAC,WAAW;YAC9B,QAAQ,CAAC,eAAe,CAAC,YAAY,EACrC;YACA,QAAQ,CAAC,IAAI,CAAC,CAAC;SAChB;IACH,CAAC,CAAC,CAAC;IAEH,iBAAiB,CAAC,CAAC,mBAAmB,EAAE,EAAE;QACxC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,IAAI,EAAE;YACrC,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;YAC/B,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,EAAC,CAAC;AACpD,CAAC"}

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { RefObject } from 'react';
export declare function useCodeWordWrap(): {
readonly codeBlockRef: RefObject<HTMLPreElement>;
readonly isEnabled: boolean;
readonly isCodeScrollable: boolean;
readonly toggle: () => void;
};
//# sourceMappingURL=useCodeWordWrap.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useCodeWordWrap.d.ts","sourceRoot":"","sources":["../../src/hooks/useCodeWordWrap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAgDrC,wBAAgB,eAAe,IAAI;IACjC,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B,CA6CA"}

View File

@@ -0,0 +1,67 @@
import { useState, useCallback, useEffect, useRef } from 'react';
import { useMutationObserver } from './useMutationObserver';
// Callback fires when the "hidden" attribute of a tabpanel changes
// See https://github.com/facebook/docusaurus/pull/7485
function useTabBecameVisibleCallback(codeBlockRef, callback) {
const [hiddenTabElement, setHiddenTabElement] = useState();
const updateHiddenTabElement = useCallback(() => {
// No need to observe non-hidden tabs
// + we want to force a re-render when a tab becomes visible
setHiddenTabElement(codeBlockRef.current?.closest('[role=tabpanel][hidden]'));
}, [codeBlockRef, setHiddenTabElement]);
useEffect(() => {
updateHiddenTabElement();
}, [updateHiddenTabElement]);
useMutationObserver(hiddenTabElement, (mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' &&
mutation.attributeName === 'hidden') {
callback();
updateHiddenTabElement();
}
});
}, {
attributes: true,
characterData: false,
childList: false,
subtree: false,
});
}
export function useCodeWordWrap() {
const [isEnabled, setIsEnabled] = useState(false);
const [isCodeScrollable, setIsCodeScrollable] = useState(false);
const codeBlockRef = useRef(null);
const toggle = useCallback(() => {
const codeElement = codeBlockRef.current.querySelector('code');
if (isEnabled) {
codeElement.removeAttribute('style');
}
else {
codeElement.style.whiteSpace = 'pre-wrap';
// When code wrap is enabled, we want to avoid a scrollbar in any case
// Ensure that very very long words/strings/tokens still wrap
codeElement.style.overflowWrap = 'anywhere';
}
setIsEnabled((value) => !value);
}, [codeBlockRef, isEnabled]);
const updateCodeIsScrollable = useCallback(() => {
const { scrollWidth, clientWidth } = codeBlockRef.current;
const isScrollable = scrollWidth > clientWidth ||
codeBlockRef.current.querySelector('code').hasAttribute('style');
setIsCodeScrollable(isScrollable);
}, [codeBlockRef]);
useTabBecameVisibleCallback(codeBlockRef, updateCodeIsScrollable);
useEffect(() => {
updateCodeIsScrollable();
}, [isEnabled, updateCodeIsScrollable]);
useEffect(() => {
window.addEventListener('resize', updateCodeIsScrollable, {
passive: true,
});
return () => {
window.removeEventListener('resize', updateCodeIsScrollable);
};
}, [updateCodeIsScrollable]);
return { codeBlockRef, isEnabled, isCodeScrollable, toggle };
}
//# sourceMappingURL=useCodeWordWrap.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useCodeWordWrap.js","sourceRoot":"","sources":["../../src/hooks/useCodeWordWrap.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D,mEAAmE;AACnE,uDAAuD;AACvD,SAAS,2BAA2B,CAClC,YAAuC,EACvC,QAAoB;IAEpB,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,EAErD,CAAC;IAEJ,MAAM,sBAAsB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9C,qCAAqC;QACrC,4DAA4D;QAC5D,mBAAmB,CACjB,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,yBAAyB,CAAC,CACzD,CAAC;IACJ,CAAC,EAAE,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAExC,SAAS,CAAC,GAAG,EAAE;QACb,sBAAsB,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE7B,mBAAmB,CACjB,gB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GAAG,YAAY,CAAC,OAAQ,CAAC;QACzD,MAAM,YAAY,GAChB,WAAW,GAAG,WAAW;YACzB,YAAY,CAAC,OAAQ,CAAC,aAAa,CAAC,MAAM,CAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACrE,mBAAmB,CAAC,YAAY,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,2BAA2B,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;IAElE,SAAS,CAAC,GAAG,EAAE;QACb,sBAAsB,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAExC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,sBAAsB,EAAE;YACxD,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;QAC/D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE7B,OAAO,EAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,EAAC,CAAC;AAC7D,CAAC"}

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Wires the imperative logic of a hideable navbar.
* @param hideOnScroll If `false`, this hook is basically a no-op.
*/
export declare function useHideableNavbar(hideOnScroll: boolean): {
/** A ref to the navbar component. Plug this into the actual element. */
readonly navbarRef: (node: HTMLElement | null) => void;
/** If `false`, the navbar component should not be rendered. */
readonly isNavbarVisible: boolean;
};
//# sourceMappingURL=useHideableNavbar.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useHideableNavbar.d.ts","sourceRoot":"","sources":["../../src/hooks/useHideableNavbar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,OAAO,GAAG;IACxD,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC,CA4DA"}

View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useState, useCallback, useRef } from 'react';
import { useLocationChange } from '../utils/useLocationChange';
import { useScrollPosition } from '../utils/scrollUtils';
/**
* Wires the imperative logic of a hideable navbar.
* @param hideOnScroll If `false`, this hook is basically a no-op.
*/
export function useHideableNavbar(hideOnScroll) {
const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
const isFocusedAnchor = useRef(false);
const navbarHeight = useRef(0);
const navbarRef = useCallback((node) => {
if (node !== null) {
navbarHeight.current = node.getBoundingClientRect().height;
}
}, []);
useScrollPosition(({ scrollY: scrollTop }, lastPosition) => {
if (!hideOnScroll) {
return;
}
// Needed mostly for handling rubber band scrolling.
// See https://github.com/facebook/docusaurus/pull/5721
if (scrollTop < navbarHeight.current) {
setIsNavbarVisible(true);
return;
}
if (isFocusedAnchor.current) {
isFocusedAnchor.current = false;
return;
}
const lastScrollTop = lastPosition?.scrollY;
const documentHeight = document.documentElement.scrollHeight - navbarHeight.current;
const windowHeight = window.innerHeight;
if (lastScrollTop && scrollTop >= lastScrollTop) {
setIsNavbarVisible(false);
}
else if (scrollTop + windowHeight < documentHeight) {
setIsNavbarVisible(true);
}
});
useLocationChange((locationChangeEvent) => {
if (!hideOnScroll) {
return;
}
// See https://github.com/facebook/docusaurus/pull/8059#issuecomment-1239639480
const currentHash = locationChangeEvent.location.hash;
const currentHashAnchor = currentHash
? document.getElementById(currentHash.substring(1))
: undefined;
if (currentHashAnchor) {
isFocusedAnchor.current = true;
setIsNavbarVisible(false);
return;
}
setIsNavbarVisible(true);
});
return { navbarRef, isNavbarVisible };
}
//# sourceMappingURL=useHideableNavbar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useHideableNavbar.js","sourceRoot":"","sources":["../../src/hooks/useHideableNavbar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAqB;IAMrD,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,IAAwB,EAAE,EAAE;QACzD,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC;SAC5D;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,iBAAiB,CAAC,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,EAAE,YAAY,EAAE,EAAE;QACvD,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,oDAAoD;QACpD,uDAAuD;QACvD,IAAI,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE;YACpC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACzB,OAAO;SACR;QAED,IAAI,eAAe,CAAC,OAAO,EAAE;YAC3B,eAAe,CAAC,OAAO,GAAG,KAAK,CAAC;YAChC,OAAO;SACR;QAED,MAAM,aAAa,GAAG,YAAY,EAAE,OAAO,CAAC;QAC5C,MAAM,cAAc,GAClB,QAAQ,CAAC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC;QAC/D,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QAExC,IAAI,aAAa,IAAI,SAAS,IAAI,aAAa,EAAE;YAC/C,kBAAkB,CAAC,KAAK,CAAC,CAAC;SAC3B;aAAM,IAAI,SAAS,GAAG,YAAY,GAAG,cAAc,EAAE;YACpD,kBAAkB,CAAC,IAAI,CAAC,CAAC;SAC1B;IACH,CAAC,CAAC,CAAC;IAEH,iBAAiB,CAAC,CAAC,mBAAmB,EAAE,EAAE;QACxC,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,+EAA+E;QAC/E,MAAM,WAAW,GAAG,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC;QACtD,MAAM,iBAAiB,GAAG,WAAW;YACnC,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACnD,CAAC,CAAC,SAAS,CAAC;QAEd,IAAI,iBAAiB,EAAE;YACrB,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;YAC/B,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1B,OAAO;SACR;QAED,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,OAAO,EAAC,SAAS,EAAE,eAAe,EAAC,CAAC;AACtC,CAAC"}

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import './styles.css';
export declare const keyboardFocusedClassName = "navigation-with-keyboard";
/**
* Side-effect that adds the `keyboardFocusedClassName` to the body element when
* the keyboard has been pressed, or removes it when the mouse is clicked.
*
* The presence of this class name signals that the user may be using keyboard
* for navigation, and the theme **must** add focus outline when this class name
* is present. (And optionally not if it's absent, for design purposes)
*
* Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
*/
export declare function useKeyboardNavigation(): void;
//# sourceMappingURL=useKeyboardNavigation.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useKeyboardNavigation.d.ts","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAqB5C"}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useEffect } from 'react';
import './styles.css';
export const keyboardFocusedClassName = 'navigation-with-keyboard';
/**
* Side-effect that adds the `keyboardFocusedClassName` to the body element when
* the keyboard has been pressed, or removes it when the mouse is clicked.
*
* The presence of this class name signals that the user may be using keyboard
* for navigation, and the theme **must** add focus outline when this class name
* is present. (And optionally not if it's absent, for design purposes)
*
* Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
*/
export function useKeyboardNavigation() {
useEffect(() => {
function handleOutlineStyles(e) {
if (e.type === 'keydown' && e.key === 'Tab') {
document.body.classList.add(keyboardFocusedClassName);
}
if (e.type === 'mousedown') {
document.body.classList.remove(keyboardFocusedClassName);
}
}
document.addEventListener('keydown', handleOutlineStyles);
document.addEventListener('mousedown', handleOutlineStyles);
return () => {
document.body.classList.remove(keyboardFocusedClassName);
document.removeEventListener('keydown', handleOutlineStyles);
document.removeEventListener('mousedown', handleOutlineStyles);
};
}, []);
}
//# sourceMappingURL=useKeyboardNavigation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useKeyboardNavigation.js","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,mBAAmB,CAAC,CAA6B;YACxD,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAK,CAAmB,CAAC,GAAG,KAAK,KAAK,EAAE;gBAC9D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;aACvD;YAED,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC1B,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;aAC1D;QACH,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAC1D,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAE5D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;YAC7D,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QACjE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}

View File

@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Side-effect that locks the document body's scroll throughout the lifetime of
* the containing component. e.g. when the mobile sidebar is expanded.
*/
export declare function useLockBodyScroll(lock?: boolean): void;
//# sourceMappingURL=useLockBodyScroll.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useLockBodyScroll.d.ts","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,OAAc,GAAG,IAAI,CAO5D"}

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useEffect } from 'react';
/**
* Side-effect that locks the document body's scroll throughout the lifetime of
* the containing component. e.g. when the mobile sidebar is expanded.
*/
export function useLockBodyScroll(lock = true) {
useEffect(() => {
document.body.style.overflow = lock ? 'hidden' : 'visible';
return () => {
document.body.style.overflow = 'visible';
};
}, [lock]);
}
//# sourceMappingURL=useLockBodyScroll.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useLockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,IAAI;IACpD,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC"}

View File

@@ -0,0 +1,4 @@
type Options = MutationObserverInit;
export declare function useMutationObserver(target: Element | undefined | null, callback: MutationCallback, options?: Options): void;
export {};
//# sourceMappingURL=useMutationObserver.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useMutationObserver.d.ts","sourceRoot":"","sources":["../../src/hooks/useMutationObserver.ts"],"names":[],"mappings":"AASA,KAAK,OAAO,GAAG,oBAAoB,CAAC;AASpC,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,EAClC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,GAAE,OAAwB,GAChC,IAAI,CAeN"}

View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useEffect } from 'react';
import { useEvent, useShallowMemoObject } from '../utils/reactUtils';
const DefaultOptions = {
attributes: true,
characterData: true,
childList: true,
subtree: true,
};
export function useMutationObserver(target, callback, options = DefaultOptions) {
const stableCallback = useEvent(callback);
// MutationObserver options are not nested much
// so this should be to memo options in 99%
// TODO handle options.attributeFilter array
const stableOptions = useShallowMemoObject(options);
useEffect(() => {
const observer = new MutationObserver(stableCallback);
if (target) {
observer.observe(target, stableOptions);
}
return () => observer.disconnect();
}, [target, stableCallback, stableOptions]);
}
//# sourceMappingURL=useMutationObserver.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useMutationObserver.js","sourceRoot":"","sources":["../../src/hooks/useMutationObserver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,QAAQ,EAAE,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAInE,MAAM,cAAc,GAAY;IAC9B,UAAU,EAAE,IAAI;IAChB,aAAa,EAAE,IAAI;IACnB,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,MAAM,UAAU,mBAAmB,CACjC,MAAkC,EAClC,QAA0B,EAC1B,UAAmB,cAAc;IAEjC,MAAM,cAAc,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE1C,+CAA+C;IAC/C,2CAA2C;IAC3C,4CAA4C;IAC5C,MAAM,aAAa,GAAY,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAE7D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,cAAc,CAAC,CAAC;QACtD,IAAI,MAAM,EAAE;YACV,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;SACzC;QACD,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;AAC9C,CAAC"}

View File

@@ -0,0 +1,13 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { PrismTheme } from 'prism-react-renderer';
/**
* Returns a color-mode-dependent Prism theme: whatever the user specified in
* the config. Falls back to `palenight`.
*/
export declare function usePrismTheme(): PrismTheme;
//# sourceMappingURL=usePrismTheme.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"usePrismTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAQ1C"}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useColorMode } from '../contexts/colorMode';
import { useThemeConfig } from '../utils/useThemeConfig';
/**
* Returns a color-mode-dependent Prism theme: whatever the user specified in
* the config. Falls back to `palenight`.
*/
export function usePrismTheme() {
const { prism } = useThemeConfig();
const { colorMode } = useColorMode();
const lightModeTheme = prism.theme;
const darkModeTheme = prism.darkTheme || lightModeTheme;
const prismTheme = colorMode === 'dark' ? darkModeTheme : lightModeTheme;
return prismTheme;
}
//# sourceMappingURL=usePrismTheme.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"usePrismTheme.js","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAGvD;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAC,KAAK,EAAC,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,YAAY,EAAE,CAAC;IACnC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC;IACnC,MAAM,aAAa,GAAG,KAAK,CAAC,SAAS,IAAI,cAAc,CAAC;IACxD,MAAM,UAAU,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC;IAEzE,OAAO,UAAU,CAAC;AACpB,CAAC"}

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Permits to read/write the current search query string
*/
export declare function useSearchQueryString(): [string, (newValue: string) => void];
/**
* Permits to create links to the search page with the appropriate query string
*/
export declare function useSearchLinkCreator(): (searchValue: string) => string;
//# sourceMappingURL=useSearchPage.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useSearchPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,CAE3E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAiBtE"}

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useCallback } from 'react';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { useQueryString } from '../utils/historyUtils';
const SEARCH_PARAM_QUERY = 'q';
/**
* Permits to read/write the current search query string
*/
export function useSearchQueryString() {
return useQueryString(SEARCH_PARAM_QUERY);
}
/**
* Permits to create links to the search page with the appropriate query string
*/
export function useSearchLinkCreator() {
const { siteConfig: { baseUrl, themeConfig }, } = useDocusaurusContext();
const { algolia: { searchPagePath }, } = themeConfig;
return useCallback((searchValue) =>
// Refer to https://github.com/facebook/docusaurus/pull/2838
// Note: if searchPagePath is falsy, useSearchPage() will not be called
`${baseUrl}${searchPagePath}?${SEARCH_PARAM_QUERY}=${encodeURIComponent(searchValue)}`, [baseUrl, searchPagePath]);
}
//# sourceMappingURL=useSearchPage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useSearchPage.js","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAC,MAAM,OAAO,CAAC;AAClC,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAGrD,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAE,WAAW,EAAC,GACnC,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EACJ,OAAO,EAAE,EAAC,cAAc,EAAC,GAC1B,GAAG,WAAiC,CAAC;IAEtC,OAAO,WAAW,CAChB,CAAC,WAAmB,EAAE,EAAE;IACtB,4DAA4D;IAC5D,uEAAuE;IACvE,GAAG,OAAO,GACR,cACF,IAAI,kBAAkB,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE,EAC7D,CAAC,OAAO,EAAE,cAAc,CAAC,CAC1B,CAAC;AACJ,CAAC"}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export type TOCHighlightConfig = {
/** A class name that all TOC links share. */
linkClassName: string;
/** The class name applied to the active (highlighted) link. */
linkActiveClassName: string;
/**
* The minimum heading level that the TOC includes. Only headings that are in
* this range will be eligible as "active heading".
*/
minHeadingLevel: number;
/** @see {@link TOCHighlightConfig.minHeadingLevel} */
maxHeadingLevel: number;
};
/**
* Side-effect that applies the active class name to the TOC heading that the
* user is currently viewing. Disabled when `config` is undefined.
*/
export declare function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
//# sourceMappingURL=useTOCHighlight.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/hooks/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6GH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAwD5E"}

View File

@@ -0,0 +1,130 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useEffect, useRef } from 'react';
import { useThemeConfig } from '../utils/useThemeConfig';
// TODO make the hardcoded theme-classic classnames configurable (or add them
// to ThemeClassNames?)
/**
* 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
*/
function getVisibleBoundingClientRect(element) {
const rect = element.getBoundingClientRect();
const hasNoHeight = rect.top === rect.bottom;
if (hasNoHeight) {
return getVisibleBoundingClientRect(element.parentNode);
}
return rect;
}
/**
* Considering we divide viewport into 2 zones of each 50vh, this returns true
* if an element is in the first zone (i.e., appear in viewport, near the top)
*/
function isInViewportTopHalf(boundingRect) {
return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
}
function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
const selectors = [];
for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
selectors.push(`h${i}.anchor`);
}
return Array.from(document.querySelectorAll(selectors.join()));
}
function getActiveAnchor(anchors, { anchorTopOffset, }) {
// Naming is hard: The "nextVisibleAnchor" is the first anchor that appear
// under the viewport top boundary. It does not mean this anchor is visible
// yet, but if user continues scrolling down, it will be the first to become
// visible
const nextVisibleAnchor = anchors.find((anchor) => {
const boundingRect = getVisibleBoundingClientRect(anchor);
return boundingRect.top >= anchorTopOffset;
});
if (nextVisibleAnchor) {
const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
// If anchor is in the top half of the viewport: it is the one we consider
// "active" (unless it's too close to the top and and soon to be scrolled
// outside viewport)
if (isInViewportTopHalf(boundingRect)) {
return nextVisibleAnchor;
}
// If anchor is in the bottom half of the viewport, or under the viewport,
// we consider the active anchor is the previous one. This is because the
// main text appearing in the user screen mostly belong to the previous
// anchor. Returns null for the first anchor, see
// https://github.com/facebook/docusaurus/issues/5318
return anchors[anchors.indexOf(nextVisibleAnchor) - 1] ?? null;
}
// No anchor under viewport top (i.e. we are at the bottom of the page),
// highlight the last anchor found
return anchors[anchors.length - 1] ?? null;
}
function getLinkAnchorValue(link) {
return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
}
function getLinks(linkClassName) {
return Array.from(document.getElementsByClassName(linkClassName));
}
function getNavbarHeight() {
// Not ideal to obtain actual height this way
// Using TS ! (not ?) because otherwise a bad selector would be un-noticed
return document.querySelector('.navbar').clientHeight;
}
function useAnchorTopOffsetRef() {
const anchorTopOffsetRef = useRef(0);
const { navbar: { hideOnScroll }, } = useThemeConfig();
useEffect(() => {
anchorTopOffsetRef.current = hideOnScroll ? 0 : getNavbarHeight();
}, [hideOnScroll]);
return anchorTopOffsetRef;
}
/**
* Side-effect that applies the active class name to the TOC heading that the
* user is currently viewing. Disabled when `config` is undefined.
*/
export function useTOCHighlight(config) {
const lastActiveLinkRef = useRef(undefined);
const anchorTopOffsetRef = useAnchorTopOffsetRef();
useEffect(() => {
if (!config) {
// No-op, highlighting is disabled
return () => { };
}
const { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, } = config;
function updateLinkActiveClass(link, active) {
if (active) {
if (lastActiveLinkRef.current && lastActiveLinkRef.current !== link) {
lastActiveLinkRef.current.classList.remove(linkActiveClassName);
}
link.classList.add(linkActiveClassName);
lastActiveLinkRef.current = link;
// link.scrollIntoView({block: 'nearest'});
}
else {
link.classList.remove(linkActiveClassName);
}
}
function updateActiveLink() {
const links = getLinks(linkClassName);
const anchors = getAnchors({ minHeadingLevel, maxHeadingLevel });
const activeAnchor = getActiveAnchor(anchors, {
anchorTopOffset: anchorTopOffsetRef.current,
});
const activeLink = links.find((link) => activeAnchor && activeAnchor.id === getLinkAnchorValue(link));
links.forEach((link) => {
updateLinkActiveClass(link, link === activeLink);
});
}
document.addEventListener('scroll', updateActiveLink);
document.addEventListener('resize', updateActiveLink);
updateActiveLink();
return () => {
document.removeEventListener('scroll', updateActiveLink);
document.removeEventListener('resize', updateActiveLink);
};
}, [config, anchorTopOffsetRef]);
}
//# sourceMappingURL=useTOCHighlight.js.map

View File

@@ -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,YAAY,GAAG,eAAe,CAAC,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"}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
declare const windowSizes: {
readonly desktop: "desktop";
readonly mobile: "mobile";
readonly ssr: "ssr";
};
type WindowSize = keyof typeof windowSizes;
/**
* Gets the current window size as an enum value. We don't want it to return the
* actual width value, so that it only re-renders once a breakpoint is crossed.
*
* It may return `"ssr"`, which is very important to handle hydration FOUC or
* layout shifts. You have to handle it explicitly upfront. On the server, you
* may need to render BOTH the mobile/desktop elements (and hide one of them
* with mediaquery). We don't return `undefined` on purpose, to make it more
* explicit.
*/
export declare function useWindowSize({ desktopBreakpoint, }?: {
desktopBreakpoint?: number;
}): WindowSize;
export {};
//# sourceMappingURL=useWindowSize.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useWindowSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,QAAA,MAAM,WAAW;;;;CAIP,CAAC;AAEX,KAAK,UAAU,GAAG,MAAM,OAAO,WAAW,CAAC;AAoB3C;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,EAC5B,iBAAqC,GACtC,GAAE;IACD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,UAAU,CAuBlB"}

View File

@@ -0,0 +1,54 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import { useEffect, useState } from 'react';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
const windowSizes = {
desktop: 'desktop',
mobile: 'mobile',
ssr: 'ssr',
};
// Note: this value is also hardcoded in Infima
// Both JS and CSS must have the same value
// Updating this JS value alone is not enough
// See https://github.com/facebook/docusaurus/issues/9603
const DesktopBreakpoint = 996;
function getWindowSize(desktopBreakpoint) {
if (!ExecutionEnvironment.canUseDOM) {
throw new Error('getWindowSize() should only be called after React hydration');
}
return window.innerWidth > desktopBreakpoint
? windowSizes.desktop
: windowSizes.mobile;
}
/**
* Gets the current window size as an enum value. We don't want it to return the
* actual width value, so that it only re-renders once a breakpoint is crossed.
*
* It may return `"ssr"`, which is very important to handle hydration FOUC or
* layout shifts. You have to handle it explicitly upfront. On the server, you
* may need to render BOTH the mobile/desktop elements (and hide one of them
* with mediaquery). We don't return `undefined` on purpose, to make it more
* explicit.
*/
export function useWindowSize({ desktopBreakpoint = DesktopBreakpoint, } = {}) {
const [windowSize, setWindowSize] = useState(() =>
// super important to return a constant value to avoid hydration mismatch
// see https://github.com/facebook/docusaurus/issues/9379
'ssr');
useEffect(() => {
function updateWindowSize() {
setWindowSize(getWindowSize(desktopBreakpoint));
}
updateWindowSize();
window.addEventListener('resize', updateWindowSize);
return () => {
window.removeEventListener('resize', updateWindowSize);
};
}, [desktopBreakpoint]);
return windowSize;
}
//# sourceMappingURL=useWindowSize.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useWindowSize.js","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAE1C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;CACF,CAAC;AAIX,+CAA+C;AAC/C,2CAA2C;AAC3C,6CAA6C;AAC7C,yDAAyD;AACzD,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,SAAS,aAAa,CAAC,iBAAyB;IAC9C,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE;QACnC,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;KACH;IAED,OAAO,MAAM,CAAC,UAAU,GAAG,iBAAiB;QAC1C,CAAC,CAAC,WAAW,CAAC,OAAO;QACrB,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,iBAAiB,GAAG,iBAAiB,MAGnC,EAAE;IACJ,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAC1C,GAAG,EAAE;IACH,yEAAyE;IACzE,yDAAyD;IACzD,KAAK,CACR,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,gBAAgB;YACvB,aAAa,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC;QAClD,CAAC;QAED,gBAAgB,EAAE,CAAC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