next-sanity 0.6.12 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -1
- package/lib/cjs/studio.js +1 -1
- package/lib/cjs/studio.js.map +1 -1
- package/lib/esm/studio.js +1 -1
- package/lib/esm/studio.js.map +1 -1
- package/package.json +1 -1
- package/src/studio/NextStudioHead.tsx +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# next-sanity
|
|
1
|
+
# next-sanity<!-- omit in toc -->
|
|
2
2
|
|
|
3
3
|
[Sanity.io](https://www.sanity.io/?utm_source=github&utm_medium=readme&utm_campaign=next-sanity) toolkit for Next.js.
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- Client-side live real-time preview for authenticated users
|
|
8
8
|
- GROQ syntax highlighting
|
|
9
|
+
- [Embed](#next-sanitystudio-dev-preview) [Studio v3](https://www.sanity.io/studio-v3) in [Next.js](https://nextjs.org/) apps
|
|
9
10
|
|
|
10
11
|
## Table of contents
|
|
11
12
|
|
|
@@ -16,7 +17,15 @@
|
|
|
16
17
|
- [Optimizing bundle size](#optimizing-bundle-size)
|
|
17
18
|
- [Usage](#usage)
|
|
18
19
|
- [Example: Minimal blog post template](#example-minimal-blog-post-template)
|
|
20
|
+
- [`next-sanity/studio` (dev-preview)](#next-sanitystudio-dev-preview)
|
|
21
|
+
- [Usage](#usage-1)
|
|
22
|
+
- [Opt-in to using `StudioProvider` and `StudioLayout`](#opt-in-to-using-studioprovider-and-studiolayout)
|
|
23
|
+
- [Customize `<ServerStyleSheetDocument />`](#customize-serverstylesheetdocument-)
|
|
24
|
+
- [Full-control mode](#full-control-mode)
|
|
19
25
|
- [Migrate](#migrate)
|
|
26
|
+
- [From `v0.4`](#from-v04)
|
|
27
|
+
- [`createPortableTextComponent` is removed](#createportabletextcomponent-is-removed)
|
|
28
|
+
- [`createImageUrlBuilder` is removed](#createimageurlbuilder-is-removed)
|
|
20
29
|
- [License](#license)
|
|
21
30
|
|
|
22
31
|
## Installation
|
|
@@ -203,6 +212,166 @@ export async function getStaticPaths() {
|
|
|
203
212
|
}
|
|
204
213
|
```
|
|
205
214
|
|
|
215
|
+
## `next-sanity/studio` (dev-preview)
|
|
216
|
+
|
|
217
|
+
> [See it live](https://next.sanity.build/)
|
|
218
|
+
|
|
219
|
+
The latest version of Sanity Studio allows you to embed a near-infinitely configurable content editing interface into any React application. This opens up many possibilities:
|
|
220
|
+
|
|
221
|
+
- Any service that hosts Next.js apps can now host your Studio.
|
|
222
|
+
- Building previews for your content is easier as your Studio lives in the same environment.
|
|
223
|
+
- Use [Data Fetching](https://nextjs.org/docs/basic-features/data-fetching/overview) to configure your Studio.
|
|
224
|
+
- Easy setup of [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).
|
|
225
|
+
|
|
226
|
+
### Usage
|
|
227
|
+
|
|
228
|
+
The basic setup is two files:
|
|
229
|
+
|
|
230
|
+
1. `pages/[[...index]].tsx`
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
// Import your sanity.config.ts file
|
|
234
|
+
import config from '../sanity.config'
|
|
235
|
+
import {NextStudio} from 'next-sanity/studio'
|
|
236
|
+
|
|
237
|
+
export default function StudioPage() {
|
|
238
|
+
// Loads the Studio, with all the needed neta tags and global CSS reqiired for it to render correctly
|
|
239
|
+
return <NextStudio config={config} />
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The `<NextStudio />` wraps `<Studio />` component and supports forwarding all its props:
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
import {Studio} from 'sanity'
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
2. `pages/_document.tsx`
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
import {ServerStyleSheetDocument} from 'next-sanity/studio'
|
|
253
|
+
|
|
254
|
+
// Set up SSR for styled-components, ensuring there's no missing CSS when deploying a Studio in Next.js into production
|
|
255
|
+
export default class Document extends ServerStyleSheetDocument {}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Opt-in to using `StudioProvider` and `StudioLayout`
|
|
259
|
+
|
|
260
|
+
If you want to go lower level and have more control over the studio you can pass `StudioProvider` and `StudioLayout` from `sanity` as `children`:
|
|
261
|
+
|
|
262
|
+
```tsx
|
|
263
|
+
import {NextStudio} from 'next-sanity/studio'
|
|
264
|
+
import {StudioProvider, StudioLayout} from 'sanity'
|
|
265
|
+
|
|
266
|
+
import config from '../sanity.config'
|
|
267
|
+
|
|
268
|
+
function StudioPage() {
|
|
269
|
+
return (
|
|
270
|
+
<NextStudio config={config}>
|
|
271
|
+
<StudioProvider config={config}>
|
|
272
|
+
{/* Put components here and you'll have access to the same React hooks as Studio gives you when writing plugins */}
|
|
273
|
+
<StudioLayout />
|
|
274
|
+
</StudioProvider>
|
|
275
|
+
</NextStudio>
|
|
276
|
+
)
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Customize `<ServerStyleSheetDocument />`
|
|
281
|
+
|
|
282
|
+
You can still customize `_document.tsx`, the same way you would the default `<Document />` component from `next/document`:
|
|
283
|
+
|
|
284
|
+
```tsx
|
|
285
|
+
import {ServerStyleSheetDocument} from 'next-sanity/studio'
|
|
286
|
+
|
|
287
|
+
export default class Document extends ServerStyleSheetDocument {
|
|
288
|
+
static async getInitialProps(ctx: DocumentContext) {
|
|
289
|
+
// You can still override renderPage:
|
|
290
|
+
const originalRenderPage = ctx.renderPage
|
|
291
|
+
ctx.renderPage = () =>
|
|
292
|
+
originalRenderPage({
|
|
293
|
+
enhanceApp: (App) => (props) => <App {...props} />,
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
const initialProps = await ServerStyleSheetDocument.getInitialProps(ctx)
|
|
297
|
+
|
|
298
|
+
const extraStyles = await getStyles()
|
|
299
|
+
return {
|
|
300
|
+
...initialProps,
|
|
301
|
+
// Add to the default styles if you want
|
|
302
|
+
styles: [initialProps.styles, extraStyles],
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
render() {
|
|
306
|
+
// do the same stuff as in `next/document`
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Full-control mode
|
|
312
|
+
|
|
313
|
+
If you only need parts of what `<NextStudio />` does for you, but not all of it.
|
|
314
|
+
No problem. You can import any which one of the components that `<NextStudio />` is importing and assemble them in any way you want.
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
import {Studio, type Config} from 'sanity'
|
|
318
|
+
import {NextStudioGlobalStyle, NextStudioHead} from 'next-sanity/studio'
|
|
319
|
+
// This implementation will only load the bare minimum of what's required for the Studio to render correctly. No favicons, fancy <meta name="theme-color"> tags or the like
|
|
320
|
+
export default function CustomNextStudio({config}: {config: Config}) {
|
|
321
|
+
return (
|
|
322
|
+
<>
|
|
323
|
+
<Studio config={config} />
|
|
324
|
+
<NextStudioHead>{/* Custom extra stuff in <head> */}</NextStudioHead>
|
|
325
|
+
<NextStudioGlobalStyle />
|
|
326
|
+
</>
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
And while `<NextStudio />` have all features enabled by default allowing you to opt-out by giving it props, the inner components `<NextStudioHead />` and `<NextStudioGlobalStyle />` are opt-in.
|
|
332
|
+
This means that these two `StudioPage` components are functionally identical:
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
import {
|
|
336
|
+
NextStudio,
|
|
337
|
+
NextStudioGlobalStyle,
|
|
338
|
+
NextStudioHead,
|
|
339
|
+
useThem,
|
|
340
|
+
useBackgroundColorsFromTheme,
|
|
341
|
+
} from 'next-sanity/studio'
|
|
342
|
+
import {Studio} from 'sanity'
|
|
343
|
+
import config from '../sanity.config'
|
|
344
|
+
|
|
345
|
+
// Turning all the features off, leaving only bare minimum required meta tags and styling
|
|
346
|
+
function StudioPage() {
|
|
347
|
+
return (
|
|
348
|
+
<NextStudio
|
|
349
|
+
config={config}
|
|
350
|
+
// an empty string turns off the CSS that sets a background on <html>
|
|
351
|
+
unstable__bg=""
|
|
352
|
+
unstable__noTailwindSvgFix
|
|
353
|
+
unstable__noFavicons
|
|
354
|
+
// an empty string turns off the <title> tag
|
|
355
|
+
unstable__document_title=""
|
|
356
|
+
/>
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Since no features are enabled it works the same way
|
|
361
|
+
function Studiopage() {
|
|
362
|
+
const theme = useTheme(config)
|
|
363
|
+
const {themeColorLight, themeColorDark} = useBackgroundColorsFromTheme(theme)
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<>
|
|
367
|
+
<Studio config={config} />
|
|
368
|
+
<NextStudioHead themeColorLight={themeColorLight} themeColorDark={themeColorDark} />
|
|
369
|
+
<NextStudioGlobalStyle />
|
|
370
|
+
</>
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
206
375
|
## Migrate
|
|
207
376
|
|
|
208
377
|
### From `v0.4`
|
package/lib/cjs/studio.js
CHANGED
|
@@ -158,7 +158,7 @@ const $9a339c4a487c3478$var$NextStudioHeadComponent = ({ children: children , th
|
|
|
158
158
|
name: "referrer",
|
|
159
159
|
content: "same-origin"
|
|
160
160
|
}),
|
|
161
|
-
/*#__PURE__*/ (0, $cerUD$reactjsxruntime.jsx)("title", {
|
|
161
|
+
title && /*#__PURE__*/ (0, $cerUD$reactjsxruntime.jsx)("title", {
|
|
162
162
|
children: title
|
|
163
163
|
}),
|
|
164
164
|
favicons && /*#__PURE__*/ (0, $cerUD$reactjsxruntime.jsx)("link", {
|
package/lib/cjs/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;AAmDA;;;GAGG,CACH,MAAM,yCAAmB,GAAG,CAAC,YAC3B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AAQ,EACN,SAAS,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;aACnF,CAAA,AAAC,CAAC,CAAA;QAEL,OAAO;YACL,GAAG,MAAM;YACT,QAAQ,EAAE,MAAM,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;SACrF,CAAA;KACF,EAAE;QAAC,MAAM;QAAE,QAAQ;KAAC,CAAC,CAAA;CACvB;;;;;;;;;AZ5ED","sources":["src/studio.ts","src/studio/index.ts","src/studio/NextStudio.tsx","src/studio/NextStudioGlobalStyle.ts","src/studio/NextStudioHead.tsx","node_modules/@parcel/runtime-js/lib/runtime-ef9b7f9202d9a806.js","node_modules/@parcel/runtime-js/lib/runtime-0bfed5d474c54129.js","node_modules/@parcel/runtime-js/lib/runtime-611c430ae589140e.js","node_modules/@parcel/runtime-js/lib/runtime-2afc5d6315990f14.js","node_modules/@parcel/runtime-js/lib/runtime-2f5b0c062978bd21.js","src/studio/webmanifest.json","src/studio/ServerStyleSheetDocument.tsx","src/studio/utils.ts"],"sourcesContent":["export * from './studio/index'\n","export * from './NextStudio'\nexport * from './NextStudioGlobalStyle'\nexport * from './NextStudioHead'\nexport * from './ServerStyleSheetDocument'\nexport * from './utils'\n","import {memo} from 'react'\nimport {type StudioProps, Studio} from 'sanity'\n\nimport {\n type NextStudioHeadProps,\n NextStudioGlobalStyle,\n NextStudioGlobalStyleProps,\n NextStudioHead,\n useBackgroundColorsFromTheme,\n useTheme,\n} from '.'\n\nexport interface NextStudioProps extends StudioProps {\n /**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n */\n children?: React.ReactNode\n /**\n * Turns off the default global styling\n */\n unstable__noGlobalStyle?: boolean\n /**\n * Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by defautl\n */\n unstable__noTailwindSvgFix?: NextStudioGlobalStyleProps['unstable__tailwindSvgFix']\n /**\n * Add stuff to the head with next/head\n */\n unstable__head?: NextStudioHeadProps['children']\n /**\n * Sets the document title\n */\n unstable__document_title?: NextStudioHeadProps['title']\n /**\n * Sets the background color of <html>\n */\n unstable__bg?: NextStudioGlobalStyleProps['bg']\n /**\n * Don't load the favicon meta tags\n */\n unstable__noFavicons?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noGlobalStyle,\n unstable__noTailwindSvgFix,\n unstable__head,\n unstable__document_title,\n unstable__bg,\n unstable__noFavicons,\n ...props\n}: NextStudioProps) => {\n const theme = useTheme(config)\n const {themeColorLight, themeColorDark} = useBackgroundColorsFromTheme(theme)\n return (\n <>\n {children || <Studio config={config} {...props} />}\n <NextStudioHead\n themeColorLight={themeColorLight}\n themeColorDark={themeColorDark}\n title={unstable__document_title}\n favicons={!unstable__noFavicons}\n >\n {unstable__head}\n </NextStudioHead>\n {!unstable__noGlobalStyle && (\n <NextStudioGlobalStyle\n bg={unstable__bg ?? themeColorLight}\n unstable__tailwindSvgFix={!unstable__noTailwindSvgFix}\n />\n )}\n </>\n )\n}\nexport const NextStudio = memo(NextStudioComponent)\n","import {createGlobalStyle, css} from 'styled-components'\n\nexport interface NextStudioGlobalStyleProps {\n bg?: string\n unstable__tailwindSvgFix?: boolean\n}\nexport const NextStudioGlobalStyle = createGlobalStyle<NextStudioGlobalStyleProps>`\n${({bg}) =>\n bg\n ? css`\n html {\n background-color: ${bg};\n }\n `\n : ''}\nhtml,\nbody,\n#__next {\n height: 100%;\n}\nbody {\n margin: 0;\n overscroll-behavior: none;\n -webkit-font-smoothing: antialiased;\n}\n${({unstable__tailwindSvgFix}) =>\n unstable__tailwindSvgFix\n ? css`\n /* override tailwind reset */\n :root svg {\n display: inline;\n }\n `\n : ''}`\n","/* eslint-disable no-process-env */\nimport Head from 'next/head'\nimport {type ComponentProps, memo, useCallback} from 'react'\n\n// @ts-ignore\nimport iconApple from './apple-touch-icon.png'\n// @ts-ignore\nimport iconIco from './favicon.ico'\n// @ts-ignore\nimport iconSvg from './favicon.svg'\n// @ts-ignore\nimport icon192 from './favicon-192.png'\n// @ts-ignore\nimport icon512 from './favicon-512.png'\nimport type {MetaThemeColors} from './utils'\nimport webmanifest from './webmanifest.json'\n\n// Interop between how Parcel and Next deals with asset imports\nconst interop = (href: string | {src: string}): string =>\n typeof href === 'string' ? href : href.src\n\nexport interface NextStudioHeadProps extends Partial<MetaThemeColors> {\n children?: ComponentProps<typeof Head>['children']\n title?: string\n favicons?: boolean\n}\nconst NextStudioHeadComponent = ({\n children,\n themeColorDark,\n themeColorLight,\n title = 'Sanity Studio',\n favicons,\n}: NextStudioHeadProps) => {\n const inlineWebmanifest = useCallback(() => {\n const manifest = JSON.parse(JSON.stringify(webmanifest))\n const icons = manifest.icons.map((icon: any) => {\n // Inline manifests works best when URLs are absolute\n const src =\n // eslint-disable-next-line no-nested-ternary\n icon.src === './favicon-192.png'\n ? interop(icon192)\n : icon.src === './favicon-512.png'\n ? interop(icon512)\n : icon.src\n return {\n ...icon,\n src: process.env.NEXT_PUBLIC_VERCEL_URL\n ? new URL(src, `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`).toString()\n : src,\n }\n })\n return `data:application/manifest+json,${encodeURIComponent(\n JSON.stringify({...manifest, icons})\n )}`\n }, [])\n\n return (\n <Head>\n <meta\n name=\"viewport\"\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n content=\"width=device-width, initial-scale=1, viewport-fit=cover\"\n />\n <meta name=\"robots\" content=\"noindex\" />\n <meta name=\"referrer\" content=\"same-origin\" />\n <title>{title}</title>\n {favicons && <link rel=\"icon\" href={interop(iconIco)} sizes=\"any\" />}\n {favicons && <link rel=\"icon\" href={interop(iconSvg)} type=\"image/svg+xml\" />}\n {favicons && <link rel=\"apple-touch-icon\" href={interop(iconApple)} />}\n {favicons && (\n <link\n rel=\"manifest\"\n // eslint-disable-next-line no-warning-comments\n // @TODO until parcel fixes https://github.com/parcel-bundler/parcel/issues/8025 and stops stripping process.env.NEXT_PUBLIC_VERCEL_URL from the compiled code, use the remove webmanifest\n href={\n process.env.NEXT_PUBLIC_VERCEL_URL\n ? inlineWebmanifest()\n : 'https://next.sanity.build/manifest.webmanifest'\n }\n />\n )}\n {/* These theme-color tags makes the Studio look really really good on devices like iPads as the browser chrome adopts the Studio background */}\n {themeColorLight && (\n <meta\n key=\"theme-color-light\"\n name=\"theme-color\"\n content={themeColorLight}\n media=\"(prefers-color-scheme: light)\"\n />\n )}\n {themeColorDark && (\n <meta\n key=\"theme-color-dark\"\n name=\"theme-color\"\n content={themeColorDark}\n media=\"(prefers-color-scheme: dark)\"\n />\n )}\n {children}\n </Head>\n )\n}\n\nexport const NextStudioHead = memo(NextStudioHeadComponent)\n","module.exports = new __parcel__URL__(\"apple-touch-icon.abc4aca2.png\").toString();","module.exports = new __parcel__URL__(\"favicon.648fc2f2.ico\").toString();","module.exports = new __parcel__URL__(\"favicon.8f76876f.svg\").toString();","module.exports = new __parcel__URL__(\"favicon-192.40c8bab4.png\").toString();","module.exports = new __parcel__URL__(\"favicon-512.5e08f951.png\").toString();","{\n \"icons\": [\n {\n \"src\": \"./favicon-192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"./favicon-512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ]\n}\n","// We can disable this rule safely as we're not trying to use it outside pages/document, we're shipping a wrapper\n// eslint-disable-next-line @next/next/no-document-import-in-page\nimport Document, {type DocumentContext} from 'next/document'\nimport {ServerStyleSheet} from 'styled-components'\n\n/**\n * Usage, from a pages/_document.tsx file:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {}\n *\n * To do extra stuff in getInitialProps:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n * import { type DocumentContext } from 'next/document'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {\n * static async getInitialProps(ctx: DocumentContext) {\n * // You can still override renderPage:\n * const originalRenderPage = ctx.renderPage\n * ctx.renderPage = () => originalRenderPage({\n * enhanceApp: (App) => (props) => <App {...props} />\n * })\n *\n * const initialProps = await ServerStyleSheetDocument.getInitialProps(ctx)\n * const extraStyles = await getStyles()\n * return {\n * ...initialProps,\n * styles: [initialProps.styles, extraStyles],\n * }\n * }\n * }\n */\n\nexport class ServerStyleSheetDocument extends Document {\n static async getInitialProps(ctx: DocumentContext) {\n const sheet = new ServerStyleSheet()\n const originalRenderPage = ctx.renderPage\n\n try {\n ctx.renderPage = () =>\n originalRenderPage({\n enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),\n })\n\n const initialProps = await Document.getInitialProps(ctx)\n return {\n ...initialProps,\n styles: [initialProps.styles, sheet.getStyleElement()],\n }\n } finally {\n sheet.seal()\n }\n }\n}\n","import {useRouter} from 'next/router'\nimport {useMemo} from 'react'\nimport {type Config, type StudioTheme, type WorkspaceOptions, defaultTheme} from 'sanity'\n\nexport function isWorkspaces(config: Config): config is WorkspaceOptions[] {\n return Array.isArray(config)\n}\n\nexport interface WorkspaceWithTheme extends Omit<WorkspaceOptions, 'theme'> {\n theme: StudioTheme\n}\n\nexport function isWorkspaceWithTheme(\n workspace: WorkspaceOptions\n): workspace is WorkspaceWithTheme {\n return Boolean(workspace.theme)\n}\n\nexport function useTheme(config: Config): StudioTheme {\n const workspace = useMemo<WorkspaceOptions>(\n () => (isWorkspaces(config) ? config[0] : config),\n [config]\n )\n return useMemo<StudioTheme>(\n () => (isWorkspaceWithTheme(workspace) ? workspace.theme : defaultTheme),\n [workspace]\n )\n}\n\nexport type MetaThemeColors = {\n themeColorLight: string\n themeColorDark: string\n}\nexport const useBackgroundColorsFromTheme = (theme: StudioTheme): MetaThemeColors => {\n return useMemo<MetaThemeColors>(\n () => ({\n themeColorLight: theme.color.light.default.base.bg,\n themeColorDark: theme.color.dark.default.base.bg,\n }),\n [theme]\n )\n}\n\n/**\n * Parses the next route to determine the what the base path for Sanity Studio should be\n */\nexport function useBasePath(): string {\n const router = useRouter()\n return useMemo(() => {\n const [basePath = '/'] = router.route.split('/[')\n return basePath\n }, [router.route])\n}\n\nexport interface WorkspaceWithBasePath extends Omit<WorkspaceOptions, 'basePath'> {\n basePath: string\n}\nexport type ConfigWithBasePath = WorkspaceWithBasePath | WorkspaceWithBasePath[]\n/**\n * Apply the base path from next to the config, prefixing any defined base path\n */\nexport function useConfigWithBasePath(config: Config): ConfigWithBasePath {\n const basePath = useBasePath()\n return useMemo(() => {\n if (isWorkspaces(config)) {\n return config.map((workspace) => ({\n ...workspace,\n basePath:\n workspace.basePath === '/' ? basePath : `${basePath}${workspace.basePath || ''}`,\n }))\n }\n return {\n ...config,\n basePath: config.basePath === '/' ? basePath : `${basePath}${config.basePath || ''}`,\n }\n }, [config, basePath])\n}\n"],"names":[],"version":3,"file":"studio.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;AAmDA;;;GAGG,CACH,MAAM,yCAAmB,GAAG,CAAC,YAC3B,QAAQ,CAAA,UACR,MAAM,CAAA,2BACN,uBAAuB,CAAA,8BACvB,0BAA0B,CAAA,kBAC1B,cAAc,CAAA,4BACd,wBAAwB,CAAA,gBACxB,YAAY,CAAA,wBACZ,oBAAoB,CAAA,EACpB,GAAG,KAAK,EACQ,GAAK;IACrB,MAAM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GAAG,MAAM;YACT,QAAQ,EAAE,MAAM,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;SACrF,CAAA;KACF,EAAE;QAAC,MAAM;QAAE,QAAQ;KAAC,CAAC,CAAA;CACvB;;;;;;;;;AZ5ED","sources":["src/studio.ts","src/studio/index.ts","src/studio/NextStudio.tsx","src/studio/NextStudioGlobalStyle.ts","src/studio/NextStudioHead.tsx","node_modules/@parcel/runtime-js/lib/runtime-ef9b7f9202d9a806.js","node_modules/@parcel/runtime-js/lib/runtime-0bfed5d474c54129.js","node_modules/@parcel/runtime-js/lib/runtime-611c430ae589140e.js","node_modules/@parcel/runtime-js/lib/runtime-2afc5d6315990f14.js","node_modules/@parcel/runtime-js/lib/runtime-2f5b0c062978bd21.js","src/studio/webmanifest.json","src/studio/ServerStyleSheetDocument.tsx","src/studio/utils.ts"],"sourcesContent":["export * from './studio/index'\n","export * from './NextStudio'\nexport * from './NextStudioGlobalStyle'\nexport * from './NextStudioHead'\nexport * from './ServerStyleSheetDocument'\nexport * from './utils'\n","import {memo} from 'react'\nimport {type StudioProps, Studio} from 'sanity'\n\nimport {\n type NextStudioHeadProps,\n NextStudioGlobalStyle,\n NextStudioGlobalStyleProps,\n NextStudioHead,\n useBackgroundColorsFromTheme,\n useTheme,\n} from '.'\n\nexport interface NextStudioProps extends StudioProps {\n /**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n */\n children?: React.ReactNode\n /**\n * Turns off the default global styling\n */\n unstable__noGlobalStyle?: boolean\n /**\n * Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by defautl\n */\n unstable__noTailwindSvgFix?: NextStudioGlobalStyleProps['unstable__tailwindSvgFix']\n /**\n * Add stuff to the head with next/head\n */\n unstable__head?: NextStudioHeadProps['children']\n /**\n * Sets the document title\n */\n unstable__document_title?: NextStudioHeadProps['title']\n /**\n * Sets the background color of <html>\n */\n unstable__bg?: NextStudioGlobalStyleProps['bg']\n /**\n * Don't load the favicon meta tags\n */\n unstable__noFavicons?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noGlobalStyle,\n unstable__noTailwindSvgFix,\n unstable__head,\n unstable__document_title,\n unstable__bg,\n unstable__noFavicons,\n ...props\n}: NextStudioProps) => {\n const theme = useTheme(config)\n const {themeColorLight, themeColorDark} = useBackgroundColorsFromTheme(theme)\n return (\n <>\n {children || <Studio config={config} {...props} />}\n <NextStudioHead\n themeColorLight={themeColorLight}\n themeColorDark={themeColorDark}\n title={unstable__document_title}\n favicons={!unstable__noFavicons}\n >\n {unstable__head}\n </NextStudioHead>\n {!unstable__noGlobalStyle && (\n <NextStudioGlobalStyle\n bg={unstable__bg ?? themeColorLight}\n unstable__tailwindSvgFix={!unstable__noTailwindSvgFix}\n />\n )}\n </>\n )\n}\nexport const NextStudio = memo(NextStudioComponent)\n","import {createGlobalStyle, css} from 'styled-components'\n\nexport interface NextStudioGlobalStyleProps {\n bg?: string\n unstable__tailwindSvgFix?: boolean\n}\nexport const NextStudioGlobalStyle = createGlobalStyle<NextStudioGlobalStyleProps>`\n${({bg}) =>\n bg\n ? css`\n html {\n background-color: ${bg};\n }\n `\n : ''}\nhtml,\nbody,\n#__next {\n height: 100%;\n}\nbody {\n margin: 0;\n overscroll-behavior: none;\n -webkit-font-smoothing: antialiased;\n}\n${({unstable__tailwindSvgFix}) =>\n unstable__tailwindSvgFix\n ? css`\n /* override tailwind reset */\n :root svg {\n display: inline;\n }\n `\n : ''}`\n","/* eslint-disable no-process-env */\nimport Head from 'next/head'\nimport {type ComponentProps, memo, useCallback} from 'react'\n\n// @ts-ignore\nimport iconApple from './apple-touch-icon.png'\n// @ts-ignore\nimport iconIco from './favicon.ico'\n// @ts-ignore\nimport iconSvg from './favicon.svg'\n// @ts-ignore\nimport icon192 from './favicon-192.png'\n// @ts-ignore\nimport icon512 from './favicon-512.png'\nimport type {MetaThemeColors} from './utils'\nimport webmanifest from './webmanifest.json'\n\n// Interop between how Parcel and Next deals with asset imports\nconst interop = (href: string | {src: string}): string =>\n typeof href === 'string' ? href : href.src\n\nexport interface NextStudioHeadProps extends Partial<MetaThemeColors> {\n children?: ComponentProps<typeof Head>['children']\n title?: string\n favicons?: boolean\n}\nconst NextStudioHeadComponent = ({\n children,\n themeColorDark,\n themeColorLight,\n title = 'Sanity Studio',\n favicons,\n}: NextStudioHeadProps) => {\n const inlineWebmanifest = useCallback(() => {\n const manifest = JSON.parse(JSON.stringify(webmanifest))\n const icons = manifest.icons.map((icon: any) => {\n // Inline manifests works best when URLs are absolute\n const src =\n // eslint-disable-next-line no-nested-ternary\n icon.src === './favicon-192.png'\n ? interop(icon192)\n : icon.src === './favicon-512.png'\n ? interop(icon512)\n : icon.src\n return {\n ...icon,\n src: process.env.NEXT_PUBLIC_VERCEL_URL\n ? new URL(src, `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`).toString()\n : src,\n }\n })\n return `data:application/manifest+json,${encodeURIComponent(\n JSON.stringify({...manifest, icons})\n )}`\n }, [])\n\n return (\n <Head>\n <meta\n name=\"viewport\"\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n content=\"width=device-width, initial-scale=1, viewport-fit=cover\"\n />\n <meta name=\"robots\" content=\"noindex\" />\n <meta name=\"referrer\" content=\"same-origin\" />\n {title && <title>{title}</title>}\n {favicons && <link rel=\"icon\" href={interop(iconIco)} sizes=\"any\" />}\n {favicons && <link rel=\"icon\" href={interop(iconSvg)} type=\"image/svg+xml\" />}\n {favicons && <link rel=\"apple-touch-icon\" href={interop(iconApple)} />}\n {favicons && (\n <link\n rel=\"manifest\"\n // eslint-disable-next-line no-warning-comments\n // @TODO until parcel fixes https://github.com/parcel-bundler/parcel/issues/8025 and stops stripping process.env.NEXT_PUBLIC_VERCEL_URL from the compiled code, use the remove webmanifest\n href={\n process.env.NEXT_PUBLIC_VERCEL_URL\n ? inlineWebmanifest()\n : 'https://next.sanity.build/manifest.webmanifest'\n }\n />\n )}\n {/* These theme-color tags makes the Studio look really really good on devices like iPads as the browser chrome adopts the Studio background */}\n {themeColorLight && (\n <meta\n key=\"theme-color-light\"\n name=\"theme-color\"\n content={themeColorLight}\n media=\"(prefers-color-scheme: light)\"\n />\n )}\n {themeColorDark && (\n <meta\n key=\"theme-color-dark\"\n name=\"theme-color\"\n content={themeColorDark}\n media=\"(prefers-color-scheme: dark)\"\n />\n )}\n {children}\n </Head>\n )\n}\n\nexport const NextStudioHead = memo(NextStudioHeadComponent)\n","module.exports = new __parcel__URL__(\"apple-touch-icon.abc4aca2.png\").toString();","module.exports = new __parcel__URL__(\"favicon.648fc2f2.ico\").toString();","module.exports = new __parcel__URL__(\"favicon.8f76876f.svg\").toString();","module.exports = new __parcel__URL__(\"favicon-192.40c8bab4.png\").toString();","module.exports = new __parcel__URL__(\"favicon-512.5e08f951.png\").toString();","{\n \"icons\": [\n {\n \"src\": \"./favicon-192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"./favicon-512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ]\n}\n","// We can disable this rule safely as we're not trying to use it outside pages/document, we're shipping a wrapper\n// eslint-disable-next-line @next/next/no-document-import-in-page\nimport Document, {type DocumentContext} from 'next/document'\nimport {ServerStyleSheet} from 'styled-components'\n\n/**\n * Usage, from a pages/_document.tsx file:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {}\n *\n * To do extra stuff in getInitialProps:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n * import { type DocumentContext } from 'next/document'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {\n * static async getInitialProps(ctx: DocumentContext) {\n * // You can still override renderPage:\n * const originalRenderPage = ctx.renderPage\n * ctx.renderPage = () => originalRenderPage({\n * enhanceApp: (App) => (props) => <App {...props} />\n * })\n *\n * const initialProps = await ServerStyleSheetDocument.getInitialProps(ctx)\n * const extraStyles = await getStyles()\n * return {\n * ...initialProps,\n * styles: [initialProps.styles, extraStyles],\n * }\n * }\n * }\n */\n\nexport class ServerStyleSheetDocument extends Document {\n static async getInitialProps(ctx: DocumentContext) {\n const sheet = new ServerStyleSheet()\n const originalRenderPage = ctx.renderPage\n\n try {\n ctx.renderPage = () =>\n originalRenderPage({\n enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),\n })\n\n const initialProps = await Document.getInitialProps(ctx)\n return {\n ...initialProps,\n styles: [initialProps.styles, sheet.getStyleElement()],\n }\n } finally {\n sheet.seal()\n }\n }\n}\n","import {useRouter} from 'next/router'\nimport {useMemo} from 'react'\nimport {type Config, type StudioTheme, type WorkspaceOptions, defaultTheme} from 'sanity'\n\nexport function isWorkspaces(config: Config): config is WorkspaceOptions[] {\n return Array.isArray(config)\n}\n\nexport interface WorkspaceWithTheme extends Omit<WorkspaceOptions, 'theme'> {\n theme: StudioTheme\n}\n\nexport function isWorkspaceWithTheme(\n workspace: WorkspaceOptions\n): workspace is WorkspaceWithTheme {\n return Boolean(workspace.theme)\n}\n\nexport function useTheme(config: Config): StudioTheme {\n const workspace = useMemo<WorkspaceOptions>(\n () => (isWorkspaces(config) ? config[0] : config),\n [config]\n )\n return useMemo<StudioTheme>(\n () => (isWorkspaceWithTheme(workspace) ? workspace.theme : defaultTheme),\n [workspace]\n )\n}\n\nexport type MetaThemeColors = {\n themeColorLight: string\n themeColorDark: string\n}\nexport const useBackgroundColorsFromTheme = (theme: StudioTheme): MetaThemeColors => {\n return useMemo<MetaThemeColors>(\n () => ({\n themeColorLight: theme.color.light.default.base.bg,\n themeColorDark: theme.color.dark.default.base.bg,\n }),\n [theme]\n )\n}\n\n/**\n * Parses the next route to determine the what the base path for Sanity Studio should be\n */\nexport function useBasePath(): string {\n const router = useRouter()\n return useMemo(() => {\n const [basePath = '/'] = router.route.split('/[')\n return basePath\n }, [router.route])\n}\n\nexport interface WorkspaceWithBasePath extends Omit<WorkspaceOptions, 'basePath'> {\n basePath: string\n}\nexport type ConfigWithBasePath = WorkspaceWithBasePath | WorkspaceWithBasePath[]\n/**\n * Apply the base path from next to the config, prefixing any defined base path\n */\nexport function useConfigWithBasePath(config: Config): ConfigWithBasePath {\n const basePath = useBasePath()\n return useMemo(() => {\n if (isWorkspaces(config)) {\n return config.map((workspace) => ({\n ...workspace,\n basePath:\n workspace.basePath === '/' ? basePath : `${basePath}${workspace.basePath || ''}`,\n }))\n }\n return {\n ...config,\n basePath: config.basePath === '/' ? basePath : `${basePath}${config.basePath || ''}`,\n }\n }, [config, basePath])\n}\n"],"names":[],"version":3,"file":"studio.js.map"}
|
package/lib/esm/studio.js
CHANGED
|
@@ -158,7 +158,7 @@ const $42e0ba93e8ca4228$var$NextStudioHeadComponent = ({ children: children , th
|
|
|
158
158
|
name: "referrer",
|
|
159
159
|
content: "same-origin"
|
|
160
160
|
}),
|
|
161
|
-
/*#__PURE__*/ (0, $4289s$jsx)("title", {
|
|
161
|
+
title && /*#__PURE__*/ (0, $4289s$jsx)("title", {
|
|
162
162
|
children: title
|
|
163
163
|
}),
|
|
164
164
|
favicons && /*#__PURE__*/ (0, $4289s$jsx)("link", {
|
package/lib/esm/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;AAmDA;;;GAGG,CACH,MAAM,yCAAmB,GAAG,CAAC,Y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N,SAAS,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;aACnF,CAAA,AAAC,CAAC,CAAA;QAEL,OAAO;YACL,GAAG,MAAM;YACT,QAAQ,EAAE,MAAM,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;SACrF,CAAA;KACF,EAAE;QAAC,MAAM;QAAE,QAAQ;KAAC,CAAC,CAAA;CACvB;;;;;;;;;AZ5ED","sources":["src/studio.ts","src/studio/index.ts","src/studio/NextStudio.tsx","src/studio/NextStudioGlobalStyle.ts","src/studio/NextStudioHead.tsx","node_modules/@parcel/runtime-js/lib/runtime-9e593bd92a039f93.js","node_modules/@parcel/runtime-js/lib/runtime-1d6e60dacba8bf0c.js","node_modules/@parcel/runtime-js/lib/runtime-9e05f9434f6564ff.js","node_modules/@parcel/runtime-js/lib/runtime-2e048d2a541e2a65.js","node_modules/@parcel/runtime-js/lib/runtime-daf66243b4f37b18.js","src/studio/webmanifest.json","src/studio/ServerStyleSheetDocument.tsx","src/studio/utils.ts"],"sourcesContent":["export * from './studio/index'\n","export * from './NextStudio'\nexport * from './NextStudioGlobalStyle'\nexport * from './NextStudioHead'\nexport * from './ServerStyleSheetDocument'\nexport * from './utils'\n","import {memo} from 'react'\nimport {type StudioProps, Studio} from 'sanity'\n\nimport {\n type NextStudioHeadProps,\n NextStudioGlobalStyle,\n NextStudioGlobalStyleProps,\n NextStudioHead,\n useBackgroundColorsFromTheme,\n useTheme,\n} from '.'\n\nexport interface NextStudioProps extends StudioProps {\n /**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n */\n children?: React.ReactNode\n /**\n * Turns off the default global styling\n */\n unstable__noGlobalStyle?: boolean\n /**\n * Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by defautl\n */\n unstable__noTailwindSvgFix?: NextStudioGlobalStyleProps['unstable__tailwindSvgFix']\n /**\n * Add stuff to the head with next/head\n */\n unstable__head?: NextStudioHeadProps['children']\n /**\n * Sets the document title\n */\n unstable__document_title?: NextStudioHeadProps['title']\n /**\n * Sets the background color of <html>\n */\n unstable__bg?: NextStudioGlobalStyleProps['bg']\n /**\n * Don't load the favicon meta tags\n */\n unstable__noFavicons?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noGlobalStyle,\n unstable__noTailwindSvgFix,\n unstable__head,\n unstable__document_title,\n unstable__bg,\n unstable__noFavicons,\n ...props\n}: NextStudioProps) => {\n const theme = useTheme(config)\n const {themeColorLight, themeColorDark} = useBackgroundColorsFromTheme(theme)\n return (\n <>\n {children || <Studio config={config} {...props} />}\n <NextStudioHead\n themeColorLight={themeColorLight}\n themeColorDark={themeColorDark}\n title={unstable__document_title}\n favicons={!unstable__noFavicons}\n >\n {unstable__head}\n </NextStudioHead>\n {!unstable__noGlobalStyle && (\n <NextStudioGlobalStyle\n bg={unstable__bg ?? themeColorLight}\n unstable__tailwindSvgFix={!unstable__noTailwindSvgFix}\n />\n )}\n </>\n )\n}\nexport const NextStudio = memo(NextStudioComponent)\n","import {createGlobalStyle, css} from 'styled-components'\n\nexport interface NextStudioGlobalStyleProps {\n bg?: string\n unstable__tailwindSvgFix?: boolean\n}\nexport const NextStudioGlobalStyle = createGlobalStyle<NextStudioGlobalStyleProps>`\n${({bg}) =>\n bg\n ? css`\n html {\n background-color: ${bg};\n }\n `\n : ''}\nhtml,\nbody,\n#__next {\n height: 100%;\n}\nbody {\n margin: 0;\n overscroll-behavior: none;\n -webkit-font-smoothing: antialiased;\n}\n${({unstable__tailwindSvgFix}) =>\n unstable__tailwindSvgFix\n ? css`\n /* override tailwind reset */\n :root svg {\n display: inline;\n }\n `\n : ''}`\n","/* eslint-disable no-process-env */\nimport Head from 'next/head'\nimport {type ComponentProps, memo, useCallback} from 'react'\n\n// @ts-ignore\nimport iconApple from './apple-touch-icon.png'\n// @ts-ignore\nimport iconIco from './favicon.ico'\n// @ts-ignore\nimport iconSvg from './favicon.svg'\n// @ts-ignore\nimport icon192 from './favicon-192.png'\n// @ts-ignore\nimport icon512 from './favicon-512.png'\nimport type {MetaThemeColors} from './utils'\nimport webmanifest from './webmanifest.json'\n\n// Interop between how Parcel and Next deals with asset imports\nconst interop = (href: string | {src: string}): string =>\n typeof href === 'string' ? href : href.src\n\nexport interface NextStudioHeadProps extends Partial<MetaThemeColors> {\n children?: ComponentProps<typeof Head>['children']\n title?: string\n favicons?: boolean\n}\nconst NextStudioHeadComponent = ({\n children,\n themeColorDark,\n themeColorLight,\n title = 'Sanity Studio',\n favicons,\n}: NextStudioHeadProps) => {\n const inlineWebmanifest = useCallback(() => {\n const manifest = JSON.parse(JSON.stringify(webmanifest))\n const icons = manifest.icons.map((icon: any) => {\n // Inline manifests works best when URLs are absolute\n const src =\n // eslint-disable-next-line no-nested-ternary\n icon.src === './favicon-192.png'\n ? interop(icon192)\n : icon.src === './favicon-512.png'\n ? interop(icon512)\n : icon.src\n return {\n ...icon,\n src: process.env.NEXT_PUBLIC_VERCEL_URL\n ? new URL(src, `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`).toString()\n : src,\n }\n })\n return `data:application/manifest+json,${encodeURIComponent(\n JSON.stringify({...manifest, icons})\n )}`\n }, [])\n\n return (\n <Head>\n <meta\n name=\"viewport\"\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n content=\"width=device-width, initial-scale=1, viewport-fit=cover\"\n />\n <meta name=\"robots\" content=\"noindex\" />\n <meta name=\"referrer\" content=\"same-origin\" />\n <title>{title}</title>\n {favicons && <link rel=\"icon\" href={interop(iconIco)} sizes=\"any\" />}\n {favicons && <link rel=\"icon\" href={interop(iconSvg)} type=\"image/svg+xml\" />}\n {favicons && <link rel=\"apple-touch-icon\" href={interop(iconApple)} />}\n {favicons && (\n <link\n rel=\"manifest\"\n // eslint-disable-next-line no-warning-comments\n // @TODO until parcel fixes https://github.com/parcel-bundler/parcel/issues/8025 and stops stripping process.env.NEXT_PUBLIC_VERCEL_URL from the compiled code, use the remove webmanifest\n href={\n process.env.NEXT_PUBLIC_VERCEL_URL\n ? inlineWebmanifest()\n : 'https://next.sanity.build/manifest.webmanifest'\n }\n />\n )}\n {/* These theme-color tags makes the Studio look really really good on devices like iPads as the browser chrome adopts the Studio background */}\n {themeColorLight && (\n <meta\n key=\"theme-color-light\"\n name=\"theme-color\"\n content={themeColorLight}\n media=\"(prefers-color-scheme: light)\"\n />\n )}\n {themeColorDark && (\n <meta\n key=\"theme-color-dark\"\n name=\"theme-color\"\n content={themeColorDark}\n media=\"(prefers-color-scheme: dark)\"\n />\n )}\n {children}\n </Head>\n )\n}\n\nexport const NextStudioHead = memo(NextStudioHeadComponent)\n","module.exports = new __parcel__URL__(\"apple-touch-icon.abc4aca2.png\").toString();","module.exports = new __parcel__URL__(\"favicon.648fc2f2.ico\").toString();","module.exports = new __parcel__URL__(\"favicon.8f76876f.svg\").toString();","module.exports = new __parcel__URL__(\"favicon-192.40c8bab4.png\").toString();","module.exports = new __parcel__URL__(\"favicon-512.5e08f951.png\").toString();","{\n \"icons\": [\n {\n \"src\": \"./favicon-192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"./favicon-512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ]\n}\n","// We can disable this rule safely as we're not trying to use it outside pages/document, we're shipping a wrapper\n// eslint-disable-next-line @next/next/no-document-import-in-page\nimport Document, {type DocumentContext} from 'next/document'\nimport {ServerStyleSheet} from 'styled-components'\n\n/**\n * Usage, from a pages/_document.tsx file:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {}\n *\n * To do extra stuff in getInitialProps:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n * import { type DocumentContext } from 'next/document'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {\n * static async getInitialProps(ctx: DocumentContext) {\n * // You can still override renderPage:\n * const originalRenderPage = ctx.renderPage\n * ctx.renderPage = () => originalRenderPage({\n * enhanceApp: (App) => (props) => <App {...props} />\n * })\n *\n * const initialProps = await ServerStyleSheetDocument.getInitialProps(ctx)\n * const extraStyles = await getStyles()\n * return {\n * ...initialProps,\n * styles: [initialProps.styles, extraStyles],\n * }\n * }\n * }\n */\n\nexport class ServerStyleSheetDocument extends Document {\n static async getInitialProps(ctx: DocumentContext) {\n const sheet = new ServerStyleSheet()\n const originalRenderPage = ctx.renderPage\n\n try {\n ctx.renderPage = () =>\n originalRenderPage({\n enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),\n })\n\n const initialProps = await Document.getInitialProps(ctx)\n return {\n ...initialProps,\n styles: [initialProps.styles, sheet.getStyleElement()],\n }\n } finally {\n sheet.seal()\n }\n }\n}\n","import {useRouter} from 'next/router'\nimport {useMemo} from 'react'\nimport {type Config, type StudioTheme, type WorkspaceOptions, defaultTheme} from 'sanity'\n\nexport function isWorkspaces(config: Config): config is WorkspaceOptions[] {\n return Array.isArray(config)\n}\n\nexport interface WorkspaceWithTheme extends Omit<WorkspaceOptions, 'theme'> {\n theme: StudioTheme\n}\n\nexport function isWorkspaceWithTheme(\n workspace: WorkspaceOptions\n): workspace is WorkspaceWithTheme {\n return Boolean(workspace.theme)\n}\n\nexport function useTheme(config: Config): StudioTheme {\n const workspace = useMemo<WorkspaceOptions>(\n () => (isWorkspaces(config) ? config[0] : config),\n [config]\n )\n return useMemo<StudioTheme>(\n () => (isWorkspaceWithTheme(workspace) ? workspace.theme : defaultTheme),\n [workspace]\n )\n}\n\nexport type MetaThemeColors = {\n themeColorLight: string\n themeColorDark: string\n}\nexport const useBackgroundColorsFromTheme = (theme: StudioTheme): MetaThemeColors => {\n return useMemo<MetaThemeColors>(\n () => ({\n themeColorLight: theme.color.light.default.base.bg,\n themeColorDark: theme.color.dark.default.base.bg,\n }),\n [theme]\n )\n}\n\n/**\n * Parses the next route to determine the what the base path for Sanity Studio should be\n */\nexport function useBasePath(): string {\n const router = useRouter()\n return useMemo(() => {\n const [basePath = '/'] = router.route.split('/[')\n return basePath\n }, [router.route])\n}\n\nexport interface WorkspaceWithBasePath extends Omit<WorkspaceOptions, 'basePath'> {\n basePath: string\n}\nexport type ConfigWithBasePath = WorkspaceWithBasePath | WorkspaceWithBasePath[]\n/**\n * Apply the base path from next to the config, prefixing any defined base path\n */\nexport function useConfigWithBasePath(config: Config): ConfigWithBasePath {\n const basePath = useBasePath()\n return useMemo(() => {\n if (isWorkspaces(config)) {\n return config.map((workspace) => ({\n ...workspace,\n basePath:\n workspace.basePath === '/' ? basePath : `${basePath}${workspace.basePath || ''}`,\n }))\n }\n return {\n ...config,\n basePath: config.basePath === '/' ? basePath : `${basePath}${config.basePath || ''}`,\n }\n }, [config, basePath])\n}\n"],"names":[],"version":3,"file":"studio.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA;;;;AAmDA;;;GAGG,CACH,MAAM,yCAAmB,GAAG,CAAC,YAC3B,QAAQ,CAAA,UACR,MAAM,CAAA,2BACN,uBAAuB,CAAA,8BACvB,0BAA0B,CAAA,kBAC1B,cAAc,CAAA,4BACd,wBAAwB,CAAA,gBACxB,YAAY,CAAA,wBACZ,oBAAoB,CAAA,EACpB,GAAG,KAAK,EACQ,GAAK;IACrB,MAAM,KA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QAAQ,EAAE,MAAM,CAAC,QAAQ,KAAK,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;SACrF,CAAA;KACF,EAAE;QAAC,MAAM;QAAE,QAAQ;KAAC,CAAC,CAAA;CACvB;;;;;;;;;AZ5ED","sources":["src/studio.ts","src/studio/index.ts","src/studio/NextStudio.tsx","src/studio/NextStudioGlobalStyle.ts","src/studio/NextStudioHead.tsx","node_modules/@parcel/runtime-js/lib/runtime-9e593bd92a039f93.js","node_modules/@parcel/runtime-js/lib/runtime-1d6e60dacba8bf0c.js","node_modules/@parcel/runtime-js/lib/runtime-9e05f9434f6564ff.js","node_modules/@parcel/runtime-js/lib/runtime-2e048d2a541e2a65.js","node_modules/@parcel/runtime-js/lib/runtime-daf66243b4f37b18.js","src/studio/webmanifest.json","src/studio/ServerStyleSheetDocument.tsx","src/studio/utils.ts"],"sourcesContent":["export * from './studio/index'\n","export * from './NextStudio'\nexport * from './NextStudioGlobalStyle'\nexport * from './NextStudioHead'\nexport * from './ServerStyleSheetDocument'\nexport * from './utils'\n","import {memo} from 'react'\nimport {type StudioProps, Studio} from 'sanity'\n\nimport {\n type NextStudioHeadProps,\n NextStudioGlobalStyle,\n NextStudioGlobalStyleProps,\n NextStudioHead,\n useBackgroundColorsFromTheme,\n useTheme,\n} from '.'\n\nexport interface NextStudioProps extends StudioProps {\n /**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n */\n children?: React.ReactNode\n /**\n * Turns off the default global styling\n */\n unstable__noGlobalStyle?: boolean\n /**\n * Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by defautl\n */\n unstable__noTailwindSvgFix?: NextStudioGlobalStyleProps['unstable__tailwindSvgFix']\n /**\n * Add stuff to the head with next/head\n */\n unstable__head?: NextStudioHeadProps['children']\n /**\n * Sets the document title\n */\n unstable__document_title?: NextStudioHeadProps['title']\n /**\n * Sets the background color of <html>\n */\n unstable__bg?: NextStudioGlobalStyleProps['bg']\n /**\n * Don't load the favicon meta tags\n */\n unstable__noFavicons?: boolean\n}\n/**\n * Intended to render at the root of a page, letting the Studio own that page and render much like it would if you used `npx sanity start` to render\n * It's a drop-in replacement for `import {Studio} from 'sanity'`\n */\nconst NextStudioComponent = ({\n children,\n config,\n unstable__noGlobalStyle,\n unstable__noTailwindSvgFix,\n unstable__head,\n unstable__document_title,\n unstable__bg,\n unstable__noFavicons,\n ...props\n}: NextStudioProps) => {\n const theme = useTheme(config)\n const {themeColorLight, themeColorDark} = useBackgroundColorsFromTheme(theme)\n return (\n <>\n {children || <Studio config={config} {...props} />}\n <NextStudioHead\n themeColorLight={themeColorLight}\n themeColorDark={themeColorDark}\n title={unstable__document_title}\n favicons={!unstable__noFavicons}\n >\n {unstable__head}\n </NextStudioHead>\n {!unstable__noGlobalStyle && (\n <NextStudioGlobalStyle\n bg={unstable__bg ?? themeColorLight}\n unstable__tailwindSvgFix={!unstable__noTailwindSvgFix}\n />\n )}\n </>\n )\n}\nexport const NextStudio = memo(NextStudioComponent)\n","import {createGlobalStyle, css} from 'styled-components'\n\nexport interface NextStudioGlobalStyleProps {\n bg?: string\n unstable__tailwindSvgFix?: boolean\n}\nexport const NextStudioGlobalStyle = createGlobalStyle<NextStudioGlobalStyleProps>`\n${({bg}) =>\n bg\n ? css`\n html {\n background-color: ${bg};\n }\n `\n : ''}\nhtml,\nbody,\n#__next {\n height: 100%;\n}\nbody {\n margin: 0;\n overscroll-behavior: none;\n -webkit-font-smoothing: antialiased;\n}\n${({unstable__tailwindSvgFix}) =>\n unstable__tailwindSvgFix\n ? css`\n /* override tailwind reset */\n :root svg {\n display: inline;\n }\n `\n : ''}`\n","/* eslint-disable no-process-env */\nimport Head from 'next/head'\nimport {type ComponentProps, memo, useCallback} from 'react'\n\n// @ts-ignore\nimport iconApple from './apple-touch-icon.png'\n// @ts-ignore\nimport iconIco from './favicon.ico'\n// @ts-ignore\nimport iconSvg from './favicon.svg'\n// @ts-ignore\nimport icon192 from './favicon-192.png'\n// @ts-ignore\nimport icon512 from './favicon-512.png'\nimport type {MetaThemeColors} from './utils'\nimport webmanifest from './webmanifest.json'\n\n// Interop between how Parcel and Next deals with asset imports\nconst interop = (href: string | {src: string}): string =>\n typeof href === 'string' ? href : href.src\n\nexport interface NextStudioHeadProps extends Partial<MetaThemeColors> {\n children?: ComponentProps<typeof Head>['children']\n title?: string\n favicons?: boolean\n}\nconst NextStudioHeadComponent = ({\n children,\n themeColorDark,\n themeColorLight,\n title = 'Sanity Studio',\n favicons,\n}: NextStudioHeadProps) => {\n const inlineWebmanifest = useCallback(() => {\n const manifest = JSON.parse(JSON.stringify(webmanifest))\n const icons = manifest.icons.map((icon: any) => {\n // Inline manifests works best when URLs are absolute\n const src =\n // eslint-disable-next-line no-nested-ternary\n icon.src === './favicon-192.png'\n ? interop(icon192)\n : icon.src === './favicon-512.png'\n ? interop(icon512)\n : icon.src\n return {\n ...icon,\n src: process.env.NEXT_PUBLIC_VERCEL_URL\n ? new URL(src, `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`).toString()\n : src,\n }\n })\n return `data:application/manifest+json,${encodeURIComponent(\n JSON.stringify({...manifest, icons})\n )}`\n }, [])\n\n return (\n <Head>\n <meta\n name=\"viewport\"\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n content=\"width=device-width, initial-scale=1, viewport-fit=cover\"\n />\n <meta name=\"robots\" content=\"noindex\" />\n <meta name=\"referrer\" content=\"same-origin\" />\n {title && <title>{title}</title>}\n {favicons && <link rel=\"icon\" href={interop(iconIco)} sizes=\"any\" />}\n {favicons && <link rel=\"icon\" href={interop(iconSvg)} type=\"image/svg+xml\" />}\n {favicons && <link rel=\"apple-touch-icon\" href={interop(iconApple)} />}\n {favicons && (\n <link\n rel=\"manifest\"\n // eslint-disable-next-line no-warning-comments\n // @TODO until parcel fixes https://github.com/parcel-bundler/parcel/issues/8025 and stops stripping process.env.NEXT_PUBLIC_VERCEL_URL from the compiled code, use the remove webmanifest\n href={\n process.env.NEXT_PUBLIC_VERCEL_URL\n ? inlineWebmanifest()\n : 'https://next.sanity.build/manifest.webmanifest'\n }\n />\n )}\n {/* These theme-color tags makes the Studio look really really good on devices like iPads as the browser chrome adopts the Studio background */}\n {themeColorLight && (\n <meta\n key=\"theme-color-light\"\n name=\"theme-color\"\n content={themeColorLight}\n media=\"(prefers-color-scheme: light)\"\n />\n )}\n {themeColorDark && (\n <meta\n key=\"theme-color-dark\"\n name=\"theme-color\"\n content={themeColorDark}\n media=\"(prefers-color-scheme: dark)\"\n />\n )}\n {children}\n </Head>\n )\n}\n\nexport const NextStudioHead = memo(NextStudioHeadComponent)\n","module.exports = new __parcel__URL__(\"apple-touch-icon.abc4aca2.png\").toString();","module.exports = new __parcel__URL__(\"favicon.648fc2f2.ico\").toString();","module.exports = new __parcel__URL__(\"favicon.8f76876f.svg\").toString();","module.exports = new __parcel__URL__(\"favicon-192.40c8bab4.png\").toString();","module.exports = new __parcel__URL__(\"favicon-512.5e08f951.png\").toString();","{\n \"icons\": [\n {\n \"src\": \"./favicon-192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"./favicon-512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ]\n}\n","// We can disable this rule safely as we're not trying to use it outside pages/document, we're shipping a wrapper\n// eslint-disable-next-line @next/next/no-document-import-in-page\nimport Document, {type DocumentContext} from 'next/document'\nimport {ServerStyleSheet} from 'styled-components'\n\n/**\n * Usage, from a pages/_document.tsx file:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {}\n *\n * To do extra stuff in getInitialProps:\n * import {ServerStyleSheetDocument} from 'next-sanity/studio'\n * import { type DocumentContext } from 'next/document'\n *\n * export default class MyDocument extends ServerStyleSheetDocument {\n * static async getInitialProps(ctx: DocumentContext) {\n * // You can still override renderPage:\n * const originalRenderPage = ctx.renderPage\n * ctx.renderPage = () => originalRenderPage({\n * enhanceApp: (App) => (props) => <App {...props} />\n * })\n *\n * const initialProps = await ServerStyleSheetDocument.getInitialProps(ctx)\n * const extraStyles = await getStyles()\n * return {\n * ...initialProps,\n * styles: [initialProps.styles, extraStyles],\n * }\n * }\n * }\n */\n\nexport class ServerStyleSheetDocument extends Document {\n static async getInitialProps(ctx: DocumentContext) {\n const sheet = new ServerStyleSheet()\n const originalRenderPage = ctx.renderPage\n\n try {\n ctx.renderPage = () =>\n originalRenderPage({\n enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />),\n })\n\n const initialProps = await Document.getInitialProps(ctx)\n return {\n ...initialProps,\n styles: [initialProps.styles, sheet.getStyleElement()],\n }\n } finally {\n sheet.seal()\n }\n }\n}\n","import {useRouter} from 'next/router'\nimport {useMemo} from 'react'\nimport {type Config, type StudioTheme, type WorkspaceOptions, defaultTheme} from 'sanity'\n\nexport function isWorkspaces(config: Config): config is WorkspaceOptions[] {\n return Array.isArray(config)\n}\n\nexport interface WorkspaceWithTheme extends Omit<WorkspaceOptions, 'theme'> {\n theme: StudioTheme\n}\n\nexport function isWorkspaceWithTheme(\n workspace: WorkspaceOptions\n): workspace is WorkspaceWithTheme {\n return Boolean(workspace.theme)\n}\n\nexport function useTheme(config: Config): StudioTheme {\n const workspace = useMemo<WorkspaceOptions>(\n () => (isWorkspaces(config) ? config[0] : config),\n [config]\n )\n return useMemo<StudioTheme>(\n () => (isWorkspaceWithTheme(workspace) ? workspace.theme : defaultTheme),\n [workspace]\n )\n}\n\nexport type MetaThemeColors = {\n themeColorLight: string\n themeColorDark: string\n}\nexport const useBackgroundColorsFromTheme = (theme: StudioTheme): MetaThemeColors => {\n return useMemo<MetaThemeColors>(\n () => ({\n themeColorLight: theme.color.light.default.base.bg,\n themeColorDark: theme.color.dark.default.base.bg,\n }),\n [theme]\n )\n}\n\n/**\n * Parses the next route to determine the what the base path for Sanity Studio should be\n */\nexport function useBasePath(): string {\n const router = useRouter()\n return useMemo(() => {\n const [basePath = '/'] = router.route.split('/[')\n return basePath\n }, [router.route])\n}\n\nexport interface WorkspaceWithBasePath extends Omit<WorkspaceOptions, 'basePath'> {\n basePath: string\n}\nexport type ConfigWithBasePath = WorkspaceWithBasePath | WorkspaceWithBasePath[]\n/**\n * Apply the base path from next to the config, prefixing any defined base path\n */\nexport function useConfigWithBasePath(config: Config): ConfigWithBasePath {\n const basePath = useBasePath()\n return useMemo(() => {\n if (isWorkspaces(config)) {\n return config.map((workspace) => ({\n ...workspace,\n basePath:\n workspace.basePath === '/' ? basePath : `${basePath}${workspace.basePath || ''}`,\n }))\n }\n return {\n ...config,\n basePath: config.basePath === '/' ? basePath : `${basePath}${config.basePath || ''}`,\n }\n }, [config, basePath])\n}\n"],"names":[],"version":3,"file":"studio.js.map"}
|
package/package.json
CHANGED
|
@@ -63,7 +63,7 @@ const NextStudioHeadComponent = ({
|
|
|
63
63
|
/>
|
|
64
64
|
<meta name="robots" content="noindex" />
|
|
65
65
|
<meta name="referrer" content="same-origin" />
|
|
66
|
-
<title>{title}</title>
|
|
66
|
+
{title && <title>{title}</title>}
|
|
67
67
|
{favicons && <link rel="icon" href={interop(iconIco)} sizes="any" />}
|
|
68
68
|
{favicons && <link rel="icon" href={interop(iconSvg)} type="image/svg+xml" />}
|
|
69
69
|
{favicons && <link rel="apple-touch-icon" href={interop(iconApple)} />}
|