Current section
Files
Jump to
Current section
Files
priv/static/primer-live.min.js
"use strict";(()=>{var c="[data-prompt]",m="[data-prompt-content]",i="[data-content]",u="[data-touch]",d='input[type="checkbox"]',x="label",k="ismounted",v="touch",y="ismodal",w="isescapable",z="focusfirst",p=o=>(o==null?void 0:o.dataset[v])!==void 0,h=o=>(o==null?void 0:o.dataset[y])!==void 0,$=o=>(o==null?void 0:o.dataset[w])!==void 0;function S(o){let e=o==null?void 0:o.closest(c);if(!e)return null;let r=e.querySelector(d);return r||null}function b(o){let e=null;if(typeof o=="string"){let r=document.querySelector(o);r&&(e=r.querySelector(d))}else e=S(o);return e}function C(o){let e=o.closest(c);if(!e)throw new Error("Prompt element ".concat(c," not found"));let r=(e==null?void 0:e.querySelector(m))||null;if(!r)throw new Error("Prompt element 'data-prompt-content' not found");let t=r==null?void 0:r.querySelector(i);if(!t)throw new Error("Prompt element ".concat(i," not found"));let a=(r==null?void 0:r.querySelector(u))||null,l=(e==null?void 0:e.querySelector(x))||null;return{root:e,touchLayer:a,content:t,toggle:l}}function g({checkbox:o,state:e,elements:r,options:t,onDidShow:a}){switch(o.dataset[k]="true",e){case"showing":delete o.dataset.ishiding,t.willShow&&t.willShow(r);break;case"endShowing":a&&a(r),t.didShow&&t.didShow(r);break;case"hiding":o.checked=!1,o.dataset.ishiding="true",t.willHide&&t.willHide(r);break;case"endHiding":delete o.dataset.ishiding,t.didHide&&t.didHide(r);break;default:break}}function f(o){var t;if(!o.target)return;let e=o.target;if(e&&e instanceof HTMLElement&&!p(e))return;let r=e.closest(c);r&&r instanceof HTMLElement&&h(r)||(t=b(e))==null||t.click()}function L(o){if(o.key==="Escape"){let r=Array.from(document.querySelectorAll("".concat(c," > ").concat(d,":checked"))).reverse()[0];if(r instanceof HTMLElement){let t=r.closest(c);$(t)&&r.click()}}}function A({root:o}){let e=o.querySelector(i);e&&F(o,e)}function F(o,e){let r=o.dataset[z];if(r){let t=e.querySelector(r);t&&t.focus()}}function n(o,e,r){let t=b(o);if(t){if(t.checked&&e==="show"||!t.checked&&e==="hide")return;r&&(t.options=r),t.click()}}var s={isInited:!1,init:function(){s.isInited||(window.addEventListener("keydown",L),s.isInited=!0)},mounted:function(){this.init()},updated:function(){this.init()},change:function(o,e={}){var a,l;let r=b(o);if(!r||!(r instanceof HTMLInputElement))return;let t=C(r);r.checked?(a=t.touchLayer)==null||a.addEventListener("click",f):(l=t.touchLayer)==null||l.removeEventListener("click",f),r.addEventListener("transitionend",function(j){g({checkbox:r,state:r.checked?"endShowing":"endHiding",elements:t,options:e,onDidShow:A})},{once:!0}),g({checkbox:r,state:r.checked?"showing":"hiding",elements:t,options:e})},hide:function(o){if(typeof o!="string"){let e=o,r=e.closest(c);if(p(e)&&h(r))return}n(o,"hide")},show:function(o){n(o,"show")},toggle:function(o){n(o,"toggle")}};typeof window<"u"&&(window.Prompt=s);})();