next-sanity 13.1.6 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/VisualEditing.js +2 -1
  2. package/dist/VisualEditing.js.map +1 -1
  3. package/dist/draft-mode/index.js +19 -2
  4. package/dist/draft-mode/index.js.map +1 -1
  5. package/dist/index.d.ts +9 -1
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +10 -1
  8. package/dist/index.js.map +1 -0
  9. package/dist/live/client-components/index.js +27 -1
  10. package/dist/live/client-components/index.js.map +1 -1
  11. package/dist/live/conditions/default/index.d.ts +77 -5
  12. package/dist/live/conditions/default/index.d.ts.map +1 -1
  13. package/dist/live/conditions/default/index.js +70 -1
  14. package/dist/live/conditions/default/index.js.map +1 -1
  15. package/dist/live/conditions/next-js/index.d.ts +10 -5
  16. package/dist/live/conditions/next-js/index.d.ts.map +1 -1
  17. package/dist/live/conditions/next-js/index.js +4 -3
  18. package/dist/live/conditions/next-js/index.js.map +1 -1
  19. package/dist/live/conditions/react-server/index.d.ts +10 -5
  20. package/dist/live/conditions/react-server/index.d.ts.map +1 -1
  21. package/dist/live/conditions/react-server/index.js +9 -3
  22. package/dist/live/conditions/react-server/index.js.map +1 -1
  23. package/dist/parseTags.d.ts +70 -1
  24. package/dist/parseTags.d.ts.map +1 -1
  25. package/dist/{resolvePerspectiveFromCookies.js → resolveVariantFromCookies.js} +73 -4
  26. package/dist/resolveVariantFromCookies.js.map +1 -0
  27. package/dist/sanitizeVariant.js +37 -0
  28. package/dist/sanitizeVariant.js.map +1 -0
  29. package/dist/types.d.ts +25 -0
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/visual-editing/index.d.ts.map +1 -1
  32. package/dist/visual-editing/index.js +2 -1
  33. package/dist/visual-editing/index.js.map +1 -1
  34. package/dist/visual-editing/server-actions/index.d.ts +5 -1
  35. package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
  36. package/dist/visual-editing/server-actions/index.js +36 -3
  37. package/dist/visual-editing/server-actions/index.js.map +1 -1
  38. package/package.json +4 -4
  39. package/dist/resolvePerspectiveFromCookies.js.map +0 -1
  40. package/dist/sanitizePerspective.js +0 -14
  41. package/dist/sanitizePerspective.js.map +0 -1
@@ -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, keepStegaOnCopy, onSuspiciousStega } = props;
90
+ const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex, onPerspectiveChange, onVariantChange, keepStegaOnCopy, onSuspiciousStega } = props;
91
91
  const router = useRouter();
92
92
  const [navigate, setNavigate] = useState();
