next-sanity 13.0.0-cache-components.19 → 13.0.0-cache-components.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/RefreshOnInterval.js +14 -0
- package/dist/RefreshOnInterval.js.map +1 -0
- package/dist/SanityLive.js +55 -49
- package/dist/SanityLive.js.map +1 -1
- package/dist/defineLive.d.ts +3 -121
- package/dist/defineLive.d.ts.map +1 -1
- package/dist/hooks/index.js +5 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/live/client-components/index.d.ts +19 -12
- package/dist/live/client-components/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.d.ts +3 -10
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts +3 -2
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +10 -10
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +2 -1
- package/dist/live/conditions/react-server/index.js +11 -11
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/live/server-actions/index.default.d.ts +9 -5
- package/dist/live/server-actions/index.default.d.ts.map +1 -1
- package/dist/live/server-actions/index.default.js +25 -26
- package/dist/live/server-actions/index.default.js.map +1 -1
- package/dist/live/server-actions/index.next-js.d.ts +9 -5
- package/dist/live/server-actions/index.next-js.d.ts.map +1 -1
- package/dist/live/server-actions/index.next-js.js +14 -25
- package/dist/live/server-actions/index.next-js.js.map +1 -1
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +6 -6
- package/dist/LiveEvents.js +0 -43
- package/dist/LiveEvents.js.map +0 -1
- package/dist/LiveEventsIncludingDrafts.js +0 -46
- package/dist/LiveEventsIncludingDrafts.js.map +0 -1
- package/dist/PresentationComlink.js +0 -36
- package/dist/PresentationComlink.js.map +0 -1
- package/dist/context.js +0 -22
- package/dist/context.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRouter } from "next/navigation";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
function RefreshOnInterval(props) {
|
|
4
|
+
const router = useRouter();
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
const interval = setInterval(() => router.refresh(), props.interval);
|
|
7
|
+
return () => clearInterval(interval);
|
|
8
|
+
}, [router, props.interval]);
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
RefreshOnInterval.displayName = "RefreshOnInterval";
|
|
12
|
+
export { RefreshOnInterval as default };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=RefreshOnInterval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefreshOnInterval.js","names":[],"sources":["../src/live/client-components/RefreshOnInterval.tsx"],"sourcesContent":["import {useRouter} from 'next/navigation'\nimport {useEffect} from 'react'\n\nexport default function RefreshOnInterval(props: {interval: number}): null {\n const router = useRouter()\n\n useEffect(() => {\n const interval = setInterval(() => router.refresh(), props.interval)\n return () => clearInterval(interval)\n }, [router, props.interval])\n\n return null\n}\nRefreshOnInterval.displayName = 'RefreshOnInterval'\n"],"mappings":";;AAGA,SAAwB,kBAAkB,OAAiC;CACzE,MAAM,SAAS,WAAW;AAE1B,iBAAgB;EACd,MAAM,WAAW,kBAAkB,OAAO,SAAS,EAAE,MAAM,SAAS;AACpE,eAAa,cAAc,SAAS;IACnC,CAAC,QAAQ,MAAM,SAAS,CAAC;AAE5B,QAAO;;AAET,kBAAkB,cAAc"}
|
package/dist/SanityLive.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { startTransition, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
3
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { createClient } from "@sanity/client";
|
|
5
5
|
import dynamic from "next/dynamic";
|
|
6
|
-
import { isMaybePresentation } from "@sanity/presentation-comlink";
|
|
7
|
-
const LiveEvents = dynamic(() => import("./LiveEvents.js"));
|
|
8
|
-
const LiveEventsIncludingDrafts = dynamic(() => import("./LiveEventsIncludingDrafts.js"));
|
|
9
|
-
const PresentationComlink = dynamic(() => import("./PresentationComlink.js"));
|
|
10
|
-
const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
|
|
11
6
|
const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"));
|
|
7
|
+
const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
|
|
8
|
+
const RefreshOnInterval = dynamic(() => import("./RefreshOnInterval.js"));
|
|
12
9
|
const RefreshOnReconnect = dynamic(() => import("./RefreshOnReconnect.js"));
|
|
13
|
-
function handleError(error) {
|
|
14
|
-
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());
|
|
15
|
-
else console.error(error);
|
|
16
|
-
}
|
|
17
|
-
function handleOnGoAway(event, intervalOnGoAway) {
|
|
18
|
-
if (intervalOnGoAway) console.warn("Sanity Live connection closed, switching to long polling set to a interval of", intervalOnGoAway / 1e3, "seconds and the server gave this reason:", event.reason);
|
|
19
|
-
else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
|
|
20
|
-
}
|
|
21
10
|
function SanityLive(props) {
|
|
22
|
-
const { config,
|
|
11
|
+
const { config, includeAllDocuments = false, action, goAwayAction, reconnectAction, restartAction, welcomeAction, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = true, requestTag } = props;
|
|
23
12
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
|
|
13
|
+
const actionContext = { includeAllDocuments };
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
if (error) if (isCorsOriginError(error)) throw new Error(`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}` : ""}`, { cause: error });
|
|
16
|
+
else throw error;
|
|
24
17
|
const client = useMemo(() => createClient({
|
|
25
18
|
projectId,
|
|
26
19
|
dataset,
|
|
@@ -40,43 +33,56 @@ function SanityLive(props) {
|
|
|
40
33
|
token,
|
|
41
34
|
useProjectHostname
|
|
42
35
|
]);
|
|
43
|
-
const [
|
|
36
|
+
const [refreshOnInterval, setRefreshOnInterval] = useState(false);
|
|
37
|
+
const handleLiveEvent = useEffectEvent(async (event) => {
|
|
38
|
+
switch (event.type) {
|
|
39
|
+
case "welcome":
|
|
40
|
+
setRefreshOnInterval(false);
|
|
41
|
+
if (welcomeAction) await welcomeAction(event, actionContext);
|
|
42
|
+
else if (welcomeAction !== false && process.env.NODE_ENV !== "production") console.info(`<SanityLive> is connected and listening for live events to ${includeAllDocuments ? "all content including drafts and version documents in content releases" : "published content"}`);
|
|
43
|
+
break;
|
|
44
|
+
case "message":
|
|
45
|
+
await action(event, actionContext);
|
|
46
|
+
break;
|
|
47
|
+
case "restart":
|
|
48
|
+
await restartAction?.(event, actionContext);
|
|
49
|
+
break;
|
|
50
|
+
case "reconnect":
|
|
51
|
+
await reconnectAction?.(event, actionContext);
|
|
52
|
+
break;
|
|
53
|
+
case "goaway":
|
|
54
|
+
if (goAwayAction !== false) {
|
|
55
|
+
let interval = goAwayAction ? await goAwayAction(event, actionContext) : 3e4;
|
|
56
|
+
if (interval === false) return;
|
|
57
|
+
if (Number.isFinite(interval) && interval > 0) {
|
|
58
|
+
startTransition(() => setRefreshOnInterval(interval));
|
|
59
|
+
if (process.env.NODE_ENV !== "production") console.warn("Sanity Live connection closed, switching to long polling set to a interval of", interval / 1e3, "seconds and the server gave this reason:", event.reason);
|
|
60
|
+
}
|
|
61
|
+
} else setError(new Error(`Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`, { cause: event }));
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
setError(new Error(`Unknown live event type`, { cause: event }));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
44
68
|
useEffect(() => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
const subscription = client.live.events({
|
|
70
|
+
includeDrafts: includeAllDocuments,
|
|
71
|
+
tag: requestTag
|
|
72
|
+
}).subscribe({
|
|
73
|
+
next: (event) => startTransition(() => handleLiveEvent(event)),
|
|
74
|
+
error: (error$1) => startTransition(() => setError(error$1))
|
|
75
|
+
});
|
|
76
|
+
return () => subscription.unsubscribe();
|
|
77
|
+
}, [
|
|
78
|
+
client.live,
|
|
79
|
+
requestTag,
|
|
80
|
+
includeAllDocuments
|
|
81
|
+
]);
|
|
57
82
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
58
|
-
onLiveEvent && /* @__PURE__ */ jsx(LiveEvents, {
|
|
59
|
-
client,
|
|
60
|
-
onEvent: onLiveEvent,
|
|
61
|
-
requestTag,
|
|
62
|
-
onError,
|
|
63
|
-
onGoAway,
|
|
64
|
-
intervalOnGoAway
|
|
65
|
-
}),
|
|
66
|
-
includeDrafts && onLiveEventIncludingDrafts && /* @__PURE__ */ jsx(LiveEventsIncludingDrafts, {
|
|
67
|
-
client,
|
|
68
|
-
onEvent: onLiveEventIncludingDrafts,
|
|
69
|
-
requestTag,
|
|
70
|
-
onError,
|
|
71
|
-
onGoAway,
|
|
72
|
-
intervalOnGoAway
|
|
73
|
-
}),
|
|
74
|
-
loadComlink && /* @__PURE__ */ jsx(PresentationComlink, {
|
|
75
|
-
projectId,
|
|
76
|
-
dataset
|
|
77
|
-
}),
|
|
78
|
-
refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
|
|
79
83
|
refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
|
|
84
|
+
refreshOnInterval && /* @__PURE__ */ jsx(RefreshOnInterval, { interval: refreshOnInterval }),
|
|
85
|
+
refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
|
|
80
86
|
refreshOnReconnect && /* @__PURE__ */ jsx(RefreshOnReconnect, {})
|
|
81
87
|
] });
|
|
82
88
|
}
|
package/dist/SanityLive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {isCorsOriginError} from '#live/isCorsOriginError'\nimport {createClient, type InitializedClientConfig, type
|
|
1
|
+
{"version":3,"file":"SanityLive.js","names":["error"],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import type {SanityLiveActionContext} from '#live/types'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\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 includeAllDocuments?: boolean\n requestTag: string\n\n action: (\n event: Extract<LiveEvent, {type: 'message'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n reconnectAction?: (\n event: Extract<LiveEvent, {type: 'reconnect'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n restartAction?: (\n event: Extract<LiveEvent, {type: 'restart'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n welcomeAction?:\n | ((\n event: Extract<LiveEvent, {type: 'welcome'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>)\n | false\n goAwayAction?:\n | ((\n event: Extract<LiveEvent, {type: 'goaway'}>,\n context: SanityLiveActionContext,\n ) => Promise<number | false>)\n | false\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n goAwayAction,\n reconnectAction,\n restartAction,\n welcomeAction,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\n const [error, setError] = useState<unknown>(null)\n if (error) {\n if (isCorsOriginError(error)) {\n throw new Error(\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.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n } else {\n throw error\n }\n }\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\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const handleLiveEvent = useEffectEvent(async (event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setRefreshOnInterval(false)\n\n if (welcomeAction) {\n await welcomeAction(event, actionContext)\n } else if (welcomeAction !== false && process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive> is connected and listening for live events to ${includeAllDocuments ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n }\n break\n }\n case 'message': {\n await action(event, actionContext)\n break\n }\n case 'restart': {\n await restartAction?.(event, actionContext)\n break\n }\n case 'reconnect': {\n await reconnectAction?.(event, actionContext)\n break\n }\n case 'goaway': {\n if (goAwayAction !== false) {\n let interval = goAwayAction ? await goAwayAction(event, actionContext) : 30_000\n if (interval === false) return\n if (Number.isFinite(interval) && interval > 0) {\n startTransition(() => setRefreshOnInterval(interval))\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n interval / 1_000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n }\n }\n } else {\n setError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n setError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: includeAllDocuments, tag: requestTag})\n .subscribe({\n next: (event) => startTransition(() => handleLiveEvent(event)),\n error: (error) => startTransition(() => setError(error)),\n })\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeAllDocuments])\n\n return (\n <>\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnInterval && <RefreshOnInterval interval={refreshOnInterval} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;AAOA,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AAgDxE,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,sBAAsB,OACtB,QACA,cACA,iBACA,eACA,eACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,MACrB,eACE;CACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,OAAO,qBACzE;CACF,MAAM,gBAAgB,EAAC,qBAAoB;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAkB,KAAK;AACjD,KAAI,MACF,KAAI,kBAAkB,MAAM,CAC1B,OAAM,IAAI,MACR,8EAA8E,OAAO,OAAO,wEAAwE,MAAM,eAAe,iBAAiB,MAAM,iBAAiB,MACjO,EAAC,OAAO,OAAM,CACf;KAED,OAAM;CAIV,MAAM,SAAS,cAEX,aAAa;EACX;EACA;EACA;EACA;EACA;EACA,2BAA2B;EAC3B;EACA,QAAQ;EACR;EACD,CAAC,EACJ;EAAC;EAAS;EAAY;EAAS;EAAW;EAAkB;EAAO;EAAmB,CACvF;CAED,MAAM,CAAC,mBAAmB,wBAAwB,SAAyB,MAAM;CAEjF,MAAM,kBAAkB,eAAe,OAAO,UAAqB;AACjE,UAAQ,MAAM,MAAd;GACE,KAAK;AAEH,yBAAqB,MAAM;AAE3B,QAAI,cACF,OAAM,cAAc,OAAO,cAAc;aAChC,kBAAkB,SAAS,QAAQ,IAAI,aAAa,aAE7D,SAAQ,KACN,8DAA8D,sBAAsB,2EAA2E,sBAChK;AAEH;GAEF,KAAK;AACH,UAAM,OAAO,OAAO,cAAc;AAClC;GAEF,KAAK;AACH,UAAM,gBAAgB,OAAO,cAAc;AAC3C;GAEF,KAAK;AACH,UAAM,kBAAkB,OAAO,cAAc;AAC7C;GAEF,KAAK;AACH,QAAI,iBAAiB,OAAO;KAC1B,IAAI,WAAW,eAAe,MAAM,aAAa,OAAO,cAAc,GAAG;AACzE,SAAI,aAAa,MAAO;AACxB,SAAI,OAAO,SAAS,SAAS,IAAI,WAAW,GAAG;AAC7C,4BAAsB,qBAAqB,SAAS,CAAC;AACrD,UAAI,QAAQ,IAAI,aAAa,aAC3B,SAAQ,KACN,iFACA,WAAW,KACX,4CACA,MAAM,OACP;;UAIL,UACE,IAAI,MACF,mGAAmG,MAAM,UACzG,EAAC,OAAO,OAAM,CACf,CACF;AAEH;GAEF;AACE,aAAS,IAAI,MAAM,2BAA2B,EAAC,OAAO,OAAM,CAAC,CAAC;AAC9D;;GAEJ;AACF,iBAAgB;EACd,MAAM,eAAe,OAAO,KACzB,OAAO;GAAC,eAAe;GAAqB,KAAK;GAAW,CAAC,CAC7D,UAAU;GACT,OAAO,UAAU,sBAAsB,gBAAgB,MAAM,CAAC;GAC9D,QAAQ,YAAU,sBAAsB,SAASA,QAAM,CAAC;GACzD,CAAC;AACJ,eAAa,aAAa,aAAa;IACtC;EAAC,OAAO;EAAM;EAAY;EAAoB,CAAC;AAElD,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,qBAAqB,oBAAC,mBAAA,EAAkB,UAAU,mBAAA,CAAqB;EACvE,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc;AAEzB,IAAA,qBAAe"}
|
package/dist/defineLive.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { t as DefinedLiveProps } from "./types.js";
|
|
1
2
|
import { cookies } from "next/headers";
|
|
2
3
|
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams, SanityClient } from "@sanity/client";
|
|
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
|
/**
|
|
6
6
|
* You must await the cookies() function from next/headers
|
|
@@ -24,115 +24,6 @@ declare const resolvePerspectiveFromCookies: ({
|
|
|
24
24
|
cookies: Awaited<ReturnType<typeof cookies>>;
|
|
25
25
|
}) => Promise<Exclude<ClientPerspective, "raw">>;
|
|
26
26
|
/**
|
|
27
|
-
* Perspectives supported by Sanity Live.
|
|
28
|
-
* Using the legacy `'raw'` perspective is not supported and leads to undefined behavior.
|
|
29
|
-
*/
|
|
30
|
-
type PerspectiveType = Exclude<ClientPerspective$1, "raw">;
|
|
31
|
-
/**
|
|
32
|
-
* TODO: docs
|
|
33
|
-
*/
|
|
34
|
-
type DefinedFetchType = <const QueryString extends string>(options: {
|
|
35
|
-
query: QueryString;
|
|
36
|
-
params?: QueryParams$1;
|
|
37
|
-
/**
|
|
38
|
-
* @defaultValue 'published'
|
|
39
|
-
*/
|
|
40
|
-
perspective?: PerspectiveType;
|
|
41
|
-
/**
|
|
42
|
-
* Enables stega encoding of the data, this is typically only used in draft mode in conjunction with `perspective: 'drafts'` and with `@sanity/visual-editing` setup.
|
|
43
|
-
* @defaultValue `false`
|
|
44
|
-
*/
|
|
45
|
-
stega?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Custom cache tags that can be used with next's `updateTag` functions for custom `read-your-write` server actions,
|
|
48
|
-
* for example a like button that uses client.mutate to update a document and then immediately shows the result.
|
|
49
|
-
*/
|
|
50
|
-
tags?: string[];
|
|
51
|
-
/**
|
|
52
|
-
* This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
|
|
53
|
-
* @see https://www.sanity.io/docs/reference-api-request-tags
|
|
54
|
-
* @defaultValue 'next-loader.fetch'
|
|
55
|
-
*/
|
|
56
|
-
requestTag?: string;
|
|
57
|
-
}) => Promise<{
|
|
58
|
-
data: ClientReturn$1<QueryString, unknown>;
|
|
59
|
-
sourceMap: ContentSourceMap$1 | null;
|
|
60
|
-
tags: string[];
|
|
61
|
-
}>;
|
|
62
|
-
interface DefinedLiveProps {
|
|
63
|
-
/**
|
|
64
|
-
* TODO: docs, settings this to `true` enables live events for draft content and requires `browserToken` to be set.
|
|
65
|
-
*/
|
|
66
|
-
includeDrafts?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Automatic refresh of RSC when the component <SanityLive /> is mounted.
|
|
69
|
-
* @defaultValue `false`
|
|
70
|
-
*/
|
|
71
|
-
refreshOnMount?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Automatically refresh when window gets focused
|
|
74
|
-
* @defaultValue `false`
|
|
75
|
-
*/
|
|
76
|
-
refreshOnFocus?: boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Automatically refresh when the browser regains a network connection (via navigator.onLine)
|
|
79
|
-
* @defaultValue `false`
|
|
80
|
-
*/
|
|
81
|
-
refreshOnReconnect?: boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Automatically refresh on an interval when the Live Event API emits a `goaway` event, which indicates that the connection is rejected or closed.
|
|
84
|
-
* This typically happens if the connection limit is reached, or if the connection is idle for too long.
|
|
85
|
-
* To disable this long polling fallback behavior set `intervalOnGoAway` to `false` or `0`.
|
|
86
|
-
* You can also use `onGoAway` to handle the `goaway` event in your own way, and read the reason why the event was emitted.
|
|
87
|
-
* @defaultValue `30_000` 30 seconds interval
|
|
88
|
-
*/
|
|
89
|
-
intervalOnGoAway?: number | false;
|
|
90
|
-
/**
|
|
91
|
-
* This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
|
|
92
|
-
* @see https://www.sanity.io/docs/reference-api-request-tags
|
|
93
|
-
* @defaultValue 'next-loader.live'
|
|
94
|
-
*/
|
|
95
|
-
requestTag?: string;
|
|
96
|
-
/**
|
|
97
|
-
* Handle errors from the Live Events subscription.
|
|
98
|
-
* By default it's reported using `console.error`, you can override this prop to handle it in your own way.
|
|
99
|
-
*/
|
|
100
|
-
onError?: (error: unknown) => void;
|
|
101
|
-
/**
|
|
102
|
-
* Handle the `goaway` event if the connection is rejected/closed.
|
|
103
|
-
* `event.reason` will be a string of why the event was emitted, for example `'connection limit reached'`.
|
|
104
|
-
* 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.
|
|
105
|
-
* If you want to disable long polling set `intervalOnGoAway` to `false` or `0`.
|
|
106
|
-
*/
|
|
107
|
-
onGoAway?: (event: LiveEventGoAway$1, intervalOnGoAway: number | false) => void;
|
|
108
|
-
/**
|
|
109
|
-
* TODO: docs, this handles events for published content only, and can be used to revalidate content for all your users when in presentation tool
|
|
110
|
-
*/
|
|
111
|
-
onLiveEvent?: (tags: string[]) => Promise<void | "refresh">;
|
|
112
|
-
/**
|
|
113
|
-
* TODO: docs, this handles events for all changes, published, drafts and even version documents in content releases.
|
|
114
|
-
* It's only used when `browserToken` is provided, and the `perspective` prop is other than `"published"`.
|
|
115
|
-
* Wether you should just `refresh()` or use `updateTag` to expire tags depends on how you fetch draft content and wether it's cached or not.
|
|
116
|
-
*/
|
|
117
|
-
onLiveEventIncludingDrafts?: (tags: string[]) => Promise<void | "refresh">;
|
|
118
|
-
}
|
|
119
|
-
interface LiveOptions {
|
|
120
|
-
/**
|
|
121
|
-
* Required for `fetch()` and `<Live>` to work
|
|
122
|
-
*/
|
|
123
|
-
client: SanityClient$1;
|
|
124
|
-
/**
|
|
125
|
-
* Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.
|
|
126
|
-
* This token is never shared with the browser, unless you reuse it in `browserToken`..
|
|
127
|
-
*/
|
|
128
|
-
serverToken?: string | false;
|
|
129
|
-
/**
|
|
130
|
-
* Optional. This token is shared with the browser when `<Live>` is given a `perspective` prop other than `"published"`, and should only have access to query published documents.
|
|
131
|
-
* It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.
|
|
132
|
-
*/
|
|
133
|
-
browserToken?: string | false;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
27
|
* @public
|
|
137
28
|
*/
|
|
138
29
|
type DefinedSanityFetchType = <const QueryString extends string>(options: {
|
|
@@ -161,15 +52,6 @@ type DefinedSanityFetchType = <const QueryString extends string>(options: {
|
|
|
161
52
|
/**
|
|
162
53
|
* @public
|
|
163
54
|
*/
|
|
164
|
-
interface DefinedSanityLiveProps extends DefinedLiveProps {
|
|
165
|
-
/**
|
|
166
|
-
* @defaultValue `automatically resolved`
|
|
167
|
-
*/
|
|
168
|
-
perspective?: PerspectiveType;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* @public
|
|
172
|
-
*/
|
|
173
55
|
interface DefineSanityLiveOptions {
|
|
174
56
|
/**
|
|
175
57
|
* Required for `sanityFetch` and `SanityLive` to work
|
|
@@ -209,7 +91,7 @@ declare function defineLive(config: DefineSanityLiveOptions): {
|
|
|
209
91
|
/**
|
|
210
92
|
* @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`
|
|
211
93
|
*/
|
|
212
|
-
SanityLive: React.ComponentType<
|
|
94
|
+
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
213
95
|
};
|
|
214
|
-
export {
|
|
96
|
+
export { resolvePerspectiveFromCookies as a, ResolvePerspectiveFromCookies as i, DefinedSanityFetchType as n, defineLive as r, DefineSanityLiveOptions as t };
|
|
215
97
|
//# sourceMappingURL=defineLive.d.ts.map
|
package/dist/defineLive.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/
|
|
1
|
+
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.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,KCCzB,sBAAA,GDDyB,CAAA,0BAAA,MAAA,CAAA,CAAA,OAAA,EAAA;EAAlB,KAAA,ECEV,WDFU;EAAR,MAAA,CAAA,ECGA,WDHA,GCGc,ODHd,CCGsB,WDHtB,CAAA;EACW;;;;AAMtB;;EAGqC,IAAA,CAAA,EAAA,MAAA,EAAA;EAAlB,WAAA,CAAA,ECCH,ODDG,CCCK,iBDDL,EAAA,KAAA,CAAA;EAAR,KAAA,CAAA,EAAA,OAAA;EACS;;;;;ECVpB,UAAY,CAAA,EAAA,MAAA;CACH,EAAA,GAiBH,OAjBG,CAAA;EACE,IAAA,EAiBH,YAjBG,CAiBU,WAjBV,CAAA;EAAsB,SAAA,EAkBpB,gBAlBoB,GAAA,IAAA;EAAR,IAAA,EAAA,MAAA,EAAA;CAQD,CAAA;;;;AAUX,UAOI,uBAAA,CAPJ;EAFP;;AASN;EAgCA,MAAgB,EA5BN,YA4BM;EAAmB;;;;EAQf,WAAA,CAAA,EAAA,MAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;iBARJ,UAAA,SAAmB;;;;eAIpB;;;;cAID,KAAA,CAAM,cAAc"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as comlinkProjectId, i as comlinkPerspective, n as comlinkDataset, r as comlinkListeners, t as comlink } from "../context.js";
|
|
3
2
|
import { stegaEncodeSourceMap } from "@sanity/client/stega";
|
|
4
3
|
import { dequal } from "dequal/lite";
|
|
5
4
|
import { useEffect, useEffectEvent, useMemo, useReducer, useSyncExternalStore } from "react";
|
|
@@ -12,6 +11,11 @@ function useLiveEnvironment() {
|
|
|
12
11
|
console.log("TODO: Implement useLiveEnvironment");
|
|
13
12
|
return null;
|
|
14
13
|
}
|
|
14
|
+
const comlinkListeners = /* @__PURE__ */ new Set();
|
|
15
|
+
let comlink = null;
|
|
16
|
+
let comlinkProjectId = null;
|
|
17
|
+
let comlinkDataset = null;
|
|
18
|
+
let comlinkPerspective = null;
|
|
15
19
|
function reducer(state, { type, payload }) {
|
|
16
20
|
switch (type) {
|
|
17
21
|
case "query-change": return dequal(state, payload) ? state : {
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,4BAA4B;AAUlC,SAAgB,qBAAuD,OAI1B;CAC3C,MAAM,CAAC,OAAO,YAAY,WAAW,SAAS,aAAa;CAC3D,MAAM,EAAC,OAAO,SAAS,oBAAoB,QAAQ,SAAQ;CAK3D,MAAMA,YAAU,qBACd,iBACMC,eACA,KACP;CAMD,MAAM,YAAY,qBAChB,iBACM,wBACA,KACP;CACD,MAAM,UAAU,qBACd,iBACM,sBACA,KACP;CAID,MAAM,cAAc,qBAClB,iBACM,0BACA,KACP;CAED,MAAM,uBAAuB,gBAAgB,cAAiD;AAE5F,MAAI,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa;AAC1C,WAAQ,KAAK,wEAAwE;IACnF;IACA;IACA;IACD,CAAC;AACF;;AAGF,MAAI,gBAAgB,KAClB;AAEF,YAAQ,KAAK,uBAAuB;GAClC;GACA;GACA;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,CAACD,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;;AC1LpB,SAAgB,wBAAwC;AAEtD,SAAQ,IAAI,wCAAwC;AAEpD,QAAO;;ACPT,SAAgB,8BAAwD;AAEtE,SAAQ,IAAI,8CAA8C;AAE1D,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["comlink","comlinkSnapshot"],"sources":["../../src/hooks/useIsLivePreview.ts","../../src/live/hooks/useLiveEnvironment.ts","../../src/live/shared/context.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} 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","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;;ACAT,MAAa,mCAAoC,IAAI,KAAK;AAC1D,IAAW,UAA2D;AACtE,IAAW,mBAAkC;AAC7C,IAAW,iBAAgC;AAC3C,IAAW,qBAA+C;AC6B1D,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,4BAA4B;AAUlC,SAAgB,qBAAuD,OAI1B;CAC3C,MAAM,CAAC,OAAO,YAAY,WAAW,SAAS,aAAa;CAC3D,MAAM,EAAC,OAAO,SAAS,oBAAoB,QAAQ,SAAQ;CAK3D,MAAMA,YAAU,qBACd,iBACMC,eACA,KACP;CAMD,MAAM,YAAY,qBAChB,iBACM,wBACA,KACP;CACD,MAAM,UAAU,qBACd,iBACM,sBACA,KACP;CAID,MAAM,cAAc,qBAClB,iBACM,0BACA,KACP;CAED,MAAM,uBAAuB,gBAAgB,cAAiD;AAE5F,MAAI,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa;AAC1C,WAAQ,KAAK,wEAAwE;IACnF;IACA;IACA;IACD,CAAC;AACF;;AAGF,MAAI,gBAAgB,KAClB;AAEF,YAAQ,KAAK,uBAAuB;GAClC;GACA;GACA;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,CAACD,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;;AC1LpB,SAAgB,wBAAwC;AAEtD,SAAQ,IAAI,wCAAwC;AAEpD,QAAO;;ACPT,SAAgB,8BAAwD;AAEtE,SAAQ,IAAI,8CAA8C;AAE1D,QAAO"}
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as SanityLiveActionContext } from "../../types.js";
|
|
2
|
+
import { InitializedClientConfig, LiveEvent } from "@sanity/client";
|
|
2
3
|
interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
|
|
3
4
|
interface SanityLiveProps {
|
|
4
5
|
config: SanityClientConfig;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
includeAllDocuments?: boolean;
|
|
7
|
+
requestTag: string;
|
|
8
|
+
action: (event: Extract<LiveEvent, {
|
|
9
|
+
type: "message";
|
|
10
|
+
}>, context: SanityLiveActionContext) => Promise<void>;
|
|
11
|
+
reconnectAction?: (event: Extract<LiveEvent, {
|
|
12
|
+
type: "reconnect";
|
|
13
|
+
}>, context: SanityLiveActionContext) => Promise<void>;
|
|
14
|
+
restartAction?: (event: Extract<LiveEvent, {
|
|
15
|
+
type: "restart";
|
|
16
|
+
}>, context: SanityLiveActionContext) => Promise<void>;
|
|
17
|
+
welcomeAction?: ((event: Extract<LiveEvent, {
|
|
18
|
+
type: "welcome";
|
|
19
|
+
}>, context: SanityLiveActionContext) => Promise<void>) | false;
|
|
20
|
+
goAwayAction?: ((event: Extract<LiveEvent, {
|
|
21
|
+
type: "goaway";
|
|
22
|
+
}>, context: SanityLiveActionContext) => Promise<number | false>) | false;
|
|
8
23
|
refreshOnMount?: boolean;
|
|
9
24
|
refreshOnFocus?: boolean;
|
|
10
25
|
refreshOnReconnect?: boolean;
|
|
11
|
-
requestTag: string;
|
|
12
|
-
/**
|
|
13
|
-
* Handle errors from the Live Events subscription.
|
|
14
|
-
* By default it's reported using `console.error`, you can override this prop to handle it in your own way.
|
|
15
|
-
*/
|
|
16
|
-
onError?: (error: unknown) => void;
|
|
17
|
-
intervalOnGoAway?: number | false;
|
|
18
|
-
onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
|
|
19
26
|
}
|
|
20
27
|
/**
|
|
21
28
|
* @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";;UAYU,kBAAA,SAA2B,KACnC;AADQ,UAWO,eAAA,CAXP;EAWV,MAAiB,EACP,kBADO;EACP,mBAAA,CAAA,EAAA,OAAA;EAKS,UAAA,EAAA,MAAA;EAAR,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,CAAQ,SAAR,EAAA;IACE,IAAA,EAAA,SAAA;EACN,CAAA,CAAA,EAAA,OAAA,EADM,uBACN,EAAA,GAAA,OAAA,CAAA,IAAA,CAAA;EAEY,eAAA,CAAA,EAAA,CAAA,KAAA,EAAR,OAAQ,CAAA,SAAA,EAAA;IAAR,IAAA,EAAA,WAAA;EACE,CAAA,CAAA,EAAA,OAAA,EAAA,uBAAA,EAAA,GACN,OADM,CAAA,IAAA,CAAA;EACN,aAAA,CAAA,EAAA,CAAA,KAAA,EAEI,OAFJ,CAEY,SAFZ,EAAA;IAEY,IAAA,EAAA,SAAA;EAAR,CAAA,CAAA,EAAA,OAAA,EACE,uBADF,EAAA,GAEJ,OAFI,CAAA,IAAA,CAAA;EACE,aAAA,CAAA,EAAA,CAAA,CAAA,KAAA,EAIE,OAJF,CAIU,SAJV,EAAA;IACN,IAAA,EAAA,SAAA;EAGgB,CAAA,CAAA,EAAA,OAAA,EACN,uBADM,EAAA,GAEZ,OAFY,CAAA,IAAA,CAAA,CAAA,GAAA,KAAA;EAAR,YAAA,CAAA,EAAA,CAAA,CAAA,KAAA,EAMA,OANA,CAMQ,SANR,EAAA;IACE,IAAA,EAAA,QAAA;EACN,CAAA,CAAA,EAAA,OAAA,EAKM,uBALN,EAAA,GAMA,OANA,CAAA,MAAA,GAAA,KAAA,CAAA,CAAA,GAAA,KAAA;EAIY,cAAA,CAAA,EAAA,OAAA;EAAR,cAAA,CAAA,EAAA,OAAA;EACE,kBAAA,CAAA,EAAA,OAAA;;;;AA9CwD;AAoBxD,cCfJ,UDeI,ECfQ,KAAA,CAAM,aDed,CCf4B,eDe5B,CAAA"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import {
|
|
2
|
+
import { r as PerspectiveType, t as DefinedLiveProps } from "../../../types.js";
|
|
3
|
+
import { i as ResolvePerspectiveFromCookies, n as DefinedSanityFetchType, t as DefineSanityLiveOptions } from "../../../defineLive.js";
|
|
3
4
|
/**
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
6
7
|
declare function defineLive(_config: DefineSanityLiveOptions): {
|
|
7
|
-
fetch: DefinedFetchType;
|
|
8
|
-
Live: React.ComponentType<DefinedLiveProps>;
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`
|
|
11
|
-
*/
|
|
12
8
|
sanityFetch: DefinedSanityFetchType;
|
|
13
|
-
|
|
14
|
-
* @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`
|
|
15
|
-
*/
|
|
16
|
-
SanityLive: React.ComponentType<DefinedSanityLiveProps>;
|
|
9
|
+
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
17
10
|
};
|
|
18
11
|
/**
|
|
19
12
|
* Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from "next-sanity/draft-mode"`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":[],"mappings":";;;AAgBA;;;AAEkC,iBAFlB,UAAA,CAEkB,OAAA,EAFE,uBAEF,CAAA,EAAA;EAApB,WAAM,EADL,sBACK;EAAA,UAAA,EAAN,KAAA,CAAM,aAAA,CAAc,gBAAd,CAAA;AASpB,CAAA;;;;;cAAa,+BAA+B"}
|
|
@@ -1 +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 {
|
|
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 {DefinedLiveProps} from '#live/types'\n\nimport type {DefineSanityLiveOptions, DefinedSanityFetchType} from '../react-server/defineLive'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\n\n/**\n * @public\n */\nexport function defineLive(_config: DefineSanityLiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\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":";AAgBA,SAAgB,WAAW,SAGzB;AACA,OAAM,IAAI,MAAM,qDAAqD;;AAOvE,MAAa,sCAAqE;AAChF,OAAM,IAAI,MAAM,wEAAwE"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import {
|
|
2
|
+
import { n as LiveOptions, r as PerspectiveType, t as DefinedLiveProps } from "../../../types.js";
|
|
3
|
+
import { a as resolvePerspectiveFromCookies, n as DefinedSanityFetchType } from "../../../defineLive.js";
|
|
3
4
|
declare function defineLive(config: LiveOptions): {
|
|
4
5
|
sanityFetch: DefinedSanityFetchType;
|
|
5
|
-
SanityLive: React.ComponentType<
|
|
6
|
+
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
6
7
|
};
|
|
7
8
|
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":";;;iBAUgB,UAAA,SAAmB;eACpB;EADf,UAAgB,EAEF,KAAA,CAAM,aAFJ,CAEkB,gBAFlB,CAAA;CAAmB"}
|
|
@@ -3,7 +3,7 @@ import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
|
3
3
|
import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
6
|
-
import {
|
|
6
|
+
import { actionRefresh, actionUpdateTags } from "next-sanity/live/server-actions";
|
|
7
7
|
import { cacheLife, cacheTag } from "next/cache";
|
|
8
8
|
import { preconnect } from "react-dom";
|
|
9
9
|
function defineLive(config) {
|
|
@@ -38,8 +38,8 @@ function defineLive(config) {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
const Live = function Live$1(props) {
|
|
41
|
-
const {
|
|
42
|
-
const shouldIncludeDrafts = typeof browserToken === "string" &&
|
|
41
|
+
const { includeAllDocuments = false, action = actionUpdateTags, restartAction = actionRefresh, reconnectAction = actionRefresh, goAwayAction, welcomeAction, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components" } = props;
|
|
42
|
+
const shouldIncludeDrafts = typeof browserToken === "string" && includeAllDocuments;
|
|
43
43
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
44
44
|
const { origin } = new URL(client.getUrl("", false));
|
|
45
45
|
preconnect(origin);
|
|
@@ -53,16 +53,16 @@ function defineLive(config) {
|
|
|
53
53
|
requestTagPrefix,
|
|
54
54
|
token: shouldIncludeDrafts ? browserToken : void 0
|
|
55
55
|
},
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
includeAllDocuments: shouldIncludeDrafts,
|
|
57
|
+
action,
|
|
58
|
+
reconnectAction: reconnectAction === false ? void 0 : reconnectAction,
|
|
59
|
+
restartAction: restartAction === false ? void 0 : restartAction,
|
|
60
|
+
welcomeAction,
|
|
61
|
+
goAwayAction,
|
|
59
62
|
requestTag,
|
|
60
63
|
refreshOnMount,
|
|
61
64
|
refreshOnFocus,
|
|
62
|
-
refreshOnReconnect
|
|
63
|
-
onError,
|
|
64
|
-
onGoAway,
|
|
65
|
-
intervalOnGoAway
|
|
65
|
+
refreshOnReconnect
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
68
|
Live.displayName = "SanityLiveServerComponent";
|