@allxsmith/bestax-bulma 5.27.0 → 5.27.2
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/dist/bestax.css +1 -1
- package/dist/bestax.css.map +1 -1
- package/dist/esm/columns/Column.js +48 -0
- package/dist/esm/columns/Column.js.map +1 -0
- package/dist/esm/columns/Columns.js +53 -0
- package/dist/esm/columns/Columns.js.map +1 -0
- package/dist/esm/components/Avatar.js +299 -0
- package/dist/esm/components/Avatar.js.map +1 -0
- package/dist/esm/components/Avatars.js +81 -0
- package/dist/esm/components/Avatars.js.map +1 -0
- package/dist/esm/components/Badge.js +105 -0
- package/dist/esm/components/Badge.js.map +1 -0
- package/dist/esm/components/Breadcrumb.js +36 -0
- package/dist/esm/components/Breadcrumb.js.map +1 -0
- package/dist/esm/components/Card.js +252 -0
- package/dist/esm/components/Card.js.map +1 -0
- package/dist/esm/components/Carousel.js +351 -0
- package/dist/esm/components/Carousel.js.map +1 -0
- package/dist/esm/components/Collapse.js +193 -0
- package/dist/esm/components/Collapse.js.map +1 -0
- package/dist/esm/components/Collapses.js +99 -0
- package/dist/esm/components/Collapses.js.map +1 -0
- package/dist/esm/components/Dialog.js +230 -0
- package/dist/esm/components/Dialog.js.map +1 -0
- package/dist/esm/components/Dropdown.js +362 -0
- package/dist/esm/components/Dropdown.js.map +1 -0
- package/dist/esm/components/Loading.js +87 -0
- package/dist/esm/components/Loading.js.map +1 -0
- package/dist/esm/components/Menu.js +117 -0
- package/dist/esm/components/Menu.js.map +1 -0
- package/dist/esm/components/Message.js +56 -0
- package/dist/esm/components/Message.js.map +1 -0
- package/dist/esm/components/Modal.js +354 -0
- package/dist/esm/components/Modal.js.map +1 -0
- package/dist/esm/components/Navbar.js +287 -0
- package/dist/esm/components/Navbar.js.map +1 -0
- package/dist/esm/components/Pagination.js +191 -0
- package/dist/esm/components/Pagination.js.map +1 -0
- package/dist/esm/components/Panel.js +100 -0
- package/dist/esm/components/Panel.js.map +1 -0
- package/dist/esm/components/Popover.js +298 -0
- package/dist/esm/components/Popover.js.map +1 -0
- package/dist/esm/components/Reveal.js +157 -0
- package/dist/esm/components/Reveal.js.map +1 -0
- package/dist/esm/components/Sidebar.js +209 -0
- package/dist/esm/components/Sidebar.js.map +1 -0
- package/dist/esm/components/Steps.js +128 -0
- package/dist/esm/components/Steps.js.map +1 -0
- package/dist/esm/components/Tabs.js +335 -0
- package/dist/esm/components/Tabs.js.map +1 -0
- package/dist/esm/components/Toast.js +322 -0
- package/dist/esm/components/Toast.js.map +1 -0
- package/dist/esm/components/Tooltip.js +202 -0
- package/dist/esm/components/Tooltip.js.map +1 -0
- package/dist/esm/components/collapsesContext.js +12 -0
- package/dist/esm/components/collapsesContext.js.map +1 -0
- package/dist/esm/elements/Block.js +29 -0
- package/dist/esm/elements/Block.js.map +1 -0
- package/dist/esm/elements/Box.js +32 -0
- package/dist/esm/elements/Box.js.map +1 -0
- package/dist/esm/elements/Button.js +139 -0
- package/dist/esm/elements/Button.js.map +1 -0
- package/dist/esm/elements/Buttons.js +42 -0
- package/dist/esm/elements/Buttons.js.map +1 -0
- package/dist/esm/elements/Code.js +25 -0
- package/dist/esm/elements/Code.js.map +1 -0
- package/dist/esm/elements/Content.js +33 -0
- package/dist/esm/elements/Content.js.map +1 -0
- package/dist/esm/elements/Delete.js +35 -0
- package/dist/esm/elements/Delete.js.map +1 -0
- package/dist/esm/elements/Divider.js +27 -0
- package/dist/esm/elements/Divider.js.map +1 -0
- package/dist/esm/elements/Emphasis.js +25 -0
- package/dist/esm/elements/Emphasis.js.map +1 -0
- package/dist/esm/elements/Figure.js +58 -0
- package/dist/esm/elements/Figure.js.map +1 -0
- package/dist/esm/elements/Icon.js +256 -0
- package/dist/esm/elements/Icon.js.map +1 -0
- package/dist/esm/elements/IconText.js +36 -0
- package/dist/esm/elements/IconText.js.map +1 -0
- package/dist/esm/elements/Image.js +46 -0
- package/dist/esm/elements/Image.js.map +1 -0
- package/dist/esm/elements/Link.js +36 -0
- package/dist/esm/elements/Link.js.map +1 -0
- package/dist/esm/elements/LinkButton.js +37 -0
- package/dist/esm/elements/LinkButton.js.map +1 -0
- package/dist/esm/elements/ListItem.js +28 -0
- package/dist/esm/elements/ListItem.js.map +1 -0
- package/dist/esm/elements/Loader.js +37 -0
- package/dist/esm/elements/Loader.js.map +1 -0
- package/dist/esm/elements/Notification.js +316 -0
- package/dist/esm/elements/Notification.js.map +1 -0
- package/dist/esm/elements/OrderedList.js +31 -0
- package/dist/esm/elements/OrderedList.js.map +1 -0
- package/dist/esm/elements/Paragraph.js +28 -0
- package/dist/esm/elements/Paragraph.js.map +1 -0
- package/dist/esm/elements/Pre.js +25 -0
- package/dist/esm/elements/Pre.js.map +1 -0
- package/dist/esm/elements/Progress.js +33 -0
- package/dist/esm/elements/Progress.js.map +1 -0
- package/dist/esm/elements/Skeleton.js +30 -0
- package/dist/esm/elements/Skeleton.js.map +1 -0
- package/dist/esm/elements/Span.js +28 -0
- package/dist/esm/elements/Span.js.map +1 -0
- package/dist/esm/elements/Strong.js +25 -0
- package/dist/esm/elements/Strong.js.map +1 -0
- package/dist/esm/elements/SubTitle.js +51 -0
- package/dist/esm/elements/SubTitle.js.map +1 -0
- package/dist/esm/elements/Table.js +51 -0
- package/dist/esm/elements/Table.js.map +1 -0
- package/dist/esm/elements/Tag.js +49 -0
- package/dist/esm/elements/Tag.js.map +1 -0
- package/dist/esm/elements/Tags.js +34 -0
- package/dist/esm/elements/Tags.js.map +1 -0
- package/dist/esm/elements/Tbody.js +26 -0
- package/dist/esm/elements/Tbody.js.map +1 -0
- package/dist/esm/elements/Td.js +61 -0
- package/dist/esm/elements/Td.js.map +1 -0
- package/dist/esm/elements/Tfoot.js +26 -0
- package/dist/esm/elements/Tfoot.js.map +1 -0
- package/dist/esm/elements/Th.js +34 -0
- package/dist/esm/elements/Th.js.map +1 -0
- package/dist/esm/elements/Thead.js +26 -0
- package/dist/esm/elements/Thead.js.map +1 -0
- package/dist/esm/elements/Title.js +44 -0
- package/dist/esm/elements/Title.js.map +1 -0
- package/dist/esm/elements/Tr.js +31 -0
- package/dist/esm/elements/Tr.js.map +1 -0
- package/dist/esm/elements/UnorderedList.js +31 -0
- package/dist/esm/elements/UnorderedList.js.map +1 -0
- package/dist/esm/elements/iconProps.js +49 -0
- package/dist/esm/elements/iconProps.js.map +1 -0
- package/dist/esm/form/Autocomplete.js +279 -0
- package/dist/esm/form/Autocomplete.js.map +1 -0
- package/dist/esm/form/Checkbox.js +111 -0
- package/dist/esm/form/Checkbox.js.map +1 -0
- package/dist/esm/form/Checkboxes.js +90 -0
- package/dist/esm/form/Checkboxes.js.map +1 -0
- package/dist/esm/form/Control.js +79 -0
- package/dist/esm/form/Control.js.map +1 -0
- package/dist/esm/form/DateInput.js +88 -0
- package/dist/esm/form/DateInput.js.map +1 -0
- package/dist/esm/form/DateInputBase.js +263 -0
- package/dist/esm/form/DateInputBase.js.map +1 -0
- package/dist/esm/form/DateRangeInput.js +77 -0
- package/dist/esm/form/DateRangeInput.js.map +1 -0
- package/dist/esm/form/DateRangeInputBase.js +301 -0
- package/dist/esm/form/DateRangeInputBase.js.map +1 -0
- package/dist/esm/form/DateTimeInput.js +88 -0
- package/dist/esm/form/DateTimeInput.js.map +1 -0
- package/dist/esm/form/DateTimeInputBase.js +333 -0
- package/dist/esm/form/DateTimeInputBase.js.map +1 -0
- package/dist/esm/form/Field.js +167 -0
- package/dist/esm/form/Field.js.map +1 -0
- package/dist/esm/form/File.js +112 -0
- package/dist/esm/form/File.js.map +1 -0
- package/dist/esm/form/FormContext.js +194 -0
- package/dist/esm/form/FormContext.js.map +1 -0
- package/dist/esm/form/Input.js +88 -0
- package/dist/esm/form/Input.js.map +1 -0
- package/dist/esm/form/InputBase.js +40 -0
- package/dist/esm/form/InputBase.js.map +1 -0
- package/dist/esm/form/Numberinput.js +201 -0
- package/dist/esm/form/Numberinput.js.map +1 -0
- package/dist/esm/form/Radio.js +108 -0
- package/dist/esm/form/Radio.js.map +1 -0
- package/dist/esm/form/Radios.js +92 -0
- package/dist/esm/form/Radios.js.map +1 -0
- package/dist/esm/form/Rate.js +280 -0
- package/dist/esm/form/Rate.js.map +1 -0
- package/dist/esm/form/Select.js +81 -0
- package/dist/esm/form/Select.js.map +1 -0
- package/dist/esm/form/SelectBase.js +54 -0
- package/dist/esm/form/SelectBase.js.map +1 -0
- package/dist/esm/form/Slider.js +461 -0
- package/dist/esm/form/Slider.js.map +1 -0
- package/dist/esm/form/Switch.js +96 -0
- package/dist/esm/form/Switch.js.map +1 -0
- package/dist/esm/form/Taginput.js +351 -0
- package/dist/esm/form/Taginput.js.map +1 -0
- package/dist/esm/form/TextArea.js +77 -0
- package/dist/esm/form/TextArea.js.map +1 -0
- package/dist/esm/form/TextAreaBase.js +45 -0
- package/dist/esm/form/TextAreaBase.js.map +1 -0
- package/dist/esm/form/TimeInput.js +84 -0
- package/dist/esm/form/TimeInput.js.map +1 -0
- package/dist/esm/form/TimeInputBase.js +246 -0
- package/dist/esm/form/TimeInputBase.js.map +1 -0
- package/dist/esm/form/_pickerInternals/Calendar.js +760 -0
- package/dist/esm/form/_pickerInternals/Calendar.js.map +1 -0
- package/dist/esm/form/_pickerInternals/PickerPopover.js +95 -0
- package/dist/esm/form/_pickerInternals/PickerPopover.js.map +1 -0
- package/dist/esm/form/_pickerInternals/TimeWheels.js +721 -0
- package/dist/esm/form/_pickerInternals/TimeWheels.js.map +1 -0
- package/dist/esm/form/_pickerInternals/audioTick.js +109 -0
- package/dist/esm/form/_pickerInternals/audioTick.js.map +1 -0
- package/dist/esm/form/_pickerInternals/dateUtils.js +267 -0
- package/dist/esm/form/_pickerInternals/dateUtils.js.map +1 -0
- package/dist/esm/form/_pickerInternals/formatters.js +322 -0
- package/dist/esm/form/_pickerInternals/formatters.js.map +1 -0
- package/dist/esm/form/_pickerInternals/haptics.js +38 -0
- package/dist/esm/form/_pickerInternals/haptics.js.map +1 -0
- package/dist/esm/form/_pickerInternals/nativeInputSupport.js +25 -0
- package/dist/esm/form/_pickerInternals/nativeInputSupport.js.map +1 -0
- package/dist/esm/form/_pickerInternals/pickerTypes.js +50 -0
- package/dist/esm/form/_pickerInternals/pickerTypes.js.map +1 -0
- package/dist/esm/form/_pickerInternals/segmentMap.js +315 -0
- package/dist/esm/form/_pickerInternals/segmentMap.js.map +1 -0
- package/dist/esm/form/_pickerInternals/useNativeMobilePicker.js +49 -0
- package/dist/esm/form/_pickerInternals/useNativeMobilePicker.js.map +1 -0
- package/dist/esm/form/_pickerInternals/useSegmentedEntry.js +427 -0
- package/dist/esm/form/_pickerInternals/useSegmentedEntry.js.map +1 -0
- package/dist/esm/form/controlLoading.js +18 -0
- package/dist/esm/form/controlLoading.js.map +1 -0
- package/dist/esm/form/useAutoLabelId.js +88 -0
- package/dist/esm/form/useAutoLabelId.js.map +1 -0
- package/dist/esm/grid/Cell.js +35 -0
- package/dist/esm/grid/Cell.js.map +1 -0
- package/dist/esm/grid/Grid.js +51 -0
- package/dist/esm/grid/Grid.js.map +1 -0
- package/dist/esm/helpers/ClientOnly.js +33 -0
- package/dist/esm/helpers/ClientOnly.js.map +1 -0
- package/dist/esm/helpers/Config.js +60 -0
- package/dist/esm/helpers/Config.js.map +1 -0
- package/dist/esm/helpers/Theme.js +947 -0
- package/dist/esm/helpers/Theme.js.map +1 -0
- package/dist/esm/helpers/anchorAttrs.js +72 -0
- package/dist/esm/helpers/anchorAttrs.js.map +1 -0
- package/dist/esm/helpers/bulmaClassHelpers.js +415 -0
- package/dist/esm/helpers/bulmaClassHelpers.js.map +1 -0
- package/dist/esm/helpers/buttonType.js +24 -0
- package/dist/esm/helpers/buttonType.js.map +1 -0
- package/dist/esm/helpers/classNames.js +137 -0
- package/dist/esm/helpers/classNames.js.map +1 -0
- package/dist/esm/helpers/colorDeprecations.js +50 -0
- package/dist/esm/helpers/colorDeprecations.js.map +1 -0
- package/dist/esm/helpers/devWarnings.js +27 -0
- package/dist/esm/helpers/devWarnings.js.map +1 -0
- package/dist/esm/helpers/inertProps.js +27 -0
- package/dist/esm/helpers/inertProps.js.map +1 -0
- package/dist/esm/helpers/mergeBulmaStyles.js +20 -0
- package/dist/esm/helpers/mergeBulmaStyles.js.map +1 -0
- package/dist/esm/helpers/polymorphic.js +18 -0
- package/dist/esm/helpers/polymorphic.js.map +1 -0
- package/dist/esm/helpers/portal.js +76 -0
- package/dist/esm/helpers/portal.js.map +1 -0
- package/dist/esm/helpers/positionStacks.js +45 -0
- package/dist/esm/helpers/positionStacks.js.map +1 -0
- package/dist/esm/helpers/scrollLock.js +38 -0
- package/dist/esm/helpers/scrollLock.js.map +1 -0
- package/dist/esm/helpers/shadowDom.js +71 -0
- package/dist/esm/helpers/shadowDom.js.map +1 -0
- package/dist/esm/helpers/statusRegion.js +282 -0
- package/dist/esm/helpers/statusRegion.js.map +1 -0
- package/dist/esm/helpers/useAnchoredPosition.js +86 -0
- package/dist/esm/helpers/useAnchoredPosition.js.map +1 -0
- package/dist/esm/helpers/useBulmaClasses.js +158 -0
- package/dist/esm/helpers/useBulmaClasses.js.map +1 -0
- package/dist/esm/helpers/useClientLayoutEffect.js +13 -0
- package/dist/esm/helpers/useClientLayoutEffect.js.map +1 -0
- package/dist/esm/helpers/useColorClasses.js +84 -0
- package/dist/esm/helpers/useColorClasses.js.map +1 -0
- package/dist/esm/helpers/useFlexboxClasses.js +92 -0
- package/dist/esm/helpers/useFlexboxClasses.js.map +1 -0
- package/dist/esm/helpers/useFocusTrap.js +470 -0
- package/dist/esm/helpers/useFocusTrap.js.map +1 -0
- package/dist/esm/helpers/useIsHydrated.js +31 -0
- package/dist/esm/helpers/useIsHydrated.js.map +1 -0
- package/dist/esm/helpers/useOtherClasses.js +115 -0
- package/dist/esm/helpers/useOtherClasses.js.map +1 -0
- package/dist/esm/helpers/useSpacingClasses.js +82 -0
- package/dist/esm/helpers/useSpacingClasses.js.map +1 -0
- package/dist/esm/helpers/useTypographyClasses.js +93 -0
- package/dist/esm/helpers/useTypographyClasses.js.map +1 -0
- package/dist/esm/helpers/useVisibilityClasses.js +134 -0
- package/dist/esm/helpers/useVisibilityClasses.js.map +1 -0
- package/dist/esm/helpers/withSubComponents.js +24 -0
- package/dist/esm/helpers/withSubComponents.js.map +1 -0
- package/dist/esm/layout/Container.js +48 -0
- package/dist/esm/layout/Container.js.map +1 -0
- package/dist/esm/layout/Footer.js +33 -0
- package/dist/esm/layout/Footer.js.map +1 -0
- package/dist/esm/layout/Hero.js +90 -0
- package/dist/esm/layout/Hero.js.map +1 -0
- package/dist/esm/layout/Level.js +110 -0
- package/dist/esm/layout/Level.js.map +1 -0
- package/dist/esm/layout/Media.js +86 -0
- package/dist/esm/layout/Media.js.map +1 -0
- package/dist/esm/layout/Section.js +30 -0
- package/dist/esm/layout/Section.js.map +1 -0
- package/dist/extras.css +1 -1
- package/dist/extras.css.map +1 -1
- package/dist/index.cjs +187 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +115 -17516
- package/dist/index.esm.js.map +1 -1
- package/dist/types/elements/Icon.d.ts +10 -7
- package/dist/types/form/Autocomplete.d.ts +1 -1
- package/dist/types/form/Checkboxes.d.ts +1 -1
- package/dist/types/form/DateInput.d.ts +1 -1
- package/dist/types/form/DateInputBase.d.ts +3 -4
- package/dist/types/form/DateRangeInput.d.ts +1 -1
- package/dist/types/form/DateTimeInput.d.ts +1 -1
- package/dist/types/form/DateTimeInputBase.d.ts +3 -4
- package/dist/types/form/Field.d.ts +2 -2
- package/dist/types/form/File.d.ts +4 -4
- package/dist/types/form/FormContext.d.ts +24 -2
- package/dist/types/form/Numberinput.d.ts +1 -1
- package/dist/types/form/Radios.d.ts +1 -1
- package/dist/types/form/Rate.d.ts +1 -1
- package/dist/types/form/Slider.d.ts +1 -1
- package/dist/types/form/Taginput.d.ts +1 -1
- package/dist/types/form/TimeInput.d.ts +1 -1
- package/dist/types/form/useAutoLabelId.d.ts +25 -4
- package/dist/types/helpers/Config.d.ts +3 -4
- package/dist/types/helpers/Theme.d.ts +44 -40
- package/dist/types-cjs/elements/Icon.d.ts +10 -7
- package/dist/types-cjs/form/Autocomplete.d.ts +1 -1
- package/dist/types-cjs/form/Checkboxes.d.ts +1 -1
- package/dist/types-cjs/form/DateInput.d.ts +1 -1
- package/dist/types-cjs/form/DateInputBase.d.ts +3 -4
- package/dist/types-cjs/form/DateRangeInput.d.ts +1 -1
- package/dist/types-cjs/form/DateTimeInput.d.ts +1 -1
- package/dist/types-cjs/form/DateTimeInputBase.d.ts +3 -4
- package/dist/types-cjs/form/Field.d.ts +2 -2
- package/dist/types-cjs/form/File.d.ts +4 -4
- package/dist/types-cjs/form/FormContext.d.ts +24 -2
- package/dist/types-cjs/form/Numberinput.d.ts +1 -1
- package/dist/types-cjs/form/Radios.d.ts +1 -1
- package/dist/types-cjs/form/Rate.d.ts +1 -1
- package/dist/types-cjs/form/Slider.d.ts +1 -1
- package/dist/types-cjs/form/Taginput.d.ts +1 -1
- package/dist/types-cjs/form/TimeInput.d.ts +1 -1
- package/dist/types-cjs/form/useAutoLabelId.d.ts +25 -4
- package/dist/types-cjs/helpers/Config.d.ts +3 -4
- package/dist/types-cjs/helpers/Theme.d.ts +44 -40
- package/dist/versions/bestax-no-dark-mode.css +1 -1
- package/dist/versions/bestax-no-dark-mode.css.map +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
- package/dist/versions/bestax-no-helpers.css +1 -1
- package/dist/versions/bestax-no-helpers.css.map +1 -1
- package/dist/versions/bestax-prefixed.css +1 -1
- package/dist/versions/bestax-prefixed.css.map +1 -1
- package/package.json +1 -1
- package/src/scss/form/_dateinput.scss +37 -6
- package/src/scss/form/_datetimeinput.scss +7 -2
- package/src/scss/form/_picker-popover.scss +1 -4
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
/* @allxsmith/bestax-bulma — AI agents: see AGENTS.md in the package root, or https://bestax.io/llms.txt */
|
|
2
|
+
import { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { useIsHydrated } from './useIsHydrated.js';
|
|
4
|
+
import { getDeepestActiveElement } from './shadowDom.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether `el` is editable while its parent is not, which makes it an editing
|
|
8
|
+
* host: the one tab stop an editable region gets. `contenteditable="false"`
|
|
9
|
+
* turns editing off, and a missing or unknown value inherits the parent's.
|
|
10
|
+
*/
|
|
11
|
+
function isEditingHost(el) {
|
|
12
|
+
const editable = (node) => {
|
|
13
|
+
const value = node.getAttribute('contenteditable')?.toLowerCase();
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
return null;
|
|
16
|
+
if (value === '' || value === 'true' || value === 'plaintext-only') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return value === 'false' ? false : null;
|
|
20
|
+
};
|
|
21
|
+
if (editable(el) !== true)
|
|
22
|
+
return false;
|
|
23
|
+
for (let node = el.parentElement; node; node = node.parentElement) {
|
|
24
|
+
const state = editable(node);
|
|
25
|
+
if (state !== null)
|
|
26
|
+
return !state;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/** Whether `el` is the summary of its `<details>`: the first one, not a stray. */
|
|
31
|
+
const isDetailsSummary = (el) => el.parentElement?.localName === 'details' &&
|
|
32
|
+
Array.from(el.parentElement.children).find(child => child.localName === 'summary') === el;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the browser puts `el` in the tab order, before anything that hides
|
|
35
|
+
* or disables it. The `tabIndex` property can't answer this on its own: it
|
|
36
|
+
* can read `-1` for an editable region or an `<embed>` that Tab still visits,
|
|
37
|
+
* and `0` for a `<video>` without controls that it doesn't. So a valid
|
|
38
|
+
* `tabindex` attribute decides, and otherwise the element's kind does.
|
|
39
|
+
*/
|
|
40
|
+
function isTabbableKind(el) {
|
|
41
|
+
const tabindex = el.getAttribute('tabindex');
|
|
42
|
+
if (tabindex !== null && /^\s*[+-]?\d/.test(tabindex)) {
|
|
43
|
+
return el.tabIndex >= 0;
|
|
44
|
+
}
|
|
45
|
+
switch (el.localName) {
|
|
46
|
+
case 'a':
|
|
47
|
+
case 'area':
|
|
48
|
+
return el.hasAttribute('href');
|
|
49
|
+
case 'input':
|
|
50
|
+
return el.type !== 'hidden';
|
|
51
|
+
case 'button':
|
|
52
|
+
case 'select':
|
|
53
|
+
case 'textarea':
|
|
54
|
+
case 'iframe':
|
|
55
|
+
case 'embed':
|
|
56
|
+
case 'object':
|
|
57
|
+
return true;
|
|
58
|
+
case 'audio':
|
|
59
|
+
case 'video':
|
|
60
|
+
return el.hasAttribute('controls');
|
|
61
|
+
case 'summary':
|
|
62
|
+
return isDetailsSummary(el);
|
|
63
|
+
default:
|
|
64
|
+
return isEditingHost(el);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The node's parent in the flattened tree, the one the browser renders and
|
|
69
|
+
* tabs through: the slot it is assigned to, else its parent, else the host of
|
|
70
|
+
* the shadow root it tops, and nothing above the document. A closed shadow
|
|
71
|
+
* root hides its slots (`assignedSlot` reads `null` under one), so a child of
|
|
72
|
+
* its host goes straight to the host, whether a slot takes it or not.
|
|
73
|
+
*/
|
|
74
|
+
const flatParent = (node) => node.assignedSlot ??
|
|
75
|
+
node.parentElement ??
|
|
76
|
+
node.parentNode?.host ??
|
|
77
|
+
null;
|
|
78
|
+
/**
|
|
79
|
+
* The element's children in the flattened tree, in the order they render: a
|
|
80
|
+
* host's shadow root content, a slot's assigned elements (or its fallback
|
|
81
|
+
* content when nothing is assigned), anything else's own children. A host
|
|
82
|
+
* whose shadow root is closed has no root to read, so its own children stand
|
|
83
|
+
* in, including any that no slot takes and that aren't rendered.
|
|
84
|
+
*/
|
|
85
|
+
function flatChildren(el) {
|
|
86
|
+
if (el.shadowRoot)
|
|
87
|
+
return Array.from(el.shadowRoot.children);
|
|
88
|
+
if (el.localName === 'slot') {
|
|
89
|
+
const assigned = el.assignedNodes();
|
|
90
|
+
if (assigned.length > 0) {
|
|
91
|
+
return assigned.filter((node) => node.nodeType === Node.ELEMENT_NODE);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return Array.from(el.children);
|
|
95
|
+
}
|
|
96
|
+
const isShown = (el) => !el.hasAttribute('inert') && getComputedStyle(el).display !== 'none';
|
|
97
|
+
const isVisible = (el) => {
|
|
98
|
+
const { visibility } = getComputedStyle(el);
|
|
99
|
+
return visibility !== 'hidden' && visibility !== 'collapse';
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Whether nothing from `el` up to `top` hides it: `inert`, `display: none`
|
|
103
|
+
* (not inherited, so each element is checked) or a closed `<details>` it
|
|
104
|
+
* isn't the summary of. `top` itself isn't checked, and `null` walks to the
|
|
105
|
+
* top of the page.
|
|
106
|
+
*/
|
|
107
|
+
function isShownUpTo(el, top) {
|
|
108
|
+
let below = null;
|
|
109
|
+
for (let node = el; node && node !== top; node = flatParent(node)) {
|
|
110
|
+
if (!isShown(node))
|
|
111
|
+
return false;
|
|
112
|
+
if (below &&
|
|
113
|
+
node.localName === 'details' &&
|
|
114
|
+
!node.hasAttribute('open') &&
|
|
115
|
+
!isDetailsSummary(below)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
below = node;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The images that use the image map `area` belongs to. An image names its
|
|
124
|
+
* map with `usemap="#…"`, matching the map's `name` or `id`.
|
|
125
|
+
*/
|
|
126
|
+
function imagesUsingMapOf(area) {
|
|
127
|
+
const map = area.closest('map');
|
|
128
|
+
if (!map)
|
|
129
|
+
return [];
|
|
130
|
+
const names = [map.getAttribute('name'), map.id].filter(name => name);
|
|
131
|
+
return Array.from(area.getRootNode().querySelectorAll('img[usemap]')).filter(img => {
|
|
132
|
+
const ref = img.getAttribute('usemap');
|
|
133
|
+
return ref.startsWith('#') && names.includes(ref.slice(1));
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Whether an image map area is shown. An area has no box of its own: the
|
|
138
|
+
* HTML rendering rules give it `display: none`, though a browser may not
|
|
139
|
+
* report that. So it counts where an image using its map is shown, as long
|
|
140
|
+
* as nothing makes it inert.
|
|
141
|
+
*/
|
|
142
|
+
function isAreaShown(area, container) {
|
|
143
|
+
for (let node = area; node && node !== container; node = flatParent(node)) {
|
|
144
|
+
if (node.hasAttribute('inert'))
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return imagesUsingMapOf(area).some(img => isShownUpTo(img, null) && isVisible(img));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Whether Tab can land on `el`, one of the kinds it visits. A disabled control
|
|
151
|
+
* (including one inside a disabled `<fieldset>`), an inert subtree and
|
|
152
|
+
* anything not rendered are skipped. `visibility` is inherited, so the
|
|
153
|
+
* element's own computed value covers its ancestors.
|
|
154
|
+
*/
|
|
155
|
+
function isRenderedAndEnabled(el, container) {
|
|
156
|
+
if (el.matches(':disabled'))
|
|
157
|
+
return false;
|
|
158
|
+
if (el.localName === 'area')
|
|
159
|
+
return isAreaShown(el, container);
|
|
160
|
+
return isShownUpTo(el, container) && isVisible(el);
|
|
161
|
+
}
|
|
162
|
+
/** A radio button with a name, which shares one tab stop with its group. */
|
|
163
|
+
const isGroupedRadio = (el) => el.localName === 'input' &&
|
|
164
|
+
el.type === 'radio' &&
|
|
165
|
+
el.name !== '';
|
|
166
|
+
/** Whether two radio buttons are in one group: same name, form owner and tree. */
|
|
167
|
+
const sameGroup = (a, b) => isGroupedRadio(b) &&
|
|
168
|
+
b.name === a.name &&
|
|
169
|
+
b.form === a.form &&
|
|
170
|
+
b.getRootNode() === a.getRootNode();
|
|
171
|
+
/**
|
|
172
|
+
* The checked button of `radio`'s group. The group isn't bounded by the trap,
|
|
173
|
+
* so this looks through the radio's whole tree.
|
|
174
|
+
*/
|
|
175
|
+
const checkedInGroup = (radio) => Array.from(radio.getRootNode().querySelectorAll('input:checked')).find(el => sameGroup(radio, el));
|
|
176
|
+
/** The flattened-tree ancestors of `node` below the container, outermost first, then `node`. */
|
|
177
|
+
function flatChain(node, container) {
|
|
178
|
+
const chain = [];
|
|
179
|
+
for (let n = node; n && n !== container; n = flatParent(n)) {
|
|
180
|
+
chain.unshift(n);
|
|
181
|
+
}
|
|
182
|
+
return chain;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Whether `node` is inside the container in the flattened tree: in it, in a
|
|
186
|
+
* shadow root it holds, or slotted into it. A child of a closed-root host
|
|
187
|
+
* counts as inside wherever the host is, as its slot can't be seen.
|
|
188
|
+
*/
|
|
189
|
+
function inside(container, node) {
|
|
190
|
+
for (let n = node; n; n = flatParent(n)) {
|
|
191
|
+
if (n === container)
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* `true` when Tab reaches `b` after `a`, which is their order in the
|
|
198
|
+
* flattened tree: a shadow host comes before its shadow root's content, and
|
|
199
|
+
* slotted content comes where its slot is. A closed root's slots can't be
|
|
200
|
+
* seen, so its host's children keep their place in the light DOM. Two
|
|
201
|
+
* flattened-tree siblings are always in one DOM tree, so their document
|
|
202
|
+
* position decides between them.
|
|
203
|
+
*/
|
|
204
|
+
function follows(container, a, b) {
|
|
205
|
+
const chainA = flatChain(a, container);
|
|
206
|
+
const chainB = flatChain(b, container);
|
|
207
|
+
for (let i = 0; i < Math.max(chainA.length, chainB.length); i++) {
|
|
208
|
+
const [x, y] = [chainA[i], chainB[i]];
|
|
209
|
+
if (x === y)
|
|
210
|
+
continue;
|
|
211
|
+
if (!x)
|
|
212
|
+
return true;
|
|
213
|
+
if (!y)
|
|
214
|
+
return false;
|
|
215
|
+
return Boolean(x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Every element of a tabbable kind under `el` in the flattened tree, depth
|
|
221
|
+
* first, which is the order Tab visits them. Under a host whose shadow root
|
|
222
|
+
* is closed, that takes in the host's own children instead, rendered or not.
|
|
223
|
+
*/
|
|
224
|
+
function collectCandidates(el, out = []) {
|
|
225
|
+
for (const child of flatChildren(el)) {
|
|
226
|
+
if (isTabbableKind(child))
|
|
227
|
+
out.push(child);
|
|
228
|
+
collectCandidates(child, out);
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The first and last tab stops inside `container`, or `null` when there are
|
|
234
|
+
* none. Only the ends matter for wrapping, so the style checks run from each
|
|
235
|
+
* end until they find a stop rather than over every candidate.
|
|
236
|
+
*
|
|
237
|
+
* A radio group is one stop, the way the browser treats it: its checked
|
|
238
|
+
* button, or its first when none is checked. Counting every button would make
|
|
239
|
+
* the group's last one an end, and Tab from the checked one would leave. The
|
|
240
|
+
* group goes by name, form owner and tree, not by the trap, so a checked
|
|
241
|
+
* button outside the container that Tab can land on leaves the group no stop
|
|
242
|
+
* inside. One that Tab can't land on leaves the group as if none were checked.
|
|
243
|
+
*/
|
|
244
|
+
function findTabStops(container) {
|
|
245
|
+
const candidates = collectCandidates(container);
|
|
246
|
+
const checked = new Map();
|
|
247
|
+
const usable = (el) => {
|
|
248
|
+
let ok = checked.get(el);
|
|
249
|
+
if (ok === undefined) {
|
|
250
|
+
ok = isRenderedAndEnabled(el, container);
|
|
251
|
+
checked.set(el, ok);
|
|
252
|
+
}
|
|
253
|
+
return ok;
|
|
254
|
+
};
|
|
255
|
+
// Resolved once per group, filed under each of its buttons, since finding
|
|
256
|
+
// the checked one scans the radio's whole tree.
|
|
257
|
+
const groupStops = new Map();
|
|
258
|
+
const groupStop = (radio) => {
|
|
259
|
+
if (groupStops.has(radio))
|
|
260
|
+
return groupStops.get(radio);
|
|
261
|
+
const group = candidates.filter(el => sameGroup(radio, el));
|
|
262
|
+
const on = checkedInGroup(radio);
|
|
263
|
+
const stop = on && isTabbableKind(on) && usable(on)
|
|
264
|
+
? group.find(el => el === on)
|
|
265
|
+
: group.find(usable);
|
|
266
|
+
for (const el of [radio, ...group])
|
|
267
|
+
groupStops.set(el, stop);
|
|
268
|
+
return stop;
|
|
269
|
+
};
|
|
270
|
+
const isStop = (el) => usable(el) && (!isGroupedRadio(el) || groupStop(el) === el);
|
|
271
|
+
const first = candidates.find(isStop);
|
|
272
|
+
if (!first)
|
|
273
|
+
return null;
|
|
274
|
+
let last = first;
|
|
275
|
+
for (let i = candidates.length - 1; candidates[i] !== first; i--) {
|
|
276
|
+
if (isStop(candidates[i])) {
|
|
277
|
+
last = candidates[i];
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
first,
|
|
283
|
+
last,
|
|
284
|
+
stopFor: node => (isGroupedRadio(node) && groupStop(node)) || node,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The first tab stop inside `container`, found the way the trap finds it, or
|
|
289
|
+
* `null` when there is none. For a component that moves focus into a panel
|
|
290
|
+
* without trapping it there. `src/index.ts` names its exports from this
|
|
291
|
+
* module, so this one stays internal.
|
|
292
|
+
*/
|
|
293
|
+
function firstTabStop(container) {
|
|
294
|
+
return findTabStops(container)?.first ?? null;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The element that has focus in the container's own document (an iframe's,
|
|
298
|
+
* when it renders into one), inside open shadow roots too. Focus inside a
|
|
299
|
+
* closed one reads as its host, which the comparisons above place like any
|
|
300
|
+
* other element. Browsers fall back to <body> when nothing has
|
|
301
|
+
* focus. jsdom, where consumers run their tests, reports nothing once focus
|
|
302
|
+
* was inside a shadow root that was removed, so this falls back for it.
|
|
303
|
+
*/
|
|
304
|
+
const focusedElement = (doc) => getDeepestActiveElement(doc) ?? doc.body;
|
|
305
|
+
/**
|
|
306
|
+
* Keeps keyboard focus inside a container while it is active: focus moves in
|
|
307
|
+
* when the trap turns on, Tab and Shift+Tab wrap between the first and last
|
|
308
|
+
* tab stops, and focus goes back where it came from when the trap turns off.
|
|
309
|
+
*
|
|
310
|
+
* Tab stops are what the browser's Tab visits, in document order: links,
|
|
311
|
+
* form controls, frames, media with controls, a `<details>` summary, editable
|
|
312
|
+
* regions, anything with `tabIndex={0}`, and the content of open shadow
|
|
313
|
+
* roots. Hidden, disabled, inert and `tabIndex={-1}` elements are skipped,
|
|
314
|
+
* and a radio group counts once. Give the container `tabIndex={-1}` so it can
|
|
315
|
+
* hold focus itself when nothing inside can. The trap listens on the
|
|
316
|
+
* container, so a trap nested inside another handles Tab first and the outer
|
|
317
|
+
* one stands aside.
|
|
318
|
+
*
|
|
319
|
+
* The trap is about Tab. If a Tab it let through still takes focus out (a
|
|
320
|
+
* browser can leave out a stop the page has, such as links when its settings
|
|
321
|
+
* say to), it sends focus back to the other end. A pointer or a script moving
|
|
322
|
+
* focus out is left alone, because pulling focus back from a click is modal
|
|
323
|
+
* behaviour, and a modal also has to block the page behind it, which `Modal`
|
|
324
|
+
* does. Content the container renders through a portal lives elsewhere in
|
|
325
|
+
* the DOM, so it is outside the trap: render nested overlays inside the
|
|
326
|
+
* container, or give them a trap of their own. To trap content a `Portal`
|
|
327
|
+
* renders, pass a ref to the element inside the `Portal` as `containerRef`.
|
|
328
|
+
*
|
|
329
|
+
* The trap looks at `containerRef` again each time the component calling it
|
|
330
|
+
* renders. A container that mounts after the trap turns on, such as a panel
|
|
331
|
+
* waiting for a `Portal` target held in state, has it attach once that
|
|
332
|
+
* component renders with the container in the DOM. When the container leaves
|
|
333
|
+
* or is replaced, the trap lets go of it as it would turning off, handing
|
|
334
|
+
* focus back, and attaches to the next one.
|
|
335
|
+
* A child that mounts the container in a render of its own (from its own
|
|
336
|
+
* state, or as a `Suspense` boundary resolves) goes unseen until the
|
|
337
|
+
* component calling the hook renders again. The trap waits for hydration, so
|
|
338
|
+
* that component renders again when the page hydrates, and portaled content,
|
|
339
|
+
* which first appears then, is found.
|
|
340
|
+
*
|
|
341
|
+
* @function useFocusTrap
|
|
342
|
+
* @param containerRef - Ref to the element focus stays inside.
|
|
343
|
+
* @param options - When the trap is on, and where focus starts and ends.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* const panelRef = useRef<HTMLDivElement>(null);
|
|
347
|
+
* useFocusTrap(panelRef, { active: isOpen });
|
|
348
|
+
* return isOpen ? (
|
|
349
|
+
* <div ref={panelRef} role="dialog" aria-label="Filters" tabIndex={-1}>
|
|
350
|
+
* …
|
|
351
|
+
* </div>
|
|
352
|
+
* ) : null;
|
|
353
|
+
*/
|
|
354
|
+
function useFocusTrap(containerRef, options = {}) {
|
|
355
|
+
const { active = true, initialFocusRef, restoreFocus = true } = options;
|
|
356
|
+
// Portaled content has no server-rendered counterpart, so a portaled
|
|
357
|
+
// container only exists from the commit after hydration.
|
|
358
|
+
const hydrated = useIsHydrated();
|
|
359
|
+
// The container the trap is attached to, or `null` while it has none.
|
|
360
|
+
const heldRef = useRef(null);
|
|
361
|
+
// Bumped to run the trap again when the container in the ref changes.
|
|
362
|
+
const [refChanges, setRefChanges] = useState(0);
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
heldRef.current = null;
|
|
365
|
+
if (!active || !hydrated)
|
|
366
|
+
return undefined;
|
|
367
|
+
const container = containerRef.current;
|
|
368
|
+
if (!container)
|
|
369
|
+
return undefined;
|
|
370
|
+
heldRef.current = container;
|
|
371
|
+
const doc = container.ownerDocument;
|
|
372
|
+
const opener = focusedElement(doc);
|
|
373
|
+
// `initialFocusRef` counts only when focusing it puts focus inside. Focus
|
|
374
|
+
// put outside would stay out, as Tab there never reaches the container's
|
|
375
|
+
// listener, and focusing something that can't take focus (a heading
|
|
376
|
+
// without `tabIndex`, a disabled control) leaves focus where it was.
|
|
377
|
+
const initial = initialFocusRef?.current;
|
|
378
|
+
const inTrap = initial && inside(container, initial) ? initial : null;
|
|
379
|
+
inTrap?.focus();
|
|
380
|
+
if (!inTrap || !inside(container, focusedElement(doc))) {
|
|
381
|
+
(findTabStops(container)?.first ?? container).focus();
|
|
382
|
+
}
|
|
383
|
+
// Where focus goes if a Tab the trap let the browser handle takes it out,
|
|
384
|
+
// held until that Tab has finished moving focus.
|
|
385
|
+
let wrapTo = null;
|
|
386
|
+
let wrapTimer;
|
|
387
|
+
const handleKeyDown = (e) => {
|
|
388
|
+
// A trap nested inside this one has already wrapped focus.
|
|
389
|
+
if (e.key !== 'Tab' || e.defaultPrevented)
|
|
390
|
+
return;
|
|
391
|
+
const stops = findTabStops(container);
|
|
392
|
+
if (!stops) {
|
|
393
|
+
e.preventDefault();
|
|
394
|
+
container.focus();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const current = stops.stopFor(focusedElement(doc));
|
|
398
|
+
// Wrap whenever the browser has no stop left in that direction inside
|
|
399
|
+
// the container. Comparing positions rather than testing `=== first`
|
|
400
|
+
// also covers focus resting on the container or on an element outside
|
|
401
|
+
// the tab order, which the browser would otherwise walk straight out of.
|
|
402
|
+
if (e.shiftKey
|
|
403
|
+
? !follows(container, stops.first, current)
|
|
404
|
+
: !follows(container, current, stops.last)) {
|
|
405
|
+
e.preventDefault();
|
|
406
|
+
(e.shiftKey ? stops.last : stops.first).focus();
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
wrapTo = e.shiftKey ? stops.last : stops.first;
|
|
410
|
+
clearTimeout(wrapTimer);
|
|
411
|
+
wrapTimer = setTimeout(() => {
|
|
412
|
+
wrapTo = null;
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
// The browser moves focus as soon as the keydown is over, so focus that
|
|
416
|
+
// lands outside while `wrapTo` is set got there by that Tab.
|
|
417
|
+
const handleFocusIn = (e) => {
|
|
418
|
+
if (!wrapTo || inside(container, e.composedPath()[0]))
|
|
419
|
+
return;
|
|
420
|
+
const target = wrapTo;
|
|
421
|
+
wrapTo = null;
|
|
422
|
+
target.focus();
|
|
423
|
+
};
|
|
424
|
+
container.addEventListener('keydown', handleKeyDown);
|
|
425
|
+
doc.addEventListener('focusin', handleFocusIn, true);
|
|
426
|
+
return () => {
|
|
427
|
+
container.removeEventListener('keydown', handleKeyDown);
|
|
428
|
+
doc.removeEventListener('focusin', handleFocusIn, true);
|
|
429
|
+
clearTimeout(wrapTimer);
|
|
430
|
+
let target = restoreFocus ? opener : null;
|
|
431
|
+
// `null` is an object too, and a caller without types can pass it.
|
|
432
|
+
if (restoreFocus && typeof restoreFocus === 'object') {
|
|
433
|
+
// Read now rather than when the trap turned on: a trigger that
|
|
434
|
+
// re-mounted in between has a new node.
|
|
435
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
436
|
+
target = restoreFocus.current;
|
|
437
|
+
}
|
|
438
|
+
// Hand focus back only while the trap still holds it: inside the
|
|
439
|
+
// container, or dropped to <body> because the container left the page.
|
|
440
|
+
const now = focusedElement(doc);
|
|
441
|
+
if (target && (now === doc.body || inside(container, now))) {
|
|
442
|
+
target.focus();
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}, [
|
|
446
|
+
active,
|
|
447
|
+
hydrated,
|
|
448
|
+
containerRef,
|
|
449
|
+
initialFocusRef,
|
|
450
|
+
restoreFocus,
|
|
451
|
+
refChanges,
|
|
452
|
+
]);
|
|
453
|
+
// Nothing says when a ref is set, so after every render, a ref that no
|
|
454
|
+
// longer matches what the trap holds (a container that mounted, left or was
|
|
455
|
+
// replaced) runs it again. Effects run in order, so whenever the effect
|
|
456
|
+
// above ran in this commit, it read the ref just before this does, and a
|
|
457
|
+
// mismatch means the ref changed in a render it didn't run for. The render
|
|
458
|
+
// a bump asks for runs it, so the two match and the trap settles. An empty
|
|
459
|
+
// ref matches a trap holding nothing, so a container that never mounts
|
|
460
|
+
// costs no render.
|
|
461
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- after every render on purpose
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
if (active && hydrated && containerRef.current !== heldRef.current) {
|
|
464
|
+
setRefChanges(n => n + 1);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export { firstTabStop, useFocusTrap };
|
|
470
|
+
//# sourceMappingURL=useFocusTrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","sources":["../../../src/helpers/useFocusTrap.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { RefObject } from 'react';\nimport { useIsHydrated } from './useIsHydrated';\nimport { getDeepestActiveElement } from './shadowDom';\n\n/**\n * Whether `el` is editable while its parent is not, which makes it an editing\n * host: the one tab stop an editable region gets. `contenteditable=\"false\"`\n * turns editing off, and a missing or unknown value inherits the parent's.\n */\nfunction isEditingHost(el: Element): boolean {\n const editable = (node: Element): boolean | null => {\n const value = node.getAttribute('contenteditable')?.toLowerCase();\n if (value === undefined) return null;\n if (value === '' || value === 'true' || value === 'plaintext-only') {\n return true;\n }\n return value === 'false' ? false : null;\n };\n if (editable(el) !== true) return false;\n for (let node = el.parentElement; node; node = node.parentElement) {\n const state = editable(node);\n if (state !== null) return !state;\n }\n return true;\n}\n\n/** Whether `el` is the summary of its `<details>`: the first one, not a stray. */\nconst isDetailsSummary = (el: Element): boolean =>\n el.parentElement?.localName === 'details' &&\n Array.from(el.parentElement.children).find(\n child => child.localName === 'summary'\n ) === el;\n\n/**\n * Whether the browser puts `el` in the tab order, before anything that hides\n * or disables it. The `tabIndex` property can't answer this on its own: it\n * can read `-1` for an editable region or an `<embed>` that Tab still visits,\n * and `0` for a `<video>` without controls that it doesn't. So a valid\n * `tabindex` attribute decides, and otherwise the element's kind does.\n */\nfunction isTabbableKind(el: Element): boolean {\n const tabindex = el.getAttribute('tabindex');\n if (tabindex !== null && /^\\s*[+-]?\\d/.test(tabindex)) {\n return (el as HTMLElement).tabIndex >= 0;\n }\n switch (el.localName) {\n case 'a':\n case 'area':\n return el.hasAttribute('href');\n case 'input':\n return (el as HTMLInputElement).type !== 'hidden';\n case 'button':\n case 'select':\n case 'textarea':\n case 'iframe':\n case 'embed':\n case 'object':\n return true;\n case 'audio':\n case 'video':\n return el.hasAttribute('controls');\n case 'summary':\n return isDetailsSummary(el);\n default:\n return isEditingHost(el);\n }\n}\n\n/**\n * The node's parent in the flattened tree, the one the browser renders and\n * tabs through: the slot it is assigned to, else its parent, else the host of\n * the shadow root it tops, and nothing above the document. A closed shadow\n * root hides its slots (`assignedSlot` reads `null` under one), so a child of\n * its host goes straight to the host, whether a slot takes it or not.\n */\nconst flatParent = (node: Node): Node | null =>\n (node as Element).assignedSlot ??\n node.parentElement ??\n (node.parentNode as ShadowRoot | null)?.host ??\n null;\n\n/**\n * The element's children in the flattened tree, in the order they render: a\n * host's shadow root content, a slot's assigned elements (or its fallback\n * content when nothing is assigned), anything else's own children. A host\n * whose shadow root is closed has no root to read, so its own children stand\n * in, including any that no slot takes and that aren't rendered.\n */\nfunction flatChildren(el: Element): Element[] {\n if (el.shadowRoot) return Array.from(el.shadowRoot.children);\n if (el.localName === 'slot') {\n const assigned = (el as HTMLSlotElement).assignedNodes();\n if (assigned.length > 0) {\n return assigned.filter(\n (node): node is Element => node.nodeType === Node.ELEMENT_NODE\n );\n }\n }\n return Array.from(el.children);\n}\n\nconst isShown = (el: Element): boolean =>\n !el.hasAttribute('inert') && getComputedStyle(el).display !== 'none';\n\nconst isVisible = (el: Element): boolean => {\n const { visibility } = getComputedStyle(el);\n return visibility !== 'hidden' && visibility !== 'collapse';\n};\n\n/**\n * Whether nothing from `el` up to `top` hides it: `inert`, `display: none`\n * (not inherited, so each element is checked) or a closed `<details>` it\n * isn't the summary of. `top` itself isn't checked, and `null` walks to the\n * top of the page.\n */\nfunction isShownUpTo(el: Element, top: Node | null): boolean {\n let below: Element | null = null;\n for (\n let node: Element | null = el;\n node && node !== top;\n node = flatParent(node) as Element | null\n ) {\n if (!isShown(node)) return false;\n if (\n below &&\n node.localName === 'details' &&\n !node.hasAttribute('open') &&\n !isDetailsSummary(below)\n ) {\n return false;\n }\n below = node;\n }\n return true;\n}\n\n/**\n * The images that use the image map `area` belongs to. An image names its\n * map with `usemap=\"#…\"`, matching the map's `name` or `id`.\n */\nfunction imagesUsingMapOf(area: Element): Element[] {\n const map = area.closest('map');\n if (!map) return [];\n const names = [map.getAttribute('name'), map.id].filter(name => name);\n return Array.from(\n (area.getRootNode() as ParentNode).querySelectorAll('img[usemap]')\n ).filter(img => {\n const ref = img.getAttribute('usemap') as string;\n return ref.startsWith('#') && names.includes(ref.slice(1));\n });\n}\n\n/**\n * Whether an image map area is shown. An area has no box of its own: the\n * HTML rendering rules give it `display: none`, though a browser may not\n * report that. So it counts where an image using its map is shown, as long\n * as nothing makes it inert.\n */\nfunction isAreaShown(area: Element, container: Element): boolean {\n for (\n let node: Element | null = area;\n node && node !== container;\n node = flatParent(node) as Element | null\n ) {\n if (node.hasAttribute('inert')) return false;\n }\n return imagesUsingMapOf(area).some(\n img => isShownUpTo(img, null) && isVisible(img)\n );\n}\n\n/**\n * Whether Tab can land on `el`, one of the kinds it visits. A disabled control\n * (including one inside a disabled `<fieldset>`), an inert subtree and\n * anything not rendered are skipped. `visibility` is inherited, so the\n * element's own computed value covers its ancestors.\n */\nfunction isRenderedAndEnabled(el: Element, container: Element): boolean {\n if (el.matches(':disabled')) return false;\n if (el.localName === 'area') return isAreaShown(el, container);\n return isShownUpTo(el, container) && isVisible(el);\n}\n\n/** A radio button with a name, which shares one tab stop with its group. */\nconst isGroupedRadio = (el: Element): el is HTMLInputElement =>\n el.localName === 'input' &&\n (el as HTMLInputElement).type === 'radio' &&\n (el as HTMLInputElement).name !== '';\n\n/** Whether two radio buttons are in one group: same name, form owner and tree. */\nconst sameGroup = (a: HTMLInputElement, b: Element): b is HTMLInputElement =>\n isGroupedRadio(b) &&\n b.name === a.name &&\n b.form === a.form &&\n b.getRootNode() === a.getRootNode();\n\n/**\n * The checked button of `radio`'s group. The group isn't bounded by the trap,\n * so this looks through the radio's whole tree.\n */\nconst checkedInGroup = (radio: HTMLInputElement): Element | undefined =>\n Array.from(\n (radio.getRootNode() as ParentNode).querySelectorAll('input:checked')\n ).find(el => sameGroup(radio, el));\n\n/** The flattened-tree ancestors of `node` below the container, outermost first, then `node`. */\nfunction flatChain(node: Node, container: Node): Node[] {\n const chain: Node[] = [];\n for (let n: Node | null = node; n && n !== container; n = flatParent(n)) {\n chain.unshift(n);\n }\n return chain;\n}\n\n/**\n * Whether `node` is inside the container in the flattened tree: in it, in a\n * shadow root it holds, or slotted into it. A child of a closed-root host\n * counts as inside wherever the host is, as its slot can't be seen.\n */\nfunction inside(container: Node, node: Node): boolean {\n for (let n: Node | null = node; n; n = flatParent(n)) {\n if (n === container) return true;\n }\n return false;\n}\n\n/**\n * `true` when Tab reaches `b` after `a`, which is their order in the\n * flattened tree: a shadow host comes before its shadow root's content, and\n * slotted content comes where its slot is. A closed root's slots can't be\n * seen, so its host's children keep their place in the light DOM. Two\n * flattened-tree siblings are always in one DOM tree, so their document\n * position decides between them.\n */\nfunction follows(container: Element, a: Node, b: Node): boolean {\n const chainA = flatChain(a, container);\n const chainB = flatChain(b, container);\n for (let i = 0; i < Math.max(chainA.length, chainB.length); i++) {\n const [x, y] = [chainA[i], chainB[i]];\n if (x === y) continue;\n if (!x) return true;\n if (!y) return false;\n return Boolean(\n x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING\n );\n }\n return false;\n}\n\n/**\n * Every element of a tabbable kind under `el` in the flattened tree, depth\n * first, which is the order Tab visits them. Under a host whose shadow root\n * is closed, that takes in the host's own children instead, rendered or not.\n */\nfunction collectCandidates(\n el: Element,\n out: HTMLElement[] = []\n): HTMLElement[] {\n for (const child of flatChildren(el)) {\n if (isTabbableKind(child)) out.push(child as HTMLElement);\n collectCandidates(child, out);\n }\n return out;\n}\n\ninterface TabStops {\n first: HTMLElement;\n last: HTMLElement;\n /** The stop that stands for `node`: its group's stop for a radio button. */\n stopFor(node: Element): Element;\n}\n\n/**\n * The first and last tab stops inside `container`, or `null` when there are\n * none. Only the ends matter for wrapping, so the style checks run from each\n * end until they find a stop rather than over every candidate.\n *\n * A radio group is one stop, the way the browser treats it: its checked\n * button, or its first when none is checked. Counting every button would make\n * the group's last one an end, and Tab from the checked one would leave. The\n * group goes by name, form owner and tree, not by the trap, so a checked\n * button outside the container that Tab can land on leaves the group no stop\n * inside. One that Tab can't land on leaves the group as if none were checked.\n */\nfunction findTabStops(container: HTMLElement): TabStops | null {\n const candidates = collectCandidates(container);\n const checked = new Map<Element, boolean>();\n const usable = (el: Element): boolean => {\n let ok = checked.get(el);\n if (ok === undefined) {\n ok = isRenderedAndEnabled(el, container);\n checked.set(el, ok);\n }\n return ok;\n };\n // Resolved once per group, filed under each of its buttons, since finding\n // the checked one scans the radio's whole tree.\n const groupStops = new Map<Element, HTMLElement | undefined>();\n const groupStop = (radio: HTMLInputElement): HTMLElement | undefined => {\n if (groupStops.has(radio)) return groupStops.get(radio);\n const group = candidates.filter(el => sameGroup(radio, el));\n const on = checkedInGroup(radio);\n const stop =\n on && isTabbableKind(on) && usable(on)\n ? group.find(el => el === on)\n : group.find(usable);\n for (const el of [radio, ...group]) groupStops.set(el, stop);\n return stop;\n };\n const isStop = (el: HTMLElement): boolean =>\n usable(el) && (!isGroupedRadio(el) || groupStop(el) === el);\n\n const first = candidates.find(isStop);\n if (!first) return null;\n let last = first;\n for (let i = candidates.length - 1; candidates[i] !== first; i--) {\n if (isStop(candidates[i])) {\n last = candidates[i];\n break;\n }\n }\n return {\n first,\n last,\n stopFor: node => (isGroupedRadio(node) && groupStop(node)) || node,\n };\n}\n\n/**\n * The first tab stop inside `container`, found the way the trap finds it, or\n * `null` when there is none. For a component that moves focus into a panel\n * without trapping it there. `src/index.ts` names its exports from this\n * module, so this one stays internal.\n */\nexport function firstTabStop(container: HTMLElement): HTMLElement | null {\n return findTabStops(container)?.first ?? null;\n}\n\n/**\n * The element that has focus in the container's own document (an iframe's,\n * when it renders into one), inside open shadow roots too. Focus inside a\n * closed one reads as its host, which the comparisons above place like any\n * other element. Browsers fall back to <body> when nothing has\n * focus. jsdom, where consumers run their tests, reports nothing once focus\n * was inside a shadow root that was removed, so this falls back for it.\n */\nconst focusedElement = (doc: Document): Element =>\n getDeepestActiveElement(doc) ?? doc.body;\n\n/**\n * Options for `useFocusTrap`.\n */\nexport interface UseFocusTrapOptions {\n /**\n * Whether the trap is on. Turning it on moves focus into the container;\n * turning it off (or unmounting) releases Tab and restores focus.\n * @defaultValue true\n */\n active?: boolean;\n /**\n * The element inside the container to focus when the trap turns on. It has\n * to be one that can take focus, so a heading needs `tabIndex={-1}`. When\n * focusing it doesn't put focus inside the container (the ref is empty, or\n * its element is outside, disabled, hidden or can't take focus), focus goes\n * to the first tab stop inside the container, and to the container itself\n * when there is none.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus goes when the trap turns off. `true` returns it to the element\n * that had focus when the trap turned on; a ref sends it to that element\n * instead; `false` leaves it alone. Focus is only moved while the trap still\n * holds it, so a click that already put focus somewhere else outside the\n * container keeps it there.\n *\n * `true` reads focus after the container's content has mounted, so content\n * that focuses itself as it mounts (an `autoFocus` input) hides the element\n * that opened it. And some browsers don't focus a button when it is\n * clicked. For a panel opened from a button, pass the button's ref.\n * @defaultValue true\n */\n restoreFocus?: boolean | RefObject<HTMLElement | null>;\n}\n\n/**\n * Keeps keyboard focus inside a container while it is active: focus moves in\n * when the trap turns on, Tab and Shift+Tab wrap between the first and last\n * tab stops, and focus goes back where it came from when the trap turns off.\n *\n * Tab stops are what the browser's Tab visits, in document order: links,\n * form controls, frames, media with controls, a `<details>` summary, editable\n * regions, anything with `tabIndex={0}`, and the content of open shadow\n * roots. Hidden, disabled, inert and `tabIndex={-1}` elements are skipped,\n * and a radio group counts once. Give the container `tabIndex={-1}` so it can\n * hold focus itself when nothing inside can. The trap listens on the\n * container, so a trap nested inside another handles Tab first and the outer\n * one stands aside.\n *\n * The trap is about Tab. If a Tab it let through still takes focus out (a\n * browser can leave out a stop the page has, such as links when its settings\n * say to), it sends focus back to the other end. A pointer or a script moving\n * focus out is left alone, because pulling focus back from a click is modal\n * behaviour, and a modal also has to block the page behind it, which `Modal`\n * does. Content the container renders through a portal lives elsewhere in\n * the DOM, so it is outside the trap: render nested overlays inside the\n * container, or give them a trap of their own. To trap content a `Portal`\n * renders, pass a ref to the element inside the `Portal` as `containerRef`.\n *\n * The trap looks at `containerRef` again each time the component calling it\n * renders. A container that mounts after the trap turns on, such as a panel\n * waiting for a `Portal` target held in state, has it attach once that\n * component renders with the container in the DOM. When the container leaves\n * or is replaced, the trap lets go of it as it would turning off, handing\n * focus back, and attaches to the next one.\n * A child that mounts the container in a render of its own (from its own\n * state, or as a `Suspense` boundary resolves) goes unseen until the\n * component calling the hook renders again. The trap waits for hydration, so\n * that component renders again when the page hydrates, and portaled content,\n * which first appears then, is found.\n *\n * @function useFocusTrap\n * @param containerRef - Ref to the element focus stays inside.\n * @param options - When the trap is on, and where focus starts and ends.\n *\n * @example\n * const panelRef = useRef<HTMLDivElement>(null);\n * useFocusTrap(panelRef, { active: isOpen });\n * return isOpen ? (\n * <div ref={panelRef} role=\"dialog\" aria-label=\"Filters\" tabIndex={-1}>\n * …\n * </div>\n * ) : null;\n */\nexport function useFocusTrap(\n containerRef: RefObject<HTMLElement | null>,\n options: UseFocusTrapOptions = {}\n): void {\n const { active = true, initialFocusRef, restoreFocus = true } = options;\n // Portaled content has no server-rendered counterpart, so a portaled\n // container only exists from the commit after hydration.\n const hydrated = useIsHydrated();\n // The container the trap is attached to, or `null` while it has none.\n const heldRef = useRef<HTMLElement | null>(null);\n // Bumped to run the trap again when the container in the ref changes.\n const [refChanges, setRefChanges] = useState(0);\n\n useEffect(() => {\n heldRef.current = null;\n if (!active || !hydrated) return undefined;\n const container = containerRef.current;\n if (!container) return undefined;\n heldRef.current = container;\n const doc = container.ownerDocument;\n\n const opener = focusedElement(doc) as HTMLElement;\n\n // `initialFocusRef` counts only when focusing it puts focus inside. Focus\n // put outside would stay out, as Tab there never reaches the container's\n // listener, and focusing something that can't take focus (a heading\n // without `tabIndex`, a disabled control) leaves focus where it was.\n const initial = initialFocusRef?.current;\n const inTrap = initial && inside(container, initial) ? initial : null;\n inTrap?.focus();\n if (!inTrap || !inside(container, focusedElement(doc))) {\n (findTabStops(container)?.first ?? container).focus();\n }\n\n // Where focus goes if a Tab the trap let the browser handle takes it out,\n // held until that Tab has finished moving focus.\n let wrapTo: HTMLElement | null = null;\n let wrapTimer: ReturnType<typeof setTimeout> | undefined;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n // A trap nested inside this one has already wrapped focus.\n if (e.key !== 'Tab' || e.defaultPrevented) return;\n const stops = findTabStops(container);\n if (!stops) {\n e.preventDefault();\n container.focus();\n return;\n }\n const current = stops.stopFor(focusedElement(doc));\n // Wrap whenever the browser has no stop left in that direction inside\n // the container. Comparing positions rather than testing `=== first`\n // also covers focus resting on the container or on an element outside\n // the tab order, which the browser would otherwise walk straight out of.\n if (\n e.shiftKey\n ? !follows(container, stops.first, current)\n : !follows(container, current, stops.last)\n ) {\n e.preventDefault();\n (e.shiftKey ? stops.last : stops.first).focus();\n return;\n }\n wrapTo = e.shiftKey ? stops.last : stops.first;\n clearTimeout(wrapTimer);\n wrapTimer = setTimeout(() => {\n wrapTo = null;\n });\n };\n\n // The browser moves focus as soon as the keydown is over, so focus that\n // lands outside while `wrapTo` is set got there by that Tab.\n const handleFocusIn = (e: FocusEvent) => {\n if (!wrapTo || inside(container, e.composedPath()[0] as Node)) return;\n const target = wrapTo;\n wrapTo = null;\n target.focus();\n };\n\n container.addEventListener('keydown', handleKeyDown);\n doc.addEventListener('focusin', handleFocusIn, true);\n return () => {\n container.removeEventListener('keydown', handleKeyDown);\n doc.removeEventListener('focusin', handleFocusIn, true);\n clearTimeout(wrapTimer);\n let target = restoreFocus ? opener : null;\n // `null` is an object too, and a caller without types can pass it.\n if (restoreFocus && typeof restoreFocus === 'object') {\n // Read now rather than when the trap turned on: a trigger that\n // re-mounted in between has a new node.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n target = restoreFocus.current;\n }\n // Hand focus back only while the trap still holds it: inside the\n // container, or dropped to <body> because the container left the page.\n const now = focusedElement(doc);\n if (target && (now === doc.body || inside(container, now))) {\n target.focus();\n }\n };\n }, [\n active,\n hydrated,\n containerRef,\n initialFocusRef,\n restoreFocus,\n refChanges,\n ]);\n\n // Nothing says when a ref is set, so after every render, a ref that no\n // longer matches what the trap holds (a container that mounted, left or was\n // replaced) runs it again. Effects run in order, so whenever the effect\n // above ran in this commit, it read the ref just before this does, and a\n // mismatch means the ref changed in a render it didn't run for. The render\n // a bump asks for runs it, so the two match and the trap settles. An empty\n // ref matches a trap holding nothing, so a container that never mounts\n // costs no render.\n // eslint-disable-next-line react-hooks/exhaustive-deps -- after every render on purpose\n useEffect(() => {\n if (active && hydrated && containerRef.current !== heldRef.current) {\n setRefChanges(n => n + 1);\n }\n });\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;AAIG;AACH,SAAS,aAAa,CAAC,EAAW,EAAA;AAChC,IAAA,MAAM,QAAQ,GAAG,CAAC,IAAa,KAAoB;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE;QACjE,IAAI,KAAK,KAAK,SAAS;AAAE,YAAA,OAAO,IAAI;AACpC,QAAA,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,gBAAgB,EAAE;AAClE,YAAA,OAAO,IAAI;QACb;QACA,OAAO,KAAK,KAAK,OAAO,GAAG,KAAK,GAAG,IAAI;AACzC,IAAA,CAAC;AACD,IAAA,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI;AAAE,QAAA,OAAO,KAAK;AACvC,IAAA,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE;AACjE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;QACpD,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC;AACpD,QAAA,OAAO,MAAK;AACV,YAAA,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC;YACvD,GAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC;YACvD,YAAY,CAAC,SAAS,CAAC;YACvB,IAAI,MAAM,GAAG,YAAY,GAAG,MAAM,GAAG,IAAI;;AAEzC,YAAA,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;;;;AAIpD,gBAAA,MAAM,GAAG,YAAY,CAAC,OAAO;YAC/B;;;AAGA,YAAA,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC;AAC/B,YAAA,IAAI,MAAM,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,EAAE;gBAC1D,MAAM,CAAC,KAAK,EAAE;YAChB;AACF,QAAA,CAAC;AACH,IAAA,CAAC,EAAE;QACD,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;QACf,YAAY;QACZ,UAAU;AACX,KAAA,CAAC;;;;;;;;;;IAWF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,MAAM,IAAI,QAAQ,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE;YAClE,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B;AACF,IAAA,CAAC,CAAC;AACJ;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* @allxsmith/bestax-bulma — AI agents: see AGENTS.md in the package root, or https://bestax.io/llms.txt */
|
|
2
|
+
import { useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
// "Are we past hydration?" as a store that never changes: React reads the
|
|
5
|
+
// server snapshot both while server-rendering and while hydrating, and the
|
|
6
|
+
// client snapshot from the first post-hydration render onward.
|
|
7
|
+
const subscribeToNothing = () => () => { };
|
|
8
|
+
const getClientSnapshot = () => true;
|
|
9
|
+
const getServerSnapshot = () => false;
|
|
10
|
+
/**
|
|
11
|
+
* Reports whether the component has passed hydration.
|
|
12
|
+
*
|
|
13
|
+
* Returns `false` during server rendering and during the hydrating client
|
|
14
|
+
* render, then `true` from the commit that follows. Use it to defer
|
|
15
|
+
* DOM-only behaviour (such as portalling) past hydration so the first client
|
|
16
|
+
* render matches the server markup instead of tripping hydration recovery.
|
|
17
|
+
*
|
|
18
|
+
* Only a component that hydrates ever sees `false` on the client. One that
|
|
19
|
+
* mounts later (after a route change, or in an app with no server rendering)
|
|
20
|
+
* gets `true` on its first render, so it pays for no extra render. It
|
|
21
|
+
* subscribes to nothing, so no later render flips it back.
|
|
22
|
+
*
|
|
23
|
+
* @function useIsHydrated
|
|
24
|
+
* @returns `true` once the hydrating render has completed, otherwise `false`.
|
|
25
|
+
*/
|
|
26
|
+
function useIsHydrated() {
|
|
27
|
+
return useSyncExternalStore(subscribeToNothing, getClientSnapshot, getServerSnapshot);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { useIsHydrated };
|
|
31
|
+
//# sourceMappingURL=useIsHydrated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsHydrated.js","sources":["../../../src/helpers/useIsHydrated.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\n// \"Are we past hydration?\" as a store that never changes: React reads the\n// server snapshot both while server-rendering and while hydrating, and the\n// client snapshot from the first post-hydration render onward.\nconst subscribeToNothing = () => () => {};\nconst getClientSnapshot = () => true;\nconst getServerSnapshot = () => false;\n\n/**\n * Reports whether the component has passed hydration.\n *\n * Returns `false` during server rendering and during the hydrating client\n * render, then `true` from the commit that follows. Use it to defer\n * DOM-only behaviour (such as portalling) past hydration so the first client\n * render matches the server markup instead of tripping hydration recovery.\n *\n * Only a component that hydrates ever sees `false` on the client. One that\n * mounts later (after a route change, or in an app with no server rendering)\n * gets `true` on its first render, so it pays for no extra render. It\n * subscribes to nothing, so no later render flips it back.\n *\n * @function useIsHydrated\n * @returns `true` once the hydrating render has completed, otherwise `false`.\n */\nexport function useIsHydrated(): boolean {\n return useSyncExternalStore(\n subscribeToNothing,\n getClientSnapshot,\n getServerSnapshot\n );\n}\n"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG,MAAM,MAAK,EAAE,CAAC;AACzC,MAAM,iBAAiB,GAAG,MAAM,IAAI;AACpC,MAAM,iBAAiB,GAAG,MAAM,KAAK;AAErC;;;;;;;;;;;;;;;AAeG;SACa,aAAa,GAAA;IAC3B,OAAO,oBAAoB,CACzB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,CAClB;AACH;;"}
|