next-sanity 13.0.0-cache-components.16 → 13.0.0-cache-components.18

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 (42) hide show
  1. package/dist/PresentationComlink.js +4 -5
  2. package/dist/PresentationComlink.js.map +1 -1
  3. package/dist/SanityLive.js +3 -9
  4. package/dist/SanityLive.js.map +1 -1
  5. package/dist/VisualEditing.js +16 -27
  6. package/dist/VisualEditing.js.map +1 -1
  7. package/dist/context.js +7 -14
  8. package/dist/context.js.map +1 -1
  9. package/dist/defineLive.d.ts +0 -7
  10. package/dist/defineLive.d.ts.map +1 -1
  11. package/dist/hooks/index.d.ts +15 -34
  12. package/dist/hooks/index.d.ts.map +1 -1
  13. package/dist/hooks/index.js +22 -26
  14. package/dist/hooks/index.js.map +1 -1
  15. package/dist/live/client-components/index.d.ts +3 -4
  16. package/dist/live/client-components/index.d.ts.map +1 -1
  17. package/dist/live/client-components/index.js.map +1 -1
  18. package/dist/live/conditions/next-js/index.d.ts.map +1 -1
  19. package/dist/live/conditions/next-js/index.js +2 -3
  20. package/dist/live/conditions/next-js/index.js.map +1 -1
  21. package/dist/live/conditions/react-server/index.js +2 -3
  22. package/dist/live/conditions/react-server/index.js.map +1 -1
  23. package/dist/live/server-actions/index.default.d.ts +1 -6
  24. package/dist/live/server-actions/index.default.d.ts.map +1 -1
  25. package/dist/live/server-actions/index.default.js +2 -22
  26. package/dist/live/server-actions/index.default.js.map +1 -1
  27. package/dist/live/server-actions/index.next-js.d.ts +1 -6
  28. package/dist/live/server-actions/index.next-js.d.ts.map +1 -1
  29. package/dist/live/server-actions/index.next-js.js +2 -16
  30. package/dist/live/server-actions/index.next-js.js.map +1 -1
  31. package/dist/visual-editing/client-component/index.d.ts +2 -2
  32. package/dist/visual-editing/client-component/index.d.ts.map +1 -1
  33. package/dist/visual-editing/client-component/index.js +3 -10
  34. package/dist/visual-editing/client-component/index.js.map +1 -1
  35. package/dist/visual-editing/index.d.ts.map +1 -1
  36. package/dist/visual-editing/index.js +4 -2
  37. package/dist/visual-editing/index.js.map +1 -1
  38. package/dist/visual-editing/server-actions/index.d.ts +11 -2
  39. package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
  40. package/dist/visual-editing/server-actions/index.js +22 -7
  41. package/dist/visual-editing/server-actions/index.js.map +1 -1
  42. package/package.json +16 -7
@@ -1,16 +1,15 @@
1
- import { f as setPerspective, l as setComlink, u as setComlinkClientConfig } from "./context.js";
1
+ import { c as setComlinkPerspective, o as setComlink, s as setComlinkClientConfig } from "./context.js";
2
2
  import { t as sanitizePerspective } from "./sanitizePerspective.js";
3
- import { startTransition, useEffect, useEffectEvent } from "react";
3
+ import { useEffect, useEffectEvent } from "react";
4
4
  import { createNode, createNodeMachine } from "@sanity/comlink";
5
5
  import { createCompatibilityActors } from "@sanity/presentation-comlink";
