phoenix_live_view 0.17.13 → 0.17.14

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.
@@ -3419,7 +3419,7 @@ within:
3419
3419
  let view = this.newRootView(rootEl);
3420
3420
  view.setHref(this.getHref());
3421
3421
  view.join();
3422
- if (rootEl.getAttribute(PHX_MAIN)) {
3422
+ if (rootEl.hasAttribute(PHX_MAIN)) {
3423
3423
  this.main = view;
3424
3424
  }
3425
3425
  }
@@ -14,4 +14,4 @@ within:
14
14
  import {Socket} from "phoenix"
15
15
  import {LiveSocket} from "phoenix_live_view"
16
16
  let liveSocket = new LiveSocket("/live", Socket, {...})
17
- `);this.socket=new t(e,i),this.bindingPrefix=i.bindingPrefix||Lt,this.opts=i,this.params=Xe(i.params||{}),this.viewLogger=i.viewLogger,this.metadataCallbacks=i.metadata||{},this.defaults=Object.assign(he(Ot),i.defaults||{}),this.activeElement=null,this.prevActive=null,this.silenced=!1,this.main=null,this.outgoingMainEl=null,this.clickStartedAtTarget=null,this.linkRef=1,this.roots={},this.href=window.location.href,this.pendingLink=null,this.currentLocation=he(window.location),this.hooks=i.hooks||{},this.uploaders=i.uploaders||{},this.loaderTimeout=i.loaderTimeout||It,this.reloadWithJitterTimer=null,this.maxReloads=i.maxReloads||vt,this.reloadJitterMin=i.reloadJitterMin||bt,this.reloadJitterMax=i.reloadJitterMax||_t,this.failsafeJitter=i.failsafeJitter||Et,this.localStorage=i.localStorage||window.localStorage,this.sessionStorage=i.sessionStorage||window.sessionStorage,this.boundTopLevelEvents=!1,this.domCallbacks=Object.assign({onNodeAdded:Xe(),onBeforeElUpdated:Xe()},i.dom||{}),this.transitions=new Wt,window.addEventListener("pagehide",r=>{this.unloaded=!0}),this.socket.onOpen(()=>{this.isUnloaded()&&window.location.reload()})}isProfileEnabled(){return this.sessionStorage.getItem(Ue)==="true"}isDebugEnabled(){return this.sessionStorage.getItem(Se)==="true"}isDebugDisabled(){return this.sessionStorage.getItem(Se)==="false"}enableDebug(){this.sessionStorage.setItem(Se,"true")}enableProfiling(){this.sessionStorage.setItem(Ue,"true")}disableDebug(){this.sessionStorage.setItem(Se,"false")}disableProfiling(){this.sessionStorage.removeItem(Ue)}enableLatencySim(e){this.enableDebug(),console.log("latency simulator enabled for the duration of this browser session. Call disableLatencySim() to disable"),this.sessionStorage.setItem(Me,e)}disableLatencySim(){this.sessionStorage.removeItem(Me)}getLatencySim(){let e=this.sessionStorage.getItem(Me);return e?parseInt(e):null}getSocket(){return this.socket}connect(){window.location.hostname==="localhost"&&!this.isDebugDisabled()&&this.enableDebug();let e=()=>{this.joinRootViews()?(this.bindTopLevelEvents(),this.socket.connect()):this.main&&this.socket.connect()};["complete","loaded","interactive"].indexOf(document.readyState)>=0?e():document.addEventListener("DOMContentLoaded",()=>e())}disconnect(e){clearTimeout(this.reloadWithJitterTimer),this.socket.disconnect(e)}replaceTransport(e){clearTimeout(this.reloadWithJitterTimer),this.socket.replaceTransport(e),this.connect()}execJS(e,t,i=null){this.owner(e,r=>O.exec(i,t,r,e))}triggerDOM(e,t){this.domCallbacks[e](...t)}time(e,t){if(!this.isProfileEnabled()||!console.time)return t();console.time(e);let i=t();return console.timeEnd(e),i}log(e,t,i){if(this.viewLogger){let[r,n]=i();this.viewLogger(e,t,r,n)}else if(this.isDebugEnabled()){let[r,n]=i();Ut(e,t,r,n)}}requestDOMUpdate(e){this.transitions.after(e)}transition(e,t,i=function(){}){this.transitions.addTransition(e,t,i)}onChannel(e,t,i){e.on(t,r=>{let n=this.getLatencySim();n?(console.log(`simulating ${n}ms of latency from server to client`),setTimeout(()=>i(r),n)):i(r)})}wrapPush(e,t,i){let r=this.getLatencySim(),n=e.joinCount;if(!r)return this.isConnected()&&t.timeout?i().receive("timeout",()=>{e.joinCount===n&&!e.isDestroyed()&&this.reloadWithJitter(e,()=>{this.log(e,"timeout",()=>["received timeout while communicating with server. Falling back to hard refresh for recovery"])})}):i();console.log(`simulating ${r}ms of latency from client to server`);let o={receives:[],receive(a,l){this.receives.push([a,l])}};return setTimeout(()=>{e.isDestroyed()||o.receives.reduce((a,[l,d])=>a.receive(l,d),i())},r),o}reloadWithJitter(e,t){clearTimeout(this.reloadWithJitterTimer),this.disconnect();let i=this.reloadJitterMin,r=this.reloadJitterMax,n=Math.floor(Math.random()*(r-i+1))+i,o=V.updateLocal(this.localStorage,window.location.pathname,ke,0,a=>a+1);o>this.maxReloads&&(n=this.failsafeJitter),this.reloadWithJitterTimer=setTimeout(()=>{e.isDestroyed()||e.isConnected()||(e.destroy(),t?t():this.log(e,"join",()=>[`encountered ${o} consecutive reloads`]),o>this.maxReloads&&this.log(e,"join",()=>[`exceeded ${this.maxReloads} consecutive reloads. Entering failsafe mode`]),this.hasPendingLink()?window.location=this.pendingLink:window.location.reload())},n)}getHookCallbacks(e){return e&&e.startsWith("Phoenix.")?$t[e.split(".")[1]]:this.hooks[e]}isUnloaded(){return this.unloaded}isConnected(){return this.socket.isConnected()}getBindingPrefix(){return this.bindingPrefix}binding(e){return`${this.getBindingPrefix()}${e}`}channel(e,t){return this.socket.channel(e,t)}joinRootViews(){let e=!1;return h.all(document,`${B}:not([${W}])`,t=>{if(!this.getRootById(t.id)){let i=this.newRootView(t);i.setHref(this.getHref()),i.join(),t.getAttribute(oe)&&(this.main=i)}e=!0}),e}redirect(e,t){this.disconnect(),V.redirect(e,t)}replaceMain(e,t,i=null,r=this.setPendingLink(e)){this.outgoingMainEl=this.outgoingMainEl||this.main.el;let n=h.cloneNode(this.outgoingMainEl,"");this.main.showLoader(this.loaderTimeout),this.main.destroy(),this.main=this.newRootView(n,t),this.main.setRedirect(e),this.transitionRemoves(),this.main.join((o,a)=>{o===1&&this.commitPendingLink(r)&&this.requestDOMUpdate(()=>{h.findPhxSticky(document).forEach(l=>n.appendChild(l)),this.outgoingMainEl.replaceWith(n),this.outgoingMainEl=null,i&&requestAnimationFrame(i),a()})})}transitionRemoves(e){let t=this.binding("remove");e=e||h.all(document,`[${t}]`),e.forEach(i=>{document.body.contains(i)&&this.execJS(i,i.getAttribute(t),"remove")})}isPhxView(e){return e.getAttribute&&e.getAttribute(L)!==null}newRootView(e,t){let i=new ce(e,this,null,t);return this.roots[i.id]=i,i}owner(e,t){let i=D(e.closest(B),r=>this.getViewByEl(r))||this.main;i&&t(i)}withinOwners(e,t){this.owner(e,i=>t(i,e))}getViewByEl(e){let t=e.getAttribute(K);return D(this.getRootById(t),i=>i.getDescendentByEl(e))}getRootById(e){return this.roots[e]}destroyAllViews(){for(let e in this.roots)this.roots[e].destroy(),delete this.roots[e];this.main=null}destroyViewByEl(e){let t=this.getRootById(e.getAttribute(K));t&&t.id===e.id?(t.destroy(),delete this.roots[t.id]):t&&t.destroyDescendent(e.id)}setActiveElement(e){if(this.activeElement===e)return;this.activeElement=e;let t=()=>{e===this.activeElement&&(this.activeElement=null),e.removeEventListener("mouseup",this),e.removeEventListener("touchend",this)};e.addEventListener("mouseup",t),e.addEventListener("touchend",t)}getActiveElement(){return document.activeElement===document.body?this.activeElement||document.activeElement:document.activeElement||document.body}dropActiveElement(e){this.prevActive&&e.ownsElement(this.prevActive)&&(this.prevActive=null)}restorePreviouslyActiveFocus(){this.prevActive&&this.prevActive!==document.body&&this.prevActive.focus()}blurActiveElement(){this.prevActive=this.getActiveElement(),this.prevActive!==document.body&&this.prevActive.blur()}bindTopLevelEvents(){this.boundTopLevelEvents||(this.boundTopLevelEvents=!0,this.socket.onClose(e=>{e&&e.code===1e3&&this.main&&this.reloadWithJitter(this.main)}),document.body.addEventListener("click",function(){}),window.addEventListener("pageshow",e=>{e.persisted&&(this.getSocket().disconnect(),this.withPageLoading({to:window.location.href,kind:"redirect"}),window.location.reload())},!0),this.bindNav(),this.bindClicks(),this.bindForms(),this.bind({keyup:"keyup",keydown:"keydown"},(e,t,i,r,n,o)=>{let a=r.getAttribute(this.binding(kt)),l=e.key&&e.key.toLowerCase();if(a&&a.toLowerCase()!==l)return;let d=se({key:e.key},this.eventMeta(t,e,r));O.exec(t,n,i,r,["push",{data:d}])}),this.bind({blur:"focusout",focus:"focusin"},(e,t,i,r,n,o)=>{if(!o){let a=se({key:e.key},this.eventMeta(t,e,r));O.exec(t,n,i,r,["push",{data:a}])}}),this.bind({blur:"blur",focus:"focus"},(e,t,i,r,n,o,a)=>{if(a==="window"){let l=this.eventMeta(t,e,r);O.exec(t,o,i,r,["push",{data:l}])}}),window.addEventListener("dragover",e=>e.preventDefault()),window.addEventListener("drop",e=>{e.preventDefault();let t=D(ee(e.target,this.binding(ze)),n=>n.getAttribute(this.binding(ze))),i=t&&document.getElementById(t),r=Array.from(e.dataTransfer.files||[]);!i||i.disabled||r.length===0||!(i.files instanceof FileList)||(y.trackFiles(i,r),i.dispatchEvent(new Event("input",{bubbles:!0})))}),this.on(Re,e=>{let t=e.target;if(!h.isUploadInput(t))return;let i=Array.from(e.detail.files||[]).filter(r=>r instanceof File||r instanceof Blob);y.trackFiles(t,i),t.dispatchEvent(new Event("input",{bubbles:!0}))}))}eventMeta(e,t,i){let r=this.metadataCallbacks[e];return r?r(t,i):{}}setPendingLink(e){return this.linkRef++,this.pendingLink=e,this.linkRef}commitPendingLink(e){return this.linkRef!==e?!1:(this.href=this.pendingLink,this.pendingLink=null,!0)}getHref(){return this.href}hasPendingLink(){return!!this.pendingLink}bind(e,t){for(let i in e){let r=e[i];this.on(r,n=>{let o=this.binding(i),a=this.binding(`window-${i}`),l=n.target.getAttribute&&n.target.getAttribute(o);l?this.debounce(n.target,n,r,()=>{this.withinOwners(n.target,d=>{t(n,i,d,n.target,l,null)})}):h.all(document,`[${a}]`,d=>{let f=d.getAttribute(a);this.debounce(d,n,r,()=>{this.withinOwners(d,p=>{t(n,i,p,d,f,"window")})})})})}}bindClicks(){window.addEventListener("mousedown",e=>this.clickStartedAtTarget=e.target),this.bindClick("click","click",!1),this.bindClick("mousedown","capture-click",!0)}bindClick(e,t,i){let r=this.binding(t);window.addEventListener(e,n=>{let o=null;if(i)o=n.target.matches(`[${r}]`)?n.target:n.target.querySelector(`[${r}]`);else{let l=this.clickStartedAtTarget||n.target;o=ee(l,r),this.dispatchClickAway(n,l),this.clickStartedAtTarget=null}let a=o&&o.getAttribute(r);!a||(o.getAttribute("href")==="#"&&n.preventDefault(),this.debounce(o,n,"click",()=>{this.withinOwners(o,l=>{O.exec("click",a,l,o,["push",{data:this.eventMeta("click",n,o)}])})}))},i)}dispatchClickAway(e,t){let i=this.binding("click-away");h.all(document,`[${i}]`,r=>{r.isSameNode(t)||r.contains(t)||this.withinOwners(e.target,n=>{let o=r.getAttribute(i);O.isVisible(r)&&O.exec("click",o,n,r,["push",{data:this.eventMeta("click",e,e.target)}])})})}bindNav(){if(!V.canPushState())return;history.scrollRestoration&&(history.scrollRestoration="manual");let e=null;window.addEventListener("scroll",t=>{clearTimeout(e),e=setTimeout(()=>{V.updateCurrentState(i=>Object.assign(i,{scroll:window.scrollY}))},100)}),window.addEventListener("popstate",t=>{if(!this.registerNewLocation(window.location))return;let{type:i,id:r,root:n,scroll:o}=t.state||{},a=window.location.href;this.requestDOMUpdate(()=>{this.main.isConnected()&&i==="patch"&&r===this.main.id?this.main.pushLinkPatch(a,null):this.replaceMain(a,null,()=>{n&&this.replaceRootHistory(),typeof o=="number"&&setTimeout(()=>{window.scrollTo(0,o)},0)})})},!1),window.addEventListener("click",t=>{let i=ee(t.target,Ie),r=i&&i.getAttribute(Ie),n=t.metaKey||t.ctrlKey||t.button===1;if(!r||!this.isConnected()||!this.main||n)return;let o=i.href,a=i.getAttribute(At);t.preventDefault(),t.stopImmediatePropagation(),this.pendingLink!==o&&this.requestDOMUpdate(()=>{if(r==="patch")this.pushHistoryPatch(o,a,i);else if(r==="redirect")this.historyRedirect(o,a);else throw new Error(`expected ${Ie} to be "patch" or "redirect", got: ${r}`)})},!1)}dispatchEvent(e,t={}){h.dispatchEvent(window,`phx:${e}`,{detail:t})}dispatchEvents(e){e.forEach(([t,i])=>this.dispatchEvent(t,i))}withPageLoading(e,t){h.dispatchEvent(window,"phx:page-loading-start",{detail:e});let i=()=>h.dispatchEvent(window,"phx:page-loading-stop",{detail:e});return t?t(i):i}pushHistoryPatch(e,t,i){this.withPageLoading({to:e,kind:"patch"},r=>{this.main.pushLinkPatch(e,i,n=>{this.historyPatch(e,t,n),r()})})}historyPatch(e,t,i=this.setPendingLink(e)){!this.commitPendingLink(i)||(V.pushState(t,{type:"patch",id:this.main.id},e),this.registerNewLocation(window.location))}historyRedirect(e,t,i){let r=window.scrollY;this.withPageLoading({to:e,kind:"redirect"},n=>{this.replaceMain(e,i,()=>{V.pushState(t,{type:"redirect",id:this.main.id,scroll:r},e),this.registerNewLocation(window.location),n()})})}replaceRootHistory(){V.pushState("replace",{root:!0,type:"patch",id:this.main.id})}registerNewLocation(e){let{pathname:t,search:i}=this.currentLocation;return t+i===e.pathname+e.search?!1:(this.currentLocation=he(e),!0)}bindForms(){let e=0;this.on("submit",t=>{let i=t.target.getAttribute(this.binding("submit"));!i||(t.preventDefault(),t.target.disabled=!0,this.withinOwners(t.target,r=>{O.exec("submit",i,r,t.target,["push",{}])}))},!1);for(let t of["change","input"])this.on(t,i=>{let r=this.binding("change"),n=i.target,o=n.getAttribute(r),a=n.form&&n.form.getAttribute(r),l=o||a;if(!l||n.type==="number"&&n.validity&&n.validity.badInput)return;let d=o?n:n.form,f=e;e++;let{at:p,type:c}=h.private(n,"prev-iteration")||{};p===f-1&&t!==c||(h.putPrivate(n,"prev-iteration",{at:f,type:t}),this.debounce(n,i,t,()=>{this.withinOwners(d,g=>{h.putPrivate(n,De,!0),h.isTextualInput(n)||this.setActiveElement(n),O.exec("change",l,g,n,["push",{_target:i.target.name,dispatcher:d}])})}))},!1)}debounce(e,t,i,r){if(i==="blur"||i==="focusout")return r();let n=this.binding(Ct),o=this.binding(Tt),a=this.defaults.debounce.toString(),l=this.defaults.throttle.toString();this.withinOwners(e,d=>{let f=()=>!d.isDestroyed()&&document.body.contains(e);h.debounce(e,t,n,a,o,l,f,()=>{r()})})}silenceEvents(e){this.silenced=!0,e(),this.silenced=!1}on(e,t){window.addEventListener(e,i=>{this.silenced||t(i)})}},Wt=class{constructor(){this.transitions=new Set,this.pendingOps=[],this.reset()}reset(){this.transitions.forEach(e=>{cancelTimeout(e),this.transitions.delete(e)}),this.flushPendingOps()}after(e){this.size()===0?e():this.pushPendingOp(e)}addTransition(e,t,i){t();let r=setTimeout(()=>{this.transitions.delete(r),i(),this.size()===0&&this.flushPendingOps()},e);this.transitions.add(r)}pushPendingOp(e){this.pendingOps.push(e)}size(){return this.transitions.size}flushPendingOps(){this.pendingOps.forEach(e=>e()),this.pendingOps=[]}};return vi;})();
17
+ `);this.socket=new t(e,i),this.bindingPrefix=i.bindingPrefix||Lt,this.opts=i,this.params=Xe(i.params||{}),this.viewLogger=i.viewLogger,this.metadataCallbacks=i.metadata||{},this.defaults=Object.assign(he(Ot),i.defaults||{}),this.activeElement=null,this.prevActive=null,this.silenced=!1,this.main=null,this.outgoingMainEl=null,this.clickStartedAtTarget=null,this.linkRef=1,this.roots={},this.href=window.location.href,this.pendingLink=null,this.currentLocation=he(window.location),this.hooks=i.hooks||{},this.uploaders=i.uploaders||{},this.loaderTimeout=i.loaderTimeout||It,this.reloadWithJitterTimer=null,this.maxReloads=i.maxReloads||vt,this.reloadJitterMin=i.reloadJitterMin||bt,this.reloadJitterMax=i.reloadJitterMax||_t,this.failsafeJitter=i.failsafeJitter||Et,this.localStorage=i.localStorage||window.localStorage,this.sessionStorage=i.sessionStorage||window.sessionStorage,this.boundTopLevelEvents=!1,this.domCallbacks=Object.assign({onNodeAdded:Xe(),onBeforeElUpdated:Xe()},i.dom||{}),this.transitions=new Wt,window.addEventListener("pagehide",r=>{this.unloaded=!0}),this.socket.onOpen(()=>{this.isUnloaded()&&window.location.reload()})}isProfileEnabled(){return this.sessionStorage.getItem(Ue)==="true"}isDebugEnabled(){return this.sessionStorage.getItem(Se)==="true"}isDebugDisabled(){return this.sessionStorage.getItem(Se)==="false"}enableDebug(){this.sessionStorage.setItem(Se,"true")}enableProfiling(){this.sessionStorage.setItem(Ue,"true")}disableDebug(){this.sessionStorage.setItem(Se,"false")}disableProfiling(){this.sessionStorage.removeItem(Ue)}enableLatencySim(e){this.enableDebug(),console.log("latency simulator enabled for the duration of this browser session. Call disableLatencySim() to disable"),this.sessionStorage.setItem(Me,e)}disableLatencySim(){this.sessionStorage.removeItem(Me)}getLatencySim(){let e=this.sessionStorage.getItem(Me);return e?parseInt(e):null}getSocket(){return this.socket}connect(){window.location.hostname==="localhost"&&!this.isDebugDisabled()&&this.enableDebug();let e=()=>{this.joinRootViews()?(this.bindTopLevelEvents(),this.socket.connect()):this.main&&this.socket.connect()};["complete","loaded","interactive"].indexOf(document.readyState)>=0?e():document.addEventListener("DOMContentLoaded",()=>e())}disconnect(e){clearTimeout(this.reloadWithJitterTimer),this.socket.disconnect(e)}replaceTransport(e){clearTimeout(this.reloadWithJitterTimer),this.socket.replaceTransport(e),this.connect()}execJS(e,t,i=null){this.owner(e,r=>O.exec(i,t,r,e))}triggerDOM(e,t){this.domCallbacks[e](...t)}time(e,t){if(!this.isProfileEnabled()||!console.time)return t();console.time(e);let i=t();return console.timeEnd(e),i}log(e,t,i){if(this.viewLogger){let[r,n]=i();this.viewLogger(e,t,r,n)}else if(this.isDebugEnabled()){let[r,n]=i();Ut(e,t,r,n)}}requestDOMUpdate(e){this.transitions.after(e)}transition(e,t,i=function(){}){this.transitions.addTransition(e,t,i)}onChannel(e,t,i){e.on(t,r=>{let n=this.getLatencySim();n?(console.log(`simulating ${n}ms of latency from server to client`),setTimeout(()=>i(r),n)):i(r)})}wrapPush(e,t,i){let r=this.getLatencySim(),n=e.joinCount;if(!r)return this.isConnected()&&t.timeout?i().receive("timeout",()=>{e.joinCount===n&&!e.isDestroyed()&&this.reloadWithJitter(e,()=>{this.log(e,"timeout",()=>["received timeout while communicating with server. Falling back to hard refresh for recovery"])})}):i();console.log(`simulating ${r}ms of latency from client to server`);let o={receives:[],receive(a,l){this.receives.push([a,l])}};return setTimeout(()=>{e.isDestroyed()||o.receives.reduce((a,[l,d])=>a.receive(l,d),i())},r),o}reloadWithJitter(e,t){clearTimeout(this.reloadWithJitterTimer),this.disconnect();let i=this.reloadJitterMin,r=this.reloadJitterMax,n=Math.floor(Math.random()*(r-i+1))+i,o=V.updateLocal(this.localStorage,window.location.pathname,ke,0,a=>a+1);o>this.maxReloads&&(n=this.failsafeJitter),this.reloadWithJitterTimer=setTimeout(()=>{e.isDestroyed()||e.isConnected()||(e.destroy(),t?t():this.log(e,"join",()=>[`encountered ${o} consecutive reloads`]),o>this.maxReloads&&this.log(e,"join",()=>[`exceeded ${this.maxReloads} consecutive reloads. Entering failsafe mode`]),this.hasPendingLink()?window.location=this.pendingLink:window.location.reload())},n)}getHookCallbacks(e){return e&&e.startsWith("Phoenix.")?$t[e.split(".")[1]]:this.hooks[e]}isUnloaded(){return this.unloaded}isConnected(){return this.socket.isConnected()}getBindingPrefix(){return this.bindingPrefix}binding(e){return`${this.getBindingPrefix()}${e}`}channel(e,t){return this.socket.channel(e,t)}joinRootViews(){let e=!1;return h.all(document,`${B}:not([${W}])`,t=>{if(!this.getRootById(t.id)){let i=this.newRootView(t);i.setHref(this.getHref()),i.join(),t.hasAttribute(oe)&&(this.main=i)}e=!0}),e}redirect(e,t){this.disconnect(),V.redirect(e,t)}replaceMain(e,t,i=null,r=this.setPendingLink(e)){this.outgoingMainEl=this.outgoingMainEl||this.main.el;let n=h.cloneNode(this.outgoingMainEl,"");this.main.showLoader(this.loaderTimeout),this.main.destroy(),this.main=this.newRootView(n,t),this.main.setRedirect(e),this.transitionRemoves(),this.main.join((o,a)=>{o===1&&this.commitPendingLink(r)&&this.requestDOMUpdate(()=>{h.findPhxSticky(document).forEach(l=>n.appendChild(l)),this.outgoingMainEl.replaceWith(n),this.outgoingMainEl=null,i&&requestAnimationFrame(i),a()})})}transitionRemoves(e){let t=this.binding("remove");e=e||h.all(document,`[${t}]`),e.forEach(i=>{document.body.contains(i)&&this.execJS(i,i.getAttribute(t),"remove")})}isPhxView(e){return e.getAttribute&&e.getAttribute(L)!==null}newRootView(e,t){let i=new ce(e,this,null,t);return this.roots[i.id]=i,i}owner(e,t){let i=D(e.closest(B),r=>this.getViewByEl(r))||this.main;i&&t(i)}withinOwners(e,t){this.owner(e,i=>t(i,e))}getViewByEl(e){let t=e.getAttribute(K);return D(this.getRootById(t),i=>i.getDescendentByEl(e))}getRootById(e){return this.roots[e]}destroyAllViews(){for(let e in this.roots)this.roots[e].destroy(),delete this.roots[e];this.main=null}destroyViewByEl(e){let t=this.getRootById(e.getAttribute(K));t&&t.id===e.id?(t.destroy(),delete this.roots[t.id]):t&&t.destroyDescendent(e.id)}setActiveElement(e){if(this.activeElement===e)return;this.activeElement=e;let t=()=>{e===this.activeElement&&(this.activeElement=null),e.removeEventListener("mouseup",this),e.removeEventListener("touchend",this)};e.addEventListener("mouseup",t),e.addEventListener("touchend",t)}getActiveElement(){return document.activeElement===document.body?this.activeElement||document.activeElement:document.activeElement||document.body}dropActiveElement(e){this.prevActive&&e.ownsElement(this.prevActive)&&(this.prevActive=null)}restorePreviouslyActiveFocus(){this.prevActive&&this.prevActive!==document.body&&this.prevActive.focus()}blurActiveElement(){this.prevActive=this.getActiveElement(),this.prevActive!==document.body&&this.prevActive.blur()}bindTopLevelEvents(){this.boundTopLevelEvents||(this.boundTopLevelEvents=!0,this.socket.onClose(e=>{e&&e.code===1e3&&this.main&&this.reloadWithJitter(this.main)}),document.body.addEventListener("click",function(){}),window.addEventListener("pageshow",e=>{e.persisted&&(this.getSocket().disconnect(),this.withPageLoading({to:window.location.href,kind:"redirect"}),window.location.reload())},!0),this.bindNav(),this.bindClicks(),this.bindForms(),this.bind({keyup:"keyup",keydown:"keydown"},(e,t,i,r,n,o)=>{let a=r.getAttribute(this.binding(kt)),l=e.key&&e.key.toLowerCase();if(a&&a.toLowerCase()!==l)return;let d=se({key:e.key},this.eventMeta(t,e,r));O.exec(t,n,i,r,["push",{data:d}])}),this.bind({blur:"focusout",focus:"focusin"},(e,t,i,r,n,o)=>{if(!o){let a=se({key:e.key},this.eventMeta(t,e,r));O.exec(t,n,i,r,["push",{data:a}])}}),this.bind({blur:"blur",focus:"focus"},(e,t,i,r,n,o,a)=>{if(a==="window"){let l=this.eventMeta(t,e,r);O.exec(t,o,i,r,["push",{data:l}])}}),window.addEventListener("dragover",e=>e.preventDefault()),window.addEventListener("drop",e=>{e.preventDefault();let t=D(ee(e.target,this.binding(ze)),n=>n.getAttribute(this.binding(ze))),i=t&&document.getElementById(t),r=Array.from(e.dataTransfer.files||[]);!i||i.disabled||r.length===0||!(i.files instanceof FileList)||(y.trackFiles(i,r),i.dispatchEvent(new Event("input",{bubbles:!0})))}),this.on(Re,e=>{let t=e.target;if(!h.isUploadInput(t))return;let i=Array.from(e.detail.files||[]).filter(r=>r instanceof File||r instanceof Blob);y.trackFiles(t,i),t.dispatchEvent(new Event("input",{bubbles:!0}))}))}eventMeta(e,t,i){let r=this.metadataCallbacks[e];return r?r(t,i):{}}setPendingLink(e){return this.linkRef++,this.pendingLink=e,this.linkRef}commitPendingLink(e){return this.linkRef!==e?!1:(this.href=this.pendingLink,this.pendingLink=null,!0)}getHref(){return this.href}hasPendingLink(){return!!this.pendingLink}bind(e,t){for(let i in e){let r=e[i];this.on(r,n=>{let o=this.binding(i),a=this.binding(`window-${i}`),l=n.target.getAttribute&&n.target.getAttribute(o);l?this.debounce(n.target,n,r,()=>{this.withinOwners(n.target,d=>{t(n,i,d,n.target,l,null)})}):h.all(document,`[${a}]`,d=>{let f=d.getAttribute(a);this.debounce(d,n,r,()=>{this.withinOwners(d,p=>{t(n,i,p,d,f,"window")})})})})}}bindClicks(){window.addEventListener("mousedown",e=>this.clickStartedAtTarget=e.target),this.bindClick("click","click",!1),this.bindClick("mousedown","capture-click",!0)}bindClick(e,t,i){let r=this.binding(t);window.addEventListener(e,n=>{let o=null;if(i)o=n.target.matches(`[${r}]`)?n.target:n.target.querySelector(`[${r}]`);else{let l=this.clickStartedAtTarget||n.target;o=ee(l,r),this.dispatchClickAway(n,l),this.clickStartedAtTarget=null}let a=o&&o.getAttribute(r);!a||(o.getAttribute("href")==="#"&&n.preventDefault(),this.debounce(o,n,"click",()=>{this.withinOwners(o,l=>{O.exec("click",a,l,o,["push",{data:this.eventMeta("click",n,o)}])})}))},i)}dispatchClickAway(e,t){let i=this.binding("click-away");h.all(document,`[${i}]`,r=>{r.isSameNode(t)||r.contains(t)||this.withinOwners(e.target,n=>{let o=r.getAttribute(i);O.isVisible(r)&&O.exec("click",o,n,r,["push",{data:this.eventMeta("click",e,e.target)}])})})}bindNav(){if(!V.canPushState())return;history.scrollRestoration&&(history.scrollRestoration="manual");let e=null;window.addEventListener("scroll",t=>{clearTimeout(e),e=setTimeout(()=>{V.updateCurrentState(i=>Object.assign(i,{scroll:window.scrollY}))},100)}),window.addEventListener("popstate",t=>{if(!this.registerNewLocation(window.location))return;let{type:i,id:r,root:n,scroll:o}=t.state||{},a=window.location.href;this.requestDOMUpdate(()=>{this.main.isConnected()&&i==="patch"&&r===this.main.id?this.main.pushLinkPatch(a,null):this.replaceMain(a,null,()=>{n&&this.replaceRootHistory(),typeof o=="number"&&setTimeout(()=>{window.scrollTo(0,o)},0)})})},!1),window.addEventListener("click",t=>{let i=ee(t.target,Ie),r=i&&i.getAttribute(Ie),n=t.metaKey||t.ctrlKey||t.button===1;if(!r||!this.isConnected()||!this.main||n)return;let o=i.href,a=i.getAttribute(At);t.preventDefault(),t.stopImmediatePropagation(),this.pendingLink!==o&&this.requestDOMUpdate(()=>{if(r==="patch")this.pushHistoryPatch(o,a,i);else if(r==="redirect")this.historyRedirect(o,a);else throw new Error(`expected ${Ie} to be "patch" or "redirect", got: ${r}`)})},!1)}dispatchEvent(e,t={}){h.dispatchEvent(window,`phx:${e}`,{detail:t})}dispatchEvents(e){e.forEach(([t,i])=>this.dispatchEvent(t,i))}withPageLoading(e,t){h.dispatchEvent(window,"phx:page-loading-start",{detail:e});let i=()=>h.dispatchEvent(window,"phx:page-loading-stop",{detail:e});return t?t(i):i}pushHistoryPatch(e,t,i){this.withPageLoading({to:e,kind:"patch"},r=>{this.main.pushLinkPatch(e,i,n=>{this.historyPatch(e,t,n),r()})})}historyPatch(e,t,i=this.setPendingLink(e)){!this.commitPendingLink(i)||(V.pushState(t,{type:"patch",id:this.main.id},e),this.registerNewLocation(window.location))}historyRedirect(e,t,i){let r=window.scrollY;this.withPageLoading({to:e,kind:"redirect"},n=>{this.replaceMain(e,i,()=>{V.pushState(t,{type:"redirect",id:this.main.id,scroll:r},e),this.registerNewLocation(window.location),n()})})}replaceRootHistory(){V.pushState("replace",{root:!0,type:"patch",id:this.main.id})}registerNewLocation(e){let{pathname:t,search:i}=this.currentLocation;return t+i===e.pathname+e.search?!1:(this.currentLocation=he(e),!0)}bindForms(){let e=0;this.on("submit",t=>{let i=t.target.getAttribute(this.binding("submit"));!i||(t.preventDefault(),t.target.disabled=!0,this.withinOwners(t.target,r=>{O.exec("submit",i,r,t.target,["push",{}])}))},!1);for(let t of["change","input"])this.on(t,i=>{let r=this.binding("change"),n=i.target,o=n.getAttribute(r),a=n.form&&n.form.getAttribute(r),l=o||a;if(!l||n.type==="number"&&n.validity&&n.validity.badInput)return;let d=o?n:n.form,f=e;e++;let{at:p,type:c}=h.private(n,"prev-iteration")||{};p===f-1&&t!==c||(h.putPrivate(n,"prev-iteration",{at:f,type:t}),this.debounce(n,i,t,()=>{this.withinOwners(d,g=>{h.putPrivate(n,De,!0),h.isTextualInput(n)||this.setActiveElement(n),O.exec("change",l,g,n,["push",{_target:i.target.name,dispatcher:d}])})}))},!1)}debounce(e,t,i,r){if(i==="blur"||i==="focusout")return r();let n=this.binding(Ct),o=this.binding(Tt),a=this.defaults.debounce.toString(),l=this.defaults.throttle.toString();this.withinOwners(e,d=>{let f=()=>!d.isDestroyed()&&document.body.contains(e);h.debounce(e,t,n,a,o,l,f,()=>{r()})})}silenceEvents(e){this.silenced=!0,e(),this.silenced=!1}on(e,t){window.addEventListener(e,i=>{this.silenced||t(i)})}},Wt=class{constructor(){this.transitions=new Set,this.pendingOps=[],this.reset()}reset(){this.transitions.forEach(e=>{cancelTimeout(e),this.transitions.delete(e)}),this.flushPendingOps()}after(e){this.size()===0?e():this.pushPendingOp(e)}addTransition(e,t,i){t();let r=setTimeout(()=>{this.transitions.delete(r),i(),this.size()===0&&this.flushPendingOps()},e);this.transitions.add(r)}pushPendingOp(e){this.pendingOps.push(e)}size(){return this.transitions.size}flushPendingOps(){this.pendingOps.forEach(e=>e()),this.pendingOps=[]}};return vi;})();