vanilla-drawers 1.1.19 → 1.1.21
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/drawers.es.js +1 -1
- package/dist/drawers.umd.js +1 -1
- package/package.json +1 -1
package/dist/drawers.es.js
CHANGED
@@ -446,7 +446,7 @@ const q = class q {
|
|
446
446
|
const o = r.getAttribute("data-drawer");
|
447
447
|
if (typeof o != "string")
|
448
448
|
return;
|
449
|
-
const i = new Le({ target: r, options: { ...t, modal: r.matches(
|
449
|
+
const i = new Le({ target: r, options: { ...t, modal: r.matches("[data-modal]") ? r.matches(':not([data-modal="false"]') : t.modal } });
|
450
450
|
s(this, I).set(o, i);
|
451
451
|
const c = r.closest(`[${F}]`), h = c ? c.getAttribute(F) : "default";
|
452
452
|
if (typeof h != "string")
|
package/dist/drawers.umd.js
CHANGED
@@ -3,4 +3,4 @@
|
|
3
3
|
*
|
4
4
|
* Copyright (c) 2014-2017, Jon Schlinkert.
|
5
5
|
* Released under the MIT License.
|
6
|
-
*/function re(s){return Object.prototype.toString.call(s)==="[object Object]"}function Ce(s){var t,e;return re(s)===!1?!1:(t=s.constructor,t===void 0?!0:(e=t.prototype,!(re(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function Z(s){return s instanceof Element?s:document.querySelector(s)}async function ee(s){return await new Promise(t=>setTimeout(t,s))}const _e='[data-elem="drawer.panel"]',J="data-drawers-group",Le=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],te={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",closingClass:"drawer_closing",openingClass:"drawer_opening",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function oe(s){return Ee.all(s,{isMergeableObject:Ce})}class Q{constructor({target:t,type:e,owner:a}){b(this,_,void 0);b(this,E,void 0);b(this,z,void 0);b(this,K,!1);const l=Z(t);if(!l)throw new Error("Trigger element cannot be found");if(!a)throw new Error("Owning drawer instance hasn't been provided");A(this,_,l),A(this,E,a),A(this,z,e),this.init()}get isActive(){return n(this,K)}get owner(){return n(this,E)}init(){n(this,_).addEventListener("click",t=>this.clickHandler(t)),n(this,E).on("open",()=>this.setActive(!0)),n(this,E).on("close",()=>this.setActive(!1))}clickHandler(t){t.__drawerTrigger=this,n(this,z)==="open"?n(this,E).isOpen||n(this,E).open(n(this,_)):n(this,z)==="close"?n(this,E).isOpen&&n(this,E).close(n(this,_)):n(this,E).isOpen?n(this,E).close(n(this,_)):n(this,E).open(n(this,_))}setActive(t){A(this,K,t),t?n(this,_).classList.add("drawer-trigger_active"):n(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,K=new WeakMap;class ie extends ae{constructor({target:e,options:a}){super();b(this,d,void 0);b(this,F,void 0);b(this,x,void 0);b(this,X,void 0);b(this,U,void 0);this.handleDocumentClick=async r=>{var c;if(((c=r.__drawerTrigger)==null?void 0:c.owner)===this)return;const o=r.target;if(r.composedPath(),this.dom.panel.contains(o))return;const i=o==null?void 0:o.closest("[data-drawer]");i?i.getAttribute("data-drawer")===n(this,U)?this.handleUnderlayClick(r):this.handleOtherDrawerClick(r):this.handleOutsideClick(r)},this.handleKeydown=r=>{n(this,d).closeOnEsc&&r.key==="Escape"&&this.close()};const l=oe(a?[te,a]:[te]),v=Z(e);if(v===null)throw new Error("Drawer's root cannot be found");A(this,U,v.getAttribute("data-drawer"));const w=v.querySelector(_e);if(w===null)throw new Error(`Drawer's panel cannot be found. Alias: ${n(this,U)}`);this.dom={root:v,panel:w},this.setOptions(l),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get isOpen(){return n(this,x)}get isModal(){return n(this,d).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}get willLockScroll(){return n(this,d).lockPageScroll}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),A(this,F,e)}get zIndex(){return n(this,F)}async open(e){await ee(0),!n(this,x)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),A(this,x,!0),this.dom.root.classList.add(n(this,d).openingClass),this.emit("open",{drawer:this,trigger:e}),typeof n(this,d).openAnimationDuration=="number"&&await ee(n(this,d).openAnimationDuration),this.dom.root.classList.remove(n(this,d).openingClass),this.dom.root.classList.add(n(this,d).openClass),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){n(this,d).onCloseConfirm&&!n(this,d).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),A(this,x,!1),this.dom.root.classList.remove(n(this,d).openClass),this.dom.root.classList.add(n(this,d).closingClass),this.emit("close",{drawer:this,trigger:e}),typeof n(this,d).closeAnimationDuration=="number"&&await ee(n(this,d).closeAnimationDuration),this.dom.root.classList.remove(n(this,d).closingClass),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){n(this,d).closeOnOutsideClick&&(typeof n(this,d).closeOnOutsideClick=="object"&&n(this,d).closeOnOutsideClick.hasOwnProperty("checkTarget")?n(this,d).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){n(this,d).closeOnOutsideClick&&this.close()}focus(){n(this,d).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(Le.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=n(this,d))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),A(this,d,n(this,d)?oe([n(this,d),e]):e)}assignGroup(e){A(this,X,e)}}d=new WeakMap,F=new WeakMap,x=new WeakMap,X=new WeakMap,U=new WeakMap;class ke{constructor(){b(this,T,new Map)}lock(t,e){n(this,T).has(t)||n(this,T).set(t,new Set);const a=n(this,T).get(t);a.size===0&&t.classList.add("scroll-lock-by-drawer"),a.add(e)}unlock(t,e){const a=n(this,T).get(t);a==null||a.delete(e),(!a||a.size===0)&&t.classList.remove("scroll-lock-by-drawer")}}T=new WeakMap;const G=class G{constructor(t){b(this,P,void 0);b(this,L,void 0);b(this,k,void 0);b(this,N,void 0);b(this,j,void 0);A(this,L,[]),A(this,k,[]),A(this,j,new Map),this.onBeforeOpen=({drawer:l,trigger:v})=>{l.isModal?(n(this,j).set(l,n(this,L).length),n(this,L).push(l),l.zIndex=n(this,k).length+n(this,L).length):(n(this,j).set(l,n(this,k).length),n(this,k).push(l),l.zIndex=n(this,k).length,n(this,L).length>0&&n(this,L).forEach((w,r)=>w.zIndex=n(this,k).length+r+1)),l.willLockScroll&&this.lockScroll(l)},this.onCloseAnimationEnd=({drawer:l,trigger:v})=>{const w=l.isModal?n(this,L):n(this,k);for(delete w[n(this,j).get(l)];w.length&&!w.at(-1);)w.pop();n(this,j).delete(l),this.unlockScroll(l)};const e=Z(t);if(e===null)throw new Error("Drawer's group root cannot be found");A(this,P,e);const a=n(this,P).closest("[data-scrollable], html")||n(this,P).matches("[data-scrollable], html")&&n(this,P);if(a===null)throw new Error("Scrollable container for group root cannot be found");A(this,N,a)}add(t){t.on("beforeOpen",this.onBeforeOpen),t.on("closeAnimationEnd",this.onCloseAnimationEnd),t.assignGroup(this)}lockScroll(t){G.scrollLock.lock(n(this,N),t)}unlockScroll(t){G.scrollLock.unlock(n(this,N),t)}};P=new WeakMap,L=new WeakMap,k=new WeakMap,N=new WeakMap,j=new WeakMap,G.scrollLock=new ke;let B=G;const H=class H{constructor(){b(this,$,new Map);b(this,q,new Map);if(H.instance)return H.instance;H.instance=this}init(t=te){document.querySelectorAll(`[${J}]`).forEach(r=>{const o=r.getAttribute(J);typeof o=="string"&&n(this,q).set(o,new B(r))}),n(this,q).set("default",new B(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(r=>{var y;const o=r.getAttribute("data-drawer");if(typeof o!="string")return;const i=new ie({target:r,options:{...t,modal:r.matches(
|
6
|
+
*/function re(s){return Object.prototype.toString.call(s)==="[object Object]"}function Ce(s){var t,e;return re(s)===!1?!1:(t=s.constructor,t===void 0?!0:(e=t.prototype,!(re(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function Z(s){return s instanceof Element?s:document.querySelector(s)}async function ee(s){return await new Promise(t=>setTimeout(t,s))}const _e='[data-elem="drawer.panel"]',J="data-drawers-group",Le=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],te={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",closingClass:"drawer_closing",openingClass:"drawer_opening",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function oe(s){return Ee.all(s,{isMergeableObject:Ce})}class Q{constructor({target:t,type:e,owner:a}){b(this,_,void 0);b(this,E,void 0);b(this,z,void 0);b(this,K,!1);const l=Z(t);if(!l)throw new Error("Trigger element cannot be found");if(!a)throw new Error("Owning drawer instance hasn't been provided");A(this,_,l),A(this,E,a),A(this,z,e),this.init()}get isActive(){return n(this,K)}get owner(){return n(this,E)}init(){n(this,_).addEventListener("click",t=>this.clickHandler(t)),n(this,E).on("open",()=>this.setActive(!0)),n(this,E).on("close",()=>this.setActive(!1))}clickHandler(t){t.__drawerTrigger=this,n(this,z)==="open"?n(this,E).isOpen||n(this,E).open(n(this,_)):n(this,z)==="close"?n(this,E).isOpen&&n(this,E).close(n(this,_)):n(this,E).isOpen?n(this,E).close(n(this,_)):n(this,E).open(n(this,_))}setActive(t){A(this,K,t),t?n(this,_).classList.add("drawer-trigger_active"):n(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,K=new WeakMap;class ie extends ae{constructor({target:e,options:a}){super();b(this,d,void 0);b(this,F,void 0);b(this,x,void 0);b(this,X,void 0);b(this,U,void 0);this.handleDocumentClick=async r=>{var c;if(((c=r.__drawerTrigger)==null?void 0:c.owner)===this)return;const o=r.target;if(r.composedPath(),this.dom.panel.contains(o))return;const i=o==null?void 0:o.closest("[data-drawer]");i?i.getAttribute("data-drawer")===n(this,U)?this.handleUnderlayClick(r):this.handleOtherDrawerClick(r):this.handleOutsideClick(r)},this.handleKeydown=r=>{n(this,d).closeOnEsc&&r.key==="Escape"&&this.close()};const l=oe(a?[te,a]:[te]),v=Z(e);if(v===null)throw new Error("Drawer's root cannot be found");A(this,U,v.getAttribute("data-drawer"));const w=v.querySelector(_e);if(w===null)throw new Error(`Drawer's panel cannot be found. Alias: ${n(this,U)}`);this.dom={root:v,panel:w},this.setOptions(l),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get isOpen(){return n(this,x)}get isModal(){return n(this,d).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}get willLockScroll(){return n(this,d).lockPageScroll}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),A(this,F,e)}get zIndex(){return n(this,F)}async open(e){await ee(0),!n(this,x)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),A(this,x,!0),this.dom.root.classList.add(n(this,d).openingClass),this.emit("open",{drawer:this,trigger:e}),typeof n(this,d).openAnimationDuration=="number"&&await ee(n(this,d).openAnimationDuration),this.dom.root.classList.remove(n(this,d).openingClass),this.dom.root.classList.add(n(this,d).openClass),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){n(this,d).onCloseConfirm&&!n(this,d).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),A(this,x,!1),this.dom.root.classList.remove(n(this,d).openClass),this.dom.root.classList.add(n(this,d).closingClass),this.emit("close",{drawer:this,trigger:e}),typeof n(this,d).closeAnimationDuration=="number"&&await ee(n(this,d).closeAnimationDuration),this.dom.root.classList.remove(n(this,d).closingClass),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){n(this,d).closeOnOutsideClick&&(typeof n(this,d).closeOnOutsideClick=="object"&&n(this,d).closeOnOutsideClick.hasOwnProperty("checkTarget")?n(this,d).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){n(this,d).closeOnOutsideClick&&this.close()}focus(){n(this,d).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(Le.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=n(this,d))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),A(this,d,n(this,d)?oe([n(this,d),e]):e)}assignGroup(e){A(this,X,e)}}d=new WeakMap,F=new WeakMap,x=new WeakMap,X=new WeakMap,U=new WeakMap;class ke{constructor(){b(this,T,new Map)}lock(t,e){n(this,T).has(t)||n(this,T).set(t,new Set);const a=n(this,T).get(t);a.size===0&&t.classList.add("scroll-lock-by-drawer"),a.add(e)}unlock(t,e){const a=n(this,T).get(t);a==null||a.delete(e),(!a||a.size===0)&&t.classList.remove("scroll-lock-by-drawer")}}T=new WeakMap;const G=class G{constructor(t){b(this,P,void 0);b(this,L,void 0);b(this,k,void 0);b(this,N,void 0);b(this,j,void 0);A(this,L,[]),A(this,k,[]),A(this,j,new Map),this.onBeforeOpen=({drawer:l,trigger:v})=>{l.isModal?(n(this,j).set(l,n(this,L).length),n(this,L).push(l),l.zIndex=n(this,k).length+n(this,L).length):(n(this,j).set(l,n(this,k).length),n(this,k).push(l),l.zIndex=n(this,k).length,n(this,L).length>0&&n(this,L).forEach((w,r)=>w.zIndex=n(this,k).length+r+1)),l.willLockScroll&&this.lockScroll(l)},this.onCloseAnimationEnd=({drawer:l,trigger:v})=>{const w=l.isModal?n(this,L):n(this,k);for(delete w[n(this,j).get(l)];w.length&&!w.at(-1);)w.pop();n(this,j).delete(l),this.unlockScroll(l)};const e=Z(t);if(e===null)throw new Error("Drawer's group root cannot be found");A(this,P,e);const a=n(this,P).closest("[data-scrollable], html")||n(this,P).matches("[data-scrollable], html")&&n(this,P);if(a===null)throw new Error("Scrollable container for group root cannot be found");A(this,N,a)}add(t){t.on("beforeOpen",this.onBeforeOpen),t.on("closeAnimationEnd",this.onCloseAnimationEnd),t.assignGroup(this)}lockScroll(t){G.scrollLock.lock(n(this,N),t)}unlockScroll(t){G.scrollLock.unlock(n(this,N),t)}};P=new WeakMap,L=new WeakMap,k=new WeakMap,N=new WeakMap,j=new WeakMap,G.scrollLock=new ke;let B=G;const H=class H{constructor(){b(this,$,new Map);b(this,q,new Map);if(H.instance)return H.instance;H.instance=this}init(t=te){document.querySelectorAll(`[${J}]`).forEach(r=>{const o=r.getAttribute(J);typeof o=="string"&&n(this,q).set(o,new B(r))}),n(this,q).set("default",new B(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(r=>{var y;const o=r.getAttribute("data-drawer");if(typeof o!="string")return;const i=new ie({target:r,options:{...t,modal:r.matches("[data-modal]")?r.matches(':not([data-modal="false"]'):t.modal}});n(this,$).set(o,i);const c=r.closest(`[${J}]`),h=c?c.getAttribute(J):"default";if(typeof h!="string")throw new Error("Group doesn't have alias set correctly");(y=n(this,q).get(h))==null||y.add(i)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(r=>{if(r.hasAttribute("data-drawer-open")){const o=r.getAttribute("data-drawer-open");v(r,o);const i=this.get(o);w(r,i,o),new Q({target:r,type:"open",owner:i})}else if(r.hasAttribute("data-drawer-close")){const o=r.getAttribute("data-drawer-close");v(r,o);const i=this.get(o);w(r,i,o),new Q({target:r,type:"close",owner:i})}else{const o=r.getAttribute("data-drawer-toggle");v(r,o);const i=this.get(o);w(r,i,o),new Q({target:r,type:"toggle",owner:i})}});function v(r,o){if(!o)throw new Error(`Drawer alias should be specified in the trigger attribute. Trigger elem: ${r}`)}function w(r,o,i){if(!o)throw new Error(`Drawer hasn't been found for the trigger elem: ${r}. Alias: ${i}`)}}open(t,{trigger:e,options:a}={}){var l;(l=this.get(t))==null||l.open(e)}close(t,{trigger:e,options:a}={}){var l;(l=this.get(t))==null||l.close(e)}get(t){return typeof t=="string"&&n(this,$).get(t)||null}on(t,e,a){var l;if(t)(l=this.get(t))==null||l.on(e,a);else for(const[v,w]of n(this,$))w.on(e,a)}};$=new WeakMap,q=new WeakMap;let W=H;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new W),f.Drawer=ie,f.DrawersGroup=B,f.Trigger=Q,f.default=W,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|