next-sanity 13.0.0-cache-components.16 → 13.0.0-cache-components.17
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 +2 -3
- package/dist/PresentationComlink.js.map +1 -1
- package/dist/SanityLive.js +2 -3
- package/dist/SanityLive.js.map +1 -1
- package/dist/VisualEditing.js +16 -27
- package/dist/VisualEditing.js.map +1 -1
- package/dist/defineLive.d.ts +0 -7
- package/dist/defineLive.d.ts.map +1 -1
- package/dist/live/client-components/index.d.ts +3 -4
- package/dist/live/client-components/index.d.ts.map +1 -1
- package/dist/live/client-components/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +2 -3
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.js +2 -3
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/live/server-actions/index.default.d.ts +1 -6
- package/dist/live/server-actions/index.default.d.ts.map +1 -1
- package/dist/live/server-actions/index.default.js +2 -22
- package/dist/live/server-actions/index.default.js.map +1 -1
- package/dist/live/server-actions/index.next-js.d.ts +1 -6
- package/dist/live/server-actions/index.next-js.d.ts.map +1 -1
- package/dist/live/server-actions/index.next-js.js +2 -16
- package/dist/live/server-actions/index.next-js.js.map +1 -1
- package/dist/visual-editing/client-component/index.d.ts +2 -2
- package/dist/visual-editing/client-component/index.d.ts.map +1 -1
- package/dist/visual-editing/client-component/index.js +3 -10
- package/dist/visual-editing/client-component/index.js.map +1 -1
- package/dist/visual-editing/index.d.ts.map +1 -1
- package/dist/visual-editing/index.js +4 -2
- package/dist/visual-editing/index.js.map +1 -1
- package/dist/visual-editing/server-actions/index.d.ts +11 -2
- package/dist/visual-editing/server-actions/index.d.ts.map +1 -1
- package/dist/visual-editing/server-actions/index.js +22 -7
- package/dist/visual-editing/server-actions/index.js.map +1 -1
- package/package.json +13 -4
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { f as setPerspective, l as setComlink, u as setComlinkClientConfig } from "./context.js";
|
|
2
2
|
import { t as sanitizePerspective } from "./sanitizePerspective.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useEffectEvent } from "react";
|
|
4
4
|
import { createNode, createNodeMachine } from "@sanity/comlink";
|
|
5
5
|
import { createCompatibilityActors } from "@sanity/presentation-comlink";
|
|
6
6
|
function PresentationComlink(props) {
|
|
7
|
-
const { projectId, dataset
|
|
7
|
+
const { projectId, dataset } = props;
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
setComlinkClientConfig(projectId, dataset);
|
|
10
10
|
}, [dataset, projectId]);
|
|
11
11
|
const handlePerspectiveChange = useEffectEvent((perspective) => {
|
|
12
12
|
setPerspective(sanitizePerspective(perspective, "drafts"));
|
|
13
|
-
startTransition(() => onPerspective(perspective));
|
|
14
13
|
});
|
|
15
14
|
useEffect(() => {
|
|
16
15
|
const controller = new AbortController();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresentationComlink.js","names":[],"sources":["../src/live/client-components/PresentationComlink.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {setComlink, setComlinkClientConfig, setPerspective} from '#live/context'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {createNode, createNodeMachine} from '@sanity/comlink'\nimport {\n createCompatibilityActors,\n type LoaderControllerMsg,\n type LoaderNodeMsg,\n} from '@sanity/presentation-comlink'\nimport {
|
|
1
|
+
{"version":3,"file":"PresentationComlink.js","names":[],"sources":["../src/live/client-components/PresentationComlink.tsx"],"sourcesContent":["import type {ClientPerspective} from '@sanity/client'\n\nimport {setComlink, setComlinkClientConfig, setPerspective} from '#live/context'\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {createNode, createNodeMachine} from '@sanity/comlink'\nimport {\n createCompatibilityActors,\n type LoaderControllerMsg,\n type LoaderNodeMsg,\n} from '@sanity/presentation-comlink'\nimport {useEffect, useEffectEvent} from 'react'\n\nexport default function PresentationComlink(props: {\n projectId: string\n dataset: string\n}): React.JSX.Element | null {\n const {projectId, dataset} = props\n\n useEffect(() => {\n setComlinkClientConfig(projectId, dataset)\n }, [dataset, projectId])\n\n const handlePerspectiveChange = useEffectEvent((perspective: ClientPerspective) => {\n setPerspective(sanitizePerspective(perspective, 'drafts'))\n })\n\n useEffect(() => {\n const controller = new AbortController()\n const comlink = createNode<LoaderNodeMsg, LoaderControllerMsg>(\n {name: 'loaders', connectTo: 'presentation'},\n createNodeMachine<LoaderNodeMsg, LoaderControllerMsg>().provide({\n actors: createCompatibilityActors<LoaderNodeMsg>(),\n }),\n )\n\n comlink.on('loader/perspective', (data) => {\n if (controller.signal.aborted) return\n\n handlePerspectiveChange(data.perspective)\n })\n\n const stop = comlink.start()\n setComlink(comlink)\n return () => {\n stop()\n controller.abort()\n }\n }, [])\n\n return null\n}\n\nPresentationComlink.displayName = 'PresentationComlink'\n"],"mappings":";;;;;AAYA,SAAwB,oBAAoB,OAGf;CAC3B,MAAM,EAAC,WAAW,YAAW;AAE7B,iBAAgB;AACd,yBAAuB,WAAW,QAAQ;IACzC,CAAC,SAAS,UAAU,CAAC;CAExB,MAAM,0BAA0B,gBAAgB,gBAAmC;AACjF,iBAAe,oBAAoB,aAAa,SAAS,CAAC;GAC1D;AAEF,iBAAgB;EACd,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,UAAU,WACd;GAAC,MAAM;GAAW,WAAW;GAAe,EAC5C,mBAAuD,CAAC,QAAQ,EAC9D,QAAQ,2BAA0C,EACnD,CAAC,CACH;AAED,UAAQ,GAAG,uBAAuB,SAAS;AACzC,OAAI,WAAW,OAAO,QAAS;AAE/B,2BAAwB,KAAK,YAAY;IACzC;EAEF,MAAM,OAAO,QAAQ,OAAO;AAC5B,aAAW,QAAQ;AACnB,eAAa;AACX,SAAM;AACN,cAAW,OAAO;;IAEnB,EAAE,CAAC;AAEN,QAAO;;AAGT,oBAAoB,cAAc"}
|
package/dist/SanityLive.js
CHANGED
|
@@ -20,7 +20,7 @@ function handleOnGoAway(event, intervalOnGoAway) {
|
|
|
20
20
|
else console.error("Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:", event.reason);
|
|
21
21
|
}
|
|
22
22
|
function SanityLive(props) {
|
|
23
|
-
const { config, onLiveEvent,
|
|
23
|
+
const { config, onLiveEvent, perspective, refreshOnMount = false, refreshOnFocus = perspective !== "published" ? false : typeof window === "undefined" ? true : window.self === window.top, refreshOnReconnect = true, intervalOnGoAway = 3e4, requestTag, onError = handleError, onGoAway = handleOnGoAway } = props;
|
|
24
24
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix } = config;
|
|
25
25
|
const client = useMemo(() => createClient({
|
|
26
26
|
projectId,
|
|
@@ -99,8 +99,7 @@ function SanityLive(props) {
|
|
|
99
99
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
100
100
|
loadComlink && /* @__PURE__ */ jsx(PresentationComlink, {
|
|
101
101
|
projectId,
|
|
102
|
-
dataset
|
|
103
|
-
onPerspective: onPresentationPerspective
|
|
102
|
+
dataset
|
|
104
103
|
}),
|
|
105
104
|
refreshOnMount && /* @__PURE__ */ jsx(RefreshOnMount, {}),
|
|
106
105
|
refreshOnFocus && /* @__PURE__ */ jsx(RefreshOnFocus, {}),
|
package/dist/SanityLive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {setEnvironment} from '#live/context'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useState, useEffectEvent} from 'react'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\n/**\n * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport interface SanityLiveProps {\n config: SanityClientConfig\n /**\n * Setting this to 'published' opens one live event connection, setting it to any other value opens both the live event connections if needed\n */\n perspective: Exclude<ClientPerspective, 'raw'>\n\n onLiveEvent: (tags: string[]) => Promise<void | 'refresh'>\n onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | 'refresh'>\n onPresentationPerspective: (perspective: ClientPerspective) => Promise<void>\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string\n\n /**\n * Handle errors from the Live Events subscription.\n * By default it's reported using `console.error`, you can override this prop to handle it in your own way.\n */\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n}\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n onLiveEvent,\n // onLiveEventIncludingDrafts,\n onPresentationPerspective,\n perspective,\n\n refreshOnMount = false,\n refreshOnFocus = perspective !== 'published'\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag,\n onError = handleError,\n onGoAway = handleOnGoAway,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n const [longPollingInterval, setLongPollingInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : perspective === 'published'\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setLongPollingInterval(false)\n } else if (event.type === 'message') {\n void onLiveEvent(\n event.tags.map((tag: SyncTag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}` as const),\n ).then((result) => {\n if (result === 'refresh') router.refresh()\n })\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n router.refresh()\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n setLongPollingInterval(intervalOnGoAway)\n }\n })\n useEffect(() => {\n const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n // console.error('What?', err)\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n const [loadComlink, setLoadComlink] = useState(false)\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n clearTimeout(timeout)\n setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 6. Handle switching to long polling when needed\n */\n useEffect(() => {\n if (!longPollingInterval) return\n const interval = setInterval(() => router.refresh(), longPollingInterval)\n return () => clearInterval(interval)\n }, [longPollingInterval, router])\n\n return (\n <>\n {loadComlink && (\n <PresentationComlink\n projectId={projectId!}\n dataset={dataset!}\n onPerspective={onPresentationPerspective}\n />\n )}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;;;;;AAgBA,MAAM,sBAAsB,cAAc,OAAO,4BAAyB;AAC1E,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;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+
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import {PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {setEnvironment} from '#live/context'\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {\n createClient,\n type ClientPerspective,\n type InitializedClientConfig,\n type LiveEvent,\n type LiveEventGoAway,\n type SyncTag,\n} from '@sanity/client'\nimport {isMaybePresentation, isMaybePreviewWindow} from '@sanity/presentation-comlink'\nimport dynamic from 'next/dynamic'\nimport {useRouter} from 'next/navigation'\nimport {useEffect, useMemo, useState, useEffectEvent} from 'react'\n\nconst PresentationComlink = dynamic(() => import('./PresentationComlink'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n /**\n * Setting this to 'published' opens one live event connection, setting it to any other value opens both the live event connections if needed\n */\n perspective: Exclude<ClientPerspective, 'raw'>\n\n onLiveEvent: (tags: string[]) => Promise<void | 'refresh'>\n onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | 'refresh'>\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n requestTag: string\n\n /**\n * Handle errors from the Live Events subscription.\n * By default it's reported using `console.error`, you can override this prop to handle it in your own way.\n */\n onError?: (error: unknown) => void\n intervalOnGoAway?: number | false\n onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void\n}\n\nfunction handleError(error: unknown) {\n if (isCorsOriginError(error)) {\n console.warn(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.`,\n error.addOriginUrl && `Add it here:`,\n error.addOriginUrl?.toString(),\n )\n } else {\n console.error(error)\n }\n}\n\nfunction handleOnGoAway(event: LiveEventGoAway, intervalOnGoAway: number | false) {\n if (intervalOnGoAway) {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n intervalOnGoAway / 1000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n } else {\n console.error(\n 'Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason:',\n event.reason,\n )\n }\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n onLiveEvent,\n // onLiveEventIncludingDrafts,\n perspective,\n\n refreshOnMount = false,\n refreshOnFocus = perspective !== 'published'\n ? false\n : typeof window === 'undefined'\n ? true\n : window.self === window.top,\n refreshOnReconnect = true,\n intervalOnGoAway = 30_000,\n requestTag,\n onError = handleError,\n onGoAway = handleOnGoAway,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n const [longPollingInterval, setLongPollingInterval] = useState<number | false>(false)\n\n /**\n * 1. Handle Live Events and call revalidateTag or router.refresh when needed\n */\n const router = useRouter()\n const handleLiveEvent = useEffectEvent((event: LiveEvent) => {\n if (process.env.NODE_ENV !== 'production' && event.type === 'welcome') {\n // oxlint-disable-next-line no-console\n console.info(\n 'Sanity is live with',\n token\n ? 'automatic revalidation for draft content changes as well as published content'\n : perspective === 'published'\n ? 'automatic revalidation for only published content. Provide a `browserToken` to `defineLive` to support draft content outside of Presentation Tool.'\n : 'automatic revalidation of published content',\n )\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setLongPollingInterval(false)\n } else if (event.type === 'message') {\n void onLiveEvent(\n event.tags.map((tag: SyncTag) => `${PUBLISHED_SYNC_TAG_PREFIX}${tag}` as const),\n ).then((result) => {\n if (result === 'refresh') router.refresh()\n })\n } else if (event.type === 'restart' || event.type === 'reconnect') {\n router.refresh()\n } else if (event.type === 'goaway') {\n onGoAway(event, intervalOnGoAway)\n setLongPollingInterval(intervalOnGoAway)\n }\n })\n useEffect(() => {\n const subscription = client.live.events({includeDrafts: !!token, tag: requestTag}).subscribe({\n next: handleLiveEvent,\n error: (err: unknown) => {\n // console.error('What?', err)\n onError(err)\n },\n })\n return () => subscription.unsubscribe()\n }, [client.live, onError, requestTag, token])\n\n const [loadComlink, setLoadComlink] = useState(false)\n\n /**\n * 4. If Presentation Tool is detected, load up the comlink and integrate with it\n */\n useEffect(() => {\n if (!isMaybePresentation()) return\n const controller = new AbortController()\n // Wait for a while to see if Presentation Tool is detected, before assuming the env to be stand-alone live preview\n const timeout = setTimeout(() => setEnvironment('live'), 3_000)\n window.addEventListener(\n 'message',\n ({data}: MessageEvent<unknown>) => {\n if (\n data &&\n typeof data === 'object' &&\n 'domain' in data &&\n data.domain === 'sanity/channels' &&\n 'from' in data &&\n data.from === 'presentation'\n ) {\n clearTimeout(timeout)\n setEnvironment(isMaybePreviewWindow() ? 'presentation-window' : 'presentation-iframe')\n setLoadComlink(true)\n controller.abort()\n }\n },\n {signal: controller.signal},\n )\n return () => {\n clearTimeout(timeout)\n controller.abort()\n }\n }, [])\n\n /**\n * 6. Handle switching to long polling when needed\n */\n useEffect(() => {\n if (!longPollingInterval) return\n const interval = setInterval(() => router.refresh(), longPollingInterval)\n return () => clearInterval(interval)\n }, [longPollingInterval, router])\n\n return (\n <>\n {loadComlink && <PresentationComlink projectId={projectId!} dataset={dataset!} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n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AAY;EAChF,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc;AAEzB,IAAA,qBAAe"}
|
package/dist/VisualEditing.js
CHANGED
|
@@ -2,7 +2,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { VisualEditing as VisualEditing$1 } from "@sanity/visual-editing/react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import {
|
|
5
|
+
import { actionRefresh } from "next-sanity/visual-editing/server-actions";
|
|
6
6
|
function pathHasPrefix(path, prefix) {
|
|
7
7
|
if (typeof path !== "string") return false;
|
|
8
8
|
const { pathname } = parsePath(path);
|
|
@@ -47,7 +47,7 @@ function removeTrailingSlash(route) {
|
|
|
47
47
|
return route.replace(/\/$/, "") || "/";
|
|
48
48
|
}
|
|
49
49
|
function VisualEditing(props) {
|
|
50
|
-
const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex } = props;
|
|
50
|
+
const { basePath = "", plugins, components, refresh, trailingSlash = false, zIndex, onPerspectiveChange } = props;
|
|
51
51
|
const router = useRouter();
|
|
52
52
|
const routerRef = useRef(router);
|
|
53
53
|
const [navigate, setNavigate] = useState();
|
|
@@ -82,39 +82,28 @@ function VisualEditing(props) {
|
|
|
82
82
|
searchParams,
|
|
83
83
|
trailingSlash
|
|
84
84
|
]);
|
|
85
|
+
const handleRefresh = useCallback((payload) => {
|
|
86
|
+
switch (payload.source) {
|
|
87
|
+
case "manual": return actionRefresh(payload);
|
|
88
|
+
case "mutation":
|
|
89
|
+
if (payload.livePreviewEnabled) {
|
|
90
|
+
console.debug("Live preview is setup, mutation is skipped assuming its handled by the live preview");
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return actionRefresh(payload);
|
|
94
|
+
default: throw new Error("Unknown refresh source", { cause: payload });
|
|
95
|
+
}
|
|
96
|
+
}, []);
|
|
85
97
|
return /* @__PURE__ */ jsx(VisualEditing$1, {
|
|
86
98
|
plugins,
|
|
87
99
|
components,
|
|
88
100
|
history,
|
|
89
101
|
portal: true,
|
|
90
|
-
refresh:
|
|
91
|
-
|
|
92
|
-
const manualFastRefresh = () => {
|
|
93
|
-
console.debug("Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data");
|
|
94
|
-
routerRef.current.refresh();
|
|
95
|
-
return Promise.resolve();
|
|
96
|
-
};
|
|
97
|
-
const manualFallbackRefresh = () => {
|
|
98
|
-
console.debug("No loaders in live mode detected, or preview kit setup, revalidating root layout");
|
|
99
|
-
return revalidateRootLayout();
|
|
100
|
-
};
|
|
101
|
-
const mutationFallbackRefresh = () => {
|
|
102
|
-
console.debug("No loaders in live mode detected, or preview kit setup, revalidating root layout");
|
|
103
|
-
return revalidateRootLayout();
|
|
104
|
-
};
|
|
105
|
-
switch (payload.source) {
|
|
106
|
-
case "manual": return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh();
|
|
107
|
-
case "mutation": return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh();
|
|
108
|
-
default: throw new Error("Unknown refresh source", { cause: payload });
|
|
109
|
-
}
|
|
110
|
-
}, [refresh]),
|
|
102
|
+
refresh: refresh ?? handleRefresh,
|
|
103
|
+
onPerspectiveChange,
|
|
111
104
|
zIndex
|
|
112
105
|
});
|
|
113
106
|
}
|
|
114
|
-
function mutationFastRefresh() {
|
|
115
|
-
console.debug("Live preview is setup, mutation is skipped assuming its handled by the live preview");
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
107
|
export { VisualEditing as default };
|
|
119
108
|
|
|
120
109
|
//# sourceMappingURL=VisualEditing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualEditing.js","names":["VisualEditingComponent"],"sources":["../src/visual-editing/client-component/utils.ts","../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {basePath = '', plugins, components, refresh, trailingSlash = false, zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type`, {cause: update})\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(\n `${pathname}${searchParams?.size ? `?${searchParams.toString()}` : ''}`,\n basePath,\n ),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback(\n (payload: HistoryRefresh) => {\n if (refresh) return refresh(payload)\n\n const manualFastRefresh = () => {\n // oxlint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data',\n )\n routerRef.current.refresh()\n return Promise.resolve()\n }\n const manualFallbackRefresh = () => {\n // oxlint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n const mutationFallbackRefresh = () => {\n // oxlint-disable-next-line no-console\n console.debug(\n 'No loaders in live mode detected, or preview kit setup, revalidating root layout',\n )\n return revalidateRootLayout()\n }\n\n switch (payload.source) {\n case 'manual':\n return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh()\n case 'mutation':\n return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh()\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n },\n [refresh],\n )\n\n return (\n <VisualEditingComponent\n plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={handleRefresh}\n zIndex={zIndex}\n />\n )\n}\n\nfunction mutationFastRefresh(): false {\n // oxlint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n}\n"],"mappings":";;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,KAAI,OAAO,SAAS,SAClB,QAAO;CAGT,MAAM,EAAC,aAAY,UAAU,KAAK;AAClC,QAAO,aAAa,UAAU,S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WAAQ,QAAQ,QAAhB;IACE,KAAK,SACH,QAAO,QAAQ,qBAAqB,mBAAmB,GAAG,uBAAuB;IACnF,KAAK,WACH,QAAO,QAAQ,qBAAqB,qBAAqB,GAAG,yBAAyB;IACvF,QACE,OAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ,CAAC;;KAGjE,CAAC,QAAQ,CACV;EASW;GACR;;AAIN,SAAS,sBAA6B;AAEpC,SAAQ,MACN,sFACD;AACD,QAAO"}
|
|
1
|
+
{"version":3,"file":"VisualEditing.js","names":["VisualEditingComponent"],"sources":["../src/visual-editing/client-component/utils.ts","../src/visual-editing/client-component/VisualEditing.tsx"],"sourcesContent":["/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/path-has-prefix.ts#L10-L17\n * Checks if a given path starts with a given prefix. It ensures it matches\n * exactly without containing extra chars. e.g. prefix /docs should replace\n * for /docs, /docs/, /docs/a but not /docsss\n * @param path The path to check.\n * @param prefix The prefix to check against.\n */\nfunction pathHasPrefix(path: string, prefix: string): boolean {\n if (typeof path !== 'string') {\n return false\n }\n\n const {pathname} = parsePath(path)\n return pathname === prefix || pathname.startsWith(`${prefix}/`)\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/parse-path.ts#L6-L22\n * Given a path this function will find the pathname, query and hash and return\n * them. This is useful to parse full paths on the client side.\n * @param path A path to parse e.g. /foo/bar?id=1#hash\n */\nfunction parsePath(path: string): {\n pathname: string\n query: string\n hash: string\n} {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex)\n\n if (hasQuery || hashIndex > -1) {\n return {\n pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),\n query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : undefined) : '',\n hash: hashIndex > -1 ? path.slice(hashIndex) : '',\n }\n }\n\n return {pathname: path, query: '', hash: ''}\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/add-path-prefix.ts#L3C1-L14C2\n * Adds the provided prefix to the given path. It first ensures that the path\n * is indeed starting with a slash.\n */\nexport function addPathPrefix(path: string, prefix?: string): string {\n if (!path.startsWith('/') || !prefix) {\n return path\n }\n // If the path is exactly '/' then return just the prefix\n if (path === '/' && prefix) {\n return prefix\n }\n\n const {pathname, query, hash} = parsePath(path)\n return `${prefix}${pathname}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/5469e6427b54ab7e9876d4c85b47f9c3afdc5c1f/packages/next/src/shared/lib/router/utils/remove-path-prefix.ts#L3-L39\n * Given a path and a prefix it will remove the prefix when it exists in the\n * given path. It ensures it matches exactly without containing extra chars\n * and if the prefix is not there it will be noop.\n *\n * @param path The path to remove the prefix from.\n * @param prefix The prefix to be removed.\n */\nexport function removePathPrefix(path: string, prefix: string): string {\n // If the path doesn't start with the prefix we can return it as is. This\n // protects us from situations where the prefix is a substring of the path\n // prefix such as:\n //\n // For prefix: /blog\n //\n // /blog -> true\n // /blog/ -> true\n // /blog/1 -> true\n // /blogging -> false\n // /blogging/ -> false\n // /blogging/1 -> false\n if (!pathHasPrefix(path, prefix)) {\n return path\n }\n\n // Remove the prefix from the path via slicing.\n const withoutPrefix = path.slice(prefix.length)\n\n // If the path without the prefix starts with a `/` we can return it as is.\n if (withoutPrefix.startsWith('/')) {\n return withoutPrefix\n }\n\n // If the path without the prefix doesn't start with a `/` we need to add it\n // back to the path to make sure it's a valid path.\n return `/${withoutPrefix}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/client/normalize-trailing-slash.ts#L16\n * Normalizes the trailing slash of a path according to the `trailingSlash` option\n * in `next.config.js`.\n */\nexport const normalizePathTrailingSlash = (path: string, trailingSlash: boolean): string => {\n const {pathname, query, hash} = parsePath(path)\n if (trailingSlash) {\n if (pathname.endsWith('/')) {\n return `${pathname}${query}${hash}`\n }\n return `${pathname}/${query}${hash}`\n }\n\n return `${removeTrailingSlash(pathname)}${query}${hash}`\n}\n\n/**\n * From: https://github.com/vercel/next.js/blob/dfe7fc03e2268e7cb765dce6a89e02c831c922d5/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L8\n * Removes the trailing slash for a given route or page path. Preserves the\n * root page. Examples:\n * - `/foo/bar/` -> `/foo/bar`\n * - `/foo/bar` -> `/foo/bar`\n * - `/` -> `/`\n */\nfunction removeTrailingSlash(route: string) {\n return route.replace(/\\/$/, '') || '/'\n}\n","import {\n type HistoryAdapter,\n type HistoryAdapterNavigate,\n type HistoryRefresh,\n VisualEditing as VisualEditingComponent,\n type VisualEditingOptions,\n} from '@sanity/visual-editing/react'\nimport {actionRefresh} from 'next-sanity/visual-editing/server-actions'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation'\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react'\n\nimport {addPathPrefix, normalizePathTrailingSlash, removePathPrefix} from './utils'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n /**\n * If next.config.ts is configured with a basePath we try to configure it automatically,\n * you can disable this by setting basePath to ''.\n * @example basePath=\"/my-custom-base-path\"\n * @alpha experimental and may change without notice\n * @defaultValue process.env.__NEXT_ROUTER_BASEPATH || ''\n */\n basePath?: string\n /**\n * If next.config.ts is configured with a `trailingSlash` we try to detect it automatically,\n * it can be controlled manually by passing a boolean.\n * @example trailingSlash={true}\n * @alpha experimental and may change without notice\n * @defaultValue Boolean(process.env.__NEXT_TRAILING_SLASH)\n */\n trailingSlash?: boolean\n}\n\nexport default function VisualEditing(props: VisualEditingProps): React.JSX.Element | null {\n const {\n basePath = '',\n plugins,\n components,\n refresh,\n trailingSlash = false,\n zIndex,\n onPerspectiveChange,\n } = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n\n const history = useMemo<HistoryAdapter>(\n () => ({\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(removePathPrefix(update.url, basePath))\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(removePathPrefix(update.url, basePath))\n default:\n throw new Error(`Unknown update type`, {cause: update})\n }\n },\n }),\n [basePath],\n )\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: normalizePathTrailingSlash(\n addPathPrefix(\n `${pathname}${searchParams?.size ? `?${searchParams.toString()}` : ''}`,\n basePath,\n ),\n trailingSlash,\n ),\n })\n }\n }, [basePath, navigate, pathname, searchParams, trailingSlash])\n\n const handleRefresh = useCallback((payload: HistoryRefresh): false | Promise<void> => {\n switch (payload.source) {\n case 'manual':\n return actionRefresh(payload)\n case 'mutation': {\n if (payload.livePreviewEnabled) {\n // oxlint-disable-next-line no-console\n console.debug(\n 'Live preview is setup, mutation is skipped assuming its handled by the live preview',\n )\n return false\n }\n return actionRefresh(payload)\n }\n default:\n throw new Error('Unknown refresh source', {cause: payload})\n }\n }, [])\n\n return (\n <VisualEditingComponent\n plugins={plugins}\n components={components}\n history={history}\n portal\n refresh={refresh ?? handleRefresh}\n onPerspectiveChange={onPerspectiveChange}\n zIndex={zIndex}\n />\n )\n}\n"],"mappings":";;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,KAAI,OAAO,SAAS,SAClB,QAAO;CAGT,MAAM,EAAC,aAAY,UAAU,KAAK;AAClC,QAAO,aAAa,UAAU,SAAS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ACR"}
|
package/dist/defineLive.d.ts
CHANGED
|
@@ -66,13 +66,6 @@ interface DefinedLiveProps {
|
|
|
66
66
|
*/
|
|
67
67
|
perspective?: PerspectiveType;
|
|
68
68
|
/**
|
|
69
|
-
* TODO: If Presentation Tool is present this event will fire with the current `perspective` stack used in the
|
|
70
|
-
* Sanity Studio global perspective menu. The default event handler will store this state in a cookie,
|
|
71
|
-
* which can be read with `resolvePerspectiveFromCookies` and used to ensure data fetching in the preview
|
|
72
|
-
* matches the perspective and content viewed in the Studio, allowing you to quickly switch and preview different perspectives.
|
|
73
|
-
*/
|
|
74
|
-
onStudioPerspective?: (perspective: ClientPerspective$1) => Promise<void>;
|
|
75
|
-
/**
|
|
76
69
|
* Automatic refresh of RSC when the component <SanityLive /> is mounted.
|
|
77
70
|
* @defaultValue `false`
|
|
78
71
|
*/
|
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/shared/types.ts","../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":[],"mappings":";;;KAOY,6BAAA;;AAAZ;;;;;;;;AAkBA;EACW,OAAA,EARA,OAQA,CARQ,UAQR,CAAA,OAR0B,OAQ1B,CAAA,CAAA;CAE0B,EAAA,GAT/B,OAS+B,CATvB,OASuB,CATf,iBASe,EAAA,KAAA,CAAA,CAAA;;;;;AACjC,cAJS,6BAIT,EAAA,CAAA;EAAA,OAAA,EAHO;CAGP,EAAA;EAAA,OAAA,EADO,OACP,CADe,UACf,CAAA,OADiC,OACjC,CAAA,CAAA;MAAA,QAAQ,QAAQ;;;;AAtBpB;AAWqC,KCJzB,eAAA,GAAkB,ODIO,CCJC,mBDID,EAAA,KAAA,CAAA;;;;AACvB,KCAF,gBAAA,GDAE,CAAA,0BAAA,MAAA,CAAA,CAAA,OAAA,EAAA;EAAR,KAAA,ECCG,WDDH;EAAA,MAAA,CAAA,ECEK,aDFL;EAMN;;;EAGmB,WAAA,CAAA,ECHH,eDGG;EAAR;;;;EACP,KAAA,CAAA,EAAA,OAAA;;ACfJ;AAKA;;EAEW,IAAA,CAAA,EAAA,MAAA,EAAA;EAIK;;;;;EAiBV,UAAA,CAAA,EAAA,MAAA;AAMN,CAAA,EAAA,GANM,OAMW,CAAA;EAKD,IAAA,EAVR,cAUQ,CAVK,WAUL,EAAA,OAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/shared/types.ts","../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":[],"mappings":";;;KAOY,6BAAA;;AAAZ;;;;;;;;AAkBA;EACW,OAAA,EARA,OAQA,CARQ,UAQR,CAAA,OAR0B,OAQ1B,CAAA,CAAA;CAE0B,EAAA,GAT/B,OAS+B,CATvB,OASuB,CATf,iBASe,EAAA,KAAA,CAAA,CAAA;;;;;AACjC,cAJS,6BAIT,EAAA,CAAA;EAAA,OAAA,EAHO;CAGP,EAAA;EAAA,OAAA,EADO,OACP,CADe,UACf,CAAA,OADiC,OACjC,CAAA,CAAA;MAAA,QAAQ,QAAQ;;;;AAtBpB;AAWqC,KCJzB,eAAA,GAAkB,ODIO,CCJC,mBDID,EAAA,KAAA,CAAA;;;;AACvB,KCAF,gBAAA,GDAE,CAAA,0BAAA,MAAA,CAAA,CAAA,OAAA,EAAA;EAAR,KAAA,ECCG,WDDH;EAAA,MAAA,CAAA,ECEK,aDFL;EAMN;;;EAGmB,WAAA,CAAA,ECHH,eDGG;EAAR;;;;EACP,KAAA,CAAA,EAAA,OAAA;;ACfJ;AAKA;;EAEW,IAAA,CAAA,EAAA,MAAA,EAAA;EAIK;;;;;EAiBV,UAAA,CAAA,EAAA,MAAA;AAMN,CAAA,EAAA,GANM,OAMW,CAAA;EAKD,IAAA,EAVR,cAUQ,CAVK,WAUL,EAAA,OAAA,CAAA;EA6CK,SAAA,EAtDR,k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BARJ,UAAA,SAAmB;;;;eAIpB;;;;cAID,KAAA,CAAM,cAAc"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { ClientPerspective, InitializedClientConfig, LiveEventGoAway } from "@sanity/client";
|
|
2
2
|
interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
|
|
3
|
-
/**
|
|
4
|
-
* @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
|
|
5
|
-
*/
|
|
6
3
|
interface SanityLiveProps {
|
|
7
4
|
config: SanityClientConfig;
|
|
8
5
|
/**
|
|
@@ -11,7 +8,6 @@ interface SanityLiveProps {
|
|
|
11
8
|
perspective: Exclude<ClientPerspective, "raw">;
|
|
12
9
|
onLiveEvent: (tags: string[]) => Promise<void | "refresh">;
|
|
13
10
|
onLiveEventIncludingDrafts: (tags: string[]) => Promise<void | "refresh">;
|
|
14
|
-
onPresentationPerspective: (perspective: ClientPerspective) => Promise<void>;
|
|
15
11
|
refreshOnMount?: boolean;
|
|
16
12
|
refreshOnFocus?: boolean;
|
|
17
13
|
refreshOnReconnect?: boolean;
|
|
@@ -24,6 +20,9 @@ interface SanityLiveProps {
|
|
|
24
20
|
intervalOnGoAway?: number | false;
|
|
25
21
|
onGoAway?: (event: LiveEventGoAway, intervalOnGoAway: number | false) => void;
|
|
26
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.
|
|
25
|
+
*/
|
|
27
26
|
declare const SanityLive: React.ComponentType<SanityLiveProps>;
|
|
28
27
|
export { SanityLive };
|
|
29
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";UAqBU,kBAAA,SAA2B,KACnC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/live/client-components/SanityLive.tsx","../../../src/live/client-components/index.ts"],"sourcesContent":[],"mappings":";UAqBU,kBAAA,SAA2B,KACnC;AADQ,UAWO,eAAA,CAXP;EAWV,MAAiB,EACP,kBADO;EACP;;;EAMyB,WAAA,EAFpB,OAEoB,CAFZ,iBAEY,EAAA,KAAA,CAAA;EACe,WAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GADf,OACe,CAAA,IAAA,GAAA,SAAA,CAAA;EAa7B,0BAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,EAAA,GAb6B,OAa7B,CAAA,IAAA,GAAA,SAAA,CAAA;EAAA,cAAA,CAAA,EAAA,OAAA;;EC7CrB,kBAA6C,CAAA,EAAA,OAAA;;;;;;;;qBD6CxB;;;AA3Cd;AAsBP;AACU,cCzBG,UDyBH,ECzBe,KAAA,CAAM,aDyBrB,CCzBmC,eDyBnC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/live/client-components/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {SanityLiveProps} from './SanityLive'\n/**\n * @alpha CAUTION: this is an internal component and does not follow semver. Using it directly is at your own risk.\n */\nexport const SanityLive: React.ComponentType<SanityLiveProps> = dynamic(\n () => import('./SanityLive'),\n {ssr: false},\n)\n"],"mappings":";;AAQA,MAAa,aAAmD,cACxD,OAAO,wBACb,EAAC,KAAK,OAAM,CACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":[],"mappings":";;iBAWgB,UAAA,SAAmB;EAAnC,WAAgB,EACD,sBADC;EAAmB,UAAA,EAErB,KAAA,CAAM,aAFe,CAED,sBAFC,CAAA;CACpB"}
|
|
@@ -4,7 +4,7 @@ import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveF
|
|
|
4
4
|
import { Suspense } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
7
|
-
import { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
7
|
+
import { actionLiveEvent, actionLiveEventIncludingDrafts } from "next-sanity/live/server-actions";
|
|
8
8
|
import { cacheLife, cacheTag } from "next/cache";
|
|
9
9
|
import { preconnect } from "react-dom";
|
|
10
10
|
function defineLive(config) {
|
|
@@ -39,7 +39,7 @@ function defineLive(config) {
|
|
|
39
39
|
};
|
|
40
40
|
};
|
|
41
41
|
const Live = function Live$1(props) {
|
|
42
|
-
const { perspective = "published", onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts,
|
|
42
|
+
const { perspective = "published", onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, refreshOnMount = false, refreshOnFocus = false, refreshOnReconnect = false, requestTag = "next-loader.live.cache-components", onError, onGoAway, intervalOnGoAway } = props;
|
|
43
43
|
const includeDrafts = typeof browserToken === "string" && perspective !== "published";
|
|
44
44
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
45
45
|
const { origin } = new URL(client.getUrl("", false));
|
|
@@ -57,7 +57,6 @@ function defineLive(config) {
|
|
|
57
57
|
perspective,
|
|
58
58
|
onLiveEvent: onChange,
|
|
59
59
|
onLiveEventIncludingDrafts: onChangeIncludingDrafts,
|
|
60
|
-
onPresentationPerspective: onStudioPerspective,
|
|
61
60
|
requestTag,
|
|
62
61
|
refreshOnMount,
|
|
63
62
|
refreshOnFocus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fetch","Live","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, LiveOptions} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["fetch","Live","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, LiveOptions} from '#live/types'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX, revalidate} from '#live/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionLiveEvent, actionLiveEventIncludingDrafts} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {Suspense} from 'react'\nimport {preconnect} from 'react-dom'\n\nimport type {DefinedSanityFetchType, DefinedSanityLiveProps} from '../react-server/defineLive'\n\nexport function defineLive(config: LiveOptions): {\n sanityFetch: DefinedSanityFetchType\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n} {\n const {client: _client, serverToken, browserToken} = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: true})\n const {token: originalToken} = client.config()\n\n const fetch: DefinedFetchType = async function fetch({\n query,\n params = {},\n perspective = 'published',\n stega = false,\n tags: customCacheTags = [],\n requestTag = 'next-loader.fetch.cache-components',\n }) {\n const useCdn = perspective === 'published'\n\n const {result, resultSourceMap, syncTags} = await client.fetch(query, params, {\n filterResponse: false,\n returnQuery: false,\n perspective,\n useCdn,\n stega,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n token: perspective === 'published' ? originalToken : serverToken || originalToken, // @TODO can pass undefined instead of config.token here?\n })\n const tags = [\n ...customCacheTags,\n ...(syncTags || []).map(\n (tag) =>\n `${perspective === 'published' ? PUBLISHED_SYNC_TAG_PREFIX : DRAFT_SYNC_TAG_PREFIX}${tag}`,\n ),\n ]\n /**\n * The tags used here, are expired later on in the `expireTags` Server Action with the `expireTag` function from `next/cache`\n */\n cacheTag(...tags)\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short,\n * userland can still set a shorter revalidate time by calling `cacheLife` themselves.\n */\n cacheLife({revalidate})\n\n return {data: result, sourceMap: resultSourceMap || null, tags}\n }\n\n const Live: React.ComponentType<DefinedLiveProps> = function Live(props) {\n const {\n perspective = 'published',\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n onError,\n onGoAway,\n intervalOnGoAway,\n } = props\n\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <Suspense>\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={perspective}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n </Suspense>\n )\n }\n Live.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch: fetch,\n SanityLive: Live,\n }\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,WAAW,QAGzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,iBAAgB;AAErD,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAK,CAAC;CAC1E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;CAE9C,MAAM,QAA0B,eAAeA,QAAM,EACnD,OACA,SAAS,EAAE,EACX,cAAc,aACd,QAAQ,OACR,MAAM,kBAAkB,EAAE,EAC1B,aAAa,wCACZ;EACD,MAAM,SAAS,gBAAgB;EAE/B,MAAM,EAAC,QAAQ,iBAAiB,aAAY,MAAM,OAAO,MAAM,OAAO,QAAQ;GAC5E,gBAAgB;GAChB,aAAa;GACb;GACA;GACA;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACL,OAAO,gBAAgB,cAAc,gBAAgB,eAAe;GACrE,CAAC;EACF,MAAM,OAAO,CACX,GAAG,iBACH,IAAI,YAAY,EAAE,EAAE,KACjB,QACC,GAAG,gBAAgB,cAAc,4BAA4B,wBAAwB,MACxF,CACF;AAID,WAAS,GAAG,KAAK;AAKjB,YAAU,EAAC,YAAW,CAAC;AAEvB,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM;GAAK;;CAGjE,MAAM,OAA8C,SAASC,OAAK,OAAO;EACvE,MAAM,EACJ,cAAc,aACd,WAAW,iBACX,0BAA0B,gCAC1B,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,OACrB,aAAa,qCACb,SACA,UACA,qBACE;EAEJ,MAAM,gBAAgB,OAAO,iBAAiB,YAAY,gBAAgB;EAE1E,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EAGjB,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAAC,UAAA,EAAA,UACC,oBAACC,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,gBAAgB,eAAe,KAAA;IACvC;GACY;GACb,aAAa;GACb,4BAA4B;GAChB;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB,EAAA,CACO;;AAGf,MAAK,cAAc;AAEnB,QAAO;EACL,aAAa;EACb,YAAY;EACb"}
|
|
@@ -5,7 +5,7 @@ import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
|
5
5
|
import { cookies, draftMode } from "next/headers";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
8
|
-
import { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
8
|
+
import { actionLiveEvent, actionLiveEventIncludingDrafts } from "next-sanity/live/server-actions";
|
|
9
9
|
import { preconnect } from "react-dom";
|
|
10
10
|
function defineLive(config) {
|
|
11
11
|
const { client: _client, serverToken, browserToken, fetchOptions, stega: stegaEnabled = true } = config;
|
|
@@ -57,7 +57,7 @@ function defineLive(config) {
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
const SanityLive$1 = async function SanityLive$2(props) {
|
|
60
|
-
const { onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts,
|
|
60
|
+
const { onChange = actionLiveEvent, onChangeIncludingDrafts = actionLiveEventIncludingDrafts, refreshOnMount, refreshOnFocus, refreshOnReconnect, requestTag = "next-loader.live", onError, onGoAway, intervalOnGoAway, perspective: _perspective } = props;
|
|
61
61
|
const { projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix } = client.config();
|
|
62
62
|
const perspective = _perspective ?? await resolveCookiePerspective();
|
|
63
63
|
const includeDrafts = typeof browserToken === "string" && perspective !== "published";
|
|
@@ -76,7 +76,6 @@ function defineLive(config) {
|
|
|
76
76
|
perspective: await resolveCookiePerspective(),
|
|
77
77
|
onLiveEvent: onChange,
|
|
78
78
|
onLiveEventIncludingDrafts: onChangeIncludingDrafts,
|
|
79
|
-
onPresentationPerspective: onStudioPerspective,
|
|
80
79
|
requestTag,
|
|
81
80
|
refreshOnMount,
|
|
82
81
|
refreshOnFocus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanityFetch","tag","SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, PerspectiveType} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n type SanityClient,\n} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {\n actionStudioPerspective,\n actionLiveEvent,\n actionLiveEventIncludingDrafts,\n} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefinedSanityLiveProps extends DefinedLiveProps {\n /**\n * @defaultValue `automatically resolved`\n */\n perspective?: PerspectiveType\n}\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedSanityLiveProps> = async function SanityLive(props) {\n const {\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n onStudioPerspective = actionStudioPerspective,\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n onError,\n onGoAway,\n intervalOnGoAway,\n perspective: _perspective,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={await resolveCookiePerspective()}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n onPresentationPerspective={onStudioPerspective}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n\nasync function resolveCookiePerspective(): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : 'published'\n}\n"],"mappings":";;;;;;;;;AA4FA,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,gBAAgB,iBAAiB,MAC7E,SAAQ,KACN,iXACD;CAGH,MAAM,SAAS,QAAQ,WAAW;EAAC,kBAAkB;EAAO,QAAQ;EAAM,CAAC;CAC3E,MAAM,EAAC,OAAO,kBAAiB,OAAO,QAAQ;CAC9C,MAAM,mBAAmB,OAAO,OAAO,QAAQ,CAAC,MAAM,cAAc;CAEpE,MAAM,cAAsC,eAAeA,cAEzD,EACA,OACA,SAAS,EAAE,EACX,OAAO,QACP,OAAO,CAAC,SAAS,EACjB,aAAa,cACb,KACA,aAAa,OAAO,uBASnB;EACD,MAAM,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM,WAAW,EAAE;EACjF,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,SAAS,gBAAgB;EAC/B,MAAM,aACJ,cAAc,eAAe,KAAA,IACzB,aAAa,aACb,QAAQ,IAAI,aAAa,eACvB,QACA,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A4B;GAC5B,2BAA2B;GACf;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["sanityFetch","tag","SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, PerspectiveType} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {\n type ClientPerspective,\n type ClientReturn,\n type ContentSourceMap,\n type QueryParams,\n type SanityClient,\n} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionLiveEvent, actionLiveEventIncludingDrafts} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\n/**\n * @public\n */\nexport type DefinedSanityFetchType = <const QueryString extends string>(options: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n /**\n * Add custom `next.tags` to the underlying fetch request.\n * @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags\n * This can be used in conjunction with custom fallback revalidation strategies, as well as with custom Server Actions that mutate data and want to render with fresh data right away (faster than the Live Event latency).\n * @defaultValue `['sanity']`\n */\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n stega?: boolean\n /**\n * This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.\n * @see https://www.sanity.io/docs/reference-api-request-tags\n * @defaultValue 'next-loader.fetch'\n */\n requestTag?: string\n}) => Promise<{\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n tags: string[]\n}>\n\n/**\n * @public\n */\nexport interface DefinedSanityLiveProps extends DefinedLiveProps {\n /**\n * @defaultValue `automatically resolved`\n */\n perspective?: PerspectiveType\n}\n\n/**\n * @public\n */\nexport interface DefineSanityLiveOptions {\n /**\n * Required for `sanityFetch` and `SanityLive` to work\n */\n client: SanityClient\n /**\n * Optional. If provided then the token needs to have permissions to query documents with `drafts.` prefixes in order for `perspective: 'drafts'` to work.\n * This token is not shared with the browser.\n */\n serverToken?: string | false\n /**\n * Optional. This token is shared with the browser, and should only have access to query published documents.\n * It is used to setup a `Live Draft Content` EventSource connection, and enables live previewing drafts stand-alone, outside of Presentation Tool.\n */\n browserToken?: string | false\n /**\n * Fetch options used by `sanityFetch`\n */\n fetchOptions?: {\n /**\n * Optional, enables time based revalidation in addition to the EventSource connection.\n * @defaultValue `false`\n */\n revalidate?: number | false\n }\n /**\n * Optional. Include stega encoding when draft mode is enabled.\n * @defaultValue `true`\n */\n stega?: boolean\n}\n\nexport function defineLive(config: DefineSanityLiveOptions): {\n /**\n * @deprecated use `fetch` instead, and define your own `sanityFetch` function with logic for when to toggle `stega` and `perspective`\n */\n sanityFetch: DefinedSanityFetchType\n /**\n * @deprecated use `Live` instead, and define your own `SanityLive` component with logic for when to toggle `perspective`\n */\n SanityLive: React.ComponentType<DefinedSanityLiveProps>\n // fetch: DefinedFetchType\n // Live: React.ComponentType<DefinedLiveProps>\n} {\n const {\n client: _client,\n serverToken,\n browserToken,\n fetchOptions,\n stega: stegaEnabled = true,\n } = config\n\n if (!_client) {\n throw new Error('`client` is required for `defineLive` to function')\n }\n\n if (process.env.NODE_ENV !== 'production' && !serverToken && serverToken !== false) {\n console.warn(\n 'No `serverToken` provided to `defineLive`. This means that only published content will be fetched and respond to live events. You can silence this warning by setting `serverToken: false`.',\n )\n }\n\n if (process.env.NODE_ENV !== 'production' && !browserToken && browserToken !== false) {\n console.warn(\n 'No `browserToken` provided to `defineLive`. This means that live previewing drafts will only work when using the Presentation Tool in your Sanity Studio. To support live previewing drafts stand-alone, provide a `browserToken`. It is shared with the browser so it should only have Viewer rights or lower. You can silence this warning by setting `browserToken: false`.',\n )\n }\n\n const client = _client.withConfig({allowReconfigure: false, useCdn: false})\n const {token: originalToken} = client.config()\n const studioUrlDefined = typeof client.config().stega.studioUrl !== 'undefined'\n\n const sanityFetch: DefinedSanityFetchType = async function sanityFetch<\n const QueryString extends string,\n >({\n query,\n params = {},\n stega: _stega,\n tags = ['sanity'],\n perspective: _perspective,\n tag,\n requestTag = tag ?? 'next-loader.fetch',\n }: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n tags?: string[]\n perspective?: Exclude<ClientPerspective, 'raw'>\n tag?: string\n requestTag?: string\n }) {\n const stega = _stega ?? (stegaEnabled && studioUrlDefined && (await draftMode()).isEnabled)\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const useCdn = perspective === 'published'\n const revalidate =\n fetchOptions?.revalidate !== undefined\n ? fetchOptions.revalidate\n : process.env.NODE_ENV === 'production'\n ? false\n : undefined\n\n // fetch the tags first, with revalidate to 1s to ensure we get the latest tags, eventually\n const {syncTags} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega: false,\n returnQuery: false,\n next: {revalidate, tags: [...tags, 'sanity:fetch-sync-tags']},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: [requestTag, 'fetch-sync-tags'].filter(Boolean).join('.'),\n })\n\n const cacheTags = [...tags, ...(syncTags?.map((tag) => `sanity:${tag}`) || [])]\n\n const {result, resultSourceMap} = await client.fetch(query, await params, {\n filterResponse: false,\n perspective: perspective as ClientPerspective,\n stega,\n token: perspective !== 'published' && serverToken ? serverToken : originalToken,\n next: {revalidate, tags: cacheTags},\n useCdn,\n cacheMode: useCdn ? 'noStale' : undefined,\n tag: requestTag,\n })\n return {data: result, sourceMap: resultSourceMap || null, tags: cacheTags}\n }\n\n const SanityLive: React.ComponentType<DefinedSanityLiveProps> = async function SanityLive(props) {\n const {\n onChange = actionLiveEvent,\n onChangeIncludingDrafts = actionLiveEventIncludingDrafts,\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n onError,\n onGoAway,\n intervalOnGoAway,\n perspective: _perspective,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const perspective = _perspective ?? (await resolveCookiePerspective())\n const includeDrafts = typeof browserToken === 'string' && perspective !== 'published'\n\n // Preconnect to the Live Event API origin early, as the Sanity API is almost always on a different origin than the app\n const {origin} = new URL(client.getUrl('', false))\n preconnect(origin)\n\n return (\n <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: includeDrafts ? browserToken : undefined,\n }}\n perspective={await resolveCookiePerspective()}\n onLiveEvent={onChange}\n onLiveEventIncludingDrafts={onChangeIncludingDrafts}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n onError={onError}\n onGoAway={onGoAway}\n intervalOnGoAway={intervalOnGoAway}\n />\n )\n }\n SanityLive.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch,\n SanityLive,\n }\n}\n\nasync function resolveCookiePerspective(): Promise<Exclude<ClientPerspective, 'raw'>> {\n return (await draftMode()).isEnabled\n ? (await cookies()).has(perspectiveCookieName)\n ? sanitizePerspective((await cookies()).get(perspectiveCookieName)?.value, 'drafts')\n : 'drafts'\n : 'published'\n}\n"],"mappings":";;;;;;;;;AAwFA,SAAgB,WAAW,QAWzB;CACA,MAAM,EACJ,QAAQ,SACR,aACA,cACA,cACA,OAAO,eAAe,SACpB;AAEJ,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,oDAAoD;AAGtE,KAAI,QAAQ,IAAI,aAAa,gBAAgB,CAAC,eAAe,gBAAgB,MAC3E,SAAQ,KACN,8LACD;AAGH,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GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMC,eAA0D,eAAeA,aAAW,OAAO;EAC/F,MAAM,EACJ,WAAW,iBACX,0BAA0B,gCAC1B,gBACA,gBACA,oBACA,aAAa,oBACb,SACA,UACA,kBACA,aAAa,iBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,cAAc,gBAAiB,MAAM,0BAA0B;EACrE,MAAM,gBAAgB,OAAO,iBAAiB,YAAY,gBAAgB;EAG1E,MAAM,EAAC,WAAU,IAAI,IAAI,OAAO,OAAO,IAAI,MAAM,CAAC;AAClD,aAAW,OAAO;AAElB,SACE,oBAACC,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,gBAAgB,eAAe,KAAA;IACvC;GACD,aAAa,MAAM,0BAA0B;GAC7C,aAAa;GACb,4BAA4B;GAChB;GACI;GACA;GACI;GACX;GACC;GACQ;IAClB;;AAGN,cAAW,cAAc;AAEzB,QAAO;EACL;EACA,YAAA;EACD;;AAGH,eAAe,2BAAuE;AACpF,SAAQ,MAAM,WAAW,EAAE,aACtB,MAAM,SAAS,EAAE,IAAI,sBAAsB,GAC1C,qBAAqB,MAAM,SAAS,EAAE,IAAI,sBAAsB,EAAE,OAAO,SAAS,GAClF,WACF"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { ClientPerspective } from "@sanity/client";
|
|
2
|
-
/**
|
|
3
|
-
* Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`
|
|
4
|
-
*/
|
|
5
|
-
declare function actionStudioPerspective(perspective: ClientPerspective): Promise<void>;
|
|
6
1
|
/**
|
|
7
2
|
* Used by `<SanityLive onLiveEvent={actionLiveEvent} />`
|
|
8
3
|
*/
|
|
@@ -11,5 +6,5 @@ declare function actionLiveEvent(_tags: unknown): Promise<void>;
|
|
|
11
6
|
* Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`
|
|
12
7
|
*/
|
|
13
8
|
declare function actionLiveEventIncludingDrafts(_tags: unknown): Promise<void>;
|
|
14
|
-
export { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
9
|
+
export { actionLiveEvent, actionLiveEventIncludingDrafts };
|
|
15
10
|
//# sourceMappingURL=index.default.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.default.d.ts","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":[],"mappings":"AAQA;AAyBA;;iBAzBsB,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,kBAAgD"}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { n as PUBLISHED_SYNC_TAG_PREFIX, t as DRAFT_SYNC_TAG_PREFIX } from "../../constants.js";
|
|
3
|
-
import {
|
|
4
|
-
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
5
|
-
import { cookies, draftMode } from "next/headers";
|
|
6
|
-
import { refresh, revalidateTag, updateTag } from "next/cache";
|
|
7
|
-
async function actionStudioPerspective(perspective) {
|
|
8
|
-
const { isEnabled } = await draftMode();
|
|
9
|
-
if (!isEnabled) {
|
|
10
|
-
console.warn("Draft mode is not enabled, skipping actionStudioPerspective");
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const jar = await cookies();
|
|
14
|
-
const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
|
|
15
|
-
if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
|
|
16
|
-
jar.set(perspectiveCookieName, Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective, {
|
|
17
|
-
httpOnly: true,
|
|
18
|
-
path: "/",
|
|
19
|
-
secure: true,
|
|
20
|
-
sameSite: "none"
|
|
21
|
-
});
|
|
22
|
-
refresh();
|
|
23
|
-
}
|
|
3
|
+
import { revalidateTag, updateTag } from "next/cache";
|
|
24
4
|
async function actionLiveEvent(_tags) {
|
|
25
5
|
if (!Array.isArray(_tags)) {
|
|
26
6
|
console.warn("<SanityLive /> `expireTags` called with non-array tags", _tags);
|
|
@@ -50,6 +30,6 @@ async function actionLiveEventIncludingDrafts(_tags) {
|
|
|
50
30
|
for (const tag of tags) updateTag(tag);
|
|
51
31
|
console.log(`<SanityLive /> updated tags: ${tags.join(", ")}`);
|
|
52
32
|
}
|
|
53
|
-
export { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
33
|
+
export { actionLiveEvent, actionLiveEventIncludingDrafts };
|
|
54
34
|
|
|
55
35
|
//# sourceMappingURL=index.default.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport
|
|
1
|
+
{"version":3,"file":"index.default.js","names":[],"sources":["../../../src/live/server-actions/index.default.ts"],"sourcesContent":["'use server'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {revalidateTag, updateTag} from 'next/cache'\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n\n revalidateTag('sanity:fetch-sync-tags', 'max')\n\n for (const tag of tags) {\n revalidateTag(tag, {expire: 0})\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> revalidated tag: ${tag}`)\n }\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(_tags: unknown): Promise<void> {\n // @TODO check draft mode before expiring tags\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;AAQA,eAAsB,gBAAgB,OAA+B;AACnE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAGF,eAAc,0BAA0B,MAAM;AAE9C,MAAK,MAAM,OAAO,MAAM;AACtB,gBAAc,KAAK,EAAC,QAAQ,GAAE,CAAC;AAE/B,UAAQ,IAAI,mCAAmC,MAAM;;;AAOzD,eAAsB,+BAA+B,OAA+B;AAElF,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { ClientPerspective } from "@sanity/client";
|
|
2
|
-
/**
|
|
3
|
-
* Used by `<SanityLive onStudioPerspective={actionStudioPerspective} />`
|
|
4
|
-
*/
|
|
5
|
-
declare function actionStudioPerspective(perspective: ClientPerspective): Promise<void>;
|
|
6
1
|
/**
|
|
7
2
|
* Used by `<SanityLive onLiveEvent={actionLiveEvent} />`
|
|
8
3
|
*/
|
|
@@ -11,5 +6,5 @@ declare function actionLiveEvent(_tags: unknown): Promise<void>;
|
|
|
11
6
|
* Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`
|
|
12
7
|
*/
|
|
13
8
|
declare function actionLiveEventIncludingDrafts(tags: unknown): Promise<void>;
|
|
14
|
-
export { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
9
|
+
export { actionLiveEvent, actionLiveEventIncludingDrafts };
|
|
15
10
|
//# sourceMappingURL=index.next-js.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.next-js.d.ts","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":[],"mappings":"AASA;AAyBA;;iBAzBsB,eAAA,kBAAiC;;;;iBAyBjC,8BAAA,iBAA+C"}
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { n as PUBLISHED_SYNC_TAG_PREFIX, t as DRAFT_SYNC_TAG_PREFIX } from "../../constants.js";
|
|
3
|
-
import {
|
|
4
|
-
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
5
|
-
import { cookies, draftMode } from "next/headers";
|
|
3
|
+
import { draftMode } from "next/headers";
|
|
6
4
|
import { refresh, updateTag } from "next/cache";
|
|
7
|
-
async function actionStudioPerspective(perspective) {
|
|
8
|
-
const jar = await cookies();
|
|
9
|
-
const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
|
|
10
|
-
if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
|
|
11
|
-
jar.set(perspectiveCookieName, Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective, {
|
|
12
|
-
httpOnly: true,
|
|
13
|
-
path: "/",
|
|
14
|
-
secure: true,
|
|
15
|
-
sameSite: "none"
|
|
16
|
-
});
|
|
17
|
-
refresh();
|
|
18
|
-
}
|
|
19
5
|
async function actionLiveEvent(_tags) {
|
|
20
6
|
if (!Array.isArray(_tags)) {
|
|
21
7
|
console.warn("<SanityLive /> `expireTags` called with non-array tags", _tags);
|
|
@@ -47,6 +33,6 @@ async function expireDraftTags(_tags) {
|
|
|
47
33
|
for (const tag of tags) updateTag(tag);
|
|
48
34
|
console.log(`<SanityLive /> updated tags: ${tags.join(", ")}`);
|
|
49
35
|
}
|
|
50
|
-
export { actionLiveEvent, actionLiveEventIncludingDrafts
|
|
36
|
+
export { actionLiveEvent, actionLiveEventIncludingDrafts };
|
|
51
37
|
|
|
52
38
|
//# sourceMappingURL=index.next-js.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport
|
|
1
|
+
{"version":3,"file":"index.next-js.js","names":[],"sources":["../../../src/live/server-actions/index.next-js.ts"],"sourcesContent":["'use server'\n\nimport {DRAFT_SYNC_TAG_PREFIX, PUBLISHED_SYNC_TAG_PREFIX} from '#live/constants'\nimport {refresh, updateTag} from 'next/cache'\nimport {draftMode} from 'next/headers'\n\n/**\n * Used by `<SanityLive onLiveEvent={actionLiveEvent} />`\n */\nexport async function actionLiveEvent(_tags: unknown): Promise<void> {\n // @TODO Draft Mode bypasses cache anyway so we don't bother with expiring tags for draft content\n // const isDraftMode = (await draftMode()).isEnabled\n // const tags = _tags.map((tag) => `${isDraftMode ? 'drafts' : 'sanity'}:${tag}`)\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(PUBLISHED_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n\n/**\n * Used by `<SanityLive onLiveEventIncludingDrafts={actionLiveEventIncludingDrafts} />`\n */\nexport async function actionLiveEventIncludingDrafts(tags: unknown): Promise<void> {\n const {isEnabled} = await draftMode()\n if (isEnabled) {\n // With cache components just refresh by default when in draft mode and assume bypass\n refresh()\n } else {\n return expireDraftTags(tags)\n }\n}\n\nasync function expireDraftTags(_tags: unknown): Promise<void> {\n if (!Array.isArray(_tags)) {\n console.warn('<SanityLive /> `expireTags` called with non-array tags', _tags)\n return undefined\n }\n const tags = _tags.filter(\n (tag) => typeof tag === 'string' && tag.startsWith(DRAFT_SYNC_TAG_PREFIX),\n )\n if (!tags.length) {\n console.warn('<SanityLive /> `expireTags` called with no valid tags', _tags)\n return undefined\n }\n for (const tag of tags) {\n updateTag(tag)\n }\n // oxlint-disable-next-line no-console\n console.log(`<SanityLive /> updated tags: ${tags.join(', ')}`)\n}\n"],"mappings":";;;;AASA,eAAsB,gBAAgB,OAA+B;AAInE,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,0BAA0B,CAC9E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG;;AAMhE,eAAsB,+BAA+B,MAA8B;CACjF,MAAM,EAAC,cAAa,MAAM,WAAW;AACrC,KAAI,UAEF,UAAS;KAET,QAAO,gBAAgB,KAAK;;AAIhC,eAAe,gBAAgB,OAA+B;AAC5D,KAAI,CAAC,MAAM,QAAQ,MAAM,EAAE;AACzB,UAAQ,KAAK,0DAA0D,MAAM;AAC7E;;CAEF,MAAM,OAAO,MAAM,QAChB,QAAQ,OAAO,QAAQ,YAAY,IAAI,WAAW,sBAAsB,CAC1E;AACD,KAAI,CAAC,KAAK,QAAQ;AAChB,UAAQ,KAAK,yDAAyD,MAAM;AAC5E;;AAEF,MAAK,MAAM,OAAO,KAChB,WAAU,IAAI;AAGhB,SAAQ,IAAI,gCAAgC,KAAK,KAAK,KAAK,GAAG"}
|
|
@@ -24,6 +24,6 @@ interface VisualEditingProps extends Omit<VisualEditingOptions, "history"> {
|
|
|
24
24
|
*/
|
|
25
25
|
trailingSlash?: boolean;
|
|
26
26
|
}
|
|
27
|
-
declare
|
|
28
|
-
export { type VisualEditingProps
|
|
27
|
+
declare const VisualEditing: React.ComponentType<VisualEditingProps>;
|
|
28
|
+
export { VisualEditing, type VisualEditingProps };
|
|
29
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/client-component/VisualEditing.tsx","../../../src/visual-editing/client-component/index.ts"],"sourcesContent":[],"mappings":";;AAgBA;;ACVa,UDUI,kBAAA,SAA2B,ICVI,CDUC,oBCVf,EAAA,SAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;cAArB,eAAe,KAAA,CAAM,cAAc"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function VisualEditingLazyClientComponent(props) {
|
|
6
|
-
return /* @__PURE__ */ jsx(Suspense, {
|
|
7
|
-
fallback: null,
|
|
8
|
-
children: /* @__PURE__ */ jsx(VisualEditingClientComponent, { ...props })
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export { VisualEditingLazyClientComponent as default };
|
|
2
|
+
import dynamic from "next/dynamic";
|
|
3
|
+
const VisualEditing = dynamic(() => import("../../VisualEditing.js"), { ssr: false });
|
|
4
|
+
export { VisualEditing };
|
|
12
5
|
|
|
13
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/client-component/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/client-component/index.ts"],"sourcesContent":["'use client'\n\nimport dynamic from 'next/dynamic'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nexport const VisualEditing: React.ComponentType<VisualEditingProps> = dynamic(\n () => import('./VisualEditing'),\n {ssr: false},\n)\nexport type {VisualEditingProps}\n"],"mappings":";;AAMA,MAAa,gBAAyD,cAC9D,OAAO,2BACb,EAAC,KAAK,OAAM,CACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":[],"mappings":";;AAQA;;iBAAgB,aAAA,QAAqB,uBAAqB,KAAA,CAAM"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { VisualEditing as VisualEditing$1 } from "next-sanity/visual-editing/client-component";
|
|
3
|
+
import { actionPerspectiveChange } from "next-sanity/visual-editing/server-actions";
|
|
3
4
|
function VisualEditing(props) {
|
|
4
5
|
let autoBasePath;
|
|
5
6
|
if (typeof props.basePath !== "string") try {
|
|
@@ -15,7 +16,8 @@ function VisualEditing(props) {
|
|
|
15
16
|
} catch (err) {
|
|
16
17
|
console.error("Failed detecting trailingSlash", err);
|
|
17
18
|
}
|
|
18
|
-
return /* @__PURE__ */ jsx(
|
|
19
|
+
return /* @__PURE__ */ jsx(VisualEditing$1, {
|
|
20
|
+
onPerspectiveChange: actionPerspectiveChange,
|
|
19
21
|
...props,
|
|
20
22
|
basePath: props.basePath ?? autoBasePath,
|
|
21
23
|
trailingSlash: props.trailingSlash ?? autoTrailingSlash
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\nimport VisualEditingComponent from 'next-sanity/visual-editing/client-component'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["VisualEditingComponent"],"sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\nimport {VisualEditing as VisualEditingComponent} from 'next-sanity/visual-editing/client-component'\nimport {actionPerspectiveChange} from 'next-sanity/visual-editing/server-actions'\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n let autoBasePath: string | undefined\n if (typeof props.basePath !== 'string') {\n try {\n autoBasePath = process.env['__NEXT_ROUTER_BASEPATH']\n if (autoBasePath) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next basePath as ${JSON.stringify(autoBasePath)} by reading \"process.env.__NEXT_ROUTER_BASEPATH\". If this is incorrect then you can set it manually with the basePath prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting basePath', err)\n }\n }\n let autoTrailingSlash: boolean | undefined\n if (typeof props.trailingSlash !== 'boolean') {\n try {\n autoTrailingSlash = Boolean(process.env['__NEXT_TRAILING_SLASH'])\n if (autoTrailingSlash) {\n // oxlint-disable-next-line no-console\n console.log(\n `Detected next trailingSlash as ${JSON.stringify(autoTrailingSlash)} by reading \"process.env.__NEXT_TRAILING_SLASH\". If this is incorrect then you can set it manually with the trailingSlash prop on the <VisualEditing /> component.`,\n )\n }\n } catch (err) {\n console.error('Failed detecting trailingSlash', err)\n }\n }\n return (\n <VisualEditingComponent\n onPerspectiveChange={actionPerspectiveChange}\n {...props}\n basePath={props.basePath ?? autoBasePath}\n trailingSlash={props.trailingSlash ?? autoTrailingSlash}\n />\n )\n}\n\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"mappings":";;;AAQA,SAAgB,cAAc,OAA+C;CAC3E,IAAI;AACJ,KAAI,OAAO,MAAM,aAAa,SAC5B,KAAI;AACF,iBAAe,QAAQ,IAAI;AAC3B,MAAI,aAEF,SAAQ,IACN,6BAA6B,KAAK,UAAU,aAAa,CAAC,gKAC3D;UAEI,KAAK;AACZ,UAAQ,MAAM,6BAA6B,IAAI;;CAGnD,IAAI;AACJ,KAAI,OAAO,MAAM,kBAAkB,UACjC,KAAI;AACF,sBAAoB,QAAQ,QAAQ,IAAI,yBAAyB;AACjE,MAAI,kBAEF,SAAQ,IACN,kCAAkC,KAAK,UAAU,kBAAkB,CAAC,oKACrE;UAEI,KAAK;AACZ,UAAQ,MAAM,kCAAkC,IAAI;;AAGxD,QACE,oBAACA,iBAAAA;EACC,qBAAqB;EACrB,GAAI;EACJ,UAAU,MAAM,YAAY;EAC5B,eAAe,MAAM,iBAAiB;GACtC"}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { HistoryRefresh } from "@sanity/visual-editing/react";
|
|
2
|
+
import { ClientPerspective } from "@sanity/client";
|
|
3
|
+
/**
|
|
4
|
+
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
5
|
+
*/
|
|
6
|
+
declare function actionRefresh(_payload: HistoryRefresh): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.
|
|
9
|
+
*/
|
|
10
|
+
declare function actionPerspectiveChange(perspective: ClientPerspective): Promise<void>;
|
|
11
|
+
export { actionPerspectiveChange, actionRefresh };
|
|
3
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":[],"mappings":";;;AAaA;AAOA;iBAPsB,aAAA,WAAwB,iBAAiB;;;;iBAOzC,uBAAA,cAAqC,oBAAoB"}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
"use server";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { t as sanitizePerspective } from "../../sanitizePerspective.js";
|
|
3
|
+
import { perspectiveCookieName } from "@sanity/preview-url-secret/constants";
|
|
4
|
+
import { cookies } from "next/headers";
|
|
5
|
+
import { refresh } from "next/cache";
|
|
6
|
+
async function actionRefresh(_payload) {
|
|
7
|
+
refresh();
|
|
8
|
+
}
|
|
9
|
+
async function actionPerspectiveChange(perspective) {
|
|
10
|
+
const sanitizedPerspective = sanitizePerspective(perspective, "drafts");
|
|
11
|
+
if (!sanitizedPerspective || Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0) throw new Error(`Invalid perspective`, { cause: perspective });
|
|
12
|
+
const nextPerspective = Array.isArray(sanitizedPerspective) ? sanitizedPerspective.join(",") : sanitizedPerspective;
|
|
13
|
+
const jar = await cookies();
|
|
14
|
+
if (nextPerspective === jar.get(perspectiveCookieName)?.value) {
|
|
15
|
+
console.debug("Perspective is the same, skipping", nextPerspective);
|
|
7
16
|
return;
|
|
8
17
|
}
|
|
9
|
-
|
|
18
|
+
jar.set(perspectiveCookieName, nextPerspective, {
|
|
19
|
+
httpOnly: true,
|
|
20
|
+
path: "/",
|
|
21
|
+
secure: true,
|
|
22
|
+
sameSite: "none"
|
|
23
|
+
});
|
|
24
|
+
refresh();
|
|
10
25
|
}
|
|
11
|
-
export {
|
|
26
|
+
export { actionPerspectiveChange, actionRefresh };
|
|
12
27
|
|
|
13
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\n\nimport type {ClientPerspective} from '@sanity/client'\nimport type {HistoryRefresh} from '@sanity/visual-editing/react'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {refresh} from 'next/cache'\nimport {cookies} from 'next/headers'\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function actionRefresh(_payload: HistoryRefresh): Promise<void> {\n refresh()\n}\n\n/**\n * @internal CAUTION: this is an internal action and does not follow semver. Using it directly is at your own risk.\n */\nexport async function actionPerspectiveChange(perspective: ClientPerspective): Promise<void> {\n const sanitizedPerspective = sanitizePerspective(perspective, 'drafts')\n if (\n !sanitizedPerspective ||\n (Array.isArray(sanitizedPerspective) && sanitizedPerspective.length === 0)\n ) {\n throw new Error(`Invalid perspective`, {cause: perspective})\n }\n\n const nextPerspective = Array.isArray(sanitizedPerspective)\n ? sanitizedPerspective.join(',')\n : sanitizedPerspective\n const jar = await cookies()\n if (nextPerspective === jar.get(perspectiveCookieName)?.value) {\n // oxlint-disable-next-line no-console\n console.debug('Perspective is the same, skipping', nextPerspective)\n return\n }\n jar.set(perspectiveCookieName, nextPerspective, {\n httpOnly: true,\n path: '/',\n secure: true,\n sameSite: 'none',\n })\n\n refresh()\n}\n"],"mappings":";;;;;AAaA,eAAsB,cAAc,UAAyC;AAC3E,UAAS;;AAMX,eAAsB,wBAAwB,aAA+C;CAC3F,MAAM,uBAAuB,oBAAoB,aAAa,SAAS;AACvE,KACE,CAAC,wBACA,MAAM,QAAQ,qBAAqB,IAAI,qBAAqB,WAAW,EAExE,OAAM,IAAI,MAAM,uBAAuB,EAAC,OAAO,aAAY,CAAC;CAG9D,MAAM,kBAAkB,MAAM,QAAQ,qBAAqB,GACvD,qBAAqB,KAAK,IAAI,GAC9B;CACJ,MAAM,MAAM,MAAM,SAAS;AAC3B,KAAI,oBAAoB,IAAI,IAAI,sBAAsB,EAAE,OAAO;AAE7D,UAAQ,MAAM,qCAAqC,gBAAgB;AACnE;;AAEF,KAAI,IAAI,uBAAuB,iBAAiB;EAC9C,UAAU;EACV,MAAM;EACN,QAAQ;EACR,UAAU;EACX,CAAC;AAEF,UAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "13.0.0-cache-components.
|
|
3
|
+
"version": "13.0.0-cache-components.17",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
31
|
"imports": {
|
|
32
|
+
"#env": {
|
|
33
|
+
"next-js": "./src/env/next-js.ts",
|
|
34
|
+
"react-server": "./src/env/react-server.ts",
|
|
35
|
+
"default": "./src/env/default.ts"
|
|
36
|
+
},
|
|
32
37
|
"#live/*": "./src/live/shared/*.ts"
|
|
33
38
|
},
|
|
34
39
|
"exports": {
|
|
@@ -61,7 +66,7 @@
|
|
|
61
66
|
"@sanity/comlink": "^4.0.1",
|
|
62
67
|
"@sanity/presentation-comlink": "^2.0.1",
|
|
63
68
|
"@sanity/preview-url-secret": "^4.0.2",
|
|
64
|
-
"@sanity/visual-editing": "^5.0
|
|
69
|
+
"@sanity/visual-editing": "^5.1.0",
|
|
65
70
|
"dequal": "^2.0.3",
|
|
66
71
|
"groq": "^5.2.0",
|
|
67
72
|
"history": "^5.3.0"
|
|
@@ -70,18 +75,22 @@
|
|
|
70
75
|
"@sanity/browserslist-config": "^1.0.5",
|
|
71
76
|
"@sanity/tsconfig": "^2.1.0",
|
|
72
77
|
"@sanity/webhook": "4.0.4",
|
|
78
|
+
"@types/js-yaml": "^4.0.9",
|
|
73
79
|
"@types/node": "^24.10.7",
|
|
74
80
|
"@types/react": "^19.2.8",
|
|
75
81
|
"@types/react-dom": "^19.2.3",
|
|
82
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
76
83
|
"@vitest/coverage-v8": "^4.0.17",
|
|
84
|
+
"js-yaml": "^4.1.1",
|
|
77
85
|
"next": "16.1.1-canary.24",
|
|
78
86
|
"publint": "^0.3.16",
|
|
79
87
|
"react": "^19.2.3",
|
|
80
88
|
"react-dom": "^19.2.3",
|
|
81
|
-
"styled-components": "^6.
|
|
89
|
+
"styled-components": "^6.3.1",
|
|
82
90
|
"tsdown": "0.19.0",
|
|
83
91
|
"typescript": "5.9.3",
|
|
84
|
-
"vitest": "^4.0.17"
|
|
92
|
+
"vitest": "^4.0.17",
|
|
93
|
+
"vitest-package-exports": "^1.1.2"
|
|
85
94
|
},
|
|
86
95
|
"peerDependencies": {
|
|
87
96
|
"@sanity/client": "^7.14.0",
|