next-sanity 13.1.2 → 13.1.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"NextStudioNoScript.js","names":[],"sources":["../src/studio/NextStudioLayout.tsx","../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst style = {\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n} satisfies React.CSSProperties\n\n/** @public */\nexport const NextStudioLayout = ({children}: NextStudioLayoutProps): React.JSX.Element => {\n return (\n <div id=\"sanity\" data-ui=\"NextStudioLayout\" style={style}>\n {children}\n </div>\n )\n}\n","const styles: Record<'outer' | 'inner', React.CSSProperties> = {\n outer: {\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n },\n inner: {\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\n/** @internal */\nexport const NextStudioNoScript = (): React.JSX.Element => (\n <noscript>\n <div style={styles.outer}>\n <div style={styles.inner}>\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"],"mappings":";AAKA,MAAM,QAAQ;CACZ,QAAQ;CACR,WAAW;CACX,oBAAoB;CACpB,qBAAqB;CACrB,UAAU;AACZ;;AAGA,MAAa,oBAAoB,EAAC,eAAwD;CACxF,OACE,oBAAC,OAAD;EAAK,IAAG;EAAS,WAAQ;EAA0B;EAChD;CACE,CAAA;AAET;ACpBA,MAAM,SAAyD;CAC7D,OAAO;EACL,UAAU;EACV,KAAK;EACL,OAAO;EACP,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,QAAQ;CACV;CACA,OAAO;EACL,UAAU;EACV,KAAK;EACL,MAAM;EACN,WAAW;EACX,WAAW;EACX,YAAY;CACd;AACF;;AAGA,MAAa,2BACX,oBAAC,YAAD,EAAA,UACE,oBAAC,OAAD;CAAK,OAAO,OAAO;WACjB,qBAAC,OAAD;EAAK,OAAO,OAAO;YAAnB,CACE,oBAAC,MAAD,EAAA,UAAI,sBAAuB,CAAA,GAC3B,qBAAC,KAAD,EAAA,UAAA;GAAG;GACM,oBAAC,KAAD;IAAG,MAAK;cAAqC;GAAoB,CAAA;GAAC;EAExE,EAAA,CAAA,CACA;;AACF,CAAA,EACG,CAAA"}
1
+ {"version":3,"file":"NextStudioNoScript.js","names":[],"sources":["../src/studio/NextStudioLayout.tsx","../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst style = {\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n} satisfies React.CSSProperties\n\n/** @public */\nexport const NextStudioLayout = ({children}: NextStudioLayoutProps): React.JSX.Element => {\n return (\n <div id=\"sanity\" data-ui=\"NextStudioLayout\" style={style}>\n {children}\n </div>\n )\n}\n","const styles: Record<'outer' | 'inner', React.CSSProperties> = {\n outer: {\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n },\n inner: {\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\n/** @internal */\nexport const NextStudioNoScript = (): React.JSX.Element => (\n <noscript>\n <div style={styles.outer}>\n <div style={styles.inner}>\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"],"mappings":";AAKA,MAAM,QAAQ;CACZ,QAAQ;CACR,WAAW;CACX,oBAAoB;CACpB,qBAAqB;CACrB,UAAU;AACZ;;AAGA,MAAa,oBAAoB,EAAC,eAAwD;CACxF,OACE,oBAAC,OAAD;EAAK,IAAG;EAAS,WAAQ;EAA0B;EAChD;CACE,CAAA;AAET;ACpBA,MAAM,SAAyD;CAC7D,OAAO;EACL,UAAU;EACV,KAAK;EACL,OAAO;EACP,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,QAAQ;CACV;CACA,OAAO;EACL,UAAU;EACV,KAAK;EACL,MAAM;EACN,WAAW;EACX,WAAW;EACX,YAAY;CACd;AACF;;AAGA,MAAa,2BACX,oBAAC,YAAD,EAAA,UACE,oBAAC,OAAD;CAAK,OAAO,OAAO;CACjB,UAAA,qBAAC,OAAD;EAAK,OAAO,OAAO;EAAnB,UAAA,CACE,oBAAC,MAAD,EAAA,UAAI,sBAAuB,CAAA,GAC3B,qBAAC,KAAD,EAAA,UAAA;GAAG;GACM,oBAAC,KAAD;IAAG,MAAK;IAAqC,UAAA;GAAoB,CAAA;GAAC;EAExE,EAAA,CAAA,CACA;;AACF,CAAA,EACG,CAAA"}
@@ -1,5 +1,5 @@
1
- import { t as isCorsOriginError } from "./isCorsOriginError.js";
2
1
  import { n as defaultApiHost, t as cacheTagPrefix } from "./constants.js";
