You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2 lines
3.2 KiB

function isValidVersion(e,t){var r=e.split(".");var a=t.split(".");for(var i=0;i<r.length;i++)if(a[i]&&a[i]>r[i])return true;return a[r.length-1]===r[r.length-1]}function dispatch(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e.dispatchEvent(new CustomEvent(t,{detail:r,bubbles:true,composed:true,cancelable:true}))}class Bridge{init(){if(!window.Alpine.version||!isValidVersion("3.0.0",window.Alpine.version))throw new Error("Invalid Alpine version. Please use Alpine 3.0.0 or above");window.Alpine.mutateDom((()=>{document.body.querySelectorAll("[x-cloak]").forEach((e=>{var t;e.setAttribute("data-alpine-was-cloaked",null!==(t=e.getAttribute("x-cloak"))&&void 0!==t?t:"")}))}));this.configureEventHandlers()}configureEventHandlers(){var renderCallback=e=>{if(!document.documentElement.hasAttribute("data-turbo-preview")){dispatch(document,"alpine:init");dispatch(document,"alpine:initializing");window.Alpine.flushAndStopDeferringMutations();dispatch(document,"alpine:initialised");window.Alpine.mutateDom((()=>{document.querySelectorAll("[data-alpine-ignored]").forEach((e=>{e.removeAttribute("x-ignore");e.removeAttribute("data-alpine-ignored")}))}))}};var beforeRenderCallback=e=>{window.Alpine.mutateDom((()=>{document.documentElement.hasAttribute("data-turbo-preview")||e.detail.newBody.querySelectorAll("[data-alpine-generated-me],[x-cloak]").forEach((e=>{if(e.hasAttribute("x-cloak")){var t;e.setAttribute("data-alpine-was-cloaked",null!==(t=e.getAttribute("x-cloak"))&&void 0!==t?t:"")}if(e.hasAttribute("data-alpine-generated-me")){e.removeAttribute("data-alpine-generated-me");e.remove()}}))}));window.Alpine.deferMutations()};var beforeCacheCallback=e=>{window.Alpine.mutateDom((()=>{document.body.querySelectorAll("[x-for],[x-if],[x-teleport],[data-alpine-was-cloaked]").forEach((e=>{if(e.hasAttribute("data-alpine-was-cloaked")){var t;e.setAttribute("x-cloak",null!==(t=e.getAttribute("data-alpine-was-cloaked"))&&void 0!==t?t:"");e.removeAttribute("data-alpine-was-cloaked")}e.hasAttribute("x-for")&&e._x_lookup&&Object.values(e._x_lookup).forEach((e=>e.setAttribute("data-alpine-generated-me",true)));e.hasAttribute("x-if")&&e._x_currentIfEl&&e._x_currentIfEl.setAttribute("data-alpine-generated-me",true);e.hasAttribute("x-teleport")&&e._x_teleport&&e._x_teleport.setAttribute("data-alpine-generated-me",true)}))}));document.querySelectorAll("[data-turbo-permanent]").forEach((e=>{window.Alpine.mutateDom((()=>{if(!e.hasAttribute("x-ignore")){e.setAttribute("x-ignore",true);e.setAttribute("data-alpine-ignored",true)}e.querySelectorAll("[data-alpine-generated-me]").forEach((e=>{e.removeAttribute("data-alpine-generated-me")}))}))}))};document.addEventListener("turbo:render",renderCallback);document.addEventListener("turbo:before-render",beforeRenderCallback);document.addEventListener("turbo:before-cache",beforeCacheCallback)}}window.Alpine&&console.error("Alpine-turbo-drive-adapter must be included before AlpineJs");Object.getOwnPropertyDescriptor(NodeList.prototype,"forEach")||Object.defineProperty(NodeList.prototype,"forEach",Object.getOwnPropertyDescriptor(Array.prototype,"forEach"));document.addEventListener("alpine:init",(()=>{var e=new Bridge;e.init()}),{once:true});var e={};export{e as default};