@zj-dynamics/components 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE.react-is +21 -0
- package/NOTICE.tabbable +22 -0
- package/README.md +23 -2
- package/compatibility.css +2 -0
- package/dist/Button.d.ts +90 -0
- package/dist/Button.js +58 -0
- package/dist/ButtonDismiss.d.ts +6 -0
- package/dist/ButtonDismiss.js +5 -0
- package/dist/Dialog.d.ts +75 -0
- package/dist/Dialog.js +59 -0
- package/dist/Icon.d.ts +20 -0
- package/dist/Icon.js +11 -0
- package/dist/InputText.d.ts +26 -0
- package/dist/InputText.js +63 -0
- package/dist/Switch.d.ts +8 -0
- package/dist/Switch.js +19 -0
- package/dist/Toast.d.ts +21 -0
- package/dist/Toast.js +58 -0
- package/dist/browserFocus.d.ts +11 -0
- package/dist/browserFocus.js +85 -0
- package/dist/browserHooks.d.ts +5 -0
- package/dist/browserHooks.js +4 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +91 -0
- package/dist/legacyModalPortal.d.ts +1 -0
- package/dist/legacyModalPortal.js +2 -0
- package/dist/mockViewportWidth.d.ts +5 -0
- package/dist/mockViewportWidth.js +58 -0
- package/dist/slotChildren.d.ts +2 -0
- package/dist/slotChildren.js +6 -0
- package/dist/theme.d.ts +26 -0
- package/dist/theme.js +65 -0
- package/dist/unstyledPrimitives.d.ts +12 -0
- package/dist/unstyledPrimitives.js +12 -0
- package/dist/useBreakpoints.d.ts +3 -0
- package/dist/useBreakpoints.js +2 -0
- package/dist/useFocusTrap.d.ts +1 -0
- package/dist/useFocusTrap.js +1 -0
- package/dist/useInView.d.ts +1 -0
- package/dist/useInView.js +1 -0
- package/dist/useIsSmallScreen.d.ts +1 -0
- package/dist/useIsSmallScreen.js +1 -0
- package/dist/useLiveAnnounce.d.ts +1 -0
- package/dist/useLiveAnnounce.js +1 -0
- package/dist/useOnKeyDown.d.ts +1 -0
- package/dist/useOnKeyDown.js +1 -0
- package/dist/useRefocusOnActivator.d.ts +1 -0
- package/dist/useRefocusOnActivator.js +1 -0
- package/dist/useResizeObserver.d.ts +22 -0
- package/dist/useResizeObserver.js +47 -0
- package/dist/useWindowDimensions.d.ts +2 -0
- package/dist/useWindowDimensions.js +1 -0
- package/dist/viewport.d.ts +46 -0
- package/dist/viewport.js +141 -0
- package/foundation/ActivityIndicator/ActivityIndicator.d.ts +38 -0
- package/foundation/ActivityIndicator/index.d.mts +2 -0
- package/foundation/ActivityIndicator/index.mjs +6 -0
- package/foundation/ActivityIndicator-es.js +30 -0
- package/foundation/Autocomplete/Autocomplete.d.ts +8 -0
- package/foundation/Autocomplete/Autocomplete.types.d.ts +401 -0
- package/foundation/Autocomplete/hooks/useAutocompleteListNav.d.ts +30 -0
- package/foundation/Autocomplete/index.d.mts +3 -0
- package/foundation/Autocomplete/index.mjs +39 -0
- package/foundation/Autocomplete/utils/interactionUtils.d.ts +14 -0
- package/foundation/Autocomplete-es.js +1322 -0
- package/foundation/Avatar/Avatar.d.ts +77 -0
- package/foundation/Avatar/index.d.mts +1 -0
- package/foundation/Avatar/index.mjs +6 -0
- package/foundation/Avatar-es.js +80 -0
- package/foundation/Banner/Banner.d.ts +10 -0
- package/foundation/Banner/Banner.types.d.ts +165 -0
- package/foundation/Banner/index.d.mts +2 -0
- package/foundation/Banner/index.mjs +14 -0
- package/foundation/Banner-es.js +134 -0
- package/foundation/Body-es.js +45 -0
- package/foundation/BottomSheet-es.js +110 -0
- package/foundation/Box/Box.d.ts +3 -0
- package/foundation/Box/Box.types.d.ts +40 -0
- package/foundation/Box/index.d.mts +1 -0
- package/foundation/Box/index.mjs +4 -0
- package/foundation/Box-es.js +130 -0
- package/foundation/Button/Button.d.ts +17 -0
- package/foundation/Button/Button.types.d.ts +112 -0
- package/foundation/Button/ButtonInternals.d.ts +11 -0
- package/foundation/Button/ButtonProvider.d.ts +11 -0
- package/foundation/Button/index.d.mts +4 -0
- package/foundation/Button/useButtonStyles.d.ts +17 -0
- package/foundation/Button-es.js +122 -0
- package/foundation/ButtonDismiss/ButtonDismiss.d.ts +6 -0
- package/foundation/ButtonDismiss/index.d.mts +1 -0
- package/foundation/ButtonDismiss-es.js +9 -0
- package/foundation/Card/Card.d.ts +78 -0
- package/foundation/Card/cardcolors.module.d.ts +90 -0
- package/foundation/Card/index.d.mts +1 -0
- package/foundation/Card/index.mjs +37 -0
- package/foundation/Card/types.d.ts +63 -0
- package/foundation/Card-es.js +138 -0
- package/foundation/Checkbox/Checkbox.d.ts +7 -0
- package/foundation/Checkbox/Checkbox.types.d.ts +51 -0
- package/foundation/Checkbox/index.d.mts +2 -0
- package/foundation/Checkbox/index.mjs +8 -0
- package/foundation/Checkbox-es.js +57 -0
- package/foundation/Chip/Chip.d.ts +14 -0
- package/foundation/Chip/Chip.types.d.ts +70 -0
- package/foundation/Chip/components/ChipDismissible/ChipDismissible.d.ts +3 -0
- package/foundation/Chip/components/ChipPrefix/Chip.Prefix.d.ts +3 -0
- package/foundation/Chip/components/ChipSelectable/ChipSelectable.d.ts +3 -0
- package/foundation/Chip/components/ChipSuffix/Chip.Suffix.d.ts +9 -0
- package/foundation/Chip/index.d.mts +4 -0
- package/foundation/Chip/index.mjs +19 -0
- package/foundation/Chip-es.js +165 -0
- package/foundation/ChipDismissible-es.js +19 -0
- package/foundation/Chips/Chip.d.ts +9 -0
- package/foundation/Chips/ChipDismissible.d.ts +11 -0
- package/foundation/Chips/ChipTypes.d.ts +59 -0
- package/foundation/Chips/Chips.d.ts +8 -0
- package/foundation/Chips/ChipsTypes.d.ts +106 -0
- package/foundation/Chips/InternalChipButton.d.ts +11 -0
- package/foundation/Chips/index.d.mts +3 -0
- package/foundation/Chips/index.mjs +56 -0
- package/foundation/Chips-es.js +114 -0
- package/foundation/Cluster/Cluster.d.ts +3 -0
- package/foundation/Cluster/index.d.mts +2 -0
- package/foundation/Cluster/index.mjs +4 -0
- package/foundation/Cluster/types.d.ts +47 -0
- package/foundation/Cluster-es.js +12 -0
- package/foundation/Combobox/Combobox.d.ts +71 -0
- package/foundation/Combobox/Combobox.footer.d.ts +7 -0
- package/foundation/Combobox/Combobox.items.d.ts +25 -0
- package/foundation/Combobox/Combobox.selectAll.d.ts +4 -0
- package/foundation/Combobox/Combobox.slotFactory.d.ts +7 -0
- package/foundation/Combobox/Combobox.types.d.ts +168 -0
- package/foundation/Combobox/index.d.mts +2 -0
- package/foundation/Combobox/index.mjs +28 -0
- package/foundation/Combobox-es.js +782 -0
- package/foundation/ComboboxPrimitive-es.js +187 -0
- package/foundation/ComboboxSeparator-es.js +3541 -0
- package/foundation/ComponentSettingsContext/ComponentSettingsContext.d.ts +41 -0
- package/foundation/ComponentSettingsContext/index.d.mts +4 -0
- package/foundation/ComponentSettingsContext/index.mjs +5 -0
- package/foundation/ComponentSettingsContext-es.js +18 -0
- package/foundation/ConfirmationModal/ConfirmationModal.d.ts +79 -0
- package/foundation/ConfirmationModal/index.d.mts +1 -0
- package/foundation/ConfirmationModal/index.mjs +37 -0
- package/foundation/ConfirmationModal-es.js +111 -0
- package/foundation/Container/Container.d.ts +6 -0
- package/foundation/Container/index.d.mts +1 -0
- package/foundation/Container/index.mjs +3 -0
- package/foundation/Container/types.d.ts +22 -0
- package/foundation/Container-es.js +16 -0
- package/foundation/Content/Content.d.ts +22 -0
- package/foundation/Content/Spacing.module.d.ts +14 -0
- package/foundation/Content/index.d.mts +1 -0
- package/foundation/Content/index.mjs +3 -0
- package/foundation/Content-es.js +13 -0
- package/foundation/ContentBlock/ContentBlock.d.ts +3 -0
- package/foundation/ContentBlock/index.d.mts +2 -0
- package/foundation/ContentBlock/index.mjs +4 -0
- package/foundation/ContentBlock/types.d.ts +37 -0
- package/foundation/ContentBlock-es.js +29 -0
- package/foundation/Countdown/Countdown.d.ts +30 -0
- package/foundation/Countdown/index.d.mts +1 -0
- package/foundation/Countdown/index.mjs +4 -0
- package/foundation/Countdown-es.js +649 -0
- package/foundation/Cover/Cover.d.ts +6 -0
- package/foundation/Cover/index.d.mts +2 -0
- package/foundation/Cover/index.mjs +4 -0
- package/foundation/Cover/types.d.ts +34 -0
- package/foundation/Cover-es.js +14 -0
- package/foundation/DataDump/DataDump.d.ts +21 -0
- package/foundation/DataDump/index.d.mts +1 -0
- package/foundation/DataDump/index.mjs +40 -0
- package/foundation/DataDump-es.js +26 -0
- package/foundation/DataList/DataList.const.d.ts +22 -0
- package/foundation/DataList/DataList.d.ts +28 -0
- package/foundation/DataList/DataList.types.d.ts +323 -0
- package/foundation/DataList/components/DataListAction/DataListAction.d.ts +3 -0
- package/foundation/DataList/components/DataListAction/index.d.mts +1 -0
- package/foundation/DataList/components/DataListBulkActions/DataListBulkActions.d.ts +4 -0
- package/foundation/DataList/components/DataListBulkActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListEmptyState/DataListEmptyState.d.ts +4 -0
- package/foundation/DataList/components/DataListEmptyState/index.d.mts +1 -0
- package/foundation/DataList/components/DataListFilters/DataListFilters.d.ts +11 -0
- package/foundation/DataList/components/DataListFilters/index.d.mts +1 -0
- package/foundation/DataList/components/DataListItemActions/DataListItemActions.d.ts +9 -0
- package/foundation/DataList/components/DataListItemActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayout/DataListLayout.d.ts +3 -0
- package/foundation/DataList/components/DataListLayout/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayoutActions/DataListLayoutActions.d.ts +2 -0
- package/foundation/DataList/components/DataListLayoutActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListSearch/DataListSearch.d.ts +8 -0
- package/foundation/DataList/components/DataListSearch/index.d.mts +1 -0
- package/foundation/DataList/components/DataListStatusBar/DataListStatusBar.d.ts +11 -0
- package/foundation/DataList/components/DataListStatusBar/index.d.mts +1 -0
- package/foundation/DataList/index.d.mts +2 -0
- package/foundation/DataList/index.mjs +96 -0
- package/foundation/DataList-es.js +141 -0
- package/foundation/DataList.const-es.js +26 -0
- package/foundation/DataList.module-es.js +3 -0
- package/foundation/DataList.utils-es.js +167 -0
- package/foundation/DataListAction-es.js +43 -0
- package/foundation/DataListActions-es.js +53 -0
- package/foundation/DataListActionsMenu-es.js +52 -0
- package/foundation/DataListBulkActions-es.js +28 -0
- package/foundation/DataListContext-es.js +26 -0
- package/foundation/DataListEmptyState-es.js +54 -0
- package/foundation/DataListFilters-es.js +43 -0
- package/foundation/DataListHeader-es.js +130 -0
- package/foundation/DataListHeaderTile-es.js +86 -0
- package/foundation/DataListItem-es.js +118 -0
- package/foundation/DataListItemActions-es.js +29 -0
- package/foundation/DataListItemActionsOverflow-es.js +34 -0
- package/foundation/DataListItemClickable-es.js +45 -0
- package/foundation/DataListItems-es.js +19 -0
- package/foundation/DataListLayout-es.js +19 -0
- package/foundation/DataListLayoutActions-es.js +36 -0
- package/foundation/DataListLayoutContext-es.js +14 -0
- package/foundation/DataListLayoutContext-es2.js +8 -0
- package/foundation/DataListLoadMore-es.js +32 -0
- package/foundation/DataListLoadingState-es.js +22 -0
- package/foundation/DataListOverflowFade-es.js +22 -0
- package/foundation/DataListSearch-es.js +84 -0
- package/foundation/DataListSort-es.js +74 -0
- package/foundation/DataListSortingOptions-es.js +34 -0
- package/foundation/DataListStatusBar-es.js +22 -0
- package/foundation/DataListStickyHeader-es.js +23 -0
- package/foundation/DataListTags-es.js +62 -0
- package/foundation/DataListTotalCount-es.js +38 -0
- package/foundation/DataTable/DataTable.d.ts +74 -0
- package/foundation/DataTable/SortIcon.d.ts +11 -0
- package/foundation/DataTable/components/DataTableActions.d.ts +2 -0
- package/foundation/DataTable/components/DataTableBody.d.ts +2 -0
- package/foundation/DataTable/components/DataTableCell.d.ts +2 -0
- package/foundation/DataTable/components/DataTableContainer.d.ts +2 -0
- package/foundation/DataTable/components/DataTableFooter.d.ts +5 -0
- package/foundation/DataTable/components/DataTableHeader.d.ts +2 -0
- package/foundation/DataTable/components/DataTableHeaderCell.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePagination.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePaginationButton.d.ts +21 -0
- package/foundation/DataTable/components/DataTableRow.d.ts +2 -0
- package/foundation/DataTable/components/DataTableRowActions.d.ts +4 -0
- package/foundation/DataTable/components/DataTableSortableHeader.d.ts +24 -0
- package/foundation/DataTable/components/DataTableTable.d.ts +11 -0
- package/foundation/DataTable/components/index.d.mts +13 -0
- package/foundation/DataTable/index.d.mts +6 -0
- package/foundation/DataTable/index.mjs +29 -0
- package/foundation/DataTable/test-utilities/helpers.d.ts +1 -0
- package/foundation/DataTable/types.d.ts +83 -0
- package/foundation/DataTable-es.js +262 -0
- package/foundation/DataTableTable-es.js +117 -0
- package/foundation/DatePicker/DatePicker.d.ts +74 -0
- package/foundation/DatePicker/DatePickerActivator.d.ts +18 -0
- package/foundation/DatePicker/index.d.mts +1 -0
- package/foundation/DatePicker/index.mjs +26 -0
- package/foundation/DatePicker-es.js +13627 -0
- package/foundation/Dialog/dialogReturnFocus.d.ts +43 -0
- package/foundation/Disclosure/Disclosure.d.ts +68 -0
- package/foundation/Disclosure/index.d.mts +1 -0
- package/foundation/Disclosure/index.mjs +7 -0
- package/foundation/Disclosure-es.js +46 -0
- package/foundation/Divider/Divider.d.ts +39 -0
- package/foundation/Divider/DividerDirections.module.d.ts +6 -0
- package/foundation/Divider/DividerSizes.module.d.ts +8 -0
- package/foundation/Divider/index.d.mts +1 -0
- package/foundation/Divider/index.mjs +3 -0
- package/foundation/Divider-es.js +15 -0
- package/foundation/Drawer/Drawer.d.ts +14 -0
- package/foundation/Drawer/DrawerGrid.d.ts +7 -0
- package/foundation/Drawer/index.d.mts +2 -0
- package/foundation/Drawer/index.mjs +13 -0
- package/foundation/DrawerGrid-es.js +39 -0
- package/foundation/DrawerTitle-es.js +90 -0
- package/foundation/Emphasis/Emphasis.d.ts +12 -0
- package/foundation/Emphasis/index.d.mts +1 -0
- package/foundation/Emphasis/index.mjs +4 -0
- package/foundation/Emphasis-es.js +13 -0
- package/foundation/FeatureSwitch/FeatureSwitch.d.ts +52 -0
- package/foundation/FeatureSwitch/index.d.mts +1 -0
- package/foundation/FeatureSwitch/index.mjs +20 -0
- package/foundation/FeatureSwitch-es.js +66 -0
- package/foundation/FieldDescription-es.js +859 -0
- package/foundation/FilterPicker/FilterPicker.d.ts +11 -0
- package/foundation/FilterPicker/FilterPicker.types.d.ts +282 -0
- package/foundation/FilterPicker/FilterPickerProvider.d.ts +18 -0
- package/foundation/FilterPicker/components/FilterPickerAction/FilterPickerAction.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerAction/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/FilterPickerActivator.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerOption/FilterPickerOption.d.ts +3 -0
- package/foundation/FilterPicker/index.d.mts +3 -0
- package/foundation/FilterPicker/index.mjs +49 -0
- package/foundation/FilterPicker-es.js +110 -0
- package/foundation/FilterPicker.messages-es.js +56 -0
- package/foundation/FilterPickerAction-es.js +30 -0
- package/foundation/FilterPickerActivator-es.js +36 -0
- package/foundation/FilterPickerContent-es.js +180 -0
- package/foundation/FilterPickerContentHeader-es.js +23 -0
- package/foundation/FilterPickerContentList-es.js +74 -0
- package/foundation/FilterPickerContentSearch-es.js +35 -0
- package/foundation/FilterPickerLoadMore-es.js +14 -0
- package/foundation/FilterPickerOption-es.js +29 -0
- package/foundation/FilterPickerProvider-es.js +10 -0
- package/foundation/FilterPickerTrigger-es.js +19 -0
- package/foundation/Flex/Flex.d.ts +33 -0
- package/foundation/Flex/Flex.types.d.ts +6 -0
- package/foundation/Flex/index.d.mts +1 -0
- package/foundation/Flex/index.mjs +3 -0
- package/foundation/Flex-es.js +28 -0
- package/foundation/FormField/FormFieldAffix.d.ts +19 -0
- package/foundation/FormField/FormFieldTypes.d.ts +185 -0
- package/foundation/FormField/FormFieldWrapper.d.ts +57 -0
- package/foundation/FormField/hooks/useFormFieldName.d.ts +6 -0
- package/foundation/FormField/hooks/useFormFieldWrapperStyles.d.ts +35 -0
- package/foundation/FormField/index.d.mts +5 -0
- package/foundation/FormField/index.mjs +17 -0
- package/foundation/FormFieldPostFix-es.js +13 -0
- package/foundation/FormFieldWrapper-es.js +233 -0
- package/foundation/FormatFile/FormatFile.d.ts +42 -0
- package/foundation/FormatFile/index.d.mts +4 -0
- package/foundation/FormatFile/index.mjs +42 -0
- package/foundation/FormatFile/types.d.ts +27 -0
- package/foundation/FormatFile/useFormatFile.d.ts +5 -0
- package/foundation/FormatFile/useFormatFileStyles.d.ts +10 -0
- package/foundation/FormatFile-es.js +137 -0
- package/foundation/Frame/Frame.d.ts +3 -0
- package/foundation/Frame/index.d.mts +2 -0
- package/foundation/Frame/index.mjs +3 -0
- package/foundation/Frame/types.d.ts +24 -0
- package/foundation/Frame-es.js +10 -0
- package/foundation/Gallery/Gallery.d.ts +3 -0
- package/foundation/Gallery/GalleryTypes.d.ts +36 -0
- package/foundation/Gallery/index.d.mts +3 -0
- package/foundation/Gallery/index.mjs +64 -0
- package/foundation/Gallery-es.js +88 -0
- package/foundation/Glimmer/Glimmer.d.ts +71 -0
- package/foundation/Glimmer/index.d.mts +1 -0
- package/foundation/Glimmer/index.mjs +5 -0
- package/foundation/Glimmer/style/Shape.module.d.ts +9 -0
- package/foundation/Glimmer/style/Sizes.module.d.ts +10 -0
- package/foundation/Glimmer/style/Timing.module.d.ts +6 -0
- package/foundation/Glimmer-es.js +53 -0
- package/foundation/Grid/Grid.d.ts +32 -0
- package/foundation/Grid/GridAlign.module.d.ts +8 -0
- package/foundation/Grid/GridCell/GridCell.d.ts +23 -0
- package/foundation/Grid/GridCell/index.d.mts +1 -0
- package/foundation/Grid/index.d.mts +1 -0
- package/foundation/Grid/index.mjs +5 -0
- package/foundation/Grid-es.js +30 -0
- package/foundation/GridCell-es.js +34 -0
- package/foundation/Heading/Heading.d.ts +41 -0
- package/foundation/Heading/index.d.mts +2 -0
- package/foundation/Heading/index.mjs +4 -0
- package/foundation/Heading-es.js +55 -0
- package/foundation/HelperText-es.js +19 -0
- package/foundation/Icon/Icon.d.ts +47 -0
- package/foundation/Icon/index.d.mts +1 -0
- package/foundation/Icon-es.js +22 -0
- package/foundation/InlineLabel/InlineLabel.d.ts +18 -0
- package/foundation/InlineLabel/index.d.mts +1 -0
- package/foundation/InlineLabel/index.mjs +4 -0
- package/foundation/InlineLabel-es.js +19 -0
- package/foundation/InputAvatar/InputAvatar.d.ts +23 -0
- package/foundation/InputAvatar/index.d.mts +1 -0
- package/foundation/InputAvatar/index.mjs +22 -0
- package/foundation/InputAvatar-es.js +64 -0
- package/foundation/InputDate/InputDate.d.ts +3 -0
- package/foundation/InputDate/InputDate.types.d.ts +36 -0
- package/foundation/InputDate/index.d.mts +2 -0
- package/foundation/InputDate/index.mjs +39 -0
- package/foundation/InputDate-es.js +104 -0
- package/foundation/InputEmail/InputEmail.d.ts +3 -0
- package/foundation/InputEmail/InputEmail.types.d.ts +16 -0
- package/foundation/InputEmail/index.d.mts +2 -0
- package/foundation/InputEmail/index.mjs +22 -0
- package/foundation/InputEmail-es.js +105 -0
- package/foundation/InputFile/FileTypes.d.ts +17 -0
- package/foundation/InputFile/InputFile.d.ts +187 -0
- package/foundation/InputFile/InputFileButton.d.ts +6 -0
- package/foundation/InputFile/InputFileContentContext.d.ts +12 -0
- package/foundation/InputFile/InputFileDescription.d.ts +4 -0
- package/foundation/InputFile/InputFileDropzoneWrapper.d.ts +4 -0
- package/foundation/InputFile/InputFileHintText.d.ts +4 -0
- package/foundation/InputFile/index.d.mts +3 -0
- package/foundation/InputFile/index.mjs +16 -0
- package/foundation/InputFile-es.js +1780 -0
- package/foundation/InputGroup/InputGroup.d.ts +12 -0
- package/foundation/InputGroup/index.d.mts +1 -0
- package/foundation/InputGroup/index.mjs +3 -0
- package/foundation/InputGroup-es.js +26 -0
- package/foundation/InputNumber/InputNumber.d.ts +77 -0
- package/foundation/InputNumber/index.d.mts +2 -0
- package/foundation/InputNumber/index.mjs +33 -0
- package/foundation/InputNumber/types.d.ts +197 -0
- package/foundation/InputNumber-es.js +348 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.d.ts +3 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.types.d.ts +24 -0
- package/foundation/InputPhoneNumber/index.d.mts +2 -0
- package/foundation/InputPhoneNumber/index.mjs +22 -0
- package/foundation/InputPhoneNumber-es.js +188 -0
- package/foundation/InputText/InputText.d.ts +3 -0
- package/foundation/InputText/InputText.types.d.ts +58 -0
- package/foundation/InputText/index.d.mts +2 -0
- package/foundation/InputText/index.mjs +23 -0
- package/foundation/InputText-es.js +196 -0
- package/foundation/InputTime/InputTime.d.ts +3 -0
- package/foundation/InputTime/InputTime.types.d.ts +34 -0
- package/foundation/InputTime/index.d.mts +2 -0
- package/foundation/InputTime/index.mjs +23 -0
- package/foundation/InputTime-es.js +297 -0
- package/foundation/InputValidation/InputValidation.d.ts +10 -0
- package/foundation/InputValidation/index.d.mts +1 -0
- package/foundation/InputValidation/index.mjs +8 -0
- package/foundation/InputValidation-es.js +22 -0
- package/foundation/InternalChipDismissible-es.js +68 -0
- package/foundation/LICENSE +21 -0
- package/foundation/LegacySelect/LegacySelect.d.ts +7 -0
- package/foundation/LegacySelect/LegacySelect.types.d.ts +18 -0
- package/foundation/LegacySelect/Option.d.ts +18 -0
- package/foundation/LegacySelect/OptionGroup.d.ts +29 -0
- package/foundation/LegacySelect/index.d.mts +3 -0
- package/foundation/LegacySelect/index.mjs +23 -0
- package/foundation/LegacySelect-es.js +76 -0
- package/foundation/LegacyThemeContext/LegacyThemeContext.d.ts +5 -0
- package/foundation/LegacyThemeContext/index.d.mts +3 -0
- package/foundation/LegacyThemeContext/index.mjs +12 -0
- package/foundation/LegacyThemeContext/types.d.ts +59 -0
- package/foundation/LegacyThemeContext/updateTheme.d.ts +7 -0
- package/foundation/LegacyThemeContext-es.js +457 -0
- package/foundation/LightBox/LightBox.d.ts +165 -0
- package/foundation/LightBox/LightBox.types.d.ts +153 -0
- package/foundation/LightBox/LightBoxContext.d.ts +5 -0
- package/foundation/LightBox/index.d.mts +3 -0
- package/foundation/LightBox/index.mjs +50 -0
- package/foundation/LightBox-es.js +454 -0
- package/foundation/Link/Link.d.ts +9 -0
- package/foundation/Link/index.d.mts +2 -0
- package/foundation/Link/index.mjs +2 -0
- package/foundation/Link-es.js +12 -0
- package/foundation/List/List.d.ts +41 -0
- package/foundation/List/ListItem.d.ts +59 -0
- package/foundation/List/index.d.mts +2 -0
- package/foundation/List/index.mjs +22 -0
- package/foundation/List-es.js +199 -0
- package/foundation/Markdown/Markdown.d.ts +24 -0
- package/foundation/Markdown/index.d.mts +1 -0
- package/foundation/Markdown/index.mjs +10 -0
- package/foundation/Markdown-es.js +20558 -0
- package/foundation/Menu/Menu.d.ts +89 -0
- package/foundation/Menu/Menu.types.d.ts +105 -0
- package/foundation/Menu/index.d.mts +2 -0
- package/foundation/Menu/index.mjs +35 -0
- package/foundation/Menu/menuComposableTypes.d.ts +103 -0
- package/foundation/Menu-es.js +1033 -0
- package/foundation/MenuSubmenuTrigger-es.js +3088 -0
- package/foundation/Modal/Modal.rebuilt.d.ts +16 -0
- package/foundation/Modal/Modal.types.d.ts +138 -0
- package/foundation/Modal/ModalContext.rebuilt.d.ts +19 -0
- package/foundation/Modal/ModalSizes.module.d.ts +7 -0
- package/foundation/Modal/index.d.mts +17 -0
- package/foundation/Modal/index.mjs +302 -0
- package/foundation/Modal/useModalStyles.d.ts +12 -0
- package/foundation/MultiSelect/MultiSelect.d.ts +30 -0
- package/foundation/MultiSelect/index.d.mts +1 -0
- package/foundation/MultiSelect/index.mjs +9 -0
- package/foundation/MultiSelect/types.d.ts +13 -0
- package/foundation/MultiSelect-es.js +172 -0
- package/foundation/OverlaySeparator-es.js +13 -0
- package/foundation/Page/Page.d.ts +74 -0
- package/foundation/Page/index.d.mts +2 -0
- package/foundation/Page/index.mjs +42 -0
- package/foundation/Page/types.d.ts +123 -0
- package/foundation/Page-es.js +196 -0
- package/foundation/Popover/Popover.d.ts +9 -0
- package/foundation/Popover/Popover.types.d.ts +109 -0
- package/foundation/Popover/PopoverContext.d.ts +18 -0
- package/foundation/Popover/index.d.mts +4 -0
- package/foundation/Popover/index.mjs +27 -0
- package/foundation/Popover/usePopoverStyles.d.ts +5 -0
- package/foundation/Popover-es.js +166 -0
- package/foundation/ProgressBar/ProgressBar.d.ts +41 -0
- package/foundation/ProgressBar/ProgressBarSizes.module.d.ts +7 -0
- package/foundation/ProgressBar/index.d.mts +1 -0
- package/foundation/ProgressBar/index.mjs +5 -0
- package/foundation/ProgressBar-es.js +48 -0
- package/foundation/ProgressIndicator/ProgressIndicator.d.ts +60 -0
- package/foundation/ProgressIndicator/index.d.mts +1 -0
- package/foundation/ProgressIndicator/index.mjs +3 -0
- package/foundation/ProgressIndicator-es.js +41 -0
- package/foundation/RadioGroup/RadioGroup.d.ts +33 -0
- package/foundation/RadioGroup/RadioOption.d.ts +48 -0
- package/foundation/RadioGroup/index.d.mts +2 -0
- package/foundation/RadioGroup/index.mjs +5 -0
- package/foundation/RadioGroup-es.js +42 -0
- package/foundation/ResponsiveSwitcher/ResponsiveSwitcher.d.ts +3 -0
- package/foundation/ResponsiveSwitcher/index.d.mts +2 -0
- package/foundation/ResponsiveSwitcher/index.mjs +4 -0
- package/foundation/ResponsiveSwitcher/types.d.ts +26 -0
- package/foundation/ResponsiveSwitcher-es.js +11 -0
- package/foundation/RulnarPortalContent-es.js +1 -0
- package/foundation/ScrollAreaViewport-es.js +3959 -0
- package/foundation/SegmentedControl/SegmentedControl.d.ts +39 -0
- package/foundation/SegmentedControl/SegmentedControlBase.d.ts +7 -0
- package/foundation/SegmentedControl/SegmentedControlOption.d.ts +15 -0
- package/foundation/SegmentedControl/SegmentedControlProvider.d.ts +17 -0
- package/foundation/SegmentedControl/index.d.mts +2 -0
- package/foundation/SegmentedControl/index.mjs +3 -0
- package/foundation/SegmentedControl-es.js +64 -0
- package/foundation/Select/Select.d.ts +31 -0
- package/foundation/Select/Select.types.d.ts +145 -0
- package/foundation/Select/index.d.mts +2 -0
- package/foundation/Select/index.mjs +29 -0
- package/foundation/Select-es.js +227 -0
- package/foundation/SelectGroupLabel-es.js +1763 -0
- package/foundation/SelectPrimitive-es.js +126 -0
- package/foundation/Separator-es.js +33 -0
- package/foundation/SideDrawer/SideDrawer.d.ts +56 -0
- package/foundation/SideDrawer/SideDrawerActions.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerBackButton.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerFooter.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerTitle.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerToolbar.d.ts +2 -0
- package/foundation/SideDrawer/index.d.mts +1 -0
- package/foundation/SideDrawer/index.mjs +16 -0
- package/foundation/SideDrawer-es.js +198 -0
- package/foundation/SideKick/SideKick.d.ts +3 -0
- package/foundation/SideKick/index.d.mts +2 -0
- package/foundation/SideKick/index.mjs +4 -0
- package/foundation/SideKick/types.d.ts +35 -0
- package/foundation/SideKick-es.js +15 -0
- package/foundation/Spinner/Spinner.d.ts +22 -0
- package/foundation/Spinner/index.d.mts +1 -0
- package/foundation/Spinner/index.mjs +6 -0
- package/foundation/Spinner-es.js +21 -0
- package/foundation/Stack/Stack.d.ts +3 -0
- package/foundation/Stack/index.d.mts +2 -0
- package/foundation/Stack/index.mjs +4 -0
- package/foundation/Stack/types.d.ts +32 -0
- package/foundation/Stack-es.js +13 -0
- package/foundation/StatusIndicator/StatusIndicator.d.ts +7 -0
- package/foundation/StatusIndicator/StatusIndicator.type.d.ts +1 -0
- package/foundation/StatusIndicator/index.d.mts +2 -0
- package/foundation/StatusIndicator/index.mjs +2 -0
- package/foundation/StatusIndicator-es.js +9 -0
- package/foundation/StatusLabel/StatusLabel.d.ts +26 -0
- package/foundation/StatusLabel/index.d.mts +1 -0
- package/foundation/StatusLabel/index.mjs +5 -0
- package/foundation/StatusLabel-es.js +16 -0
- package/foundation/Table/Body.d.ts +7 -0
- package/foundation/Table/Cells/Cell.d.ts +8 -0
- package/foundation/Table/Cells/CellCurrency.d.ts +9 -0
- package/foundation/Table/Cells/CellNumeric.d.ts +5 -0
- package/foundation/Table/Footer.d.ts +7 -0
- package/foundation/Table/Header.d.ts +7 -0
- package/foundation/Table/Row.d.ts +7 -0
- package/foundation/Table/Table.d.ts +7 -0
- package/foundation/Table/index.d.mts +8 -0
- package/foundation/Table/index.mjs +4 -0
- package/foundation/Tabs/Tabs.d.ts +38 -0
- package/foundation/Tabs/index.d.mts +1 -0
- package/foundation/Tabs/index.mjs +8 -0
- package/foundation/Tabs-es.js +227 -0
- package/foundation/Text/Text.d.ts +29 -0
- package/foundation/Text/index.d.mts +2 -0
- package/foundation/Text/index.mjs +4 -0
- package/foundation/Text-es.js +25 -0
- package/foundation/Thumbnail/Thumbnail.d.ts +25 -0
- package/foundation/Thumbnail/index.d.mts +1 -0
- package/foundation/Thumbnail/index.mjs +9 -0
- package/foundation/Thumbnail-es.js +119 -0
- package/foundation/Tiles/Tiles.d.ts +3 -0
- package/foundation/Tiles/index.d.mts +2 -0
- package/foundation/Tiles/index.mjs +4 -0
- package/foundation/Tiles/types.d.ts +34 -0
- package/foundation/Tiles-es.js +11 -0
- package/foundation/Tooltip/Tooltip.d.ts +18 -0
- package/foundation/Tooltip/Tooltip.types.d.ts +1 -0
- package/foundation/Tooltip/index.d.mts +1 -0
- package/foundation/Tooltip/index.mjs +8 -0
- package/foundation/Tooltip-es.js +137 -0
- package/foundation/Typography/Typography.d.ts +64 -0
- package/foundation/Typography/css/Emphasis.module.d.ts +6 -0
- package/foundation/Typography/css/FontFamilies.module.d.ts +6 -0
- package/foundation/Typography/css/FontSizes.module.d.ts +12 -0
- package/foundation/Typography/css/FontWeights.module.d.ts +10 -0
- package/foundation/Typography/css/TextAlignment.module.d.ts +7 -0
- package/foundation/Typography/css/TextCases.module.d.ts +8 -0
- package/foundation/Typography/css/TextColors.module.d.ts +69 -0
- package/foundation/Typography/index.d.mts +1 -0
- package/foundation/Typography/index.mjs +3 -0
- package/foundation/Typography/types.d.ts +7 -0
- package/foundation/Typography-es.js +53 -0
- package/foundation/_baseAssignValue-es.js +29 -0
- package/foundation/_baseEach-es.js +1028 -0
- package/foundation/_baseFlatten-es.js +65 -0
- package/foundation/_baseFor-es.js +45 -0
- package/foundation/_commonjsHelpers-es.js +7 -0
- package/foundation/_getAllKeys-es.js +506 -0
- package/foundation/_getTag-es.js +133 -0
- package/foundation/_isIterateeCall-es.js +55 -0
- package/foundation/_setToString-es.js +168 -0
- package/foundation/buttonRenderAdapter-es.js +52 -0
- package/foundation/buttonStyles.d.mts +1 -0
- package/foundation/buttonStyles.mjs +1 -0
- package/foundation/clearable.d.ts +1 -0
- package/foundation/common.messages-es.js +18 -0
- package/foundation/compatHooks.mjs +2 -0
- package/foundation/constants-es.js +3 -0
- package/foundation/dateLocale-es.js +1142 -0
- package/foundation/debounce-es.js +329 -0
- package/foundation/dialogFocus.d.mts +1 -0
- package/foundation/dialogFocus.mjs +66 -0
- package/foundation/filterDataAttributes-es.js +24 -0
- package/foundation/floating-ui.react-es.js +6174 -0
- package/foundation/getMappedSpaceToken-es.js +18 -0
- package/foundation/helpers-es.js +15 -0
- package/foundation/identity-es.js +809 -0
- package/foundation/imageTypes.d.mts +1 -0
- package/foundation/imageTypes.mjs +1 -0
- package/foundation/index-es.js +1186 -0
- package/foundation/isObjectLike-es.js +190 -0
- package/foundation/isSymbol-es.js +33 -0
- package/foundation/isTypedArray-es.js +589 -0
- package/foundation/keysIn-es.js +385 -0
- package/foundation/linkEvents.d.mts +1 -0
- package/foundation/linkEvents.mjs +9 -0
- package/foundation/maxHeight-es.js +22 -0
- package/foundation/mergeClassName-es.js +10 -0
- package/foundation/mergeRefs-es.js +18 -0
- package/foundation/nestedEscape-es.js +91 -0
- package/foundation/noop-es.js +24 -0
- package/foundation/primitives/BottomSheet/BottomSheet.d.ts +37 -0
- package/foundation/primitives/BottomSheet/BottomSheet.types.d.ts +36 -0
- package/foundation/primitives/BottomSheet/index.d.mts +2 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.d.ts +32 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.types.d.ts +30 -0
- package/foundation/primitives/ComboboxPrimitive/index.d.mts +2 -0
- package/foundation/primitives/HelperText/HelperText.d.ts +25 -0
- package/foundation/primitives/HelperText/index.d.mts +1 -0
- package/foundation/primitives/OverlaySeparator/OverlaySeparator.d.ts +6 -0
- package/foundation/primitives/OverlaySeparator/index.d.mts +1 -0
- package/foundation/primitives/SelectPrimitive/SelectPrimitive.d.ts +74 -0
- package/foundation/primitives/SelectPrimitive/index.d.mts +2 -0
- package/foundation/primitives/SelectPrimitive/types.d.ts +31 -0
- package/foundation/primitives/index.d.mts +12 -0
- package/foundation/primitives/index.mjs +29 -0
- package/foundation/routerLink.d.mts +3 -0
- package/foundation/routerLink.mjs +1 -0
- package/foundation/scrollEdges-es.js +64 -0
- package/foundation/scrollable-es.js +54 -0
- package/foundation/sharedHelpers/getMappedBreakpointWidth.d.ts +8 -0
- package/foundation/sharedHelpers/types.d.ts +254 -0
- package/foundation/stringifyLocale-es.js +11 -0
- package/foundation/styles.css +16646 -0
- package/foundation/tslib.es6-es.js +97 -0
- package/foundation/unstyledPrimitives/index.d.mts +22 -0
- package/foundation/useActiveLayout-es.js +14 -0
- package/foundation/useBatchSelect-es.js +36 -0
- package/foundation/useChildComponent-es.js +15 -0
- package/foundation/useComponentMessages-es.js +86 -0
- package/foundation/useCompositeListItem-es.js +3955 -0
- package/foundation/useFormFieldFocus-es.js +37 -0
- package/foundation/useFormFieldName-es.js +11 -0
- package/foundation/useLabel-es.js +81 -0
- package/foundation/useRenderElement-es.js +628 -0
- package/foundation/useResponsiveSizing-es.js +8 -0
- package/foundation/useScrollLock-es.js +5746 -0
- package/foundation/useScrollToActive-es.js +581 -0
- package/foundation/utils/isNormalClick.d.ts +6 -0
- package/foundation/utils/isPreviewableImage.d.ts +1 -0
- package/foundation/utils/meta/meta.json +298 -0
- package/foundation.css +67 -0
- package/package.json +540 -4
- package/src/styles.css +181 -0
|
@@ -0,0 +1,3959 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { E as EMPTY_OBJECT, N as NOOP, f as formatErrorMessage, u as useRenderElement, m as mergeProps } from './useRenderElement-es.js';
|
|
3
|
+
import { aK as FloatingRootStore, aL as PopupTriggerMap, b3 as shimExports, a6 as popupStateMapping, t as transitionStatusMapping, a2 as FloatingPortal, a3 as InternalBackdrop, a4 as inertValue, W as useDismiss, e as getTarget, a0 as contains, b2 as useScrollLock, c as useIsoLayoutEffect, b4 as usePopupInteractionProps, X as ReactStore, b5 as setPopupOpenState, b6 as usePopupRootStore, b7 as usePopupRootSync, b8 as useImplicitActiveTrigger, b9 as useOpenStateTransitions, h as createChangeEventDetails, k as imperativeAction, ba as PopupHandleAttachment, u as useBaseUiId, bb as useTriggerDataForwarding, f as useButton, V as useClick, bc as useOpenMethodTriggerProps, bd as CLICK_TRIGGER_IDENTIFIER, be as triggerOpenStateMapping, p as popupTransitionStateMapping, bf as CommonPopupDataAttributes, d as useStableCallback, o as ownerDocument, S as SafeReact, r as error, l as useOpenChangeComplete, F as FOCUSABLE_POPUP_PROPS, n as FloatingFocusManager, v as useControlled, z as none, bg as android, I as getWindow, y as addEventListener, bh as closeWatcher, a8 as useAnimationFrame, au as isElement, D as activeElement, bi as TransitionStatusDataAttributes, bj as swipe, bk as BASE_UI_SWIPE_IGNORE_SELECTOR, q as useTimeout, a7 as useDirection, a9 as webkit } from './useScrollLock-es.js';
|
|
4
|
+
import { c as clamp, C as COMPOSITE_KEYS, u as useCSPContext, s as styleDisableScrollbar, n as normalizeScrollOffset } from './scrollEdges-es.js';
|
|
5
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
|
+
import * as ReactDOM from 'react-dom';
|
|
7
|
+
import { f as findScrollableTouchTarget, h as hasScrollableAncestor } from './scrollable-es.js';
|
|
8
|
+
|
|
9
|
+
function getEmptyRootContext() {
|
|
10
|
+
return new FloatingRootStore({
|
|
11
|
+
open: false,
|
|
12
|
+
transitionStatus: undefined,
|
|
13
|
+
floatingElement: null,
|
|
14
|
+
referenceElement: null,
|
|
15
|
+
triggerElements: new PopupTriggerMap(),
|
|
16
|
+
floatingId: undefined,
|
|
17
|
+
syncOnly: false,
|
|
18
|
+
nested: false,
|
|
19
|
+
onOpenChange: undefined
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* State common to all popup stores.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
function createInitialPopupStoreState() {
|
|
28
|
+
return {
|
|
29
|
+
open: false,
|
|
30
|
+
openProp: undefined,
|
|
31
|
+
mounted: false,
|
|
32
|
+
transitionStatus: undefined,
|
|
33
|
+
floatingRootContext: getEmptyRootContext(),
|
|
34
|
+
floatingId: undefined,
|
|
35
|
+
triggerCount: 0,
|
|
36
|
+
preventUnmountingOnClose: false,
|
|
37
|
+
payload: undefined,
|
|
38
|
+
activeTriggerId: null,
|
|
39
|
+
activeTriggerElement: null,
|
|
40
|
+
triggerIdProp: undefined,
|
|
41
|
+
popupElement: null,
|
|
42
|
+
positionerElement: null,
|
|
43
|
+
activeTriggerProps: EMPTY_OBJECT,
|
|
44
|
+
inactiveTriggerProps: EMPTY_OBJECT,
|
|
45
|
+
popupProps: EMPTY_OBJECT
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function createPopupFloatingRootContext(triggerElements, floatingId, nested = false) {
|
|
49
|
+
return new FloatingRootStore({
|
|
50
|
+
open: false,
|
|
51
|
+
transitionStatus: undefined,
|
|
52
|
+
floatingElement: null,
|
|
53
|
+
referenceElement: null,
|
|
54
|
+
triggerElements,
|
|
55
|
+
floatingId,
|
|
56
|
+
syncOnly: true,
|
|
57
|
+
nested,
|
|
58
|
+
onOpenChange: undefined
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const activeTriggerIdSelector = state => state.triggerIdProp ?? state.activeTriggerId;
|
|
62
|
+
const openSelector = state => state.openProp ?? state.open;
|
|
63
|
+
const popupIdSelector = state => {
|
|
64
|
+
const popupId = state.popupElement?.id ?? state.floatingId;
|
|
65
|
+
return popupId || undefined;
|
|
66
|
+
};
|
|
67
|
+
function triggerOwnsOpenPopup(state, triggerId) {
|
|
68
|
+
return triggerId !== undefined && openSelector(state) && activeTriggerIdSelector(state) === triggerId;
|
|
69
|
+
}
|
|
70
|
+
function triggerOwnsOpenPopupOrIsOnlyTrigger(state, triggerId) {
|
|
71
|
+
if (triggerOwnsOpenPopup(state, triggerId)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return triggerId !== undefined && openSelector(state) && activeTriggerIdSelector(state) == null && state.triggerCount === 1;
|
|
75
|
+
}
|
|
76
|
+
const popupStoreSelectors = {
|
|
77
|
+
open: openSelector,
|
|
78
|
+
mounted: state => state.mounted,
|
|
79
|
+
transitionStatus: state => state.transitionStatus,
|
|
80
|
+
floatingRootContext: state => state.floatingRootContext,
|
|
81
|
+
triggerCount: state => state.triggerCount,
|
|
82
|
+
preventUnmountingOnClose: state => state.preventUnmountingOnClose,
|
|
83
|
+
payload: state => state.payload,
|
|
84
|
+
activeTriggerId: activeTriggerIdSelector,
|
|
85
|
+
activeTriggerElement: state => state.mounted ? state.activeTriggerElement : null,
|
|
86
|
+
popupId: popupIdSelector,
|
|
87
|
+
/**
|
|
88
|
+
* Whether the trigger with the given ID was used to open the popup.
|
|
89
|
+
*/
|
|
90
|
+
isTriggerActive: (state, triggerId) => triggerId !== undefined && activeTriggerIdSelector(state) === triggerId,
|
|
91
|
+
/**
|
|
92
|
+
* Whether the popup is open and was activated by a trigger with the given ID.
|
|
93
|
+
*/
|
|
94
|
+
isOpenedByTrigger: (state, triggerId) => triggerOwnsOpenPopup(state, triggerId),
|
|
95
|
+
/**
|
|
96
|
+
* Whether the popup is mounted and was activated by a trigger with the given ID.
|
|
97
|
+
*/
|
|
98
|
+
isMountedByTrigger: (state, triggerId) => triggerId !== undefined && activeTriggerIdSelector(state) === triggerId && state.mounted,
|
|
99
|
+
triggerProps: (state, isActive) => isActive ? state.activeTriggerProps : state.inactiveTriggerProps,
|
|
100
|
+
/**
|
|
101
|
+
* Popup id for the trigger that currently owns the open popup.
|
|
102
|
+
*/
|
|
103
|
+
triggerPopupId: (state, triggerId) => triggerOwnsOpenPopupOrIsOnlyTrigger(state, triggerId) ? popupIdSelector(state) : undefined,
|
|
104
|
+
popupProps: state => state.popupProps,
|
|
105
|
+
popupElement: state => state.popupElement,
|
|
106
|
+
positionerElement: state => state.positionerElement
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Store members a detached handle-backed trigger reads or invokes for trigger registration and data
|
|
111
|
+
* forwarding. `set`/`update` are included only for trigger-count and trigger-data bookkeeping; on a
|
|
112
|
+
* detached (inert) store they are intentionally no-ops, so a write through them is not guaranteed to
|
|
113
|
+
* be durable. Component handle-store views Pick these from their concrete store (preserving its
|
|
114
|
+
* context and selectors) and add any component-specific trigger-invoked members such as `setOpen`.
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The subset of a popup store that trigger registration and data forwarding rely on. Narrow enough
|
|
119
|
+
* that an inert store can be passed while detached.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reads the store currently exposed by a popup handle and subscribes to store-pointer changes.
|
|
124
|
+
* Detached triggers use this to follow a handle as a root attaches or detaches: while no root is
|
|
125
|
+
* attached, the handle exposes its fallback store; once a root attaches, subscribers re-render and
|
|
126
|
+
* read from the live root store.
|
|
127
|
+
*
|
|
128
|
+
* Returns `undefined` when no handle is provided so callers can fall back to their root context.
|
|
129
|
+
*
|
|
130
|
+
* @param handle The popup handle to read from, or `undefined` when the trigger is not handle-bound.
|
|
131
|
+
*/
|
|
132
|
+
function usePopupHandleStore(handle) {
|
|
133
|
+
const subscribe = React.useCallback(listener => {
|
|
134
|
+
if (handle === undefined) {
|
|
135
|
+
return NOOP;
|
|
136
|
+
}
|
|
137
|
+
return handle.subscribeStore(listener);
|
|
138
|
+
}, [handle]);
|
|
139
|
+
const getSnapshot = React.useCallback(() => {
|
|
140
|
+
return handle === undefined ? undefined : handle.store;
|
|
141
|
+
}, [handle]);
|
|
142
|
+
return shimExports.useSyncExternalStore(subscribe, getSnapshot, () => handle?.serverStore);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const DialogRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
146
|
+
if (process.env.NODE_ENV !== "production") DialogRootContext.displayName = "DialogRootContext";
|
|
147
|
+
function useDialogRootContext(optional) {
|
|
148
|
+
const store = React.useContext(DialogRootContext);
|
|
149
|
+
if (!optional && store === undefined) {
|
|
150
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: DialogRootContext is missing. Dialog parts must be placed within <Dialog.Root>.' : formatErrorMessage(27));
|
|
151
|
+
}
|
|
152
|
+
return store;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const DialogPortalContext = /*#__PURE__*/React.createContext(undefined);
|
|
156
|
+
if (process.env.NODE_ENV !== "production") DialogPortalContext.displayName = "DialogPortalContext";
|
|
157
|
+
function useDialogPortalContext() {
|
|
158
|
+
const value = React.useContext(DialogPortalContext);
|
|
159
|
+
if (value === undefined) {
|
|
160
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Dialog.Portal> is missing.' : formatErrorMessage(26));
|
|
161
|
+
}
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Shared by `Dialog.Popup` and `Dialog.Viewport`, whose states have the same shape.
|
|
167
|
+
* `nested` is not mapped: unmapped `true` booleans already render as `data-nested`.
|
|
168
|
+
*/
|
|
169
|
+
const dialogStateAttributesMapping = {
|
|
170
|
+
...popupStateMapping,
|
|
171
|
+
...transitionStatusMapping,
|
|
172
|
+
nestedDialogOpen(value) {
|
|
173
|
+
return value ? {
|
|
174
|
+
'data-nested-dialog-open': ''
|
|
175
|
+
} : null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const DialogPortal = /*#__PURE__*/React.forwardRef(function DialogPortal(props, forwardedRef) {
|
|
180
|
+
const {
|
|
181
|
+
keepMounted = false,
|
|
182
|
+
...portalProps
|
|
183
|
+
} = props;
|
|
184
|
+
const store = useDialogRootContext();
|
|
185
|
+
const mounted = store.useState('mounted');
|
|
186
|
+
const modal = store.useState('modal');
|
|
187
|
+
const open = store.useState('open');
|
|
188
|
+
const shouldRender = mounted || keepMounted;
|
|
189
|
+
if (!shouldRender) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return /*#__PURE__*/jsx(DialogPortalContext.Provider, {
|
|
193
|
+
value: keepMounted,
|
|
194
|
+
children: /*#__PURE__*/jsxs(FloatingPortal, {
|
|
195
|
+
ref: forwardedRef,
|
|
196
|
+
...portalProps,
|
|
197
|
+
children: [mounted && modal === true && /*#__PURE__*/jsx(InternalBackdrop, {
|
|
198
|
+
ref: store.context.internalBackdropRef,
|
|
199
|
+
inert: inertValue(!open)
|
|
200
|
+
}), props.children]
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
if (process.env.NODE_ENV !== "production") DialogPortal.displayName = "DialogPortal";
|
|
205
|
+
|
|
206
|
+
function DialogInteractions({
|
|
207
|
+
store,
|
|
208
|
+
parentContext,
|
|
209
|
+
isDrawer
|
|
210
|
+
}) {
|
|
211
|
+
const open = store.useState('open');
|
|
212
|
+
const disablePointerDismissal = store.useState('disablePointerDismissal');
|
|
213
|
+
const modal = store.useState('modal');
|
|
214
|
+
const popupElement = store.useState('popupElement');
|
|
215
|
+
const floatingRootContext = store.useState('floatingRootContext');
|
|
216
|
+
const [ownNestedOpenDialogs, setOwnNestedOpenDialogs] = React.useState(0);
|
|
217
|
+
const [ownNestedOpenDrawers, setOwnNestedOpenDrawers] = React.useState(0);
|
|
218
|
+
const isTopmost = ownNestedOpenDialogs === 0;
|
|
219
|
+
const dismiss = useDismiss(floatingRootContext, {
|
|
220
|
+
outsidePressEvent() {
|
|
221
|
+
if (store.context.internalBackdropRef.current || store.context.backdropRef.current) {
|
|
222
|
+
return 'intentional';
|
|
223
|
+
}
|
|
224
|
+
// Ensure `aria-hidden` on outside elements is removed immediately
|
|
225
|
+
// on outside press when trapping focus.
|
|
226
|
+
return {
|
|
227
|
+
mouse: modal === 'trap-focus' ? 'sloppy' : 'intentional',
|
|
228
|
+
touch: 'sloppy'
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
outsidePress(event) {
|
|
232
|
+
if (!store.context.outsidePressEnabledRef.current) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// For mouse events, only accept left button (button 0)
|
|
237
|
+
// For touch events, a single touch is equivalent to left button
|
|
238
|
+
if ('button' in event && event.button !== 0) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if ('touches' in event) {
|
|
242
|
+
// Outside press can be handled on `touchend`, where the lifted point is
|
|
243
|
+
// reported in `changedTouches` and `touches` contains any remaining
|
|
244
|
+
// active points. Treat it as a single-finger tap only when exactly one
|
|
245
|
+
// touch ended and no other fingers are still down.
|
|
246
|
+
if (event.type === 'touchend') {
|
|
247
|
+
if (event.changedTouches.length !== 1 || event.touches.length !== 0) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
} else if (event.touches.length !== 1) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const target = getTarget(event);
|
|
255
|
+
if (isTopmost && !disablePointerDismissal) {
|
|
256
|
+
// Only close if the click occurred on the dialog's owning backdrop.
|
|
257
|
+
// This supports multiple modal dialogs that aren't nested in the React tree:
|
|
258
|
+
// https://github.com/mui/base-ui/issues/1320
|
|
259
|
+
if (modal) {
|
|
260
|
+
const internalBackdrop = store.context.internalBackdropRef.current;
|
|
261
|
+
const backdrop = store.context.backdropRef.current;
|
|
262
|
+
return internalBackdrop || backdrop ? internalBackdrop === target || backdrop === target || contains(target, popupElement) && !target?.hasAttribute('data-base-ui-portal') : true;
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
},
|
|
268
|
+
escapeKey: isTopmost
|
|
269
|
+
});
|
|
270
|
+
useScrollLock(open && modal === true, popupElement);
|
|
271
|
+
|
|
272
|
+
// Listen for nested open/close events on this store to maintain the counts.
|
|
273
|
+
// A close notification is an open notification with zeroed counts.
|
|
274
|
+
store.useContextCallback('onNestedDialogOpen', (dialogCount, drawerCount) => {
|
|
275
|
+
setOwnNestedOpenDialogs(dialogCount);
|
|
276
|
+
setOwnNestedOpenDrawers(drawerCount);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Notify parent of our open/close state using parent callbacks, if any
|
|
280
|
+
useIsoLayoutEffect(() => {
|
|
281
|
+
if (parentContext?.onNestedDialogOpen) {
|
|
282
|
+
if (open) {
|
|
283
|
+
parentContext.onNestedDialogOpen(ownNestedOpenDialogs + 1, ownNestedOpenDrawers + (isDrawer ? 1 : 0));
|
|
284
|
+
} else {
|
|
285
|
+
parentContext.onNestedDialogOpen(0, 0);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return () => {
|
|
289
|
+
if (parentContext?.onNestedDialogOpen && open) {
|
|
290
|
+
parentContext.onNestedDialogOpen(0, 0);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}, [isDrawer, open, ownNestedOpenDialogs, ownNestedOpenDrawers, parentContext]);
|
|
294
|
+
usePopupInteractionProps(store, {
|
|
295
|
+
// `enabled` is not passed to `useDismiss`, so its props are always defined,
|
|
296
|
+
// and `trigger` is the same object as `reference`.
|
|
297
|
+
activeTriggerProps: dismiss.reference,
|
|
298
|
+
inactiveTriggerProps: dismiss.trigger,
|
|
299
|
+
// DialogPopup and DrawerPopup spread `FOCUSABLE_POPUP_PROPS` directly, so
|
|
300
|
+
// this only needs to carry the dismiss handlers.
|
|
301
|
+
popupProps: dismiss.floating,
|
|
302
|
+
nestedOpenDialogCount: ownNestedOpenDialogs,
|
|
303
|
+
nestedOpenDrawerCount: ownNestedOpenDrawers
|
|
304
|
+
});
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* A `ReactStore` whose state never changes.
|
|
310
|
+
*
|
|
311
|
+
* Useful for fallback stores that need to support normal store reads while detached from the
|
|
312
|
+
* component that owns real state. Context values may still contain mutable refs or maps.
|
|
313
|
+
*/
|
|
314
|
+
class NullStore extends ReactStore {
|
|
315
|
+
// `update`/`set`/`notifyAll` funnel through `setState` in the base `Store`, so overriding
|
|
316
|
+
// `setState` alone would neutralize them today. They are overridden explicitly so the store stays
|
|
317
|
+
// inert even if a future base-class change stops routing a mutator through `setState`.
|
|
318
|
+
setState(_newState) {}
|
|
319
|
+
update(_changes) {}
|
|
320
|
+
set(_key, _value) {}
|
|
321
|
+
notifyAll() {}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const selectors = {
|
|
325
|
+
...popupStoreSelectors,
|
|
326
|
+
modal: state => state.modal,
|
|
327
|
+
nested: state => state.nested,
|
|
328
|
+
nestedOpenDialogCount: state => state.nestedOpenDialogCount,
|
|
329
|
+
nestedOpenDrawerCount: state => state.nestedOpenDrawerCount,
|
|
330
|
+
disablePointerDismissal: state => state.disablePointerDismissal,
|
|
331
|
+
openMethod: state => state.openMethod,
|
|
332
|
+
descriptionElementId: state => state.descriptionElementId,
|
|
333
|
+
titleElementId: state => state.titleElementId,
|
|
334
|
+
viewportElement: state => state.viewportElement,
|
|
335
|
+
role: state => state.role
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The subset of `DialogStore` that detached handle-backed triggers rely on. Both the real
|
|
340
|
+
* `DialogStore` and the inert fallback store satisfy it, so a trigger can read from whichever
|
|
341
|
+
* store the handle currently exposes.
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
class DialogStore extends ReactStore {
|
|
345
|
+
constructor(initialState, floatingId, nested) {
|
|
346
|
+
const triggerElements = new PopupTriggerMap();
|
|
347
|
+
const state = createInitialState(initialState, triggerElements, floatingId, nested);
|
|
348
|
+
super(state, createInitialContext(triggerElements), selectors);
|
|
349
|
+
}
|
|
350
|
+
setOpen = (nextOpen, eventDetails) => {
|
|
351
|
+
eventDetails.preventUnmountOnClose = () => {
|
|
352
|
+
this.set('preventUnmountingOnClose', true);
|
|
353
|
+
};
|
|
354
|
+
if (!nextOpen && eventDetails.trigger == null && this.state.activeTriggerId != null) {
|
|
355
|
+
// When closing the dialog, pass the old trigger to the onOpenChange event
|
|
356
|
+
// so it's not reset too early (potentially causing focus issues in controlled scenarios).
|
|
357
|
+
eventDetails.trigger = this.state.activeTriggerElement ?? undefined;
|
|
358
|
+
}
|
|
359
|
+
this.context.onOpenChange?.(nextOpen, eventDetails);
|
|
360
|
+
if (eventDetails.isCanceled) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.state.floatingRootContext.dispatchOpenChange(nextOpen, eventDetails);
|
|
364
|
+
const updatedState = {
|
|
365
|
+
open: nextOpen
|
|
366
|
+
};
|
|
367
|
+
setPopupOpenState(updatedState, nextOpen, eventDetails.trigger);
|
|
368
|
+
this.update(updatedState);
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Creates the inert fallback store used by detached handle-backed triggers while no
|
|
374
|
+
* `Dialog.Root` is attached. It preserves a dialog-specific trigger registry in context so
|
|
375
|
+
* detached triggers can register before migrating to the live root store.
|
|
376
|
+
*/
|
|
377
|
+
function createNullDialogStore() {
|
|
378
|
+
const triggerElements = new PopupTriggerMap();
|
|
379
|
+
return new NullStore(Object.freeze(createInitialState(undefined, triggerElements)), Object.freeze(createInitialContext(triggerElements)), selectors);
|
|
380
|
+
}
|
|
381
|
+
function createInitialState(initialState, triggerElements, floatingId, nested = false) {
|
|
382
|
+
const state = {
|
|
383
|
+
...createInitialPopupStoreState(),
|
|
384
|
+
modal: true,
|
|
385
|
+
disablePointerDismissal: false,
|
|
386
|
+
viewportElement: null,
|
|
387
|
+
descriptionElementId: undefined,
|
|
388
|
+
titleElementId: undefined,
|
|
389
|
+
openMethod: null,
|
|
390
|
+
nested: false,
|
|
391
|
+
nestedOpenDialogCount: 0,
|
|
392
|
+
nestedOpenDrawerCount: 0,
|
|
393
|
+
role: 'dialog',
|
|
394
|
+
...initialState
|
|
395
|
+
};
|
|
396
|
+
state.floatingRootContext = createPopupFloatingRootContext(triggerElements, floatingId, nested);
|
|
397
|
+
return state;
|
|
398
|
+
}
|
|
399
|
+
function createInitialContext(triggerElements) {
|
|
400
|
+
return {
|
|
401
|
+
popupRef: /*#__PURE__*/React.createRef(),
|
|
402
|
+
backdropRef: /*#__PURE__*/React.createRef(),
|
|
403
|
+
internalBackdropRef: /*#__PURE__*/React.createRef(),
|
|
404
|
+
outsidePressEnabledRef: {
|
|
405
|
+
current: true
|
|
406
|
+
},
|
|
407
|
+
triggerElements,
|
|
408
|
+
onOpenChange: undefined,
|
|
409
|
+
onOpenChangeComplete: undefined
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function useRenderDialogRoot(mode, props) {
|
|
414
|
+
const {
|
|
415
|
+
children,
|
|
416
|
+
open: openProp,
|
|
417
|
+
defaultOpen = false,
|
|
418
|
+
onOpenChange,
|
|
419
|
+
onOpenChangeComplete,
|
|
420
|
+
disablePointerDismissal: disablePointerDismissalProp = false,
|
|
421
|
+
modal: modalProp = true,
|
|
422
|
+
actionsRef,
|
|
423
|
+
handle,
|
|
424
|
+
triggerId: triggerIdProp,
|
|
425
|
+
defaultTriggerId: defaultTriggerIdProp = null
|
|
426
|
+
} = props;
|
|
427
|
+
const isDrawer = mode === 'drawer';
|
|
428
|
+
const isAlertDialog = mode === 'alert-dialog';
|
|
429
|
+
const modal = isAlertDialog ? true : modalProp;
|
|
430
|
+
const disablePointerDismissal = isAlertDialog || disablePointerDismissalProp;
|
|
431
|
+
const role = isAlertDialog ? 'alertdialog' : 'dialog';
|
|
432
|
+
const parentStore = useDialogRootContext(true);
|
|
433
|
+
const nested = parentStore != null;
|
|
434
|
+
const rootState = {
|
|
435
|
+
modal,
|
|
436
|
+
disablePointerDismissal,
|
|
437
|
+
nested,
|
|
438
|
+
role
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// The store is owned by this Root instance and created exactly once. It is not tied to the handle:
|
|
442
|
+
// the handle attaches to it, so swapping the handle re-attaches rather than recreating state.
|
|
443
|
+
// Default values are only initial values; controlled values and root state are synced after creation.
|
|
444
|
+
// Dialogs pass the popup element to Floating UI as the floating element (`treatPopupAsFloatingElement`).
|
|
445
|
+
const store = usePopupRootStore((floatingId, floatingNested) => new DialogStore({
|
|
446
|
+
open: defaultOpen,
|
|
447
|
+
openProp,
|
|
448
|
+
activeTriggerId: defaultTriggerIdProp,
|
|
449
|
+
triggerIdProp,
|
|
450
|
+
...rootState
|
|
451
|
+
}, floatingId, floatingNested), true);
|
|
452
|
+
store.useControlledProp('openProp', openProp);
|
|
453
|
+
store.useControlledProp('triggerIdProp', triggerIdProp);
|
|
454
|
+
store.useSyncedValues(rootState);
|
|
455
|
+
store.useContextCallback('onOpenChange', onOpenChange);
|
|
456
|
+
store.useContextCallback('onOpenChangeComplete', onOpenChangeComplete);
|
|
457
|
+
const open = store.useState('open');
|
|
458
|
+
const mounted = store.useState('mounted');
|
|
459
|
+
const payload = store.useState('payload');
|
|
460
|
+
usePopupRootSync(store, open);
|
|
461
|
+
useImplicitActiveTrigger(store);
|
|
462
|
+
const {
|
|
463
|
+
forceUnmount
|
|
464
|
+
} = useOpenStateTransitions(open, store);
|
|
465
|
+
React.useImperativeHandle(actionsRef, () => ({
|
|
466
|
+
unmount: forceUnmount,
|
|
467
|
+
close: () => store.setOpen(false, createChangeEventDetails(imperativeAction))
|
|
468
|
+
}), [forceUnmount, store]);
|
|
469
|
+
const shouldRenderInteractions = open || mounted;
|
|
470
|
+
return /*#__PURE__*/jsxs(DialogRootContext.Provider, {
|
|
471
|
+
value: store,
|
|
472
|
+
children: [handle && /*#__PURE__*/jsx(PopupHandleAttachment, {
|
|
473
|
+
handle: handle,
|
|
474
|
+
store: store
|
|
475
|
+
}), shouldRenderInteractions && /*#__PURE__*/jsx(DialogInteractions, {
|
|
476
|
+
store: store,
|
|
477
|
+
parentContext: parentStore?.context,
|
|
478
|
+
isDrawer: isDrawer
|
|
479
|
+
}), typeof children === 'function' ? children({
|
|
480
|
+
payload
|
|
481
|
+
}) : children]
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* A positioning container for the dialog popup that can be made scrollable.
|
|
487
|
+
* Renders a `<div>` element.
|
|
488
|
+
*
|
|
489
|
+
* Documentation: [Base UI Dialog](https://base-ui.com/react/components/dialog)
|
|
490
|
+
*/
|
|
491
|
+
const DialogViewport = /*#__PURE__*/React.forwardRef(function DialogViewport(componentProps, forwardedRef) {
|
|
492
|
+
const {
|
|
493
|
+
render,
|
|
494
|
+
className,
|
|
495
|
+
style,
|
|
496
|
+
children,
|
|
497
|
+
...elementProps
|
|
498
|
+
} = componentProps;
|
|
499
|
+
const keepMounted = useDialogPortalContext();
|
|
500
|
+
const store = useDialogRootContext();
|
|
501
|
+
const open = store.useState('open');
|
|
502
|
+
const nested = store.useState('nested');
|
|
503
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
504
|
+
const nestedOpenDialogCount = store.useState('nestedOpenDialogCount');
|
|
505
|
+
const mounted = store.useState('mounted');
|
|
506
|
+
const setViewportElement = store.useStateSetter('viewportElement');
|
|
507
|
+
const nestedDialogOpen = nestedOpenDialogCount > 0;
|
|
508
|
+
const state = {
|
|
509
|
+
open,
|
|
510
|
+
nested,
|
|
511
|
+
transitionStatus,
|
|
512
|
+
nestedDialogOpen
|
|
513
|
+
};
|
|
514
|
+
const shouldRender = keepMounted || mounted;
|
|
515
|
+
return useRenderElement('div', componentProps, {
|
|
516
|
+
enabled: shouldRender,
|
|
517
|
+
state,
|
|
518
|
+
ref: [forwardedRef, setViewportElement],
|
|
519
|
+
stateAttributesMapping: dialogStateAttributesMapping,
|
|
520
|
+
props: [{
|
|
521
|
+
role: 'presentation',
|
|
522
|
+
hidden: !mounted,
|
|
523
|
+
style: {
|
|
524
|
+
pointerEvents: !open ? 'none' : undefined
|
|
525
|
+
},
|
|
526
|
+
children
|
|
527
|
+
}, elementProps]
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
if (process.env.NODE_ENV !== "production") DialogViewport.displayName = "DialogViewport";
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* A button that opens the dialog.
|
|
534
|
+
* Renders a `<button>` element.
|
|
535
|
+
*
|
|
536
|
+
* Documentation: [Base UI Dialog](https://base-ui.com/react/components/dialog)
|
|
537
|
+
*/
|
|
538
|
+
const DialogTrigger = /*#__PURE__*/React.forwardRef(function DialogTrigger(componentProps, forwardedRef) {
|
|
539
|
+
const {
|
|
540
|
+
render,
|
|
541
|
+
className,
|
|
542
|
+
style,
|
|
543
|
+
disabled = false,
|
|
544
|
+
nativeButton = true,
|
|
545
|
+
id: idProp,
|
|
546
|
+
payload,
|
|
547
|
+
handle,
|
|
548
|
+
...elementProps
|
|
549
|
+
} = componentProps;
|
|
550
|
+
const dialogRootStore = useDialogRootContext(true);
|
|
551
|
+
const handleStore = usePopupHandleStore(handle);
|
|
552
|
+
const store = handleStore ?? dialogRootStore;
|
|
553
|
+
if (!store) {
|
|
554
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Dialog.Trigger> must be used within <Dialog.Root> or provided with a handle.' : formatErrorMessage(79));
|
|
555
|
+
}
|
|
556
|
+
const thisTriggerId = useBaseUiId(idProp);
|
|
557
|
+
const floatingContext = store.useState('floatingRootContext');
|
|
558
|
+
const isOpenedByThisTrigger = store.useState('isOpenedByTrigger', thisTriggerId);
|
|
559
|
+
const popupId = store.useState('triggerPopupId', thisTriggerId);
|
|
560
|
+
const triggerElementRef = React.useRef(null);
|
|
561
|
+
const {
|
|
562
|
+
registerTrigger,
|
|
563
|
+
isMountedByThisTrigger
|
|
564
|
+
} = useTriggerDataForwarding(thisTriggerId, triggerElementRef, store, {
|
|
565
|
+
payload
|
|
566
|
+
});
|
|
567
|
+
const {
|
|
568
|
+
getButtonProps,
|
|
569
|
+
buttonRef
|
|
570
|
+
} = useButton({
|
|
571
|
+
disabled,
|
|
572
|
+
native: nativeButton
|
|
573
|
+
});
|
|
574
|
+
const click = useClick(floatingContext);
|
|
575
|
+
const interactionTypeProps = useOpenMethodTriggerProps(() => store.select('open'), interactionType => {
|
|
576
|
+
store.set('openMethod', interactionType);
|
|
577
|
+
});
|
|
578
|
+
const state = {
|
|
579
|
+
disabled,
|
|
580
|
+
open: isOpenedByThisTrigger
|
|
581
|
+
};
|
|
582
|
+
const rootTriggerProps = store.useState('triggerProps', isMountedByThisTrigger);
|
|
583
|
+
return useRenderElement('button', componentProps, {
|
|
584
|
+
state,
|
|
585
|
+
ref: [buttonRef, forwardedRef, registerTrigger, triggerElementRef],
|
|
586
|
+
props: [click.reference, rootTriggerProps, interactionTypeProps, {
|
|
587
|
+
[CLICK_TRIGGER_IDENTIFIER]: '',
|
|
588
|
+
id: thisTriggerId,
|
|
589
|
+
'aria-haspopup': 'dialog',
|
|
590
|
+
'aria-expanded': isOpenedByThisTrigger,
|
|
591
|
+
'aria-controls': popupId
|
|
592
|
+
}, elementProps, getButtonProps],
|
|
593
|
+
stateAttributesMapping: triggerOpenStateMapping
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
if (process.env.NODE_ENV !== "production") DialogTrigger.displayName = "DialogTrigger";
|
|
597
|
+
|
|
598
|
+
let DrawerPopupCssVars = /*#__PURE__*/function (DrawerPopupCssVars) {
|
|
599
|
+
/**
|
|
600
|
+
* The number of nested drawers that are currently open.
|
|
601
|
+
* @type {number}
|
|
602
|
+
*/
|
|
603
|
+
DrawerPopupCssVars["nestedDrawers"] = "--nested-drawers";
|
|
604
|
+
/**
|
|
605
|
+
* The height of the drawer popup.
|
|
606
|
+
* @type {CSS length}
|
|
607
|
+
*/
|
|
608
|
+
DrawerPopupCssVars["height"] = "--drawer-height";
|
|
609
|
+
/**
|
|
610
|
+
* The height of the frontmost open drawer in the current nested drawer stack.
|
|
611
|
+
* @type {CSS length}
|
|
612
|
+
*/
|
|
613
|
+
DrawerPopupCssVars["frontmostHeight"] = "--drawer-frontmost-height";
|
|
614
|
+
/**
|
|
615
|
+
* The swipe movement on the X axis.
|
|
616
|
+
* @type {CSS length}
|
|
617
|
+
*/
|
|
618
|
+
DrawerPopupCssVars["swipeMovementX"] = "--drawer-swipe-movement-x";
|
|
619
|
+
/**
|
|
620
|
+
* The swipe movement on the Y axis.
|
|
621
|
+
* @type {CSS length}
|
|
622
|
+
*/
|
|
623
|
+
DrawerPopupCssVars["swipeMovementY"] = "--drawer-swipe-movement-y";
|
|
624
|
+
/**
|
|
625
|
+
* The snap point offset used for translating the drawer.
|
|
626
|
+
* @type {CSS length}
|
|
627
|
+
*/
|
|
628
|
+
DrawerPopupCssVars["snapPointOffset"] = "--drawer-snap-point-offset";
|
|
629
|
+
/**
|
|
630
|
+
* A scalar (0.1-1) used to scale the swipe release transition duration in CSS.
|
|
631
|
+
* @type {number}
|
|
632
|
+
*/
|
|
633
|
+
DrawerPopupCssVars["swipeStrength"] = "--drawer-swipe-strength";
|
|
634
|
+
return DrawerPopupCssVars;
|
|
635
|
+
}({});
|
|
636
|
+
|
|
637
|
+
let DrawerBackdropCssVars = /*#__PURE__*/function (DrawerBackdropCssVars) {
|
|
638
|
+
/**
|
|
639
|
+
* The swipe progress of the drawer gesture.
|
|
640
|
+
* @type {number}
|
|
641
|
+
*/
|
|
642
|
+
DrawerBackdropCssVars["swipeProgress"] = "--drawer-swipe-progress";
|
|
643
|
+
return DrawerBackdropCssVars;
|
|
644
|
+
}({});
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* An overlay displayed beneath the popup.
|
|
648
|
+
* Renders a `<div>` element.
|
|
649
|
+
*
|
|
650
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
651
|
+
*/
|
|
652
|
+
const DrawerBackdrop = /*#__PURE__*/React.forwardRef(function DrawerBackdrop(componentProps, forwardedRef) {
|
|
653
|
+
const {
|
|
654
|
+
render,
|
|
655
|
+
className,
|
|
656
|
+
style,
|
|
657
|
+
forceRender = false,
|
|
658
|
+
...elementProps
|
|
659
|
+
} = componentProps;
|
|
660
|
+
const store = useDialogRootContext();
|
|
661
|
+
const open = store.useState('open');
|
|
662
|
+
const nested = store.useState('nested');
|
|
663
|
+
const mounted = store.useState('mounted');
|
|
664
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
665
|
+
const state = {
|
|
666
|
+
open,
|
|
667
|
+
transitionStatus
|
|
668
|
+
};
|
|
669
|
+
return useRenderElement('div', componentProps, {
|
|
670
|
+
state,
|
|
671
|
+
ref: [store.context.backdropRef, forwardedRef],
|
|
672
|
+
stateAttributesMapping: popupTransitionStateMapping,
|
|
673
|
+
props: [{
|
|
674
|
+
role: 'presentation',
|
|
675
|
+
hidden: !mounted,
|
|
676
|
+
style: {
|
|
677
|
+
pointerEvents: !open ? 'none' : undefined,
|
|
678
|
+
userSelect: 'none',
|
|
679
|
+
WebkitUserSelect: 'none',
|
|
680
|
+
[DrawerBackdropCssVars.swipeProgress]: '0',
|
|
681
|
+
[DrawerPopupCssVars.swipeStrength]: '1'
|
|
682
|
+
}
|
|
683
|
+
}, elementProps],
|
|
684
|
+
enabled: forceRender || !nested
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
if (process.env.NODE_ENV !== "production") DrawerBackdrop.displayName = "DrawerBackdrop";
|
|
688
|
+
|
|
689
|
+
const DRAWER_CONTENT_ATTRIBUTE = 'data-drawer-content';
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* A container for the drawer contents.
|
|
693
|
+
* Renders a `<div>` element.
|
|
694
|
+
*
|
|
695
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
696
|
+
*/
|
|
697
|
+
const DrawerContent = /*#__PURE__*/React.forwardRef(function DrawerContent(componentProps, forwardedRef) {
|
|
698
|
+
const {
|
|
699
|
+
render,
|
|
700
|
+
className,
|
|
701
|
+
style,
|
|
702
|
+
...elementProps
|
|
703
|
+
} = componentProps;
|
|
704
|
+
useDialogRootContext();
|
|
705
|
+
return useRenderElement('div', componentProps, {
|
|
706
|
+
ref: forwardedRef,
|
|
707
|
+
props: [{
|
|
708
|
+
[DRAWER_CONTENT_ATTRIBUTE]: ''
|
|
709
|
+
}, elementProps]
|
|
710
|
+
});
|
|
711
|
+
});
|
|
712
|
+
if (process.env.NODE_ENV !== "production") DrawerContent.displayName = "DrawerContent";
|
|
713
|
+
|
|
714
|
+
const DrawerProviderContext = /*#__PURE__*/React.createContext(undefined);
|
|
715
|
+
if (process.env.NODE_ENV !== "production") DrawerProviderContext.displayName = "DrawerProviderContext";
|
|
716
|
+
function useDrawerProviderContext() {
|
|
717
|
+
return React.useContext(DrawerProviderContext);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
let DrawerPopupDataAttributes = function (DrawerPopupDataAttributes) {
|
|
721
|
+
/**
|
|
722
|
+
* Present when the drawer is open.
|
|
723
|
+
*/
|
|
724
|
+
DrawerPopupDataAttributes[DrawerPopupDataAttributes["open"] = CommonPopupDataAttributes.open] = "open";
|
|
725
|
+
/**
|
|
726
|
+
* Present when the drawer is closed.
|
|
727
|
+
*/
|
|
728
|
+
DrawerPopupDataAttributes[DrawerPopupDataAttributes["closed"] = CommonPopupDataAttributes.closed] = "closed";
|
|
729
|
+
/**
|
|
730
|
+
* Present when the drawer begins animating in.
|
|
731
|
+
*/
|
|
732
|
+
DrawerPopupDataAttributes[DrawerPopupDataAttributes["startingStyle"] = CommonPopupDataAttributes.startingStyle] = "startingStyle";
|
|
733
|
+
/**
|
|
734
|
+
* Present when the drawer is animating out.
|
|
735
|
+
*/
|
|
736
|
+
DrawerPopupDataAttributes[DrawerPopupDataAttributes["endingStyle"] = CommonPopupDataAttributes.endingStyle] = "endingStyle";
|
|
737
|
+
/**
|
|
738
|
+
* Present when the drawer is at the expanded (full-height) snap point.
|
|
739
|
+
*/
|
|
740
|
+
DrawerPopupDataAttributes["expanded"] = "data-expanded";
|
|
741
|
+
/**
|
|
742
|
+
* Present when a nested drawer is open.
|
|
743
|
+
*/
|
|
744
|
+
DrawerPopupDataAttributes["nestedDrawerOpen"] = "data-nested-drawer-open";
|
|
745
|
+
/**
|
|
746
|
+
* Present when a nested drawer is being swiped.
|
|
747
|
+
*/
|
|
748
|
+
DrawerPopupDataAttributes["nestedDrawerSwiping"] = "data-nested-drawer-swiping";
|
|
749
|
+
/**
|
|
750
|
+
* Present when the drawer is dismissed by swiping.
|
|
751
|
+
*/
|
|
752
|
+
DrawerPopupDataAttributes["swipeDismiss"] = "data-swipe-dismiss";
|
|
753
|
+
/**
|
|
754
|
+
* Indicates the swipe direction.
|
|
755
|
+
* @type {'up' | 'down' | 'left' | 'right'}
|
|
756
|
+
*/
|
|
757
|
+
DrawerPopupDataAttributes["swipeDirection"] = "data-swipe-direction";
|
|
758
|
+
/**
|
|
759
|
+
* Present when the drawer is being swiped.
|
|
760
|
+
*/
|
|
761
|
+
DrawerPopupDataAttributes["swiping"] = "data-swiping";
|
|
762
|
+
return DrawerPopupDataAttributes;
|
|
763
|
+
}({});
|
|
764
|
+
|
|
765
|
+
const DrawerRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
766
|
+
if (process.env.NODE_ENV !== "production") DrawerRootContext.displayName = "DrawerRootContext";
|
|
767
|
+
function useDrawerRootContext(optional) {
|
|
768
|
+
const drawerRootContext = React.useContext(DrawerRootContext);
|
|
769
|
+
if (optional !== true && drawerRootContext === undefined) {
|
|
770
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: DrawerRootContext is missing. Drawer parts must be placed within <Drawer.Root>.' : formatErrorMessage(90));
|
|
771
|
+
}
|
|
772
|
+
return drawerRootContext;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Resolves the vertical swipe movement for a snap point, applying square-root damping once the drag
|
|
777
|
+
* overshoots the fully-open edge (`nextOffset < 0`) so the popup resists travelling past it.
|
|
778
|
+
*/
|
|
779
|
+
function getSnapPointSwipeMovement(baseOffset, movementValue) {
|
|
780
|
+
const nextOffset = baseOffset + movementValue;
|
|
781
|
+
if (nextOffset >= 0) {
|
|
782
|
+
return movementValue;
|
|
783
|
+
}
|
|
784
|
+
return -Math.sqrt(-nextOffset) - baseOffset;
|
|
785
|
+
}
|
|
786
|
+
function resolveSnapPointValue(snapPoint, viewportHeight, rootFontSize) {
|
|
787
|
+
if (!Number.isFinite(viewportHeight) || viewportHeight <= 0) {
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
if (typeof snapPoint === 'number') {
|
|
791
|
+
if (!Number.isFinite(snapPoint)) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
if (snapPoint <= 1) {
|
|
795
|
+
return clamp(snapPoint, 0, 1) * viewportHeight;
|
|
796
|
+
}
|
|
797
|
+
return snapPoint;
|
|
798
|
+
}
|
|
799
|
+
const trimmed = snapPoint.trim();
|
|
800
|
+
if (trimmed.endsWith('px')) {
|
|
801
|
+
const value = Number.parseFloat(trimmed);
|
|
802
|
+
return Number.isFinite(value) ? value : null;
|
|
803
|
+
}
|
|
804
|
+
if (trimmed.endsWith('rem')) {
|
|
805
|
+
const value = Number.parseFloat(trimmed);
|
|
806
|
+
return Number.isFinite(value) ? value * rootFontSize : null;
|
|
807
|
+
}
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Returns the index of the value closest to `target`, or `-1` if `values` is empty.
|
|
813
|
+
*/
|
|
814
|
+
function closestSnapPointIndex(values, target) {
|
|
815
|
+
let closestIndex = -1;
|
|
816
|
+
let closestDistance = Infinity;
|
|
817
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
818
|
+
const distance = Math.abs(values[index] - target);
|
|
819
|
+
if (distance < closestDistance) {
|
|
820
|
+
closestDistance = distance;
|
|
821
|
+
closestIndex = index;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return closestIndex;
|
|
825
|
+
}
|
|
826
|
+
function useDrawerSnapPoints() {
|
|
827
|
+
const store = useDialogRootContext();
|
|
828
|
+
const {
|
|
829
|
+
snapPoints,
|
|
830
|
+
activeSnapPoint,
|
|
831
|
+
setActiveSnapPoint,
|
|
832
|
+
popupHeight
|
|
833
|
+
} = useDrawerRootContext();
|
|
834
|
+
const viewportElement = store.useState('viewportElement');
|
|
835
|
+
const [viewportHeight, setViewportHeight] = React.useState(0);
|
|
836
|
+
const [rootFontSize, setRootFontSize] = React.useState(16);
|
|
837
|
+
const measureViewportHeight = useStableCallback(() => {
|
|
838
|
+
const doc = ownerDocument(viewportElement);
|
|
839
|
+
const html = doc.documentElement;
|
|
840
|
+
setViewportHeight(viewportElement ? viewportElement.offsetHeight : html.clientHeight);
|
|
841
|
+
const fontSize = parseFloat(getComputedStyle(html).fontSize);
|
|
842
|
+
if (Number.isFinite(fontSize)) {
|
|
843
|
+
setRootFontSize(fontSize);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
useIsoLayoutEffect(() => {
|
|
847
|
+
measureViewportHeight();
|
|
848
|
+
if (!viewportElement || typeof ResizeObserver !== 'function') {
|
|
849
|
+
return undefined;
|
|
850
|
+
}
|
|
851
|
+
const resizeObserver = new ResizeObserver(measureViewportHeight);
|
|
852
|
+
resizeObserver.observe(viewportElement);
|
|
853
|
+
return () => {
|
|
854
|
+
resizeObserver.disconnect();
|
|
855
|
+
};
|
|
856
|
+
}, [measureViewportHeight, viewportElement]);
|
|
857
|
+
const resolvedSnapPoints = React.useMemo(() => {
|
|
858
|
+
if (!snapPoints || snapPoints.length === 0 || viewportHeight <= 0 || popupHeight <= 0) {
|
|
859
|
+
return [];
|
|
860
|
+
}
|
|
861
|
+
const maxHeight = Math.min(popupHeight, viewportHeight);
|
|
862
|
+
const resolved = snapPoints.map(value => {
|
|
863
|
+
const resolvedHeight = resolveSnapPointValue(value, viewportHeight, rootFontSize);
|
|
864
|
+
if (resolvedHeight === null) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
const clampedHeight = clamp(resolvedHeight, 0, maxHeight);
|
|
868
|
+
return {
|
|
869
|
+
value,
|
|
870
|
+
height: clampedHeight,
|
|
871
|
+
offset: Math.max(0, popupHeight - clampedHeight)
|
|
872
|
+
};
|
|
873
|
+
}).filter(point => Boolean(point));
|
|
874
|
+
if (resolved.length <= 1) {
|
|
875
|
+
return resolved;
|
|
876
|
+
}
|
|
877
|
+
const deduped = [];
|
|
878
|
+
const seenHeights = [];
|
|
879
|
+
for (let index = resolved.length - 1; index >= 0; index -= 1) {
|
|
880
|
+
const point = resolved[index];
|
|
881
|
+
const isDuplicate = seenHeights.some(height => Math.abs(height - point.height) <= 1);
|
|
882
|
+
if (isDuplicate) {
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
seenHeights.push(point.height);
|
|
886
|
+
deduped.push(point);
|
|
887
|
+
}
|
|
888
|
+
deduped.reverse();
|
|
889
|
+
return deduped;
|
|
890
|
+
}, [popupHeight, rootFontSize, snapPoints, viewportHeight]);
|
|
891
|
+
const resolvedActiveSnapPoint = React.useMemo(() => {
|
|
892
|
+
if (activeSnapPoint === null) {
|
|
893
|
+
return undefined;
|
|
894
|
+
}
|
|
895
|
+
const exactMatch = resolvedSnapPoints.find(point => Object.is(point.value, activeSnapPoint));
|
|
896
|
+
if (exactMatch) {
|
|
897
|
+
return exactMatch;
|
|
898
|
+
}
|
|
899
|
+
const maxHeight = Math.min(popupHeight, viewportHeight);
|
|
900
|
+
const resolvedHeight = resolveSnapPointValue(activeSnapPoint, viewportHeight, rootFontSize);
|
|
901
|
+
if (resolvedHeight === null) {
|
|
902
|
+
return undefined;
|
|
903
|
+
}
|
|
904
|
+
const clampedHeight = clamp(resolvedHeight, 0, maxHeight);
|
|
905
|
+
return resolvedSnapPoints[closestSnapPointIndex(resolvedSnapPoints.map(point => point.height), clampedHeight)];
|
|
906
|
+
}, [activeSnapPoint, popupHeight, resolvedSnapPoints, rootFontSize, viewportHeight]);
|
|
907
|
+
return {
|
|
908
|
+
snapPoints,
|
|
909
|
+
activeSnapPoint,
|
|
910
|
+
setActiveSnapPoint,
|
|
911
|
+
popupHeight,
|
|
912
|
+
viewportHeight,
|
|
913
|
+
resolvedSnapPoints,
|
|
914
|
+
activeSnapPointOffset: resolvedActiveSnapPoint?.offset ?? null
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const DrawerViewportContext = /*#__PURE__*/React.createContext(null);
|
|
919
|
+
if (process.env.NODE_ENV !== "production") DrawerViewportContext.displayName = "DrawerViewportContext";
|
|
920
|
+
function useDrawerViewportContext() {
|
|
921
|
+
return React.useContext(DrawerViewportContext);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
let drawerSwipeVarsRegistered = false;
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Removes inheritance of high-frequency drawer swipe CSS variables, which
|
|
928
|
+
* reduces style recalculation cost in complex drawers with deep subtrees.
|
|
929
|
+
* See https://motion.dev/blog/web-animation-performance-tier-list
|
|
930
|
+
* under the "Improving CSS variable performance" section.
|
|
931
|
+
*/
|
|
932
|
+
function removeCSSVariableInheritance$1() {
|
|
933
|
+
if (drawerSwipeVarsRegistered) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// Intentionally keep inheritance disabled on WebKit as well. Safari doesn't support
|
|
938
|
+
// opting descendants back in via `--var: inherit` for custom properties registered
|
|
939
|
+
// with `inherits: false`, but Drawer does not rely on descendant access to these vars
|
|
940
|
+
// (unlike ScrollArea), so we keep the performance optimization enabled.
|
|
941
|
+
if (typeof CSS !== 'undefined' && 'registerProperty' in CSS) {
|
|
942
|
+
[DrawerPopupCssVars.swipeMovementX, DrawerPopupCssVars.swipeMovementY, DrawerPopupCssVars.snapPointOffset].forEach(name => {
|
|
943
|
+
try {
|
|
944
|
+
CSS.registerProperty({
|
|
945
|
+
name,
|
|
946
|
+
syntax: '<length>',
|
|
947
|
+
inherits: false,
|
|
948
|
+
initialValue: '0px'
|
|
949
|
+
});
|
|
950
|
+
} catch {
|
|
951
|
+
/* ignore already-registered */
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
[{
|
|
955
|
+
name: DrawerBackdropCssVars.swipeProgress,
|
|
956
|
+
initialValue: '0'
|
|
957
|
+
}, {
|
|
958
|
+
name: DrawerPopupCssVars.swipeStrength,
|
|
959
|
+
initialValue: '1'
|
|
960
|
+
}].forEach(({
|
|
961
|
+
name,
|
|
962
|
+
initialValue
|
|
963
|
+
}) => {
|
|
964
|
+
try {
|
|
965
|
+
CSS.registerProperty({
|
|
966
|
+
name,
|
|
967
|
+
syntax: '<number>',
|
|
968
|
+
inherits: false,
|
|
969
|
+
initialValue
|
|
970
|
+
});
|
|
971
|
+
} catch {
|
|
972
|
+
/* ignore already-registered */
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
drawerSwipeVarsRegistered = true;
|
|
977
|
+
}
|
|
978
|
+
const stateAttributesMapping = {
|
|
979
|
+
...popupTransitionStateMapping,
|
|
980
|
+
expanded(value) {
|
|
981
|
+
return value ? {
|
|
982
|
+
[DrawerPopupDataAttributes.expanded]: ''
|
|
983
|
+
} : null;
|
|
984
|
+
},
|
|
985
|
+
nestedDrawerOpen(value) {
|
|
986
|
+
return value ? {
|
|
987
|
+
[DrawerPopupDataAttributes.nestedDrawerOpen]: ''
|
|
988
|
+
} : null;
|
|
989
|
+
},
|
|
990
|
+
nestedDrawerSwiping(value) {
|
|
991
|
+
return value ? {
|
|
992
|
+
[DrawerPopupDataAttributes.nestedDrawerSwiping]: ''
|
|
993
|
+
} : null;
|
|
994
|
+
},
|
|
995
|
+
swipeDirection(value) {
|
|
996
|
+
return {
|
|
997
|
+
[DrawerPopupDataAttributes.swipeDirection]: value
|
|
998
|
+
};
|
|
999
|
+
},
|
|
1000
|
+
swiping(value) {
|
|
1001
|
+
return value ? {
|
|
1002
|
+
[DrawerPopupDataAttributes.swiping]: ''
|
|
1003
|
+
} : null;
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* A container for the drawer contents.
|
|
1009
|
+
* Renders a `<div>` element.
|
|
1010
|
+
*
|
|
1011
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
1012
|
+
*/
|
|
1013
|
+
const DrawerPopup = /*#__PURE__*/React.forwardRef(function DrawerPopup(componentProps, forwardedRef) {
|
|
1014
|
+
const {
|
|
1015
|
+
render,
|
|
1016
|
+
className,
|
|
1017
|
+
style,
|
|
1018
|
+
finalFocus,
|
|
1019
|
+
initialFocus,
|
|
1020
|
+
...elementProps
|
|
1021
|
+
} = componentProps;
|
|
1022
|
+
const store = useDialogRootContext();
|
|
1023
|
+
const popupRef = store.context.popupRef;
|
|
1024
|
+
const {
|
|
1025
|
+
swipeDirection,
|
|
1026
|
+
frontmostHeight,
|
|
1027
|
+
hasNestedDrawer,
|
|
1028
|
+
nestedSwiping,
|
|
1029
|
+
nestedSwipeProgressStore,
|
|
1030
|
+
onPopupHeightChange,
|
|
1031
|
+
notifyParentFrontmostHeight,
|
|
1032
|
+
notifyParentHasNestedDrawer
|
|
1033
|
+
} = useDrawerRootContext();
|
|
1034
|
+
const descriptionElementId = store.useState('descriptionElementId');
|
|
1035
|
+
const disablePointerDismissal = store.useState('disablePointerDismissal');
|
|
1036
|
+
const floatingRootContext = store.useState('floatingRootContext');
|
|
1037
|
+
const rootPopupProps = store.useState('popupProps');
|
|
1038
|
+
const modal = store.useState('modal');
|
|
1039
|
+
const mounted = store.useState('mounted');
|
|
1040
|
+
const nested = store.useState('nested');
|
|
1041
|
+
const nestedOpenDrawerCount = store.useState('nestedOpenDrawerCount');
|
|
1042
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
1043
|
+
const open = store.useState('open');
|
|
1044
|
+
const openMethod = store.useState('openMethod');
|
|
1045
|
+
const titleElementId = store.useState('titleElementId');
|
|
1046
|
+
const role = store.useState('role');
|
|
1047
|
+
const floatingId = floatingRootContext.useState('floatingId');
|
|
1048
|
+
const popupId = elementProps.id ?? floatingId;
|
|
1049
|
+
const swipe = useDrawerViewportContext();
|
|
1050
|
+
useDialogPortalContext();
|
|
1051
|
+
const {
|
|
1052
|
+
snapPoints,
|
|
1053
|
+
activeSnapPoint,
|
|
1054
|
+
activeSnapPointOffset
|
|
1055
|
+
} = useDrawerSnapPoints();
|
|
1056
|
+
const nestedDrawerOpen = nestedOpenDrawerCount > 0;
|
|
1057
|
+
const swiping = swipe?.swiping ?? false;
|
|
1058
|
+
const swipeStrength = swipe?.swipeStrength ?? null;
|
|
1059
|
+
const [popupHeight, setPopupHeight] = React.useState(0);
|
|
1060
|
+
const popupHeightRef = React.useRef(0);
|
|
1061
|
+
|
|
1062
|
+
/* istanbul ignore else -- process.env.NODE_ENV is a build-time constant. */
|
|
1063
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1064
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
1065
|
+
React.useEffect(() => {
|
|
1066
|
+
if (swipe) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const ownerStackMessage = SafeReact.captureOwnerStack?.() || '';
|
|
1070
|
+
const message = '<Drawer.Popup> expected to be rendered within <Drawer.Viewport>. Omitting the ' + 'viewport disables drawer swipe handling and touch scroll locking. Wrap ' + '<Drawer.Popup> in <Drawer.Viewport>.';
|
|
1071
|
+
error(`${message}${ownerStackMessage}`);
|
|
1072
|
+
}, [swipe]);
|
|
1073
|
+
}
|
|
1074
|
+
const measureHeight = useStableCallback(() => {
|
|
1075
|
+
const popupElement = popupRef.current;
|
|
1076
|
+
if (!popupElement) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
const offsetHeight = popupElement.offsetHeight;
|
|
1080
|
+
|
|
1081
|
+
// Only skip while the element is still actually stretched beyond its last measured height.
|
|
1082
|
+
if (popupHeightRef.current > 0 && frontmostHeight > popupHeightRef.current && offsetHeight > popupHeightRef.current) {
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
const keepHeightWhileNested = popupHeightRef.current > 0 && hasNestedDrawer;
|
|
1086
|
+
if (keepHeightWhileNested) {
|
|
1087
|
+
const oldHeight = popupHeightRef.current;
|
|
1088
|
+
setPopupHeight(oldHeight);
|
|
1089
|
+
onPopupHeightChange(oldHeight);
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
const nextHeight = offsetHeight;
|
|
1093
|
+
if (nextHeight === popupHeightRef.current) {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
popupHeightRef.current = nextHeight;
|
|
1097
|
+
setPopupHeight(nextHeight);
|
|
1098
|
+
onPopupHeightChange(nextHeight);
|
|
1099
|
+
});
|
|
1100
|
+
useIsoLayoutEffect(() => {
|
|
1101
|
+
if (!mounted) {
|
|
1102
|
+
popupHeightRef.current = 0;
|
|
1103
|
+
setPopupHeight(0);
|
|
1104
|
+
onPopupHeightChange(0);
|
|
1105
|
+
return undefined;
|
|
1106
|
+
}
|
|
1107
|
+
const popupElement = popupRef.current;
|
|
1108
|
+
if (!popupElement) {
|
|
1109
|
+
return undefined;
|
|
1110
|
+
}
|
|
1111
|
+
removeCSSVariableInheritance$1();
|
|
1112
|
+
measureHeight();
|
|
1113
|
+
if (typeof ResizeObserver !== 'function') {
|
|
1114
|
+
return undefined;
|
|
1115
|
+
}
|
|
1116
|
+
const resizeObserver = new ResizeObserver(measureHeight);
|
|
1117
|
+
resizeObserver.observe(popupElement);
|
|
1118
|
+
return () => {
|
|
1119
|
+
resizeObserver.disconnect();
|
|
1120
|
+
};
|
|
1121
|
+
}, [measureHeight, mounted, nestedDrawerOpen, onPopupHeightChange, popupRef]);
|
|
1122
|
+
useIsoLayoutEffect(() => {
|
|
1123
|
+
const syncNestedSwipeProgress = () => {
|
|
1124
|
+
const popupElement = popupRef.current;
|
|
1125
|
+
if (!popupElement) {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
const progress = nestedSwipeProgressStore.getSnapshot();
|
|
1129
|
+
if (progress > 0) {
|
|
1130
|
+
popupElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, `${progress}`);
|
|
1131
|
+
} else {
|
|
1132
|
+
popupElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, '0');
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
syncNestedSwipeProgress();
|
|
1136
|
+
const unsubscribe = nestedSwipeProgressStore.subscribe(syncNestedSwipeProgress);
|
|
1137
|
+
const popupElement = popupRef.current;
|
|
1138
|
+
return () => {
|
|
1139
|
+
unsubscribe();
|
|
1140
|
+
if (popupElement) {
|
|
1141
|
+
popupElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, '0');
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
}, [nestedSwipeProgressStore, popupRef]);
|
|
1145
|
+
useIsoLayoutEffect(() => {
|
|
1146
|
+
if (!open) {
|
|
1147
|
+
return undefined;
|
|
1148
|
+
}
|
|
1149
|
+
notifyParentFrontmostHeight?.(frontmostHeight);
|
|
1150
|
+
return () => {
|
|
1151
|
+
notifyParentFrontmostHeight?.(0);
|
|
1152
|
+
};
|
|
1153
|
+
}, [frontmostHeight, open, notifyParentFrontmostHeight]);
|
|
1154
|
+
useIsoLayoutEffect(() => {
|
|
1155
|
+
if (!notifyParentHasNestedDrawer) {
|
|
1156
|
+
return undefined;
|
|
1157
|
+
}
|
|
1158
|
+
const present = open || transitionStatus === 'ending';
|
|
1159
|
+
notifyParentHasNestedDrawer(present);
|
|
1160
|
+
return () => {
|
|
1161
|
+
notifyParentHasNestedDrawer(false);
|
|
1162
|
+
};
|
|
1163
|
+
}, [notifyParentHasNestedDrawer, open, transitionStatus]);
|
|
1164
|
+
useOpenChangeComplete({
|
|
1165
|
+
open,
|
|
1166
|
+
ref: popupRef,
|
|
1167
|
+
onComplete() {
|
|
1168
|
+
if (open) {
|
|
1169
|
+
store.context.onOpenChangeComplete?.(true);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
const resolvedInitialFocus = initialFocus === undefined ? popupRef : initialFocus;
|
|
1174
|
+
const setPopupElement = store.useStateSetter('popupElement');
|
|
1175
|
+
const state = {
|
|
1176
|
+
open,
|
|
1177
|
+
nested,
|
|
1178
|
+
transitionStatus,
|
|
1179
|
+
expanded: activeSnapPoint === 1,
|
|
1180
|
+
nestedDrawerOpen,
|
|
1181
|
+
nestedDrawerSwiping: nestedSwiping,
|
|
1182
|
+
swipeDirection,
|
|
1183
|
+
swiping
|
|
1184
|
+
};
|
|
1185
|
+
let popupHeightCssVarValue;
|
|
1186
|
+
const shouldUseAutoHeight = !hasNestedDrawer && transitionStatus !== 'ending';
|
|
1187
|
+
if (popupHeight && !shouldUseAutoHeight) {
|
|
1188
|
+
popupHeightCssVarValue = `${popupHeight}px`;
|
|
1189
|
+
}
|
|
1190
|
+
const shouldApplySnapPoints = snapPoints && snapPoints.length > 0 && (swipeDirection === 'down' || swipeDirection === 'up');
|
|
1191
|
+
let snapPointOffsetValue = null;
|
|
1192
|
+
if (shouldApplySnapPoints && activeSnapPointOffset !== null) {
|
|
1193
|
+
snapPointOffsetValue = swipeDirection === 'up' ? -activeSnapPointOffset : activeSnapPointOffset;
|
|
1194
|
+
}
|
|
1195
|
+
let dragStyles = swipe ? swipe.getDragStyles() : EMPTY_OBJECT;
|
|
1196
|
+
if (shouldApplySnapPoints && swipeDirection === 'down') {
|
|
1197
|
+
const baseOffset = activeSnapPointOffset ?? 0;
|
|
1198
|
+
const movementValue = Number.parseFloat(String(dragStyles[DrawerPopupCssVars.swipeMovementY]));
|
|
1199
|
+
if (swiping && Number.isFinite(movementValue)) {
|
|
1200
|
+
dragStyles = {
|
|
1201
|
+
...dragStyles,
|
|
1202
|
+
transform: undefined,
|
|
1203
|
+
[DrawerPopupCssVars.swipeMovementY]: `${getSnapPointSwipeMovement(baseOffset, movementValue)}px`
|
|
1204
|
+
};
|
|
1205
|
+
} else {
|
|
1206
|
+
dragStyles = {
|
|
1207
|
+
...dragStyles,
|
|
1208
|
+
transform: undefined
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const element = useRenderElement('div', componentProps, {
|
|
1213
|
+
state,
|
|
1214
|
+
props: [rootPopupProps, {
|
|
1215
|
+
id: popupId,
|
|
1216
|
+
'aria-labelledby': titleElementId,
|
|
1217
|
+
'aria-describedby': descriptionElementId,
|
|
1218
|
+
role,
|
|
1219
|
+
...FOCUSABLE_POPUP_PROPS,
|
|
1220
|
+
hidden: !mounted,
|
|
1221
|
+
onKeyDown(event) {
|
|
1222
|
+
if (COMPOSITE_KEYS.has(event.key)) {
|
|
1223
|
+
event.stopPropagation();
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
style: {
|
|
1227
|
+
...dragStyles,
|
|
1228
|
+
[DrawerBackdropCssVars.swipeProgress]: '0',
|
|
1229
|
+
[DrawerPopupCssVars.nestedDrawers]: nestedOpenDrawerCount,
|
|
1230
|
+
[DrawerPopupCssVars.height]: popupHeightCssVarValue,
|
|
1231
|
+
[DrawerPopupCssVars.snapPointOffset]: typeof snapPointOffsetValue === 'number' ? `${snapPointOffsetValue}px` : '0px',
|
|
1232
|
+
[DrawerPopupCssVars.frontmostHeight]: frontmostHeight ? `${frontmostHeight}px` : undefined,
|
|
1233
|
+
[DrawerPopupCssVars.swipeStrength]: typeof swipeStrength === 'number' && Number.isFinite(swipeStrength) && swipeStrength > 0 ? `${swipeStrength}` : '1'
|
|
1234
|
+
}
|
|
1235
|
+
}, elementProps],
|
|
1236
|
+
ref: [forwardedRef, popupRef, setPopupElement],
|
|
1237
|
+
stateAttributesMapping
|
|
1238
|
+
});
|
|
1239
|
+
return /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
1240
|
+
context: floatingRootContext,
|
|
1241
|
+
openInteractionType: openMethod,
|
|
1242
|
+
disabled: !mounted,
|
|
1243
|
+
closeOnFocusOut: !disablePointerDismissal,
|
|
1244
|
+
initialFocus: resolvedInitialFocus,
|
|
1245
|
+
returnFocus: finalFocus,
|
|
1246
|
+
modal: modal !== false,
|
|
1247
|
+
restoreFocus: "popup",
|
|
1248
|
+
children: element
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
if (process.env.NODE_ENV !== "production") DrawerPopup.displayName = "DrawerPopup";
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* A portal element that moves the popup to a different part of the DOM.
|
|
1255
|
+
* By default, the portal element is appended to `<body>`.
|
|
1256
|
+
* Renders a `<div>` element.
|
|
1257
|
+
*
|
|
1258
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
1259
|
+
*/
|
|
1260
|
+
const DrawerPortal = DialogPortal;
|
|
1261
|
+
|
|
1262
|
+
var _DrawerProviderReport, _DrawerProviderReport2;
|
|
1263
|
+
/**
|
|
1264
|
+
* Groups all parts of the drawer.
|
|
1265
|
+
* Doesn't render its own HTML element.
|
|
1266
|
+
*
|
|
1267
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
1268
|
+
*/
|
|
1269
|
+
function DrawerRoot(props) {
|
|
1270
|
+
const {
|
|
1271
|
+
children,
|
|
1272
|
+
open: openProp,
|
|
1273
|
+
defaultOpen = false,
|
|
1274
|
+
onOpenChange,
|
|
1275
|
+
onOpenChangeComplete,
|
|
1276
|
+
disablePointerDismissal = false,
|
|
1277
|
+
modal = true,
|
|
1278
|
+
actionsRef,
|
|
1279
|
+
handle,
|
|
1280
|
+
triggerId: triggerIdProp,
|
|
1281
|
+
defaultTriggerId: defaultTriggerIdProp = null,
|
|
1282
|
+
swipeDirection = 'down',
|
|
1283
|
+
snapToSequentialPoints = false,
|
|
1284
|
+
snapPoints,
|
|
1285
|
+
snapPoint: snapPointProp,
|
|
1286
|
+
defaultSnapPoint,
|
|
1287
|
+
onSnapPointChange
|
|
1288
|
+
} = props;
|
|
1289
|
+
const parentDrawerRootContext = useDrawerRootContext(true);
|
|
1290
|
+
const notifyParentSwipeProgressChange = parentDrawerRootContext?.onNestedSwipeProgressChange;
|
|
1291
|
+
const notifyParentFrontmostHeight = parentDrawerRootContext?.onNestedFrontmostHeightChange;
|
|
1292
|
+
const notifyParentSwipingChange = parentDrawerRootContext?.onNestedSwipingChange;
|
|
1293
|
+
const notifyParentHasNestedDrawer = parentDrawerRootContext?.onNestedDrawerPresenceChange;
|
|
1294
|
+
const [popupHeight, setPopupHeight] = React.useState(0);
|
|
1295
|
+
const [frontmostHeight, setFrontmostHeight] = React.useState(0);
|
|
1296
|
+
const [hasNestedDrawer, setHasNestedDrawer] = React.useState(false);
|
|
1297
|
+
const [nestedSwiping, setNestedSwiping] = React.useState(false);
|
|
1298
|
+
const [nestedSwipeProgressStore] = React.useState(createNestedSwipeProgressStore);
|
|
1299
|
+
const resolvedDefaultSnapPoint = defaultSnapPoint !== undefined ? defaultSnapPoint : snapPoints?.[0] ?? null;
|
|
1300
|
+
const isSnapPointControlled = snapPointProp !== undefined;
|
|
1301
|
+
const [activeSnapPoint, setActiveSnapPointUnwrapped] = useControlled({
|
|
1302
|
+
controlled: snapPointProp,
|
|
1303
|
+
default: resolvedDefaultSnapPoint,
|
|
1304
|
+
name: 'Drawer',
|
|
1305
|
+
state: 'snapPoint'
|
|
1306
|
+
});
|
|
1307
|
+
const isNestedDrawerOpenRef = React.useRef(false);
|
|
1308
|
+
const swipeAreaActiveRef = React.useRef(false);
|
|
1309
|
+
const setActiveSnapPoint = useStableCallback((nextSnapPoint, eventDetails) => {
|
|
1310
|
+
const resolvedEventDetails = eventDetails ?? createChangeEventDetails(none);
|
|
1311
|
+
onSnapPointChange?.(nextSnapPoint, resolvedEventDetails);
|
|
1312
|
+
if (resolvedEventDetails.isCanceled) {
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
setActiveSnapPointUnwrapped(nextSnapPoint);
|
|
1316
|
+
});
|
|
1317
|
+
const resolvedActiveSnapPoint = React.useMemo(() => {
|
|
1318
|
+
if (isSnapPointControlled) {
|
|
1319
|
+
return activeSnapPoint;
|
|
1320
|
+
}
|
|
1321
|
+
if (!snapPoints || snapPoints.length === 0) {
|
|
1322
|
+
return activeSnapPoint;
|
|
1323
|
+
}
|
|
1324
|
+
if (activeSnapPoint === null || !snapPoints.some(snapPoint => Object.is(snapPoint, activeSnapPoint))) {
|
|
1325
|
+
return resolvedDefaultSnapPoint;
|
|
1326
|
+
}
|
|
1327
|
+
return activeSnapPoint;
|
|
1328
|
+
}, [activeSnapPoint, isSnapPointControlled, resolvedDefaultSnapPoint, snapPoints]);
|
|
1329
|
+
const onPopupHeightChange = useStableCallback(height => {
|
|
1330
|
+
setPopupHeight(height);
|
|
1331
|
+
if (!isNestedDrawerOpenRef.current && height > 0) {
|
|
1332
|
+
setFrontmostHeight(height);
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
const onNestedFrontmostHeightChange = useStableCallback(height => {
|
|
1336
|
+
if (height > 0) {
|
|
1337
|
+
isNestedDrawerOpenRef.current = true;
|
|
1338
|
+
setFrontmostHeight(height);
|
|
1339
|
+
return;
|
|
1340
|
+
}
|
|
1341
|
+
isNestedDrawerOpenRef.current = false;
|
|
1342
|
+
if (popupHeight > 0) {
|
|
1343
|
+
setFrontmostHeight(popupHeight);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
const onNestedDrawerPresenceChange = useStableCallback(present => {
|
|
1347
|
+
setHasNestedDrawer(present);
|
|
1348
|
+
});
|
|
1349
|
+
const onNestedSwipeProgressChange = useStableCallback(progress => {
|
|
1350
|
+
nestedSwipeProgressStore.set(progress);
|
|
1351
|
+
notifyParentSwipeProgressChange?.(progress);
|
|
1352
|
+
});
|
|
1353
|
+
const onNestedSwipingChange = useStableCallback(swiping => {
|
|
1354
|
+
setNestedSwiping(swiping);
|
|
1355
|
+
notifyParentSwipingChange?.(swiping);
|
|
1356
|
+
});
|
|
1357
|
+
const handleOpenChange = useStableCallback((nextOpen, eventDetails) => {
|
|
1358
|
+
onOpenChange?.(nextOpen, eventDetails);
|
|
1359
|
+
if (eventDetails.isCanceled) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
if (!nextOpen && snapPoints && snapPoints.length > 0) {
|
|
1363
|
+
setActiveSnapPoint(resolvedDefaultSnapPoint, createChangeEventDetails(eventDetails.reason, eventDetails.event, eventDetails.trigger));
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
const contextValue = React.useMemo(() => ({
|
|
1367
|
+
swipeDirection,
|
|
1368
|
+
swipeAreaActiveRef,
|
|
1369
|
+
snapToSequentialPoints,
|
|
1370
|
+
snapPoints,
|
|
1371
|
+
activeSnapPoint: resolvedActiveSnapPoint,
|
|
1372
|
+
setActiveSnapPoint,
|
|
1373
|
+
frontmostHeight,
|
|
1374
|
+
popupHeight,
|
|
1375
|
+
hasNestedDrawer,
|
|
1376
|
+
nestedSwiping,
|
|
1377
|
+
nestedSwipeProgressStore,
|
|
1378
|
+
onNestedDrawerPresenceChange,
|
|
1379
|
+
onPopupHeightChange,
|
|
1380
|
+
onNestedFrontmostHeightChange,
|
|
1381
|
+
onNestedSwipingChange,
|
|
1382
|
+
onNestedSwipeProgressChange,
|
|
1383
|
+
notifyParentFrontmostHeight,
|
|
1384
|
+
notifyParentSwipingChange,
|
|
1385
|
+
notifyParentSwipeProgressChange,
|
|
1386
|
+
notifyParentHasNestedDrawer
|
|
1387
|
+
}), [resolvedActiveSnapPoint, frontmostHeight, hasNestedDrawer, nestedSwiping, nestedSwipeProgressStore, notifyParentHasNestedDrawer, notifyParentSwipeProgressChange, notifyParentSwipingChange, notifyParentFrontmostHeight, onNestedDrawerPresenceChange, onNestedFrontmostHeightChange, onNestedSwipeProgressChange, onNestedSwipingChange, onPopupHeightChange, popupHeight, setActiveSnapPoint, snapPoints, snapToSequentialPoints, swipeAreaActiveRef, swipeDirection]);
|
|
1388
|
+
const resolvedChildren = typeof children === 'function' ? payload => /*#__PURE__*/jsxs(React.Fragment, {
|
|
1389
|
+
children: [_DrawerProviderReport || (_DrawerProviderReport = /*#__PURE__*/jsx(DrawerProviderReporter, {})), children(payload)]
|
|
1390
|
+
}) : /*#__PURE__*/jsxs(React.Fragment, {
|
|
1391
|
+
children: [_DrawerProviderReport2 || (_DrawerProviderReport2 = /*#__PURE__*/jsx(DrawerProviderReporter, {})), children]
|
|
1392
|
+
});
|
|
1393
|
+
const dialog = useRenderDialogRoot('drawer', {
|
|
1394
|
+
open: openProp,
|
|
1395
|
+
defaultOpen,
|
|
1396
|
+
onOpenChange: handleOpenChange,
|
|
1397
|
+
onOpenChangeComplete,
|
|
1398
|
+
disablePointerDismissal,
|
|
1399
|
+
modal,
|
|
1400
|
+
actionsRef,
|
|
1401
|
+
handle,
|
|
1402
|
+
triggerId: triggerIdProp,
|
|
1403
|
+
defaultTriggerId: defaultTriggerIdProp,
|
|
1404
|
+
children: resolvedChildren
|
|
1405
|
+
});
|
|
1406
|
+
return /*#__PURE__*/jsx(DrawerRootContext.Provider, {
|
|
1407
|
+
value: contextValue,
|
|
1408
|
+
children: dialog
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
function createNestedSwipeProgressStore() {
|
|
1412
|
+
let progress = 0;
|
|
1413
|
+
const listeners = new Set();
|
|
1414
|
+
return {
|
|
1415
|
+
getSnapshot: () => progress,
|
|
1416
|
+
set(nextProgress) {
|
|
1417
|
+
const resolved = Number.isFinite(nextProgress) ? nextProgress : 0;
|
|
1418
|
+
if (resolved === progress) {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
progress = resolved;
|
|
1422
|
+
listeners.forEach(listener => {
|
|
1423
|
+
listener();
|
|
1424
|
+
});
|
|
1425
|
+
},
|
|
1426
|
+
subscribe(listener) {
|
|
1427
|
+
listeners.add(listener);
|
|
1428
|
+
return () => {
|
|
1429
|
+
listeners.delete(listener);
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
function DrawerProviderReporter() {
|
|
1435
|
+
const providerContext = useDrawerProviderContext();
|
|
1436
|
+
const store = useDialogRootContext(false);
|
|
1437
|
+
const setDrawerOpen = providerContext?.setDrawerOpen;
|
|
1438
|
+
const removeDrawer = providerContext?.removeDrawer;
|
|
1439
|
+
const open = store.useState('open');
|
|
1440
|
+
const nestedOpenDialogCount = store.useState('nestedOpenDialogCount');
|
|
1441
|
+
const popupElement = store.useState('popupElement');
|
|
1442
|
+
const isTopmost = nestedOpenDialogCount === 0;
|
|
1443
|
+
useIsoLayoutEffect(() => {
|
|
1444
|
+
if (!removeDrawer) {
|
|
1445
|
+
return undefined;
|
|
1446
|
+
}
|
|
1447
|
+
return () => {
|
|
1448
|
+
removeDrawer(store);
|
|
1449
|
+
};
|
|
1450
|
+
}, [removeDrawer, store]);
|
|
1451
|
+
useIsoLayoutEffect(() => {
|
|
1452
|
+
setDrawerOpen?.(store, open);
|
|
1453
|
+
}, [open, setDrawerOpen, store]);
|
|
1454
|
+
React.useEffect(() => {
|
|
1455
|
+
// CloseWatcher enables the Android back gesture (Chromium-only).
|
|
1456
|
+
// Keep this Android-only for now to avoid interfering with Escape/nesting semantics on desktop due to `useDismiss`.
|
|
1457
|
+
if (!open || !isTopmost || !android) {
|
|
1458
|
+
return undefined;
|
|
1459
|
+
}
|
|
1460
|
+
const win = getWindow(popupElement);
|
|
1461
|
+
const CloseWatcherCtor = win.CloseWatcher;
|
|
1462
|
+
if (!CloseWatcherCtor) {
|
|
1463
|
+
return undefined;
|
|
1464
|
+
}
|
|
1465
|
+
function handleCloseWatcher(event) {
|
|
1466
|
+
if (!store.select('open')) {
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
store.setOpen(false, createChangeEventDetails(closeWatcher, event));
|
|
1470
|
+
}
|
|
1471
|
+
const closeWatcher$1 = new CloseWatcherCtor();
|
|
1472
|
+
const unsubscribe = addEventListener(closeWatcher$1, 'close', handleCloseWatcher);
|
|
1473
|
+
return () => {
|
|
1474
|
+
unsubscribe();
|
|
1475
|
+
closeWatcher$1.destroy();
|
|
1476
|
+
};
|
|
1477
|
+
}, [store, isTopmost, open, popupElement]);
|
|
1478
|
+
return null;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
// `Document.elementFromPoint` retargets shadow content to the shadow host, which then fails
|
|
1482
|
+
// `contains()` checks against a popup inside that shadow root, so callers pass `getRootNode()`
|
|
1483
|
+
// (a document or a shadow root) rather than `ownerDocument()`.
|
|
1484
|
+
function getElementAtPoint(root, x, y) {
|
|
1485
|
+
return typeof root?.elementFromPoint === 'function' ? root.elementFromPoint(x, y) : null;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
const DEFAULT_SWIPE_THRESHOLD = 40;
|
|
1489
|
+
const REVERSE_CANCEL_THRESHOLD = 10;
|
|
1490
|
+
const MIN_DRAG_THRESHOLD = 1;
|
|
1491
|
+
const MIN_VELOCITY_DURATION_MS = 50;
|
|
1492
|
+
const MIN_RELEASE_VELOCITY_DURATION_MS = 16;
|
|
1493
|
+
const MAX_RELEASE_VELOCITY_AGE_MS = 80;
|
|
1494
|
+
const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
|
|
1495
|
+
function getDisplacement(direction, deltaX, deltaY) {
|
|
1496
|
+
switch (direction) {
|
|
1497
|
+
case 'up':
|
|
1498
|
+
return -deltaY;
|
|
1499
|
+
case 'down':
|
|
1500
|
+
return deltaY;
|
|
1501
|
+
case 'left':
|
|
1502
|
+
return -deltaX;
|
|
1503
|
+
case 'right':
|
|
1504
|
+
return deltaX;
|
|
1505
|
+
default:
|
|
1506
|
+
return 0;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
function getElementTransform(element) {
|
|
1510
|
+
const computedStyle = getWindow(element).getComputedStyle(element);
|
|
1511
|
+
const transform = computedStyle.transform;
|
|
1512
|
+
let translateX = 0;
|
|
1513
|
+
let translateY = 0;
|
|
1514
|
+
let scale = 1;
|
|
1515
|
+
if (transform && transform !== 'none') {
|
|
1516
|
+
const matrix = transform.match(/matrix(?:3d)?\(([^)]+)\)/);
|
|
1517
|
+
if (matrix) {
|
|
1518
|
+
const values = matrix[1].split(', ').map(parseFloat);
|
|
1519
|
+
if (values.length === 6) {
|
|
1520
|
+
translateX = values[4];
|
|
1521
|
+
translateY = values[5];
|
|
1522
|
+
scale = Math.sqrt(values[0] * values[0] + values[1] * values[1]);
|
|
1523
|
+
} else if (values.length === 16) {
|
|
1524
|
+
translateX = values[12];
|
|
1525
|
+
translateY = values[13];
|
|
1526
|
+
scale = values[0];
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return {
|
|
1531
|
+
x: translateX,
|
|
1532
|
+
y: translateY,
|
|
1533
|
+
scale
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
function getValidTimeStamp(timeStamp) {
|
|
1537
|
+
return Number.isFinite(timeStamp) && timeStamp > 0 ? timeStamp : null;
|
|
1538
|
+
}
|
|
1539
|
+
function getDragTransform(dragOffset, scale) {
|
|
1540
|
+
return `translate3d(${dragOffset.x}px,${dragOffset.y}px,0) scale(${scale})`;
|
|
1541
|
+
}
|
|
1542
|
+
function hasPrimaryMouseButton(buttons) {
|
|
1543
|
+
return buttons % 2 === 1;
|
|
1544
|
+
}
|
|
1545
|
+
function safelyChangePointerCapture(element, pointerId, method) {
|
|
1546
|
+
const pointerCaptureMethod = element[method];
|
|
1547
|
+
if (typeof pointerCaptureMethod !== 'function') {
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
try {
|
|
1551
|
+
pointerCaptureMethod.call(element, pointerId);
|
|
1552
|
+
} catch (error) {
|
|
1553
|
+
if (error && typeof error === 'object' && 'name' in error && error.name === 'NotFoundError') {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
throw error;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
function useSwipeDismiss(options) {
|
|
1560
|
+
const {
|
|
1561
|
+
enabled,
|
|
1562
|
+
directions,
|
|
1563
|
+
elementRef,
|
|
1564
|
+
movementCssVars,
|
|
1565
|
+
canStart,
|
|
1566
|
+
ignoreSelectorWhenTouch = true,
|
|
1567
|
+
ignoreScrollableAncestors = false,
|
|
1568
|
+
swipeThreshold: swipeThresholdProp,
|
|
1569
|
+
onDismiss,
|
|
1570
|
+
onProgress,
|
|
1571
|
+
onCancel,
|
|
1572
|
+
onSwipeStart,
|
|
1573
|
+
onRelease,
|
|
1574
|
+
onSwipingChange,
|
|
1575
|
+
trackDrag = true
|
|
1576
|
+
} = options;
|
|
1577
|
+
const ignoreSelector = DEFAULT_IGNORE_SELECTOR;
|
|
1578
|
+
const primaryDirection = directions.length === 1 ? directions[0] : undefined;
|
|
1579
|
+
const swipeThresholdDefault = Math.max(0, typeof swipeThresholdProp === 'number' ? swipeThresholdProp : DEFAULT_SWIPE_THRESHOLD);
|
|
1580
|
+
const allowLeft = directions.includes('left');
|
|
1581
|
+
const allowRight = directions.includes('right');
|
|
1582
|
+
const allowUp = directions.includes('up');
|
|
1583
|
+
const allowDown = directions.includes('down');
|
|
1584
|
+
const hasHorizontal = allowLeft || allowRight;
|
|
1585
|
+
const hasVertical = allowUp || allowDown;
|
|
1586
|
+
const scrollAxes = React.useMemo(() => {
|
|
1587
|
+
const axes = [];
|
|
1588
|
+
if (hasVertical) {
|
|
1589
|
+
axes.push('vertical');
|
|
1590
|
+
}
|
|
1591
|
+
if (hasHorizontal) {
|
|
1592
|
+
axes.push('horizontal');
|
|
1593
|
+
}
|
|
1594
|
+
return axes;
|
|
1595
|
+
}, [hasHorizontal, hasVertical]);
|
|
1596
|
+
const [currentSwipeDirection, setCurrentSwipeDirection] = React.useState(undefined);
|
|
1597
|
+
const [isSwiping, setIsSwiping] = React.useState(false);
|
|
1598
|
+
const [dragDismissed, setDragDismissed] = React.useState(false);
|
|
1599
|
+
const dragStartPosRef = React.useRef({
|
|
1600
|
+
x: 0,
|
|
1601
|
+
y: 0
|
|
1602
|
+
});
|
|
1603
|
+
const dragOffsetRef = React.useRef({
|
|
1604
|
+
x: 0,
|
|
1605
|
+
y: 0
|
|
1606
|
+
});
|
|
1607
|
+
const lastMovePosRef = React.useRef(null);
|
|
1608
|
+
const initialTransformRef = React.useRef({
|
|
1609
|
+
x: 0,
|
|
1610
|
+
y: 0,
|
|
1611
|
+
scale: 1
|
|
1612
|
+
});
|
|
1613
|
+
const intendedSwipeDirectionRef = React.useRef(undefined);
|
|
1614
|
+
const maxSwipeDisplacementRef = React.useRef(0);
|
|
1615
|
+
const cancelledSwipeRef = React.useRef(false);
|
|
1616
|
+
const swipeCancelBaselineRef = React.useRef({
|
|
1617
|
+
x: 0,
|
|
1618
|
+
y: 0
|
|
1619
|
+
});
|
|
1620
|
+
const lockedDirectionRef = React.useRef(null);
|
|
1621
|
+
const isFirstPointerMoveRef = React.useRef(false);
|
|
1622
|
+
const pendingSwipeRef = React.useRef(false);
|
|
1623
|
+
const pendingSwipeStartPosRef = React.useRef(null);
|
|
1624
|
+
const swipeFromScrollableRef = React.useRef(false);
|
|
1625
|
+
const sawPrimaryButtonsOnMoveRef = React.useRef(false);
|
|
1626
|
+
const elementSizeRef = React.useRef({
|
|
1627
|
+
width: 0,
|
|
1628
|
+
height: 0
|
|
1629
|
+
});
|
|
1630
|
+
const swipeProgressRef = React.useRef(0);
|
|
1631
|
+
const swipeThresholdRef = React.useRef(swipeThresholdDefault);
|
|
1632
|
+
const swipeThresholdFunctionRef = React.useRef(null);
|
|
1633
|
+
const swipeStartTimeRef = React.useRef(null);
|
|
1634
|
+
const lastDragSampleRef = React.useRef(null);
|
|
1635
|
+
const lastDragVelocityRef = React.useRef({
|
|
1636
|
+
x: 0,
|
|
1637
|
+
y: 0
|
|
1638
|
+
});
|
|
1639
|
+
const lastProgressDetailsRef = React.useRef(null);
|
|
1640
|
+
const isSwipingRef = React.useRef(false);
|
|
1641
|
+
const dragStyleSnapshotRef = React.useRef(null);
|
|
1642
|
+
const setSwiping = useStableCallback(nextSwiping => {
|
|
1643
|
+
if (isSwipingRef.current === nextSwiping) {
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
isSwipingRef.current = nextSwiping;
|
|
1647
|
+
setIsSwiping(nextSwiping);
|
|
1648
|
+
onSwipingChange?.(nextSwiping);
|
|
1649
|
+
});
|
|
1650
|
+
function resolveSwipeThreshold(direction) {
|
|
1651
|
+
if (!direction) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
const element = elementRef.current;
|
|
1655
|
+
const thresholdFunction = swipeThresholdFunctionRef.current;
|
|
1656
|
+
if (!element || !thresholdFunction) {
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
const value = thresholdFunction({
|
|
1660
|
+
element,
|
|
1661
|
+
direction
|
|
1662
|
+
});
|
|
1663
|
+
swipeThresholdRef.current = Math.max(0, value);
|
|
1664
|
+
}
|
|
1665
|
+
const updateSwipeProgress = useStableCallback((progress, details) => {
|
|
1666
|
+
const nextProgress = Number.isFinite(progress) ? clamp(progress, 0, 1) : 0;
|
|
1667
|
+
const progressChanged = nextProgress !== swipeProgressRef.current;
|
|
1668
|
+
let detailsChanged = false;
|
|
1669
|
+
if (details) {
|
|
1670
|
+
const lastDetails = lastProgressDetailsRef.current;
|
|
1671
|
+
detailsChanged = !lastDetails || lastDetails.deltaX !== details.deltaX || lastDetails.deltaY !== details.deltaY || lastDetails.direction !== details.direction;
|
|
1672
|
+
}
|
|
1673
|
+
if (!progressChanged && !detailsChanged) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
swipeProgressRef.current = nextProgress;
|
|
1677
|
+
if (details) {
|
|
1678
|
+
lastProgressDetailsRef.current = details;
|
|
1679
|
+
} else if (progressChanged) {
|
|
1680
|
+
lastProgressDetailsRef.current = null;
|
|
1681
|
+
}
|
|
1682
|
+
onProgress?.(nextProgress, details);
|
|
1683
|
+
});
|
|
1684
|
+
const syncDragStyles = useStableCallback(swiping => {
|
|
1685
|
+
const element = elementRef.current;
|
|
1686
|
+
if (!trackDrag || !element) {
|
|
1687
|
+
if (!swiping) {
|
|
1688
|
+
dragStyleSnapshotRef.current = null;
|
|
1689
|
+
}
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
const style = element.style;
|
|
1693
|
+
const dragStyleSnapshot = dragStyleSnapshotRef.current;
|
|
1694
|
+
if (swiping) {
|
|
1695
|
+
if (!dragStyleSnapshot) {
|
|
1696
|
+
dragStyleSnapshotRef.current = [style.transition, style.transform];
|
|
1697
|
+
}
|
|
1698
|
+
style.transition = 'none';
|
|
1699
|
+
} else if (dragStyleSnapshot) {
|
|
1700
|
+
[style.transition, style.transform] = dragStyleSnapshot;
|
|
1701
|
+
dragStyleSnapshotRef.current = null;
|
|
1702
|
+
}
|
|
1703
|
+
const dragOffset = dragOffsetRef.current;
|
|
1704
|
+
const initialTransform = initialTransformRef.current;
|
|
1705
|
+
const deltaX = dragOffset.x - initialTransform.x;
|
|
1706
|
+
const deltaY = dragOffset.y - initialTransform.y;
|
|
1707
|
+
if (swiping) {
|
|
1708
|
+
style.transform = getDragTransform(dragOffset, initialTransform.scale);
|
|
1709
|
+
}
|
|
1710
|
+
style.setProperty(movementCssVars.x, `${deltaX}px`);
|
|
1711
|
+
style.setProperty(movementCssVars.y, `${deltaY}px`);
|
|
1712
|
+
});
|
|
1713
|
+
function recordDragSample(offset, timeStamp) {
|
|
1714
|
+
if (timeStamp === null) {
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
const lastSample = lastDragSampleRef.current;
|
|
1718
|
+
if (lastSample && timeStamp > lastSample.time) {
|
|
1719
|
+
const durationMs = Math.max(timeStamp - lastSample.time, MIN_RELEASE_VELOCITY_DURATION_MS);
|
|
1720
|
+
lastDragVelocityRef.current = {
|
|
1721
|
+
x: (offset.x - lastSample.x) / durationMs,
|
|
1722
|
+
y: (offset.y - lastSample.y) / durationMs
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
lastDragSampleRef.current = {
|
|
1726
|
+
x: offset.x,
|
|
1727
|
+
y: offset.y,
|
|
1728
|
+
time: timeStamp
|
|
1729
|
+
};
|
|
1730
|
+
}
|
|
1731
|
+
const reset = React.useCallback(() => {
|
|
1732
|
+
setCurrentSwipeDirection(undefined);
|
|
1733
|
+
setSwiping(false);
|
|
1734
|
+
setDragDismissed(false);
|
|
1735
|
+
updateSwipeProgress(0);
|
|
1736
|
+
swipeThresholdRef.current = swipeThresholdDefault;
|
|
1737
|
+
swipeThresholdFunctionRef.current = null;
|
|
1738
|
+
dragStartPosRef.current = {
|
|
1739
|
+
x: 0,
|
|
1740
|
+
y: 0
|
|
1741
|
+
};
|
|
1742
|
+
dragOffsetRef.current = {
|
|
1743
|
+
x: 0,
|
|
1744
|
+
y: 0
|
|
1745
|
+
};
|
|
1746
|
+
initialTransformRef.current = {
|
|
1747
|
+
x: 0,
|
|
1748
|
+
y: 0,
|
|
1749
|
+
scale: 1
|
|
1750
|
+
};
|
|
1751
|
+
intendedSwipeDirectionRef.current = undefined;
|
|
1752
|
+
maxSwipeDisplacementRef.current = 0;
|
|
1753
|
+
cancelledSwipeRef.current = false;
|
|
1754
|
+
swipeCancelBaselineRef.current = {
|
|
1755
|
+
x: 0,
|
|
1756
|
+
y: 0
|
|
1757
|
+
};
|
|
1758
|
+
lockedDirectionRef.current = null;
|
|
1759
|
+
isFirstPointerMoveRef.current = false;
|
|
1760
|
+
lastMovePosRef.current = null;
|
|
1761
|
+
pendingSwipeRef.current = false;
|
|
1762
|
+
pendingSwipeStartPosRef.current = null;
|
|
1763
|
+
swipeFromScrollableRef.current = false;
|
|
1764
|
+
sawPrimaryButtonsOnMoveRef.current = false;
|
|
1765
|
+
elementSizeRef.current = {
|
|
1766
|
+
width: 0,
|
|
1767
|
+
height: 0
|
|
1768
|
+
};
|
|
1769
|
+
swipeStartTimeRef.current = null;
|
|
1770
|
+
lastDragSampleRef.current = null;
|
|
1771
|
+
lastDragVelocityRef.current = {
|
|
1772
|
+
x: 0,
|
|
1773
|
+
y: 0
|
|
1774
|
+
};
|
|
1775
|
+
lastProgressDetailsRef.current = null;
|
|
1776
|
+
syncDragStyles(false);
|
|
1777
|
+
}, [setSwiping, swipeThresholdDefault, syncDragStyles, updateSwipeProgress]);
|
|
1778
|
+
function getPrimaryPointerPosition(event) {
|
|
1779
|
+
if ('touches' in event) {
|
|
1780
|
+
const touch = event.touches[0];
|
|
1781
|
+
return touch ? {
|
|
1782
|
+
x: touch.clientX,
|
|
1783
|
+
y: touch.clientY
|
|
1784
|
+
} : null;
|
|
1785
|
+
}
|
|
1786
|
+
return {
|
|
1787
|
+
x: event.clientX,
|
|
1788
|
+
y: event.clientY
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
function isTouchLikeEvent(event) {
|
|
1792
|
+
if ('touches' in event) {
|
|
1793
|
+
return true;
|
|
1794
|
+
}
|
|
1795
|
+
return event.pointerType === 'touch';
|
|
1796
|
+
}
|
|
1797
|
+
function getTargetAtPoint(position, nativeEvent) {
|
|
1798
|
+
const root = elementRef.current?.getRootNode();
|
|
1799
|
+
const elementAtPoint = getElementAtPoint(root, position.x, position.y);
|
|
1800
|
+
const target = elementAtPoint ?? getTarget(nativeEvent);
|
|
1801
|
+
return target;
|
|
1802
|
+
}
|
|
1803
|
+
function findGestureScrollableTouchTarget(target, root) {
|
|
1804
|
+
if (hasHorizontal && !hasVertical) {
|
|
1805
|
+
return findScrollableTouchTarget(target, root, 'horizontal');
|
|
1806
|
+
}
|
|
1807
|
+
if (hasVertical && !hasHorizontal) {
|
|
1808
|
+
return findScrollableTouchTarget(target, root, 'vertical');
|
|
1809
|
+
}
|
|
1810
|
+
return findScrollableTouchTarget(target, root, 'vertical') ?? findScrollableTouchTarget(target, root, 'horizontal');
|
|
1811
|
+
}
|
|
1812
|
+
function startSwipeAtPosition(event, position, startOptions) {
|
|
1813
|
+
swipeFromScrollableRef.current = false;
|
|
1814
|
+
const touchLike = isTouchLikeEvent(event);
|
|
1815
|
+
const target = getTargetAtPoint(position, event.nativeEvent);
|
|
1816
|
+
const doc = ownerDocument(elementRef.current);
|
|
1817
|
+
const body = doc.body;
|
|
1818
|
+
const scrollableTarget = touchLike && body ? findGestureScrollableTouchTarget(target, body) : null;
|
|
1819
|
+
const ignoreScrollableTarget = startOptions?.ignoreScrollableTarget ?? false;
|
|
1820
|
+
if (scrollableTarget && !ignoreScrollableTarget) {
|
|
1821
|
+
return false;
|
|
1822
|
+
}
|
|
1823
|
+
swipeFromScrollableRef.current = Boolean(scrollableTarget && ignoreScrollableTarget);
|
|
1824
|
+
const isInteractiveElement = target ? target.closest(ignoreSelector) : false;
|
|
1825
|
+
if (isInteractiveElement && (!touchLike || ignoreSelectorWhenTouch)) {
|
|
1826
|
+
return false;
|
|
1827
|
+
}
|
|
1828
|
+
const element = elementRef.current;
|
|
1829
|
+
if (ignoreScrollableAncestors && element && target && scrollAxes.length > 0) {
|
|
1830
|
+
const ignoreAncestors = startOptions?.ignoreScrollableAncestors ?? false;
|
|
1831
|
+
if (!ignoreAncestors && hasScrollableAncestor(target, element, scrollAxes)) {
|
|
1832
|
+
return false;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
cancelledSwipeRef.current = false;
|
|
1836
|
+
intendedSwipeDirectionRef.current = undefined;
|
|
1837
|
+
maxSwipeDisplacementRef.current = 0;
|
|
1838
|
+
dragStartPosRef.current = position;
|
|
1839
|
+
swipeStartTimeRef.current = getValidTimeStamp(event.timeStamp);
|
|
1840
|
+
swipeCancelBaselineRef.current = position;
|
|
1841
|
+
lastMovePosRef.current = position;
|
|
1842
|
+
swipeThresholdRef.current = swipeThresholdDefault;
|
|
1843
|
+
swipeThresholdFunctionRef.current = typeof swipeThresholdProp === 'function' ? swipeThresholdProp : null;
|
|
1844
|
+
if (element) {
|
|
1845
|
+
elementSizeRef.current = {
|
|
1846
|
+
width: element.offsetWidth,
|
|
1847
|
+
height: element.offsetHeight
|
|
1848
|
+
};
|
|
1849
|
+
resolveSwipeThreshold(primaryDirection);
|
|
1850
|
+
const transform = getElementTransform(element);
|
|
1851
|
+
initialTransformRef.current = transform;
|
|
1852
|
+
dragOffsetRef.current = {
|
|
1853
|
+
x: transform.x,
|
|
1854
|
+
y: transform.y
|
|
1855
|
+
};
|
|
1856
|
+
recordDragSample({
|
|
1857
|
+
x: transform.x,
|
|
1858
|
+
y: transform.y
|
|
1859
|
+
}, swipeStartTimeRef.current);
|
|
1860
|
+
if (!('touches' in event)) {
|
|
1861
|
+
safelyChangePointerCapture(element, event.pointerId, 'setPointerCapture');
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
onSwipeStart?.(event.nativeEvent);
|
|
1865
|
+
setSwiping(true);
|
|
1866
|
+
lockedDirectionRef.current = null;
|
|
1867
|
+
isFirstPointerMoveRef.current = true;
|
|
1868
|
+
updateSwipeProgress(0);
|
|
1869
|
+
syncDragStyles(true);
|
|
1870
|
+
return true;
|
|
1871
|
+
}
|
|
1872
|
+
function resetPendingSwipeState() {
|
|
1873
|
+
clearPendingSwipeStartState();
|
|
1874
|
+
swipeFromScrollableRef.current = false;
|
|
1875
|
+
lastMovePosRef.current = null;
|
|
1876
|
+
}
|
|
1877
|
+
function clearPendingSwipeStartState() {
|
|
1878
|
+
pendingSwipeRef.current = false;
|
|
1879
|
+
pendingSwipeStartPosRef.current = null;
|
|
1880
|
+
}
|
|
1881
|
+
function cancelSwipeInteraction(event) {
|
|
1882
|
+
resetPendingSwipeState();
|
|
1883
|
+
if (!isSwipingRef.current) {
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
setSwiping(false);
|
|
1887
|
+
lockedDirectionRef.current = null;
|
|
1888
|
+
const resolvedInitialTransform = initialTransformRef.current;
|
|
1889
|
+
dragOffsetRef.current = {
|
|
1890
|
+
x: resolvedInitialTransform.x,
|
|
1891
|
+
y: resolvedInitialTransform.y
|
|
1892
|
+
};
|
|
1893
|
+
setCurrentSwipeDirection(undefined);
|
|
1894
|
+
sawPrimaryButtonsOnMoveRef.current = false;
|
|
1895
|
+
syncDragStyles(false);
|
|
1896
|
+
const element = elementRef.current;
|
|
1897
|
+
if (element) {
|
|
1898
|
+
safelyChangePointerCapture(element, event.pointerId, 'releasePointerCapture');
|
|
1899
|
+
}
|
|
1900
|
+
updateSwipeProgress(0, {
|
|
1901
|
+
deltaX: 0,
|
|
1902
|
+
deltaY: 0,
|
|
1903
|
+
direction: undefined
|
|
1904
|
+
});
|
|
1905
|
+
onCancel?.(event.nativeEvent);
|
|
1906
|
+
}
|
|
1907
|
+
function applyDirectionalDamping(deltaX, deltaY) {
|
|
1908
|
+
const exponent = value => Math.sign(value) * Math.abs(value) ** 0.5;
|
|
1909
|
+
const dampAxis = (delta, allowNegative, allowPositive) => {
|
|
1910
|
+
if (!allowNegative && delta < 0 || !allowPositive && delta > 0) {
|
|
1911
|
+
return exponent(delta);
|
|
1912
|
+
}
|
|
1913
|
+
return delta;
|
|
1914
|
+
};
|
|
1915
|
+
const newDeltaX = hasHorizontal ? dampAxis(deltaX, allowLeft, allowRight) : exponent(deltaX);
|
|
1916
|
+
const newDeltaY = hasVertical ? dampAxis(deltaY, allowUp, allowDown) : exponent(deltaY);
|
|
1917
|
+
return {
|
|
1918
|
+
x: newDeltaX,
|
|
1919
|
+
y: newDeltaY
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
function canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY) {
|
|
1923
|
+
// Swiping toward the axis start edge (down/right) is allowed when scrolled to the start;
|
|
1924
|
+
// toward the end edge (up/left) when scrolled to the end.
|
|
1925
|
+
const canSwipeOnAxis = (delta, scrollOffset, maxScrollOffset, allowTowardStart, allowTowardEnd) => delta > 0 && scrollOffset <= 0 && allowTowardStart || delta < 0 && scrollOffset >= Math.max(0, maxScrollOffset) && allowTowardEnd;
|
|
1926
|
+
const absDeltaX = Math.abs(deltaX);
|
|
1927
|
+
const absDeltaY = Math.abs(deltaY);
|
|
1928
|
+
if (hasVertical && deltaY !== 0 && (!hasHorizontal || absDeltaY >= absDeltaX)) {
|
|
1929
|
+
return canSwipeOnAxis(deltaY, scrollTarget.scrollTop, scrollTarget.scrollHeight - scrollTarget.clientHeight, allowDown, allowUp);
|
|
1930
|
+
}
|
|
1931
|
+
if (hasHorizontal && deltaX !== 0 && (!hasVertical || absDeltaX > absDeltaY)) {
|
|
1932
|
+
return canSwipeOnAxis(deltaX, scrollTarget.scrollLeft, scrollTarget.scrollWidth - scrollTarget.clientWidth, allowRight, allowLeft);
|
|
1933
|
+
}
|
|
1934
|
+
return null;
|
|
1935
|
+
}
|
|
1936
|
+
const handleStart = useStableCallback(event => {
|
|
1937
|
+
if (!enabled) {
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
if (event.defaultPrevented || event.nativeEvent.defaultPrevented) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
if (!('touches' in event) && event.button !== 0) {
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
const startPos = getPrimaryPointerPosition(event);
|
|
1947
|
+
if (!startPos) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
pendingSwipeRef.current = true;
|
|
1951
|
+
pendingSwipeStartPosRef.current = startPos;
|
|
1952
|
+
swipeFromScrollableRef.current = false;
|
|
1953
|
+
sawPrimaryButtonsOnMoveRef.current = !('touches' in event);
|
|
1954
|
+
const allowedToStart = canStart ? canStart(startPos, {
|
|
1955
|
+
nativeEvent: event.nativeEvent,
|
|
1956
|
+
direction: primaryDirection
|
|
1957
|
+
}) : true;
|
|
1958
|
+
if (!allowedToStart) {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
if (startSwipeAtPosition(event, startPos)) {
|
|
1962
|
+
clearPendingSwipeStartState();
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
function handleMoveCore(event, position, movement) {
|
|
1966
|
+
if (!enabled || !isSwipingRef.current) {
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
const target = getTarget(event.nativeEvent);
|
|
1970
|
+
if (isTouchLikeEvent(event) && !swipeFromScrollableRef.current) {
|
|
1971
|
+
const boundaryElement = event.currentTarget;
|
|
1972
|
+
if (findGestureScrollableTouchTarget(target, boundaryElement)) {
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
if (!('touches' in event)) {
|
|
1977
|
+
// Prevent text selection on Safari
|
|
1978
|
+
event.preventDefault();
|
|
1979
|
+
}
|
|
1980
|
+
if (isFirstPointerMoveRef.current) {
|
|
1981
|
+
isFirstPointerMoveRef.current = false;
|
|
1982
|
+
// Reset the drag origin to the first move's position to absorb the gap between the press and
|
|
1983
|
+
// the first move event — notably on iOS touch, where the first `touchmove` arrives already
|
|
1984
|
+
// offset from the `touchstart` — which would otherwise make the dragged element jump. This
|
|
1985
|
+
// only matters when an element follows the pointer; when `trackDrag` is false (e.g. the
|
|
1986
|
+
// swipe-area, which only opens the drawer) keep the original press position so a quick flick
|
|
1987
|
+
// still registers: on a low-refresh-rate display the whole travel can land in this single
|
|
1988
|
+
// first move, and discarding it would drop the gesture.
|
|
1989
|
+
if (trackDrag) {
|
|
1990
|
+
dragStartPosRef.current = position;
|
|
1991
|
+
const moveTime = getValidTimeStamp(event.timeStamp);
|
|
1992
|
+
if (moveTime !== null) {
|
|
1993
|
+
swipeStartTimeRef.current = moveTime;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
const clientX = position.x;
|
|
1998
|
+
const clientY = position.y;
|
|
1999
|
+
const movementX = movement.x;
|
|
2000
|
+
const movementY = movement.y;
|
|
2001
|
+
if (movementY < 0 && clientY > swipeCancelBaselineRef.current.y || movementY > 0 && clientY < swipeCancelBaselineRef.current.y) {
|
|
2002
|
+
swipeCancelBaselineRef.current = {
|
|
2003
|
+
x: swipeCancelBaselineRef.current.x,
|
|
2004
|
+
y: clientY
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
if (movementX < 0 && clientX > swipeCancelBaselineRef.current.x || movementX > 0 && clientX < swipeCancelBaselineRef.current.x) {
|
|
2008
|
+
swipeCancelBaselineRef.current = {
|
|
2009
|
+
x: clientX,
|
|
2010
|
+
y: swipeCancelBaselineRef.current.y
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
const deltaX = clientX - dragStartPosRef.current.x;
|
|
2014
|
+
const deltaY = clientY - dragStartPosRef.current.y;
|
|
2015
|
+
const cancelDeltaY = clientY - swipeCancelBaselineRef.current.y;
|
|
2016
|
+
const cancelDeltaX = clientX - swipeCancelBaselineRef.current.x;
|
|
2017
|
+
let lockedDirection = lockedDirectionRef.current;
|
|
2018
|
+
if (lockedDirection === null && hasHorizontal && hasVertical) {
|
|
2019
|
+
const movementDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
2020
|
+
if (movementDistance >= MIN_DRAG_THRESHOLD) {
|
|
2021
|
+
lockedDirection = Math.abs(deltaX) > Math.abs(deltaY) ? 'horizontal' : 'vertical';
|
|
2022
|
+
lockedDirectionRef.current = lockedDirection;
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
let candidate;
|
|
2026
|
+
if (!intendedSwipeDirectionRef.current) {
|
|
2027
|
+
if (lockedDirection === 'vertical') {
|
|
2028
|
+
if (deltaY > 0) {
|
|
2029
|
+
candidate = 'down';
|
|
2030
|
+
} else if (deltaY < 0) {
|
|
2031
|
+
candidate = 'up';
|
|
2032
|
+
}
|
|
2033
|
+
} else if (lockedDirection === 'horizontal') {
|
|
2034
|
+
if (deltaX > 0) {
|
|
2035
|
+
candidate = 'right';
|
|
2036
|
+
} else if (deltaX < 0) {
|
|
2037
|
+
candidate = 'left';
|
|
2038
|
+
}
|
|
2039
|
+
} else if (Math.abs(deltaX) >= Math.abs(deltaY)) {
|
|
2040
|
+
candidate = deltaX > 0 ? 'right' : 'left';
|
|
2041
|
+
} else {
|
|
2042
|
+
candidate = deltaY > 0 ? 'down' : 'up';
|
|
2043
|
+
}
|
|
2044
|
+
if (candidate) {
|
|
2045
|
+
const isAllowed = candidate === 'left' && allowLeft || candidate === 'right' && allowRight || candidate === 'up' && allowUp || candidate === 'down' && allowDown;
|
|
2046
|
+
if (isAllowed) {
|
|
2047
|
+
intendedSwipeDirectionRef.current = candidate;
|
|
2048
|
+
maxSwipeDisplacementRef.current = getDisplacement(candidate, deltaX, deltaY);
|
|
2049
|
+
setCurrentSwipeDirection(candidate);
|
|
2050
|
+
resolveSwipeThreshold(candidate);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
} else {
|
|
2054
|
+
const direction = intendedSwipeDirectionRef.current;
|
|
2055
|
+
const currentDisplacement = getDisplacement(direction, cancelDeltaX, cancelDeltaY);
|
|
2056
|
+
if (currentDisplacement > swipeThresholdRef.current) {
|
|
2057
|
+
cancelledSwipeRef.current = false;
|
|
2058
|
+
setCurrentSwipeDirection(direction);
|
|
2059
|
+
} else if (!(allowLeft && allowRight) && !(allowUp && allowDown) && maxSwipeDisplacementRef.current - currentDisplacement >= REVERSE_CANCEL_THRESHOLD) {
|
|
2060
|
+
// Mark that a change-of-mind has occurred
|
|
2061
|
+
cancelledSwipeRef.current = true;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
const dampedDelta = applyDirectionalDamping(deltaX, deltaY);
|
|
2065
|
+
let newOffsetX = initialTransformRef.current.x;
|
|
2066
|
+
let newOffsetY = initialTransformRef.current.y;
|
|
2067
|
+
if (lockedDirection === 'horizontal') {
|
|
2068
|
+
if (hasHorizontal) {
|
|
2069
|
+
newOffsetX += dampedDelta.x;
|
|
2070
|
+
}
|
|
2071
|
+
} else if (lockedDirection === 'vertical') {
|
|
2072
|
+
if (hasVertical) {
|
|
2073
|
+
newOffsetY += dampedDelta.y;
|
|
2074
|
+
}
|
|
2075
|
+
} else {
|
|
2076
|
+
if (hasHorizontal) {
|
|
2077
|
+
newOffsetX += dampedDelta.x;
|
|
2078
|
+
}
|
|
2079
|
+
if (hasVertical) {
|
|
2080
|
+
newOffsetY += dampedDelta.y;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
// Only rewrite drag styles when the drag offset actually changed. `syncDragStyles` writes the
|
|
2085
|
+
// raw (undamped) frozen transform and movement vars, relying on the consumer's `onProgress`
|
|
2086
|
+
// to overwrite them with damped styles — but `updateSwipeProgress` dedupes unchanged
|
|
2087
|
+
// deltas and skips `onProgress`. A move that doesn't change the offset (e.g. the cursor
|
|
2088
|
+
// pinned at a screen edge during an off-screen drag, jittering only on the ignored axis)
|
|
2089
|
+
// would otherwise reinstate the raw styles with no correction, jumping the element to the
|
|
2090
|
+
// undamped position.
|
|
2091
|
+
const previousOffset = dragOffsetRef.current;
|
|
2092
|
+
const offsetChanged = newOffsetX !== previousOffset.x || newOffsetY !== previousOffset.y;
|
|
2093
|
+
dragOffsetRef.current = {
|
|
2094
|
+
x: newOffsetX,
|
|
2095
|
+
y: newOffsetY
|
|
2096
|
+
};
|
|
2097
|
+
if (offsetChanged) {
|
|
2098
|
+
syncDragStyles(true);
|
|
2099
|
+
}
|
|
2100
|
+
recordDragSample({
|
|
2101
|
+
x: newOffsetX,
|
|
2102
|
+
y: newOffsetY
|
|
2103
|
+
}, getValidTimeStamp(event.timeStamp));
|
|
2104
|
+
const dragDeltaX = newOffsetX - initialTransformRef.current.x;
|
|
2105
|
+
const dragDeltaY = newOffsetY - initialTransformRef.current.y;
|
|
2106
|
+
const progressDetails = {
|
|
2107
|
+
deltaX: dragDeltaX,
|
|
2108
|
+
deltaY: dragDeltaY,
|
|
2109
|
+
direction: intendedSwipeDirectionRef.current
|
|
2110
|
+
};
|
|
2111
|
+
let progress = 0;
|
|
2112
|
+
const progressDirection = primaryDirection ?? intendedSwipeDirectionRef.current;
|
|
2113
|
+
if (progressDirection) {
|
|
2114
|
+
const size = progressDirection === 'left' || progressDirection === 'right' ? elementSizeRef.current.width : elementSizeRef.current.height;
|
|
2115
|
+
const scale = initialTransformRef.current.scale || 1;
|
|
2116
|
+
const progressDisplacement = getDisplacement(progressDirection, dragDeltaX, dragDeltaY);
|
|
2117
|
+
if (size > 0 && scale > 0 && progressDisplacement > 0) {
|
|
2118
|
+
progress = progressDisplacement / (size * scale);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
updateSwipeProgress(progress, progressDetails);
|
|
2122
|
+
}
|
|
2123
|
+
const handleEnd = useStableCallback(event => {
|
|
2124
|
+
if (!enabled) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
const resolvedDragOffset = dragOffsetRef.current;
|
|
2128
|
+
const resolvedInitialTransform = initialTransformRef.current;
|
|
2129
|
+
const releaseDeltaX = resolvedDragOffset.x - resolvedInitialTransform.x;
|
|
2130
|
+
const releaseDeltaY = resolvedDragOffset.y - resolvedInitialTransform.y;
|
|
2131
|
+
const progressDetails = {
|
|
2132
|
+
deltaX: releaseDeltaX,
|
|
2133
|
+
deltaY: releaseDeltaY,
|
|
2134
|
+
direction: intendedSwipeDirectionRef.current
|
|
2135
|
+
};
|
|
2136
|
+
if (!isSwipingRef.current) {
|
|
2137
|
+
resetPendingSwipeState();
|
|
2138
|
+
updateSwipeProgress(0, progressDetails);
|
|
2139
|
+
return;
|
|
2140
|
+
}
|
|
2141
|
+
setSwiping(false);
|
|
2142
|
+
lockedDirectionRef.current = null;
|
|
2143
|
+
resetPendingSwipeState();
|
|
2144
|
+
sawPrimaryButtonsOnMoveRef.current = false;
|
|
2145
|
+
const element = elementRef.current;
|
|
2146
|
+
if (element) {
|
|
2147
|
+
if (!('touches' in event)) {
|
|
2148
|
+
safelyChangePointerCapture(element, event.pointerId, 'releasePointerCapture');
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
const deltaX = releaseDeltaX;
|
|
2152
|
+
const deltaY = releaseDeltaY;
|
|
2153
|
+
const startTime = swipeStartTimeRef.current;
|
|
2154
|
+
const endTime = getValidTimeStamp(event.timeStamp);
|
|
2155
|
+
const durationMs = startTime !== null && endTime !== null && endTime > startTime ? endTime - startTime : 0;
|
|
2156
|
+
const velocityDurationMs = durationMs > 0 ? Math.max(durationMs, MIN_VELOCITY_DURATION_MS) : 0;
|
|
2157
|
+
const velocityX = velocityDurationMs > 0 ? deltaX / velocityDurationMs : 0;
|
|
2158
|
+
const velocityY = velocityDurationMs > 0 ? deltaY / velocityDurationMs : 0;
|
|
2159
|
+
let releaseVelocityX = lastDragVelocityRef.current.x;
|
|
2160
|
+
let releaseVelocityY = lastDragVelocityRef.current.y;
|
|
2161
|
+
const lastSample = lastDragSampleRef.current;
|
|
2162
|
+
if (lastSample && endTime !== null && endTime >= lastSample.time) {
|
|
2163
|
+
const ageMs = endTime - lastSample.time;
|
|
2164
|
+
if (ageMs <= MAX_RELEASE_VELOCITY_AGE_MS) {
|
|
2165
|
+
const sampleDurationMs = Math.max(ageMs, MIN_RELEASE_VELOCITY_DURATION_MS);
|
|
2166
|
+
const deltaFromLastSampleX = resolvedDragOffset.x - lastSample.x;
|
|
2167
|
+
const deltaFromLastSampleY = resolvedDragOffset.y - lastSample.y;
|
|
2168
|
+
const sampleVelocityX = deltaFromLastSampleX / sampleDurationMs;
|
|
2169
|
+
const sampleVelocityY = deltaFromLastSampleY / sampleDurationMs;
|
|
2170
|
+
if (sampleVelocityX !== 0) {
|
|
2171
|
+
releaseVelocityX = sampleVelocityX;
|
|
2172
|
+
}
|
|
2173
|
+
if (sampleVelocityY !== 0) {
|
|
2174
|
+
releaseVelocityY = sampleVelocityY;
|
|
2175
|
+
}
|
|
2176
|
+
} else {
|
|
2177
|
+
releaseVelocityX = 0;
|
|
2178
|
+
releaseVelocityY = 0;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
const releaseDecision = onRelease?.({
|
|
2182
|
+
event: event.nativeEvent,
|
|
2183
|
+
direction: intendedSwipeDirectionRef.current,
|
|
2184
|
+
deltaX,
|
|
2185
|
+
deltaY,
|
|
2186
|
+
velocityX,
|
|
2187
|
+
velocityY,
|
|
2188
|
+
releaseVelocityX,
|
|
2189
|
+
releaseVelocityY
|
|
2190
|
+
});
|
|
2191
|
+
const hasReleaseDecision = typeof releaseDecision === 'boolean';
|
|
2192
|
+
if (cancelledSwipeRef.current && !hasReleaseDecision) {
|
|
2193
|
+
dragOffsetRef.current = {
|
|
2194
|
+
x: resolvedInitialTransform.x,
|
|
2195
|
+
y: resolvedInitialTransform.y
|
|
2196
|
+
};
|
|
2197
|
+
setCurrentSwipeDirection(undefined);
|
|
2198
|
+
syncDragStyles(false);
|
|
2199
|
+
updateSwipeProgress(0, progressDetails);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
let shouldClose = false;
|
|
2203
|
+
let dismissDirection;
|
|
2204
|
+
if (hasReleaseDecision) {
|
|
2205
|
+
shouldClose = releaseDecision;
|
|
2206
|
+
dismissDirection = intendedSwipeDirectionRef.current ?? primaryDirection;
|
|
2207
|
+
} else {
|
|
2208
|
+
for (const direction of directions) {
|
|
2209
|
+
if (getDisplacement(direction, deltaX, deltaY) > swipeThresholdRef.current) {
|
|
2210
|
+
shouldClose = true;
|
|
2211
|
+
dismissDirection = direction;
|
|
2212
|
+
break;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
if (shouldClose && dismissDirection) {
|
|
2217
|
+
setCurrentSwipeDirection(dismissDirection);
|
|
2218
|
+
setDragDismissed(true);
|
|
2219
|
+
syncDragStyles(false);
|
|
2220
|
+
onDismiss?.(event.nativeEvent, {
|
|
2221
|
+
direction: dismissDirection
|
|
2222
|
+
});
|
|
2223
|
+
} else {
|
|
2224
|
+
dragOffsetRef.current = {
|
|
2225
|
+
x: resolvedInitialTransform.x,
|
|
2226
|
+
y: resolvedInitialTransform.y
|
|
2227
|
+
};
|
|
2228
|
+
setCurrentSwipeDirection(undefined);
|
|
2229
|
+
syncDragStyles(false);
|
|
2230
|
+
updateSwipeProgress(0, progressDetails);
|
|
2231
|
+
}
|
|
2232
|
+
});
|
|
2233
|
+
const handleMove = useStableCallback(event => {
|
|
2234
|
+
const currentPos = getPrimaryPointerPosition(event);
|
|
2235
|
+
if (!currentPos) {
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
let endAfterMove = false;
|
|
2239
|
+
if (!('touches' in event)) {
|
|
2240
|
+
const hasPrimaryButton = hasPrimaryMouseButton(event.buttons);
|
|
2241
|
+
if (hasPrimaryButton) {
|
|
2242
|
+
sawPrimaryButtonsOnMoveRef.current = true;
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
// Cancel the swipe if a non-primary button takes over the interaction.
|
|
2246
|
+
// This handles cases where a right-click interrupts dragging.
|
|
2247
|
+
if (event.buttons !== 0 && !hasPrimaryButton) {
|
|
2248
|
+
cancelSwipeInteraction(event);
|
|
2249
|
+
return;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// A `buttons: 0` pointermove means the primary button was already released, so the gesture is
|
|
2253
|
+
// over even if no pointerup reached us. On fast trackpad flicks this trailing move is
|
|
2254
|
+
// dispatched just before pointerup; treat it as the release (mirroring touchend) instead of
|
|
2255
|
+
// cancelling and snapping the element back.
|
|
2256
|
+
if (event.buttons === 0 && sawPrimaryButtonsOnMoveRef.current) {
|
|
2257
|
+
if (!isSwipingRef.current) {
|
|
2258
|
+
// The gesture never activated — discard it.
|
|
2259
|
+
handleEnd(event);
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
// This release move can itself carry the threshold-crossing displacement (and the peak
|
|
2263
|
+
// release velocity), so let it flow through `handleMoveCore` below to update the drag
|
|
2264
|
+
// offset / velocity sample, then commit the release afterwards.
|
|
2265
|
+
endAfterMove = true;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
if (!isSwiping && pendingSwipeRef.current) {
|
|
2269
|
+
if (!isTouchLikeEvent(event) && (event.defaultPrevented || event.nativeEvent.defaultPrevented)) {
|
|
2270
|
+
resetPendingSwipeState();
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
const allowedToStart = canStart ? canStart(currentPos, {
|
|
2274
|
+
nativeEvent: event.nativeEvent,
|
|
2275
|
+
direction: primaryDirection
|
|
2276
|
+
}) : true;
|
|
2277
|
+
if (allowedToStart) {
|
|
2278
|
+
const pendingStartPos = pendingSwipeStartPosRef.current;
|
|
2279
|
+
let ignoreScrollableOnStart = false;
|
|
2280
|
+
if (isTouchLikeEvent(event)) {
|
|
2281
|
+
const element = elementRef.current;
|
|
2282
|
+
if (pendingStartPos && element) {
|
|
2283
|
+
const target = getTargetAtPoint(currentPos, event.nativeEvent);
|
|
2284
|
+
const doc = ownerDocument(element);
|
|
2285
|
+
const body = doc.body;
|
|
2286
|
+
const scrollTarget = body ? findGestureScrollableTouchTarget(target, body) : null;
|
|
2287
|
+
if (scrollTarget && (contains(element, scrollTarget) || contains(scrollTarget, element))) {
|
|
2288
|
+
const deltaX = currentPos.x - pendingStartPos.x;
|
|
2289
|
+
const deltaY = currentPos.y - pendingStartPos.y;
|
|
2290
|
+
const canSwipeFromEdge = canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY);
|
|
2291
|
+
if (canSwipeFromEdge === false) {
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
if (canSwipeFromEdge === true) {
|
|
2295
|
+
ignoreScrollableOnStart = true;
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
const started = startSwipeAtPosition(event, currentPos, {
|
|
2301
|
+
ignoreScrollableTarget: ignoreScrollableOnStart,
|
|
2302
|
+
ignoreScrollableAncestors: ignoreScrollableOnStart
|
|
2303
|
+
});
|
|
2304
|
+
if (started) {
|
|
2305
|
+
if (pendingStartPos && ignoreScrollableOnStart) {
|
|
2306
|
+
// Preserve displacement between touchstart and the move that activates swipe from
|
|
2307
|
+
// a scroll-edge so quick flicks can dismiss.
|
|
2308
|
+
clearPendingSwipeStartState();
|
|
2309
|
+
dragStartPosRef.current = pendingStartPos;
|
|
2310
|
+
swipeCancelBaselineRef.current = pendingStartPos;
|
|
2311
|
+
lastMovePosRef.current = pendingStartPos;
|
|
2312
|
+
isFirstPointerMoveRef.current = false;
|
|
2313
|
+
} else {
|
|
2314
|
+
// Start from the current in-bounds position without dropping follow-up move
|
|
2315
|
+
// displacement; this avoids jumps when entering from outside the element while
|
|
2316
|
+
// keeping swipe tracking responsive on the next move.
|
|
2317
|
+
clearPendingSwipeStartState();
|
|
2318
|
+
swipeFromScrollableRef.current = false;
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
const previousPos = lastMovePosRef.current;
|
|
2324
|
+
const movement = previousPos === null ? {
|
|
2325
|
+
x: 0,
|
|
2326
|
+
y: 0
|
|
2327
|
+
} : {
|
|
2328
|
+
x: currentPos.x - previousPos.x,
|
|
2329
|
+
y: currentPos.y - previousPos.y
|
|
2330
|
+
};
|
|
2331
|
+
lastMovePosRef.current = currentPos;
|
|
2332
|
+
handleMoveCore(event, currentPos, movement);
|
|
2333
|
+
|
|
2334
|
+
// `endAfterMove` is only set in the non-touch branch above; the `'touches'` guard re-narrows the
|
|
2335
|
+
// event type for `handleEnd` after the shared move handling has run.
|
|
2336
|
+
if (endAfterMove && !('touches' in event)) {
|
|
2337
|
+
handleEnd(event);
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
|
|
2341
|
+
// Feeds a native touchmove into the swipe pipeline. Used by consumers that claim the gesture
|
|
2342
|
+
// in a capture-phase listener and stop it from reaching React's delegated touch handlers.
|
|
2343
|
+
const moveNative = useStableCallback((nativeEvent, currentTarget) => {
|
|
2344
|
+
handleMove({
|
|
2345
|
+
touches: nativeEvent.touches,
|
|
2346
|
+
currentTarget,
|
|
2347
|
+
nativeEvent,
|
|
2348
|
+
defaultPrevented: nativeEvent.defaultPrevented,
|
|
2349
|
+
timeStamp: nativeEvent.timeStamp
|
|
2350
|
+
});
|
|
2351
|
+
});
|
|
2352
|
+
const getDragStyles = React.useCallback(() => {
|
|
2353
|
+
// Read `isSwipingRef`, not the lagging `isSwiping` state, to match the imperative writer
|
|
2354
|
+
// `syncDragStyles`. Otherwise a render that commits before `setSwiping(true)` flushes strips the
|
|
2355
|
+
// transform it just wrote, flashing the popup to its resting position for a frame.
|
|
2356
|
+
const swiping = isSwipingRef.current;
|
|
2357
|
+
const dragOffset = dragOffsetRef.current;
|
|
2358
|
+
const initialTransform = initialTransformRef.current;
|
|
2359
|
+
const deltaX = dragOffset.x - initialTransform.x;
|
|
2360
|
+
const deltaY = dragOffset.y - initialTransform.y;
|
|
2361
|
+
if (!swiping && deltaX === 0 && deltaY === 0 && !dragDismissed) {
|
|
2362
|
+
return {
|
|
2363
|
+
[movementCssVars.x]: '0px',
|
|
2364
|
+
[movementCssVars.y]: '0px'
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
return {
|
|
2368
|
+
transition: swiping ? 'none' : undefined,
|
|
2369
|
+
// While swiping, freeze the element at its current visual transform so it doesn't snap to the
|
|
2370
|
+
// end position.
|
|
2371
|
+
transform: swiping ? getDragTransform(dragOffset, initialTransform.scale) : undefined,
|
|
2372
|
+
[movementCssVars.x]: `${deltaX}px`,
|
|
2373
|
+
[movementCssVars.y]: `${deltaY}px`
|
|
2374
|
+
};
|
|
2375
|
+
}, [dragDismissed, movementCssVars]);
|
|
2376
|
+
const getPointerProps = React.useCallback(() => {
|
|
2377
|
+
if (!enabled) {
|
|
2378
|
+
return {};
|
|
2379
|
+
}
|
|
2380
|
+
return {
|
|
2381
|
+
onPointerDown: handleStart,
|
|
2382
|
+
onPointerMove: handleMove,
|
|
2383
|
+
onPointerUp: handleEnd,
|
|
2384
|
+
onPointerCancel: handleEnd
|
|
2385
|
+
};
|
|
2386
|
+
}, [enabled, handleEnd, handleMove, handleStart]);
|
|
2387
|
+
const getTouchProps = React.useCallback(() => {
|
|
2388
|
+
if (!enabled) {
|
|
2389
|
+
return {};
|
|
2390
|
+
}
|
|
2391
|
+
return {
|
|
2392
|
+
onTouchStart: handleStart,
|
|
2393
|
+
onTouchMove: handleMove,
|
|
2394
|
+
onTouchEnd: handleEnd,
|
|
2395
|
+
onTouchCancel: handleEnd
|
|
2396
|
+
};
|
|
2397
|
+
}, [enabled, handleEnd, handleMove, handleStart]);
|
|
2398
|
+
return {
|
|
2399
|
+
swiping: isSwiping,
|
|
2400
|
+
swipeDirection: currentSwipeDirection,
|
|
2401
|
+
dragDismissed,
|
|
2402
|
+
getPointerProps,
|
|
2403
|
+
getTouchProps,
|
|
2404
|
+
moveNative,
|
|
2405
|
+
getDragStyles,
|
|
2406
|
+
reset
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
/**
|
|
2411
|
+
* A button that opens the drawer.
|
|
2412
|
+
* Renders a `<button>` element.
|
|
2413
|
+
*
|
|
2414
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
2415
|
+
*/
|
|
2416
|
+
const DrawerTrigger = DialogTrigger;
|
|
2417
|
+
|
|
2418
|
+
const DrawerVirtualKeyboardContext = /*#__PURE__*/React.createContext(undefined);
|
|
2419
|
+
if (process.env.NODE_ENV !== "production") DrawerVirtualKeyboardContext.displayName = "DrawerVirtualKeyboardContext";
|
|
2420
|
+
function useDrawerVirtualKeyboardContext() {
|
|
2421
|
+
return React.useContext(DrawerVirtualKeyboardContext);
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
const MIN_SWIPE_THRESHOLD = 10;
|
|
2425
|
+
const FAST_SWIPE_VELOCITY = 0.5;
|
|
2426
|
+
const SNAP_VELOCITY_THRESHOLD = 0.5;
|
|
2427
|
+
const SNAP_VELOCITY_MULTIPLIER = 300;
|
|
2428
|
+
const MAX_SNAP_VELOCITY = 4;
|
|
2429
|
+
const MIN_SWIPE_RELEASE_VELOCITY = 0.2;
|
|
2430
|
+
const MAX_SWIPE_RELEASE_VELOCITY = 4;
|
|
2431
|
+
const MIN_SWIPE_RELEASE_DURATION_MS = 80;
|
|
2432
|
+
const MAX_SWIPE_RELEASE_DURATION_MS = 360;
|
|
2433
|
+
const MIN_SWIPE_RELEASE_SCALAR = 0.1;
|
|
2434
|
+
const MAX_SWIPE_RELEASE_SCALAR = 1;
|
|
2435
|
+
const AXIS_LOCK_SLOP = 6;
|
|
2436
|
+
const AXIS_LOCK_BIAS = 2;
|
|
2437
|
+
const DRAWER_CONTENT_SELECTOR = `[${DRAWER_CONTENT_ATTRIBUTE}]`;
|
|
2438
|
+
/**
|
|
2439
|
+
* A positioning container for the drawer popup that can be made scrollable.
|
|
2440
|
+
* Renders a `<div>` element.
|
|
2441
|
+
*
|
|
2442
|
+
* Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
|
|
2443
|
+
*/
|
|
2444
|
+
const DrawerViewport = /*#__PURE__*/React.forwardRef(function DrawerViewport(props, forwardedRef) {
|
|
2445
|
+
const {
|
|
2446
|
+
render,
|
|
2447
|
+
className,
|
|
2448
|
+
style,
|
|
2449
|
+
children,
|
|
2450
|
+
...elementProps
|
|
2451
|
+
} = props;
|
|
2452
|
+
const store = useDialogRootContext();
|
|
2453
|
+
const popupRef = store.context.popupRef;
|
|
2454
|
+
const backdropRef = store.context.backdropRef;
|
|
2455
|
+
const {
|
|
2456
|
+
swipeDirection,
|
|
2457
|
+
notifyParentSwipingChange,
|
|
2458
|
+
notifyParentSwipeProgressChange,
|
|
2459
|
+
frontmostHeight,
|
|
2460
|
+
snapToSequentialPoints,
|
|
2461
|
+
swipeAreaActiveRef
|
|
2462
|
+
} = useDrawerRootContext();
|
|
2463
|
+
const providerContext = useDrawerProviderContext();
|
|
2464
|
+
const {
|
|
2465
|
+
snapPoints,
|
|
2466
|
+
resolvedSnapPoints,
|
|
2467
|
+
activeSnapPoint,
|
|
2468
|
+
activeSnapPointOffset,
|
|
2469
|
+
setActiveSnapPoint,
|
|
2470
|
+
popupHeight
|
|
2471
|
+
} = useDrawerSnapPoints();
|
|
2472
|
+
const open = store.useState('open');
|
|
2473
|
+
const mounted = store.useState('mounted');
|
|
2474
|
+
const nested = store.useState('nested');
|
|
2475
|
+
const nestedOpenDrawerCount = store.useState('nestedOpenDrawerCount');
|
|
2476
|
+
const viewportElement = store.useState('viewportElement');
|
|
2477
|
+
const popupElementState = store.useState('popupElement');
|
|
2478
|
+
const visualStateStore = providerContext?.visualStateStore;
|
|
2479
|
+
const nestedDrawerOpen = nestedOpenDrawerCount > 0;
|
|
2480
|
+
const scrollAxis = swipeDirection === 'left' || swipeDirection === 'right' ? 'horizontal' : 'vertical';
|
|
2481
|
+
const isVerticalScrollAxis = scrollAxis === 'vertical';
|
|
2482
|
+
const crossScrollAxis = isVerticalScrollAxis ? 'horizontal' : 'vertical';
|
|
2483
|
+
const [swipeRelease, setSwipeRelease] = React.useState(null);
|
|
2484
|
+
const pendingSwipeCloseSnapPointRef = React.useRef(undefined);
|
|
2485
|
+
const resetSwipeRef = React.useRef(null);
|
|
2486
|
+
const controlledDismissFrame = useAnimationFrame();
|
|
2487
|
+
const swipingRef = React.useRef(false);
|
|
2488
|
+
const nestedSwipeActiveRef = React.useRef(false);
|
|
2489
|
+
const lastPointerTypeRef = React.useRef('');
|
|
2490
|
+
const ignoreNextTouchStartFromPenRef = React.useRef(false);
|
|
2491
|
+
const ignoreTouchSwipeRef = React.useRef(false);
|
|
2492
|
+
const touchScrollStateRef = React.useRef(null);
|
|
2493
|
+
const virtualKeyboard = useDrawerVirtualKeyboardContext();
|
|
2494
|
+
const snapPointRange = React.useMemo(() => {
|
|
2495
|
+
if (!snapPoints || snapPoints.length < 2 || resolvedSnapPoints.length < 2 || swipeDirection !== 'down' && swipeDirection !== 'up') {
|
|
2496
|
+
return null;
|
|
2497
|
+
}
|
|
2498
|
+
const offsets = resolvedSnapPoints.map(point => point.offset).sort((a, b) => a - b);
|
|
2499
|
+
const minOffset = offsets[0];
|
|
2500
|
+
const nextOffset = offsets[1];
|
|
2501
|
+
const range = nextOffset - minOffset;
|
|
2502
|
+
return {
|
|
2503
|
+
minOffset,
|
|
2504
|
+
range
|
|
2505
|
+
};
|
|
2506
|
+
}, [resolvedSnapPoints, snapPoints, swipeDirection]);
|
|
2507
|
+
const snapPointProgress = React.useMemo(() => {
|
|
2508
|
+
if (!snapPointRange || activeSnapPointOffset === null) {
|
|
2509
|
+
return null;
|
|
2510
|
+
}
|
|
2511
|
+
return clamp((activeSnapPointOffset - snapPointRange.minOffset) / snapPointRange.range, 0, 1);
|
|
2512
|
+
}, [activeSnapPointOffset, snapPointRange]);
|
|
2513
|
+
const swipeDirections = React.useMemo(() => {
|
|
2514
|
+
if (snapPoints && snapPoints.length > 0 && (swipeDirection === 'down' || swipeDirection === 'up')) {
|
|
2515
|
+
return swipeDirection === 'down' ? ['down', 'up'] : ['up', 'down'];
|
|
2516
|
+
}
|
|
2517
|
+
return [swipeDirection];
|
|
2518
|
+
}, [snapPoints, swipeDirection]);
|
|
2519
|
+
const setSwipeDismissed = useStableCallback(dismissed => {
|
|
2520
|
+
popupRef.current?.toggleAttribute(DrawerPopupDataAttributes.swipeDismiss, dismissed);
|
|
2521
|
+
backdropRef.current?.toggleAttribute(DrawerPopupDataAttributes.swipeDismiss, dismissed);
|
|
2522
|
+
});
|
|
2523
|
+
const clearSwipeRelease = useStableCallback(() => {
|
|
2524
|
+
setSwipeDismissed(false);
|
|
2525
|
+
popupRef.current?.removeAttribute(TransitionStatusDataAttributes.endingStyle);
|
|
2526
|
+
setSwipeRelease(null);
|
|
2527
|
+
});
|
|
2528
|
+
const finishNestedSwipe = useStableCallback(() => {
|
|
2529
|
+
if (!nestedSwipeActiveRef.current) {
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
nestedSwipeActiveRef.current = false;
|
|
2533
|
+
notifyParentSwipingChange?.(false);
|
|
2534
|
+
});
|
|
2535
|
+
const applySwipeProgress = useStableCallback((resolvedProgress, shouldTrackProgress, notifyParent) => {
|
|
2536
|
+
const isActive = open && !nested && shouldTrackProgress;
|
|
2537
|
+
const swipeProgress = isActive ? resolvedProgress : 0;
|
|
2538
|
+
const nestedSwipeProgress = open && shouldTrackProgress ? resolvedProgress : 0;
|
|
2539
|
+
if (notifyParent && notifyParentSwipeProgressChange) {
|
|
2540
|
+
notifyParentSwipeProgressChange(nestedSwipeProgress);
|
|
2541
|
+
if (nestedSwipeProgress <= 0) {
|
|
2542
|
+
finishNestedSwipe();
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
visualStateStore?.set({
|
|
2546
|
+
swipeProgress,
|
|
2547
|
+
frontmostHeight: swipeProgress > 0 ? frontmostHeight : 0
|
|
2548
|
+
});
|
|
2549
|
+
const backdropElement = backdropRef.current;
|
|
2550
|
+
if (!backdropElement) {
|
|
2551
|
+
return;
|
|
2552
|
+
}
|
|
2553
|
+
const showProgress = isActive && swipeProgress > 0;
|
|
2554
|
+
backdropElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, showProgress ? `${swipeProgress}` : '0');
|
|
2555
|
+
if (showProgress && frontmostHeight > 0) {
|
|
2556
|
+
backdropElement.style.setProperty(DrawerPopupCssVars.height, `${frontmostHeight}px`);
|
|
2557
|
+
} else {
|
|
2558
|
+
backdropElement.style.removeProperty(DrawerPopupCssVars.height);
|
|
2559
|
+
}
|
|
2560
|
+
});
|
|
2561
|
+
function resolveSwipeRelease(popupElement, direction, deltaX, deltaY, velocityX, velocityY, releaseVelocityX, releaseVelocityY) {
|
|
2562
|
+
const size = getBaseSwipeSize(popupElement, direction);
|
|
2563
|
+
if (size <= 0) {
|
|
2564
|
+
return null;
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
// The snap point base offset shifts the popup along the dismiss direction for both
|
|
2568
|
+
// `down` (+offset) and `up` (-offset), so it always adds to the directional translation.
|
|
2569
|
+
const snapPointBaseOffset = (direction === 'down' || direction === 'up') && snapPoints && snapPoints.length > 0 ? activeSnapPointOffset ?? 0 : 0;
|
|
2570
|
+
const translationAlongDirection = snapPointBaseOffset + getDisplacement(direction, deltaX, deltaY);
|
|
2571
|
+
const remainingDistance = Math.max(0, size - translationAlongDirection);
|
|
2572
|
+
if (remainingDistance <= 0) {
|
|
2573
|
+
return null;
|
|
2574
|
+
}
|
|
2575
|
+
const releaseVelocity = getDisplacement(direction, releaseVelocityX, releaseVelocityY);
|
|
2576
|
+
const directionalVelocity = Math.abs(releaseVelocity) > 0 ? releaseVelocity : getDisplacement(direction, velocityX, velocityY);
|
|
2577
|
+
if (directionalVelocity <= MIN_SWIPE_RELEASE_VELOCITY) {
|
|
2578
|
+
return null;
|
|
2579
|
+
}
|
|
2580
|
+
const clampedVelocity = clamp(directionalVelocity, MIN_SWIPE_RELEASE_VELOCITY, MAX_SWIPE_RELEASE_VELOCITY);
|
|
2581
|
+
// The gesture hook supplies finite deltas and velocities. The guards above keep the remaining
|
|
2582
|
+
// distance and divisor positive, so the duration stays within [MIN, MAX] and the resulting
|
|
2583
|
+
// scalar within (0, 1].
|
|
2584
|
+
const durationMs = clamp(remainingDistance / clampedVelocity, MIN_SWIPE_RELEASE_DURATION_MS, MAX_SWIPE_RELEASE_DURATION_MS);
|
|
2585
|
+
const normalizedDuration = (durationMs - MIN_SWIPE_RELEASE_DURATION_MS) / (MAX_SWIPE_RELEASE_DURATION_MS - MIN_SWIPE_RELEASE_DURATION_MS);
|
|
2586
|
+
return MIN_SWIPE_RELEASE_SCALAR + normalizedDuration * (MAX_SWIPE_RELEASE_SCALAR - MIN_SWIPE_RELEASE_SCALAR);
|
|
2587
|
+
}
|
|
2588
|
+
function updateNestedSwipeActive(details) {
|
|
2589
|
+
if (nestedSwipeActiveRef.current || !details) {
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
const direction = details.direction ?? swipeDirection;
|
|
2593
|
+
const delta = getDisplacement(direction, details.deltaX, details.deltaY);
|
|
2594
|
+
if (Math.abs(delta) < MIN_SWIPE_THRESHOLD) {
|
|
2595
|
+
return;
|
|
2596
|
+
}
|
|
2597
|
+
nestedSwipeActiveRef.current = true;
|
|
2598
|
+
notifyParentSwipingChange?.(true);
|
|
2599
|
+
}
|
|
2600
|
+
const swipe$1 = useSwipeDismiss({
|
|
2601
|
+
enabled: mounted && !nestedDrawerOpen,
|
|
2602
|
+
directions: swipeDirections,
|
|
2603
|
+
elementRef: store.context.popupRef,
|
|
2604
|
+
ignoreSelectorWhenTouch: false,
|
|
2605
|
+
ignoreScrollableAncestors: true,
|
|
2606
|
+
movementCssVars: {
|
|
2607
|
+
x: DrawerPopupCssVars.swipeMovementX,
|
|
2608
|
+
y: DrawerPopupCssVars.swipeMovementY
|
|
2609
|
+
},
|
|
2610
|
+
onSwipeStart(event) {
|
|
2611
|
+
if ('touches' in event || event.pointerType === 'touch') {
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
const popupElement = popupRef.current;
|
|
2615
|
+
const doc = ownerDocument(popupElement);
|
|
2616
|
+
const selection = doc.getSelection?.();
|
|
2617
|
+
if (!selection || selection.isCollapsed) {
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
const anchorElement = isElement(selection.anchorNode) ? selection.anchorNode : selection.anchorNode?.parentElement;
|
|
2621
|
+
const focusElement = isElement(selection.focusNode) ? selection.focusNode : selection.focusNode?.parentElement;
|
|
2622
|
+
if (!contains(popupElement, anchorElement) && !contains(popupElement, focusElement)) {
|
|
2623
|
+
return;
|
|
2624
|
+
}
|
|
2625
|
+
selection.removeAllRanges();
|
|
2626
|
+
},
|
|
2627
|
+
onSwipingChange(swiping) {
|
|
2628
|
+
swipingRef.current = swiping;
|
|
2629
|
+
setBackdropSwipingAttribute(store.context.backdropRef.current, swiping);
|
|
2630
|
+
if (!swiping && !notifyParentSwipeProgressChange) {
|
|
2631
|
+
finishNestedSwipe();
|
|
2632
|
+
}
|
|
2633
|
+
},
|
|
2634
|
+
swipeThreshold({
|
|
2635
|
+
element,
|
|
2636
|
+
direction
|
|
2637
|
+
}) {
|
|
2638
|
+
return getBaseSwipeThreshold(element, direction);
|
|
2639
|
+
},
|
|
2640
|
+
canStart(position, details) {
|
|
2641
|
+
const popupElement = store.context.popupRef.current;
|
|
2642
|
+
if (!popupElement) {
|
|
2643
|
+
return false;
|
|
2644
|
+
}
|
|
2645
|
+
const doc = popupElement.ownerDocument;
|
|
2646
|
+
const elementAtPoint = getElementAtPoint(popupElement.getRootNode(), position.x, position.y);
|
|
2647
|
+
if (!elementAtPoint || !contains(popupElement, elementAtPoint)) {
|
|
2648
|
+
return false;
|
|
2649
|
+
}
|
|
2650
|
+
const nativeEvent = details.nativeEvent;
|
|
2651
|
+
const touchLike = 'touches' in nativeEvent || nativeEvent.pointerType === 'touch';
|
|
2652
|
+
if (touchLike && shouldIgnoreSwipeForTextSelection(doc, popupElement)) {
|
|
2653
|
+
return false;
|
|
2654
|
+
}
|
|
2655
|
+
return true;
|
|
2656
|
+
},
|
|
2657
|
+
onProgress(progress, details) {
|
|
2658
|
+
updateNestedSwipeActive(details);
|
|
2659
|
+
const hasSnapPoints = Boolean(snapPoints && snapPoints.length > 0);
|
|
2660
|
+
if (swipingRef.current && swipeDirection === 'down' && hasSnapPoints && details) {
|
|
2661
|
+
const popupElement = store.context.popupRef.current;
|
|
2662
|
+
if (popupElement) {
|
|
2663
|
+
popupElement.style.removeProperty('transform');
|
|
2664
|
+
popupElement.style.setProperty(DrawerPopupCssVars.swipeMovementY, `${getSnapPointSwipeMovement(activeSnapPointOffset ?? 0, details.deltaY)}px`);
|
|
2665
|
+
}
|
|
2666
|
+
}
|
|
2667
|
+
let resolvedProgress = progress;
|
|
2668
|
+
if (snapPointRange && popupHeight > 0) {
|
|
2669
|
+
const baseOffset = activeSnapPointOffset ?? snapPointRange.minOffset;
|
|
2670
|
+
const offsetToProgress = nextOffset => clamp((nextOffset - snapPointRange.minOffset) / snapPointRange.range, 0, 1);
|
|
2671
|
+
if (details && Number.isFinite(details.deltaY)) {
|
|
2672
|
+
resolvedProgress = offsetToProgress(clamp(baseOffset + details.deltaY, 0, popupHeight));
|
|
2673
|
+
} else if (snapPointProgress !== null) {
|
|
2674
|
+
resolvedProgress = snapPointProgress;
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
applySwipeProgress(resolvedProgress, true, true);
|
|
2678
|
+
},
|
|
2679
|
+
onRelease({
|
|
2680
|
+
event,
|
|
2681
|
+
deltaX,
|
|
2682
|
+
deltaY,
|
|
2683
|
+
direction,
|
|
2684
|
+
velocityX,
|
|
2685
|
+
velocityY,
|
|
2686
|
+
releaseVelocityX,
|
|
2687
|
+
releaseVelocityY
|
|
2688
|
+
}) {
|
|
2689
|
+
const popupElement = store.context.popupRef.current;
|
|
2690
|
+
if (!popupElement) {
|
|
2691
|
+
clearSwipeRelease();
|
|
2692
|
+
return undefined;
|
|
2693
|
+
}
|
|
2694
|
+
const releasePopupElement = popupElement;
|
|
2695
|
+
function startSwipeRelease(resolvedDirection) {
|
|
2696
|
+
// Start ending transition styles earlier and synchronously to prevent a period where
|
|
2697
|
+
// the popup appears stuck on release before the actual closing animation starts.
|
|
2698
|
+
finishNestedSwipe();
|
|
2699
|
+
setSwipeDismissed(true);
|
|
2700
|
+
releasePopupElement.style.removeProperty('transition');
|
|
2701
|
+
releasePopupElement.setAttribute(TransitionStatusDataAttributes.endingStyle, '');
|
|
2702
|
+
ReactDOM.flushSync(() => {
|
|
2703
|
+
setSwipeRelease(resolveSwipeRelease(releasePopupElement, resolvedDirection, deltaX, deltaY, velocityX, velocityY, releaseVelocityX, releaseVelocityY));
|
|
2704
|
+
});
|
|
2705
|
+
}
|
|
2706
|
+
if (!snapPoints || snapPoints.length === 0) {
|
|
2707
|
+
if (!direction) {
|
|
2708
|
+
clearSwipeRelease();
|
|
2709
|
+
return undefined;
|
|
2710
|
+
}
|
|
2711
|
+
const directionalDelta = getDisplacement(direction, deltaX, deltaY);
|
|
2712
|
+
if (directionalDelta <= 0) {
|
|
2713
|
+
clearSwipeRelease();
|
|
2714
|
+
return false;
|
|
2715
|
+
}
|
|
2716
|
+
if (getDisplacement(direction, velocityX, velocityY) >= FAST_SWIPE_VELOCITY) {
|
|
2717
|
+
startSwipeRelease(direction);
|
|
2718
|
+
return true;
|
|
2719
|
+
}
|
|
2720
|
+
const shouldClose = directionalDelta > getBaseSwipeThreshold(releasePopupElement, direction);
|
|
2721
|
+
if (shouldClose) {
|
|
2722
|
+
startSwipeRelease(direction);
|
|
2723
|
+
} else {
|
|
2724
|
+
clearSwipeRelease();
|
|
2725
|
+
}
|
|
2726
|
+
return shouldClose;
|
|
2727
|
+
}
|
|
2728
|
+
if (swipeDirection !== 'down' && swipeDirection !== 'up') {
|
|
2729
|
+
clearSwipeRelease();
|
|
2730
|
+
return undefined;
|
|
2731
|
+
}
|
|
2732
|
+
if (!popupHeight) {
|
|
2733
|
+
clearSwipeRelease();
|
|
2734
|
+
return false;
|
|
2735
|
+
}
|
|
2736
|
+
if (resolvedSnapPoints.length === 0) {
|
|
2737
|
+
clearSwipeRelease();
|
|
2738
|
+
return undefined;
|
|
2739
|
+
}
|
|
2740
|
+
const dragDelta = swipeDirection === 'down' ? deltaY : -deltaY;
|
|
2741
|
+
const dragDirection = Math.sign(dragDelta);
|
|
2742
|
+
const releaseDirectionalVelocity = swipeDirection === 'down' ? releaseVelocityY : -releaseVelocityY;
|
|
2743
|
+
const fallbackDirectionalVelocity = swipeDirection === 'down' ? velocityY : -velocityY;
|
|
2744
|
+
let resolvedDirectionalVelocity = releaseDirectionalVelocity;
|
|
2745
|
+
if (dragDirection !== 0 && Math.abs(dragDelta) >= MIN_SWIPE_THRESHOLD) {
|
|
2746
|
+
const velocityDirection = Math.sign(resolvedDirectionalVelocity);
|
|
2747
|
+
if (velocityDirection !== 0 && velocityDirection !== dragDirection) {
|
|
2748
|
+
// Ignore touch reversals that would otherwise flip the snap decision.
|
|
2749
|
+
resolvedDirectionalVelocity = fallbackDirectionalVelocity;
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
const currentOffset = activeSnapPointOffset ?? 0;
|
|
2753
|
+
const dragTargetOffset = clamp(currentOffset + dragDelta, 0, popupHeight);
|
|
2754
|
+
const velocityOffset = Math.abs(resolvedDirectionalVelocity) >= SNAP_VELOCITY_THRESHOLD ? clamp(resolvedDirectionalVelocity, -MAX_SNAP_VELOCITY, MAX_SNAP_VELOCITY) * SNAP_VELOCITY_MULTIPLIER : 0;
|
|
2755
|
+
const targetOffset = snapToSequentialPoints ? dragTargetOffset : clamp(dragTargetOffset + velocityOffset, 0, popupHeight);
|
|
2756
|
+
const snapPointEventDetails = createChangeEventDetails(swipe, event);
|
|
2757
|
+
const closeFromSnapPoints = () => {
|
|
2758
|
+
pendingSwipeCloseSnapPointRef.current = activeSnapPoint;
|
|
2759
|
+
setActiveSnapPoint(null, snapPointEventDetails);
|
|
2760
|
+
startSwipeRelease(swipeDirection);
|
|
2761
|
+
return true;
|
|
2762
|
+
};
|
|
2763
|
+
if (snapToSequentialPoints) {
|
|
2764
|
+
const orderedSnapPoints = [...resolvedSnapPoints].sort((first, second) => first.offset - second.offset);
|
|
2765
|
+
const orderedOffsets = orderedSnapPoints.map(point => point.offset);
|
|
2766
|
+
const currentIndex = closestSnapPointIndex(orderedOffsets, currentOffset);
|
|
2767
|
+
let targetSnapPoint = orderedSnapPoints[closestSnapPointIndex(orderedOffsets, targetOffset)];
|
|
2768
|
+
const velocityDirection = Math.sign(resolvedDirectionalVelocity);
|
|
2769
|
+
const shouldAdvance = dragDirection !== 0 && velocityDirection !== 0 && velocityDirection === dragDirection && Math.abs(resolvedDirectionalVelocity) >= SNAP_VELOCITY_THRESHOLD;
|
|
2770
|
+
let effectiveTargetOffset = targetOffset;
|
|
2771
|
+
if (shouldAdvance) {
|
|
2772
|
+
const adjacentIndex = clamp(currentIndex + dragDirection, 0, orderedSnapPoints.length - 1);
|
|
2773
|
+
if (adjacentIndex !== currentIndex) {
|
|
2774
|
+
const adjacentPoint = orderedSnapPoints[adjacentIndex];
|
|
2775
|
+
const shouldForceAdjacent = dragDirection > 0 ? targetOffset < adjacentPoint.offset : targetOffset > adjacentPoint.offset;
|
|
2776
|
+
if (shouldForceAdjacent) {
|
|
2777
|
+
targetSnapPoint = adjacentPoint;
|
|
2778
|
+
effectiveTargetOffset = adjacentPoint.offset;
|
|
2779
|
+
}
|
|
2780
|
+
} else if (dragDirection > 0) {
|
|
2781
|
+
return closeFromSnapPoints();
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
const closeDistance = Math.abs(effectiveTargetOffset - popupHeight);
|
|
2785
|
+
const snapDistance = Math.abs(effectiveTargetOffset - targetSnapPoint.offset);
|
|
2786
|
+
if (closeDistance < snapDistance) {
|
|
2787
|
+
return closeFromSnapPoints();
|
|
2788
|
+
}
|
|
2789
|
+
setActiveSnapPoint(targetSnapPoint.value, snapPointEventDetails);
|
|
2790
|
+
clearSwipeRelease();
|
|
2791
|
+
return false;
|
|
2792
|
+
}
|
|
2793
|
+
if (resolvedDirectionalVelocity >= FAST_SWIPE_VELOCITY && dragDelta > 0) {
|
|
2794
|
+
return closeFromSnapPoints();
|
|
2795
|
+
}
|
|
2796
|
+
const closestSnapPoint = resolvedSnapPoints[closestSnapPointIndex(resolvedSnapPoints.map(point => point.offset), targetOffset)];
|
|
2797
|
+
const closeDistance = Math.abs(targetOffset - popupHeight);
|
|
2798
|
+
if (closeDistance < Math.abs(targetOffset - closestSnapPoint.offset)) {
|
|
2799
|
+
return closeFromSnapPoints();
|
|
2800
|
+
}
|
|
2801
|
+
setActiveSnapPoint(closestSnapPoint.value, snapPointEventDetails);
|
|
2802
|
+
clearSwipeRelease();
|
|
2803
|
+
return false;
|
|
2804
|
+
},
|
|
2805
|
+
onDismiss(event) {
|
|
2806
|
+
visualStateStore?.set({
|
|
2807
|
+
swipeProgress: 0,
|
|
2808
|
+
frontmostHeight: 0
|
|
2809
|
+
});
|
|
2810
|
+
const backdropElement = store.context.backdropRef.current;
|
|
2811
|
+
if (backdropElement) {
|
|
2812
|
+
backdropElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, '0');
|
|
2813
|
+
backdropElement.style.removeProperty(DrawerPopupCssVars.height);
|
|
2814
|
+
}
|
|
2815
|
+
const dismissEventDetails = createChangeEventDetails(swipe, event);
|
|
2816
|
+
store.setOpen(false, dismissEventDetails);
|
|
2817
|
+
if (dismissEventDetails.isCanceled) {
|
|
2818
|
+
const pendingSnapPoint = pendingSwipeCloseSnapPointRef.current;
|
|
2819
|
+
if (pendingSnapPoint !== undefined) {
|
|
2820
|
+
setActiveSnapPoint(pendingSnapPoint, createChangeEventDetails(swipe, event));
|
|
2821
|
+
}
|
|
2822
|
+
pendingSwipeCloseSnapPointRef.current = undefined;
|
|
2823
|
+
resetSwipeRef.current?.();
|
|
2824
|
+
clearSwipeRelease();
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// In controlled mode, the effective open state may not have changed yet
|
|
2829
|
+
// (openProp takes precedence over state.open). Proceed optimistically with the
|
|
2830
|
+
// dismiss animation — React's Scheduler flushes before the next rAF, so we can
|
|
2831
|
+
// reliably check whether the parent accepted or rejected the close.
|
|
2832
|
+
// Note: if onOpenChange is asynchronous (e.g., closes the drawer after a network
|
|
2833
|
+
// call), the rAF check will see open === true, revert the animation, and the
|
|
2834
|
+
// drawer will close without animation when the parent eventually sets open={false}.
|
|
2835
|
+
if (store.select('open')) {
|
|
2836
|
+
const savedEvent = event;
|
|
2837
|
+
controlledDismissFrame.request(() => {
|
|
2838
|
+
if (store.select('open')) {
|
|
2839
|
+
// Parent rejected: revert animation and restore snap point.
|
|
2840
|
+
const pendingSnapPoint = pendingSwipeCloseSnapPointRef.current;
|
|
2841
|
+
if (pendingSnapPoint !== undefined) {
|
|
2842
|
+
setActiveSnapPoint(pendingSnapPoint, createChangeEventDetails(swipe, savedEvent));
|
|
2843
|
+
}
|
|
2844
|
+
pendingSwipeCloseSnapPointRef.current = undefined;
|
|
2845
|
+
clearSwipeRelease();
|
|
2846
|
+
resetSwipeRef.current?.();
|
|
2847
|
+
} else {
|
|
2848
|
+
// Parent accepted: clean up the ref.
|
|
2849
|
+
pendingSwipeCloseSnapPointRef.current = undefined;
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
pendingSwipeCloseSnapPointRef.current = undefined;
|
|
2855
|
+
setSwipeDismissed(true);
|
|
2856
|
+
}
|
|
2857
|
+
});
|
|
2858
|
+
const swipePointerProps = swipe$1.getPointerProps();
|
|
2859
|
+
const swipeTouchProps = swipe$1.getTouchProps();
|
|
2860
|
+
const {
|
|
2861
|
+
moveNative: moveSwipeNative,
|
|
2862
|
+
reset: resetSwipe
|
|
2863
|
+
} = swipe$1;
|
|
2864
|
+
resetSwipeRef.current = resetSwipe;
|
|
2865
|
+
React.useEffect(() => {
|
|
2866
|
+
const rootElement = viewportElement ?? popupElementState;
|
|
2867
|
+
if (!rootElement) {
|
|
2868
|
+
return undefined;
|
|
2869
|
+
}
|
|
2870
|
+
const resolvedRootElement = rootElement;
|
|
2871
|
+
const doc = ownerDocument(resolvedRootElement);
|
|
2872
|
+
function processTouchMove(event, touchState, touch) {
|
|
2873
|
+
const drawerAxisDelta = isVerticalScrollAxis ? touch.clientY - touchState.lastY : touch.clientX - touchState.lastX;
|
|
2874
|
+
|
|
2875
|
+
// Avoid blocking pinch zoom or text selection adjustments on iOS Safari.
|
|
2876
|
+
if (event.touches.length === 2) {
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
const allowTouchMove = shouldIgnoreSwipeForTextSelection(doc, resolvedRootElement);
|
|
2880
|
+
if (allowTouchMove || !open || !mounted || nestedDrawerOpen) {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
if (shouldYieldTouchMove(touchState, event, touch, isVerticalScrollAxis)) {
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2886
|
+
const scrollTarget = touchState.scrollTarget;
|
|
2887
|
+
if (!scrollTarget || scrollTarget === doc.documentElement || scrollTarget === doc.body) {
|
|
2888
|
+
if (event.cancelable) {
|
|
2889
|
+
event.preventDefault();
|
|
2890
|
+
}
|
|
2891
|
+
// Claim the gesture before React's delegated touch handlers see it; dispatching the
|
|
2892
|
+
// move through React re-rasterizes the popup content on every frame.
|
|
2893
|
+
event.stopPropagation();
|
|
2894
|
+
moveSwipeNative(event, resolvedRootElement);
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
if (!hasScrollableContentOnAxis(scrollTarget, scrollAxis)) {
|
|
2898
|
+
// If the scroll container doesn't overflow on the drawer axis, prevent the window from
|
|
2899
|
+
// scrolling instead.
|
|
2900
|
+
if (event.cancelable) {
|
|
2901
|
+
event.preventDefault();
|
|
2902
|
+
}
|
|
2903
|
+
event.stopPropagation();
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
if (drawerAxisDelta !== 0) {
|
|
2907
|
+
const canSwipeFromScrollEdge = canSwipeFromScrollEdgeOnMove(scrollTarget, scrollAxis, swipeDirection, drawerAxisDelta);
|
|
2908
|
+
if (!touchState.allowSwipe) {
|
|
2909
|
+
if (event.cancelable && canSwipeFromScrollEdge) {
|
|
2910
|
+
touchState.allowSwipe = true;
|
|
2911
|
+
event.preventDefault();
|
|
2912
|
+
} else {
|
|
2913
|
+
touchState.allowSwipe = false;
|
|
2914
|
+
}
|
|
2915
|
+
} else if (event.cancelable) {
|
|
2916
|
+
event.preventDefault();
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
if (touchState.allowSwipe === true) {
|
|
2920
|
+
event.stopPropagation();
|
|
2921
|
+
moveSwipeNative(event, resolvedRootElement);
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
function handleNativeTouchMove(event) {
|
|
2925
|
+
// The virtual keyboard provider observes the move to tell a tap apart from a drag.
|
|
2926
|
+
// It must run even when the swipe gesture below claims the event with
|
|
2927
|
+
// `stopPropagation()`, which would otherwise prevent React's delegated handlers
|
|
2928
|
+
// (and the provider) from ever seeing the move.
|
|
2929
|
+
virtualKeyboard?.onTouchMove(event);
|
|
2930
|
+
if (ignoreTouchSwipeRef.current) {
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
const touchState = touchScrollStateRef.current;
|
|
2934
|
+
const touch = event.touches[0];
|
|
2935
|
+
if (!touch || !touchState) {
|
|
2936
|
+
return;
|
|
2937
|
+
}
|
|
2938
|
+
processTouchMove(event, touchState, touch);
|
|
2939
|
+
updateTouchScrollPosition(touchState, touch);
|
|
2940
|
+
}
|
|
2941
|
+
return addEventListener(doc, 'touchmove', handleNativeTouchMove, {
|
|
2942
|
+
passive: false,
|
|
2943
|
+
capture: true
|
|
2944
|
+
});
|
|
2945
|
+
}, [mounted, nestedDrawerOpen, open, popupElementState, isVerticalScrollAxis, scrollAxis, swipeDirection, moveSwipeNative, viewportElement, virtualKeyboard]);
|
|
2946
|
+
useIsoLayoutEffect(() => {
|
|
2947
|
+
if (!snapPointRange || swipe$1.swiping) {
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2950
|
+
applySwipeProgress(!open || nested ? 0 : snapPointProgress ?? 0, true, false);
|
|
2951
|
+
}, [applySwipeProgress, frontmostHeight, nested, notifyParentSwipeProgressChange, open, snapPointProgress, snapPointRange, swipe$1.swiping, store, visualStateStore]);
|
|
2952
|
+
useIsoLayoutEffect(() => {
|
|
2953
|
+
if (!notifyParentSwipeProgressChange) {
|
|
2954
|
+
return undefined;
|
|
2955
|
+
}
|
|
2956
|
+
if (!open) {
|
|
2957
|
+
notifyParentSwipeProgressChange(0);
|
|
2958
|
+
}
|
|
2959
|
+
return () => {
|
|
2960
|
+
notifyParentSwipeProgressChange(0);
|
|
2961
|
+
};
|
|
2962
|
+
}, [notifyParentSwipeProgressChange, open]);
|
|
2963
|
+
useIsoLayoutEffect(() => {
|
|
2964
|
+
if (open) {
|
|
2965
|
+
// Skip `resetSwipe` while `Drawer.SwipeArea` is driving the open: it zeroes the popup's
|
|
2966
|
+
// `--swipe-movement-*` (via `syncDragStyles(false)`), flashing it fully open for a frame.
|
|
2967
|
+
// `clearSwipeRelease` doesn't touch those vars, so always run it to clear any leftover
|
|
2968
|
+
// release state from a prior dismiss (e.g. when the popup is kept mounted).
|
|
2969
|
+
if (!swipeAreaActiveRef.current) {
|
|
2970
|
+
resetSwipe();
|
|
2971
|
+
}
|
|
2972
|
+
clearSwipeRelease();
|
|
2973
|
+
}
|
|
2974
|
+
}, [clearSwipeRelease, open, resetSwipe, swipeAreaActiveRef]);
|
|
2975
|
+
useIsoLayoutEffect(() => {
|
|
2976
|
+
const backdropElement = backdropRef.current;
|
|
2977
|
+
return () => {
|
|
2978
|
+
visualStateStore?.set({
|
|
2979
|
+
swipeProgress: 0,
|
|
2980
|
+
frontmostHeight: 0
|
|
2981
|
+
});
|
|
2982
|
+
setBackdropSwipingAttribute(backdropElement, false);
|
|
2983
|
+
// `data-swiping` is set on whichever backdrop is current when a swipe starts, which can
|
|
2984
|
+
// differ from the captured element if the backdrop mounted late or changed identity.
|
|
2985
|
+
// Reading the live ref here is intentional so the current backdrop is cleared too.
|
|
2986
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2987
|
+
const currentBackdrop = backdropRef.current;
|
|
2988
|
+
if (currentBackdrop !== backdropElement) {
|
|
2989
|
+
setBackdropSwipingAttribute(currentBackdrop, false);
|
|
2990
|
+
}
|
|
2991
|
+
finishNestedSwipe();
|
|
2992
|
+
};
|
|
2993
|
+
}, [backdropRef, finishNestedSwipe, visualStateStore]);
|
|
2994
|
+
const swipeProviderValue = React.useMemo(() => ({
|
|
2995
|
+
swiping: swipe$1.swiping,
|
|
2996
|
+
getDragStyles: swipe$1.getDragStyles,
|
|
2997
|
+
swipeStrength: swipeRelease ?? null,
|
|
2998
|
+
setSwipeDismissed
|
|
2999
|
+
}), [setSwipeDismissed, swipe$1.getDragStyles, swipe$1.swiping, swipeRelease]);
|
|
3000
|
+
function resetTouchSwipeState(ignoreSwipe) {
|
|
3001
|
+
ignoreTouchSwipeRef.current = ignoreSwipe;
|
|
3002
|
+
touchScrollStateRef.current = null;
|
|
3003
|
+
}
|
|
3004
|
+
function resetTouchTrackingState() {
|
|
3005
|
+
resetTouchSwipeState(false);
|
|
3006
|
+
lastPointerTypeRef.current = '';
|
|
3007
|
+
ignoreNextTouchStartFromPenRef.current = false;
|
|
3008
|
+
}
|
|
3009
|
+
function handlePointerEnd(event) {
|
|
3010
|
+
lastPointerTypeRef.current = '';
|
|
3011
|
+
return event.pointerType !== 'touch';
|
|
3012
|
+
}
|
|
3013
|
+
return /*#__PURE__*/jsx(DialogViewport, {
|
|
3014
|
+
ref: forwardedRef,
|
|
3015
|
+
className: className,
|
|
3016
|
+
style: style,
|
|
3017
|
+
render: render,
|
|
3018
|
+
...mergeProps(elementProps, {
|
|
3019
|
+
onPointerDown(event) {
|
|
3020
|
+
lastPointerTypeRef.current = event.pointerType;
|
|
3021
|
+
ignoreNextTouchStartFromPenRef.current = event.pointerType === 'pen';
|
|
3022
|
+
if (!open || !mounted || nestedDrawerOpen) {
|
|
3023
|
+
return;
|
|
3024
|
+
}
|
|
3025
|
+
const elementAtPoint = getElementAtPoint(event.currentTarget.getRootNode(), event.clientX, event.clientY);
|
|
3026
|
+
if (isSwipeIgnoredTarget(elementAtPoint) || isDrawerContentTarget(elementAtPoint)) {
|
|
3027
|
+
return;
|
|
3028
|
+
}
|
|
3029
|
+
if (event.pointerType === 'touch') {
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
swipePointerProps.onPointerDown?.(event);
|
|
3033
|
+
},
|
|
3034
|
+
onPointerMove(event) {
|
|
3035
|
+
if (event.pointerType === 'touch') {
|
|
3036
|
+
return;
|
|
3037
|
+
}
|
|
3038
|
+
swipePointerProps.onPointerMove?.(event);
|
|
3039
|
+
},
|
|
3040
|
+
onPointerUp(event) {
|
|
3041
|
+
if (handlePointerEnd(event)) {
|
|
3042
|
+
swipePointerProps.onPointerUp?.(event);
|
|
3043
|
+
}
|
|
3044
|
+
},
|
|
3045
|
+
onPointerCancel(event) {
|
|
3046
|
+
if (handlePointerEnd(event)) {
|
|
3047
|
+
swipePointerProps.onPointerCancel?.(event);
|
|
3048
|
+
}
|
|
3049
|
+
},
|
|
3050
|
+
onTouchStart(event) {
|
|
3051
|
+
const startedFromPenPointerDown = lastPointerTypeRef.current === 'pen' && ignoreNextTouchStartFromPenRef.current;
|
|
3052
|
+
if (startedFromPenPointerDown) {
|
|
3053
|
+
ignoreNextTouchStartFromPenRef.current = false;
|
|
3054
|
+
resetTouchSwipeState(false);
|
|
3055
|
+
return;
|
|
3056
|
+
}
|
|
3057
|
+
if (!open || !mounted || nestedDrawerOpen) {
|
|
3058
|
+
resetTouchSwipeState(false);
|
|
3059
|
+
return;
|
|
3060
|
+
}
|
|
3061
|
+
const touch = event.touches[0];
|
|
3062
|
+
if (!touch) {
|
|
3063
|
+
return;
|
|
3064
|
+
}
|
|
3065
|
+
if (isReactTouchEventOnRangeInput(event)) {
|
|
3066
|
+
resetTouchSwipeState(false);
|
|
3067
|
+
return;
|
|
3068
|
+
}
|
|
3069
|
+
const rootElement = event.currentTarget;
|
|
3070
|
+
const elementAtPoint = getElementAtPoint(rootElement.getRootNode(), touch.clientX, touch.clientY);
|
|
3071
|
+
const eventTarget = getTarget(event.nativeEvent);
|
|
3072
|
+
const target = isElement(eventTarget) ? eventTarget : rootElement;
|
|
3073
|
+
if (!contains(rootElement, target)) {
|
|
3074
|
+
resetTouchSwipeState(true);
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
virtualKeyboard?.onTouchStart(event);
|
|
3078
|
+
if (isSwipeIgnoredTarget(elementAtPoint)) {
|
|
3079
|
+
resetTouchSwipeState(true);
|
|
3080
|
+
return;
|
|
3081
|
+
}
|
|
3082
|
+
ignoreTouchSwipeRef.current = false;
|
|
3083
|
+
const scrollTarget = findScrollableTouchTarget(target, rootElement, scrollAxis);
|
|
3084
|
+
const hasCrossAxisScrollableContent = findScrollableTouchTarget(target, rootElement, crossScrollAxis) != null;
|
|
3085
|
+
let allowSwipe = null;
|
|
3086
|
+
if (scrollTarget) {
|
|
3087
|
+
const canSwipeFromEdge = isAtSwipeStartEdge(scrollTarget, scrollAxis, swipeDirection);
|
|
3088
|
+
allowSwipe = canSwipeFromEdge ? null : false;
|
|
3089
|
+
}
|
|
3090
|
+
touchScrollStateRef.current = {
|
|
3091
|
+
startX: touch.clientX,
|
|
3092
|
+
startY: touch.clientY,
|
|
3093
|
+
lastX: touch.clientX,
|
|
3094
|
+
lastY: touch.clientY,
|
|
3095
|
+
scrollTarget,
|
|
3096
|
+
hasCrossAxisScrollableContent,
|
|
3097
|
+
allowSwipe,
|
|
3098
|
+
preserveNativeCrossAxisScroll: false,
|
|
3099
|
+
drawerAxisAttributed: false
|
|
3100
|
+
};
|
|
3101
|
+
swipeTouchProps.onTouchStart?.(event);
|
|
3102
|
+
},
|
|
3103
|
+
onTouchEnd(event) {
|
|
3104
|
+
virtualKeyboard?.onTouchEnd(event);
|
|
3105
|
+
resetTouchTrackingState();
|
|
3106
|
+
swipeTouchProps.onTouchEnd?.(event);
|
|
3107
|
+
},
|
|
3108
|
+
onTouchCancel(event) {
|
|
3109
|
+
virtualKeyboard?.onTouchCancel();
|
|
3110
|
+
resetTouchTrackingState();
|
|
3111
|
+
swipeTouchProps.onTouchCancel?.(event);
|
|
3112
|
+
},
|
|
3113
|
+
// Drawer popups use drawer-specific nested state attributes.
|
|
3114
|
+
// Suppress DialogViewport's generic nested dialog attribute.
|
|
3115
|
+
['data-nested-dialog-open']: undefined
|
|
3116
|
+
}),
|
|
3117
|
+
children: /*#__PURE__*/jsx(DrawerViewportContext.Provider, {
|
|
3118
|
+
value: swipeProviderValue,
|
|
3119
|
+
children: children
|
|
3120
|
+
})
|
|
3121
|
+
});
|
|
3122
|
+
});
|
|
3123
|
+
if (process.env.NODE_ENV !== "production") DrawerViewport.displayName = "DrawerViewport";
|
|
3124
|
+
function setBackdropSwipingAttribute(backdropElement, swiping) {
|
|
3125
|
+
backdropElement?.toggleAttribute(DrawerPopupDataAttributes.swiping, swiping);
|
|
3126
|
+
}
|
|
3127
|
+
function isSwipeIgnoredTarget(target) {
|
|
3128
|
+
return Boolean(target?.closest(BASE_UI_SWIPE_IGNORE_SELECTOR));
|
|
3129
|
+
}
|
|
3130
|
+
function isDrawerContentTarget(target) {
|
|
3131
|
+
return Boolean(target?.closest(DRAWER_CONTENT_SELECTOR));
|
|
3132
|
+
}
|
|
3133
|
+
function getBaseSwipeSize(element, direction) {
|
|
3134
|
+
return direction === 'left' || direction === 'right' ? element.offsetWidth : element.offsetHeight;
|
|
3135
|
+
}
|
|
3136
|
+
function getBaseSwipeThreshold(element, direction) {
|
|
3137
|
+
return Math.max(getBaseSwipeSize(element, direction) * 0.5, MIN_SWIPE_THRESHOLD);
|
|
3138
|
+
}
|
|
3139
|
+
function isRangeInput(target, win) {
|
|
3140
|
+
return target instanceof win.HTMLInputElement && target.type === 'range';
|
|
3141
|
+
}
|
|
3142
|
+
function isTextSelectionControl(target) {
|
|
3143
|
+
return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
|
|
3144
|
+
}
|
|
3145
|
+
function hasExpandedSelectionWithinTarget(selection, target) {
|
|
3146
|
+
const anchorElement = isElement(selection.anchorNode) ? selection.anchorNode : selection.anchorNode?.parentElement;
|
|
3147
|
+
const focusElement = isElement(selection.focusNode) ? selection.focusNode : selection.focusNode?.parentElement;
|
|
3148
|
+
return selection.containsNode(target, true) || contains(target, anchorElement) || contains(target, focusElement);
|
|
3149
|
+
}
|
|
3150
|
+
function shouldIgnoreSwipeForTextSelection(doc, rootElement) {
|
|
3151
|
+
const activeEl = activeElement(doc);
|
|
3152
|
+
if (activeEl && contains(rootElement, activeEl) && isTextSelectionControl(activeEl)) {
|
|
3153
|
+
const {
|
|
3154
|
+
selectionStart,
|
|
3155
|
+
selectionEnd
|
|
3156
|
+
} = activeEl;
|
|
3157
|
+
if (selectionStart != null && selectionEnd != null && selectionStart < selectionEnd) {
|
|
3158
|
+
return true;
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
const selection = doc.getSelection?.();
|
|
3162
|
+
if (!selection || selection.isCollapsed) {
|
|
3163
|
+
return false;
|
|
3164
|
+
}
|
|
3165
|
+
return hasExpandedSelectionWithinTarget(selection, rootElement);
|
|
3166
|
+
}
|
|
3167
|
+
function isEventOnRangeInput(event, win) {
|
|
3168
|
+
return event.composedPath().some(pathTarget => isRangeInput(pathTarget, win));
|
|
3169
|
+
}
|
|
3170
|
+
function isReactTouchEventOnRangeInput(event) {
|
|
3171
|
+
return isEventOnRangeInput(event.nativeEvent, getWindow(event.currentTarget));
|
|
3172
|
+
}
|
|
3173
|
+
function updateTouchScrollPosition(touchState, touch) {
|
|
3174
|
+
touchState.lastX = touch.clientX;
|
|
3175
|
+
touchState.lastY = touch.clientY;
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
/**
|
|
3179
|
+
* Arbitrates a touchmove between the drawer swipe and a native cross-axis scroll.
|
|
3180
|
+
* Returns `true` when the move must be left alone — either because the cross axis already won the
|
|
3181
|
+
* gesture, or because neither axis has passed the slop yet and the gesture cannot be attributed.
|
|
3182
|
+
*/
|
|
3183
|
+
function shouldYieldTouchMove(touchState, event, touch, isVerticalScrollAxis) {
|
|
3184
|
+
if (touchState.preserveNativeCrossAxisScroll) {
|
|
3185
|
+
return true;
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
// Attribution happens once per gesture. Re-arbitrating after the drawer axis has won would let
|
|
3189
|
+
// the pre-attribution branches below fire mid-drag (the slop is measured from the touch origin,
|
|
3190
|
+
// which is never re-baselined), freezing the popup and dropping `preventDefault()`.
|
|
3191
|
+
if (touchState.drawerAxisAttributed || touchState.allowSwipe === true || !touchState.hasCrossAxisScrollableContent) {
|
|
3192
|
+
return false;
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
// A non-cancelable touchmove means the browser has already committed the gesture to a native
|
|
3196
|
+
// scroll; claiming it for the swipe would drag the popup alongside the scrolling content.
|
|
3197
|
+
if (!event.cancelable) {
|
|
3198
|
+
touchState.preserveNativeCrossAxisScroll = true;
|
|
3199
|
+
return true;
|
|
3200
|
+
}
|
|
3201
|
+
const drawerAxisGestureDelta = isVerticalScrollAxis ? touch.clientY - touchState.startY : touch.clientX - touchState.startX;
|
|
3202
|
+
const crossAxisGestureDelta = isVerticalScrollAxis ? touch.clientX - touchState.startX : touch.clientY - touchState.startY;
|
|
3203
|
+
const absDrawerAxisGestureDelta = Math.abs(drawerAxisGestureDelta);
|
|
3204
|
+
const absCrossAxisGestureDelta = Math.abs(crossAxisGestureDelta);
|
|
3205
|
+
if (absCrossAxisGestureDelta >= AXIS_LOCK_SLOP && absCrossAxisGestureDelta > absDrawerAxisGestureDelta + AXIS_LOCK_BIAS) {
|
|
3206
|
+
touchState.preserveNativeCrossAxisScroll = true;
|
|
3207
|
+
return true;
|
|
3208
|
+
}
|
|
3209
|
+
if (absDrawerAxisGestureDelta >= AXIS_LOCK_SLOP) {
|
|
3210
|
+
touchState.drawerAxisAttributed = true;
|
|
3211
|
+
return false;
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
// Neither axis has traveled past the slop yet, so the gesture cannot be attributed. Leave the
|
|
3215
|
+
// event alone: on iOS, `preventDefault()` on the first cancelable touchmove cancels native
|
|
3216
|
+
// scrolling for the entire gesture, which would lock a cross-axis scroll that only passes the
|
|
3217
|
+
// slop on a later move.
|
|
3218
|
+
return true;
|
|
3219
|
+
}
|
|
3220
|
+
function hasScrollableContentOnAxis(scrollTarget, axis) {
|
|
3221
|
+
return getScrollMetrics(scrollTarget, axis).max > 0;
|
|
3222
|
+
}
|
|
3223
|
+
function getScrollMetrics(scrollTarget, axis) {
|
|
3224
|
+
if (axis === 'vertical') {
|
|
3225
|
+
const max = Math.max(0, scrollTarget.scrollHeight - scrollTarget.clientHeight);
|
|
3226
|
+
return {
|
|
3227
|
+
offset: scrollTarget.scrollTop,
|
|
3228
|
+
max
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3231
|
+
const max = Math.max(0, scrollTarget.scrollWidth - scrollTarget.clientWidth);
|
|
3232
|
+
return {
|
|
3233
|
+
offset: scrollTarget.scrollLeft,
|
|
3234
|
+
max
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
function isAtSwipeStartEdge(scrollTarget, axis, direction) {
|
|
3238
|
+
const dismissFromStartEdge = shouldDismissFromStartEdge(direction, axis);
|
|
3239
|
+
const {
|
|
3240
|
+
offset,
|
|
3241
|
+
max
|
|
3242
|
+
} = getScrollMetrics(scrollTarget, axis);
|
|
3243
|
+
return dismissFromStartEdge ? offset <= 0 : offset >= max;
|
|
3244
|
+
}
|
|
3245
|
+
function canSwipeFromScrollEdgeOnMove(scrollTarget, axis, direction, delta) {
|
|
3246
|
+
const dismissFromStartEdge = shouldDismissFromStartEdge(direction, axis);
|
|
3247
|
+
const movingTowardDismiss = dismissFromStartEdge ? delta > 0 : delta < 0;
|
|
3248
|
+
if (!movingTowardDismiss) {
|
|
3249
|
+
return false;
|
|
3250
|
+
}
|
|
3251
|
+
return isAtSwipeStartEdge(scrollTarget, axis, direction);
|
|
3252
|
+
}
|
|
3253
|
+
function shouldDismissFromStartEdge(direction, axis) {
|
|
3254
|
+
return axis === 'vertical' ? direction === 'down' : direction === 'right';
|
|
3255
|
+
}
|
|
3256
|
+
|
|
3257
|
+
const ScrollAreaRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
3258
|
+
if (process.env.NODE_ENV !== "production") ScrollAreaRootContext.displayName = "ScrollAreaRootContext";
|
|
3259
|
+
function useScrollAreaRootContext() {
|
|
3260
|
+
const context = React.useContext(ScrollAreaRootContext);
|
|
3261
|
+
if (context === undefined) {
|
|
3262
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ScrollAreaRootContext is missing. ScrollArea parts must be placed within <ScrollArea.Root>.' : formatErrorMessage(53));
|
|
3263
|
+
}
|
|
3264
|
+
return context;
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
const SCROLL_TIMEOUT = 500;
|
|
3268
|
+
const MIN_THUMB_SIZE = 16;
|
|
3269
|
+
|
|
3270
|
+
function getOffset(element, prop, axis) {
|
|
3271
|
+
if (!element) {
|
|
3272
|
+
return 0;
|
|
3273
|
+
}
|
|
3274
|
+
const styles = getComputedStyle(element);
|
|
3275
|
+
const key = `${prop}${axis === 'x' ? 'Inline' : 'Block'}`;
|
|
3276
|
+
const start = parseFloat(styles[`${key}Start`]);
|
|
3277
|
+
|
|
3278
|
+
// Safari misreports `marginInlineEnd` in RTL.
|
|
3279
|
+
// We have to assume the start/end values are symmetrical, which is likely.
|
|
3280
|
+
if (axis === 'x' && prop === 'margin') {
|
|
3281
|
+
return start * 2;
|
|
3282
|
+
}
|
|
3283
|
+
return start + parseFloat(styles[`${key}End`]);
|
|
3284
|
+
}
|
|
3285
|
+
|
|
3286
|
+
// Data-attribute strings inlined so `ScrollAreaRootDataAttributes` tree-shakes out.
|
|
3287
|
+
const attr = name => value => value ? {
|
|
3288
|
+
[name]: ''
|
|
3289
|
+
} : null;
|
|
3290
|
+
const scrollAreaStateAttributesMapping = {
|
|
3291
|
+
hasOverflowX: attr('data-has-overflow-x'),
|
|
3292
|
+
hasOverflowY: attr('data-has-overflow-y'),
|
|
3293
|
+
overflowXStart: attr('data-overflow-x-start'),
|
|
3294
|
+
overflowXEnd: attr('data-overflow-x-end'),
|
|
3295
|
+
overflowYStart: attr('data-overflow-y-start'),
|
|
3296
|
+
overflowYEnd: attr('data-overflow-y-end'),
|
|
3297
|
+
cornerHidden: () => null
|
|
3298
|
+
};
|
|
3299
|
+
|
|
3300
|
+
const DEFAULT_COORDS = {
|
|
3301
|
+
x: 0,
|
|
3302
|
+
y: 0
|
|
3303
|
+
};
|
|
3304
|
+
const DEFAULT_SIZE = {
|
|
3305
|
+
width: 0,
|
|
3306
|
+
height: 0
|
|
3307
|
+
};
|
|
3308
|
+
const DEFAULT_OVERFLOW_EDGES = {
|
|
3309
|
+
xStart: false,
|
|
3310
|
+
xEnd: false,
|
|
3311
|
+
yStart: false,
|
|
3312
|
+
yEnd: false
|
|
3313
|
+
};
|
|
3314
|
+
const DEFAULT_HIDDEN_STATE = {
|
|
3315
|
+
x: true,
|
|
3316
|
+
y: true,
|
|
3317
|
+
corner: true
|
|
3318
|
+
};
|
|
3319
|
+
/**
|
|
3320
|
+
* Groups all parts of the scroll area.
|
|
3321
|
+
* Renders a `<div>` element.
|
|
3322
|
+
*
|
|
3323
|
+
* Documentation: [Base UI Scroll Area](https://base-ui.com/react/components/scroll-area)
|
|
3324
|
+
*/
|
|
3325
|
+
const ScrollAreaRoot = /*#__PURE__*/React.forwardRef(function ScrollAreaRoot(componentProps, forwardedRef) {
|
|
3326
|
+
const {
|
|
3327
|
+
render,
|
|
3328
|
+
className,
|
|
3329
|
+
overflowEdgeThreshold: overflowEdgeThresholdProp,
|
|
3330
|
+
style,
|
|
3331
|
+
...elementProps
|
|
3332
|
+
} = componentProps;
|
|
3333
|
+
const {
|
|
3334
|
+
xStart,
|
|
3335
|
+
xEnd,
|
|
3336
|
+
yStart,
|
|
3337
|
+
yEnd
|
|
3338
|
+
} = normalizeOverflowEdgeThreshold(overflowEdgeThresholdProp);
|
|
3339
|
+
const rootId = useBaseUiId();
|
|
3340
|
+
const scrollYTimeout = useTimeout();
|
|
3341
|
+
const scrollXTimeout = useTimeout();
|
|
3342
|
+
const {
|
|
3343
|
+
nonce,
|
|
3344
|
+
disableStyleElements
|
|
3345
|
+
} = useCSPContext();
|
|
3346
|
+
const [hovering, setHovering] = React.useState(false);
|
|
3347
|
+
const [scrollingX, setScrollingX] = React.useState(false);
|
|
3348
|
+
const [scrollingY, setScrollingY] = React.useState(false);
|
|
3349
|
+
const [touchModality, setTouchModality] = React.useState(false);
|
|
3350
|
+
const [hasMeasuredScrollbar, setHasMeasuredScrollbar] = React.useState(false);
|
|
3351
|
+
const [cornerSize, setCornerSize] = React.useState(DEFAULT_SIZE);
|
|
3352
|
+
const [thumbSize, setThumbSize] = React.useState(DEFAULT_SIZE);
|
|
3353
|
+
const [overflowEdges, setOverflowEdges] = React.useState(DEFAULT_OVERFLOW_EDGES);
|
|
3354
|
+
const [hiddenState, setHiddenState] = React.useState(DEFAULT_HIDDEN_STATE);
|
|
3355
|
+
const rootRef = React.useRef(null);
|
|
3356
|
+
const viewportRef = React.useRef(null);
|
|
3357
|
+
const scrollbarYRef = React.useRef(null);
|
|
3358
|
+
const scrollbarXRef = React.useRef(null);
|
|
3359
|
+
const thumbYRef = React.useRef(null);
|
|
3360
|
+
const thumbXRef = React.useRef(null);
|
|
3361
|
+
const cornerRef = React.useRef(null);
|
|
3362
|
+
const activePointerIdRef = React.useRef(null);
|
|
3363
|
+
const startYRef = React.useRef(0);
|
|
3364
|
+
const startXRef = React.useRef(0);
|
|
3365
|
+
const startScrollTopRef = React.useRef(0);
|
|
3366
|
+
const startScrollLeftRef = React.useRef(0);
|
|
3367
|
+
const currentOrientationRef = React.useRef('vertical');
|
|
3368
|
+
const scrollPositionRef = React.useRef(DEFAULT_COORDS);
|
|
3369
|
+
const savedSnapTypeRef = React.useRef(null);
|
|
3370
|
+
function startScrolling(vertical) {
|
|
3371
|
+
const setScrolling = vertical ? setScrollingY : setScrollingX;
|
|
3372
|
+
const timeout = vertical ? scrollYTimeout : scrollXTimeout;
|
|
3373
|
+
setScrolling(true);
|
|
3374
|
+
timeout.start(SCROLL_TIMEOUT, () => {
|
|
3375
|
+
setScrolling(false);
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
const handleScroll = useStableCallback(scrollPosition => {
|
|
3379
|
+
const offsetX = scrollPosition.x - scrollPositionRef.current.x;
|
|
3380
|
+
const offsetY = scrollPosition.y - scrollPositionRef.current.y;
|
|
3381
|
+
scrollPositionRef.current = scrollPosition;
|
|
3382
|
+
if (offsetY !== 0) {
|
|
3383
|
+
startScrolling(true);
|
|
3384
|
+
}
|
|
3385
|
+
if (offsetX !== 0) {
|
|
3386
|
+
startScrolling(false);
|
|
3387
|
+
}
|
|
3388
|
+
});
|
|
3389
|
+
|
|
3390
|
+
// CSS scroll snap forces every programmatic scroll to land on a snap
|
|
3391
|
+
// point, making thumb dragging jump between snap points. Native
|
|
3392
|
+
// scrollbars suppress snapping while dragging, so disable it until the
|
|
3393
|
+
// pointer is released; restoring the value re-snaps the viewport. The
|
|
3394
|
+
// save is guarded so a second pointer during an active drag can't
|
|
3395
|
+
// clobber the saved value with `none`.
|
|
3396
|
+
const disableViewportSnap = useStableCallback(() => {
|
|
3397
|
+
const viewportEl = viewportRef.current;
|
|
3398
|
+
if (viewportEl && savedSnapTypeRef.current === null) {
|
|
3399
|
+
savedSnapTypeRef.current = viewportEl.style.scrollSnapType;
|
|
3400
|
+
viewportEl.style.scrollSnapType = 'none';
|
|
3401
|
+
}
|
|
3402
|
+
});
|
|
3403
|
+
const handlePointerDown = useStableCallback(event => {
|
|
3404
|
+
if (event.button !== 0) {
|
|
3405
|
+
return;
|
|
3406
|
+
}
|
|
3407
|
+
if (activePointerIdRef.current !== null) {
|
|
3408
|
+
const activeThumb = currentOrientationRef.current === 'vertical' ? thumbYRef.current : thumbXRef.current;
|
|
3409
|
+
// A live drag holds capture for the active pointer — ignore other pointers.
|
|
3410
|
+
// No capture means the release went missing entirely (silent capture drop
|
|
3411
|
+
// with an id that never reappears, e.g. a lost touch contact), so let the
|
|
3412
|
+
// new pointer take over the latch instead of leaving dragging dead.
|
|
3413
|
+
if (activeThumb?.hasPointerCapture(activePointerIdRef.current)) {
|
|
3414
|
+
return;
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
activePointerIdRef.current = event.pointerId;
|
|
3418
|
+
startYRef.current = event.clientY;
|
|
3419
|
+
startXRef.current = event.clientX;
|
|
3420
|
+
// Literal instead of `ScrollAreaScrollbarDataAttributes.orientation`: referencing an
|
|
3421
|
+
// enum member retains its whole object in the bundle, so the strings are inlined and
|
|
3422
|
+
// the enums kept for docs only.
|
|
3423
|
+
currentOrientationRef.current = event.currentTarget.getAttribute('data-orientation');
|
|
3424
|
+
const viewportEl = viewportRef.current;
|
|
3425
|
+
if (viewportEl) {
|
|
3426
|
+
startScrollTopRef.current = viewportEl.scrollTop;
|
|
3427
|
+
startScrollLeftRef.current = viewportEl.scrollLeft;
|
|
3428
|
+
disableViewportSnap();
|
|
3429
|
+
}
|
|
3430
|
+
const thumb = currentOrientationRef.current === 'vertical' ? thumbYRef.current : thumbXRef.current;
|
|
3431
|
+
thumb?.setPointerCapture(event.pointerId);
|
|
3432
|
+
});
|
|
3433
|
+
const handlePointerUp = useStableCallback(event => {
|
|
3434
|
+
if (event.pointerId !== activePointerIdRef.current) {
|
|
3435
|
+
return;
|
|
3436
|
+
}
|
|
3437
|
+
activePointerIdRef.current = null;
|
|
3438
|
+
// Clear the drag's scrolling state immediately rather than waiting for the
|
|
3439
|
+
// `SCROLL_TIMEOUT` timer armed by the last drag move, so every release path
|
|
3440
|
+
// (real, `pointercancel`, or the missed-release fallback) behaves the same.
|
|
3441
|
+
(currentOrientationRef.current === 'vertical' ? setScrollingY : setScrollingX)(false);
|
|
3442
|
+
if (savedSnapTypeRef.current !== null) {
|
|
3443
|
+
if (viewportRef.current) {
|
|
3444
|
+
viewportRef.current.style.scrollSnapType = savedSnapTypeRef.current;
|
|
3445
|
+
}
|
|
3446
|
+
savedSnapTypeRef.current = null;
|
|
3447
|
+
}
|
|
3448
|
+
const thumb = currentOrientationRef.current === 'vertical' ? thumbYRef.current : thumbXRef.current;
|
|
3449
|
+
// `pointercancel` releases capture implicitly, so guard against releasing a
|
|
3450
|
+
// capture we no longer hold (which would throw).
|
|
3451
|
+
if (thumb?.hasPointerCapture(event.pointerId)) {
|
|
3452
|
+
thumb.releasePointerCapture(event.pointerId);
|
|
3453
|
+
}
|
|
3454
|
+
});
|
|
3455
|
+
const handlePointerMove = useStableCallback(event => {
|
|
3456
|
+
if (event.pointerId !== activePointerIdRef.current) {
|
|
3457
|
+
return;
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
// The release can go missing entirely (e.g. the browser drops pointer
|
|
3461
|
+
// capture while the scrollbar is hidden mid-drag), leaving the drag
|
|
3462
|
+
// latched so a buttonless hover over the thumb scrolls the viewport.
|
|
3463
|
+
// Treat a move without the primary button held (`buttons` bit 1 unset)
|
|
3464
|
+
// as the missed release.
|
|
3465
|
+
if (event.buttons % 2 === 0) {
|
|
3466
|
+
handlePointerUp(event);
|
|
3467
|
+
return;
|
|
3468
|
+
}
|
|
3469
|
+
const viewportEl = viewportRef.current;
|
|
3470
|
+
if (!viewportEl) {
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const vertical = currentOrientationRef.current === 'vertical';
|
|
3474
|
+
const thumbEl = vertical ? thumbYRef.current : thumbXRef.current;
|
|
3475
|
+
const scrollbarEl = vertical ? scrollbarYRef.current : scrollbarXRef.current;
|
|
3476
|
+
if (!thumbEl || !scrollbarEl) {
|
|
3477
|
+
return;
|
|
3478
|
+
}
|
|
3479
|
+
const axis = vertical ? 'y' : 'x';
|
|
3480
|
+
const scrollbarOffset = getOffset(scrollbarEl, 'padding', axis);
|
|
3481
|
+
const thumbOffset = getOffset(thumbEl, 'margin', axis);
|
|
3482
|
+
const thumbSizePx = vertical ? thumbEl.offsetHeight : thumbEl.offsetWidth;
|
|
3483
|
+
const trackSize = vertical ? scrollbarEl.offsetHeight : scrollbarEl.offsetWidth;
|
|
3484
|
+
const maxThumbOffset = trackSize - thumbSizePx - scrollbarOffset - thumbOffset;
|
|
3485
|
+
// A short or heavily padded track can drive `maxThumbOffset` to zero or
|
|
3486
|
+
// negative once the thumb hits its `MIN_THUMB_SIZE` floor. Dividing by it
|
|
3487
|
+
// would yield a non-finite (`Infinity`/`NaN`) or inverted scroll position.
|
|
3488
|
+
const delta = vertical ? event.clientY - startYRef.current : event.clientX - startXRef.current;
|
|
3489
|
+
const scrollRatio = maxThumbOffset <= 0 ? 0 : delta / maxThumbOffset;
|
|
3490
|
+
const scrollableSize = vertical ? viewportEl.scrollHeight : viewportEl.scrollWidth;
|
|
3491
|
+
const viewportSize = vertical ? viewportEl.clientHeight : viewportEl.clientWidth;
|
|
3492
|
+
const startScroll = vertical ? startScrollTopRef.current : startScrollLeftRef.current;
|
|
3493
|
+
const nextScroll = startScroll + scrollRatio * (scrollableSize - viewportSize);
|
|
3494
|
+
if (vertical) {
|
|
3495
|
+
viewportEl.scrollTop = nextScroll;
|
|
3496
|
+
} else {
|
|
3497
|
+
viewportEl.scrollLeft = nextScroll;
|
|
3498
|
+
}
|
|
3499
|
+
event.preventDefault();
|
|
3500
|
+
startScrolling(vertical);
|
|
3501
|
+
});
|
|
3502
|
+
function handleTouchModalityChange(event) {
|
|
3503
|
+
setTouchModality(event.pointerType === 'touch');
|
|
3504
|
+
}
|
|
3505
|
+
function handlePointerEnterOrMove(event) {
|
|
3506
|
+
handleTouchModalityChange(event);
|
|
3507
|
+
if (event.pointerType !== 'touch') {
|
|
3508
|
+
const isTargetRootChild = contains(rootRef.current, event.target);
|
|
3509
|
+
setHovering(isTargetRootChild);
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
const state = React.useMemo(() => ({
|
|
3513
|
+
scrolling: scrollingX || scrollingY,
|
|
3514
|
+
hasOverflowX: !hiddenState.x,
|
|
3515
|
+
hasOverflowY: !hiddenState.y,
|
|
3516
|
+
overflowXStart: overflowEdges.xStart,
|
|
3517
|
+
overflowXEnd: overflowEdges.xEnd,
|
|
3518
|
+
overflowYStart: overflowEdges.yStart,
|
|
3519
|
+
overflowYEnd: overflowEdges.yEnd,
|
|
3520
|
+
cornerHidden: hiddenState.corner
|
|
3521
|
+
}), [scrollingX, scrollingY, hiddenState.x, hiddenState.y, hiddenState.corner, overflowEdges]);
|
|
3522
|
+
const props = {
|
|
3523
|
+
role: 'presentation',
|
|
3524
|
+
onPointerEnter: handlePointerEnterOrMove,
|
|
3525
|
+
onPointerMove: handlePointerEnterOrMove,
|
|
3526
|
+
onPointerDown: handleTouchModalityChange,
|
|
3527
|
+
onPointerLeave() {
|
|
3528
|
+
setHovering(false);
|
|
3529
|
+
},
|
|
3530
|
+
style: {
|
|
3531
|
+
position: 'relative',
|
|
3532
|
+
['--scroll-area-corner-height']: `${cornerSize.height}px`,
|
|
3533
|
+
['--scroll-area-corner-width']: `${cornerSize.width}px`
|
|
3534
|
+
}
|
|
3535
|
+
};
|
|
3536
|
+
const element = useRenderElement('div', componentProps, {
|
|
3537
|
+
state,
|
|
3538
|
+
ref: [forwardedRef, rootRef],
|
|
3539
|
+
props: [props, elementProps],
|
|
3540
|
+
stateAttributesMapping: scrollAreaStateAttributesMapping
|
|
3541
|
+
});
|
|
3542
|
+
const contextValue = React.useMemo(() => ({
|
|
3543
|
+
handlePointerDown,
|
|
3544
|
+
handlePointerMove,
|
|
3545
|
+
handlePointerUp,
|
|
3546
|
+
handleScroll,
|
|
3547
|
+
disableViewportSnap,
|
|
3548
|
+
cornerSize,
|
|
3549
|
+
setCornerSize,
|
|
3550
|
+
thumbSize,
|
|
3551
|
+
setThumbSize,
|
|
3552
|
+
hasMeasuredScrollbar,
|
|
3553
|
+
setHasMeasuredScrollbar,
|
|
3554
|
+
touchModality,
|
|
3555
|
+
cornerRef,
|
|
3556
|
+
scrollingX,
|
|
3557
|
+
scrollingY,
|
|
3558
|
+
hovering,
|
|
3559
|
+
setHovering,
|
|
3560
|
+
viewportRef,
|
|
3561
|
+
scrollbarYRef,
|
|
3562
|
+
scrollbarXRef,
|
|
3563
|
+
thumbYRef,
|
|
3564
|
+
thumbXRef,
|
|
3565
|
+
rootId,
|
|
3566
|
+
hiddenState,
|
|
3567
|
+
setHiddenState,
|
|
3568
|
+
overflowEdges,
|
|
3569
|
+
setOverflowEdges,
|
|
3570
|
+
viewportState: state,
|
|
3571
|
+
overflowEdgeThreshold: {
|
|
3572
|
+
xStart,
|
|
3573
|
+
xEnd,
|
|
3574
|
+
yStart,
|
|
3575
|
+
yEnd
|
|
3576
|
+
}
|
|
3577
|
+
}), [handlePointerDown, handlePointerMove, handlePointerUp, handleScroll, disableViewportSnap, cornerSize, thumbSize, hasMeasuredScrollbar, touchModality, scrollingX, scrollingY, hovering, rootId, hiddenState, overflowEdges, state, xStart, xEnd, yStart, yEnd]);
|
|
3578
|
+
return /*#__PURE__*/jsxs(ScrollAreaRootContext.Provider, {
|
|
3579
|
+
value: contextValue,
|
|
3580
|
+
children: [!disableStyleElements && styleDisableScrollbar.getElement(nonce), element]
|
|
3581
|
+
});
|
|
3582
|
+
});
|
|
3583
|
+
if (process.env.NODE_ENV !== "production") ScrollAreaRoot.displayName = "ScrollAreaRoot";
|
|
3584
|
+
function normalizeOverflowEdgeThreshold(threshold) {
|
|
3585
|
+
const thresholds = typeof threshold === 'number' ? {
|
|
3586
|
+
xStart: threshold,
|
|
3587
|
+
xEnd: threshold,
|
|
3588
|
+
yStart: threshold,
|
|
3589
|
+
yEnd: threshold
|
|
3590
|
+
} : threshold;
|
|
3591
|
+
return {
|
|
3592
|
+
xStart: Math.max(0, thresholds?.xStart || 0),
|
|
3593
|
+
xEnd: Math.max(0, thresholds?.xEnd || 0),
|
|
3594
|
+
yStart: Math.max(0, thresholds?.yStart || 0),
|
|
3595
|
+
yEnd: Math.max(0, thresholds?.yEnd || 0)
|
|
3596
|
+
};
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
const ScrollAreaViewportContext = /*#__PURE__*/React.createContext(undefined);
|
|
3600
|
+
if (process.env.NODE_ENV !== "production") ScrollAreaViewportContext.displayName = "ScrollAreaViewportContext";
|
|
3601
|
+
function useScrollAreaViewportContext() {
|
|
3602
|
+
const context = React.useContext(ScrollAreaViewportContext);
|
|
3603
|
+
if (context === undefined) {
|
|
3604
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ScrollAreaViewportContext missing. ScrollAreaViewport parts must be placed within <ScrollArea.Viewport>.' : formatErrorMessage(55));
|
|
3605
|
+
}
|
|
3606
|
+
return context;
|
|
3607
|
+
}
|
|
3608
|
+
|
|
3609
|
+
const OVERFLOW_EDGE_VARS = ['--scroll-area-overflow-x-start', '--scroll-area-overflow-x-end', '--scroll-area-overflow-y-start', '--scroll-area-overflow-y-end'];
|
|
3610
|
+
|
|
3611
|
+
// Module-level flag to ensure we only register the CSS properties once,
|
|
3612
|
+
// regardless of how many Scroll Area components are mounted.
|
|
3613
|
+
let scrollAreaOverflowVarsRegistered = false;
|
|
3614
|
+
|
|
3615
|
+
/**
|
|
3616
|
+
* Removes inheritance of the scroll area overflow CSS variables, which
|
|
3617
|
+
* improves rendering performance in complex scroll areas with deep subtrees.
|
|
3618
|
+
* Instead, each child must manually opt-in to using these properties by
|
|
3619
|
+
* specifying `inherit`.
|
|
3620
|
+
* See https://motion.dev/blog/web-animation-performance-tier-list
|
|
3621
|
+
* under the "Improving CSS variable performance" section.
|
|
3622
|
+
*/
|
|
3623
|
+
function removeCSSVariableInheritance() {
|
|
3624
|
+
if (scrollAreaOverflowVarsRegistered ||
|
|
3625
|
+
// When `inherits: false`, specifying `inherit` on child elements doesn't work
|
|
3626
|
+
// in Safari. To let CSS features work correctly, this optimization must be skipped.
|
|
3627
|
+
webkit) {
|
|
3628
|
+
return;
|
|
3629
|
+
}
|
|
3630
|
+
if (typeof CSS !== 'undefined' && 'registerProperty' in CSS) {
|
|
3631
|
+
OVERFLOW_EDGE_VARS.forEach(name => {
|
|
3632
|
+
try {
|
|
3633
|
+
CSS.registerProperty({
|
|
3634
|
+
name,
|
|
3635
|
+
syntax: '<length>',
|
|
3636
|
+
inherits: false,
|
|
3637
|
+
initialValue: '0px'
|
|
3638
|
+
});
|
|
3639
|
+
} catch {
|
|
3640
|
+
/* ignore already-registered */
|
|
3641
|
+
}
|
|
3642
|
+
});
|
|
3643
|
+
}
|
|
3644
|
+
scrollAreaOverflowVarsRegistered = true;
|
|
3645
|
+
}
|
|
3646
|
+
|
|
3647
|
+
/**
|
|
3648
|
+
* The actual scrollable container of the scroll area.
|
|
3649
|
+
* Renders a `<div>` element.
|
|
3650
|
+
*
|
|
3651
|
+
* Documentation: [Base UI Scroll Area](https://base-ui.com/react/components/scroll-area)
|
|
3652
|
+
*/
|
|
3653
|
+
const ScrollAreaViewport = /*#__PURE__*/React.forwardRef(function ScrollAreaViewport(componentProps, forwardedRef) {
|
|
3654
|
+
const {
|
|
3655
|
+
render,
|
|
3656
|
+
className,
|
|
3657
|
+
style,
|
|
3658
|
+
...elementProps
|
|
3659
|
+
} = componentProps;
|
|
3660
|
+
const {
|
|
3661
|
+
viewportRef,
|
|
3662
|
+
scrollbarYRef,
|
|
3663
|
+
scrollbarXRef,
|
|
3664
|
+
thumbYRef,
|
|
3665
|
+
thumbXRef,
|
|
3666
|
+
cornerRef,
|
|
3667
|
+
cornerSize,
|
|
3668
|
+
setCornerSize,
|
|
3669
|
+
setThumbSize,
|
|
3670
|
+
rootId,
|
|
3671
|
+
setHiddenState,
|
|
3672
|
+
hiddenState,
|
|
3673
|
+
setHasMeasuredScrollbar,
|
|
3674
|
+
handleScroll,
|
|
3675
|
+
touchModality,
|
|
3676
|
+
setHovering,
|
|
3677
|
+
setOverflowEdges,
|
|
3678
|
+
overflowEdgeThreshold,
|
|
3679
|
+
viewportState
|
|
3680
|
+
} = useScrollAreaRootContext();
|
|
3681
|
+
const direction = useDirection();
|
|
3682
|
+
const programmaticScrollRef = React.useRef(true);
|
|
3683
|
+
const lastMeasuredViewportMetricsRef = React.useRef([NaN, NaN, NaN, NaN]);
|
|
3684
|
+
const scrollEndTimeout = useTimeout();
|
|
3685
|
+
const waitForAnimationsTimeout = useTimeout();
|
|
3686
|
+
const computeThumbPosition = useStableCallback(() => {
|
|
3687
|
+
const viewportEl = viewportRef.current;
|
|
3688
|
+
const scrollbarYEl = scrollbarYRef.current;
|
|
3689
|
+
const scrollbarXEl = scrollbarXRef.current;
|
|
3690
|
+
const thumbYEl = thumbYRef.current;
|
|
3691
|
+
const thumbXEl = thumbXRef.current;
|
|
3692
|
+
const cornerEl = cornerRef.current;
|
|
3693
|
+
if (!viewportEl) {
|
|
3694
|
+
return;
|
|
3695
|
+
}
|
|
3696
|
+
const scrollableContentHeight = viewportEl.scrollHeight;
|
|
3697
|
+
const scrollableContentWidth = viewportEl.scrollWidth;
|
|
3698
|
+
const viewportHeight = viewportEl.clientHeight;
|
|
3699
|
+
const viewportWidth = viewportEl.clientWidth;
|
|
3700
|
+
const scrollTop = viewportEl.scrollTop;
|
|
3701
|
+
const scrollLeft = viewportEl.scrollLeft;
|
|
3702
|
+
const lastMeasuredViewportMetrics = lastMeasuredViewportMetricsRef.current;
|
|
3703
|
+
const isFirstMeasurement = Number.isNaN(lastMeasuredViewportMetrics[0]);
|
|
3704
|
+
lastMeasuredViewportMetrics[0] = viewportHeight;
|
|
3705
|
+
lastMeasuredViewportMetrics[1] = scrollableContentHeight;
|
|
3706
|
+
lastMeasuredViewportMetrics[2] = viewportWidth;
|
|
3707
|
+
lastMeasuredViewportMetrics[3] = scrollableContentWidth;
|
|
3708
|
+
if (isFirstMeasurement) {
|
|
3709
|
+
setHasMeasuredScrollbar(true);
|
|
3710
|
+
}
|
|
3711
|
+
if (scrollableContentHeight === 0 || scrollableContentWidth === 0) {
|
|
3712
|
+
return;
|
|
3713
|
+
}
|
|
3714
|
+
const nextHiddenState = getHiddenState(viewportEl);
|
|
3715
|
+
const scrollbarYHidden = nextHiddenState.y;
|
|
3716
|
+
const scrollbarXHidden = nextHiddenState.x;
|
|
3717
|
+
const ratioX = viewportWidth / scrollableContentWidth;
|
|
3718
|
+
const ratioY = viewportHeight / scrollableContentHeight;
|
|
3719
|
+
const maxScrollLeft = Math.max(0, scrollableContentWidth - viewportWidth);
|
|
3720
|
+
const maxScrollTop = Math.max(0, scrollableContentHeight - viewportHeight);
|
|
3721
|
+
let scrollLeftFromStart = 0;
|
|
3722
|
+
let scrollLeftFromEnd = 0;
|
|
3723
|
+
if (!scrollbarXHidden) {
|
|
3724
|
+
// `normalizeScrollOffset` clamps internally.
|
|
3725
|
+
scrollLeftFromStart = normalizeScrollOffset(direction === 'rtl' ? -scrollLeft : scrollLeft, maxScrollLeft);
|
|
3726
|
+
scrollLeftFromEnd = maxScrollLeft - scrollLeftFromStart;
|
|
3727
|
+
}
|
|
3728
|
+
const scrollTopFromStart = scrollbarYHidden ? 0 : normalizeScrollOffset(scrollTop, maxScrollTop);
|
|
3729
|
+
const scrollTopFromEnd = scrollbarYHidden ? 0 : maxScrollTop - scrollTopFromStart;
|
|
3730
|
+
const nextWidth = scrollbarXHidden ? 0 : viewportWidth;
|
|
3731
|
+
const nextHeight = scrollbarYHidden ? 0 : viewportHeight;
|
|
3732
|
+
let nextCornerWidth = 0;
|
|
3733
|
+
let nextCornerHeight = 0;
|
|
3734
|
+
if (!scrollbarXHidden && !scrollbarYHidden) {
|
|
3735
|
+
nextCornerWidth = scrollbarYEl?.offsetWidth || 0;
|
|
3736
|
+
nextCornerHeight = scrollbarXEl?.offsetHeight || 0;
|
|
3737
|
+
}
|
|
3738
|
+
|
|
3739
|
+
// Only subtract corner size from scrollbar dimensions if the corner hasn't been sized yet.
|
|
3740
|
+
// Once sized, the layout will already account for it.
|
|
3741
|
+
const cornerNotYetSized = cornerSize.width === 0 && cornerSize.height === 0;
|
|
3742
|
+
const cornerWidthOffset = cornerNotYetSized ? nextCornerWidth : 0;
|
|
3743
|
+
const cornerHeightOffset = cornerNotYetSized ? nextCornerHeight : 0;
|
|
3744
|
+
const scrollbarXOffset = getOffset(scrollbarXEl, 'padding', 'x');
|
|
3745
|
+
const scrollbarYOffset = getOffset(scrollbarYEl, 'padding', 'y');
|
|
3746
|
+
const thumbXOffset = getOffset(thumbXEl, 'margin', 'x');
|
|
3747
|
+
const thumbYOffset = getOffset(thumbYEl, 'margin', 'y');
|
|
3748
|
+
const idealNextWidth = nextWidth - scrollbarXOffset - thumbXOffset;
|
|
3749
|
+
const idealNextHeight = nextHeight - scrollbarYOffset - thumbYOffset;
|
|
3750
|
+
const maxNextWidth = scrollbarXEl ? Math.min(scrollbarXEl.offsetWidth - cornerWidthOffset, idealNextWidth) : idealNextWidth;
|
|
3751
|
+
const maxNextHeight = scrollbarYEl ? Math.min(scrollbarYEl.offsetHeight - cornerHeightOffset, idealNextHeight) : idealNextHeight;
|
|
3752
|
+
const clampedNextWidth = Math.max(MIN_THUMB_SIZE, maxNextWidth * ratioX);
|
|
3753
|
+
const clampedNextHeight = Math.max(MIN_THUMB_SIZE, maxNextHeight * ratioY);
|
|
3754
|
+
setThumbSize(prevSize => pickState(prevSize, {
|
|
3755
|
+
width: clampedNextWidth,
|
|
3756
|
+
height: clampedNextHeight
|
|
3757
|
+
}));
|
|
3758
|
+
|
|
3759
|
+
// Handle Y (vertical) scroll
|
|
3760
|
+
if (scrollbarYEl && thumbYEl) {
|
|
3761
|
+
const maxThumbOffsetY = scrollbarYEl.offsetHeight - clampedNextHeight - scrollbarYOffset - thumbYOffset;
|
|
3762
|
+
const thumbOffsetY = applyOverscrollThumb(thumbYEl, '--scroll-area-thumb-height', scrollTop, maxScrollTop, scrollableContentHeight, clampedNextHeight, maxThumbOffsetY);
|
|
3763
|
+
thumbYEl.style.transform = `translate3d(0,${thumbOffsetY}px,0)`;
|
|
3764
|
+
}
|
|
3765
|
+
|
|
3766
|
+
// Handle X (horizontal) scroll
|
|
3767
|
+
if (scrollbarXEl && thumbXEl) {
|
|
3768
|
+
const maxThumbOffsetX = scrollbarXEl.offsetWidth - clampedNextWidth - scrollbarXOffset - thumbXOffset;
|
|
3769
|
+
// RTL scrolls from 0 down to `-maxScrollLeft`; measure from the inline start edge so the
|
|
3770
|
+
// overscroll math is direction-agnostic, then flip the resulting offset back below.
|
|
3771
|
+
const scrollFromStart = direction === 'rtl' ? -scrollLeft : scrollLeft;
|
|
3772
|
+
const offsetX = applyOverscrollThumb(thumbXEl, '--scroll-area-thumb-width', scrollFromStart, maxScrollLeft, scrollableContentWidth, clampedNextWidth, maxThumbOffsetX);
|
|
3773
|
+
thumbXEl.style.transform = `translate3d(${direction === 'rtl' ? -offsetX : offsetX}px,0,0)`;
|
|
3774
|
+
}
|
|
3775
|
+
const overflowMetricsPx = [scrollLeftFromStart, scrollLeftFromEnd, scrollTopFromStart, scrollTopFromEnd];
|
|
3776
|
+
OVERFLOW_EDGE_VARS.forEach((cssVar, index) => {
|
|
3777
|
+
viewportEl.style.setProperty(cssVar, `${overflowMetricsPx[index]}px`);
|
|
3778
|
+
});
|
|
3779
|
+
if (cornerEl) {
|
|
3780
|
+
// Bail when the size is unchanged (like `setThumbSize` above); otherwise a
|
|
3781
|
+
// fresh object literal on every scroll frame rebuilds the root context and
|
|
3782
|
+
// re-renders every scroll-area part.
|
|
3783
|
+
// `nextCornerWidth`/`nextCornerHeight` stay 0 when either scrollbar is hidden.
|
|
3784
|
+
setCornerSize(prevSize => pickState(prevSize, {
|
|
3785
|
+
width: nextCornerWidth,
|
|
3786
|
+
height: nextCornerHeight
|
|
3787
|
+
}));
|
|
3788
|
+
}
|
|
3789
|
+
setHiddenState(prevState => pickState(prevState, nextHiddenState));
|
|
3790
|
+
const nextOverflowEdges = {
|
|
3791
|
+
xStart: !scrollbarXHidden && scrollLeftFromStart > overflowEdgeThreshold.xStart,
|
|
3792
|
+
xEnd: !scrollbarXHidden && scrollLeftFromEnd > overflowEdgeThreshold.xEnd,
|
|
3793
|
+
yStart: !scrollbarYHidden && scrollTopFromStart > overflowEdgeThreshold.yStart,
|
|
3794
|
+
yEnd: !scrollbarYHidden && scrollTopFromEnd > overflowEdgeThreshold.yEnd
|
|
3795
|
+
};
|
|
3796
|
+
setOverflowEdges(prev => pickState(prev, nextOverflowEdges));
|
|
3797
|
+
});
|
|
3798
|
+
useIsoLayoutEffect(() => {
|
|
3799
|
+
removeCSSVariableInheritance();
|
|
3800
|
+
}, []);
|
|
3801
|
+
useIsoLayoutEffect(() => {
|
|
3802
|
+
// Wait for scrollbar and thumb refs after hidden-state toggles, refresh math on direction
|
|
3803
|
+
// flips, and re-evaluate overflow edges when the threshold changes.
|
|
3804
|
+
queueMicrotask(computeThumbPosition);
|
|
3805
|
+
}, [computeThumbPosition, hiddenState, direction, overflowEdgeThreshold.xStart, overflowEdgeThreshold.xEnd, overflowEdgeThreshold.yStart, overflowEdgeThreshold.yEnd]);
|
|
3806
|
+
useIsoLayoutEffect(() => {
|
|
3807
|
+
// `onMouseEnter` doesn't fire upon load, so we need to check if the viewport is already
|
|
3808
|
+
// being hovered.
|
|
3809
|
+
if (viewportRef.current?.matches(':hover')) {
|
|
3810
|
+
setHovering(true);
|
|
3811
|
+
}
|
|
3812
|
+
}, [viewportRef, setHovering]);
|
|
3813
|
+
useIsoLayoutEffect(() => {
|
|
3814
|
+
const viewport = viewportRef.current;
|
|
3815
|
+
if (typeof ResizeObserver === 'undefined' || !viewport) {
|
|
3816
|
+
return undefined;
|
|
3817
|
+
}
|
|
3818
|
+
let hasInitialized = false;
|
|
3819
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
3820
|
+
// Avoid duplicate mount-time recompute when observer data matches what the mount
|
|
3821
|
+
// scheduling pass already measured. If dimensions changed before the first observer
|
|
3822
|
+
// delivery, keep the recompute so overflow transitions stay in sync.
|
|
3823
|
+
if (!hasInitialized) {
|
|
3824
|
+
hasInitialized = true;
|
|
3825
|
+
const lastMeasuredViewportMetrics = lastMeasuredViewportMetricsRef.current;
|
|
3826
|
+
if (lastMeasuredViewportMetrics[0] === viewport.clientHeight && lastMeasuredViewportMetrics[1] === viewport.scrollHeight && lastMeasuredViewportMetrics[2] === viewport.clientWidth && lastMeasuredViewportMetrics[3] === viewport.scrollWidth) {
|
|
3827
|
+
return;
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
computeThumbPosition();
|
|
3831
|
+
});
|
|
3832
|
+
resizeObserver.observe(viewport);
|
|
3833
|
+
|
|
3834
|
+
// Wait for subtree animations to finish, then recompute thumb geometry that
|
|
3835
|
+
// may have been affected by transform-based animations.
|
|
3836
|
+
waitForAnimationsTimeout.start(0, () => {
|
|
3837
|
+
const animations = viewport.getAnimations({
|
|
3838
|
+
subtree: true
|
|
3839
|
+
});
|
|
3840
|
+
if (animations.length === 0) {
|
|
3841
|
+
return;
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
// `allSettled` never rejects, but `computeThumbPosition` can still run against a
|
|
3845
|
+
// torn-down tree once the animations resolve. Swallow instead of leaking an unhandled
|
|
3846
|
+
// rejection; `void` alone would only silence the floating-promise lint.
|
|
3847
|
+
Promise.allSettled(animations.map(animation => animation.finished)).then(computeThumbPosition).catch(() => {});
|
|
3848
|
+
});
|
|
3849
|
+
return () => {
|
|
3850
|
+
resizeObserver.disconnect();
|
|
3851
|
+
waitForAnimationsTimeout.clear();
|
|
3852
|
+
};
|
|
3853
|
+
}, [computeThumbPosition, viewportRef, waitForAnimationsTimeout]);
|
|
3854
|
+
function handleUserInteraction() {
|
|
3855
|
+
programmaticScrollRef.current = false;
|
|
3856
|
+
}
|
|
3857
|
+
const props = {
|
|
3858
|
+
role: 'presentation',
|
|
3859
|
+
...(rootId && {
|
|
3860
|
+
'data-id': `${rootId}-viewport`
|
|
3861
|
+
}),
|
|
3862
|
+
// https://accessibilityinsights.io/info-examples/web/scrollable-region-focusable/
|
|
3863
|
+
// Keep non-scrollable viewports out of tab order.
|
|
3864
|
+
tabIndex: hiddenState.x && hiddenState.y ? -1 : 0,
|
|
3865
|
+
className: styleDisableScrollbar.className,
|
|
3866
|
+
style: {
|
|
3867
|
+
overflow: 'scroll'
|
|
3868
|
+
},
|
|
3869
|
+
onScroll() {
|
|
3870
|
+
if (!viewportRef.current) {
|
|
3871
|
+
return;
|
|
3872
|
+
}
|
|
3873
|
+
computeThumbPosition();
|
|
3874
|
+
|
|
3875
|
+
// WebKit consumes a touch that catches an in-flight momentum scroll or
|
|
3876
|
+
// rubber-band bounce without dispatching any DOM events for the whole
|
|
3877
|
+
// gesture (not even `touchstart`), so scrolls cannot be attributed to
|
|
3878
|
+
// the user through events. Treat every scroll in touch modality as
|
|
3879
|
+
// user-driven instead.
|
|
3880
|
+
if (touchModality || !programmaticScrollRef.current) {
|
|
3881
|
+
handleScroll({
|
|
3882
|
+
x: viewportRef.current.scrollLeft,
|
|
3883
|
+
y: viewportRef.current.scrollTop
|
|
3884
|
+
});
|
|
3885
|
+
}
|
|
3886
|
+
|
|
3887
|
+
// Debounce the restoration of the programmatic flag so that it only
|
|
3888
|
+
// flips back to `true` once scrolling has come to a rest. This ensures
|
|
3889
|
+
// that momentum scrolling (where no further user-interaction events fire)
|
|
3890
|
+
// is still treated as user-driven.
|
|
3891
|
+
// 100 ms without scroll events ≈ scroll end
|
|
3892
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollend_event
|
|
3893
|
+
scrollEndTimeout.start(100, () => {
|
|
3894
|
+
programmaticScrollRef.current = true;
|
|
3895
|
+
});
|
|
3896
|
+
},
|
|
3897
|
+
onWheel: handleUserInteraction,
|
|
3898
|
+
onPointerMove: handleUserInteraction,
|
|
3899
|
+
onPointerEnter: handleUserInteraction,
|
|
3900
|
+
onKeyDown: handleUserInteraction
|
|
3901
|
+
};
|
|
3902
|
+
const element = useRenderElement('div', componentProps, {
|
|
3903
|
+
ref: [forwardedRef, viewportRef],
|
|
3904
|
+
state: viewportState,
|
|
3905
|
+
props: [props, elementProps],
|
|
3906
|
+
stateAttributesMapping: scrollAreaStateAttributesMapping
|
|
3907
|
+
});
|
|
3908
|
+
const contextValue = React.useMemo(() => ({
|
|
3909
|
+
computeThumbPosition
|
|
3910
|
+
}), [computeThumbPosition]);
|
|
3911
|
+
return /*#__PURE__*/jsx(ScrollAreaViewportContext.Provider, {
|
|
3912
|
+
value: contextValue,
|
|
3913
|
+
children: element
|
|
3914
|
+
});
|
|
3915
|
+
});
|
|
3916
|
+
if (process.env.NODE_ENV !== "production") ScrollAreaViewport.displayName = "ScrollAreaViewport";
|
|
3917
|
+
function getHiddenState(viewport) {
|
|
3918
|
+
const y = viewport.clientHeight >= viewport.scrollHeight;
|
|
3919
|
+
const x = viewport.clientWidth >= viewport.scrollWidth;
|
|
3920
|
+
return {
|
|
3921
|
+
y,
|
|
3922
|
+
x,
|
|
3923
|
+
corner: y || x
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
/**
|
|
3928
|
+
* Returns `prev` when `next` is shallow-equal to it so setState bails out and
|
|
3929
|
+
* scroll-frame updates don't rebuild the root context.
|
|
3930
|
+
*/
|
|
3931
|
+
function pickState(prev, next) {
|
|
3932
|
+
for (const key in next) {
|
|
3933
|
+
if (prev[key] !== next[key]) {
|
|
3934
|
+
return next;
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
return prev;
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
/**
|
|
3941
|
+
* Sizes the thumb and returns its axis offset. On overscroll (Safari rubber-band only) it shrinks
|
|
3942
|
+
* against the pinned edge, damped by `content / (content + overscroll)` to match native feedback;
|
|
3943
|
+
* the size flows through the thumb-size variable so the resting `var(...)` still applies.
|
|
3944
|
+
*/
|
|
3945
|
+
function applyOverscrollThumb(thumbEl, sizeVar, scrollFromStart, maxScroll, content, size, maxThumbOffset) {
|
|
3946
|
+
const clamped = clamp(scrollFromStart, 0, maxScroll);
|
|
3947
|
+
const overscroll = scrollFromStart - clamped;
|
|
3948
|
+
const nextSize = Math.max(MIN_THUMB_SIZE, size * content / (content + Math.abs(overscroll)));
|
|
3949
|
+
|
|
3950
|
+
// Passing an empty string removes the override, restoring the resting `var(...)` size.
|
|
3951
|
+
thumbEl.style.setProperty(sizeVar, overscroll ? `${nextSize}px` : '');
|
|
3952
|
+
|
|
3953
|
+
// Slide proportionally; at the end edge push down by the shrink so the thumb stays pinned to
|
|
3954
|
+
// it, while a start overscroll pins to offset 0.
|
|
3955
|
+
const offset = maxScroll ? clamped / maxScroll * maxThumbOffset : 0;
|
|
3956
|
+
return offset + (overscroll > 0 ? size - nextSize : 0);
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
export { getElementTransform as A, DrawerVirtualKeyboardContext as B, getElementAtPoint as C, DrawerTrigger as D, useScrollAreaRootContext as E, getOffset as F, scrollAreaStateAttributesMapping as G, useScrollAreaViewportContext as H, NullStore as N, ScrollAreaRoot as S, DrawerRoot as a, DrawerPortal as b, DrawerBackdrop as c, DrawerViewport as d, DrawerPopup as e, ScrollAreaViewport as f, DrawerContent as g, DialogTrigger as h, DialogPortal as i, DialogViewport as j, useDialogPortalContext as k, dialogStateAttributesMapping as l, useRenderDialogRoot as m, createNullDialogStore as n, createInitialPopupStoreState as o, popupStoreSelectors as p, usePopupHandleStore as q, useDrawerProviderContext as r, DrawerBackdropCssVars as s, DrawerPopupCssVars as t, useDialogRootContext as u, DrawerProviderContext as v, useDrawerRootContext as w, useSwipeDismiss as x, getDisplacement as y, DrawerPopupDataAttributes as z };
|