vanilla-drawers 1.0.9 → 1.0.10
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 +5 -4
- package/dist/drawers.umd.js +1 -1
- package/package.json +1 -1
package/dist/drawers.es.js
CHANGED
@@ -455,10 +455,11 @@ const q = class q {
|
|
455
455
|
}
|
456
456
|
on(t, e, a) {
|
457
457
|
var s;
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
458
|
+
if (t)
|
459
|
+
(s = this.get(t)) == null || s.on(e, a);
|
460
|
+
else
|
461
|
+
for (const [f, d] of r(this, I))
|
462
|
+
d.on(e, a);
|
462
463
|
}
|
463
464
|
};
|
464
465
|
I = new WeakMap(), z = new WeakMap();
|
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 ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ae(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function W(r){return r instanceof Element?r:document.querySelector(r)}async function X(r){return await new Promise(n=>setTimeout(n,r))}const Ce='[data-elem="drawer.panel"]',V="data-drawers-group",_e=["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^="-"])'],re={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",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function se(r){return Ee.all(r,{isMergeableObject:Ae})}class Y{constructor({target:n,type:e,owner:a}){g(this,_,void 0);g(this,E,void 0);g(this,z,void 0);g(this,B,!1);const s=W(n);if(!s)throw new Error("Trigger element cannot be found");O(this,_,s),O(this,E,a),O(this,z,e),this.init()}get isActive(){return t(this,B)}get owner(){return t(this,E)}init(){t(this,_).addEventListener("click",n=>this.clickHandler(n)),t(this,E).on("open",()=>this.setActive(!0)),t(this,E).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,z)==="open"?t(this,E).isOpen||t(this,E).open(t(this,_)):t(this,z)==="close"?t(this,E).isOpen&&t(this,E).close(t(this,_)):t(this,E).isOpen?t(this,E).close(t(this,_)):t(this,E).open(t(this,_))}setActive(n){O(this,B,n),n?t(this,_).classList.add("drawer-trigger_active"):t(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,B=new WeakMap;class ie extends le{constructor({target:e,options:a}){super();g(this,m,void 0);g(this,$,void 0);g(this,T,void 0);g(this,Q,void 0);g(this,U,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const u=h.target;if(h.composedPath(),this.dom.panel.contains(u))return;const i=u==null?void 0:u.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,U)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,m).closeOnEsc&&h.key==="Escape"&&this.close()};const s=se(a?[re,a]:[re]),f=W(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,U,f.getAttribute("data-drawer"));const d=f.querySelector(Ce);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,U)}`);this.dom={root:f,panel:d},this.setOptions(s),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 t(this,T)}get isModal(){return t(this,m).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),O(this,$,e)}get zIndex(){return t(this,$)}async open(e){await X(0),!t(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,T,!0),this.dom.root.classList.add(t(this,m).openClass),this.emit("open",{drawer:this,trigger:e}),typeof t(this,m).openAnimationDuration=="number"&&X(t(this,m).openAnimationDuration),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){t(this,m).onCloseConfirm&&!t(this,m).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),O(this,T,!1),this.dom.root.classList.remove(t(this,m).openClass),this.emit("close",{drawer:this,trigger:e}),typeof t(this,m).closeAnimationDuration=="number"&&X(t(this,m).closeAnimationDuration),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){t(this,m).closeOnOutsideClick&&(typeof t(this,m).closeOnOutsideClick=="object"&&t(this,m).closeOnOutsideClick.hasOwnProperty("checkTarget")?t(this,m).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){t(this,m).closeOnOutsideClick&&this.close()}focus(){t(this,m).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(_e.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=t(this,m))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),O(this,m,t(this,m)?se([t(this,m),e]):e)}assignGroup(e){O(this,Q,e)}}m=new WeakMap,$=new WeakMap,T=new WeakMap,Q=new WeakMap,U=new WeakMap;class Z{constructor(n){g(this,P,void 0);g(this,j,void 0);g(this,S,void 0);g(this,N,void 0);g(this,M,void 0);g(this,k,void 0);O(this,j,[]),O(this,S,[]),O(this,M,new Set),O(this,k,new Map),this.onBeforeOpen=({drawer:s,trigger:f})=>{s.isModal?(t(this,k).set(s,t(this,j).length),t(this,j).push(s),s.zIndex=t(this,S).length+t(this,j).length):(t(this,k).set(s,t(this,S).length),t(this,S).push(s),s.zIndex=t(this,S).length,t(this,j).length>0&&t(this,j).forEach((d,h)=>d.zIndex=t(this,S).length+h+1)),this.lockScroll(s)},this.onCloseAnimationEnd=({drawer:s,trigger:f})=>{const d=s.isModal?t(this,j):t(this,S);for(delete d[t(this,k).get(s)];d.length&&!d.at(-1);)d.pop();t(this,k).delete(s),this.unlockScroll(s)};const e=W(n);if(e===null)throw new Error("Drawer's group root cannot be found");O(this,P,e);const a=t(this,P).closest("[data-scrollable], html")||t(this,P).matches("[data-scrollable], html")&&t(this,P);if(a===null)throw new Error("Scrollable container for group root cannot be found");O(this,N,a)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,M).size===0&&t(this,N).classList.add("scroll-lock-by-drawer"),t(this,M).add(n)}unlockScroll(n){t(this,M).delete(n),t(this,M).size===0&&t(this,N).classList.remove("scroll-lock-by-drawer")}}P=new WeakMap,j=new WeakMap,S=new WeakMap,N=new WeakMap,M=new WeakMap,k=new WeakMap;const K=class K{constructor(){g(this,q,new Map);g(this,G,new Map);if(K.instance)return K.instance;K.instance=this}init(n){document.querySelectorAll(`[${V}]`).forEach(f=>{const d=f.getAttribute(V);typeof d=="string"&&t(this,G).set(d,new Z(f))}),t(this,G).set("default",new Z(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new ie({target:f,options:n});t(this,q).set(d,h);const u=f.closest(`[${V}]`),i=u?u.getAttribute(V):"default";if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,G).get(i))==null||o.add(h)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(f=>{if(f.hasAttribute("data-drawer-open")){const d=f.getAttribute("data-drawer-open");new Y({target:f,type:"open",owner:this.get(d)})}else if(f.hasAttribute("data-drawer-close")){const d=f.getAttribute("data-drawer-close");new Y({target:f,type:"close",owner:this.get(d)})}else{const d=f.getAttribute("data-drawer-toggle");new Y({target:f,type:"toggle",owner:this.get(d)})}})}open(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,q).get(n)||null}on(n,e,a){var s;n
|
6
|
+
*/function ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ae(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function W(r){return r instanceof Element?r:document.querySelector(r)}async function X(r){return await new Promise(n=>setTimeout(n,r))}const Ce='[data-elem="drawer.panel"]',V="data-drawers-group",_e=["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^="-"])'],re={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",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function se(r){return Ee.all(r,{isMergeableObject:Ae})}class Y{constructor({target:n,type:e,owner:a}){g(this,_,void 0);g(this,E,void 0);g(this,z,void 0);g(this,B,!1);const s=W(n);if(!s)throw new Error("Trigger element cannot be found");O(this,_,s),O(this,E,a),O(this,z,e),this.init()}get isActive(){return t(this,B)}get owner(){return t(this,E)}init(){t(this,_).addEventListener("click",n=>this.clickHandler(n)),t(this,E).on("open",()=>this.setActive(!0)),t(this,E).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,z)==="open"?t(this,E).isOpen||t(this,E).open(t(this,_)):t(this,z)==="close"?t(this,E).isOpen&&t(this,E).close(t(this,_)):t(this,E).isOpen?t(this,E).close(t(this,_)):t(this,E).open(t(this,_))}setActive(n){O(this,B,n),n?t(this,_).classList.add("drawer-trigger_active"):t(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,B=new WeakMap;class ie extends le{constructor({target:e,options:a}){super();g(this,m,void 0);g(this,$,void 0);g(this,T,void 0);g(this,Q,void 0);g(this,U,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const u=h.target;if(h.composedPath(),this.dom.panel.contains(u))return;const i=u==null?void 0:u.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,U)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,m).closeOnEsc&&h.key==="Escape"&&this.close()};const s=se(a?[re,a]:[re]),f=W(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,U,f.getAttribute("data-drawer"));const d=f.querySelector(Ce);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,U)}`);this.dom={root:f,panel:d},this.setOptions(s),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 t(this,T)}get isModal(){return t(this,m).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),O(this,$,e)}get zIndex(){return t(this,$)}async open(e){await X(0),!t(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,T,!0),this.dom.root.classList.add(t(this,m).openClass),this.emit("open",{drawer:this,trigger:e}),typeof t(this,m).openAnimationDuration=="number"&&X(t(this,m).openAnimationDuration),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){t(this,m).onCloseConfirm&&!t(this,m).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),O(this,T,!1),this.dom.root.classList.remove(t(this,m).openClass),this.emit("close",{drawer:this,trigger:e}),typeof t(this,m).closeAnimationDuration=="number"&&X(t(this,m).closeAnimationDuration),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){t(this,m).closeOnOutsideClick&&(typeof t(this,m).closeOnOutsideClick=="object"&&t(this,m).closeOnOutsideClick.hasOwnProperty("checkTarget")?t(this,m).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){t(this,m).closeOnOutsideClick&&this.close()}focus(){t(this,m).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(_e.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=t(this,m))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),O(this,m,t(this,m)?se([t(this,m),e]):e)}assignGroup(e){O(this,Q,e)}}m=new WeakMap,$=new WeakMap,T=new WeakMap,Q=new WeakMap,U=new WeakMap;class Z{constructor(n){g(this,P,void 0);g(this,j,void 0);g(this,S,void 0);g(this,N,void 0);g(this,M,void 0);g(this,k,void 0);O(this,j,[]),O(this,S,[]),O(this,M,new Set),O(this,k,new Map),this.onBeforeOpen=({drawer:s,trigger:f})=>{s.isModal?(t(this,k).set(s,t(this,j).length),t(this,j).push(s),s.zIndex=t(this,S).length+t(this,j).length):(t(this,k).set(s,t(this,S).length),t(this,S).push(s),s.zIndex=t(this,S).length,t(this,j).length>0&&t(this,j).forEach((d,h)=>d.zIndex=t(this,S).length+h+1)),this.lockScroll(s)},this.onCloseAnimationEnd=({drawer:s,trigger:f})=>{const d=s.isModal?t(this,j):t(this,S);for(delete d[t(this,k).get(s)];d.length&&!d.at(-1);)d.pop();t(this,k).delete(s),this.unlockScroll(s)};const e=W(n);if(e===null)throw new Error("Drawer's group root cannot be found");O(this,P,e);const a=t(this,P).closest("[data-scrollable], html")||t(this,P).matches("[data-scrollable], html")&&t(this,P);if(a===null)throw new Error("Scrollable container for group root cannot be found");O(this,N,a)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,M).size===0&&t(this,N).classList.add("scroll-lock-by-drawer"),t(this,M).add(n)}unlockScroll(n){t(this,M).delete(n),t(this,M).size===0&&t(this,N).classList.remove("scroll-lock-by-drawer")}}P=new WeakMap,j=new WeakMap,S=new WeakMap,N=new WeakMap,M=new WeakMap,k=new WeakMap;const K=class K{constructor(){g(this,q,new Map);g(this,G,new Map);if(K.instance)return K.instance;K.instance=this}init(n){document.querySelectorAll(`[${V}]`).forEach(f=>{const d=f.getAttribute(V);typeof d=="string"&&t(this,G).set(d,new Z(f))}),t(this,G).set("default",new Z(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new ie({target:f,options:n});t(this,q).set(d,h);const u=f.closest(`[${V}]`),i=u?u.getAttribute(V):"default";if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,G).get(i))==null||o.add(h)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(f=>{if(f.hasAttribute("data-drawer-open")){const d=f.getAttribute("data-drawer-open");new Y({target:f,type:"open",owner:this.get(d)})}else if(f.hasAttribute("data-drawer-close")){const d=f.getAttribute("data-drawer-close");new Y({target:f,type:"close",owner:this.get(d)})}else{const d=f.getAttribute("data-drawer-toggle");new Y({target:f,type:"toggle",owner:this.get(d)})}})}open(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,q).get(n)||null}on(n,e,a){var s;if(n)(s=this.get(n))==null||s.on(e,a);else for(const[f,d]of t(this,q))d.on(e,a)}};q=new WeakMap,G=new WeakMap;let J=K;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new J),p.Drawer=ie,p.DrawersGroup=Z,p.Trigger=Y,p.default=J,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|