6
6
  function PresentationComlink(props) {
7
- const { projectId, dataset, onPerspective } = props;
7
+ const { projectId, dataset } = props;
8
8
  useEffect(() => {
9
9
  setComlinkClientConfig(projectId, dataset);
10
10
  }, [dataset, projectId]);
11
11
  const handlePerspectiveChange = useEffectEvent((perspective) => {
12
- setPerspective(sanitizePerspective(perspective, "drafts"));
13
- startTransition(() => onPerspective(perspective));
12
+ setComlinkPerspective(sanitizePerspective(perspective, "drafts"));
14
13
  });
15
14
  useEffect(() => {
16
15
  const controller = new AbortController();
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationComlink.js","names":[],"sources":["../src/live/client-components/PresentationComlink.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {setComlink, setComlinkClientConfig, setPerspective} from '#live/context'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {createNode, createNodeMachine} from '@sanity/comlink'\nimport {\n createCompatibilityActors,\n type LoaderControllerMsg,\n type LoaderNodeMsg,\n} from '@sanity/presentation-comlink'\nimport {startTransition, useEffect, useEffectEvent} from 'react'\n\nexport default function PresentationComlink(props: {\n projectId: string\n dataset: string\n onPerspective: (perspective: ClientPerspective) => Promise<void>\n}): React.JSX.Element | null {\n const {projectId, dataset, onPerspective} = props\n\n useEffect(() => {\n setComlinkClientConfig(projectId, dataset)\n }, [dataset, projectId])\n\n const handlePerspectiveChange = useEffectEvent((perspective: ClientPerspective) => {\n // @TODO remove `setPerspective` util and state\n setPerspective(sanitizePerspective(perspective, 'drafts'))\n startTransition(() => onPerspective(perspective))\n })\n\n useEffect(() => {\n const controller = new AbortController()\n const comlink = createNode<LoaderNodeMsg, LoaderControllerMsg>(\n {name: 'loaders', connectTo: 'presentation'},\n createNodeMachine<LoaderNodeMsg, LoaderControllerMsg>().provide({\n actors: createCompatibilityActors<LoaderNodeMsg>(),\n }),\n )\n\n comlink.on('loader/perspective', (data) => {\n if (controller.signal.aborted) return\n\n handlePerspectiveChange(data.perspective)\n })\n\n const stop = comlink.start()\n setComlink(comlink)\n return () => {\n stop()\n controller.abort()\n }\n }, [])\n\n return null\n}\n\nPresentationComlink.displayName = 'PresentationComlink'\n"],"mappings":";;;;;AAYA,SAAwB,oBAAoB,OAIf;CAC3B,MAAM,EAAC,WAAW,SAAS,kBAAiB;AAE5C,iBAAgB;AACd,yBAAuB,WAAW,QAAQ;IACzC,CAAC,SAAS,UAAU,CAAC;CAExB,MAAM,0BAA0B,gBAAgB,gBAAmC;AAEjF,iBAAe,oBAAoB,aAAa,SAAS,CAAC;AAC1D,wBAAsB,cAAc,YAAY,CAAC;GACjD;AAEF,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,UAAU,WACd;GAAC,MAAM;GAAW,WAAW;GAAe,EAC5C,mBAAuD,CAAC,QAAQ,EAC9D,QAAQ,2BAA0C,EACnD,CAAC,CACH;AAED,UAAQ,GAAG,uBAAuB,SAAS;AACzC,OAAI,WAAW,OAAO,QAAS;AAE/B,2BAAwB,KAAK,YAAY;IACzC;EAEF,MAAM,OAAO,QAAQ,OAAO;AAC5B,aAAW,QAAQ;AACnB,eAAa;AACX,SAAM;AACN,cAAW,OAAO;;IAEnB,EAAE,CAAC;AAEN,QAAO;;AAGT,oBAAoB,cAAc"}
1
+ {"version":3,"file":"PresentationComlink.js","names":[],"sources":["../src/live/client-components/PresentationComlink.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {setComlink, setComlinkClientConfig, setComlinkPerspective} from '#live/context'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {createNode, createNodeMachine} from '@sanity/comlink'\nimport {\n createCompatibilityActors,\n type LoaderControllerMsg,\n type LoaderNodeMsg,\n} from '@sanity/presentation-comlink'\nimport {useEffect, useEffectEvent} from 'react'\n\nexport default function PresentationComlink(props: {\n projectId: string\n dataset: string\n}): React.JSX.Element | null {\n const {projectId, dataset} = props\n\n useEffect(() => {\n setComlinkClientConfig(projectId, dataset)\n }, [dataset, projectId])\n\n const handlePerspectiveChange = useEffectEvent((perspective: ClientPerspective) => {\n setComlinkPerspective(sanitizePerspective(perspective, 'drafts'))\n })\n\n useEffect(() => {\n const controller = new AbortController()\n const comlink = createNode<LoaderNodeMsg, LoaderControllerMsg>(\n {name: 'loaders', connectTo: 'presentation'},\n createNodeMachine<LoaderNodeMsg, LoaderControllerMsg>().provide({\n actors: createCompatibilityActors<LoaderNodeMsg>(),\n }),\n )\n\n comlink.on('loader/perspective', (data) => {\n if (controller.signal.aborted) return\n\n handlePerspectiveChange(data.perspective)\n })\n\n const stop = comlink.start()\n setComlink(comlink)\n return () => {\n stop()\n controller.abort()\n }\n }, [])\n\n return null\n}\n\nPresentationComlink.displayName = 'PresentationComlink'\n"],"mappings":";;;;;AAYA,SAAwB,oBAAoB,OAGf;CAC3B,MAAM,EAAC,WAAW,YAAW;AAE7B,iBAAgB;AACd,yBAAuB,WAAW,QAAQ;IACzC,CAAC,SAAS,UAAU,CAAC;CAExB,MAAM,0BAA0B,gBAAgB,gBAAmC;AACjF,wBAAsB,oBAAoB,aAAa,SAAS,CAAC;GACjE;AAEF,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,UAAU,WACd;GAAC,MAAM;GAAW,WAAW;GAAe,EAC5C,mBAAuD,CAAC,QAAQ,EAC9D,QAAQ,2BAA0C,EACnD,CAAC,CACH;AAED,UAAQ,GAAG,uBAAuB,SAAS;AACzC,OAAI,WAAW,OAAO,QAAS;AAE/B,2BAAwB,KAAK,YAAY;IACzC;EAEF,MAAM,OAAO,QAAQ,OAAO;AAC5B,aAAW,QAAQ;AACnB,eAAa;AACX,SAAM;AACN,cAAW,OAAO;;IAEnB,EAAE,CAAC;AAEN,QAAO;;AAGT,oBAAoB,cAAc"}
@@ -1,12 +1,11 @@
1
1
  import { n as PUBLISHED_SYNC_TAG_PREFIX } from "./constants.js";
2
- import { d as setEnvironment } from "./context.js";
3
2
  import { t as isCorsOriginError } from "./isCorsOriginError.js";
4
3
  import { useRouter } from "next/navigation";
5
4
  import { useEffect, useEffectEvent, useMemo, useState } from "react";
6
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
6
  import { createClient } from "@sanity/client";
8
7
  import dynamic from "next/dynamic";
9
- import { isMaybePresentation, isMaybePreviewWindow } from "@sanity/presentation-comlink";
8
+ import { isMaybePresentation } from "@sanity/presentation-comlink";
10
9
  const PresentationComlink = dynamic(() => import("./PresentationComlink.js"));
11
10
  const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
12
11
  const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"));
@@ -20,7 +19,7 @@ function handleOnGoAway(event, intervalOnGoAway) {
20
19
  else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
21
20
  }
22
21
  function SanityLive(props) {
23
- const { config, onLiveEvent, onPresentationPerspective, perspective, refreshOnMount = false, refreshOnFocus = perspective !== "published" ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true, intervalOnGoAway = 3e4, requestTag, onError = handleError, onGoAway = handleOnGoAway } = props;
22
+ const { config, onLiveEvent, perspective, refreshOnMount = false, refreshOnFocus = perspective !== "published" ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true, intervalOnGoAway = 3e4, requestTag, onError = handleError, onGoAway = handleOnGoAway } = props;
24
23
  const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
25
24
  const client = useMemo(() => createClient({
26
25
  projectId,
@@ -77,17 +76,13 @@ function SanityLive(props) {
77
76
  useEffect(() => {
78
77
  if (!isMaybePresentation()) return;
79
78
  const controller = new AbortController();
80
- const timeout = setTimeout(() => setEnvironment("live"), 3e3);
81
79
  window.addEventListener("message", ({ data }) => {
82
80
  if (data && typeof data === "object" && "domain" in data && data.domain === "sanity/channels" && "from" in data && data.from === "presentation") {
83
- clearTimeout(timeout);
84
- setEnvironment(isMaybePreviewWindow() ? "presentation-window" : "presentation-iframe");
85
81
  setLoadComlink(true);
86
82
  controller.abort();
87
83
  }
88
84
  }, { signal: controller.signal });
89
85
  return () => {
90
- clearTimeout(timeout);
91
86
  controller.abort();
92
87
  };
93
88
  }, []);
@@ -99,8 +94,7 @@ function SanityLive(props) {
99
94
  return /* @__PURE__ */ jsxs(Fragment, { children: [
100
95
  loadComlink && /* @__PURE__ */ jsx(PresentationComlink, {
101
96
  projectId,
102
- dataset,
103
- onPerspective: onPresentationPerspective
97
+ dataset
104
98
  }),
105
99
  refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
106
100
  refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
@@ -1 +1 @@
1
- {"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {setEnvironment} from '#live/context'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useState, useEffectEvent} from 'react'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\n/**\n * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport interface SanityLiveProps {\n config: SanityClientConfig\n /**\n * Setting this to 'published' opens one live event connection, setting it to any other value opens both the live event connections if needed\n */\n perspective: Exclude<ClientPerspective, 'raw'>\n\n onLiveEvent: (tags: string[]) => Promise<void | 'refresh'>\n onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | 'refresh'>\n onPresentationPerspective: (perspective: ClientPerspective) => Promise<void>\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string\n\n /**\n * Handle errors from the Live Events subscription.\n * By default it's reported using `console.error`, you can override this prop to handle it in your own way.\n */\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n}\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n onLiveEvent,\n // onLiveEventIncludingDrafts,\n onPresentationPerspective,\n perspective,\n\n refreshOnMount = false,\n refreshOnFocus = perspective !== 'published'\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag,\n onError = handleError,\n onGoAway = handleOnGoAway,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n const [longPollingInterval, setLongPollingInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : perspective === 'published'\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setLongPollingInterval(false)\n } else if (event.type === 'message') {\n void onLiveEvent(\n event.tags.map((tag: SyncTag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}` as const),\n ).then((result) => {\n if (result === 'refresh') router.refresh()\n })\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n router.refresh()\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n setLongPollingInterval(intervalOnGoAway)\n }\n })\n useEffect(() => {\n const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n // console.error('What?', err)\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n const [loadComlink, setLoadComlink] = useState(false)\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n clearTimeout(timeout)\n setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 6. Handle switching to long polling when needed\n */\n useEffect(() => {\n if (!longPollingInterval) return\n const interval = setInterval(() => router.refresh(), longPollingInterval)\n return () => clearInterval(interval)\n }, [longPollingInterval, router])\n\n return (\n <>\n {loadComlink && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n onPerspective={onPresentationPerspective}\n />\n )}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;;;;;AAgBA,MAAM,sBAAsB,cAAc,OAAO,4BAAyB;AAC1E,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,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B;KAC5C;;AAIP,WAAW,cAAc;AAEzB,IAAA,qBAAe"}
1
+ {"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {\n isMaybePresentation,\n\n // isMaybePreviewWindow\n} from '@sanity/presentation-comlink'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useState, useEffectEvent} from 'react'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n /**\n * Setting this to 'published' opens one live event connection, setting it to any other value opens both the live event connections if needed\n */\n perspective: Exclude<ClientPerspective, 'raw'>\n\n onLiveEvent: (tags: string[]) => Promise<void | 'refresh'>\n onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | 'refresh'>\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string\n\n /**\n * Handle errors from the Live Events subscription.\n * By default it's reported using `console.error`, you can override this prop to handle it in your own way.\n */\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n}\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n onLiveEvent,\n // onLiveEventIncludingDrafts,\n perspective,\n\n refreshOnMount = false,\n refreshOnFocus = perspective !== 'published'\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag,\n onError = handleError,\n onGoAway = handleOnGoAway,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n const [longPollingInterval, setLongPollingInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : perspective === 'published'\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setLongPollingInterval(false)\n } else if (event.type === 'message') {\n void onLiveEvent(\n event.tags.map((tag: SyncTag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}` as const),\n ).then((result) => {\n if (result === 'refresh') router.refresh()\n })\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n router.refresh()\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n setLongPollingInterval(intervalOnGoAway)\n }\n })\n useEffect(() => {\n const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n // console.error('What?', err)\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n const [loadComlink, setLoadComlink] = useState(false)\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n // const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n // clearTimeout(timeout)\n // setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n // clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 6. Handle switching to long polling when needed\n */\n useEffect(() => {\n if (!longPollingInterval) return\n const interval = setInterval(() => router.refresh(), longPollingInterval)\n return () => clearInterval(interval)\n }, [longPollingInterval, router])\n\n return (\n <>\n {loadComlink && <PresentationComlink projectId={projectId!} dataset={dataset!} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\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;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc;AAEzB,IAAA,qBAAe"}
@@ -2,7 +2,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation";
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { VisualEditing as VisualEditing$1 } from "@sanity/visual-editing/react";
4
4
  import { jsx } from "react/jsx-runtime";
5
- import { revalidateRootLayout } from "next-sanity/visual-editing/server-actions";
5
+ import { actionRefresh } from "next-sanity/visual-editing/server-actions";
6
6
  function pathHasPrefix(path, prefix) {
7
7
  if (typeof path !== "string") return false;
8
8
  const { pathname } = parsePath(path);
@@ -47,7 +47,7 @@ function removeTrailingSlash(route) {
47
47
  return route.replace(/\/$/, "") || "/";
48
48
  }
49
49
  function VisualEditing(props) {
50
- const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex } = props;
50
+ const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex, onPerspectiveChange } = props;
51
51
  const router = useRouter();
52
52
  const routerRef = useRef(router);
53
53
  const [navigate, setNavigate] = useState();
@@ -82,39 +82,28 @@ function VisualEditing(props) {
82
82
  searchParams,
83
83
  trailingSlash
84
84
  ]);
85
+ const handleRefresh = useCallback((payload) => {
86
+ switch (payload.source) {
87
+ case "manual": return actionRefresh(payload);
88
+ case "mutation":
89
+ if (payload.livePreviewEnabled) {
90
+ console.debug("Live preview is setup, mutation is skipped assuming its handled by the live preview");
91
+ return false;
92
+ }
93
+ return actionRefresh(payload);
94
+ default: throw new Error("Unknown refresh source", { cause: payload });
95
+ }
96
+ }, []);
85
97
  return /* @__PURE__ */ jsx(VisualEditing$1, {
86
98
  plugins,
87
99
  components,
88
100
  history,
89
101
  portal: true,
90
- refresh: useCallback((payload) => {
91
- if (refresh) return refresh(payload);
92
- const manualFastRefresh = () => {
93
- console.debug("Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data");
94
- routerRef.current.refresh();
95
- return Promise.resolve();
96
- };
97
- const manualFallbackRefresh = () => {
98
- console.debug("No loaders in live mode detected, or preview kit setup, revalidating root layout");
99
- return revalidateRootLayout();
100
- };
101
- const mutationFallbackRefresh = () => {
102
- console.debug("No loaders in live mode detected, or preview kit setup, revalidating root layout");
103
- return revalidateRootLayout();
104
- };
105
- switch (payload.source) {
106
- case "manual": return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh();
107
- case "mutation": return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh();
108
- default: throw new Error("Unknown refresh source", { cause: payload });
109
- }
110
- }, [refresh]),
102
+ refresh: refresh ?? handleRefresh,
103
+ onPerspectiveChange,
111
104
  zIndex
112
105
  });
113
106
  }
114
- function mutationFastRefresh() {
115
- console.debug("Live preview is setup, mutation is skipped assuming its handled by the live preview");
116
- return false;
117
- }
118
107
  export { VisualEditing as default };
119
108
 
120
109
  //# sourceMappingURL=VisualEditing.js.map
@@ -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 {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation'\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 = '', plugins, 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`, {cause: update})\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(\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) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // oxlint-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 // oxlint-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 const mutationFallbackRefresh = () => {\n // oxlint-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 plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={handleRefresh}\n zIndex={zIndex}\n />\n )\n}\n\nfunction mutationFastRefresh(): false {\n // oxlint-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"],"mappings":";;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,KAAI,OAAO,SAAS,SAClB,QAAO;CAGT,MAAM,EAAC,aAAY,UAAU,KAAK;AAClC,QAAO,aAAa,UAAU,SAAS,WAAW,GAAG,OAAO,GAAG;;AASjE,SAAS,UAAU,MAIjB;CACA,MAAM,YAAY,KAAK,QAAQ,IAAI;CACnC,MAAM,aAAa,KAAK,QAAQ,IAAI;CACpC,MAAM,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAEnE,KAAI,YAAY,YAAY,GAC1B,QAAO;EACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,UAAU;EAC9D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,KAAA,EAAU,GAAG;EACvF,MAAM,YAAY,KAAK,KAAK,MAAM,UAAU,GAAG;EAChD;AAGH,QAAO;EAAC,UAAU;EAAM,OAAO;EAAI,MAAM;EAAG;;AAQ9C,SAAgB,cAAc,MAAc,QAAyB;AACnE,KAAI,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,OAC5B,QAAO;AAGT,KAAI,SAAS,OAAO,OAClB,QAAO;CAG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,QAAO,CAAC;;;EAG9D,GACD,CAAC,SAAS,CACX;CAED,MAAM,WAAW,aAAa;CAC9B,MAAM,eAAe,iBAAiB;AACtC,iBAAgB;AACd,MAAI,SACF,UAAS;GACP,MAAM;GACN,KAAK,2BACH,cACE,GAAG,WAAW,cAAc,OAAO,IAAI,aAAa,UAAU,KAAK,MACnE,SACD,EACD,cACD;GACF,CAAC;IAEH;EAAC;EAAU;EAAU;EAAU;EAAc;EAAc,CAAC;AA0C/D,QACE,oBAACA,iBAAAA;EACU;EACG;EACH;EACT,QAAA;EACA,SA9CkB,aACnB,YAA4B;AAC3B,OAAI,QAAS,QAAO,QAAQ,QAAQ;GAEpC,MAAM,0BAA0B;AAE9B,YAAQ,MACN,kHACD;AACD,cAAU,QAAQ,SAAS;AAC3B,WAAO,QAAQ,SAAS;;GAE1B,MAAM,8BAA8B;AAElC,YAAQ,MACN,mFACD;AACD,WAAO,sBAAsB;;GAG/B,MAAM,gCAAgC;AAEpC,YAAQ,MACN,mFACD;AACD,WAAO,sBAAsB;;AAG/B,WAAQ,QAAQ,QAAhB;IACE,KAAK,SACH,QAAO,QAAQ,qBAAqB,mBAAmB,GAAG,uBAAuB;IACnF,KAAK,WACH,QAAO,QAAQ,qBAAqB,qBAAqB,GAAG,yBAAyB;IACvF,QACE,OAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ,CAAC;;KAGjE,CAAC,QAAQ,CACV;EASW;GACR;;AAIN,SAAS,sBAA6B;AAEpC,SAAQ,MACN,sFACD;AACD,QAAO"}
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 {actionRefresh} from 'next-sanity/visual-editing/server-actions'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation'\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 {\n basePath = '',\n plugins,\n components,\n refresh,\n trailingSlash = false,\n zIndex,\n onPerspectiveChange,\n } = 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`, {cause: update})\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(\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((payload: HistoryRefresh): false | Promise<void> => {\n switch (payload.source) {\n case 'manual':\n return actionRefresh(payload)\n case 'mutation': {\n if (payload.livePreviewEnabled) {\n // oxlint-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 return actionRefresh(payload)\n }\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n }, [])\n\n return (\n <VisualEditingComponent\n plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={refresh ?? handleRefresh}\n onPerspectiveChange={onPerspectiveChange}\n zIndex={zIndex}\n />\n )\n}\n"],"mappings":";;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,KAAI,OAAO,SAAS,SAClB,QAAO;CAGT,MAAM,EAAC,aAAY,UAAU,KAAK;AAClC,QAAO,aAAa,UAAU,SAAS,WAAW,GAAG,OAAO,GAAG;;AASjE,SAAS,UAAU,MAIjB;CACA,MAAM,YAAY,KAAK,QAAQ,IAAI;CACnC,MAAM,aAAa,KAAK,QAAQ,IAAI;CACpC,MAAM,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAEnE,KAAI,YAAY,YAAY,GAC1B,QAAO;EACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,UAAU;EAC9D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,KAAA,EAAU,GAAG;EACvF,MAAM,YAAY,KAAK,KAAK,MAAM,UAAU,GAAG;EAChD;AAGH,QAAO;EAAC,UAAU;EAAM,OAAO;EAAI,MAAM;EAAG;;AAQ9C,SAAgB,cAAc,MAAc,QAAyB;AACnE,KAAI,CAAC,KAAK,WAAW,IAAI,IAAI,CAAC,OAC5B,QAAO;AAGT,KAAI,SAAS,OAAO,OAClB,QAAO;CAGT,MAAM,EA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AC;;;EAG9D,GACD,CAAC,SAAS,CACX;CAED,MAAM,WAAW,aAAa;CAC9B,MAAM,eAAe,iBAAiB;AACtC,iBAAgB;AACd,MAAI,SACF,UAAS;GACP,MAAM;GACN,KAAK,2BACH,cACE,GAAG,WAAW,cAAc,OAAO,IAAI,aAAa,UAAU,KAAK,MACnE,SACD,EACD,cACD;GACF,CAAC;IAEH;EAAC;EAAU;EAAU;EAAU;EAAc;EAAc,CAAC;CAE/D,MAAM,gBAAgB,aAAa,YAAmD;AACpF,UAAQ,QAAQ,QAAhB;GACE,KAAK,SACH,QAAO,cAAc,QAAQ;GAC/B,KAAK;AACH,QAAI,QAAQ,oBAAoB;AAE9B,aAAQ,MACN,sFACD;AACD,YAAO;;AAET,WAAO,cAAc,QAAQ;GAE/B,QACE,OAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ,CAAC;;IAE9D,EAAE,CAAC;AAEN,QACE,oBAACA,iBAAAA;EACU;EACG;EACH;EACT,QAAA;EACA,SAAS,WAAW;EACC;EACb;GACR"}
package/dist/context.js CHANGED
@@ -1,20 +1,8 @@
1
- const perspectiveListeners = /* @__PURE__ */ new Set();
2
- let perspective = "checking";
3
- function setPerspective(nextPerspective) {
4
- if (perspective.toString() === nextPerspective.toString()) return;
5
- perspective = nextPerspective;
6
- for (const onPerspectiveChange of perspectiveListeners) onPerspectiveChange();
7
- }
8
- const environmentListeners = /* @__PURE__ */ new Set();
9
- let environment = "checking";
10
- function setEnvironment(nextEnvironment) {
11
- environment = nextEnvironment;
12
- for (const onEnvironmentChange of environmentListeners) onEnvironmentChange();
13
- }
14
1
  const comlinkListeners = /* @__PURE__ */ new Set();
15
2
  let comlink = null;
16
3
  let comlinkProjectId = null;
17
4
  let comlinkDataset = null;
5
+ let comlinkPerspective = null;
18
6
  function setComlink(nextComlink) {
19
7
  comlink = nextComlink;
20
8
  for (const onComlinkChange of comlinkListeners) onComlinkChange();
@@ -24,6 +12,11 @@ function setComlinkClientConfig(nextComlinkProjectId, nextComlinkDataset) {
24
12
  comlinkDataset = nextComlinkDataset;
25
13
  for (const onComlinkChange of comlinkListeners) onComlinkChange();
26
14
  }
27
- export { environment as a, perspectiveListeners as c, setEnvironment as d, setPerspective as f, comlinkProjectId as i, setComlink as l, comlinkDataset as n, environmentListeners as o, comlinkListeners as r, perspective as s, comlink as t, setComlinkClientConfig as u };
15
+ function setComlinkPerspective(nextComlinkPerspective) {
16
+ if (comlinkPerspective?.toString() === nextComlinkPerspective?.toString()) return;
17
+ comlinkPerspective = nextComlinkPerspective;
18
+ for (const onComlinkChange of comlinkListeners) onComlinkChange();
19
+ }
20
+ export { comlinkProjectId as a, setComlinkPerspective as c, comlinkPerspective as i, comlinkDataset as n, setComlink as o, comlinkListeners as r, setComlinkClientConfig as s, comlink as t };
28
21
 
29
22
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/live/shared/context.ts"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\nimport type {Node} from '@sanity/comlink'\nimport type {LoaderControllerMsg, LoaderNodeMsg} from '@sanity/presentation-comlink'\n\nexport type LivePerspective = 'checking' | 'unknown' | ClientPerspective\n\nexport const perspectiveListeners: Set<() => void> = new Set()\nexport let perspective: LivePerspective = 'checking'\nexport function setPerspective(nextPerspective: LivePerspective): void {\n if (perspective.toString() === nextPerspective.toString()) return\n perspective = nextPerspective\n for (const onPerspectiveChange of perspectiveListeners) {\n onPerspectiveChange()\n }\n}\n\nexport type LiveEnvironment =\n | 'checking'\n | 'presentation-iframe'\n | 'presentation-window'\n | 'live'\n | 'static'\n | 'unknown'\n\nexport const environmentListeners: Set<() => void> = new Set()\nexport let environment: LiveEnvironment = 'checking'\nexport function setEnvironment(nextEnvironment: LiveEnvironment): void {\n environment = nextEnvironment\n for (const onEnvironmentChange of environmentListeners) {\n onEnvironmentChange()\n }\n}\n\nexport const comlinkListeners: Set<() => void> = new Set()\nexport let comlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null = null\nexport let comlinkProjectId: string | null = null\nexport let comlinkDataset: string | null = null\nexport function setComlink(nextComlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null): void {\n comlink = nextComlink\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkClientConfig(\n nextComlinkProjectId: string | null,\n nextComlinkDataset: string | null,\n): void {\n comlinkProjectId = nextComlinkProjectId\n comlinkDataset = nextComlinkDataset\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\n"],"mappings":"AAMA,MAAa,uCAAwC,IAAI,KAAK;AAC9D,IAAW,cAA+B;AAC1C,SAAgB,eAAe,iBAAwC;AACrE,KAAI,YAAY,UAAU,KAAK,gBAAgB,UAAU,CAAE;AAC3D,eAAc;AACd,MAAK,MAAM,uBAAuB,qBAChC,sBAAqB;;AAYzB,MAAa,uCAAwC,IAAI,KAAK;AAC9D,IAAW,cAA+B;AAC1C,SAAgB,eAAe,iBAAwC;AACrE,eAAc;AACd,MAAK,MAAM,uBAAuB,qBAChC,sBAAqB;;AAIzB,MAAa,mCAAoC,IAAI,KAAK;AAC1D,IAAW,UAA2D;AACtE,IAAW,mBAAkC;AAC7C,IAAW,iBAAgC;AAC3C,SAAgB,WAAW,aAAoE;AAC7F,WAAU;AACV,MAAK,MAAM,mBAAmB,iBAC5B,kBAAiB;;AAGrB,SAAgB,uBACd,sBACA,oBACM;AACN,oBAAmB;AACnB,kBAAiB;AACjB,MAAK,MAAM,mBAAmB,iBAC5B,kBAAiB"}
1
+ {"version":3,"file":"context.js","names":[],"sources":["../src/live/shared/context.ts"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\nimport type {Node} from '@sanity/comlink'\nimport type {LoaderControllerMsg, LoaderNodeMsg} from '@sanity/presentation-comlink'\n\nexport const comlinkListeners: Set<() => void> = new Set()\nexport let comlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null = null\nexport let comlinkProjectId: string | null = null\nexport let comlinkDataset: string | null = null\nexport let comlinkPerspective: ClientPerspective | null = null\nexport function setComlink(nextComlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null): void {\n comlink = nextComlink\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkClientConfig(\n nextComlinkProjectId: string | null,\n nextComlinkDataset: string | null,\n): void {\n comlinkProjectId = nextComlinkProjectId\n comlinkDataset = nextComlinkDataset\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkPerspective(nextComlinkPerspective: ClientPerspective | null): void {\n if (comlinkPerspective?.toString() === nextComlinkPerspective?.toString()) return\n comlinkPerspective = nextComlinkPerspective\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\n"],"mappings":"AAIA,MAAa,mCAAoC,IAAI,KAAK;AAC1D,IAAW,UAA2D;AACtE,IAAW,mBAAkC;AAC7C,IAAW,iBAAgC;AAC3C,IAAW,qBAA+C;AAC1D,SAAgB,WAAW,aAAoE;AAC7F,WAAU;AACV,MAAK,MAAM,mBAAmB,iBAC5B,kBAAiB;;AAGrB,SAAgB,uBACd,sBACA,oBACM;AACN,oBAAmB;AACnB,kBAAiB;AACjB,MAAK,MAAM,mBAAmB,iBAC5B,kBAAiB;;AAGrB,SAAgB,sBAAsB,wBAAwD;AAC5F,KAAI,oBAAoB,UAAU,KAAK,wBAAwB,UAAU,CAAE;AAC3E,sBAAqB;AACrB,MAAK,MAAM,mBAAmB,iBAC5B,kBAAiB"}
@@ -66,13 +66,6 @@ interface DefinedLiveProps {
66
66
  */
67
67
  perspective?: PerspectiveType;
68
68
  /**
69
- * TODO: If Presentation Tool is present this event will fire with the current `perspective` stack used in the
70
- * Sanity Studio global perspective menu. The default event handler will store this state in a cookie,
71
- * which can be read with `resolvePerspectiveFromCookies` and used to ensure data fetching in the preview
72
- * matches the perspective and content viewed in the Studio, allowing you to quickly switch and preview different perspectives.
73
- */
74
- onStudioPerspective?: (perspective: ClientPerspective$1) => Promise<void>;
75
- /**
76
69
  * Automatic refresh of RSC when the component <SanityLive /> is mounted.
77
70
  * @defaultValue `false`
78
71
  */
@@ -1 +1 @@
1
- {"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/shared/types.ts","../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":[],"mappings":";;;KAOY,6BAAA;;AAAZ;;;;;;;;AAkBA;EACW,OAAA,EARA,OAQA,CARQ,UAQR,CAAA,OAR0B,OAQ1B,CAAA,CAAA;CAE0B,EAAA,GAT/B,OAS+B,CATvB,OASuB,CATf,iBASe,EAAA,KAAA,CAAA,CAAA;;;;;AACjC,cAJS,6BAIT,EAAA,CAAA;EAAA,OAAA,EAHO;CAGP,EAAA;EAAA,OAAA,EADO,OACP,CADe,UACf,CAAA,OADiC,OACjC,CAAA,CAAA;MAAA,QAAQ,QAAQ;;;;AAtBpB;AAWqC,KCJzB,eAAA,GAAkB,ODIO,CCJC,mBDID,EAAA,KAAA,CAAA;;;;AACvB,KCAF,gBAAA,GDAE,CAAA,0BAAA,MAAA,CAAA,CAAA,OAAA,EAAA;EAAR,KAAA,ECCG,WDDH;EAAA,MAAA,CAAA,ECEK,aDFL;EAMN;;;EAGmB,WAAA,CAAA,ECHH,eDGG;EAAR;;;;EACP,KAAA,CAAA,EAAA,OAAA;;ACfJ;AAKA;;EAEW,IAAA,CAAA,EAAA,MAAA,EAAA;EAIK;;;;;EAiBV,UAAA,CAAA,EAAA,MAAA;AAMN,CAAA,EAAA,GANM,OAMW,CAAA;EAKD,IAAA,EAVR,cAUQ,CAVK,WAUL,EAAA,OAAA,CAAA;EAQsB,SAAA,EAjBzB,kBAiByB,GAAA,IAAA;EAAsB,IAAA,EAAA,MAAA,EAAA;CA6CvC,CAAA;AAKY,UA/DhB,gBAAA,CA+DgB;EAOe;;AAGhD;;EClGA,WAAY,CAAA,ED8BI,eC9BJ;EACH;;;;;;EAkBY,mBAAA,CAAA,EAA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gDAOe;;UAG/B,WAAA;;;;UAIP;;;;;;;;;;;;;;AD9GV;AAWqC,KECzB,sBAAA,GFDyB,CAAA,0BAAA,MAAA,CAAA,CAAA,OAAA,EAAA;EAAlB,KAAA,EEEV,WFFU;EAAR,MAAA,CAAA,EEGA,WFHA,GEGc,OFHd,CEGsB,WFHtB,CAAA;EACW;;;;AAMtB;;EAGqC,IAAA,CAAA,EAAA,MAAA,EAAA;EAAlB,WAAA,CAAA,EECH,OFDG,CECK,iBFDL,EAAA,KAAA,CAAA;EAAR,KAAA,CAAA,EAAA,OAAA;EACS;;;;;ECfpB,UAAY,CAAA,EAAA,MAAA;AAKZ,CAAA,EAAA,GCkBM,ODlBM,CAAA;EACH,IAAA,ECkBD,YDlBC,CCkBY,WDlBZ,CAAA;EACE,SAAA,ECkBE,gBDlBF,GAAA,IAAA;EAIK,IAAA,EAAA,MAAA,EAAA;CAkBK,CAAA;;;;AADf,UCIW,sBAAA,SAA+B,gBDJ1C,CAAA;EAMN;;;EAuDiC,WAAA,CAAA,ECrDjB,eDqDiB;;;AAUjC;;AC9FY,UAqCK,uBAAA,CArCL;EACH;;;EACgB,MAAA,EAuCf,YAvCe;EAQD;;;;EAUX,WAAA,CAAA,EAAA,MAAA,GAAA,KAAA;EAFP;;AASN;AAUA;EAgCA,YAAgB,CAAA,EAAA,MAAA,GAAA,KAAA;EAAmB;;;EAQrB,YAAM,CAAA,EAAA;IAAA;;;;;;;;;;;;iBARJ,UAAA,SAAmB;;;;eAIpB;;;;cAID,KAAA,CAAM,cAAc"}
@@ -1,38 +1,5 @@
1
1
  import { useOptimistic } from "@sanity/visual-editing/react";
2
2
  import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
3
- import "@sanity/comlink";
4
- import "@sanity/presentation-comlink";
5
- type LivePerspective = "checking" | "unknown" | ClientPerspective;
6
- type LiveEnvironment = "checking" | "presentation-iframe" | "presentation-window" | "live" | "static" | "unknown";
7
- /**
8
- * Reports the current draft mode environment.
9
- * Use it to determine how to adapt the UI based on wether:
10
- * - Your app is previewed in a iframe, inside Presentation Tool in a Sanity Studio.
11
- * - Your app is previewed in a new window, spawned from Presentation Tool in a Sanity Studio.
12
- * - Your app is live previewing drafts in a standalone context.
13
- * - Your app is previewing drafts, but not live.
14
- * - Your app is not previewing anything (that could be detected).
15
- * @public
16
- */
17
- declare function useDraftModeEnvironment(): LiveEnvironment;
18
- /**
19
- * Reports the Sanity Client perspective used to fetch data in `sanityFetch` used on the page.
20
- * If the hook is used outside Draft Mode it will resolve to `'unknown'`.
21
- * If the hook is used but the `<SanityLive />` component is not present then it'll stay in `'checking'` and console warn after a timeout that it seems like you're missing the component.
22
- * @public
23
- */
24
- declare function useDraftModePerspective(): LivePerspective;
25
- /**
26
- * Detects if the application is being previewed inside Sanity Presentation Tool.
27
- * Presentation Tool can open the application in an iframe, or in a new window.
28
- * When in this context there are some UI you usually don't want to show,
29
- * for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to
30
- * the editorial experience.
31
- * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,
32
- * then `true` if it is, and `false` otherwise.
33
- * @public
34
- */
35
- declare function useIsPresentationTool(): boolean | null;
36
3
  /**
37
4
  * Detects if the application is considered to be in a "Live Preview" mode.
38
5
  * Live Preview means that the application is either:
@@ -49,6 +16,7 @@ declare function useIsPresentationTool(): boolean | null;
49
16
  * @public
50
17
  */
51
18
  declare function useIsLivePreview(): boolean | null;
19
+ declare function useLiveEnvironment(): null;
52
20
  /** @alpha */
53
21
  type UsePresentationQueryReturnsInactive = {
54
22
  data: null;
@@ -75,5 +43,18 @@ declare function usePresentationQuery<const QueryString extends string>(props: {
75
43
  params?: QueryParams | Promise<QueryParams>;
76
44
  stega?: boolean;
77
45
  }): UsePresentationQueryReturns<QueryString>;
78
- export { UsePresentationQueryReturns, UsePresentationQueryReturnsActive, UsePresentationQueryReturnsInactive, useDraftModeEnvironment, useDraftModePerspective, useIsLivePreview, useIsPresentationTool, useOptimistic, usePresentationQuery };
46
+ /**
47
+ * Detects if the application is being previewed inside Sanity Presentation Tool.
48
+ * Presentation Tool can open the application in an iframe, or in a new window.
49
+ * When in this context there are some UI you usually don't want to show,
50
+ * for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to
51
+ * the editorial experience.
52
+ * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,
53
+ * then `true` if it is, and `false` otherwise.
54
+ * @public
55
+ */
56
+ declare function useIsPresentationTool(): boolean | null;
57
+ type VisualEditingEnvironment = null | "unknown" | "presentation-iframe" | "presentation-window" | "standalone";
58
+ declare function useVisualEditingEnvironment(): VisualEditingEnvironment;
59
+ export { UsePresentationQueryReturns, UsePresentationQueryReturnsActive, UsePresentationQueryReturnsInactive, useIsLivePreview, useIsPresentationTool, useLiveEnvironment, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
79
60
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/live/shared/context.ts","../../src/live/hooks/useDraftMode.ts","../../src/live/hooks/useIsPresentationTool.ts","../../src/live/hooks/useIsLivePreview.ts","../../src/live/hooks/usePresentationQuery.ts"],"sourcesContent":[],"mappings":";;;;KAIY,eAAA,4BAA2C;KAY3C,eAAA;;;;;AAZZ;AAYA;;ACIA;AAmBA;;AC3BgB,iBDQA,uBAAA,CAAA,CCRA,EDQ2B,eCR3B;;ACKhB;;ACDA;AAOA;;AACQ,iBHeQ,uBAAA,CAAA,CGfR,EHemC,eGfnC;;;;;;AJpBR;AAYA;;ACIA;AAmBA;iBC3BgB,qBAAA,CAAA;;;;;;AFRhB;AAYA;;ACIA;AAmBA;;AC3BA;;ACKA;;ACDY,iBDCI,gBAAA,CAAA,CCDJ,EAAA,OAAA,GAAA,IAAA;;KAAA,mCAAA;;;EJZZ,WAAY,EAAA,IAAA;AAYZ,CAAA;;ACIgB,KGGJ,iCHH+B,CAAA,oBAAA,MAAA,CAAA,GAAA;EAmB3C,IAAgB,EGfR,YHeQ,CGfK,WHeL,CAAA;aGdH;EFbb,WAAgB,EEcD,iBFdC;;ACKA,KCYJ,2BDZI,CAAA,oBAAA,MAAA,CAAA,GCaZ,mCDbY,GCcZ,iCDdY,CCcsB,WDdtB,CAAA;;ACDhB;AAOA;;;;;;AAMY,iBAyDI,oBAzDJ,CAAA,0BAAA,MAAA,CAAA,CAAA,KAAA,EAAA;EACR,KAAA,EAyDK,WAzDL;EACkC,MAAA,CAAA,EAyD3B,WAzD2B,GAyDb,OAzDa,CAyDL,WAzDK,CAAA;EAAlC,KAAA,CAAA,EAAA,OAAA;CAAA,CAAA,EA2DA,2BA3DA,CA2D4B,WA3D5B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/hooks/useIsLivePreview.ts","../../src/live/hooks/useLiveEnvironment.ts","../../src/live/hooks/usePresentationQuery.ts","../../src/visual-editing/hooks/useIsPresentationTool.ts","../../src/visual-editing/hooks/useVisualEditingEnvironment.ts"],"sourcesContent":[],"mappings":";;;;;AAeA;;ACfA;;ACeA;AAOA;;;;;;AAMA;AACI,iBFdY,gBAAA,CAAA,CEcZ,EAAA,OAAA,GAAA,IAAA;iBD7BY,kBAAA,CAAA;;KCeJ,mCAAA;EFAZ,IAAgB,EAAA,IAAA;;ECfhB,WAAgB,EAAA,IAAA;;ACehB;AAOY,KAAA,iCAAA,CAAA,oBAAA,MAAA,CAAA,GAAA;EACS,IAAA,EAAb,YAAa,CAAA,WAAA,CAAA;EAAb,SAAA,EACK,gBADL,GAAA,IAAA;EACK,WAAA,EACE,iBADF;CACE;AAAA,KAGH,2BAHG,CAAA,oBAAA,MAAA,CAAA,GAIX,mCAJW,GAKX,iCALW,CAKuB,WALvB,CAAA;AAGf;;;;;AAyDA;;;AAEiC,iBAFjB,oBAEiB,CAAA,0BAAA,MAAA,CAAA,CAAA,KAAA,EAAA;EAAR,KAAA,EADhB,WACgB;EAEO,MAAA,CAAA,EAFrB,WAEqB,GAFP,OAEO,CAFC,WAED,CAAA;EAA5B,KAAA,CAAA,EAAA,OAAA;CAAA,CAAA,EAAA,2BAAA,CAA4B,WAA5B,CAAA;;;;AF1EJ;;ACfA;;ACeA;AAOA;;AACQ,iBCbQ,qBAAA,CAAA,CDaR,EAAA,OAAA,GAAA,IAAA;KEvBH,wBAAA;iBAOW,2BAAA,CAAA,GAA+B"}
@@ -1,28 +1,16 @@
1
1
  "use client";
2
- import { a as environment, c as perspectiveListeners, i as comlinkProjectId, n as comlinkDataset, o as environmentListeners, r as comlinkListeners, s as perspective, t as comlink } from "../context.js";
3
- import { useCallback, useEffect, useEffectEvent, useMemo, useReducer, useSyncExternalStore } from "react";
2
+ import { a as comlinkProjectId, i as comlinkPerspective, n as comlinkDataset, r as comlinkListeners, t as comlink } from "../context.js";
4
3
  import { stegaEncodeSourceMap } from "@sanity/client/stega";
5
4
  import { dequal } from "dequal/lite";
5
+ import { useEffect, useEffectEvent, useMemo, useReducer, useSyncExternalStore } from "react";
6
6
  import { useOptimistic } from "@sanity/visual-editing/react";
7
- function useDraftModeEnvironment() {
8
- return useSyncExternalStore(useCallback((listener) => {
9
- environmentListeners.add(listener);
10
- return () => environmentListeners.delete(listener);
11
- }, []), () => environment, () => "checking");
12
- }
13
- function useDraftModePerspective() {
14
- return useSyncExternalStore(useCallback((listener) => {
15
- perspectiveListeners.add(listener);
16
- return () => perspectiveListeners.delete(listener);
17
- }, []), () => perspective, () => "checking");
18
- }
19
- function useIsPresentationTool() {
20
- const environment$1 = useDraftModeEnvironment();
21
- return environment$1 === "checking" ? null : environment$1 === "presentation-iframe" || environment$1 === "presentation-window";
22
- }
23
7
  function useIsLivePreview() {
24
- const environment$1 = useDraftModeEnvironment();
25
- return environment$1 === "checking" ? null : environment$1 === "presentation-iframe" || environment$1 === "presentation-window" || environment$1 === "live";
8
+ console.log("TODO: Implement useIsLivePreview");
9
+ return null;
10
+ }
11
+ function useLiveEnvironment() {
12
+ console.log("TODO: Implement useLiveEnvironment");
13
+ return null;
26
14
  }
27
15
  function reducer(state, { type, payload }) {
28
16
  switch (type) {
@@ -52,21 +40,21 @@ function usePresentationQuery(props) {
52
40
  const comlink$1 = useSyncExternalStore(subscribe, () => comlink, () => null);
53
41
  const projectId = useSyncExternalStore(subscribe, () => comlinkProjectId, () => null);
54
42
  const dataset = useSyncExternalStore(subscribe, () => comlinkDataset, () => null);
55
- const perspective$1 = useDraftModePerspective();
43
+ const perspective = useSyncExternalStore(subscribe, () => comlinkPerspective, () => null);
56
44
  const handleQueryHeartbeat = useEffectEvent((comlink$2) => {
57
- if (!projectId || !dataset || !perspective$1) {
45
+ if (!projectId || !dataset || !perspective) {
58
46
  console.warn("usePresentationQuery: projectId, dataset and perspective must be set", {
59
47
  projectId,
60
48
  dataset,
61
- perspective: perspective$1
49
+ perspective
62
50
  });
63
51
  return;
64
52
  }
65
- if (perspective$1 === "checking" || perspective$1 === "unknown") return;
53
+ if (perspective === null) return;
66
54
  comlink$2.post("loader/query-listen", {
67
55
  projectId,
68
56
  dataset,
69
- perspective: perspective$1,
57
+ perspective,
70
58
  query,
71
59
  params,
72
60
  heartbeat: LISTEN_HEARTBEAT_INTERVAL
@@ -112,6 +100,14 @@ function usePresentationQuery(props) {
112
100
  return state;
113
101
  }, [state, stega]);
114
102
  }
115
- export { useDraftModeEnvironment, useDraftModePerspective, useIsLivePreview, useIsPresentationTool, useOptimistic, usePresentationQuery };
103
+ function useIsPresentationTool() {
104
+ console.log("TODO: Implement useIsPresentationTool");
105
+ return null;
106
+ }
107
+ function useVisualEditingEnvironment() {
108
+ console.log("TODO: Implement useVisualEditingEnvironment");
109
+ return null;
110
+ }
111
+ export { useIsLivePreview, useIsPresentationTool, useLiveEnvironment, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
116
112
 
117
113
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["environment","environment","comlink","comlinkSnapshot","perspective"],"sources":["../../src/live/hooks/useDraftMode.ts","../../src/live/hooks/useIsPresentationTool.ts","../../src/live/hooks/useIsLivePreview.ts","../../src/live/hooks/usePresentationQuery.ts"],"sourcesContent":["import {\n environment,\n environmentListeners,\n perspective,\n perspectiveListeners,\n type LiveEnvironment,\n type LivePerspective,\n} from '#live/context'\nimport {useCallback, useSyncExternalStore} from 'react'\n\n/**\n * Reports the current draft mode environment.\n * Use it to determine how to adapt the UI based on wether:\n * - Your app is previewed in a iframe, inside Presentation Tool in a Sanity Studio.\n * - Your app is previewed in a new window, spawned from Presentation Tool in a Sanity Studio.\n * - Your app is live previewing drafts in a standalone context.\n * - Your app is previewing drafts, but not live.\n * - Your app is not previewing anything (that could be detected).\n * @public\n */\nexport function useDraftModeEnvironment(): LiveEnvironment {\n const subscribe = useCallback((listener: () => void) => {\n environmentListeners.add(listener)\n return () => environmentListeners.delete(listener)\n }, [])\n\n return useSyncExternalStore(\n subscribe,\n () => environment,\n () => 'checking',\n )\n}\n\n/**\n * Reports the Sanity Client perspective used to fetch data in `sanityFetch` used on the page.\n * If the hook is used outside Draft Mode it will resolve to `'unknown'`.\n * If the hook is used but the `<SanityLive />` component is not present then it'll stay in `'checking'` and console warn after a timeout that it seems like you're missing the component.\n * @public\n */\nexport function useDraftModePerspective(): LivePerspective {\n const subscribe = useCallback((listener: () => void) => {\n perspectiveListeners.add(listener)\n return () => perspectiveListeners.delete(listener)\n }, [])\n\n return useSyncExternalStore(\n subscribe,\n () => perspective,\n () => 'checking',\n )\n}\n","import {useDraftModeEnvironment} from './useDraftMode'\n\n/**\n * Detects if the application is being previewed inside Sanity Presentation Tool.\n * Presentation Tool can open the application in an iframe, or in a new window.\n * When in this context there are some UI you usually don't want to show,\n * for example a Draft Mode toggle, or a \"Viewing draft content\" indicators, these are unnecessary and add clutter to\n * the editorial experience.\n * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,\n * then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsPresentationTool(): boolean | null {\n const environment = useDraftModeEnvironment()\n return environment === 'checking'\n ? null\n : environment === 'presentation-iframe' || environment === 'presentation-window'\n}\n","import {useDraftModeEnvironment} from './useDraftMode'\n\n/**\n * Detects if the application is considered to be in a \"Live Preview\" mode.\n * Live Preview means that the application is either:\n * - being previewed inside Sanity Presentation Tool\n * - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as \"Standalone Live Preview'\"\n * When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.\n * This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,\n * to avoid interrupting the user that is consuming your content.\n * This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,\n * while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.\n *\n * The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.\n * Then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsLivePreview(): boolean | null {\n const environment = useDraftModeEnvironment()\n return environment === 'checking'\n ? null\n : environment === 'presentation-iframe' ||\n environment === 'presentation-window' ||\n environment === 'live'\n}\n","import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\nimport type {LoaderControllerMsg} from '@sanity/presentation-comlink'\n\nimport {\n comlinkDataset,\n comlinkListeners,\n comlinkProjectId,\n comlink as comlinkSnapshot,\n} from '#live/context'\nimport {stegaEncodeSourceMap} from '@sanity/client/stega'\nimport {dequal} from 'dequal/lite'\nimport {useEffect, useMemo, useReducer, useSyncExternalStore, useEffectEvent} from 'react'\n\nimport {useDraftModePerspective} from './useDraftMode'\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\ntype Action<QueryString extends string> = {\n type: 'query-change'\n payload: UsePresentationQueryReturnsActive<QueryString>\n}\n\nfunction reducer<QueryString extends string>(\n state: UsePresentationQueryReturns<QueryString>,\n {type, payload}: Action<QueryString>,\n): UsePresentationQueryReturns<QueryString> {\n switch (type) {\n case 'query-change':\n return dequal(state, payload)\n ? state\n : {\n ...state,\n data: dequal(state.data, payload.data)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.data as ClientReturn<QueryString>)\n : payload.data,\n sourceMap: dequal(state.sourceMap, payload.sourceMap)\n ? state.sourceMap\n : payload.sourceMap,\n perspective: dequal(state.perspective, payload.perspective)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.perspective as Exclude<ClientPerspective, 'raw'>)\n : payload.perspective,\n }\n default:\n return state\n }\n}\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\nfunction subscribe(listener: () => void) {\n comlinkListeners.add(listener)\n return () => comlinkListeners.delete(listener)\n}\n\nconst EMPTY_QUERY_PARAMS: QueryParams = {}\nconst LISTEN_HEARTBEAT_INTERVAL = 10_000\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(props: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n const [state, dispatch] = useReducer(reducer, initialState)\n const {query, params = EMPTY_QUERY_PARAMS, stega = true} = props\n\n /**\n * Comlink forwards queries we want to run to the parent window where Presentation Tool handles it for us\n */\n const comlink = useSyncExternalStore(\n subscribe,\n () => comlinkSnapshot,\n () => null,\n )\n /**\n * The comlink events requires projectId and dataset, Presentation Tool uses it to protect against project and dataset mismatch errors.\n * We don't want to force the consumers of the `usePresentationQuery` hook to provide these,\n * so we set them in the component that establishes the comlink connection and propagates it to all the subscribes.\n */\n const projectId = useSyncExternalStore(\n subscribe,\n () => comlinkProjectId,\n () => null,\n )\n const dataset = useSyncExternalStore(\n subscribe,\n () => comlinkDataset,\n () => null,\n )\n /**\n * The perspective is kept in sync with Presentation Tool's perspective, and even knows what perspective the page loaded with initially and can forward it to the Sanity Studio.\n */\n const perspective = useDraftModePerspective()\n const handleQueryHeartbeat = useEffectEvent((comlink: NonNullable<typeof comlinkSnapshot>) => {\n // Handle odd case where the comlink can take events but some data is missing\n if (!projectId || !dataset || !perspective) {\n console.warn('usePresentationQuery: projectId, dataset and perspective must be set', {\n projectId,\n dataset,\n perspective,\n })\n return\n }\n // Another odd case where the initial perspective states haven't resolved to the actual perspective state\n if (perspective === 'checking' || perspective === 'unknown') {\n return\n }\n comlink.post('loader/query-listen', {\n projectId,\n dataset,\n perspective,\n query,\n params,\n heartbeat: LISTEN_HEARTBEAT_INTERVAL,\n })\n })\n const handleQueryChange = useEffectEvent(\n (event: Extract<LoaderControllerMsg, {type: 'loader/query-change'}>['data']) => {\n if (\n dequal(\n {\n projectId,\n dataset,\n query,\n params,\n },\n {\n projectId: event.projectId,\n dataset: event.dataset,\n query: event.query,\n params: event.params,\n },\n )\n ) {\n dispatch({\n type: 'query-change',\n payload: {\n data: event.result,\n sourceMap: event.resultSourceMap || null,\n perspective: event.perspective,\n },\n })\n }\n },\n )\n useEffect(() => {\n if (!comlink) return\n\n const unsubscribe = comlink.on('loader/query-change', handleQueryChange)\n const interval = setInterval(() => handleQueryHeartbeat(comlink), LISTEN_HEARTBEAT_INTERVAL)\n return () => {\n clearInterval(interval)\n unsubscribe()\n }\n }, [comlink])\n\n return useMemo(() => {\n if (stega && state.sourceMap) {\n return {\n ...state,\n data: stegaEncodeSourceMap(state.data, state.sourceMap, {enabled: true, studioUrl: '/'}),\n }\n }\n return state\n }, [state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Q,SAAQ;CAK3D,MAAMC,YAAU,qBACd,iBACMC,eACA,KACP;CAMD,MAAM,YAAY,qBAChB,iBACM,wBACA,KACP;CACD,MAAM,UAAU,qBACd,iBACM,sBACA,KACP;CAID,MAAMC,gBAAc,yBAAyB;CAC7C,MAAM,uBAAuB,gBAAgB,cAAiD;AAE5F,MAAI,CAAC,aAAa,CAAC,WAAW,CAACA,eAAa;AAC1C,WAAQ,KAAK,wEAAwE;IACnF;IACA;IACA,aAAA;IACD,CAAC;AACF;;AAGF,MAAIA,kBAAgB,cAAcA,kBAAgB,UAChD;AAEF,YAAQ,KAAK,uBAAuB;GAClC;GACA;GACA,aAAA;GACA;GACA;GACA,WAAW;GACZ,CAAC;GACF;CACF,MAAM,oBAAoB,gBACvB,UAA+E;AAC9E,MACE,OACE;GACE;GACA;GACA;GACA;GACD,EACD;GACE,WAAW,MAAM;GACjB,SAAS,MAAM;GACf,OAAO,MAAM;GACb,QAAQ,MAAM;GACf,CACF,CAED,UAAS;GACP,MAAM;GACN,SAAS;IACP,MAAM,MAAM;IACZ,WAAW,MAAM,mBAAmB;IACpC,aAAa,MAAM;IACpB;GACF,CAAC;GAGP;AACD,iBAAgB;AACd,MAAI,CAACF,UAAS;EAEd,MAAM,cAAcA,UAAQ,GAAG,uBAAuB,kBAAkB;EACxE,MAAM,WAAW,kBAAkB,qBAAqBA,UAAQ,EAAE,0BAA0B;AAC5F,eAAa;AACX,iBAAc,SAAS;AACvB,gBAAa;;IAEd,CAACA,UAAQ,CAAC;AAEb,QAAO,cAAc;AACnB,MAAI,SAAS,MAAM,UACjB,QAAO;GACL,GAAG;GACH,MAAM,qBAAqB,MAAM,MAAM,MAAM,WAAW;IAAC,SAAS;IAAM,WAAW;IAAI,CAAC;GACzF;AAEH,SAAO;IACN,CAAC,OAAO,MAAM,CAAC"}
1
+ {"version":3,"file":"index.js","names":["comlink","comlinkSnapshot"],"sources":["../../src/hooks/useIsLivePreview.ts","../../src/live/hooks/useLiveEnvironment.ts","../../src/live/hooks/usePresentationQuery.ts","../../src/visual-editing/hooks/useIsPresentationTool.ts","../../src/visual-editing/hooks/useVisualEditingEnvironment.ts"],"sourcesContent":["/**\n * Detects if the application is considered to be in a \"Live Preview\" mode.\n * Live Preview means that the application is either:\n * - being previewed inside Sanity Presentation Tool\n * - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as \"Standalone Live Preview'\"\n * When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.\n * This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,\n * to avoid interrupting the user that is consuming your content.\n * This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,\n * while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.\n *\n * The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.\n * Then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsLivePreview(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsLivePreview')\n\n return null\n}\n","export function useLiveEnvironment(): null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useLiveEnvironment')\n\n return null\n}\n","import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\nimport type {LoaderControllerMsg} from '@sanity/presentation-comlink'\n\nimport {\n comlinkDataset,\n comlinkListeners,\n comlinkProjectId,\n comlinkPerspective,\n comlink as comlinkSnapshot,\n} from '#live/context'\nimport {stegaEncodeSourceMap} from '@sanity/client/stega'\nimport {dequal} from 'dequal/lite'\nimport {useEffect, useMemo, useReducer, useSyncExternalStore, useEffectEvent} from 'react'\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\ntype Action<QueryString extends string> = {\n type: 'query-change'\n payload: UsePresentationQueryReturnsActive<QueryString>\n}\n\nfunction reducer<QueryString extends string>(\n state: UsePresentationQueryReturns<QueryString>,\n {type, payload}: Action<QueryString>,\n): UsePresentationQueryReturns<QueryString> {\n switch (type) {\n case 'query-change':\n return dequal(state, payload)\n ? state\n : {\n ...state,\n data: dequal(state.data, payload.data)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.data as ClientReturn<QueryString>)\n : payload.data,\n sourceMap: dequal(state.sourceMap, payload.sourceMap)\n ? state.sourceMap\n : payload.sourceMap,\n perspective: dequal(state.perspective, payload.perspective)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.perspective as Exclude<ClientPerspective, 'raw'>)\n : payload.perspective,\n }\n default:\n return state\n }\n}\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\nfunction subscribe(listener: () => void) {\n comlinkListeners.add(listener)\n return () => comlinkListeners.delete(listener)\n}\n\nconst EMPTY_QUERY_PARAMS: QueryParams = {}\nconst LISTEN_HEARTBEAT_INTERVAL = 10_000\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(props: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n const [state, dispatch] = useReducer(reducer, initialState)\n const {query, params = EMPTY_QUERY_PARAMS, stega = true} = props\n\n /**\n * Comlink forwards queries we want to run to the parent window where Presentation Tool handles it for us\n */\n const comlink = useSyncExternalStore(\n subscribe,\n () => comlinkSnapshot,\n () => null,\n )\n /**\n * The comlink events requires projectId and dataset, Presentation Tool uses it to protect against project and dataset mismatch errors.\n * We don't want to force the consumers of the `usePresentationQuery` hook to provide these,\n * so we set them in the component that establishes the comlink connection and propagates it to all the subscribes.\n */\n const projectId = useSyncExternalStore(\n subscribe,\n () => comlinkProjectId,\n () => null,\n )\n const dataset = useSyncExternalStore(\n subscribe,\n () => comlinkDataset,\n () => null,\n )\n /**\n * The perspective is kept in sync with Presentation Tool's perspective, and even knows what perspective the page loaded with initially and can forward it to the Sanity Studio.\n */\n const perspective = useSyncExternalStore(\n subscribe,\n () => comlinkPerspective,\n () => null,\n )\n\n const handleQueryHeartbeat = useEffectEvent((comlink: NonNullable<typeof comlinkSnapshot>) => {\n // Handle odd case where the comlink can take events but some data is missing\n if (!projectId || !dataset || !perspective) {\n console.warn('usePresentationQuery: projectId, dataset and perspective must be set', {\n projectId,\n dataset,\n perspective,\n })\n return\n }\n // Another odd case where the initial perspective states haven't resolved to the actual perspective state\n if (perspective === null) {\n return\n }\n comlink.post('loader/query-listen', {\n projectId,\n dataset,\n perspective,\n query,\n params,\n heartbeat: LISTEN_HEARTBEAT_INTERVAL,\n })\n })\n const handleQueryChange = useEffectEvent(\n (event: Extract<LoaderControllerMsg, {type: 'loader/query-change'}>['data']) => {\n if (\n dequal(\n {\n projectId,\n dataset,\n query,\n params,\n },\n {\n projectId: event.projectId,\n dataset: event.dataset,\n query: event.query,\n params: event.params,\n },\n )\n ) {\n dispatch({\n type: 'query-change',\n payload: {\n data: event.result,\n sourceMap: event.resultSourceMap || null,\n perspective: event.perspective,\n },\n })\n }\n },\n )\n useEffect(() => {\n if (!comlink) return\n\n const unsubscribe = comlink.on('loader/query-change', handleQueryChange)\n const interval = setInterval(() => handleQueryHeartbeat(comlink), LISTEN_HEARTBEAT_INTERVAL)\n return () => {\n clearInterval(interval)\n unsubscribe()\n }\n }, [comlink])\n\n return useMemo(() => {\n if (stega && state.sourceMap) {\n return {\n ...state,\n data: stegaEncodeSourceMap(state.data, state.sourceMap, {enabled: true, studioUrl: '/'}),\n }\n }\n return state\n }, [state, stega])\n}\n","/**\n * Detects if the application is being previewed inside Sanity Presentation Tool.\n * Presentation Tool can open the application in an iframe, or in a new window.\n * When in this context there are some UI you usually don't want to show,\n * for example a Draft Mode toggle, or a \"Viewing draft content\" indicators, these are unnecessary and add clutter to\n * the editorial experience.\n * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,\n * then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsPresentationTool(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsPresentationTool')\n\n return null\n}\n","type VisualEditingEnvironment =\n | null\n | 'unknown'\n | 'presentation-iframe'\n | 'presentation-window'\n | 'standalone'\n\nexport function useVisualEditingEnvironment(): VisualEditingEnvironment {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useVisualEditingEnvironment')\n\n return null\n}\n"],"mappings":";;;;;;AAeA,SAAgB,mBAAmC;AAEjD,SAAQ,IAAI,mCAAmC;AAE/C,QAAO;;ACnBT,SAAgB,qBAA2B;AAEzC,SAAQ,IAAI,qCAAqC;AAEjD,QAAO;;ACiCT,SAAS,QACP,OACA,EAAC,MAAM,WACmC;AAC1C,SAAQ,MAAR;EACE,KAAK,eACH,QAAO,OAAO,OAAO,QAAQ,GACzB,QACA;GACE,GAAG;GACH,MAAM,OAAO,MAAM,MAAM,QAAQ,KAAK,GAEjC,MAAM,OACP,QAAQ;GACZ,WAAW,OAAO,MAAM,WAAW,QAAQ,UAAU,GACjD,MAAM,YACN,QAAQ;GACZ,aAAa,OAAO,MAAM,aAAa,QAAQ,YAAY,GAEtD,MAAM,cACP,QAAQ;GACb;EACP,QACE,QAAO;;;AAGb,MAAM,eAAoD;CACxD,MAAM;CACN,WAAW;CACX,aAAa;CACd;AAED,SAAS,UAAU,UAAsB;AACvC,kBAAiB,IAAI,SAAS;AAC9B,cAAa,iBAAiB,OAAO,SAAS;;AAGhD,MAAM,qBAAkC,EAAE;AAC1C,MAAM,4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M,CAAC;;AC1LpB,SAAgB,wBAAwC;AAEtD,SAAQ,IAAI,wCAAwC;AAEpD,QAAO;;ACPT,SAAgB,8BAAwD;AAEtE,SAAQ,IAAI,8CAA8C;AAE1D,QAAO"}
@@ -1,8 +1,5 @@
1
1
  import { ClientPerspective, InitializedClientConfig, LiveEventGoAway } from "@sanity/client";
2
2
  interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
3
- /**
4
- * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
5
- */
6
3
  interface SanityLiveProps {
7
4
  config: SanityClientConfig;
8
5
  /**
@@ -11,7 +8,6 @@ interface SanityLiveProps {
11
8
  perspective: Exclude<ClientPerspective, "raw">;
12
9
  onLiveEvent: (tags: string[]) => Promise<void | "refresh">;
13
10
  onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | "refresh">;
14
- onPresentationPerspective: (perspective: ClientPerspective) => Promise<void>;
15
11
  refreshOnMount?: boolean;
16
12
  refreshOnFocus?: boolean;
17
13
  refreshOnReconnect?: boolean;
@@ -24,6 +20,9 @@ interface SanityLiveProps {
24
20
  intervalOnGoAway?: number | false;
25
21
  onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
26
22
  }
23
+ /**
24
+ * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
25
+ */
27
26
  declare const SanityLive: React.ComponentType<SanityLiveProps>;
28
27
  export { SanityLive };
29
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";UAqBU,kBAAA,SAA2B,KACnC;AAZK;AAyBP;;AAKuB,UALN,eAAA,CAKM;EAAR,MAAA,EAJL,kBAIK;EAEoB;;;EAE8B,WAAA,EAJlD,OAIkD,CAJ1C,iBAI0C,EAAA,KAAA,CAAA;EAa5C,WAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GAfc,OAed,CAAA,IAAA,GAAA,SAAA,CAAA;EAAA,0BAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GAd6B,OAc7B,CAAA,IAAA,GAAA,SAAA,CAAA;2CAbsB,sBAAsB;ECvCjE,cAAa,CAAA,EAAgC,OAAA;;;;;;;;;;qBDoDxB;;cCpDR,YAAY,KAAA,CAAM,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";UAwBU,kBAAA,SAA2B,KACnC;AADQ,UAWO,eAAA,CAXP;EAWV,MAAiB,EACP,kBADO;EACP;;;EAMyB,WAAA,EAFpB,OAEoB,CAFZ,iBAEY,EAAA,KAAA,CAAA;EACe,WAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GADf,OACe,CAAA,IAAA,GAAA,SAAA,CAAA;EAa7B,0BAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GAb6B,OAa7B,CAAA,IAAA,GAAA,SAAA,CAAA;EAAA,cAAA,CAAA,EAAA,OAAA;;EChDrB,kBAA6C,CAAA,EAAA,OAAA;;;;;;;;qBDgDxB;;;AA/Cd;AA0BP;AACU,cC5BG,UD4BH,EC5Be,KAAA,CAAM,aD4BrB,CC5BmC,eD4BnC,CAAA"}
@@ -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'\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;AAKA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
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 * @alpha 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,OAAM,CACb"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":";;iBAegB,UAAA,SAAmB;EAAnC,WAAgB,EACD,sBADC;EAAmB,UAAA,EAErB,KAAA,CAAM,aAFe,CAED,sBAFC,CAAA;CACpB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":";;iBAWgB,UAAA,SAAmB;EAAnC,WAAgB,EACD,sBADC;EAAmB,UAAA,EAErB,KAAA,CAAM,aAFe,CAED,sBAFC,CAAA;CACpB"}
@@ -4,7 +4,7 @@ import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveF
4
4
  import { Suspense } from "react";
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { SanityLive } from "next-sanity/live/client-components";
7
- import { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective } from "next-sanity/live/server-actions";
7
+ import { actionLiveEvent, actionLiveEventIncludingDrafts } from "next-sanity/live/server-actions";
8
8
  import { cacheLife, cacheTag } from "next/cache";
9
9
  import { preconnect } from "react-dom";
10
10
  function defineLive(config) {
@@ -39,7 +39,7 @@ function defineLive(config) {
39
39
  };
40
40
  };
41
41
  const Live = function Live$1(props) {
42
- const { perspective = "published", onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, onStudioPerspective = actionStudioPerspective, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components", onError, onGoAway, intervalOnGoAway } = props;
42
+ const { perspective = "published", onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components", onError, onGoAway, intervalOnGoAway } = props;
43
43
  const includeDrafts = typeof browserToken === "string" && perspective !== "published";
44
44
  const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
45
45
  const { origin } = new URL(client.getUrl("", false));
@@ -57,7 +57,6 @@ function defineLive(config) {
57
57
  perspective,
58
58
  onLiveEvent: onChange,
59
59
  onLiveEventIncludingDrafts: onChangeIncludingDrafts,
60
- onPresentationPerspective: onStudioPerspective,
61
60
  requestTag,
62
61
  refreshOnMount,
63
62
  refreshOnFocus,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fetch","Live","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, LiveOptions} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {\n actionStudioPerspective,\n actionLiveEvent,\n actionLiveEventIncludingDrafts,\n} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {Suspense} from 'react'\nimport {preconnect} from 'react-dom'\n\nimport type {DefinedSanityFetchType, DefinedSanityLiveProps} from '../react-server/defineLive'\n\nexport function defineLive(config: LiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n} {\n const {client: _client, serverToken, browserToken} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: true})\n const {token: originalToken} = client.config()\n\n const fetch: DefinedFetchType = async function fetch({\n query,\n params = {},\n perspective = 'published',\n stega = false,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n const useCdn = perspective === 'published'\n\n const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [\n ...customCacheTags,\n ...(syncTags || []).map(\n (tag) =>\n `${perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`,\n ),\n ]\n /**\n * The tags used here, are expired later on in the `expireTags` Server Action with the `expireTag` function from `next/cache`\n */\n cacheTag(...tags)\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short,\n * userland can still set a shorter revalidate time by calling `cacheLife` themselves.\n */\n cacheLife({revalidate})\n\n return {data: result, sourceMap: resultSourceMap || null, tags}\n }\n\n const Live: React.ComponentType<DefinedLiveProps> = function Live(props) {\n const {\n perspective = 'published',\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n onStudioPerspective = actionStudioPerspective,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n onError,\n onGoAway,\n intervalOnGoAway,\n } = props\n\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <Suspense>\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={perspective}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n onPresentationPerspective={onStudioPerspective}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n </Suspense>\n )\n }\n Live.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch: fetch,\n SanityLive: Live,\n }\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,WAAW,QAGzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,iBAAgB;AAErD,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAK,CAAC;CAC1E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;CAE9C,MAAM,QAA0B,eAAeA,QAAM,EACnD,OACA,SAAS,EAAE,EACX,cAAc,aACd,QAAQ,OACR,MAAM,kBAAkB,EAAE,EAC1B,aAAa,wCACZ;EACD,MAAM,SAAS,gBAAgB;EAE/B,MAAM,EAAC,QAAQ,iBAAiB,aAAY,MAAM,OAAO,MAAM,OAAO,QAAQ;GAC5E,gBAAgB;GAChB,aAAa;GACb;GACA;GACA;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACL,OAAO,gBAAgB,cAAc,gBAAgB,eAAe;GACrE,CAAC;EACF,MAAM,OAAO,CACX,GAAG,iBACH,IAAI,YAAY,EAAE,EAAE,KACjB,QACC,GAAG,gBAAgB,cAAc,4BAA4B,wBAAwB,MACxF,CACF;AAID,WAAS,GAAG,KAAK;AAKjB,YAAU,EAAC,YAAW,CAAC;AAEvB,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM;GAAK;;CAGjE,MAAM,OAA8C,SAASC,OAAK,OAAO;EACvE,MAAM,EACJ,cAAc,aACd,WAAW,iBACX,0BAA0B,gCAC1B,sBAAsB,yBACtB,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,OACrB,aAAa,qCACb,SACA,UACA,qBACE;EAEJ,MAAM,gBAAgB,OAAO,iBAAiB,YAAY,gBAAgB;EAE1E,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EAGjB,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAAC,UAAA,EAAA,UACC,oBAACC,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,gBAAgB,eAAe,KAAA;IACvC;GACY;GACb,aAAa;GACb,4BAA4B;GAC5B,2BAA2B;GACf;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB,EAAA,CACO;;AAGf,MAAK,cAAc;AAEnB,QAAO;EACL,aAAa;EACb,YAAY;EACb"}
1
+ {"version":3,"file":"index.js","names":["fetch","Live","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, LiveOptions} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionLiveEvent, actionLiveEventIncludingDrafts} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {Suspense} from 'react'\nimport {preconnect} from 'react-dom'\n\nimport type {DefinedSanityFetchType, DefinedSanityLiveProps} from '../react-server/defineLive'\n\nexport function defineLive(config: LiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n} {\n const {client: _client, serverToken, browserToken} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: true})\n const {token: originalToken} = client.config()\n\n const fetch: DefinedFetchType = async function fetch({\n query,\n params = {},\n perspective = 'published',\n stega = false,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n const useCdn = perspective === 'published'\n\n const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [\n ...customCacheTags,\n ...(syncTags || []).map(\n (tag) =>\n `${perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`,\n ),\n ]\n /**\n * The tags used here, are expired later on in the `expireTags` Server Action with the `expireTag` function from `next/cache`\n */\n cacheTag(...tags)\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short,\n * userland can still set a shorter revalidate time by calling `cacheLife` themselves.\n */\n cacheLife({revalidate})\n\n return {data: result, sourceMap: resultSourceMap || null, tags}\n }\n\n const Live: React.ComponentType<DefinedLiveProps> = function Live(props) {\n const {\n perspective = 'published',\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n onError,\n onGoAway,\n intervalOnGoAway,\n } = props\n\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <Suspense>\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={perspective}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n </Suspense>\n )\n }\n Live.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch: fetch,\n SanityLive: Live,\n }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,WAAW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SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EAGjB,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAAC,UAAA,EAAA,UACC,oBAACC,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,gBAAgB,eAAe,KAAA;IACvC;GACY;GACb,aAAa;GACb,4BAA4B;GAChB;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB,EAAA,CACO;;AAGf,MAAK,cAAc;AAEnB,QAAO;EACL,aAAa;EACb,YAAY;EACb"}
@@ -5,7 +5,7 @@ import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
5
5
  import { cookies, draftMode } from "next/headers";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  import { SanityLive } from "next-sanity/live/client-components";
8
- import { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective } from "next-sanity/live/server-actions";
8
+ import { actionLiveEvent, actionLiveEventIncludingDrafts } from "next-sanity/live/server-actions";
9
9
  import { preconnect } from "react-dom";
10
10
  function defineLive(config) {
11
11
  const { client: _client, serverToken, browserToken, fetchOptions, stega: stegaEnabled = true } = config;
@@ -57,7 +57,7 @@ function defineLive(config) {
57
57
  };
58
58
  };
59
59
  const SanityLive$1 = async function SanityLive$2(props) {
60
- const { onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, onStudioPerspective = actionStudioPerspective, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live", onError, onGoAway, intervalOnGoAway, perspective: _perspective } = props;
60
+ const { onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live", onError, onGoAway, intervalOnGoAway, perspective: _perspective } = props;
61
61
  const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
62
62
  const perspective = _perspective ?? await resolveCookiePerspective();
63
63
  const includeDrafts = typeof browserToken === "string" && perspective !== "published";
@@ -76,7 +76,6 @@ function defineLive(config) {
76
76
  perspective: await resolveCookiePerspective(),
77
77
  onLiveEvent: onChange,
78
78
  onLiveEventIncludingDrafts: onChangeIncludingDrafts,
79
- onPresentationPerspective: onStudioPerspective,
80
79
  requestTag,
81
80
  refreshOnMount,
82
81
  refreshOnFocus,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["sanityFetch","tag","SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, PerspectiveType} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n type SanityClient,\n} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {\n actionStudioPerspective,\n actionLiveEvent,\n actionLiveEventIncludingDrafts,\n} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefinedSanityLiveProps extends DefinedLiveProps {\n /**\n * @defaultValue `automatically resolved`\n */\n perspective?: PerspectiveType\n}\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedSanityLiveProps> = async function SanityLive(props) {\n const {\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n onStudioPerspective = actionStudioPerspective,\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n onError,\n onGoAway,\n intervalOnGoAway,\n perspective: _perspective,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={await resolveCookiePerspective()}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n onPresentationPerspective={onStudioPerspective}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n\nasync function resolveCookiePerspective(): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : 'published'\n}\n"],"mappings":";;;;;;;;;AA4FA,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAA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AY,KAAA;GAChC,KAAK;GACN,CAAC;AACF,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMC,eAA0D,eAAeA,aAAW,OAAO;EAC/F,MAAM,EACJ,WAAW,iBACX,0BAA0B,gCAC1B,sBAAsB,yBACtB,gBACA,gBACA,oBACA,aAAa,oBACb,SACA,UACA,kBACA,aAAa,iBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,gBAAgB,OAAO,iBAAiB,YAAY,gBAAgB;EAG1E,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAACC,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,gBAAgB,eAAe,KAAA;IACvC;GACD,aAAa,MAAM,0BAA0B;GAC7C,aAAa;GACb,4BAA4B;GAC5B,2BAA2B;GACf;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
1
+ {"version":3,"file":"index.js","names":["sanityFetch","tag","SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, PerspectiveType} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n type SanityClient,\n} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionLiveEvent, actionLiveEventIncludingDrafts} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefinedSanityLiveProps extends DefinedLiveProps {\n /**\n * @defaultValue `automatically resolved`\n */\n perspective?: PerspectiveType\n}\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedSanityLiveProps> = async function SanityLive(props) {\n const {\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n onError,\n onGoAway,\n intervalOnGoAway,\n perspective: _perspective,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={await resolveCookiePerspective()}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n\nasync function resolveCookiePerspective(): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : 'published'\n}\n"],"mappings":";;;;;;;;;AAwFA,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAM,CAAC;CAC3E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;CAC9C,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;CAEpE,MAAM,cAAsC,eAAeA,cAEzD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,CAAC,SAAS,EACjB,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;EACD,MAAM,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;EACjF,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,SAAS,gBAAgB;EAC/B,MAAM,aACJ,cAAc,eAAe,KAAA,IACzB,aAAa,aACb,QAAQ,IAAI,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AA4B;GAChB;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
@@ -1,8 +1,3 @@
1
- import { ClientPerspective } from "@sanity/client";
2
- /**
3
- * Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`
4
- */
5
- declare function actionStudioPerspective(perspective: ClientPerspective): Promise<void>;
6
1
  /**
7
2
  * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`
8
3
  */
@@ -11,5 +6,5 @@ declare function actionLiveEvent(_tags: unknown): Promise<void>;
11
6
  * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`
12
7
  */
13
8
  declare function actionLiveEventIncludingDrafts(_tags: unknown): Promise<void>;
14
- export { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective };
9
+ export { actionLiveEvent, actionLiveEventIncludingDrafts };
15
10
  //# sourceMappingURL=index.default.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":[],"mappings":";;AAcA;AAkCA;AAyBsB,iBA3DA,uBAAA,CA2DA,WAAgD,EA3DX,iBA2DW,CAAA,EA3DS,OA2DT,CAAA,IAAA,CAAA;;;;iBAzBhD,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,kBAAgD"}
1
+ {"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":[],"mappings":"AAQA;AAyBA;;iBAzBsB,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,kBAAgD"}
@@ -1,26 +1,6 @@
1
1
  "use server";
2
2
  import { n as PUBLISHED_SYNC_TAG_PREFIX, t as DRAFT_SYNC_TAG_PREFIX } from "../../constants.js";
3
- import { t as sanitizePerspective } from "../../sanitizePerspective.js";
4
- import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
5
- import { cookies, draftMode } from "next/headers";
6
- import { refresh, revalidateTag, updateTag } from "next/cache";
7
- async function actionStudioPerspective(perspective) {
8
- const { isEnabled } = await draftMode();
9
- if (!isEnabled) {
10
- console.warn("Draft mode is not enabled, skipping actionStudioPerspective");
11
- return;
12
- }
13
- const jar = await cookies();
14
- const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
15
- if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
16
- jar.set(perspectiveCookieName, Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective, {
17
- httpOnly: true,
18
- path: "/",
19
- secure: true,
20
- sameSite: "none"
21
- });
22
- refresh();
23
- }
3
+ import { revalidateTag, updateTag } from "next/cache";
24
4
  async function actionLiveEvent(_tags) {
25
5
  if (!Array.isArray(_tags)) {
26
6
  console.warn("<SanityLive /> `expireTags` called with non-array tags", _tags);
@@ -50,6 +30,6 @@ async function actionLiveEventIncludingDrafts(_tags) {
50
30
  for (const tag of tags) updateTag(tag);
51
31
  console.log(`<SanityLive /> updated tags: ${tags.join(", ")}`);
52
32
  }
53
- export { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective };
33
+ export { actionLiveEvent, actionLiveEventIncludingDrafts };
54
34
 
55
35
  //# sourceMappingURL=index.default.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\n\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh, revalidateTag, updateTag} from 'next/cache'\nimport {cookies, draftMode} from 'next/headers'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '../shared/constants'\nimport {sanitizePerspective} from '../shared/sanitizePerspective'\n\n/**\n * Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`\n */\nexport async function actionStudioPerspective(perspective: ClientPerspective): Promise<void> {\n const {isEnabled} = await draftMode()\n if (!isEnabled) {\n console.warn('Draft mode is not enabled, skipping actionStudioPerspective')\n return\n }\n\n const jar = await cookies()\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n // @TODO check if the cookie is already set, before setting it and then calling refresh()\n jar.set(\n perspectiveCookieName,\n Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(',') : sanitizedPerspective,\n {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n },\n )\n\n refresh()\n}\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n\n revalidateTag('sanity:fetch-sync-tags', 'max')\n\n for (const tag of tags) {\n revalidateTag(tag, {expire: 0})\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> revalidated tag: ${tag}`)\n }\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(_tags: unknown): Promise<void> {\n // @TODO check draft mode before expiring tags\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;;;;AAcA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,EAAC,cAAa,MAAM,WAAW;AACrC,KAAI,CAAC,WAAW;AACd,UAAQ,KAAK,8DAA8D;AAC3E;;CAGF,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;AAI9D,KAAI,IACF,uBACA,MAAM,QAAQ,qBAAqB,GAAG,qBAAqB,KAAK,IAAI,GAAG,sBACvE;EACE,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CACF;AAED,UAAS;;AAMX,eAAsB,gBAAgB,OAA+B;AACnE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAGF,eAAc,0BAA0B,MAAM;AAE9C,MAAK,MAAM,OAAO,MAAM;AACtB,gBAAc,KAAK,EAAC,QAAQ,GAAE,CAAC;AAE/B,UAAQ,IAAI,mCAAmC,MAAM;;;AAOzD,eAAsB,+BAA+B,OAA+B;AAElF,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
1
+ {"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {revalidateTag, updateTag} from 'next/cache'\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n\n revalidateTag('sanity:fetch-sync-tags', 'max')\n\n for (const tag of tags) {\n revalidateTag(tag, {expire: 0})\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> revalidated tag: ${tag}`)\n }\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(_tags: unknown): Promise<void> {\n // @TODO check draft mode before expiring tags\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;AAQA,eAAsB,gBAAgB,OAA+B;AACnE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAGF,eAAc,0BAA0B,MAAM;AAE9C,MAAK,MAAM,OAAO,MAAM;AACtB,gBAAc,KAAK,EAAC,QAAQ,GAAE,CAAC;AAE/B,UAAQ,IAAI,mCAAmC,MAAM;;;AAOzD,eAAsB,+BAA+B,OAA+B;AAElF,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
@@ -1,8 +1,3 @@
1
- import { ClientPerspective } from "@sanity/client";
2
- /**
3
- * Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`
4
- */
5
- declare function actionStudioPerspective(perspective: ClientPerspective): Promise<void>;
6
1
  /**
7
2
  * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`
8
3
  */
@@ -11,5 +6,5 @@ declare function actionLiveEvent(_tags: unknown): Promise<void>;
11
6
  * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`
12
7
  */
13
8
  declare function actionLiveEventIncludingDrafts(tags: unknown): Promise<void>;
14
- export { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective };
9
+ export { actionLiveEvent, actionLiveEventIncludingDrafts };
15
10
  //# sourceMappingURL=index.next-js.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":[],"mappings":";;AAaA;AA4BA;AAyBsB,iBArDA,uBAAA,CAqD+C,WAAA,EArDV,iBAqDU,CAAA,EArDU,OAqDV,CAAA,IAAA,CAAA;;;;iBAzB/C,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,iBAA+C"}
1
+ {"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":[],"mappings":"AASA;AAyBA;;iBAzBsB,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,iBAA+C"}
@@ -1,21 +1,7 @@
1
1
  "use server";
2
2
  import { n as PUBLISHED_SYNC_TAG_PREFIX, t as DRAFT_SYNC_TAG_PREFIX } from "../../constants.js";
3
- import { t as sanitizePerspective } from "../../sanitizePerspective.js";
4
- import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
5
- import { cookies, draftMode } from "next/headers";
3
+ import { draftMode } from "next/headers";
6
4
  import { refresh, updateTag } from "next/cache";
7
- async function actionStudioPerspective(perspective) {
8
- const jar = await cookies();
9
- const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
10
- if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
11
- jar.set(perspectiveCookieName, Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective, {
12
- httpOnly: true,
13
- path: "/",
14
- secure: true,
15
- sameSite: "none"
16
- });
17
- refresh();
18
- }
19
5
  async function actionLiveEvent(_tags) {
20
6
  if (!Array.isArray(_tags)) {
21
7
  console.warn("<SanityLive /> `expireTags` called with non-array tags", _tags);
@@ -47,6 +33,6 @@ async function expireDraftTags(_tags) {
47
33
  for (const tag of tags) updateTag(tag);
48
34
  console.log(`<SanityLive /> updated tags: ${tags.join(", ")}`);
49
35
  }
50
- export { actionLiveEvent, actionLiveEventIncludingDrafts, actionStudioPerspective };
36
+ export { actionLiveEvent, actionLiveEventIncludingDrafts };
51
37
 
52
38
  //# sourceMappingURL=index.next-js.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh, updateTag} from 'next/cache'\nimport {cookies, draftMode} from 'next/headers'\n\n/**\n * Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`\n */\nexport async function actionStudioPerspective(perspective: ClientPerspective): Promise<void> {\n const jar = await cookies()\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n // @TODO check if the cookie is already set, before setting it and then calling refresh()\n jar.set(\n perspectiveCookieName,\n Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(',') : sanitizedPerspective,\n {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n },\n )\n\n refresh()\n}\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n // @TODO Draft Mode bypasses cache anyway so we don't bother with expiring tags for draft content\n // const isDraftMode = (await draftMode()).isEnabled\n // const tags = _tags.map((tag) => `${isDraftMode ? 'drafts' : 'sanity'}:${tag}`)\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(tags: unknown): Promise<void> {\n const {isEnabled} = await draftMode()\n if (isEnabled) {\n // With cache components just refresh by default when in draft mode and assume bypass\n refresh()\n } else {\n return expireDraftTags(tags)\n }\n}\n\nasync function expireDraftTags(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;;;;AAaA,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;AAI9D,KAAI,IACF,uBACA,MAAM,QAAQ,qBAAqB,GAAG,qBAAqB,KAAK,IAAI,GAAG,sBACvE;EACE,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CACF;AAED,UAAS;;AAMX,eAAsB,gBAAgB,OAA+B;AAInE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG;;AAMhE,eAAsB,+BAA+B,MAA8B;CACjF,MAAM,EAAC,cAAa,MAAM,WAAW;AACrC,KAAI,UAEF,UAAS;KAET,QAAO,gBAAgB,KAAK;;AAIhC,eAAe,gBAAgB,OAA+B;AAC5D,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
1
+ {"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {refresh, updateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n // @TODO Draft Mode bypasses cache anyway so we don't bother with expiring tags for draft content\n // const isDraftMode = (await draftMode()).isEnabled\n // const tags = _tags.map((tag) => `${isDraftMode ? 'drafts' : 'sanity'}:${tag}`)\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(tags: unknown): Promise<void> {\n const {isEnabled} = await draftMode()\n if (isEnabled) {\n // With cache components just refresh by default when in draft mode and assume bypass\n refresh()\n } else {\n return expireDraftTags(tags)\n }\n}\n\nasync function expireDraftTags(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;;AASA,eAAsB,gBAAgB,OAA+B;AAInE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG;;AAMhE,eAAsB,+BAA+B,MAA8B;CACjF,MAAM,EAAC,cAAa,MAAM,WAAW;AACrC,KAAI,UAEF,UAAS;KAET,QAAO,gBAAgB,KAAK;;AAIhC,eAAe,gBAAgB,OAA+B;AAC5D,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
@@ -24,6 +24,6 @@ interface VisualEditingProps extends Omit<VisualEditingOptions, "history"> {
24
24
  */
25
25
  trailingSlash?: boolean;
26
26
  }
27
- declare function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode;
28
- export { type VisualEditingProps, VisualEditingLazyClientComponent as default };
27
+ declare const VisualEditing: React.ComponentType<VisualEditingProps>;
28
+ export { VisualEditing, type VisualEditingProps };
29
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":[],"mappings":";;AAgBA;;ACFgB,UDEC,kBAAA,SAA2B,ICF5B,CDEiC,oBCFO,EAAqB,SAAM,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;iBAAnE,gCAAA,QAAwC,qBAAqB,KAAA,CAAM"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/index.ts"],"sourcesContent":[],"mappings":";;AAgBA;;ACVa,UDUI,kBAAA,SAA2B,ICVI,CDUC,oBCVf,EAAA,SAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;cAArB,eAAe,KAAA,CAAM,cAAc"}
@@ -1,13 +1,6 @@
1
1
  "use client";
2
- import { Suspense, lazy } from "react";
3
- import { jsx } from "react/jsx-runtime";
4
- const VisualEditingClientComponent = lazy(() => import("../../VisualEditing.js"));
5
- function VisualEditingLazyClientComponent(props) {
6
- return /* @__PURE__ */ jsx(Suspense, {
7
- fallback: null,
8
- children: /* @__PURE__ */ jsx(VisualEditingClientComponent, { ...props })
9
- });
10
- }
11
- export { VisualEditingLazyClientComponent as default };
2
+ import dynamic from "next/dynamic";
3
+ const VisualEditing = dynamic(() => import("../../VisualEditing.js"), { ssr: false });
4
+ export { VisualEditing };
12
5
 
13
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"mappings":";;;AAYA,MAAM,+BAA+B,WAAW,OAAO,0BAAmB;AAE1E,SAAgB,iCAAiC,OAA4C;AAC3F,QACE,oBAAC,UAAA;EAAS,UAAU;YAClB,oBAAC,8BAAA,EAA6B,GAAI,OAAA,CAAS;GAClC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/client-component/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nexport const VisualEditing: React.ComponentType<VisualEditingProps> = dynamic(\n () => import('./VisualEditing'),\n {ssr: false},\n)\nexport type {VisualEditingProps}\n"],"mappings":";;AAMA,MAAa,gBAAyD,cAC9D,OAAO,2BACb,EAAC,KAAK,OAAM,CACb"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":[],"mappings":";;AAOA;;iBAAgB,aAAA,QAAqB,uBAAqB,KAAA,CAAM"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":[],"mappings":";;AAQA;;iBAAgB,aAAA,QAAqB,uBAAqB,KAAA,CAAM"}
@@ -1,5 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import VisualEditingComponent from "next-sanity/visual-editing/client-component";
2
+ import { VisualEditing as VisualEditing$1 } from "next-sanity/visual-editing/client-component";
3
+ import { actionPerspectiveChange } from "next-sanity/visual-editing/server-actions";
3
4
  function VisualEditing(props) {
4
5
  let autoBasePath;
5
6
  if (typeof props.basePath !== "string") try {
@@ -15,7 +16,8 @@ function VisualEditing(props) {
15
16
  } catch (err) {
16
17
  console.error("Failed detecting trailingSlash", err);
17
18
  }
18
- return /* @__PURE__ */ jsx(VisualEditingComponent, {
19
+ return /* @__PURE__ */ jsx(VisualEditing$1, {
20
+ onPerspectiveChange: actionPerspectiveChange,
19
21
  ...props,
20
22
  basePath: props.basePath ?? autoBasePath,
21
23
  trailingSlash: props.trailingSlash ?? autoTrailingSlash
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;AAOA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAAC,wBAAA;EACC,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;GACtC"}
1
+ {"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {actionPerspectiveChange} from 'next-sanity/visual-editing/server-actions'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n onPerspectiveChange={actionPerspectiveChange}\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;;AAQA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAACA,iBAAAA;EACC,qBAAqB;EACrB,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;GACtC"}
@@ -1,3 +1,12 @@
1
- declare function revalidateRootLayout(): Promise<void>;
2
- export { revalidateRootLayout };
1
+ import { HistoryRefresh } from "@sanity/visual-editing/react";
2
+ import { ClientPerspective } from "@sanity/client";
3
+ /**
4
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
5
+ */
6
+ declare function actionRefresh(_payload: HistoryRefresh): Promise<void>;
7
+ /**
8
+ * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
9
+ */
10
+ declare function actionPerspectiveChange(perspective: ClientPerspective): Promise<void>;
11
+ export { actionPerspectiveChange, actionRefresh };
3
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":[],"mappings":"AAIsB,iBAAA,oBAAA,CAAA,CAAwB,EAAA,OAAA,CAAA,IAAA,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":[],"mappings":";;;AAaA;AAOA;iBAPsB,aAAA,WAAwB,iBAAiB;;;;iBAOzC,uBAAA,cAAqC,oBAAoB"}
@@ -1,13 +1,28 @@
1
1
  "use server";
2
- import { draftMode } from "next/headers";
3
- import { revalidatePath } from "next/cache";
4
- async function revalidateRootLayout() {
5
- if (!(await draftMode()).isEnabled) {
6
- console.warn("Skipped revalidatePath request because draft mode is not enabled");
2
+ import { t as sanitizePerspective } from "../../sanitizePerspective.js";
3
+ import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
4
+ import { cookies } from "next/headers";
5
+ import { refresh } from "next/cache";
6
+ async function actionRefresh(_payload) {
7
+ refresh();
8
+ }
9
+ async function actionPerspectiveChange(perspective) {
10
+ const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
11
+ if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
12
+ const nextPerspective = Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective;
13
+ const jar = await cookies();
14
+ if (nextPerspective === jar.get(perspectiveCookieName)?.value) {
15
+ console.debug("Perspective is the same, skipping", nextPerspective);
7
16
  return;
8
17
  }
9
- revalidatePath("/", "layout");
18
+ jar.set(perspectiveCookieName, nextPerspective, {
19
+ httpOnly: true,
20
+ path: "/",
21
+ secure: true,
22
+ sameSite: "none"
23
+ });
24
+ refresh();
10
25
  }
11
- export { revalidateRootLayout };
26
+ export { actionPerspectiveChange, actionRefresh };
12
27
 
13
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n revalidatePath('/', 'layout')\n}\n"],"mappings":";;;AAIA,eAAsB,uBAAsC;AAC1D,KAAI,EAAE,MAAM,WAAW,EAAE,WAAW;AAClC,UAAQ,KAAK,mEAAmE;AAChF;;AAEF,gBAAe,KAAK,SAAS"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport type {HistoryRefresh} from '@sanity/visual-editing/react'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function actionRefresh(_payload: HistoryRefresh): Promise<void> {\n refresh()\n}\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function actionPerspectiveChange(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (nextPerspective === jar.get(perspectiveCookieName)?.value) {\n // oxlint-disable-next-line no-console\n console.debug('Perspective is the same, skipping', nextPerspective)\n return\n }\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;AAaA,eAAsB,cAAc,UAAyC;AAC3E,UAAS;;AAMX,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;CAG9D,MAAM,kBAAkB,MAAM,QAAQ,qBAAqB,GACvD,qBAAqB,KAAK,IAAI,GAC9B;CACJ,MAAM,MAAM,MAAM,SAAS;AAC3B,KAAI,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,OAAO;AAE7D,UAAQ,MAAM,qCAAqC,gBAAgB;AACnE;;AAEF,KAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CAAC;AAEF,UAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-sanity",
3
- "version": "13.0.0-cache-components.16",
3
+ "version": "13.0.0-cache-components.18",
4
4
  "description": "Sanity.io toolkit for Next.js",
5
5
  "keywords": [
6
6
  "live",
@@ -29,6 +29,11 @@
29
29
  "sideEffects": false,
30
30
  "types": "./dist/index.d.ts",
31
31
  "imports": {
32
+ "#env": {
33
+ "next-js": "./src/_env/next-js.ts",
34
+ "react-server": "./src/_env/react-server.ts",
35
+ "default": "./src/_env/default.ts"
36
+ },
32
37
  "#live/*": "./src/live/shared/*.ts"
33
38
  },
34
39
  "exports": {
@@ -61,34 +66,38 @@
61
66
  "@sanity/comlink": "^4.0.1",
62
67
  "@sanity/presentation-comlink": "^2.0.1",
63
68
  "@sanity/preview-url-secret": "^4.0.2",
64
- "@sanity/visual-editing": "^5.0.4",
69
+ "@sanity/visual-editing": "^5.1.0",
65
70
  "dequal": "^2.0.3",
66
- "groq": "^5.2.0",
71
+ "groq": "^5.3.0",
67
72
  "history": "^5.3.0"
68
73
  },
69
74
  "devDependencies": {
70
75
  "@sanity/browserslist-config": "^1.0.5",
71
76
  "@sanity/tsconfig": "^2.1.0",
72
77
  "@sanity/webhook": "4.0.4",
73
- "@types/node": "^24.10.7",
78
+ "@types/js-yaml": "^4.0.9",
79
+ "@types/node": "^24.10.8",
74
80
  "@types/react": "^19.2.8",
75
81
  "@types/react-dom": "^19.2.3",
82
+ "@vitejs/plugin-react": "^5.1.2",
76
83
  "@vitest/coverage-v8": "^4.0.17",
84
+ "js-yaml": "^4.1.1",
77
85
  "next": "16.1.1-canary.24",
78
86
  "publint": "^0.3.16",
79
87
  "react": "^19.2.3",
80
88
  "react-dom": "^19.2.3",
81
- "styled-components": "^6.2.0",
89
+ "styled-components": "^6.3.1",
82
90
  "tsdown": "0.19.0",
83
91
  "typescript": "5.9.3",
84
- "vitest": "^4.0.17"
92
+ "vitest": "^4.0.17",
93
+ "vitest-package-exports": "^1.1.2"
85
94
  },
86
95
  "peerDependencies": {
87
96
  "@sanity/client": "^7.14.0",
88
97
  "next": "^16.0.0-0",
89
98
  "react": "^19.2.3",
90
99
  "react-dom": "^19.2.3",
91
- "sanity": "^5.2.0",
100
+ "sanity": "^5.3.0",
92
101
  "styled-components": "^6.1"
93
102
  },
94
103
  "browserslist": "extends @sanity/browserslist-config",