1import{d as X,u as V,a as H,o as Y,_ as j,b as ee,c as T,e as q,n as te,F as ne,f,g as oe,h as L,i as D,w as U,T as z,t as ie,r as M,j as B,k as ae,l as se,m as re,q as de,p as pe,s as E,v as O,x as ue,y as J,z as W,A as le}from"./iaI7qNOJ.js";const ce={key:0},fe={key:0},we={id:"__preview_loader"},ve=X({__name:"ContentPreviewMode",props:{previewToken:{type:String,required:!0},apiURL:{type:String,required:!0},syncPreview:{type:Function,required:!0},requestPreviewSyncAPI:{type:Function,required:!0}},setup(i){const a=i,e=["__nuxt_preview","__preview_enabled"],l=V(),g=H(),c=M(!0),h=M(!1),t=M(!1),o=M("");let n;const s=async()=>{B("previewToken").value="",window.sessionStorage.removeItem("previewToken"),window.sessionStorage.removeItem("previewAPI"),await g.replace({query:{preview:void 0}}),window.location.reload()},m=async _=>{const p=await a.syncPreview(_);if(t.value!==!0){if(!p){setTimeout(()=>m(_),1e3);return}B("previewToken").value&&(t.value=!0,await g.replace({query:{}}),l.callHook("nuxt-studio:preview:ready"),window.parent&&window.self!==window.parent&&n.disconnect())}};return Y(async()=>{n=(await j(()=>import("./BxTbGR0_.js"),[],import.meta.url)).connect(`${a.apiURL}/preview`,{transports:["websocket","polling"],auth:{token:a.previewToken}});let p;n.on("connect",()=>{p=setTimeout(()=>{t.value||(p=setTimeout(()=>{o.value="Preview sync timed out",t.value=!1},3e4),n.emit("draft:requestSync"))},3e4)});const x=()=>{p&&(clearTimeout(p),p=null)};n.on("draft:sync",async S=>{if(x(),!S){try{n.once("draft:ready",()=>{n.emit("draft:requestSync")}),await a.requestPreviewSyncAPI()}catch(A){x(),A.response.status===404?(o.value="Preview draft not found",t.value=!1):(o.value="An error occurred while syncing preview",t.value=!1)}return}m(S)}),n.on("draft:unauthorized",()=>{x(),o.value="Unauthorized preview",t.value=!1}),n.on("disconnect",()=>{x()}),document.body.classList.add(...e),n.on("draft:update",S=>{h.value=!0,a.syncPreview(S),h.value=!1})}),ee(()=>{document.body.classList.remove(...e)}),(_,p)=>(T(),q("div",null,[c.value?(T(),q("div",{key:0,id:"__nuxt_preview",class:te({__preview_ready:t.value,__preview_refreshing:h.value})},[t.value?(T(),q(ne,{key:0},[p[0]||(p[0]=f("svg",{viewBox:"0 0 90 90",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[f("path",{d:"M50.0016 71.0999h29.2561c.9293.0001 1.8422-.241 2.6469-.6992.8047-.4582 1.4729-1.1173 1.9373-1.9109.4645-.7936.7088-1.6939.7083-2.6102-.0004-.9162-.2455-1.8163-.7106-2.6095L64.192 29.713c-.4644-.7934-1.1325-1.4523-1.937-1.9105-.8046-.4581-1.7173-.6993-2.6463-.6993-.9291 0-1.8418.2412-2.6463.6993-.8046.4582-1.4726 1.1171-1.937 1.9105l-5.0238 8.5861-9.8224-16.7898c-.4648-.7934-1.1332-1.4522-1.938-1.9102-.8047-.4581-1.7176-.6992-2.6468-.6992-.9292 0-1.842.2411-2.6468.6992-.8048.458-1.4731 1.1168-1.9379 1.9102L6.56062 63.2701c-.46512.7932-.71021 1.6933-.71061 2.6095-.00041.9163.24389 1.8166.70831 2.6102.46443.7936 1.1326 1.4527 1.93732 1.9109.80473.4582 1.71766.6993 2.64686.6992h18.3646c7.2763 0 12.6422-3.1516 16.3345-9.3002l8.9642-15.3081 4.8015-8.1925 14.4099 24.6083H54.8058l-4.8042 8.1925ZM29.2077 62.899l-12.8161-.0028L35.603 30.0869l9.5857 16.4047-6.418 10.9645c-2.4521 3.9894-5.2377 5.4429-9.563 5.4429Z",fill:"currentColor"})],-1)),p[1]||(p[1]=f("span",null,[f("a",{href:"https://nuxt.studio",target:"_blank",rel:"noopener"},"Nuxt Studio"),oe(": Preview enabled")],-1)),f("button",{onClick:s}," Close ")],64)):L("",!0)],2)):L("",!0),D(z,{name:"preview-loading"},{default:U(()=>[c.value&&!t.value&&!o.value?(T(),q("div",ce,[p[4]||(p[4]=f("div",{id:"__preview_background"},null,-1)),f("div",{id:"__preview_loader"},[p[2]||(p[2]=f("svg",{id:"__preview_loading_icon",width:"32",height:"32",viewBox:"0 0 24 24"},[f("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 0 0 4.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 0 1-15.357-2m15.357 2H15"})],-1)),p[3]||(p[3]=f("p",null,"Initializing the preview...",-1)),f("button",{onClick:s}," Cancel ")])])):L("",!0)]),_:1}),D(z,{name:"preview-loading"},{default:U(()=>[o.value?(T(),q("div",fe,[p[5]||(p[5]=f("div",{id:"__preview_background"},null,-1)),f("div",we,[f("p",null,ie(o.value),1),f("button",{onClick:s}," Exit preview ")])])):L("",!0)]),_:1})]))}}),me=ae(ve,[["__scopeId","data-v-19d7f7af"]]),ge=(i=[],a,e)=>{const l=[...a||[]],g=[...e||[]],c=JSON.parse(JSON.stringify(i));for(const t of l)if(t.new)c.push({path:t.path,parsed:t.parsed});else if(t.oldPath)if(g.splice(g.findIndex(n=>n.path===t.oldPath),1),l.find(n=>n.path===t.oldPath))c.push({path:t.path,parsed:t.parsed});else{const n=c.find(s=>s.path===t.oldPath);n&&(n.path=t.path,t.parsed?n.parsed=t.parsed:t.pathMeta&&["_file","_path","_id","_locale"].forEach(s=>
1{n.parsed[s]=t.pathMeta[s]}))}else{const o=c.find(n=>n.path===t.path);o?Object.assign(o,{path:t.path,parsed:t.parsed}):c.push({path:t.path,parsed:t.parsed})}for(const t of g)c.splice(c.findIndex(o=>o.path===t.path),1);const h=new Intl.Collator(void 0,{numeric:!0});return c.sort((t,o)=>h.compare(t.path,o.path)),c},y={appConfig:"app.config.ts",appConfigV4:"app/app.config.ts",nuxtConfig:"nuxt.config.ts"},ye=se((i,a,e)=>{if(Array.isArray(i[a])&&Array.isArray(e))return i[a]=e,!0}),he=i=>{let a;return e=>(a||(a=i()),a)};function Z(i,a){for(const e in i){const l=a[e];e in a||delete i[e],l!==null&&typeof l=="object"&&Z(i[e],a[e])}}function G(i,a){for(const e in a){const l=a[e];l!==null&&typeof l=="object"?Array.isArray(l)&&Array.isArray(i[e])?i[e]=l:(i[e]=i[e]||{},G(i[e],l)):i[e]=l}}const _e=()=>{const i=V(),a={},e=re("studio-client-db",()=>null);e.value||(i.hook("content:storage",o=>{e.value=o}),de("/non-existing-path").findOne());const l=async o=>{const n=window.sessionStorage.getItem("previewToken");if(!o)return null;o=o.replace(/\/$/,"");let s=await e.value?.getItem(`${n}:${o}`);return s||(s=await e.value?.getItem(`cached:${o}`)),s||(s=s=await e.value?.getItem(o)),s||(s=a[o||"/"]),s};return{storage:e,findContentItem:l,updateContentItem:(o,n)=>{e.value&&(a[n.parsed._path]=n.parsed,e.value.setItem(`${o}:${n.parsed?._id}`,JSON.stringify(n.parsed)))},removeContentItem:async(o,n)=>{const s=await l(n);if(await e.value?.removeItem(`${o}:${n}`),s){delete a[s._path];const m=await l(s._id);m&&(a[m._path]=m)}},removeAllContentItems:async o=>{const n=await e.value.getKeys(`${o}:`);await Promise.all(n.map(s=>e.value.removeItem(s)))},setPreviewMetaItems:async(o,n)=>{const s=new Set(n.map(m=>m.parsed._id.split(":").shift()));await e.value.setItem(`${o}$`,JSON.stringify({ignoreSources:Array.from(s)}))}}},Ce=he(()=>JSON.parse(JSON.stringify(W())));let F=[];const Ie=()=>{const i=V(),{storage:a,findContentItem:e,updateContentItem:l,removeContentItem:g,removeAllContentItems:c,setPreviewMetaItems:h}=_e(),{studio:t,content:o}=pe().public,n=window.sessionStorage.getItem("previewAPI")||t?.apiURL,s=Ce(),m=async d=>{const u=window.sessionStorage.getItem("previewToken");c(u),h(u,d),await Promise.all(d.map(w=>{l(u,w)}))},_=d=>{const u=J(i,W);u?.ui&&(u.ui.icons={...u.ui.icons,dynamic:!0}),G(u,ye(d,s)),d||Z(u,s)},p=async d=>{if(F=d.files=d.files||F||[],!a.value)return!1;F=[];const u=ge(d.files,d.additions,d.deletions),w=u.filter(C=>![y.appConfig,y.appConfigV4,y.nuxtConfig].includes(C.path));await m(w);const k=u.find(C=>[y.appConfig,y.appConfigV4].includes(C.path));return _(k?.parsed),A(),!0},x=async()=>{const d=window.sessionStorage.getItem("previewToken");await $fetch("api/projects/preview/sync",{baseURL:n,method:"POST",params:{token:d}})},S=()=>{const d=window.sessionStorage.getItem("previewToken"),u=document.createElement("div");u.id="__nuxt_preview_wrapper",document.body.appendChild(u),ue(me,{previewToken:d,apiURL:n,syncPreview:p,requestPreviewSyncAPI:x}).mount(u)},A=async()=>{if(o?.documentDriven){const{pages:d}=J(i,le),u=await Promise.all(Object.keys(d.value).map(async w=>await e(d.value[w]?._id??w)));d.value=u.reduce((w,k,C)=>(k&&(w[Object.keys(d.value)[C]]=k),w),{})}await i.hooks.callHookParallel("app:data:refresh")};return{mountPreviewUI:S,initiateIframeCommunication:Q};function Q(){if(!window.parent||window.self===window.parent)return;const d=H(),u=E(),w=M(""),k=r=>({path:r.path,query:O(r.query),params:O(r.params),fullPath:r.fullPath,meta:O(r.meta)});window.addEventListener("keydown",r=>{(r.metaKey||r.ctrlKey||r.altKey||r.shiftKey)&&window.parent.postMessage({type:"nuxt-studio:preview:keydown",payload:{key:r.key,metaKey:r.metaKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,altKey:r.altKey}},"*")}),window.addEventListener("message",async r=>{if(!["https://nuxt.studio","https://new.nuxt.studio","https://new.dev.nuxt.studio","https://dev.nuxt.studio","http://localhost:3000",...t?.iframeMessagingAllowedOrigins?.split(",").map(v=>v.trim())||[]].includes(r.origin))return;const{type:N,payload:R={}}=r.data||{};switch(N){case"nuxt-studio:editor:file-selected":{const v=await e(R.path);if(!v||v._partial)return;if(!String(R.path).endsWith(".md")){const P=d.resolve(v._path);if(!P||!P.matched||P.matched.length===0)return}v._path!==E().path&&(w.value=v._path,d.push(v._path));break}case"nuxt-studio:editor:media-changed":case"nuxt-studio:editor:file-changed":{const v=window.sessionStorage.getItem("previewToken"),{additions:P=[],deletions:b=[]}=R;for(const K of P)await l(v,K);for(const K of b)await g(v,K.path);A();break}case"nuxt-studio:config:file-changed":{const{additions:v=[],deletions:P=[]}=R,b=v.find($=>[y.appConfig,y.appConfigV4].includes($.path));b&&_(b?.parsed),P.find($=>[y.appConfig,y.appConfigV4].includes($.path))&&_(void 0)}}}),i.hook("page:finish",()=>{C(),i.payload.prerenderedAt&&A()}),i.hook("content:document-driven:finish",({route:r,page:I})=>{r.meta.studio_page_contentId=I?._id}),i.hook("nuxt-studio:preview:ready",()=>{window.parent.postMessage({type:"nuxt-studio:preview:ready",payload:k(E())},"*"),setTimeout(()=>{C()},100)});function C(){const r=Array.from(window.document.querySelectorAll("[data-content-id]")).map(N=>N.getAttribute("data-content-id")),I=Array.from(new Set([u.meta.studio_page_contentId,...r])).filter(
1Boolean);if(w.value===I[0]){w.value="";return}window.openContentInStudioEditor(I,{navigate:!0,pageContentId:u.meta.studio_page_contentId})}window.openContentInStudioEditor=(r,I={})=>{window.parent.postMessage({type:"nuxt-studio:preview:navigate",payload:{...k(u),contentIds:r,...I}},"*")}}};export{Ie as useStudio};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.