2
+ import { t as isCorsOriginError } from "./isCorsOriginError.js";
3
3
  import { useRouter } from "next/navigation";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  import { createClient } from "@sanity/client";
@@ -87,7 +87,7 @@ function removeTrailingSlash(route) {
87
87
  return route.replace(/\/$/, "") || "/";
88
88
  }
89
89
  function VisualEditing(props) {
90
- const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex, onPerspectiveChange } = props;
90
+ const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex, onPerspectiveChange, keepStegaOnCopy, onSuspiciousStega } = props;
91
91
  const router = useRouter();
92
92
  const [navigate, setNavigate] = useState();
93
93
  const history = useMemo(() => ({
@@ -137,6 +137,8 @@ function VisualEditing(props) {
137
137
  portal: true,
138
138
  refresh: refresh ?? handleRefresh,
139
139
  onPerspectiveChange,
140
+ keepStegaOnCopy,
141
+ onSuspiciousStega,
140
142
  zIndex
141
143
  });
142
144
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VisualEditing.js","names":["VisualEditingComponent"],"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'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\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 {\n basePath = '',\n plugins,\n components,\n refresh,\n trailingSlash = false,\n zIndex,\n onPerspectiveChange,\n } = props\n\n const router = useRouter()\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\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 router.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return router.back()\n case 'replace':\n return router.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type`, {cause: update})\n }\n },\n }),\n [basePath, router],\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(\n `${pathname}${searchParams?.size ? `?${searchParams.toString()}` : ''}`,\n basePath,\n ),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh): false | Promise<void> => {\n switch (payload.source) {\n case 'manual':\n router.refresh()\n break\n case 'mutation': {\n // oxlint-disable-next-line no-console\n console.debug(\n '<VisualEditing /> refresh called with source \"mutation\", if you want automatic refresh when this happens, or silence this message, provide your own handler to the refresh prop',\n )\n return false\n }\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n return new Promise((resolve) => setTimeout(resolve, 1_000))\n },\n [router],\n )\n\n return (\n <VisualEditingComponent\n plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={refresh ?? handleRefresh}\n onPerspectiveChange={onPerspectiveChange}\n zIndex={zIndex}\n />\n )\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"VisualEditing.js","names":["VisualEditingComponent"],"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'\nimport {useCallback, useEffect, useMemo, useState} from 'react'\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 {\n basePath = '',\n plugins,\n components,\n refresh,\n trailingSlash = false,\n zIndex,\n onPerspectiveChange,\n keepStegaOnCopy,\n onSuspiciousStega,\n } = props\n\n const router = useRouter()\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\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 router.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return router.back()\n case 'replace':\n return router.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type`, {cause: update})\n }\n },\n }),\n [basePath, router],\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(\n `${pathname}${searchParams?.size ? `?${searchParams.toString()}` : ''}`,\n basePath,\n ),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh): false | Promise<void> => {\n switch (payload.source) {\n case 'manual':\n router.refresh()\n break\n case 'mutation': {\n // oxlint-disable-next-line no-console\n console.debug(\n '<VisualEditing /> refresh called with source \"mutation\", if you want automatic refresh when this happens, or silence this message, provide your own handler to the refresh prop',\n )\n return false\n }\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n return new Promise((resolve) => setTimeout(resolve, 1_000))\n },\n [router],\n )\n\n return (\n <VisualEditingComponent\n plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={refresh ?? handleRefresh}\n onPerspectiveChange={onPerspectiveChange}\n keepStegaOnCopy={keepStegaOnCopy}\n onSuspiciousStega={onSuspiciousStega}\n zIndex={zIndex}\n />\n )\n}\n"],"mappings":"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"}
package/dist/constants.js CHANGED
@@ -1,6 +1,14 @@
1
1
  const cacheTagPrefix = "sanity:";
