next-sanity 9.8.30 → 9.8.32
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/dist/_chunks-cjs/VisualEditing.cjs.map +1 -1
- package/dist/draft-mode.cjs +5 -5
- package/dist/draft-mode.cjs.map +1 -1
- package/dist/draft-mode.js +5 -5
- package/dist/draft-mode.js.map +1 -1
- package/dist/studio.d.cts +2 -2
- package/dist/studio.d.ts +2 -2
- package/package.json +9 -9
- package/src/draft-mode/define-enable-draft-mode.ts +6 -4
|
@@ -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'\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 return (\n <VisualEditingComponent\n components={components}\n history={history}\n portal\n refresh={handleRefresh}\n zIndex={zIndex}\n />\n )\n}\n"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","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,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,M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-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'\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 return (\n <VisualEditingComponent\n components={components}\n history={history}\n portal\n refresh={handleRefresh}\n zIndex={zIndex}\n />\n )\n}\n"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","jsx","VisualEditingComponent"],"mappings":";;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,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AAA,QAAQ,OAAO;AAE7B,YAAA,oBAAoB,OAExB,QAAQ;AAAA,QACN;AAAA,MAAA,GAEF,UAAU,QAAQ,WACX,QAAQ,QAAQ,IAEnB,wBAAwB,OAE5B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAAC,cAAA,qBAAA,IAEH,sBAAsB,OAE1B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAA,KAEH,0BAA0B,OAE9B,QAAQ;AAAA,QACN;AAAA,SAEKA,cAAqB,qBAAA;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,EACV;AAGE,SAAAC,2BAAA;AAAA,IAACC,QAAA;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,QAAM;AAAA,MACN,SAAS;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;;"}
|
package/dist/draft-mode.cjs
CHANGED
|
@@ -14,21 +14,21 @@ function defineEnableDraftMode(options) {
|
|
|
14
14
|
return new Response("Invalid secret", { status: 401 });
|
|
15
15
|
const draftModeStore = await headers.draftMode();
|
|
16
16
|
draftModeStore.isEnabled || draftModeStore.enable();
|
|
17
|
-
const cookieStore = await headers.cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
17
|
+
const dev = process.env.NODE_ENV !== "production", cookieStore = await headers.cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
18
18
|
return cookieStore.set({
|
|
19
19
|
name: "__prerender_bypass",
|
|
20
20
|
value: cookie?.value,
|
|
21
21
|
httpOnly: !0,
|
|
22
22
|
path: "/",
|
|
23
|
-
secure: !
|
|
24
|
-
sameSite: "none"
|
|
23
|
+
secure: !dev,
|
|
24
|
+
sameSite: dev ? "lax" : "none"
|
|
25
25
|
}), studioPreviewPerspective && cookieStore.set({
|
|
26
26
|
name: constants.perspectiveCookieName,
|
|
27
27
|
value: studioPreviewPerspective,
|
|
28
28
|
httpOnly: !0,
|
|
29
29
|
path: "/",
|
|
30
|
-
secure: !
|
|
31
|
-
sameSite: "none"
|
|
30
|
+
secure: !dev,
|
|
31
|
+
sameSite: dev ? "lax" : "none"
|
|
32
32
|
}), navigation.redirect(redirectTo);
|
|
33
33
|
}
|
|
34
34
|
};
|
package/dist/draft-mode.cjs.map
CHANGED
|
@@ -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:
|
|
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 const dev = process.env.NODE_ENV !== 'production'\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: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : '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;AAGxB,YAAM,MAAM,QAAQ,IAAI,aAAa,cAI/B,cAAc,MAAMC,QAAAA,QACpB,GAAA,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAMC,UAAA;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAIIC,WAAA,SAAS,UAAU;AAAA,IAAA;AAAA,EAE9B;AACF;;"}
|
package/dist/draft-mode.js
CHANGED
|
@@ -15,21 +15,21 @@ function defineEnableDraftMode(options) {
|
|
|
15
15
|
return new Response("Invalid secret", { status: 401 });
|
|
16
16
|
const draftModeStore = await draftMode();
|
|
17
17
|
draftModeStore.isEnabled || draftModeStore.enable();
|
|
18
|
-
const cookieStore = await cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
18
|
+
const dev = process.env.NODE_ENV !== "production", cookieStore = await cookies(), cookie = cookieStore.get("__prerender_bypass");
|
|
19
19
|
return cookieStore.set({
|
|
20
20
|
name: "__prerender_bypass",
|
|
21
21
|
value: cookie?.value,
|
|
22
22
|
httpOnly: !0,
|
|
23
23
|
path: "/",
|
|
24
|
-
secure: !
|
|
25
|
-
sameSite: "none"
|
|
24
|
+
secure: !dev,
|
|
25
|
+
sameSite: dev ? "lax" : "none"
|
|
26
26
|
}), studioPreviewPerspective && cookieStore.set({
|
|
27
27
|
name: perspectiveCookieName,
|
|
28
28
|
value: studioPreviewPerspective,
|
|
29
29
|
httpOnly: !0,
|
|
30
30
|
path: "/",
|
|
31
|
-
secure: !
|
|
32
|
-
sameSite: "none"
|
|
31
|
+
secure: !dev,
|
|
32
|
+
sameSite: dev ? "lax" : "none"
|
|
33
33
|
}), redirect(redirectTo);
|
|
34
34
|
}
|
|
35
35
|
};
|
package/dist/draft-mode.js.map
CHANGED
|
@@ -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:
|
|
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 const dev = process.env.NODE_ENV !== 'production'\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: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : '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;AAGxB,YAAM,MAAM,QAAQ,IAAI,aAAa,cAI/B,cAAc,MAAM,QACpB,GAAA,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAII,SAAS,UAAU;AAAA,IAAA;AAAA,EAE9B;AACF;"}
|
package/dist/studio.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {JSX
|
|
1
|
+
import {JSX} from 'react'
|
|
2
2
|
import {MemoExoticComponent} from 'react'
|
|
3
3
|
import {NextStudio} from 'next-sanity/studio/client-component'
|
|
4
4
|
import {NextStudioProps} from 'next-sanity/studio/client-component'
|
|
@@ -30,7 +30,7 @@ export {NextStudio}
|
|
|
30
30
|
|
|
31
31
|
/** @public */
|
|
32
32
|
export declare const NextStudioLayout: MemoExoticComponent<
|
|
33
|
-
({children}: NextStudioLayoutProps) =>
|
|
33
|
+
({children}: NextStudioLayoutProps) => JSX.Element
|
|
34
34
|
>
|
|
35
35
|
|
|
36
36
|
/** @public */
|
package/dist/studio.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {JSX
|
|
1
|
+
import {JSX} from 'react'
|
|
2
2
|
import {MemoExoticComponent} from 'react'
|
|
3
3
|
import {NextStudio} from 'next-sanity/studio/client-component'
|
|
4
4
|
import {NextStudioProps} from 'next-sanity/studio/client-component'
|
|
@@ -30,7 +30,7 @@ export {NextStudio}
|
|
|
30
30
|
|
|
31
31
|
/** @public */
|
|
32
32
|
export declare const NextStudioLayout: MemoExoticComponent<
|
|
33
|
-
({children}: NextStudioLayoutProps) =>
|
|
33
|
+
({children}: NextStudioLayoutProps) => JSX.Element
|
|
34
34
|
>
|
|
35
35
|
|
|
36
36
|
/** @public */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "9.8.
|
|
3
|
+
"version": "9.8.32",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -142,31 +142,31 @@
|
|
|
142
142
|
"@sanity/next-loader": "1.2.8",
|
|
143
143
|
"@sanity/preview-kit": "5.1.26",
|
|
144
144
|
"@sanity/preview-url-secret": "2.0.5",
|
|
145
|
-
"@sanity/visual-editing": "2.11.
|
|
145
|
+
"@sanity/visual-editing": "2.11.4",
|
|
146
146
|
"groq": "^3.68.3",
|
|
147
147
|
"history": "^5.3.0"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@sanity/browserslist-config": "^1.0.5",
|
|
151
151
|
"@sanity/eslint-config-studio": "^5.0.1",
|
|
152
|
-
"@sanity/pkg-utils": "^6.
|
|
152
|
+
"@sanity/pkg-utils": "^6.13.1",
|
|
153
153
|
"@sanity/webhook": "4.0.4",
|
|
154
|
-
"@types/react": "^
|
|
155
|
-
"@types/react-dom": "^
|
|
154
|
+
"@types/react": "^19.0.3",
|
|
155
|
+
"@types/react-dom": "^19.0.2",
|
|
156
156
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
157
157
|
"@vitest/coverage-v8": "^2.1.8",
|
|
158
158
|
"eslint": "^8.57.1",
|
|
159
159
|
"eslint-config-prettier": "^9.1.0",
|
|
160
160
|
"eslint-config-sanity": "^7.1.3",
|
|
161
161
|
"eslint-gitignore": "^0.1.0",
|
|
162
|
-
"eslint-plugin-react": "^7.37.
|
|
162
|
+
"eslint-plugin-react": "^7.37.3",
|
|
163
163
|
"eslint-plugin-react-compiler": "beta",
|
|
164
164
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
165
165
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
166
|
-
"next": "15.1.
|
|
166
|
+
"next": "15.1.3",
|
|
167
167
|
"react": "19.0.0",
|
|
168
168
|
"react-dom": "19.0.0",
|
|
169
|
-
"styled-components": "^6.1.
|
|
169
|
+
"styled-components": "^6.1.14",
|
|
170
170
|
"typescript": "5.7.2",
|
|
171
171
|
"vite-tsconfig-paths": "^5.1.4",
|
|
172
172
|
"vitest": "^2.1.8",
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
},
|
|
175
175
|
"peerDependencies": {
|
|
176
176
|
"@sanity/client": "^6.24.1",
|
|
177
|
-
"@sanity/icons": "^3.5.
|
|
177
|
+
"@sanity/icons": "^3.5.6",
|
|
178
178
|
"@sanity/types": "^3.68.1",
|
|
179
179
|
"@sanity/ui": "^2.10.12",
|
|
180
180
|
"next": "^14.2 || ^15.0.0-0",
|
|
@@ -59,6 +59,8 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
59
59
|
draftModeStore.enable()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
const dev = process.env.NODE_ENV !== 'production'
|
|
63
|
+
|
|
62
64
|
// Override cookie header for draft mode for usage in live-preview
|
|
63
65
|
// https://github.com/vercel/next.js/issues/49927
|
|
64
66
|
const cookieStore = await cookies()
|
|
@@ -68,8 +70,8 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
68
70
|
value: cookie?.value,
|
|
69
71
|
httpOnly: true,
|
|
70
72
|
path: '/',
|
|
71
|
-
secure:
|
|
72
|
-
sameSite: 'none',
|
|
73
|
+
secure: !dev,
|
|
74
|
+
sameSite: dev ? 'lax' : 'none',
|
|
73
75
|
})
|
|
74
76
|
|
|
75
77
|
if (studioPreviewPerspective) {
|
|
@@ -78,8 +80,8 @@ export function defineEnableDraftMode(options: DefineEnableDraftModeOptions): En
|
|
|
78
80
|
value: studioPreviewPerspective,
|
|
79
81
|
httpOnly: true,
|
|
80
82
|
path: '/',
|
|
81
|
-
secure:
|
|
82
|
-
sameSite: 'none',
|
|
83
|
+
secure: !dev,
|
|
84
|
+
sameSite: dev ? 'lax' : 'none',
|
|
83
85
|
})
|
|
84
86
|
}
|
|
85
87
|
|