@servicetitan/anvil2 2.5.1 → 2.6.1
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/CHANGELOG.md +24 -0
- package/dist/{Alert-D9mBPs6z.js → Alert-C_o2f78C.js} +5 -5
- package/dist/{Alert-D9mBPs6z.js.map → Alert-C_o2f78C.js.map} +1 -1
- package/dist/Alert.js +1 -1
- package/dist/{Announcement-B34cD6BC.js → Announcement-CyrTvgP4.js} +5 -5
- package/dist/{Announcement-B34cD6BC.js.map → Announcement-CyrTvgP4.js.map} +1 -1
- package/dist/Announcement.js +1 -1
- package/dist/{AnvilProvider-C3pjoStP.js → AnvilProvider-ClfmLl_6.js} +5 -5
- package/dist/{AnvilProvider-C3pjoStP.js.map → AnvilProvider-ClfmLl_6.js.map} +1 -1
- package/dist/AnvilProvider.js +1 -1
- package/dist/{Avatar-DShevhcs.js → Avatar--CnTAnfD.js} +2 -2
- package/dist/{Avatar-DShevhcs.js.map → Avatar--CnTAnfD.js.map} +1 -1
- package/dist/{Avatar-COMPK7Ym.js → Avatar-CCnbKkCm.js} +4 -4
- package/dist/{Avatar-COMPK7Ym.js.map → Avatar-CCnbKkCm.js.map} +1 -1
- package/dist/Avatar.js +2 -2
- package/dist/{Badge-CS-CwcOQ.js → Badge-C2W7Dls9.js} +4 -4
- package/dist/{Badge-CS-CwcOQ.js.map → Badge-C2W7Dls9.js.map} +1 -1
- package/dist/Badge.js +1 -1
- package/dist/{Breadcrumbs-CEVH4s23.js → Breadcrumbs-3Y7jnj-F.js} +6 -6
- package/dist/{Breadcrumbs-CEVH4s23.js.map → Breadcrumbs-3Y7jnj-F.js.map} +1 -1
- package/dist/Breadcrumbs.js +1 -1
- package/dist/{Button-DrNDkO2f.js → Button-CVsGhVJz.js} +6 -6
- package/dist/{Button-DrNDkO2f.js.map → Button-CVsGhVJz.js.map} +1 -1
- package/dist/Button.css +49 -49
- package/dist/Button.js +1 -1
- package/dist/Button.module-wCtFYGVD.js +26 -0
- package/dist/Button.module-wCtFYGVD.js.map +1 -0
- package/dist/{ButtonCompound-D9VTKcL4.js → ButtonCompound-Cmw3cgMY.js} +4 -4
- package/dist/{ButtonCompound-D9VTKcL4.js.map → ButtonCompound-Cmw3cgMY.js.map} +1 -1
- package/dist/ButtonCompound.js +1 -1
- package/dist/{ButtonLink-DDtrmbVM.js → ButtonLink-BJKTJER8.js} +6 -6
- package/dist/{ButtonLink-DDtrmbVM.js.map → ButtonLink-BJKTJER8.js.map} +1 -1
- package/dist/ButtonLink.js +1 -1
- package/dist/{ButtonToggle-DrFewgOG.js → ButtonToggle-DaYJWso_.js} +5 -5
- package/dist/{ButtonToggle-DrFewgOG.js.map → ButtonToggle-DaYJWso_.js.map} +1 -1
- package/dist/ButtonToggle.js +1 -1
- package/dist/{Calendar-CtkL4zYU.js → Calendar-B0u3EgCY.js} +7 -7
- package/dist/{Calendar-CtkL4zYU.js.map → Calendar-B0u3EgCY.js.map} +1 -1
- package/dist/{Calendar-CkgpKD7Q.js → Calendar-B5d2SUrH.js} +2 -2
- package/dist/{Calendar-CkgpKD7Q.js.map → Calendar-B5d2SUrH.js.map} +1 -1
- package/dist/Calendar.js +2 -2
- package/dist/{Card-DDH7gI8m.js → Card-wz71dEVA.js} +3 -3
- package/dist/{Card-DDH7gI8m.js.map → Card-wz71dEVA.js.map} +1 -1
- package/dist/Card.js +1 -1
- package/dist/{Checkbox-CxjZpzPp.js → Checkbox-BwULIo4D.js} +26 -36
- package/dist/Checkbox-BwULIo4D.js.map +1 -0
- package/dist/{Checkbox-CFgjreAl.js → Checkbox-CIj37_vY.js} +2 -2
- package/dist/{Checkbox-CFgjreAl.js.map → Checkbox-CIj37_vY.js.map} +1 -1
- package/dist/Checkbox.css +71 -66
- package/dist/Checkbox.js +1 -1
- package/dist/Checkbox.module-EkRZO48Y.js +28 -0
- package/dist/Checkbox.module-EkRZO48Y.js.map +1 -0
- package/dist/{Chip-Bc7jiIJ1.js → Chip-DjTAR0va.js} +6 -6
- package/dist/{Chip-Bc7jiIJ1.js.map → Chip-DjTAR0va.js.map} +1 -1
- package/dist/Chip.js +1 -1
- package/dist/{Combobox-Drqb3GVU.js → Combobox-Clymsgli.js} +16 -19
- package/dist/Combobox-Clymsgli.js.map +1 -0
- package/dist/Combobox.js +1 -1
- package/dist/{DataTable-BLuJ4FtH.js → DataTable-qoseu_e2.js} +83 -48
- package/dist/DataTable-qoseu_e2.js.map +1 -0
- package/dist/DataTable.css +68 -55
- package/dist/{DateFieldRange-CvlOeE4v.js → DateFieldRange-rks7jQor.js} +45 -54
- package/dist/DateFieldRange-rks7jQor.js.map +1 -0
- package/dist/DateFieldRange.js +1 -1
- package/dist/{DateFieldSingle-9UHxIxIA.js → DateFieldSingle-C0WXU7H1.js} +43 -52
- package/dist/DateFieldSingle-C0WXU7H1.js.map +1 -0
- package/dist/DateFieldSingle.js +1 -1
- package/dist/{DateFieldYearless-HNydELvO.js → DateFieldYearless-2p3a7Xgo.js} +15 -23
- package/dist/DateFieldYearless-2p3a7Xgo.js.map +1 -0
- package/dist/DateFieldYearless.js +1 -1
- package/dist/{DateFieldYearlessRange-COb8v2CG.js → DateFieldYearlessRange-DLmhPug8.js} +18 -25
- package/dist/DateFieldYearlessRange-DLmhPug8.js.map +1 -0
- package/dist/DateFieldYearlessRange.js +1 -1
- package/dist/{DaysOfTheWeek-D-WPj18i.js → DaysOfTheWeek-BR32AA32.js} +6 -6
- package/dist/{DaysOfTheWeek-D-WPj18i.js.map → DaysOfTheWeek-BR32AA32.js.map} +1 -1
- package/dist/DaysOfTheWeek.js +1 -1
- package/dist/{Details-BF0-a1by.js → Details-Dxq_v3Qg.js} +4 -4
- package/dist/{Details-BF0-a1by.js.map → Details-Dxq_v3Qg.js.map} +1 -1
- package/dist/Details.js +1 -1
- package/dist/{Dialog-DEAR058v.js → Dialog-CMhypnCD.js} +5 -5
- package/dist/{Dialog-DEAR058v.js.map → Dialog-CMhypnCD.js.map} +1 -1
- package/dist/Dialog.js +1 -1
- package/dist/{DialogCancelButton-BfI9K4a4.js → DialogCancelButton-DQDMzGeT.js} +2 -2
- package/dist/{DialogCancelButton-BfI9K4a4.js.map → DialogCancelButton-DQDMzGeT.js.map} +1 -1
- package/dist/{Divider-De04mOU6.js → Divider-B1UoK8ho.js} +3 -3
- package/dist/{Divider-De04mOU6.js.map → Divider-B1UoK8ho.js.map} +1 -1
- package/dist/Divider.js +1 -1
- package/dist/Dnd.js +1 -1
- package/dist/DndSort.js +6 -6
- package/dist/{Drawer-CnMskBQl.js → Drawer-CSelPi8t.js} +5 -5
- package/dist/{Drawer-CnMskBQl.js.map → Drawer-CSelPi8t.js.map} +1 -1
- package/dist/Drawer.js +1 -1
- package/dist/DrillDown.js +1 -1
- package/dist/{EditCard-CH-JE4ba.js → EditCard-CLN0GBN_.js} +7 -7
- package/dist/{EditCard-CH-JE4ba.js.map → EditCard-CLN0GBN_.js.map} +1 -1
- package/dist/EditCard.js +1 -1
- package/dist/FieldLabel-DbMosKtd.js +125 -0
- package/dist/FieldLabel-DbMosKtd.js.map +1 -0
- package/dist/FieldLabel.css +80 -10
- package/dist/FieldLabel.js +1 -1
- package/dist/{FieldMessage-OeP_xSUE.js → FieldMessage-COHqUdj5.js} +3 -3
- package/dist/{FieldMessage-OeP_xSUE.js.map → FieldMessage-COHqUdj5.js.map} +1 -1
- package/dist/FieldMessage.js +2 -2
- package/dist/{Flex-CUtXN-C0.js → Flex-WyyZm1bf.js} +3 -3
- package/dist/{Flex-CUtXN-C0.js.map → Flex-WyyZm1bf.js.map} +1 -1
- package/dist/Flex.js +1 -1
- package/dist/{Grid-CatFkT0X.js → Grid-ONcUpb__.js} +3 -3
- package/dist/{Grid-CatFkT0X.js.map → Grid-ONcUpb__.js.map} +1 -1
- package/dist/Grid.js +1 -1
- package/dist/{Helper-B2UrgJvr.js → Helper-B_FIOlhy.js} +3 -3
- package/dist/{Helper-B2UrgJvr.js.map → Helper-B_FIOlhy.js.map} +1 -1
- package/dist/{Icon-Bcil6aBo.js → Icon-DuIlne4x.js} +3 -3
- package/dist/{Icon-Bcil6aBo.js.map → Icon-DuIlne4x.js.map} +1 -1
- package/dist/Icon.js +1 -1
- package/dist/{InputMask-B7ZnJoR5.js → InputMask-BKs-x6ds.js} +3 -3
- package/dist/{InputMask-B7ZnJoR5.js.map → InputMask-BKs-x6ds.js.map} +1 -1
- package/dist/InputMask.js +1 -1
- package/dist/{InteractiveCard-OszQGxGw.js → InteractiveCard-GTYbR6Xy.js} +3 -3
- package/dist/{InteractiveCard-OszQGxGw.js.map → InteractiveCard-GTYbR6Xy.js.map} +1 -1
- package/dist/InteractiveCard.js +1 -1
- package/dist/{Layout-DTAU7jS5.js → Layout-VfhlilMG.js} +2 -2
- package/dist/{Layout-DTAU7jS5.js.map → Layout-VfhlilMG.js.map} +1 -1
- package/dist/Layout.js +1 -1
- package/dist/{Link-B3reiL5f.js → Link-jTvzyXca.js} +4 -4
- package/dist/{Link-B3reiL5f.js.map → Link-jTvzyXca.js.map} +1 -1
- package/dist/Link.js +1 -1
- package/dist/{LinkButton-D62f2os3.js → LinkButton-DGyHR1E7.js} +3 -3
- package/dist/{LinkButton-D62f2os3.js.map → LinkButton-DGyHR1E7.js.map} +1 -1
- package/dist/LinkButton.js +1 -1
- package/dist/{List-CtdOo1dv.js → List-CJZjElAQ.js} +3 -3
- package/dist/{List-CtdOo1dv.js.map → List-CJZjElAQ.js.map} +1 -1
- package/dist/List.js +1 -1
- package/dist/{ListView-CN8zu-cq.js → ListView-CeGwrRbt.js} +4 -4
- package/dist/{ListView-CN8zu-cq.js.map → ListView-CeGwrRbt.js.map} +1 -1
- package/dist/ListView.js +1 -1
- package/dist/{Listbox-DMyxIokT.js → Listbox-BtAgBDRS.js} +7 -7
- package/dist/{Listbox-DMyxIokT.js.map → Listbox-BtAgBDRS.js.map} +1 -1
- package/dist/Listbox.css +29 -29
- package/dist/Listbox.js +1 -1
- package/dist/Listbox.module-HAXMOKvC.js +18 -0
- package/dist/Listbox.module-HAXMOKvC.js.map +1 -0
- package/dist/{LocalizationProvider-ay-XWdlo.js → LocalizationProvider-DWCyga_d.js} +2 -2
- package/dist/{LocalizationProvider-ay-XWdlo.js.map → LocalizationProvider-DWCyga_d.js.map} +1 -1
- package/dist/LocalizationProvider.js +1 -1
- package/dist/{Menu-CpRnsr0v.js → Menu-BXsmCP20.js} +6 -5
- package/dist/{Menu-CpRnsr0v.js.map → Menu-BXsmCP20.js.map} +1 -1
- package/dist/Menu.js +1 -1
- package/dist/MultiSelectField.js +1 -1
- package/dist/{MultiSelectFieldSync-BnPzYM72.js → MultiSelectFieldSync-EELhdoD6.js} +92 -177
- package/dist/MultiSelectFieldSync-EELhdoD6.js.map +1 -0
- package/dist/MultiSelectMenu.d.ts +2 -0
- package/dist/MultiSelectMenu.js +2 -0
- package/dist/MultiSelectMenu.js.map +1 -0
- package/dist/MultiSelectMenuSync-CAPhhkK1.js +432 -0
- package/dist/MultiSelectMenuSync-CAPhhkK1.js.map +1 -0
- package/dist/{NumberField-ecubQsaf.js → NumberField-svhZp1kB.js} +14 -15
- package/dist/NumberField-svhZp1kB.js.map +1 -0
- package/dist/NumberField.js +1 -1
- package/dist/Overflow.js +3 -3
- package/dist/{Page-qOkG6psI.js → Page-BpV1yHkm.js} +16 -16
- package/dist/{Page-qOkG6psI.js.map → Page-BpV1yHkm.js.map} +1 -1
- package/dist/Page.js +1 -1
- package/dist/{Pagination-BuiyhZlJ.js → Pagination-BAwqfl_2.js} +8 -8
- package/dist/{Pagination-BuiyhZlJ.js.map → Pagination-BAwqfl_2.js.map} +1 -1
- package/dist/Pagination.js +1 -1
- package/dist/{Popover-CYWYCj7l.js → Popover-Br6qPgKe.js} +7 -26
- package/dist/Popover-Br6qPgKe.js.map +1 -0
- package/dist/Popover-Dkw_8dZx.js +535 -0
- package/dist/Popover-Dkw_8dZx.js.map +1 -0
- package/dist/Popover.js +1 -1
- package/dist/Popover2.css +68 -0
- package/dist/{ProgressBar-CBhVZIzK.js → ProgressBar-JpRDW5vG.js} +8 -8
- package/dist/{ProgressBar-CBhVZIzK.js.map → ProgressBar-JpRDW5vG.js.map} +1 -1
- package/dist/ProgressBar.js +1 -1
- package/dist/{Radio-DtYoRq3m.js → Radio-8DmfWHYq.js} +38 -46
- package/dist/Radio-8DmfWHYq.js.map +1 -0
- package/dist/{Radio-BMFwnzyz.js → Radio-M7lc0BsU.js} +2 -2
- package/dist/{Radio-BMFwnzyz.js.map → Radio-M7lc0BsU.js.map} +1 -1
- package/dist/Radio.css +52 -47
- package/dist/Radio.js +1 -1
- package/dist/{SearchField-CtdtcrVV.js → SearchField-im7AHGYo.js} +5 -5
- package/dist/{SearchField-CtdtcrVV.js.map → SearchField-im7AHGYo.js.map} +1 -1
- package/dist/SearchField.js +1 -1
- package/dist/{SegmentedControl-CzTtiYS9.js → SegmentedControl-7fDLhgvh.js} +3 -3
- package/dist/{SegmentedControl-CzTtiYS9.js.map → SegmentedControl-7fDLhgvh.js.map} +1 -1
- package/dist/SegmentedControl.js +1 -1
- package/dist/{SelectCard-yWBNnm7t.js → SelectCard-D5dcOIuf.js} +6 -6
- package/dist/{SelectCard-yWBNnm7t.js.map → SelectCard-D5dcOIuf.js.map} +1 -1
- package/dist/SelectCard.js +1 -1
- package/dist/SelectField.js +1 -1
- package/dist/SelectFieldLabel-Dr8HeW3N.js +31 -0
- package/dist/SelectFieldLabel-Dr8HeW3N.js.map +1 -0
- package/dist/{SelectFieldSync-DCrafdbx.js → SelectFieldSync-BPopU0om.js} +80 -169
- package/dist/SelectFieldSync-BPopU0om.js.map +1 -0
- package/dist/SelectMenu.d.ts +2 -0
- package/dist/SelectMenu.js +2 -0
- package/dist/SelectMenu.js.map +1 -0
- package/dist/SelectMenuSync-DeMYO1m_.js +327 -0
- package/dist/SelectMenuSync-DeMYO1m_.js.map +1 -0
- package/dist/SelectOptions-DBe5ZN_-.js +26 -0
- package/dist/SelectOptions-DBe5ZN_-.js.map +1 -0
- package/dist/{SelectTrigger-Cs5CGc4D.js → SelectTrigger-ObsnAKNp.js} +6 -9
- package/dist/SelectTrigger-ObsnAKNp.js.map +1 -0
- package/dist/SelectTrigger.js +1 -1
- package/dist/{SelectTriggerBase-Cs827tDp.js → SelectTriggerBase-DKfOL2RJ.js} +8 -8
- package/dist/{SelectTriggerBase-Cs827tDp.js.map → SelectTriggerBase-DKfOL2RJ.js.map} +1 -1
- package/dist/{SideNav-CbMGsIPM.js → SideNav-KksbSQn7.js} +4 -4
- package/dist/{SideNav-CbMGsIPM.js.map → SideNav-KksbSQn7.js.map} +1 -1
- package/dist/SideNav.js +1 -1
- package/dist/Skeleton.js +2 -2
- package/dist/{Spinner-CpEm3Lud.js → Spinner-BqmcE2pb.js} +2 -2
- package/dist/{Spinner-CpEm3Lud.js.map → Spinner-BqmcE2pb.js.map} +1 -1
- package/dist/Spinner.js +1 -1
- package/dist/{SrOnly-CrdBTl6E.js → SrOnly-eUpYGpAT.js} +2 -2
- package/dist/{SrOnly-CrdBTl6E.js.map → SrOnly-eUpYGpAT.js.map} +1 -1
- package/dist/SrOnly.js +1 -1
- package/dist/{Stepper-CzVKDg-N.js → Stepper-Dt8_ImvJ.js} +5 -5
- package/dist/{Stepper-CzVKDg-N.js.map → Stepper-Dt8_ImvJ.js.map} +1 -1
- package/dist/Stepper.js +1 -1
- package/dist/{Switch-CEmjmSiL.js → Switch-DpPHr3G3.js} +6 -6
- package/dist/{Switch-CEmjmSiL.js.map → Switch-DpPHr3G3.js.map} +1 -1
- package/dist/Switch.js +1 -1
- package/dist/{Tab-DXivEqur.js → Tab-DO7LaUbw.js} +4 -4
- package/dist/{Tab-DXivEqur.js.map → Tab-DO7LaUbw.js.map} +1 -1
- package/dist/Tab.js +1 -1
- package/dist/Table.js +1 -1
- package/dist/{Text-DhheKsns.js → Text-BJo4oMI2.js} +3 -3
- package/dist/{Text-DhheKsns.js.map → Text-BJo4oMI2.js.map} +1 -1
- package/dist/Text.js +1 -1
- package/dist/{TextField-D9VWORek.js → TextField--co7QJ4r.js} +2 -2
- package/dist/{TextField-D9VWORek.js.map → TextField--co7QJ4r.js.map} +1 -1
- package/dist/{TextField-atI4M79b.js → TextField-Cax4UeNl.js} +12 -16
- package/dist/TextField-Cax4UeNl.js.map +1 -0
- package/dist/TextField.js +1 -1
- package/dist/{Textarea-D-kPIsIN.js → Textarea-DyqdMTvQ.js} +11 -15
- package/dist/Textarea-DyqdMTvQ.js.map +1 -0
- package/dist/Textarea.js +1 -1
- package/dist/{ThemeProvider-BEt_iJgf.js → ThemeProvider-CaYW3RuA.js} +3 -3
- package/dist/{ThemeProvider-BEt_iJgf.js.map → ThemeProvider-CaYW3RuA.js.map} +1 -1
- package/dist/ThemeProvider.js +1 -1
- package/dist/{TimeField-DREFzFkw.js → TimeField-BfcLCWMG.js} +23 -13
- package/dist/TimeField-BfcLCWMG.js.map +1 -0
- package/dist/TimeField.js +1 -1
- package/dist/Toast.js +2 -2
- package/dist/{Toaster-Bisc1mlh.js → Toaster-DikGo_hR.js} +2 -2
- package/dist/{Toaster-Bisc1mlh.js.map → Toaster-DikGo_hR.js.map} +1 -1
- package/dist/{Toaster-B652KIzq.js → Toaster-b0-Ub3yt.js} +7 -7
- package/dist/{Toaster-B652KIzq.js.map → Toaster-b0-Ub3yt.js.map} +1 -1
- package/dist/{Toolbar-jfZ-CupZ.js → Toolbar-DqYMc_w8.js} +39 -126
- package/dist/Toolbar-DqYMc_w8.js.map +1 -0
- package/dist/Toolbar.js +1 -1
- package/dist/{Tooltip-Bt62hC5J.js → Tooltip-Bupqao9B.js} +13 -6
- package/dist/Tooltip-Bupqao9B.js.map +1 -0
- package/dist/Tooltip.js +1 -1
- package/dist/{YearlessDateInputWithPicker-mW5KykHZ.js → YearlessDateInputWithPicker-aq99rKJU.js} +14 -15
- package/dist/YearlessDateInputWithPicker-aq99rKJU.js.map +1 -0
- package/dist/YearlessDateInputWithPicker.css +33 -33
- package/dist/assets/icons/st/resize_window_alt.svg +1 -0
- package/dist/assets/icons/st.ts +1 -0
- package/dist/beta/components/MultiSelectField/MultiSelectFieldSync.d.ts +2 -3
- package/dist/beta/components/MultiSelectField/internal/useComboMultiple.d.ts +8 -7
- package/dist/beta/components/MultiSelectField/internal/useSelectModeMultiple.d.ts +6 -4
- package/dist/beta/components/MultiSelectField/types.d.ts +2 -3
- package/dist/beta/components/MultiSelectMenu/MultiSelectMenu.d.ts +30 -0
- package/dist/beta/components/MultiSelectMenu/MultiSelectMenuSync.d.ts +54 -0
- package/dist/beta/components/MultiSelectMenu/index.d.ts +3 -0
- package/dist/beta/components/MultiSelectMenu/types.d.ts +170 -0
- package/dist/beta/components/SelectField/SelectFieldSync.d.ts +2 -3
- package/dist/beta/components/SelectField/internal/SelectFieldComboboxMode.d.ts +1 -1
- package/dist/beta/components/SelectField/internal/SelectFieldSelectMode.d.ts +1 -1
- package/dist/beta/components/SelectField/internal/useCombo.d.ts +7 -7
- package/dist/beta/components/SelectField/internal/useSelectMode.d.ts +7 -6
- package/dist/beta/components/SelectField/types.d.ts +2 -9
- package/dist/beta/components/SelectMenu/SelectMenu.d.ts +27 -0
- package/dist/beta/components/SelectMenu/SelectMenuSync.d.ts +41 -0
- package/dist/beta/components/SelectMenu/index.d.ts +3 -0
- package/dist/beta/components/SelectMenu/internal/useMenuInteraction.d.ts +72 -0
- package/dist/beta/components/SelectMenu/types.d.ts +153 -0
- package/dist/beta/components/Table/DataTable/internal/cells/CellFocusContext.d.ts +1 -1
- package/dist/beta/components/Table/DataTable/internal/cells/CellStatus.d.ts +12 -0
- package/dist/beta/components/Table/types.d.ts +14 -0
- package/dist/beta/components/Toolbar/ToolbarSelect.d.ts +3 -3
- package/dist/beta/components/index.d.ts +2 -0
- package/dist/beta.js +10 -8
- package/dist/beta.js.map +1 -1
- package/dist/components/Avatar/Avatar.figma.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.figma.d.ts +1 -0
- package/dist/components/Card/Card.figma.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.figma.d.ts +1 -0
- package/dist/components/Chip/Chip.figma.d.ts +1 -0
- package/dist/components/Combobox/ComboboxTypes.d.ts +1 -1
- package/dist/components/DateFieldYearless/internal/YearlessDateSelectionPopover.d.ts +1 -1
- package/dist/components/FieldLabel/FieldLabel.d.ts +3 -0
- package/dist/components/FieldLabel/internal/FieldLabelButton.d.ts +22 -0
- package/dist/components/FieldLabel/internal/FieldLabelMoreInfoIcon.d.ts +4 -6
- package/dist/components/Link/Link.figma.d.ts +1 -0
- package/dist/components/ProgressBar/ProgressBar.figma.d.ts +1 -0
- package/dist/components/SelectTrigger/SelectTrigger.d.ts +1 -1
- package/dist/components/Spinner/Spinner.figma.d.ts +1 -0
- package/dist/components/Textarea/Textarea.d.ts +1 -1
- package/dist/components/Toolbar/ToolbarSelect.d.ts +3 -3
- package/dist/components/Tooltip/Tooltip.figma.d.ts +1 -0
- package/dist/{match-sorter.esm-adzV1NDp.js → downshift.esm-xtSnQp44.js} +3 -907
- package/dist/downshift.esm-xtSnQp44.js.map +1 -0
- package/dist/floating-ui.react-aKYfs-aw.js +2374 -0
- package/dist/floating-ui.react-aKYfs-aw.js.map +1 -0
- package/dist/{floating-ui.react-dom-BZbDMh89.js → floating-ui.react-dom-imrk9N49.js} +237 -19
- package/dist/floating-ui.react-dom-imrk9N49.js.map +1 -0
- package/dist/hooks/useBreakpoint/useBreakpoint.d.ts +3 -3
- package/dist/{index-ClUtwV8V.js → index-D6ag_WQW.js} +4 -4
- package/dist/{index-ClUtwV8V.js.map → index-D6ag_WQW.js.map} +1 -1
- package/dist/{index-SvGbrGuT.js → index-De1g9FRV.js} +2 -2
- package/dist/{index-SvGbrGuT.js.map → index-De1g9FRV.js.map} +1 -1
- package/dist/index.js +73 -99
- package/dist/index.js.map +1 -1
- package/dist/internal/components/MultiSelectOptions.d.ts +23 -0
- package/dist/{beta/components/SelectField/internal/FieldDialog/FieldDialog.d.ts → internal/components/OptionsDialog/OptionsDialog.d.ts} +2 -2
- package/dist/internal/components/OptionsPanel.d.ts +26 -0
- package/dist/internal/components/OptionsPopover/OptionsPopover.d.ts +16 -0
- package/dist/internal/components/Popover/Popover.d.ts +267 -0
- package/dist/internal/components/Popover/PopoverButton.d.ts +24 -0
- package/dist/internal/components/Popover/PopoverClose.d.ts +24 -0
- package/dist/internal/components/Popover/PopoverContent.d.ts +34 -0
- package/dist/internal/components/Popover/PopoverTrigger.d.ts +46 -0
- package/dist/internal/components/Popover/index.d.ts +6 -0
- package/dist/internal/components/Popover/internal/PopoverContext.d.ts +45 -0
- package/dist/internal/components/Popover/internal/usePopoverContext.d.ts +6 -0
- package/dist/internal/components/SelectOption.d.ts +13 -0
- package/dist/internal/components/SelectOptions.d.ts +23 -0
- package/dist/internal/components/VirtualizedOptionsPanel.d.ts +2 -0
- package/dist/internal/functions/buildSelectItems.d.ts +22 -0
- package/dist/internal/functions/syncFilterUtils.d.ts +10 -0
- package/dist/{beta/components/SelectField/internal → internal/hooks}/useGroupedOptions.d.ts +4 -3
- package/dist/{beta/components/SelectField/internal/useFieldListSections.d.ts → internal/hooks/useOptionsSections.d.ts} +7 -8
- package/dist/{beta/components/SelectField/internal → internal/hooks}/usePinnedOptions.d.ts +1 -1
- package/dist/{beta/components/SelectField/internal → internal/hooks}/useProcessedOptions.d.ts +2 -2
- package/dist/internal/hooks/useSelectOrchestration.d.ts +38 -0
- package/dist/{beta/components/MultiSelectField/internal → internal/hooks}/useToggleSelection.d.ts +2 -2
- package/dist/{beta/components/SelectField/internal/types.d.ts → internal/types/selectFieldInternalTypes.d.ts} +11 -3
- package/dist/match-sorter.esm-CGAauEiU.js +908 -0
- package/dist/match-sorter.esm-CGAauEiU.js.map +1 -0
- package/dist/safePopover-BDso-xSH.js +17 -0
- package/dist/safePopover-BDso-xSH.js.map +1 -0
- package/dist/{FieldDialog-C5mwMjrr.js → syncFilterUtils-BRKjFwxk.js} +287 -146
- package/dist/syncFilterUtils-BRKjFwxk.js.map +1 -0
- package/dist/{FieldDialog.css → syncFilterUtils.css} +18 -11
- package/dist/{useBreakpoint-BP3HZXmh.js → useBreakpoint-okJ64T1D.js} +4 -3
- package/dist/useBreakpoint-okJ64T1D.js.map +1 -0
- package/dist/useBreakpoint.js +1 -1
- package/dist/{useDrilldown-hUxMOdnz.js → useDrilldown-CqBBB_r1.js} +5 -5
- package/dist/{useDrilldown-hUxMOdnz.js.map → useDrilldown-CqBBB_r1.js.map} +1 -1
- package/dist/{useLayoutPropsUtil-loxbyklF.js → useLayoutPropsUtil-DMDdfIah.js} +2 -2
- package/dist/{useLayoutPropsUtil-loxbyklF.js.map → useLayoutPropsUtil-DMDdfIah.js.map} +1 -1
- package/dist/useMenuInteraction-zR_78KQC.js +249 -0
- package/dist/useMenuInteraction-zR_78KQC.js.map +1 -0
- package/dist/usePopoverTransitionStates-CDIoNUuf.js +24 -0
- package/dist/usePopoverTransitionStates-CDIoNUuf.js.map +1 -0
- package/dist/useToggleSelection-JD62Jzqu.js +63 -0
- package/dist/useToggleSelection-JD62Jzqu.js.map +1 -0
- package/dist/{utils-pudAMGnO.js → utils-CM48ODEJ.js} +3 -13
- package/dist/utils-CM48ODEJ.js.map +1 -0
- package/dist/warnOnce-Y9PRHcU4.js +13 -0
- package/dist/warnOnce-Y9PRHcU4.js.map +1 -0
- package/package.json +1 -1
- package/dist/Button.module-DwCq9XU0.js +0 -26
- package/dist/Button.module-DwCq9XU0.js.map +0 -1
- package/dist/Checkbox-CxjZpzPp.js.map +0 -1
- package/dist/Checkbox.module-D4EgXL0i.js +0 -27
- package/dist/Checkbox.module-D4EgXL0i.js.map +0 -1
- package/dist/Combobox-Drqb3GVU.js.map +0 -1
- package/dist/DataTable-BLuJ4FtH.js.map +0 -1
- package/dist/DateFieldRange-CvlOeE4v.js.map +0 -1
- package/dist/DateFieldSingle-9UHxIxIA.js.map +0 -1
- package/dist/DateFieldYearless-HNydELvO.js.map +0 -1
- package/dist/DateFieldYearlessRange-COb8v2CG.js.map +0 -1
- package/dist/FieldDialog-C5mwMjrr.js.map +0 -1
- package/dist/FieldLabel-DL0D6fvc.js +0 -95
- package/dist/FieldLabel-DL0D6fvc.js.map +0 -1
- package/dist/Listbox.module-XuKszT3X.js +0 -18
- package/dist/Listbox.module-XuKszT3X.js.map +0 -1
- package/dist/MultiSelectFieldSync-BnPzYM72.js.map +0 -1
- package/dist/NumberField-ecubQsaf.js.map +0 -1
- package/dist/Popover-CYWYCj7l.js.map +0 -1
- package/dist/Radio-DtYoRq3m.js.map +0 -1
- package/dist/SelectFieldSync-DCrafdbx.js.map +0 -1
- package/dist/SelectTrigger-Cs5CGc4D.js.map +0 -1
- package/dist/TextField-atI4M79b.js.map +0 -1
- package/dist/Textarea-D-kPIsIN.js.map +0 -1
- package/dist/TimeField-DREFzFkw.js.map +0 -1
- package/dist/Toolbar-jfZ-CupZ.js.map +0 -1
- package/dist/Tooltip-Bt62hC5J.js.map +0 -1
- package/dist/YearlessDateInputWithPicker-mW5KykHZ.js.map +0 -1
- package/dist/beta/components/MultiSelectField/internal/MultiSelectFieldList.d.ts +0 -24
- package/dist/beta/components/SelectField/internal/FieldListBase.d.ts +0 -27
- package/dist/beta/components/SelectField/internal/FieldPopover/FieldPopover.d.ts +0 -9
- package/dist/beta/components/SelectField/internal/SelectFieldList.d.ts +0 -26
- package/dist/beta/components/SelectField/internal/SelectFieldListItem.d.ts +0 -14
- package/dist/beta/components/SelectField/internal/VirtualizedFieldListBase.d.ts +0 -2
- package/dist/beta/components/SelectField/internal/buildDownshiftItems.d.ts +0 -22
- package/dist/beta/components/Table/DataTable/internal/cells/CellError.d.ts +0 -10
- package/dist/floating-ui.react-P5949bpO.js +0 -28
- package/dist/floating-ui.react-P5949bpO.js.map +0 -1
- package/dist/floating-ui.react-dom-BZbDMh89.js.map +0 -1
- package/dist/match-sorter.esm-adzV1NDp.js.map +0 -1
- package/dist/useBreakpoint-BP3HZXmh.js.map +0 -1
- package/dist/utils-pudAMGnO.js.map +0 -1
- /package/dist/{beta/components/SelectField/internal → internal/components}/InView.d.ts +0 -0
|
@@ -0,0 +1,2374 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLayoutEffect, useEffect, useRef } from 'react';
|
|
3
|
+
import { i as isShadowRoot, a as isHTMLElement, u as useFloating$1, b as isElement, g as getWindow, c as getOverflowAncestors, d as isWebKit, e as isLastTraversableNode, f as getParentNode, h as getComputedStyle, j as getNodeName } from './floating-ui.react-dom-imrk9N49.js';
|
|
4
|
+
import { t as tabbable, i as isTabbable } from './index.esm-K9kxJhLx.js';
|
|
5
|
+
import 'react-dom';
|
|
6
|
+
|
|
7
|
+
function activeElement(doc) {
|
|
8
|
+
let activeElement = doc.activeElement;
|
|
9
|
+
while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
|
|
10
|
+
var _activeElement;
|
|
11
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
|
12
|
+
}
|
|
13
|
+
return activeElement;
|
|
14
|
+
}
|
|
15
|
+
function contains(parent, child) {
|
|
16
|
+
if (!parent || !child) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
|
|
20
|
+
|
|
21
|
+
// First, attempt with faster native method
|
|
22
|
+
if (parent.contains(child)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// then fallback to custom implementation with Shadow DOM support
|
|
27
|
+
if (rootNode && isShadowRoot(rootNode)) {
|
|
28
|
+
let next = child;
|
|
29
|
+
while (next) {
|
|
30
|
+
if (parent === next) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
next = next.parentNode || next.host;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Give up, the result is false
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Avoid Chrome DevTools blue warning.
|
|
42
|
+
function getPlatform() {
|
|
43
|
+
const uaData = navigator.userAgentData;
|
|
44
|
+
if (uaData != null && uaData.platform) {
|
|
45
|
+
return uaData.platform;
|
|
46
|
+
}
|
|
47
|
+
return navigator.platform;
|
|
48
|
+
}
|
|
49
|
+
function getUserAgent() {
|
|
50
|
+
const uaData = navigator.userAgentData;
|
|
51
|
+
if (uaData && Array.isArray(uaData.brands)) {
|
|
52
|
+
return uaData.brands.map(_ref => {
|
|
53
|
+
let {
|
|
54
|
+
brand,
|
|
55
|
+
version
|
|
56
|
+
} = _ref;
|
|
57
|
+
return brand + "/" + version;
|
|
58
|
+
}).join(' ');
|
|
59
|
+
}
|
|
60
|
+
return navigator.userAgent;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
|
|
64
|
+
function isVirtualClick(event) {
|
|
65
|
+
// FIXME: Firefox is now emitting a deprecation warning for `mozInputSource`.
|
|
66
|
+
// Try to find a workaround for this. `react-aria` source still has the check.
|
|
67
|
+
if (event.mozInputSource === 0 && event.isTrusted) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (isAndroid() && event.pointerType) {
|
|
71
|
+
return event.type === 'click' && event.buttons === 1;
|
|
72
|
+
}
|
|
73
|
+
return event.detail === 0 && !event.pointerType;
|
|
74
|
+
}
|
|
75
|
+
function isVirtualPointerEvent(event) {
|
|
76
|
+
if (isJSDOM()) return false;
|
|
77
|
+
return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' ||
|
|
78
|
+
// iOS VoiceOver returns 0.333• for width/height.
|
|
79
|
+
event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch';
|
|
80
|
+
}
|
|
81
|
+
function isSafari() {
|
|
82
|
+
// Chrome DevTools does not complain about navigator.vendor
|
|
83
|
+
return /apple/i.test(navigator.vendor);
|
|
84
|
+
}
|
|
85
|
+
function isAndroid() {
|
|
86
|
+
const re = /android/i;
|
|
87
|
+
return re.test(getPlatform()) || re.test(getUserAgent());
|
|
88
|
+
}
|
|
89
|
+
function isMac() {
|
|
90
|
+
return getPlatform().toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
|
|
91
|
+
}
|
|
92
|
+
function isJSDOM() {
|
|
93
|
+
return getUserAgent().includes('jsdom/');
|
|
94
|
+
}
|
|
95
|
+
function isMouseLikePointerType(pointerType, strict) {
|
|
96
|
+
// On some Linux machines with Chromium, mouse inputs return a `pointerType`
|
|
97
|
+
// of "pen": https://github.com/floating-ui/floating-ui/issues/2015
|
|
98
|
+
const values = ['mouse', 'pen'];
|
|
99
|
+
if (!strict) {
|
|
100
|
+
values.push('', undefined);
|
|
101
|
+
}
|
|
102
|
+
return values.includes(pointerType);
|
|
103
|
+
}
|
|
104
|
+
function isReactEvent(event) {
|
|
105
|
+
return 'nativeEvent' in event;
|
|
106
|
+
}
|
|
107
|
+
function isRootElement(element) {
|
|
108
|
+
return element.matches('html,body');
|
|
109
|
+
}
|
|
110
|
+
function getDocument(node) {
|
|
111
|
+
return (node == null ? void 0 : node.ownerDocument) || document;
|
|
112
|
+
}
|
|
113
|
+
function isEventTargetWithin(event, node) {
|
|
114
|
+
if (node == null) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if ('composedPath' in event) {
|
|
118
|
+
return event.composedPath().includes(node);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
|
|
122
|
+
const e = event;
|
|
123
|
+
return e.target != null && node.contains(e.target);
|
|
124
|
+
}
|
|
125
|
+
function getTarget(event) {
|
|
126
|
+
if ('composedPath' in event) {
|
|
127
|
+
return event.composedPath()[0];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// TS thinks `event` is of type never as it assumes all browsers support
|
|
131
|
+
// `composedPath()`, but browsers without shadow DOM don't.
|
|
132
|
+
return event.target;
|
|
133
|
+
}
|
|
134
|
+
const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
|
|
135
|
+
function isTypeableElement(element) {
|
|
136
|
+
return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
|
|
137
|
+
}
|
|
138
|
+
function stopEvent(event) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopPropagation();
|
|
141
|
+
}
|
|
142
|
+
function isTypeableCombobox(element) {
|
|
143
|
+
if (!element) return false;
|
|
144
|
+
return element.getAttribute('role') === 'combobox' && isTypeableElement(element);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Merges an array of refs into a single memoized callback ref or `null`.
|
|
149
|
+
* @see https://floating-ui.com/docs/react-utils#usemergerefs
|
|
150
|
+
*/
|
|
151
|
+
function useMergeRefs(refs) {
|
|
152
|
+
return React.useMemo(() => {
|
|
153
|
+
if (refs.every(ref => ref == null)) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return value => {
|
|
157
|
+
refs.forEach(ref => {
|
|
158
|
+
if (typeof ref === 'function') {
|
|
159
|
+
ref(value);
|
|
160
|
+
} else if (ref != null) {
|
|
161
|
+
ref.current = value;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
|
+
}, refs);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
|
|
170
|
+
const SafeReact = {
|
|
171
|
+
...React
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const useInsertionEffect = SafeReact.useInsertionEffect;
|
|
175
|
+
const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
|
|
176
|
+
function useEffectEvent(callback) {
|
|
177
|
+
const ref = React.useRef(() => {
|
|
178
|
+
if (process.env.NODE_ENV !== "production") {
|
|
179
|
+
throw new Error('Cannot call an event handler while rendering.');
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
useSafeInsertionEffect(() => {
|
|
183
|
+
ref.current = callback;
|
|
184
|
+
});
|
|
185
|
+
return React.useCallback(function () {
|
|
186
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
187
|
+
args[_key] = arguments[_key];
|
|
188
|
+
}
|
|
189
|
+
return ref.current == null ? void 0 : ref.current(...args);
|
|
190
|
+
}, []);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
|
|
194
|
+
|
|
195
|
+
function _extends() {
|
|
196
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
197
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
198
|
+
var source = arguments[i];
|
|
199
|
+
for (var key in source) {
|
|
200
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
201
|
+
target[key] = source[key];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return target;
|
|
206
|
+
};
|
|
207
|
+
return _extends.apply(this, arguments);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let serverHandoffComplete = false;
|
|
211
|
+
let count = 0;
|
|
212
|
+
const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
|
|
213
|
+
// on <React 18
|
|
214
|
+
"floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
|
|
215
|
+
function useFloatingId() {
|
|
216
|
+
const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
|
|
217
|
+
index(() => {
|
|
218
|
+
if (id == null) {
|
|
219
|
+
setId(genId());
|
|
220
|
+
}
|
|
221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
+
}, []);
|
|
223
|
+
React.useEffect(() => {
|
|
224
|
+
serverHandoffComplete = true;
|
|
225
|
+
}, []);
|
|
226
|
+
return id;
|
|
227
|
+
}
|
|
228
|
+
const useReactId = SafeReact.useId;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Uses React 18's built-in `useId()` when available, or falls back to a
|
|
232
|
+
* slightly less performant (requiring a double render) implementation for
|
|
233
|
+
* earlier React versions.
|
|
234
|
+
* @see https://floating-ui.com/docs/react-utils#useid
|
|
235
|
+
*/
|
|
236
|
+
const useId = useReactId || useFloatingId;
|
|
237
|
+
|
|
238
|
+
let devMessageSet;
|
|
239
|
+
if (process.env.NODE_ENV !== "production") {
|
|
240
|
+
devMessageSet = /*#__PURE__*/new Set();
|
|
241
|
+
}
|
|
242
|
+
function error() {
|
|
243
|
+
var _devMessageSet3;
|
|
244
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
245
|
+
messages[_key2] = arguments[_key2];
|
|
246
|
+
}
|
|
247
|
+
const message = "Floating UI: " + messages.join(' ');
|
|
248
|
+
if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
|
|
249
|
+
var _devMessageSet4;
|
|
250
|
+
(_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
|
|
251
|
+
console.error(message);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function createPubSub() {
|
|
256
|
+
const map = new Map();
|
|
257
|
+
return {
|
|
258
|
+
emit(event, data) {
|
|
259
|
+
var _map$get;
|
|
260
|
+
(_map$get = map.get(event)) == null || _map$get.forEach(handler => handler(data));
|
|
261
|
+
},
|
|
262
|
+
on(event, listener) {
|
|
263
|
+
map.set(event, [...(map.get(event) || []), listener]);
|
|
264
|
+
},
|
|
265
|
+
off(event, listener) {
|
|
266
|
+
var _map$get2;
|
|
267
|
+
map.set(event, ((_map$get2 = map.get(event)) == null ? void 0 : _map$get2.filter(l => l !== listener)) || []);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
|
|
273
|
+
const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Returns the parent node id for nested floating elements, if available.
|
|
277
|
+
* Returns `null` for top-level floating elements.
|
|
278
|
+
*/
|
|
279
|
+
const useFloatingParentNodeId = () => {
|
|
280
|
+
var _React$useContext;
|
|
281
|
+
return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Returns the nearest floating tree context, if available.
|
|
286
|
+
*/
|
|
287
|
+
const useFloatingTree = () => React.useContext(FloatingTreeContext);
|
|
288
|
+
|
|
289
|
+
function createAttribute(name) {
|
|
290
|
+
return "data-floating-ui-" + name;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function useLatestRef(value) {
|
|
294
|
+
const ref = useRef(value);
|
|
295
|
+
index(() => {
|
|
296
|
+
ref.current = value;
|
|
297
|
+
});
|
|
298
|
+
return ref;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const safePolygonIdentifier = /*#__PURE__*/createAttribute('safe-polygon');
|
|
302
|
+
function getDelay(value, prop, pointerType) {
|
|
303
|
+
if (pointerType && !isMouseLikePointerType(pointerType)) {
|
|
304
|
+
return 0;
|
|
305
|
+
}
|
|
306
|
+
if (typeof value === 'number') {
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
return value == null ? void 0 : value[prop];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Opens the floating element while hovering over the reference element, like
|
|
313
|
+
* CSS `:hover`.
|
|
314
|
+
* @see https://floating-ui.com/docs/useHover
|
|
315
|
+
*/
|
|
316
|
+
function useHover(context, props) {
|
|
317
|
+
if (props === void 0) {
|
|
318
|
+
props = {};
|
|
319
|
+
}
|
|
320
|
+
const {
|
|
321
|
+
open,
|
|
322
|
+
onOpenChange,
|
|
323
|
+
dataRef,
|
|
324
|
+
events,
|
|
325
|
+
elements
|
|
326
|
+
} = context;
|
|
327
|
+
const {
|
|
328
|
+
enabled = true,
|
|
329
|
+
delay = 0,
|
|
330
|
+
handleClose = null,
|
|
331
|
+
mouseOnly = false,
|
|
332
|
+
restMs = 0,
|
|
333
|
+
move = true
|
|
334
|
+
} = props;
|
|
335
|
+
const tree = useFloatingTree();
|
|
336
|
+
const parentId = useFloatingParentNodeId();
|
|
337
|
+
const handleCloseRef = useLatestRef(handleClose);
|
|
338
|
+
const delayRef = useLatestRef(delay);
|
|
339
|
+
const openRef = useLatestRef(open);
|
|
340
|
+
const pointerTypeRef = React.useRef();
|
|
341
|
+
const timeoutRef = React.useRef(-1);
|
|
342
|
+
const handlerRef = React.useRef();
|
|
343
|
+
const restTimeoutRef = React.useRef(-1);
|
|
344
|
+
const blockMouseMoveRef = React.useRef(true);
|
|
345
|
+
const performedPointerEventsMutationRef = React.useRef(false);
|
|
346
|
+
const unbindMouseMoveRef = React.useRef(() => {});
|
|
347
|
+
const restTimeoutPendingRef = React.useRef(false);
|
|
348
|
+
const isHoverOpen = React.useCallback(() => {
|
|
349
|
+
var _dataRef$current$open;
|
|
350
|
+
const type = (_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type;
|
|
351
|
+
return (type == null ? void 0 : type.includes('mouse')) && type !== 'mousedown';
|
|
352
|
+
}, [dataRef]);
|
|
353
|
+
|
|
354
|
+
// When closing before opening, clear the delay timeouts to cancel it
|
|
355
|
+
// from showing.
|
|
356
|
+
React.useEffect(() => {
|
|
357
|
+
if (!enabled) return;
|
|
358
|
+
function onOpenChange(_ref) {
|
|
359
|
+
let {
|
|
360
|
+
open
|
|
361
|
+
} = _ref;
|
|
362
|
+
if (!open) {
|
|
363
|
+
clearTimeout(timeoutRef.current);
|
|
364
|
+
clearTimeout(restTimeoutRef.current);
|
|
365
|
+
blockMouseMoveRef.current = true;
|
|
366
|
+
restTimeoutPendingRef.current = false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
events.on('openchange', onOpenChange);
|
|
370
|
+
return () => {
|
|
371
|
+
events.off('openchange', onOpenChange);
|
|
372
|
+
};
|
|
373
|
+
}, [enabled, events]);
|
|
374
|
+
React.useEffect(() => {
|
|
375
|
+
if (!enabled) return;
|
|
376
|
+
if (!handleCloseRef.current) return;
|
|
377
|
+
if (!open) return;
|
|
378
|
+
function onLeave(event) {
|
|
379
|
+
if (isHoverOpen()) {
|
|
380
|
+
onOpenChange(false, event, 'hover');
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const html = getDocument(elements.floating).documentElement;
|
|
384
|
+
html.addEventListener('mouseleave', onLeave);
|
|
385
|
+
return () => {
|
|
386
|
+
html.removeEventListener('mouseleave', onLeave);
|
|
387
|
+
};
|
|
388
|
+
}, [elements.floating, open, onOpenChange, enabled, handleCloseRef, isHoverOpen]);
|
|
389
|
+
const closeWithDelay = React.useCallback(function (event, runElseBranch, reason) {
|
|
390
|
+
if (runElseBranch === void 0) {
|
|
391
|
+
runElseBranch = true;
|
|
392
|
+
}
|
|
393
|
+
if (reason === void 0) {
|
|
394
|
+
reason = 'hover';
|
|
395
|
+
}
|
|
396
|
+
const closeDelay = getDelay(delayRef.current, 'close', pointerTypeRef.current);
|
|
397
|
+
if (closeDelay && !handlerRef.current) {
|
|
398
|
+
clearTimeout(timeoutRef.current);
|
|
399
|
+
timeoutRef.current = window.setTimeout(() => onOpenChange(false, event, reason), closeDelay);
|
|
400
|
+
} else if (runElseBranch) {
|
|
401
|
+
clearTimeout(timeoutRef.current);
|
|
402
|
+
onOpenChange(false, event, reason);
|
|
403
|
+
}
|
|
404
|
+
}, [delayRef, onOpenChange]);
|
|
405
|
+
const cleanupMouseMoveHandler = useEffectEvent(() => {
|
|
406
|
+
unbindMouseMoveRef.current();
|
|
407
|
+
handlerRef.current = undefined;
|
|
408
|
+
});
|
|
409
|
+
const clearPointerEvents = useEffectEvent(() => {
|
|
410
|
+
if (performedPointerEventsMutationRef.current) {
|
|
411
|
+
const body = getDocument(elements.floating).body;
|
|
412
|
+
body.style.pointerEvents = '';
|
|
413
|
+
body.removeAttribute(safePolygonIdentifier);
|
|
414
|
+
performedPointerEventsMutationRef.current = false;
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
const isClickLikeOpenEvent = useEffectEvent(() => {
|
|
418
|
+
return dataRef.current.openEvent ? ['click', 'mousedown'].includes(dataRef.current.openEvent.type) : false;
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// Registering the mouse events on the reference directly to bypass React's
|
|
422
|
+
// delegation system. If the cursor was on a disabled element and then entered
|
|
423
|
+
// the reference (no gap), `mouseenter` doesn't fire in the delegation system.
|
|
424
|
+
React.useEffect(() => {
|
|
425
|
+
if (!enabled) return;
|
|
426
|
+
function onMouseEnter(event) {
|
|
427
|
+
clearTimeout(timeoutRef.current);
|
|
428
|
+
blockMouseMoveRef.current = false;
|
|
429
|
+
if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || restMs > 0 && !getDelay(delayRef.current, 'open')) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const openDelay = getDelay(delayRef.current, 'open', pointerTypeRef.current);
|
|
433
|
+
if (openDelay) {
|
|
434
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
435
|
+
if (!openRef.current) {
|
|
436
|
+
onOpenChange(true, event, 'hover');
|
|
437
|
+
}
|
|
438
|
+
}, openDelay);
|
|
439
|
+
} else if (!open) {
|
|
440
|
+
onOpenChange(true, event, 'hover');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
function onMouseLeave(event) {
|
|
444
|
+
if (isClickLikeOpenEvent()) return;
|
|
445
|
+
unbindMouseMoveRef.current();
|
|
446
|
+
const doc = getDocument(elements.floating);
|
|
447
|
+
clearTimeout(restTimeoutRef.current);
|
|
448
|
+
restTimeoutPendingRef.current = false;
|
|
449
|
+
if (handleCloseRef.current && dataRef.current.floatingContext) {
|
|
450
|
+
// Prevent clearing `onScrollMouseLeave` timeout.
|
|
451
|
+
if (!open) {
|
|
452
|
+
clearTimeout(timeoutRef.current);
|
|
453
|
+
}
|
|
454
|
+
handlerRef.current = handleCloseRef.current({
|
|
455
|
+
...dataRef.current.floatingContext,
|
|
456
|
+
tree,
|
|
457
|
+
x: event.clientX,
|
|
458
|
+
y: event.clientY,
|
|
459
|
+
onClose() {
|
|
460
|
+
clearPointerEvents();
|
|
461
|
+
cleanupMouseMoveHandler();
|
|
462
|
+
if (!isClickLikeOpenEvent()) {
|
|
463
|
+
closeWithDelay(event, true, 'safe-polygon');
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
const handler = handlerRef.current;
|
|
468
|
+
doc.addEventListener('mousemove', handler);
|
|
469
|
+
unbindMouseMoveRef.current = () => {
|
|
470
|
+
doc.removeEventListener('mousemove', handler);
|
|
471
|
+
};
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Allow interactivity without `safePolygon` on touch devices. With a
|
|
476
|
+
// pointer, a short close delay is an alternative, so it should work
|
|
477
|
+
// consistently.
|
|
478
|
+
const shouldClose = pointerTypeRef.current === 'touch' ? !contains(elements.floating, event.relatedTarget) : true;
|
|
479
|
+
if (shouldClose) {
|
|
480
|
+
closeWithDelay(event);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Ensure the floating element closes after scrolling even if the pointer
|
|
485
|
+
// did not move.
|
|
486
|
+
// https://github.com/floating-ui/floating-ui/discussions/1692
|
|
487
|
+
function onScrollMouseLeave(event) {
|
|
488
|
+
if (isClickLikeOpenEvent()) return;
|
|
489
|
+
if (!dataRef.current.floatingContext) return;
|
|
490
|
+
handleCloseRef.current == null || handleCloseRef.current({
|
|
491
|
+
...dataRef.current.floatingContext,
|
|
492
|
+
tree,
|
|
493
|
+
x: event.clientX,
|
|
494
|
+
y: event.clientY,
|
|
495
|
+
onClose() {
|
|
496
|
+
clearPointerEvents();
|
|
497
|
+
cleanupMouseMoveHandler();
|
|
498
|
+
if (!isClickLikeOpenEvent()) {
|
|
499
|
+
closeWithDelay(event);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
})(event);
|
|
503
|
+
}
|
|
504
|
+
if (isElement(elements.domReference)) {
|
|
505
|
+
var _elements$floating;
|
|
506
|
+
const ref = elements.domReference;
|
|
507
|
+
open && ref.addEventListener('mouseleave', onScrollMouseLeave);
|
|
508
|
+
(_elements$floating = elements.floating) == null || _elements$floating.addEventListener('mouseleave', onScrollMouseLeave);
|
|
509
|
+
move && ref.addEventListener('mousemove', onMouseEnter, {
|
|
510
|
+
once: true
|
|
511
|
+
});
|
|
512
|
+
ref.addEventListener('mouseenter', onMouseEnter);
|
|
513
|
+
ref.addEventListener('mouseleave', onMouseLeave);
|
|
514
|
+
return () => {
|
|
515
|
+
var _elements$floating2;
|
|
516
|
+
open && ref.removeEventListener('mouseleave', onScrollMouseLeave);
|
|
517
|
+
(_elements$floating2 = elements.floating) == null || _elements$floating2.removeEventListener('mouseleave', onScrollMouseLeave);
|
|
518
|
+
move && ref.removeEventListener('mousemove', onMouseEnter);
|
|
519
|
+
ref.removeEventListener('mouseenter', onMouseEnter);
|
|
520
|
+
ref.removeEventListener('mouseleave', onMouseLeave);
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
}, [elements, enabled, context, mouseOnly, restMs, move, closeWithDelay, cleanupMouseMoveHandler, clearPointerEvents, onOpenChange, open, openRef, tree, delayRef, handleCloseRef, dataRef, isClickLikeOpenEvent]);
|
|
524
|
+
|
|
525
|
+
// Block pointer-events of every element other than the reference and floating
|
|
526
|
+
// while the floating element is open and has a `handleClose` handler. Also
|
|
527
|
+
// handles nested floating elements.
|
|
528
|
+
// https://github.com/floating-ui/floating-ui/issues/1722
|
|
529
|
+
index(() => {
|
|
530
|
+
var _handleCloseRef$curre;
|
|
531
|
+
if (!enabled) return;
|
|
532
|
+
if (open && (_handleCloseRef$curre = handleCloseRef.current) != null && _handleCloseRef$curre.__options.blockPointerEvents && isHoverOpen()) {
|
|
533
|
+
performedPointerEventsMutationRef.current = true;
|
|
534
|
+
const floatingEl = elements.floating;
|
|
535
|
+
if (isElement(elements.domReference) && floatingEl) {
|
|
536
|
+
var _tree$nodesRef$curren;
|
|
537
|
+
const body = getDocument(elements.floating).body;
|
|
538
|
+
body.setAttribute(safePolygonIdentifier, '');
|
|
539
|
+
const ref = elements.domReference;
|
|
540
|
+
const parentFloating = tree == null || (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren.elements.floating;
|
|
541
|
+
if (parentFloating) {
|
|
542
|
+
parentFloating.style.pointerEvents = '';
|
|
543
|
+
}
|
|
544
|
+
body.style.pointerEvents = 'none';
|
|
545
|
+
ref.style.pointerEvents = 'auto';
|
|
546
|
+
floatingEl.style.pointerEvents = 'auto';
|
|
547
|
+
return () => {
|
|
548
|
+
body.style.pointerEvents = '';
|
|
549
|
+
ref.style.pointerEvents = '';
|
|
550
|
+
floatingEl.style.pointerEvents = '';
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}, [enabled, open, parentId, elements, tree, handleCloseRef, isHoverOpen]);
|
|
555
|
+
index(() => {
|
|
556
|
+
if (!open) {
|
|
557
|
+
pointerTypeRef.current = undefined;
|
|
558
|
+
restTimeoutPendingRef.current = false;
|
|
559
|
+
cleanupMouseMoveHandler();
|
|
560
|
+
clearPointerEvents();
|
|
561
|
+
}
|
|
562
|
+
}, [open, cleanupMouseMoveHandler, clearPointerEvents]);
|
|
563
|
+
React.useEffect(() => {
|
|
564
|
+
return () => {
|
|
565
|
+
cleanupMouseMoveHandler();
|
|
566
|
+
clearTimeout(timeoutRef.current);
|
|
567
|
+
clearTimeout(restTimeoutRef.current);
|
|
568
|
+
clearPointerEvents();
|
|
569
|
+
};
|
|
570
|
+
}, [enabled, elements.domReference, cleanupMouseMoveHandler, clearPointerEvents]);
|
|
571
|
+
const reference = React.useMemo(() => {
|
|
572
|
+
function setPointerRef(event) {
|
|
573
|
+
pointerTypeRef.current = event.pointerType;
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
onPointerDown: setPointerRef,
|
|
577
|
+
onPointerEnter: setPointerRef,
|
|
578
|
+
onMouseMove(event) {
|
|
579
|
+
const {
|
|
580
|
+
nativeEvent
|
|
581
|
+
} = event;
|
|
582
|
+
function handleMouseMove() {
|
|
583
|
+
if (!blockMouseMoveRef.current && !openRef.current) {
|
|
584
|
+
onOpenChange(true, nativeEvent, 'hover');
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current)) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (open || restMs === 0) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// Ignore insignificant movements to account for tremors.
|
|
595
|
+
if (restTimeoutPendingRef.current && event.movementX ** 2 + event.movementY ** 2 < 2) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
clearTimeout(restTimeoutRef.current);
|
|
599
|
+
if (pointerTypeRef.current === 'touch') {
|
|
600
|
+
handleMouseMove();
|
|
601
|
+
} else {
|
|
602
|
+
restTimeoutPendingRef.current = true;
|
|
603
|
+
restTimeoutRef.current = window.setTimeout(handleMouseMove, restMs);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
}, [mouseOnly, onOpenChange, open, openRef, restMs]);
|
|
608
|
+
const floating = React.useMemo(() => ({
|
|
609
|
+
onMouseEnter() {
|
|
610
|
+
clearTimeout(timeoutRef.current);
|
|
611
|
+
},
|
|
612
|
+
onMouseLeave(event) {
|
|
613
|
+
if (!isClickLikeOpenEvent()) {
|
|
614
|
+
closeWithDelay(event.nativeEvent, false);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}), [closeWithDelay, isClickLikeOpenEvent]);
|
|
618
|
+
return React.useMemo(() => enabled ? {
|
|
619
|
+
reference,
|
|
620
|
+
floating
|
|
621
|
+
} : {}, [enabled, reference, floating]);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
let rafId = 0;
|
|
625
|
+
function enqueueFocus(el, options) {
|
|
626
|
+
if (options === void 0) {
|
|
627
|
+
options = {};
|
|
628
|
+
}
|
|
629
|
+
const {
|
|
630
|
+
preventScroll = false,
|
|
631
|
+
cancelPrevious = true,
|
|
632
|
+
sync = false
|
|
633
|
+
} = options;
|
|
634
|
+
cancelPrevious && cancelAnimationFrame(rafId);
|
|
635
|
+
const exec = () => el == null ? void 0 : el.focus({
|
|
636
|
+
preventScroll
|
|
637
|
+
});
|
|
638
|
+
if (sync) {
|
|
639
|
+
exec();
|
|
640
|
+
} else {
|
|
641
|
+
rafId = requestAnimationFrame(exec);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function getAncestors(nodes, id) {
|
|
646
|
+
var _nodes$find;
|
|
647
|
+
let allAncestors = [];
|
|
648
|
+
let currentParentId = (_nodes$find = nodes.find(node => node.id === id)) == null ? void 0 : _nodes$find.parentId;
|
|
649
|
+
while (currentParentId) {
|
|
650
|
+
const currentNode = nodes.find(node => node.id === currentParentId);
|
|
651
|
+
currentParentId = currentNode == null ? void 0 : currentNode.parentId;
|
|
652
|
+
if (currentNode) {
|
|
653
|
+
allAncestors = allAncestors.concat(currentNode);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return allAncestors;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function getChildren(nodes, id) {
|
|
660
|
+
let allChildren = nodes.filter(node => {
|
|
661
|
+
var _node$context;
|
|
662
|
+
return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
|
|
663
|
+
});
|
|
664
|
+
let currentChildren = allChildren;
|
|
665
|
+
while (currentChildren.length) {
|
|
666
|
+
currentChildren = nodes.filter(node => {
|
|
667
|
+
var _currentChildren;
|
|
668
|
+
return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some(n => {
|
|
669
|
+
var _node$context2;
|
|
670
|
+
return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
allChildren = allChildren.concat(currentChildren);
|
|
674
|
+
}
|
|
675
|
+
return allChildren;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// Modified to add conditional `aria-hidden` support:
|
|
679
|
+
// https://github.com/theKashey/aria-hidden/blob/9220c8f4a4fd35f63bee5510a9f41a37264382d4/src/index.ts
|
|
680
|
+
let counterMap = /*#__PURE__*/new WeakMap();
|
|
681
|
+
let uncontrolledElementsSet = /*#__PURE__*/new WeakSet();
|
|
682
|
+
let markerMap = {};
|
|
683
|
+
let lockCount$1 = 0;
|
|
684
|
+
const supportsInert = () => typeof HTMLElement !== 'undefined' && 'inert' in HTMLElement.prototype;
|
|
685
|
+
const unwrapHost = node => node && (node.host || unwrapHost(node.parentNode));
|
|
686
|
+
const correctElements = (parent, targets) => targets.map(target => {
|
|
687
|
+
if (parent.contains(target)) {
|
|
688
|
+
return target;
|
|
689
|
+
}
|
|
690
|
+
const correctedTarget = unwrapHost(target);
|
|
691
|
+
if (parent.contains(correctedTarget)) {
|
|
692
|
+
return correctedTarget;
|
|
693
|
+
}
|
|
694
|
+
return null;
|
|
695
|
+
}).filter(x => x != null);
|
|
696
|
+
function applyAttributeToOthers(uncorrectedAvoidElements, body, ariaHidden, inert) {
|
|
697
|
+
const markerName = 'data-floating-ui-inert';
|
|
698
|
+
const controlAttribute = inert ? 'inert' : ariaHidden ? 'aria-hidden' : null;
|
|
699
|
+
const avoidElements = correctElements(body, uncorrectedAvoidElements);
|
|
700
|
+
const elementsToKeep = new Set();
|
|
701
|
+
const elementsToStop = new Set(avoidElements);
|
|
702
|
+
const hiddenElements = [];
|
|
703
|
+
if (!markerMap[markerName]) {
|
|
704
|
+
markerMap[markerName] = new WeakMap();
|
|
705
|
+
}
|
|
706
|
+
const markerCounter = markerMap[markerName];
|
|
707
|
+
avoidElements.forEach(keep);
|
|
708
|
+
deep(body);
|
|
709
|
+
elementsToKeep.clear();
|
|
710
|
+
function keep(el) {
|
|
711
|
+
if (!el || elementsToKeep.has(el)) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
elementsToKeep.add(el);
|
|
715
|
+
el.parentNode && keep(el.parentNode);
|
|
716
|
+
}
|
|
717
|
+
function deep(parent) {
|
|
718
|
+
if (!parent || elementsToStop.has(parent)) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
[].forEach.call(parent.children, node => {
|
|
722
|
+
if (getNodeName(node) === 'script') return;
|
|
723
|
+
if (elementsToKeep.has(node)) {
|
|
724
|
+
deep(node);
|
|
725
|
+
} else {
|
|
726
|
+
const attr = controlAttribute ? node.getAttribute(controlAttribute) : null;
|
|
727
|
+
const alreadyHidden = attr !== null && attr !== 'false';
|
|
728
|
+
const counterValue = (counterMap.get(node) || 0) + 1;
|
|
729
|
+
const markerValue = (markerCounter.get(node) || 0) + 1;
|
|
730
|
+
counterMap.set(node, counterValue);
|
|
731
|
+
markerCounter.set(node, markerValue);
|
|
732
|
+
hiddenElements.push(node);
|
|
733
|
+
if (counterValue === 1 && alreadyHidden) {
|
|
734
|
+
uncontrolledElementsSet.add(node);
|
|
735
|
+
}
|
|
736
|
+
if (markerValue === 1) {
|
|
737
|
+
node.setAttribute(markerName, '');
|
|
738
|
+
}
|
|
739
|
+
if (!alreadyHidden && controlAttribute) {
|
|
740
|
+
node.setAttribute(controlAttribute, 'true');
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
lockCount$1++;
|
|
746
|
+
return () => {
|
|
747
|
+
hiddenElements.forEach(element => {
|
|
748
|
+
const counterValue = (counterMap.get(element) || 0) - 1;
|
|
749
|
+
const markerValue = (markerCounter.get(element) || 0) - 1;
|
|
750
|
+
counterMap.set(element, counterValue);
|
|
751
|
+
markerCounter.set(element, markerValue);
|
|
752
|
+
if (!counterValue) {
|
|
753
|
+
if (!uncontrolledElementsSet.has(element) && controlAttribute) {
|
|
754
|
+
element.removeAttribute(controlAttribute);
|
|
755
|
+
}
|
|
756
|
+
uncontrolledElementsSet.delete(element);
|
|
757
|
+
}
|
|
758
|
+
if (!markerValue) {
|
|
759
|
+
element.removeAttribute(markerName);
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
lockCount$1--;
|
|
763
|
+
if (!lockCount$1) {
|
|
764
|
+
counterMap = new WeakMap();
|
|
765
|
+
counterMap = new WeakMap();
|
|
766
|
+
uncontrolledElementsSet = new WeakSet();
|
|
767
|
+
markerMap = {};
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function markOthers(avoidElements, ariaHidden, inert) {
|
|
772
|
+
if (ariaHidden === void 0) {
|
|
773
|
+
ariaHidden = false;
|
|
774
|
+
}
|
|
775
|
+
if (inert === void 0) {
|
|
776
|
+
inert = false;
|
|
777
|
+
}
|
|
778
|
+
const body = getDocument(avoidElements[0]).body;
|
|
779
|
+
return applyAttributeToOthers(avoidElements.concat(Array.from(body.querySelectorAll('[aria-live]'))), body, ariaHidden, inert);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const getTabbableOptions = () => ({
|
|
783
|
+
getShadowRoot: true,
|
|
784
|
+
displayCheck:
|
|
785
|
+
// JSDOM does not support the `tabbable` library. To solve this we can
|
|
786
|
+
// check if `ResizeObserver` is a real function (not polyfilled), which
|
|
787
|
+
// determines if the current environment is JSDOM-like.
|
|
788
|
+
typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
|
|
789
|
+
});
|
|
790
|
+
function getTabbableIn(container, direction) {
|
|
791
|
+
const allTabbable = tabbable(container, getTabbableOptions());
|
|
792
|
+
if (direction === 'prev') {
|
|
793
|
+
allTabbable.reverse();
|
|
794
|
+
}
|
|
795
|
+
const activeIndex = allTabbable.indexOf(activeElement(getDocument(container)));
|
|
796
|
+
const nextTabbableElements = allTabbable.slice(activeIndex + 1);
|
|
797
|
+
return nextTabbableElements[0];
|
|
798
|
+
}
|
|
799
|
+
function getNextTabbable() {
|
|
800
|
+
return getTabbableIn(document.body, 'next');
|
|
801
|
+
}
|
|
802
|
+
function getPreviousTabbable() {
|
|
803
|
+
return getTabbableIn(document.body, 'prev');
|
|
804
|
+
}
|
|
805
|
+
function isOutsideEvent(event, container) {
|
|
806
|
+
const containerElement = container || event.currentTarget;
|
|
807
|
+
const relatedTarget = event.relatedTarget;
|
|
808
|
+
return !relatedTarget || !contains(containerElement, relatedTarget);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
|
|
812
|
+
// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
|
|
813
|
+
|
|
814
|
+
const HIDDEN_STYLES = {
|
|
815
|
+
border: 0,
|
|
816
|
+
clip: 'rect(0 0 0 0)',
|
|
817
|
+
height: '1px',
|
|
818
|
+
margin: '-1px',
|
|
819
|
+
overflow: 'hidden',
|
|
820
|
+
padding: 0,
|
|
821
|
+
position: 'fixed',
|
|
822
|
+
whiteSpace: 'nowrap',
|
|
823
|
+
width: '1px',
|
|
824
|
+
top: 0,
|
|
825
|
+
left: 0
|
|
826
|
+
};
|
|
827
|
+
let timeoutId;
|
|
828
|
+
function setActiveElementOnTab(event) {
|
|
829
|
+
if (event.key === 'Tab') {
|
|
830
|
+
event.target;
|
|
831
|
+
clearTimeout(timeoutId);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
|
|
835
|
+
const [role, setRole] = React.useState();
|
|
836
|
+
index(() => {
|
|
837
|
+
if (isSafari()) {
|
|
838
|
+
// Unlike other screen readers such as NVDA and JAWS, the virtual cursor
|
|
839
|
+
// on VoiceOver does trigger the onFocus event, so we can use the focus
|
|
840
|
+
// trap element. On Safari, only buttons trigger the onFocus event.
|
|
841
|
+
// NB: "group" role in the Sandbox no longer appears to work, must be a
|
|
842
|
+
// button role.
|
|
843
|
+
setRole('button');
|
|
844
|
+
}
|
|
845
|
+
document.addEventListener('keydown', setActiveElementOnTab);
|
|
846
|
+
return () => {
|
|
847
|
+
document.removeEventListener('keydown', setActiveElementOnTab);
|
|
848
|
+
};
|
|
849
|
+
}, []);
|
|
850
|
+
const restProps = {
|
|
851
|
+
ref,
|
|
852
|
+
tabIndex: 0,
|
|
853
|
+
// Role is only for VoiceOver
|
|
854
|
+
role,
|
|
855
|
+
'aria-hidden': role ? undefined : true,
|
|
856
|
+
[createAttribute('focus-guard')]: '',
|
|
857
|
+
style: HIDDEN_STYLES
|
|
858
|
+
};
|
|
859
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, props, restProps));
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
const PortalContext = /*#__PURE__*/React.createContext(null);
|
|
863
|
+
const usePortalContext = () => React.useContext(PortalContext);
|
|
864
|
+
|
|
865
|
+
const FOCUSABLE_ATTRIBUTE = 'data-floating-ui-focusable';
|
|
866
|
+
function getFloatingFocusElement(floatingElement) {
|
|
867
|
+
if (!floatingElement) {
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
// Try to find the element that has `{...getFloatingProps()}` spread on it.
|
|
871
|
+
// This indicates the floating element is acting as a positioning wrapper, and
|
|
872
|
+
// so focus should be managed on the child element with the event handlers and
|
|
873
|
+
// aria props.
|
|
874
|
+
return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
const LIST_LIMIT = 20;
|
|
878
|
+
let previouslyFocusedElements = [];
|
|
879
|
+
function addPreviouslyFocusedElement(element) {
|
|
880
|
+
previouslyFocusedElements = previouslyFocusedElements.filter(el => el.isConnected);
|
|
881
|
+
let tabbableEl = element;
|
|
882
|
+
if (!tabbableEl || getNodeName(tabbableEl) === 'body') return;
|
|
883
|
+
if (!isTabbable(tabbableEl, getTabbableOptions())) {
|
|
884
|
+
const tabbableChild = tabbable(tabbableEl, getTabbableOptions())[0];
|
|
885
|
+
if (tabbableChild) {
|
|
886
|
+
tabbableEl = tabbableChild;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
previouslyFocusedElements.push(tabbableEl);
|
|
890
|
+
if (previouslyFocusedElements.length > LIST_LIMIT) {
|
|
891
|
+
previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
function getPreviouslyFocusedElement() {
|
|
895
|
+
return previouslyFocusedElements.slice().reverse().find(el => el.isConnected);
|
|
896
|
+
}
|
|
897
|
+
const VisuallyHiddenDismiss = /*#__PURE__*/React.forwardRef(function VisuallyHiddenDismiss(props, ref) {
|
|
898
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
899
|
+
type: "button",
|
|
900
|
+
ref: ref,
|
|
901
|
+
tabIndex: -1,
|
|
902
|
+
style: HIDDEN_STYLES
|
|
903
|
+
}));
|
|
904
|
+
});
|
|
905
|
+
/**
|
|
906
|
+
* Provides focus management for the floating element.
|
|
907
|
+
* @see https://floating-ui.com/docs/FloatingFocusManager
|
|
908
|
+
*/
|
|
909
|
+
function FloatingFocusManager(props) {
|
|
910
|
+
const {
|
|
911
|
+
context,
|
|
912
|
+
children,
|
|
913
|
+
disabled = false,
|
|
914
|
+
order = ['content'],
|
|
915
|
+
guards: _guards = true,
|
|
916
|
+
initialFocus = 0,
|
|
917
|
+
returnFocus = true,
|
|
918
|
+
restoreFocus = false,
|
|
919
|
+
modal = true,
|
|
920
|
+
visuallyHiddenDismiss = false,
|
|
921
|
+
closeOnFocusOut = true
|
|
922
|
+
} = props;
|
|
923
|
+
const {
|
|
924
|
+
open,
|
|
925
|
+
refs,
|
|
926
|
+
nodeId,
|
|
927
|
+
onOpenChange,
|
|
928
|
+
events,
|
|
929
|
+
dataRef,
|
|
930
|
+
floatingId,
|
|
931
|
+
elements: {
|
|
932
|
+
domReference,
|
|
933
|
+
floating
|
|
934
|
+
}
|
|
935
|
+
} = context;
|
|
936
|
+
const ignoreInitialFocus = typeof initialFocus === 'number' && initialFocus < 0;
|
|
937
|
+
// If the reference is a combobox and is typeable (e.g. input/textarea),
|
|
938
|
+
// there are different focus semantics. The guards should not be rendered, but
|
|
939
|
+
// aria-hidden should be applied to all nodes still. Further, the visually
|
|
940
|
+
// hidden dismiss button should only appear at the end of the list, not the
|
|
941
|
+
// start.
|
|
942
|
+
const isUntrappedTypeableCombobox = isTypeableCombobox(domReference) && ignoreInitialFocus;
|
|
943
|
+
|
|
944
|
+
// Force the guards to be rendered if the `inert` attribute is not supported.
|
|
945
|
+
const guards = supportsInert() ? _guards : true;
|
|
946
|
+
const orderRef = useLatestRef(order);
|
|
947
|
+
const initialFocusRef = useLatestRef(initialFocus);
|
|
948
|
+
const returnFocusRef = useLatestRef(returnFocus);
|
|
949
|
+
const tree = useFloatingTree();
|
|
950
|
+
const portalContext = usePortalContext();
|
|
951
|
+
const startDismissButtonRef = React.useRef(null);
|
|
952
|
+
const endDismissButtonRef = React.useRef(null);
|
|
953
|
+
const preventReturnFocusRef = React.useRef(false);
|
|
954
|
+
const isPointerDownRef = React.useRef(false);
|
|
955
|
+
const tabbableIndexRef = React.useRef(-1);
|
|
956
|
+
const isInsidePortal = portalContext != null;
|
|
957
|
+
const floatingFocusElement = getFloatingFocusElement(floating);
|
|
958
|
+
const getTabbableContent = useEffectEvent(function (container) {
|
|
959
|
+
if (container === void 0) {
|
|
960
|
+
container = floatingFocusElement;
|
|
961
|
+
}
|
|
962
|
+
return container ? tabbable(container, getTabbableOptions()) : [];
|
|
963
|
+
});
|
|
964
|
+
const getTabbableElements = useEffectEvent(container => {
|
|
965
|
+
const content = getTabbableContent(container);
|
|
966
|
+
return orderRef.current.map(type => {
|
|
967
|
+
if (domReference && type === 'reference') {
|
|
968
|
+
return domReference;
|
|
969
|
+
}
|
|
970
|
+
if (floatingFocusElement && type === 'floating') {
|
|
971
|
+
return floatingFocusElement;
|
|
972
|
+
}
|
|
973
|
+
return content;
|
|
974
|
+
}).filter(Boolean).flat();
|
|
975
|
+
});
|
|
976
|
+
React.useEffect(() => {
|
|
977
|
+
if (disabled) return;
|
|
978
|
+
if (!modal) return;
|
|
979
|
+
function onKeyDown(event) {
|
|
980
|
+
if (event.key === 'Tab') {
|
|
981
|
+
// The focus guards have nothing to focus, so we need to stop the event.
|
|
982
|
+
if (contains(floatingFocusElement, activeElement(getDocument(floatingFocusElement))) && getTabbableContent().length === 0 && !isUntrappedTypeableCombobox) {
|
|
983
|
+
stopEvent(event);
|
|
984
|
+
}
|
|
985
|
+
const els = getTabbableElements();
|
|
986
|
+
const target = getTarget(event);
|
|
987
|
+
if (orderRef.current[0] === 'reference' && target === domReference) {
|
|
988
|
+
stopEvent(event);
|
|
989
|
+
if (event.shiftKey) {
|
|
990
|
+
enqueueFocus(els[els.length - 1]);
|
|
991
|
+
} else {
|
|
992
|
+
enqueueFocus(els[1]);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (orderRef.current[1] === 'floating' && target === floatingFocusElement && event.shiftKey) {
|
|
996
|
+
stopEvent(event);
|
|
997
|
+
enqueueFocus(els[0]);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
const doc = getDocument(floatingFocusElement);
|
|
1002
|
+
doc.addEventListener('keydown', onKeyDown);
|
|
1003
|
+
return () => {
|
|
1004
|
+
doc.removeEventListener('keydown', onKeyDown);
|
|
1005
|
+
};
|
|
1006
|
+
}, [disabled, domReference, floatingFocusElement, modal, orderRef, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
|
|
1007
|
+
React.useEffect(() => {
|
|
1008
|
+
if (disabled) return;
|
|
1009
|
+
if (!floating) return;
|
|
1010
|
+
function handleFocusIn(event) {
|
|
1011
|
+
const target = getTarget(event);
|
|
1012
|
+
const tabbableContent = getTabbableContent();
|
|
1013
|
+
const tabbableIndex = tabbableContent.indexOf(target);
|
|
1014
|
+
if (tabbableIndex !== -1) {
|
|
1015
|
+
tabbableIndexRef.current = tabbableIndex;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
floating.addEventListener('focusin', handleFocusIn);
|
|
1019
|
+
return () => {
|
|
1020
|
+
floating.removeEventListener('focusin', handleFocusIn);
|
|
1021
|
+
};
|
|
1022
|
+
}, [disabled, floating, getTabbableContent]);
|
|
1023
|
+
React.useEffect(() => {
|
|
1024
|
+
if (disabled) return;
|
|
1025
|
+
if (!closeOnFocusOut) return;
|
|
1026
|
+
|
|
1027
|
+
// In Safari, buttons lose focus when pressing them.
|
|
1028
|
+
function handlePointerDown() {
|
|
1029
|
+
isPointerDownRef.current = true;
|
|
1030
|
+
setTimeout(() => {
|
|
1031
|
+
isPointerDownRef.current = false;
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
function handleFocusOutside(event) {
|
|
1035
|
+
const relatedTarget = event.relatedTarget;
|
|
1036
|
+
queueMicrotask(() => {
|
|
1037
|
+
const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute(createAttribute('focus-guard')) || tree && (getChildren(tree.nodesRef.current, nodeId).find(node => {
|
|
1038
|
+
var _node$context, _node$context2;
|
|
1039
|
+
return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
|
|
1040
|
+
}) || getAncestors(tree.nodesRef.current, nodeId).find(node => {
|
|
1041
|
+
var _node$context3, _node$context4;
|
|
1042
|
+
return ((_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating) === relatedTarget || ((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.domReference) === relatedTarget;
|
|
1043
|
+
})));
|
|
1044
|
+
|
|
1045
|
+
// Restore focus to the previous tabbable element index to prevent
|
|
1046
|
+
// focus from being lost outside the floating tree.
|
|
1047
|
+
if (restoreFocus && movedToUnrelatedNode && activeElement(getDocument(floatingFocusElement)) === getDocument(floatingFocusElement).body) {
|
|
1048
|
+
// Let `FloatingPortal` effect knows that focus is still inside the
|
|
1049
|
+
// floating tree.
|
|
1050
|
+
if (isHTMLElement(floatingFocusElement)) {
|
|
1051
|
+
floatingFocusElement.focus();
|
|
1052
|
+
}
|
|
1053
|
+
const prevTabbableIndex = tabbableIndexRef.current;
|
|
1054
|
+
const tabbableContent = getTabbableContent();
|
|
1055
|
+
const nodeToFocus = tabbableContent[prevTabbableIndex] || tabbableContent[tabbableContent.length - 1] || floatingFocusElement;
|
|
1056
|
+
if (isHTMLElement(nodeToFocus)) {
|
|
1057
|
+
nodeToFocus.focus();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// Focus did not move inside the floating tree, and there are no tabbable
|
|
1062
|
+
// portal guards to handle closing.
|
|
1063
|
+
if ((isUntrappedTypeableCombobox ? true : !modal) && relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current &&
|
|
1064
|
+
// Fix React 18 Strict Mode returnFocus due to double rendering.
|
|
1065
|
+
relatedTarget !== getPreviouslyFocusedElement()) {
|
|
1066
|
+
preventReturnFocusRef.current = true;
|
|
1067
|
+
onOpenChange(false, event, 'focus-out');
|
|
1068
|
+
}
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
if (floating && isHTMLElement(domReference)) {
|
|
1072
|
+
domReference.addEventListener('focusout', handleFocusOutside);
|
|
1073
|
+
domReference.addEventListener('pointerdown', handlePointerDown);
|
|
1074
|
+
floating.addEventListener('focusout', handleFocusOutside);
|
|
1075
|
+
return () => {
|
|
1076
|
+
domReference.removeEventListener('focusout', handleFocusOutside);
|
|
1077
|
+
domReference.removeEventListener('pointerdown', handlePointerDown);
|
|
1078
|
+
floating.removeEventListener('focusout', handleFocusOutside);
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
}, [disabled, domReference, floating, floatingFocusElement, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut, restoreFocus, getTabbableContent, isUntrappedTypeableCombobox]);
|
|
1082
|
+
React.useEffect(() => {
|
|
1083
|
+
var _portalContext$portal;
|
|
1084
|
+
if (disabled) return;
|
|
1085
|
+
|
|
1086
|
+
// Don't hide portals nested within the parent portal.
|
|
1087
|
+
const portalNodes = Array.from((portalContext == null || (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll("[" + createAttribute('portal') + "]")) || []);
|
|
1088
|
+
if (floating) {
|
|
1089
|
+
const insideElements = [floating, ...portalNodes, startDismissButtonRef.current, endDismissButtonRef.current, orderRef.current.includes('reference') || isUntrappedTypeableCombobox ? domReference : null].filter(x => x != null);
|
|
1090
|
+
const cleanup = modal || isUntrappedTypeableCombobox ? markOthers(insideElements, guards, !guards) : markOthers(insideElements);
|
|
1091
|
+
return () => {
|
|
1092
|
+
cleanup();
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
}, [disabled, domReference, floating, modal, orderRef, portalContext, isUntrappedTypeableCombobox, guards]);
|
|
1096
|
+
index(() => {
|
|
1097
|
+
if (disabled || !isHTMLElement(floatingFocusElement)) return;
|
|
1098
|
+
const doc = getDocument(floatingFocusElement);
|
|
1099
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
1100
|
+
|
|
1101
|
+
// Wait for any layout effect state setters to execute to set `tabIndex`.
|
|
1102
|
+
queueMicrotask(() => {
|
|
1103
|
+
const focusableElements = getTabbableElements(floatingFocusElement);
|
|
1104
|
+
const initialFocusValue = initialFocusRef.current;
|
|
1105
|
+
const elToFocus = (typeof initialFocusValue === 'number' ? focusableElements[initialFocusValue] : initialFocusValue.current) || floatingFocusElement;
|
|
1106
|
+
const focusAlreadyInsideFloatingEl = contains(floatingFocusElement, previouslyFocusedElement);
|
|
1107
|
+
if (!ignoreInitialFocus && !focusAlreadyInsideFloatingEl && open) {
|
|
1108
|
+
enqueueFocus(elToFocus, {
|
|
1109
|
+
preventScroll: elToFocus === floatingFocusElement
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
}, [disabled, open, floatingFocusElement, ignoreInitialFocus, getTabbableElements, initialFocusRef]);
|
|
1114
|
+
index(() => {
|
|
1115
|
+
if (disabled || !floatingFocusElement) return;
|
|
1116
|
+
let preventReturnFocusScroll = false;
|
|
1117
|
+
const doc = getDocument(floatingFocusElement);
|
|
1118
|
+
const previouslyFocusedElement = activeElement(doc);
|
|
1119
|
+
const contextData = dataRef.current;
|
|
1120
|
+
let openEvent = contextData.openEvent;
|
|
1121
|
+
addPreviouslyFocusedElement(previouslyFocusedElement);
|
|
1122
|
+
|
|
1123
|
+
// Dismissing via outside press should always ignore `returnFocus` to
|
|
1124
|
+
// prevent unwanted scrolling.
|
|
1125
|
+
function onOpenChange(_ref) {
|
|
1126
|
+
let {
|
|
1127
|
+
open,
|
|
1128
|
+
reason,
|
|
1129
|
+
event,
|
|
1130
|
+
nested
|
|
1131
|
+
} = _ref;
|
|
1132
|
+
if (open) {
|
|
1133
|
+
openEvent = event;
|
|
1134
|
+
}
|
|
1135
|
+
if (reason === 'escape-key' && refs.domReference.current) {
|
|
1136
|
+
addPreviouslyFocusedElement(refs.domReference.current);
|
|
1137
|
+
}
|
|
1138
|
+
if (reason === 'hover' && event.type === 'mouseleave') {
|
|
1139
|
+
preventReturnFocusRef.current = true;
|
|
1140
|
+
}
|
|
1141
|
+
if (reason !== 'outside-press') return;
|
|
1142
|
+
if (nested) {
|
|
1143
|
+
preventReturnFocusRef.current = false;
|
|
1144
|
+
preventReturnFocusScroll = true;
|
|
1145
|
+
} else {
|
|
1146
|
+
preventReturnFocusRef.current = !(isVirtualClick(event) || isVirtualPointerEvent(event));
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
events.on('openchange', onOpenChange);
|
|
1150
|
+
const fallbackEl = doc.createElement('span');
|
|
1151
|
+
fallbackEl.setAttribute('tabindex', '-1');
|
|
1152
|
+
fallbackEl.setAttribute('aria-hidden', 'true');
|
|
1153
|
+
Object.assign(fallbackEl.style, HIDDEN_STYLES);
|
|
1154
|
+
if (isInsidePortal && domReference) {
|
|
1155
|
+
domReference.insertAdjacentElement('afterend', fallbackEl);
|
|
1156
|
+
}
|
|
1157
|
+
function getReturnElement() {
|
|
1158
|
+
if (typeof returnFocusRef.current === 'boolean') {
|
|
1159
|
+
return getPreviouslyFocusedElement() || fallbackEl;
|
|
1160
|
+
}
|
|
1161
|
+
return returnFocusRef.current.current || fallbackEl;
|
|
1162
|
+
}
|
|
1163
|
+
return () => {
|
|
1164
|
+
events.off('openchange', onOpenChange);
|
|
1165
|
+
const activeEl = activeElement(doc);
|
|
1166
|
+
const isFocusInsideFloatingTree = contains(floating, activeEl) || tree && getChildren(tree.nodesRef.current, nodeId).some(node => {
|
|
1167
|
+
var _node$context5;
|
|
1168
|
+
return contains((_node$context5 = node.context) == null ? void 0 : _node$context5.elements.floating, activeEl);
|
|
1169
|
+
});
|
|
1170
|
+
const shouldFocusReference = isFocusInsideFloatingTree || openEvent && ['click', 'mousedown'].includes(openEvent.type);
|
|
1171
|
+
if (shouldFocusReference && refs.domReference.current) {
|
|
1172
|
+
addPreviouslyFocusedElement(refs.domReference.current);
|
|
1173
|
+
}
|
|
1174
|
+
const returnElement = getReturnElement();
|
|
1175
|
+
queueMicrotask(() => {
|
|
1176
|
+
if (
|
|
1177
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1178
|
+
returnFocusRef.current && !preventReturnFocusRef.current && isHTMLElement(returnElement) && (
|
|
1179
|
+
// If the focus moved somewhere else after mount, avoid returning focus
|
|
1180
|
+
// since it likely entered a different element which should be
|
|
1181
|
+
// respected: https://github.com/floating-ui/floating-ui/issues/2607
|
|
1182
|
+
returnElement !== activeEl && activeEl !== doc.body ? isFocusInsideFloatingTree : true)) {
|
|
1183
|
+
returnElement.focus({
|
|
1184
|
+
preventScroll: preventReturnFocusScroll
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
fallbackEl.remove();
|
|
1188
|
+
});
|
|
1189
|
+
};
|
|
1190
|
+
}, [disabled, floating, floatingFocusElement, returnFocusRef, dataRef, refs, events, tree, nodeId, isInsidePortal, domReference]);
|
|
1191
|
+
React.useEffect(() => {
|
|
1192
|
+
// The `returnFocus` cleanup behavior is inside a microtask; ensure we
|
|
1193
|
+
// wait for it to complete before resetting the flag.
|
|
1194
|
+
queueMicrotask(() => {
|
|
1195
|
+
preventReturnFocusRef.current = false;
|
|
1196
|
+
});
|
|
1197
|
+
}, [disabled]);
|
|
1198
|
+
|
|
1199
|
+
// Synchronize the `context` & `modal` value to the FloatingPortal context.
|
|
1200
|
+
// It will decide whether or not it needs to render its own guards.
|
|
1201
|
+
index(() => {
|
|
1202
|
+
if (disabled) return;
|
|
1203
|
+
if (!portalContext) return;
|
|
1204
|
+
portalContext.setFocusManagerState({
|
|
1205
|
+
modal,
|
|
1206
|
+
closeOnFocusOut,
|
|
1207
|
+
open,
|
|
1208
|
+
onOpenChange,
|
|
1209
|
+
refs
|
|
1210
|
+
});
|
|
1211
|
+
return () => {
|
|
1212
|
+
portalContext.setFocusManagerState(null);
|
|
1213
|
+
};
|
|
1214
|
+
}, [disabled, portalContext, modal, open, onOpenChange, refs, closeOnFocusOut]);
|
|
1215
|
+
index(() => {
|
|
1216
|
+
if (disabled) return;
|
|
1217
|
+
if (!floatingFocusElement) return;
|
|
1218
|
+
if (typeof MutationObserver !== 'function') return;
|
|
1219
|
+
if (ignoreInitialFocus) return;
|
|
1220
|
+
const handleMutation = () => {
|
|
1221
|
+
const tabIndex = floatingFocusElement.getAttribute('tabindex');
|
|
1222
|
+
const tabbableContent = getTabbableContent();
|
|
1223
|
+
const activeEl = activeElement(getDocument(floating));
|
|
1224
|
+
const tabbableIndex = tabbableContent.indexOf(activeEl);
|
|
1225
|
+
if (tabbableIndex !== -1) {
|
|
1226
|
+
tabbableIndexRef.current = tabbableIndex;
|
|
1227
|
+
}
|
|
1228
|
+
if (orderRef.current.includes('floating') || activeEl !== refs.domReference.current && tabbableContent.length === 0) {
|
|
1229
|
+
if (tabIndex !== '0') {
|
|
1230
|
+
floatingFocusElement.setAttribute('tabindex', '0');
|
|
1231
|
+
}
|
|
1232
|
+
} else if (tabIndex !== '-1') {
|
|
1233
|
+
floatingFocusElement.setAttribute('tabindex', '-1');
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
handleMutation();
|
|
1237
|
+
const observer = new MutationObserver(handleMutation);
|
|
1238
|
+
observer.observe(floatingFocusElement, {
|
|
1239
|
+
childList: true,
|
|
1240
|
+
subtree: true,
|
|
1241
|
+
attributes: true
|
|
1242
|
+
});
|
|
1243
|
+
return () => {
|
|
1244
|
+
observer.disconnect();
|
|
1245
|
+
};
|
|
1246
|
+
}, [disabled, floating, floatingFocusElement, refs, orderRef, getTabbableContent, ignoreInitialFocus]);
|
|
1247
|
+
function renderDismissButton(location) {
|
|
1248
|
+
if (disabled || !visuallyHiddenDismiss || !modal) {
|
|
1249
|
+
return null;
|
|
1250
|
+
}
|
|
1251
|
+
return /*#__PURE__*/React.createElement(VisuallyHiddenDismiss, {
|
|
1252
|
+
ref: location === 'start' ? startDismissButtonRef : endDismissButtonRef,
|
|
1253
|
+
onClick: event => onOpenChange(false, event.nativeEvent)
|
|
1254
|
+
}, typeof visuallyHiddenDismiss === 'string' ? visuallyHiddenDismiss : 'Dismiss');
|
|
1255
|
+
}
|
|
1256
|
+
const shouldRenderGuards = !disabled && guards && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
1257
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, shouldRenderGuards && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
1258
|
+
"data-type": "inside",
|
|
1259
|
+
ref: portalContext == null ? void 0 : portalContext.beforeInsideRef,
|
|
1260
|
+
onFocus: event => {
|
|
1261
|
+
if (modal) {
|
|
1262
|
+
const els = getTabbableElements();
|
|
1263
|
+
enqueueFocus(order[0] === 'reference' ? els[0] : els[els.length - 1]);
|
|
1264
|
+
} else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
|
|
1265
|
+
preventReturnFocusRef.current = false;
|
|
1266
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
1267
|
+
const nextTabbable = getNextTabbable() || domReference;
|
|
1268
|
+
nextTabbable == null || nextTabbable.focus();
|
|
1269
|
+
} else {
|
|
1270
|
+
var _portalContext$before;
|
|
1271
|
+
(_portalContext$before = portalContext.beforeOutsideRef.current) == null || _portalContext$before.focus();
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}), !isUntrappedTypeableCombobox && renderDismissButton('start'), children, renderDismissButton('end'), shouldRenderGuards && /*#__PURE__*/React.createElement(FocusGuard, {
|
|
1276
|
+
"data-type": "inside",
|
|
1277
|
+
ref: portalContext == null ? void 0 : portalContext.afterInsideRef,
|
|
1278
|
+
onFocus: event => {
|
|
1279
|
+
if (modal) {
|
|
1280
|
+
enqueueFocus(getTabbableElements()[0]);
|
|
1281
|
+
} else if (portalContext != null && portalContext.preserveTabOrder && portalContext.portalNode) {
|
|
1282
|
+
if (closeOnFocusOut) {
|
|
1283
|
+
preventReturnFocusRef.current = true;
|
|
1284
|
+
}
|
|
1285
|
+
if (isOutsideEvent(event, portalContext.portalNode)) {
|
|
1286
|
+
const prevTabbable = getPreviousTabbable() || domReference;
|
|
1287
|
+
prevTabbable == null || prevTabbable.focus();
|
|
1288
|
+
} else {
|
|
1289
|
+
var _portalContext$afterO;
|
|
1290
|
+
(_portalContext$afterO = portalContext.afterOutsideRef.current) == null || _portalContext$afterO.focus();
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}));
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function isButtonTarget(event) {
|
|
1298
|
+
return isHTMLElement(event.target) && event.target.tagName === 'BUTTON';
|
|
1299
|
+
}
|
|
1300
|
+
function isSpaceIgnored(element) {
|
|
1301
|
+
return isTypeableElement(element);
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Opens or closes the floating element when clicking the reference element.
|
|
1305
|
+
* @see https://floating-ui.com/docs/useClick
|
|
1306
|
+
*/
|
|
1307
|
+
function useClick(context, props) {
|
|
1308
|
+
if (props === void 0) {
|
|
1309
|
+
props = {};
|
|
1310
|
+
}
|
|
1311
|
+
const {
|
|
1312
|
+
open,
|
|
1313
|
+
onOpenChange,
|
|
1314
|
+
dataRef,
|
|
1315
|
+
elements: {
|
|
1316
|
+
domReference
|
|
1317
|
+
}
|
|
1318
|
+
} = context;
|
|
1319
|
+
const {
|
|
1320
|
+
enabled = true,
|
|
1321
|
+
event: eventOption = 'click',
|
|
1322
|
+
toggle = true,
|
|
1323
|
+
ignoreMouse = false,
|
|
1324
|
+
keyboardHandlers = true,
|
|
1325
|
+
stickIfOpen = true
|
|
1326
|
+
} = props;
|
|
1327
|
+
const pointerTypeRef = React.useRef();
|
|
1328
|
+
const didKeyDownRef = React.useRef(false);
|
|
1329
|
+
const reference = React.useMemo(() => ({
|
|
1330
|
+
onPointerDown(event) {
|
|
1331
|
+
pointerTypeRef.current = event.pointerType;
|
|
1332
|
+
},
|
|
1333
|
+
onMouseDown(event) {
|
|
1334
|
+
const pointerType = pointerTypeRef.current;
|
|
1335
|
+
|
|
1336
|
+
// Ignore all buttons except for the "main" button.
|
|
1337
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
1338
|
+
if (event.button !== 0) return;
|
|
1339
|
+
if (eventOption === 'click') return;
|
|
1340
|
+
if (isMouseLikePointerType(pointerType, true) && ignoreMouse) return;
|
|
1341
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === 'mousedown' : true)) {
|
|
1342
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
1343
|
+
} else {
|
|
1344
|
+
// Prevent stealing focus from the floating element
|
|
1345
|
+
event.preventDefault();
|
|
1346
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
1347
|
+
}
|
|
1348
|
+
},
|
|
1349
|
+
onClick(event) {
|
|
1350
|
+
const pointerType = pointerTypeRef.current;
|
|
1351
|
+
if (eventOption === 'mousedown' && pointerTypeRef.current) {
|
|
1352
|
+
pointerTypeRef.current = undefined;
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
if (isMouseLikePointerType(pointerType, true) && ignoreMouse) return;
|
|
1356
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === 'click' : true)) {
|
|
1357
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
1358
|
+
} else {
|
|
1359
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
onKeyDown(event) {
|
|
1363
|
+
pointerTypeRef.current = undefined;
|
|
1364
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (event.key === ' ' && !isSpaceIgnored(domReference)) {
|
|
1368
|
+
// Prevent scrolling
|
|
1369
|
+
event.preventDefault();
|
|
1370
|
+
didKeyDownRef.current = true;
|
|
1371
|
+
}
|
|
1372
|
+
if (event.key === 'Enter') {
|
|
1373
|
+
if (open && toggle) {
|
|
1374
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
1375
|
+
} else {
|
|
1376
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
},
|
|
1380
|
+
onKeyUp(event) {
|
|
1381
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference)) {
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1384
|
+
if (event.key === ' ' && didKeyDownRef.current) {
|
|
1385
|
+
didKeyDownRef.current = false;
|
|
1386
|
+
if (open && toggle) {
|
|
1387
|
+
onOpenChange(false, event.nativeEvent, 'click');
|
|
1388
|
+
} else {
|
|
1389
|
+
onOpenChange(true, event.nativeEvent, 'click');
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
}), [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, stickIfOpen, toggle]);
|
|
1394
|
+
return React.useMemo(() => enabled ? {
|
|
1395
|
+
reference
|
|
1396
|
+
} : {}, [enabled, reference]);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
const bubbleHandlerKeys = {
|
|
1400
|
+
pointerdown: 'onPointerDown',
|
|
1401
|
+
mousedown: 'onMouseDown',
|
|
1402
|
+
click: 'onClick'
|
|
1403
|
+
};
|
|
1404
|
+
const captureHandlerKeys = {
|
|
1405
|
+
pointerdown: 'onPointerDownCapture',
|
|
1406
|
+
mousedown: 'onMouseDownCapture',
|
|
1407
|
+
click: 'onClickCapture'
|
|
1408
|
+
};
|
|
1409
|
+
const normalizeProp = normalizable => {
|
|
1410
|
+
var _normalizable$escapeK, _normalizable$outside;
|
|
1411
|
+
return {
|
|
1412
|
+
escapeKey: typeof normalizable === 'boolean' ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
|
|
1413
|
+
outsidePress: typeof normalizable === 'boolean' ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
|
|
1414
|
+
};
|
|
1415
|
+
};
|
|
1416
|
+
/**
|
|
1417
|
+
* Closes the floating element when a dismissal is requested — by default, when
|
|
1418
|
+
* the user presses the `escape` key or outside of the floating element.
|
|
1419
|
+
* @see https://floating-ui.com/docs/useDismiss
|
|
1420
|
+
*/
|
|
1421
|
+
function useDismiss(context, props) {
|
|
1422
|
+
if (props === void 0) {
|
|
1423
|
+
props = {};
|
|
1424
|
+
}
|
|
1425
|
+
const {
|
|
1426
|
+
open,
|
|
1427
|
+
onOpenChange,
|
|
1428
|
+
elements,
|
|
1429
|
+
dataRef
|
|
1430
|
+
} = context;
|
|
1431
|
+
const {
|
|
1432
|
+
enabled = true,
|
|
1433
|
+
escapeKey = true,
|
|
1434
|
+
outsidePress: unstable_outsidePress = true,
|
|
1435
|
+
outsidePressEvent = 'pointerdown',
|
|
1436
|
+
referencePress = false,
|
|
1437
|
+
referencePressEvent = 'pointerdown',
|
|
1438
|
+
ancestorScroll = false,
|
|
1439
|
+
bubbles,
|
|
1440
|
+
capture
|
|
1441
|
+
} = props;
|
|
1442
|
+
const tree = useFloatingTree();
|
|
1443
|
+
const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
|
|
1444
|
+
const outsidePress = typeof unstable_outsidePress === 'function' ? outsidePressFn : unstable_outsidePress;
|
|
1445
|
+
const insideReactTreeRef = React.useRef(false);
|
|
1446
|
+
const endedOrStartedInsideRef = React.useRef(false);
|
|
1447
|
+
const {
|
|
1448
|
+
escapeKey: escapeKeyBubbles,
|
|
1449
|
+
outsidePress: outsidePressBubbles
|
|
1450
|
+
} = normalizeProp(bubbles);
|
|
1451
|
+
const {
|
|
1452
|
+
escapeKey: escapeKeyCapture,
|
|
1453
|
+
outsidePress: outsidePressCapture
|
|
1454
|
+
} = normalizeProp(capture);
|
|
1455
|
+
const isComposingRef = React.useRef(false);
|
|
1456
|
+
const closeOnEscapeKeyDown = useEffectEvent(event => {
|
|
1457
|
+
var _dataRef$current$floa;
|
|
1458
|
+
if (!open || !enabled || !escapeKey || event.key !== 'Escape') {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// Wait until IME is settled. Pressing `Escape` while composing should
|
|
1463
|
+
// close the compose menu, but not the floating element.
|
|
1464
|
+
if (isComposingRef.current) {
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
|
|
1468
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
1469
|
+
if (!escapeKeyBubbles) {
|
|
1470
|
+
event.stopPropagation();
|
|
1471
|
+
if (children.length > 0) {
|
|
1472
|
+
let shouldDismiss = true;
|
|
1473
|
+
children.forEach(child => {
|
|
1474
|
+
var _child$context;
|
|
1475
|
+
if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
|
|
1476
|
+
shouldDismiss = false;
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
if (!shouldDismiss) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, 'escape-key');
|
|
1486
|
+
});
|
|
1487
|
+
const closeOnEscapeKeyDownCapture = useEffectEvent(event => {
|
|
1488
|
+
var _getTarget2;
|
|
1489
|
+
const callback = () => {
|
|
1490
|
+
var _getTarget;
|
|
1491
|
+
closeOnEscapeKeyDown(event);
|
|
1492
|
+
(_getTarget = getTarget(event)) == null || _getTarget.removeEventListener('keydown', callback);
|
|
1493
|
+
};
|
|
1494
|
+
(_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener('keydown', callback);
|
|
1495
|
+
});
|
|
1496
|
+
const closeOnPressOutside = useEffectEvent(event => {
|
|
1497
|
+
var _dataRef$current$floa2;
|
|
1498
|
+
// Given developers can stop the propagation of the synthetic event,
|
|
1499
|
+
// we can only be confident with a positive value.
|
|
1500
|
+
const insideReactTree = insideReactTreeRef.current;
|
|
1501
|
+
insideReactTreeRef.current = false;
|
|
1502
|
+
|
|
1503
|
+
// When click outside is lazy (`click` event), handle dragging.
|
|
1504
|
+
// Don't close if:
|
|
1505
|
+
// - The click started inside the floating element.
|
|
1506
|
+
// - The click ended inside the floating element.
|
|
1507
|
+
const endedOrStartedInside = endedOrStartedInsideRef.current;
|
|
1508
|
+
endedOrStartedInsideRef.current = false;
|
|
1509
|
+
if (outsidePressEvent === 'click' && endedOrStartedInside) {
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
if (insideReactTree) {
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
if (typeof outsidePress === 'function' && !outsidePress(event)) {
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
const target = getTarget(event);
|
|
1519
|
+
const inertSelector = "[" + createAttribute('inert') + "]";
|
|
1520
|
+
const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
|
|
1521
|
+
let targetRootAncestor = isElement(target) ? target : null;
|
|
1522
|
+
while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
|
|
1523
|
+
const nextParent = getParentNode(targetRootAncestor);
|
|
1524
|
+
if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
|
|
1525
|
+
break;
|
|
1526
|
+
}
|
|
1527
|
+
targetRootAncestor = nextParent;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// Check if the click occurred on a third-party element injected after the
|
|
1531
|
+
// floating element rendered.
|
|
1532
|
+
if (markers.length && isElement(target) && !isRootElement(target) &&
|
|
1533
|
+
// Clicked on a direct ancestor (e.g. FloatingOverlay).
|
|
1534
|
+
!contains(target, elements.floating) &&
|
|
1535
|
+
// If the target root element contains none of the markers, then the
|
|
1536
|
+
// element was injected after the floating element rendered.
|
|
1537
|
+
Array.from(markers).every(marker => !contains(targetRootAncestor, marker))) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
// Check if the click occurred on the scrollbar
|
|
1542
|
+
if (isHTMLElement(target) && floating) {
|
|
1543
|
+
// In Firefox, `target.scrollWidth > target.clientWidth` for inline
|
|
1544
|
+
// elements.
|
|
1545
|
+
const canScrollX = target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
|
|
1546
|
+
const canScrollY = target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
|
|
1547
|
+
let xCond = canScrollY && event.offsetX > target.clientWidth;
|
|
1548
|
+
|
|
1549
|
+
// In some browsers it is possible to change the <body> (or window)
|
|
1550
|
+
// scrollbar to the left side, but is very rare and is difficult to
|
|
1551
|
+
// check for. Plus, for modal dialogs with backdrops, it is more
|
|
1552
|
+
// important that the backdrop is checked but not so much the window.
|
|
1553
|
+
if (canScrollY) {
|
|
1554
|
+
const isRTL = getComputedStyle(target).direction === 'rtl';
|
|
1555
|
+
if (isRTL) {
|
|
1556
|
+
xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
if (xCond || canScrollX && event.offsetY > target.clientHeight) {
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
|
|
1564
|
+
const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some(node => {
|
|
1565
|
+
var _node$context;
|
|
1566
|
+
return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
|
|
1567
|
+
});
|
|
1568
|
+
if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
|
|
1572
|
+
if (children.length > 0) {
|
|
1573
|
+
let shouldDismiss = true;
|
|
1574
|
+
children.forEach(child => {
|
|
1575
|
+
var _child$context2;
|
|
1576
|
+
if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
|
|
1577
|
+
shouldDismiss = false;
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
});
|
|
1581
|
+
if (!shouldDismiss) {
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
onOpenChange(false, event, 'outside-press');
|
|
1586
|
+
});
|
|
1587
|
+
const closeOnPressOutsideCapture = useEffectEvent(event => {
|
|
1588
|
+
var _getTarget4;
|
|
1589
|
+
const callback = () => {
|
|
1590
|
+
var _getTarget3;
|
|
1591
|
+
closeOnPressOutside(event);
|
|
1592
|
+
(_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
|
|
1593
|
+
};
|
|
1594
|
+
(_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
|
|
1595
|
+
});
|
|
1596
|
+
React.useEffect(() => {
|
|
1597
|
+
if (!open || !enabled) {
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
|
|
1601
|
+
dataRef.current.__outsidePressBubbles = outsidePressBubbles;
|
|
1602
|
+
let compositionTimeout = -1;
|
|
1603
|
+
function onScroll(event) {
|
|
1604
|
+
onOpenChange(false, event, 'ancestor-scroll');
|
|
1605
|
+
}
|
|
1606
|
+
function handleCompositionStart() {
|
|
1607
|
+
window.clearTimeout(compositionTimeout);
|
|
1608
|
+
isComposingRef.current = true;
|
|
1609
|
+
}
|
|
1610
|
+
function handleCompositionEnd() {
|
|
1611
|
+
// Safari fires `compositionend` before `keydown`, so we need to wait
|
|
1612
|
+
// until the next tick to set `isComposing` to `false`.
|
|
1613
|
+
// https://bugs.webkit.org/show_bug.cgi?id=165004
|
|
1614
|
+
compositionTimeout = window.setTimeout(() => {
|
|
1615
|
+
isComposingRef.current = false;
|
|
1616
|
+
},
|
|
1617
|
+
// 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
|
|
1618
|
+
// Only apply to WebKit for the test to remain 0ms.
|
|
1619
|
+
isWebKit() ? 5 : 0);
|
|
1620
|
+
}
|
|
1621
|
+
const doc = getDocument(elements.floating);
|
|
1622
|
+
if (escapeKey) {
|
|
1623
|
+
doc.addEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1624
|
+
doc.addEventListener('compositionstart', handleCompositionStart);
|
|
1625
|
+
doc.addEventListener('compositionend', handleCompositionEnd);
|
|
1626
|
+
}
|
|
1627
|
+
outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1628
|
+
let ancestors = [];
|
|
1629
|
+
if (ancestorScroll) {
|
|
1630
|
+
if (isElement(elements.domReference)) {
|
|
1631
|
+
ancestors = getOverflowAncestors(elements.domReference);
|
|
1632
|
+
}
|
|
1633
|
+
if (isElement(elements.floating)) {
|
|
1634
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
|
|
1635
|
+
}
|
|
1636
|
+
if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
|
|
1637
|
+
ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// Ignore the visual viewport for scrolling dismissal (allow pinch-zoom)
|
|
1642
|
+
ancestors = ancestors.filter(ancestor => {
|
|
1643
|
+
var _doc$defaultView;
|
|
1644
|
+
return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
|
|
1645
|
+
});
|
|
1646
|
+
ancestors.forEach(ancestor => {
|
|
1647
|
+
ancestor.addEventListener('scroll', onScroll, {
|
|
1648
|
+
passive: true
|
|
1649
|
+
});
|
|
1650
|
+
});
|
|
1651
|
+
return () => {
|
|
1652
|
+
if (escapeKey) {
|
|
1653
|
+
doc.removeEventListener('keydown', escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
|
|
1654
|
+
doc.removeEventListener('compositionstart', handleCompositionStart);
|
|
1655
|
+
doc.removeEventListener('compositionend', handleCompositionEnd);
|
|
1656
|
+
}
|
|
1657
|
+
outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
|
|
1658
|
+
ancestors.forEach(ancestor => {
|
|
1659
|
+
ancestor.removeEventListener('scroll', onScroll);
|
|
1660
|
+
});
|
|
1661
|
+
window.clearTimeout(compositionTimeout);
|
|
1662
|
+
};
|
|
1663
|
+
}, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
|
|
1664
|
+
React.useEffect(() => {
|
|
1665
|
+
insideReactTreeRef.current = false;
|
|
1666
|
+
}, [outsidePress, outsidePressEvent]);
|
|
1667
|
+
const reference = React.useMemo(() => ({
|
|
1668
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
1669
|
+
[bubbleHandlerKeys[referencePressEvent]]: event => {
|
|
1670
|
+
if (referencePress) {
|
|
1671
|
+
onOpenChange(false, event.nativeEvent, 'reference-press');
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
}), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
|
|
1675
|
+
const floating = React.useMemo(() => ({
|
|
1676
|
+
onKeyDown: closeOnEscapeKeyDown,
|
|
1677
|
+
onMouseDown() {
|
|
1678
|
+
endedOrStartedInsideRef.current = true;
|
|
1679
|
+
},
|
|
1680
|
+
onMouseUp() {
|
|
1681
|
+
endedOrStartedInsideRef.current = true;
|
|
1682
|
+
},
|
|
1683
|
+
[captureHandlerKeys[outsidePressEvent]]: () => {
|
|
1684
|
+
insideReactTreeRef.current = true;
|
|
1685
|
+
}
|
|
1686
|
+
}), [closeOnEscapeKeyDown, outsidePressEvent]);
|
|
1687
|
+
return React.useMemo(() => enabled ? {
|
|
1688
|
+
reference,
|
|
1689
|
+
floating
|
|
1690
|
+
} : {}, [enabled, reference, floating]);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
function useFloatingRootContext(options) {
|
|
1694
|
+
const {
|
|
1695
|
+
open = false,
|
|
1696
|
+
onOpenChange: onOpenChangeProp,
|
|
1697
|
+
elements: elementsProp
|
|
1698
|
+
} = options;
|
|
1699
|
+
const floatingId = useId();
|
|
1700
|
+
const dataRef = React.useRef({});
|
|
1701
|
+
const [events] = React.useState(() => createPubSub());
|
|
1702
|
+
const nested = useFloatingParentNodeId() != null;
|
|
1703
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1704
|
+
const optionDomReference = elementsProp.reference;
|
|
1705
|
+
if (optionDomReference && !isElement(optionDomReference)) {
|
|
1706
|
+
error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
|
|
1710
|
+
const onOpenChange = useEffectEvent((open, event, reason) => {
|
|
1711
|
+
dataRef.current.openEvent = open ? event : undefined;
|
|
1712
|
+
events.emit('openchange', {
|
|
1713
|
+
open,
|
|
1714
|
+
event,
|
|
1715
|
+
reason,
|
|
1716
|
+
nested
|
|
1717
|
+
});
|
|
1718
|
+
onOpenChangeProp == null || onOpenChangeProp(open, event, reason);
|
|
1719
|
+
});
|
|
1720
|
+
const refs = React.useMemo(() => ({
|
|
1721
|
+
setPositionReference
|
|
1722
|
+
}), []);
|
|
1723
|
+
const elements = React.useMemo(() => ({
|
|
1724
|
+
reference: positionReference || elementsProp.reference || null,
|
|
1725
|
+
floating: elementsProp.floating || null,
|
|
1726
|
+
domReference: elementsProp.reference
|
|
1727
|
+
}), [positionReference, elementsProp.reference, elementsProp.floating]);
|
|
1728
|
+
return React.useMemo(() => ({
|
|
1729
|
+
dataRef,
|
|
1730
|
+
open,
|
|
1731
|
+
onOpenChange,
|
|
1732
|
+
elements,
|
|
1733
|
+
events,
|
|
1734
|
+
floatingId,
|
|
1735
|
+
refs
|
|
1736
|
+
}), [open, onOpenChange, elements, events, floatingId, refs]);
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
/**
|
|
1740
|
+
* Provides data to position a floating element and context to add interactions.
|
|
1741
|
+
* @see https://floating-ui.com/docs/useFloating
|
|
1742
|
+
*/
|
|
1743
|
+
function useFloating(options) {
|
|
1744
|
+
if (options === void 0) {
|
|
1745
|
+
options = {};
|
|
1746
|
+
}
|
|
1747
|
+
const {
|
|
1748
|
+
nodeId
|
|
1749
|
+
} = options;
|
|
1750
|
+
const internalRootContext = useFloatingRootContext({
|
|
1751
|
+
...options,
|
|
1752
|
+
elements: {
|
|
1753
|
+
reference: null,
|
|
1754
|
+
floating: null,
|
|
1755
|
+
...options.elements
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
const rootContext = options.rootContext || internalRootContext;
|
|
1759
|
+
const computedElements = rootContext.elements;
|
|
1760
|
+
const [_domReference, setDomReference] = React.useState(null);
|
|
1761
|
+
const [positionReference, _setPositionReference] = React.useState(null);
|
|
1762
|
+
const optionDomReference = computedElements == null ? void 0 : computedElements.domReference;
|
|
1763
|
+
const domReference = optionDomReference || _domReference;
|
|
1764
|
+
const domReferenceRef = React.useRef(null);
|
|
1765
|
+
const tree = useFloatingTree();
|
|
1766
|
+
index(() => {
|
|
1767
|
+
if (domReference) {
|
|
1768
|
+
domReferenceRef.current = domReference;
|
|
1769
|
+
}
|
|
1770
|
+
}, [domReference]);
|
|
1771
|
+
const position = useFloating$1({
|
|
1772
|
+
...options,
|
|
1773
|
+
elements: {
|
|
1774
|
+
...computedElements,
|
|
1775
|
+
...(positionReference && {
|
|
1776
|
+
reference: positionReference
|
|
1777
|
+
})
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
const setPositionReference = React.useCallback(node => {
|
|
1781
|
+
const computedPositionReference = isElement(node) ? {
|
|
1782
|
+
getBoundingClientRect: () => node.getBoundingClientRect(),
|
|
1783
|
+
contextElement: node
|
|
1784
|
+
} : node;
|
|
1785
|
+
// Store the positionReference in state if the DOM reference is specified externally via the
|
|
1786
|
+
// `elements.reference` option. This ensures that it won't be overridden on future renders.
|
|
1787
|
+
_setPositionReference(computedPositionReference);
|
|
1788
|
+
position.refs.setReference(computedPositionReference);
|
|
1789
|
+
}, [position.refs]);
|
|
1790
|
+
const setReference = React.useCallback(node => {
|
|
1791
|
+
if (isElement(node) || node === null) {
|
|
1792
|
+
domReferenceRef.current = node;
|
|
1793
|
+
setDomReference(node);
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
// Backwards-compatibility for passing a virtual element to `reference`
|
|
1797
|
+
// after it has set the DOM reference.
|
|
1798
|
+
if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
|
|
1799
|
+
// Don't allow setting virtual elements using the old technique back to
|
|
1800
|
+
// `null` to support `positionReference` + an unstable `reference`
|
|
1801
|
+
// callback ref.
|
|
1802
|
+
node !== null && !isElement(node)) {
|
|
1803
|
+
position.refs.setReference(node);
|
|
1804
|
+
}
|
|
1805
|
+
}, [position.refs]);
|
|
1806
|
+
const refs = React.useMemo(() => ({
|
|
1807
|
+
...position.refs,
|
|
1808
|
+
setReference,
|
|
1809
|
+
setPositionReference,
|
|
1810
|
+
domReference: domReferenceRef
|
|
1811
|
+
}), [position.refs, setReference, setPositionReference]);
|
|
1812
|
+
const elements = React.useMemo(() => ({
|
|
1813
|
+
...position.elements,
|
|
1814
|
+
domReference: domReference
|
|
1815
|
+
}), [position.elements, domReference]);
|
|
1816
|
+
const context = React.useMemo(() => ({
|
|
1817
|
+
...position,
|
|
1818
|
+
...rootContext,
|
|
1819
|
+
refs,
|
|
1820
|
+
elements,
|
|
1821
|
+
nodeId
|
|
1822
|
+
}), [position, refs, elements, nodeId, rootContext]);
|
|
1823
|
+
index(() => {
|
|
1824
|
+
rootContext.dataRef.current.floatingContext = context;
|
|
1825
|
+
const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
|
|
1826
|
+
if (node) {
|
|
1827
|
+
node.context = context;
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
return React.useMemo(() => ({
|
|
1831
|
+
...position,
|
|
1832
|
+
context,
|
|
1833
|
+
refs,
|
|
1834
|
+
elements
|
|
1835
|
+
}), [position, refs, elements, context]);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
/**
|
|
1839
|
+
* Opens the floating element while the reference element has focus, like CSS
|
|
1840
|
+
* `:focus`.
|
|
1841
|
+
* @see https://floating-ui.com/docs/useFocus
|
|
1842
|
+
*/
|
|
1843
|
+
function useFocus(context, props) {
|
|
1844
|
+
if (props === void 0) {
|
|
1845
|
+
props = {};
|
|
1846
|
+
}
|
|
1847
|
+
const {
|
|
1848
|
+
open,
|
|
1849
|
+
onOpenChange,
|
|
1850
|
+
events,
|
|
1851
|
+
dataRef,
|
|
1852
|
+
elements
|
|
1853
|
+
} = context;
|
|
1854
|
+
const {
|
|
1855
|
+
enabled = true,
|
|
1856
|
+
visibleOnly = true
|
|
1857
|
+
} = props;
|
|
1858
|
+
const blockFocusRef = React.useRef(false);
|
|
1859
|
+
const timeoutRef = React.useRef();
|
|
1860
|
+
const keyboardModalityRef = React.useRef(true);
|
|
1861
|
+
React.useEffect(() => {
|
|
1862
|
+
if (!enabled) return;
|
|
1863
|
+
const win = getWindow(elements.domReference);
|
|
1864
|
+
|
|
1865
|
+
// If the reference was focused and the user left the tab/window, and the
|
|
1866
|
+
// floating element was not open, the focus should be blocked when they
|
|
1867
|
+
// return to the tab/window.
|
|
1868
|
+
function onBlur() {
|
|
1869
|
+
if (!open && isHTMLElement(elements.domReference) && elements.domReference === activeElement(getDocument(elements.domReference))) {
|
|
1870
|
+
blockFocusRef.current = true;
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
function onKeyDown() {
|
|
1874
|
+
keyboardModalityRef.current = true;
|
|
1875
|
+
}
|
|
1876
|
+
win.addEventListener('blur', onBlur);
|
|
1877
|
+
win.addEventListener('keydown', onKeyDown, true);
|
|
1878
|
+
return () => {
|
|
1879
|
+
win.removeEventListener('blur', onBlur);
|
|
1880
|
+
win.removeEventListener('keydown', onKeyDown, true);
|
|
1881
|
+
};
|
|
1882
|
+
}, [elements.domReference, open, enabled]);
|
|
1883
|
+
React.useEffect(() => {
|
|
1884
|
+
if (!enabled) return;
|
|
1885
|
+
function onOpenChange(_ref) {
|
|
1886
|
+
let {
|
|
1887
|
+
reason
|
|
1888
|
+
} = _ref;
|
|
1889
|
+
if (reason === 'reference-press' || reason === 'escape-key') {
|
|
1890
|
+
blockFocusRef.current = true;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
events.on('openchange', onOpenChange);
|
|
1894
|
+
return () => {
|
|
1895
|
+
events.off('openchange', onOpenChange);
|
|
1896
|
+
};
|
|
1897
|
+
}, [events, enabled]);
|
|
1898
|
+
React.useEffect(() => {
|
|
1899
|
+
return () => {
|
|
1900
|
+
clearTimeout(timeoutRef.current);
|
|
1901
|
+
};
|
|
1902
|
+
}, []);
|
|
1903
|
+
const reference = React.useMemo(() => ({
|
|
1904
|
+
onPointerDown(event) {
|
|
1905
|
+
if (isVirtualPointerEvent(event.nativeEvent)) return;
|
|
1906
|
+
keyboardModalityRef.current = false;
|
|
1907
|
+
},
|
|
1908
|
+
onMouseLeave() {
|
|
1909
|
+
blockFocusRef.current = false;
|
|
1910
|
+
},
|
|
1911
|
+
onFocus(event) {
|
|
1912
|
+
if (blockFocusRef.current) return;
|
|
1913
|
+
const target = getTarget(event.nativeEvent);
|
|
1914
|
+
if (visibleOnly && isElement(target)) {
|
|
1915
|
+
try {
|
|
1916
|
+
// Mac Safari unreliably matches `:focus-visible` on the reference
|
|
1917
|
+
// if focus was outside the page initially - use the fallback
|
|
1918
|
+
// instead.
|
|
1919
|
+
if (isSafari() && isMac()) throw Error();
|
|
1920
|
+
if (!target.matches(':focus-visible')) return;
|
|
1921
|
+
} catch (e) {
|
|
1922
|
+
// Old browsers will throw an error when using `:focus-visible`.
|
|
1923
|
+
if (!keyboardModalityRef.current && !isTypeableElement(target)) {
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
onOpenChange(true, event.nativeEvent, 'focus');
|
|
1929
|
+
},
|
|
1930
|
+
onBlur(event) {
|
|
1931
|
+
blockFocusRef.current = false;
|
|
1932
|
+
const relatedTarget = event.relatedTarget;
|
|
1933
|
+
const nativeEvent = event.nativeEvent;
|
|
1934
|
+
|
|
1935
|
+
// Hit the non-modal focus management portal guard. Focus will be
|
|
1936
|
+
// moved into the floating element immediately after.
|
|
1937
|
+
const movedToFocusGuard = isElement(relatedTarget) && relatedTarget.hasAttribute(createAttribute('focus-guard')) && relatedTarget.getAttribute('data-type') === 'outside';
|
|
1938
|
+
|
|
1939
|
+
// Wait for the window blur listener to fire.
|
|
1940
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
1941
|
+
var _dataRef$current$floa;
|
|
1942
|
+
const activeEl = activeElement(elements.domReference ? elements.domReference.ownerDocument : document);
|
|
1943
|
+
|
|
1944
|
+
// Focus left the page, keep it open.
|
|
1945
|
+
if (!relatedTarget && activeEl === elements.domReference) return;
|
|
1946
|
+
|
|
1947
|
+
// When focusing the reference element (e.g. regular click), then
|
|
1948
|
+
// clicking into the floating element, prevent it from hiding.
|
|
1949
|
+
// Note: it must be focusable, e.g. `tabindex="-1"`.
|
|
1950
|
+
// We can not rely on relatedTarget to point to the correct element
|
|
1951
|
+
// as it will only point to the shadow host of the newly focused element
|
|
1952
|
+
// and not the element that actually has received focus if it is located
|
|
1953
|
+
// inside a shadow root.
|
|
1954
|
+
if (contains((_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.refs.floating.current, activeEl) || contains(elements.domReference, activeEl) || movedToFocusGuard) {
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
onOpenChange(false, nativeEvent, 'focus');
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
}), [dataRef, elements.domReference, onOpenChange, visibleOnly]);
|
|
1961
|
+
return React.useMemo(() => enabled ? {
|
|
1962
|
+
reference
|
|
1963
|
+
} : {}, [enabled, reference]);
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
const ACTIVE_KEY = 'active';
|
|
1967
|
+
const SELECTED_KEY = 'selected';
|
|
1968
|
+
function mergeProps(userProps, propsList, elementKey) {
|
|
1969
|
+
const map = new Map();
|
|
1970
|
+
const isItem = elementKey === 'item';
|
|
1971
|
+
let domUserProps = userProps;
|
|
1972
|
+
if (isItem && userProps) {
|
|
1973
|
+
const {
|
|
1974
|
+
[ACTIVE_KEY]: _,
|
|
1975
|
+
[SELECTED_KEY]: __,
|
|
1976
|
+
...validProps
|
|
1977
|
+
} = userProps;
|
|
1978
|
+
domUserProps = validProps;
|
|
1979
|
+
}
|
|
1980
|
+
return {
|
|
1981
|
+
...(elementKey === 'floating' && {
|
|
1982
|
+
tabIndex: -1,
|
|
1983
|
+
[FOCUSABLE_ATTRIBUTE]: ''
|
|
1984
|
+
}),
|
|
1985
|
+
...domUserProps,
|
|
1986
|
+
...propsList.map(value => {
|
|
1987
|
+
const propsOrGetProps = value ? value[elementKey] : null;
|
|
1988
|
+
if (typeof propsOrGetProps === 'function') {
|
|
1989
|
+
return userProps ? propsOrGetProps(userProps) : null;
|
|
1990
|
+
}
|
|
1991
|
+
return propsOrGetProps;
|
|
1992
|
+
}).concat(userProps).reduce((acc, props) => {
|
|
1993
|
+
if (!props) {
|
|
1994
|
+
return acc;
|
|
1995
|
+
}
|
|
1996
|
+
Object.entries(props).forEach(_ref => {
|
|
1997
|
+
let [key, value] = _ref;
|
|
1998
|
+
if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
if (key.indexOf('on') === 0) {
|
|
2002
|
+
if (!map.has(key)) {
|
|
2003
|
+
map.set(key, []);
|
|
2004
|
+
}
|
|
2005
|
+
if (typeof value === 'function') {
|
|
2006
|
+
var _map$get;
|
|
2007
|
+
(_map$get = map.get(key)) == null || _map$get.push(value);
|
|
2008
|
+
acc[key] = function () {
|
|
2009
|
+
var _map$get2;
|
|
2010
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2011
|
+
args[_key] = arguments[_key];
|
|
2012
|
+
}
|
|
2013
|
+
return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map(fn => fn(...args)).find(val => val !== undefined);
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
} else {
|
|
2017
|
+
acc[key] = value;
|
|
2018
|
+
}
|
|
2019
|
+
});
|
|
2020
|
+
return acc;
|
|
2021
|
+
}, {})
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Merges an array of interaction hooks' props into prop getters, allowing
|
|
2026
|
+
* event handler functions to be composed together without overwriting one
|
|
2027
|
+
* another.
|
|
2028
|
+
* @see https://floating-ui.com/docs/useInteractions
|
|
2029
|
+
*/
|
|
2030
|
+
function useInteractions(propsList) {
|
|
2031
|
+
if (propsList === void 0) {
|
|
2032
|
+
propsList = [];
|
|
2033
|
+
}
|
|
2034
|
+
const referenceDeps = propsList.map(key => key == null ? void 0 : key.reference);
|
|
2035
|
+
const floatingDeps = propsList.map(key => key == null ? void 0 : key.floating);
|
|
2036
|
+
const itemDeps = propsList.map(key => key == null ? void 0 : key.item);
|
|
2037
|
+
const getReferenceProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'reference'),
|
|
2038
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2039
|
+
referenceDeps);
|
|
2040
|
+
const getFloatingProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'floating'),
|
|
2041
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2042
|
+
floatingDeps);
|
|
2043
|
+
const getItemProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'item'),
|
|
2044
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2045
|
+
itemDeps);
|
|
2046
|
+
return React.useMemo(() => ({
|
|
2047
|
+
getReferenceProps,
|
|
2048
|
+
getFloatingProps,
|
|
2049
|
+
getItemProps
|
|
2050
|
+
}), [getReferenceProps, getFloatingProps, getItemProps]);
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
const componentRoleToAriaRoleMap = /*#__PURE__*/new Map([['select', 'listbox'], ['combobox', 'listbox'], ['label', false]]);
|
|
2054
|
+
|
|
2055
|
+
/**
|
|
2056
|
+
* Adds base screen reader props to the reference and floating elements for a
|
|
2057
|
+
* given floating element `role`.
|
|
2058
|
+
* @see https://floating-ui.com/docs/useRole
|
|
2059
|
+
*/
|
|
2060
|
+
function useRole(context, props) {
|
|
2061
|
+
var _componentRoleToAriaR;
|
|
2062
|
+
if (props === void 0) {
|
|
2063
|
+
props = {};
|
|
2064
|
+
}
|
|
2065
|
+
const {
|
|
2066
|
+
open,
|
|
2067
|
+
floatingId
|
|
2068
|
+
} = context;
|
|
2069
|
+
const {
|
|
2070
|
+
enabled = true,
|
|
2071
|
+
role = 'dialog'
|
|
2072
|
+
} = props;
|
|
2073
|
+
const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
|
|
2074
|
+
const referenceId = useId();
|
|
2075
|
+
const parentId = useFloatingParentNodeId();
|
|
2076
|
+
const isNested = parentId != null;
|
|
2077
|
+
const reference = React.useMemo(() => {
|
|
2078
|
+
if (ariaRole === 'tooltip' || role === 'label') {
|
|
2079
|
+
return {
|
|
2080
|
+
["aria-" + (role === 'label' ? 'labelledby' : 'describedby')]: open ? floatingId : undefined
|
|
2081
|
+
};
|
|
2082
|
+
}
|
|
2083
|
+
return {
|
|
2084
|
+
'aria-expanded': open ? 'true' : 'false',
|
|
2085
|
+
'aria-haspopup': ariaRole === 'alertdialog' ? 'dialog' : ariaRole,
|
|
2086
|
+
'aria-controls': open ? floatingId : undefined,
|
|
2087
|
+
...(ariaRole === 'listbox' && {
|
|
2088
|
+
role: 'combobox'
|
|
2089
|
+
}),
|
|
2090
|
+
...(ariaRole === 'menu' && {
|
|
2091
|
+
id: referenceId
|
|
2092
|
+
}),
|
|
2093
|
+
...(ariaRole === 'menu' && isNested && {
|
|
2094
|
+
role: 'menuitem'
|
|
2095
|
+
}),
|
|
2096
|
+
...(role === 'select' && {
|
|
2097
|
+
'aria-autocomplete': 'none'
|
|
2098
|
+
}),
|
|
2099
|
+
...(role === 'combobox' && {
|
|
2100
|
+
'aria-autocomplete': 'list'
|
|
2101
|
+
})
|
|
2102
|
+
};
|
|
2103
|
+
}, [ariaRole, floatingId, isNested, open, referenceId, role]);
|
|
2104
|
+
const floating = React.useMemo(() => {
|
|
2105
|
+
const floatingProps = {
|
|
2106
|
+
id: floatingId,
|
|
2107
|
+
...(ariaRole && {
|
|
2108
|
+
role: ariaRole
|
|
2109
|
+
})
|
|
2110
|
+
};
|
|
2111
|
+
if (ariaRole === 'tooltip' || role === 'label') {
|
|
2112
|
+
return floatingProps;
|
|
2113
|
+
}
|
|
2114
|
+
return {
|
|
2115
|
+
...floatingProps,
|
|
2116
|
+
...(ariaRole === 'menu' && {
|
|
2117
|
+
'aria-labelledby': referenceId
|
|
2118
|
+
})
|
|
2119
|
+
};
|
|
2120
|
+
}, [ariaRole, floatingId, referenceId, role]);
|
|
2121
|
+
const item = React.useCallback(_ref => {
|
|
2122
|
+
let {
|
|
2123
|
+
active,
|
|
2124
|
+
selected
|
|
2125
|
+
} = _ref;
|
|
2126
|
+
const commonProps = {
|
|
2127
|
+
role: 'option',
|
|
2128
|
+
...(active && {
|
|
2129
|
+
id: floatingId + "-option"
|
|
2130
|
+
})
|
|
2131
|
+
};
|
|
2132
|
+
|
|
2133
|
+
// For `menu`, we are unable to tell if the item is a `menuitemradio`
|
|
2134
|
+
// or `menuitemcheckbox`. For backwards-compatibility reasons, also
|
|
2135
|
+
// avoid defaulting to `menuitem` as it may overwrite custom role props.
|
|
2136
|
+
switch (role) {
|
|
2137
|
+
case 'select':
|
|
2138
|
+
return {
|
|
2139
|
+
...commonProps,
|
|
2140
|
+
'aria-selected': active && selected
|
|
2141
|
+
};
|
|
2142
|
+
case 'combobox':
|
|
2143
|
+
{
|
|
2144
|
+
return {
|
|
2145
|
+
...commonProps,
|
|
2146
|
+
...(active && {
|
|
2147
|
+
'aria-selected': true
|
|
2148
|
+
})
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return {};
|
|
2153
|
+
}, [floatingId, role]);
|
|
2154
|
+
return React.useMemo(() => enabled ? {
|
|
2155
|
+
reference,
|
|
2156
|
+
floating,
|
|
2157
|
+
item
|
|
2158
|
+
} : {}, [enabled, reference, floating, item]);
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
function isPointInPolygon(point, polygon) {
|
|
2162
|
+
const [x, y] = point;
|
|
2163
|
+
let isInside = false;
|
|
2164
|
+
const length = polygon.length;
|
|
2165
|
+
for (let i = 0, j = length - 1; i < length; j = i++) {
|
|
2166
|
+
const [xi, yi] = polygon[i] || [0, 0];
|
|
2167
|
+
const [xj, yj] = polygon[j] || [0, 0];
|
|
2168
|
+
const intersect = yi >= y !== yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
2169
|
+
if (intersect) {
|
|
2170
|
+
isInside = !isInside;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return isInside;
|
|
2174
|
+
}
|
|
2175
|
+
function isInside(point, rect) {
|
|
2176
|
+
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Generates a safe polygon area that the user can traverse without closing the
|
|
2180
|
+
* floating element once leaving the reference element.
|
|
2181
|
+
* @see https://floating-ui.com/docs/useHover#safepolygon
|
|
2182
|
+
*/
|
|
2183
|
+
function safePolygon(options) {
|
|
2184
|
+
if (options === void 0) {
|
|
2185
|
+
options = {};
|
|
2186
|
+
}
|
|
2187
|
+
const {
|
|
2188
|
+
buffer = 0.5,
|
|
2189
|
+
blockPointerEvents = false,
|
|
2190
|
+
requireIntent = true
|
|
2191
|
+
} = options;
|
|
2192
|
+
let timeoutId;
|
|
2193
|
+
let hasLanded = false;
|
|
2194
|
+
let lastX = null;
|
|
2195
|
+
let lastY = null;
|
|
2196
|
+
let lastCursorTime = performance.now();
|
|
2197
|
+
function getCursorSpeed(x, y) {
|
|
2198
|
+
const currentTime = performance.now();
|
|
2199
|
+
const elapsedTime = currentTime - lastCursorTime;
|
|
2200
|
+
if (lastX === null || lastY === null || elapsedTime === 0) {
|
|
2201
|
+
lastX = x;
|
|
2202
|
+
lastY = y;
|
|
2203
|
+
lastCursorTime = currentTime;
|
|
2204
|
+
return null;
|
|
2205
|
+
}
|
|
2206
|
+
const deltaX = x - lastX;
|
|
2207
|
+
const deltaY = y - lastY;
|
|
2208
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
2209
|
+
const speed = distance / elapsedTime; // px / ms
|
|
2210
|
+
|
|
2211
|
+
lastX = x;
|
|
2212
|
+
lastY = y;
|
|
2213
|
+
lastCursorTime = currentTime;
|
|
2214
|
+
return speed;
|
|
2215
|
+
}
|
|
2216
|
+
const fn = _ref => {
|
|
2217
|
+
let {
|
|
2218
|
+
x,
|
|
2219
|
+
y,
|
|
2220
|
+
placement,
|
|
2221
|
+
elements,
|
|
2222
|
+
onClose,
|
|
2223
|
+
nodeId,
|
|
2224
|
+
tree
|
|
2225
|
+
} = _ref;
|
|
2226
|
+
return function onMouseMove(event) {
|
|
2227
|
+
function close() {
|
|
2228
|
+
clearTimeout(timeoutId);
|
|
2229
|
+
onClose();
|
|
2230
|
+
}
|
|
2231
|
+
clearTimeout(timeoutId);
|
|
2232
|
+
if (!elements.domReference || !elements.floating || placement == null || x == null || y == null) {
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
const {
|
|
2236
|
+
clientX,
|
|
2237
|
+
clientY
|
|
2238
|
+
} = event;
|
|
2239
|
+
const clientPoint = [clientX, clientY];
|
|
2240
|
+
const target = getTarget(event);
|
|
2241
|
+
const isLeave = event.type === 'mouseleave';
|
|
2242
|
+
const isOverFloatingEl = contains(elements.floating, target);
|
|
2243
|
+
const isOverReferenceEl = contains(elements.domReference, target);
|
|
2244
|
+
const refRect = elements.domReference.getBoundingClientRect();
|
|
2245
|
+
const rect = elements.floating.getBoundingClientRect();
|
|
2246
|
+
const side = placement.split('-')[0];
|
|
2247
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
2248
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
2249
|
+
const isOverReferenceRect = isInside(clientPoint, refRect);
|
|
2250
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
2251
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
2252
|
+
const left = (isFloatingWider ? refRect : rect).left;
|
|
2253
|
+
const right = (isFloatingWider ? refRect : rect).right;
|
|
2254
|
+
const top = (isFloatingTaller ? refRect : rect).top;
|
|
2255
|
+
const bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
2256
|
+
if (isOverFloatingEl) {
|
|
2257
|
+
hasLanded = true;
|
|
2258
|
+
if (!isLeave) {
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
if (isOverReferenceEl) {
|
|
2263
|
+
hasLanded = false;
|
|
2264
|
+
}
|
|
2265
|
+
if (isOverReferenceEl && !isLeave) {
|
|
2266
|
+
hasLanded = true;
|
|
2267
|
+
return;
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
// Prevent overlapping floating element from being stuck in an open-close
|
|
2271
|
+
// loop: https://github.com/floating-ui/floating-ui/issues/1910
|
|
2272
|
+
if (isLeave && isElement(event.relatedTarget) && contains(elements.floating, event.relatedTarget)) {
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
// If any nested child is open, abort.
|
|
2277
|
+
if (tree && getChildren(tree.nodesRef.current, nodeId).some(_ref2 => {
|
|
2278
|
+
let {
|
|
2279
|
+
context
|
|
2280
|
+
} = _ref2;
|
|
2281
|
+
return context == null ? void 0 : context.open;
|
|
2282
|
+
})) {
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
// If the pointer is leaving from the opposite side, the "buffer" logic
|
|
2287
|
+
// creates a point where the floating element remains open, but should be
|
|
2288
|
+
// ignored.
|
|
2289
|
+
// A constant of 1 handles floating point rounding errors.
|
|
2290
|
+
if (side === 'top' && y >= refRect.bottom - 1 || side === 'bottom' && y <= refRect.top + 1 || side === 'left' && x >= refRect.right - 1 || side === 'right' && x <= refRect.left + 1) {
|
|
2291
|
+
return close();
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
// Ignore when the cursor is within the rectangular trough between the
|
|
2295
|
+
// two elements. Since the triangle is created from the cursor point,
|
|
2296
|
+
// which can start beyond the ref element's edge, traversing back and
|
|
2297
|
+
// forth from the ref to the floating element can cause it to close. This
|
|
2298
|
+
// ensures it always remains open in that case.
|
|
2299
|
+
let rectPoly = [];
|
|
2300
|
+
switch (side) {
|
|
2301
|
+
case 'top':
|
|
2302
|
+
rectPoly = [[left, refRect.top + 1], [left, rect.bottom - 1], [right, rect.bottom - 1], [right, refRect.top + 1]];
|
|
2303
|
+
break;
|
|
2304
|
+
case 'bottom':
|
|
2305
|
+
rectPoly = [[left, rect.top + 1], [left, refRect.bottom - 1], [right, refRect.bottom - 1], [right, rect.top + 1]];
|
|
2306
|
+
break;
|
|
2307
|
+
case 'left':
|
|
2308
|
+
rectPoly = [[rect.right - 1, bottom], [rect.right - 1, top], [refRect.left + 1, top], [refRect.left + 1, bottom]];
|
|
2309
|
+
break;
|
|
2310
|
+
case 'right':
|
|
2311
|
+
rectPoly = [[refRect.right - 1, bottom], [refRect.right - 1, top], [rect.left + 1, top], [rect.left + 1, bottom]];
|
|
2312
|
+
break;
|
|
2313
|
+
}
|
|
2314
|
+
function getPolygon(_ref3) {
|
|
2315
|
+
let [x, y] = _ref3;
|
|
2316
|
+
switch (side) {
|
|
2317
|
+
case 'top':
|
|
2318
|
+
{
|
|
2319
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
2320
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
|
|
2321
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.bottom - buffer : isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
|
|
2322
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
2323
|
+
}
|
|
2324
|
+
case 'bottom':
|
|
2325
|
+
{
|
|
2326
|
+
const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
2327
|
+
const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
|
|
2328
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.top + buffer : isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
|
|
2329
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
2330
|
+
}
|
|
2331
|
+
case 'left':
|
|
2332
|
+
{
|
|
2333
|
+
const cursorPointOne = [x + buffer + 1, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
2334
|
+
const cursorPointTwo = [x + buffer + 1, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
2335
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.right - buffer : isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]];
|
|
2336
|
+
return [...commonPoints, cursorPointOne, cursorPointTwo];
|
|
2337
|
+
}
|
|
2338
|
+
case 'right':
|
|
2339
|
+
{
|
|
2340
|
+
const cursorPointOne = [x - buffer, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
2341
|
+
const cursorPointTwo = [x - buffer, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
|
|
2342
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.left + buffer : isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
|
|
2343
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
if (isPointInPolygon([clientX, clientY], rectPoly)) {
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
if (hasLanded && !isOverReferenceRect) {
|
|
2351
|
+
return close();
|
|
2352
|
+
}
|
|
2353
|
+
if (!isLeave && requireIntent) {
|
|
2354
|
+
const cursorSpeed = getCursorSpeed(event.clientX, event.clientY);
|
|
2355
|
+
const cursorSpeedThreshold = 0.1;
|
|
2356
|
+
if (cursorSpeed !== null && cursorSpeed < cursorSpeedThreshold) {
|
|
2357
|
+
return close();
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
if (!isPointInPolygon([clientX, clientY], getPolygon([x, y]))) {
|
|
2361
|
+
close();
|
|
2362
|
+
} else if (!hasLanded && requireIntent) {
|
|
2363
|
+
timeoutId = window.setTimeout(close, 40);
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
};
|
|
2367
|
+
fn.__options = {
|
|
2368
|
+
blockPointerEvents
|
|
2369
|
+
};
|
|
2370
|
+
return fn;
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
export { FloatingFocusManager as F, useFloating as a, useRole as b, useHover as c, useFocus as d, useClick as e, useDismiss as f, useInteractions as g, safePolygon as s, useMergeRefs as u };
|
|
2374
|
+
//# sourceMappingURL=floating-ui.react-aKYfs-aw.js.map
|