Socket
Socket
Sign inDemoInstall

@sanity/presentation

Package Overview
Dependencies
Maintainers
53
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/presentation - npm Package Compare versions

Comparing version 1.15.12 to 1.15.13

2

dist/_chunks-es/PresentationTool.js

@@ -50,4 +50,4 @@ var e=Object.defineProperty,t=(t,n,r)=>((t,n,r)=>n in t?e(t,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[n]=r)(t,"symbol"!=typeof n?n+"":n,r);import{jsx as n,jsxs as r,Fragment as i}from"react/jsx-runtime";import{studioPath as o}from"@sanity/client/csm";import{Button as a,Card as s,Flex as c,Container as l,Stack as d,Text as u,Inline as p,Box as m,Code as f,Label as h,ErrorBoundary as v,Badge as g,TextInput as y,MenuItem as w,useToast as b,usePrefersReducedMotion as x,TooltipDelayGroupProvider as P,Tooltip as E,Switch as k,MenuButton as S,Menu as I,Spinner as z,BoundaryElementProvider as D}from"@sanity/ui";import{createContext as C,useContext as O,useLayoutEffect as _,useMemo as L,useRef as $,useState as U,useCallback as R,useEffect as j,forwardRef as T,memo as A,createElement as W,startTransition as M,useReducer as N,Suspense as F,lazy as K}from"react";import{useTranslation as V,useUnique as B,getPublishedId as q,useSchema as G,Preview as J,Translate as X,CommentsIntentProvider as H,useActiveWorkspace as Z,useClient as Q,useCurrentUser as Y,Hotkeys as ee,useDocumentStore as te,useProjectId as ne,useDataset as re,useWorkspace as ie}from"sanity";import{StateLink as oe,useRouter as ae,decodeJsonParams as se}from"sanity/router";import{styled as ce}from"styled-components";import{p as le,u as de,P as ue,a as pe,b as me,A as fe,M as he,c as ve,C as ge,E as ye,D as we}from"./index.js";import{WarningOutlineIcon as be,ResetIcon as xe,LaunchIcon as Pe,CopyIcon as Ee,PanelLeftIcon as ke,RefreshIcon as Se,ShareIcon as Ie,ChevronDownIcon as ze,CheckmarkIcon as De,DesktopIcon as Ce,MobileDeviceIcon as Oe,EditIcon as _e,PublishIcon as Le}from"@sanity/icons";import{PaneRouterContext as $e,PaneLayout as Ue,StructureToolProvider as Re,DocumentListPane as je,DocumentPane as Te}from"sanity/structure";import{D as Ae}from"./DisplayedDocumentBroadcaster.js";import{hasSecretSearchParams as We,setSecretSearchParams as Me,withoutSecretSearchParams as Ne}from"@sanity/preview-url-secret/without-secret-search-params";import{motion as Fe,MotionConfig as Ke,AnimatePresence as Ve}from"framer-motion";import{createPreviewSecret as Be}from"@sanity/preview-url-secret/create-secret";import qe from"fast-deep-equal";import{match as Ge}from"path-to-regexp";import{definePreviewUrl as Je}from"@sanity/preview-url-secret/define-preview-url";import{suspend as Xe}from"suspend-react";let He;const Ze=new Uint8Array(16);function Qe(){if(!He&&(He=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!He))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return He(Ze)}const Ye=[];for(let e=0;e<256;++e)Ye.push((e+256).toString(16).slice(1));var et={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function tt(e,t,n){if(et.randomUUID&&!t&&!e)return et.randomUUID();const r=(e=e||{}).random||(e.rng||Qe)();return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(e,t=0){return Ye[e[t+0]]+Ye[e[t+1]]+Ye[e[t+2]]+Ye[e[t+3]]+"-"+Ye[e[t+4]]+Ye[e[t+5]]+"-"+Ye[e[t+6]]+Ye[e[t+7]]+"-"+Ye[e[t+8]]+Ye[e[t+9]]+"-"+Ye[e[t+10]]+Ye[e[t+11]]+Ye[e[t+12]]+Ye[e[t+13]]+Ye[e[t+14]]+Ye[e[t+15]]}(r)}const nt=1e3,rt=1e3,it=500,ot=["handshake/syn","handshake/syn-ack","handshake/ack"],at=e=>ot.some((t=>t===e)),st=({data:e={}})=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&!("domain"in e)&&["id","type","from","to"].every((t=>t in e))&&e.type.startsWith("handshake/");function ct(e){const t=e.target,n=e.connectTo.map((e=>({buffer:[],config:e,id:"",handler:i,status:"connecting",interval:void 0,heartbeat:void 0})));function r(e){window.clearInterval(e.interval)}function i(e){const{data:t}=e;if(at(t.type)){const e=n.find((e=>e.config.id===t.from));e&&"handshake/syn-ack"===t.type&&(c(e,"connected"),l(e,"handshake/ack",{id:e.id}))}}const o=t=>{var r,i,o;const a=t.data;if(!at(a.type)&&n.find((e=>e.id===a.connectionId))){const t=n.find((e=>e.config.id===a.from));if(t){const n=[a.type,a.data];null==(i=(r=t.config).onEvent)||i.call(r,...n),null==(o=e.onEvent)||o.call(e,...n),d(t,"channel/response",{responseTo:a.id},!1)}}};function a(t){var r;if(st(t))console.error("Visual editing package mismatch detected! Please ensure you are using the latest version of Sanity Studio and any packages listed here:\nhttps://github.com/sanity-io/visual-editing");else if(function(t){const{data:r,origin:i}=t;return"sanity/channels"===r.domain&&r.to==e.id&&n.map((e=>e.config.id)).includes(r.from)&&"channel/response"!==r.type&&i===e.targetOrigin}(t)){const{data:e}=t;null==(r=n.find((t=>t.config.id===e.from)))||r.handler(t)}}function s(e){e.heartbeat&&window.clearInterval(e.heartbeat)}function c(t,n){var a,c,u;t.status=n,null==(c=(a=t.config).onStatusUpdate)||c.call(a,n,t.config.id),null==(u=e.onStatusUpdate)||u.call(e,n,t.config.id),"connecting"===n||"reconnecting"===n?(t.handler=i,s(t),function(e){e.id=tt(),e.interval=window.setInterval((()=>{l(e,"handshake/syn",{id:e.id})}),it)}(t)):"connected"===n?(t.handler=o,r(t),function(e){if(s(e),e.config.heartbeat){const t="number"==typeof e.config.heartbeat?e.config.heartbeat:rt;e.heartbeat=window.setInterval((()=>{d(e,"channel/heartbeat")}),t)}}(t),function(e){const t=[...e.buffer];e.buffer.splice(0,e.buffer.length),t.forEach((({type:t,data:n})=>{d(e,t,n)}))}(t)):"disconnected"===n&&(t.id=null,t.handler=i,r(t),s(t))}function l(n,r,i){if(!n.id)throw new Error("No channel ID set");const o={connectionId:n.id,data:i,domain:"sanity/channels",from:e.id,id:tt(),to:n.config.id,type:r};try{null==t||t.postMessage(o,{targetOrigin:"*"})}catch{throw new Error(`Failed to postMessage '${o.id}' on '${e.id}'`)}}function d(n,r,i,o=!0){const a=tt();if("connecting"===n.status||"reconnecting"===n.status||"disconnected"===n.status)return void n.buffer.push({type:r,data:i});if(!n.id)throw new Error("No channel ID set");const s={connectionId:n.id,data:i,domain:"sanity/channels",from:e.id,id:a,to:n.config.id,type:r};if(o){const t=setTimeout((()=>{s.connectionId===n.id&&(window.removeEventListener("message",o,!1),"channel/heartbeat"!==r&&n.buffer.push({type:r,data:i}),c(n,"reconnecting"),console.warn(`Received no response to message '${s.type}' on client '${e.id}' (ID: '${s.id}').`))}),nt),o=e=>{var n;const{data:r}=e;"channel/response"===r.type&&null!=(n=r.data)&&n.responseTo&&r.data.responseTo===s.id&&(window.removeEventListener("message",o,!1),clearTimeout(t))};window.addEventListener("message",o,!1)}try{null==t||t.postMessage(s,{targetOrigin:e.targetOrigin})}catch{throw new Error(`Failed to postMessage '${s.id}' on client '${e.id}'`)}}return window.addEventListener("message",a,!1),n.forEach((e=>{c(e,"connecting")})),{destroy:function(){n.forEach((e=>{["disconnected"].includes(e.status)||(d(e,"channel/disconnect",{id:e.id},!1),c(e,"disconnected"))})),window.removeEventListener("message",a,!1),n.forEach((e=>{s(e),r(e)}))},send:function(e,t,r){(e?Array.isArray(e)?[...e]:[e]:n).forEach((e=>{const i=n.find((t=>t.config.id===e));if(!i)throw new Error("Invalid channel ID");d(i,t,r)}))}}}var lt,dt,ut,pt,mt=class extends Error{constructor(e){super(e[0].message),t(this,"issues"),this.name="ValiError",this.issues=e}};function ft(e,t){return Array.isArray(e)?[void 0,e]:[e,t]}function ht(e,t,n,r,i){var o,a,s,c,l;const d=null!=(l=null!=(c=null!=(s=null!=(a=null!=(o=t.message)?o:function(e,t){var n;return null==(n=null==pt?void 0:pt.get(e))?void 0:n.get(t)}(n,i.lang))?a:e?(u=i.lang,null==ut?void 0:ut.get(u)):null)?s:null==r?void 0:r.message)?c:function(e){return null==dt?void 0:dt.get(e)}(i.lang))?l:i.message;var u;return"function"==typeof d?d(i):d}function vt(e,t,n){return{typed:e,output:t,issues:n}}function gt(e){let t=typeof e;return"object"===t&&(t=e?Object.getPrototypeOf(e).constructor.name:"null"),"string"===t?`"${e}"`:"number"===t||"bigint"===t||"boolean"===t?`${e}`:t}function yt(e,t,n){var r;const i=null!=(r=n.received)?r:gt(n.input),o={reason:e.type,context:n.context.type,expected:n.context.expects,received:i,message:`Invalid ${n.label}: ${n.context.expects?`Expected ${n.context.expects} but r`:"R"}eceived ${i}`,input:n.input,requirement:n.context.requirement,path:n.path,lang:null==t?void 0:t.lang,abortEarly:null==t?void 0:t.abortEarly,abortPipeEarly:null==t?void 0:t.abortPipeEarly,skipPipe:null==t?void 0:t.skipPipe};return o.message=ht(!1,n.context,n.reference,t,o),o}function wt(e,t,n,r){if(e.pipe&&(null==n||!n.skipPipe))for(const i of e.pipe){const o=i._parse(t);if(o.issues){for(const t of o.issues){const i=yt(e,n,t);r?r.push(i):r=[i]}if(null!=n&&n.abortEarly||null!=n&&n.abortPipeEarly)break}else t=o.output}return vt(!0,t,r)}function bt(e,t,n,r,i){var o,a;const s=gt(n),c=null!=(o=null==i?void 0:i.expected)?o:e.expects,l={reason:null!=(a=null==i?void 0:i.reason)?a:"type",context:e.type,expected:c,received:s,message:`Invalid type: Expected ${c} but received ${s}`,input:n,path:null==i?void 0:i.path,issues:null==i?void 0:i.issues,lang:null==r?void 0:r.lang,abortEarly:null==r?void 0:r.abortEarly,abortPipeEarly:null==r?void 0:r.abortPipeEarly,skipPipe:null==r?void 0:r.skipPipe};return l.message=ht(!0,e,t,r,l),{typed:!1,output:n,issues:[l]}}function xt(e,t){return{...e,fallback:t,_parse(t,n){const r=e._parse(t,n);return r.issues?vt(!0,function(e,t){return"function"==typeof e.fallback?e.fallback(t):e.fallback}(this,{input:t,issues:r.issues})):r}}}function Pt(e,t){const[n,r]=ft(e,t);return{type:"boolean",expects:"boolean",async:!1,message:n,pipe:r,_parse(e,t){return"boolean"==typeof e?wt(this,e,t):bt(this,Pt,e,t)}}}function Et(e,t,n,r){const[i,o,a]=function(e,t,n){if(!e||"object"==typeof e&&!Array.isArray(e)){const[r,i]=ft(t,n);return[e,r,i]}const[r,i]=ft(e,t);return[void 0,r,i]}(t,n,r);let s;return{type:"object",expects:"Object",async:!1,entries:e,rest:i,message:o,pipe:a,_parse(e,t){if(e&&"object"==typeof e){s=null!=s?s:Object.entries(this.entries);let n,r=!0;const i={};for(const[o,a]of s){const s=e[o],c=a._parse(s,t);if(c.issues){const i={type:"object",origin:"value",input:e,key:o,value:s};for(const e of c.issues)e.path?e.path.unshift(i):e.path=[i],null==n||n.push(e);if(n||(n=c.issues),null!=t&&t.abortEarly){r=!1;break}}c.typed||(r=!1),(void 0!==c.output||o in e)&&(i[o]=c.output)}if(this.rest&&(null==t||!t.abortEarly||!n))for(const o in e)if(!(o in this.entries)){const a=e[o],s=this.rest._parse(a,t);if(s.issues){const i={type:"object",origin:"value",input:e,key:o,value:a};for(const e of s.issues)e.path?e.path.unshift(i):e.path=[i],null==n||n.push(e);if(n||(n=s.issues),null!=t&&t.abortEarly){r=!1;break}}s.typed||(r=!1),i[o]=s.output}return r?wt(this,i,t,n):vt(!1,i,n)}return bt(this,Et,e,t)}}}function kt(e,t){return{type:"picklist",expects:e.map(gt).join(" | "),async:!1,options:e,message:t,_parse(e,t){return this.options.includes(e)?vt(!0,e):bt(this,kt,e,t)}}}function St(e,t,n){const r=e._parse(t,function(e){var t,n,r,i;return{lang:null!=(t=null==e?void 0:e.lang)?t:null==lt?void 0:lt.lang,message:null==e?void 0:e.message,abortEarly:null!=(n=null==e?void 0:e.abortEarly)?n:null==lt?void 0:lt.abortEarly,abortPipeEarly:null!=(r=null==e?void 0:e.abortPipeEarly)?r:null==lt?void 0:lt.abortPipeEarly,skipPipe:null!=(i=null==e?void 0:e.skipPipe)?i:null==lt?void 0:lt.skipPipe}}(n));if(r.issues)throw new mt(r.issues);return r.output}const It=/^([A-Za-z]+):([0-9]+)$/,zt=/^([A-Za-z]+):([0-9]+),([0-9]+)$/,Dt=/^([A-Za-z]+):([a-z0-9]+)$/;function Ct(e,t){return`${e}-${"string"==typeof t?t:JSON.stringify(t)}`}const Ot={alt:"altKey",ctrl:"ctrlKey",mod:typeof window<"u"&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform)?"metaKey":"ctrlKey",shift:"shiftKey"};function _t(e){return"Alt"===e.key}function Lt(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout((()=>{e.apply(e,r)}),t)}}const $t=C(null);$t.displayName="PanelsContext";const Ut=ce.div`

display: block;
`),Rn=function(e){var t;const{fontSize:r=1,onChange:o,origin:a,padding:s=3,prefix:c,suffix:l,value:d}=e,{t:u}=V(le),{basePath:p="/"}=(null==(t=Z())?void 0:t.activeWorkspace)||{},m=$(null),[f,h]=U(void 0),[v,g]=U(void 0),w=R((e=>{h(e.currentTarget.value)}),[]),b=R((e=>{var t;if("Enter"===e.key){if(void 0===f)return;const e=f.startsWith("/")||""===f?`${a}${f}`:f;if(!e.startsWith(a+"/")&&e!==a)return void g(u("preview-location-input.error",{origin:a,context:"missing-origin"}));if(!a&&(e.startsWith(`${p}/`)||e===p))return void g(u("preview-location-input.error",{basePath:p,context:"same-base-path"}));const n=e===a?a+"/":e;g(void 0),h(void 0),o(n.slice(a.length)),null==(t=m.current)||t.blur()}"Escape"===e.key&&(g(void 0),h(void 0))}),[p,o,a,f,u]),x=R((()=>{g(void 0),h(void 0)}),[]);j((()=>{g(void 0),h(void 0)}),[a,d]);const P=L((()=>({icon:xe})),[]);return n(i,{children:n(y,{clearButton:v?P:void 0,customValidity:v,fontSize:r,onBlur:x,onClear:()=>{g(void 0),h(a+d)},onChange:w,onKeyDownCapture:b,padding:s,prefix:c,style:{zIndex:1},radius:2,ref:m,space:s,suffix:l,value:void 0===f?`${a}${d}`:f})})};function jn(e){const{initialUrl:t,openPopup:o,previewLocationOrigin:a,previewLocationRoute:s}=e,{t:c}=V(le),l=R((e=>{e.preventDefault(),o(e.currentTarget.href)}),[o]);return r(i,{children:[n(Tn,{initialUrl:t,previewLocationOrigin:a,previewLocationRoute:s}),n(w,{icon:Pe,text:c("share-url.menu-item.open.text"),as:"a",href:`${a}${s}`,onClick:l,rel:"opener",target:"_blank"})]})}function Tn(e){const{initialUrl:t,previewLocationOrigin:r,previewLocationRoute:i}=e,{t:o}=V(le),{push:a}=b(),s=Q({apiVersion:fe}),c=Y(),[l,d]=U(!1);return n(w,{disabled:l,onClick:()=>{if(null==navigator||!navigator.clipboard)return a({closable:!0,status:"error",title:o("share-url.clipboard.status",{context:"unsupported"})}),!1;d(!0);let e,n=`${r}${i}`;const l=()=>{a({id:e,closable:!0,status:"success",title:o("share-url.clipboard.status",{context:"success"})}),d(!1)},u=e=>{a({closable:!0,status:"error",title:o("share-url.clipboard.status",{context:"failed"}),description:e.message||e.toString()}),d(!1)};if(We(t)&&typeof ClipboardItem<"u"){const r="text/plain",d=async()=>{e=a({closable:!0,title:o("share-url.clipboard.status",{context:"copying"})});const l=await Be(s,"@sanity/presentation",typeof window>"u"?"":location.href,null==c?void 0:c.id);return n=Me(t,l.secret,i).toString(),new Blob([n],{type:r})},p=new ClipboardItem({[r]:d()});navigator.clipboard.write([p]).then(l).catch(u)}else navigator.clipboard.writeText(n).then(l).catch(u)},text:o("share-url.menu-item.copy.text"),icon:Ee})}const An=Fe(c),Wn={previewDrafts:"preview-frame.perspective.previewDrafts.title",published:"preview-frame.perspective.published.title"},Mn="caution",Nn="positive",Fn={previewDrafts:_e,published:Le},Kn=T((function(e,t){const{dispatch:o,iframe:l,initialUrl:p,loadersConnection:v,navigatorEnabled:g,onPathChange:y,onRefresh:b,openPopup:D,overlaysConnection:C,params:O,perspective:_,targetOrigin:$,toggleNavigator:T,toggleOverlay:A,viewport:M,visualEditing:{overlaysEnabled:N}}=e,{t:F}=V(le),{devMode:K}=de(),B=x(),q=R((()=>o({type:En,viewport:"desktop"})),[o]),G=R((()=>o({type:En,viewport:"mobile"})),[o]),J="loading"===l.status||"reloading"===l.status,[X,H]=U(!1),Z="refreshing"===l.status,[Q,Y]=U(!1),te=J||Z||"connecting"===C,ne=L((()=>$===location.origin?"":$),[$]),re=R((()=>{b((()=>{"function"==typeof t||null==t||!t.current||(o({type:xn}),t.current.src=`${$}${O.preview||"/"}`)}))}),[o,b,O.preview,$,t]),ie=R((()=>{"function"==typeof t||null==t||!t.current||(t.current.src=p.toString(),o({type:xn}))}),[o,t,p]),oe=R((()=>{se(!0)}),[]),[ae,se]=U(!1),[ce,ue]=U(!1);j((()=>{if(!(J||Z||"connecting"!==C&&"reconnecting"!==C)){const e=setTimeout((()=>{ue(!0)}),1e3);return()=>clearTimeout(e)}}),[C,J,Z]),j((()=>{if(!J&&!Z&&ce){if("connected"===C&&(Y(!1),ue(!1),H(!1),se(!1)),"connecting"===C){const e=setTimeout((()=>{H(!0),console.error("Unable to connect to visual editing. Make sure you've setup '@sanity/visual-editing' correctly")}),he);return()=>clearTimeout(e)}if("reconnecting"===C){const e=setTimeout((()=>{H(!0),Y(!0)}),he);return()=>clearTimeout(e)}"disconnected"===C&&Y(!0)}}),[J,C,Z,ce]);const pe=L((()=>{const e=new URL(O.preview||"/",$),{pathname:t,search:n}=Ne(e);return`${t}${n}`}),[O.preview,$]),me=R((()=>{o({type:wn})}),[o]);return j((()=>{if("function"==typeof t||null==t||!t.current)return;const e=t.current;function n(){e===document.activeElement&&e.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0}))}return window.addEventListener("blur",n),()=>{window.removeEventListener("blur",n)}}),[t]),n(Ke,{transition:B?{duration:0}:void 0,children:r(P,{delay:1e3,children:[n(s,{flex:"none",padding:2,shadow:1,style:{position:"relative"},children:r(c,{align:"center",style:{minHeight:0},children:[T&&n(m,{flex:"none",marginRight:1,padding:1,children:n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.navigator.toggle-button.tooltip")}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.navigator.toggle-button.aria-label"),fontSize:1,icon:ke,mode:"bleed",onClick:T,padding:2,selected:g})})}),n(E,{animate:!0,content:r(c,{align:"center",style:{whiteSpace:"nowrap"},children:[n(m,{padding:1,children:n(u,{size:1,children:F("preview-frame.overlay.toggle-button.tooltip",{context:N?"disable":"enable"})})}),n(m,{paddingY:1,children:n(ee,{keys:["Alt"],style:{marginTop:-4,marginBottom:-4}})})]}),fallbackPlacements:["bottom-start"],padding:1,placement:"bottom",portal:!0,children:n(s,{as:"label",flex:"none",marginRight:1,padding:3,style:{lineHeight:0,borderRadius:999,userSelect:"none"},tone:N?"transparent":void 0,children:r(c,{align:"center",gap:3,children:[n("div",{style:{margin:-4},children:n(k,{checked:N,onChange:A,disabled:"loading"===l.status||"connected"!==C})}),n(m,{children:n(u,{muted:!N,size:1,weight:"medium",children:F("preview-frame.overlay.toggle-button.text")})})]})})}),n(m,{flex:1,marginX:1,children:n(Rn,{prefix:n(m,{padding:1,children:n(E,{animate:!0,content:n(u,{size:1,children:"loaded"===l.status?F("preview-frame.refresh-button.tooltip"):F("preview-frame.status",{context:l.status})}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.refresh-button.aria-label"),fontSize:1,icon:Se,mode:"bleed",loading:"reloading"===l.status||"refreshing"===l.status,onClick:re,padding:2})})}),onChange:y,origin:ne,suffix:n(m,{padding:1,children:n(S,{button:n(a,{fontSize:1,iconRight:Ie,mode:"bleed",padding:2,space:2}),id:"location-menu",menu:n(I,{children:n(jn,{initialUrl:p,openPopup:D,previewLocationOrigin:ne,previewLocationRoute:pe})}),popover:{animate:!0,constrainSize:!0,placement:"bottom",portal:!0}})}),value:pe})}),n(c,{align:"center",flex:"none",gap:1,padding:1,children:n(S,{button:n(a,{fontSize:1,iconRight:ze,mode:"bleed",padding:2,space:2,text:F(Wn["connected"===v?_:"previewDrafts"]),loading:"reconnecting"===v&&"loaded"!==l.status,disabled:"connected"!==v}),id:"perspective-menu",menu:r(I,{style:{maxWidth:240},children:[n(w,{fontSize:1,onClick:()=>o({type:Pn,perspective:"previewDrafts"}),padding:3,pressed:"previewDrafts"===_,tone:Mn,children:r(c,{align:"flex-start",gap:3,children:[n(m,{flex:"none",children:n(u,{size:1,children:W(Fn.previewDrafts)})}),r(d,{flex:1,space:2,children:[n(u,{size:1,weight:"medium",children:F(Wn.previewDrafts)}),n(u,{muted:!0,size:1,children:F("preview-frame.perspective.previewDrafts.text")})]}),n(m,{flex:"none",children:n(u,{muted:!0,size:1,style:{opacity:"previewDrafts"===_?1:0},children:n(De,{})})})]})}),n(w,{fontSize:1,onClick:()=>o({type:Pn,perspective:"published"}),padding:3,pressed:"published"===_,tone:Nn,children:r(c,{align:"flex-start",gap:3,children:[n(m,{flex:"none",children:n(u,{size:1,children:W(Fn.published)})}),r(d,{flex:1,space:2,children:[n(u,{size:1,weight:"medium",children:F(Wn.published)}),n(u,{muted:!0,size:1,children:F("preview-frame.perspective.published.text")})]}),n(m,{flex:"none",children:n(u,{muted:!0,size:1,style:{opacity:"published"===_?1:0},children:n(De,{})})})]})})]}),popover:{animate:!0,constrainSize:!0,placement:"bottom",portal:!0}})}),r(c,{align:"center",flex:"none",gap:1,padding:1,children:[n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.viewport-full-button.tooltip")}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.viewport-full-button.aria-label"),fontSize:1,icon:Ce,mode:"bleed",onClick:q,padding:2,selected:"desktop"===M})}),n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.viewport-narrow-button.tooltip")}),padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.viewport-narrow-button.aria-label"),fontSize:1,icon:Oe,mode:"bleed",onClick:G,padding:2,selected:"mobile"===M})})]})]})}),n(s,{flex:1,tone:"transparent",children:r(c,{align:"center",height:"fill",justify:"center",padding:"desktop"===M?0:2,sizing:"border",style:{position:"relative",cursor:te?"wait":void 0},children:[n(Ve,{children:Q||J||Z||!ce||ae?(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?n(An,{initial:"initial",animate:"animate",exit:"exit",variants:Bn,justify:"center",align:"center",style:{inset:"0",position:"absolute"},children:r(c,{style:{...Vn[M]},justify:"center",align:"center",direction:"column",gap:4,children:[n(z,{muted:!0}),n(u,{muted:!0,size:1,children:F("preview-frame.status",{context:"loading"})})]})}):Q&&!ae?n(An,{initial:"initial",animate:"animate",exit:"exit",variants:qn,justify:"center",align:"center",style:{background:"var(--card-bg-color)",inset:"0",position:"absolute",borderTop:"1px solid transparent",boxShadow:"0 0 0 1px var(--card-border-color)"},children:n(Xt,{flex:1,message:F("preview-frame.connection.error.text"),onRetry:ie,onContinueAnyway:oe,children:K&&r(i,{children:["connected"!==C&&n(s,{padding:3,radius:2,tone:"critical",children:r(d,{space:3,children:[n(h,{muted:!0,size:0,children:F("preview-frame.overlay.connection-status.label")}),n(f,{size:1,children:F("channel.status",{context:C})})]})}),"connected"!==v&&n(s,{padding:3,radius:2,tone:"critical",children:r(d,{space:3,children:[n(h,{muted:!0,size:0,children:F("preview-frame.loader.connection-status.label")}),n(f,{size:1,children:F("channel.status",{context:v})})]})})]})})}):null:n(An,{initial:"initial",animate:"animate",exit:"exit",variants:Bn,justify:"center",align:"center",style:{inset:"0",position:"absolute",backdropFilter:X?"blur(16px) saturate(0.5) grayscale(0.5)":"blur(2px)",transition:"backdrop-filter 0.2s ease-in-out",WebkitBackdropFilter:X?"blur(16px) saturate(0.5) grayscale(0.5)":"blur(2px)",WebkitTransition:"-webkit-backdrop-filter 0.2s ease-in-out",zIndex:1},children:r(c,{style:{...Vn[M]},justify:"center",align:"center",direction:"column",gap:4,children:[X&&n(a,{disabled:!0,fontSize:1,mode:"ghost",text:F("preview-frame.continue-button.text"),style:{opacity:0}}),n(s,{radius:2,tone:X?"caution":"inherit",padding:4,shadow:1,children:r(c,{justify:"center",align:"center",direction:"column",gap:4,children:[n(z,{muted:!0}),n(u,{muted:!0,size:1,children:F("preview-frame.status",X?{context:"timeout"}:{context:"connecting"})})]})}),X&&n(a,{fontSize:1,tone:"critical",onClick:oe,text:F("preview-frame.continue-button.text")})]})})}),n(Un,{ref:t,style:{pointerEvents:(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?"none":"auto",boxShadow:"0 0 0 1px var(--card-border-color)",borderTop:"1px solid transparent"},src:p.toString(),initial:["background"],variants:Gn,animate:[(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?"background":"active",J?"reloading":"idle",M,ce&&!ae?"timedOut":""],onLoad:me})]})})]})})})),Vn={desktop:{width:"100%",height:"100%"},mobile:{width:375,height:650}},Bn={initial:{opacity:1},animate:{opacity:[0,0,1]},exit:{opacity:[1,0,0]}},qn={initial:{opacity:1},animate:{opacity:[0,0,1]},exit:{opacity:[1,0,0]}},Gn={desktop:{...Vn.desktop,boxShadow:"0 0 0 0px var(--card-border-color)"},mobile:{...Vn.mobile,boxShadow:"0 0 0 1px var(--card-border-color)"},background:{opacity:0,scale:1},idle:{scale:1},reloading:{scale:[1,1,1,.98]},active:{opacity:[0,0,1],scale:1},timedOut:{opacity:[0,0,1]}};let Jn=!1;function Xn(e,t){return e instanceof Function?e(t):e}function Hn(e,t){const n=Array.isArray(e)?e:[e];for(e of n){let n,r=e;if("string"==typeof e)try{const t=new URL(e);n=t.origin,r=t.pathname}catch{}if(!n||t.origin===n)try{const e=Ge(r,{decode:decodeURIComponent})(t.pathname);if(e){const{params:t,path:r}=e;return{origin:n,params:t,path:r}}}catch{throw new Error(`"${e}" is not a valid route pattern`)}}}function Zn(e){const{navigate:t,resolvers:n=[],path:r,previewUrl:i}=e,{state:o}=ae(),a=te(),s=Q({apiVersion:fe}),[c,l]=U(void 0),d=$(void 0),u=L((()=>{var e,t;const n=r||(null==(t=null==(e=o._searchParams)?void 0:e.find((([e])=>"preview"===e)))?void 0:t[1])||"",a="string"==typeof i?i:"object"==typeof i&&(null==i?void 0:i.origin)||location.origin;return new URL(n,a)}),[r,i,o._searchParams]),p=R((()=>{l(void 0),d.current=void 0}),[]);return j((()=>{if(n.length&&u){let c;for(const e of n){const t=Hn(e.route,u);if(t){c={context:t,resolver:e};break}}if(c){const n=function(e,t){var n;if(e.resolve){const r=null==(n=e.resolve(t))?void 0:n.filter;return r?`*[${r}][0]{_id, _type}`:void 0}return"type"in e?`*[_type == "${e.type}"][0]{_id, _type}`:`*[${Xn(e.filter,t)}][0]{_id, _type}`}(c.resolver,c.context),p=(e=c.resolver,r=c.context,e.resolve?null!=(o=null==(i=e.resolve(r))?void 0:i.params)?o:r.params:"type"in e?{}:null!=(a=Xn(e.params,r))?a:r.params);if(n){const e=new AbortController,r={perspective:"previewDrafts",signal:e.signal};return s.fetch(n,p,r).then((e=>{(!e||d.current!==e._id)&&(l({document:e,path:u.pathname}),null==t||t({id:null==e?void 0:e._id,type:null==e?void 0:e._type}),d.current=null==e?void 0:e._id)})).catch((e=>{e instanceof Error&&"AbortError"===e.name||(l({document:void 0,path:u.pathname}),d.current=void 0)})),()=>{e.abort()}}}}var e,r,i,o,a;p()}),[s,p,a,t,n,u]),c}function Qn(e){var t;if(void 0===e)return;const n=null==(t=decodeURIComponent(e))?void 0:t.split(".");return"drafts"===n[0]&&n.shift(),n.join(".")}function Yn(e){if(void 0!==e)return o.toString(function(e){const t=[];for(const n of e.split(".")){const e=It.exec(n);if(e){t.push(e[1],Number(e[2]));continue}const r=zt.exec(n);if(r){t.push(r[1],[Number(r[2]),Number(r[3])]);continue}const i=Dt.exec(n);i?t.push(i[1],{_key:i[2]}):t.push(n)}return t}(decodeURIComponent(e)))}function er(e){return Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e&&""!==e&&null!==e)))}function tr({initialPreviewUrl:e,routerNavigate:t,routerState:n,routerSearchParams:r,frameStateRef:i}){const o=L((()=>{const{id:t,path:i,type:o}={id:Qn((a=n).id),path:Yn(a.path),type:a.type};var a;return{id:t,type:o,path:i,preview:r.preview||`${e.pathname}${e.search}`,perspective:r.perspective,viewport:r.viewport,inspect:r.inspect,rev:r.rev,prefersLatestPublished:r.prefersLatestPublished,since:r.since,template:r.template,templateParams:r.templateParams,view:r.view,pathKey:r.pathKey,instruction:r.instruction,comment:r.comment}}),[n,r,e]),a=L((()=>er({inspect:o.inspect,path:o.path,rev:o.rev,prefersLatestPublished:o.prefersLatestPublished,since:o.since,template:o.template,templateParams:o.templateParams,view:o.view,pathKey:o.pathKey,instruction:o.instruction,comment:o.comment})),[o.comment,o.inspect,o.instruction,o.path,o.pathKey,o.prefersLatestPublished,o.rev,o.since,o.template,o.templateParams,o.view]),s=$(n);j((()=>{s.current=n}),[n]);return{structureParams:a,navigate:R(((e,n={},r)=>{e.id&&(e.id=q(e.id));const{_searchParams:o,...a}=s.current,c=(o||[]).reduce(((e,[t,n])=>(e[t]=n,e)),{}),l=er({...a,...e}),d=er({...c,...n});a.id!==l.id&&(delete d.template,delete d.templateParams),l._searchParams=Object.entries(d).reduce(((e,[t,n])=>[...e,[t,n]]),[]);const u=null!=r?r:d.preview===i.current.url;t(l,{replace:u})}),[t,i]),params:o}}function nr(e,t,n){var r,i;const o=Q({apiVersion:fe}),a=Z(),s=(null==(r=null==a?void 0:a.activeWorkspace)?void 0:r.basePath)||"/",c=(null==(i=null==a?void 0:a.activeWorkspace)?void 0:i.name)||"default",l=function(e,t,n,r){const[i,o]=U((()=>r||"")),a=$(0);j((()=>{if(i&&r)return window.clearTimeout(a.current),()=>{a.current=window.setTimeout((()=>{o("")}),100)}}),[i,r]);const s=Y();return L((()=>["@sanity/presentation",t,n,e,null==s?void 0:s.id,rr,i]),[t,null==s?void 0:s.id,e,n,i])}(t,s,c,n),d=function(e,t){const n=Q({apiVersion:fe}),r=Y(),[i,o]=U(""),a=e?Xe((async()=>await Be(n,"@sanity/presentation",typeof window>"u"?"":location.href,null==r?void 0:r.id)),[...t,i]):null;return j((()=>{if(!a)return;const e=setTimeout((()=>{M((()=>o(a.expiresAt.toString())))}),a.expiresAt.getTime()-Date.now());return()=>clearTimeout(e)}),[a]),(null==a?void 0:a.secret)||null}("object"==typeof e||"function"==typeof e,l);return Xe((async()=>{if("string"==typeof e){const t=new URL(e,location.origin);let r=t;try{if(n){const e=new URL(n,t);e.origin===t.origin&&(r=e)}else if(document.referrer){const e=new URL(document.referrer);e.origin===t.origin&&(r=e)}}catch{}return location.origin!==r.origin||!r.pathname.startsWith(`${s}/`)&&r.pathname!==s?r:t}const t=await("object"==typeof e?Je(e):e)({client:o,previewUrlSecret:d,previewSearchParam:n,referrer:typeof document>"u"?null:document.referrer,studioBasePath:s});return new URL(t,location.origin)}),[...l,d])}const rr=Symbol();const ir=K((()=>import("./LoaderQueries.js"))),or=K((()=>import("./PostMessageRefreshMutations.js"))),ar=ce(c)`
`),Rn=function(e){var t;const{fontSize:r=1,onChange:o,origin:a,padding:s=3,prefix:c,suffix:l,value:d}=e,{t:u}=V(le),{basePath:p="/"}=(null==(t=Z())?void 0:t.activeWorkspace)||{},m=$(null),[f,h]=U(void 0),[v,g]=U(void 0),w=R((e=>{h(e.currentTarget.value)}),[]),b=R((e=>{var t;if("Enter"===e.key){if(void 0===f)return;const e=f.startsWith("/")||""===f?`${a}${f}`:f;if(!e.startsWith(a+"/")&&e!==a)return void g(u("preview-location-input.error",{origin:a,context:"missing-origin"}));if(!a&&(e.startsWith(`${p}/`)||e===p))return void g(u("preview-location-input.error",{basePath:p,context:"same-base-path"}));const n=e===a?a+"/":e;g(void 0),h(void 0),o(n.slice(a.length)),null==(t=m.current)||t.blur()}"Escape"===e.key&&(g(void 0),h(void 0))}),[p,o,a,f,u]),x=R((()=>{g(void 0),h(void 0)}),[]);j((()=>{g(void 0),h(void 0)}),[a,d]);const P=L((()=>({icon:xe})),[]);return n(i,{children:n(y,{clearButton:v?P:void 0,customValidity:v,fontSize:r,onBlur:x,onClear:()=>{g(void 0),h(a+d)},onChange:w,onKeyDownCapture:b,padding:s,prefix:c,style:{zIndex:1},radius:2,ref:m,space:s,suffix:l,value:void 0===f?`${a}${d}`:f})})};function jn(e){const{initialUrl:t,openPopup:o,previewLocationOrigin:a,previewLocationRoute:s}=e,{t:c}=V(le),l=R((e=>{e.preventDefault(),o(e.currentTarget.href)}),[o]);return r(i,{children:[n(Tn,{initialUrl:t,previewLocationOrigin:a,previewLocationRoute:s}),n(w,{icon:Pe,text:c("share-url.menu-item.open.text"),as:"a",href:`${a}${s}`,onClick:l,rel:"opener",target:"_blank"})]})}function Tn(e){const{initialUrl:t,previewLocationOrigin:r,previewLocationRoute:i}=e,{t:o}=V(le),{push:a}=b(),s=Q({apiVersion:fe}),c=Y(),[l,d]=U(!1);return n(w,{disabled:l,onClick:()=>{if(null==navigator||!navigator.clipboard)return a({closable:!0,status:"error",title:o("share-url.clipboard.status",{context:"unsupported"})}),!1;let e;d(!0);const n=`${r}${i}`,l=()=>{a({id:e,closable:!0,status:"success",title:o("share-url.clipboard.status",{context:"success"})}),d(!1)},u=e=>{a({closable:!0,status:"error",title:o("share-url.clipboard.status",{context:"failed"}),description:e.message||e.toString()}),d(!1)};if(We(t)){const n=async()=>{e=a({closable:!0,title:o("share-url.clipboard.status",{context:"copying"})});const n=await Be(s,"@sanity/presentation",typeof window>"u"?"":location.href,null==c?void 0:c.id);return Me(t,n.secret,i).toString()};if(typeof ClipboardItem<"u"){const e="text/plain",t=new ClipboardItem({[e]:n().then((t=>new Blob([t],{type:e})))});navigator.clipboard.write([t]).then(l).catch(u)}else n().then((e=>navigator.clipboard.writeText(e))).then(l).catch(u)}else navigator.clipboard.writeText(n).then(l).catch(u)},text:o("share-url.menu-item.copy.text"),icon:Ee})}const An=Fe(c),Wn={previewDrafts:"preview-frame.perspective.previewDrafts.title",published:"preview-frame.perspective.published.title"},Mn="caution",Nn="positive",Fn={previewDrafts:_e,published:Le},Kn=T((function(e,t){const{dispatch:o,iframe:l,initialUrl:p,loadersConnection:v,navigatorEnabled:g,onPathChange:y,onRefresh:b,openPopup:D,overlaysConnection:C,params:O,perspective:_,targetOrigin:$,toggleNavigator:T,toggleOverlay:A,viewport:M,visualEditing:{overlaysEnabled:N}}=e,{t:F}=V(le),{devMode:K}=de(),B=x(),q=R((()=>o({type:En,viewport:"desktop"})),[o]),G=R((()=>o({type:En,viewport:"mobile"})),[o]),J="loading"===l.status||"reloading"===l.status,[X,H]=U(!1),Z="refreshing"===l.status,[Q,Y]=U(!1),te=J||Z||"connecting"===C,ne=L((()=>$===location.origin?"":$),[$]),re=R((()=>{b((()=>{"function"==typeof t||null==t||!t.current||(o({type:xn}),t.current.src=`${$}${O.preview||"/"}`)}))}),[o,b,O.preview,$,t]),ie=R((()=>{"function"==typeof t||null==t||!t.current||(t.current.src=p.toString(),o({type:xn}))}),[o,t,p]),oe=R((()=>{se(!0)}),[]),[ae,se]=U(!1),[ce,ue]=U(!1);j((()=>{if(!(J||Z||"connecting"!==C&&"reconnecting"!==C)){const e=setTimeout((()=>{ue(!0)}),1e3);return()=>clearTimeout(e)}}),[C,J,Z]),j((()=>{if(!J&&!Z&&ce){if("connected"===C&&(Y(!1),ue(!1),H(!1),se(!1)),"connecting"===C){const e=setTimeout((()=>{H(!0),console.error("Unable to connect to visual editing. Make sure you've setup '@sanity/visual-editing' correctly")}),he);return()=>clearTimeout(e)}if("reconnecting"===C){const e=setTimeout((()=>{H(!0),Y(!0)}),he);return()=>clearTimeout(e)}"disconnected"===C&&Y(!0)}}),[J,C,Z,ce]);const pe=L((()=>{const e=new URL(O.preview||"/",$),{pathname:t,search:n}=Ne(e);return`${t}${n}`}),[O.preview,$]),me=R((()=>{o({type:wn})}),[o]);return j((()=>{if("function"==typeof t||null==t||!t.current)return;const e=t.current;function n(){e===document.activeElement&&e.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0}))}return window.addEventListener("blur",n),()=>{window.removeEventListener("blur",n)}}),[t]),n(Ke,{transition:B?{duration:0}:void 0,children:r(P,{delay:1e3,children:[n(s,{flex:"none",padding:2,shadow:1,style:{position:"relative"},children:r(c,{align:"center",style:{minHeight:0},children:[T&&n(m,{flex:"none",marginRight:1,padding:1,children:n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.navigator.toggle-button.tooltip")}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.navigator.toggle-button.aria-label"),fontSize:1,icon:ke,mode:"bleed",onClick:T,padding:2,selected:g})})}),n(E,{animate:!0,content:r(c,{align:"center",style:{whiteSpace:"nowrap"},children:[n(m,{padding:1,children:n(u,{size:1,children:F("preview-frame.overlay.toggle-button.tooltip",{context:N?"disable":"enable"})})}),n(m,{paddingY:1,children:n(ee,{keys:["Alt"],style:{marginTop:-4,marginBottom:-4}})})]}),fallbackPlacements:["bottom-start"],padding:1,placement:"bottom",portal:!0,children:n(s,{as:"label",flex:"none",marginRight:1,padding:3,style:{lineHeight:0,borderRadius:999,userSelect:"none"},tone:N?"transparent":void 0,children:r(c,{align:"center",gap:3,children:[n("div",{style:{margin:-4},children:n(k,{checked:N,onChange:A,disabled:"loading"===l.status||"connected"!==C})}),n(m,{children:n(u,{muted:!N,size:1,weight:"medium",children:F("preview-frame.overlay.toggle-button.text")})})]})})}),n(m,{flex:1,marginX:1,children:n(Rn,{prefix:n(m,{padding:1,children:n(E,{animate:!0,content:n(u,{size:1,children:"loaded"===l.status?F("preview-frame.refresh-button.tooltip"):F("preview-frame.status",{context:l.status})}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.refresh-button.aria-label"),fontSize:1,icon:Se,mode:"bleed",loading:"reloading"===l.status||"refreshing"===l.status,onClick:re,padding:2})})}),onChange:y,origin:ne,suffix:n(m,{padding:1,children:n(S,{button:n(a,{fontSize:1,iconRight:Ie,mode:"bleed",padding:2,space:2}),id:"location-menu",menu:n(I,{children:n(jn,{initialUrl:p,openPopup:D,previewLocationOrigin:ne,previewLocationRoute:pe})}),popover:{animate:!0,constrainSize:!0,placement:"bottom",portal:!0}})}),value:pe})}),n(c,{align:"center",flex:"none",gap:1,padding:1,children:n(S,{button:n(a,{fontSize:1,iconRight:ze,mode:"bleed",padding:2,space:2,text:F(Wn["connected"===v?_:"previewDrafts"]),loading:"reconnecting"===v&&"loaded"!==l.status,disabled:"connected"!==v}),id:"perspective-menu",menu:r(I,{style:{maxWidth:240},children:[n(w,{fontSize:1,onClick:()=>o({type:Pn,perspective:"previewDrafts"}),padding:3,pressed:"previewDrafts"===_,tone:Mn,children:r(c,{align:"flex-start",gap:3,children:[n(m,{flex:"none",children:n(u,{size:1,children:W(Fn.previewDrafts)})}),r(d,{flex:1,space:2,children:[n(u,{size:1,weight:"medium",children:F(Wn.previewDrafts)}),n(u,{muted:!0,size:1,children:F("preview-frame.perspective.previewDrafts.text")})]}),n(m,{flex:"none",children:n(u,{muted:!0,size:1,style:{opacity:"previewDrafts"===_?1:0},children:n(De,{})})})]})}),n(w,{fontSize:1,onClick:()=>o({type:Pn,perspective:"published"}),padding:3,pressed:"published"===_,tone:Nn,children:r(c,{align:"flex-start",gap:3,children:[n(m,{flex:"none",children:n(u,{size:1,children:W(Fn.published)})}),r(d,{flex:1,space:2,children:[n(u,{size:1,weight:"medium",children:F(Wn.published)}),n(u,{muted:!0,size:1,children:F("preview-frame.perspective.published.text")})]}),n(m,{flex:"none",children:n(u,{muted:!0,size:1,style:{opacity:"published"===_?1:0},children:n(De,{})})})]})})]}),popover:{animate:!0,constrainSize:!0,placement:"bottom",portal:!0}})}),r(c,{align:"center",flex:"none",gap:1,padding:1,children:[n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.viewport-full-button.tooltip")}),fallbackPlacements:["bottom-start"],padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.viewport-full-button.aria-label"),fontSize:1,icon:Ce,mode:"bleed",onClick:q,padding:2,selected:"desktop"===M})}),n(E,{animate:!0,content:n(u,{size:1,children:F("preview-frame.viewport-narrow-button.tooltip")}),padding:2,placement:"bottom",portal:!0,children:n(a,{"aria-label":F("preview-frame.viewport-narrow-button.aria-label"),fontSize:1,icon:Oe,mode:"bleed",onClick:G,padding:2,selected:"mobile"===M})})]})]})}),n(s,{flex:1,tone:"transparent",children:r(c,{align:"center",height:"fill",justify:"center",padding:"desktop"===M?0:2,sizing:"border",style:{position:"relative",cursor:te?"wait":void 0},children:[n(Ve,{children:Q||J||Z||!ce||ae?(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?n(An,{initial:"initial",animate:"animate",exit:"exit",variants:Bn,justify:"center",align:"center",style:{inset:"0",position:"absolute"},children:r(c,{style:{...Vn[M]},justify:"center",align:"center",direction:"column",gap:4,children:[n(z,{muted:!0}),n(u,{muted:!0,size:1,children:F("preview-frame.status",{context:"loading"})})]})}):Q&&!ae?n(An,{initial:"initial",animate:"animate",exit:"exit",variants:qn,justify:"center",align:"center",style:{background:"var(--card-bg-color)",inset:"0",position:"absolute",borderTop:"1px solid transparent",boxShadow:"0 0 0 1px var(--card-border-color)"},children:n(Xt,{flex:1,message:F("preview-frame.connection.error.text"),onRetry:ie,onContinueAnyway:oe,children:K&&r(i,{children:["connected"!==C&&n(s,{padding:3,radius:2,tone:"critical",children:r(d,{space:3,children:[n(h,{muted:!0,size:0,children:F("preview-frame.overlay.connection-status.label")}),n(f,{size:1,children:F("channel.status",{context:C})})]})}),"connected"!==v&&n(s,{padding:3,radius:2,tone:"critical",children:r(d,{space:3,children:[n(h,{muted:!0,size:0,children:F("preview-frame.loader.connection-status.label")}),n(f,{size:1,children:F("channel.status",{context:v})})]})})]})})}):null:n(An,{initial:"initial",animate:"animate",exit:"exit",variants:Bn,justify:"center",align:"center",style:{inset:"0",position:"absolute",backdropFilter:X?"blur(16px) saturate(0.5) grayscale(0.5)":"blur(2px)",transition:"backdrop-filter 0.2s ease-in-out",WebkitBackdropFilter:X?"blur(16px) saturate(0.5) grayscale(0.5)":"blur(2px)",WebkitTransition:"-webkit-backdrop-filter 0.2s ease-in-out",zIndex:1},children:r(c,{style:{...Vn[M]},justify:"center",align:"center",direction:"column",gap:4,children:[X&&n(a,{disabled:!0,fontSize:1,mode:"ghost",text:F("preview-frame.continue-button.text"),style:{opacity:0}}),n(s,{radius:2,tone:X?"caution":"inherit",padding:4,shadow:1,children:r(c,{justify:"center",align:"center",direction:"column",gap:4,children:[n(z,{muted:!0}),n(u,{muted:!0,size:1,children:F("preview-frame.status",X?{context:"timeout"}:{context:"connecting"})})]})}),X&&n(a,{fontSize:1,tone:"critical",onClick:oe,text:F("preview-frame.continue-button.text")})]})})}),n(Un,{ref:t,style:{pointerEvents:(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?"none":"auto",boxShadow:"0 0 0 1px var(--card-border-color)",borderTop:"1px solid transparent"},src:p.toString(),initial:["background"],variants:Gn,animate:[(J||"connecting"===C&&"refreshing"!==l.status)&&!ae?"background":"active",J?"reloading":"idle",M,ce&&!ae?"timedOut":""],onLoad:me})]})})]})})})),Vn={desktop:{width:"100%",height:"100%"},mobile:{width:375,height:650}},Bn={initial:{opacity:1},animate:{opacity:[0,0,1]},exit:{opacity:[1,0,0]}},qn={initial:{opacity:1},animate:{opacity:[0,0,1]},exit:{opacity:[1,0,0]}},Gn={desktop:{...Vn.desktop,boxShadow:"0 0 0 0px var(--card-border-color)"},mobile:{...Vn.mobile,boxShadow:"0 0 0 1px var(--card-border-color)"},background:{opacity:0,scale:1},idle:{scale:1},reloading:{scale:[1,1,1,.98]},active:{opacity:[0,0,1],scale:1},timedOut:{opacity:[0,0,1]}};let Jn=!1;function Xn(e,t){return e instanceof Function?e(t):e}function Hn(e,t){const n=Array.isArray(e)?e:[e];for(e of n){let n,r=e;if("string"==typeof e)try{const t=new URL(e);n=t.origin,r=t.pathname}catch{}if(!n||t.origin===n)try{const e=Ge(r,{decode:decodeURIComponent})(t.pathname);if(e){const{params:t,path:r}=e;return{origin:n,params:t,path:r}}}catch{throw new Error(`"${e}" is not a valid route pattern`)}}}function Zn(e){const{navigate:t,resolvers:n=[],path:r,previewUrl:i}=e,{state:o}=ae(),a=te(),s=Q({apiVersion:fe}),[c,l]=U(void 0),d=$(void 0),u=L((()=>{var e,t;const n=r||(null==(t=null==(e=o._searchParams)?void 0:e.find((([e])=>"preview"===e)))?void 0:t[1])||"",a="string"==typeof i?i:"object"==typeof i&&(null==i?void 0:i.origin)||location.origin;return new URL(n,a)}),[r,i,o._searchParams]),p=R((()=>{l(void 0),d.current=void 0}),[]);return j((()=>{if(n.length&&u){let c;for(const e of n){const t=Hn(e.route,u);if(t){c={context:t,resolver:e};break}}if(c){const n=function(e,t){var n;if(e.resolve){const r=null==(n=e.resolve(t))?void 0:n.filter;return r?`*[${r}][0]{_id, _type}`:void 0}return"type"in e?`*[_type == "${e.type}"][0]{_id, _type}`:`*[${Xn(e.filter,t)}][0]{_id, _type}`}(c.resolver,c.context),p=(e=c.resolver,r=c.context,e.resolve?null!=(o=null==(i=e.resolve(r))?void 0:i.params)?o:r.params:"type"in e?{}:null!=(a=Xn(e.params,r))?a:r.params);if(n){const e=new AbortController,r={perspective:"previewDrafts",signal:e.signal};return s.fetch(n,p,r).then((e=>{(!e||d.current!==e._id)&&(l({document:e,path:u.pathname}),null==t||t({id:null==e?void 0:e._id,type:null==e?void 0:e._type}),d.current=null==e?void 0:e._id)})).catch((e=>{e instanceof Error&&"AbortError"===e.name||(l({document:void 0,path:u.pathname}),d.current=void 0)})),()=>{e.abort()}}}}var e,r,i,o,a;p()}),[s,p,a,t,n,u]),c}function Qn(e){var t;if(void 0===e)return;const n=null==(t=decodeURIComponent(e))?void 0:t.split(".");return"drafts"===n[0]&&n.shift(),n.join(".")}function Yn(e){if(void 0!==e)return o.toString(function(e){const t=[];for(const n of e.split(".")){const e=It.exec(n);if(e){t.push(e[1],Number(e[2]));continue}const r=zt.exec(n);if(r){t.push(r[1],[Number(r[2]),Number(r[3])]);continue}const i=Dt.exec(n);i?t.push(i[1],{_key:i[2]}):t.push(n)}return t}(decodeURIComponent(e)))}function er(e){return Object.fromEntries(Object.entries(e).filter((([,e])=>void 0!==e&&""!==e&&null!==e)))}function tr({initialPreviewUrl:e,routerNavigate:t,routerState:n,routerSearchParams:r,frameStateRef:i}){const o=L((()=>{const{id:t,path:i,type:o}={id:Qn((a=n).id),path:Yn(a.path),type:a.type};var a;return{id:t,type:o,path:i,preview:r.preview||`${e.pathname}${e.search}`,perspective:r.perspective,viewport:r.viewport,inspect:r.inspect,rev:r.rev,prefersLatestPublished:r.prefersLatestPublished,since:r.since,template:r.template,templateParams:r.templateParams,view:r.view,pathKey:r.pathKey,instruction:r.instruction,comment:r.comment}}),[n,r,e]),a=L((()=>er({inspect:o.inspect,path:o.path,rev:o.rev,prefersLatestPublished:o.prefersLatestPublished,since:o.since,template:o.template,templateParams:o.templateParams,view:o.view,pathKey:o.pathKey,instruction:o.instruction,comment:o.comment})),[o.comment,o.inspect,o.instruction,o.path,o.pathKey,o.prefersLatestPublished,o.rev,o.since,o.template,o.templateParams,o.view]),s=$(n);j((()=>{s.current=n}),[n]);return{structureParams:a,navigate:R(((e,n={},r)=>{e.id&&(e.id=q(e.id));const{_searchParams:o,...a}=s.current,c=(o||[]).reduce(((e,[t,n])=>(e[t]=n,e)),{}),l=er({...a,...e}),d=er({...c,...n});a.id!==l.id&&(delete d.template,delete d.templateParams),l._searchParams=Object.entries(d).reduce(((e,[t,n])=>[...e,[t,n]]),[]);const u=null!=r?r:d.preview===i.current.url;t(l,{replace:u})}),[t,i]),params:o}}function nr(e,t,n){var r,i;const o=Q({apiVersion:fe}),a=Z(),s=(null==(r=null==a?void 0:a.activeWorkspace)?void 0:r.basePath)||"/",c=(null==(i=null==a?void 0:a.activeWorkspace)?void 0:i.name)||"default",l=function(e,t,n,r){const[i,o]=U((()=>r||"")),a=$(0);j((()=>{if(i&&r)return window.clearTimeout(a.current),()=>{a.current=window.setTimeout((()=>{o("")}),100)}}),[i,r]);const s=Y();return L((()=>["@sanity/presentation",t,n,e,null==s?void 0:s.id,rr,i]),[t,null==s?void 0:s.id,e,n,i])}(t,s,c,n),d=function(e,t){const n=Q({apiVersion:fe}),r=Y(),[i,o]=U(""),a=e?Xe((async()=>await Be(n,"@sanity/presentation",typeof window>"u"?"":location.href,null==r?void 0:r.id)),[...t,i]):null;return j((()=>{if(!a)return;const e=setTimeout((()=>{M((()=>o(a.expiresAt.toString())))}),a.expiresAt.getTime()-Date.now());return()=>clearTimeout(e)}),[a]),(null==a?void 0:a.secret)||null}("object"==typeof e||"function"==typeof e,l);return Xe((async()=>{if("string"==typeof e){const t=new URL(e,location.origin);let r=t;try{if(n){const e=new URL(n,t);e.origin===t.origin&&(r=e)}else if(document.referrer){const e=new URL(document.referrer);e.origin===t.origin&&(r=e)}}catch{}return location.origin!==r.origin||!r.pathname.startsWith(`${s}/`)&&r.pathname!==s?r:t}const t=await("object"==typeof e?Je(e):e)({client:o,previewUrlSecret:d,previewSearchParam:n,referrer:typeof document>"u"?null:document.referrer,studioBasePath:s});return new URL(t,location.origin)}),[...l,d])}const rr=Symbol();const ir=K((()=>import("./LoaderQueries.js"))),or=K((()=>import("./PostMessageRefreshMutations.js"))),ar=ce(c)`
overflow-x: auto;
`;function sr(e){var t,a,s,l;const{previewUrl:d,components:u}=null!=(t=e.tool.options)?t:{},p=e.tool.name||we,{unstable_navigator:m}=u||{},{navigate:f,state:h}=ae(),v=B(Object.fromEntries(h._searchParams||[])),g=nr(d||"/",p,v.preview||null),[y]=U((()=>{var t;const n=null==(t=e.tool.options)?void 0:t.devMode;return"function"==typeof n?n():"boolean"==typeof n?n:typeof window<"u"&&"localhost"===window.location.hostname})),w=L((()=>g.origin),[g.origin]),b=$(null),[x,P]=U(),[E,k]=U({}),S=$({title:void 0,url:void 0}),{navigate:I,params:z,structureParams:C}=tr({initialPreviewUrl:g,routerNavigate:f,routerState:h,routerSearchParams:v,frameStateRef:S}),O=L((()=>Lt(I,50)),[I]),[_,T]=N(Sn,{perspective:z.perspective,viewport:z.viewport},$n),[A,W]=function(e,t){if("published"!==e&&"previewDrafts"!==e)throw new Error(`Invalid perspective: ${e}`);const[n,r]=U({}),[i,o]=U({}),a=$(""),s=R(((e,n,i=[])=>{const s=i.filter((e=>"_projectId"in e&&e._projectId?(Jn||(console.warn("Cross dataset references are not supported yet, ignoring source document",e),Jn=!0),!1):e));("published"===n?r:o)((n=>{const r={};for(const e of s)r[e._id]=e;if(a.current!==t.current.url)return a.current=t.current.url,{[e]:r};const i=n[e];return qe(i,r)?n:{...n,[e]:r}}))}),[t]);return[L((()=>{const t=Object.values("published"===e?n:i).reduce(((e,t)=>(Object.values(t).forEach((t=>{e[t._id]=t})),e)),{});return Object.values(t)}),[e,i,n]),s]}(_.perspective,S),M=ne(),K=re(),V=Zn({resolvers:null==(s=null==(a=e.tool.options)?void 0:a.resolve)?void 0:s.mainDocuments,previewUrl:null==(l=e.tool.options)?void 0:l.previewUrl,path:z.preview,navigate:I});j((()=>{(_.perspective!==z.perspective||_.viewport!==z.viewport)&&O({},{perspective:"previewDrafts"===_.perspective?void 0:_.perspective,viewport:"desktop"===_.viewport?void 0:_.viewport})}),[z.perspective,_.perspective,O,_.viewport,z.viewport,z.rev,z.prefersLatestPublished]);const[q,G]=U("connecting"),[J,X]=U("connecting"),[H,Z]=U("connecting"),[Q]=U((()=>new Set)),Y=R((e=>{const t=window.open(e,"_blank");t&&Q.add(t)}),[Q]);j((()=>{if(Q.size&&x)for(const e of Q)e&&"closed"in e&&!e.closed&&x.addSource(e)}),[x,Q,Q.size]);const ee=$(_.perspective);j((()=>{ee.current=_.perspective}),[_.perspective]),j((()=>{var e;const t=null==(e=b.current)?void 0:e.contentWindow;if(!t)return;const n=function(e){const{destroy:t,send:n}=ct(e),r=new Set,i=new WeakMap,o=new Set;return{destroy:()=>{t();for(const e of o)e()},send:(e,...t)=>{n(e,...t);for(const n of r)n&&"closed"in n&&!n.closed&&i.has(n)&&i.get(n)(e,...t)},addSource(t){if(r.has(t))return;if(!("closed"in t))throw console.warn("Source is unsupported",{source:t}),new Error("Source is unsupported");if(t.closed)throw new Error("Source is closed");const{send:n,destroy:a}=ct({...e,target:t,connectTo:e.connectTo.map((e=>{const{onStatusUpdate:t,onEvent:n,...r}=e;return{...r,onEvent:n?(...e)=>{const[t]=e;if("preview-kit/documents"!==t&&"overlay/navigate"!==t&&"loader/documents"!==t)return n(...e)}:void 0}}))});o.add(a),i.set(t,n),r.add(t)}}}({id:"presentation",target:t,targetOrigin:w,connectTo:[{id:"overlays",heartbeat:!0,onStatusUpdate:G,onEvent(e,t){if("visual-editing/focus"!==e&&"overlay/focus"!==e||!("id"in t))if("visual-editing/navigate"===e||"overlay/navigate"===e){const{title:e,url:n}=t;S.current.url!==n&&O({},{preview:n}),S.current={title:e,url:n}}else"visual-editing/meta"===e?S.current.title=t.title:"visual-editing/toggle"===e||"overlay/toggle"===e?T({type:kn,enabled:t.enabled}):"visual-editing/documents"===e?W("visual-editing",t.perspective,t.documents):"visual-editing/refreshing"===e&&"manual"===t.source?clearTimeout(xe.current):"visual-editing/refreshing"===e&&"mutation"===t.source?T({type:bn}):"visual-editing/refreshed"===e&&T({type:wn});else O({type:t.type,id:t.id,path:t.path},{prefersLatestPublished:"isDraft"in t||"previewDrafts"===ee.current?void 0:"true"})}},{id:"loaders",heartbeat:!0,onStatusUpdate:X,onEvent(e,t){if("loader/documents"===e&&t.projectId===M&&t.dataset===K)W("loaders",t.perspective,t.documents);else if("loader/query-listen"===e&&t.projectId===M&&t.dataset===K){if("number"==typeof t.heartbeat&&t.heartbeat<ve)throw new Error(`Loader query listen heartbeat interval must be at least ${ve}ms`);k((e=>{var n;return{...e,[Ct(t.query,t.params)]:{perspective:t.perspective,query:t.query,params:t.params,receivedAt:Date.now(),heartbeat:null!=(n=t.heartbeat)&&n}}}))}}},{id:"preview-kit",heartbeat:!0,onStatusUpdate:Z,onEvent(e,t){"preview-kit/documents"===e&&t.projectId===M&&t.dataset===K&&W("preview-kit",t.perspective,t.documents)}}]});return P(n),()=>{n.destroy(),P(void 0)}}),[K,M,W,O,w]),j((()=>{const e=setInterval((()=>k((e=>{if(Object.keys(e).length<1)return e;const t=Date.now();if(!Object.values(e).some((e=>!1!==e.heartbeat&&t>e.receivedAt+e.heartbeat)))return e;const n={};for(const[r,i]of Object.entries(e))!1!==i.heartbeat&&t>i.receivedAt+i.heartbeat||(n[r]=i);return n}))),ve);return()=>clearInterval(e)}),[]);const te=R((e=>{O({path:o.toString(e)},{},!0)}),[O]),oe=R((e=>{const t=new URL(e,g.origin),n=t.pathname+t.search;t.origin===g.origin&&n!==z.preview&&O({},{preview:n})}),[g,z,O]),se=R((e=>{O({},e)}),[O]);j((()=>{null==x||x.send("overlays","presentation/perspective",{perspective:_.perspective})}),[x,_.perspective]),j((()=>{z.id&&z.path?null==x||x.send("overlays","presentation/focus",{id:z.id,path:z.path}):null==x||x.send("overlays","presentation/blur",void 0)}),[x,z.id,z.path]),j((()=>{"published"===_.perspective&&z.id&&!z.rev&&!z.prefersLatestPublished&&O({},{prefersLatestPublished:"true"})}),[O,z.id,z.prefersLatestPublished,z.rev,_.perspective]),j((()=>{S.current.url&&z.preview&&S.current.url!==z.preview&&(S.current.url=z.preview,"connected"!==q&&b.current?b.current.src=`${w}${z.preview}`:null==x||x.send("overlays","presentation/navigate",{url:z.preview,type:"replace"}))}),[x,q,w,z.preview]);const ce=R((()=>null==x?void 0:x.send("overlays","presentation/toggleOverlay",void 0)),[x]),[le,de]=U(null);j((()=>{const e=e=>{_t(e)&&ce()},t=e=>{var t;_t(e)&&ce(),t=e,["mod","\\"].every((e=>Ot[e]?t[Ot[e]]:t.key===e.toUpperCase()))&&ce()};return window.addEventListener("keydown",t),window.addEventListener("keyup",e),()=>{window.removeEventListener("keydown",t),window.removeEventListener("keyup",e)}}),[ce]);const[ue,pe]=U(null),[{navigatorEnabled:me,toggleNavigator:fe},he]=hn({unstable_navigator:m}),be=$(z.id);j((()=>{z.rev&&be.current&&z.id!==be.current&&O({},{rev:void 0}),be.current=z.id}));const xe=$(),Pe=R((e=>{if(T({type:bn}),x)return xe.current=window.setTimeout(e,300),void x.send("overlays","presentation/refresh",{source:"manual",livePreviewEnabled:"connected"===H||"connected"===J});e()}),[x,J,H]),Ee=ie(),ke=R((({id:e,type:t,path:n})=>{if(S.current.url)return{title:S.current.title||S.current.url,name:"edit",params:{id:e,path:n,type:t,inspect:ge,workspace:Ee.name,mode:ye,preview:z.preview}}}),[z.preview,Ee.name]);return r(i,{children:[n(yn,{devMode:y,name:p,navigate:O,params:z,structureParams:C,children:n(fn,{navigate:O,children:n(gn,{params:z,children:n(ar,{height:"fill",children:r(Jt,{children:[n(he,{}),n(Rt,{id:"preview",minWidth:325,defaultSize:me?50:75,order:3,children:n(c,{direction:"column",flex:1,height:"fill",ref:pe,children:n(D,{element:ue,children:n(Kn,{dispatch:T,iframe:_.iframe,initialUrl:g,loadersConnection:J,navigatorEnabled:me,onPathChange:oe,onRefresh:Pe,openPopup:Y,overlaysConnection:q,params:z,perspective:_.perspective,ref:b,targetOrigin:w,toggleNavigator:fe,toggleOverlay:ce,viewport:_.viewport,visualEditing:_.visualEditing})})})}),n(mn,{mainDocumentState:V,params:z,documentsOnPage:A,getCommentIntent:ke,onFocusPath:te,onStructureParams:se,setDisplayedDocument:de,structureParams:C})]})})})})}),x&&n(F,{children:n(ir,{channel:x,liveQueries:E,perspective:_.perspective,liveDocument:le,documentsOnPage:A})}),x&&z.id&&z.type&&n(F,{children:n(or,{channel:x,id:z.id,type:z.type,loadersConnection:J,previewKitConnection:H})})]})}export{sr as default};//# sourceMappingURL=PresentationTool.js.map
{
"name": "@sanity/presentation",
"version": "1.15.12",
"version": "1.15.13",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/presentation#readme",

@@ -5,0 +5,0 @@ "bugs": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc