next-sanity 9.8.8 → 9.8.10

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 CHANGED
@@ -768,9 +768,11 @@ export const {GET} = defineEnableDraftMode({
768
768
  ```
769
769
 
770
770
  The main benefit of `defineEnableDraftMode` is that it fully implements all of Sanity Presentation Tool's features, including the perspective switcher:
771
+
771
772
  <img width="530" alt="image" src="https://github.com/user-attachments/assets/774d8f92-527f-4478-8089-2fb7e6a5c618">
772
773
 
773
774
  And the Preview URL Sharing feature:
775
+
774
776
  <img width="450" alt="image" src="https://github.com/user-attachments/assets/d11b38eb-389b-448f-862c-b39b3adbb7e3">
775
777
 
776
778
  In your `sanity.config.ts`, set the `previewMode.enable` option for `presentationTool`:
@@ -1 +1 @@
1
- {"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\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 * ```\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 * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":["history","createHashHistory","useState","ServerStyleSheet","useServerInsertedHTML","jsx","Fragment","StyleSheetManager","useSyncExternalStore","useMemo","jsxs","NextStudioNoScript","NextStudioLayout","Studio"],"mappings":";;AAGO,SAAS,6BAAsC;AACpD,QAAMA,YAAUC,QAAAA;AACT,SAAA;AAAA,IACL,IAAI,SAAS;AACX,aAAOD,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,WAAW;AACb,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,aAAa;AACf,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,KAAK;AACP,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AACV,aAAOA,UAAQ;AAAA,IACjB;AAAA;AAAA,IAEA,O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,uBAAY,UAAU,CAAC,YACpB,OACA,YACEP,2BAAA;AAAA,MAACQ,OAAA;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,uBAAqB;AAAA,QACpB,GAAG;AAAA,QACJ,kBAAkB;AAAA,MAAA;AAAA,OAG5B,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;;"}
1
+ {"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\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 * ```\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 * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":["history","createHashHistory","useState","ServerStyleSheet","useServerInsertedHTML","jsx","Fragment","StyleSheetManager","useSyncExternalStore","useMemo","jsxs","NextStudioNoScript","NextStudioLayout","Studio"],"mappings":";;AAGO,SAAS,6BAAsC;AACpD,QAAMA,YAAUC,QAAAA,kBAAkB;AAC3B,SAAA;AAAA,IACL,IAAI,SAAS;AACX,aAAOD,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,WAAW;AACb,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,aAAa;AACf,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,KAAK;AACP,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AACV,aAAOA,UAAQ;AAAA,IACjB;AAAA;AAAA,IAEA,OAAO,UAAoB;AAEzB,aAAOA,UAAQ,OAAO,CAAC,EAAC,eAAc;AAGpC,iBAAS,QAAQ;AAAA,MAAA,CAClB;AAAA,IAAA;AAAA,EAEL;AACF;ACtCO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGgB;AAGd,QAAM,CAAC,0BAA0B,IAAIE,eAAS,MAAM,IAAIC,mCAAkB;AAQ1E,SANAC,oCAAs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x","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div\n id=\"sanity\"\n data-ui=\"NextStudioLayout\"\n style={{\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n }}\n >\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","/** @internal */\nexport const NextStudioNoScript = (): JSX.Element => (\n <noscript>\n <div\n style={{\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n }}\n >\n <div\n style={{\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n }}\n >\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":["jsx","memo","jsxs"],"mappings":";;AAOA,MAAM,4BAA4B,CAAC,EAAC,SAAA,MAEhCA,2BAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,WAAQ;AAAA,IACR,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,qBAAqB;AAAA,MACrB,UAAU;AAAA,IACZ;AAAA,IAEC;AAAA,EAAA;AACH,GAKS,mBAAmBC,WAAK,yBAAyB,GCzBjD,qBAAqB,MAChCD,2BAAA,IAAC,YACC,EAAA,UAAAA,2BAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAO;AAAA,MACL,UAAU;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV;AAAA,IAEA,UAAAE,2BAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,WAAW;AAAA,UACX,YAAY;AAAA,QACd;AAAA,QAEA,UAAA;AAAA,UAAAF,2BAAAA,IAAC,QAAG,UAAmB,sBAAA,CAAA;AAAA,0CACtB,KAAE,EAAA,UAAA;AAAA,YAAA;AAAA,YACOA,2BAAA,IAAA,KAAA,EAAE,MAAK,sCAAqC,UAAiB,qBAAA;AAAA,YAAI;AAAA,UAAA,GAE3E;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AACF,EACF,CAAA;;;"}
1
+ {"version":3,"file":"NextStudioNoScript.cjs","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div\n id=\"sanity\"\n data-ui=\"NextStudioLayout\"\n style={{\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n }}\n >\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","/** @internal */\nexport const NextStudioNoScript = (): JSX.Element => (\n <noscript>\n <div\n style={{\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n }}\n >\n <div\n style={{\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n }}\n >\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":["jsx","memo","jsxs"],"mappings":";;AAOA,MAAM,4BAA4B,CAAC,EAAC,SAAA,MAEhCA,2BAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,WAAQ;AAAA,IACR,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,qBAAqB;AAAA,MACrB,UAAU;AAAA,IACZ;AAAA,IAEC;AAAA,EAAA;AACH,GAKS,mBAAmBC,WAAK,yBAAyB,GCzBjD,qBAAqB,MAChCD,2BAAA,IAAC,YACC,EAAA,UAAAA,2BAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAO;AAAA,MACL,UAAU;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV;AAAA,IAEA,UAAAE,2BAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,WAAW;AAAA,UACX,YAAY;AAAA,QACd;AAAA,QAEA,UAAA;AAAA,UAAAF,2BAAAA,IAAC,QAAG,UAAmB,sBAAA,CAAA;AAAA,0CACtB,KAAE,EAAA,UAAA;AAAA,YAAA;AAAA,YACOA,2BAAA,IAAA,KAAA,EAAE,MAAK,sCAAqC,UAAiB,qBAAA;AAAA,YAAI;AAAA,UAAA,EAE3E,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AACF,EACF,CAAA;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"VisualEditing.cjs","sources":["../../src/visual-editing/client-component/utils.ts","../../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {createPortal} from 'react-dom'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {basePath = '', components, refresh, trailingSlash = false, zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data',\n )\n routerRef.current.refresh()\n return Promise.resolve()\n }\n const manualFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n const mutationFastRefresh = (): false => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n }\n const mutationFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n switch (payload.source) {\n case 'manual':\n return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh()\n case 'mutation':\n return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh()\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n },\n [refresh],\n )\n\n const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent\n components={components}\n history={history}\n refresh={handleRefresh}\n zIndex={zIndex}\n />,\n node,\n )\n}\n"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","node","createPortal","jsx","VisualEditingComponent"],"mappings":";;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAE/D,SAAA,YAAY,YAAY,KACnB;AAAA,IACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,SAAS;AAAA,IAC7D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,MAAS,IAAI;AAAA,IACvF,MAAM,YAAY,KAAK,KAAK,MAAM,SAAS,IAAI;AAAA,EAAA,IAI5C,EAAC,UAAU,MAAM,OAAO,IAAI,MAAM;AAC3C;AAOgB,SAAA,cAAc,MAAc,QAAyB;AACnE,MAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC;AACrB,WAAA;AAGT,MAAI,SAAS,OAAO;AACX,WAAA;AAGT,QAAM,EAAC,UAAU,OAAO,KAAI,IAAI,UAAU,IAAI;AAC9C,SAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,IAAI;AAC5C;AAWgB,SAAA,iBAAiB,MAAc,QAAwB;AAajE,MAAA,CAAC,cAAc,MAAM,MAAM;AACtB,WAAA;AAIT,QAAM,gBAAgB,KAAK,MAAM,OAAO,MAAM;AAG9C,SAAI,cAAc,WAAW,GAAG,IACvB,gB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,EAE7C,GACC,CAAE,CAAA,GAEA,OAEEC,SAAA;AAAA,IACLC,2BAAA;AAAA,MAACC,QAAA;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,IACA;AAAA,EATgB,IAAA;AAWpB;;"}
1
+ {"version":3,"file":"VisualEditing.cjs","sources":["../../src/visual-editing/client-component/utils.ts","../../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {createPortal} from 'react-dom'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {basePath = '', components, refresh, trailingSlash = false, zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data',\n )\n routerRef.current.refresh()\n return Promise.resolve()\n }\n const manualFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n const mutationFastRefresh = (): false => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n }\n const mutationFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n switch (payload.source) {\n case 'manual':\n return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh()\n case 'mutation':\n return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh()\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n },\n [refresh],\n )\n\n const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent\n components={components}\n history={history}\n refresh={handleRefresh}\n zIndex={zIndex}\n />,\n node,\n )\n}\n"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","node","createPortal","jsx","VisualEditingComponent"],"mappings":";;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAE/D,SAAA,YAAY,YAAY,KACnB;AAAA,IACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,SAAS;AAAA,IAC7D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,MAAS,IAAI;AAAA,IACvF,MAAM,YAAY,KAAK,KAAK,MAAM,SAAS,IAAI;AAAA,EAAA,IAI5C,EAAC,UAAU,MAAM,OAAO,IAAI,MAAM,GAAE;AAC7C;AAOgB,SAAA,cAAc,MAAc,QAAyB;AACnE,MAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC;AACrB,WAAA;AAGT,M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AAAA,KAGJ,CAAC,MAAM,OAAO,IAAIN,MAAAA,SAAgC,IAAI;AAmB5D,SAlBAC,gBAAU,MAAM;AAIRM,UAAAA,QAAO,SAAS,cAAc,KAAK;AAGzCA,WAAAA,MAAK,KAAK,yBACV,SAAS,gBAAgB,YAAYA,KAAI,GACzC,QAAQA,KAAI,GACL,MAAM;AACH,cAAA,IAAI,GACR,SAAS,gBAAgB,SAASA,KAAI,KACxC,SAAS,gBAAgB,YAAYA,KAAI;AAAA,IAE7C;AAAA,EAAA,GACC,CAAE,CAAA,GAEA,OAEEC,SAAA;AAAA,IACLC,2BAAA;AAAA,MAACC,QAAA;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,IACA;AAAA,EAAA,IATgB;AAWpB;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"NextStudio.js","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\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 * ```\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 * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAGO,SAAS,6BAAsC;AACpD,QAAM,UAAU;AACT,SAAA;AAAA,IACL,IAAI,SAAS;AACX,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,WAAW;AACb,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,aAAa;AACf,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,KAAK;AACP,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AACV,aAAO,QAAQ;AAAA,IACjB;AAAA;AAAA,IAEA,OAAO,UAAoB;AAEzB,aAAO,QAAQ,OAAO,CAAC,EAAC,eAAc;AAGpC,iBAAS,QAAQ;AAAA,MAAA,CACl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file":"NextStudio.js","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\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 * ```\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 * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry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AAC;AC8BpC,SAAwB,oBAAoB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAuC;AACrC,QAAM,YAAY,aAAA,GACZ,kBAAkB,QAAuC,MAAM;AACnE,QAAI,MAAM,oBAAoB;AACtB,YAAA,IAAI,MAAM,yEAAyE;AAG3F,WAAI,aAAa,YAAY,SACpB,+BAEF,MAAM;AAAA,KACZ,CAAC,SAAS,WAAW,MAAM,gBAAgB,CAAC;AAE/C,SAEK,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,0CAAuB,oBAAmB,EAAA;AAAA,IAC3C,oBAAC,0BAAyB,EAAA,WACxB,UAAC,oBAAA,kBAAA,EACE,sBAAY,UAAU,CAAC,YACpB,OACA,YACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,uBAAqB;AAAA,QACpB,GAAG;AAAA,QACJ,kBAAkB;AAAA,MAAA;AAAA,OAG5B,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"NextStudioNoScript.js","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div\n id=\"sanity\"\n data-ui=\"NextStudioLayout\"\n style={{\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n }}\n >\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","/** @internal */\nexport const NextStudioNoScript = (): JSX.Element => (\n <noscript>\n <div\n style={{\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n }}\n >\n <div\n style={{\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n }}\n >\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":[],"mappings":";;AAOA,MAAM,4BAA4B,CAAC,EAAC,SAAA,MAEhC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,WAAQ;AAAA,IACR,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,qBAAqB;AAAA,MACrB,UAAU;AAAA,IACZ;AAAA,IAEC;AAAA,EAAA;AACH,GAKS,mBAAmB,KAAK,yBAAyB,GCzBjD,qBAAqB,MAChC,oBAAC,YACC,EAAA,UAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAO;AAAA,MACL,UAAU;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV;AAAA,IAEA,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,WAAW;AAAA,UACX,YAAY;AAAA,QACd;AAAA,QAEA,UAAA;AAAA,UAAA,oBAAC,QAAG,UAAmB,sBAAA,CAAA;AAAA,+BACtB,KAAE,EAAA,UAAA;AAAA,YAAA;AAAA,YACO,oBAAA,KAAA,EAAE,MAAK,sCAAqC,UAAiB,qBAAA;AAAA,YAAI;AAAA,UAAA,GAE3E;AAAA,QAAA;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AACF,EACF,CAAA;"}
1
+ {"version":3,"file":"NextStudioNoScript.js","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div\n id=\"sanity\"\n data-ui=\"NextStudioLayout\"\n style={{\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n }}\n >\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","/** @internal */\nexport const NextStudioNoScript = (): JSX.Element => (\n <noscript>\n <div\n style={{\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n }}\n >\n <div\n style={{\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n }}\n >\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":[],"mappings":";;AAOA,MAAM,4BAA4B,CAAC,EAAC,SAAA,MAEhC;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,WAAQ;AAAA,IACR,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,WAAW;AAAA,MACX,oBAAoB;AAAA,MACpB,qBAAqB;AAAA,MACrB,UAAU;AAAA,IACZ;AAAA,IAEC;AAAA,EAAA;AACH,GAKS,mBAAmB,KAAK,yBAAyB,GCzBjD,qBAAqB,MAChC,oBAAC,YACC,EAAA,UAAA;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,OAAO;AAAA,MACL,UAAU;AAAA,MACV,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,YAAY;AAAA,MACZ,QAAQ;AAAA,IACV;AAAA,IAEA,UAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,OAAO;AAAA,UACL,UAAU;AAAA,UACV,KAAK;AAAA,UACL,MAAM;AAAA,UACN,WAAW;AAAA,UACX,WAAW;AAAA,UACX,YAAY;AAAA,QACd;AAAA,QAEA,UAAA;AAAA,UAAA,oBAAC,QAAG,UAAmB,sBAAA,CAAA;AAAA,+BACtB,KAAE,EAAA,UAAA;AAAA,YAAA;AAAA,YACO,oBAAA,KAAA,EAAE,MAAK,sCAAqC,UAAiB,qBAAA;AAAA,YAAI;AAAA,UAAA,EAE3E,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AACF,EACF,CAAA;"}
@@ -1 +1 @@
1
- {"version":3,"file":"VisualEditing.js","sources":["../../src/visual-editing/client-component/utils.ts","../../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {createPortal} from 'react-dom'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {basePath = '', components, refresh, trailingSlash = false, zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data',\n )\n routerRef.current.refresh()\n return Promise.resolve()\n }\n const manualFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n const mutationFastRefresh = (): false => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n }\n const mutationFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n switch (payload.source) {\n case 'manual':\n return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh()\n case 'mutation':\n return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh()\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n },\n [refresh],\n )\n\n const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent\n components={components}\n history={history}\n refresh={handleRefresh}\n zIndex={zIndex}\n />,\n node,\n )\n}\n"],"names":["node","VisualEditingComponent"],"mappings":";;;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAE/D,SAAA,YAAY,YAAY,KACnB;AAAA,IACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,SAAS;AAAA,IAC7D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,MAAS,I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,qBAAqB,oBAAoB,IAAI,wBAAwB;AAAA,QACtF;AACE,gBAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,QAAQ,CAAA;AAAA,MAC9D;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,KAGJ,CAAC,MAAM,OAAO,IAAI,SAAgC,IAAI;AAmB5D,SAlBA,UAAU,MAAM;AAIRA,UAAAA,QAAO,SAAS,cAAc,KAAK;AAGzCA,WAAAA,MAAK,KAAK,yBACV,SAAS,gBAAgB,YAAYA,KAAI,GACzC,QAAQA,KAAI,GACL,MAAM;AACH,cAAA,IAAI,GACR,SAAS,gBAAgB,SAASA,KAAI,KACxC,SAAS,gBAAgB,YAAYA,KAAI;AAAA,IAAA;AAAA,EAE7C,GACC,CAAE,CAAA,GAEA,OAEE;AAAA,IACL;AAAA,MAACC;AAAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,IACA;AAAA,EATgB,IAAA;AAWpB;"}
1
+ {"version":3,"file":"VisualEditing.js","sources":["../../src/visual-editing/client-component/utils.ts","../../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {createPortal} from 'react-dom'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {basePath = '', components, refresh, trailingSlash = false, zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data',\n )\n routerRef.current.refresh()\n return Promise.resolve()\n }\n const manualFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n const mutationFastRefresh = (): false => {\n // eslint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n }\n const mutationFallbackRefresh = () => {\n // eslint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n switch (payload.source) {\n case 'manual':\n return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh()\n case 'mutation':\n return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh()\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n },\n [refresh],\n )\n\n const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent\n components={components}\n history={history}\n refresh={handleRefresh}\n zIndex={zIndex}\n />,\n node,\n )\n}\n"],"names":["node","VisualEditingComponent"],"mappings":";;;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAE/D,SAAA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AAA,SAEK,qBAAqB;AAG9B,cAAQ,QAAQ,QAAQ;AAAA,QACtB,KAAK;AACH,iBAAO,QAAQ,qBAAqB,kBAAkB,IAAI,sBAAsB;AAAA,QAClF,KAAK;AACH,iBAAO,QAAQ,qBAAqB,oBAAoB,IAAI,wBAAwB;AAAA,QACtF;AACE,gBAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ;AAAA,MAAA;AAAA,IAEhE;AAAA,IACA,CAAC,OAAO;AAAA,KAGJ,CAAC,MAAM,OAAO,IAAI,SAAgC,IAAI;AAmB5D,SAlBA,UAAU,MAAM;AAIRA,UAAAA,QAAO,SAAS,cAAc,KAAK;AAGzCA,WAAAA,MAAK,KAAK,yBACV,SAAS,gBAAgB,YAAYA,KAAI,GACzC,QAAQA,KAAI,GACL,MAAM;AACH,cAAA,IAAI,GACR,SAAS,gBAAgB,SAASA,KAAI,KACxC,SAAS,gBAAgB,YAAYA,KAAI;AAAA,IAE7C;AAAA,EAAA,GACC,CAAE,CAAA,GAEA,OAEE;AAAA,IACL;AAAA,MAACC;AAAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,IACA;AAAA,EAAA,IATgB;AAWpB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":["validatePreviewUrl","draftMode","cookies","perspectiveCookieName","redirect"],"mappings":";;;AAsCO,SAAS,sBAAsB,SAAwD;AACtF,QAAA,EAAC,OAAU,IAAA;AACV,SAAA;AAAA,IACL,KAAK,OAAO,YAAqB;AAIzB,YAAA;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MACE,IAAA,MAAMA,iBAAAA,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,IAAI,CAAA;AAG/C,YAAA,iBAAiB,MAAMC,QAAAA;AAGxB,qBAAe,aAClB,eAAe;AAKjB,YAAM,cAAc,MAAMC,mBACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAMC,UAAA;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAIIC,WAAAA,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":["validatePreviewUrl","draftMode","cookies","perspectiveCookieName","redirect"],"mappings":";;;AAsCO,SAAS,sBAAsB,SAAwD;AACtF,QAAA,EAAC,WAAU;AACV,SAAA;AAAA,IACL,KAAK,OAAO,YAAqB;AAIzB,YAAA;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MACE,IAAA,MAAMA,iBAAmB,mBAAA,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAG/C,YAAA,iBAAiB,MAAMC,kBAAU;AAGlC,qBAAe,aAClB,eAAe,OAAO;AAKxB,YAAM,cAAc,MAAMC,mBACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAMC,UAAA;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAIIC,WAAA,SAAS,UAAU;AAAA,IAAA;AAAA,EAE9B;AACF;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":[],"mappings":";;;;AAsCO,SAAS,sBAAsB,SAAwD;AACtF,QAAA,EAAC,OAAU,IAAA;AACV,SAAA;AAAA,IACL,KAAK,OAAO,YAAqB;AAIzB,YAAA;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MACE,IAAA,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,IAAI,CAAA;AAG/C,YAAA,iBAAiB,MAAM;AAGxB,qBAAe,aAClB,eAAe;AAKjB,YAAM,cAAc,MAAM,WACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAII,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":[],"mappings":";;;;AAsCO,SAAS,sBAAsB,SAAwD;AACtF,QAAA,EAAC,WAAU;AACV,SAAA;AAAA,IACL,KAAK,OAAO,YAAqB;AAIzB,YAAA;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MACE,IAAA,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAG/C,YAAA,iBAAiB,MAAM,UAAU;AAGlC,qBAAe,aAClB,eAAe,OAAO;AAKxB,YAAM,cAAc,MAAM,WACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,UAAU;AAAA,MAAA,CACX,GAII,SAAS,UAAU;AAAA,IAAA;AAAA,EAE9B;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"image.cjs","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n url.searchParams.set(\n 'fit',\n url.searchParams.get('fit') || url.searchParams.has('h') ? 'min' : 'max',\n )\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["jsx","NextImage"],"mappings":";;;;;;;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AAC/C,QAAA,MAAM,IAAI,IAAI,GAAG;AAMvB,MALA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GACrC,IAAI,aAAa;AAAA,IACf;AAAA,IACA,IAAI,aAAa,IAAI,KAAK,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ;AAAA,EAAA,GAEjE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AACzD,QAAA,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAU,CAAA;AAAA,EAC3F;AACA,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAU,CAAA,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,UAAU,GAEvC,IAAI;AACb;ACDO,SAAS,MAAM,OAAgC;AACpD,QAAM,EAAC,QAAQ,KAAK,GAAG,SAAQ;AAC3B,MAAA;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGA,MAAA;AACA,MAAA;AACO,aAAA,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,WAExC,KAAK;AACN,UAAA,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EACH;AACO,SAAAA,+BAACC,mBAAAA,WAAW,GAAG,MAAM,KAAK,OAAO,SAAY,GAAA,QAAQ,YAAa,CAAA;AAC3E;;;"}
1
+ {"version":3,"file":"image.cjs","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n url.searchParams.set(\n 'fit',\n url.searchParams.get('fit') || url.searchParams.has('h') ? 'min' : 'max',\n )\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["jsx","NextImage"],"mappings":";;;;;;;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AAC/C,QAAA,MAAM,IAAI,IAAI,GAAG;AAMvB,MALA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GACrC,IAAI,aAAa;AAAA,IACf;AAAA,IACA,IAAI,aAAa,IAAI,KAAK,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ;AAAA,EAAA,GAEjE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AACzD,QAAA,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAA,CAAU;AAAA,EAAA;AAE3F,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAA,CAAU,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,SAAU,CAAA,GAEvC,IAAI;AACb;ACDO,SAAS,MAAM,OAAgC;AACpD,QAAM,EAAC,QAAQ,KAAK,GAAG,KAAQ,IAAA;AAC3B,MAAA;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEE,MAAA;AACA,MAAA;AACO,aAAA,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,WAExC,KAAK;AACN,UAAA,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EAAA;AAEI,SAAAA,+BAACC,mBAAAA,WAAW,GAAG,MAAM,KAAK,OAAO,SAAY,GAAA,QAAQ,aAAa;AAC3E;;;"}
package/dist/image.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n url.searchParams.set(\n 'fit',\n url.searchParams.get('fit') || url.searchParams.has('h') ? 'min' : 'max',\n )\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AAC/C,QAAA,MAAM,IAAI,IAAI,GAAG;AAMvB,MALA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GACrC,IAAI,aAAa;AAAA,IACf;AAAA,IACA,IAAI,aAAa,IAAI,KAAK,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ;AAAA,EAAA,GAEjE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AACzD,QAAA,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAU,CAAA;AAAA,EAC3F;AACA,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAU,CAAA,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,UAAU,GAEvC,IAAI;AACb;ACDO,SAAS,MAAM,OAAgC;AACpD,QAAM,EAAC,QAAQ,KAAK,GAAG,SAAQ;AAC3B,MAAA;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGA,MAAA;AACA,MAAA;AACO,aAAA,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,WAExC,KAAK;AACN,UAAA,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EACH;AACO,SAAA,oBAAC,aAAW,GAAG,MAAM,KAAK,OAAO,SAAY,GAAA,QAAQ,YAAa,CAAA;AAC3E;"}
1
+ {"version":3,"file":"image.js","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n url.searchParams.set(\n 'fit',\n url.searchParams.get('fit') || url.searchParams.has('h') ? 'min' : 'max',\n )\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AAC/C,QAAA,MAAM,IAAI,IAAI,GAAG;AAMvB,MALA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GACrC,IAAI,aAAa;AAAA,IACf;AAAA,IACA,IAAI,aAAa,IAAI,KAAK,KAAK,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ;AAAA,EAAA,GAEjE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AACzD,QAAA,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAA,CAAU;AAAA,EAAA;AAE3F,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAA,CAAU,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,SAAU,CAAA,GAEvC,IAAI;AACb;ACDO,SAAS,MAAM,OAAgC;AACpD,QAAM,EAAC,QAAQ,KAAK,GAAG,KAAQ,IAAA;AAC3B,MAAA;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEE,MAAA;AACA,MAAA;AACO,aAAA,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,WAExC,KAAK;AACN,UAAA,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EAAA;AAEI,SAAA,oBAAC,aAAW,GAAG,MAAM,KAAK,OAAO,SAAY,GAAA,QAAQ,aAAa;AAC3E;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":["jsx","VisualEditingComponent"],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,aAGtD,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEE,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,aAGhE,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAGA,SAAAA,2BAAA;AAAA,IAACC,gCAAA;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":["jsx","VisualEditingComponent"],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAC3D;AAAA,aAEK,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAAA;AAG9C,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MACrE;AAAA,aAEK,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IAAA;AAIrD,SAAAA,2BAAA;AAAA,IAACC,gCAAA;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EACxC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":[],"mappings":";;;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,aAGtD,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEE,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,aAGhE,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAGA,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;"}
1
+ {"version":3,"file":"index.js","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // eslint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":[],"mappings":";;;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAC3D;AAAA,aAEK,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAAA;AAG9C,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MACrE;AAAA,aAEK,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IAAA;AAIrD,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EACxC;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-component.cjs","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;;AAYA,MAAM,4BAA4BA,MAAA,KAAK,MAAM,QAAO,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAA,+BAAc;AAAC,CAAA,CAAA;AAE5D,SAAS,8BAA8B,OAAyC;AAEnF,SAAAC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,2BAA2B,EAAA,GAAG,MAAO,CAAA,EACxC,CAAA;AAEJ;;"}
1
+ {"version":3,"file":"client-component.cjs","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;;AAYA,MAAM,4BAA4BA,MAAA,KAAK,MAAM,QAAO,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAA,+BAAc;EAAC;AAE5D,SAAS,8BAA8B,OAAyC;AAEnF,SAAAC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,2BAA2B,EAAA,GAAG,OAAO,EACxC,CAAA;AAEJ;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-component.js","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,4BAA4B,KAAK,MAAM,OAAO,6BAAc,CAAC;AAE5D,SAAS,8BAA8B,OAAyC;AAEnF,SAAA,oBAAC,YAAS,UAAU,MAClB,8BAAC,2BAA2B,EAAA,GAAG,MAAO,CAAA,EACxC,CAAA;AAEJ;"}
1
+ {"version":3,"file":"client-component.js","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,4BAA4B,KAAK,MAAM,OAAO,6BAAc,CAAC;AAE5D,SAAS,8BAA8B,OAAyC;AAEnF,SAAA,oBAAC,YAAS,UAAU,MAClB,8BAAC,2BAA2B,EAAA,GAAG,OAAO,EACxC,CAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-component.cjs","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;AAYA,MAAM,+BAA+BA,MAAA,KAAK,MAAM,QAAO,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAA,kCAAiB;AAAC,CAAA,CAAA;AAElE,SAAS,iCAAiC,OAA4C;AAEzF,SAAAC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,8BAA8B,EAAA,GAAG,MAAO,CAAA,EAC3C,CAAA;AAEJ;;"}
1
+ {"version":3,"file":"client-component.cjs","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;AAYA,MAAM,+BAA+BA,MAAA,KAAK,MAAM,QAAO,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAA,kCAAiB;EAAC;AAElE,SAAS,iCAAiC,OAA4C;AAEzF,SAAAC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,8BAA8B,EAAA,GAAG,OAAO,EAC3C,CAAA;AAEJ;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"client-component.js","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,+BAA+B,KAAK,MAAM,OAAO,gCAAiB,CAAC;AAElE,SAAS,iCAAiC,OAA4C;AAEzF,SAAA,oBAAC,YAAS,UAAU,MAClB,8BAAC,8BAA8B,EAAA,GAAG,MAAO,CAAA,EAC3C,CAAA;AAEJ;"}
1
+ {"version":3,"file":"client-component.js","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,+BAA+B,KAAK,MAAM,OAAO,gCAAiB,CAAC;AAElE,SAAS,iCAAiC,OAA4C;AAEzF,SAAA,oBAAC,YAAS,UAAU,MAClB,8BAAC,8BAA8B,EAAA,GAAG,OAAO,EAC3C,CAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"server-actions.cjs","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":["draftMode","revalidatePath"],"mappings":";;;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAMA,qBAAU,GAAG,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EACF;AACM,QAAAC,SAAA,eAAe,KAAK,QAAQ;AACpC;;"}
1
+ {"version":3,"file":"server-actions.cjs","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":["draftMode","revalidatePath"],"mappings":";;;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAMA,qBAAU,GAAG,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EAAA;AAEI,QAAAC,SAAA,eAAe,KAAK,QAAQ;AACpC;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"server-actions.js","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAM,UAAU,GAAG,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EACF;AACM,QAAA,eAAe,KAAK,QAAQ;AACpC;"}
1
+ {"version":3,"file":"server-actions.js","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAM,UAAU,GAAG,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EAAA;AAEI,QAAA,eAAe,KAAK,QAAQ;AACpC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.cjs","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACV;AACA;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,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;AAAA,IACvD;AAAA,IACA,IAAI,OAAO,MAAM;AAAA,IACjB,EAAE,MAAM,QAAQ,MAAM,UAAW;AAAA,IACjC;AAAA,IACA,CAAC,MAAM;AAAA,EACR,GAAE,mBAAmB,GAAG,SAAS,IAAI,kBAAkB,IAAI,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAK,IAAI,OAAO,gBAAgB,CAAC,GAAG,iBAAiB,MAAM,KAAK,IAAI,WAAW,SAAS,CAAC;AAClM,SAAO,KAAK,OAAO,aAAa,MAAM,MAAM,cAAc,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AACxH;ACxEA,eAAsB,UACpB,KACA,QACA,wCAAwC,IACb;AAC3B,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB;AACvD,MAAI,CAAC;AACH,WAAA,QAAQ,MAAM,0BAA0B,GACjC,EAAC,MAAM,MAAM,kBAAkB;AAGxC,QAAM,OAAO,MAAM,IAAI,QACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAM,CAAA,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,SAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EAAA;AAEtB;;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"webhook.cjs","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACP;AACH;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,QAAM,EAAE,UAAS,IAAK,sBAAsB,SAAS,GAAG,U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IACjB,EAAE,MAAM,QAAQ,MAAM,UAAW;AAAA,IACjC;AAAA,IACA,CAAC,MAAM;AAAA,EACR,GAAE,mBAAmB,GAAG,SAAS,IAAI,kBAAkB,IAAI,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAK,IAAI,OAAO,gBAAgB,CAAC,GAAG,iBAAiB,MAAM,KAAK,IAAI,WAAW,SAAS,CAAC;AAClM,SAAO,KAAK,OAAO,aAAa,MAAM,MAAM,cAAc,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AACxH;ACxEA,eAAsB,UACpB,KACA,QACA,wCAAwC,IACb;AAC3B,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB;AACvD,MAAI,CAAC;AACH,WAAA,QAAQ,MAAM,0BAA0B,GACjC,EAAC,MAAM,MAAM,kBAAkB,KAAI;AAG5C,QAAM,OAAO,MAAM,IAAI,QACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAA,CAAM,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,SAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EACpB;AACF;;","x_google_ignoreList":[0]}
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.js","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":"AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACV;AACA;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,QAAM,EAAE,UAAS,IAAK,sBAAsB,SAAS,GAAG,UAAU,MAAM,sBAAsB,oBAAoB,WAAW,M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AAW;AAAA,IACjC;AAAA,IACA,CAAC,MAAM;AAAA,EACR,GAAE,mBAAmB,GAAG,SAAS,IAAI,kBAAkB,IAAI,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAK,IAAI,OAAO,gBAAgB,CAAC,GAAG,iBAAiB,MAAM,KAAK,IAAI,WAAW,SAAS,CAAC;AAClM,SAAO,KAAK,OAAO,aAAa,MAAM,MAAM,cAAc,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AACxH;ACxEA,eAAsB,UACpB,KACA,QACA,wCAAwC,IACb;AAC3B,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB;AACvD,MAAI,CAAC;AACH,WAAA,QAAQ,MAAM,0BAA0B,GACjC,EAAC,MAAM,MAAM,kBAAkB;AAGxC,QAAM,OAAO,MAAM,IAAI,QACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAM,CAAA,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,SAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EAAA;AAEtB;","x_google_ignoreList":[0]}
1
+ {"version":3,"file":"webhook.js","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":"AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACP;AACH;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,QAAM,EAAE,UAAS,IAAK,sBAAsB,SAAS,GAAG,UAAU,MAAM,sBAAsB,oBAAoB,WAAW,MAAM;AACnI,MAAI,cAAc;AAChB,UAAM,IAAI,2BAA2B,s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AE,mBAAmB,GAAG,SAAS,IAAI,kBAAkB,IAAI,YAAY,MAAM,OAAO,OAAO,KAAK,QAAQ,KAAK,IAAI,OAAO,gBAAgB,CAAC,GAAG,iBAAiB,MAAM,KAAK,IAAI,WAAW,SAAS,CAAC;AAClM,SAAO,KAAK,OAAO,aAAa,MAAM,MAAM,cAAc,CAAC,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,EAAE;AACxH;ACxEA,eAAsB,UACpB,KACA,QACA,wCAAwC,IACb;AAC3B,QAAM,YAAY,IAAI,QAAQ,IAAI,qBAAqB;AACvD,MAAI,CAAC;AACH,WAAA,QAAQ,MAAM,0BAA0B,GACjC,EAAC,MAAM,MAAM,kBAAkB,KAAI;AAG5C,QAAM,OAAO,MAAM,IAAI,QACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAA,CAAM,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,SAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EACpB;AACF;","x_google_ignoreList":[0]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "9.8.8",
3
+ "version": "9.8.10",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "sanity",
@@ -138,23 +138,23 @@
138
138
  "browserslist": "extends @sanity/browserslist-config",
139
139
  "dependencies": {
140
140
  "@portabletext/react": "^3.1.0",
141
- "@sanity/client": "^6.22.2",
142
- "@sanity/next-loader": "1.1.0",
143
- "@sanity/preview-kit": "5.1.10",
144
- "@sanity/preview-url-secret": "2.0.0",
145
- "@sanity/visual-editing": "2.4.2",
146
- "groq": "^3.62.2",
141
+ "@sanity/client": "^6.22.3",
142
+ "@sanity/next-loader": "1.1.3",
143
+ "@sanity/preview-kit": "5.1.14",
144
+ "@sanity/preview-url-secret": "2.0.1",
145
+ "@sanity/visual-editing": "2.5.1",
146
+ "groq": "^3.63.0",
147
147
  "history": "^5.3.0"
148
148
  },
149
149
  "devDependencies": {
150
150
  "@sanity/browserslist-config": "^1.0.3",
151
151
  "@sanity/eslint-config-studio": "^4.0.0",
152
- "@sanity/pkg-utils": "^6.11.4",
152
+ "@sanity/pkg-utils": "^6.11.9",
153
153
  "@sanity/webhook": "4.0.4",
154
154
  "@types/react": "^18.3.12",
155
155
  "@types/react-dom": "^18.3.1",
156
156
  "@typescript-eslint/eslint-plugin": "^7.18.0",
157
- "@vitest/coverage-v8": "^2.1.3",
157
+ "@vitest/coverage-v8": "^2.1.4",
158
158
  "eslint": "^8.57.1",
159
159
  "eslint-config-prettier": "^9.1.0",
160
160
  "eslint-config-sanity": "^7.1.3",
@@ -164,17 +164,17 @@
164
164
  "eslint-plugin-react-hooks": "^5.0.0",
165
165
  "eslint-plugin-simple-import-sort": "^12.1.1",
166
166
  "ls-engines": "^0.9.3",
167
- "next": "15.0.1",
167
+ "next": "15.0.2",
168
168
  "react": "19.0.0-rc.0",
169
169
  "react-dom": "19.0.0-rc.0",
170
170
  "styled-components": "^6.1.13",
171
171
  "typescript": "5.6.3",
172
- "vite-tsconfig-paths": "^5.0.1",
173
- "vitest": "^2.1.3",
172
+ "vite-tsconfig-paths": "^5.1.0",
173
+ "vitest": "^2.1.4",
174
174
  "vitest-github-actions-reporter": "^0.11.1"
175
175
  },
176
176
  "peerDependencies": {
177
- "@sanity/client": "^6.22.2",
177
+ "@sanity/client": "^6.22.3",
178
178
  "@sanity/icons": "^3.4.0",
179
179
  "@sanity/types": "^3.62.0",
180
180
  "@sanity/ui": "^2.8.10",