next-sanity 13.0.0-cache-components.13 → 13.0.0-cache-components.15

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 (61) hide show
  1. package/dist/PresentationComlink.js +3 -3
  2. package/dist/PresentationComlink.js.map +1 -1
  3. package/dist/RefreshOnFocus.js.map +1 -1
  4. package/dist/RefreshOnMount.js +2 -2
  5. package/dist/RefreshOnMount.js.map +1 -1
  6. package/dist/RefreshOnReconnect.js.map +1 -1
  7. package/dist/{live/client-components/live/index.js → SanityLive.js} +23 -46
  8. package/dist/SanityLive.js.map +1 -0
  9. package/dist/constants.js.map +1 -1
  10. package/dist/context.js.map +1 -1
  11. package/dist/defineLive.d.ts +5 -50
  12. package/dist/defineLive.d.ts.map +1 -1
  13. package/dist/hooks/index.d.ts +1 -1
  14. package/dist/hooks/index.d.ts.map +1 -1
  15. package/dist/hooks/index.js.map +1 -1
  16. package/dist/isCorsOriginError.d.ts.map +1 -1
  17. package/dist/isCorsOriginError.js.map +1 -1
  18. package/dist/{experimental/client-components/live.d.ts → live/client-components/index.d.ts} +12 -11
  19. package/dist/live/client-components/index.d.ts.map +1 -0
  20. package/dist/live/client-components/index.js +6 -0
  21. package/dist/live/client-components/index.js.map +1 -0
  22. package/dist/{live.d.ts → live/conditions/default/index.d.ts} +3 -3
  23. package/dist/live/conditions/default/index.d.ts.map +1 -0
  24. package/dist/{live.js → live/conditions/default/index.js} +2 -2
  25. package/dist/live/conditions/default/index.js.map +1 -0
  26. package/dist/live/conditions/next-js/index.d.ts +8 -0
  27. package/dist/live/conditions/next-js/index.d.ts.map +1 -0
  28. package/dist/live/conditions/next-js/index.js +78 -0
  29. package/dist/live/conditions/next-js/index.js.map +1 -0
  30. package/dist/live/conditions/react-server/index.d.ts +3 -0
  31. package/dist/live/conditions/react-server/index.js +100 -0
  32. package/dist/live/conditions/react-server/index.js.map +1 -0
  33. package/dist/live/server-actions/index.default.d.ts +15 -0
  34. package/dist/live/server-actions/index.default.d.ts.map +1 -0
  35. package/dist/live/server-actions/{index.js → index.default.js} +26 -13
  36. package/dist/live/server-actions/index.default.js.map +1 -0
  37. package/dist/live/server-actions/index.next-js.d.ts +15 -0
  38. package/dist/live/server-actions/index.next-js.d.ts.map +1 -0
  39. package/dist/live/server-actions/index.next-js.js +52 -0
  40. package/dist/live/server-actions/index.next-js.js.map +1 -0
  41. package/dist/resolvePerspectiveFromCookies.js.map +1 -1
  42. package/dist/sanitizePerspective.js.map +1 -1
  43. package/package.json +18 -17
  44. package/dist/experimental/client-components/live.d.ts.map +0 -1
  45. package/dist/experimental/client-components/live.js +0 -179
  46. package/dist/experimental/client-components/live.js.map +0 -1
  47. package/dist/live/client-components/live/index.d.ts +0 -26
  48. package/dist/live/client-components/live/index.d.ts.map +0 -1
  49. package/dist/live/client-components/live/index.js.map +0 -1
  50. package/dist/live/server-actions/index.d.ts +0 -6
  51. package/dist/live/server-actions/index.d.ts.map +0 -1
  52. package/dist/live/server-actions/index.js.map +0 -1
  53. package/dist/live.d.ts.map +0 -1
  54. package/dist/live.js.map +0 -1
  55. package/dist/live.next-js.d.ts +0 -16
  56. package/dist/live.next-js.d.ts.map +0 -1
  57. package/dist/live.next-js.js +0 -87
  58. package/dist/live.next-js.js.map +0 -1
  59. package/dist/live.react-server.d.ts +0 -3
  60. package/dist/live.react-server.js +0 -94
  61. package/dist/live.react-server.js.map +0 -1
@@ -1,11 +1,10 @@
1
1
  import { f as setPerspective, l as setComlink, u as setComlinkClientConfig } from "./context.js";
2
2
  import { t as sanitizePerspective } from "./sanitizePerspective.js";
3
3
  import { startTransition, useEffect, useEffectEvent } from "react";
4
- import { createCompatibilityActors } from "@sanity/presentation-comlink";
5
- import { setPerspectiveCookie } from "next-sanity/live/server-actions";
6
4
  import { createNode, createNodeMachine } from "@sanity/comlink";
5
+ import { createCompatibilityActors } from "@sanity/presentation-comlink";
7
6
  function PresentationComlink(props) {
8
- const { projectId, dataset, onPerspective = setPerspectiveCookie } = props;
7
+ const { projectId, dataset, onPerspective } = props;
9
8
  useEffect(() => {
10
9
  setComlinkClientConfig(projectId, dataset);
11
10
  }, [dataset, projectId]);
@@ -32,6 +31,7 @@ function PresentationComlink(props) {
32
31
  }, []);
33
32
  return null;
34
33
  }
34
+ PresentationComlink.displayName = "PresentationComlink";
35
35
  export { PresentationComlink as default };
36
36
 