2
2
  /** The default API host used by @sanity/client when none is specified. */
3
3
  const defaultApiHost = "https://api.sanity.io";
4
- export { defaultApiHost as n, cacheTagPrefix as t };
4
+ /**
5
+ * Companion cookie set alongside CHIPS-partitioned draft-mode cookies.
6
+ * Presence of this cookie tells later writes (e.g. perspective changes via
7
+ * server actions) to keep using the `Partitioned` attribute.
8
+ *
9
+ * @see https://github.com/sanity-io/sanity/issues/12806
10
+ */
11
+ const partitionedCookieName = "sanity-preview-partitioned";
12
+ export { defaultApiHost as n, partitionedCookieName as r, cacheTagPrefix as t };
5
13
 
6
14
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/live/shared/constants.ts"],"sourcesContent":["import type {CacheTagPrefix} from '#live/types'\n\n// @TODO make this configurable\nexport const cacheTagPrefix: 'sanity:' = 'sanity:' satisfies CacheTagPrefix\n\n/** The default API host used by @sanity/client when none is specified. */\nexport const defaultApiHost = 'https://api.sanity.io'\n"],"mappings":"AAGA,MAAa,iBAA4B;;AAGzC,MAAa,iBAAiB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/live/shared/constants.ts"],"sourcesContent":["import type {CacheTagPrefix} from '#live/types'\n\n// @TODO make this configurable\nexport const cacheTagPrefix: 'sanity:' = 'sanity:' satisfies CacheTagPrefix\n\n/** The default API host used by @sanity/client when none is specified. */\nexport const defaultApiHost = 'https://api.sanity.io'\n\n/**\n * Companion cookie set alongside CHIPS-partitioned draft-mode cookies.\n * Presence of this cookie tells later writes (e.g. perspective changes via\n * server actions) to keep using the `Partitioned` attribute.\n *\n * @see https://github.com/sanity-io/sanity/issues/12806\n */\nexport const partitionedCookieName = 'sanity-preview-partitioned'\n"],"mappings":"AAGA,MAAa,iBAA4B;;AAGzC,MAAa,iBAAiB;;;;;;;;AAS9B,MAAa,wBAAwB"}
@@ -21,6 +21,14 @@ interface EnableDraftMode {
21
21
  /**
22
22
  * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.
23
23
  * Can also be used with `sanity-plugin-iframe-pane`.
24
+ *
25
+ * When the preview loads in a cross-site iframe (Presentation Tool), draft-mode
26
+ * cookies are set with the CHIPS `Partitioned` attribute so Safari 18.4+ stores
27
+ * them despite third-party cookie blocking. Top-level / same-site requests keep
28
+ * unpartitioned cookies so `draftMode().disable()` continues to work.
29
+ *
30
+ * @see https://github.com/sanity-io/sanity/issues/12806
31
+ *
24
32
  * @example
25
33
  * ```ts
26
34
  * // src/app/api/draft-mode/enable/route.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"mappings":";;;;UASiB;EACf,QAAQ;;;;;;;EAOR;;;;;UAMe;EACf,MAAM,SAAS,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;iBAoBrB,sBAAsB,SAAS,+BAA+B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"mappings":";;;;UAWiB;EACf,QAAQ;;;;;;;EAOR;;;;;UAMe;EACf,MAAM,SAAS,YAAY,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BrB,sBAAsB,SAAS,+BAA+B"}
@@ -1,3 +1,4 @@
1
+ import { r as partitionedCookieName } from "../constants.js";
1
2
  import { validatePreviewUrl } from "@sanity/preview-url-secret";
2
3
  import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
3
4
  import { cookies, draftMode } from "next/headers";
@@ -5,6 +6,14 @@ import { redirect } from "next/navigation";
5
6
  /**
6
7
  * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.
7
8
  * Can also be used with `sanity-plugin-iframe-pane`.
9
+ *
10
+ * When the preview loads in a cross-site iframe (Presentation Tool), draft-mode
11
+ * cookies are set with the CHIPS `Partitioned` attribute so Safari 18.4+ stores
12
+ * them despite third-party cookie blocking. Top-level / same-site requests keep
13
+ * unpartitioned cookies so `draftMode().disable()` continues to work.
14
+ *
15
+ * @see https://github.com/sanity-io/sanity/issues/12806
16
+ *
8
17
  * @example
9
18
  * ```ts
10
19
  * // src/app/api/draft-mode/enable/route.ts
@@ -27,6 +36,7 @@ function defineEnableDraftMode(options) {
27
36
  const draftModeStore = await draftMode();
28
37
  if (!draftModeStore.isEnabled) draftModeStore.enable();
29
38
  const isSecure = process.env.NODE_ENV === "production" || (options.secureDevMode ?? false);
39
+ const partitioned = isSecure && request.headers.get("sec-fetch-dest") === "iframe" && request.headers.get("sec-fetch-site") === "cross-site";
30
40
  const cookieStore = await cookies();
31
41
  const cookie = cookieStore.get("__prerender_bypass");
32
42
  cookieStore.set({
@@ -35,7 +45,8 @@ function defineEnableDraftMode(options) {
35
45
  httpOnly: true,
36
46
  path: "/",
37
47
  secure: isSecure,
38
- sameSite: isSecure ? "none" : "lax"
48
+ sameSite: isSecure ? "none" : "lax",
49
+ partitioned
39
50
  });
40
51
  if (studioPreviewPerspective) cookieStore.set({
41
52
  name: perspectiveCookieName,
@@ -43,7 +54,17 @@ function defineEnableDraftMode(options) {
43
54
  httpOnly: true,
44
55
  path: "/",
45
56
  secure: isSecure,
46
- sameSite: isSecure ? "none" : "lax"
57
+ sameSite: isSecure ? "none" : "lax",
58
+ partitioned
59
+ });
60
+ if (partitioned) cookieStore.set({
61
+ name: partitionedCookieName,
62
+ value: "1",
63
+ httpOnly: true,
64
+ path: "/",
65
+ secure: true,
66
+ sameSite: "none",
67
+ partitioned: true
47
68
  });
48
69
  return redirect(redirectTo);
49
70
  } };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import type {SanityClient} from '@sanity/client'\nimport {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\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n /**\n * Force secure cookies in development mode.\n * Enable this when using Next.js --experimental-https flag.\n * This option has no effect in production (cookies are always secure).\n * @defaultValue false\n */\n secureDevMode?: boolean\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 // @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 const isProduction = process.env.NODE_ENV === 'production'\n\n // We can't auto-detect HTTPS in dev due to Next.js limitations,\n // so we need an explicit option\n const isSecure = isProduction || (options.secureDevMode ?? false)\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: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n })\n }\n\n return redirect(redirectTo)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,sBAAsB,SAAwD;CAC5F,MAAM,EAAC,WAAU;CACjB,OAAO,EACL,KAAK,OAAO,YAAqB;EAG/B,MAAM,EACJ,SACA,aAAa,KACb,6BACE,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;EAChD,IAAI,CAAC,SACH,OAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,IAAG,CAAC;EAGrD,MAAM,iBAAiB,MAAM,UAAU;EAGvC,IAAI,CAAC,eAAe,WAClB,eAAe,OAAO;EAOxB,MAAM,WAJe,QAAQ,IAAI,aAAa,iBAIZ,QAAQ,iBAAiB;EAI3D,MAAM,cAAc,MAAM,QAAQ;EAClC,MAAM,SAAS,YAAY,IAAI,oBAAoB;EACnD,YAAY,IAAI;GACd,MAAM;GACN,OAAO,QAAQ;GACf,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU,WAAW,SAAS;EAChC,CAAC;EAED,IAAI,0BACF,YAAY,IAAI;GACd,MAAM;GACN,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU,WAAW,SAAS;EAChC,CAAC;EAGH,OAAO,SAAS,UAAU;CAC5B,EACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import type {SanityClient} from '@sanity/client'\nimport {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 {partitionedCookieName} from '#live/constants'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n /**\n * Force secure cookies in development mode.\n * Enable this when using Next.js --experimental-https flag.\n * This option has no effect in production (cookies are always secure).\n * @defaultValue false\n */\n secureDevMode?: boolean\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 *\n * When the preview loads in a cross-site iframe (Presentation Tool), draft-mode\n * cookies are set with the CHIPS `Partitioned` attribute so Safari 18.4+ stores\n * them despite third-party cookie blocking. Top-level / same-site requests keep\n * unpartitioned cookies so `draftMode().disable()` continues to work.\n *\n * @see https://github.com/sanity-io/sanity/issues/12806\n *\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 // @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 const isProduction = process.env.NODE_ENV === 'production'\n\n // We can't auto-detect HTTPS in dev due to Next.js limitations,\n // so we need an explicit option\n const isSecure = isProduction || (options.secureDevMode ?? false)\n\n // Safari blocks unpartitioned third-party cookies. When the enable route is\n // hit from a cross-site iframe (Presentation), opt into CHIPS so the cookies\n // are stored under the studio's partition. Skip partitioning for top-level /\n // same-site requests so draftMode().disable() can still clear them.\n // https://github.com/sanity-io/sanity/issues/12806\n const partitioned =\n isSecure &&\n request.headers.get('sec-fetch-dest') === 'iframe' &&\n request.headers.get('sec-fetch-site') === 'cross-site'\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: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n partitioned,\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n partitioned,\n })\n }\n\n // Persist the partitioning decision for later writes (server actions have no\n // Sec-Fetch iframe signal). The flag cookie is itself partitioned, so it is\n // only visible inside the same cross-site iframe context.\n if (partitioned) {\n cookieStore.set({\n name: partitionedCookieName,\n value: '1',\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: true,\n })\n }\n\n return redirect(redirectTo)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,sBAAsB,SAAwD;CAC5F,MAAM,EAAC,WAAU;CACjB,OAAO,EACL,KAAK,OAAO,YAAqB;EAG/B,MAAM,EACJ,SACA,aAAa,KACb,6BACE,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;EAChD,IAAI,CAAC,SACH,OAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,IAAG,CAAC;EAGrD,MAAM,iBAAiB,MAAM,UAAU;EAGvC,IAAI,CAAC,eAAe,WAClB,eAAe,OAAO;EAOxB,MAAM,WAJe,QAAQ,IAAI,aAAa,iBAIZ,QAAQ,iBAAiB;EAO3D,MAAM,cACJ,YACA,QAAQ,QAAQ,IAAI,gBAAgB,MAAM,YAC1C,QAAQ,QAAQ,IAAI,gBAAgB,MAAM;EAI5C,MAAM,cAAc,MAAM,QAAQ;EAClC,MAAM,SAAS,YAAY,IAAI,oBAAoB;EACnD,YAAY,IAAI;GACd,MAAM;GACN,OAAO,QAAQ;GACf,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU,WAAW,SAAS;GAC9B;EACF,CAAC;EAED,IAAI,0BACF,YAAY,IAAI;GACd,MAAM;GACN,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU,WAAW,SAAS;GAC9B;EACF,CAAC;EAMH,IAAI,aACF,YAAY,IAAI;GACd,MAAM;GACN,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU;GACV,aAAa;EACf,CAAC;EAGH,OAAO,SAAS,UAAU;CAC5B,EACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
1
  import { t as cacheTagPrefix } from "../../../constants.js";
2
+ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
3
3
  import { i as preconnect, n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
4
4
  import { t as parseTags } from "../../../parseTags.js";
5
5
  import { jsx } from "react/jsx-runtime";
@@ -1,5 +1,5 @@
1
- import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
1
  import "../../../constants.js";
2
+ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
3
3
  import { i as preconnect, n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
4
4
  import { t as parseTags } from "../../../parseTags.js";
5
5
  import { cookies, draftMode } from "next/headers";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"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"],"mappings":";;;;;;;;;;AAYA,MAAM,4BAA4B,WAAW,OAAO,sBAAe;AAEnE,SAAgB,8BAA8B,OAAyC;CACrF,OACE,oBAAC,UAAD;EAAU,UAAU;YAClB,oBAAC,2BAAD,EAA2B,GAAI,MAAQ,CAAA;CAC/B,CAAA;AAEd"}
1
+ {"version":3,"file":"index.js","names":[],"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"],"mappings":";;;;;;;;;;AAYA,MAAM,4BAA4B,WAAW,OAAO,sBAAe;AAEnE,SAAgB,8BAA8B,OAAyC;CACrF,OACE,oBAAC,UAAD;EAAU,UAAU;EAClB,UAAA,oBAAC,2BAAD,EAA2B,GAAI,MAAQ,CAAA;CAC/B,CAAA;AAEd"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"mappings":";;;;iBAYsB,wBAAwB,aAAa,oBAAoB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"mappings":";;;;iBAasB,wBAAwB,aAAa,oBAAoB"}
@@ -1,4 +1,5 @@
1
1
  "use server";
2
+ import { r as partitionedCookieName } from "../../constants.js";
2
3
  import { t as sanitizePerspective } from "../../sanitizePerspective.js";
3
4
  import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
4
5
  import { cookies } from "next/headers";
@@ -19,7 +20,8 @@ async function perspectiveChangeAction(perspective) {
19
20
  httpOnly: true,
20
21
  path: "/",
21
22
  secure: true,
22
- sameSite: "none"
23
+ sameSite: "none",
24
+ partitioned: jar.has(partitionedCookieName)
23
25
  });
