Socket
Socket
Sign inDemoInstall

@sanity/presentation

Package Overview
Dependencies
Maintainers
56
Versions
135
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.16.4 to 1.16.5

6

dist/_chunks-es/index.js

@@ -1,3 +0,3 @@

import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useMemo as i,useEffect as o,createContext as s,useContext as c,useCallback as a,createElement as l,useRef as d,useLayoutEffect as p,lazy as u,Suspense as m}from"react";import{useDocumentStore as h,isRecord as f,isReference as y,defineLocaleResourceBundle as g,useTranslation as v,defineDocumentFieldAction as w,useWorkspace as b,pathToString as _,getPublishedId as P,definePlugin as j,isDocumentSchemaType as x}from"sanity";import{ComposeIcon as I,InfoOutlineIcon as T,ChevronRightIcon as S,DesktopIcon as O,WarningOutlineIcon as k,ErrorOutlineIcon as z,MasterDetailIcon as D}from"@sanity/icons";import{Card as A,Flex as E,Box as $,Text as C,Spinner as B,Stack as R,rem as U}from"@sanity/ui";import{styled as H}from"styled-components";import L from"lodash.get";import{Observable as N,switchMap as M,isObservable as Q,from as q,map as F,of as G,combineLatest as J,mergeAll as K,scan as V}from"rxjs";import{useIntentLink as W,useRouter as X,encodeJsonParams as Y,route as Z}from"sanity/router";import{uuid as ee}from"@sanity/uuid";const te=I,ne="presentation",re="Presentation",ie="sanity/structure/comments",oe="presentation",se=3e3,ce="2023-10-16",ae=1e3,le=100,de=2048;function pe(e,t,n){return{...e,[t]:n}}function ue(e={}){return t=>new N((e=>t.subscribe(e))).pipe(M((t=>{const n=(r=t,Object.keys(r)).map((e=>{const n=t[e];return Q(n)?q(n).pipe(F((t=>[e,t]))):G([e,n])}));var r;return e.wait?J(n).pipe(F((e=>e.reduce(((e,[t,n])=>pe(e,t,n)),{})))):q(n).pipe(K(),V(((e,[t,n])=>pe(e,t,n)),{}))})))}const me={locations:[]};function he(e,t,n){if(!e||"object"!=typeof e)return G(e);const r=function(e){return y(e)?e._ref:"_id"in e?e._id:void 0}(e),i=function(e,t){const n=e?{...t,_id:e}:{...t};return"reference"===n._type&&(delete n._type,delete n._ref,delete n._weak,delete n._dataset,delete n._projectId,delete n._strengthenOnPublish),n}(r,e),o=t.filter((e=>!(e[0]in i)));if(r&&o.length){return function(e,t,n){const r=`*[_id==$id][0]{${t.join(", ")}}`,i={id:e};return n.listenQuery(r,i,{perspective:"previewDrafts"})}(r,[...new Set(o.map((e=>e[0])))],n).pipe(M((e=>e?he(e,t,n):G(null))))}const s={};t.forEach((e=>{const[t,...n]=e;s[t]||(s[t]=[]),s[t].push(n)}));const c=Object.keys(s).reduce(((t,r)=>{const i=s[r].filter((e=>e.length>0));return 0===i.length?t[r]=f(e)?e[r]:void 0:t[r]=he(e[r],i,n),t}),i);return G(c).pipe(ue({wait:!0}))}function fe(e){const{id:t,resolvers:n,type:s}=e,c=h(),[a,l]=r(me),d=n&&("function"==typeof n?n:n[s]),[p,u]=r(d?"resolving":"empty"),m=i((()=>{if(d){if("function"==typeof d){const e=d({id:t,type:s},{documentStore:c});return Q(e)?e:G(e)}return"select"in d&&"resolve"in d?function(e,t,n){const{select:r}=t;return he({_type:"reference",_ref:e},Object.values(r).map((e=>String(e).split(".")))||[],n).pipe(F((e=>Object.keys(r).reduce(((t,n)=>(t[n]=L(e,r[n]),t)),{}))),F(t.resolve))}(t,d,c):G(d)}}),[c,t,d,s]);return o((()=>{const e=m?.subscribe((e=>{l(e||me),u(e?"resolved":"empty")}));return()=>e?.unsubscribe()}),[m]),{state:a,status:p}}const ye="presentation",ge=g({locale:"en-US",namespace:ye,resources:()=>import("./resources.js")}),ve=s(null);function we(){const e=c(ve);if(!e)throw new Error("Presentation context is missing");return e}const be={positive:T,caution:k,critical:z};function _e(i){const{documentId:o,isResolving:s,options:d,schemaType:p,showPresentationTitle:u}=i,{locations:m,message:h,tone:f}=i.state,y=m?.length||0,{t:g}=v(ye),w=c(ve),[b,_]=r(!1),P=a((()=>{y&&_((e=>!e))}),[y]),j=s?g("locations-banner.resolving.text"):h||g("locations-banner.locations-count",{count:y});return e(A,{padding:1,radius:2,border:!0,tone:f,children:t("div",{style:{margin:-1},children:[!m&&t(E,{align:"flex-start",gap:3,padding:3,children:[f&&e($,{flex:"none",children:e(C,{size:1,children:l(be[f])})}),e($,{flex:1,children:t(C,{size:1,weight:"medium",children:[u&&t(n,{children:[d.title||re," · "]}),j]})})]}),m&&t(n,{children:[e(A,{as:y?"button":void 0,onClick:P,padding:3,radius:1,tone:"inherit",children:t(E,{gap:3,children:[e($,{flex:"none",children:s?e(B,{size:1}):e(C,{size:1,children:0===y?e(T,{}):e(S,{style:{transform:`rotate(${b?"90deg":0})`,transition:"transform 100ms ease-in-out"}})})}),e($,{flex:1,children:t(C,{size:1,weight:"medium",children:[u&&t(n,{children:[d.title||re," · "]}),j]})})]})}),e(R,{hidden:!b,marginTop:1,space:1,children:m.map(((t,n)=>e(Pe,{active:(d.name||ne)===w?.name&&t.href===w?.params.preview,documentId:o,documentType:p.name,node:t,toolName:d.name||ne},n)))})]})]})})}function Pe(n){const{documentId:r,documentType:i,node:o,active:s,toolName:d}=n,p=c(ve),u=d===function(){try{return we().name}catch{return}}(),m=p?.navigate,h=W({intent:"edit",params:{id:r,type:i,mode:"presentation",presentation:d,...p?.structureParams,preview:o.href}}),f=a((()=>{m?.({},{preview:o.href})}),[o.href,m]);return l(A,{...u?{}:h,as:"a",key:o.href,onClick:u?f:h.onClick,padding:3,radius:1,pressed:s,tone:"inherit"},t(E,{gap:3,children:[e($,{flex:"none",children:e(C,{size:1,children:e(O,{})})}),t(R,{flex:1,space:2,children:[e(C,{size:1,weight:"medium",children:o.title}),e(C,{muted:!0,size:1,textOverflow:"ellipsis",children:o.href})]})]}))}const je=s(null),xe=H(R)`
min-height: ${U(42)};
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useMemo as i,useEffect as o,createContext as s,useContext as c,useCallback as a,createElement as l,useRef as d,useLayoutEffect as p,lazy as u,Suspense as m}from"react";import{useDocumentStore as h,isRecord as f,isReference as y,defineLocaleResourceBundle as v,useTranslation as g,defineDocumentFieldAction as w,useWorkspace as b,pathToString as _,getPublishedId as P,definePlugin as j,isDocumentSchemaType as x}from"sanity";import{ComposeIcon as I,InfoOutlineIcon as T,ChevronRightIcon as S,DesktopIcon as O,WarningOutlineIcon as k,ErrorOutlineIcon as z,MasterDetailIcon as D}from"@sanity/icons";import{Card as A,Flex as E,Box as $,Text as C,Spinner as R,Stack as U,rem as B}from"@sanity/ui";import{styled as L}from"styled-components";import H from"lodash.get";import{Observable as N,switchMap as M,isObservable as Q,from as q,map as F,of as G,combineLatest as J,mergeAll as K,scan as V}from"rxjs";import{useIntentLink as W,useRouter as X,encodeJsonParams as Y,route as Z}from"sanity/router";import{uuid as ee}from"@sanity/uuid";const te=I,ne="presentation",re="Presentation",ie="sanity/structure/comments",oe="presentation",se=3e3,ce="2023-10-16",ae=1e3,le=100,de=2048;function pe(e,t,n){return{...e,[t]:n}}function ue(e={}){return t=>new N((e=>t.subscribe(e))).pipe(M((t=>{const n=(r=t,Object.keys(r)).map((e=>{const n=t[e];return Q(n)?q(n).pipe(F((t=>[e,t]))):G([e,n])}));var r;return e.wait?J(n).pipe(F((e=>e.reduce(((e,[t,n])=>pe(e,t,n)),{})))):q(n).pipe(K(),V(((e,[t,n])=>pe(e,t,n)),{}))})))}const me={locations:[]};function he(e,t,n){if(!e||"object"!=typeof e)return G(e);const r=function(e){return y(e)?e._ref:"_id"in e?e._id:void 0}(e),i=function(e,t){const n=e?{...t,_id:e}:{...t};return"reference"===n._type&&(delete n._type,delete n._ref,delete n._weak,delete n._dataset,delete n._projectId,delete n._strengthenOnPublish),n}(r,e),o=t.filter((e=>!(e[0]in i)));if(r&&o.length){return function(e,t,n){const r=`*[_id==$id][0]{${t.join(", ")}}`,i={id:e};return n.listenQuery(r,i,{perspective:"previewDrafts"})}(r,[...new Set(o.map((e=>e[0])))],n).pipe(M((e=>e?he(e,t,n):G(null))))}const s={};t.forEach((e=>{const[t,...n]=e;s[t]||(s[t]=[]),s[t].push(n)}));const c=Object.keys(s).reduce(((t,r)=>{const i=s[r].filter((e=>e.length>0));return 0===i.length?t[r]=f(e)?e[r]:void 0:t[r]=he(e[r],i,n),t}),i);return G(c).pipe(ue({wait:!0}))}function fe(e){const{id:t,resolvers:n,type:s}=e,c=h(),[a,l]=r(me),d=n&&("function"==typeof n?n:n[s]),[p,u]=r(d?"resolving":"empty"),m=i((()=>{if(d){if("function"==typeof d){const e=d({id:t,type:s},{documentStore:c});return Q(e)?e:G(e)}return"select"in d&&"resolve"in d?function(e,t,n){const{select:r}=t;return he({_type:"reference",_ref:e},Object.values(r).map((e=>String(e).split(".")))||[],n).pipe(F((e=>Object.keys(r).reduce(((t,n)=>(t[n]=H(e,r[n]),t)),{}))),F(t.resolve))}(t,d,c):G(d)}}),[c,t,d,s]);return o((()=>{const e=m?.subscribe((e=>{l(e||me),u(e?"resolved":"empty")}));return()=>e?.unsubscribe()}),[m]),{state:a,status:p}}const ye="presentation",ve=v({locale:"en-US",namespace:ye,resources:()=>import("./resources.js")}),ge=s(null);function we(){const e=c(ge);if(!e)throw new Error("Presentation context is missing");return e}const be={positive:T,caution:k,critical:z};function _e(i){const{documentId:o,isResolving:s,options:d,schemaType:p,showPresentationTitle:u}=i,{locations:m,message:h,tone:f}=i.state,y=m?.length||0,{t:v}=g(ye),w=c(ge),[b,_]=r(!1),P=a((()=>{y&&_((e=>!e))}),[y]),j=s?v("locations-banner.resolving.text"):h||v("locations-banner.locations-count",{count:y});return e(A,{padding:1,radius:2,border:!0,tone:f,children:t("div",{style:{margin:-1},children:[!m&&t(E,{align:"flex-start",gap:3,padding:3,children:[f&&e($,{flex:"none",children:e(C,{size:1,children:l(be[f])})}),e($,{flex:1,children:t(C,{size:1,weight:"medium",children:[u&&t(n,{children:[d.title||re," · "]}),j]})})]}),m&&t(n,{children:[e(A,{as:y?"button":void 0,onClick:P,padding:3,radius:1,tone:"inherit",children:t(E,{gap:3,children:[e($,{flex:"none",children:s?e(R,{size:1}):e(C,{size:1,children:0===y?e(T,{}):e(S,{style:{transform:`rotate(${b?"90deg":0})`,transition:"transform 100ms ease-in-out"}})})}),e($,{flex:1,children:t(C,{size:1,weight:"medium",children:[u&&t(n,{children:[d.title||re," · "]}),j]})})]})}),e(U,{hidden:!b,marginTop:1,space:1,children:m.map(((t,n)=>e(Pe,{active:(d.name||ne)===w?.name&&t.href===w?.params.preview,documentId:o,documentType:p.name,node:t,toolName:d.name||ne},n)))})]})]})})}function Pe(n){const{documentId:r,documentType:i,node:o,active:s,toolName:d}=n,p=c(ge),u=d===function(){try{return we().name}catch{return}}(),m=p?.navigate,h=W({intent:"edit",params:{id:r,type:i,mode:"presentation",presentation:d,...p?.structureParams,preview:o.href}}),f=a((()=>{m?.({},{preview:o.href})}),[o.href,m]);return l(A,{...u?{}:h,as:"a",key:o.href,onClick:u?f:h.onClick,padding:3,radius:1,pressed:s,tone:"inherit"},t(E,{gap:3,children:[e($,{flex:"none",children:e(C,{size:1,children:e(O,{})})}),t(U,{flex:1,space:2,children:[e(C,{size:1,weight:"medium",children:o.title}),e(C,{muted:!0,size:1,textOverflow:"ellipsis",children:o.href})]})]}))}const je=s(null),xe=L(U)`
min-height: ${B(42)};

