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.
- package/dist/PresentationComlink.js +3 -3
- package/dist/PresentationComlink.js.map +1 -1
- package/dist/RefreshOnFocus.js.map +1 -1
- package/dist/RefreshOnMount.js +2 -2
- package/dist/RefreshOnMount.js.map +1 -1
- package/dist/RefreshOnReconnect.js.map +1 -1
- package/dist/{live/client-components/live/index.js → SanityLive.js} +23 -46
- package/dist/SanityLive.js.map +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/defineLive.d.ts +5 -50
- package/dist/defineLive.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/isCorsOriginError.d.ts.map +1 -1
- package/dist/isCorsOriginError.js.map +1 -1
- package/dist/{experimental/client-components/live.d.ts → live/client-components/index.d.ts} +12 -11
- package/dist/live/client-components/index.d.ts.map +1 -0
- package/dist/live/client-components/index.js +6 -0
- package/dist/live/client-components/index.js.map +1 -0
- package/dist/{live.d.ts → live/conditions/default/index.d.ts} +3 -3
- package/dist/live/conditions/default/index.d.ts.map +1 -0
- package/dist/{live.js → live/conditions/default/index.js} +2 -2
- package/dist/live/conditions/default/index.js.map +1 -0
- package/dist/live/conditions/next-js/index.d.ts +8 -0
- package/dist/live/conditions/next-js/index.d.ts.map +1 -0
- package/dist/live/conditions/next-js/index.js +78 -0
- package/dist/live/conditions/next-js/index.js.map +1 -0
- package/dist/live/conditions/react-server/index.d.ts +3 -0
- package/dist/live/conditions/react-server/index.js +100 -0
- package/dist/live/conditions/react-server/index.js.map +1 -0
- package/dist/live/server-actions/index.default.d.ts +15 -0
- package/dist/live/server-actions/index.default.d.ts.map +1 -0
- package/dist/live/server-actions/{index.js → index.default.js} +26 -13
- package/dist/live/server-actions/index.default.js.map +1 -0
- package/dist/live/server-actions/index.next-js.d.ts +15 -0
- package/dist/live/server-actions/index.next-js.d.ts.map +1 -0
- package/dist/live/server-actions/index.next-js.js +52 -0
- package/dist/live/server-actions/index.next-js.js.map +1 -0
- package/dist/resolvePerspectiveFromCookies.js.map +1 -1
- package/dist/sanitizePerspective.js.map +1 -1
- package/package.json +18 -17
- package/dist/experimental/client-components/live.d.ts.map +0 -1
- package/dist/experimental/client-components/live.js +0 -179
- package/dist/experimental/client-components/live.js.map +0 -1
- package/dist/live/client-components/live/index.d.ts +0 -26
- package/dist/live/client-components/live/index.d.ts.map +0 -1
- package/dist/live/client-components/live/index.js.map +0 -1
- package/dist/live/server-actions/index.d.ts +0 -6
- package/dist/live/server-actions/index.d.ts.map +0 -1
- package/dist/live/server-actions/index.js.map +0 -1
- package/dist/live.d.ts.map +0 -1
- package/dist/live.js.map +0 -1
- package/dist/live.next-js.d.ts +0 -16
- package/dist/live.next-js.d.ts.map +0 -1
- package/dist/live.next-js.js +0 -87
- package/dist/live.next-js.js.map +0 -1
- package/dist/live.react-server.d.ts +0 -3
- package/dist/live.react-server.js +0 -94
- package/dist/live.react-server.js.map +0 -1
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { n as PUBLISHED_SYNC_TAG_PREFIX } from "../../constants.js";
|
|
3
|
-
import { d as setEnvironment, f as setPerspective } from "../../context.js";
|
|
4
|
-
import { t as isCorsOriginError } from "../../isCorsOriginError.js";
|
|
5
|
-
import { t as sanitizePerspective } from "../../sanitizePerspective.js";
|
|
6
|
-
import { useRouter } from "next/navigation";
|
|
7
|
-
import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
|
|
8
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import { createClient } from "@sanity/client";
|
|
10
|
-
import { isMaybePresentation, isMaybePreviewWindow } from "@sanity/presentation-comlink";
|
|
11
|
-
import { expireTags } from "next-sanity/live/server-actions";
|
|
12
|
-
import dynamic from "next/dynamic";
|
|
13
|
-
const PresentationComlink = dynamic(() => import("../../PresentationComlink.js"), { ssr: false });
|
|
14
|
-
const RefreshOnMount = dynamic(() => import("../../RefreshOnMount.js"), { ssr: false });
|
|
15
|
-
const RefreshOnFocus = dynamic(() => import("../../RefreshOnFocus.js"), { ssr: false });
|
|
16
|
-
const RefreshOnReconnect = dynamic(() => import("../../RefreshOnReconnect.js"), { ssr: false });
|
|
17
|
-
function handleError(error) {
|
|
18
|
-
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());
|
|
19
|
-
else console.error(error);
|
|
20
|
-
}
|
|
21
|
-
function handleOnGoAway(event, intervalOnGoAway) {
|
|
22
|
-
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);
|
|
23
|
-
else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
|
|
24
|
-
}
|
|
25
|
-
function SanityLive(props) {
|
|
26
|
-
const { config, draftModeEnabled, 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 = expireTags, resolveDraftModePerspective } = props;
|
|
27
|
-
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
|
|
28
|
-
const client = useMemo(() => createClient({
|
|
29
|
-
projectId,
|
|
30
|
-
dataset,
|
|
31
|
-
apiHost,
|
|
32
|
-
apiVersion,
|
|
33
|
-
useProjectHostname,
|
|
34
|
-
ignoreBrowserTokenWarning: true,
|
|
35
|
-
token,
|
|
36
|
-
useCdn: false,
|
|
37
|
-
requestTagPrefix
|
|
38
|
-
}), [
|
|
39
|
-
apiHost,
|
|
40
|
-
apiVersion,
|
|
41
|
-
dataset,
|
|
42
|
-
projectId,
|
|
43
|
-
requestTagPrefix,
|
|
44
|
-
token,
|
|
45
|
-
useProjectHostname
|
|
46
|
-
]);
|
|
47
|
-
const [longPollingInterval, setLongPollingInterval] = useState(false);
|
|
48
|
-
const [resolvedInitialPerspective, setResolvedInitialPerspective] = useState(false);
|
|
49
|
-
const router = useRouter();
|
|
50
|
-
const handleLiveEvent = useEffectEvent((event) => {
|
|
51
|
-
if (process.env.NODE_ENV !== "production" && event.type === "welcome") {
|
|
52
|
-
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");
|
|
53
|
-
setLongPollingInterval(false);
|
|
54
|
-
} else if (event.type === "message") revalidateSyncTags$1(event.tags.map((tag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}`)).then((result) => {
|
|
55
|
-
if (result === "refresh") router.refresh();
|
|
56
|
-
});
|
|
57
|
-
else if (event.type === "restart" || event.type === "reconnect") router.refresh();
|
|
58
|
-
else if (event.type === "goaway") {
|
|
59
|
-
onGoAway(event, intervalOnGoAway);
|
|
60
|
-
setLongPollingInterval(intervalOnGoAway);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
const subscription = client.live.events({ tag: requestTag }).subscribe({
|
|
65
|
-
next: handleLiveEvent,
|
|
66
|
-
error: (err) => {
|
|
67
|
-
onError(err);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return () => subscription.unsubscribe();
|
|
71
|
-
}, [
|
|
72
|
-
client.live,
|
|
73
|
-
onError,
|
|
74
|
-
requestTag,
|
|
75
|
-
token
|
|
76
|
-
]);
|
|
77
|
-
const handleLiveDraftEvent = useEffectEvent((event) => {
|
|
78
|
-
if (event.type === "message") router.refresh();
|
|
79
|
-
});
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (!token) return;
|
|
82
|
-
const subscription = client.live.events({
|
|
83
|
-
includeDrafts: !!token,
|
|
84
|
-
tag: requestTag
|
|
85
|
-
}).subscribe({
|
|
86
|
-
next: handleLiveDraftEvent,
|
|
87
|
-
error: (err) => {
|
|
88
|
-
onError(err);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return () => subscription.unsubscribe();
|
|
92
|
-
}, [
|
|
93
|
-
client.live,
|
|
94
|
-
onError,
|
|
95
|
-
requestTag,
|
|
96
|
-
token
|
|
97
|
-
]);
|
|
98
|
-
useEffect(() => {
|
|
99
|
-
if (resolvedInitialPerspective) return void 0;
|
|
100
|
-
if (!draftModeEnabled) {
|
|
101
|
-
setResolvedInitialPerspective(true);
|
|
102
|
-
setPerspective("unknown");
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const controller = new AbortController();
|
|
106
|
-
resolveDraftModePerspective().then((perspective) => {
|
|
107
|
-
if (controller.signal.aborted) return;
|
|
108
|
-
setResolvedInitialPerspective(true);
|
|
109
|
-
setPerspective(sanitizePerspective(perspective, "drafts"));
|
|
110
|
-
}).catch((err) => {
|
|
111
|
-
if (controller.signal.aborted) return;
|
|
112
|
-
console.error("Failed to resolve draft mode perspective", err);
|
|
113
|
-
setResolvedInitialPerspective(true);
|
|
114
|
-
setPerspective("unknown");
|
|
115
|
-
});
|
|
116
|
-
return () => controller.abort();
|
|
117
|
-
}, [
|
|
118
|
-
draftModeEnabled,
|
|
119
|
-
resolveDraftModePerspective,
|
|
120
|
-
resolvedInitialPerspective
|
|
121
|
-
]);
|
|
122
|
-
const [loadComlink, setLoadComlink] = useState(false);
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (isMaybePresentation()) return;
|
|
125
|
-
if (draftModeEnabled && token) {
|
|
126
|
-
setEnvironment("live");
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (draftModeEnabled) {
|
|
130
|
-
setEnvironment("static");
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
setEnvironment("unknown");
|
|
134
|
-
}, [draftModeEnabled, token]);
|
|
135
|
-
useEffect(() => {
|
|
136
|
-
if (!isMaybePresentation()) return;
|
|
137
|
-
const controller = new AbortController();
|
|
138
|
-
const timeout = setTimeout(() => setEnvironment("live"), 3e3);
|
|
139
|
-
window.addEventListener("message", ({ data }) => {
|
|
140
|
-
if (data && typeof data === "object" && "domain" in data && data.domain === "sanity/channels" && "from" in data && data.from === "presentation") {
|
|
141
|
-
clearTimeout(timeout);
|
|
142
|
-
setEnvironment(isMaybePreviewWindow() ? "presentation-window" : "presentation-iframe");
|
|
143
|
-
setLoadComlink(true);
|
|
144
|
-
controller.abort();
|
|
145
|
-
}
|
|
146
|
-
}, { signal: controller.signal });
|
|
147
|
-
return () => {
|
|
148
|
-
clearTimeout(timeout);
|
|
149
|
-
controller.abort();
|
|
150
|
-
};
|
|
151
|
-
}, []);
|
|
152
|
-
const draftModeEnabledWarnRef = useRef(void 0);
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (!draftModeEnabled) return;
|
|
155
|
-
clearTimeout(draftModeEnabledWarnRef.current);
|
|
156
|
-
return () => {
|
|
157
|
-
draftModeEnabledWarnRef.current = setTimeout(() => {
|
|
158
|
-
console.warn("Sanity Live: Draft mode was enabled, but is now being disabled");
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
}, [draftModeEnabled]);
|
|
162
|
-
useEffect(() => {
|
|
163
|
-
if (!longPollingInterval) return;
|
|
164
|
-
const interval = setInterval(() => router.refresh(), longPollingInterval);
|
|
165
|
-
return () => clearInterval(interval);
|
|
166
|
-
}, [longPollingInterval, router]);
|
|
167
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
168
|
-
draftModeEnabled && loadComlink && resolvedInitialPerspective && /* @__PURE__ */ jsx(PresentationComlink, {
|
|
169
|
-
projectId,
|
|
170
|
-
dataset
|
|
171
|
-
}),
|
|
172
|
-
!draftModeEnabled && refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
|
|
173
|
-
!draftModeEnabled && refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
|
|
174
|
-
!draftModeEnabled && refreshOnReconnect && /* @__PURE__ */ jsx(RefreshOnReconnect, {})
|
|
175
|
-
] });
|
|
176
|
-
}
|
|
177
|
-
export { SanityLive as default };
|
|
178
|
-
|
|
179
|
-
//# sourceMappingURL=live.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.js","names":["revalidateSyncTags"],"sources":["../../../src/experimental/client-components/live.tsx"],"sourcesContent":["'use client'\n\nimport {setEnvironment, setPerspective} from '#client-components/context'\nimport {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n createClient,\n type ClientPerspective,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport {expireTags} from 'next-sanity/live/server-actions'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useRef, useState, useEffectEvent} from 'react'\n\nimport type {SanityClientConfig} from '../types'\n\nconst PresentationComlink = dynamic(() => import('#client-components/PresentationComlink'), {ssr: false})\nconst RefreshOnMount = dynamic(() => import('../../live/client-components/live/RefreshOnMount'), {\n ssr: false,\n})\nconst RefreshOnFocus = dynamic(() => import('../../live/client-components/live/RefreshOnFocus'), {\n ssr: false,\n})\nconst RefreshOnReconnect = dynamic(\n () => import('../../live/client-components/live/RefreshOnReconnect'),\n {ssr: false},\n)\n\n/**\n * @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.\n */\nexport interface SanityLiveProps {\n config: SanityClientConfig\n draftModeEnabled: boolean\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string | undefined\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 revalidateSyncTags?: (tags: string[]) => Promise<void | 'refresh'>\n resolveDraftModePerspective: () => Promise<ClientPerspective>\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\n/**\n * @alpha CAUTION: This API does not follow semver and could have breaking changes in future minor releases.\n */\nexport default function SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n draftModeEnabled,\n refreshOnMount = false,\n refreshOnFocus = draftModeEnabled\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag = 'next-loader.live',\n onError = handleError,\n onGoAway = handleOnGoAway,\n revalidateSyncTags = expireTags,\n resolveDraftModePerspective,\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 const [resolvedInitialPerspective, setResolvedInitialPerspective] = useState(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 : draftModeEnabled\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 revalidateSyncTags(\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 // @TODO previous version that handle both published and draft events\n // useEffect(() => {\n // const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n // next: handleLiveEvent,\n // error: (err: unknown) => {\n // onError(err)\n // },\n // })\n // return () => subscription.unsubscribe()\n // }, [client.live, onError, requestTag, token])\n useEffect(() => {\n const subscription = client.live.events({tag: requestTag}).subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n /**\n * Handle live events for drafts differently, only use it to trigger refreshes, don't expire the cache\n */\n const handleLiveDraftEvent = useEffectEvent((event: LiveEvent) => {\n if (event.type === 'message') {\n // Just refresh, due to cache bypass in draft mode it'll fetch fresh content (though we wish cache worked as in production)\n // @TODO if draft content is published, then this extra refresh is unnecessary, it's tricky to check since `event.id` are different on the two EventSource connections\n router.refresh()\n }\n })\n useEffect(() => {\n if (!token) return\n const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n next: handleLiveDraftEvent,\n error: (err: unknown) => {\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n /**\n * 2. Notify what perspective we're in, when in Draft Mode\n */\n useEffect(() => {\n if (resolvedInitialPerspective) return undefined\n\n if (!draftModeEnabled) {\n setResolvedInitialPerspective(true)\n setPerspective('unknown')\n return undefined\n }\n\n const controller = new AbortController()\n resolveDraftModePerspective()\n .then((perspective) => {\n if (controller.signal.aborted) return\n setResolvedInitialPerspective(true)\n setPerspective(sanitizePerspective(perspective, 'drafts'))\n })\n .catch((err) => {\n if (controller.signal.aborted) return\n console.error('Failed to resolve draft mode perspective', err)\n setResolvedInitialPerspective(true)\n setPerspective('unknown')\n })\n return () => controller.abort()\n }, [draftModeEnabled, resolveDraftModePerspective, resolvedInitialPerspective])\n\n const [loadComlink, setLoadComlink] = useState(false)\n /**\n * 3. Notify what environment we're in, when in Draft Mode\n */\n useEffect(() => {\n // If we might be in Presentation Tool, then skip detecting here as it's handled later\n if (isMaybePresentation()) return\n\n // If we're definitely not in Presentation Tool, then we can set the environment as stand-alone live preview\n // if we have both a browser token, and draft mode is enabled\n if (draftModeEnabled && token) {\n setEnvironment('live')\n return\n }\n // If we're in draft mode, but don't have a browser token, then we're in static mode\n // which means that published content is still live, but draft changes likely need manual refresh\n if (draftModeEnabled) {\n setEnvironment('static')\n return\n }\n\n // Fallback to `unknown` otherwise, as we simply don't know how it's setup\n setEnvironment('unknown')\n return\n }, [draftModeEnabled, token])\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 * 5. Warn if draft mode is being disabled\n * @TODO move logic into PresentationComlink, or maybe VisualEditing?\n */\n const draftModeEnabledWarnRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n useEffect(() => {\n if (!draftModeEnabled) return\n clearTimeout(draftModeEnabledWarnRef.current)\n return () => {\n draftModeEnabledWarnRef.current = setTimeout(() => {\n console.warn('Sanity Live: Draft mode was enabled, but is now being disabled')\n })\n }\n }, [draftModeEnabled])\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 {draftModeEnabled && loadComlink && resolvedInitialPerspective && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n // onPerspective={setPerspectiveCookie}\n />\n )}\n {!draftModeEnabled && refreshOnMount && <RefreshOnMount />}\n {!draftModeEnabled && refreshOnFocus && <RefreshOnFocus />}\n {!draftModeEnabled && refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,MAAM,sBAAsB,cAAc,OAAO,iCAA2C,EAAC,KAAK,OAAM,CAAC;AACzG,MAAM,iBAAiB,cAAc,OAAO,4BAAqD,EAC/F,KAAK,OACN,CAAC;AACF,MAAM,iBAAiB,cAAc,OAAO,4BAAqD,EAC/F,KAAK,OACN,CAAC;AACF,MAAM,qBAAqB,cACnB,OA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AA,CAAiB;EACzD,CAAC,oBAAoB,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KACjE"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ClientPerspective, InitializedClientConfig, LiveEventGoAway, SyncTag } from "@sanity/client";
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
interface SanityLiveProps extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {
|
|
6
|
-
draftModeEnabled: boolean;
|
|
7
|
-
draftModePerspective?: ClientPerspective;
|
|
8
|
-
refreshOnMount?: boolean;
|
|
9
|
-
refreshOnFocus?: boolean;
|
|
10
|
-
refreshOnReconnect?: boolean;
|
|
11
|
-
requestTag: string | undefined;
|
|
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
|
-
revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | "refresh">;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
declare function SanityLive(props: SanityLiveProps): React.JSX.Element | null;
|
|
25
|
-
export { type SanityLiveProps, SanityLive as default };
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/client-components/live/SanityLive.tsx"],"sourcesContent":[],"mappings":";;AAwBA;;AAYyB,UAZR,eAAA,SAAwB,IAYhB,CAXvB,uBAWuB,EAAA,WAAA,GAAA,SAAA,GAAA,SAAA,GAAA,YAAA,GAAA,oBAAA,GAAA,OAAA,GAAA,kBAAA,CAAA,CAAA;EAWJ,gBAAA,EAAA,OAAA;EACS,oBAAA,CAAA,EAZL,iBAYK;EAAc,cAAA,CAAA,EAAA,OAAA;EAxBH,cAAA,CAAA,EAAA,OAAA;EAAA,kBAAA,CAAA,EAAA,OAAA;EA0DzC,UAAgB,EAAA,MAAA,GAAA,SAAkB;;;;;;;qBAnCb;8BACS,cAAc;;;;;iBAkC5B,UAAA,QAAkB,kBAAkB,KAAA,CAAM,GAAA,CAAI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["defaultRevalidateSyncTags","revalidateSyncTags"],"sources":["../../../../src/live/client-components/live/SanityLive.tsx"],"sourcesContent":["import {setEnvironment, setPerspective} from '#client-components/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 {revalidateSyncTags as defaultRevalidateSyncTags} from 'next-sanity/live/server-actions'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useRef, useState, useEffectEvent} from 'react'\n\nconst PresentationComlink = dynamic(() => import('#client-components/PresentationComlink'), {ssr: false})\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'), {ssr: false})\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'), {ssr: false})\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'), {ssr: false})\n\n/**\n * @public\n */\nexport interface SanityLiveProps extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {\n // handleDraftModeAction: (secret: string) => Promise<void | string>\n draftModeEnabled: boolean\n draftModePerspective?: ClientPerspective\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string | undefined\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 revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | 'refresh'>\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\n/**\n * @public\n */\nexport function SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n token,\n requestTagPrefix,\n // handleDraftModeAction,\n draftModeEnabled,\n draftModePerspective,\n refreshOnMount = false,\n refreshOnFocus = draftModeEnabled\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag = 'next-loader.live',\n onError = handleError,\n onGoAway = handleOnGoAway,\n revalidateSyncTags = defaultRevalidateSyncTags,\n } = props\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 : draftModeEnabled\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 revalidateSyncTags(event.tags).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 /**\n * 2. Notify what perspective we're in, when in Draft Mode\n */\n useEffect(() => {\n if (draftModeEnabled && draftModePerspective) {\n setPerspective(draftModePerspective)\n } else {\n setPerspective('unknown')\n }\n }, [draftModeEnabled, draftModePerspective])\n\n const [loadComlink, setLoadComlink] = useState(false)\n /**\n * 3. Notify what environment we're in, when in Draft Mode\n */\n useEffect(() => {\n // If we might be in Presentation Tool, then skip detecting here as it's handled later\n if (isMaybePresentation()) return\n\n // If we're definitely not in Presentation Tool, then we can set the environment as stand-alone live preview\n // if we have both a browser token, and draft mode is enabled\n if (draftModeEnabled && token) {\n setEnvironment('live')\n return\n }\n // If we're in draft mode, but don't have a browser token, then we're in static mode\n // which means that published content is still live, but draft changes likely need manual refresh\n if (draftModeEnabled) {\n setEnvironment('static')\n return\n }\n\n // Fallback to `unknown` otherwise, as we simply don't know how it's setup\n setEnvironment('unknown')\n return\n }, [draftModeEnabled, token])\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 * 5. Warn if draft mode is being disabled\n * @TODO move logic into PresentationComlink, or maybe VisualEditing?\n */\n const draftModeEnabledWarnRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)\n useEffect(() => {\n if (!draftModeEnabled) return\n clearTimeout(draftModeEnabledWarnRef.current)\n return () => {\n draftModeEnabledWarnRef.current = setTimeout(() => {\n console.warn('Sanity Live: Draft mode was enabled, but is now being disabled')\n })\n }\n }, [draftModeEnabled])\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 {draftModeEnabled && loadComlink && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n // onPerspective={setPerspectiveCookie}\n />\n )}\n {!draftModeEnabled && refreshOnMount && <RefreshOnMount />}\n {!draftModeEnabled && refreshOnFocus && <RefreshOnFocus />}\n {!draftModeEnabled && refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n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W,OAAO;;KAGtB,EAAC,QAAQ,WAAW,QAAO,CAC5B;AACD,eAAa;AACX,gBAAa,QAAQ;AACrB,cAAW,OAAO;;IAEnB,EAAE,CAAC;CAMN,MAAM,0BAA0B,OAAkD,KAAA,EAAU;AAC5F,iBAAgB;AACd,MAAI,CAAC,iBAAkB;AACvB,eAAa,wBAAwB,QAAQ;AAC7C,eAAa;AACX,2BAAwB,UAAU,iBAAiB;AACjD,YAAQ,KAAK,iEAAiE;KAC9E;;IAEH,CAAC,iBAAiB,CAAC;AAKtB,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,oBAAoB,eACnB,oBAAC,qBAAA;GACY;GACF;IAET;EAEH,CAAC,oBAAoB,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACzD,CAAC,oBAAoB,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACzD,CAAC,oBAAoB,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KACjE"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ClientPerspective, SyncTag } from "@sanity/client";
|
|
2
|
-
declare function revalidateSyncTags(tags: SyncTag[]): Promise<void>;
|
|
3
|
-
declare function setPerspectiveCookie(perspective: ClientPerspective): Promise<void>;
|
|
4
|
-
declare function expireTags(_tags: unknown): Promise<void>;
|
|
5
|
-
export { expireTags, revalidateSyncTags, setPerspectiveCookie };
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/server-actions/index.ts"],"sourcesContent":[],"mappings":";iBAUsB,kBAAA,OAAyB,YAAY;AAArC,iBAWA,oBAAA,CAXqC,WAAA,EAWH,iBAXG,CAAA,EAWiB,OAXjB,CAAA,IAAA,CAAA;AAWrC,iBAyBA,UAAA,CAzBA,KAAkC,EAAA,OAAA,CAAA,EAyBN,OAzB0B,CAAA,IAAA,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/live/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective, SyncTag} from '@sanity/client'\n\nimport {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh, revalidateTag, updateTag} from 'next/cache'\nimport {cookies} from 'next/headers'\n\nexport async function revalidateSyncTags(tags: SyncTag[]): Promise<void> {\n revalidateTag('sanity:fetch-sync-tags', 'max')\n\n for (const _tag of tags) {\n const tag = `sanity:${_tag}`\n revalidateTag(tag, {expire: 0})\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> revalidated tag: ${tag}`)\n }\n}\n\nexport async function setPerspectiveCookie(perspective: ClientPerspective): Promise<void> {\n const jar = await cookies()\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n // @TODO check if the cookie is already set, before setting it and then calling refresh()\n jar.set(\n perspectiveCookieName,\n Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(',') : sanitizedPerspective,\n {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n },\n )\n\n refresh()\n}\n\n// @TODO expose parseTags function that returns the correct array of tags\n// we already have s1: prefixes, but they could change\n// use sp: for prod, sd: for draft, keep em short\nexport async function expireTags(_tags: unknown): Promise<void> {\n // @TODO Draft Mode bypasses cache anyway so we don't bother with expiring tags for draft content\n // const isDraftMode = (await draftMode()).isEnabled\n // const tags = _tags.map((tag) => `${isDraftMode ? 'drafts' : 'sanity'}:${tag}`)\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;;;;AAUA,eAAsB,mBAAmB,MAAgC;AACvE,eAAc,0BAA0B,MAAM;AAE9C,MAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,MAAM,UAAU;AACtB,gBAAc,KAAK,EAAC,QAAQ,GAAE,CAAC;AAE/B,UAAQ,IAAI,mCAAmC,MAAM;;;AAIzD,eAAsB,qBAAqB,aAA+C;CACxF,MAAM,MAAM,MAAM,SAAS;CAC3B,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KAAI,CAAC,wBAAwB,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAClG,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;AAI9D,KAAI,IACF,uBACA,MAAM,QAAQ,qBAAqB,GAAG,qBAAqB,KAAK,IAAI,GAAG,sBACvE;EACE,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CACF;AAED,UAAS;;AAMX,eAAsB,WAAW,OAA+B;AAI9D,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
|
package/dist/live.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.d.ts","names":[],"sources":["../src/live.tsx"],"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"}
|
package/dist/live.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.js","names":[],"sources":["../src/live.tsx"],"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 './live/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"}
|
package/dist/live.next-js.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { a as DefinedFetchType, c as PerspectiveType, n as DefinedSanityFetchType, o as DefinedLiveProps, r as DefinedSanityLiveProps, s as LiveOptions, u as resolvePerspectiveFromCookies } from "./defineLive.js";
|
|
3
|
-
declare function defineLive(config: LiveOptions): {
|
|
4
|
-
fetch: DefinedFetchType;
|
|
5
|
-
Live: React.ComponentType<DefinedLiveProps>;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`
|
|
8
|
-
*/
|
|
9
|
-
sanityFetch: DefinedSanityFetchType;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`
|
|
12
|
-
*/
|
|
13
|
-
SanityLive: React.ComponentType<DefinedSanityLiveProps>;
|
|
14
|
-
};
|
|
15
|
-
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
16
|
-
//# sourceMappingURL=live.next-js.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.next-js.d.ts","names":[],"sources":["../src/experimental/live.tsx"],"sourcesContent":[],"mappings":";;iBAYgB,UAAA,SAAmB;EAAnC,KAAgB,EACP,gBADO;EAAmB,IAAA,EAE3B,KAAA,CAAM,aAFqB,CAEP,gBAFO,CAAA;EAC1B;;;EAKM,WAAA,EAAA,sBAAA;EAImB;;;cAApB,KAAA,CAAM,cAAc"}
|
package/dist/live.next-js.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { n as PUBLISHED_SYNC_TAG_PREFIX, r as revalidate, t as DRAFT_SYNC_TAG_PREFIX } from "./constants.js";
|
|
2
|
-
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
3
|
-
import { t as resolvePerspectiveFromCookies } from "./resolvePerspectiveFromCookies.js";
|
|
4
|
-
import { cookies, draftMode } from "next/headers";
|
|
5
|
-
import { Suspense } from "react";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import SanityLiveClientComponent from "next-sanity/experimental/client-components/live";
|
|
8
|
-
import { cacheLife, cacheTag } from "next/cache";
|
|
9
|
-
import { preconnect } from "react-dom";
|
|
10
|
-
function defineLive(config) {
|
|
11
|
-
const { client: _client, serverToken, browserToken } = config;
|
|
12
|
-
if (!_client) throw new Error("`client` is required for `defineLive` to function");
|
|
13
|
-
if (process.env.NODE_ENV !== "production" && !serverToken && serverToken !== false) console.warn("No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.");
|
|
14
|
-
if (process.env.NODE_ENV !== "production" && !browserToken && browserToken !== false) console.warn("No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.");
|
|
15
|
-
const client = _client.withConfig({
|
|
16
|
-
allowReconfigure: false,
|
|
17
|
-
useCdn: true
|
|
18
|
-
});
|
|
19
|
-
const { token: originalToken } = client.config();
|
|
20
|
-
return {
|
|
21
|
-
fetch: async function fetch({ query, params = {}, perspective = "published", stega = false, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
|
|
22
|
-
const useCdn = perspective === "published";
|
|
23
|
-
const { result, resultSourceMap, syncTags } = await client.fetch(query, params, {
|
|
24
|
-
filterResponse: false,
|
|
25
|
-
returnQuery: false,
|
|
26
|
-
perspective,
|
|
27
|
-
useCdn,
|
|
28
|
-
stega,
|
|
29
|
-
cacheMode: useCdn ? "noStale" : void 0,
|
|
30
|
-
tag: requestTag,
|
|
31
|
-
token: perspective === "published" ? originalToken : serverToken || originalToken
|
|
32
|
-
});
|
|
33
|
-
const tags = [...customCacheTags, ...(syncTags || []).map((tag) => `${perspective === "published" ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`)];
|
|
34
|
-
cacheTag(...tags);
|
|
35
|
-
cacheLife({ revalidate });
|
|
36
|
-
return {
|
|
37
|
-
data: result,
|
|
38
|
-
sourceMap: resultSourceMap || null,
|
|
39
|
-
tags
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
Live: function Live(props) {
|
|
43
|
-
const { perspective = "published", onChange, onChangeIncludingDrafts, onStudioPerspective, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components", onError, onGoAway, intervalOnGoAway } = props;
|
|
44
|
-
if (onChangeIncludingDrafts) console.warn("`onChangeIncludingDrafts` is not implemented yet");
|
|
45
|
-
if (onStudioPerspective) console.warn("`onStudioPerspective` is not implemented yet");
|
|
46
|
-
const includeDrafts = typeof browserToken === "string" && perspective !== "published";
|
|
47
|
-
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
48
|
-
const { origin } = new URL(client.getUrl("", false));
|
|
49
|
-
preconnect(origin);
|
|
50
|
-
return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(SanityLiveClientComponent, {
|
|
51
|
-
config: {
|
|
52
|
-
projectId,
|
|
53
|
-
dataset,
|
|
54
|
-
apiHost,
|
|
55
|
-
apiVersion,
|
|
56
|
-
useProjectHostname,
|
|
57
|
-
requestTagPrefix,
|
|
58
|
-
token: includeDrafts ? browserToken : void 0
|
|
59
|
-
},
|
|
60
|
-
requestTag,
|
|
61
|
-
draftModeEnabled: includeDrafts,
|
|
62
|
-
refreshOnMount,
|
|
63
|
-
refreshOnFocus,
|
|
64
|
-
refreshOnReconnect,
|
|
65
|
-
onError,
|
|
66
|
-
onGoAway,
|
|
67
|
-
intervalOnGoAway,
|
|
68
|
-
revalidateSyncTags: onChange,
|
|
69
|
-
resolveDraftModePerspective
|
|
70
|
-
}) });
|
|
71
|
-
},
|
|
72
|
-
sanityFetch: () => {
|
|
73
|
-
throw new Error("`defineLive().sanityFetch` is not available when `cacheComponents: true`, use `defineLive().fetch` instead");
|
|
74
|
-
},
|
|
75
|
-
SanityLive: () => {
|
|
76
|
-
throw new Error("`defineLive().SanityLive` is not available when `cacheComponents: true`, use `defineLive().Live` instead");
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async function resolveDraftModePerspective() {
|
|
81
|
-
"use server";
|
|
82
|
-
if ((await draftMode()).isEnabled) return resolvePerspectiveFromCookies({ cookies: await cookies() });
|
|
83
|
-
return "published";
|
|
84
|
-
}
|
|
85
|
-
export { defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
86
|
-
|
|
87
|
-
//# sourceMappingURL=live.next-js.js.map
|
package/dist/live.next-js.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.next-js.js","names":[],"sources":["../src/experimental/live.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, LiveOptions, PerspectiveType} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {resolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport SanityLiveClientComponent from 'next-sanity/experimental/client-components/live'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {draftMode, cookies} from 'next/headers'\nimport {Suspense} from 'react'\nimport {preconnect} from 'react-dom'\n\nimport type {DefinedSanityFetchType, DefinedSanityLiveProps} from '../live/defineLive'\n\nexport function defineLive(config: LiveOptions): {\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 const {client: _client, serverToken, browserToken} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: true})\n const {token: originalToken} = client.config()\n\n const fetch: DefinedFetchType = async function fetch({\n query,\n params = {},\n perspective = 'published',\n stega = false,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n const useCdn = perspective === 'published'\n\n const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [\n ...customCacheTags,\n ...(syncTags || []).map(\n (tag) =>\n `${perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`,\n ),\n ]\n /**\n * The tags used here, are expired later on in the `expireTags` Server Action with the `expireTag` function from `next/cache`\n */\n cacheTag(...tags)\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short,\n * userland can still set a shorter revalidate time by calling `cacheLife` themselves.\n */\n cacheLife({revalidate})\n \n\n return {data: result, sourceMap: resultSourceMap || null, tags}\n }\n\n const Live: React.ComponentType<DefinedLiveProps> = function Live(props) {\n const {\n perspective = 'published',\n onChange,\n onChangeIncludingDrafts,\n onStudioPerspective,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n onError,\n onGoAway,\n intervalOnGoAway,\n } = props\n\n if (onChangeIncludingDrafts) {\n console.warn('`onChangeIncludingDrafts` is not implemented yet')\n }\n if (onStudioPerspective) {\n console.warn('`onStudioPerspective` is not implemented yet')\n }\n\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const {origin} = new URL(client.getUrl('', false))\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n preconnect(origin)\n\n return (\n <Suspense>\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n requestTag={requestTag}\n // origin={origin}\n draftModeEnabled={includeDrafts}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n revalidateSyncTags={onChange}\n resolveDraftModePerspective={resolveDraftModePerspective}\n />\n </Suspense>\n )\n }\n\n return {\n fetch,\n Live,\n sanityFetch: () => {\n throw new Error(\n '`defineLive().sanityFetch` is not available when `cacheComponents: true`, use `defineLive().fetch` instead',\n )\n },\n SanityLive: () => {\n throw new Error(\n '`defineLive().SanityLive` is not available when `cacheComponents: true`, use `defineLive().Live` instead',\n )\n },\n }\n}\n\nasync function resolveDraftModePerspective(): Promise<PerspectiveType> {\n 'use server'\n if ((await draftMode()).isEnabled) {\n const jar = await cookies()\n return resolvePerspectiveFromCookies({cookies: jar})\n }\n return 'published'\n}\n\n// revalidateSyncTags => actionUpdateTags\n// router.refresh() => actionRefresh\n"],"mappings":";;;;;;;;;AAYA,SAAgB,WAAW,QAWzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,iBAAgB;AAErD,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAK,CAAC;CAC1E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;AAsG9C,QAAO;EACL,OArG8B,eAAe,MAAM,EACnD,OACA,SAAS,EAAE,EACX,cAAc,aACd,QAAQ,OACR,MAAM,kBAAkB,EAAE,EAC1B,aAAa,wCACZ;GACD,MAAM,SAAS,gBAAgB;GAE/B,MAAM,EAAC,QAAQ,iBAAiB,aAAY,MAAM,OAAO,MAAM,OAAO,QAAQ;IAC5E,gBAAgB;IAChB,aAAa;IACb;IACA;IACA;IACA,WAAW,SAAS,YAAY,KAAA;IAChC,KAAK;IACL,OAAO,gBAAgB,cAAc,gBAAgB,eAAe;IACrE,CAAC;GACF,MAAM,OAAO,CACX,GAAG,iBACH,IAAI,YAAY,EAAE,EAAE,KACjB,QACC,GAAG,gBAAgB,cAAc,4BAA4B,wBAAwB,MACxF,CACF;AAID,YAAS,GAAG,KAAK;AAKjB,aAAU,EAAC,YAAW,CAAC;AAGvB,UAAO;IAAC,MAAM;IAAQ,WAAW,mBAAmB;IAAM;IAAK;;EAgE/D,MA7DkD,SAAS,KAAK,OAAO;GACvE,MAAM,EACJ,cAAc,aACd,UACA,yBACA,qBACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,OACrB,aAAa,qCACb,SACA,UACA,qBACE;AAEJ,OAAI,wBACF,SAAQ,KAAK,mDAAmD;AAElE,OAAI,oBACF,SAAQ,KAAK,+CAA+C;GAG9D,MAAM,gBAAgB,OAAO,iBAAiB,YAAY,gBAAgB;GAE1E,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;GACjB,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAGlD,cAAW,OAAO;AAElB,UACE,oBAAC,UAAA,EAAA,UACC,oBAAC,2BAAA;IACC,QAAQ;KACN;KACA;KACA;KACA;KACA;KACA;KACA,OAAO,gBAAgB,eAAe,KAAA;KACvC;IACW;IAEZ,kBAAkB;IACF;IACA;IACI;IACX;IACC;IACQ;IAClB,oBAAoB;IACS;KAC7B,EAAA,CACO;;EAOb,mBAAmB;AACjB,SAAM,IAAI,MACR,6GACD;;EAEH,kBAAkB;AAChB,SAAM,IAAI,MACR,2GACD;;EAEJ;;AAGH,eAAe,8BAAwD;AACrE;AACA,MAAK,MAAM,WAAW,EAAE,UAEtB,QAAO,8BAA8B,EAAC,SAD1B,MAAM,SAAS,EACwB,CAAC;AAEtD,QAAO"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { c as PerspectiveType, i as defineLive, u as resolvePerspectiveFromCookies } from "./defineLive.js";
|
|
3
|
-
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { t as sanitizePerspective } from "./sanitizePerspective.js";
|
|
3
|
-
import { t as resolvePerspectiveFromCookies } from "./resolvePerspectiveFromCookies.js";
|
|
4
|
-
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
5
|
-
import { cookies, draftMode } from "next/headers";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
import "@sanity/client";
|
|
8
|
-
import { preconnect, prefetchDNS } from "react-dom";
|
|
9
|
-
import SanityLiveClientComponent from "next-sanity/live/client-components/live";
|
|
10
|
-
async function resolveCookiePerspective() {
|
|
11
|
-
return (await draftMode()).isEnabled ? (await cookies()).has(perspectiveCookieName) ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, "drafts") : "drafts" : "published";
|
|
12
|
-
}
|
|
13
|
-
function defineLive(config) {
|
|
14
|
-
const { client: _client, serverToken, browserToken, fetchOptions, stega: stegaEnabled = true } = config;
|
|
15
|
-
if (!_client) throw new Error("`client` is required for `defineLive` to function");
|
|
16
|
-
if (process.env.NODE_ENV !== "production" && !serverToken && serverToken !== false) console.warn("No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.");
|
|
17
|
-
if (process.env.NODE_ENV !== "production" && !browserToken && browserToken !== false) console.warn("No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.");
|
|
18
|
-
const client = _client.withConfig({
|
|
19
|
-
allowReconfigure: false,
|
|
20
|
-
useCdn: false
|
|
21
|
-
});
|
|
22
|
-
const { token: originalToken } = client.config();
|
|
23
|
-
const studioUrlDefined = typeof client.config().stega.studioUrl !== "undefined";
|
|
24
|
-
return {
|
|
25
|
-
sanityFetch: async function sanityFetch({ query, params = {}, stega: _stega, tags = ["sanity"], perspective: _perspective, tag, requestTag = tag ?? "next-loader.fetch" }) {
|
|
26
|
-
const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled);
|
|
27
|
-
const perspective = _perspective ?? await resolveCookiePerspective();
|
|
28
|
-
const useCdn = perspective === "published";
|
|
29
|
-
const revalidate = fetchOptions?.revalidate !== void 0 ? fetchOptions.revalidate : process.env.NODE_ENV === "production" ? false : void 0;
|
|
30
|
-
const { syncTags } = await client.fetch(query, await params, {
|
|
31
|
-
filterResponse: false,
|
|
32
|
-
perspective,
|
|
33
|
-
stega: false,
|
|
34
|
-
returnQuery: false,
|
|
35
|
-
next: {
|
|
36
|
-
revalidate,
|
|
37
|
-
tags: [...tags, "sanity:fetch-sync-tags"]
|
|
38
|
-
},
|
|
39
|
-
useCdn,
|
|
40
|
-
cacheMode: useCdn ? "noStale" : void 0,
|
|
41
|
-
tag: [requestTag, "fetch-sync-tags"].filter(Boolean).join(".")
|
|
42
|
-
});
|
|
43
|
-
const cacheTags = [...tags, ...syncTags?.map((tag$1) => `sanity:${tag$1}`) || []];
|
|
44
|
-
const { result, resultSourceMap } = await client.fetch(query, await params, {
|
|
45
|
-
filterResponse: false,
|
|
46
|
-
perspective,
|
|
47
|
-
stega,
|
|
48
|
-
token: perspective !== "published" && serverToken ? serverToken : originalToken,
|
|
49
|
-
next: {
|
|
50
|
-
revalidate,
|
|
51
|
-
tags: cacheTags
|
|
52
|
-
},
|
|
53
|
-
useCdn,
|
|
54
|
-
cacheMode: useCdn ? "noStale" : void 0,
|
|
55
|
-
tag: requestTag
|
|
56
|
-
});
|
|
57
|
-
return {
|
|
58
|
-
data: result,
|
|
59
|
-
sourceMap: resultSourceMap || null,
|
|
60
|
-
tags: cacheTags
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
SanityLive: async function SanityLive(props) {
|
|
64
|
-
const { refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag, onError, onGoAway, intervalOnGoAway, revalidateSyncTags } = props;
|
|
65
|
-
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
66
|
-
const { isEnabled: isDraftModeEnabled } = await draftMode();
|
|
67
|
-
const { origin } = new URL(client.getUrl("", false));
|
|
68
|
-
preconnect(origin);
|
|
69
|
-
prefetchDNS(origin);
|
|
70
|
-
return /* @__PURE__ */ jsx(SanityLiveClientComponent, {
|
|
71
|
-
projectId,
|
|
72
|
-
dataset,
|
|
73
|
-
apiHost,
|
|
74
|
-
apiVersion,
|
|
75
|
-
useProjectHostname,
|
|
76
|
-
requestTagPrefix,
|
|
77
|
-
requestTag,
|
|
78
|
-
token: typeof browserToken === "string" && isDraftModeEnabled ? browserToken : void 0,
|
|
79
|
-
draftModeEnabled: isDraftModeEnabled,
|
|
80
|
-
draftModePerspective: await resolveCookiePerspective(),
|
|
81
|
-
refreshOnMount,
|
|
82
|
-
refreshOnFocus,
|
|
83
|
-
refreshOnReconnect,
|
|
84
|
-
onError,
|
|
85
|
-
onGoAway,
|
|
86
|
-
intervalOnGoAway,
|
|
87
|
-
revalidateSyncTags
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
export { defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
93
|
-
|
|
94
|
-
//# sourceMappingURL=live.react-server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"live.react-server.js","names":["tag"],"sources":["../src/live/resolveCookiePerspective.ts","../src/live/defineLive.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\n\n/**\n * @internal\n */\nexport async function resolveCookiePerspective(): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : 'published'\n}\n","// import type {DefinedFetchType, DefinedLiveProps} from '#live/types'\n\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type LiveEventGoAway,\n type QueryParams,\n type SanityClient,\n type SyncTag,\n} from '@sanity/client'\nimport SanityLiveClientComponent from 'next-sanity/live/client-components/live'\nimport {draftMode} from 'next/headers'\nimport {prefetchDNS, preconnect} from 'react-dom'\n\nimport {resolveCookiePerspective} from './resolveCookiePerspective'\n\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefinedSanityLiveProps {\n /**\n * Automatic refresh of RSC when the component <SanityLive /> is mounted.\n * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.\n * @defaultValue `true`\n */\n refreshOnMount?: boolean\n /**\n * Automatically refresh when window gets focused\n * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.\n * @defaultValue `false` if draftMode().isEnabled, otherwise `true` if not inside an iframe\n */\n refreshOnFocus?: boolean\n /**\n * Automatically refresh when the browser regains a network connection (via navigator.onLine)\n * Note that this is different from revalidation, which is based on tags and causes `sanityFetch` calls to be re-fetched.\n * @defaultValue `true`\n */\n refreshOnReconnect?: boolean\n /**\n * Automatically refresh on an interval when the Live Event API emits a `goaway` event, which indicates that the connection is rejected or closed.\n * This typically happens if the connection limit is reached, or if the connection is idle for too long.\n * To disable this long polling fallback behavior set `intervalOnGoAway` to `false` or `0`.\n * You can also use `onGoAway` to handle the `goaway` event in your own way, and read the reason why the event was emitted.\n * @defaultValue `30_000` 30 seconds interval\n */\n intervalOnGoAway?: number | false\n\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.live'\n */\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\n /**\n * Handle the `goaway` event if the connection is rejected/closed.\n * `event.reason` will be a string of why the event was emitted, for example `'connection limit reached'`.\n * 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.\n * If you want to disable long polling set `intervalOnGoAway` to `false` or `0`.\n */\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n\n /**\n * Override how cache tags are invalidated, you need to pass a server action here.\n * You can also pass a `use client` function here, and have `router.refresh()` be called if the promise resolves to `'refresh'`.\n */\n revalidateSyncTags?: (tags: SyncTag[]) => Promise<void | 'refresh'>\n}\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedSanityLiveProps> = async function SanityLive(props) {\n const {\n // handleDraftModeAction = handleDraftModeActionMissing\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag,\n onError,\n onGoAway,\n intervalOnGoAway,\n revalidateSyncTags,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const {isEnabled: isDraftModeEnabled} = await draftMode()\n\n // Preconnect to the Live Event API origin, or at least prefetch the DNS if preconenct is not supported\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n prefetchDNS(origin)\n\n return (\n <SanityLiveClientComponent\n projectId={projectId}\n dataset={dataset}\n apiHost={apiHost}\n apiVersion={apiVersion}\n useProjectHostname={useProjectHostname}\n requestTagPrefix={requestTagPrefix}\n requestTag={requestTag}\n token={typeof browserToken === 'string' && isDraftModeEnabled ? browserToken : undefined}\n draftModeEnabled={isDraftModeEnabled}\n // handleDraftModeAction={handleDraftModeAction}\n draftModePerspective={await resolveCookiePerspective()}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n revalidateSyncTags={revalidateSyncTags}\n />\n )\n }\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n"],"mappings":";;;;;;;;;AASA,eAAsB,2BAAuE;AAC3F,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF;;AC4HN,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAM,CAAC;CAC3E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;CAC9C,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;AAuGpE,QAAO;EACL,aAtG0C,eAAe,YAEzD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,CAAC,SAAS,EACjB,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;GACD,MAAM,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;GACjF,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;GACrE,MAAM,SAAS,gBAAgB;GAC/B,MAAM,aACJ,cAAc,e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