24
26
  refresh();
25
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function perspectiveChangeAction(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('perspectiveChangeAction', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;AAYA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,QAAQ;CACtE,IACE,CAAC,wBACA,MAAM,QAAQ,oBAAoB,KAAK,qBAAqB,WAAW,GAExE,MAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,YAAW,CAAC;CAG7D,MAAM,kBAAkB,MAAM,QAAQ,oBAAoB,IACtD,qBAAqB,KAAK,GAAG,IAC7B;CACJ,MAAM,MAAM,MAAM,QAAQ;CAC1B,IACE,oBAAoB,IAAI,IAAI,qBAAqB,CAAC,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;EAEA,QAAQ,MAAM,2BAA2B,qCAAqC,eAAe;EAC7F;CACF;CACA,IAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;CACZ,CAAC;CAED,QAAQ;AACV"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nimport {partitionedCookieName} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function perspectiveChangeAction(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (\n nextPerspective === jar.get(perspectiveCookieName)?.value &&\n process.env.NODE_ENV !== 'production'\n ) {\n // oxlint-disable-next-line no-console\n console.debug('perspectiveChangeAction', 'Perspective is the same, skipping', nextPerspective)\n return\n }\n // Mirror the CHIPS partitioning decision from defineEnableDraftMode. Server\n // actions do not receive Sec-Fetch iframe headers, so we rely on the companion\n // flag cookie set during enable.\n // https://github.com/sanity-io/sanity/issues/12806\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n partitioned: jar.has(partitionedCookieName),\n })\n\n refresh()\n}\n"],"mappings":";;;;;;;;;AAaA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,QAAQ;CACtE,IACE,CAAC,wBACA,MAAM,QAAQ,oBAAoB,KAAK,qBAAqB,WAAW,GAExE,MAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,YAAW,CAAC;CAG7D,MAAM,kBAAkB,MAAM,QAAQ,oBAAoB,IACtD,qBAAqB,KAAK,GAAG,IAC7B;CACJ,MAAM,MAAM,MAAM,QAAQ;CAC1B,IACE,oBAAoB,IAAI,IAAI,qBAAqB,CAAC,EAAE,SACpD,QAAQ,IAAI,aAAa,cACzB;EAEA,QAAQ,MAAM,2BAA2B,qCAAqC,eAAe;EAC7F;CACF;CAKA,IAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACV,aAAa,IAAI,IAAI,qBAAqB;CAC5C,CAAC;CAED,QAAQ;AACV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "13.1.2",
3
+ "version": "13.1.4",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "live",
@@ -59,41 +59,39 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@portabletext/react": "^6.2.0",
62
- "@sanity/client": "^7.23.0",
62
+ "@sanity/client": "^7.24.0",
63
63
  "@sanity/generate-help-url": "^4.0.0",
64
- "@sanity/preview-url-secret": "^4.0.7",
65
- "@sanity/visual-editing": "^5.4.5",
64
+ "@sanity/preview-url-secret": "^4.0.8",
65
+ "@sanity/visual-editing": "^5.5.0",
66
66
  "@sanity/webhook": "^4.0.4",
67
- "groq": "^6.2.0",
67
+ "groq": "^6.5.0",
68
68
  "history": "^5.3.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@sanity/tsconfig": "^2.2.0",
72
- "@types/js-yaml": "^4.0.9",
73
- "@types/node": "^24.13.2",
71
+ "@sanity/tsconfig": "^2.2.1",
72
+ "@types/node": "^24.13.3",
74
73
  "@types/react": "^19.2.17",
75
74
  "@types/react-dom": "^19.2.3",
76
75
  "@vercel/stega": "^1.1.0",
77
76
  "@vitejs/plugin-react": "^6.0.3",
78
77
  "@vitest/browser-playwright": "^4.1.10",
79
78
  "@vitest/coverage-v8": "^4.1.10",
80
- "js-yaml": "^4.2.0",
79
+ "js-yaml": "^5.2.1",
81
80
  "msw": "^2.15.0",
82
- "next": "16.3.0-canary.83",
81
+ "next": "16.3.0-canary.90",
83
82
  "publint": "^0.3.21",
84
83
  "react": "^19.2.7",
85
84
  "react-dom": "^19.2.7",
86
- "styled-components": "^6.4.3",
87
- "tsdown": "^0.22.7",
88
- "typedoc": "^0.28.20",
89
- "typescript": "6.0.3",
90
- "vite": "^8.1.4",
85
+ "styled-components": "^6.4.4",
86
+ "tsdown": "^0.22.12",
87
+ "typescript": "7.0.2",
88
+ "vite": "^8.1.5",
91
89
  "vitest": "^4.1.10",
92
90
  "vitest-browser-react": "^2.2.0",
93
91
  "vitest-package-exports": "^1.2.0"
94
92
  },
95
93
  "peerDependencies": {
96
- "@sanity/client": "^7.23.0",
94
+ "@sanity/client": "^7.24.0",
97
95
  "next": "^16.0.0-0",
98
96
  "react": "^19.2.3",
99
97
  "react-dom": "^19.2.3",
@@ -113,8 +111,7 @@
113
111
  "coverage": "npm test -- --coverage",
114
112
  "dev": "tsdown --watch",
115
113
  "test": "vitest --project unit",
116
- "test:e2e": "vitest --project browser",
117
114
  "test:coverage": "vitest --coverage run",
118
- "docs:generate": "typedoc"
115
+ "test:e2e": "vitest --project browser"
119
116
  }
120
117
  }