next-sanity 13.0.0-cache-components.21 → 13.0.0-cache-components.23
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/README.md +3 -1
- package/dist/NextStudio.js +1 -1
- package/dist/SanityLive.js +2 -3
- package/dist/SanityLive.js.map +1 -1
- package/dist/VisualEditing.js +1 -1
- package/dist/hooks/index.d.ts +3 -33
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +5 -108
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/live/cache-life.d.ts.map +1 -0
- package/dist/live/cache-life.js.map +1 -0
- package/dist/live/client-components/index.d.ts +1 -1
- package/dist/live/conditions/default/index.d.ts +3 -3
- package/dist/live/conditions/default/index.d.ts.map +1 -1
- package/dist/live/conditions/default/index.js.map +1 -1
- package/dist/live/conditions/next-js/index.d.ts +3 -3
- package/dist/live/conditions/next-js/index.d.ts.map +1 -1
- package/dist/live/conditions/next-js/index.js +2 -2
- package/dist/live/conditions/next-js/index.js.map +1 -1
- package/dist/live/conditions/react-server/index.d.ts +8 -3
- package/dist/live/conditions/react-server/index.d.ts.map +1 -0
- package/dist/live/conditions/react-server/index.js.map +1 -1
- package/dist/live/server-actions/index.default.d.ts +1 -1
- package/dist/live/server-actions/index.next-js.d.ts +1 -1
- package/dist/resolvePerspectiveFromCookies.d.ts +26 -0
- package/dist/resolvePerspectiveFromCookies.d.ts.map +1 -0
- package/dist/studio/client-component/index.js +1 -1
- package/dist/types.d.ts +33 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/cache-life.d.ts.map +0 -1
- package/dist/cache-life.js.map +0 -1
- package/dist/defineLive.d.ts +0 -57
- package/dist/defineLive.d.ts.map +0 -1
- /package/dist/{cache-life.d.ts → live/cache-life.d.ts} +0 -0
- /package/dist/{cache-life.js → live/cache-life.js} +0 -0
package/README.md
CHANGED
|
@@ -641,10 +641,11 @@ The same token can be used as both `browserToken` and `serverToken`, as the `bro
|
|
|
641
641
|
```tsx
|
|
642
642
|
// src/app/layout.tsx
|
|
643
643
|
|
|
644
|
+
import {draftMode} from 'next/headers'
|
|
644
645
|
import {VisualEditing} from 'next-sanity/visual-editing'
|
|
645
646
|
import {SanityLive} from '@/sanity/lib/live'
|
|
646
647
|
|
|
647
|
-
export default function RootLayout({children}: {children: React.ReactNode}) {
|
|
648
|
+
export default async function RootLayout({children}: {children: React.ReactNode}) {
|
|
648
649
|
return (
|
|
649
650
|
<html lang="en">
|
|
650
651
|
<body>
|
|
@@ -832,6 +833,7 @@ import {
|
|
|
832
833
|
useIsPresentationTool,
|
|
833
834
|
useDraftModeEnvironment,
|
|
834
835
|
useDraftModePerspective,
|
|
836
|
+
useVisualEditingEnvironment,
|
|
835
837
|
} from 'next-sanity/hooks'
|
|
836
838
|
```
|
|
837
839
|
|
package/dist/NextStudio.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as NextStudioLayout, t as NextStudioNoScript } from "./NextStudioNoScript.js";
|
|
2
|
-
import { useMemo, useSyncExternalStore } from "react";
|
|
3
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useSyncExternalStore } from "react";
|
|
4
4
|
import { Studio } from "sanity";
|
|
5
5
|
import { createHashHistory } from "history";
|
|
6
6
|
function createHashHistoryForStudio() {
|
package/dist/SanityLive.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { startTransition, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
3
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
3
|
import { createClient } from "@sanity/client";
|
|
5
4
|
import dynamic from "next/dynamic";
|
|
5
|
+
import { startTransition, useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
6
6
|
const RefreshOnFocus = dynamic(() => import("./RefreshOnFocus.js"));
|
|
7
7
|
const RefreshOnMount = dynamic(() => import("./RefreshOnMount.js"));
|
|
8
8
|
const RefreshOnInterval = dynamic(() => import("./RefreshOnInterval.js"));
|
|
@@ -87,7 +87,6 @@ function SanityLive(props) {
|
|
|
87
87
|
] });
|
|
88
88
|
}
|
|
89
89
|
SanityLive.displayName = "SanityLiveClientComponent";
|
|
90
|
-
|
|
91
|
-
export { SanityLive_default as default };
|
|
90
|
+
export { SanityLive as default };
|
|
92
91
|
|
|
93
92
|
//# sourceMappingURL=SanityLive.js.map
|
package/dist/SanityLive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import type {SanityLiveActionContext} from '#live/types'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeAllDocuments?: boolean\n requestTag: string\n\n action: (\n event: Extract<LiveEvent, {type: 'message'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n reconnectAction?: (\n event: Extract<LiveEvent, {type: 'reconnect'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n restartAction?: (\n event: Extract<LiveEvent, {type: 'restart'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n welcomeAction?:\n | ((\n event: Extract<LiveEvent, {type: 'welcome'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>)\n | false\n goAwayAction?:\n | ((\n event: Extract<LiveEvent, {type: 'goaway'}>,\n context: SanityLiveActionContext,\n ) => Promise<number | false>)\n | false\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n goAwayAction,\n reconnectAction,\n restartAction,\n welcomeAction,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\n const [error, setError] = useState<unknown>(null)\n if (error) {\n if (isCorsOriginError(error)) {\n throw new Error(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n } else {\n throw error\n }\n }\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const handleLiveEvent = useEffectEvent(async (event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setRefreshOnInterval(false)\n\n if (welcomeAction) {\n await welcomeAction(event, actionContext)\n } else if (welcomeAction !== false && process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive> is connected and listening for live events to ${includeAllDocuments ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n }\n break\n }\n case 'message': {\n await action(event, actionContext)\n break\n }\n case 'restart': {\n await restartAction?.(event, actionContext)\n break\n }\n case 'reconnect': {\n await reconnectAction?.(event, actionContext)\n break\n }\n case 'goaway': {\n if (goAwayAction !== false) {\n let interval = goAwayAction ? await goAwayAction(event, actionContext) : 30_000\n if (interval === false) return\n if (Number.isFinite(interval) && interval > 0) {\n startTransition(() => setRefreshOnInterval(interval))\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n interval / 1_000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n }\n }\n } else {\n setError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n setError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: includeAllDocuments, tag: requestTag})\n .subscribe({\n next: (event) => startTransition(() => handleLiveEvent(event)),\n error: (error) => startTransition(() => setError(error)),\n })\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeAllDocuments])\n\n return (\n <>\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnInterval && <RefreshOnInterval interval={refreshOnInterval} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;AAOA,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AAgDxE,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,sBAAsB,OACtB,QACA,cACA,iBACA,eACA,eACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,MACrB,eACE;CACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,OAAO,qBACzE;CACF,MAAM,gBAAgB,EAAC,qBAAoB;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAkB,KAAK;AACjD,KAAI,MACF,KAAI,kBAAkB,MAAM,CAC1B,OAAM,IAAI,MACR,8EAA8E,OAAO,OAAO,wEAAwE,MAAM,eAAe,iBAAiB,MAAM,iBAAiB,MACjO,EAAC,OAAO,OAAM,CACf;KAED,OAAM;CAIV,MAAM,SAAS,cAEX,aAAa;EACX;EACA;EACA;EACA;EACA;EACA,2BAA2B;EAC3B;EACA,QAAQ;EACR;EACD,CAAC,EACJ;EAAC;EAAS;EAAY;EAAS;EAAW;EAAkB;EAAO;EAAmB,CACvF;CAED,MAAM,CAAC,mBAAmB,wBAAwB,SAAyB,MAAM;CAEjF,MAAM,kBAAkB,eAAe,OAAO,UAAqB;AACjE,UAAQ,MAAM,MAAd;GACE,KAAK;AAEH,yBAAqB,MAAM;AAE3B,QAAI,cACF,OAAM,cAAc,OAAO,cAAc;aAChC,kBAAkB,SAAS,QAAQ,IAAI,aAAa,aAE7D,SAAQ,KACN,8DAA8D,sBAAsB,2EAA2E,sBAChK;AAEH;GAEF,KAAK;AACH,UAAM,OAAO,OAAO,cAAc;AAClC;GAEF,KAAK;AACH,UAAM,gBAAgB,OAAO,cAAc;AAC3C;GAEF,KAAK;AACH,UAAM,kBAAkB,OAAO,cAAc;AAC7C;GAEF,KAAK;AACH,QAAI,iBAAiB,OAAO;KAC1B,IAAI,WAAW,eAAe,MAAM,aAAa,OAAO,cAAc,GAAG;AACzE,SAAI,aAAa,MAAO;AACxB,SAAI,OAAO,SAAS,SAAS,IAAI,WAAW,GAAG;AAC7C,4BAAsB,qBAAqB,SAAS,CAAC;AACrD,UAAI,QAAQ,IAAI,aAAa,aAC3B,SAAQ,KACN,iFACA,WAAW,KACX,4CACA,MAAM,OACP;;UAIL,UACE,IAAI,MACF,mGAAmG,MAAM,UACzG,EAAC,OAAO,OAAM,CACf,CACF;AAEH;GAEF;AACE,aAAS,IAAI,MAAM,2BAA2B,EAAC,OAAO,OAAM,CAAC,CAAC;AAC9D;;GAEJ;AACF,iBAAgB;EACd,MAAM,eAAe,OAAO,KACzB,OAAO;GAAC,eAAe;GAAqB,KAAK;GAAW,CAAC,CAC7D,UAAU;GACT,OAAO,UAAU,sBAAsB,gBAAgB,MAAM,CAAC;GAC9D,QAAQ,UAAU,sBAAsB,SAAS,MAAM,CAAC;GACzD,CAAC;AACJ,eAAa,aAAa,aAAa;IACtC;EAAC,OAAO;EAAM;EAAY;EAAoB,CAAC;AAElD,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,qBAAqB,oBAAC,mBAAA,EAAkB,UAAU,mBAAA,CAAqB;EACvE,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc
|
|
1
|
+
{"version":3,"file":"SanityLive.js","names":[],"sources":["../src/live/client-components/SanityLive.tsx"],"sourcesContent":["import type {SanityLiveActionContext} from '#live/types'\n\nimport {isCorsOriginError} from '#live/isCorsOriginError'\nimport {createClient, type InitializedClientConfig, type LiveEvent} from '@sanity/client'\nimport dynamic from 'next/dynamic'\nimport {startTransition, useEffect, useEffectEvent, useMemo, useState} from 'react'\n\nconst RefreshOnFocus = dynamic(() => import('./RefreshOnFocus'))\nconst RefreshOnMount = dynamic(() => import('./RefreshOnMount'))\nconst RefreshOnInterval = dynamic(() => import('./RefreshOnInterval'))\nconst RefreshOnReconnect = dynamic(() => import('./RefreshOnReconnect'))\n\ninterface SanityClientConfig extends Pick<\n InitializedClientConfig,\n | 'projectId'\n | 'dataset'\n | 'apiHost'\n | 'apiVersion'\n | 'useProjectHostname'\n | 'token'\n | 'requestTagPrefix'\n> {}\n\nexport interface SanityLiveProps {\n config: SanityClientConfig\n includeAllDocuments?: boolean\n requestTag: string\n\n action: (\n event: Extract<LiveEvent, {type: 'message'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n reconnectAction?: (\n event: Extract<LiveEvent, {type: 'reconnect'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n restartAction?: (\n event: Extract<LiveEvent, {type: 'restart'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>\n welcomeAction?:\n | ((\n event: Extract<LiveEvent, {type: 'welcome'}>,\n context: SanityLiveActionContext,\n ) => Promise<void>)\n | false\n goAwayAction?:\n | ((\n event: Extract<LiveEvent, {type: 'goaway'}>,\n context: SanityLiveActionContext,\n ) => Promise<number | false>)\n | false\n\n refreshOnMount?: boolean\n refreshOnFocus?: boolean\n refreshOnReconnect?: boolean\n}\n\nfunction SanityLive(props: SanityLiveProps): React.JSX.Element | null {\n const {\n config,\n includeAllDocuments = false,\n action,\n goAwayAction,\n reconnectAction,\n restartAction,\n welcomeAction,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = true,\n requestTag,\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, token, requestTagPrefix} =\n config\n const actionContext = {includeAllDocuments} satisfies SanityLiveActionContext\n const [error, setError] = useState<unknown>(null)\n if (error) {\n if (isCorsOriginError(error)) {\n throw new Error(\n `Sanity Live is unable to connect to the Sanity API as the current origin - ${window.origin} - is not in the list of allowed CORS origins for this Sanity Project.${error.addOriginUrl ? ` Add it here: ${error.addOriginUrl}` : ''}`,\n {cause: error},\n )\n } else {\n throw error\n }\n }\n\n const client = useMemo(\n () =>\n createClient({\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n ignoreBrowserTokenWarning: true,\n token,\n useCdn: false,\n requestTagPrefix,\n }),\n [apiHost, apiVersion, dataset, projectId, requestTagPrefix, token, useProjectHostname],\n )\n\n const [refreshOnInterval, setRefreshOnInterval] = useState<number | false>(false)\n\n const handleLiveEvent = useEffectEvent(async (event: LiveEvent) => {\n switch (event.type) {\n case 'welcome': {\n // Disable long polling when welcome event is received, this is a no-op if long polling is already disabled\n setRefreshOnInterval(false)\n\n if (welcomeAction) {\n await welcomeAction(event, actionContext)\n } else if (welcomeAction !== false && process.env.NODE_ENV !== 'production') {\n // oxlint-disable-next-line no-console\n console.info(\n `<SanityLive> is connected and listening for live events to ${includeAllDocuments ? 'all content including drafts and version documents in content releases' : 'published content'}`,\n )\n }\n break\n }\n case 'message': {\n await action(event, actionContext)\n break\n }\n case 'restart': {\n await restartAction?.(event, actionContext)\n break\n }\n case 'reconnect': {\n await reconnectAction?.(event, actionContext)\n break\n }\n case 'goaway': {\n if (goAwayAction !== false) {\n let interval = goAwayAction ? await goAwayAction(event, actionContext) : 30_000\n if (interval === false) return\n if (Number.isFinite(interval) && interval > 0) {\n startTransition(() => setRefreshOnInterval(interval))\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n 'Sanity Live connection closed, switching to long polling set to a interval of',\n interval / 1_000,\n 'seconds and the server gave this reason:',\n event.reason,\n )\n }\n }\n } else {\n setError(\n new Error(\n `Sanity Live connection closed, automatic revalidation is disabled, the server gave this reason: ${event.reason}`,\n {cause: event},\n ),\n )\n }\n break\n }\n default:\n setError(new Error(`Unknown live event type`, {cause: event}))\n break\n }\n })\n useEffect(() => {\n const subscription = client.live\n .events({includeDrafts: includeAllDocuments, tag: requestTag})\n .subscribe({\n next: (event) => startTransition(() => handleLiveEvent(event)),\n error: (error) => startTransition(() => setError(error)),\n })\n return () => subscription.unsubscribe()\n }, [client.live, requestTag, includeAllDocuments])\n\n return (\n <>\n {refreshOnFocus && <RefreshOnFocus />}\n {refreshOnInterval && <RefreshOnInterval interval={refreshOnInterval} />}\n {refreshOnMount && <RefreshOnMount />}\n {refreshOnReconnect && <RefreshOnReconnect />}\n </>\n )\n}\n\nSanityLive.displayName = 'SanityLiveClientComponent'\n\nexport default SanityLive\n"],"mappings":";;;;;AAOA,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,iBAAiB,cAAc,OAAO,uBAAoB;AAChE,MAAM,oBAAoB,cAAc,OAAO,0BAAuB;AACtE,MAAM,qBAAqB,cAAc,OAAO,2BAAwB;AAgDxE,SAAS,WAAW,OAAkD;CACpE,MAAM,EACJ,QACA,sBAAsB,OACtB,QACA,cACA,iBACA,eACA,eACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,MACrB,eACE;CACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,OAAO,qBACzE;CACF,MAAM,gBAAgB,EAAC,qBAAoB;CAC3C,MAAM,CAAC,OAAO,YAAY,SAAkB,KAAK;AACjD,KAAI,MACF,KAAI,kBAAkB,MAAM,CAC1B,OAAM,IAAI,MACR,8EAA8E,OAAO,OAAO,wEAAwE,MAAM,eAAe,iBAAiB,MAAM,iBAAiB,MACjO,EAAC,OAAO,OAAM,CACf;KAED,OAAM;CAIV,MAAM,SAAS,cAEX,aAAa;EACX;EACA;EACA;EACA;EACA;EACA,2BAA2B;EAC3B;EACA,QAAQ;EACR;EACD,CAAC,EACJ;EAAC;EAAS;EAAY;EAAS;EAAW;EAAkB;EAAO;EAAmB,CACvF;CAED,MAAM,CAAC,mBAAmB,wBAAwB,SAAyB,MAAM;CAEjF,MAAM,kBAAkB,eAAe,OAAO,UAAqB;AACjE,UAAQ,MAAM,MAAd;GACE,KAAK;AAEH,yBAAqB,MAAM;AAE3B,QAAI,cACF,OAAM,cAAc,OAAO,cAAc;aAChC,kBAAkB,SAAS,QAAQ,IAAI,aAAa,aAE7D,SAAQ,KACN,8DAA8D,sBAAsB,2EAA2E,sBAChK;AAEH;GAEF,KAAK;AACH,UAAM,OAAO,OAAO,cAAc;AAClC;GAEF,KAAK;AACH,UAAM,gBAAgB,OAAO,cAAc;AAC3C;GAEF,KAAK;AACH,UAAM,kBAAkB,OAAO,cAAc;AAC7C;GAEF,KAAK;AACH,QAAI,iBAAiB,OAAO;KAC1B,IAAI,WAAW,eAAe,MAAM,aAAa,OAAO,cAAc,GAAG;AACzE,SAAI,aAAa,MAAO;AACxB,SAAI,OAAO,SAAS,SAAS,IAAI,WAAW,GAAG;AAC7C,4BAAsB,qBAAqB,SAAS,CAAC;AACrD,UAAI,QAAQ,IAAI,aAAa,aAC3B,SAAQ,KACN,iFACA,WAAW,KACX,4CACA,MAAM,OACP;;UAIL,UACE,IAAI,MACF,mGAAmG,MAAM,UACzG,EAAC,OAAO,OAAM,CACf,CACF;AAEH;GAEF;AACE,aAAS,IAAI,MAAM,2BAA2B,EAAC,OAAO,OAAM,CAAC,CAAC;AAC9D;;GAEJ;AACF,iBAAgB;EACd,MAAM,eAAe,OAAO,KACzB,OAAO;GAAC,eAAe;GAAqB,KAAK;GAAW,CAAC,CAC7D,UAAU;GACT,OAAO,UAAU,sBAAsB,gBAAgB,MAAM,CAAC;GAC9D,QAAQ,UAAU,sBAAsB,SAAS,MAAM,CAAC;GACzD,CAAC;AACJ,eAAa,aAAa,aAAa;IACtC;EAAC,OAAO;EAAM;EAAY;EAAoB,CAAC;AAElD,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,qBAAqB,oBAAC,mBAAA,EAAkB,UAAU,mBAAA,CAAqB;EACvE,kBAAkB,oBAAC,gBAAA,EAAA,CAAiB;EACpC,sBAAsB,oBAAC,oBAAA,EAAA,CAAqB;KAC5C;;AAIP,WAAW,cAAc"}
|
package/dist/VisualEditing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
2
|
import { VisualEditing as VisualEditing$1 } from "@sanity/visual-editing/react";
|
|
4
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { actionRefresh } from "next-sanity/visual-editing/server-actions";
|
|
6
6
|
function pathHasPrefix(path, prefix) {
|
|
7
7
|
if (typeof path !== "string") return false;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
import { useOptimistic } from "@sanity/visual-editing/react";
|
|
1
|
+
import { useIsPresentationTool, useOptimistic, useVisualEditingEnvironment } from "@sanity/visual-editing/react";
|
|
2
2
|
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
|
|
3
|
-
/**
|
|
4
|
-
* Detects if the application is considered to be in a "Live Preview" mode.
|
|
5
|
-
* Live Preview means that the application is either:
|
|
6
|
-
* - being previewed inside Sanity Presentation Tool
|
|
7
|
-
* - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as "Standalone Live Preview'"
|
|
8
|
-
* When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.
|
|
9
|
-
* This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,
|
|
10
|
-
* to avoid interrupting the user that is consuming your content.
|
|
11
|
-
* This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,
|
|
12
|
-
* while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.
|
|
13
|
-
*
|
|
14
|
-
* The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.
|
|
15
|
-
* Then `true` if it is, and `false` otherwise.
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
declare function useIsLivePreview(): boolean | null;
|
|
19
|
-
declare function useLiveEnvironment(): null;
|
|
20
3
|
/** @alpha */
|
|
21
4
|
type UsePresentationQueryReturnsInactive = {
|
|
22
5
|
data: null;
|
|
@@ -38,23 +21,10 @@ type UsePresentationQueryReturns<QueryString extends string> = UsePresentationQu
|
|
|
38
21
|
* Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.
|
|
39
22
|
* @alpha
|
|
40
23
|
*/
|
|
41
|
-
declare function usePresentationQuery<const QueryString extends string>(
|
|
24
|
+
declare function usePresentationQuery<const QueryString extends string>(_: {
|
|
42
25
|
query: QueryString;
|
|
43
26
|
params?: QueryParams | Promise<QueryParams>;
|
|
44
27
|
stega?: boolean;
|
|
45
28
|
}): UsePresentationQueryReturns<QueryString>;
|
|
46
|
-
|
|
47
|
-
* Detects if the application is being previewed inside Sanity Presentation Tool.
|
|
48
|
-
* Presentation Tool can open the application in an iframe, or in a new window.
|
|
49
|
-
* When in this context there are some UI you usually don't want to show,
|
|
50
|
-
* for example a Draft Mode toggle, or a "Viewing draft content" indicators, these are unnecessary and add clutter to
|
|
51
|
-
* the editorial experience.
|
|
52
|
-
* The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,
|
|
53
|
-
* then `true` if it is, and `false` otherwise.
|
|
54
|
-
* @public
|
|
55
|
-
*/
|
|
56
|
-
declare function useIsPresentationTool(): boolean | null;
|
|
57
|
-
type VisualEditingEnvironment = null | "unknown" | "presentation-iframe" | "presentation-window" | "standalone";
|
|
58
|
-
declare function useVisualEditingEnvironment(): VisualEditingEnvironment;
|
|
59
|
-
export { UsePresentationQueryReturns, UsePresentationQueryReturnsActive, UsePresentationQueryReturnsInactive, useIsLivePreview, useIsPresentationTool, useLiveEnvironment, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
29
|
+
export { useIsPresentationTool, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
60
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/visual-editing/hooks/usePresentationQuery.ts"],"mappings":";;;KAGY,mCAAA;EACV,IAAA;EACA,SAAA;EACA,WAAA;AAAA;;KAIU,iCAAA;EACV,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,WAAA,EAAa,iBAAA;AAAA;AAAA,KAGH,2BAAA,+BACR,mCAAA,GACA,iCAAA,CAAkC,WAAA;;;;;;;;;iBAgBtB,oBAAA,kCAAA,CAAuD,CAAA;EACrE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;EAC/B,KAAA;AAAA,IACE,2BAAA,CAA4B,WAAA"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,117 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { dequal } from "dequal/lite";
|
|
4
|
-
import { useEffect, useEffectEvent, useMemo, useReducer, useSyncExternalStore } from "react";
|
|
5
|
-
import { useOptimistic } from "@sanity/visual-editing/react";
|
|
6
|
-
function useIsLivePreview() {
|
|
7
|
-
console.log("TODO: Implement useIsLivePreview");
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
function useLiveEnvironment() {
|
|
11
|
-
console.log("TODO: Implement useLiveEnvironment");
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const comlinkListeners = /* @__PURE__ */ new Set();
|
|
15
|
-
let comlink = null;
|
|
16
|
-
let comlinkProjectId = null;
|
|
17
|
-
let comlinkDataset = null;
|
|
18
|
-
let comlinkPerspective = null;
|
|
19
|
-
function reducer(state, { type, payload }) {
|
|
20
|
-
switch (type) {
|
|
21
|
-
case "query-change": return dequal(state, payload) ? state : {
|
|
22
|
-
...state,
|
|
23
|
-
data: dequal(state.data, payload.data) ? state.data : payload.data,
|
|
24
|
-
sourceMap: dequal(state.sourceMap, payload.sourceMap) ? state.sourceMap : payload.sourceMap,
|
|
25
|
-
perspective: dequal(state.perspective, payload.perspective) ? state.perspective : payload.perspective
|
|
26
|
-
};
|
|
27
|
-
default: return state;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
2
|
+
import { useIsPresentationTool, useOptimistic, useVisualEditingEnvironment } from "@sanity/visual-editing/react";
|
|
30
3
|
const initialState = {
|
|
31
4
|
data: null,
|
|
32
5
|
sourceMap: null,
|
|
33
6
|
perspective: null
|
|
34
7
|
};
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
const EMPTY_QUERY_PARAMS = {};
|
|
40
|
-
const LISTEN_HEARTBEAT_INTERVAL = 1e4;
|
|
41
|
-
function usePresentationQuery(props) {
|
|
42
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
43
|
-
const { query, params = EMPTY_QUERY_PARAMS, stega = true } = props;
|
|
44
|
-
const comlink$1 = useSyncExternalStore(subscribe, () => comlink, () => null);
|
|
45
|
-
const projectId = useSyncExternalStore(subscribe, () => comlinkProjectId, () => null);
|
|
46
|
-
const dataset = useSyncExternalStore(subscribe, () => comlinkDataset, () => null);
|
|
47
|
-
const perspective = useSyncExternalStore(subscribe, () => comlinkPerspective, () => null);
|
|
48
|
-
const handleQueryHeartbeat = useEffectEvent((comlink) => {
|
|
49
|
-
if (!projectId || !dataset || !perspective) {
|
|
50
|
-
console.warn("usePresentationQuery: projectId, dataset and perspective must be set", {
|
|
51
|
-
projectId,
|
|
52
|
-
dataset,
|
|
53
|
-
perspective
|
|
54
|
-
});
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (perspective === null) return;
|
|
58
|
-
comlink.post("loader/query-listen", {
|
|
59
|
-
projectId,
|
|
60
|
-
dataset,
|
|
61
|
-
perspective,
|
|
62
|
-
query,
|
|
63
|
-
params,
|
|
64
|
-
heartbeat: LISTEN_HEARTBEAT_INTERVAL
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
const handleQueryChange = useEffectEvent((event) => {
|
|
68
|
-
if (dequal({
|
|
69
|
-
projectId,
|
|
70
|
-
dataset,
|
|
71
|
-
query,
|
|
72
|
-
params
|
|
73
|
-
}, {
|
|
74
|
-
projectId: event.projectId,
|
|
75
|
-
dataset: event.dataset,
|
|
76
|
-
query: event.query,
|
|
77
|
-
params: event.params
|
|
78
|
-
})) dispatch({
|
|
79
|
-
type: "query-change",
|
|
80
|
-
payload: {
|
|
81
|
-
data: event.result,
|
|
82
|
-
sourceMap: event.resultSourceMap || null,
|
|
83
|
-
perspective: event.perspective
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (!comlink$1) return;
|
|
89
|
-
const unsubscribe = comlink$1.on("loader/query-change", handleQueryChange);
|
|
90
|
-
const interval = setInterval(() => handleQueryHeartbeat(comlink$1), LISTEN_HEARTBEAT_INTERVAL);
|
|
91
|
-
return () => {
|
|
92
|
-
clearInterval(interval);
|
|
93
|
-
unsubscribe();
|
|
94
|
-
};
|
|
95
|
-
}, [comlink$1]);
|
|
96
|
-
return useMemo(() => {
|
|
97
|
-
if (stega && state.sourceMap) return {
|
|
98
|
-
...state,
|
|
99
|
-
data: stegaEncodeSourceMap(state.data, state.sourceMap, {
|
|
100
|
-
enabled: true,
|
|
101
|
-
studioUrl: "/"
|
|
102
|
-
})
|
|
103
|
-
};
|
|
104
|
-
return state;
|
|
105
|
-
}, [state, stega]);
|
|
106
|
-
}
|
|
107
|
-
function useIsPresentationTool() {
|
|
108
|
-
console.log("TODO: Implement useIsPresentationTool");
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
function useVisualEditingEnvironment() {
|
|
112
|
-
console.log("TODO: Implement useVisualEditingEnvironment");
|
|
113
|
-
return null;
|
|
8
|
+
function usePresentationQuery(_) {
|
|
9
|
+
console.log("TODO: Implement usePresentationQuery");
|
|
10
|
+
return initialState;
|
|
114
11
|
}
|
|
115
|
-
export {
|
|
12
|
+
export { useIsPresentationTool, useOptimistic, usePresentationQuery, useVisualEditingEnvironment };
|
|
116
13
|
|
|
117
14
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["comlink","comlinkSnapshot"],"sources":["../../src/hooks/useIsLivePreview.ts","../../src/live/hooks/useLiveEnvironment.ts","../../src/live/shared/context.ts","../../src/live/hooks/usePresentationQuery.ts","../../src/visual-editing/hooks/useIsPresentationTool.ts","../../src/visual-editing/hooks/useVisualEditingEnvironment.ts"],"sourcesContent":["/**\n * Detects if the application is considered to be in a \"Live Preview\" mode.\n * Live Preview means that the application is either:\n * - being previewed inside Sanity Presentation Tool\n * - being previewed in Draft Mode, with a `browserToken` given to `defineLive`, also known as \"Standalone Live Preview'\"\n * When in Live Preview mode, you typically want UI to update as new content comes in, without any manual intervention.\n * This is very different from Live Production mode, where you usually want to delay updates that might cause layout shifts,\n * to avoid interrupting the user that is consuming your content.\n * This hook lets you adapt to this difference, making sure production doesn't cause layout shifts that worsen the UX,\n * while in Live Preview mode layout shift is less of an issue and it's better for the editorial experience to auto refresh in real time.\n *\n * The hook returns `null` initially, to signal it doesn't yet know if it's live previewing or not.\n * Then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsLivePreview(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsLivePreview')\n\n return null\n}\n","export function useLiveEnvironment(): null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useLiveEnvironment')\n\n return null\n}\n","import type {ClientPerspective} from '@sanity/client'\nimport type {Node} from '@sanity/comlink'\nimport type {LoaderControllerMsg, LoaderNodeMsg} from '@sanity/presentation-comlink'\n\nexport const comlinkListeners: Set<() => void> = new Set()\nexport let comlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null = null\nexport let comlinkProjectId: string | null = null\nexport let comlinkDataset: string | null = null\nexport let comlinkPerspective: ClientPerspective | null = null\nexport function setComlink(nextComlink: Node<LoaderNodeMsg, LoaderControllerMsg> | null): void {\n comlink = nextComlink\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkClientConfig(\n nextComlinkProjectId: string | null,\n nextComlinkDataset: string | null,\n): void {\n comlinkProjectId = nextComlinkProjectId\n comlinkDataset = nextComlinkDataset\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\nexport function setComlinkPerspective(nextComlinkPerspective: ClientPerspective | null): void {\n if (comlinkPerspective?.toString() === nextComlinkPerspective?.toString()) return\n comlinkPerspective = nextComlinkPerspective\n for (const onComlinkChange of comlinkListeners) {\n onComlinkChange()\n }\n}\n","import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\nimport type {LoaderControllerMsg} from '@sanity/presentation-comlink'\n\nimport {\n comlinkDataset,\n comlinkListeners,\n comlinkProjectId,\n comlinkPerspective,\n comlink as comlinkSnapshot,\n} from '#live/context'\nimport {stegaEncodeSourceMap} from '@sanity/client/stega'\nimport {dequal} from 'dequal/lite'\nimport {useEffect, useMemo, useReducer, useSyncExternalStore, useEffectEvent} from 'react'\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\ntype Action<QueryString extends string> = {\n type: 'query-change'\n payload: UsePresentationQueryReturnsActive<QueryString>\n}\n\nfunction reducer<QueryString extends string>(\n state: UsePresentationQueryReturns<QueryString>,\n {type, payload}: Action<QueryString>,\n): UsePresentationQueryReturns<QueryString> {\n switch (type) {\n case 'query-change':\n return dequal(state, payload)\n ? state\n : {\n ...state,\n data: dequal(state.data, payload.data)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.data as ClientReturn<QueryString>)\n : payload.data,\n sourceMap: dequal(state.sourceMap, payload.sourceMap)\n ? state.sourceMap\n : payload.sourceMap,\n perspective: dequal(state.perspective, payload.perspective)\n ? // oxlint-disable-next-line no-unsafe-type-assertion\n (state.perspective as Exclude<ClientPerspective, 'raw'>)\n : payload.perspective,\n }\n default:\n return state\n }\n}\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\nfunction subscribe(listener: () => void) {\n comlinkListeners.add(listener)\n return () => comlinkListeners.delete(listener)\n}\n\nconst EMPTY_QUERY_PARAMS: QueryParams = {}\nconst LISTEN_HEARTBEAT_INTERVAL = 10_000\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(props: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n const [state, dispatch] = useReducer(reducer, initialState)\n const {query, params = EMPTY_QUERY_PARAMS, stega = true} = props\n\n /**\n * Comlink forwards queries we want to run to the parent window where Presentation Tool handles it for us\n */\n const comlink = useSyncExternalStore(\n subscribe,\n () => comlinkSnapshot,\n () => null,\n )\n /**\n * The comlink events requires projectId and dataset, Presentation Tool uses it to protect against project and dataset mismatch errors.\n * We don't want to force the consumers of the `usePresentationQuery` hook to provide these,\n * so we set them in the component that establishes the comlink connection and propagates it to all the subscribes.\n */\n const projectId = useSyncExternalStore(\n subscribe,\n () => comlinkProjectId,\n () => null,\n )\n const dataset = useSyncExternalStore(\n subscribe,\n () => comlinkDataset,\n () => null,\n )\n /**\n * The perspective is kept in sync with Presentation Tool's perspective, and even knows what perspective the page loaded with initially and can forward it to the Sanity Studio.\n */\n const perspective = useSyncExternalStore(\n subscribe,\n () => comlinkPerspective,\n () => null,\n )\n\n const handleQueryHeartbeat = useEffectEvent((comlink: NonNullable<typeof comlinkSnapshot>) => {\n // Handle odd case where the comlink can take events but some data is missing\n if (!projectId || !dataset || !perspective) {\n console.warn('usePresentationQuery: projectId, dataset and perspective must be set', {\n projectId,\n dataset,\n perspective,\n })\n return\n }\n // Another odd case where the initial perspective states haven't resolved to the actual perspective state\n if (perspective === null) {\n return\n }\n comlink.post('loader/query-listen', {\n projectId,\n dataset,\n perspective,\n query,\n params,\n heartbeat: LISTEN_HEARTBEAT_INTERVAL,\n })\n })\n const handleQueryChange = useEffectEvent(\n (event: Extract<LoaderControllerMsg, {type: 'loader/query-change'}>['data']) => {\n if (\n dequal(\n {\n projectId,\n dataset,\n query,\n params,\n },\n {\n projectId: event.projectId,\n dataset: event.dataset,\n query: event.query,\n params: event.params,\n },\n )\n ) {\n dispatch({\n type: 'query-change',\n payload: {\n data: event.result,\n sourceMap: event.resultSourceMap || null,\n perspective: event.perspective,\n },\n })\n }\n },\n )\n useEffect(() => {\n if (!comlink) return\n\n const unsubscribe = comlink.on('loader/query-change', handleQueryChange)\n const interval = setInterval(() => handleQueryHeartbeat(comlink), LISTEN_HEARTBEAT_INTERVAL)\n return () => {\n clearInterval(interval)\n unsubscribe()\n }\n }, [comlink])\n\n return useMemo(() => {\n if (stega && state.sourceMap) {\n return {\n ...state,\n data: stegaEncodeSourceMap(state.data, state.sourceMap, {enabled: true, studioUrl: '/'}),\n }\n }\n return state\n }, [state, stega])\n}\n","/**\n * Detects if the application is being previewed inside Sanity Presentation Tool.\n * Presentation Tool can open the application in an iframe, or in a new window.\n * When in this context there are some UI you usually don't want to show,\n * for example a Draft Mode toggle, or a \"Viewing draft content\" indicators, these are unnecessary and add clutter to\n * the editorial experience.\n * The hook returns `null` initially, when it's not yet sure if the application is running inside Presentation Tool,\n * then `true` if it is, and `false` otherwise.\n * @public\n */\nexport function useIsPresentationTool(): boolean | null {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useIsPresentationTool')\n\n return null\n}\n","type VisualEditingEnvironment =\n | null\n | 'unknown'\n | 'presentation-iframe'\n | 'presentation-window'\n | 'standalone'\n\nexport function useVisualEditingEnvironment(): VisualEditingEnvironment {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement useVisualEditingEnvironment')\n\n return null\n}\n"],"mappings":";;;;;AAeA,SAAgB,mBAAmC;AAEjD,SAAQ,IAAI,mCAAmC;AAE/C,QAAO;;ACnBT,SAAgB,qBAA2B;AAEzC,SAAQ,IAAI,qCAAqC;AAEjD,QAAO;;ACAT,MAAa,mCAAoC,IAAI,KAAK;AAC1D,IAAW,UAA2D;AACtE,IAAW,mBAAkC;AAC7C,IAAW,iBAAgC;AAC3C,IAAW,qBAA+C;AC6B1D,SAAS,QACP,OACA,EAAC,MAAM,WACmC;AAC1C,SAAQ,MAAR;EACE,KAAK,eACH,QAAO,OAAO,OAAO,QAAQ,GACzB,QACA;GACE,GAAG;GACH,MAAM,OAAO,MAAM,MAAM,QAAQ,KAAK,GAEjC,MAAM,OACP,QAAQ;GACZ,WAAW,OAAO,MAAM,WAAW,QAAQ,UAAU,GACjD,MAAM,YACN,QAAQ;GACZ,aAAa,OAAO,MAAM,aAAa,QAAQ,YAAY,GAEtD,MAAM,cACP,QAAQ;GACb;EACP,QACE,QAAO;;;AAGb,MAAM,eAAoD;CACxD,MAAM;CACN,WAAW;CACX,aAAa;CACd;AAED,SAAS,UAAU,UAAsB;AACvC,kBAAiB,IAAI,SAAS;AAC9B,cAAa,iBAAiB,OAAO,SAAS;;AAGhD,MAAM,qBAAkC,EAAE;AAC1C,MAAM,4BAA4B;AAUlC,SAAgB,qBAAuD,OAI1B;CAC3C,MAAM,CAAC,OAAO,YAAY,WAAW,SAAS,aAAa;CAC3D,MAAM,EAAC,OAAO,SAAS,oBAAoB,QAAQ,SAAQ;CAK3D,MAAMA,YAAU,qBACd,iBACMC,eACA,KACP;CAMD,MAAM,YAAY,qBAChB,iBACM,wBACA,KACP;CACD,MAAM,UAAU,qBACd,iBACM,sBACA,KACP;CAID,MAAM,cAAc,qBAClB,iBACM,0BACA,KACP;CAED,MAAM,uBAAuB,gBAAgB,YAAiD;AAE5F,MAAI,CAAC,aAAa,CAAC,WAAW,CAAC,aAAa;AAC1C,WAAQ,KAAK,wEAAwE;IACnF;IACA;IACA;IACD,CAAC;AACF;;AAGF,MAAI,gBAAgB,KAClB;AAEF,UAAQ,KAAK,uBAAuB;GAClC;GACA;GACA;GACA;GACA;GACA,WAAW;GACZ,CAAC;GACF;CACF,MAAM,oBAAoB,gBACvB,UAA+E;AAC9E,MACE,OACE;GACE;GACA;GACA;GACA;GACD,EACD;GACE,WAAW,MAAM;GACjB,SAAS,MAAM;GACf,OAAO,MAAM;GACb,QAAQ,MAAM;GACf,CACF,CAED,UAAS;GACP,MAAM;GACN,SAAS;IACP,MAAM,MAAM;IACZ,WAAW,MAAM,mBAAmB;IACpC,aAAa,MAAM;IACpB;GACF,CAAC;GAGP;AACD,iBAAgB;AACd,MAAI,CAACD,UAAS;EAEd,MAAM,cAAcA,UAAQ,GAAG,uBAAuB,kBAAkB;EACxE,MAAM,WAAW,kBAAkB,qBAAqBA,UAAQ,EAAE,0BAA0B;AAC5F,eAAa;AACX,iBAAc,SAAS;AACvB,gBAAa;;IAEd,CAACA,UAAQ,CAAC;AAEb,QAAO,cAAc;AACnB,MAAI,SAAS,MAAM,UACjB,QAAO;GACL,GAAG;GACH,MAAM,qBAAqB,MAAM,MAAM,MAAM,WAAW;IAAC,SAAS;IAAM,WAAW;IAAI,CAAC;GACzF;AAEH,SAAO;IACN,CAAC,OAAO,MAAM,CAAC;;AC1LpB,SAAgB,wBAAwC;AAEtD,SAAQ,IAAI,wCAAwC;AAEpD,QAAO;;ACPT,SAAgB,8BAAwD;AAEtE,SAAQ,IAAI,8CAA8C;AAE1D,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/visual-editing/hooks/usePresentationQuery.ts"],"sourcesContent":["import type {ClientPerspective, ClientReturn, ContentSourceMap, QueryParams} from '@sanity/client'\n\n/** @alpha */\nexport type UsePresentationQueryReturnsInactive = {\n data: null\n sourceMap: null\n perspective: null\n}\n\n/** @alpha */\nexport type UsePresentationQueryReturnsActive<QueryString extends string> = {\n data: ClientReturn<QueryString>\n sourceMap: ContentSourceMap | null\n perspective: ClientPerspective\n}\n\nexport type UsePresentationQueryReturns<QueryString extends string> =\n | UsePresentationQueryReturnsInactive\n | UsePresentationQueryReturnsActive<QueryString>\n\nconst initialState: UsePresentationQueryReturnsInactive = {\n data: null,\n sourceMap: null,\n perspective: null,\n}\n\n/**\n * Experimental hook that can run queries in Presentation Tool.\n * Query results are sent back over postMessage whenever the query results change.\n * It also works with optimistic updates in the studio itself, offering low latency updates.\n * It's not as low latency as the `useOptimistic` hook, but it's a good compromise for some use cases.\n * Especially until `useOptimistic` propagates edits in the Studio parent window back into the iframe.\n * @alpha\n */\nexport function usePresentationQuery<const QueryString extends string>(_: {\n query: QueryString\n params?: QueryParams | Promise<QueryParams>\n stega?: boolean\n}): UsePresentationQueryReturns<QueryString> {\n // oxlint-disable-next-line no-console\n console.log('TODO: Implement usePresentationQuery')\n\n return initialState\n}\n"],"mappings":";;AAoBA,MAAM,eAAoD;CACxD,MAAM;CACN,WAAW;CACX,aAAa;CACd;AAUD,SAAgB,qBAAuD,GAI1B;AAE3C,SAAQ,IAAI,uCAAuC;AAEnD,QAAO"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { stegaClean } from "@sanity/client/stega";
|
|
3
2
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
3
|
+
import { stegaClean } from "@sanity/client/stega";
|
|
4
4
|
import { CreateDataAttribute, CreateDataAttributeProps, createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
5
5
|
import groq, { defineQuery } from "groq";
|
|
6
6
|
export * from "@sanity/client";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "./isCorsOriginError.js";
|
|
2
|
-
import { stegaClean } from "@sanity/client/stega";
|
|
3
2
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
3
|
+
import { stegaClean } from "@sanity/client/stega";
|
|
4
4
|
import { createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
5
5
|
import groq, { defineQuery } from "groq";
|
|
6
6
|
export * from "@portabletext/react";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-life.d.ts","names":[],"sources":["../../src/live/cache-life.ts"],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAa,MAAA;;;;WAIX,UAAA;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-life.js","names":[],"sources":["../../src/live/cache-life.ts"],"sourcesContent":["import {revalidate} from '#live/constants'\n\n/**\n * For usage with `cacheComponents: true`, and `defineLive`:\n * ```ts\n * // next.config.ts\n *\n * import type {NextConfig} from 'next'\n * import {sanity} from 'next-sanity/cache-life'\n *\n * const nextConfig: NextConfig = {\n * cacheComponents: true,\n * cacheLife: {\n * sanity\n * }\n * }\n *\n * export default nextConfig\n * ```\n *\n * ```ts\n *\n * async function sanityFetch() {\n * 'use cache'\n * cacheLife('sanity')\n * const {data} = await fetch({query, params})\n * return data\n * }\n */\nexport const sanity = {\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\n revalidate: 31_536_000, // 365 days\n} as const satisfies {\n /**\n * This cache may be stale on clients for ... seconds before checking with the server.\n */\n stale?: number\n /**\n * If the server receives a new request after ... seconds, start revalidating new values in the background.\n */\n revalidate?: typeof revalidate\n /**\n * If this entry has no traffic for ... seconds it will expire. The next request will recompute it.\n */\n expire?: number\n}\n"],"mappings":"AA6BA,MAAa,SAAS,EAIpB,YAAY,SACb"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as SanityLiveActionContext } from "../../types.js";
|
|
2
2
|
import { InitializedClientConfig, LiveEvent } from "@sanity/client";
|
|
3
3
|
interface SanityClientConfig extends Pick<InitializedClientConfig, "projectId" | "dataset" | "apiHost" | "apiVersion" | "useProjectHostname" | "token" | "requestTagPrefix"> {}
|
|
4
4
|
interface SanityLiveProps {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
2
|
+
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
|
+
import { t as ResolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
7
|
declare function defineLive(_config: DefineLiveOptions): {
|
|
8
|
-
sanityFetch:
|
|
8
|
+
sanityFetch: DefinedFetchType;
|
|
9
9
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"mappings":";;;;AAcA;;iBAAgB,UAAA,CAAW,OAAA,EAAS,iBAAA;EAClC,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA;;;;;cASrB,6BAAA,EAA+B,6BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {ResolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/live/conditions/default/index.ts"],"sourcesContent":["// This is the fallback export condition for `import 'next-sanity/live'`,\n// it should have the same type definitions as the other conditions so that userland don't have to worry about setting the right\n// `customCondition` in their `tsconfig.json` in order to get accurate typings.\n// The implementation here though should all throw errors, as importing this file means userland made a mistake and somehow a client component is\n// trying to pull in something it shouldn't.\n\nimport type {ResolvePerspectiveFromCookies} from '#live/resolvePerspectiveFromCookies'\nimport type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nexport {isCorsOriginError} from '#live/isCorsOriginError'\n\n/**\n * @public\n */\nexport function defineLive(_config: DefineLiveOptions): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n throw new Error(`defineLive can't be imported by a client component`)\n}\n\n/**\n * Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from \"next-sanity/draft-mode\"`\n * @public\n */\nexport const resolvePerspectiveFromCookies: ResolvePerspectiveFromCookies = () => {\n throw new Error(`resolvePerspectiveFromCookies can't be imported by a client component`)\n}\n\nexport type {PerspectiveType as LivePerspective} from '#live/types'\n"],"mappings":";AAcA,SAAgB,WAAW,SAGzB;AACA,OAAM,IAAI,MAAM,qDAAqD;;AAOvE,MAAa,sCAAqE;AAChF,OAAM,IAAI,MAAM,wEAAwE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
2
|
+
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
|
+
import { n as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
4
|
declare function defineLive(config: DefineLiveOptions): {
|
|
5
|
-
sanityFetch:
|
|
5
|
+
sanityFetch: DefinedFetchType;
|
|
6
6
|
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
7
7
|
};
|
|
8
8
|
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"mappings":";;;iBAQgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EACjC,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as PUBLISHED_SYNC_TAG_PREFIX, r as revalidate, t as DRAFT_SYNC_TAG_PREFIX } from "../../../constants.js";
|
|
2
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
+
import { n as PUBLISHED_SYNC_TAG_PREFIX, r as revalidate, t as DRAFT_SYNC_TAG_PREFIX } from "../../../constants.js";
|
|
3
3
|
import { t as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { SanityLive } from "next-sanity/live/client-components";
|
|
@@ -18,7 +18,7 @@ function defineLive(config) {
|
|
|
18
18
|
const { token: originalToken } = client.config();
|
|
19
19
|
const fetch = async function fetch({ query, params = {}, perspective = "published", stega = false, tags: customCacheTags = [], requestTag = "next-loader.fetch.cache-components" }) {
|
|
20
20
|
const useCdn = perspective === "published";
|
|
21
|
-
const { result, resultSourceMap, syncTags } = await client.fetch(query, params, {
|
|
21
|
+
const { result, resultSourceMap, syncTags } = await client.fetch(query, await params, {
|
|
22
22
|
filterResponse: false,
|
|
23
23
|
returnQuery: false,
|
|
24
24
|
perspective,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} 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 {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {preconnect} from 'react-dom'\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/next-js/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} 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 {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cacheLife, cacheTag} from 'next/cache'\nimport {preconnect} from 'react-dom'\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\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, await 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 includeAllDocuments = false,\n action = actionUpdateTags,\n restartAction = actionRefresh,\n reconnectAction = actionRefresh,\n goAwayAction,\n welcomeAction,\n refreshOnMount = false,\n refreshOnFocus = false,\n refreshOnReconnect = false,\n requestTag = 'next-loader.live.cache-components',\n } = props\n\n const shouldIncludeDrafts = typeof browserToken === 'string' && includeAllDocuments\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 <SanityLiveClientComponent\n config={{\n projectId,\n dataset,\n apiHost,\n apiVersion,\n useProjectHostname,\n requestTagPrefix,\n token: shouldIncludeDrafts ? browserToken : undefined,\n }}\n includeAllDocuments={shouldIncludeDrafts}\n action={action}\n reconnectAction={reconnectAction === false ? undefined : reconnectAction}\n restartAction={restartAction === false ? undefined : restartAction}\n welcomeAction={welcomeAction}\n goAwayAction={goAwayAction}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\n />\n )\n }\n Live.displayName = 'SanityLiveServerComponent'\n\n return {\n sanityFetch: fetch,\n SanityLive: Live,\n }\n}\n"],"mappings":";;;;;;;;AAQA,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,eAAe,MAAM,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,MAAM,QAAQ;GAClF,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,SAAS,KAAK,OAAO;EACvE,MAAM,EACJ,sBAAsB,OACtB,SAAS,kBACT,gBAAgB,eAChB,kBAAkB,eAClB,cACA,eACA,iBAAiB,OACjB,iBAAiB,OACjB,qBAAqB,OACrB,aAAa,wCACX;EAEJ,MAAM,sBAAsB,OAAO,iBAAiB,YAAY;EAEhE,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,oBAACA,YAAAA;GACC,QAAQ;IACN;IACA;IACA;IACA;IACA;IACA;IACA,OAAO,sBAAsB,eAAe,KAAA;IAC7C;GACD,qBAAqB;GACb;GACR,iBAAiB,oBAAoB,QAAQ,KAAA,IAAY;GACzD,eAAe,kBAAkB,QAAQ,KAAA,IAAY;GACtC;GACD;GACF;GACI;GACA;GACI;IACpB;;AAGN,MAAK,cAAc;AAEnB,QAAO;EACL,aAAa;EACb,YAAY;EACb"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { t as isCorsOriginError } from "../../../isCorsOriginError.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { i as PerspectiveType, n as DefinedFetchType, r as DefinedLiveProps, t as DefineLiveOptions } from "../../../types.js";
|
|
3
|
+
import { n as resolvePerspectiveFromCookies } from "../../../resolvePerspectiveFromCookies.js";
|
|
4
|
+
declare function defineLive(config: DefineLiveOptions): {
|
|
5
|
+
sanityFetch: DefinedFetchType;
|
|
6
|
+
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
7
|
+
};
|
|
8
|
+
export { type PerspectiveType as LivePerspective, defineLive, isCorsOriginError, resolvePerspectiveFromCookies };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"mappings":";;;iBAUgB,UAAA,CAAW,MAAA,EAAQ,iBAAA;EACjC,WAAA,EAAa,gBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":["SanityLive","SanityLiveClientComponent"],"sources":["../../../../src/live/conditions/react-server/defineLive.tsx"],"sourcesContent":["import type {DefinedFetchType, DefinedLiveProps, DefineLiveOptions} from '#live/types'\n\nimport {sanitizePerspective} from '#live/sanitizePerspective'\nimport {type ClientPerspective, type QueryParams} from '@sanity/client'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {SanityLive as SanityLiveClientComponent} from 'next-sanity/live/client-components'\nimport {actionRefresh, actionUpdateTags} from 'next-sanity/live/server-actions'\nimport {cookies, draftMode} from 'next/headers'\nimport {preconnect} from 'react-dom'\n\nexport function defineLive(config: DefineLiveOptions): {\n sanityFetch: DefinedFetchType\n SanityLive: React.ComponentType<DefinedLiveProps>\n} {\n const {client: _client, serverToken, browserToken, stega: stegaEnabled = true} = 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: DefinedFetchType = 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 = false\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<DefinedLiveProps> = async function SanityLive(props) {\n const {\n includeAllDocuments = (await draftMode()).isEnabled,\n action = actionUpdateTags,\n restartAction = actionRefresh,\n reconnectAction = actionRefresh,\n goAwayAction,\n welcomeAction,\n refreshOnMount,\n refreshOnFocus,\n refreshOnReconnect,\n requestTag = 'next-loader.live',\n } = props\n const {projectId, dataset, apiHost, apiVersion, useProjectHostname, requestTagPrefix} =\n client.config()\n const shouldIncludeAllDocuments = typeof browserToken === 'string' && includeAllDocuments\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: shouldIncludeAllDocuments ? browserToken : undefined,\n }}\n includeAllDocuments={shouldIncludeAllDocuments}\n action={action}\n reconnectAction={reconnectAction === false ? undefined : reconnectAction}\n restartAction={restartAction === false ? undefined : restartAction}\n welcomeAction={welcomeAction}\n goAwayAction={goAwayAction}\n requestTag={requestTag}\n refreshOnMount={refreshOnMount}\n refreshOnFocus={refreshOnFocus}\n refreshOnReconnect={refreshOnReconnect}\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":";;;;;;;;;AAUA,SAAgB,WAAW,QAGzB;CACA,MAAM,EAAC,QAAQ,SAAS,aAAa,cAAc,OAAO,eAAe,SAAQ;AAEjF,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,cAAgC,eAAe,YAEnD,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,aAAa;EAGnB,MAAM,EAAC,aAAY,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACzD,gBAAgB;GACH;GACb,OAAO;GACP,aAAa;GACb,MAAM;IAAC;IAAY,MAAM,CAAC,GAAG,MAAM,yBAAyB;IAAC;GAC7D;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK,CAAC,YAAY,kBAAkB,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;GAC/D,CAAC;EAEF,MAAM,YAAY,CAAC,GAAG,MAAM,GAAI,UAAU,KAAK,QAAQ,UAAU,MAAM,IAAI,EAAE,CAAE;EAE/E,MAAM,EAAC,QAAQ,oBAAmB,MAAM,OAAO,MAAM,OAAO,MAAM,QAAQ;GACxE,gBAAgB;GACH;GACb;GACA,OAAO,gBAAgB,eAAe,cAAc,cAAc;GAClE,MAAM;IAAC;IAAY,MAAM;IAAU;GACnC;GACA,WAAW,SAAS,YAAY,KAAA;GAChC,KAAK;GACN,CAAC;AACF,SAAO;GAAC,MAAM;GAAQ,WAAW,mBAAmB;GAAM,MAAM;GAAU;;CAG5E,MAAMA,eAAoD,eAAeA,aAAW,OAAO;EACzF,MAAM,EACJ,uBAAuB,MAAM,WAAW,EAAE,WAC1C,SAAS,kBACT,gBAAgB,eAChB,kBAAkB,eAClB,cACA,eACA,gBACA,gBACA,oBACA,aAAa,uBACX;EACJ,MAAM,EAAC,WAAW,SAAS,SAAS,YAAY,oBAAoB,qBAClE,OAAO,QAAQ;EACjB,MAAM,4BAA4B,OAAO,iBAAiB,YAAY;EAGtE,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,4BAA4B,eAAe,KAAA;IACnD;GACD,qBAAqB;GACb;GACR,iBAAiB,oBAAoB,QAAQ,KAAA,IAAY;GACzD,eAAe,kBAAkB,QAAQ,KAAA,IAAY;GACtC;GACD;GACF;GACI;GACA;GACI;IACpB;;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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { cookies } from "next/headers";
|
|
2
|
+
import { ClientPerspective } from "@sanity/client";
|
|
3
|
+
type ResolvePerspectiveFromCookies = (options: {
|
|
4
|
+
/**
|
|
5
|
+
* You must await the cookies() function from next/headers
|
|
6
|
+
* and pass it here.
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { cookies } from 'next/headers'
|
|
10
|
+
*
|
|
11
|
+
* const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
cookies: Awaited<ReturnType<typeof cookies>>;
|
|
15
|
+
}) => Promise<Exclude<ClientPerspective, "raw">>;
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from "next-sanity/draft-mode"`
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare const resolvePerspectiveFromCookies: ({
|
|
21
|
+
cookies: jar
|
|
22
|
+
}: {
|
|
23
|
+
cookies: Awaited<ReturnType<typeof cookies>>;
|
|
24
|
+
}) => Promise<Exclude<ClientPerspective, "raw">>;
|
|
25
|
+
export { resolvePerspectiveFromCookies as n, ResolvePerspectiveFromCookies as t };
|
|
26
|
+
//# sourceMappingURL=resolvePerspectiveFromCookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvePerspectiveFromCookies.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts"],"mappings":";;KAOY,6BAAA,IAAiC,OAAA;EAA7C;;;;;;;;;;EAWE,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MAC/B,OAAA,CAAQ,OAAA,CAAQ,iBAAA;;;;;cAMT,6BAAA;EACX,OAAA,EAAS;AAAA;EAET,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MACjC,OAAA,CAAQ,OAAA,CAAQ,iBAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Suspense, lazy } from "react";
|
|
3
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Suspense, lazy } from "react";
|
|
4
4
|
const NextStudioClientComponent = lazy(() => import("../../NextStudio.js"));
|
|
5
5
|
function NextStudioLazyClientComponent(props) {
|
|
6
6
|
return /* @__PURE__ */ jsx(Suspense, {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientPerspective, LiveEvent, SanityClient } from "next-sanity";
|
|
1
|
+
import { ClientPerspective, ClientReturn, ContentSourceMap, LiveEvent, QueryParams, SanityClient } from "next-sanity";
|
|
2
2
|
/**
|
|
3
3
|
* Perspectives supported by Sanity Live.
|
|
4
4
|
* Using the legacy `'raw'` perspective is not supported and leads to undefined behavior.
|
|
@@ -7,6 +7,37 @@ type PerspectiveType = Exclude<ClientPerspective, "raw">;
|
|
|
7
7
|
/**
|
|
8
8
|
* TODO: docs
|
|
9
9
|
*/
|
|
10
|
+
type DefinedFetchType = <const QueryString extends string>(options: {
|
|
11
|
+
query: QueryString;
|
|
12
|
+
params?: QueryParams | Promise<QueryParams>;
|
|
13
|
+
/**
|
|
14
|
+
* @defaultValue 'published'
|
|
15
|
+
*/
|
|
16
|
+
perspective?: PerspectiveType;
|
|
17
|
+
/**
|
|
18
|
+
* Enables stega encoding of the data, this is typically only used in draft mode in conjunction with `perspective: 'drafts'` and with `@sanity/visual-editing` setup.
|
|
19
|
+
* @defaultValue `false`
|
|
20
|
+
*/
|
|
21
|
+
stega?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Custom cache tags that can be used with next's `updateTag` functions for custom `read-your-write` server actions,
|
|
24
|
+
* for example a like button that uses client.mutate to update a document and then immediately shows the result.
|
|
25
|
+
*/
|
|
26
|
+
tags?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
|
|
29
|
+
* @see https://www.sanity.io/docs/reference-api-request-tags
|
|
30
|
+
* @defaultValue 'next-loader.fetch'
|
|
31
|
+
*/
|
|
32
|
+
requestTag?: string;
|
|
33
|
+
}) => Promise<{
|
|
34
|
+
data: ClientReturn<QueryString, unknown>;
|
|
35
|
+
sourceMap: ContentSourceMap | null;
|
|
36
|
+
tags: string[];
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* TODO: docs
|
|
40
|
+
*/
|
|
10
41
|
interface SanityLiveActionContext {
|
|
11
42
|
includeAllDocuments: boolean;
|
|
12
43
|
}
|
|
@@ -77,5 +108,5 @@ interface DefineLiveOptions {
|
|
|
77
108
|
*/
|
|
78
109
|
stega?: boolean;
|
|
79
110
|
}
|
|
80
|
-
export { SanityLiveActionContext as i,
|
|
111
|
+
export { SanityLiveActionContext as a, PerspectiveType as i, DefinedFetchType as n, DefinedLiveProps as r, DefineLiveOptions as t };
|
|
81
112
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/live/shared/types.ts"],"mappings":";;AAcA;;;KAAY,eAAA,GAAkB,OAAA,CAAQ,iBAAA;;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/live/shared/types.ts"],"mappings":";;AAcA;;;KAAY,eAAA,GAAkB,OAAA,CAAQ,iBAAA;;AAKtC;;KAAY,gBAAA,sCAAsD,OAAA;EAChE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;;;;EAI/B,WAAA,GAAc,eAAA;;;;;EAKd,KAAA;;;;;EAKA,IAAA;;;;;;EAMA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA;;;;UAMe,uBAAA;EACf,mBAAA;AAAA;AAAA,UAQe,gBAAA;EAAjB;;;EAIE,mBAAA;;;;EAIA,MAAA,IACE,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EACL,aAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,YAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,eAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;EAET,aAAA,KAEM,KAAA,EAAO,OAAA,CAAQ,SAAA;IAAY,IAAA;EAAA,IAC3B,OAAA,EAAS,uBAAA,KACN,OAAA;;;;;EAOT,cAAA;;;;;EAKA,cAAA;;;;;EAKA,kBAAA;;;;;;EAOA,UAAA;AAAA;AAAA,UAGe,iBAAA;;;;EAIf,MAAA,EAAQ,YAAA;;;;;EAKR,WAAA;;;;;EAKA,YAAA;;;;;;EAMA,KAAA;AAAA"}
|
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.23",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"live",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"exports": {
|
|
40
40
|
".": "./dist/index.js",
|
|
41
|
-
"./cache-life": "./dist/cache-life.js",
|
|
42
41
|
"./draft-mode": "./dist/draft-mode/index.js",
|
|
43
42
|
"./hooks": "./dist/hooks/index.js",
|
|
44
43
|
"./image": "./dist/image/index.js",
|
|
@@ -47,6 +46,7 @@
|
|
|
47
46
|
"react-server": "./dist/live/conditions/react-server/index.js",
|
|
48
47
|
"default": "./dist/live/conditions/default/index.js"
|
|
49
48
|
},
|
|
49
|
+
"./live/cache-life": "./dist/live/cache-life.js",
|
|
50
50
|
"./live/client-components": "./dist/live/client-components/index.js",
|
|
51
51
|
"./live/server-actions": {
|
|
52
52
|
"next-js": "./dist/live/server-actions/index.next-js.js",
|
|
@@ -65,38 +65,38 @@
|
|
|
65
65
|
"@sanity/client": "^7.14.1",
|
|
66
66
|
"@sanity/comlink": "^4.0.1",
|
|
67
67
|
"@sanity/presentation-comlink": "^2.0.1",
|
|
68
|
-
"@sanity/preview-url-secret": "^4.0.
|
|
69
|
-
"@sanity/visual-editing": "^5.
|
|
68
|
+
"@sanity/preview-url-secret": "^4.0.3",
|
|
69
|
+
"@sanity/visual-editing": "^5.2.1",
|
|
70
70
|
"@sanity/webhook": "^4.0.4",
|
|
71
71
|
"dequal": "^2.0.3",
|
|
72
|
-
"groq": "^5.
|
|
72
|
+
"groq": "^5.8.1",
|
|
73
73
|
"history": "^5.3.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@sanity/tsconfig": "^2.1.0",
|
|
77
77
|
"@types/js-yaml": "^4.0.9",
|
|
78
|
-
"@types/node": "^24.10.
|
|
79
|
-
"@types/react": "^19.2.
|
|
78
|
+
"@types/node": "^24.10.11",
|
|
79
|
+
"@types/react": "^19.2.13",
|
|
80
80
|
"@types/react-dom": "^19.2.3",
|
|
81
|
-
"@vitejs/plugin-react": "^5.1.
|
|
81
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
82
82
|
"@vitest/coverage-v8": "^4.0.18",
|
|
83
83
|
"js-yaml": "^4.1.1",
|
|
84
|
-
"next": "16.2.0-canary.
|
|
84
|
+
"next": "16.2.0-canary.29",
|
|
85
85
|
"publint": "^0.3.17",
|
|
86
86
|
"react": "^19.2.4",
|
|
87
87
|
"react-dom": "^19.2.4",
|
|
88
88
|
"styled-components": "^6.3.8",
|
|
89
|
-
"tsdown": "0.20.
|
|
89
|
+
"tsdown": "0.20.3",
|
|
90
90
|
"typescript": "5.9.3",
|
|
91
91
|
"vitest": "^4.0.18",
|
|
92
|
-
"vitest-package-exports": "^1.
|
|
92
|
+
"vitest-package-exports": "^1.2.0"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@sanity/client": "^7.14.1",
|
|
96
96
|
"next": "^16.0.0-0",
|
|
97
97
|
"react": "^19.2.3",
|
|
98
98
|
"react-dom": "^19.2.3",
|
|
99
|
-
"sanity": "^5.
|
|
99
|
+
"sanity": "^5.8.1",
|
|
100
100
|
"styled-components": "^6.1"
|
|
101
101
|
},
|
|
102
102
|
"engines": {
|
package/dist/cache-life.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-life.d.ts","names":[],"sources":["../src/cache-life.ts"],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAa,MAAA;;;;WAIX,UAAA;AAAA"}
|
package/dist/cache-life.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-life.js","names":[],"sources":["../src/cache-life.ts"],"sourcesContent":["import {revalidate} from '#live/constants'\n\n/**\n * For usage with `cacheComponents: true`, and `defineLive`:\n * ```ts\n * // next.config.ts\n *\n * import type {NextConfig} from 'next'\n * import {sanity} from 'next-sanity/cache-life'\n *\n * const nextConfig: NextConfig = {\n * cacheComponents: true,\n * cacheLife: {\n * sanity\n * }\n * }\n *\n * export default nextConfig\n * ```\n *\n * ```ts\n *\n * async function sanityFetch() {\n * 'use cache'\n * cacheLife('sanity')\n * const {data} = await fetch({query, params})\n * return data\n * }\n */\nexport const sanity = {\n /**\n * Sanity Live handles on-demand revalidation, so the default 15min time based revalidation is too short\n */\n revalidate: 31_536_000, // 365 days\n} as const satisfies {\n /**\n * This cache may be stale on clients for ... seconds before checking with the server.\n */\n stale?: number\n /**\n * If the server receives a new request after ... seconds, start revalidating new values in the background.\n */\n revalidate?: typeof revalidate\n /**\n * If this entry has no traffic for ... seconds it will expire. The next request will recompute it.\n */\n expire?: number\n}\n"],"mappings":"AA6BA,MAAa,SAAS,EAIpB,YAAY,SACb"}
|
package/dist/defineLive.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { n as DefinedLiveProps, t as DefineLiveOptions } from "./types.js";
|
|
2
|
-
import { cookies } from "next/headers";
|
|
3
|
-
import { ClientPerspective, ClientReturn, ContentSourceMap, QueryParams } from "@sanity/client";
|
|
4
|
-
type ResolvePerspectiveFromCookies = (options: {
|
|
5
|
-
/**
|
|
6
|
-
* You must await the cookies() function from next/headers
|
|
7
|
-
* and pass it here.
|
|
8
|
-
* Example:
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { cookies } from 'next/headers'
|
|
11
|
-
*
|
|
12
|
-
* const perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
cookies: Awaited<ReturnType<typeof cookies>>;
|
|
16
|
-
}) => Promise<Exclude<ClientPerspective, "raw">>;
|
|
17
|
-
/**
|
|
18
|
-
* Resolves the perspective from the cookie that is set by `import { defineEnableDraftMode } from "next-sanity/draft-mode"`
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
declare const resolvePerspectiveFromCookies: ({
|
|
22
|
-
cookies: jar
|
|
23
|
-
}: {
|
|
24
|
-
cookies: Awaited<ReturnType<typeof cookies>>;
|
|
25
|
-
}) => Promise<Exclude<ClientPerspective, "raw">>;
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
type DefinedSanityFetchType = <const QueryString extends string>(options: {
|
|
30
|
-
query: QueryString;
|
|
31
|
-
params?: QueryParams | Promise<QueryParams>;
|
|
32
|
-
/**
|
|
33
|
-
* Add custom `next.tags` to the underlying fetch request.
|
|
34
|
-
* @see https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags
|
|
35
|
-
* 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).
|
|
36
|
-
* @defaultValue `['sanity']`
|
|
37
|
-
*/
|
|
38
|
-
tags?: string[];
|
|
39
|
-
perspective?: Exclude<ClientPerspective, "raw">;
|
|
40
|
-
stega?: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* This request tag is used to identify the request when viewing request logs from your Sanity Content Lake.
|
|
43
|
-
* @see https://www.sanity.io/docs/reference-api-request-tags
|
|
44
|
-
* @defaultValue 'next-loader.fetch'
|
|
45
|
-
*/
|
|
46
|
-
requestTag?: string;
|
|
47
|
-
}) => Promise<{
|
|
48
|
-
data: ClientReturn<QueryString>;
|
|
49
|
-
sourceMap: ContentSourceMap | null;
|
|
50
|
-
tags: string[];
|
|
51
|
-
}>;
|
|
52
|
-
declare function defineLive(config: DefineLiveOptions): {
|
|
53
|
-
sanityFetch: DefinedSanityFetchType;
|
|
54
|
-
SanityLive: React.ComponentType<DefinedLiveProps>;
|
|
55
|
-
};
|
|
56
|
-
export { resolvePerspectiveFromCookies as i, defineLive as n, ResolvePerspectiveFromCookies as r, DefinedSanityFetchType as t };
|
|
57
|
-
//# sourceMappingURL=defineLive.d.ts.map
|
package/dist/defineLive.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineLive.d.ts","names":[],"sources":["../src/live/shared/resolvePerspectiveFromCookies.ts","../src/live/conditions/react-server/defineLive.tsx"],"mappings":";;;KAOY,6BAAA,IAAiC,OAAA;;AAA7C;;;;;;;;;EAWE,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MAC/B,OAAA,CAAQ,OAAA,CAAQ,iBAAA;;;;;cAMT,6BAAA;EACX,OAAA,EAAS;AAAA;EAET,OAAA,EAAS,OAAA,CAAQ,UAAA,QAAkB,OAAA;AAAA,MACjC,OAAA,CAAQ,OAAA,CAAQ,iBAAA;;;AAtBpB;KCWY,sBAAA,sCAA4D,OAAA;EACtE,KAAA,EAAO,WAAA;EACP,MAAA,GAAS,WAAA,GAAc,OAAA,CAAQ,WAAA;;;;;;;EAO/B,IAAA;EACA,WAAA,GAAc,OAAA,CAAQ,iBAAA;EACtB,KAAA;;;;;;EAMA,UAAA;AAAA,MACI,OAAA;EACJ,IAAA,EAAM,YAAA,CAAa,WAAA;EACnB,SAAA,EAAW,gBAAA;EACX,IAAA;AAAA;AAAA,iBAKc,UAAA,CAAW,MAAA,EAAQ,iBAAA;EACjC,WAAA,EAAa,sBAAA;EACb,UAAA,EAAY,KAAA,CAAM,aAAA,CAAc,gBAAA;AAAA"}
|
|
File without changes
|
|
File without changes
|