ivt 0.3.2 → 0.3.4
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/accordion/index.mjs +19 -1
- package/dist/accordion/index.mjs.map +1 -1
- package/dist/alert/index.mjs +43 -1
- package/dist/alert/index.mjs.map +1 -1
- package/dist/alert-dialog/index.mjs +260 -1
- package/dist/alert-dialog/index.mjs.map +1 -1
- package/dist/avatar/index.mjs +164 -1
- package/dist/avatar/index.mjs.map +1 -1
- package/dist/badge/index.mjs +6 -1
- package/dist/badge/index.mjs.map +1 -1
- package/dist/base/index.mjs +760 -1
- package/dist/base/index.mjs.map +1 -1
- package/dist/button/index.mjs +6 -1
- package/dist/button/index.mjs.map +1 -1
- package/dist/calendar/index.mjs +11 -1
- package/dist/calendar/index.mjs.map +1 -1
- package/dist/card/index.mjs +55 -1
- package/dist/card/index.mjs.map +1 -1
- package/dist/chart/index.mjs +17042 -1
- package/dist/chart/index.mjs.map +1 -1
- package/dist/checkbox/index.mjs +223 -1
- package/dist/checkbox/index.mjs.map +1 -1
- package/dist/chunks/_commonjsHelpers-DqEvkrE1.mjs +6 -0
- package/dist/chunks/_commonjsHelpers-DqEvkrE1.mjs.map +1 -0
- package/dist/chunks/accordion-BMP2PSSC.mjs +455 -0
- package/dist/chunks/{accordion-CdshDFZC.mjs.map → accordion-BMP2PSSC.mjs.map} +1 -1
- package/dist/chunks/badge-DxuZhgBF.mjs +57 -0
- package/dist/chunks/{badge-BYqshEmA.mjs.map → badge-DxuZhgBF.mjs.map} +1 -1
- package/dist/chunks/bundle-mjs-tFg__FnT.mjs +4491 -0
- package/dist/chunks/{bundle-mjs-9BXytT_r.mjs.map → bundle-mjs-tFg__FnT.mjs.map} +1 -1
- package/dist/chunks/button-CX0htulo.mjs +47 -0
- package/dist/chunks/{button-DrFZXJ7z.mjs.map → button-CX0htulo.mjs.map} +1 -1
- package/dist/chunks/calendar-B4IV5RyM.mjs +7106 -0
- package/dist/chunks/calendar-B4IV5RyM.mjs.map +1 -0
- package/dist/chunks/check-B7209s3e.mjs +15 -0
- package/dist/chunks/{check-CimnOyD7.mjs.map → check-B7209s3e.mjs.map} +1 -1
- package/dist/chunks/chevron-down-D84DRJBv.mjs +15 -0
- package/dist/chunks/{chevron-down-D3fvbjxE.mjs.map → chevron-down-D84DRJBv.mjs.map} +1 -1
- package/dist/chunks/chevron-left-DtL1t1DJ.mjs +15 -0
- package/dist/chunks/{chevron-left-CrN7DlXg.mjs.map → chevron-left-DtL1t1DJ.mjs.map} +1 -1
- package/dist/chunks/chevron-right-Cdxg1JSQ.mjs +15 -0
- package/dist/chunks/{chevron-right-BMSCuDGK.mjs.map → chevron-right-Cdxg1JSQ.mjs.map} +1 -1
- package/dist/chunks/chevrons-up-down-DtBUG1i8.mjs +22 -0
- package/dist/chunks/{chevrons-up-down-DBgvRkZm.mjs.map → chevrons-up-down-DtBUG1i8.mjs.map} +1 -1
- package/dist/chunks/circle-BLWMZ9yp.mjs +17 -0
- package/dist/chunks/{circle-CGqt18Bd.mjs.map → circle-BLWMZ9yp.mjs.map} +1 -1
- package/dist/chunks/command-C8cVzg-x.mjs +611 -0
- package/dist/chunks/command-C8cVzg-x.mjs.map +1 -0
- package/dist/chunks/createLucideIcon-Ba0IWqsz.mjs +60 -0
- package/dist/chunks/{createLucideIcon-L-tld2uc.mjs.map → createLucideIcon-Ba0IWqsz.mjs.map} +1 -1
- package/dist/chunks/dialog-D9vbxUuQ.mjs +80 -0
- package/dist/chunks/{dialog-36eqHzT3.mjs.map → dialog-D9vbxUuQ.mjs.map} +1 -1
- package/dist/chunks/hover-card-idvDPXrI.mjs +274 -0
- package/dist/chunks/{hover-card-Cnd58du6.mjs.map → hover-card-idvDPXrI.mjs.map} +1 -1
- package/dist/chunks/index-6JUj2Tld.mjs +18 -0
- package/dist/chunks/{index-CRxQlsb9.mjs.map → index-6JUj2Tld.mjs.map} +1 -1
- package/dist/chunks/index-B0IElWB4.mjs +51 -0
- package/dist/chunks/{index-vmPXTidH.mjs.map → index-B0IElWB4.mjs.map} +1 -1
- package/dist/chunks/index-B4VRyyD1.mjs +40 -0
- package/dist/chunks/index-B4VRyyD1.mjs.map +1 -0
- package/dist/chunks/index-BE-_q4IW.mjs +266 -0
- package/dist/chunks/index-BE-_q4IW.mjs.map +1 -0
- package/dist/chunks/index-BNxaLFA6.mjs +216 -0
- package/dist/chunks/{index-LvOFIVGz.mjs.map → index-BNxaLFA6.mjs.map} +1 -1
- package/dist/chunks/index-BZUrHhU8.mjs +7 -0
- package/dist/chunks/{index-CLtWFQL5.mjs.map → index-BZUrHhU8.mjs.map} +1 -1
- package/dist/chunks/index-B_FsTtnF.mjs +110 -0
- package/dist/chunks/{index-CCcl327A.mjs.map → index-B_FsTtnF.mjs.map} +1 -1
- package/dist/chunks/index-CAg47KJ6.mjs +13 -0
- package/dist/chunks/{index-CXszXOf_.mjs.map → index-CAg47KJ6.mjs.map} +1 -1
- package/dist/chunks/index-CXuEm8w1.mjs +12 -0
- package/dist/chunks/{index-CU_y1XAz.mjs.map → index-CXuEm8w1.mjs.map} +1 -1
- package/dist/chunks/index-C_jFwfR_.mjs +77 -0
- package/dist/chunks/{index-CybgQKpz.mjs.map → index-C_jFwfR_.mjs.map} +1 -1
- package/dist/chunks/index-CglX-DNW.mjs +21 -0
- package/dist/chunks/index-CglX-DNW.mjs.map +1 -0
- package/dist/chunks/index-CyMuypYR.mjs +324 -0
- package/dist/chunks/{index-DUNcuWJE.mjs.map → index-CyMuypYR.mjs.map} +1 -1
- package/dist/chunks/index-D0S6rRRE.mjs +50 -0
- package/dist/chunks/{index-w9bxia3O.mjs.map → index-D0S6rRRE.mjs.map} +1 -1
- package/dist/chunks/index-D23BhVQG.mjs +859 -0
- package/dist/chunks/{index-DZHMFdr0.mjs.map → index-D23BhVQG.mjs.map} +1 -1
- package/dist/chunks/index-D2wfJaZh.mjs +145 -0
- package/dist/chunks/index-D2wfJaZh.mjs.map +1 -0
- package/dist/chunks/index-DNvm9MP3.mjs +34 -0
- package/dist/chunks/{index-D2sZp5OP.mjs.map → index-DNvm9MP3.mjs.map} +1 -1
- package/dist/chunks/index-Dm4_czlz.mjs +12 -0
- package/dist/chunks/index-Dm4_czlz.mjs.map +1 -0
- package/dist/chunks/index-PaJVyocC.mjs +151 -0
- package/dist/chunks/index-PaJVyocC.mjs.map +1 -0
- package/dist/chunks/index-kr6_v_F8.mjs +2370 -0
- package/dist/chunks/index-kr6_v_F8.mjs.map +1 -0
- package/dist/chunks/index-sz_BcBbA.mjs +1210 -0
- package/dist/chunks/index-sz_BcBbA.mjs.map +1 -0
- package/dist/chunks/input-DK1slFF1.mjs +14 -0
- package/dist/chunks/{input-85UFztMJ.mjs.map → input-DK1slFF1.mjs.map} +1 -1
- package/dist/chunks/label-D7ONQdHc.mjs +32 -0
- package/dist/chunks/{label-CICFzZIt.mjs.map → label-D7ONQdHc.mjs.map} +1 -1
- package/dist/chunks/pagination-BM_IQ6Qk.mjs +106 -0
- package/dist/chunks/{pagination-CReDQes6.mjs.map → pagination-BM_IQ6Qk.mjs.map} +1 -1
- package/dist/chunks/popover-D3F326FR.mjs +308 -0
- package/dist/chunks/{popover-Cn2ZTvKd.mjs.map → popover-D3F326FR.mjs.map} +1 -1
- package/dist/chunks/progress-BCl5yD5Q.mjs +99 -0
- package/dist/chunks/{progress-CSxQH6-f.mjs.map → progress-BCl5yD5Q.mjs.map} +1 -1
- package/dist/chunks/scroll-area-DB3eUx8V.mjs +791 -0
- package/dist/chunks/scroll-area-DB3eUx8V.mjs.map +1 -0
- package/dist/chunks/select-Cw81y8pT.mjs +104 -0
- package/dist/chunks/{select-BR6_N_Yo.mjs.map → select-Cw81y8pT.mjs.map} +1 -1
- package/dist/chunks/separator-2k1C7RSn.mjs +48 -0
- package/dist/chunks/{separator-BB6-E9Z1.mjs.map → separator-2k1C7RSn.mjs.map} +1 -1
- package/dist/chunks/skeleton-qx8-vr62.mjs +13 -0
- package/dist/chunks/{skeleton-XPWWiaac.mjs.map → skeleton-qx8-vr62.mjs.map} +1 -1
- package/dist/chunks/sortable-D8ayoe_b.mjs +4221 -0
- package/dist/chunks/sortable-D8ayoe_b.mjs.map +1 -0
- package/dist/chunks/table-BDNUhtz-.mjs +62 -0
- package/dist/chunks/{table-LQIHzPHi.mjs.map → table-BDNUhtz-.mjs.map} +1 -1
- package/dist/chunks/toggle-CE2ycSdL.mjs +65 -0
- package/dist/chunks/{toggle-Co72WXGd.mjs.map → toggle-CE2ycSdL.mjs.map} +1 -1
- package/dist/chunks/tooltip-DLD0ycR4.mjs +596 -0
- package/dist/chunks/{tooltip-qX2HjdJP.mjs.map → tooltip-DLD0ycR4.mjs.map} +1 -1
- package/dist/chunks/tslib.es6-BgHLrbno.mjs +61 -0
- package/dist/chunks/{tslib.es6-cMGqxriw.mjs.map → tslib.es6-BgHLrbno.mjs.map} +1 -1
- package/dist/chunks/utils-BUelq9Ro.mjs +42 -0
- package/dist/chunks/utils-BUelq9Ro.mjs.map +1 -0
- package/dist/chunks/x-Bjz0Vo6R.mjs +22 -0
- package/dist/chunks/{x-BNLl0E-E.mjs.map → x-Bjz0Vo6R.mjs.map} +1 -1
- package/dist/combobox/index.mjs +65 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/command/index.mjs +23 -1
- package/dist/command/index.mjs.map +1 -1
- package/dist/data-table/index.mjs +673 -1
- package/dist/data-table/index.mjs.map +1 -1
- package/dist/dialog/index.mjs +22 -1
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/dropdown-menu/index.mjs +438 -1
- package/dist/dropdown-menu/index.mjs.map +1 -1
- package/dist/dropzone/index.mjs +7839 -1
- package/dist/dropzone/index.mjs.map +1 -1
- package/dist/form/index.mjs +649 -1
- package/dist/form/index.mjs.map +1 -1
- package/dist/hover-card/index.mjs +18 -1
- package/dist/hover-card/index.mjs.map +1 -1
- package/dist/icon/index.mjs +317 -1
- package/dist/icon/index.mjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/input/index.mjs +4 -1
- package/dist/input/index.mjs.map +1 -1
- package/dist/ivt.css +1 -1
- package/dist/label/index.mjs +8 -1
- package/dist/label/index.mjs.map +1 -1
- package/dist/menubar/index.mjs +583 -1
- package/dist/menubar/index.mjs.map +1 -1
- package/dist/multi-select/index.mjs +297 -1
- package/dist/multi-select/index.mjs.map +1 -1
- package/dist/pagination/index.mjs +10 -1
- package/dist/pagination/index.mjs.map +1 -1
- package/dist/popover/index.mjs +21 -1
- package/dist/popover/index.mjs.map +1 -1
- package/dist/progress/index.mjs +9 -1
- package/dist/progress/index.mjs.map +1 -1
- package/dist/radio-group/index.mjs +267 -1
- package/dist/radio-group/index.mjs.map +1 -1
- package/dist/scroll-area/index.mjs +15 -1
- package/dist/scroll-area/index.mjs.map +1 -1
- package/dist/select/index.mjs +8 -1
- package/dist/select/index.mjs.map +1 -1
- package/dist/separator/index.mjs +8 -1
- package/dist/separator/index.mjs.map +1 -1
- package/dist/sheet/index.mjs +96 -1
- package/dist/sheet/index.mjs.map +1 -1
- package/dist/skeleton/index.mjs +4 -1
- package/dist/skeleton/index.mjs.map +1 -1
- package/dist/sonner/index.mjs +1140 -1
- package/dist/sonner/index.mjs.map +1 -1
- package/dist/sortable/index.mjs +8 -1
- package/dist/sortable/index.mjs.map +1 -1
- package/dist/table/index.mjs +4 -1
- package/dist/table/index.mjs.map +1 -1
- package/dist/tabs/index.mjs +193 -1
- package/dist/tabs/index.mjs.map +1 -1
- package/dist/textarea/index.mjs +13 -1
- package/dist/textarea/index.mjs.map +1 -1
- package/dist/toast/index.mjs +705 -1
- package/dist/toast/index.mjs.map +1 -1
- package/dist/toggle/index.mjs +12 -1
- package/dist/toggle/index.mjs.map +1 -1
- package/dist/toggle-group/index.mjs +219 -1
- package/dist/toggle-group/index.mjs.map +1 -1
- package/dist/tooltip/index.mjs +20 -1
- package/dist/tooltip/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/_commonjsHelpers-6qLFzZa5.mjs +0 -2
- package/dist/chunks/_commonjsHelpers-6qLFzZa5.mjs.map +0 -1
- package/dist/chunks/accordion-CdshDFZC.mjs +0 -2
- package/dist/chunks/badge-BYqshEmA.mjs +0 -2
- package/dist/chunks/bundle-mjs-9BXytT_r.mjs +0 -2
- package/dist/chunks/button-DrFZXJ7z.mjs +0 -2
- package/dist/chunks/calendar-BY6t8wdJ.mjs +0 -2
- package/dist/chunks/calendar-BY6t8wdJ.mjs.map +0 -1
- package/dist/chunks/check-CimnOyD7.mjs +0 -2
- package/dist/chunks/chevron-down-D3fvbjxE.mjs +0 -2
- package/dist/chunks/chevron-left-CrN7DlXg.mjs +0 -2
- package/dist/chunks/chevron-right-BMSCuDGK.mjs +0 -2
- package/dist/chunks/chevrons-up-down-DBgvRkZm.mjs +0 -2
- package/dist/chunks/circle-CGqt18Bd.mjs +0 -2
- package/dist/chunks/command-C6ON-ciq.mjs +0 -2
- package/dist/chunks/command-C6ON-ciq.mjs.map +0 -1
- package/dist/chunks/createLucideIcon-L-tld2uc.mjs +0 -2
- package/dist/chunks/dialog-36eqHzT3.mjs +0 -2
- package/dist/chunks/hover-card-Cnd58du6.mjs +0 -2
- package/dist/chunks/index-B4QsDzeM.mjs +0 -2
- package/dist/chunks/index-B4QsDzeM.mjs.map +0 -1
- package/dist/chunks/index-BdpYc58_.mjs +0 -2
- package/dist/chunks/index-BdpYc58_.mjs.map +0 -1
- package/dist/chunks/index-CCcl327A.mjs +0 -2
- package/dist/chunks/index-CLtWFQL5.mjs +0 -2
- package/dist/chunks/index-COvW87ew.mjs +0 -2
- package/dist/chunks/index-COvW87ew.mjs.map +0 -1
- package/dist/chunks/index-CRxQlsb9.mjs +0 -2
- package/dist/chunks/index-CU_y1XAz.mjs +0 -2
- package/dist/chunks/index-CXszXOf_.mjs +0 -2
- package/dist/chunks/index-CdJCOoFA.mjs +0 -2
- package/dist/chunks/index-CdJCOoFA.mjs.map +0 -1
- package/dist/chunks/index-Cpq7N5Ej.mjs +0 -2
- package/dist/chunks/index-Cpq7N5Ej.mjs.map +0 -1
- package/dist/chunks/index-CybgQKpz.mjs +0 -2
- package/dist/chunks/index-D2sZp5OP.mjs +0 -2
- package/dist/chunks/index-DOyt-JEx.mjs +0 -2
- package/dist/chunks/index-DOyt-JEx.mjs.map +0 -1
- package/dist/chunks/index-DUNcuWJE.mjs +0 -2
- package/dist/chunks/index-DZHMFdr0.mjs +0 -2
- package/dist/chunks/index-LvOFIVGz.mjs +0 -2
- package/dist/chunks/index-lvPXnk5F.mjs +0 -2
- package/dist/chunks/index-lvPXnk5F.mjs.map +0 -1
- package/dist/chunks/index-vmPXTidH.mjs +0 -2
- package/dist/chunks/index-w9bxia3O.mjs +0 -2
- package/dist/chunks/index-xew3kygQ.mjs +0 -2
- package/dist/chunks/index-xew3kygQ.mjs.map +0 -1
- package/dist/chunks/input-85UFztMJ.mjs +0 -2
- package/dist/chunks/label-CICFzZIt.mjs +0 -2
- package/dist/chunks/pagination-CReDQes6.mjs +0 -2
- package/dist/chunks/popover-Cn2ZTvKd.mjs +0 -2
- package/dist/chunks/progress-CSxQH6-f.mjs +0 -2
- package/dist/chunks/scroll-area-CvCz7cL_.mjs +0 -2
- package/dist/chunks/scroll-area-CvCz7cL_.mjs.map +0 -1
- package/dist/chunks/select-BR6_N_Yo.mjs +0 -2
- package/dist/chunks/separator-BB6-E9Z1.mjs +0 -2
- package/dist/chunks/skeleton-XPWWiaac.mjs +0 -2
- package/dist/chunks/sortable-CqPFGn8Q.mjs +0 -2
- package/dist/chunks/sortable-CqPFGn8Q.mjs.map +0 -1
- package/dist/chunks/table-LQIHzPHi.mjs +0 -2
- package/dist/chunks/toggle-Co72WXGd.mjs +0 -2
- package/dist/chunks/tooltip-qX2HjdJP.mjs +0 -2
- package/dist/chunks/tslib.es6-cMGqxriw.mjs +0 -2
- package/dist/chunks/utils-BctauAA9.mjs +0 -2
- package/dist/chunks/utils-BctauAA9.mjs.map +0 -1
- package/dist/chunks/x-BNLl0E-E.mjs +0 -2
@@ -0,0 +1,1210 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { useState } from 'react';
|
3
|
+
import { u as useComposedRefs } from './index-B4VRyyD1.mjs';
|
4
|
+
import { P as Primitive } from './index-D0S6rRRE.mjs';
|
5
|
+
import { u as useCallbackRef$1 } from './index-CAg47KJ6.mjs';
|
6
|
+
import { jsx } from 'react/jsx-runtime';
|
7
|
+
import { _ as __assign, a as __rest, b as __spreadArray } from './tslib.es6-BgHLrbno.mjs';
|
8
|
+
|
9
|
+
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
10
|
+
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
11
|
+
var EVENT_OPTIONS = {
|
12
|
+
bubbles: false,
|
13
|
+
cancelable: true
|
14
|
+
};
|
15
|
+
var FOCUS_SCOPE_NAME = "FocusScope";
|
16
|
+
var FocusScope = React.forwardRef((props, forwardedRef)=>{
|
17
|
+
const { loop = false, trapped = false, onMountAutoFocus: onMountAutoFocusProp, onUnmountAutoFocus: onUnmountAutoFocusProp, ...scopeProps } = props;
|
18
|
+
const [container, setContainer] = React.useState(null);
|
19
|
+
const onMountAutoFocus = useCallbackRef$1(onMountAutoFocusProp);
|
20
|
+
const onUnmountAutoFocus = useCallbackRef$1(onUnmountAutoFocusProp);
|
21
|
+
const lastFocusedElementRef = React.useRef(null);
|
22
|
+
const composedRefs = useComposedRefs(forwardedRef, (node)=>setContainer(node));
|
23
|
+
const focusScope = React.useRef({
|
24
|
+
paused: false,
|
25
|
+
pause () {
|
26
|
+
this.paused = true;
|
27
|
+
},
|
28
|
+
resume () {
|
29
|
+
this.paused = false;
|
30
|
+
}
|
31
|
+
}).current;
|
32
|
+
React.useEffect(()=>{
|
33
|
+
if (trapped) {
|
34
|
+
let handleFocusIn2 = function(event) {
|
35
|
+
if (focusScope.paused || !container) return;
|
36
|
+
const target = event.target;
|
37
|
+
if (container.contains(target)) {
|
38
|
+
lastFocusedElementRef.current = target;
|
39
|
+
} else {
|
40
|
+
focus(lastFocusedElementRef.current, {
|
41
|
+
select: true
|
42
|
+
});
|
43
|
+
}
|
44
|
+
}, handleFocusOut2 = function(event) {
|
45
|
+
if (focusScope.paused || !container) return;
|
46
|
+
const relatedTarget = event.relatedTarget;
|
47
|
+
if (relatedTarget === null) return;
|
48
|
+
if (!container.contains(relatedTarget)) {
|
49
|
+
focus(lastFocusedElementRef.current, {
|
50
|
+
select: true
|
51
|
+
});
|
52
|
+
}
|
53
|
+
}, handleMutations2 = function(mutations) {
|
54
|
+
const focusedElement = document.activeElement;
|
55
|
+
if (focusedElement !== document.body) return;
|
56
|
+
for (const mutation of mutations){
|
57
|
+
if (mutation.removedNodes.length > 0) focus(container);
|
58
|
+
}
|
59
|
+
};
|
60
|
+
document.addEventListener("focusin", handleFocusIn2);
|
61
|
+
document.addEventListener("focusout", handleFocusOut2);
|
62
|
+
const mutationObserver = new MutationObserver(handleMutations2);
|
63
|
+
if (container) mutationObserver.observe(container, {
|
64
|
+
childList: true,
|
65
|
+
subtree: true
|
66
|
+
});
|
67
|
+
return ()=>{
|
68
|
+
document.removeEventListener("focusin", handleFocusIn2);
|
69
|
+
document.removeEventListener("focusout", handleFocusOut2);
|
70
|
+
mutationObserver.disconnect();
|
71
|
+
};
|
72
|
+
}
|
73
|
+
}, [
|
74
|
+
trapped,
|
75
|
+
container,
|
76
|
+
focusScope.paused
|
77
|
+
]);
|
78
|
+
React.useEffect(()=>{
|
79
|
+
if (container) {
|
80
|
+
focusScopesStack.add(focusScope);
|
81
|
+
const previouslyFocusedElement = document.activeElement;
|
82
|
+
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
83
|
+
if (!hasFocusedCandidate) {
|
84
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
85
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
86
|
+
container.dispatchEvent(mountEvent);
|
87
|
+
if (!mountEvent.defaultPrevented) {
|
88
|
+
focusFirst(removeLinks(getTabbableCandidates(container)), {
|
89
|
+
select: true
|
90
|
+
});
|
91
|
+
if (document.activeElement === previouslyFocusedElement) {
|
92
|
+
focus(container);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return ()=>{
|
97
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
98
|
+
setTimeout(()=>{
|
99
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
100
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
101
|
+
container.dispatchEvent(unmountEvent);
|
102
|
+
if (!unmountEvent.defaultPrevented) {
|
103
|
+
focus(previouslyFocusedElement ?? document.body, {
|
104
|
+
select: true
|
105
|
+
});
|
106
|
+
}
|
107
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
108
|
+
focusScopesStack.remove(focusScope);
|
109
|
+
}, 0);
|
110
|
+
};
|
111
|
+
}
|
112
|
+
}, [
|
113
|
+
container,
|
114
|
+
onMountAutoFocus,
|
115
|
+
onUnmountAutoFocus,
|
116
|
+
focusScope
|
117
|
+
]);
|
118
|
+
const handleKeyDown = React.useCallback((event)=>{
|
119
|
+
if (!loop && !trapped) return;
|
120
|
+
if (focusScope.paused) return;
|
121
|
+
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
122
|
+
const focusedElement = document.activeElement;
|
123
|
+
if (isTabKey && focusedElement) {
|
124
|
+
const container2 = event.currentTarget;
|
125
|
+
const [first, last] = getTabbableEdges(container2);
|
126
|
+
const hasTabbableElementsInside = first && last;
|
127
|
+
if (!hasTabbableElementsInside) {
|
128
|
+
if (focusedElement === container2) event.preventDefault();
|
129
|
+
} else {
|
130
|
+
if (!event.shiftKey && focusedElement === last) {
|
131
|
+
event.preventDefault();
|
132
|
+
if (loop) focus(first, {
|
133
|
+
select: true
|
134
|
+
});
|
135
|
+
} else if (event.shiftKey && focusedElement === first) {
|
136
|
+
event.preventDefault();
|
137
|
+
if (loop) focus(last, {
|
138
|
+
select: true
|
139
|
+
});
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}, [
|
144
|
+
loop,
|
145
|
+
trapped,
|
146
|
+
focusScope.paused
|
147
|
+
]);
|
148
|
+
return /* @__PURE__ */ jsx(Primitive.div, {
|
149
|
+
tabIndex: -1,
|
150
|
+
...scopeProps,
|
151
|
+
ref: composedRefs,
|
152
|
+
onKeyDown: handleKeyDown
|
153
|
+
});
|
154
|
+
});
|
155
|
+
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
156
|
+
function focusFirst(candidates, { select = false } = {}) {
|
157
|
+
const previouslyFocusedElement = document.activeElement;
|
158
|
+
for (const candidate of candidates){
|
159
|
+
focus(candidate, {
|
160
|
+
select
|
161
|
+
});
|
162
|
+
if (document.activeElement !== previouslyFocusedElement) return;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
function getTabbableEdges(container) {
|
166
|
+
const candidates = getTabbableCandidates(container);
|
167
|
+
const first = findVisible(candidates, container);
|
168
|
+
const last = findVisible(candidates.reverse(), container);
|
169
|
+
return [
|
170
|
+
first,
|
171
|
+
last
|
172
|
+
];
|
173
|
+
}
|
174
|
+
function getTabbableCandidates(container) {
|
175
|
+
const nodes = [];
|
176
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
177
|
+
acceptNode: (node)=>{
|
178
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
179
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
180
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
181
|
+
}
|
182
|
+
});
|
183
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
184
|
+
return nodes;
|
185
|
+
}
|
186
|
+
function findVisible(elements, container) {
|
187
|
+
for (const element of elements){
|
188
|
+
if (!isHidden(element, {
|
189
|
+
upTo: container
|
190
|
+
})) return element;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
function isHidden(node, { upTo }) {
|
194
|
+
if (getComputedStyle(node).visibility === "hidden") return true;
|
195
|
+
while(node){
|
196
|
+
if (upTo !== void 0 && node === upTo) return false;
|
197
|
+
if (getComputedStyle(node).display === "none") return true;
|
198
|
+
node = node.parentElement;
|
199
|
+
}
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
function isSelectableInput(element) {
|
203
|
+
return element instanceof HTMLInputElement && "select" in element;
|
204
|
+
}
|
205
|
+
function focus(element, { select = false } = {}) {
|
206
|
+
if (element && element.focus) {
|
207
|
+
const previouslyFocusedElement = document.activeElement;
|
208
|
+
element.focus({
|
209
|
+
preventScroll: true
|
210
|
+
});
|
211
|
+
if (element !== previouslyFocusedElement && isSelectableInput(element) && select) element.select();
|
212
|
+
}
|
213
|
+
}
|
214
|
+
var focusScopesStack = createFocusScopesStack();
|
215
|
+
function createFocusScopesStack() {
|
216
|
+
let stack = [];
|
217
|
+
return {
|
218
|
+
add (focusScope) {
|
219
|
+
const activeFocusScope = stack[0];
|
220
|
+
if (focusScope !== activeFocusScope) {
|
221
|
+
activeFocusScope?.pause();
|
222
|
+
}
|
223
|
+
stack = arrayRemove(stack, focusScope);
|
224
|
+
stack.unshift(focusScope);
|
225
|
+
},
|
226
|
+
remove (focusScope) {
|
227
|
+
stack = arrayRemove(stack, focusScope);
|
228
|
+
stack[0]?.resume();
|
229
|
+
}
|
230
|
+
};
|
231
|
+
}
|
232
|
+
function arrayRemove(array, item) {
|
233
|
+
const updatedArray = [
|
234
|
+
...array
|
235
|
+
];
|
236
|
+
const index = updatedArray.indexOf(item);
|
237
|
+
if (index !== -1) {
|
238
|
+
updatedArray.splice(index, 1);
|
239
|
+
}
|
240
|
+
return updatedArray;
|
241
|
+
}
|
242
|
+
function removeLinks(items) {
|
243
|
+
return items.filter((item)=>item.tagName !== "A");
|
244
|
+
}
|
245
|
+
|
246
|
+
var count = 0;
|
247
|
+
function useFocusGuards() {
|
248
|
+
React.useEffect(()=>{
|
249
|
+
const edgeGuards = document.querySelectorAll("[data-radix-focus-guard]");
|
250
|
+
document.body.insertAdjacentElement("afterbegin", edgeGuards[0] ?? createFocusGuard());
|
251
|
+
document.body.insertAdjacentElement("beforeend", edgeGuards[1] ?? createFocusGuard());
|
252
|
+
count++;
|
253
|
+
return ()=>{
|
254
|
+
if (count === 1) {
|
255
|
+
document.querySelectorAll("[data-radix-focus-guard]").forEach((node)=>node.remove());
|
256
|
+
}
|
257
|
+
count--;
|
258
|
+
};
|
259
|
+
}, []);
|
260
|
+
}
|
261
|
+
function createFocusGuard() {
|
262
|
+
const element = document.createElement("span");
|
263
|
+
element.setAttribute("data-radix-focus-guard", "");
|
264
|
+
element.tabIndex = 0;
|
265
|
+
element.style.outline = "none";
|
266
|
+
element.style.opacity = "0";
|
267
|
+
element.style.position = "fixed";
|
268
|
+
element.style.pointerEvents = "none";
|
269
|
+
return element;
|
270
|
+
}
|
271
|
+
|
272
|
+
var zeroRightClassName = 'right-scroll-bar-position';
|
273
|
+
var fullWidthClassName = 'width-before-scroll-bar';
|
274
|
+
var noScrollbarsClassName = 'with-scroll-bars-hidden';
|
275
|
+
/**
|
276
|
+
* Name of a CSS variable containing the amount of "hidden" scrollbar
|
277
|
+
* ! might be undefined ! use will fallback!
|
278
|
+
*/ var removedBarSizeVariable = '--removed-body-scroll-bar-size';
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Assigns a value for a given ref, no matter of the ref format
|
282
|
+
* @param {RefObject} ref - a callback function or ref object
|
283
|
+
* @param value - a new value
|
284
|
+
*
|
285
|
+
* @see https://github.com/theKashey/use-callback-ref#assignref
|
286
|
+
* @example
|
287
|
+
* const refObject = useRef();
|
288
|
+
* const refFn = (ref) => {....}
|
289
|
+
*
|
290
|
+
* assignRef(refObject, "refValue");
|
291
|
+
* assignRef(refFn, "refValue");
|
292
|
+
*/ function assignRef(ref, value) {
|
293
|
+
if (typeof ref === 'function') {
|
294
|
+
ref(value);
|
295
|
+
} else if (ref) {
|
296
|
+
ref.current = value;
|
297
|
+
}
|
298
|
+
return ref;
|
299
|
+
}
|
300
|
+
|
301
|
+
/**
|
302
|
+
* creates a MutableRef with ref change callback
|
303
|
+
* @param initialValue - initial ref value
|
304
|
+
* @param {Function} callback - a callback to run when value changes
|
305
|
+
*
|
306
|
+
* @example
|
307
|
+
* const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
|
308
|
+
* ref.current = 1;
|
309
|
+
* // prints 0 -> 1
|
310
|
+
*
|
311
|
+
* @see https://reactjs.org/docs/hooks-reference.html#useref
|
312
|
+
* @see https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
|
313
|
+
* @returns {MutableRefObject}
|
314
|
+
*/ function useCallbackRef(initialValue, callback) {
|
315
|
+
var ref = useState(function() {
|
316
|
+
return {
|
317
|
+
// value
|
318
|
+
value: initialValue,
|
319
|
+
// last callback
|
320
|
+
callback: callback,
|
321
|
+
// "memoized" public interface
|
322
|
+
facade: {
|
323
|
+
get current () {
|
324
|
+
return ref.value;
|
325
|
+
},
|
326
|
+
set current (value){
|
327
|
+
var last = ref.value;
|
328
|
+
if (last !== value) {
|
329
|
+
ref.value = value;
|
330
|
+
ref.callback(value, last);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
}
|
334
|
+
};
|
335
|
+
})[0];
|
336
|
+
// update callback
|
337
|
+
ref.callback = callback;
|
338
|
+
return ref.facade;
|
339
|
+
}
|
340
|
+
|
341
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
342
|
+
var currentValues = new WeakMap();
|
343
|
+
/**
|
344
|
+
* Merges two or more refs together providing a single interface to set their value
|
345
|
+
* @param {RefObject|Ref} refs
|
346
|
+
* @returns {MutableRefObject} - a new ref, which translates all changes to {refs}
|
347
|
+
*
|
348
|
+
* @see {@link mergeRefs} a version without buit-in memoization
|
349
|
+
* @see https://github.com/theKashey/use-callback-ref#usemergerefs
|
350
|
+
* @example
|
351
|
+
* const Component = React.forwardRef((props, ref) => {
|
352
|
+
* const ownRef = useRef();
|
353
|
+
* const domRef = useMergeRefs([ref, ownRef]); // 👈 merge together
|
354
|
+
* return <div ref={domRef}>...</div>
|
355
|
+
* }
|
356
|
+
*/ function useMergeRefs(refs, defaultValue) {
|
357
|
+
var callbackRef = useCallbackRef(null, function(newValue) {
|
358
|
+
return refs.forEach(function(ref) {
|
359
|
+
return assignRef(ref, newValue);
|
360
|
+
});
|
361
|
+
});
|
362
|
+
// handle refs changes - added or removed
|
363
|
+
useIsomorphicLayoutEffect(function() {
|
364
|
+
var oldValue = currentValues.get(callbackRef);
|
365
|
+
if (oldValue) {
|
366
|
+
var prevRefs_1 = new Set(oldValue);
|
367
|
+
var nextRefs_1 = new Set(refs);
|
368
|
+
var current_1 = callbackRef.current;
|
369
|
+
prevRefs_1.forEach(function(ref) {
|
370
|
+
if (!nextRefs_1.has(ref)) {
|
371
|
+
assignRef(ref, null);
|
372
|
+
}
|
373
|
+
});
|
374
|
+
nextRefs_1.forEach(function(ref) {
|
375
|
+
if (!prevRefs_1.has(ref)) {
|
376
|
+
assignRef(ref, current_1);
|
377
|
+
}
|
378
|
+
});
|
379
|
+
}
|
380
|
+
currentValues.set(callbackRef, refs);
|
381
|
+
}, [
|
382
|
+
refs
|
383
|
+
]);
|
384
|
+
return callbackRef;
|
385
|
+
}
|
386
|
+
|
387
|
+
function ItoI(a) {
|
388
|
+
return a;
|
389
|
+
}
|
390
|
+
function innerCreateMedium(defaults, middleware) {
|
391
|
+
if (middleware === void 0) {
|
392
|
+
middleware = ItoI;
|
393
|
+
}
|
394
|
+
var buffer = [];
|
395
|
+
var assigned = false;
|
396
|
+
var medium = {
|
397
|
+
read: function() {
|
398
|
+
if (assigned) {
|
399
|
+
throw new Error('Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.');
|
400
|
+
}
|
401
|
+
if (buffer.length) {
|
402
|
+
return buffer[buffer.length - 1];
|
403
|
+
}
|
404
|
+
return defaults;
|
405
|
+
},
|
406
|
+
useMedium: function(data) {
|
407
|
+
var item = middleware(data, assigned);
|
408
|
+
buffer.push(item);
|
409
|
+
return function() {
|
410
|
+
buffer = buffer.filter(function(x) {
|
411
|
+
return x !== item;
|
412
|
+
});
|
413
|
+
};
|
414
|
+
},
|
415
|
+
assignSyncMedium: function(cb) {
|
416
|
+
assigned = true;
|
417
|
+
while(buffer.length){
|
418
|
+
var cbs = buffer;
|
419
|
+
buffer = [];
|
420
|
+
cbs.forEach(cb);
|
421
|
+
}
|
422
|
+
buffer = {
|
423
|
+
push: function(x) {
|
424
|
+
return cb(x);
|
425
|
+
},
|
426
|
+
filter: function() {
|
427
|
+
return buffer;
|
428
|
+
}
|
429
|
+
};
|
430
|
+
},
|
431
|
+
assignMedium: function(cb) {
|
432
|
+
assigned = true;
|
433
|
+
var pendingQueue = [];
|
434
|
+
if (buffer.length) {
|
435
|
+
var cbs = buffer;
|
436
|
+
buffer = [];
|
437
|
+
cbs.forEach(cb);
|
438
|
+
pendingQueue = buffer;
|
439
|
+
}
|
440
|
+
var executeQueue = function() {
|
441
|
+
var cbs = pendingQueue;
|
442
|
+
pendingQueue = [];
|
443
|
+
cbs.forEach(cb);
|
444
|
+
};
|
445
|
+
var cycle = function() {
|
446
|
+
return Promise.resolve().then(executeQueue);
|
447
|
+
};
|
448
|
+
cycle();
|
449
|
+
buffer = {
|
450
|
+
push: function(x) {
|
451
|
+
pendingQueue.push(x);
|
452
|
+
cycle();
|
453
|
+
},
|
454
|
+
filter: function(filter) {
|
455
|
+
pendingQueue = pendingQueue.filter(filter);
|
456
|
+
return buffer;
|
457
|
+
}
|
458
|
+
};
|
459
|
+
}
|
460
|
+
};
|
461
|
+
return medium;
|
462
|
+
}
|
463
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
464
|
+
function createSidecarMedium(options) {
|
465
|
+
if (options === void 0) {
|
466
|
+
options = {};
|
467
|
+
}
|
468
|
+
var medium = innerCreateMedium(null);
|
469
|
+
medium.options = __assign({
|
470
|
+
async: true,
|
471
|
+
ssr: false
|
472
|
+
}, options);
|
473
|
+
return medium;
|
474
|
+
}
|
475
|
+
|
476
|
+
var SideCar$1 = function(_a) {
|
477
|
+
var sideCar = _a.sideCar, rest = __rest(_a, [
|
478
|
+
"sideCar"
|
479
|
+
]);
|
480
|
+
if (!sideCar) {
|
481
|
+
throw new Error('Sidecar: please provide `sideCar` property to import the right car');
|
482
|
+
}
|
483
|
+
var Target = sideCar.read();
|
484
|
+
if (!Target) {
|
485
|
+
throw new Error('Sidecar medium not found');
|
486
|
+
}
|
487
|
+
return React.createElement(Target, __assign({}, rest));
|
488
|
+
};
|
489
|
+
SideCar$1.isSideCarExport = true;
|
490
|
+
function exportSidecar(medium, exported) {
|
491
|
+
medium.useMedium(exported);
|
492
|
+
return SideCar$1;
|
493
|
+
}
|
494
|
+
|
495
|
+
var effectCar = createSidecarMedium();
|
496
|
+
|
497
|
+
var nothing = function() {
|
498
|
+
return;
|
499
|
+
};
|
500
|
+
/**
|
501
|
+
* Removes scrollbar from the page and contain the scroll within the Lock
|
502
|
+
*/ var RemoveScroll = React.forwardRef(function(props, parentRef) {
|
503
|
+
var ref = React.useRef(null);
|
504
|
+
var _a = React.useState({
|
505
|
+
onScrollCapture: nothing,
|
506
|
+
onWheelCapture: nothing,
|
507
|
+
onTouchMoveCapture: nothing
|
508
|
+
}), callbacks = _a[0], setCallbacks = _a[1];
|
509
|
+
var forwardProps = props.forwardProps, children = props.children, className = props.className, removeScrollBar = props.removeScrollBar, enabled = props.enabled, shards = props.shards, sideCar = props.sideCar, noRelative = props.noRelative, noIsolation = props.noIsolation, inert = props.inert, allowPinchZoom = props.allowPinchZoom, _b = props.as, Container = _b === void 0 ? 'div' : _b, gapMode = props.gapMode, rest = __rest(props, [
|
510
|
+
"forwardProps",
|
511
|
+
"children",
|
512
|
+
"className",
|
513
|
+
"removeScrollBar",
|
514
|
+
"enabled",
|
515
|
+
"shards",
|
516
|
+
"sideCar",
|
517
|
+
"noRelative",
|
518
|
+
"noIsolation",
|
519
|
+
"inert",
|
520
|
+
"allowPinchZoom",
|
521
|
+
"as",
|
522
|
+
"gapMode"
|
523
|
+
]);
|
524
|
+
var SideCar = sideCar;
|
525
|
+
var containerRef = useMergeRefs([
|
526
|
+
ref,
|
527
|
+
parentRef
|
528
|
+
]);
|
529
|
+
var containerProps = __assign(__assign({}, rest), callbacks);
|
530
|
+
return React.createElement(React.Fragment, null, enabled && React.createElement(SideCar, {
|
531
|
+
sideCar: effectCar,
|
532
|
+
removeScrollBar: removeScrollBar,
|
533
|
+
shards: shards,
|
534
|
+
noRelative: noRelative,
|
535
|
+
noIsolation: noIsolation,
|
536
|
+
inert: inert,
|
537
|
+
setCallbacks: setCallbacks,
|
538
|
+
allowPinchZoom: !!allowPinchZoom,
|
539
|
+
lockRef: ref,
|
540
|
+
gapMode: gapMode
|
541
|
+
}), forwardProps ? React.cloneElement(React.Children.only(children), __assign(__assign({}, containerProps), {
|
542
|
+
ref: containerRef
|
543
|
+
})) : React.createElement(Container, __assign({}, containerProps, {
|
544
|
+
className: className,
|
545
|
+
ref: containerRef
|
546
|
+
}), children));
|
547
|
+
});
|
548
|
+
RemoveScroll.defaultProps = {
|
549
|
+
enabled: true,
|
550
|
+
removeScrollBar: true,
|
551
|
+
inert: false
|
552
|
+
};
|
553
|
+
RemoveScroll.classNames = {
|
554
|
+
fullWidth: fullWidthClassName,
|
555
|
+
zeroRight: zeroRightClassName
|
556
|
+
};
|
557
|
+
|
558
|
+
var getNonce = function() {
|
559
|
+
if (typeof __webpack_nonce__ !== 'undefined') {
|
560
|
+
return __webpack_nonce__;
|
561
|
+
}
|
562
|
+
return undefined;
|
563
|
+
};
|
564
|
+
|
565
|
+
function makeStyleTag() {
|
566
|
+
if (!document) return null;
|
567
|
+
var tag = document.createElement('style');
|
568
|
+
tag.type = 'text/css';
|
569
|
+
var nonce = getNonce();
|
570
|
+
if (nonce) {
|
571
|
+
tag.setAttribute('nonce', nonce);
|
572
|
+
}
|
573
|
+
return tag;
|
574
|
+
}
|
575
|
+
function injectStyles(tag, css) {
|
576
|
+
// @ts-ignore
|
577
|
+
if (tag.styleSheet) {
|
578
|
+
// @ts-ignore
|
579
|
+
tag.styleSheet.cssText = css;
|
580
|
+
} else {
|
581
|
+
tag.appendChild(document.createTextNode(css));
|
582
|
+
}
|
583
|
+
}
|
584
|
+
function insertStyleTag(tag) {
|
585
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
586
|
+
head.appendChild(tag);
|
587
|
+
}
|
588
|
+
var stylesheetSingleton = function() {
|
589
|
+
var counter = 0;
|
590
|
+
var stylesheet = null;
|
591
|
+
return {
|
592
|
+
add: function(style) {
|
593
|
+
if (counter == 0) {
|
594
|
+
if (stylesheet = makeStyleTag()) {
|
595
|
+
injectStyles(stylesheet, style);
|
596
|
+
insertStyleTag(stylesheet);
|
597
|
+
}
|
598
|
+
}
|
599
|
+
counter++;
|
600
|
+
},
|
601
|
+
remove: function() {
|
602
|
+
counter--;
|
603
|
+
if (!counter && stylesheet) {
|
604
|
+
stylesheet.parentNode && stylesheet.parentNode.removeChild(stylesheet);
|
605
|
+
stylesheet = null;
|
606
|
+
}
|
607
|
+
}
|
608
|
+
};
|
609
|
+
};
|
610
|
+
|
611
|
+
/**
|
612
|
+
* creates a hook to control style singleton
|
613
|
+
* @see {@link styleSingleton} for a safer component version
|
614
|
+
* @example
|
615
|
+
* ```tsx
|
616
|
+
* const useStyle = styleHookSingleton();
|
617
|
+
* ///
|
618
|
+
* useStyle('body { overflow: hidden}');
|
619
|
+
*/ var styleHookSingleton = function() {
|
620
|
+
var sheet = stylesheetSingleton();
|
621
|
+
return function(styles, isDynamic) {
|
622
|
+
React.useEffect(function() {
|
623
|
+
sheet.add(styles);
|
624
|
+
return function() {
|
625
|
+
sheet.remove();
|
626
|
+
};
|
627
|
+
}, [
|
628
|
+
styles && isDynamic
|
629
|
+
]);
|
630
|
+
};
|
631
|
+
};
|
632
|
+
|
633
|
+
/**
|
634
|
+
* create a Component to add styles on demand
|
635
|
+
* - styles are added when first instance is mounted
|
636
|
+
* - styles are removed when the last instance is unmounted
|
637
|
+
* - changing styles in runtime does nothing unless dynamic is set. But with multiple components that can lead to the undefined behavior
|
638
|
+
*/ var styleSingleton = function() {
|
639
|
+
var useStyle = styleHookSingleton();
|
640
|
+
var Sheet = function(_a) {
|
641
|
+
var styles = _a.styles, dynamic = _a.dynamic;
|
642
|
+
useStyle(styles, dynamic);
|
643
|
+
return null;
|
644
|
+
};
|
645
|
+
return Sheet;
|
646
|
+
};
|
647
|
+
|
648
|
+
var zeroGap = {
|
649
|
+
left: 0,
|
650
|
+
top: 0,
|
651
|
+
right: 0,
|
652
|
+
gap: 0
|
653
|
+
};
|
654
|
+
var parse = function(x) {
|
655
|
+
return parseInt(x || '', 10) || 0;
|
656
|
+
};
|
657
|
+
var getOffset = function(gapMode) {
|
658
|
+
var cs = window.getComputedStyle(document.body);
|
659
|
+
var left = cs[gapMode === 'padding' ? 'paddingLeft' : 'marginLeft'];
|
660
|
+
var top = cs[gapMode === 'padding' ? 'paddingTop' : 'marginTop'];
|
661
|
+
var right = cs[gapMode === 'padding' ? 'paddingRight' : 'marginRight'];
|
662
|
+
return [
|
663
|
+
parse(left),
|
664
|
+
parse(top),
|
665
|
+
parse(right)
|
666
|
+
];
|
667
|
+
};
|
668
|
+
var getGapWidth = function(gapMode) {
|
669
|
+
if (gapMode === void 0) {
|
670
|
+
gapMode = 'margin';
|
671
|
+
}
|
672
|
+
if (typeof window === 'undefined') {
|
673
|
+
return zeroGap;
|
674
|
+
}
|
675
|
+
var offsets = getOffset(gapMode);
|
676
|
+
var documentWidth = document.documentElement.clientWidth;
|
677
|
+
var windowWidth = window.innerWidth;
|
678
|
+
return {
|
679
|
+
left: offsets[0],
|
680
|
+
top: offsets[1],
|
681
|
+
right: offsets[2],
|
682
|
+
gap: Math.max(0, windowWidth - documentWidth + offsets[2] - offsets[0])
|
683
|
+
};
|
684
|
+
};
|
685
|
+
|
686
|
+
var Style = styleSingleton();
|
687
|
+
var lockAttribute = 'data-scroll-locked';
|
688
|
+
// important tip - once we measure scrollBar width and remove them
|
689
|
+
// we could not repeat this operation
|
690
|
+
// thus we are using style-singleton - only the first "yet correct" style will be applied.
|
691
|
+
var getStyles = function(_a, allowRelative, gapMode, important) {
|
692
|
+
var left = _a.left, top = _a.top, right = _a.right, gap = _a.gap;
|
693
|
+
if (gapMode === void 0) {
|
694
|
+
gapMode = 'margin';
|
695
|
+
}
|
696
|
+
return "\n .".concat(noScrollbarsClassName, " {\n overflow: hidden ").concat(important, ";\n padding-right: ").concat(gap, "px ").concat(important, ";\n }\n body[").concat(lockAttribute, "] {\n overflow: hidden ").concat(important, ";\n overscroll-behavior: contain;\n ").concat([
|
697
|
+
allowRelative && "position: relative ".concat(important, ";"),
|
698
|
+
gapMode === 'margin' && "\n padding-left: ".concat(left, "px;\n padding-top: ").concat(top, "px;\n padding-right: ").concat(right, "px;\n margin-left:0;\n margin-top:0;\n margin-right: ").concat(gap, "px ").concat(important, ";\n "),
|
699
|
+
gapMode === 'padding' && "padding-right: ".concat(gap, "px ").concat(important, ";")
|
700
|
+
].filter(Boolean).join(''), "\n }\n \n .").concat(zeroRightClassName, " {\n right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " {\n margin-right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(zeroRightClassName, " .").concat(zeroRightClassName, " {\n right: 0 ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " .").concat(fullWidthClassName, " {\n margin-right: 0 ").concat(important, ";\n }\n \n body[").concat(lockAttribute, "] {\n ").concat(removedBarSizeVariable, ": ").concat(gap, "px;\n }\n");
|
701
|
+
};
|
702
|
+
var getCurrentUseCounter = function() {
|
703
|
+
var counter = parseInt(document.body.getAttribute(lockAttribute) || '0', 10);
|
704
|
+
return isFinite(counter) ? counter : 0;
|
705
|
+
};
|
706
|
+
var useLockAttribute = function() {
|
707
|
+
React.useEffect(function() {
|
708
|
+
document.body.setAttribute(lockAttribute, (getCurrentUseCounter() + 1).toString());
|
709
|
+
return function() {
|
710
|
+
var newCounter = getCurrentUseCounter() - 1;
|
711
|
+
if (newCounter <= 0) {
|
712
|
+
document.body.removeAttribute(lockAttribute);
|
713
|
+
} else {
|
714
|
+
document.body.setAttribute(lockAttribute, newCounter.toString());
|
715
|
+
}
|
716
|
+
};
|
717
|
+
}, []);
|
718
|
+
};
|
719
|
+
/**
|
720
|
+
* Removes page scrollbar and blocks page scroll when mounted
|
721
|
+
*/ var RemoveScrollBar = function(_a) {
|
722
|
+
var noRelative = _a.noRelative, noImportant = _a.noImportant, _b = _a.gapMode, gapMode = _b === void 0 ? 'margin' : _b;
|
723
|
+
useLockAttribute();
|
724
|
+
/*
|
725
|
+
gap will be measured on every component mount
|
726
|
+
however it will be used only by the "first" invocation
|
727
|
+
due to singleton nature of <Style
|
728
|
+
*/ var gap = React.useMemo(function() {
|
729
|
+
return getGapWidth(gapMode);
|
730
|
+
}, [
|
731
|
+
gapMode
|
732
|
+
]);
|
733
|
+
return React.createElement(Style, {
|
734
|
+
styles: getStyles(gap, !noRelative, gapMode, !noImportant ? '!important' : '')
|
735
|
+
});
|
736
|
+
};
|
737
|
+
|
738
|
+
var passiveSupported = false;
|
739
|
+
if (typeof window !== 'undefined') {
|
740
|
+
try {
|
741
|
+
var options = Object.defineProperty({}, 'passive', {
|
742
|
+
get: function() {
|
743
|
+
passiveSupported = true;
|
744
|
+
return true;
|
745
|
+
}
|
746
|
+
});
|
747
|
+
// @ts-ignore
|
748
|
+
window.addEventListener('test', options, options);
|
749
|
+
// @ts-ignore
|
750
|
+
window.removeEventListener('test', options, options);
|
751
|
+
} catch (err) {
|
752
|
+
passiveSupported = false;
|
753
|
+
}
|
754
|
+
}
|
755
|
+
var nonPassive = passiveSupported ? {
|
756
|
+
passive: false
|
757
|
+
} : false;
|
758
|
+
|
759
|
+
var alwaysContainsScroll = function(node) {
|
760
|
+
// textarea will always _contain_ scroll inside self. It only can be hidden
|
761
|
+
return node.tagName === 'TEXTAREA';
|
762
|
+
};
|
763
|
+
var elementCanBeScrolled = function(node, overflow) {
|
764
|
+
if (!(node instanceof Element)) {
|
765
|
+
return false;
|
766
|
+
}
|
767
|
+
var styles = window.getComputedStyle(node);
|
768
|
+
return(// not-not-scrollable
|
769
|
+
styles[overflow] !== 'hidden' && // contains scroll inside self
|
770
|
+
!(styles.overflowY === styles.overflowX && !alwaysContainsScroll(node) && styles[overflow] === 'visible'));
|
771
|
+
};
|
772
|
+
var elementCouldBeVScrolled = function(node) {
|
773
|
+
return elementCanBeScrolled(node, 'overflowY');
|
774
|
+
};
|
775
|
+
var elementCouldBeHScrolled = function(node) {
|
776
|
+
return elementCanBeScrolled(node, 'overflowX');
|
777
|
+
};
|
778
|
+
var locationCouldBeScrolled = function(axis, node) {
|
779
|
+
var ownerDocument = node.ownerDocument;
|
780
|
+
var current = node;
|
781
|
+
do {
|
782
|
+
// Skip over shadow root
|
783
|
+
if (typeof ShadowRoot !== 'undefined' && current instanceof ShadowRoot) {
|
784
|
+
current = current.host;
|
785
|
+
}
|
786
|
+
var isScrollable = elementCouldBeScrolled(axis, current);
|
787
|
+
if (isScrollable) {
|
788
|
+
var _a = getScrollVariables(axis, current), scrollHeight = _a[1], clientHeight = _a[2];
|
789
|
+
if (scrollHeight > clientHeight) {
|
790
|
+
return true;
|
791
|
+
}
|
792
|
+
}
|
793
|
+
current = current.parentNode;
|
794
|
+
}while (current && current !== ownerDocument.body)
|
795
|
+
return false;
|
796
|
+
};
|
797
|
+
var getVScrollVariables = function(_a) {
|
798
|
+
var scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight;
|
799
|
+
return [
|
800
|
+
scrollTop,
|
801
|
+
scrollHeight,
|
802
|
+
clientHeight
|
803
|
+
];
|
804
|
+
};
|
805
|
+
var getHScrollVariables = function(_a) {
|
806
|
+
var scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth;
|
807
|
+
return [
|
808
|
+
scrollLeft,
|
809
|
+
scrollWidth,
|
810
|
+
clientWidth
|
811
|
+
];
|
812
|
+
};
|
813
|
+
var elementCouldBeScrolled = function(axis, node) {
|
814
|
+
return axis === 'v' ? elementCouldBeVScrolled(node) : elementCouldBeHScrolled(node);
|
815
|
+
};
|
816
|
+
var getScrollVariables = function(axis, node) {
|
817
|
+
return axis === 'v' ? getVScrollVariables(node) : getHScrollVariables(node);
|
818
|
+
};
|
819
|
+
var getDirectionFactor = function(axis, direction) {
|
820
|
+
/**
|
821
|
+
* If the element's direction is rtl (right-to-left), then scrollLeft is 0 when the scrollbar is at its rightmost position,
|
822
|
+
* and then increasingly negative as you scroll towards the end of the content.
|
823
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
|
824
|
+
*/ return axis === 'h' && direction === 'rtl' ? -1 : 1;
|
825
|
+
};
|
826
|
+
var handleScroll = function(axis, endTarget, event, sourceDelta, noOverscroll) {
|
827
|
+
var directionFactor = getDirectionFactor(axis, window.getComputedStyle(endTarget).direction);
|
828
|
+
var delta = directionFactor * sourceDelta;
|
829
|
+
// find scrollable target
|
830
|
+
var target = event.target;
|
831
|
+
var targetInLock = endTarget.contains(target);
|
832
|
+
var shouldCancelScroll = false;
|
833
|
+
var isDeltaPositive = delta > 0;
|
834
|
+
var availableScroll = 0;
|
835
|
+
var availableScrollTop = 0;
|
836
|
+
do {
|
837
|
+
if (!target) {
|
838
|
+
break;
|
839
|
+
}
|
840
|
+
var _a = getScrollVariables(axis, target), position = _a[0], scroll_1 = _a[1], capacity = _a[2];
|
841
|
+
var elementScroll = scroll_1 - capacity - directionFactor * position;
|
842
|
+
if (position || elementScroll) {
|
843
|
+
if (elementCouldBeScrolled(axis, target)) {
|
844
|
+
availableScroll += elementScroll;
|
845
|
+
availableScrollTop += position;
|
846
|
+
}
|
847
|
+
}
|
848
|
+
var parent_1 = target.parentNode;
|
849
|
+
// we will "bubble" from ShadowDom in case we are, or just to the parent in normal case
|
850
|
+
// this is the same logic used in focus-lock
|
851
|
+
target = parent_1 && parent_1.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? parent_1.host : parent_1;
|
852
|
+
}while (// portaled content
|
853
|
+
!targetInLock && target !== document.body || // self content
|
854
|
+
targetInLock && (endTarget.contains(target) || endTarget === target))
|
855
|
+
// handle epsilon around 0 (non standard zoom levels)
|
856
|
+
if (isDeltaPositive && (Math.abs(availableScroll) < 1 || false)) {
|
857
|
+
shouldCancelScroll = true;
|
858
|
+
} else if (!isDeltaPositive && (Math.abs(availableScrollTop) < 1 || false)) {
|
859
|
+
shouldCancelScroll = true;
|
860
|
+
}
|
861
|
+
return shouldCancelScroll;
|
862
|
+
};
|
863
|
+
|
864
|
+
var getTouchXY = function(event) {
|
865
|
+
return 'changedTouches' in event ? [
|
866
|
+
event.changedTouches[0].clientX,
|
867
|
+
event.changedTouches[0].clientY
|
868
|
+
] : [
|
869
|
+
0,
|
870
|
+
0
|
871
|
+
];
|
872
|
+
};
|
873
|
+
var getDeltaXY = function(event) {
|
874
|
+
return [
|
875
|
+
event.deltaX,
|
876
|
+
event.deltaY
|
877
|
+
];
|
878
|
+
};
|
879
|
+
var extractRef = function(ref) {
|
880
|
+
return ref && 'current' in ref ? ref.current : ref;
|
881
|
+
};
|
882
|
+
var deltaCompare = function(x, y) {
|
883
|
+
return x[0] === y[0] && x[1] === y[1];
|
884
|
+
};
|
885
|
+
var generateStyle = function(id) {
|
886
|
+
return "\n .block-interactivity-".concat(id, " {pointer-events: none;}\n .allow-interactivity-").concat(id, " {pointer-events: all;}\n");
|
887
|
+
};
|
888
|
+
var idCounter = 0;
|
889
|
+
var lockStack = [];
|
890
|
+
function RemoveScrollSideCar(props) {
|
891
|
+
var shouldPreventQueue = React.useRef([]);
|
892
|
+
var touchStartRef = React.useRef([
|
893
|
+
0,
|
894
|
+
0
|
895
|
+
]);
|
896
|
+
var activeAxis = React.useRef();
|
897
|
+
var id = React.useState(idCounter++)[0];
|
898
|
+
var Style = React.useState(styleSingleton)[0];
|
899
|
+
var lastProps = React.useRef(props);
|
900
|
+
React.useEffect(function() {
|
901
|
+
lastProps.current = props;
|
902
|
+
}, [
|
903
|
+
props
|
904
|
+
]);
|
905
|
+
React.useEffect(function() {
|
906
|
+
if (props.inert) {
|
907
|
+
document.body.classList.add("block-interactivity-".concat(id));
|
908
|
+
var allow_1 = __spreadArray([
|
909
|
+
props.lockRef.current
|
910
|
+
], (props.shards || []).map(extractRef), true).filter(Boolean);
|
911
|
+
allow_1.forEach(function(el) {
|
912
|
+
return el.classList.add("allow-interactivity-".concat(id));
|
913
|
+
});
|
914
|
+
return function() {
|
915
|
+
document.body.classList.remove("block-interactivity-".concat(id));
|
916
|
+
allow_1.forEach(function(el) {
|
917
|
+
return el.classList.remove("allow-interactivity-".concat(id));
|
918
|
+
});
|
919
|
+
};
|
920
|
+
}
|
921
|
+
return;
|
922
|
+
}, [
|
923
|
+
props.inert,
|
924
|
+
props.lockRef.current,
|
925
|
+
props.shards
|
926
|
+
]);
|
927
|
+
var shouldCancelEvent = React.useCallback(function(event, parent) {
|
928
|
+
if ('touches' in event && event.touches.length === 2 || event.type === 'wheel' && event.ctrlKey) {
|
929
|
+
return !lastProps.current.allowPinchZoom;
|
930
|
+
}
|
931
|
+
var touch = getTouchXY(event);
|
932
|
+
var touchStart = touchStartRef.current;
|
933
|
+
var deltaX = 'deltaX' in event ? event.deltaX : touchStart[0] - touch[0];
|
934
|
+
var deltaY = 'deltaY' in event ? event.deltaY : touchStart[1] - touch[1];
|
935
|
+
var currentAxis;
|
936
|
+
var target = event.target;
|
937
|
+
var moveDirection = Math.abs(deltaX) > Math.abs(deltaY) ? 'h' : 'v';
|
938
|
+
// allow horizontal touch move on Range inputs. They will not cause any scroll
|
939
|
+
if ('touches' in event && moveDirection === 'h' && target.type === 'range') {
|
940
|
+
return false;
|
941
|
+
}
|
942
|
+
var canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
943
|
+
if (!canBeScrolledInMainDirection) {
|
944
|
+
return true;
|
945
|
+
}
|
946
|
+
if (canBeScrolledInMainDirection) {
|
947
|
+
currentAxis = moveDirection;
|
948
|
+
} else {
|
949
|
+
currentAxis = moveDirection === 'v' ? 'h' : 'v';
|
950
|
+
canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
951
|
+
// other axis might be not scrollable
|
952
|
+
}
|
953
|
+
if (!canBeScrolledInMainDirection) {
|
954
|
+
return false;
|
955
|
+
}
|
956
|
+
if (!activeAxis.current && 'changedTouches' in event && (deltaX || deltaY)) {
|
957
|
+
activeAxis.current = currentAxis;
|
958
|
+
}
|
959
|
+
if (!currentAxis) {
|
960
|
+
return true;
|
961
|
+
}
|
962
|
+
var cancelingAxis = activeAxis.current || currentAxis;
|
963
|
+
return handleScroll(cancelingAxis, parent, event, cancelingAxis === 'h' ? deltaX : deltaY);
|
964
|
+
}, []);
|
965
|
+
var shouldPrevent = React.useCallback(function(_event) {
|
966
|
+
var event = _event;
|
967
|
+
if (!lockStack.length || lockStack[lockStack.length - 1] !== Style) {
|
968
|
+
// not the last active
|
969
|
+
return;
|
970
|
+
}
|
971
|
+
var delta = 'deltaY' in event ? getDeltaXY(event) : getTouchXY(event);
|
972
|
+
var sourceEvent = shouldPreventQueue.current.filter(function(e) {
|
973
|
+
return e.name === event.type && (e.target === event.target || event.target === e.shadowParent) && deltaCompare(e.delta, delta);
|
974
|
+
})[0];
|
975
|
+
// self event, and should be canceled
|
976
|
+
if (sourceEvent && sourceEvent.should) {
|
977
|
+
if (event.cancelable) {
|
978
|
+
event.preventDefault();
|
979
|
+
}
|
980
|
+
return;
|
981
|
+
}
|
982
|
+
// outside or shard event
|
983
|
+
if (!sourceEvent) {
|
984
|
+
var shardNodes = (lastProps.current.shards || []).map(extractRef).filter(Boolean).filter(function(node) {
|
985
|
+
return node.contains(event.target);
|
986
|
+
});
|
987
|
+
var shouldStop = shardNodes.length > 0 ? shouldCancelEvent(event, shardNodes[0]) : !lastProps.current.noIsolation;
|
988
|
+
if (shouldStop) {
|
989
|
+
if (event.cancelable) {
|
990
|
+
event.preventDefault();
|
991
|
+
}
|
992
|
+
}
|
993
|
+
}
|
994
|
+
}, []);
|
995
|
+
var shouldCancel = React.useCallback(function(name, delta, target, should) {
|
996
|
+
var event = {
|
997
|
+
name: name,
|
998
|
+
delta: delta,
|
999
|
+
target: target,
|
1000
|
+
should: should,
|
1001
|
+
shadowParent: getOutermostShadowParent(target)
|
1002
|
+
};
|
1003
|
+
shouldPreventQueue.current.push(event);
|
1004
|
+
setTimeout(function() {
|
1005
|
+
shouldPreventQueue.current = shouldPreventQueue.current.filter(function(e) {
|
1006
|
+
return e !== event;
|
1007
|
+
});
|
1008
|
+
}, 1);
|
1009
|
+
}, []);
|
1010
|
+
var scrollTouchStart = React.useCallback(function(event) {
|
1011
|
+
touchStartRef.current = getTouchXY(event);
|
1012
|
+
activeAxis.current = undefined;
|
1013
|
+
}, []);
|
1014
|
+
var scrollWheel = React.useCallback(function(event) {
|
1015
|
+
shouldCancel(event.type, getDeltaXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
1016
|
+
}, []);
|
1017
|
+
var scrollTouchMove = React.useCallback(function(event) {
|
1018
|
+
shouldCancel(event.type, getTouchXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
1019
|
+
}, []);
|
1020
|
+
React.useEffect(function() {
|
1021
|
+
lockStack.push(Style);
|
1022
|
+
props.setCallbacks({
|
1023
|
+
onScrollCapture: scrollWheel,
|
1024
|
+
onWheelCapture: scrollWheel,
|
1025
|
+
onTouchMoveCapture: scrollTouchMove
|
1026
|
+
});
|
1027
|
+
document.addEventListener('wheel', shouldPrevent, nonPassive);
|
1028
|
+
document.addEventListener('touchmove', shouldPrevent, nonPassive);
|
1029
|
+
document.addEventListener('touchstart', scrollTouchStart, nonPassive);
|
1030
|
+
return function() {
|
1031
|
+
lockStack = lockStack.filter(function(inst) {
|
1032
|
+
return inst !== Style;
|
1033
|
+
});
|
1034
|
+
document.removeEventListener('wheel', shouldPrevent, nonPassive);
|
1035
|
+
document.removeEventListener('touchmove', shouldPrevent, nonPassive);
|
1036
|
+
document.removeEventListener('touchstart', scrollTouchStart, nonPassive);
|
1037
|
+
};
|
1038
|
+
}, []);
|
1039
|
+
var removeScrollBar = props.removeScrollBar, inert = props.inert;
|
1040
|
+
return React.createElement(React.Fragment, null, inert ? React.createElement(Style, {
|
1041
|
+
styles: generateStyle(id)
|
1042
|
+
}) : null, removeScrollBar ? React.createElement(RemoveScrollBar, {
|
1043
|
+
noRelative: props.noRelative,
|
1044
|
+
gapMode: props.gapMode
|
1045
|
+
}) : null);
|
1046
|
+
}
|
1047
|
+
function getOutermostShadowParent(node) {
|
1048
|
+
var shadowParent = null;
|
1049
|
+
while(node !== null){
|
1050
|
+
if (node instanceof ShadowRoot) {
|
1051
|
+
shadowParent = node.host;
|
1052
|
+
node = node.host;
|
1053
|
+
}
|
1054
|
+
node = node.parentNode;
|
1055
|
+
}
|
1056
|
+
return shadowParent;
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
var SideCar = exportSidecar(effectCar, RemoveScrollSideCar);
|
1060
|
+
|
1061
|
+
var ReactRemoveScroll = React.forwardRef(function(props, ref) {
|
1062
|
+
return React.createElement(RemoveScroll, __assign({}, props, {
|
1063
|
+
ref: ref,
|
1064
|
+
sideCar: SideCar
|
1065
|
+
}));
|
1066
|
+
});
|
1067
|
+
ReactRemoveScroll.classNames = RemoveScroll.classNames;
|
1068
|
+
|
1069
|
+
var getDefaultParent = function(originalTarget) {
|
1070
|
+
if (typeof document === 'undefined') {
|
1071
|
+
return null;
|
1072
|
+
}
|
1073
|
+
var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
1074
|
+
return sampleTarget.ownerDocument.body;
|
1075
|
+
};
|
1076
|
+
var counterMap = new WeakMap();
|
1077
|
+
var uncontrolledNodes = new WeakMap();
|
1078
|
+
var markerMap = {};
|
1079
|
+
var lockCount = 0;
|
1080
|
+
var unwrapHost = function(node) {
|
1081
|
+
return node && (node.host || unwrapHost(node.parentNode));
|
1082
|
+
};
|
1083
|
+
var correctTargets = function(parent, targets) {
|
1084
|
+
return targets.map(function(target) {
|
1085
|
+
if (parent.contains(target)) {
|
1086
|
+
return target;
|
1087
|
+
}
|
1088
|
+
var correctedTarget = unwrapHost(target);
|
1089
|
+
if (correctedTarget && parent.contains(correctedTarget)) {
|
1090
|
+
return correctedTarget;
|
1091
|
+
}
|
1092
|
+
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing');
|
1093
|
+
return null;
|
1094
|
+
}).filter(function(x) {
|
1095
|
+
return Boolean(x);
|
1096
|
+
});
|
1097
|
+
};
|
1098
|
+
/**
|
1099
|
+
* Marks everything except given node(or nodes) as aria-hidden
|
1100
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
1101
|
+
* @param [parentNode] - top element, defaults to document.body
|
1102
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
1103
|
+
* @param {String} [controlAttribute] - html Attribute to control
|
1104
|
+
* @return {Undo} undo command
|
1105
|
+
*/ var applyAttributeToOthers = function(originalTarget, parentNode, markerName, controlAttribute) {
|
1106
|
+
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [
|
1107
|
+
originalTarget
|
1108
|
+
]);
|
1109
|
+
if (!markerMap[markerName]) {
|
1110
|
+
markerMap[markerName] = new WeakMap();
|
1111
|
+
}
|
1112
|
+
var markerCounter = markerMap[markerName];
|
1113
|
+
var hiddenNodes = [];
|
1114
|
+
var elementsToKeep = new Set();
|
1115
|
+
var elementsToStop = new Set(targets);
|
1116
|
+
var keep = function(el) {
|
1117
|
+
if (!el || elementsToKeep.has(el)) {
|
1118
|
+
return;
|
1119
|
+
}
|
1120
|
+
elementsToKeep.add(el);
|
1121
|
+
keep(el.parentNode);
|
1122
|
+
};
|
1123
|
+
targets.forEach(keep);
|
1124
|
+
var deep = function(parent) {
|
1125
|
+
if (!parent || elementsToStop.has(parent)) {
|
1126
|
+
return;
|
1127
|
+
}
|
1128
|
+
Array.prototype.forEach.call(parent.children, function(node) {
|
1129
|
+
if (elementsToKeep.has(node)) {
|
1130
|
+
deep(node);
|
1131
|
+
} else {
|
1132
|
+
try {
|
1133
|
+
var attr = node.getAttribute(controlAttribute);
|
1134
|
+
var alreadyHidden = attr !== null && attr !== 'false';
|
1135
|
+
var counterValue = (counterMap.get(node) || 0) + 1;
|
1136
|
+
var markerValue = (markerCounter.get(node) || 0) + 1;
|
1137
|
+
counterMap.set(node, counterValue);
|
1138
|
+
markerCounter.set(node, markerValue);
|
1139
|
+
hiddenNodes.push(node);
|
1140
|
+
if (counterValue === 1 && alreadyHidden) {
|
1141
|
+
uncontrolledNodes.set(node, true);
|
1142
|
+
}
|
1143
|
+
if (markerValue === 1) {
|
1144
|
+
node.setAttribute(markerName, 'true');
|
1145
|
+
}
|
1146
|
+
if (!alreadyHidden) {
|
1147
|
+
node.setAttribute(controlAttribute, 'true');
|
1148
|
+
}
|
1149
|
+
} catch (e) {
|
1150
|
+
console.error('aria-hidden: cannot operate on ', node, e);
|
1151
|
+
}
|
1152
|
+
}
|
1153
|
+
});
|
1154
|
+
};
|
1155
|
+
deep(parentNode);
|
1156
|
+
elementsToKeep.clear();
|
1157
|
+
lockCount++;
|
1158
|
+
return function() {
|
1159
|
+
hiddenNodes.forEach(function(node) {
|
1160
|
+
var counterValue = counterMap.get(node) - 1;
|
1161
|
+
var markerValue = markerCounter.get(node) - 1;
|
1162
|
+
counterMap.set(node, counterValue);
|
1163
|
+
markerCounter.set(node, markerValue);
|
1164
|
+
if (!counterValue) {
|
1165
|
+
if (!uncontrolledNodes.has(node)) {
|
1166
|
+
node.removeAttribute(controlAttribute);
|
1167
|
+
}
|
1168
|
+
uncontrolledNodes.delete(node);
|
1169
|
+
}
|
1170
|
+
if (!markerValue) {
|
1171
|
+
node.removeAttribute(markerName);
|
1172
|
+
}
|
1173
|
+
});
|
1174
|
+
lockCount--;
|
1175
|
+
if (!lockCount) {
|
1176
|
+
// clear
|
1177
|
+
counterMap = new WeakMap();
|
1178
|
+
counterMap = new WeakMap();
|
1179
|
+
uncontrolledNodes = new WeakMap();
|
1180
|
+
markerMap = {};
|
1181
|
+
}
|
1182
|
+
};
|
1183
|
+
};
|
1184
|
+
/**
|
1185
|
+
* Marks everything except given node(or nodes) as aria-hidden
|
1186
|
+
* @param {Element | Element[]} originalTarget - elements to keep on the page
|
1187
|
+
* @param [parentNode] - top element, defaults to document.body
|
1188
|
+
* @param {String} [markerName] - a special attribute to mark every node
|
1189
|
+
* @return {Undo} undo command
|
1190
|
+
*/ var hideOthers = function(originalTarget, parentNode, markerName) {
|
1191
|
+
if (markerName === void 0) {
|
1192
|
+
markerName = 'data-aria-hidden';
|
1193
|
+
}
|
1194
|
+
var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [
|
1195
|
+
originalTarget
|
1196
|
+
]);
|
1197
|
+
var activeParentNode = getDefaultParent(originalTarget);
|
1198
|
+
if (!activeParentNode) {
|
1199
|
+
return function() {
|
1200
|
+
return null;
|
1201
|
+
};
|
1202
|
+
}
|
1203
|
+
// we should not hide aria-live elements - https://github.com/theKashey/aria-hidden/issues/10
|
1204
|
+
// and script elements, as they have no impact on accessibility.
|
1205
|
+
targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll('[aria-live], script')));
|
1206
|
+
return applyAttributeToOthers(targets, activeParentNode, markerName, 'aria-hidden');
|
1207
|
+
};
|
1208
|
+
|
1209
|
+
export { FocusScope as F, ReactRemoveScroll as R, hideOthers as h, useFocusGuards as u };
|
1210
|
+
//# sourceMappingURL=index-sz_BcBbA.mjs.map
|