@n8d/htwoo-core
Version:
hTWOo is a Fluent Design Framework purely in HTML and CSS
2 lines (1 loc) • 2.81 kB
JavaScript
"use strict";var e,t,o,s,i,r,l,a,n,c,h=function(e,t,o,s,i){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?i.call(e,o):i?i.value=o:t.set(e,o),o},f=function(e,t,o,s){if("a"===o&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===o?s:"a"===o?s.call(e):s?s.value:t.get(e)};exports.DialogType=void 0,(c=exports.DialogType||(exports.DialogType={})).DIALOG="dialog",c.MODAL="modal";class d{constructor(c,p,w=exports.DialogType.DIALOG,u=d.options){e.set(this,void 0),t.set(this,void 0),o.set(this,void 0),s.set(this,void 0),i.set(this,{closer:null,backdropCloser:!0,escCloser:!0}),r.set(this,(()=>{if(console.debug("-> Fired showDialog -- ",f(this,t,"f")),f(this,o,"f")===exports.DialogType.DIALOG)f(this,t,"f").show();else{if(f(this,o,"f")!==exports.DialogType.MODAL)throw new Error(`Invalid dialog type specified for ${f(this,t,"f")}`);f(this,t,"f").showModal(),f(this,t,"f").addEventListener("click",f(this,l,"f"))}f(this,s,"f")&&f(this,s,"f").addEventListener("click",f(this,n,"f"));f(this,t,"f").querySelector("[autofocus]")&&(console.debug("No Autofocus"),f(this,t,"f").focus()),f(this,t,"f").addEventListener("keydown",f(this,a,"f"))})),l.set(this,(e=>{const o=f(this,t,"f").getBoundingClientRect();o.top<=e.clientY&&e.clientY<=o.top+o.height&&o.left<=e.clientX&&e.clientX<=o.left+o.width||e.target!==f(this,t,"f")||f(this,t,"f").close()})),a.set(this,(e=>{27===e.keyCode&&f(this,t,"f").close()})),n.set(this,(e=>{console.debug("closing dialog"),f(this,t,"f").close()})),console.debug("Register dialog",w);const g=document.querySelector(c),y=document.querySelector(p);if(!g)throw new Error(`Launcher '${c}' Element cannot be found`);if(h(this,e,g,"f"),!y)throw new Error(`Dialog '${p}' Element not found`);if(h(this,t,y,"f"),f(this,e,"f").addEventListener("click",f(this,r,"f")),h(this,o,w,"f"),h(this,i,{closer:void 0===u.closer?null:u.closer,backdropCloser:void 0===u.backdropCloser||u.backdropCloser,escCloser:void 0===u.escCloser||u.escCloser},"f"),null!==u.closer){const e=y.querySelector(u.closer);f(this,i,"f").closer=u.closer,e&&h(this,s,e,"f")}console.debug("AFTER LAUNCH ::: ",f(this,o,"f"),f(this,e,"f"),f(this,t,"f"),f(this,s,"f"))}}e=new WeakMap,t=new WeakMap,o=new WeakMap,s=new WeakMap,i=new WeakMap,r=new WeakMap,l=new WeakMap,a=new WeakMap,n=new WeakMap,d.options={closer:null,backdropCloser:!0,escCloser:!0},d.dialogType=exports.DialogType,exports.HOODialog=d;