next-sanity 9.12.0 → 9.12.2
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/_chunks-cjs/NextStudio.cjs.map +1 -1
- package/dist/_chunks-cjs/NextStudioNoScript.cjs +31 -48
- package/dist/_chunks-cjs/NextStudioNoScript.cjs.map +1 -1
- package/dist/_chunks-cjs/VisualEditing.cjs +6 -3
- package/dist/_chunks-cjs/VisualEditing.cjs.map +1 -1
- package/dist/_chunks-es/NextStudio.js.map +1 -1
- package/dist/_chunks-es/NextStudioNoScript.js +31 -48
- package/dist/_chunks-es/NextStudioNoScript.js.map +1 -1
- package/dist/_chunks-es/VisualEditing.js +6 -3
- package/dist/_chunks-es/VisualEditing.js.map +1 -1
- package/dist/draft-mode.cjs.map +1 -1
- package/dist/draft-mode.js.map +1 -1
- package/dist/image.cjs.map +1 -1
- package/dist/image.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.edge-light.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/studio/client-component.cjs.map +1 -1
- package/dist/studio/client-component.js.map +1 -1
- package/dist/studio.cjs.map +1 -1
- package/dist/studio.js.map +1 -1
- package/dist/visual-editing/client-component.cjs.map +1 -1
- package/dist/visual-editing/client-component.js.map +1 -1
- package/dist/visual-editing/server-actions.cjs.map +1 -1
- package/dist/visual-editing/server-actions.js.map +1 -1
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +10 -1
- package/dist/webhook.d.ts +10 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +20 -33
- package/src/studio/NextStudioLayout.tsx +9 -11
- package/src/studio/NextStudioNoScript.tsx +22 -21
- package/src/visual-editing/client-component/VisualEditing.tsx +9 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): React.JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":["history","createHashHistory","useState","ServerStyleSheet","useServerInsertedHTML","jsx","Fragment","StyleSheetManager","useSyncExternalStore","useMemo","jsxs","NextStudioNoScript","NextStudioLayout","Studio"],"mappings":";;AAGO,SAAS,6BAAsC;AACpD,QAAMA,YAAUC,QAAAA,
|
|
1
|
+
{"version":3,"file":"NextStudio.cjs","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): React.JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":["history","createHashHistory","useState","ServerStyleSheet","useServerInsertedHTML","jsx","Fragment","StyleSheetManager","useSyncExternalStore","useMemo","jsxs","NextStudioNoScript","NextStudioLayout","Studio"],"mappings":";;AAGO,SAAS,6BAAsC;AACpD,QAAMA,YAAUC,QAAAA,kBAAA;AAChB,SAAO;AAAA,IACL,IAAI,SAAS;AACX,aAAOD,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,WAAW;AACb,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,aAAa;AACf,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,KAAK;AACP,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAOA,UAAQ;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AACV,aAAOA,UAAQ;AAAA,IACjB;AAAA;AAAA,IAEA,OAAO,UAAoB;AAEzB,aAAOA,UAAQ,OAAO,CAAC,EAAC,eAAc;AAGpC,iBAAS,QAAQ;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,EAAA;AAEJ;ACtCO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGsB;AAGpB,QAAM,CAAC,0BAA0B,IAAIE,MAAAA,SAAS,MAAM,IAAIC,iBAAAA,kBAAkB;AAQ1E,SANAC,cAAAA,sBAAsB,MAAM;AAC1B,UAAM,SAAS,2BAA2B,gBAAA;AAC1C,WAAA,2BAA2B,SAAS,SAAA,GAC7BC,2BAAAA,IAA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5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const style = {
|
|
4
|
+
height: "100vh",
|
|
5
|
+
maxHeight: "100dvh",
|
|
6
|
+
overscrollBehavior: "none",
|
|
7
|
+
WebkitFontSmoothing: "antialiased",
|
|
8
|
+
overflow: "auto"
|
|
9
|
+
}, NextStudioLayoutComponent = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { id: "sanity", "data-ui": "NextStudioLayout", style, children }), NextStudioLayout = react.memo(NextStudioLayoutComponent), styles = {
|
|
10
|
+
outer: {
|
|
11
|
+
position: "absolute",
|
|
12
|
+
top: 0,
|
|
13
|
+
right: 0,
|
|
14
|
+
left: 0,
|
|
15
|
+
bottom: 0,
|
|
16
|
+
background: "#fff",
|
|
17
|
+
zIndex: 1
|
|
18
|
+
},
|
|
19
|
+
inner: {
|
|
20
|
+
position: "absolute",
|
|
21
|
+
top: "50%",
|
|
22
|
+
left: "50%",
|
|
23
|
+
transform: "translate(-50%, -50%)",
|
|
24
|
+
textAlign: "center",
|
|
25
|
+
fontFamily: "helvetica, arial, sans-serif"
|
|
16
26
|
}
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
bottom: 0,
|
|
26
|
-
background: "#fff",
|
|
27
|
-
zIndex: 1
|
|
28
|
-
},
|
|
29
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
30
|
-
"div",
|
|
31
|
-
{
|
|
32
|
-
style: {
|
|
33
|
-
position: "absolute",
|
|
34
|
-
top: "50%",
|
|
35
|
-
left: "50%",
|
|
36
|
-
transform: "translate(-50%, -50%)",
|
|
37
|
-
textAlign: "center",
|
|
38
|
-
fontFamily: "helvetica, arial, sans-serif"
|
|
39
|
-
},
|
|
40
|
-
children: [
|
|
41
|
-
/* @__PURE__ */ jsxRuntime.jsx("h1", { children: "JavaScript disabled" }),
|
|
42
|
-
/* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
43
|
-
"Please ",
|
|
44
|
-
/* @__PURE__ */ jsxRuntime.jsx("a", { href: "https://www.enable-javascript.com/", children: "enable JavaScript" }),
|
|
45
|
-
" in your browser and reload the page to proceed."
|
|
46
|
-
] })
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
) });
|
|
27
|
+
}, NextStudioNoScript = () => /* @__PURE__ */ jsxRuntime.jsx("noscript", { children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: styles.outer, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: styles.inner, children: [
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { children: "JavaScript disabled" }),
|
|
29
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
30
|
+
"Please ",
|
|
31
|
+
/* @__PURE__ */ jsxRuntime.jsx("a", { href: "https://www.enable-javascript.com/", children: "enable JavaScript" }),
|
|
32
|
+
" in your browser and reload the page to proceed."
|
|
33
|
+
] })
|
|
34
|
+
] }) }) });
|
|
52
35
|
exports.NextStudioLayout = NextStudioLayout;
|
|
53
36
|
exports.NextStudioNoScript = NextStudioNoScript;
|
|
54
37
|
//# sourceMappingURL=NextStudioNoScript.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudioNoScript.cjs","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst
|
|
1
|
+
{"version":3,"file":"NextStudioNoScript.cjs","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst style = {\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n} satisfies React.CSSProperties\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div id=\"sanity\" data-ui=\"NextStudioLayout\" style={style}>\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","const styles: Record<'outer' | 'inner', React.CSSProperties> = {\n outer: {\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n },\n inner: {\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n },\n}\n\n/** @internal */\nexport const NextStudioNoScript = (): React.JSX.Element => (\n <noscript>\n <div style={styles.outer}>\n <div style={styles.inner}>\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":["jsx","memo","jsxs"],"mappings":";;AAOA,MAAM,QAAQ;AAAA,EACZ,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,UAAU;AACZ,GAEM,4BAA4B,CAAC,EAAC,SAAA,MAEhCA,2BAAAA,IAAC,OAAA,EAAI,IAAG,UAAS,WAAQ,oBAAmB,OACzC,SAAA,CACH,GAKS,mBAAmBC,MAAAA,KAAK,yBAAyB,GCxBxD,SAAyD;AAAA,EAC7D,OAAO;AAAA,IACL,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,QAAQ;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACL,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AAAA,IACX,WAAW;AAAA,IACX,YAAY;AAAA,EAAA;AAEhB,GAGa,qBAAqB,MAChCD,2BAAAA,IAAC,YAAA,EACC,UAAAA,2BAAAA,IAAC,OAAA,EAAI,OAAO,OAAO,OACjB,UAAAE,2BAAAA,KAAC,OAAA,EAAI,OAAO,OAAO,OACjB,UAAA;AAAA,EAAAF,2BAAAA,IAAC,QAAG,UAAA,sBAAA,CAAmB;AAAA,kCACtB,KAAA,EAAE,UAAA;AAAA,IAAA;AAAA,IACMA,2BAAAA,IAAC,KAAA,EAAE,MAAK,sCAAqC,UAAA,qBAAiB;AAAA,IAAI;AAAA,EAAA,EAAA,CAE3E;AAAA,EAAA,CACF,GACF,EAAA,CACF;;;"}
|
|
@@ -74,9 +74,7 @@ function VisualEditing(props) {
|
|
|
74
74
|
"Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data"
|
|
75
75
|
), routerRef.current.refresh(), Promise.resolve()), manualFallbackRefresh = () => (console.debug(
|
|
76
76
|
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
77
|
-
), serverActions.revalidateRootLayout()),
|
|
78
|
-
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
79
|
-
), !1), mutationFallbackRefresh = () => (console.debug(
|
|
77
|
+
), serverActions.revalidateRootLayout()), mutationFallbackRefresh = () => (console.debug(
|
|
80
78
|
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
81
79
|
), serverActions.revalidateRootLayout());
|
|
82
80
|
switch (payload.source) {
|
|
@@ -102,5 +100,10 @@ function VisualEditing(props) {
|
|
|
102
100
|
}
|
|
103
101
|
);
|
|
104
102
|
}
|
|
103
|
+
function mutationFastRefresh() {
|
|
104
|
+
return console.debug(
|
|
105
|
+
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
106
|
+
), !1;
|
|
107
|
+
}
|
|
105
108
|
exports.default = VisualEditing;
|
|
106
109
|
//# sourceMappingURL=VisualEditing.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualEditing.cjs","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 {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\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: ${update.type}`)\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(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\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 // eslint-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 // eslint-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 const mutationFastRefresh = (): false => {\n // eslint-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 const mutationFallbackRefresh = () => {\n // eslint-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"],"names":["useRouter","useRef","useState","useEffect","useMemo","us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AA,MAAA;AAAA,IACF,CACD;AAAA,EAAA,GAEF,CAAC,UAAU,UAAU,UAAU,cAAc,aAAa,CAAC;AAE9D,QAAM,gBAAgBI,MAAA;AAAA,IACpB,CAAC,YAA4B;AACvB,UAAA,QAAgB,QAAA,QAAQ,OAAO;AAE7B,YAAA,oBAAoB,OAExB,QAAQ;AAAA,QACN;AAAA,MAAA,GAEF,UAAU,QAAQ,WACX,QAAQ,QAAQ,IAEnB,wBAAwB,OAE5B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAAC,cAAA,qBAAA,IAEH,sBAAsB,OAE1B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAA,KAEH,0BAA0B,OAE9B,QAAQ;AAAA,QACN;AAAA,SAEKA,cAAqB,qBAAA;AAG9B,cAAQ,QAAQ,QAAQ;AAAA,QACtB,KAAK;AACH,iBAAO,QAAQ,qBAAqB,kBAAkB,IAAI,sBAAsB;AAAA,QAClF,KAAK;AACH,iBAAO,QAAQ,qBAAqB,oBAAoB,IAAI,wBAAwB;AAAA,QACtF;AACE,gBAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ;AAAA,MAAA;AAAA,IAEhE;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAGE,SAAAC,2BAAA;AAAA,IAACC,QAAA;AAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAM;AAAA,MACN,SAAS;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;;"}
|
|
1
|
+
{"version":3,"file":"VisualEditing.cjs","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 {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\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: ${update.type}`)\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(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\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 // eslint-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 // eslint-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 // eslint-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 // eslint-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"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","jsx","VisualEditingComponent"],"mappings":";;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AAClB,WAAO;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAEnE,SAAI,Y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AQ;AAAA,QACN;AAAA,MAAA,GAEKA,cAAAA,qBAAA;AAGT,cAAQ,QAAQ,QAAA;AAAA,QACd,KAAK;AACH,iBAAO,QAAQ,qBAAqB,kBAAA,IAAsB,sBAAA;AAAA,QAC5D,KAAK;AACH,iBAAO,QAAQ,qBAAqB,oBAAA,IAAwB,wBAAA;AAAA,QAC9D;AACE,gBAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ;AAAA,MAAA;AAAA,IAEhE;AAAA,IACA,CAAC,OAAO;AAAA,EAAA;AAGV,SACEC,2BAAAA;AAAAA,IAACC,QAAAA;AAAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAM;AAAA,MACN,SAAS;AAAA,MACT;AAAA,IAAA;AAAA,EAAA;AAGN;AAEA,SAAS,sBAA6B;AAEpC,SAAA,QAAQ;AAAA,IACN;AAAA,EAAA,GAEK;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudio.js","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): React.JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAGO,SAAS,6BAAsC;AACpD,QAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"NextStudio.js","sources":["../../src/studio/client-component/createHashHistoryForStudio.ts","../../src/studio/client-component/registry.tsx","../../src/studio/client-component/useIsMounted.ts","../../src/studio/client-component/NextStudio.tsx"],"sourcesContent":["import {createHashHistory, type History, type Listener} from 'history'\n\n/** @internal */\nexport function createHashHistoryForStudio(): History {\n const history = createHashHistory()\n return {\n get action() {\n return history.action\n },\n get location() {\n return history.location\n },\n get createHref() {\n return history.createHref\n },\n get push() {\n return history.push\n },\n get replace() {\n return history.replace\n },\n get go() {\n return history.go\n },\n get back() {\n return history.back\n },\n get forward() {\n return history.forward\n },\n get block() {\n return history.block\n },\n // Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)\n listen(listener: Listener) {\n // return history.listen(({ action, location }) => {\n return history.listen(({location}) => {\n // console.debug('history.listen', action, location)\n // @ts-expect-error -- working around a bug? in studio\n listener(location)\n })\n },\n }\n}\n","// https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components\nimport {useServerInsertedHTML} from 'next/navigation.js'\nimport {useState} from 'react'\nimport {ServerStyleSheet, StyleSheetManager} from 'styled-components'\n\nexport function StyledComponentsRegistry({\n children,\n isMounted,\n}: {\n children: React.ReactNode\n isMounted: boolean\n}): React.JSX.Element {\n // Only create stylesheet once with lazy initial state\n // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state\n const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet())\n\n useServerInsertedHTML(() => {\n const styles = styledComponentsStyleSheet.getStyleElement()\n styledComponentsStyleSheet.instance.clearTag()\n return <>{styles}</>\n })\n\n if (isMounted) return <>{children}</>\n\n return (\n <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>{children}</StyleSheetManager>\n )\n}\n","import {useSyncExternalStore} from 'react'\n\n/** @internal */\nexport function useIsMounted(): boolean {\n return useSyncExternalStore(\n emptySubscribe,\n () => true,\n () => false,\n )\n}\n// eslint-disable-next-line no-empty-function\nconst emptySubscribe = () => () => {}\n","import {useMemo} from 'react'\nimport {Studio, type StudioProps} from 'sanity'\n\nimport {NextStudioLayout} from '../NextStudioLayout'\nimport {NextStudioNoScript} from '../NextStudioNoScript'\nimport {createHashHistoryForStudio} from './createHashHistoryForStudio'\nimport {StyledComponentsRegistry} from './registry'\nimport {useIsMounted} from './useIsMounted'\n\n/** @public */\nexport interface NextStudioProps extends StudioProps {\n children?: React.ReactNode\n /**\n * Render the <noscript> tag\n * @defaultValue true\n * @alpha\n */\n unstable__noScript?: boolean\n /**\n * The 'hash' option is new feature that is not yet stable for production, but is available for testing and its API won't change in a breaking way.\n * If 'hash' doesn't work for you, or if you want to use a memory based history, you can use the `unstable_history` prop instead.\n * @alpha\n * @defaultValue 'browser'\n */\n history?: 'browser' | 'hash'\n}\n/**\n * Override how the Studio renders by passing children.\n * This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:\n * ```\n * import {StudioProvider, StudioLayout} from 'sanity'\n * import {NextStudio} from 'next-sanity/studio'\n * <NextStudio config={config}>\n * <StudioProvider config={config}>\n * <CustomComponentThatUsesContextFromStudioProvider />\n * <StudioLayout />\n * </StudioProvider>\n * </NextStudio>\n * ```\n * @public\n */\nexport default function NextStudioComponent({\n children,\n config,\n unstable__noScript = true,\n scheme,\n history,\n ...props\n}: NextStudioProps): React.JSX.Element {\n const isMounted = useIsMounted()\n const unstableHistory = useMemo<typeof props.unstable_history>(() => {\n if (props.unstable_history && history) {\n throw new Error('Cannot use both `unstable_history` and `history` props at the same time')\n }\n\n if (isMounted && history === 'hash') {\n return createHashHistoryForStudio()\n }\n return props.unstable_history\n }, [history, isMounted, props.unstable_history])\n\n return (\n <>\n {unstable__noScript && <NextStudioNoScript />}\n <StyledComponentsRegistry isMounted={isMounted}>\n <NextStudioLayout>\n {history === 'hash' && !isMounted\n ? null\n : children || (\n <Studio\n config={config}\n scheme={scheme}\n unstable_globalStyles\n {...props}\n unstable_history={unstableHistory}\n />\n )}\n </NextStudioLayout>\n </StyledComponentsRegistry>\n </>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAGO,SAAS,6BAAsC;AACpD,QAAM,UAAU,kBAAA;AAChB,SAAO;AAAA,IACL,IAAI,SAAS;AACX,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,WAAW;AACb,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,aAAa;AACf,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,KAAK;AACP,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,OAAO;AACT,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,IAAI,UAAU;AACZ,aAAO,QAAQ;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YACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,uBAAqB;AAAA,QACpB,GAAG;AAAA,QACJ,kBAAkB;AAAA,MAAA;AAAA,IAAA,GAG5B,EAAA,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -1,54 +1,37 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { memo } from "react";
|
|
3
|
-
const
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const style = {
|
|
4
|
+
height: "100vh",
|
|
5
|
+
maxHeight: "100dvh",
|
|
6
|
+
overscrollBehavior: "none",
|
|
7
|
+
WebkitFontSmoothing: "antialiased",
|
|
8
|
+
overflow: "auto"
|
|
9
|
+
}, NextStudioLayoutComponent = ({ children }) => /* @__PURE__ */ jsx("div", { id: "sanity", "data-ui": "NextStudioLayout", style, children }), NextStudioLayout = memo(NextStudioLayoutComponent), styles = {
|
|
10
|
+
outer: {
|
|
11
|
+
position: "absolute",
|
|
12
|
+
top: 0,
|
|
13
|
+
right: 0,
|
|
14
|
+
left: 0,
|
|
15
|
+
bottom: 0,
|
|
16
|
+
background: "#fff",
|
|
17
|
+
zIndex: 1
|
|
18
|
+
},
|
|
19
|
+
inner: {
|
|
20
|
+
position: "absolute",
|
|
21
|
+
top: "50%",
|
|
22
|
+
left: "50%",
|
|
23
|
+
transform: "translate(-50%, -50%)",
|
|
24
|
+
textAlign: "center",
|
|
25
|
+
fontFamily: "helvetica, arial, sans-serif"
|
|
16
26
|
}
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
bottom: 0,
|
|
26
|
-
background: "#fff",
|
|
27
|
-
zIndex: 1
|
|
28
|
-
},
|
|
29
|
-
children: /* @__PURE__ */ jsxs(
|
|
30
|
-
"div",
|
|
31
|
-
{
|
|
32
|
-
style: {
|
|
33
|
-
position: "absolute",
|
|
34
|
-
top: "50%",
|
|
35
|
-
left: "50%",
|
|
36
|
-
transform: "translate(-50%, -50%)",
|
|
37
|
-
textAlign: "center",
|
|
38
|
-
fontFamily: "helvetica, arial, sans-serif"
|
|
39
|
-
},
|
|
40
|
-
children: [
|
|
41
|
-
/* @__PURE__ */ jsx("h1", { children: "JavaScript disabled" }),
|
|
42
|
-
/* @__PURE__ */ jsxs("p", { children: [
|
|
43
|
-
"Please ",
|
|
44
|
-
/* @__PURE__ */ jsx("a", { href: "https://www.enable-javascript.com/", children: "enable JavaScript" }),
|
|
45
|
-
" in your browser and reload the page to proceed."
|
|
46
|
-
] })
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
) });
|
|
27
|
+
}, NextStudioNoScript = () => /* @__PURE__ */ jsx("noscript", { children: /* @__PURE__ */ jsx("div", { style: styles.outer, children: /* @__PURE__ */ jsxs("div", { style: styles.inner, children: [
|
|
28
|
+
/* @__PURE__ */ jsx("h1", { children: "JavaScript disabled" }),
|
|
29
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
30
|
+
"Please ",
|
|
31
|
+
/* @__PURE__ */ jsx("a", { href: "https://www.enable-javascript.com/", children: "enable JavaScript" }),
|
|
32
|
+
" in your browser and reload the page to proceed."
|
|
33
|
+
] })
|
|
34
|
+
] }) }) });
|
|
52
35
|
export {
|
|
53
36
|
NextStudioLayout,
|
|
54
37
|
NextStudioNoScript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextStudioNoScript.js","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst
|
|
1
|
+
{"version":3,"file":"NextStudioNoScript.js","sources":["../../src/studio/NextStudioLayout.tsx","../../src/studio/NextStudioNoScript.tsx"],"sourcesContent":["import {memo} from 'react'\n\n/** @public */\nexport interface NextStudioLayoutProps {\n children: React.ReactNode\n}\n\nconst style = {\n height: '100vh',\n maxHeight: '100dvh',\n overscrollBehavior: 'none',\n WebkitFontSmoothing: 'antialiased',\n overflow: 'auto',\n} satisfies React.CSSProperties\n\nconst NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {\n return (\n <div id=\"sanity\" data-ui=\"NextStudioLayout\" style={style}>\n {children}\n </div>\n )\n}\n\n/** @public */\nexport const NextStudioLayout = memo(NextStudioLayoutComponent)\n","const styles: Record<'outer' | 'inner', React.CSSProperties> = {\n outer: {\n position: 'absolute',\n top: 0,\n right: 0,\n left: 0,\n bottom: 0,\n background: '#fff',\n zIndex: 1,\n },\n inner: {\n position: 'absolute',\n top: '50%',\n left: '50%',\n transform: 'translate(-50%, -50%)',\n textAlign: 'center',\n fontFamily: 'helvetica, arial, sans-serif',\n },\n}\n\n/** @internal */\nexport const NextStudioNoScript = (): React.JSX.Element => (\n <noscript>\n <div style={styles.outer}>\n <div style={styles.inner}>\n <h1>JavaScript disabled</h1>\n <p>\n Please <a href=\"https://www.enable-javascript.com/\">enable JavaScript</a> in your browser\n and reload the page to proceed.\n </p>\n </div>\n </div>\n </noscript>\n)\n"],"names":[],"mappings":";;AAOA,MAAM,QAAQ;AAAA,EACZ,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,UAAU;AACZ,GAEM,4BAA4B,CAAC,EAAC,SAAA,MAEhC,oBAAC,OAAA,EAAI,IAAG,UAAS,WAAQ,oBAAmB,OACzC,SAAA,CACH,GAKS,mBAAmB,KAAK,yBAAyB,GCxBxD,SAAyD;AAAA,EAC7D,OAAO;AAAA,IACL,UAAU;AAAA,IACV,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,QAAQ;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACL,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,WAAW;AAAA,IACX,WAAW;AAAA,IACX,YAAY;AAAA,EAAA;AAEhB,GAGa,qBAAqB,MAChC,oBAAC,YAAA,EACC,UAAA,oBAAC,OAAA,EAAI,OAAO,OAAO,OACjB,UAAA,qBAAC,OAAA,EAAI,OAAO,OAAO,OACjB,UAAA;AAAA,EAAA,oBAAC,QAAG,UAAA,sBAAA,CAAmB;AAAA,uBACtB,KAAA,EAAE,UAAA;AAAA,IAAA;AAAA,IACM,oBAAC,KAAA,EAAE,MAAK,sCAAqC,UAAA,qBAAiB;AAAA,IAAI;AAAA,EAAA,EAAA,CAE3E;AAAA,EAAA,CACF,GACF,EAAA,CACF;"}
|
|
@@ -77,9 +77,7 @@ function VisualEditing(props) {
|
|
|
77
77
|
"Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data"
|
|
78
78
|
), routerRef.current.refresh(), Promise.resolve()), manualFallbackRefresh = () => (console.debug(
|
|
79
79
|
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
80
|
-
), revalidateRootLayout()),
|
|
81
|
-
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
82
|
-
), !1), mutationFallbackRefresh = () => (console.debug(
|
|
80
|
+
), revalidateRootLayout()), mutationFallbackRefresh = () => (console.debug(
|
|
83
81
|
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
84
82
|
), revalidateRootLayout());
|
|
85
83
|
switch (payload.source) {
|
|
@@ -105,6 +103,11 @@ function VisualEditing(props) {
|
|
|
105
103
|
}
|
|
106
104
|
);
|
|
107
105
|
}
|
|
106
|
+
function mutationFastRefresh() {
|
|
107
|
+
return console.debug(
|
|
108
|
+
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
109
|
+
), !1;
|
|
110
|
+
}
|
|
108
111
|
export {
|
|
109
112
|
VisualEditing as default
|
|
110
113
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualEditing.js","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 {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\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: ${update.type}`)\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(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\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 // eslint-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 // eslint-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 const mutationFastRefresh = (): false => {\n // eslint-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 const mutationFallbackRefresh = () => {\n // eslint-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"],"names":["VisualEditingCompon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,QAAM,gBAAgB;AAAA,IACpB,CAAC,YAA4B;AACvB,UAAA,QAAgB,QAAA,QAAQ,OAAO;AAE7B,YAAA,oBAAoB,OAExB,QAAQ;AAAA,QACN;AAAA,MAAA,GAEF,UAAU,QAAQ,WACX,QAAQ,QAAQ,IAEnB,wBAAwB,OAE5B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAA,qBAAA,IAEH,sBAAsB,OAE1B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAA,KAEH,0BAA0B,OAE9B,QAAQ;AAAA,QACN;AAAA,SAEK,qBAAqB;AAG9B,cAAQ,QAAQ,QAAQ;AAAA,QACtB,KAAK;AACH,iBAAO,QAAQ,qBAAqB,kBAAkB,IAAI,sBAAsB;AAAA,QAClF,KAAK;AACH,iBAAO,QAAQ,qBAAqB,oBAAoB,IAAI,wBAAwB;AAAA,QACtF;AACE,gBAAM,IAAI,MAAM,0BAA0B,EAAC,OAAO,SAAQ;AAAA,MAAA;AAAA,IAEhE;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAGE,SAAA;AAAA,IAACA;AAAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAM;AAAA,MACN,SAAS;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"VisualEditing.js","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 {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {revalidateRootLayout} from 'next-sanity/visual-editing/server-actions'\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: ${update.type}`)\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(`${pathname}${searchParams?.size ? `?${searchParams}` : ''}`, basePath),\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 // eslint-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 // eslint-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 // eslint-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 // eslint-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"],"names":["VisualEditingComponent"],"mappings":";;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AAClB,WAAO;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;AAChE;AAQA,SAAS,UAAU,MAIjB;AACA,QAAM,YAAY,KAAK,QAAQ,GAAG,GAC5B,aAAa,KAAK,QAAQ,GAAG,GAC7B,WAAW,aAAa,OAAO,YAAY,KAAK,aAAa;AAEnE,SAAI,YAAY,YAAY,KACnB;AAAA,IACL,UAAU,KAAK,UAAU,GAAG,WAAW,aAAa,SAAS;AAAA,IAC7D,OAAO,WAAW,KAAK,UAAU,YAAY,YAAY,KAAK,YAAY,MAAS,IAAI;AAAA,IACvF,MAAM,YAAY,KAAK,KAAK,MAAM,SAAS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AAQ;AAAA,MAAA;AAAA,IAEhE;AAAA,IACA,CAAC,OAAO;AAAA,EAAA;AAGV,SACE;AAAA,IAACA;AAAAA,IAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAM;AAAA,MACN,SAAS;AAAA,MACT;AAAA,IAAA;AAAA,EAAA;AAGN;AAEA,SAAS,sBAA6B;AAEpC,SAAA,QAAQ;AAAA,IACN;AAAA,EAAA,GAEK;AACT;"}
|
package/dist/draft-mode.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const dev = process.env.NODE_ENV !== 'production'\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":["validatePreviewUrl","draftMode","cookies","perspectiveCookieName","redirect"],"mappings":";;;AAsCO,SAAS,sBAAsB,SAAwD;
|
|
1
|
+
{"version":3,"file":"draft-mode.cjs","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const dev = process.env.NODE_ENV !== 'production'\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":["validatePreviewUrl","draftMode","cookies","perspectiveCookieName","redirect"],"mappings":";;;AAsCO,SAAS,sBAAsB,SAAwD;AAC5F,QAAM,EAAC,WAAU;AACjB,SAAO;AAAA,IACL,KAAK,OAAO,YAAqB;AAI/B,YAAM;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MAAA,IACE,MAAMA,iBAAAA,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAGrD,YAAM,iBAAiB,MAAMC,kBAAA;AAGxB,qBAAe,aAClB,eAAe,OAAA;AAGjB,YAAM,MAAM,QAAQ,IAAI,aAAa,cAI/B,cAAc,MAAMC,QAAAA,QAAA,GACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAMC,UAAAA;AAAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAIIC,WAAAA,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;;"}
|
package/dist/draft-mode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const dev = process.env.NODE_ENV !== 'production'\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":[],"mappings":";;;;AAsCO,SAAS,sBAAsB,SAAwD;
|
|
1
|
+
{"version":3,"file":"draft-mode.js","sources":["../src/draft-mode/define-enable-draft-mode.ts"],"sourcesContent":["import {validatePreviewUrl} from '@sanity/preview-url-secret'\nimport {perspectiveCookieName} from '@sanity/preview-url-secret/constants'\nimport {cookies, draftMode} from 'next/headers'\nimport {redirect} from 'next/navigation'\n\nimport type {SanityClient} from '../client'\n\n/**\n * @public\n */\nexport interface DefineEnableDraftModeOptions {\n client: SanityClient\n}\n\n/**\n * @public\n */\nexport interface EnableDraftMode {\n GET: (request: Request) => Promise<Response>\n}\n\n/**\n * Sets up an API route for enabling draft mode, can be paired with the `previewUrl.previewMode.enable` in `sanity/presentation`.\n * Can also be used with `sanity-plugin-iframe-pane`.\n * @example\n * ```ts\n * // src/app/api/draft-mode/enable/route.ts\n *\n * import { defineEnableDraftMode } from \"next-sanity/draft-mode\";\n * import { client } from \"@/sanity/lib/client\";\n *\n * export const { GET } = defineEnableDraftMode({\n * client: client.withConfig({ token: process.env.SANITY_API_READ_TOKEN }),\n * });\n * ```\n *\n * @public\n */\nexport function defineEnableDraftMode(options: DefineEnableDraftModeOptions): EnableDraftMode {\n const {client} = options\n return {\n GET: async (request: Request) => {\n // eslint-disable-next-line no-warning-comments\n // @TODO check if already in draft mode at a much earlier stage, and skip validation\n\n const {\n isValid,\n redirectTo = '/',\n studioPreviewPerspective,\n } = await validatePreviewUrl(client, request.url)\n if (!isValid) {\n return new Response('Invalid secret', {status: 401})\n }\n\n const draftModeStore = await draftMode()\n\n // Let's enable draft mode if it's not already enabled\n if (!draftModeStore.isEnabled) {\n draftModeStore.enable()\n }\n\n const dev = process.env.NODE_ENV !== 'production'\n\n // Override cookie header for draft mode for usage in live-preview\n // https://github.com/vercel/next.js/issues/49927\n const cookieStore = await cookies()\n const cookie = cookieStore.get('__prerender_bypass')!\n cookieStore.set({\n name: '__prerender_bypass',\n value: cookie?.value,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n\n if (studioPreviewPerspective) {\n cookieStore.set({\n name: perspectiveCookieName,\n value: studioPreviewPerspective,\n httpOnly: true,\n path: '/',\n secure: !dev,\n sameSite: dev ? 'lax' : 'none',\n })\n }\n\n // the `redirect` function throws, and eventually returns a Promise<Response>. TSC doesn't \"see\" that so we have to tell it\n return redirect(redirectTo) as Promise<Response>\n },\n }\n}\n"],"names":[],"mappings":";;;;AAsCO,SAAS,sBAAsB,SAAwD;AAC5F,QAAM,EAAC,WAAU;AACjB,SAAO;AAAA,IACL,KAAK,OAAO,YAAqB;AAI/B,YAAM;AAAA,QACJ;AAAA,QACA,aAAa;AAAA,QACb;AAAA,MAAA,IACE,MAAM,mBAAmB,QAAQ,QAAQ,GAAG;AAChD,UAAI,CAAC;AACH,eAAO,IAAI,SAAS,kBAAkB,EAAC,QAAQ,KAAI;AAGrD,YAAM,iBAAiB,MAAM,UAAA;AAGxB,qBAAe,aAClB,eAAe,OAAA;AAGjB,YAAM,MAAM,QAAQ,IAAI,aAAa,cAI/B,cAAc,MAAM,QAAA,GACpB,SAAS,YAAY,IAAI,oBAAoB;AACnD,aAAA,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO,QAAQ;AAAA,QACf,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAEG,4BACF,YAAY,IAAI;AAAA,QACd,MAAM;AAAA,QACN,OAAO;AAAA,QACP,UAAU;AAAA,QACV,MAAM;AAAA,QACN,QAAQ,CAAC;AAAA,QACT,UAAU,MAAM,QAAQ;AAAA,MAAA,CACzB,GAII,SAAS,UAAU;AAAA,IAC5B;AAAA,EAAA;AAEJ;"}
|
package/dist/image.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.cjs","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n if (!url.searchParams.has('fit')) {\n url.searchParams.set('fit', url.searchParams.has('h') ? 'min' : 'max')\n }\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): React.JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["jsx","NextImage"],"mappings":";;;;;;;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;
|
|
1
|
+
{"version":3,"file":"image.cjs","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n if (!url.searchParams.has('fit')) {\n url.searchParams.set('fit', url.searchParams.has('h') ? 'min' : 'max')\n }\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): React.JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":["jsx","NextImage"],"mappings":";;;;;;;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AACrD,QAAM,MAAM,IAAI,IAAI,GAAG;AAKvB,MAJA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GAChC,IAAI,aAAa,IAAI,KAAK,KAC7B,IAAI,aAAa,IAAI,OAAO,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ,KAAK,GAEnE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AAC7D,QAAI,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAA,CAAU;AAAA,EAC3F;AACA,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAA,CAAU,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,SAAA,CAAU,GAEvC,IAAI;AACb;ACAO,SAAS,MAAM,OAAsC;AAC1D,QAAM,EAAC,QAAQ,KAAK,GAAG,SAAQ;AAC/B,MAAI;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,EAEjD,SAAS,KAAK;AACZ,UAAM,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EACH;AACA,SAAOA,+BAACC,mBAAAA,WAAW,GAAG,MAAM,KAAK,OAAO,SAAA,GAAY,QAAQ,aAAa;AAC3E;;;"}
|
package/dist/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image.js","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n if (!url.searchParams.has('fit')) {\n url.searchParams.set('fit', url.searchParams.has('h') ? 'min' : 'max')\n }\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): React.JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;
|
|
1
|
+
{"version":3,"file":"image.js","sources":["../src/image/imageLoader.ts","../src/image/Image.tsx"],"sourcesContent":["import type {ImageLoader} from 'next/image'\n\n/**\n * @alpha\n */\nexport const imageLoader = (({src, width, quality}) => {\n const url = new URL(src)\n url.searchParams.set('auto', 'format')\n if (!url.searchParams.has('fit')) {\n url.searchParams.set('fit', url.searchParams.has('h') ? 'min' : 'max')\n }\n if (url.searchParams.has('h') && url.searchParams.has('w')) {\n const originalHeight = parseInt(url.searchParams.get('h')!, 10)\n const originalWidth = parseInt(url.searchParams.get('w')!, 10)\n url.searchParams.set('h', Math.round((originalHeight / originalWidth) * width).toString())\n }\n url.searchParams.set('w', width.toString())\n if (quality) {\n url.searchParams.set('q', quality.toString())\n }\n return url.href\n}) satisfies ImageLoader\n","import NextImage, {type ImageProps as NextImageProps} from 'next/image'\n\nimport {imageLoader} from './imageLoader'\n\n/**\n * @alpha\n */\nexport interface ImageProps extends Omit<NextImageProps, 'loader' | 'src'> {\n /**\n * The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.\n */\n loader?: never\n /**\n * Must be a string that is a valid URL to an image on the Sanity Image CDN.\n */\n src: string\n}\n\n/**\n * @alpha\n */\nexport function Image(props: ImageProps): React.JSX.Element {\n const {loader, src, ...rest} = props\n if (loader) {\n throw new TypeError(\n 'The `loader` prop is not supported on `Image` components. Use `next/image` directly to use a custom loader.',\n )\n }\n let srcUrl: URL\n try {\n srcUrl = new URL(src)\n if (props.height) {\n srcUrl.searchParams.set('h', `${props.height}`)\n }\n if (props.width) {\n srcUrl.searchParams.set('w', `${props.width}`)\n }\n } catch (err) {\n throw new TypeError('The `src` prop must be a valid URL to an image on the Sanity Image CDN.', {\n cause: err,\n })\n }\n return <NextImage {...rest} src={srcUrl.toString()} loader={imageLoader} />\n}\n"],"names":[],"mappings":";;;AAKO,MAAM,cAAe,CAAC,EAAC,KAAK,OAAO,cAAa;AACrD,QAAM,MAAM,IAAI,IAAI,GAAG;AAKvB,MAJA,IAAI,aAAa,IAAI,QAAQ,QAAQ,GAChC,IAAI,aAAa,IAAI,KAAK,KAC7B,IAAI,aAAa,IAAI,OAAO,IAAI,aAAa,IAAI,GAAG,IAAI,QAAQ,KAAK,GAEnE,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,GAAG,GAAG;AAC1D,UAAM,iBAAiB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE,GACxD,gBAAgB,SAAS,IAAI,aAAa,IAAI,GAAG,GAAI,EAAE;AAC7D,QAAI,aAAa,IAAI,KAAK,KAAK,MAAO,iBAAiB,gBAAiB,KAAK,EAAE,SAAA,CAAU;AAAA,EAC3F;AACA,SAAA,IAAI,aAAa,IAAI,KAAK,MAAM,SAAA,CAAU,GACtC,WACF,IAAI,aAAa,IAAI,KAAK,QAAQ,SAAA,CAAU,GAEvC,IAAI;AACb;ACAO,SAAS,MAAM,OAAsC;AAC1D,QAAM,EAAC,QAAQ,KAAK,GAAG,SAAQ;AAC/B,MAAI;AACF,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,MAAI;AACJ,MAAI;AACF,aAAS,IAAI,IAAI,GAAG,GAChB,MAAM,UACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,MAAM,EAAE,GAE5C,MAAM,SACR,OAAO,aAAa,IAAI,KAAK,GAAG,MAAM,KAAK,EAAE;AAAA,EAEjD,SAAS,KAAK;AACZ,UAAM,IAAI,UAAU,2EAA2E;AAAA,MAC7F,OAAO;AAAA,IAAA,CACR;AAAA,EACH;AACA,SAAO,oBAAC,aAAW,GAAG,MAAM,KAAK,OAAO,SAAA,GAAY,QAAQ,aAAa;AAC3E;"}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\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 // eslint-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 // eslint-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"],"names":["jsx","VisualEditingComponent"],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\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 // eslint-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 // eslint-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"],"names":["jsx","VisualEditingComponent"],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;AAC3E,MAAI;AACJ,MAAI,OAAO,MAAM,YAAa;AAC5B,QAAI;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,IAG/D,SAAS,KAAK;AACZ,cAAQ,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEF,MAAI;AACJ,MAAI,OAAO,MAAM,iBAAkB;AACjC,QAAI;AACF,0BAAoB,CAAA,CAAQ,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,IAGzE,SAAS,KAAK;AACZ,cAAQ,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAEF,SACEA,2BAAAA;AAAAA,IAACC,gCAAAA;AAAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.edge-light.js","sources":["../src/index.edge-light.ts"],"sourcesContent":["/**\n * Some of the exports on index.ts causes errors on the edge runtime, so we omit them here.\n */\n\nimport type {VisualEditingProps} from './visual-editing'\n\nexport * from './client'\nexport * from './create-data-attribute'\nexport * from '@portabletext/react'\nexport * from '@sanity/next-loader'\nexport {defineQuery, default as groq} from 'groq'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function VisualEditing(_props: VisualEditingProps): React.ReactNode {\n throw new TypeError('VisualEditing is not supported on the edge runtime')\n}\n"],"names":[],"mappings":";;;;;;AAcO,SAAS,cAAc,QAA6C;
|
|
1
|
+
{"version":3,"file":"index.edge-light.js","sources":["../src/index.edge-light.ts"],"sourcesContent":["/**\n * Some of the exports on index.ts causes errors on the edge runtime, so we omit them here.\n */\n\nimport type {VisualEditingProps} from './visual-editing'\n\nexport * from './client'\nexport * from './create-data-attribute'\nexport * from '@portabletext/react'\nexport * from '@sanity/next-loader'\nexport {defineQuery, default as groq} from 'groq'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function VisualEditing(_props: VisualEditingProps): React.ReactNode {\n throw new TypeError('VisualEditing is not supported on the edge runtime')\n}\n"],"names":[],"mappings":";;;;;;AAcO,SAAS,cAAc,QAA6C;AACzE,QAAM,IAAI,UAAU,oDAAoD;AAC1E;"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\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 // eslint-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 // eslint-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"],"names":[],"mappings":";;;;;;;;AAMO,SAAS,cAAc,OAA+C;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["import type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\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 // eslint-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 // eslint-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"],"names":[],"mappings":";;;;;;;;AAMO,SAAS,cAAc,OAA+C;AAC3E,MAAI;AACJ,MAAI,OAAO,MAAM,YAAa;AAC5B,QAAI;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,IAG/D,SAAS,KAAK;AACZ,cAAQ,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEF,MAAI;AACJ,MAAI,OAAO,MAAM,iBAAkB;AACjC,QAAI;AACF,0BAAoB,CAAA,CAAQ,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,IAGzE,SAAS,KAAK;AACZ,cAAQ,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAEF,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-component.cjs","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;;AAYA,MAAM,4BAA4BA,
|
|
1
|
+
{"version":3,"file":"client-component.cjs","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;;AAYA,MAAM,4BAA4BA,MAAAA,KAAK,MAAM,QAAA,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAO,+BAAc;EAAC;AAE5D,SAAS,8BAA8B,OAAyC;AACrF,SACEC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,2BAAA,EAA2B,GAAG,OAAO,EAAA,CACxC;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-component.js","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,4BAA4B,KAAK,MAAM,OAAO,6BAAc,CAAC;AAE5D,SAAS,8BAA8B,OAAyC;
|
|
1
|
+
{"version":3,"file":"client-component.js","sources":["../../src/studio/client-component/NextStudioLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {NextStudioProps} from './NextStudio'\n\nconst NextStudioClientComponent = lazy(() => import('./NextStudio'))\n\nexport function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <NextStudioClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,4BAA4B,KAAK,MAAM,OAAO,6BAAc,CAAC;AAE5D,SAAS,8BAA8B,OAAyC;AACrF,SACE,oBAAC,YAAS,UAAU,MAClB,8BAAC,2BAAA,EAA2B,GAAG,OAAO,EAAA,CACxC;AAEJ;"}
|
package/dist/studio.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.cjs","sources":["../src/studio/head.tsx","../src/studio/NextStudioWithBridge.tsx"],"sourcesContent":["import type {Metadata, Viewport} from 'next'\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the viewport config directly:\n * export {viewport} from 'next-sanity/studio'\n *\n * // To customize the viewport config, spread it on the export:\n * import {viewport as studioViewport} from 'next-sanity/studio'\n * import type { Viewport } from 'next'\n *\n * export const viewport: Viewport = {\n * ...studioViewport,\n * // Overrides the viewport to resize behavior\n * interactiveWidget: 'resizes-content'\n * })\n * ```\n * @public\n */\nexport const viewport = {\n width: 'device-width' as const,\n initialScale: 1 as const,\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n viewportFit: 'cover',\n} satisfies Viewport\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the metadata directly:\n * export {metadata} from 'next-sanity/studio'\n *\n * // To customize the metadata, spread it on the export:\n * import {metadata as studioMetadata} from 'next-sanity/studio'\n * import type { Metadata } from 'next'\n *\n * export const metadata: Metadata = {\n * ...studioMetadata,\n * // Set another title\n * title: 'My Studio',\n * })\n * ```\n * @public\n */\nexport const metadata = {\n referrer: 'same-origin' as const,\n robots: 'noindex' as const,\n} satisfies Metadata\n","import {NextStudio, type NextStudioProps} from 'next-sanity/studio/client-component'\nimport {preloadModule} from 'react-dom'\n\n/**\n * Loads the bridge script the same way Sanity Studio does:\n * https://github.com/sanity-io/sanity/blob/bd5b1acb5015baaddd8d96c2abd1eaf579b3c904/packages/sanity/src/_internal/cli/server/renderDocument.tsx#L124-L139\n */\n\nconst bridgeScript = 'https://core.sanity-cdn.com/bridge.js'\n\nexport function NextStudioWithBridge(props: NextStudioProps): React.JSX.Element {\n preloadModule(bridgeScript, {as: 'script'})\n\n return (\n <>\n <script src={bridgeScript} async type=\"module\" data-sanity-core />\n <NextStudio {...props} />\n </>\n )\n}\n"],"names":["preloadModule","jsxs","Fragment","jsx","NextStudio"],"mappings":";;;AAoBO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,cAAc;AAAA;AAAA,EAEd,aAAa;AACf,GAoBa,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,QAAQ;AACV,GCxCM,eAAe;AAEd,SAAS,qBAAqB,OAA2C;AAC9E,SAAAA,
|
|
1
|
+
{"version":3,"file":"studio.cjs","sources":["../src/studio/head.tsx","../src/studio/NextStudioWithBridge.tsx"],"sourcesContent":["import type {Metadata, Viewport} from 'next'\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the viewport config directly:\n * export {viewport} from 'next-sanity/studio'\n *\n * // To customize the viewport config, spread it on the export:\n * import {viewport as studioViewport} from 'next-sanity/studio'\n * import type { Viewport } from 'next'\n *\n * export const viewport: Viewport = {\n * ...studioViewport,\n * // Overrides the viewport to resize behavior\n * interactiveWidget: 'resizes-content'\n * })\n * ```\n * @public\n */\nexport const viewport = {\n width: 'device-width' as const,\n initialScale: 1 as const,\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n viewportFit: 'cover',\n} satisfies Viewport\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the metadata directly:\n * export {metadata} from 'next-sanity/studio'\n *\n * // To customize the metadata, spread it on the export:\n * import {metadata as studioMetadata} from 'next-sanity/studio'\n * import type { Metadata } from 'next'\n *\n * export const metadata: Metadata = {\n * ...studioMetadata,\n * // Set another title\n * title: 'My Studio',\n * })\n * ```\n * @public\n */\nexport const metadata = {\n referrer: 'same-origin' as const,\n robots: 'noindex' as const,\n} satisfies Metadata\n","import {NextStudio, type NextStudioProps} from 'next-sanity/studio/client-component'\nimport {preloadModule} from 'react-dom'\n\n/**\n * Loads the bridge script the same way Sanity Studio does:\n * https://github.com/sanity-io/sanity/blob/bd5b1acb5015baaddd8d96c2abd1eaf579b3c904/packages/sanity/src/_internal/cli/server/renderDocument.tsx#L124-L139\n */\n\nconst bridgeScript = 'https://core.sanity-cdn.com/bridge.js'\n\nexport function NextStudioWithBridge(props: NextStudioProps): React.JSX.Element {\n preloadModule(bridgeScript, {as: 'script'})\n\n return (\n <>\n <script src={bridgeScript} async type=\"module\" data-sanity-core />\n <NextStudio {...props} />\n </>\n )\n}\n"],"names":["preloadModule","jsxs","Fragment","jsx","NextStudio"],"mappings":";;;AAoBO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,cAAc;AAAA;AAAA,EAEd,aAAa;AACf,GAoBa,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,QAAQ;AACV,GCxCM,eAAe;AAEd,SAAS,qBAAqB,OAA2C;AAC9E,SAAAA,SAAAA,cAAc,cAAc,EAAC,IAAI,SAAA,CAAS,GAGxCC,2BAAAA,KAAAC,qBAAA,EACE,UAAA;AAAA,IAAAC,2BAAAA,IAAC,UAAA,EAAO,KAAK,cAAc,OAAK,IAAC,MAAK,UAAS,oBAAgB,GAAA,CAAC;AAAA,IAChEA,+BAACC,gBAAAA,YAAA,EAAY,GAAG,MAAA,CAAO;AAAA,EAAA,GACzB;AAEJ;;;;;;"}
|
package/dist/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.js","sources":["../src/studio/head.tsx","../src/studio/NextStudioWithBridge.tsx"],"sourcesContent":["import type {Metadata, Viewport} from 'next'\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the viewport config directly:\n * export {viewport} from 'next-sanity/studio'\n *\n * // To customize the viewport config, spread it on the export:\n * import {viewport as studioViewport} from 'next-sanity/studio'\n * import type { Viewport } from 'next'\n *\n * export const viewport: Viewport = {\n * ...studioViewport,\n * // Overrides the viewport to resize behavior\n * interactiveWidget: 'resizes-content'\n * })\n * ```\n * @public\n */\nexport const viewport = {\n width: 'device-width' as const,\n initialScale: 1 as const,\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n viewportFit: 'cover',\n} satisfies Viewport\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the metadata directly:\n * export {metadata} from 'next-sanity/studio'\n *\n * // To customize the metadata, spread it on the export:\n * import {metadata as studioMetadata} from 'next-sanity/studio'\n * import type { Metadata } from 'next'\n *\n * export const metadata: Metadata = {\n * ...studioMetadata,\n * // Set another title\n * title: 'My Studio',\n * })\n * ```\n * @public\n */\nexport const metadata = {\n referrer: 'same-origin' as const,\n robots: 'noindex' as const,\n} satisfies Metadata\n","import {NextStudio, type NextStudioProps} from 'next-sanity/studio/client-component'\nimport {preloadModule} from 'react-dom'\n\n/**\n * Loads the bridge script the same way Sanity Studio does:\n * https://github.com/sanity-io/sanity/blob/bd5b1acb5015baaddd8d96c2abd1eaf579b3c904/packages/sanity/src/_internal/cli/server/renderDocument.tsx#L124-L139\n */\n\nconst bridgeScript = 'https://core.sanity-cdn.com/bridge.js'\n\nexport function NextStudioWithBridge(props: NextStudioProps): React.JSX.Element {\n preloadModule(bridgeScript, {as: 'script'})\n\n return (\n <>\n <script src={bridgeScript} async type=\"module\" data-sanity-core />\n <NextStudio {...props} />\n </>\n )\n}\n"],"names":[],"mappings":";;;;AAoBO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,cAAc;AAAA;AAAA,EAEd,aAAa;AACf,GAoBa,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,QAAQ;AACV,GCxCM,eAAe;AAEd,SAAS,qBAAqB,OAA2C;AAC9E,SAAA,cAAc,cAAc,EAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"studio.js","sources":["../src/studio/head.tsx","../src/studio/NextStudioWithBridge.tsx"],"sourcesContent":["import type {Metadata, Viewport} from 'next'\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the viewport config directly:\n * export {viewport} from 'next-sanity/studio'\n *\n * // To customize the viewport config, spread it on the export:\n * import {viewport as studioViewport} from 'next-sanity/studio'\n * import type { Viewport } from 'next'\n *\n * export const viewport: Viewport = {\n * ...studioViewport,\n * // Overrides the viewport to resize behavior\n * interactiveWidget: 'resizes-content'\n * })\n * ```\n * @public\n */\nexport const viewport = {\n width: 'device-width' as const,\n initialScale: 1 as const,\n // Studio implements display cutouts CSS (The iPhone Notch ™ ) and needs `viewport-fit=covered` for it to work correctly\n viewportFit: 'cover',\n} satisfies Viewport\n\n/**\n * In router segments (`/app/studio/[[...index]]/page.tsx`):\n * ```tsx\n * // If you don't want to change any defaults you can just re-export the metadata directly:\n * export {metadata} from 'next-sanity/studio'\n *\n * // To customize the metadata, spread it on the export:\n * import {metadata as studioMetadata} from 'next-sanity/studio'\n * import type { Metadata } from 'next'\n *\n * export const metadata: Metadata = {\n * ...studioMetadata,\n * // Set another title\n * title: 'My Studio',\n * })\n * ```\n * @public\n */\nexport const metadata = {\n referrer: 'same-origin' as const,\n robots: 'noindex' as const,\n} satisfies Metadata\n","import {NextStudio, type NextStudioProps} from 'next-sanity/studio/client-component'\nimport {preloadModule} from 'react-dom'\n\n/**\n * Loads the bridge script the same way Sanity Studio does:\n * https://github.com/sanity-io/sanity/blob/bd5b1acb5015baaddd8d96c2abd1eaf579b3c904/packages/sanity/src/_internal/cli/server/renderDocument.tsx#L124-L139\n */\n\nconst bridgeScript = 'https://core.sanity-cdn.com/bridge.js'\n\nexport function NextStudioWithBridge(props: NextStudioProps): React.JSX.Element {\n preloadModule(bridgeScript, {as: 'script'})\n\n return (\n <>\n <script src={bridgeScript} async type=\"module\" data-sanity-core />\n <NextStudio {...props} />\n </>\n )\n}\n"],"names":[],"mappings":";;;;AAoBO,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,cAAc;AAAA;AAAA,EAEd,aAAa;AACf,GAoBa,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,QAAQ;AACV,GCxCM,eAAe;AAEd,SAAS,qBAAqB,OAA2C;AAC9E,SAAA,cAAc,cAAc,EAAC,IAAI,SAAA,CAAS,GAGxC,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA,oBAAC,UAAA,EAAO,KAAK,cAAc,OAAK,IAAC,MAAK,UAAS,oBAAgB,GAAA,CAAC;AAAA,IAChE,oBAAC,YAAA,EAAY,GAAG,MAAA,CAAO;AAAA,EAAA,GACzB;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-component.cjs","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;AAYA,MAAM,+BAA+BA,
|
|
1
|
+
{"version":3,"file":"client-component.cjs","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["lazy","jsx","Suspense"],"mappings":";;;AAYA,MAAM,+BAA+BA,MAAAA,KAAK,MAAM,QAAA,QAAA,EAAA,KAAA,WAAA;AAAA,SAAA,QAAO,kCAAiB;EAAC;AAElE,SAAS,iCAAiC,OAA4C;AAC3F,SACEC,+BAACC,MAAAA,YAAS,UAAU,MAClB,yCAAC,8BAAA,EAA8B,GAAG,OAAO,EAAA,CAC3C;AAEJ;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-component.js","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,+BAA+B,KAAK,MAAM,OAAO,gCAAiB,CAAC;AAElE,SAAS,iCAAiC,OAA4C;
|
|
1
|
+
{"version":3,"file":"client-component.js","sources":["../../src/visual-editing/client-component/VisualEditingLazy.tsx"],"sourcesContent":["/**\n *\n * If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`),\n * or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet)\n * we could use `dynamic(() => import('...), {ssr: false})` here.\n * Since we can't, we need to use a lazy import and Suspense ourself.\n */\n\nimport {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingClientComponent = lazy(() => import('./VisualEditing'))\n\nexport function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode {\n return (\n <Suspense fallback={null}>\n <VisualEditingClientComponent {...props} />\n </Suspense>\n )\n}\n"],"names":[],"mappings":";;;AAYA,MAAM,+BAA+B,KAAK,MAAM,OAAO,gCAAiB,CAAC;AAElE,SAAS,iCAAiC,OAA4C;AAC3F,SACE,oBAAC,YAAS,UAAU,MAClB,8BAAC,8BAAA,EAA8B,GAAG,OAAO,EAAA,CAC3C;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-actions.cjs","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":["draftMode","revalidatePath"],"mappings":";;;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAMA,
|
|
1
|
+
{"version":3,"file":"server-actions.cjs","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":["draftMode","revalidatePath"],"mappings":";;;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAMA,qBAAA,GAAa,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EACF;AACA,QAAMC,SAAAA,eAAe,KAAK,QAAQ;AACpC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-actions.js","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"server-actions.js","sources":["../../src/visual-editing/server-actions/index.ts"],"sourcesContent":["'use server'\nimport {revalidatePath} from 'next/cache.js'\nimport {draftMode} from 'next/headers.js'\n\nexport async function revalidateRootLayout(): Promise<void> {\n if (!(await draftMode()).isEnabled) {\n // eslint-disable-next-line no-console\n console.warn('Skipped revalidatePath request because draft mode is not enabled')\n return\n }\n await revalidatePath('/', 'layout')\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,uBAAsC;AAC1D,MAAI,EAAE,MAAM,UAAA,GAAa,WAAW;AAElC,YAAQ,KAAK,kEAAkE;AAC/E;AAAA,EACF;AACA,QAAM,eAAe,KAAK,QAAQ;AACpC;"}
|
package/dist/webhook.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.cjs","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,
|
|
1
|
+
{"version":3,"file":"webhook.cjs","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACV;AACA;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,QAAM,EAAE,UAAS,IAAK,sBAAsB,SAAS,GAAG,UAAU,MAAM,sBAAsB,oBAAoB,WAAW,MAAM;AACnI,MAAI,cAAc;AAChB,UAAM,IAAI,2BAA2B,sBAAsB;AAC/D;AACA,eAAe,iBAAiB,oBAAoB,WAAW,QAAQ;AACrE,MAAI;AACF,WAAO,MAAM,qBAAqB,oBAAoB,WAAW,MAAM,GAAG;AAAA,EAC5E,SAAS,KAAK;AACZ,QAAI,iBAAiB,GAAG;AACtB,aAAO;AACT,UAAM;AAAA,EACR;AACF;AAyBA,eAAe,sBAAsB,oBAAoB,WAAW,QAAQ;AAC1E,QAAM,YAAY,MAAM,qBAAqB,oBAAoB,WAAW,MAAM;AAClF,SAAO,KAAK,SAAS,OAAO,SAAS;AACvC;AACA,SAAS,sBAAsB,kBAAkB;AAC/C,MAAI,CAAC;AACH,UAAM,IAAI,4BAA4B,mCAAmC;AAC3E,QA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A0B,GACjC,EAAC,MAAM,MAAM,kBAAkB,KAAA;AAGxC,QAAM,OAAO,MAAM,IAAI,KAAA,GACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAA,CAAM,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,KAAA,IAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EAAA;AAEtB;;","x_google_ignoreList":[0]}
|
package/dist/webhook.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {NextRequest} from 'next/server'
|
|
2
|
-
import type {SanityDocument} from '@sanity/types'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
@@ -21,4 +20,14 @@ export declare type ParsedBody<T> = {
|
|
|
21
20
|
body: T | null
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
/** @public */
|
|
24
|
+
declare interface SanityDocument {
|
|
25
|
+
_id: string
|
|
26
|
+
_type: string
|
|
27
|
+
_createdAt: string
|
|
28
|
+
_updatedAt: string
|
|
29
|
+
_rev: string
|
|
30
|
+
[key: string]: unknown
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export {}
|
package/dist/webhook.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {NextRequest} from 'next/server'
|
|
2
|
-
import type {SanityDocument} from '@sanity/types'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries
|
|
@@ -21,4 +20,14 @@ export declare type ParsedBody<T> = {
|
|
|
21
20
|
body: T | null
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
/** @public */
|
|
24
|
+
declare interface SanityDocument {
|
|
25
|
+
_id: string
|
|
26
|
+
_type: string
|
|
27
|
+
_createdAt: string
|
|
28
|
+
_updatedAt: string
|
|
29
|
+
_rev: string
|
|
30
|
+
[key: string]: unknown
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
export {}
|
package/dist/webhook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.js","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":"AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,
|
|
1
|
+
{"version":3,"file":"webhook.js","sources":["../../../node_modules/.pnpm/@sanity+webhook@4.0.4/node_modules/@sanity/webhook/dist/index.mjs","../src/webhook/index.ts"],"sourcesContent":["class WebhookSignatureValueError extends Error {\n type = \"WebhookSignatureValueError\";\n statusCode = 401;\n}\nclass WebhookSignatureFormatError extends Error {\n type = \"WebhookSignatureFormatError\";\n statusCode = 400;\n}\nfunction isSignatureError(error) {\n return typeof error == \"object\" && error !== null && \"type\" in error && [\"WebhookSignatureValueError\", \"WebhookSignatureFormatError\"].includes(\n error.type\n );\n}\nconst MINIMUM_TIMESTAMP = 16094592e5, SIGNATURE_HEADER_REGEX = /^t=(\\d+)[, ]+v1=([^, ]+)$/, SIGNATURE_HEADER_NAME = \"sanity-webhook-signature\";\nasync function assertValidSignature(stringifiedPayload, signature, secret) {\n const { timestamp } = decodeSignatureHeader(signature), encoded = await encodeSignatureHeader(stringifiedPayload, timestamp, secret);\n if (signature !== encoded)\n throw new WebhookSignatureValueError(\"Signature is invalid\");\n}\nasync function isValidSignature(stringifiedPayload, signature, secret) {\n try {\n return await assertValidSignature(stringifiedPayload, signature, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function assertValidRequest(request, secret) {\n const signature = request.headers[SIGNATURE_HEADER_NAME];\n if (Array.isArray(signature))\n throw new WebhookSignatureFormatError(\"Multiple signature headers received\");\n if (typeof signature != \"string\")\n throw new WebhookSignatureValueError(\"Request contained no signature header\");\n if (typeof request.body > \"u\")\n throw new WebhookSignatureFormatError(\"Request contained no parsed request body\");\n if (typeof request.body == \"string\" || Buffer.isBuffer(request.body))\n await assertValidSignature(request.body.toString(\"utf8\"), signature, secret);\n else\n throw new Error(\n \"[@sanity/webhook] `request.body` was not a string/buffer - this can lead to invalid signatures. See the [migration docs](https://github.com/sanity-io/webhook-toolkit#from-parsed-to-unparsed-body) for details on how to fix this.\"\n );\n}\nasync function isValidRequest(request, secret) {\n try {\n return await assertValidRequest(request, secret), !0;\n } catch (err) {\n if (isSignatureError(err))\n return !1;\n throw err;\n }\n}\nasync function encodeSignatureHeader(stringifiedPayload, timestamp, secret) {\n const signature = await createHS256Signature(stringifiedPayload, timestamp, secret);\n return `t=${timestamp},v1=${signature}`;\n}\nfunction decodeSignatureHeader(signaturePayload) {\n if (!signaturePayload)\n throw new WebhookSignatureFormatError(\"Missing or empty signature header\");\n const [, timestamp, hashedPayload] = signaturePayload.trim().match(SIGNATURE_HEADER_REGEX) || [];\n if (!timestamp || !hashedPayload)\n throw new WebhookSignatureFormatError(\"Invalid signature payload format\");\n return {\n timestamp: parseInt(timestamp, 10),\n hashedPayload\n };\n}\nasync function createHS256Signature(stringifiedPayload, timestamp, secret) {\n if (typeof crypto > \"u\")\n throw new TypeError(\n \"The Web Crypto API is not available in this environment, either polyfill `globalThis.crypto` or downgrade to `@sanity/webhook@3` which uses the Node.js `crypto` module.\"\n );\n if (!secret || typeof secret != \"string\")\n throw new WebhookSignatureFormatError(\"Invalid secret provided\");\n if (!stringifiedPayload)\n throw new WebhookSignatureFormatError(\"Can not create signature for empty payload\");\n if (typeof stringifiedPayload != \"string\")\n throw new WebhookSignatureFormatError(\"Payload must be a JSON-encoded string\");\n if (typeof timestamp != \"number\" || isNaN(timestamp) || timestamp < MINIMUM_TIMESTAMP)\n throw new WebhookSignatureFormatError(\n \"Invalid signature timestamp, must be a unix timestamp with millisecond precision\"\n );\n const enc = new TextEncoder(), key = await crypto.subtle.importKey(\n \"raw\",\n enc.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n !1,\n [\"sign\"]\n ), signaturePayload = `${timestamp}.${stringifiedPayload}`, signature = await crypto.subtle.sign(\"HMAC\", key, enc.encode(signaturePayload)), signatureArray = Array.from(new Uint8Array(signature));\n return btoa(String.fromCharCode.apply(null, signatureArray)).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\");\n}\nfunction requireSignedRequest(options) {\n const parseBody = typeof options.parseBody > \"u\" ? !0 : options.parseBody, respondOnError = typeof options.respondOnError > \"u\" ? !0 : options.respondOnError;\n return async function(request, response, next) {\n try {\n await assertValidRequest(request, options.secret), parseBody && typeof request.body == \"string\" && (request.body = JSON.parse(request.body)), next();\n } catch (err) {\n if (!respondOnError || !isSignatureError(err)) {\n next(err);\n return;\n }\n response.status(err.statusCode).json({ message: err.message });\n }\n };\n}\nexport {\n SIGNATURE_HEADER_NAME,\n WebhookSignatureFormatError,\n WebhookSignatureValueError,\n assertValidRequest,\n assertValidSignature,\n decodeSignatureHeader,\n encodeSignatureHeader,\n isSignatureError,\n isValidRequest,\n isValidSignature,\n requireSignedRequest\n};\n//# sourceMappingURL=index.mjs.map\n","import type {SanityDocument} from '@sanity/types'\nimport {isValidSignature, SIGNATURE_HEADER_NAME} from '@sanity/webhook'\nimport type {NextRequest} from 'next/server'\n\n/** @public */\nexport type ParsedBody<T> = {\n /**\n * If a secret is given then it returns a boolean. If no secret is provided then no validation is done on the signature, and it'll return `null`\n */\n isValidSignature: boolean | null\n body: T | null\n}\n\n/**\n * Handles parsing the body JSON, and validating its signature. Also waits for Content Lake eventual consistency so you can run your queries\n * without worrying about getting stale data.\n * @public\n */\nexport async function parseBody<Body = SanityDocument>(\n req: NextRequest,\n secret?: string,\n waitForContentLakeEventualConsistency = true,\n): Promise<ParsedBody<Body>> {\n const signature = req.headers.get(SIGNATURE_HEADER_NAME)\n if (!signature) {\n console.error('Missing signature header')\n return {body: null, isValidSignature: null}\n }\n\n const body = await req.text()\n const validSignature = secret ? await isValidSignature(body, signature, secret.trim()) : null\n\n if (validSignature !== false && waitForContentLakeEventualConsistency) {\n await new Promise((resolve) => setTimeout(resolve, 3000))\n }\n\n return {\n body: body.trim() ? JSON.parse(body) : null,\n isValidSignature: validSignature,\n }\n}\n"],"names":[],"mappings":"AAAA,MAAM,mCAAmC,MAAM;AAAA,EAC7C,OAAO;AAAA,EACP,aAAa;AACf;AACA,MAAM,oCAAoC,MAAM;AAAA,EAC9C,OAAO;AAAA,EACP,aAAa;AACf;AACA,SAAS,iBAAiB,OAAO;AAC/B,SAAO,OAAO,SAAS,YAAY,UAAU,QAAQ,UAAU,SAAS,CAAC,8BAA8B,6BAA6B,EAAE;AAAA,IACpI,MAAM;AAAA,EACV;AACA;AACA,MAAM,oBAAoB,YAAY,yBAAyB,6BAA6B,wBAAwB;AACpH,eAAe,qBAAqB,oBAAoB,WAAW,QAAQ;AACzE,QAAM,EAAE,UAAS,IAAK,sBAAsB,SAAS,GAAG,UAAU,MAAM,sBAAsB,oBAAoB,WAAW,MAAM;AACnI,MAAI,cAAc;AAChB,UAAM,IAAI,2BAA2B,sBAAsB;AAC/D;AACA,eAAe,iBAAiB,oBAAoB,WAAW,QAAQ;AACrE,MAAI;AACF,WAAO,MAAM,qBAAqB,oBAAoB,WAAW,MAAM,GAAG;AAAA,EAC5E,SAAS,KAAK;AACZ,QAAI,iBAAiB,GAAG;AACtB,aAAO;AACT,UAAM;AAAA,EACR;AACF;AAyBA,eAAe,sBAAsB,oBAAoB,WAAW,QAAQ;AAC1E,QAAM,YAAY,MAAM,qBAAqB,oBAAoB,WAAW,MAAM;AAClF,SAAO,KAAK,SAAS,OAAO,SAAS;AACvC;AACA,SAAS,sBAAsB,kBAAkB;AAC/C,MAAI,CAAC;AACH,UAAM,IAAI,4BAA4B,mCAAmC;AAC3E,QAAM,CAAA,EAAG,WA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AAM,MAAM,kBAAkB,KAAA;AAGxC,QAAM,OAAO,MAAM,IAAI,KAAA,GACjB,iBAAiB,SAAS,MAAM,iBAAiB,MAAM,WAAW,OAAO,KAAA,CAAM,IAAI;AAEzF,SAAI,mBAAmB,MAAS,yCAC9B,MAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAI,CAAC,GAGnD;AAAA,IACL,MAAM,KAAK,KAAA,IAAS,KAAK,MAAM,IAAI,IAAI;AAAA,IACvC,kBAAkB;AAAA,EAAA;AAEtB;","x_google_ignoreList":[0]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "9.12.
|
|
3
|
+
"version": "9.12.2",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -138,48 +138,37 @@
|
|
|
138
138
|
"browserslist": "extends @sanity/browserslist-config",
|
|
139
139
|
"dependencies": {
|
|
140
140
|
"@portabletext/react": "^3.2.1",
|
|
141
|
-
"@sanity/client": "^7.
|
|
142
|
-
"@sanity/next-loader": "^1.
|
|
143
|
-
"@sanity/preview-kit": "^6.1.
|
|
144
|
-
"@sanity/preview-url-secret": "^2.1.
|
|
145
|
-
"@sanity/visual-editing": "^2.
|
|
146
|
-
"groq": "^3.
|
|
141
|
+
"@sanity/client": "^7.6.0",
|
|
142
|
+
"@sanity/next-loader": "^1.7.0",
|
|
143
|
+
"@sanity/preview-kit": "^6.1.1",
|
|
144
|
+
"@sanity/preview-url-secret": "^2.1.12",
|
|
145
|
+
"@sanity/visual-editing": "^2.15.2",
|
|
146
|
+
"groq": "^3.99.0",
|
|
147
147
|
"history": "^5.3.0"
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"@sanity/browserslist-config": "^1.0.5",
|
|
151
|
-
"@sanity/
|
|
152
|
-
"@sanity/
|
|
151
|
+
"@sanity/pkg-utils": "^7.9.4",
|
|
152
|
+
"@sanity/types": "^3.99.0",
|
|
153
153
|
"@sanity/webhook": "4.0.4",
|
|
154
|
-
"@types/react": "^19.1.
|
|
155
|
-
"@types/react-dom": "^19.1.
|
|
156
|
-
"@
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
"
|
|
161
|
-
"eslint-gitignore": "^0.1.0",
|
|
162
|
-
"eslint-plugin-react": "^7.37.5",
|
|
163
|
-
"eslint-plugin-react-compiler": "beta",
|
|
164
|
-
"eslint-plugin-react-hooks": "^5.2.0",
|
|
165
|
-
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
166
|
-
"next": "15.3.1",
|
|
167
|
-
"react": "19.1.0",
|
|
168
|
-
"react-dom": "19.1.0",
|
|
169
|
-
"styled-components": "^6.1.17",
|
|
154
|
+
"@types/react": "^19.1.8",
|
|
155
|
+
"@types/react-dom": "^19.1.6",
|
|
156
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
157
|
+
"next": "^15.3.5",
|
|
158
|
+
"react": "^19.1.0",
|
|
159
|
+
"react-dom": "^19.1.0",
|
|
160
|
+
"styled-components": "^6.1.19",
|
|
170
161
|
"typescript": "5.8.3",
|
|
171
162
|
"vite-tsconfig-paths": "^5.1.4",
|
|
172
|
-
"vitest": "^3.
|
|
163
|
+
"vitest": "^3.2.4"
|
|
173
164
|
},
|
|
174
165
|
"peerDependencies": {
|
|
175
|
-
"@sanity/client": "^7.
|
|
176
|
-
"@sanity/
|
|
177
|
-
"@sanity/types": "^3.88.2",
|
|
178
|
-
"@sanity/ui": "^2.15.17",
|
|
166
|
+
"@sanity/client": "^7.6.0",
|
|
167
|
+
"@sanity/ui": "^2.16.7",
|
|
179
168
|
"next": "^14.2 || ^15.0.0-0",
|
|
180
169
|
"react": "^18.3 || ^19.0.0-0",
|
|
181
170
|
"react-dom": "^18.3 || ^19.0.0-0",
|
|
182
|
-
"sanity": "^3.
|
|
171
|
+
"sanity": "^3.99.0",
|
|
183
172
|
"styled-components": "^6.1"
|
|
184
173
|
},
|
|
185
174
|
"engines": {
|
|
@@ -188,8 +177,6 @@
|
|
|
188
177
|
"scripts": {
|
|
189
178
|
"build": "pkg build --strict --clean --check",
|
|
190
179
|
"coverage": "npm test -- --coverage",
|
|
191
|
-
"format": "eslint --fix .",
|
|
192
|
-
"lint": "eslint --max-warnings 0 .",
|
|
193
180
|
"test": "vitest",
|
|
194
181
|
"type-check": "tsc --noEmit"
|
|
195
182
|
}
|
|
@@ -5,19 +5,17 @@ export interface NextStudioLayoutProps {
|
|
|
5
5
|
children: React.ReactNode
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
const style = {
|
|
9
|
+
height: '100vh',
|
|
10
|
+
maxHeight: '100dvh',
|
|
11
|
+
overscrollBehavior: 'none',
|
|
12
|
+
WebkitFontSmoothing: 'antialiased',
|
|
13
|
+
overflow: 'auto',
|
|
14
|
+
} satisfies React.CSSProperties
|
|
15
|
+
|
|
8
16
|
const NextStudioLayoutComponent = ({children}: NextStudioLayoutProps) => {
|
|
9
17
|
return (
|
|
10
|
-
<div
|
|
11
|
-
id="sanity"
|
|
12
|
-
data-ui="NextStudioLayout"
|
|
13
|
-
style={{
|
|
14
|
-
height: '100vh',
|
|
15
|
-
maxHeight: '100dvh',
|
|
16
|
-
overscrollBehavior: 'none',
|
|
17
|
-
WebkitFontSmoothing: 'antialiased',
|
|
18
|
-
overflow: 'auto',
|
|
19
|
-
}}
|
|
20
|
-
>
|
|
18
|
+
<div id="sanity" data-ui="NextStudioLayout" style={style}>
|
|
21
19
|
{children}
|
|
22
20
|
</div>
|
|
23
21
|
)
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
+
const styles: Record<'outer' | 'inner', React.CSSProperties> = {
|
|
2
|
+
outer: {
|
|
3
|
+
position: 'absolute',
|
|
4
|
+
top: 0,
|
|
5
|
+
right: 0,
|
|
6
|
+
left: 0,
|
|
7
|
+
bottom: 0,
|
|
8
|
+
background: '#fff',
|
|
9
|
+
zIndex: 1,
|
|
10
|
+
},
|
|
11
|
+
inner: {
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
top: '50%',
|
|
14
|
+
left: '50%',
|
|
15
|
+
transform: 'translate(-50%, -50%)',
|
|
16
|
+
textAlign: 'center',
|
|
17
|
+
fontFamily: 'helvetica, arial, sans-serif',
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
1
21
|
/** @internal */
|
|
2
22
|
export const NextStudioNoScript = (): React.JSX.Element => (
|
|
3
23
|
<noscript>
|
|
4
|
-
<div
|
|
5
|
-
style={
|
|
6
|
-
position: 'absolute',
|
|
7
|
-
top: 0,
|
|
8
|
-
right: 0,
|
|
9
|
-
left: 0,
|
|
10
|
-
bottom: 0,
|
|
11
|
-
background: '#fff',
|
|
12
|
-
zIndex: 1,
|
|
13
|
-
}}
|
|
14
|
-
>
|
|
15
|
-
<div
|
|
16
|
-
style={{
|
|
17
|
-
position: 'absolute',
|
|
18
|
-
top: '50%',
|
|
19
|
-
left: '50%',
|
|
20
|
-
transform: 'translate(-50%, -50%)',
|
|
21
|
-
textAlign: 'center',
|
|
22
|
-
fontFamily: 'helvetica, arial, sans-serif',
|
|
23
|
-
}}
|
|
24
|
-
>
|
|
24
|
+
<div style={styles.outer}>
|
|
25
|
+
<div style={styles.inner}>
|
|
25
26
|
<h1>JavaScript disabled</h1>
|
|
26
27
|
<p>
|
|
27
28
|
Please <a href="https://www.enable-javascript.com/">enable JavaScript</a> in your browser
|
|
@@ -103,13 +103,7 @@ export default function VisualEditing(props: VisualEditingProps): React.JSX.Elem
|
|
|
103
103
|
)
|
|
104
104
|
return revalidateRootLayout()
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
// eslint-disable-next-line no-console
|
|
108
|
-
console.debug(
|
|
109
|
-
'Live preview is setup, mutation is skipped assuming its handled by the live preview',
|
|
110
|
-
)
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
106
|
+
|
|
113
107
|
const mutationFallbackRefresh = () => {
|
|
114
108
|
// eslint-disable-next-line no-console
|
|
115
109
|
console.debug(
|
|
@@ -141,3 +135,11 @@ export default function VisualEditing(props: VisualEditingProps): React.JSX.Elem
|
|
|
141
135
|
/>
|
|
142
136
|
)
|
|
143
137
|
}
|
|
138
|
+
|
|
139
|
+
function mutationFastRefresh(): false {
|
|
140
|
+
// eslint-disable-next-line no-console
|
|
141
|
+
console.debug(
|
|
142
|
+
'Live preview is setup, mutation is skipped assuming its handled by the live preview',
|
|
143
|
+
)
|
|
144
|
+
return false
|
|
145
|
+
}
|