1import{g as ee,r as a,j as D}from"./preload-helper-pGM20HTl.js";import{w as te,r as se,p as ie,t as re,D as V,g as P,a as ne}from"./resolveEditInfo-CkL6yx9w.js";import{X as ae,o as oe,W as T,p as ce}from"./studio._-CSSH7R8v.js";import{l as ue,f as de,i as le,t as he}from"./lru-cache-DbK9v9jx.js";import"./index.browser-BF9SBpQR.js";import"./index-CKyJHHLi.js";import"./projectDetails-kEH6YTdk.js";import"./client-Do8zOFoQ.js";import"./index-CPx8-F0-.js";import"./motion-B6WPpABr.js";import"./frame-BoJ9ysBG.js";import"./index-E2abZQ7o.js";import"./urlPathResolver-DuAwaCNz.js";const pe=i=>i;function fe(i,t,e,n=pe,s="raw"){if(!t)return i;if(s!=="published"&&s!=="raw"&&s!=="previewDrafts")throw new Error(`Unknown perspective "${s}"`);return te(JSON.parse(JSON.stringify(i)),(r,l)=>{const d=se(l,t);if(!d)return r;const{mapping:c,pathSuffix:h}=d;if(c.type!=="value"||c.source.type!=="documentValue")return r;const o=t.documents[c.source.document],w=t.paths[c.source.path];if(o){const f=ie(w+h),p=re(f);if(p==="_id")return r;let u;if(s==="previewDrafts"?(u=e(o._id.startsWith(V)?o:{...o,_id:`${V}${o._id}}`}),u||(u=e(o._id.startsWith(V)?{...o,_id:P(o._id)}:o)),u&&(u={...u,_id:P(o._id),_originalId:o._id})):u=e(o),!u)return r;const m=u?ne(u,p,r):r;return r===m?r:n(m,{cachedDocument:u,previousValue:r,sourceDocument:o,sourcePath:f})}return r})}var j=ue,me=de,ve=he,we=le;function S(i,t,e){arguments.length<2?j.call(this,i):j.call(this,i,t,e);var n=ve.getPointerArray(this.capacity);this.deleted=new n(this.capacity),this.deletedSize=0}for(var W in j.prototype)S.prototype[W]=j.prototype[W];typeof Symbol<"u"&&(S.prototype[Symbol.iterator]=j.prototype[Symbol.iterator]);S.prototype.clear=function(){j.prototype.clear.call(this),this.deletedSize=0};S.prototype.set=function(i,t){var e=this.items[i];if(typeof e<"u"){this.splayOnTop(e),this.V[e]=t;return}this.size<this.capacity?(this.deletedSize>0?e=this.deleted[--this.deletedSize]:e=this.size,this.size++):(e=this.tail,this.tail=this.backward[e],delete this.items[this.K[e]]),this.items[i]=e,this.K[e]=i,this.V[e]=t,this.forward[e]=this.head,this.backward[this.head]=e,this.head=e};S.prototype.setpop=function(i,t){var e=null,n=null,s=this.items[i];return typeof s<"u"?(this.splayOnTop(s),e=this.V[s],this.V[s]=t,{evicted:!1,key:i,value:e}):(this.size<this.capacity?(this.deletedSize>0?s=this.deleted[--this.deletedSize]:s=this.size,this.size++):(s=this.tail,this.tail=this.backward[s],e=this.V[s],n=this.K[s],delete this.items[n]),this.items[i]=s,this.K[s]=i,this.V[s]=t,this.forward[s]=this.head,this.backward[this.head]=s,this.head=s,n?{evicted:!0,key:n,value:e}:null)};S.prototype.delete=function(i){var t=this.items[i];if(typeof t>"u")return!1;if(delete this.items[i],this.size===1)return this.size=0,this.head=0,this.tail=0,this.deletedSize=0,!0;var e=this.backward[t],n=this.forward[t];return this.head===t&&(this.head=n),this.tail===t&&(this.tail=e),this.forward[e]=n,this.backward[n]=e,this.size--,this.deleted[this.deletedSize++]=t,!0};S.prototype.remove=function(i,t=void 0){var e=this.items[i];if(typeof e>"u")return t;var n=this.V[e];if(delete this.items[i],this.size===1)return this.size=0,this.head=0,this.tail=0,this.deletedSize=0,n;var s=this.backward[e],r=this.forward[e];return this.head===e&&(this.head=r),this.tail===e&&(this.tail=s),this.forward[s]=r,this.backward[r]=s,this.size--,this.deleted[this.deletedSize++]=e,n};S.from=function(i,t,e,n){if(arguments.length<2){if(n=we.guessLength(i),typeof n!="number")throw new Error("mnemonist/lru-cache.from: could not guess iterable length. Please provide desired capacity as last argument.")}else arguments.length===2&&(n=t,t=null,e=null);var s=new S(t,e,n);return me(i,function(r,l){s.set(l,r)}),s};var ge=S;const ye=ee(ge);function Se(i){return document.addEventListener("visibilitychange",i),()=>document.removeEventListener("visibilitychange",i)}function qe(i){const{liveDocument:t,channel:e,perspective:n,liveQueries:s,documentsOnPage:r}=i,[l]=a.useState(()=>new ye(ae)),d=oe({apiVersion:"2023-10-16"}),c=a.useMemo(()=>d.config(),[d]),h=a.useMemo(()=>d.withConfig({resultSourceMap:"withKeyArraySelector"}),[d]);a.useEffect(()=>{if(e){const{projectId:p,dataset:u}=c;e.send("loaders","loader/perspective",{projectId:p,dataset:u,perspective:n})}},[e,c,n]);const o=a.useMemo(()=>{const p=r.map(({_id:g})=>g),u=[...new Set(p)],m=l.capacity;return u.length>=m&&(u.length=m),u},[l.capacity,r]),[w,f]=a.useState(0);
1return D.jsxs(D.Fragment,{children:[D.jsx(be,{cache:l,client:h,turboIds:o,setDocumentsCacheLastUpdated:f}),Object.entries(s).map(([p,{query:u,params:m,perspective:g}])=>D.jsx(Ie,{cache:l,projectId:c.projectId,dataset:c.dataset,perspective:g,query:u,params:m,channel:e,client:h,refreshInterval:n?2e3:0,liveDocument:t,documentsCacheLastUpdated:w},`${p}${g}`))]})}const be=a.memo(function(i){const{cache:t,client:e,turboIds:n,setDocumentsCacheLastUpdated:s}=i,[r,l]=a.useState([]);return a.useEffect(()=>{const d=new Set(r.flat()),c=new Set;for(const o of n)!d.has(o)&&!t.has(o)&&c.add(o);const h=[...c].slice(0,T);h.length!==0&&l(o=>[...o.slice(-T),h])},[r,t,n]),a.useEffect(()=>{const d=e.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"presentation-loader"}).subscribe(c=>{var h,o;if(c.type==="mutation"&&c.transition==="disappear"&&t.delete(c.documentId)&&s(Date.now()),c.type!=="mutation"||(o=(h=c.effects)==null?void 0:h.apply)==null||!o.length)return;const w=t.peek(c.documentId);if(w){const f={...w};delete f._rev;const p=ce(f,c.effects.apply);t.set(c.documentId,p),s(Date.now())}});return()=>d.unsubscribe()},[t,e,s]),D.jsx(D.Fragment,{children:r.map(d=>D.jsx(X,{cache:t,client:e,ids:d,setDocumentsCacheLastUpdated:s},JSON.stringify(d)))})}),X=a.memo(function(i){const{client:t,cache:e,ids:n,setDocumentsCacheLastUpdated:s}=i;return a.useEffect(()=>{const r=n.filter(l=>!e.has(l));r.length!==0&&t.getDocuments(r).then(l=>{for(const d of l)d&&d!=null&&d._id&&(e.set(d._id,d),s(Date.now()))},console.error)},[e,t,n,s]),null});function Ie(i){const{cache:t,projectId:e,dataset:n,perspective:s,query:r,client:l,refreshInterval:d,liveDocument:c,channel:h,documentsCacheLastUpdated:o}=i,w=function(m){const g=a.useMemo(()=>JSON.stringify(m||{}),[m]);return a.useMemo(()=>JSON.parse(g),[g])}(i.params),f=function(m){const{cache:g,liveDocument:U,client:M,refreshInterval:G,query:R,params:O,perspective:x,documentsCacheLastUpdated:q}
1=m,[E,Q]=a.useState(null),{projectId:B,dataset:H}=a.useMemo(()=>{const{projectId:L,dataset:v}=M.config();return{projectId:L,dataset:v}},[M]),[A,Y]=a.useState(null);if(A)throw A;const[F,$]=function(L){const{refreshInterval:v}=L,_=function(){const[I,C]=a.useState(!1);a.useEffect(()=>{C(navigator.onLine);const J=()=>C(!0),N=()=>C(!1);return window.addEventListener("online",J),window.addEventListener("offline",N),()=>{window.removeEventListener("online",J),window.removeEventListener("offline",N)}},[]);const Z=a.useSyncExternalStore(Se,()=>document.visibilityState,()=>"hidden");return!I||Z==="hidden"}(),[y,b]=a.useState("hit"),z=a.useCallback(()=>(b("inflight"),()=>b("hit")),[]);return a.useEffect(()=>{if(!v||y!=="hit")return;const I=setTimeout(()=>b("stale"),v);return()=>clearTimeout(I)},[v,y]),a.useEffect(()=>{if(y!=="hit")return;const I=()=>b("stale");return window.addEventListener("focus",I),()=>window.removeEventListener("focus",I)},[v,y]),a.useEffect(()=>{_&&y==="hit"&&b("stale"),!_&&y==="stale"&&b("refresh")},[_,y]),[y,z]}({refreshInterval:G}),k=F==="refresh"||F==="inflight";return a.useEffect(()=>{if(!k)return;let L=!1,v=!1;const _=new AbortController;async function y(){const{signal:z}=_;v=!0;const{result:I,resultSourceMap:C}=await M.fetch(R,O,{tag:"presentation-loader",signal:z,perspective:x,filterResponse:!1});v=!1,z.aborted||(Q({result:I,resultSourceMap:C}),L=!0)}const b=$();return y().catch(z=>{v=!1,z.name!=="AbortError"&&Y(z)}).finally(b),()=>{!L&&!v&&_.abort()}},[M,H,U,O,x,B,R,k,$]),a.useMemo(()=>q&&E!=null&&E.resultSourceMap?{result:Ee(g,U,E.result,x,E.resultSourceMap),resultSourceMap:E.resultSourceMap}:E,[g,q,U,x,E])}({cache:t,client:l,liveDocument:c,params:w,perspective:s,query:r,refreshInterval:d,documentsCacheLastUpdated:o}),p=f==null?void 0:f.result,u=f==null?void 0:f.resultSourceMap;return a.useEffect(()=>{u&&h.send("loaders","loader/query-change",{projectId:e,dataset:n,perspective:s,query:r,params:w,result:p,resultSourceMap:u})},[h,n,w,s,e,r,p,u]),null}X.displayName="GetDocuments";let K=!1;function Ee(i,t,e,n,s){if(n==="raw")throw new Error("turboChargeResultIfSourceMap does not support raw perspective");return fe(e,s,r=>{if(!r._projectId)return t!=null&&t._id&&P(t._id)===P(r._id)?t:i.get(r._id);K||(console.warn("Cross dataset references are not supported yet, ignoring source document",r),K=!0)},(r,{previousValue:l})=>typeof r=="number"&&typeof l=="string"?`${r}`:r,n)}export{qe as default,Ee as turboChargeResultIfSourceMap};
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.