@sprawlify/primitives 0.0.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/dist/anatomy.cjs +3 -0
- package/dist/anatomy.d.cts +2 -0
- package/dist/anatomy.d.mts +2 -0
- package/dist/anatomy.mjs +3 -0
- package/dist/aria-hidden-DqYx0f_y.mjs +177 -0
- package/dist/aria-hidden-DtLU6hSU.cjs +182 -0
- package/dist/aria-hidden.cjs +4 -0
- package/dist/aria-hidden.d.cts +16 -0
- package/dist/aria-hidden.d.mts +16 -0
- package/dist/aria-hidden.mjs +4 -0
- package/dist/auto-resize-D3qHtFy1.mjs +114 -0
- package/dist/auto-resize-xzlPFDyD.cjs +125 -0
- package/dist/auto-resize.cjs +5 -0
- package/dist/auto-resize.d.cts +17 -0
- package/dist/auto-resize.d.mts +17 -0
- package/dist/auto-resize.mjs +4 -0
- package/dist/chunk-CbDLau6x.cjs +34 -0
- package/dist/collection-8XqaNHs_.mjs +1279 -0
- package/dist/collection-DIoIDISa.cjs +1326 -0
- package/dist/collection.cjs +11 -0
- package/dist/collection.d.cts +5 -0
- package/dist/collection.d.mts +5 -0
- package/dist/collection.mjs +4 -0
- package/dist/color-BkAP1Tkd.d.mts +60 -0
- package/dist/color-VKewNv2e.d.cts +60 -0
- package/dist/color-utils-Cc5GVXZh.mjs +657 -0
- package/dist/color-utils-LER_6Zwu.cjs +680 -0
- package/dist/color-utils.cjs +7 -0
- package/dist/color-utils.d.cts +19 -0
- package/dist/color-utils.d.mts +19 -0
- package/dist/color-utils.mjs +4 -0
- package/dist/core-30pJjyC2.d.mts +49 -0
- package/dist/core-CQFbMdTl.cjs +176 -0
- package/dist/core-CefBjbst.d.cts +49 -0
- package/dist/core-DCFNMTZF.mjs +129 -0
- package/dist/core.cjs +12 -0
- package/dist/core.d.cts +3 -0
- package/dist/core.d.mts +3 -0
- package/dist/core.mjs +5 -0
- package/dist/create-anatomy-B3XYc-qG.d.mts +70 -0
- package/dist/create-anatomy-BGQ8pv8J.d.cts +70 -0
- package/dist/create-anatomy-BbDZbHpC.mjs +39 -0
- package/dist/create-anatomy-CDsIFUXg.cjs +45 -0
- package/dist/create-props-BnF_vl-E.mjs +5 -0
- package/dist/create-props-YKy7JIKj.cjs +11 -0
- package/dist/data-url-C3ITPVRX.d.cts +10 -0
- package/dist/data-url-DLwZ9M77.d.mts +10 -0
- package/dist/date-utils-D2xPHa_I.cjs +738 -0
- package/dist/date-utils-wEa1hhpc.mjs +474 -0
- package/dist/date-utils.cjs +46 -0
- package/dist/date-utils.d.cts +101 -0
- package/dist/date-utils.d.mts +2 -0
- package/dist/date-utils.mjs +3 -0
- package/dist/defineProperty-BoUOT9Ie.cjs +49 -0
- package/dist/defineProperty-DrXfyjd4.mjs +43 -0
- package/dist/dismissable-CTfKZ4OG.cjs +282 -0
- package/dist/dismissable-DDrx0xnH.mjs +271 -0
- package/dist/dismissable-layer-C7pZU2wi.d.cts +39 -0
- package/dist/dismissable-layer-t_b0fk-p.d.mts +39 -0
- package/dist/dismissable.cjs +7 -0
- package/dist/dismissable.d.cts +3 -0
- package/dist/dismissable.d.mts +3 -0
- package/dist/dismissable.mjs +6 -0
- package/dist/dom-query-CWZdWUGp.cjs +2141 -0
- package/dist/dom-query-DFCRhyj1.mjs +1374 -0
- package/dist/dom-query.cjs +130 -0
- package/dist/dom-query.d.cts +307 -0
- package/dist/dom-query.d.mts +307 -0
- package/dist/dom-query.mjs +3 -0
- package/dist/file-utils.cjs +220 -0
- package/dist/file-utils.d.cts +51 -0
- package/dist/file-utils.d.mts +51 -0
- package/dist/file-utils.mjs +210 -0
- package/dist/focus-trap-D-bypQEJ.mjs +485 -0
- package/dist/focus-trap-D4i52S9A.cjs +496 -0
- package/dist/focus-trap.cjs +5 -0
- package/dist/focus-trap.d.cts +88 -0
- package/dist/focus-trap.d.mts +88 -0
- package/dist/focus-trap.mjs +4 -0
- package/dist/focus-visible-DYTWdWpa.cjs +210 -0
- package/dist/focus-visible-irppYatv.mjs +175 -0
- package/dist/focus-visible.cjs +9 -0
- package/dist/focus-visible.d.cts +31 -0
- package/dist/focus-visible.d.mts +31 -0
- package/dist/focus-visible.mjs +4 -0
- package/dist/functions-BOkTDEFM.d.cts +15 -0
- package/dist/functions-IZtWcC8Q.d.mts +15 -0
- package/dist/highlight-word.cjs +100 -0
- package/dist/highlight-word.d.cts +24 -0
- package/dist/highlight-word.d.mts +24 -0
- package/dist/highlight-word.mjs +99 -0
- package/dist/hotkeys.cjs +758 -0
- package/dist/hotkeys.d.cts +130 -0
- package/dist/hotkeys.d.mts +130 -0
- package/dist/hotkeys.mjs +754 -0
- package/dist/i18n-utils.cjs +450 -0
- package/dist/i18n-utils.d.cts +61 -0
- package/dist/i18n-utils.d.mts +61 -0
- package/dist/i18n-utils.mjs +440 -0
- package/dist/index-BkzYij2j.d.mts +25 -0
- package/dist/index-Bqw3r34-.d.cts +1383 -0
- package/dist/index-C0MKXQmE.d.mts +1383 -0
- package/dist/index-C9-feK5c.d.cts +25 -0
- package/dist/index-CD5FN7kY.d.mts +114 -0
- package/dist/index-CJji6wHl.d.cts +15 -0
- package/dist/index-CNi5FkPe.d.mts +15 -0
- package/dist/index-D96rs8B0.d.mts +115 -0
- package/dist/index.cjs +0 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/interact-outside-BplxR9cR.mjs +200 -0
- package/dist/interact-outside-C8-oFBpB.cjs +205 -0
- package/dist/interact-outside.cjs +5 -0
- package/dist/interact-outside.d.cts +2 -0
- package/dist/interact-outside.d.mts +2 -0
- package/dist/interact-outside.mjs +5 -0
- package/dist/json-tree-utils.cjs +1512 -0
- package/dist/json-tree-utils.d.cts +117 -0
- package/dist/json-tree-utils.d.mts +117 -0
- package/dist/json-tree-utils.mjs +1463 -0
- package/dist/list-collection-BIMJGQjn.d.cts +61 -0
- package/dist/list-collection-Db3eixRU.d.mts +61 -0
- package/dist/live-region-CcZPGo89.cjs +52 -0
- package/dist/live-region-CnPh21WH.mjs +46 -0
- package/dist/live-region.cjs +3 -0
- package/dist/live-region.d.cts +2 -0
- package/dist/live-region.d.mts +2 -0
- package/dist/live-region.mjs +3 -0
- package/dist/machines/accordion/index.cjs +328 -0
- package/dist/machines/accordion/index.d.cts +83 -0
- package/dist/machines/accordion/index.d.mts +83 -0
- package/dist/machines/accordion/index.mjs +322 -0
- package/dist/machines/async-list/index.cjs +311 -0
- package/dist/machines/async-list/index.d.cts +89 -0
- package/dist/machines/async-list/index.d.mts +89 -0
- package/dist/machines/async-list/index.mjs +310 -0
- package/dist/machines/avatar/index.cjs +169 -0
- package/dist/machines/avatar/index.d.cts +63 -0
- package/dist/machines/avatar/index.d.mts +63 -0
- package/dist/machines/avatar/index.mjs +165 -0
- package/dist/machines/bottom-sheet/index.cjs +676 -0
- package/dist/machines/bottom-sheet/index.d.cts +239 -0
- package/dist/machines/bottom-sheet/index.d.mts +239 -0
- package/dist/machines/bottom-sheet/index.mjs +672 -0
- package/dist/machines/carousel/index.cjs +859 -0
- package/dist/machines/carousel/index.d.cts +146 -0
- package/dist/machines/carousel/index.d.mts +146 -0
- package/dist/machines/carousel/index.mjs +851 -0
- package/dist/machines/checkbox/index.cjs +316 -0
- package/dist/machines/checkbox/index.d.cts +81 -0
- package/dist/machines/checkbox/index.d.mts +81 -0
- package/dist/machines/checkbox/index.mjs +312 -0
- package/dist/machines/clipboard/index.cjs +225 -0
- package/dist/machines/clipboard/index.d.cts +68 -0
- package/dist/machines/clipboard/index.d.mts +68 -0
- package/dist/machines/clipboard/index.mjs +219 -0
- package/dist/machines/collapsible/index.cjs +362 -0
- package/dist/machines/collapsible/index.d.cts +82 -0
- package/dist/machines/collapsible/index.d.mts +82 -0
- package/dist/machines/collapsible/index.mjs +358 -0
- package/dist/machines/color-picker/index.cjs +1529 -0
- package/dist/machines/color-picker/index.d.cts +205 -0
- package/dist/machines/color-picker/index.d.mts +205 -0
- package/dist/machines/color-picker/index.mjs +1514 -0
- package/dist/machines/combobox/index.cjs +1593 -0
- package/dist/machines/combobox/index.d.cts +214 -0
- package/dist/machines/combobox/index.d.mts +214 -0
- package/dist/machines/combobox/index.mjs +1582 -0
- package/dist/machines/date-picker/index.cjs +2177 -0
- package/dist/machines/date-picker/index.d.cts +350 -0
- package/dist/machines/date-picker/index.d.mts +350 -0
- package/dist/machines/date-picker/index.mjs +2161 -0
- package/dist/machines/dialog/index.cjs +325 -0
- package/dist/machines/dialog/index.d.cts +80 -0
- package/dist/machines/dialog/index.d.mts +80 -0
- package/dist/machines/dialog/index.mjs +321 -0
- package/dist/machines/editable/index.cjs +551 -0
- package/dist/machines/editable/index.d.cts +114 -0
- package/dist/machines/editable/index.d.mts +114 -0
- package/dist/machines/editable/index.mjs +547 -0
- package/dist/machines/floating-panel/index.cjs +995 -0
- package/dist/machines/floating-panel/index.d.cts +147 -0
- package/dist/machines/floating-panel/index.d.mts +147 -0
- package/dist/machines/floating-panel/index.mjs +988 -0
- package/dist/machines/hover-card/index.cjs +383 -0
- package/dist/machines/hover-card/index.d.cts +69 -0
- package/dist/machines/hover-card/index.d.mts +69 -0
- package/dist/machines/hover-card/index.mjs +379 -0
- package/dist/machines/image-cropper/index.cjs +1995 -0
- package/dist/machines/image-cropper/index.d.cts +182 -0
- package/dist/machines/image-cropper/index.d.mts +182 -0
- package/dist/machines/image-cropper/index.mjs +1990 -0
- package/dist/machines/listbox/index.cjs +794 -0
- package/dist/machines/listbox/index.d.cts +168 -0
- package/dist/machines/listbox/index.d.mts +168 -0
- package/dist/machines/listbox/index.mjs +782 -0
- package/dist/machines/marquee/index.cjs +395 -0
- package/dist/machines/marquee/index.d.cts +102 -0
- package/dist/machines/marquee/index.d.mts +102 -0
- package/dist/machines/marquee/index.mjs +391 -0
- package/dist/machines/menu/index.cjs +1298 -0
- package/dist/machines/menu/index.d.cts +175 -0
- package/dist/machines/menu/index.d.mts +175 -0
- package/dist/machines/menu/index.mjs +1286 -0
- package/dist/machines/navigation-menu/index.cjs +861 -0
- package/dist/machines/navigation-menu/index.d.cts +127 -0
- package/dist/machines/navigation-menu/index.d.mts +127 -0
- package/dist/machines/navigation-menu/index.mjs +857 -0
- package/dist/machines/number-input/index.cjs +996 -0
- package/dist/machines/number-input/index.d.cts +134 -0
- package/dist/machines/number-input/index.d.mts +134 -0
- package/dist/machines/number-input/index.mjs +991 -0
- package/dist/machines/pagination/index.cjs +419 -0
- package/dist/machines/pagination/index.d.cts +139 -0
- package/dist/machines/pagination/index.d.mts +139 -0
- package/dist/machines/pagination/index.mjs +411 -0
- package/dist/machines/password-input/index.cjs +228 -0
- package/dist/machines/password-input/index.d.cts +71 -0
- package/dist/machines/password-input/index.d.mts +71 -0
- package/dist/machines/password-input/index.mjs +224 -0
- package/dist/machines/pin-input/index.cjs +523 -0
- package/dist/machines/pin-input/index.d.cts +105 -0
- package/dist/machines/pin-input/index.d.mts +105 -0
- package/dist/machines/pin-input/index.mjs +519 -0
- package/dist/machines/popover/index.cjs +430 -0
- package/dist/machines/popover/index.d.cts +88 -0
- package/dist/machines/popover/index.d.mts +88 -0
- package/dist/machines/popover/index.mjs +426 -0
- package/dist/machines/presence/index.cjs +192 -0
- package/dist/machines/presence/index.d.cts +44 -0
- package/dist/machines/presence/index.d.mts +44 -0
- package/dist/machines/presence/index.mjs +190 -0
- package/dist/machines/progress/index.cjs +288 -0
- package/dist/machines/progress/index.d.cts +96 -0
- package/dist/machines/progress/index.d.mts +96 -0
- package/dist/machines/progress/index.mjs +284 -0
- package/dist/machines/qr-code/index.cjs +172 -0
- package/dist/machines/qr-code/index.d.cts +70 -0
- package/dist/machines/qr-code/index.d.mts +70 -0
- package/dist/machines/qr-code/index.mjs +167 -0
- package/dist/machines/radio-group/index.cjs +436 -0
- package/dist/machines/radio-group/index.d.cts +106 -0
- package/dist/machines/radio-group/index.d.mts +106 -0
- package/dist/machines/radio-group/index.mjs +430 -0
- package/dist/machines/rating-group/index.cjs +405 -0
- package/dist/machines/rating-group/index.d.cts +101 -0
- package/dist/machines/rating-group/index.d.mts +101 -0
- package/dist/machines/rating-group/index.mjs +399 -0
- package/dist/machines/scroll-area/index.cjs +857 -0
- package/dist/machines/scroll-area/index.d.cts +159 -0
- package/dist/machines/scroll-area/index.d.mts +159 -0
- package/dist/machines/scroll-area/index.mjs +853 -0
- package/dist/machines/select/index.cjs +1165 -0
- package/dist/machines/select/index.d.cts +183 -0
- package/dist/machines/select/index.d.mts +183 -0
- package/dist/machines/select/index.mjs +1154 -0
- package/dist/machines/signature-pad/index.cjs +334 -0
- package/dist/machines/signature-pad/index.d.cts +108 -0
- package/dist/machines/signature-pad/index.d.mts +108 -0
- package/dist/machines/signature-pad/index.mjs +328 -0
- package/dist/machines/slider/index.cjs +957 -0
- package/dist/machines/slider/index.d.cts +149 -0
- package/dist/machines/slider/index.d.mts +149 -0
- package/dist/machines/slider/index.mjs +949 -0
- package/dist/machines/splitter/index.cjs +1112 -0
- package/dist/machines/splitter/index.d.cts +155 -0
- package/dist/machines/splitter/index.d.mts +155 -0
- package/dist/machines/splitter/index.mjs +1103 -0
- package/dist/machines/steps/index.cjs +289 -0
- package/dist/machines/steps/index.d.cts +97 -0
- package/dist/machines/steps/index.d.mts +97 -0
- package/dist/machines/steps/index.mjs +285 -0
- package/dist/machines/switch/index.cjs +305 -0
- package/dist/machines/switch/index.d.cts +80 -0
- package/dist/machines/switch/index.d.mts +80 -0
- package/dist/machines/switch/index.mjs +301 -0
- package/dist/machines/tabs/index.cjs +508 -0
- package/dist/machines/tabs/index.d.cts +111 -0
- package/dist/machines/tabs/index.d.mts +111 -0
- package/dist/machines/tabs/index.mjs +500 -0
- package/dist/machines/tags-input/index.cjs +1127 -0
- package/dist/machines/tags-input/index.d.cts +179 -0
- package/dist/machines/tags-input/index.d.mts +179 -0
- package/dist/machines/tags-input/index.mjs +1121 -0
- package/dist/machines/timer/index.cjs +329 -0
- package/dist/machines/timer/index.d.cts +98 -0
- package/dist/machines/timer/index.d.mts +98 -0
- package/dist/machines/timer/index.mjs +324 -0
- package/dist/machines/toast/index.cjs +1155 -0
- package/dist/machines/toast/index.d.cts +195 -0
- package/dist/machines/toast/index.d.mts +195 -0
- package/dist/machines/toast/index.mjs +1151 -0
- package/dist/machines/toggle/index.cjs +103 -0
- package/dist/machines/toggle/index.d.cts +46 -0
- package/dist/machines/toggle/index.d.mts +46 -0
- package/dist/machines/toggle/index.mjs +99 -0
- package/dist/machines/toggle-group/index.cjs +328 -0
- package/dist/machines/toggle-group/index.d.cts +81 -0
- package/dist/machines/toggle-group/index.d.mts +81 -0
- package/dist/machines/toggle-group/index.mjs +322 -0
- package/dist/machines/tooltip/index.cjs +516 -0
- package/dist/machines/tooltip/index.d.cts +71 -0
- package/dist/machines/tooltip/index.d.mts +71 -0
- package/dist/machines/tooltip/index.mjs +512 -0
- package/dist/machines/tour/index.cjs +1108 -0
- package/dist/machines/tour/index.d.cts +206 -0
- package/dist/machines/tour/index.d.mts +206 -0
- package/dist/machines/tour/index.mjs +1101 -0
- package/dist/machines/tree-view/index.cjs +1271 -0
- package/dist/machines/tree-view/index.d.cts +215 -0
- package/dist/machines/tree-view/index.d.mts +215 -0
- package/dist/machines/tree-view/index.mjs +1263 -0
- package/dist/node-BctU8GXk.d.mts +24 -0
- package/dist/node-CSsuPZVZ.d.cts +24 -0
- package/dist/popper-BPJeAtcA.mjs +349 -0
- package/dist/popper-D0FAW_p7.cjs +373 -0
- package/dist/popper.cjs +8 -0
- package/dist/popper.d.cts +74 -0
- package/dist/popper.d.mts +2 -0
- package/dist/popper.mjs +5 -0
- package/dist/raf-BnlYUlDi.d.mts +15 -0
- package/dist/raf-Cd2FGy0z.d.cts +15 -0
- package/dist/rect-utils-0ellN0a_.mjs +854 -0
- package/dist/rect-utils-DKLRhP8G.cjs +1147 -0
- package/dist/rect-utils.cjs +51 -0
- package/dist/rect-utils.d.cts +198 -0
- package/dist/rect-utils.d.mts +198 -0
- package/dist/rect-utils.mjs +3 -0
- package/dist/remove-scroll-Lrfv79X_.mjs +58 -0
- package/dist/remove-scroll-Uvzg1L9r.cjs +63 -0
- package/dist/remove-scroll.cjs +0 -0
- package/dist/remove-scroll.d.cts +1 -0
- package/dist/remove-scroll.d.mts +1 -0
- package/dist/remove-scroll.mjs +1 -0
- package/dist/scroll-snap-CrTmQRzA.mjs +152 -0
- package/dist/scroll-snap-zyiZLv7W.cjs +175 -0
- package/dist/scroll-snap.cjs +7 -0
- package/dist/scroll-snap.d.cts +14 -0
- package/dist/scroll-snap.d.mts +14 -0
- package/dist/scroll-snap.mjs +4 -0
- package/dist/selection-BIhSzkF7.d.mts +50 -0
- package/dist/selection-CS1GBp8e.d.cts +50 -0
- package/dist/store-BZcXv49B.cjs +305 -0
- package/dist/store-DEojWy9H.mjs +263 -0
- package/dist/store.cjs +9 -0
- package/dist/store.d.cts +26 -0
- package/dist/store.d.mts +26 -0
- package/dist/store.mjs +3 -0
- package/dist/stringify-state.cjs +49 -0
- package/dist/stringify-state.d.cts +8 -0
- package/dist/stringify-state.d.mts +8 -0
- package/dist/stringify-state.mjs +46 -0
- package/dist/tree-collection-BwU5WhGQ.d.mts +78 -0
- package/dist/tree-collection-DP_eznnI.d.cts +78 -0
- package/dist/typeahead-BdNwVP09.d.cts +45 -0
- package/dist/typeahead-XN6lZ7G9.d.mts +45 -0
- package/dist/types-BivBkYg9.d.cts +57 -0
- package/dist/types-Bl_6JtPQ.d.mts +57 -0
- package/dist/types-CPUMVt7c.d.mts +54 -0
- package/dist/types-CT_W6HWr.d.cts +54 -0
- package/dist/types-DDTcG99l.d.mts +201 -0
- package/dist/types-DejIu60O.d.cts +201 -0
- package/dist/types-DiIdKZ3K.d.cts +45 -0
- package/dist/types-GxLIgJib.d.cts +17 -0
- package/dist/types.cjs +15 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +14 -0
- package/dist/utils-BZyrxWWR.mjs +525 -0
- package/dist/utils-_6frwjgJ.cjs +1040 -0
- package/dist/utils.cjs +88 -0
- package/dist/utils.d.cts +144 -0
- package/dist/utils.d.mts +144 -0
- package/dist/utils.mjs +3 -0
- package/dist/wait-for-CMjPsqWk.d.cts +10 -0
- package/dist/wait-for-D2nkdD4z.d.mts +10 -0
- package/package.json +399 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { $ as getTabbables, Gt as isControlledByExpandedController, J as getFocusables, Kt as isControlledElement, Qt as getDocument, U as raf, Ut as getControlledElements, Wt as hasControllerElements, Z as getTabIndex, Zt as getActiveElement, et as isFocusable, ft as getEventTarget, on as isDocument, st as addDomEvent, tt as isTabbable } from "./dom-query-DFCRhyj1.mjs";
|
|
2
|
+
import { t as _defineProperty } from "./defineProperty-DrXfyjd4.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/shared/focus-trap/focus-trap.ts
|
|
5
|
+
const activeFocusTraps = {
|
|
6
|
+
activateTrap(trapStack, trap) {
|
|
7
|
+
if (trapStack.length > 0) {
|
|
8
|
+
const activeTrap = trapStack[trapStack.length - 1];
|
|
9
|
+
if (activeTrap !== trap) activeTrap.pause();
|
|
10
|
+
}
|
|
11
|
+
const trapIndex = trapStack.indexOf(trap);
|
|
12
|
+
if (trapIndex === -1) trapStack.push(trap);
|
|
13
|
+
else {
|
|
14
|
+
trapStack.splice(trapIndex, 1);
|
|
15
|
+
trapStack.push(trap);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
deactivateTrap(trapStack, trap) {
|
|
19
|
+
const trapIndex = trapStack.indexOf(trap);
|
|
20
|
+
if (trapIndex !== -1) trapStack.splice(trapIndex, 1);
|
|
21
|
+
if (trapStack.length > 0) trapStack[trapStack.length - 1].unpause();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const sharedTrapStack = [];
|
|
25
|
+
var FocusTrap = class {
|
|
26
|
+
addPortalContainer(controlledElement) {
|
|
27
|
+
const portalContainer = controlledElement.parentElement;
|
|
28
|
+
if (portalContainer && !this.portalContainers.has(portalContainer)) {
|
|
29
|
+
this.portalContainers.add(portalContainer);
|
|
30
|
+
if (this.state.active && !this.state.paused) this.observePortalContainer(portalContainer);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
observePortalContainer(portalContainer) {
|
|
34
|
+
this._mutationObserver?.observe(portalContainer, {
|
|
35
|
+
subtree: true,
|
|
36
|
+
childList: true,
|
|
37
|
+
attributes: true,
|
|
38
|
+
attributeFilter: ["aria-controls", "aria-expanded"]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
updatePortalContainers() {
|
|
42
|
+
if (!this.config.followControlledElements) return;
|
|
43
|
+
this.state.containers.forEach((container) => {
|
|
44
|
+
getControlledElements(container).forEach((controlledElement) => {
|
|
45
|
+
this.addPortalContainer(controlledElement);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
get active() {
|
|
50
|
+
return this.state.active;
|
|
51
|
+
}
|
|
52
|
+
get paused() {
|
|
53
|
+
return this.state.paused;
|
|
54
|
+
}
|
|
55
|
+
constructor(elements, options) {
|
|
56
|
+
_defineProperty(this, "trapStack", void 0);
|
|
57
|
+
_defineProperty(this, "config", void 0);
|
|
58
|
+
_defineProperty(this, "doc", void 0);
|
|
59
|
+
_defineProperty(this, "state", {
|
|
60
|
+
containers: [],
|
|
61
|
+
containerGroups: [],
|
|
62
|
+
tabbableGroups: [],
|
|
63
|
+
nodeFocusedBeforeActivation: null,
|
|
64
|
+
mostRecentlyFocusedNode: null,
|
|
65
|
+
active: false,
|
|
66
|
+
paused: false,
|
|
67
|
+
delayInitialFocusTimer: void 0,
|
|
68
|
+
recentNavEvent: void 0
|
|
69
|
+
});
|
|
70
|
+
_defineProperty(this, "portalContainers", /* @__PURE__ */ new Set());
|
|
71
|
+
_defineProperty(this, "listenerCleanups", []);
|
|
72
|
+
_defineProperty(this, "handleFocus", (event) => {
|
|
73
|
+
const target = getEventTarget(event);
|
|
74
|
+
const targetContained = this.findContainerIndex(target, event) >= 0;
|
|
75
|
+
if (targetContained || isDocument(target)) {
|
|
76
|
+
if (targetContained) this.state.mostRecentlyFocusedNode = target;
|
|
77
|
+
} else {
|
|
78
|
+
event.stopImmediatePropagation();
|
|
79
|
+
let nextNode;
|
|
80
|
+
let navAcrossContainers = true;
|
|
81
|
+
if (this.state.mostRecentlyFocusedNode) {
|
|
82
|
+
if (getTabIndex(this.state.mostRecentlyFocusedNode) > 0) {
|
|
83
|
+
const mruContainerIdx = this.findContainerIndex(this.state.mostRecentlyFocusedNode);
|
|
84
|
+
const { tabbableNodes } = this.state.containerGroups[mruContainerIdx];
|
|
85
|
+
if (tabbableNodes.length > 0) {
|
|
86
|
+
const mruTabIdx = tabbableNodes.findIndex((node) => node === this.state.mostRecentlyFocusedNode);
|
|
87
|
+
if (mruTabIdx >= 0) {
|
|
88
|
+
if (this.config.isKeyForward(this.state.recentNavEvent)) {
|
|
89
|
+
if (mruTabIdx + 1 < tabbableNodes.length) {
|
|
90
|
+
nextNode = tabbableNodes[mruTabIdx + 1];
|
|
91
|
+
navAcrossContainers = false;
|
|
92
|
+
}
|
|
93
|
+
} else if (mruTabIdx - 1 >= 0) {
|
|
94
|
+
nextNode = tabbableNodes[mruTabIdx - 1];
|
|
95
|
+
navAcrossContainers = false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} else if (!this.state.containerGroups.some((g) => g.tabbableNodes.some((n) => getTabIndex(n) > 0))) navAcrossContainers = false;
|
|
100
|
+
} else navAcrossContainers = false;
|
|
101
|
+
if (navAcrossContainers) nextNode = this.findNextNavNode({
|
|
102
|
+
target: this.state.mostRecentlyFocusedNode,
|
|
103
|
+
isBackward: this.config.isKeyBackward(this.state.recentNavEvent)
|
|
104
|
+
});
|
|
105
|
+
if (nextNode) this.tryFocus(nextNode);
|
|
106
|
+
else this.tryFocus(this.state.mostRecentlyFocusedNode || this.getInitialFocusNode());
|
|
107
|
+
}
|
|
108
|
+
this.state.recentNavEvent = void 0;
|
|
109
|
+
});
|
|
110
|
+
_defineProperty(this, "handlePointerDown", (event) => {
|
|
111
|
+
const target = getEventTarget(event);
|
|
112
|
+
if (this.findContainerIndex(target, event) >= 0) return;
|
|
113
|
+
if (valueOrHandler(this.config.clickOutsideDeactivates, event)) {
|
|
114
|
+
this.deactivate({ returnFocus: this.config.returnFocusOnDeactivate });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (valueOrHandler(this.config.allowOutsideClick, event)) return;
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
});
|
|
120
|
+
_defineProperty(this, "handleClick", (event) => {
|
|
121
|
+
const target = getEventTarget(event);
|
|
122
|
+
if (this.findContainerIndex(target, event) >= 0) return;
|
|
123
|
+
if (valueOrHandler(this.config.clickOutsideDeactivates, event)) return;
|
|
124
|
+
if (valueOrHandler(this.config.allowOutsideClick, event)) return;
|
|
125
|
+
event.preventDefault();
|
|
126
|
+
event.stopImmediatePropagation();
|
|
127
|
+
});
|
|
128
|
+
_defineProperty(this, "handleTabKey", (event) => {
|
|
129
|
+
if (this.config.isKeyForward(event) || this.config.isKeyBackward(event)) {
|
|
130
|
+
this.state.recentNavEvent = event;
|
|
131
|
+
const isBackward = this.config.isKeyBackward(event);
|
|
132
|
+
const destinationNode = this.findNextNavNode({
|
|
133
|
+
event,
|
|
134
|
+
isBackward
|
|
135
|
+
});
|
|
136
|
+
if (!destinationNode) return;
|
|
137
|
+
if (isTabEvent(event)) event.preventDefault();
|
|
138
|
+
this.tryFocus(destinationNode);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
_defineProperty(this, "handleEscapeKey", (event) => {
|
|
142
|
+
if (isEscapeEvent(event) && valueOrHandler(this.config.escapeDeactivates, event) !== false) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
this.deactivate();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
_defineProperty(this, "_mutationObserver", void 0);
|
|
148
|
+
_defineProperty(this, "setupMutationObserver", () => {
|
|
149
|
+
this._mutationObserver = new (this.doc.defaultView || window).MutationObserver((mutations) => {
|
|
150
|
+
if (mutations.some((mutation) => {
|
|
151
|
+
return Array.from(mutation.removedNodes).some((node) => node === this.state.mostRecentlyFocusedNode);
|
|
152
|
+
})) this.tryFocus(this.getInitialFocusNode());
|
|
153
|
+
if (mutations.some((mutation) => {
|
|
154
|
+
if (mutation.type === "attributes" && (mutation.attributeName === "aria-controls" || mutation.attributeName === "aria-expanded")) return true;
|
|
155
|
+
if (mutation.type === "childList" && mutation.addedNodes.length > 0) return Array.from(mutation.addedNodes).some((node) => {
|
|
156
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
157
|
+
const element = node;
|
|
158
|
+
if (hasControllerElements(element)) return true;
|
|
159
|
+
if (element.id && !this.state.containers.some((c) => c.contains(element))) return isControlledByExpandedController(element);
|
|
160
|
+
return false;
|
|
161
|
+
});
|
|
162
|
+
return false;
|
|
163
|
+
}) && this.state.active && !this.state.paused) {
|
|
164
|
+
this.updateTabbableNodes();
|
|
165
|
+
this.updatePortalContainers();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
_defineProperty(this, "updateObservedNodes", () => {
|
|
170
|
+
this._mutationObserver?.disconnect();
|
|
171
|
+
if (this.state.active && !this.state.paused) {
|
|
172
|
+
this.state.containers.map((container) => {
|
|
173
|
+
this._mutationObserver?.observe(container, {
|
|
174
|
+
subtree: true,
|
|
175
|
+
childList: true,
|
|
176
|
+
attributes: true,
|
|
177
|
+
attributeFilter: ["aria-controls", "aria-expanded"]
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
this.portalContainers.forEach((portalContainer) => {
|
|
181
|
+
this.observePortalContainer(portalContainer);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
_defineProperty(this, "getInitialFocusNode", () => {
|
|
186
|
+
let node = this.getNodeForOption("initialFocus", { hasFallback: true });
|
|
187
|
+
if (node === false) return false;
|
|
188
|
+
if (node === void 0 || node && !isFocusable(node)) {
|
|
189
|
+
const activeElement = getActiveElement(this.doc);
|
|
190
|
+
if (activeElement && this.findContainerIndex(activeElement) >= 0) node = activeElement;
|
|
191
|
+
else {
|
|
192
|
+
const firstTabbableGroup = this.state.tabbableGroups[0];
|
|
193
|
+
node = firstTabbableGroup && firstTabbableGroup.firstTabbableNode || this.getNodeForOption("fallbackFocus");
|
|
194
|
+
}
|
|
195
|
+
} else if (node === null) node = this.getNodeForOption("fallbackFocus");
|
|
196
|
+
if (!node) throw new Error("Your focus-trap needs to have at least one focusable element");
|
|
197
|
+
if (!node.isConnected) node = this.getNodeForOption("fallbackFocus");
|
|
198
|
+
return node;
|
|
199
|
+
});
|
|
200
|
+
_defineProperty(this, "tryFocus", (node) => {
|
|
201
|
+
if (node === false) return;
|
|
202
|
+
if (node === getActiveElement(this.doc)) return;
|
|
203
|
+
if (!node || !node.focus) {
|
|
204
|
+
this.tryFocus(this.getInitialFocusNode());
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
node.focus({ preventScroll: !!this.config.preventScroll });
|
|
208
|
+
this.state.mostRecentlyFocusedNode = node;
|
|
209
|
+
if (isSelectableInput(node)) node.select();
|
|
210
|
+
});
|
|
211
|
+
_defineProperty(this, "deactivate", (deactivateOptions) => {
|
|
212
|
+
if (!this.state.active) return this;
|
|
213
|
+
const options$1 = {
|
|
214
|
+
onDeactivate: this.config.onDeactivate,
|
|
215
|
+
onPostDeactivate: this.config.onPostDeactivate,
|
|
216
|
+
checkCanReturnFocus: this.config.checkCanReturnFocus,
|
|
217
|
+
...deactivateOptions
|
|
218
|
+
};
|
|
219
|
+
clearTimeout(this.state.delayInitialFocusTimer);
|
|
220
|
+
this.state.delayInitialFocusTimer = void 0;
|
|
221
|
+
this.removeListeners();
|
|
222
|
+
this.state.active = false;
|
|
223
|
+
this.state.paused = false;
|
|
224
|
+
this.updateObservedNodes();
|
|
225
|
+
activeFocusTraps.deactivateTrap(this.trapStack, this);
|
|
226
|
+
this.portalContainers.clear();
|
|
227
|
+
const onDeactivate = this.getOption(options$1, "onDeactivate");
|
|
228
|
+
const onPostDeactivate = this.getOption(options$1, "onPostDeactivate");
|
|
229
|
+
const checkCanReturnFocus = this.getOption(options$1, "checkCanReturnFocus");
|
|
230
|
+
const returnFocus = this.getOption(options$1, "returnFocus", "returnFocusOnDeactivate");
|
|
231
|
+
onDeactivate?.();
|
|
232
|
+
const finishDeactivation = () => {
|
|
233
|
+
delay(() => {
|
|
234
|
+
if (returnFocus) {
|
|
235
|
+
const returnFocusNode = this.getReturnFocusNode(this.state.nodeFocusedBeforeActivation);
|
|
236
|
+
this.tryFocus(returnFocusNode);
|
|
237
|
+
}
|
|
238
|
+
onPostDeactivate?.();
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
if (returnFocus && checkCanReturnFocus) {
|
|
242
|
+
checkCanReturnFocus(this.getReturnFocusNode(this.state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
finishDeactivation();
|
|
246
|
+
return this;
|
|
247
|
+
});
|
|
248
|
+
_defineProperty(this, "pause", (pauseOptions) => {
|
|
249
|
+
if (this.state.paused || !this.state.active) return this;
|
|
250
|
+
const onPause = this.getOption(pauseOptions, "onPause");
|
|
251
|
+
const onPostPause = this.getOption(pauseOptions, "onPostPause");
|
|
252
|
+
this.state.paused = true;
|
|
253
|
+
onPause?.();
|
|
254
|
+
this.removeListeners();
|
|
255
|
+
this.updateObservedNodes();
|
|
256
|
+
onPostPause?.();
|
|
257
|
+
return this;
|
|
258
|
+
});
|
|
259
|
+
_defineProperty(this, "unpause", (unpauseOptions) => {
|
|
260
|
+
if (!this.state.paused || !this.state.active) return this;
|
|
261
|
+
const onUnpause = this.getOption(unpauseOptions, "onUnpause");
|
|
262
|
+
const onPostUnpause = this.getOption(unpauseOptions, "onPostUnpause");
|
|
263
|
+
this.state.paused = false;
|
|
264
|
+
onUnpause?.();
|
|
265
|
+
this.updateTabbableNodes();
|
|
266
|
+
this.addListeners();
|
|
267
|
+
this.updateObservedNodes();
|
|
268
|
+
onPostUnpause?.();
|
|
269
|
+
return this;
|
|
270
|
+
});
|
|
271
|
+
_defineProperty(this, "updateContainerElements", (containerElements) => {
|
|
272
|
+
this.state.containers = Array.isArray(containerElements) ? containerElements.filter(Boolean) : [containerElements].filter(Boolean);
|
|
273
|
+
if (this.state.active) this.updateTabbableNodes();
|
|
274
|
+
this.updateObservedNodes();
|
|
275
|
+
return this;
|
|
276
|
+
});
|
|
277
|
+
_defineProperty(this, "getReturnFocusNode", (previousActiveElement) => {
|
|
278
|
+
const node = this.getNodeForOption("setReturnFocus", { params: [previousActiveElement] });
|
|
279
|
+
return node ? node : node === false ? false : previousActiveElement;
|
|
280
|
+
});
|
|
281
|
+
_defineProperty(this, "getOption", (configOverrideOptions, optionName, configOptionName) => {
|
|
282
|
+
return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : this.config[configOptionName || optionName];
|
|
283
|
+
});
|
|
284
|
+
_defineProperty(this, "getNodeForOption", (optionName, { hasFallback = false, params = [] } = {}) => {
|
|
285
|
+
let optionValue = this.config[optionName];
|
|
286
|
+
if (typeof optionValue === "function") optionValue = optionValue(...params);
|
|
287
|
+
if (optionValue === true) optionValue = void 0;
|
|
288
|
+
if (!optionValue) {
|
|
289
|
+
if (optionValue === void 0 || optionValue === false) return optionValue;
|
|
290
|
+
throw new Error(`\`${optionName}\` was specified but was not a node, or did not return a node`);
|
|
291
|
+
}
|
|
292
|
+
let node = optionValue;
|
|
293
|
+
if (typeof optionValue === "string") {
|
|
294
|
+
try {
|
|
295
|
+
node = this.doc.querySelector(optionValue);
|
|
296
|
+
} catch (err) {
|
|
297
|
+
throw new Error(`\`${optionName}\` appears to be an invalid selector; error="${err.message}"`);
|
|
298
|
+
}
|
|
299
|
+
if (!node) {
|
|
300
|
+
if (!hasFallback) throw new Error(`\`${optionName}\` as selector refers to no known node`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return node;
|
|
304
|
+
});
|
|
305
|
+
_defineProperty(this, "findNextNavNode", (opts) => {
|
|
306
|
+
const { event, isBackward = false } = opts;
|
|
307
|
+
const target = opts.target || getEventTarget(event);
|
|
308
|
+
this.updateTabbableNodes();
|
|
309
|
+
let destinationNode = null;
|
|
310
|
+
if (this.state.tabbableGroups.length > 0) {
|
|
311
|
+
const containerIndex = this.findContainerIndex(target, event);
|
|
312
|
+
const containerGroup = containerIndex >= 0 ? this.state.containerGroups[containerIndex] : void 0;
|
|
313
|
+
if (containerIndex < 0) if (isBackward) destinationNode = this.state.tabbableGroups[this.state.tabbableGroups.length - 1].lastTabbableNode;
|
|
314
|
+
else destinationNode = this.state.tabbableGroups[0].firstTabbableNode;
|
|
315
|
+
else if (isBackward) {
|
|
316
|
+
let startOfGroupIndex = this.state.tabbableGroups.findIndex(({ firstTabbableNode }) => target === firstTabbableNode);
|
|
317
|
+
if (startOfGroupIndex < 0 && (containerGroup?.container === target || isFocusable(target) && !isTabbable(target) && !containerGroup?.nextTabbableNode(target, false))) startOfGroupIndex = containerIndex;
|
|
318
|
+
if (startOfGroupIndex >= 0) {
|
|
319
|
+
const destinationGroupIndex = startOfGroupIndex === 0 ? this.state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
|
|
320
|
+
const destinationGroup = this.state.tabbableGroups[destinationGroupIndex];
|
|
321
|
+
destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
|
|
322
|
+
} else if (!isTabEvent(event)) destinationNode = containerGroup?.nextTabbableNode(target, false);
|
|
323
|
+
} else {
|
|
324
|
+
let lastOfGroupIndex = this.state.tabbableGroups.findIndex(({ lastTabbableNode }) => target === lastTabbableNode);
|
|
325
|
+
if (lastOfGroupIndex < 0 && (containerGroup?.container === target || isFocusable(target) && !isTabbable(target) && !containerGroup?.nextTabbableNode(target))) lastOfGroupIndex = containerIndex;
|
|
326
|
+
if (lastOfGroupIndex >= 0) {
|
|
327
|
+
const destinationGroupIndex = lastOfGroupIndex === this.state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
|
|
328
|
+
const destinationGroup = this.state.tabbableGroups[destinationGroupIndex];
|
|
329
|
+
destinationNode = getTabIndex(target) >= 0 ? destinationGroup.firstTabbableNode : destinationGroup.firstDomTabbableNode;
|
|
330
|
+
} else if (!isTabEvent(event)) destinationNode = containerGroup?.nextTabbableNode(target);
|
|
331
|
+
}
|
|
332
|
+
} else destinationNode = this.getNodeForOption("fallbackFocus");
|
|
333
|
+
return destinationNode;
|
|
334
|
+
});
|
|
335
|
+
this.trapStack = options.trapStack || sharedTrapStack;
|
|
336
|
+
const config = {
|
|
337
|
+
returnFocusOnDeactivate: true,
|
|
338
|
+
escapeDeactivates: true,
|
|
339
|
+
delayInitialFocus: true,
|
|
340
|
+
followControlledElements: true,
|
|
341
|
+
isKeyForward(e) {
|
|
342
|
+
return isTabEvent(e) && !e.shiftKey;
|
|
343
|
+
},
|
|
344
|
+
isKeyBackward(e) {
|
|
345
|
+
return isTabEvent(e) && e.shiftKey;
|
|
346
|
+
},
|
|
347
|
+
...options
|
|
348
|
+
};
|
|
349
|
+
this.doc = config.document || getDocument(Array.isArray(elements) ? elements[0] : elements);
|
|
350
|
+
this.config = config;
|
|
351
|
+
this.updateContainerElements(elements);
|
|
352
|
+
this.setupMutationObserver();
|
|
353
|
+
}
|
|
354
|
+
findContainerIndex(element, event) {
|
|
355
|
+
const composedPath = typeof event?.composedPath === "function" ? event.composedPath() : void 0;
|
|
356
|
+
return this.state.containerGroups.findIndex(({ container, tabbableNodes }) => container.contains(element) || composedPath?.includes(container) || tabbableNodes.find((node) => node === element) || this.isControlledElement(container, element));
|
|
357
|
+
}
|
|
358
|
+
isControlledElement(container, element) {
|
|
359
|
+
if (!this.config.followControlledElements) return false;
|
|
360
|
+
return isControlledElement(container, element);
|
|
361
|
+
}
|
|
362
|
+
updateTabbableNodes() {
|
|
363
|
+
this.state.containerGroups = this.state.containers.map((container) => {
|
|
364
|
+
const tabbableNodes = getTabbables(container, { getShadowRoot: this.config.getShadowRoot });
|
|
365
|
+
const focusableNodes = getFocusables(container, { getShadowRoot: this.config.getShadowRoot });
|
|
366
|
+
const firstTabbableNode = tabbableNodes[0];
|
|
367
|
+
const lastTabbableNode = tabbableNodes[tabbableNodes.length - 1];
|
|
368
|
+
const firstDomTabbableNode = firstTabbableNode;
|
|
369
|
+
const lastDomTabbableNode = lastTabbableNode;
|
|
370
|
+
let posTabIndexesFound = false;
|
|
371
|
+
for (let i = 0; i < tabbableNodes.length; i++) if (getTabIndex(tabbableNodes[i]) > 0) {
|
|
372
|
+
posTabIndexesFound = true;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
function nextTabbableNode(node, forward = true) {
|
|
376
|
+
const nodeIdx = tabbableNodes.indexOf(node);
|
|
377
|
+
if (nodeIdx >= 0) return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
|
|
378
|
+
const focusableIdx = focusableNodes.indexOf(node);
|
|
379
|
+
if (focusableIdx < 0) return void 0;
|
|
380
|
+
if (forward) {
|
|
381
|
+
for (let i = focusableIdx + 1; i < focusableNodes.length; i++) if (isTabbable(focusableNodes[i])) return focusableNodes[i];
|
|
382
|
+
} else for (let i = focusableIdx - 1; i >= 0; i--) if (isTabbable(focusableNodes[i])) return focusableNodes[i];
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
container,
|
|
386
|
+
tabbableNodes,
|
|
387
|
+
focusableNodes,
|
|
388
|
+
posTabIndexesFound,
|
|
389
|
+
firstTabbableNode,
|
|
390
|
+
lastTabbableNode,
|
|
391
|
+
firstDomTabbableNode,
|
|
392
|
+
lastDomTabbableNode,
|
|
393
|
+
nextTabbableNode
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
this.state.tabbableGroups = this.state.containerGroups.filter((group) => group.tabbableNodes.length > 0);
|
|
397
|
+
if (this.state.tabbableGroups.length <= 0 && !this.getNodeForOption("fallbackFocus")) throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");
|
|
398
|
+
if (this.state.containerGroups.find((g) => g.posTabIndexesFound) && this.state.containerGroups.length > 1) throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.");
|
|
399
|
+
}
|
|
400
|
+
addListeners() {
|
|
401
|
+
if (!this.state.active) return;
|
|
402
|
+
activeFocusTraps.activateTrap(this.trapStack, this);
|
|
403
|
+
this.state.delayInitialFocusTimer = this.config.delayInitialFocus ? delay(() => {
|
|
404
|
+
this.tryFocus(this.getInitialFocusNode());
|
|
405
|
+
}) : this.tryFocus(this.getInitialFocusNode());
|
|
406
|
+
this.listenerCleanups.push(addDomEvent(this.doc, "focusin", this.handleFocus, true), addDomEvent(this.doc, "mousedown", this.handlePointerDown, {
|
|
407
|
+
capture: true,
|
|
408
|
+
passive: false
|
|
409
|
+
}), addDomEvent(this.doc, "touchstart", this.handlePointerDown, {
|
|
410
|
+
capture: true,
|
|
411
|
+
passive: false
|
|
412
|
+
}), addDomEvent(this.doc, "click", this.handleClick, {
|
|
413
|
+
capture: true,
|
|
414
|
+
passive: false
|
|
415
|
+
}), addDomEvent(this.doc, "keydown", this.handleTabKey, {
|
|
416
|
+
capture: true,
|
|
417
|
+
passive: false
|
|
418
|
+
}), addDomEvent(this.doc, "keydown", this.handleEscapeKey));
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
removeListeners() {
|
|
422
|
+
if (!this.state.active) return;
|
|
423
|
+
this.listenerCleanups.forEach((cleanup) => cleanup());
|
|
424
|
+
this.listenerCleanups = [];
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
activate(activateOptions) {
|
|
428
|
+
if (this.state.active) return this;
|
|
429
|
+
const onActivate = this.getOption(activateOptions, "onActivate");
|
|
430
|
+
const onPostActivate = this.getOption(activateOptions, "onPostActivate");
|
|
431
|
+
const checkCanFocusTrap = this.getOption(activateOptions, "checkCanFocusTrap");
|
|
432
|
+
if (!checkCanFocusTrap) this.updateTabbableNodes();
|
|
433
|
+
this.state.active = true;
|
|
434
|
+
this.state.paused = false;
|
|
435
|
+
this.state.nodeFocusedBeforeActivation = getActiveElement(this.doc);
|
|
436
|
+
onActivate?.();
|
|
437
|
+
const finishActivation = () => {
|
|
438
|
+
if (checkCanFocusTrap) this.updateTabbableNodes();
|
|
439
|
+
this.addListeners();
|
|
440
|
+
this.updateObservedNodes();
|
|
441
|
+
onPostActivate?.();
|
|
442
|
+
};
|
|
443
|
+
if (checkCanFocusTrap) {
|
|
444
|
+
checkCanFocusTrap(this.state.containers.concat()).then(finishActivation, finishActivation);
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
finishActivation();
|
|
448
|
+
return this;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
const isTabEvent = (event) => event.key === "Tab";
|
|
452
|
+
const valueOrHandler = (value, ...params) => typeof value === "function" ? value(...params) : value;
|
|
453
|
+
const isEscapeEvent = (event) => !event.isComposing && event.key === "Escape";
|
|
454
|
+
const delay = (fn) => setTimeout(fn, 0);
|
|
455
|
+
const isSelectableInput = (node) => node.localName === "input" && "select" in node && typeof node.select === "function";
|
|
456
|
+
|
|
457
|
+
//#endregion
|
|
458
|
+
//#region src/shared/focus-trap/index.ts
|
|
459
|
+
function trapFocus(el, options = {}) {
|
|
460
|
+
let trap;
|
|
461
|
+
const cleanup = raf(() => {
|
|
462
|
+
const contentEl = typeof el === "function" ? el() : el;
|
|
463
|
+
if (!contentEl) return;
|
|
464
|
+
trap = new FocusTrap(contentEl, {
|
|
465
|
+
escapeDeactivates: false,
|
|
466
|
+
allowOutsideClick: true,
|
|
467
|
+
preventScroll: true,
|
|
468
|
+
returnFocusOnDeactivate: true,
|
|
469
|
+
delayInitialFocus: false,
|
|
470
|
+
fallbackFocus: contentEl,
|
|
471
|
+
...options,
|
|
472
|
+
document: getDocument(contentEl)
|
|
473
|
+
});
|
|
474
|
+
try {
|
|
475
|
+
trap.activate();
|
|
476
|
+
} catch {}
|
|
477
|
+
});
|
|
478
|
+
return function destroy() {
|
|
479
|
+
trap?.deactivate();
|
|
480
|
+
cleanup();
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
//#endregion
|
|
485
|
+
export { FocusTrap as n, trapFocus as t };
|