@@ -7,2 +7,2 @@ & + &:empty {

}
`;function Ie(t){const{documentId:n,options:r,schemaType:i}=t,o=c(je),{state:s,status:a}=fe({id:n,resolvers:r.resolve?.locations||r.locate,type:i.name});if(o&&o.options[0]!==r||"empty"===a)return null;const l=o?.options||[];return e(xe,{marginBottom:5,space:5,children:e(R,{space:2,children:l.map(((t,r)=>e(_e,{documentId:n,isResolving:"resolving"===a,options:t,schemaType:i,showPresentationTitle:l.length>1,state:s},r)))})})}function Te(t){const{children:n,options:o}=t,s=c(je),l=s?.register,[u,m]=r((()=>[])),h=a((e=>l?l(e):(m((t=>[e].concat(t))),()=>{m((t=>t.filter((t=>t!==e))))})),[l]),f=d(h);f.current=h;const y=i((()=>({options:s?.options||u,register:h})),[u,s,h]);return p((()=>f.current(o)),[o]),e(je.Provider,{value:y,children:n})}const Se=w({name:"presentation/openInStructure",useAction({documentId:e,documentType:t,path:n}){const r=b(),{navigateIntent:o}=X(),s=c(ve),a=i((()=>function(e,t,n){const r=e.map((e=>{const r=e.canHandleIntent?.("edit",{id:t,type:n,mode:"structure"},{});return{tool:e,match:r}})),i=r.filter((e=>f(e.match)&&e.match.mode));return i.length>0?i[0].tool:r.filter((e=>e.match))[0]?.tool}(r.tools,e,t)),[e,t,r.tools]);return{type:"action",hidden:!s||n.length>0||!a,icon:a?.icon||D,title:`Open in ${a?.title||"Structure"}`,onAction(){o("edit",{id:e,type:t,mode:"structure",path:_(n)})},renderAsButton:!0}}});const Oe=["preview","perspective","viewport"];function ke(e,t,n,r){const{id:i,mode:o,path:s,presentation:c,type:a,...l}=t,d={...(n?._searchParams||[]).filter((([e])=>Oe.includes(e))).reduce(((e,[t,n])=>({...e,[t]:n})),{}),...l};return"edit"===e&&i?{type:a||"*",id:P(i),path:s,_searchParams:Object.entries(d)}:"create"===e?(d.preview=d.preview||new URLSearchParams(window.location.search).get("preview")||"/",r&&"object"==typeof r&&(d.templateParams=Y(r)),{type:a||"*",id:i||ee(),_searchParams:Object.entries(d)}):{intent:e,params:t,payload:r}}const ze=Z.create("/",{__unsafe_disableScopedSearchParams:!0},[Z.intents("/intent"),Z.create(":type",[Z.create(":id",[Z.create(":path")])])]),De=u((()=>import("./PresentationTool.js"))),Ae=u((()=>import("./BroadcastDisplayedDocument.js")));function Ee(e){return e}function $e(e){return e}const Ce=j((n=>{const r=n.name||ne;"locate"in n&&console.warn("Presentation’s `locate` option is deprecated. Use `resolve.locations` instead.");const i=!(!n.resolve?.locations&&!n.locate);return{i18n:{bundles:[ge]},document:{unstable_fieldActions:e=>[...e.filter((e=>e.name!==Se.name)),Se]},form:{components:{input:function(r){const o=r.value,s=o?._id?P(o?._id):void 0;return x(r.schemaType)?t(Te,{options:n,children:[i&&s&&e(Ie,{documentId:s,options:n,schemaType:r.schemaType}),r.renderDefault(r),e(m,{children:e(Ae,{value:o},s)},"broadcast-displayed-document")]}):r.renderDefault(r)}}},tools:[{icon:n.icon||te,name:r,title:n.title,component:De,options:n,canHandleIntent:(e,t)=>"create"===e?function(e){return"type"in e&&(!("presentation"in e)||e.presentation===r)&&(!("template"in e)||{template:!0})}(t):"edit"===e&&function(e){return"type"in e&&"id"in e&&(!("presentation"in e)||e.presentation===r)&&(!("mode"in e)||{mode:e.mode===oe})}(t),getIntentState:ke,router:ze}]}})),Be=s(null);function Re(){const e=c(Be);if(!e)throw new Error("Presentation navigate context is missing");return e}const Ue=s(null);function He(e=!0){const t=c(Ue);if(e&&!t)throw new Error("Presentation params context is missing");return t}export{ce as A,ie as C,ne as D,oe as E,de as L,se as M,Be as P,Ue as a,ve as b,ae as c,He as d,le as e,Re as f,Ee as g,$e as h,Ce as i,ye as p,we as u};//# sourceMappingURL=index.js.map
`;function Ie(t){const{documentId:n,options:r,schemaType:i}=t,o=c(je),{state:s,status:a}=fe({id:n,resolvers:r.resolve?.locations||r.locate,type:i.name});if(o&&o.options[0]!==r||"empty"===a)return null;const l=o?.options||[];return e(xe,{marginBottom:5,space:5,children:e(U,{space:2,children:l.map(((t,r)=>e(_e,{documentId:n,isResolving:"resolving"===a,options:t,schemaType:i,showPresentationTitle:l.length>1,state:s},r)))})})}function Te(t){const{children:n,options:o}=t,s=c(je),l=s?.register,[u,m]=r((()=>[])),h=a((e=>l?l(e):(m((t=>[e].concat(t))),()=>{m((t=>t.filter((t=>t!==e))))})),[l]),f=d(h);f.current=h;const y=i((()=>({options:s?.options||u,register:h})),[u,s,h]);return p((()=>f.current(o)),[o]),e(je.Provider,{value:y,children:n})}const Se=w({name:"presentation/openInStructure",useAction({documentId:e,documentType:t,path:n}){const r=b(),{navigateIntent:o}=X(),s=c(ge),a=i((()=>function(e,t,n){const r=e.map((e=>{const r=e.canHandleIntent?.("edit",{id:t,type:n,mode:"structure"},{});return{tool:e,match:r}})),i=r.filter((e=>f(e.match)&&e.match.mode));return i.length>0?i[0].tool:r.filter((e=>e.match))[0]?.tool}(r.tools,e,t)),[e,t,r.tools]);return{type:"action",hidden:!s||n.length>0||!a,icon:a?.icon||D,title:`Open in ${a?.title||"Structure"}`,onAction(){o("edit",{id:e,type:t,mode:"structure",path:_(n)})},renderAsButton:!0}}});const Oe=["preview","perspective","viewport"];function ke(e,t,n,r){const{id:i,mode:o,path:s,presentation:c,type:a,...l}=t,d={...(n?._searchParams||[]).filter((([e])=>Oe.includes(e))).reduce(((e,[t,n])=>({...e,[t]:n})),{}),...l};return"edit"===e&&i?(d.preview=d.preview||new URLSearchParams(window.location.search).get("preview")||"/",{type:a||"*",id:P(i),path:s,_searchParams:Object.entries(d)}):"create"===e?(d.preview=d.preview||new URLSearchParams(window.location.search).get("preview")||"/",r&&"object"==typeof r&&(d.templateParams=Y(r)),{type:a||"*",id:i||ee(),_searchParams:Object.entries(d)}):{intent:e,params:t,payload:r}}const ze=Z.create("/",{__unsafe_disableScopedSearchParams:!0},[Z.intents("/intent"),Z.create(":type",[Z.create(":id",[Z.create(":path")])])]),De=u((()=>import("./PresentationTool.js"))),Ae=u((()=>import("./BroadcastDisplayedDocument.js")));function Ee(e){return e}function $e(e){return e}const Ce=j((n=>{const r=n.name||ne;"locate"in n&&console.warn("Presentation’s `locate` option is deprecated. Use `resolve.locations` instead.");const i=!(!n.resolve?.locations&&!n.locate);return{i18n:{bundles:[ve]},document:{unstable_fieldActions:e=>[...e.filter((e=>e.name!==Se.name)),Se]},form:{components:{input:function(r){const o=r.value,s=o?._id?P(o?._id):void 0;return x(r.schemaType)?t(Te,{options:n,children:[i&&s&&e(Ie,{documentId:s,options:n,schemaType:r.schemaType}),r.renderDefault(r),e(m,{children:e(Ae,{value:o},s)},"broadcast-displayed-document")]}):r.renderDefault(r)}}},tools:[{icon:n.icon||te,name:r,title:n.title,component:De,options:n,canHandleIntent:(e,t)=>"create"===e?function(e){return"type"in e&&(!("presentation"in e)||e.presentation===r)&&(!("template"in e)||{template:!0})}(t):"edit"===e&&function(e){return"type"in e&&"id"in e&&(!("presentation"in e)||e.presentation===r)&&(!("mode"in e)||{mode:e.mode===oe})}(t),getIntentState:ke,router:ze}]}})),Re=s(null);function Ue(){const e=c(Re);if(!e)throw new Error("Presentation navigate context is missing");return e}const Be=s(null);function Le(e=!0){const t=c(Be);if(e&&!t)throw new Error("Presentation params context is missing");return t}export{ce as A,ie as C,ne as D,oe as E,de as L,se as M,Re as P,Be as a,ge as b,ae as c,Le as d,le as e,Ue as f,Ee as g,$e as h,Ce as i,ye as p,we as u};//# sourceMappingURL=index.js.map

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

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

