Packages
primer_live
0.11.0
An implementation of GitHub's Primer Design System for Phoenix LiveView.
Current section
Files
Jump to
Current section
Files
priv/static/primer-live.min.js
"use strict";(()=>{var s={mounted(){let t=this.el;if(!(t.querySelector("[data-content]")instanceof HTMLElement)){console.error("Missing element with attribute [data-content]");return}let i=(o,e)=>{var r;(r=this.pushEventTo)==null||r.call(this,o,"primer_live:prompt",{elementId:t.id,selector:o,status:e})},a=(o,e)=>r=>{let{selector:l,transitionDuration:d}=r.detail;if(!l){console.error("Missing status_callback_selector");return}i(l,o),setTimeout(()=>{i(l,e)},d)};this.handlePromptToggle=o=>{var r;let e=t.classList.contains("is-open")?t.dataset.close:t.dataset.open;e?(r=this.liveSocket)==null||r.execJS(t,e):console.error("No command found in element dataset")},this.handlePromptOpen=a("opening","opened"),t.addEventListener("prompt:open",this.handlePromptOpen),this.handlePromptClose=a("closing","closed"),t.addEventListener("prompt:close",this.handlePromptClose),t.addEventListener("prompt:toggle",this.handlePromptToggle)},destroyed(){this.el&&(this.handlePromptOpen&&this.el.removeEventListener("prompt:open",this.handlePromptOpen),this.handlePromptClose&&this.el.removeEventListener("prompt:close",this.handlePromptClose),this.handlePromptToggle&&this.el.removeEventListener("prompt:toggle",this.handlePromptToggle))}};typeof window<"u"&&(window.Prompt=s);window.addEventListener("keydown",p);function p(t){if(t.key==="Escape"){let n=Array.from(document.querySelectorAll("[data-prompt].is-open")).filter(a=>a.dataset.isescapable!==void 0),i=n.reverse()[0];if(!(i instanceof HTMLElement))return;n.forEach(a=>{let o=a.querySelector("[data-focuswrap]");if(o instanceof HTMLElement){let e=a==i?"Escape":"Escape_disabled";o.setAttribute("phx-key",e)}})}}})();