@samline/drawer 2.0.6 → 2.0.8
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/browser/{components-client-CJuQ5vtW.js → components-client-B8ZDZqhE.js} +25 -16
- package/dist/{svelte/components-client-tfLTRxPH.mjs → browser/components-client-LPOAyYIW.mjs} +25 -16
- package/dist/browser/index.cjs +71 -23
- package/dist/browser/index.js +71 -23
- package/dist/browser/index.mjs +71 -23
- package/dist/{svelte/components-client-CJuQ5vtW.js → components-client-B8ZDZqhE.js} +25 -16
- package/dist/{browser/components-client-tfLTRxPH.mjs → components-client-LPOAyYIW.mjs} +25 -16
- package/dist/index.js +71 -23
- package/dist/index.mjs +71 -23
- package/dist/react/index.js +75 -25
- package/dist/react/index.mjs +75 -25
- package/dist/{components-client-CJuQ5vtW.js → svelte/components-client-B8ZDZqhE.js} +25 -16
- package/dist/{components-client-tfLTRxPH.mjs → svelte/components-client-LPOAyYIW.mjs} +25 -16
- package/dist/svelte/index.js +71 -23
- package/dist/svelte/index.mjs +71 -23
- package/dist/vue/{components-client-CJuQ5vtW.js → components-client-B8ZDZqhE.js} +25 -16
- package/dist/vue/{components-client-DSM2G8ef.mjs → components-client-BlpMZJqu.mjs} +25 -16
- package/dist/vue/index.js +71 -23
- package/dist/vue/index.mjs +71 -23
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1509,6 +1509,27 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1509
1509
|
const drawerHeightRef = React__default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
|
|
1510
1510
|
const drawerWidthRef = React__default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
|
|
1511
1511
|
const initialDrawerHeight = React__default.useRef(0);
|
|
1512
|
+
const releaseHiddenFocusBeforeOpen = React__default.useCallback(()=>{
|
|
1513
|
+
var _drawerRef_current;
|
|
1514
|
+
if (!modal || autoFocus || typeof document === 'undefined') {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
const activeElement = document.activeElement;
|
|
1518
|
+
if (!activeElement || activeElement === document.body) {
|
|
1519
|
+
return;
|
|
1520
|
+
}
|
|
1521
|
+
const activeElementNode = activeElement;
|
|
1522
|
+
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
if (typeof activeElementNode.blur !== 'function') {
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
activeElementNode.blur();
|
|
1529
|
+
}, [
|
|
1530
|
+
autoFocus,
|
|
1531
|
+
modal
|
|
1532
|
+
]);
|
|
1512
1533
|
const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{
|
|
1513
1534
|
// Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
|
|
1514
1535
|
if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
|
|
@@ -1560,26 +1581,13 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1560
1581
|
autoFocus
|
|
1561
1582
|
});
|
|
1562
1583
|
useSafeLayoutEffect$1(()=>{
|
|
1563
|
-
|
|
1564
|
-
if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
|
|
1565
|
-
return;
|
|
1566
|
-
}
|
|
1567
|
-
const activeElement = document.activeElement;
|
|
1568
|
-
if (!activeElement || activeElement === document.body) {
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
|
-
const activeElementNode = activeElement;
|
|
1572
|
-
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1584
|
+
if (!isOpen) {
|
|
1573
1585
|
return;
|
|
1574
1586
|
}
|
|
1575
|
-
|
|
1576
|
-
return;
|
|
1577
|
-
}
|
|
1578
|
-
activeElementNode.blur();
|
|
1587
|
+
releaseHiddenFocusBeforeOpen();
|
|
1579
1588
|
}, [
|
|
1580
|
-
autoFocus,
|
|
1581
1589
|
isOpen,
|
|
1582
|
-
|
|
1590
|
+
releaseHiddenFocusBeforeOpen
|
|
1583
1591
|
]);
|
|
1584
1592
|
function getScale() {
|
|
1585
1593
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
@@ -1988,6 +1996,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1988
1996
|
onOpenChange: (open)=>{
|
|
1989
1997
|
if (!dismissible && !open) return;
|
|
1990
1998
|
if (open) {
|
|
1999
|
+
releaseHiddenFocusBeforeOpen();
|
|
1991
2000
|
setHasBeenOpened(true);
|
|
1992
2001
|
} else {
|
|
1993
2002
|
closeDrawer(true);
|
|
@@ -2582,7 +2591,7 @@ function openAncestorChain(parentId) {
|
|
|
2582
2591
|
openAncestorChain(nextParentId);
|
|
2583
2592
|
}
|
|
2584
2593
|
if (!parentRuntime.controller.getSnapshot().state.isOpen) {
|
|
2585
|
-
releaseHiddenFocusBeforeOpen(parentRuntime.options);
|
|
2594
|
+
releaseHiddenFocusBeforeOpen(parentRuntime.options, getRuntimeDrawerElement(parentRuntime));
|
|
2586
2595
|
parentRuntime.controller.setOpen(true);
|
|
2587
2596
|
notifyOpenStateChange(parentRuntime, true);
|
|
2588
2597
|
renderVanillaDrawer(parentRuntime.id);
|
|
@@ -2597,18 +2606,36 @@ function cleanupRuntimeTrigger(runtime) {
|
|
|
2597
2606
|
}
|
|
2598
2607
|
function bindTriggerElement(runtime) {
|
|
2599
2608
|
cleanupRuntimeTrigger(runtime);
|
|
2609
|
+
const drawerElement = getRuntimeDrawerElement(runtime);
|
|
2610
|
+
const builtInTriggerElement = getRuntimeTriggerElement(runtime);
|
|
2611
|
+
const cleanups = [];
|
|
2612
|
+
if (builtInTriggerElement) {
|
|
2613
|
+
const handleBuiltInTriggerClick = ()=>{
|
|
2614
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
2615
|
+
};
|
|
2616
|
+
builtInTriggerElement.addEventListener('click', handleBuiltInTriggerClick);
|
|
2617
|
+
cleanups.push(()=>{
|
|
2618
|
+
builtInTriggerElement.removeEventListener('click', handleBuiltInTriggerClick);
|
|
2619
|
+
});
|
|
2620
|
+
}
|
|
2600
2621
|
if (!runtime.options.triggerElement) {
|
|
2622
|
+
runtime.cleanupTriggerElement = cleanups.length ? ()=>{
|
|
2623
|
+
cleanups.forEach((cleanup)=>cleanup());
|
|
2624
|
+
} : null;
|
|
2601
2625
|
return;
|
|
2602
2626
|
}
|
|
2603
2627
|
const triggerElement = runtime.options.triggerElement;
|
|
2604
2628
|
const handleClick = ()=>{
|
|
2605
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
2629
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
2606
2630
|
runtime.controller.setOpen(true);
|
|
2607
2631
|
renderVanillaDrawer(runtime.id);
|
|
2608
2632
|
};
|
|
2609
2633
|
triggerElement.addEventListener('click', handleClick);
|
|
2610
|
-
|
|
2634
|
+
cleanups.push(()=>{
|
|
2611
2635
|
triggerElement.removeEventListener('click', handleClick);
|
|
2636
|
+
});
|
|
2637
|
+
runtime.cleanupTriggerElement = ()=>{
|
|
2638
|
+
cleanups.forEach((cleanup)=>cleanup());
|
|
2612
2639
|
};
|
|
2613
2640
|
}
|
|
2614
2641
|
function notifyOpenStateChange(runtime, open) {
|
|
@@ -2638,15 +2665,32 @@ function notifyOpenStateChange(runtime, open) {
|
|
|
2638
2665
|
function canUseDOM() {
|
|
2639
2666
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
2640
2667
|
}
|
|
2641
|
-
function
|
|
2668
|
+
function isElementInsideDrawer(element) {
|
|
2669
|
+
let currentElement = element;
|
|
2670
|
+
while(currentElement){
|
|
2671
|
+
if (currentElement instanceof HTMLElement && currentElement.hasAttribute('data-drawer')) {
|
|
2672
|
+
return true;
|
|
2673
|
+
}
|
|
2674
|
+
currentElement = currentElement.parentElement;
|
|
2675
|
+
}
|
|
2676
|
+
return false;
|
|
2677
|
+
}
|
|
2678
|
+
function releaseHiddenFocusBeforeOpen(options, drawerElement) {
|
|
2642
2679
|
if (!canUseDOM() || options.modal === false || options.autoFocus) {
|
|
2643
2680
|
return;
|
|
2644
2681
|
}
|
|
2645
2682
|
const activeElement = document.activeElement;
|
|
2646
|
-
if (!activeElement || activeElement === document.body
|
|
2683
|
+
if (!activeElement || activeElement === document.body) {
|
|
2684
|
+
return;
|
|
2685
|
+
}
|
|
2686
|
+
const activeElementNode = activeElement;
|
|
2687
|
+
if ((drawerElement == null ? void 0 : drawerElement.contains(activeElementNode)) || isElementInsideDrawer(activeElementNode)) {
|
|
2647
2688
|
return;
|
|
2648
2689
|
}
|
|
2649
|
-
|
|
2690
|
+
if (typeof activeElementNode.blur !== 'function') {
|
|
2691
|
+
return;
|
|
2692
|
+
}
|
|
2693
|
+
activeElementNode.blur();
|
|
2650
2694
|
}
|
|
2651
2695
|
function getRuntimeDrawerElement(runtime) {
|
|
2652
2696
|
if (!runtime.element) {
|
|
@@ -2654,6 +2698,12 @@ function getRuntimeDrawerElement(runtime) {
|
|
|
2654
2698
|
}
|
|
2655
2699
|
return runtime.element.querySelector('[data-drawer]');
|
|
2656
2700
|
}
|
|
2701
|
+
function getRuntimeTriggerElement(runtime) {
|
|
2702
|
+
if (!runtime.element) {
|
|
2703
|
+
return null;
|
|
2704
|
+
}
|
|
2705
|
+
return runtime.element.querySelector('[data-drawer-vanilla-trigger]');
|
|
2706
|
+
}
|
|
2657
2707
|
function getViewportSizeForDirection(direction) {
|
|
2658
2708
|
if (!canUseDOM()) {
|
|
2659
2709
|
return 0;
|
|
@@ -2699,7 +2749,7 @@ function renderVanillaDrawer(id) {
|
|
|
2699
2749
|
onOpenChange: (open)=>{
|
|
2700
2750
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
2701
2751
|
if (open) {
|
|
2702
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
2752
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
2703
2753
|
}
|
|
2704
2754
|
runtime.controller.setOpen(open);
|
|
2705
2755
|
if (previousOpen !== open) {
|
|
@@ -2754,7 +2804,7 @@ function buildVanillaController(id) {
|
|
|
2754
2804
|
}).getSnapshot();
|
|
2755
2805
|
}
|
|
2756
2806
|
if (open) {
|
|
2757
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
2807
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
2758
2808
|
}
|
|
2759
2809
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
2760
2810
|
const snapshot = runtime.controller.setOpen(open);
|
|
@@ -2850,7 +2900,7 @@ function createDrawer(options = {}) {
|
|
|
2850
2900
|
}
|
|
2851
2901
|
}
|
|
2852
2902
|
if (nextOptions.open && !previousOpen) {
|
|
2853
|
-
releaseHiddenFocusBeforeOpen(nextOptions);
|
|
2903
|
+
releaseHiddenFocusBeforeOpen(nextOptions, existing ? getRuntimeDrawerElement(existing) : null);
|
|
2854
2904
|
}
|
|
2855
2905
|
renderVanillaDrawer(id);
|
|
2856
2906
|
if (nextOptions.parentId && nextOptions.open) {
|
|
@@ -1528,6 +1528,27 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1528
1528
|
const drawerHeightRef = React__namespace.default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
|
|
1529
1529
|
const drawerWidthRef = React__namespace.default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
|
|
1530
1530
|
const initialDrawerHeight = React__namespace.default.useRef(0);
|
|
1531
|
+
const releaseHiddenFocusBeforeOpen = React__namespace.default.useCallback(()=>{
|
|
1532
|
+
var _drawerRef_current;
|
|
1533
|
+
if (!modal || autoFocus || typeof document === 'undefined') {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
const activeElement = document.activeElement;
|
|
1537
|
+
if (!activeElement || activeElement === document.body) {
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const activeElementNode = activeElement;
|
|
1541
|
+
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
if (typeof activeElementNode.blur !== 'function') {
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
activeElementNode.blur();
|
|
1548
|
+
}, [
|
|
1549
|
+
autoFocus,
|
|
1550
|
+
modal
|
|
1551
|
+
]);
|
|
1531
1552
|
const onSnapPointChange = React__namespace.default.useCallback((activeSnapPointIndex)=>{
|
|
1532
1553
|
// Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
|
|
1533
1554
|
if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
|
|
@@ -1579,26 +1600,13 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1579
1600
|
autoFocus
|
|
1580
1601
|
});
|
|
1581
1602
|
useSafeLayoutEffect(()=>{
|
|
1582
|
-
|
|
1583
|
-
if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
|
|
1603
|
+
if (!isOpen) {
|
|
1584
1604
|
return;
|
|
1585
1605
|
}
|
|
1586
|
-
|
|
1587
|
-
if (!activeElement || activeElement === document.body) {
|
|
1588
|
-
return;
|
|
1589
|
-
}
|
|
1590
|
-
const activeElementNode = activeElement;
|
|
1591
|
-
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
if (typeof activeElementNode.blur !== 'function') {
|
|
1595
|
-
return;
|
|
1596
|
-
}
|
|
1597
|
-
activeElementNode.blur();
|
|
1606
|
+
releaseHiddenFocusBeforeOpen();
|
|
1598
1607
|
}, [
|
|
1599
|
-
autoFocus,
|
|
1600
1608
|
isOpen,
|
|
1601
|
-
|
|
1609
|
+
releaseHiddenFocusBeforeOpen
|
|
1602
1610
|
]);
|
|
1603
1611
|
function getScale() {
|
|
1604
1612
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
@@ -2007,6 +2015,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
2007
2015
|
onOpenChange: (open)=>{
|
|
2008
2016
|
if (!dismissible && !open) return;
|
|
2009
2017
|
if (open) {
|
|
2018
|
+
releaseHiddenFocusBeforeOpen();
|
|
2010
2019
|
setHasBeenOpened(true);
|
|
2011
2020
|
} else {
|
|
2012
2021
|
closeDrawer(true);
|
|
@@ -1508,6 +1508,27 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1508
1508
|
const drawerHeightRef = React__default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
|
|
1509
1509
|
const drawerWidthRef = React__default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
|
|
1510
1510
|
const initialDrawerHeight = React__default.useRef(0);
|
|
1511
|
+
const releaseHiddenFocusBeforeOpen = React__default.useCallback(()=>{
|
|
1512
|
+
var _drawerRef_current;
|
|
1513
|
+
if (!modal || autoFocus || typeof document === 'undefined') {
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
const activeElement = document.activeElement;
|
|
1517
|
+
if (!activeElement || activeElement === document.body) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
const activeElementNode = activeElement;
|
|
1521
|
+
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (typeof activeElementNode.blur !== 'function') {
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
activeElementNode.blur();
|
|
1528
|
+
}, [
|
|
1529
|
+
autoFocus,
|
|
1530
|
+
modal
|
|
1531
|
+
]);
|
|
1511
1532
|
const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{
|
|
1512
1533
|
// Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
|
|
1513
1534
|
if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
|
|
@@ -1559,26 +1580,13 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1559
1580
|
autoFocus
|
|
1560
1581
|
});
|
|
1561
1582
|
useSafeLayoutEffect(()=>{
|
|
1562
|
-
|
|
1563
|
-
if (!isOpen || !modal || autoFocus || typeof document === 'undefined') {
|
|
1583
|
+
if (!isOpen) {
|
|
1564
1584
|
return;
|
|
1565
1585
|
}
|
|
1566
|
-
|
|
1567
|
-
if (!activeElement || activeElement === document.body) {
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
const activeElementNode = activeElement;
|
|
1571
|
-
if (((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.contains(activeElementNode)) || (activeElementNode.closest == null ? void 0 : activeElementNode.closest.call(activeElementNode, '[data-drawer]'))) {
|
|
1572
|
-
return;
|
|
1573
|
-
}
|
|
1574
|
-
if (typeof activeElementNode.blur !== 'function') {
|
|
1575
|
-
return;
|
|
1576
|
-
}
|
|
1577
|
-
activeElementNode.blur();
|
|
1586
|
+
releaseHiddenFocusBeforeOpen();
|
|
1578
1587
|
}, [
|
|
1579
|
-
autoFocus,
|
|
1580
1588
|
isOpen,
|
|
1581
|
-
|
|
1589
|
+
releaseHiddenFocusBeforeOpen
|
|
1582
1590
|
]);
|
|
1583
1591
|
function getScale() {
|
|
1584
1592
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
@@ -1987,6 +1995,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
|
|
|
1987
1995
|
onOpenChange: (open)=>{
|
|
1988
1996
|
if (!dismissible && !open) return;
|
|
1989
1997
|
if (open) {
|
|
1998
|
+
releaseHiddenFocusBeforeOpen();
|
|
1990
1999
|
setHasBeenOpened(true);
|
|
1991
2000
|
} else {
|
|
1992
2001
|
closeDrawer(true);
|
package/dist/svelte/index.js
CHANGED
|
@@ -28077,6 +28077,23 @@ function Root2({
|
|
|
28077
28077
|
const drawerHeightRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
|
|
28078
28078
|
const drawerWidthRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
|
|
28079
28079
|
const initialDrawerHeight = import_react9.default.useRef(0);
|
|
28080
|
+
const releaseHiddenFocusBeforeOpen2 = import_react9.default.useCallback(() => {
|
|
28081
|
+
if (!modal || autoFocus || typeof document === "undefined") {
|
|
28082
|
+
return;
|
|
28083
|
+
}
|
|
28084
|
+
const activeElement = document.activeElement;
|
|
28085
|
+
if (!activeElement || activeElement === document.body) {
|
|
28086
|
+
return;
|
|
28087
|
+
}
|
|
28088
|
+
const activeElementNode = activeElement;
|
|
28089
|
+
if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
|
|
28090
|
+
return;
|
|
28091
|
+
}
|
|
28092
|
+
if (typeof activeElementNode.blur !== "function") {
|
|
28093
|
+
return;
|
|
28094
|
+
}
|
|
28095
|
+
activeElementNode.blur();
|
|
28096
|
+
}, [autoFocus, modal]);
|
|
28080
28097
|
const onSnapPointChange = import_react9.default.useCallback((activeSnapPointIndex2) => {
|
|
28081
28098
|
if (snapPoints && activeSnapPointIndex2 === snapPointsOffset.length - 1) openTime.current = /* @__PURE__ */ new Date();
|
|
28082
28099
|
}, []);
|
|
@@ -28136,22 +28153,11 @@ function Root2({
|
|
|
28136
28153
|
autoFocus
|
|
28137
28154
|
});
|
|
28138
28155
|
useSafeLayoutEffect(() => {
|
|
28139
|
-
if (!isOpen
|
|
28140
|
-
return;
|
|
28141
|
-
}
|
|
28142
|
-
const activeElement = document.activeElement;
|
|
28143
|
-
if (!activeElement || activeElement === document.body) {
|
|
28156
|
+
if (!isOpen) {
|
|
28144
28157
|
return;
|
|
28145
28158
|
}
|
|
28146
|
-
|
|
28147
|
-
|
|
28148
|
-
return;
|
|
28149
|
-
}
|
|
28150
|
-
if (typeof activeElementNode.blur !== "function") {
|
|
28151
|
-
return;
|
|
28152
|
-
}
|
|
28153
|
-
activeElementNode.blur();
|
|
28154
|
-
}, [autoFocus, isOpen, modal]);
|
|
28159
|
+
releaseHiddenFocusBeforeOpen2();
|
|
28160
|
+
}, [isOpen, releaseHiddenFocusBeforeOpen2]);
|
|
28155
28161
|
function getScale() {
|
|
28156
28162
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
28157
28163
|
}
|
|
@@ -28535,6 +28541,7 @@ function Root2({
|
|
|
28535
28541
|
onOpenChange: (open) => {
|
|
28536
28542
|
if (!dismissible && !open) return;
|
|
28537
28543
|
if (open) {
|
|
28544
|
+
releaseHiddenFocusBeforeOpen2();
|
|
28538
28545
|
setHasBeenOpened(true);
|
|
28539
28546
|
} else {
|
|
28540
28547
|
closeDrawer2(true);
|
|
@@ -29128,7 +29135,7 @@ function openAncestorChain(parentId) {
|
|
|
29128
29135
|
openAncestorChain(nextParentId);
|
|
29129
29136
|
}
|
|
29130
29137
|
if (!parentRuntime.controller.getSnapshot().state.isOpen) {
|
|
29131
|
-
releaseHiddenFocusBeforeOpen(parentRuntime.options);
|
|
29138
|
+
releaseHiddenFocusBeforeOpen(parentRuntime.options, getRuntimeDrawerElement(parentRuntime));
|
|
29132
29139
|
parentRuntime.controller.setOpen(true);
|
|
29133
29140
|
notifyOpenStateChange(parentRuntime, true);
|
|
29134
29141
|
renderVanillaDrawer(parentRuntime.id);
|
|
@@ -29143,18 +29150,36 @@ function cleanupRuntimeTrigger(runtime) {
|
|
|
29143
29150
|
}
|
|
29144
29151
|
function bindTriggerElement(runtime) {
|
|
29145
29152
|
cleanupRuntimeTrigger(runtime);
|
|
29153
|
+
const drawerElement = getRuntimeDrawerElement(runtime);
|
|
29154
|
+
const builtInTriggerElement = getRuntimeTriggerElement(runtime);
|
|
29155
|
+
const cleanups = [];
|
|
29156
|
+
if (builtInTriggerElement) {
|
|
29157
|
+
const handleBuiltInTriggerClick = () => {
|
|
29158
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
29159
|
+
};
|
|
29160
|
+
builtInTriggerElement.addEventListener("click", handleBuiltInTriggerClick);
|
|
29161
|
+
cleanups.push(() => {
|
|
29162
|
+
builtInTriggerElement.removeEventListener("click", handleBuiltInTriggerClick);
|
|
29163
|
+
});
|
|
29164
|
+
}
|
|
29146
29165
|
if (!runtime.options.triggerElement) {
|
|
29166
|
+
runtime.cleanupTriggerElement = cleanups.length ? () => {
|
|
29167
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
29168
|
+
} : null;
|
|
29147
29169
|
return;
|
|
29148
29170
|
}
|
|
29149
29171
|
const triggerElement = runtime.options.triggerElement;
|
|
29150
29172
|
const handleClick = () => {
|
|
29151
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29173
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
29152
29174
|
runtime.controller.setOpen(true);
|
|
29153
29175
|
renderVanillaDrawer(runtime.id);
|
|
29154
29176
|
};
|
|
29155
29177
|
triggerElement.addEventListener("click", handleClick);
|
|
29156
|
-
|
|
29178
|
+
cleanups.push(() => {
|
|
29157
29179
|
triggerElement.removeEventListener("click", handleClick);
|
|
29180
|
+
});
|
|
29181
|
+
runtime.cleanupTriggerElement = () => {
|
|
29182
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
29158
29183
|
};
|
|
29159
29184
|
}
|
|
29160
29185
|
function notifyOpenStateChange(runtime, open) {
|
|
@@ -29184,15 +29209,32 @@ function notifyOpenStateChange(runtime, open) {
|
|
|
29184
29209
|
function canUseDOM3() {
|
|
29185
29210
|
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
29186
29211
|
}
|
|
29187
|
-
function
|
|
29212
|
+
function isElementInsideDrawer(element) {
|
|
29213
|
+
let currentElement = element;
|
|
29214
|
+
while (currentElement) {
|
|
29215
|
+
if (currentElement instanceof HTMLElement && currentElement.hasAttribute("data-drawer")) {
|
|
29216
|
+
return true;
|
|
29217
|
+
}
|
|
29218
|
+
currentElement = currentElement.parentElement;
|
|
29219
|
+
}
|
|
29220
|
+
return false;
|
|
29221
|
+
}
|
|
29222
|
+
function releaseHiddenFocusBeforeOpen(options, drawerElement) {
|
|
29188
29223
|
if (!canUseDOM3() || options.modal === false || options.autoFocus) {
|
|
29189
29224
|
return;
|
|
29190
29225
|
}
|
|
29191
29226
|
const activeElement = document.activeElement;
|
|
29192
|
-
if (!activeElement || activeElement === document.body
|
|
29227
|
+
if (!activeElement || activeElement === document.body) {
|
|
29193
29228
|
return;
|
|
29194
29229
|
}
|
|
29195
|
-
activeElement
|
|
29230
|
+
const activeElementNode = activeElement;
|
|
29231
|
+
if (drawerElement?.contains(activeElementNode) || isElementInsideDrawer(activeElementNode)) {
|
|
29232
|
+
return;
|
|
29233
|
+
}
|
|
29234
|
+
if (typeof activeElementNode.blur !== "function") {
|
|
29235
|
+
return;
|
|
29236
|
+
}
|
|
29237
|
+
activeElementNode.blur();
|
|
29196
29238
|
}
|
|
29197
29239
|
function getRuntimeDrawerElement(runtime) {
|
|
29198
29240
|
if (!runtime.element) {
|
|
@@ -29200,6 +29242,12 @@ function getRuntimeDrawerElement(runtime) {
|
|
|
29200
29242
|
}
|
|
29201
29243
|
return runtime.element.querySelector("[data-drawer]");
|
|
29202
29244
|
}
|
|
29245
|
+
function getRuntimeTriggerElement(runtime) {
|
|
29246
|
+
if (!runtime.element) {
|
|
29247
|
+
return null;
|
|
29248
|
+
}
|
|
29249
|
+
return runtime.element.querySelector("[data-drawer-vanilla-trigger]");
|
|
29250
|
+
}
|
|
29203
29251
|
function getViewportSizeForDirection(direction) {
|
|
29204
29252
|
if (!canUseDOM3()) {
|
|
29205
29253
|
return 0;
|
|
@@ -29248,7 +29296,7 @@ function renderVanillaDrawer(id) {
|
|
|
29248
29296
|
onOpenChange: (open) => {
|
|
29249
29297
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
29250
29298
|
if (open) {
|
|
29251
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29299
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
29252
29300
|
}
|
|
29253
29301
|
runtime.controller.setOpen(open);
|
|
29254
29302
|
if (previousOpen !== open) {
|
|
@@ -29297,7 +29345,7 @@ function buildVanillaController(id) {
|
|
|
29297
29345
|
return createDrawer({ id, open }).getSnapshot();
|
|
29298
29346
|
}
|
|
29299
29347
|
if (open) {
|
|
29300
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29348
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
29301
29349
|
}
|
|
29302
29350
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
29303
29351
|
const snapshot = runtime.controller.setOpen(open);
|
|
@@ -29370,7 +29418,7 @@ function createDrawer(options = {}) {
|
|
|
29370
29418
|
}
|
|
29371
29419
|
}
|
|
29372
29420
|
if (nextOptions.open && !previousOpen) {
|
|
29373
|
-
releaseHiddenFocusBeforeOpen(nextOptions);
|
|
29421
|
+
releaseHiddenFocusBeforeOpen(nextOptions, existing ? getRuntimeDrawerElement(existing) : null);
|
|
29374
29422
|
}
|
|
29375
29423
|
renderVanillaDrawer(id);
|
|
29376
29424
|
if (nextOptions.parentId && nextOptions.open) {
|
package/dist/svelte/index.mjs
CHANGED
|
@@ -28049,6 +28049,23 @@ function Root2({
|
|
|
28049
28049
|
const drawerHeightRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
|
|
28050
28050
|
const drawerWidthRef = import_react9.default.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
|
|
28051
28051
|
const initialDrawerHeight = import_react9.default.useRef(0);
|
|
28052
|
+
const releaseHiddenFocusBeforeOpen2 = import_react9.default.useCallback(() => {
|
|
28053
|
+
if (!modal || autoFocus || typeof document === "undefined") {
|
|
28054
|
+
return;
|
|
28055
|
+
}
|
|
28056
|
+
const activeElement = document.activeElement;
|
|
28057
|
+
if (!activeElement || activeElement === document.body) {
|
|
28058
|
+
return;
|
|
28059
|
+
}
|
|
28060
|
+
const activeElementNode = activeElement;
|
|
28061
|
+
if (drawerRef.current?.contains(activeElementNode) || activeElementNode.closest?.("[data-drawer]")) {
|
|
28062
|
+
return;
|
|
28063
|
+
}
|
|
28064
|
+
if (typeof activeElementNode.blur !== "function") {
|
|
28065
|
+
return;
|
|
28066
|
+
}
|
|
28067
|
+
activeElementNode.blur();
|
|
28068
|
+
}, [autoFocus, modal]);
|
|
28052
28069
|
const onSnapPointChange = import_react9.default.useCallback((activeSnapPointIndex2) => {
|
|
28053
28070
|
if (snapPoints && activeSnapPointIndex2 === snapPointsOffset.length - 1) openTime.current = /* @__PURE__ */ new Date();
|
|
28054
28071
|
}, []);
|
|
@@ -28108,22 +28125,11 @@ function Root2({
|
|
|
28108
28125
|
autoFocus
|
|
28109
28126
|
});
|
|
28110
28127
|
useSafeLayoutEffect(() => {
|
|
28111
|
-
if (!isOpen
|
|
28112
|
-
return;
|
|
28113
|
-
}
|
|
28114
|
-
const activeElement = document.activeElement;
|
|
28115
|
-
if (!activeElement || activeElement === document.body) {
|
|
28128
|
+
if (!isOpen) {
|
|
28116
28129
|
return;
|
|
28117
28130
|
}
|
|
28118
|
-
|
|
28119
|
-
|
|
28120
|
-
return;
|
|
28121
|
-
}
|
|
28122
|
-
if (typeof activeElementNode.blur !== "function") {
|
|
28123
|
-
return;
|
|
28124
|
-
}
|
|
28125
|
-
activeElementNode.blur();
|
|
28126
|
-
}, [autoFocus, isOpen, modal]);
|
|
28131
|
+
releaseHiddenFocusBeforeOpen2();
|
|
28132
|
+
}, [isOpen, releaseHiddenFocusBeforeOpen2]);
|
|
28127
28133
|
function getScale() {
|
|
28128
28134
|
return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
|
|
28129
28135
|
}
|
|
@@ -28507,6 +28513,7 @@ function Root2({
|
|
|
28507
28513
|
onOpenChange: (open) => {
|
|
28508
28514
|
if (!dismissible && !open) return;
|
|
28509
28515
|
if (open) {
|
|
28516
|
+
releaseHiddenFocusBeforeOpen2();
|
|
28510
28517
|
setHasBeenOpened(true);
|
|
28511
28518
|
} else {
|
|
28512
28519
|
closeDrawer2(true);
|
|
@@ -29100,7 +29107,7 @@ function openAncestorChain(parentId) {
|
|
|
29100
29107
|
openAncestorChain(nextParentId);
|
|
29101
29108
|
}
|
|
29102
29109
|
if (!parentRuntime.controller.getSnapshot().state.isOpen) {
|
|
29103
|
-
releaseHiddenFocusBeforeOpen(parentRuntime.options);
|
|
29110
|
+
releaseHiddenFocusBeforeOpen(parentRuntime.options, getRuntimeDrawerElement(parentRuntime));
|
|
29104
29111
|
parentRuntime.controller.setOpen(true);
|
|
29105
29112
|
notifyOpenStateChange(parentRuntime, true);
|
|
29106
29113
|
renderVanillaDrawer(parentRuntime.id);
|
|
@@ -29115,18 +29122,36 @@ function cleanupRuntimeTrigger(runtime) {
|
|
|
29115
29122
|
}
|
|
29116
29123
|
function bindTriggerElement(runtime) {
|
|
29117
29124
|
cleanupRuntimeTrigger(runtime);
|
|
29125
|
+
const drawerElement = getRuntimeDrawerElement(runtime);
|
|
29126
|
+
const builtInTriggerElement = getRuntimeTriggerElement(runtime);
|
|
29127
|
+
const cleanups = [];
|
|
29128
|
+
if (builtInTriggerElement) {
|
|
29129
|
+
const handleBuiltInTriggerClick = () => {
|
|
29130
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
29131
|
+
};
|
|
29132
|
+
builtInTriggerElement.addEventListener("click", handleBuiltInTriggerClick);
|
|
29133
|
+
cleanups.push(() => {
|
|
29134
|
+
builtInTriggerElement.removeEventListener("click", handleBuiltInTriggerClick);
|
|
29135
|
+
});
|
|
29136
|
+
}
|
|
29118
29137
|
if (!runtime.options.triggerElement) {
|
|
29138
|
+
runtime.cleanupTriggerElement = cleanups.length ? () => {
|
|
29139
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
29140
|
+
} : null;
|
|
29119
29141
|
return;
|
|
29120
29142
|
}
|
|
29121
29143
|
const triggerElement = runtime.options.triggerElement;
|
|
29122
29144
|
const handleClick = () => {
|
|
29123
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29145
|
+
releaseHiddenFocusBeforeOpen(runtime.options, drawerElement);
|
|
29124
29146
|
runtime.controller.setOpen(true);
|
|
29125
29147
|
renderVanillaDrawer(runtime.id);
|
|
29126
29148
|
};
|
|
29127
29149
|
triggerElement.addEventListener("click", handleClick);
|
|
29128
|
-
|
|
29150
|
+
cleanups.push(() => {
|
|
29129
29151
|
triggerElement.removeEventListener("click", handleClick);
|
|
29152
|
+
});
|
|
29153
|
+
runtime.cleanupTriggerElement = () => {
|
|
29154
|
+
cleanups.forEach((cleanup) => cleanup());
|
|
29130
29155
|
};
|
|
29131
29156
|
}
|
|
29132
29157
|
function notifyOpenStateChange(runtime, open) {
|
|
@@ -29156,15 +29181,32 @@ function notifyOpenStateChange(runtime, open) {
|
|
|
29156
29181
|
function canUseDOM3() {
|
|
29157
29182
|
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
29158
29183
|
}
|
|
29159
|
-
function
|
|
29184
|
+
function isElementInsideDrawer(element) {
|
|
29185
|
+
let currentElement = element;
|
|
29186
|
+
while (currentElement) {
|
|
29187
|
+
if (currentElement instanceof HTMLElement && currentElement.hasAttribute("data-drawer")) {
|
|
29188
|
+
return true;
|
|
29189
|
+
}
|
|
29190
|
+
currentElement = currentElement.parentElement;
|
|
29191
|
+
}
|
|
29192
|
+
return false;
|
|
29193
|
+
}
|
|
29194
|
+
function releaseHiddenFocusBeforeOpen(options, drawerElement) {
|
|
29160
29195
|
if (!canUseDOM3() || options.modal === false || options.autoFocus) {
|
|
29161
29196
|
return;
|
|
29162
29197
|
}
|
|
29163
29198
|
const activeElement = document.activeElement;
|
|
29164
|
-
if (!activeElement || activeElement === document.body
|
|
29199
|
+
if (!activeElement || activeElement === document.body) {
|
|
29165
29200
|
return;
|
|
29166
29201
|
}
|
|
29167
|
-
activeElement
|
|
29202
|
+
const activeElementNode = activeElement;
|
|
29203
|
+
if (drawerElement?.contains(activeElementNode) || isElementInsideDrawer(activeElementNode)) {
|
|
29204
|
+
return;
|
|
29205
|
+
}
|
|
29206
|
+
if (typeof activeElementNode.blur !== "function") {
|
|
29207
|
+
return;
|
|
29208
|
+
}
|
|
29209
|
+
activeElementNode.blur();
|
|
29168
29210
|
}
|
|
29169
29211
|
function getRuntimeDrawerElement(runtime) {
|
|
29170
29212
|
if (!runtime.element) {
|
|
@@ -29172,6 +29214,12 @@ function getRuntimeDrawerElement(runtime) {
|
|
|
29172
29214
|
}
|
|
29173
29215
|
return runtime.element.querySelector("[data-drawer]");
|
|
29174
29216
|
}
|
|
29217
|
+
function getRuntimeTriggerElement(runtime) {
|
|
29218
|
+
if (!runtime.element) {
|
|
29219
|
+
return null;
|
|
29220
|
+
}
|
|
29221
|
+
return runtime.element.querySelector("[data-drawer-vanilla-trigger]");
|
|
29222
|
+
}
|
|
29175
29223
|
function getViewportSizeForDirection(direction) {
|
|
29176
29224
|
if (!canUseDOM3()) {
|
|
29177
29225
|
return 0;
|
|
@@ -29220,7 +29268,7 @@ function renderVanillaDrawer(id) {
|
|
|
29220
29268
|
onOpenChange: (open) => {
|
|
29221
29269
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
29222
29270
|
if (open) {
|
|
29223
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29271
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
29224
29272
|
}
|
|
29225
29273
|
runtime.controller.setOpen(open);
|
|
29226
29274
|
if (previousOpen !== open) {
|
|
@@ -29269,7 +29317,7 @@ function buildVanillaController(id) {
|
|
|
29269
29317
|
return createDrawer({ id, open }).getSnapshot();
|
|
29270
29318
|
}
|
|
29271
29319
|
if (open) {
|
|
29272
|
-
releaseHiddenFocusBeforeOpen(runtime.options);
|
|
29320
|
+
releaseHiddenFocusBeforeOpen(runtime.options, getRuntimeDrawerElement(runtime));
|
|
29273
29321
|
}
|
|
29274
29322
|
const previousOpen = runtime.controller.getSnapshot().state.isOpen;
|
|
29275
29323
|
const snapshot = runtime.controller.setOpen(open);
|
|
@@ -29342,7 +29390,7 @@ function createDrawer(options = {}) {
|
|
|
29342
29390
|
}
|
|
29343
29391
|
}
|
|
29344
29392
|
if (nextOptions.open && !previousOpen) {
|
|
29345
|
-
releaseHiddenFocusBeforeOpen(nextOptions);
|
|
29393
|
+
releaseHiddenFocusBeforeOpen(nextOptions, existing ? getRuntimeDrawerElement(existing) : null);
|
|
29346
29394
|
}
|
|
29347
29395
|
renderVanillaDrawer(id);
|
|
29348
29396
|
if (nextOptions.parentId && nextOptions.open) {
|