93
93
  const history = useMemo(() => ({
@@ -137,6 +137,7 @@ function VisualEditing(props) {
137
137
  portal: true,
138
138
  refresh: refresh ?? handleRefresh,
139
139
  onPerspectiveChange,
140
+ onVariantChange,
140
141
  keepStegaOnCopy,
141
142
  onSuspiciousStega,
142
143
  zIndex
@@ -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 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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"}
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 onVariantChange,\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 onVariantChange={onVariantChange}\n keepStegaOnCopy={keepStegaOnCopy}\n onSuspiciousStega={onSuspiciousStega}\n zIndex={zIndex}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;CAC5D,IAAI,OAAO,SAAS,UAClB,OAAO;CAGT,MAAM,EAAC,aAAY,UAAU,IAAI;CACjC,OAAO,aAAa,UAAU,SAAS,WAAW,GAAG,OAAO,EAAE;AAChE;;;;;;;AAQA,SAAS,UAAU,MAIjB;CACA,MAAM,YAAY,KAAK,QAAQ,GAAG;CAClC,MAAM,aAAa,KAAK,QAAQ,GAAG;CACnC,MAAM,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;CAEnE,IAAI,YAAY,YAAY,IAC1B,OAAO;EACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,SAAS;EAC7D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,KAAA,CAAS,IAAI;EACvF,MAAM,YAAY,KAAK,KAAK,MAAM,SAAS,IAAI;CACjD;CAGF,OAAO;EAAC,UAAU;EAAM,OAAO;EAAI,MAAM;CAAE;AAC7C;;;;;;AAOA,SAAgB,cAAc,MAAc,QAAyB;CACnE,IAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC,QAC5B,OAAO;CAGT,IAAI,SAAS,OAAO,QAClB,OAAO;CAGT,MAAM,EAAC,UAAU,OAAO,SAAQ,UAAU,IAAI;CAC9C,OAAO,GAAG,SAAS,WAAW,QAAQ;AACxC;;;;;;;;;;AAWA,SAAgB,iBAAiB,MAAc,QAAwB;CAarE,IAAI,CAAC,cAAc,MAAM,MAAM,GAC7B,OAAO;CAIT,MAAM,gBAAgB,KAAK,MAAM,OAAO,MAAM;CAG9C,IAAI,cAAc,WAAW,GAAG,GAC9B,OAAO;CAKT,OAAO,IAAI;AACb;;;;;;AAOA,MAAa,8BAA8B,MAAc,kBAAmC;CAC1F,MAAM,EAAC,UAAU,OAAO,SAAQ,UAAU,IAAI;CAC9C,IAAI,eAAe;EACjB,IAAI,SAAS,SAAS,GAAG,GACvB,OAAO,GAAG,WAAW,QAAQ;EAE/B,OAAO,GAAG,SAAS,GAAG,QAAQ;CAChC;CAEA,OAAO,GAAG,oBAAoB,QAAQ,IAAI,QAAQ;AACpD;;;;;;;;;AAUA,SAAS,oBAAoB,OAAe;CAC1C,OAAO,MAAM,QAAQ,OAAO,EAAE,KAAK;AACrC;ACzFA,SAAwB,cAAc,OAAqD;CACzF,MAAM,EACJ,WAAW,IACX,SACA,YACA,SACA,gBAAgB,OAChB,QACA,qBACA,iBACA,iBACA,sBACE;CAEJ,MAAM,SAAS,UAAU;CACzB,MAAM,CAAC,UAAU,eAAe,SAA6C;CAE7E,MAAM,UAAU,eACP;EACL,YAAY,cAAc;GACxB,kBAAkB,SAAS;GAC3B,aAAa,YAAY,KAAA,CAAS;EACpC;EACA,SAAS,WAAW;GAClB,QAAQ,OAAO,MAAf;IACE,KAAK,QACH,OAAO,OAAO,KAAK,iBAAiB,OAAO,KAAK,QAAQ,CAAC;IAC3D,KAAK,OACH,OAAO,OAAO,KAAK;IACrB,KAAK,WACH,OAAO,OAAO,QAAQ,iBAAiB,OAAO,KAAK,QAAQ,CAAC;IAC9D,SACE,MAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,OAAM,CAAC;GAC1D;EACF;CACF,IACA,CAAC,UAAU,MAAM,CACnB;CAEA,MAAM,WAAW,YAAY;CAC7B,MAAM,eAAe,gBAAgB;CACrC,gBAAgB;EACd,IAAI,UACF,SAAS;GACP,MAAM;GACN,KAAK,2BACH,cACE,GAAG,WAAW,cAAc,OAAO,IAAI,aAAa,SAAS,MAAM,MACnE,QACF,GACA,aACF;EACF,CAAC;CAEL,GAAG;EAAC;EAAU;EAAU;EAAU;EAAc;CAAa,CAAC;CAE9D,MAAM,gBAAgB,aACnB,YAAmD;EAClD,QAAQ,QAAQ,QAAhB;GACE,KAAK;IACH,OAAO,QAAQ;IACf;GACF,KAAK;IAEH,QAAQ,MACN,mLACF;IACA,OAAO;GAET,SACE,MAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,QAAO,CAAC;EAC9D;EACA,OAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAK,CAAC;CAC5D,GACA,CAAC,MAAM,CACT;CAEA,OACE,oBAACA,iBAAD;EACW;EACG;EACH;EACT,QAAA;EACA,SAAS,WAAW;EACC;EACJ;EACA;EACE;EACX;CACT,CAAA;AAEL"}
@@ -1,6 +1,6 @@
1
1
  import { r as partitionedCookieName } from "../constants.js";
2
2
  import { validatePreviewUrl } from "@sanity/preview-url-secret";
3
- import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
3
+ import { perspectiveCookieName, variantCookieName } from "@sanity/preview-url-secret/constants";
4
4
  import { cookies, draftMode } from "next/headers";
5
5
  import { redirect } from "next/navigation";
6
6
  /**
@@ -31,7 +31,7 @@ import { redirect } from "next/navigation";
31
31
  function defineEnableDraftMode(options) {
32
32
  const { client } = options;
33
33
  return { GET: async (request) => {
34
- const { isValid, redirectTo = "/", studioPreviewPerspective } = await validatePreviewUrl(client, request.url);
34
+ const { isValid, redirectTo = "/", studioPreviewPerspective, studioPreviewVariant } = await validatePreviewUrl(client, request.url);
35
35
  if (!isValid) return new Response("Invalid secret", { status: 401 });
36
36
  const draftModeStore = await draftMode();
37
37
  if (!draftModeStore.isEnabled) draftModeStore.enable();
@@ -57,6 +57,23 @@ function defineEnableDraftMode(options) {
57
57
  sameSite: isSecure ? "none" : "lax",
58
58
  partitioned
59
59
  });
60
+ if (studioPreviewVariant) cookieStore.set({
61
+ name: variantCookieName,
62
+ value: studioPreviewVariant,
63
+ httpOnly: true,
64
+ path: "/",
65
+ secure: isSecure,
66
+ sameSite: isSecure ? "none" : "lax",
67
+ partitioned
68
+ });
69
+ else cookieStore.delete({
70
+ name: variantCookieName,
71
+ httpOnly: true,
72
+ path: "/",
73
+ secure: isSecure,
74
+ sameSite: isSecure ? "none" : "lax",
75
+ partitioned
76
+ });
60
77
  if (partitioned) cookieStore.set({
61
78
  name: partitionedCookieName,
62
79
  value: "1",
@@ -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\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
+ {"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, variantCookieName} 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 studioPreviewVariant,\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 if (studioPreviewVariant) {\n cookieStore.set({\n name: variantCookieName,\n value: studioPreviewVariant,\n httpOnly: true,\n path: '/',\n secure: isSecure,\n sameSite: isSecure ? 'none' : 'lax',\n partitioned,\n })\n } else {\n // Unlike perspective, the variant is optional on the enable URL. Entering\n // preview without a variant must clear any stale variant cookie from a\n // previous session, passing matching attributes so partitioned cookies\n // are actually removed.\n cookieStore.delete({\n name: variantCookieName,\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,0BACA,yBACE,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;EAGH,IAAI,sBACF,YAAY,IAAI;GACd,MAAM;GACN,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,UAAU,WAAW,SAAS;GAC9B;EACF,CAAC;OAMD,YAAY,OAAO;GACjB,MAAM;GACN,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"}
package/dist/index.d.ts CHANGED
@@ -5,4 +5,12 @@ import { CreateDataAttribute, CreateDataAttributeProps, createDataAttribute } fr
5
5
  import groq, { defineQuery } from "groq";
6
6
  export * from "@sanity/client";
7
7
  export * from "@portabletext/react";
8
- export { type CreateDataAttribute, type CreateDataAttributeProps, createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaClean, unstable__adapter, unstable__environment };
8
+ /**
9
+ * API version required for editing variants queries.
10
+ * Uses the `X` alias while variants are in beta; will move to a dated version when stable.
11
+ *
12
+ * @public
13
+ */
14
+ declare const variantsApiVersion = "X";
15
+ export { type CreateDataAttribute, type CreateDataAttributeProps, createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaClean, unstable__adapter, unstable__environment, variantsApiVersion };
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/variants/constants.ts"],"mappings":";;;;;;;;;;;;;cAMa"}
package/dist/index.js CHANGED
@@ -4,4 +4,13 @@ import { stegaClean } from "@sanity/client/stega";
4
4
  import { createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
5
5
  import groq, { defineQuery } from "groq";
6
6
  export * from "@portabletext/react";
7
- export { createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaClean, unstable__adapter, unstable__environment };
7
+ /**
8
+ * API version required for editing variants queries.
9
+ * Uses the `X` alias while variants are in beta; will move to a dated version when stable.
10
+ *
11
+ * @public
12
+ */
13
+ const variantsApiVersion = "X";
14
+ export { createClient, createDataAttribute, defineQuery, groq, isCorsOriginError, stegaClean, unstable__adapter, unstable__environment, variantsApiVersion };
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/variants/constants.ts"],"sourcesContent":["/**\n * API version required for editing variants queries.\n * Uses the `X` alias while variants are in beta; will move to a dated version when stable.\n *\n * @public\n */\nexport const variantsApiVersion = 'X'\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,qBAAqB"}
@@ -1,9 +1,35 @@
1
1
  "use client";
2
+ import { jsx } from "react/jsx-runtime";
2
3
  import dynamic from "next/dynamic";
4
+ import { startTransition, useEffect, useState } from "react";
5
+ const SanityLiveClientComponent = dynamic(() => import("../../SanityLive.js"), { ssr: false });
6
+ /**
7
+ * Renders `<SanityLive>` in the browser only, after hydration. `next/dynamic` with
8
+ * `ssr: false` keeps `@sanity/client` and the live event machinery in a separate chunk
9
+ * that's only downloaded if the component actually renders
10
+ * (https://github.com/sanity-io/next-sanity/issues/3306), and gives the Next.js bundler
11
+ * better optimization opportunities than `React.lazy`.
12
+ *
13
+ * The mount gate exists because `next/dynamic` implements `ssr: false` by throwing a
14
+ * `BailoutToCSRError` during server rendering, which leaves
15
+ * `<template data-dgst="BAILOUT_TO_CLIENT_SIDE_RENDERING">` markers (empty,
16
+ * client-rendered suspense boundaries) in otherwise fully prerendered HTML:
17
+ * https://github.com/sanity-io/next-sanity/issues/2525
18
+ * Gated behind the mount check the component only ever renders in the browser,
19
+ * where `next/dynamic` doesn't throw.
20
+ */
21
+ function SanityLiveLazyClientComponent(props) {
22
+ const [mounted, setMounted] = useState(false);
23
+ useEffect(() => {
24
+ startTransition(() => setMounted(true));
25
+ }, []);
26
+ if (!mounted) return null;
27
+ return /* @__PURE__ */ jsx(SanityLiveClientComponent, { ...props });
28
+ }
3
29
  /**
4
30
  * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
5
31
  */
6
- const SanityLive = dynamic(() => import("../../SanityLive.js"), { ssr: false });
32
+ const SanityLive = SanityLiveLazyClientComponent;
7
33
  export { SanityLive };
8
34
 
9
35
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;;;;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,MAAK,CACb"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/SanityLiveLazy.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useState} from 'react'\n\nimport type {SanityLiveProps} from './SanityLive'\n\nconst SanityLiveClientComponent: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n\n/**\n * Renders `<SanityLive>` in the browser only, after hydration. `next/dynamic` with\n * `ssr: false` keeps `@sanity/client` and the live event machinery in a separate chunk\n * that's only downloaded if the component actually renders\n * (https://github.com/sanity-io/next-sanity/issues/3306), and gives the Next.js bundler\n * better optimization opportunities than `React.lazy`.\n *\n * The mount gate exists because `next/dynamic` implements `ssr: false` by throwing a\n * `BailoutToCSRError` during server rendering, which leaves\n * `<template data-dgst=\"BAILOUT_TO_CLIENT_SIDE_RENDERING\">` markers (empty,\n * client-rendered suspense boundaries) in otherwise fully prerendered HTML:\n * https://github.com/sanity-io/next-sanity/issues/2525\n * Gated behind the mount check the component only ever renders in the browser,\n * where `next/dynamic` doesn't throw.\n */\nexport function SanityLiveLazyClientComponent(props: SanityLiveProps): React.JSX.Element | null {\n const [mounted, setMounted] = useState(false)\n useEffect(() => {\n // The transition keeps the previously committed UI (nothing) while the lazy chunk loads,\n // instead of committing the suspense fallback of `next/dynamic`'s own suspense boundary\n startTransition(() => setMounted(true))\n }, [])\n\n // On the server, and on the client during hydration, render nothing instead of throwing\n if (!mounted) return null\n\n return <SanityLiveClientComponent {...props} />\n}\n","'use client'\n\nimport type {SanityLiveProps} from './SanityLive'\nimport {SanityLiveLazyClientComponent} from './SanityLiveLazy'\n\n/**\n * @internal CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = SanityLiveLazyClientComponent\n"],"mappings":";;;;AAOA,MAAM,4BAAkE,cAChE,OAAO,wBACb,EAAC,KAAK,MAAK,CACb;;;;;;;;;;;;;;;;AAiBA,SAAgB,8BAA8B,OAAkD;CAC9F,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,gBAAgB;EAGd,sBAAsB,WAAW,IAAI,CAAC;CACxC,GAAG,CAAC,CAAC;CAGL,IAAI,CAAC,SAAS,OAAO;CAErB,OAAO,oBAAC,2BAAD,EAA2B,GAAI,MAAQ,CAAA;AAChD;;;;AC/BA,MAAa,aAAmD"}
@@ -1,6 +1,6 @@
1
1
  import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
2
  import { c as SanityLiveOnError, d as SanityLiveOnRestart, f as SanityLiveOnWelcome, i as LivePerspective, l as SanityLiveOnGoaway, m as StrictDefinedLiveProps, n as DefinedFetchType, o as SanityLiveAction, p as StrictDefinedFetchType, r as DefinedLiveProps, s as SanityLiveContext, t as DefineLiveOptions, u as SanityLiveOnReconnect } from "../../../types.js";
3
- import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../parseTags.js";
3
+ import { n as resolveVariantFromCookies$1, r as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../parseTags.js";
4
4
  /**
5
5
  * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`
6
6
  * and `<SanityLive />`, which connect your Sanity client to the Live Content API
@@ -22,6 +22,7 @@ import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../p
22
22
  * import {
23
23
  * defineLive,
24
24
  * resolvePerspectiveFromCookies,
25
+ * resolveVariantFromCookies,
25
26
  * type LivePerspective,
26
27
  * } from 'next-sanity/live'
27
28
  *
@@ -42,6 +43,7 @@ import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../p
42
43
  *
43
44
  * export interface DynamicFetchOptions {
44
45
  * perspective: LivePerspective
46
+ * variant?: string
45
47
  * stega: boolean
46
48
  * }
47
49
  *
@@ -54,7 +56,8 @@ import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../p
54
56
  *
55
57
  * const jar = await cookies()
56
58
  * const perspective = await resolvePerspectiveFromCookies({cookies: jar})
57
- * return {perspective: perspective ?? 'drafts', stega: true}
59
+ * const variant = await resolveVariantFromCookies({cookies: jar})
60
+ * return {perspective: perspective ?? 'drafts', variant, stega: true}
58
61
  * }
59
62
  * ```
60
63
  *
@@ -125,14 +128,15 @@ import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../p
125
128
  *
126
129
  * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {
127
130
  * const {slug} = await props.params
128
- * const {perspective, stega} = await getDynamicFetchOptions()
131
+ * const {perspective, variant, stega} = await getDynamicFetchOptions()
129
132
  *
130
- * return <CachedPage slug={slug} perspective={perspective} stega={stega} />
133
+ * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega={stega} />
131
134
  * }
132
135
  *
133
136
  * async function CachedPage({
134
137
  * slug,
135
138
  * perspective,
139
+ * variant,
136
140
  * stega,
137
141
  * }: {slug: string} & DynamicFetchOptions) {
138
142
  * 'use cache'
@@ -141,6 +145,7 @@ import { n as resolvePerspectiveFromCookies$1, t as parseTags } from "../../../p
141
145
  * query: POST_QUERY,
142
146
  * params: {slug},
143
147
  * perspective,
148
+ * variant,
144
149
  * stega,
145
150
  * })
146
151
  *
@@ -303,5 +308,72 @@ declare function defineLive(config: DefineLiveOptions & {
303
308
  * @public
304
309
  */
305
310
  declare const resolvePerspectiveFromCookies: typeof resolvePerspectiveFromCookies$1;
306
- export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
311
+ /**
312
+ * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
313
+ * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
314
+ * Resolve the variant once outside the cache boundary and pass it in as a prop / cache key.
315
+ *
316
+ * Unlike `resolvePerspectiveFromCookies` there is no fallback value: when no
317
+ * variant cookie is set (or its value is invalid) it resolves to `undefined`,
318
+ * meaning "no variant selected" and queries return base content.
319
+ *
320
+ * @example
321
+ * ```tsx
322
+ * import {cookies, draftMode} from 'next/headers'
323
+ * import {defineQuery} from 'next-sanity'
324
+ * import {
325
+ * resolvePerspectiveFromCookies,
326
+ * resolveVariantFromCookies,
327
+ * type LivePerspective,
328
+ * } from 'next-sanity/live'
329
+ * import {sanityFetch} from '#sanity/live'
330
+ *
331
+ * export default async function Page({params}: PageProps<'/[slug]'>) {
332
+ * const {isEnabled: isDraftMode} = await draftMode()
333
+ *
334
+ * if (isDraftMode) {
335
+ * return (
336
+ * <Suspense>
337
+ * <DynamicPage params={params} />
338
+ * </Suspense>
339
+ * )
340
+ * }
341
+ *
342
+ * const {slug} = await params
343
+ *
344
+ * return <CachedPage slug={slug} perspective="published" stega={false} />
345
+ * }
346
+ *
347
+ * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {
348
+ * const {slug} = await params
349
+ * const jar = await cookies()
350
+ * const perspective = await resolvePerspectiveFromCookies({cookies: jar})
351
+ * const variant = await resolveVariantFromCookies({cookies: jar})
352
+ *
353
+ * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega />
354
+ * }
355
+ *
356
+ * async function CachedPage({
357
+ * slug,
358
+ * perspective,
359
+ * variant,
360
+ * stega,
361
+ * }: Awaited<PageProps<'/[slug]'>['params']> & {
362
+ * perspective: LivePerspective
363
+ * variant: string | undefined
364
+ * stega: boolean
365
+ * }) {
366
+ * 'use cache'
367
+ *
368
+ * const query = defineQuery(`*[_type == "page" && slug.current == $slug][0]`)
369
+ * const {data} = await sanityFetch({query, params: {slug}, perspective, variant, stega})
370
+ *
371
+ * return <article>...</article>
372
+ * }
373
+ * ```
374
+ *
375
+ * @public
376
+ */
377
+ declare const resolveVariantFromCookies: typeof resolveVariantFromCookies$1;
378
+ export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies, resolveVariantFromCookies };
307
379
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8JgB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoFrB,sCAAsC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoKgB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAoFrB,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsEtC,kCAAkC"}
@@ -65,6 +65,75 @@ function defineLive(_config) {
65
65
  const resolvePerspectiveFromCookies = () => {
66
66
  throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`);
67
67
  };
68
- export { defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
68
+ /**
69
+ * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),
70
+ * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.
71
+ * Resolve the variant once outside the cache boundary and pass it in as a prop / cache key.
72
+ *
73
+ * Unlike `resolvePerspectiveFromCookies` there is no fallback value: when no
74
+ * variant cookie is set (or its value is invalid) it resolves to `undefined`,
75
+ * meaning "no variant selected" and queries return base content.
76
+ *
77
+ * @example
78
+ * ```tsx
79
+ * import {cookies, draftMode} from 'next/headers'
80
+ * import {defineQuery} from 'next-sanity'
81
+ * import {
82
+ * resolvePerspectiveFromCookies,
83
+ * resolveVariantFromCookies,
84
+ * type LivePerspective,
85
+ * } from 'next-sanity/live'
86
+ * import {sanityFetch} from '#sanity/live'
87
+ *
88
+ * export default async function Page({params}: PageProps<'/[slug]'>) {
89
+ * const {isEnabled: isDraftMode} = await draftMode()
90
+ *
91
+ * if (isDraftMode) {
92
+ * return (
93
+ * <Suspense>
94
+ * <DynamicPage params={params} />
95
+ * </Suspense>
96
+ * )
97
+ * }
98
+ *
99
+ * const {slug} = await params
100
+ *
101
+ * return <CachedPage slug={slug} perspective="published" stega={false} />
102
+ * }
103
+ *
104
+ * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {
105
+ * const {slug} = await params
106
+ * const jar = await cookies()
107
+ * const perspective = await resolvePerspectiveFromCookies({cookies: jar})
108
+ * const variant = await resolveVariantFromCookies({cookies: jar})
109
+ *
110
+ * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega />
111
+ * }
112
+ *
113
+ * async function CachedPage({
114
+ * slug,
115
+ * perspective,
116
+ * variant,
117
+ * stega,
118
+ * }: Awaited<PageProps<'/[slug]'>['params']> & {
119
+ * perspective: LivePerspective
120
+ * variant: string | undefined
121
+ * stega: boolean
122
+ * }) {
123
+ * 'use cache'
124
+ *
125
+ * const query = defineQuery(`*[_type == "page" && slug.current == $slug][0]`)
126
+ * const {data} = await sanityFetch({query, params: {slug}, perspective, variant, stega})
127
+ *
128
+ * return <article>...</article>
129
+ * }
130
+ * ```
131
+ *
132
+ * @public
133
+ */
134
+ const resolveVariantFromCookies = () => {
135
+ throw new Error(`resolveVariantFromCookies can't be imported by a client component`);
136
+ };
137
+ export { defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies, resolveVariantFromCookies };
69
138
 
70
139
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["import type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\n/**\n * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`\n * and `<SanityLive />`, which connect your Sanity client to the Live Content API\n * so cached pages can update in response to fine-grained content changes.\n *\n * With `strict: true`, `perspective` and `stega` become required\n * `sanityFetch` options, and `includeDrafts` becomes required on\n * `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`\n * outside `'use cache'` boundaries, then pass them into cached components.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * // sanity/live.ts\n * import {cookies, draftMode} from 'next/headers'\n * import {createClient} from 'next-sanity'\n * import {\n * defineLive,\n * resolvePerspectiveFromCookies,\n * type LivePerspective,\n * } from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * strict: true,\n * })\n *\n * export interface DynamicFetchOptions {\n * perspective: LivePerspective\n * stega: boolean\n * }\n *\n * // Resolve dynamic values outside 'use cache' boundaries.\n * export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (!isDraftMode) {\n * return {perspective: 'published', stega: false}\n * }\n *\n * const jar = await cookies()\n * const perspective = await resolvePerspectiveFromCookies({cookies: jar})\n * return {perspective: perspective ?? 'drafts', stega: true}\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {draftMode} from 'next/headers'\n *\n * import {SanityLive} from '@/sanity/live'\n *\n * export default async function RootLayout({children}: {children: React.ReactNode}) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive includeDrafts={isDraftMode} />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {draftMode} from 'next/headers'\n * import {Suspense} from 'react'\n * import {defineQuery} from 'next-sanity'\n *\n * import {\n * getDynamicFetchOptions,\n * sanityFetch,\n * type DynamicFetchOptions,\n * } from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (isDraftMode) {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <DynamicPage params={props.params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await props.params\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await props.params\n * const {perspective, stega} = await getDynamicFetchOptions()\n *\n * return <CachedPage slug={slug} perspective={perspective} stega={stega} />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * stega,\n * }: {slug: string} & DynamicFetchOptions) {\n * 'use cache'\n *\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * perspective,\n * stega,\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,\n * which connect your Sanity client to the Live Content API so pages can serve\n * cached content and update in response to fine-grained content changes.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * import {createClient} from 'next-sanity'\n * import {defineLive} from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * })\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {SanityLive} from '@/sanity/live'\n *\n * export default function RootLayout({children}: {children: React.ReactNode}) {\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {defineQuery} from 'next-sanity'\n * import {sanityFetch} from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {slug} = await props.params\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\nexport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n LivePerspective,\n SanityLiveAction,\n SanityLiveContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {defineQuery} from 'next-sanity'\n * import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch, sanityFetchStaticParams} from '#sanity/live'\n *\n * export async function generateStaticParams() {\n * const query = defineQuery(`*[_type == \"page\" && defined(slug.current)]{\"slug\": slug.current}`)\n * return await sanityFetchStaticParams({query})\n * }\n *\n * export default async function Page({params}: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * if (isDraftMode) {\n * return (\n * <Suspense>\n * <DynamicPage params={params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await params\n *\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await params\n * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n *\n * return <CachedPage slug={slug} perspective={perspective} stega />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * stega,\n * }: Awaited<PageProps<'/[slug]'>['params']> & {\n * perspective: LivePerspective\n * stega: boolean\n * }) {\n * 'use cache'\n *\n * const query = defineQuery(`*[_type == \"page\" && slug.current == $slug][0]`)\n * const {data} = await sanityFetch({query, params: {slug}, perspective, stega})\n *\n * return <article>...</article>\n * }\n * ```\n *\n * @public\n */\nexport const resolvePerspectiveFromCookies: typeof _resolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n"],"mappings":";;AAuPA,SAAgB,WAAW,SAAmC;CAC5D,MAAM,IAAI,MAAM,oDAAoD;AACtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAa,sCAA6E;CACxF,MAAM,IAAI,MAAM,uEAAuE;AACzF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["import type {resolvePerspectiveFromCookies as _resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {resolveVariantFromCookies as _resolveVariantFromCookies} from '#live/resolveVariantFromCookies'\nimport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\n/**\n * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`\n * and `<SanityLive />`, which connect your Sanity client to the Live Content API\n * so cached pages can update in response to fine-grained content changes.\n *\n * With `strict: true`, `perspective` and `stega` become required\n * `sanityFetch` options, and `includeDrafts` becomes required on\n * `<SanityLive />`. Resolve dynamic values from `draftMode()` and `cookies()`\n * outside `'use cache'` boundaries, then pass them into cached components.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * // sanity/live.ts\n * import {cookies, draftMode} from 'next/headers'\n * import {createClient} from 'next-sanity'\n * import {\n * defineLive,\n * resolvePerspectiveFromCookies,\n * resolveVariantFromCookies,\n * type LivePerspective,\n * } from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * strict: true,\n * })\n *\n * export interface DynamicFetchOptions {\n * perspective: LivePerspective\n * variant?: string\n * stega: boolean\n * }\n *\n * // Resolve dynamic values outside 'use cache' boundaries.\n * export async function getDynamicFetchOptions(): Promise<DynamicFetchOptions> {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (!isDraftMode) {\n * return {perspective: 'published', stega: false}\n * }\n *\n * const jar = await cookies()\n * const perspective = await resolvePerspectiveFromCookies({cookies: jar})\n * const variant = await resolveVariantFromCookies({cookies: jar})\n * return {perspective: perspective ?? 'drafts', variant, stega: true}\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {draftMode} from 'next/headers'\n *\n * import {SanityLive} from '@/sanity/live'\n *\n * export default async function RootLayout({children}: {children: React.ReactNode}) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive includeDrafts={isDraftMode} />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {draftMode} from 'next/headers'\n * import {Suspense} from 'react'\n * import {defineQuery} from 'next-sanity'\n *\n * import {\n * getDynamicFetchOptions,\n * sanityFetch,\n * type DynamicFetchOptions,\n * } from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n * if (isDraftMode) {\n * return (\n * <Suspense fallback={<div>Loading...</div>}>\n * <DynamicPage params={props.params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await props.params\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await props.params\n * const {perspective, variant, stega} = await getDynamicFetchOptions()\n *\n * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega={stega} />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * variant,\n * stega,\n * }: {slug: string} & DynamicFetchOptions) {\n * 'use cache'\n *\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * perspective,\n * variant,\n * stega,\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict: true}): {\n sanityFetch: StrictDefinedFetchType\n SanityLive: React.ComponentType<StrictDefinedLiveProps>\n}\n/**\n * Set up Sanity Live. `defineLive` returns `sanityFetch` and `<SanityLive />`,\n * which connect your Sanity client to the Live Content API so pages can serve\n * cached content and update in response to fine-grained content changes.\n *\n * @see [Live Content API](https://www.sanity.io/docs/content-lake/live-content-api)\n * @see [Sanity Live](https://www.sanity.io/live)\n *\n * @example\n * ```tsx\n * import {createClient} from 'next-sanity'\n * import {defineLive} from 'next-sanity/live'\n *\n * const client = createClient({\n * projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,\n * dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,\n * useCdn: true,\n * perspective: 'published',\n * })\n * const token = process.env.SANITY_API_READ_TOKEN\n *\n * export const {sanityFetch, SanityLive} = defineLive({\n * client,\n * browserToken: token,\n * serverToken: token,\n * })\n * ```\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import {SanityLive} from '@/sanity/live'\n *\n * export default function RootLayout({children}: {children: React.ReactNode}) {\n * return (\n * <html lang=\"en\">\n * <body>\n * {children}\n * <SanityLive />\n * </body>\n * </html>\n * )\n * }\n * ```\n *\n * @example\n * ```tsx\n * // app/[slug]/page.tsx\n * import {defineQuery} from 'next-sanity'\n * import {sanityFetch} from '@/sanity/live'\n *\n * const POSTS_SLUGS_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current]{\"slug\": slug.current}\n * `)\n * const POST_QUERY = defineQuery(`\n * *[_type == \"post\" && slug.current == $slug][0]\n * `)\n *\n * export async function generateStaticParams() {\n * const {data} = await sanityFetch({\n * query: POSTS_SLUGS_QUERY,\n * perspective: 'published',\n * stega: false,\n * })\n *\n * return data\n * }\n *\n * export default async function Page(props: PageProps<'/[slug]'>) {\n * const {slug} = await props.params\n * const {data} = await sanityFetch({\n * query: POST_QUERY,\n * params: {slug},\n * })\n *\n * return <pre>{JSON.stringify(data, null, 2)}</pre>\n * }\n * ```\n *\n * @public\n */\nexport function defineLive(config: DefineLiveOptions & {strict?: false}): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n}\nexport function defineLive(_config: DefineLiveOptions): never {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\nexport type {\n DefinedFetchType,\n DefinedLiveProps,\n DefineLiveOptions,\n LivePerspective,\n SanityLiveAction,\n SanityLiveContext,\n SanityLiveOnError,\n SanityLiveOnGoaway,\n SanityLiveOnReconnect,\n SanityLiveOnRestart,\n SanityLiveOnWelcome,\n StrictDefinedFetchType,\n StrictDefinedLiveProps,\n} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\nexport {parseTags} from '#live/parseTags'\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the perspective once outside the cache boundary and pass it in as a prop / cache key.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {defineQuery} from 'next-sanity'\n * import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'\n * import {sanityFetch, sanityFetchStaticParams} from '#sanity/live'\n *\n * export async function generateStaticParams() {\n * const query = defineQuery(`*[_type == \"page\" && defined(slug.current)]{\"slug\": slug.current}`)\n * return await sanityFetchStaticParams({query})\n * }\n *\n * export default async function Page({params}: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * if (isDraftMode) {\n * return (\n * <Suspense>\n * <DynamicPage params={params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await params\n *\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await params\n * const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})\n *\n * return <CachedPage slug={slug} perspective={perspective} stega />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * stega,\n * }: Awaited<PageProps<'/[slug]'>['params']> & {\n * perspective: LivePerspective\n * stega: boolean\n * }) {\n * 'use cache'\n *\n * const query = defineQuery(`*[_type == \"page\" && slug.current == $slug][0]`)\n * const {data} = await sanityFetch({query, params: {slug}, perspective, stega})\n *\n * return <article>...</article>\n * }\n * ```\n *\n * @public\n */\nexport const resolvePerspectiveFromCookies: typeof _resolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\n/**\n * This helper is intended for use with Next.js Cache Components (`cacheComponents: true`),\n * where `cookies()` and `draftMode()` cannot be called inside `'use cache'` boundaries.\n * Resolve the variant once outside the cache boundary and pass it in as a prop / cache key.\n *\n * Unlike `resolvePerspectiveFromCookies` there is no fallback value: when no\n * variant cookie is set (or its value is invalid) it resolves to `undefined`,\n * meaning \"no variant selected\" and queries return base content.\n *\n * @example\n * ```tsx\n * import {cookies, draftMode} from 'next/headers'\n * import {defineQuery} from 'next-sanity'\n * import {\n * resolvePerspectiveFromCookies,\n * resolveVariantFromCookies,\n * type LivePerspective,\n * } from 'next-sanity/live'\n * import {sanityFetch} from '#sanity/live'\n *\n * export default async function Page({params}: PageProps<'/[slug]'>) {\n * const {isEnabled: isDraftMode} = await draftMode()\n *\n * if (isDraftMode) {\n * return (\n * <Suspense>\n * <DynamicPage params={params} />\n * </Suspense>\n * )\n * }\n *\n * const {slug} = await params\n *\n * return <CachedPage slug={slug} perspective=\"published\" stega={false} />\n * }\n *\n * async function DynamicPage({params}: Pick<PageProps<'/[slug]'>, 'params'>) {\n * const {slug} = await params\n * const jar = await cookies()\n * const perspective = await resolvePerspectiveFromCookies({cookies: jar})\n * const variant = await resolveVariantFromCookies({cookies: jar})\n *\n * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega />\n * }\n *\n * async function CachedPage({\n * slug,\n * perspective,\n * variant,\n * stega,\n * }: Awaited<PageProps<'/[slug]'>['params']> & {\n * perspective: LivePerspective\n * variant: string | undefined\n * stega: boolean\n * }) {\n * 'use cache'\n *\n * const query = defineQuery(`*[_type == \"page\" && slug.current == $slug][0]`)\n * const {data} = await sanityFetch({query, params: {slug}, perspective, variant, stega})\n *\n * return <article>...</article>\n * }\n * ```\n *\n * @public\n */\nexport const resolveVariantFromCookies: typeof _resolveVariantFromCookies = () => {\n throw new Error(`resolveVariantFromCookies can't be imported by a client component`)\n}\n"],"mappings":";;AA6PA,SAAgB,WAAW,SAAmC;CAC5D,MAAM,IAAI,MAAM,oDAAoD;AACtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAa,sCAA6E;CACxF,MAAM,IAAI,MAAM,uEAAuE;AACzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAa,kCAAqE;CAChF,MAAM,IAAI,MAAM,mEAAmE;AACrF"}
@@ -1,6 +1,6 @@
1
1
  import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
2
  import { c as SanityLiveOnError, d as SanityLiveOnRestart, f as SanityLiveOnWelcome, i as LivePerspective, l as SanityLiveOnGoaway, m as StrictDefinedLiveProps, n as DefinedFetchType, o as SanityLiveAction, p as StrictDefinedFetchType, r as DefinedLiveProps, s as SanityLiveContext, t as DefineLiveOptions, u as SanityLiveOnReconnect } from "../../../types.js";
3
- import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../parseTags.js";
3
+ import { n as resolveVariantFromCookies, r as resolvePerspectiveFromCookies, t as parseTags } from "../../../parseTags.js";
4
4
  /**
5
5
  * Set up Sanity Live for Cache Components. `defineLive` returns `sanityFetch`
6
6
  * and `<SanityLive />`, which connect your Sanity client to the Live Content API
@@ -22,6 +22,7 @@ import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../par
22
22
  * import {
23
23
  * defineLive,
24
24
  * resolvePerspectiveFromCookies,
25
+ * resolveVariantFromCookies,
25
26
  * type LivePerspective,
26
27
  * } from 'next-sanity/live'
27
28
  *
@@ -42,6 +43,7 @@ import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../par
42
43
  *
43
44
  * export interface DynamicFetchOptions {
44
45
  * perspective: LivePerspective
46
+ * variant?: string
45
47
  * stega: boolean
46
48
  * }
47
49
  *
@@ -54,7 +56,8 @@ import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../par
54
56
  *
55
57
  * const jar = await cookies()
56
58
  * const perspective = await resolvePerspectiveFromCookies({cookies: jar})
57
- * return {perspective: perspective ?? 'drafts', stega: true}
59
+ * const variant = await resolveVariantFromCookies({cookies: jar})
60
+ * return {perspective: perspective ?? 'drafts', variant, stega: true}
58
61
  * }
59
62
  * ```
60
63
  *
@@ -125,14 +128,15 @@ import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../par
125
128
  *
126
129
  * async function DynamicPage(props: Pick<PageProps<'/[slug]'>, 'params'>) {
127
130
  * const {slug} = await props.params
128
- * const {perspective, stega} = await getDynamicFetchOptions()
131
+ * const {perspective, variant, stega} = await getDynamicFetchOptions()
129
132
  *
130
- * return <CachedPage slug={slug} perspective={perspective} stega={stega} />
133
+ * return <CachedPage slug={slug} perspective={perspective} variant={variant} stega={stega} />
131
134
  * }
132
135
  *
133
136
  * async function CachedPage({
134
137
  * slug,
135
138
  * perspective,
139
+ * variant,
136
140
  * stega,
137
141
  * }: {slug: string} & DynamicFetchOptions) {
138
142
  * 'use cache'
@@ -141,6 +145,7 @@ import { n as resolvePerspectiveFromCookies, t as parseTags } from "../../../par
141
145
  * query: POST_QUERY,
142
146
  * params: {slug},
143
147
  * perspective,
148
+ * variant,
144
149
  * stega,
145
150
  * })
146
151
  *
@@ -243,5 +248,5 @@ declare function defineLive(config: DefineLiveOptions & {
243
248
  sanityFetch: DefinedFetchType;
244
249
  SanityLive: React.ComponentType<DefinedLiveProps>;
245
250
  };
246
- export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
251
+ export { type DefineLiveOptions, type DefinedFetchType, type DefinedLiveProps, type LivePerspective, type SanityLiveAction, type SanityLiveContext, type SanityLiveOnError, type SanityLiveOnGoaway, type SanityLiveOnReconnect, type SanityLiveOnRestart, type SanityLiveOnWelcome, type StrictDefinedFetchType, type StrictDefinedLiveProps, defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies, resolveVariantFromCookies };
247
252
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsKgB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2KgB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmFlB,WAAW,QAAQ;EAAqB;;EACtD,aAAa;EACb,YAAY,MAAM,cAAc"}
@@ -1,6 +1,6 @@
1
1
  import { t as cacheTagPrefix } from "../../../constants.js";
2
2
  import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
3
- import { i as preconnect, n as validateStrictFetchOptions, r as validateStrictSanityLiveProps, t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
3
+ import { a as preconnect, i as validateStrictSanityLiveProps, n as resolvePerspectiveFromCookies, r as validateStrictFetchOptions, t as resolveVariantFromCookies } from "../../../resolveVariantFromCookies.js";
4
4
  import { t as parseTags } from "../../../parseTags.js";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { sanity } from "next-sanity/live/cache-life";
@@ -19,7 +19,7 @@ function defineLive(config) {
19
19
  perspective: "published",
20
20
  stega: false
21
21
  });
22
- const sanityFetch = async function sanityFetch({ query, params = {}, perspective, stega, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
22
+ const sanityFetch = async function sanityFetch({ query, params = {}, perspective, variant, stega, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
23
23
  if (strict) validateStrictFetchOptions({
24
24
  perspective,
25
25
  stega
@@ -31,6 +31,7 @@ function defineLive(config) {
31
31
  const { result, resultSourceMap, syncTags } = await client.fetch(query, await params, {
32
32
  filterResponse: false,
33
33
  perspective,
34
+ variant,
34
35
  stega,
35
36
  returnQuery: false,
36
37
  useCdn,
@@ -89,6 +90,6 @@ function defineLive(config) {
89
90
  SanityLive: SanityLive$2
90
91
  };
91
92
  }
92
- export { defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies };
93
+ export { defineLive, isCorsOriginError, parseTags, resolvePerspectiveFromCookies, resolveVariantFromCookies };
93
94
 
94
95
  //# sourceMappingURL=index.js.map