@@ -1,3 +0,1 @@

/// <reference types="react" />
import type {ClientPerspective} from '@sanity/client'

@@ -4,0 +2,0 @@ import type {ComponentType} from 'react'

{
"name": "@sanity/presentation",
"version": "1.16.4",
"version": "1.16.5",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/presentation#readme",

@@ -93,4 +93,4 @@ "bugs": {

"dependencies": {
"@sanity/icons": "^3.3.1",
"@sanity/ui": "^2.8.8",
"@sanity/icons": "^3.4.0",
"@sanity/ui": "^2.8.9",
"@sanity/uuid": "3.0.2",

@@ -107,21 +107,21 @@ "@types/lodash.isequal": "^4.5.8",

"suspend-react": "0.1.3",
"@sanity/preview-url-secret": "^1.6.20"
"@sanity/preview-url-secret": "^1.6.21"
},
"devDependencies": {
"@sanity/client": "^6.21.2",
"@sanity/pkg-utils": "6.9.3",
"@sanity/client": "^6.21.3",
"@sanity/pkg-utils": "6.11.1",
"@types/lodash.get": "^4.4.9",
"happy-dom": "^14.12.3",
"happy-dom": "^15.7.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sanity": "^3.53.0",
"styled-components": "6.1.12",
"typescript": "5.4.5",
"sanity": "^3.57.2",
"styled-components": "6.1.13",
"typescript": "5.6.2",
"vitest": "^2.0.5",
"@repo/channels": "0.4.0",
"@repo/package.config": "0.0.0",
"@repo/visual-editing-helpers": "0.6.20"
"@repo/visual-editing-helpers": "0.6.21",
"@repo/package.config": "0.0.0"
},
"peerDependencies": {
"@sanity/client": "^6.21.2"
"@sanity/client": "^6.21.3"
},

@@ -128,0 +128,0 @@ "engines": {

@@ -38,2 +38,4 @@ import {uuid} from '@sanity/uuid'

if (intent === 'edit' && id) {
_searchParams['preview'] =
_searchParams['preview'] || new URLSearchParams(window.location.search).get('preview') || '/'
return {

@@ -40,0 +42,0 @@ type: type || '*',

@@ -36,7 +36,2 @@ import {createPreviewSecret} from '@sanity/preview-url-secret/create-secret'

}
} else if (document.referrer) {
const referrerUrl = new URL(document.referrer)
if (referrerUrl.origin === resolvedUrl.origin) {
resultUrl = referrerUrl
}
}

@@ -61,3 +56,2 @@ } catch {

previewSearchParam,
referrer: typeof document === 'undefined' ? null : document.referrer,
studioBasePath: basePath,

@@ -64,0 +58,0 @@ })

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

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