sanity-plugin-iframe-pane
This is a Sanity Studio v3 plugin.
For the v2 version, please refer to the v2-branch.
Display any URL in a View Pane, along with helpful buttons to Copy the URL or open it in a new tab.
Accepts either a string or an async function to resolve a URL based on the current document.

Installation
npm install --save sanity-plugin-iframe-pane
or
yarn add sanity-plugin-iframe-pane
Usage
This is designed to be used as a Component inside of a View.
The simplest way to configure views is by customizing the defaultDocumentNode
setting in the structureTool()
plugin.
export default defineConfig({
plugins: [
structureTool({
defaultDocumentNode,
structure,
}),
],
})
A basic example of a custom defaultDocumentNode
function, to only show the Iframe Pane on movie
type documents.
import {type DefaultDocumentNodeResolver} from 'sanity/structure'
import {Iframe, UrlResolver} from 'sanity-plugin-iframe-pane'
import {type SanityDocument} from 'sanity'
const getPreviewUrl: UrlResolver = (doc, perspective) => {
return doc?.slug?.current
? `${window.location.host}/${doc.slug.current}?perspective=${perspective.perspectiveStack}`
: `${window.location.host}`
}
export const defaultDocumentNode: DefaultDocumentNodeResolver = (S, {schemaType}) => {
switch (schemaType) {
case `movie`:
return S.document().views([
S.view.form(),
S.view
.component(Iframe)
.options({
url: getPreviewUrl,
})
.title('Preview'),
])
default:
return S.document().views([S.view.form()])
}
}
Options
url: (doc, {perspectiveStack, selectedPerspectiveName}) => resolveProductionUrl(doc),
url: `https://sanity.io`,
url: {
origin: 'https://sanity.io'
preview: (document, {perspectiveStack, selectedPerspective}) => document?.slug?.current ? `/posts/${document.slug.current}` : new Error('Missing slug'),
draftMode: '/api/draft'
},
showDisplayUrl: true
defaultSize: `mobile`,
reload: {
button: true,
},
attributes: {
allow: 'fullscreen',
referrerPolicy: 'strict-origin-when-cross-origin',
sandbox: 'allow-same-origin',
}
License
MIT-licensed. See LICENSE.
Develop & test
This plugin uses @sanity/plugin-kit
with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio
on how to run this plugin with hotreload in the studio.
Release new version
Run "CI & Release" workflow.
Make sure to select the main
branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.