37
37
  //# sourceMappingURL=PresentationComlink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationComlink.js","names":[],"sources":["../src/shared/client-components/PresentationComlink.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {\n setComlink,\n setComlinkClientConfig,\n setPerspective,\n} from '#client-components/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 {setPerspectiveCookie} from 'next-sanity/live/server-actions'\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 = setPerspectiveCookie} = props\n\n useEffect(() => {\n setComlinkClientConfig(projectId, dataset)\n }, [dataset, projectId])\n\n const handlePerspectiveChange = useEffectEvent(\n (perspective: ClientPerspective) => {\n // @TODO remove `setPerspective` util and state\n setPerspective(sanitizePerspective(perspective, 'drafts'))\n startTransition(() => onPerspective(perspective))\n },\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"],"mappings":";;;;;;AAiBA,SAAwB,oBAAoB,OAIf;CAC3B,MAAM,EAAC,WAAW,SAAS,gBAAgB,yBAAwB;AAEnE,iBAAgB;AACd,yBAAuB,WAAW,QAAQ;IACzC,CAAC,SAAS,UAAU,CAAC;CAExB,MAAM,0BAA0B,gBAC7B,gBAAmC;AAEhC,iBAAe,oBAAoB,aAAa,SAAS,CAAC;AAC1D,wBAAuB,cAAc,YAAY,CAAC;GAEvD;AAED,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,OAAG,WAAW,OAAO,QAAS;AAE9B,2BAAwB,KAAK,YAAY;IACzC;EAEF,MAAM,OAAO,QAAQ,OAAO;AAC5B,aAAW,QAAQ;AACnB,eAAa;AACX,SAAM;AACN,cAAW,OAAO;;IAEnB,EAAE,CAAC;AAEN,QAAO"}
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 +1 @@
1
- {"version":3,"file":"RefreshOnFocus.js","names":[],"sources":["../src/live/client-components/live/RefreshOnFocus.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation'\nimport {useEffect} from 'react'\n\nconst focusThrottleInterval = 5_000\n\nexport default function RefreshOnFocus(): null {\n const router = useRouter()\n\n useEffect(() => {\n const controller = new AbortController()\n let nextFocusRevalidatedAt = 0\n const callback = () => {\n const now = Date.now()\n if (now > nextFocusRevalidatedAt && document.visibilityState !== 'hidden') {\n router.refresh()\n nextFocusRevalidatedAt = now + focusThrottleInterval\n }\n }\n const {signal} = controller\n document.addEventListener('visibilitychange', callback, {passive: true, signal})\n window.addEventListener('focus', callback, {passive: true, signal})\n return () => controller.abort()\n }, [router])\n\n return null\n}\nRefreshOnFocus.displayName = 'RefreshOnFocus'\n"],"mappings":";;AAGA,MAAM,wBAAwB;AAE9B,SAAwB,iBAAuB;CAC7C,MAAM,SAAS,WAAW;AAE1B,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,IAAI,yBAAyB;EAC7B,MAAM,iBAAiB;GACrB,MAAM,MAAM,KAAK,KAAK;AACtB,OAAI,MAAM,0BAA0B,SAAS,oBAAoB,UAAU;AACzE,WAAO,SAAS;AAChB,6BAAyB,MAAM;;;EAGnC,MAAM,EAAC,WAAU;AACjB,WAAS,iBAAiB,oBAAoB,UAAU;GAAC,SAAS;GAAM;GAAO,CAAC;AAChF,SAAO,iBAAiB,SAAS,UAAU;GAAC,SAAS;GAAM;GAAO,CAAC;AACnE,eAAa,WAAW,OAAO;IAC9B,CAAC,OAAO,CAAC;AAEZ,QAAO;;AAET,eAAe,cAAc"}
1
+ {"version":3,"file":"RefreshOnFocus.js","names":[],"sources":["../src/live/client-components/RefreshOnFocus.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation'\nimport {useEffect} from 'react'\n\nconst focusThrottleInterval = 5_000\n\nexport default function RefreshOnFocus(): null {\n const router = useRouter()\n\n useEffect(() => {\n const controller = new AbortController()\n let nextFocusRevalidatedAt = 0\n const callback = () => {\n const now = Date.now()\n if (now > nextFocusRevalidatedAt && document.visibilityState !== 'hidden') {\n router.refresh()\n nextFocusRevalidatedAt = now + focusThrottleInterval\n }\n }\n const {signal} = controller\n document.addEventListener('visibilitychange', callback, {passive: true, signal})\n window.addEventListener('focus', callback, {passive: true, signal})\n return () => controller.abort()\n }, [router])\n\n return null\n}\nRefreshOnFocus.displayName = 'RefreshOnFocus'\n"],"mappings":";;AAGA,MAAM,wBAAwB;AAE9B,SAAwB,iBAAuB;CAC7C,MAAM,SAAS,WAAW;AAE1B,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,IAAI,yBAAyB;EAC7B,MAAM,iBAAiB;GACrB,MAAM,MAAM,KAAK,KAAK;AACtB,OAAI,MAAM,0BAA0B,SAAS,oBAAoB,UAAU;AACzE,WAAO,SAAS;AAChB,6BAAyB,MAAM;;;EAGnC,MAAM,EAAC,WAAU;AACjB,WAAS,iBAAiB,oBAAoB,UAAU;GAAC,SAAS;GAAM;GAAO,CAAC;AAChF,SAAO,iBAAiB,SAAS,UAAU;GAAC,SAAS;GAAM;GAAO,CAAC;AACnE,eAAa,WAAW,OAAO;IAC9B,CAAC,OAAO,CAAC;AAEZ,QAAO;;AAET,eAAe,cAAc"}
@@ -1,11 +1,11 @@
1
1
  import { useRouter } from "next/navigation";
2
- import { useEffect, useReducer } from "react";
2
+ import { startTransition, useEffect, useReducer } from "react";
3
3
  function RefreshOnMount() {
4
4
  const router = useRouter();
5
5
  const [mounted, mount] = useReducer(() => true, false);
6
6
  useEffect(() => {
7
7
  if (!mounted) {
8
- mount();
8
+ startTransition(() => mount());
9
9
  router.refresh();
10
10
  }
11
11
  }, [mounted, router]);
@@ -1 +1 @@
1
- {"version":3,"file":"RefreshOnMount.js","names":[],"sources":["../src/live/client-components/live/RefreshOnMount.tsx"],"sourcesContent":["/**\n * Handles refreshing the page when the page is mounted,\n * in case the content changes at a high enough frequency that by\n * the time the page started streaming, and the <SanityLive> component sets\n * up the EventSource connection, content might have changed.\n */\n\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useReducer} from 'react'\n\nexport default function RefreshOnMount(): null {\n const router = useRouter()\n const [mounted, mount] = useReducer(() => true, false)\n\n useEffect(() => {\n if (!mounted) {\n mount()\n router.refresh()\n }\n }, [mounted, router])\n\n return null\n}\nRefreshOnMount.displayName = 'RefreshOnMount'\n"],"mappings":";;AAUA,SAAwB,iBAAuB;CAC7C,MAAM,SAAS,WAAW;CAC1B,MAAM,CAAC,SAAS,SAAS,iBAAiB,MAAM,MAAM;AAEtD,iBAAgB;AACd,MAAI,CAAC,SAAS;AACZ,UAAO;AACP,UAAO,SAAS;;IAEjB,CAAC,SAAS,OAAO,CAAC;AAErB,QAAO;;AAET,eAAe,cAAc"}
1
+ {"version":3,"file":"RefreshOnMount.js","names":[],"sources":["../src/live/client-components/RefreshOnMount.tsx"],"sourcesContent":["/**\n * Handles refreshing the page when the page is mounted,\n * in case the content changes at a high enough frequency that by\n * the time the page started streaming, and the <SanityLive> component sets\n * up the EventSource connection, content might have changed.\n */\n\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useReducer, startTransition} from 'react'\n\nexport default function RefreshOnMount(): null {\n const router = useRouter()\n const [mounted, mount] = useReducer(() => true, false)\n\n useEffect(() => {\n if (!mounted) {\n startTransition(() => mount())\n router.refresh()\n }\n }, [mounted, router])\n\n return null\n}\nRefreshOnMount.displayName = 'RefreshOnMount'\n"],"mappings":";;AAUA,SAAwB,iBAAuB;CAC7C,MAAM,SAAS,WAAW;CAC1B,MAAM,CAAC,SAAS,SAAS,iBAAiB,MAAM,MAAM;AAEtD,iBAAgB;AACd,MAAI,CAAC,SAAS;AACZ,yBAAsB,OAAO,CAAC;AAC9B,UAAO,SAAS;;IAEjB,CAAC,SAAS,OAAO,CAAC;AAErB,QAAO;;AAET,eAAe,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"RefreshOnReconnect.js","names":[],"sources":["../src/live/client-components/live/RefreshOnReconnect.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation'\nimport {useEffect} from 'react'\n\nexport default function RefreshOnReconnect(): null {\n const router = useRouter()\n\n useEffect(() => {\n const controller = new AbortController()\n const {signal} = controller\n window.addEventListener('online', () => router.refresh(), {passive: true, signal})\n return () => controller.abort()\n }, [router])\n\n return null\n}\nRefreshOnReconnect.displayName = 'RefreshOnReconnect'\n"],"mappings":";;AAGA,SAAwB,qBAA2B;CACjD,MAAM,SAAS,WAAW;AAE1B,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,EAAC,WAAU;AACjB,SAAO,iBAAiB,gBAAgB,OAAO,SAAS,EAAE;GAAC,SAAS;GAAM;GAAO,CAAC;AAClF,eAAa,WAAW,OAAO;IAC9B,CAAC,OAAO,CAAC;AAEZ,QAAO;;AAET,mBAAmB,cAAc"}
1
+ {"version":3,"file":"RefreshOnReconnect.js","names":[],"sources":["../src/live/client-components/RefreshOnReconnect.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation'\nimport {useEffect} from 'react'\n\nexport default function RefreshOnReconnect(): null {\n const router = useRouter()\n\n useEffect(() => {\n const controller = new AbortController()\n const {signal} = controller\n window.addEventListener('online', () => router.refresh(), {passive: true, signal})\n return () => controller.abort()\n }, [router])\n\n return null\n}\nRefreshOnReconnect.displayName = 'RefreshOnReconnect'\n"],"mappings":";;AAGA,SAAwB,qBAA2B;CACjD,MAAM,SAAS,WAAW;AAE1B,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,EAAC,WAAU;AACjB,SAAO,iBAAiB,gBAAgB,OAAO,SAAS,EAAE;GAAC,SAAS;GAAM;GAAO,CAAC;AAClF,eAAa,WAAW,OAAO;IAC9B,CAAC,OAAO,CAAC;AAEZ,QAAO;;AAET,mBAAmB,cAAc"}
@@ -1,17 +1,16 @@
1
- "use client";
2
- import { d as setEnvironment, f as setPerspective } from "../../../context.js";
3
- import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
1
+ import { n as PUBLISHED_SYNC_TAG_PREFIX } from "./constants.js";
2
+ import { d as setEnvironment } from "./context.js";
3
+ import { t as isCorsOriginError } from "./isCorsOriginError.js";
4
4
  import { useRouter } from "next/navigation";
5
- import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
5
+ import { useEffect, useEffectEvent, useMemo, useState } from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { createClient } from "@sanity/client";
8
- import { isMaybePresentation, isMaybePreviewWindow } from "@sanity/presentation-comlink";
9
- import { revalidateSyncTags } from "next-sanity/live/server-actions";
10
8
  import dynamic from "next/dynamic";
11
- const PresentationComlink = dynamic(() => import("../../../PresentationComlink.js"), { ssr: false });
12
- const RefreshOnMount = dynamic(() => import("../../../RefreshOnMount.js"), { ssr: false });
13
- const RefreshOnFocus = dynamic(() => import("../../../RefreshOnFocus.js"), { ssr: false });
14
- const RefreshOnReconnect = dynamic(() => import("../../../RefreshOnReconnect.js"), { ssr: false });
9
+ import { isMaybePresentation, isMaybePreviewWindow } from "@sanity/presentation-comlink";
10
+ const PresentationComlink = dynamic(() => import("./PresentationComlink.js"), { ssr: false });
11
+ const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"), { ssr: false });
12
+ const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"), { ssr: false });
13
+ const RefreshOnReconnect = dynamic(() => import("./RefreshOnReconnect.js"), { ssr: false });
15
14
  function handleError(error) {
16
15
  if (isCorsOriginError(error)) console.warn(`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.`, error.addOriginUrl && `Add it here:`, error.addOriginUrl?.toString());
17
16
  else console.error(error);
@@ -21,7 +20,8 @@ function handleOnGoAway(event, intervalOnGoAway) {
21
20
  else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
22
21
  }
23
22
  function SanityLive(props) {
24
- const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix, draftModeEnabled, draftModePerspective, refreshOnMount = false, refreshOnFocus = draftModeEnabled ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true, intervalOnGoAway = 3e4, requestTag = "next-loader.live", onError = handleError, onGoAway = handleOnGoAway, revalidateSyncTags: revalidateSyncTags$1 = revalidateSyncTags } = 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;
24
+ const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
25
25
  const client = useMemo(() => createClient({
26
26
  projectId,
27
27
  dataset,
@@ -45,9 +45,9 @@ function SanityLive(props) {
45
45
  const router = useRouter();
46
46
  const handleLiveEvent = useEffectEvent((event) => {
47
47
  if (process.env.NODE_ENV !== "production" && event.type === "welcome") {
48
- console.info("Sanity is live with", token ? "automatic revalidation for draft content changes as well as published content" : draftModeEnabled ? "automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool." : "automatic revalidation of published content");
48
+ console.info("Sanity is live with", token ? "automatic revalidation for draft content changes as well as published content" : perspective === "published" ? "automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool." : "automatic revalidation of published content");
49
49
  setLongPollingInterval(false);
50
- } else if (event.type === "message") revalidateSyncTags$1(event.tags).then((result) => {
50
+ } else if (event.type === "message") onLiveEvent(event.tags.map((tag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}`)).then((result) => {
51
51
  if (result === "refresh") router.refresh();
52
52
  });
53
53
  else if (event.type === "restart" || event.type === "reconnect") router.refresh();
@@ -73,23 +73,7 @@ function SanityLive(props) {
73
73
  requestTag,
74
74
  token
75
75
  ]);
76
- useEffect(() => {
77
- if (draftModeEnabled && draftModePerspective) setPerspective(draftModePerspective);
78
- else setPerspective("unknown");
79
- }, [draftModeEnabled, draftModePerspective]);
80
76
  const [loadComlink, setLoadComlink] = useState(false);
81
- useEffect(() => {
82
- if (isMaybePresentation()) return;
83
- if (draftModeEnabled && token) {
84
- setEnvironment("live");
85
- return;
86
- }
87
- if (draftModeEnabled) {
88
- setEnvironment("static");
89
- return;
90
- }
91
- setEnvironment("unknown");
92
- }, [draftModeEnabled, token]);
93
77
  useEffect(() => {
94
78
  if (!isMaybePresentation()) return;
95
79
  const controller = new AbortController();
@@ -107,31 +91,24 @@ function SanityLive(props) {
107
91
  controller.abort();
108
92
  };
109
93
  }, []);
110
- const draftModeEnabledWarnRef = useRef(void 0);
111
- useEffect(() => {
112
- if (!draftModeEnabled) return;
113
- clearTimeout(draftModeEnabledWarnRef.current);
114
- return () => {
115
- draftModeEnabledWarnRef.current = setTimeout(() => {
116
- console.warn("Sanity Live: Draft mode was enabled, but is now being disabled");
117
- });
118
- };
119
- }, [draftModeEnabled]);
120
94
  useEffect(() => {
121
95
  if (!longPollingInterval) return;
122
96
  const interval = setInterval(() => router.refresh(), longPollingInterval);
123
97
  return () => clearInterval(interval);
124
98
  }, [longPollingInterval, router]);
125
99
  return /* @__PURE__ */ jsxs(Fragment, { children: [
126
- draftModeEnabled && loadComlink && /* @__PURE__ */ jsx(PresentationComlink, {
100
+ loadComlink && /* @__PURE__ */ jsx(PresentationComlink, {
127
101
  projectId,
128
- dataset
102
+ dataset,
103
+ onPerspective: onPresentationPerspective
129
104
  }),
130
- !draftModeEnabled && refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
131
- !draftModeEnabled && refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
132
- !draftModeEnabled && refreshOnReconnect && /* @__PURE__ */ jsx(RefreshOnReconnect, {})
105
+ refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
106
+ refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
107
+ refreshOnReconnect && /* @__PURE__ */ jsx(RefreshOnReconnect, {})
133
108
  ] });
134
109
  }
135
- export { SanityLive as default };
110
+ SanityLive.displayName = "SanityLiveClientComponent";
111
+ var SanityLive_default = SanityLive;
112
+ export { SanityLive_default as default };
136
113
 
137
- //# sourceMappingURL=index.js.map
114
+ //# sourceMappingURL=SanityLive.js.map
@@ -0,0 +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'), {\n ssr: false,\n})\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'), {ssr: false})\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'), {ssr: false})\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'), {\n ssr: false,\n})\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,6BAA0B,EACzE,KAAK,OACN,CAAC;AACF,MAAM,iBAAiB,cAAc,OAAO,wBAAqB,EAAC,KAAK,OAAM,CAAC;AAC9E,MAAM,iBAAiB,cAAc,OAAO,wBAAqB,EAAC,KAAK,OAAM,CAAC;AAC9E,MAAM,qBAAqB,cAAc,OAAO,4BAAyB,EACvE,KAAK,OACN,CAAC;AAyCF,SAAS,YAAY,OAAgB;AACnC,KAAI,kBAAkB,MAAM,CAC1B,SAAQ,KACN,8EAA8E,OAAO,OAAO,yEAC5F,MAAM,gBAAgB,gBACtB,MAAM,cAAc,UAAU,CAC/B;KAED,SAAQ,MAAM,MAAM;;AAIxB,SAAS,eAAe,OAAwB,kBAAkC;AAChF,KAAI,iBACF,SAAQ,KACN,iFACA,mBAAmB,KACnB,4CACA,MAAM,OACP;KAED,SAAQ,MACN,mGACA,MAAM,OACP;;AAIL,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,aAEA,2BACA,aAEA,iBAAiB,OACjB,iBAAiB,gBAAgB,cAC7B,QACA,OAAO,WAAW,cAChB,OACA,OAAO,SAAS,OAAO,KAC7B,qBAAqB,MACrB,mBAAmB,KACnB,YACA,UAAU,aACV,WAAW,mBACT;CACJ,MAA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ChB,YAAY,QACZ,KAAK,WAAW,qBAChB,UAAU,QACV,KAAK,SAAS,gBACd;AACA,iBAAa,QAAQ;AACrB,mBAAe,sBAAsB,GAAG,wBAAwB,sBAAsB;AACtF,mBAAe,KAAK;AACpB,eAAW,OAAO;;KAGtB,EAAC,QAAQ,WAAW,QAAO,CAC5B;AACD,eAAa;AACX,gBAAa,QAAQ;AACrB,cAAW,OAAO;;IAEnB,EAAE,CAAC;AAKN,iBAAgB;AACd,MAAI,CAAC,oBAAqB;EAC1B,MAAM,WAAW,kBAAkB,OAAO,SAAS,EAAE,oBAAoB;AACzE,eAAa,cAAc,SAAS;IACnC,CAAC,qBAAqB,OAAO,CAAC;AAEjC,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,eACC,oBAAC,qBAAA;GACY;GACF;GACT,eAAe;IACf;EAEH,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc;AAEzB,IAAA,qBAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/shared/live/constants.ts"],"sourcesContent":["/**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\nexport const revalidate = 31_536_000 // 365 days\n\nexport const PUBLISHED_SYNC_TAG_PREFIX = 'sp:'\nexport const DRAFT_SYNC_TAG_PREFIX = 'sd:'\n"],"mappings":"AAGA,MAAa,aAAa;AAE1B,MAAa,4BAA4B;AACzC,MAAa,wBAAwB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/live/shared/constants.ts"],"sourcesContent":["/**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\nexport const revalidate = 31_536_000 // 365 days\n\nexport const PUBLISHED_SYNC_TAG_PREFIX = 'sp:'\nexport const DRAFT_SYNC_TAG_PREFIX = 'sd:'\n"],"mappings":"AAGA,MAAa,aAAa;AAE1B,MAAa,4BAA4B;AACzC,MAAa,wBAAwB"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/shared/client-components/context.tsx"],"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 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,5 +1,5 @@
1
1
  import { cookies } from "next/headers";
2
- import { ClientPerspective, ClientReturn, ContentSourceMap, LiveEventGoAway, QueryParams, SanityClient, SyncTag } from "@sanity/client";
2
+ import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams, SanityClient } from "@sanity/client";
3
3
  import { ClientPerspective as ClientPerspective$1, ClientReturn as ClientReturn$1, ContentSourceMap as ContentSourceMap$1, LiveEventGoAway as LiveEventGoAway$1, QueryParams as QueryParams$1, SanityClient as SanityClient$1 } from "next-sanity";
4
4
  type ResolvePerspectiveFromCookies = (options: {
5
5
  /**
@@ -71,7 +71,7 @@ interface DefinedLiveProps {
71
71
  * which can be read with `resolvePerspectiveFromCookies` and used to ensure data fetching in the preview
72
72
  * matches the perspective and content viewed in the Studio, allowing you to quickly switch and preview different perspectives.
73
73
  */
74
- onStudioPerspective?: (perspective: PerspectiveType) => void;
74
+ onStudioPerspective?: (perspective: ClientPerspective$1) => Promise<void>;
75
75
  /**
76
76
  * Automatic refresh of RSC when the component <SanityLive /> is mounted.
77
77
  * @defaultValue `false`
@@ -169,56 +169,11 @@ type DefinedSanityFetchType = <const QueryString extends string>(options: {
169
169
  /**
170
170
  * @public
171
171
  */
172
- interface DefinedSanityLiveProps {
172
+ interface DefinedSanityLiveProps extends DefinedLiveProps {
173
173
  /**
174
- * Automatic refresh of RSC when the component <SanityLive /> is mounted.
175
- * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.
176
- * @defaultValue `true`
177
- */
178
- refreshOnMount?: boolean;
179
- /**
180
- * Automatically refresh when window gets focused
181
- * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.
182
- * @defaultValue `false` if draftMode().isEnabled, otherwise `true` if not inside an iframe
183
- */
184
- refreshOnFocus?: boolean;
185
- /**
186
- * Automatically refresh when the browser regains a network connection (via navigator.onLine)
187
- * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.
188
- * @defaultValue `true`
189
- */
190
- refreshOnReconnect?: boolean;
191
- /**
192
- * Automatically refresh on an interval when the Live Event API emits a `goaway` event, which indicates that the connection is rejected or closed.
193
- * This typically happens if the connection limit is reached, or if the connection is idle for too long.
194
- * To disable this long polling fallback behavior set `intervalOnGoAway` to `false` or `0`.
195
- * You can also use `onGoAway` to handle the `goaway` event in your own way, and read the reason why the event was emitted.
196
- * @defaultValue `30_000` 30 seconds interval
197
- */
198
- intervalOnGoAway?: number | false;
199
- /**
200
- * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
201
- * @see https://www.sanity.io/docs/reference-api-request-tags
202
- * @defaultValue 'next-loader.live'
203
- */
204
- requestTag?: string;
205
- /**
206
- * Handle errors from the Live Events subscription.
207
- * By default it's reported using `console.error`, you can override this prop to handle it in your own way.
174
+ * @defaultValue `automatically resolved`
208
175
  */
209
- onError?: (error: unknown) => void;
210
- /**
211
- * Handle the `goaway` event if the connection is rejected/closed.
212
- * `event.reason` will be a string of why the event was emitted, for example `'connection limit reached'`.
213
- * When this happens the `<SanityLive />` will fallback to long polling with a default interval of 30 seconds, providing your own `onGoAway` handler does not change this behavior.
214
- * If you want to disable long polling set `intervalOnGoAway` to `false` or `0`.
215
- */
216
- onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
217
- /**
218
- * Override how cache tags are invalidated, you need to pass a server action here.
219
- * You can also pass a `use client` function here, and have `router.refresh()` be called if the promise resolves to `'refresh'`.
220
- */
221
- revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | "refresh">;
176
+ perspective?: PerspectiveType;
222
177
  }
223
178
  /**
224
179
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/shared/live/resolvePerspectiveFromCookies.ts","../src/shared/live/types.ts","../src/live/defineLive.tsx"],"sourcesContent":[],"mappings":";;;KAMY,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,KC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KZ,IAAY,ECqBJ,YDrBI,CCqBS,WDrBT,CAAA;EACH,SAAA,ECqBI,gBDrBJ,GAAA,IAAA;EACE,IAAA,EAAA,MAAA,EAAA;CAIK,CAAA;;;;AAiBV,UCMW,sBAAA,CDNX;EAAA;AAMN;;;;EA+DiC,cAAA,CAAA,EAAA,OAAA;EAOe;;AAGhD;;ACpGA;EACS,cAAA,CAAA,EAAA,OAAA;EACE;;;;;EAiBU,kBAAA,CAAA,EAAA,OAAA;EAAb;;;;AAQR;;;EAqD4C,gBAAA,CAAA,EAAA,MAAA,GAAA,KAAA;EAAA;AAM5C;AAgCA;;;EAQkC,UAAA,CAAA,EAAA,MAAA;EAApB;;;;;;;;;;;qBApDO;;;;;8BAMS,cAAc;;;;;UAM3B,uBAAA;;;;UAIP;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BM,UAAA,SAAmB;;;;eAIpB;;;;cAID,KAAA,CAAM,cAAc"}
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,CA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A;EAIK,IAAA,EAAA,MAAA,EAAA;CAkBK,CAAA;;;;AADf,UCQW,sBAAA,SAA+B,gBDR1C,CAAA;EAMN;;;EAa4D,WAAA,CAAA,ECP5C,eDO4C;;;;;AA4D3C,UC7DA,uBAAA,CDiEP;;ACtGV;;EAEW,MAAA,EAuCD,YAvCC;EAAsB;;;;EAiBZ,WAAA,CAAA,EAAA,MAAA,GAAA,KAAA;EAAb;;;;EAQR,YAAiB,CAAA,EAAA,MAAA,GAAA,KAAA;EAUjB;AAgCA;;EAIe,YAAA,CAAA,EAAA;IAImB;;;;;;;;;;;;iBARlB,UAAA,SAAmB;;;;eAIpB;;;;cAID,KAAA,CAAM,cAAc"}
@@ -1,7 +1,7 @@
1
1
  import { useOptimistic } from "@sanity/visual-editing/react";
2
2
  import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
3
- import "@sanity/presentation-comlink";
4
3
  import "@sanity/comlink";
4
+ import "@sanity/presentation-comlink";
5
5
  type LivePerspective = "checking" | "unknown" | ClientPerspective;
6
6
  type LiveEnvironment = "checking" | "presentation-iframe" | "presentation-window" | "live" | "static" | "unknown";
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shared/client-components/context.tsx","../../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/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 +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 '#client-components/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 '#client-components/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, stega])\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,0BAA2C;AAMzD,QAAO,qBALW,aAAa,aAAyB;AACtD,uBAAqB,IAAI,SAAS;AAClC,eAAa,qBAAqB,OAAO,SAAS;IACjD,EAAE,CAAC,QAIE,mBACA,WACP;;AASH,SAAgB,0BAA2C;AAMzD,QAAO,qBALW,aAAa,aAAyB;AACtD,uBAAqB,IAAI,SAAS;AAClC,eAAa,qBAAqB,OAAO,SAAS;IACjD,EAAE,CAAC,QAIE,mBACA,WACP;;ACrCH,SAAgB,wBAAwC;CACtD,MAAMA,gBAAc,yBAAyB;AAC7C,QAAOA,kBAAgB,aACnB,OACAA,kBAAgB,yBAAyBA,kBAAgB;;ACC/D,SAAgB,mBAAmC;CACjD,MAAMC,gBAAc,yBAAyB;AAC7C,QAAOA,kBAAgB,aACnB,OACAA,kBAAgB,yBACdA,kBAAgB,yBAChBA,kBAAgB;;ACexB,SAAS,QACP,OACA,EAAC,MAAM,WACmC;AAC1C,SAAQ,MAAR;EACE,KAAK,eACH,QAAO,OAAO,OAAO,QAAQ,GACzB,QACA;GACE,GAAG;GACH,MAAM,OAAO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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":["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, stega])\n}\n"],"mappings":";;;;;;AAoBA,SAAgB,0BAA2C;AAMzD,QAAO,qBALW,aAAa,aAAyB;AACtD,uBAAqB,IAAI,SAAS;AAClC,eAAa,qBAAqB,OAAO,SAAS;IACjD,EAAE,CAAC,QAIE,mBACA,WACP;;AASH,SAAgB,0BAA2C;AAMzD,QAAO,qBALW,aAAa,aAAyB;AACtD,uBAAqB,IAAI,SAAS;AAClC,eAAa,qBAAqB,OAAO,SAAS;IACjD,EAAE,CAAC,QAIE,mBACA,WACP;;ACrCH,SAAgB,wBAAwC;CACtD,MAAMA,gBAAc,yBAAyB;AAC7C,QAAOA,kBAAgB,aACnB,OACAA,kBAAgB,yBAAyBA,kBAAgB;;ACC/D,SAAgB,mBAAmC;CACjD,MAAMC,gBAAc,yBAAyB;AAC7C,QAAOA,kBAAgB,aACnB,OACAA,kBAAgB,yBACdA,kBAAgB,yBAChBA,kBAAgB;;ACexB,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,OAC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AACF,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 +1 @@
1
- {"version":3,"file":"isCorsOriginError.d.ts","names":[],"sources":["../src/shared/live/isCorsOriginError.ts"],"sourcesContent":[],"mappings":";;AAGgB,iBAAA,iBAAA,CAA4C,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAAA,eAAA"}
1
+ {"version":3,"file":"isCorsOriginError.d.ts","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"sourcesContent":[],"mappings":";;AAGgB,iBAAA,iBAAA,CAA4C,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAAA,eAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"isCorsOriginError.js","names":[],"sources":["../src/shared/live/isCorsOriginError.ts"],"sourcesContent":["import type {CorsOriginError} from '@sanity/client'\n\n/** @public */\nexport function isCorsOriginError(error: unknown): error is CorsOriginError {\n return error instanceof Error && error.name === 'CorsOriginError'\n}\n\nexport type {CorsOriginError}\n"],"mappings":"AAGA,SAAgB,kBAAkB,OAA0C;AAC1E,QAAO,iBAAiB,SAAS,MAAM,SAAS"}
1
+ {"version":3,"file":"isCorsOriginError.js","names":[],"sources":["../src/live/shared/isCorsOriginError.ts"],"sourcesContent":["import type {CorsOriginError} from '@sanity/client'\n\n/** @public */\nexport function isCorsOriginError(error: unknown): error is CorsOriginError {\n return error instanceof Error && error.name === 'CorsOriginError'\n}\n\nexport type {CorsOriginError}\n"],"mappings":"AAGA,SAAgB,kBAAkB,OAA0C;AAC1E,QAAO,iBAAiB,SAAS,MAAM,SAAS"}
@@ -1,15 +1,21 @@
1
1
  import { ClientPerspective, InitializedClientConfig, LiveEventGoAway } from "@sanity/client";
2
2
  interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
3
3
  /**
4
- * @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
4
+ * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
5
5
  */
6
6
  interface SanityLiveProps {
7
7
  config: SanityClientConfig;
8
- draftModeEnabled: boolean;
8
+ /**
9
+ * Setting this to 'published' opens one live event connection, setting it to any other value opens both the live event connections if needed
10
+ */
11
+ perspective: Exclude<ClientPerspective, "raw">;
12
+ onLiveEvent: (tags: string[]) => Promise<void | "refresh">;
13
+ onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | "refresh">;
14
+ onPresentationPerspective: (perspective: ClientPerspective) => Promise<void>;
9
15
  refreshOnMount?: boolean;
10
16
  refreshOnFocus?: boolean;
11
17
  refreshOnReconnect?: boolean;
12
- requestTag: string | undefined;
18
+ requestTag: string;
13
19
  /**
14
20
  * Handle errors from the Live Events subscription.
15
21
  * By default it's reported using `console.error`, you can override this prop to handle it in your own way.
@@ -17,12 +23,7 @@ interface SanityLiveProps {
17
23
  onError?: (error: unknown) => void;
18
24
  intervalOnGoAway?: number | false;
19
25
  onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
20
- revalidateSyncTags?: (tags: string[]) => Promise<void | "refresh">;
21
- resolveDraftModePerspective: () => Promise<ClientPerspective>;
22
26
  }
23
- /**
24
- * @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.
25
- */
26
- declare function SanityLive(props: SanityLiveProps): React.JSX.Element | null;
27
- export { SanityLiveProps, SanityLive as default };
28
- //# sourceMappingURL=live.d.ts.map
27
+ declare const SanityLive: React.ComponentType<SanityLiveProps>;
28
+ export { SanityLive };
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";UAyBU,kBAAA,SAA2B,KACnC;AAhBK;AA6BP;;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;EC3CjE,cAAa,CAAA,EAAgC,OAAA;;;;;;;;;;qBDwDxB;;cCxDR,YAAY,KAAA,CAAM,cAAc"}
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import dynamic from "next/dynamic";
3
+ const SanityLive = dynamic(() => import("../../SanityLive.js"), { ssr: false });
4
+ export { SanityLive };
5
+
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,5 +1,5 @@
1
- import { t as isCorsOriginError } from "./isCorsOriginError.js";
2
- import { a as DefinedFetchType, c as PerspectiveType, l as ResolvePerspectiveFromCookies, n as DefinedSanityFetchType, o as DefinedLiveProps, r as DefinedSanityLiveProps, t as DefineSanityLiveOptions } from "./defineLive.js";
1
+ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
+ import { a as DefinedFetchType, c as PerspectiveType, l as ResolvePerspectiveFromCookies, n as DefinedSanityFetchType, o as DefinedLiveProps, r as DefinedSanityLiveProps, t as DefineSanityLiveOptions } from "../../../defineLive.js";
3
3
  /**
4
4
  * @public
5
5
  */
@@ -21,4 +21,4 @@ declare function defineLive(_config: DefineSanityLiveOptions): {
21
21
  */
22
22
  declare const resolvePerspectiveFromCookies: ResolvePerspectiveFromCookies;
23
23
  export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
24
- //# sourceMappingURL=live.d.ts.map
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":[],"mappings":";;;;;AAsBc,iBAFE,UAAA,CAEF,OAAA,EAFsB,uBAEtB,CAAA,EAAA;EAIC,KAAA,EALN,gBAKM;EAImB,IAAA,EAR1B,KAAA,CAAM,aAQoB,CARN,gBAQM,CAAA;EAApB;;AASd;eAbe;;;;cAID,KAAA,CAAM,cAAc;;;;;;cASrB,+BAA+B"}
@@ -1,4 +1,4 @@
1
- import { t as isCorsOriginError } from "./isCorsOriginError.js";
1
+ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
2
  function defineLive(_config) {
3
3
  throw new Error(`defineLive can't be imported by a client component`);
4
4
  }
@@ -7,4 +7,4 @@ const resolvePerspectiveFromCookies = () => {
7
7
  };
8
8
  export { defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
9
9
 
10
- //# sourceMappingURL=live.js.map
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {ResolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {DefinedFetchType, DefinedLiveProps} from '#live/types'\n\nimport type {\n DefineSanityLiveOptions,\n DefinedSanityFetchType,\n DefinedSanityLiveProps,\n} from '../react-server/defineLive'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\n\n/**\n * @public\n */\nexport function defineLive(_config: DefineSanityLiveOptions): {\n fetch: DefinedFetchType\n Live: React.ComponentType<DefinedLiveProps>\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} {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n/**\n * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from \"next-sanity/draft-mode\"`\n * @public\n */\nexport const resolvePerspectiveFromCookies: ResolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {PerspectiveType as LivePerspective} from '#live/types'\n"],"mappings":";AAoBA,SAAgB,WAAW,SAWzB;AACA,OAAM,IAAI,MAAM,qDAAqD;;AAOvE,MAAa,sCAAqE;AAChF,OAAM,IAAI,MAAM,wEAAwE"}
@@ -0,0 +1,8 @@
1
+ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
2
+ import { c as PerspectiveType, n as DefinedSanityFetchType, r as DefinedSanityLiveProps, s as LiveOptions, u as resolvePerspectiveFromCookies } from "../../../defineLive.js";
3
+ declare function defineLive(config: LiveOptions): {
4
+ sanityFetch: DefinedSanityFetchType;
5
+ SanityLive: React.ComponentType<DefinedSanityLiveProps>;
6
+ };
7
+ export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}