next-sanity 9.5.2 → 9.5.3
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 +88 -0
- package/dist/_chunks-cjs/NextStudio.cjs.map +1 -0
- package/dist/_chunks-cjs/VisualEditing.cjs +104 -0
- package/dist/_chunks-cjs/VisualEditing.cjs.map +1 -0
- package/dist/_chunks-es/NextStudio.js +95 -0
- package/dist/_chunks-es/NextStudio.js.map +1 -0
- package/dist/_chunks-es/VisualEditing.js +110 -0
- package/dist/_chunks-es/VisualEditing.js.map +1 -0
- package/dist/index.cjs +3 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/studio/client-component.cjs +11 -83
- package/dist/studio/client-component.cjs.map +1 -1
- package/dist/studio/client-component.d.cts +1 -28
- package/dist/studio/client-component.d.ts +1 -28
- package/dist/studio/client-component.js +6 -90
- package/dist/studio/client-component.js.map +1 -1
- package/dist/studio.cjs +8 -26
- package/dist/studio.cjs.map +1 -1
- package/dist/studio.d.cts +2 -2
- package/dist/studio.d.ts +2 -2
- package/dist/studio.js +2 -2
- package/dist/studio.js.map +1 -1
- package/dist/visual-editing/client-component.cjs +12 -91
- package/dist/visual-editing/client-component.cjs.map +1 -1
- package/dist/visual-editing/client-component.d.cts +3 -3
- package/dist/visual-editing/client-component.d.ts +3 -3
- package/dist/visual-editing/client-component.js +6 -93
- package/dist/visual-editing/client-component.js.map +1 -1
- package/package.json +2 -2
- package/src/studio/client-component/NextStudio.tsx +16 -22
- package/src/studio/client-component/NextStudioLazy.tsx +15 -0
- package/src/studio/client-component/index.ts +3 -1
- package/src/studio/index.ts +1 -4
- package/src/visual-editing/client-component/VisualEditing.tsx +159 -0
- package/src/visual-editing/client-component/VisualEditingLazy.tsx +15 -0
- package/src/visual-editing/client-component/index.ts +2 -132
- package/src/visual-editing/index.tsx +1 -7
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react = require("react"), sanity = require("sanity"), NextStudioNoScript = require("./NextStudioNoScript.cjs"), history = require("history"), navigation_js = require("next/navigation.js"), styledComponents = require("styled-components");
|
|
3
|
+
function createHashHistoryForStudio() {
|
|
4
|
+
const history$1 = history.createHashHistory();
|
|
5
|
+
return {
|
|
6
|
+
get action() {
|
|
7
|
+
return history$1.action;
|
|
8
|
+
},
|
|
9
|
+
get location() {
|
|
10
|
+
return history$1.location;
|
|
11
|
+
},
|
|
12
|
+
get createHref() {
|
|
13
|
+
return history$1.createHref;
|
|
14
|
+
},
|
|
15
|
+
get push() {
|
|
16
|
+
return history$1.push;
|
|
17
|
+
},
|
|
18
|
+
get replace() {
|
|
19
|
+
return history$1.replace;
|
|
20
|
+
},
|
|
21
|
+
get go() {
|
|
22
|
+
return history$1.go;
|
|
23
|
+
},
|
|
24
|
+
get back() {
|
|
25
|
+
return history$1.back;
|
|
26
|
+
},
|
|
27
|
+
get forward() {
|
|
28
|
+
return history$1.forward;
|
|
29
|
+
},
|
|
30
|
+
get block() {
|
|
31
|
+
return history$1.block;
|
|
32
|
+
},
|
|
33
|
+
// Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)
|
|
34
|
+
listen(listener) {
|
|
35
|
+
return history$1.listen(({ location }) => {
|
|
36
|
+
listener(location);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function StyledComponentsRegistry({
|
|
42
|
+
children,
|
|
43
|
+
isMounted
|
|
44
|
+
}) {
|
|
45
|
+
const [styledComponentsStyleSheet] = react.useState(() => new styledComponents.ServerStyleSheet());
|
|
46
|
+
return navigation_js.useServerInsertedHTML(() => {
|
|
47
|
+
const styles = styledComponentsStyleSheet.getStyleElement();
|
|
48
|
+
return styledComponentsStyleSheet.instance.clearTag(), /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: styles });
|
|
49
|
+
}), isMounted ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : /* @__PURE__ */ jsxRuntime.jsx(styledComponents.StyleSheetManager, { sheet: styledComponentsStyleSheet.instance, children });
|
|
50
|
+
}
|
|
51
|
+
function useIsMounted() {
|
|
52
|
+
return react.useSyncExternalStore(
|
|
53
|
+
emptySubscribe,
|
|
54
|
+
() => !0,
|
|
55
|
+
() => !1
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const emptySubscribe = () => () => {
|
|
59
|
+
};
|
|
60
|
+
function NextStudioComponent({
|
|
61
|
+
children,
|
|
62
|
+
config,
|
|
63
|
+
unstable__noScript = !0,
|
|
64
|
+
scheme,
|
|
65
|
+
history: history2,
|
|
66
|
+
...props
|
|
67
|
+
}) {
|
|
68
|
+
const isMounted = useIsMounted(), unstableHistory = react.useMemo(() => {
|
|
69
|
+
if (props.unstable_history && history2)
|
|
70
|
+
throw new Error("Cannot use both `unstable_history` and `history` props at the same time");
|
|
71
|
+
return isMounted && history2 === "hash" ? createHashHistoryForStudio() : props.unstable_history;
|
|
72
|
+
}, [history2, isMounted, props.unstable_history]);
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
74
|
+
unstable__noScript && /* @__PURE__ */ jsxRuntime.jsx(NextStudioNoScript.NextStudioNoScript, {}),
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx(StyledComponentsRegistry, { isMounted, children: /* @__PURE__ */ jsxRuntime.jsx(NextStudioNoScript.NextStudioLayout, { children: history2 === "hash" && !isMounted ? null : children || /* @__PURE__ */ jsxRuntime.jsx(
|
|
76
|
+
sanity.Studio,
|
|
77
|
+
{
|
|
78
|
+
config,
|
|
79
|
+
scheme,
|
|
80
|
+
unstable_globalStyles: !0,
|
|
81
|
+
...props,
|
|
82
|
+
unstable_history: unstableHistory
|
|
83
|
+
}
|
|
84
|
+
) }) })
|
|
85
|
+
] });
|
|
86
|
+
}
|
|
87
|
+
exports.default = NextStudioComponent;
|
|
88
|
+
//# sourceMappingURL=NextStudio.cjs.map
|
|
@@ -0,0 +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}): 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;AACT,SAAA;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,MAAA,CAClB;AAAA,IACH;AAAA,EAAA;AAEJ;ACtCO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGgB;AAGd,QAAM,CAAC,0BAA0B,IAAIE,MAAAA,SAAS,MAAM,IAAIC,iBAAAA,iBAAkB,CAAA;AAQ1E,SANAC,oCAAsB,MAAM;AACpB,UAAA,SAAS,2BAA2B;AAC1C,WAAA,2BAA2B,SAAS,YAC7BC,2BAAAA,IAAAC,WAAAA,UAAA,EAAG,UAAO,OAAA,CAAA;AAAA,EAClB,CAAA,GAEG,YAAqBD,2BAAAA,IAAAC,WAAAA,UAAA,EAAA,SAAA,CAAS,IAGhCD,2BAAA,IAACE,iBAAkB,mBAAA,EAAA,OAAO,2BAA2B,UAAW,SAAS,CAAA;AAE7E;ACxBO,SAAS,eAAwB;AAC/B,SAAAC,MAAA;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,EAAA;AAEV;AAEA,MAAM,iBAAiB,MAAM,MAAM;AAAC;AC8BpC,SAAwB,oBAAoB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA,SAAAR;AAAA,EACA,GAAG;AACL,GAAuC;AACrC,QAAM,YAAY,aAAA,GACZ,kBAAkBS,cAAuC,MAAM;AACnE,QAAI,MAAM,oBAAoBT;AACtB,YAAA,IAAI,MAAM,yEAAyE;AAG3F,WAAI,aAAaA,aAAY,SACpB,+BAEF,MAAM;AAAA,KACZ,CAACA,UAAS,WAAW,MAAM,gBAAgB,CAAC;AAE/C,SAEKU,2BAAA,KAAAJ,qBAAA,EAAA,UAAA;AAAA,IAAA,qDAAuBK,mBAAmB,oBAAA,EAAA;AAAA,IAC3CN,2BAAAA,IAAC,0BAAyB,EAAA,WACxB,UAACA,2BAAA,IAAAO,mBAAA,kBAAA,EACE,uBAAY,UAAU,CAAC,YACpB,OACA,YACEP,2BAAA;AAAA,MAACQ,OAAA;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,uBAAqB;AAAA,QACpB,GAAG;AAAA,QACJ,kBAAkB;AAAA,MAAA;AAAA,OAG5B,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), react$1 = require("@sanity/visual-editing/react"), navigation_js = require("next/navigation.js"), serverActions = require("next-sanity/visual-editing/server-actions"), react = require("react"), reactDom = require("react-dom");
|
|
3
|
+
function pathHasPrefix(path, prefix) {
|
|
4
|
+
if (typeof path != "string")
|
|
5
|
+
return !1;
|
|
6
|
+
const { pathname } = parsePath(path);
|
|
7
|
+
return pathname === prefix || pathname.startsWith(`${prefix}/`);
|
|
8
|
+
}
|
|
9
|
+
function parsePath(path) {
|
|
10
|
+
const hashIndex = path.indexOf("#"), queryIndex = path.indexOf("?"), hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
|
|
11
|
+
return hasQuery || hashIndex > -1 ? {
|
|
12
|
+
pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),
|
|
13
|
+
query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : void 0) : "",
|
|
14
|
+
hash: hashIndex > -1 ? path.slice(hashIndex) : ""
|
|
15
|
+
} : { pathname: path, query: "", hash: "" };
|
|
16
|
+
}
|
|
17
|
+
function addPathPrefix(path, prefix) {
|
|
18
|
+
if (!path.startsWith("/") || !prefix)
|
|
19
|
+
return path;
|
|
20
|
+
if (path === "/" && prefix)
|
|
21
|
+
return prefix;
|
|
22
|
+
const { pathname, query, hash } = parsePath(path);
|
|
23
|
+
return `${prefix}${pathname}${query}${hash}`;
|
|
24
|
+
}
|
|
25
|
+
function removePathPrefix(path, prefix) {
|
|
26
|
+
if (!pathHasPrefix(path, prefix))
|
|
27
|
+
return path;
|
|
28
|
+
const withoutPrefix = path.slice(prefix.length);
|
|
29
|
+
return withoutPrefix.startsWith("/") ? withoutPrefix : `/${withoutPrefix}`;
|
|
30
|
+
}
|
|
31
|
+
const normalizePathTrailingSlash = (path, trailingSlash) => {
|
|
32
|
+
const { pathname, query, hash } = parsePath(path);
|
|
33
|
+
return trailingSlash ? pathname.endsWith("/") ? `${pathname}${query}${hash}` : `${pathname}/${query}${hash}` : `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
34
|
+
};
|
|
35
|
+
function removeTrailingSlash(route) {
|
|
36
|
+
return route.replace(/\/$/, "") || "/";
|
|
37
|
+
}
|
|
38
|
+
function VisualEditing(props) {
|
|
39
|
+
const { basePath = "", refresh, trailingSlash = !1, zIndex } = props, router = navigation_js.useRouter(), routerRef = react.useRef(router), [navigate, setNavigate] = react.useState();
|
|
40
|
+
react.useEffect(() => {
|
|
41
|
+
routerRef.current = router;
|
|
42
|
+
}, [router]);
|
|
43
|
+
const history = react.useMemo(
|
|
44
|
+
() => ({
|
|
45
|
+
subscribe: (_navigate) => (setNavigate(() => _navigate), () => setNavigate(void 0)),
|
|
46
|
+
update: (update) => {
|
|
47
|
+
switch (update.type) {
|
|
48
|
+
case "push":
|
|
49
|
+
return routerRef.current.push(removePathPrefix(update.url, basePath));
|
|
50
|
+
case "pop":
|
|
51
|
+
return routerRef.current.back();
|
|
52
|
+
case "replace":
|
|
53
|
+
return routerRef.current.replace(removePathPrefix(update.url, basePath));
|
|
54
|
+
default:
|
|
55
|
+
throw new Error(`Unknown update type: ${update.type}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}),
|
|
59
|
+
[basePath]
|
|
60
|
+
), pathname = navigation_js.usePathname(), searchParams = navigation_js.useSearchParams();
|
|
61
|
+
react.useEffect(() => {
|
|
62
|
+
navigate && navigate({
|
|
63
|
+
type: "push",
|
|
64
|
+
url: normalizePathTrailingSlash(
|
|
65
|
+
addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ""}`, basePath),
|
|
66
|
+
trailingSlash
|
|
67
|
+
)
|
|
68
|
+
});
|
|
69
|
+
}, [basePath, navigate, pathname, searchParams, trailingSlash]);
|
|
70
|
+
const handleRefresh = react.useCallback(
|
|
71
|
+
(payload) => {
|
|
72
|
+
if (refresh) return refresh(payload);
|
|
73
|
+
const manualFastRefresh = () => (console.debug(
|
|
74
|
+
"Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data"
|
|
75
|
+
), routerRef.current.refresh(), Promise.resolve()), manualFallbackRefresh = () => (console.debug(
|
|
76
|
+
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
77
|
+
), serverActions.revalidateRootLayout()), mutationFastRefresh = () => (console.debug(
|
|
78
|
+
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
79
|
+
), !1), mutationFallbackRefresh = () => (console.debug(
|
|
80
|
+
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
81
|
+
), serverActions.revalidateRootLayout());
|
|
82
|
+
switch (payload.source) {
|
|
83
|
+
case "manual":
|
|
84
|
+
return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh();
|
|
85
|
+
case "mutation":
|
|
86
|
+
return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh();
|
|
87
|
+
default:
|
|
88
|
+
throw new Error("Unknown refresh source", { cause: payload });
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
[refresh]
|
|
92
|
+
), [node, setNode] = react.useState(null);
|
|
93
|
+
return react.useEffect(() => {
|
|
94
|
+
const node2 = document.createElement("div");
|
|
95
|
+
return node2.id = "sanity-visual-editing", document.documentElement.appendChild(node2), setNode(node2), () => {
|
|
96
|
+
setNode(null), document.documentElement.contains(node2) && document.documentElement.removeChild(node2);
|
|
97
|
+
};
|
|
98
|
+
}, []), node ? reactDom.createPortal(
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsx(react$1.VisualEditing, { history, refresh: handleRefresh, zIndex }),
|
|
100
|
+
node
|
|
101
|
+
) : null;
|
|
102
|
+
}
|
|
103
|
+
exports.default = VisualEditing;
|
|
104
|
+
//# sourceMappingURL=VisualEditing.cjs.map
|
|
@@ -0,0 +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'\nimport {createPortal} from 'react-dom'\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 = '', 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 const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent history={history} refresh={handleRefresh} zIndex={zIndex} />,\n node,\n )\n}\n"],"names":["useRouter","useRef","useState","useEffect","useMemo","usePathname","useSearchParams","useCallback","revalidateRootLayout","node","createPortal","jsx","VisualEditingComponent"],"mappings":";;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;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;AAE/D,SAAA,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,IAAI;AAAA,EAAA,IAI5C,EAAC,UAAU,MAAM,OAAO,IAAI,MAAM;AAC3C;AAOgB,SAAA,cAAc,MAAc,QAAyB;AACnE,MAAI,CAAC,KAAK,WAAW,GAAG,KAAK,CAAC;AACrB,WAAA;AAGT,MAAI,SAAS,OAAO;AACX,WAAA;AAGT,QAAM,EAAC,UAAU,OAAO,KAAI,IAAI,UAAU,IAAI;AAC9C,SAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,IAAI;AAC5C;AAWgB,SAAA,iBAAiB,MAAc,QAAwB;AAajE,MAAA,CAAC,cAAc,MAAM,MAAM;AACtB,WAAA;AAIT,QAAM,gBAAgB,KAAK,MAAM,OAAO,MAAM;AAG9C,SAAI,cAAc,WAAW,GAAG,IACvB,gBAKF,IAAI,aAAa;AAC1B;AAOa,MAAA,6BAA6B,CAAC,MAAc,kBAAmC;AAC1F,QAAM,EAAC,UAAU,OAAO,KAAI,IAAI,UAA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AA,IAClF;AAAA,EAJgB,IAAA;AAMpB;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useSyncExternalStore, useMemo } from "react";
|
|
3
|
+
import { Studio } from "sanity";
|
|
4
|
+
import { NextStudioNoScript, NextStudioLayout } from "./NextStudioNoScript.js";
|
|
5
|
+
import { createHashHistory } from "history";
|
|
6
|
+
import { useServerInsertedHTML } from "next/navigation.js";
|
|
7
|
+
import { ServerStyleSheet, StyleSheetManager } from "styled-components";
|
|
8
|
+
function createHashHistoryForStudio() {
|
|
9
|
+
const history = createHashHistory();
|
|
10
|
+
return {
|
|
11
|
+
get action() {
|
|
12
|
+
return history.action;
|
|
13
|
+
},
|
|
14
|
+
get location() {
|
|
15
|
+
return history.location;
|
|
16
|
+
},
|
|
17
|
+
get createHref() {
|
|
18
|
+
return history.createHref;
|
|
19
|
+
},
|
|
20
|
+
get push() {
|
|
21
|
+
return history.push;
|
|
22
|
+
},
|
|
23
|
+
get replace() {
|
|
24
|
+
return history.replace;
|
|
25
|
+
},
|
|
26
|
+
get go() {
|
|
27
|
+
return history.go;
|
|
28
|
+
},
|
|
29
|
+
get back() {
|
|
30
|
+
return history.back;
|
|
31
|
+
},
|
|
32
|
+
get forward() {
|
|
33
|
+
return history.forward;
|
|
34
|
+
},
|
|
35
|
+
get block() {
|
|
36
|
+
return history.block;
|
|
37
|
+
},
|
|
38
|
+
// Overriding listen to workaround a problem where native history provides history.listen(location => void), but the npm package is history.listen(({action, location}) => void)
|
|
39
|
+
listen(listener) {
|
|
40
|
+
return history.listen(({ location }) => {
|
|
41
|
+
listener(location);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function StyledComponentsRegistry({
|
|
47
|
+
children,
|
|
48
|
+
isMounted
|
|
49
|
+
}) {
|
|
50
|
+
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());
|
|
51
|
+
return useServerInsertedHTML(() => {
|
|
52
|
+
const styles = styledComponentsStyleSheet.getStyleElement();
|
|
53
|
+
return styledComponentsStyleSheet.instance.clearTag(), /* @__PURE__ */ jsx(Fragment, { children: styles });
|
|
54
|
+
}), isMounted ? /* @__PURE__ */ jsx(Fragment, { children }) : /* @__PURE__ */ jsx(StyleSheetManager, { sheet: styledComponentsStyleSheet.instance, children });
|
|
55
|
+
}
|
|
56
|
+
function useIsMounted() {
|
|
57
|
+
return useSyncExternalStore(
|
|
58
|
+
emptySubscribe,
|
|
59
|
+
() => !0,
|
|
60
|
+
() => !1
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const emptySubscribe = () => () => {
|
|
64
|
+
};
|
|
65
|
+
function NextStudioComponent({
|
|
66
|
+
children,
|
|
67
|
+
config,
|
|
68
|
+
unstable__noScript = !0,
|
|
69
|
+
scheme,
|
|
70
|
+
history,
|
|
71
|
+
...props
|
|
72
|
+
}) {
|
|
73
|
+
const isMounted = useIsMounted(), unstableHistory = useMemo(() => {
|
|
74
|
+
if (props.unstable_history && history)
|
|
75
|
+
throw new Error("Cannot use both `unstable_history` and `history` props at the same time");
|
|
76
|
+
return isMounted && history === "hash" ? createHashHistoryForStudio() : props.unstable_history;
|
|
77
|
+
}, [history, isMounted, props.unstable_history]);
|
|
78
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
79
|
+
unstable__noScript && /* @__PURE__ */ jsx(NextStudioNoScript, {}),
|
|
80
|
+
/* @__PURE__ */ jsx(StyledComponentsRegistry, { isMounted, children: /* @__PURE__ */ jsx(NextStudioLayout, { children: history === "hash" && !isMounted ? null : children || /* @__PURE__ */ jsx(
|
|
81
|
+
Studio,
|
|
82
|
+
{
|
|
83
|
+
config,
|
|
84
|
+
scheme,
|
|
85
|
+
unstable_globalStyles: !0,
|
|
86
|
+
...props,
|
|
87
|
+
unstable_history: unstableHistory
|
|
88
|
+
}
|
|
89
|
+
) }) })
|
|
90
|
+
] });
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
NextStudioComponent as default
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=NextStudio.js.map
|
|
@@ -0,0 +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}): 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;AACT,SAAA;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;AAAA,IACjB;AAAA,IACA,IAAI,QAAQ;AACV,aAAO,QAAQ;AAAA,IACjB;AAAA;AAAA,IAEA,OAAO,UAAoB;AAEzB,aAAO,QAAQ,OAAO,CAAC,EAAC,eAAc;AAGpC,iBAAS,QAAQ;AAAA,MAAA,CAClB;AAAA,IACH;AAAA,EAAA;AAEJ;ACtCO,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AACF,GAGgB;AAGd,QAAM,CAAC,0BAA0B,IAAI,SAAS,MAAM,IAAI,iBAAkB,CAAA;AAQ1E,SANA,sBAAsB,MAAM;AACpB,UAAA,SAAS,2BAA2B;AAC1C,WAAA,2BAA2B,SAAS,YAC7B,oBAAA,UAAA,EAAG,UAAO,OAAA,CAAA;AAAA,EAClB,CAAA,GAEG,YAAqB,oBAAA,UAAA,EAAA,SAAA,CAAS,IAGhC,oBAAC,mBAAkB,EAAA,OAAO,2BAA2B,UAAW,SAAS,CAAA;AAE7E;ACxBO,SAAS,eAAwB;AAC/B,SAAA;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,EAAA;AAEV;AAEA,MAAM,iBAAiB,MAAM,MAAM;AAAC;AC8BpC,SAAwB,oBAAoB;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAuC;AACrC,QAAM,YAAY,aAAA,GACZ,kBAAkB,QAAuC,MAAM;AACnE,QAAI,MAAM,oBAAoB;AACtB,YAAA,IAAI,MAAM,yEAAyE;AAG3F,WAAI,aAAa,YAAY,SACpB,+BAEF,MAAM;AAAA,KACZ,CAAC,SAAS,WAAW,MAAM,gBAAgB,CAAC;AAE/C,SAEK,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,0CAAuB,oBAAmB,EAAA;AAAA,IAC3C,oBAAC,0BAAyB,EAAA,WACxB,UAAC,oBAAA,kBAAA,EACE,sBAAY,UAAU,CAAC,YACpB,OACA,YACE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA,uBAAqB;AAAA,QACpB,GAAG;AAAA,QACJ,kBAAkB;AAAA,MAAA;AAAA,OAG5B,EACF,CAAA;AAAA,EACF,EAAA,CAAA;AAEJ;"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { VisualEditing as VisualEditing$1 } from "@sanity/visual-editing/react";
|
|
3
|
+
import { useRouter, usePathname, useSearchParams } from "next/navigation.js";
|
|
4
|
+
import { revalidateRootLayout } from "next-sanity/visual-editing/server-actions";
|
|
5
|
+
import { useRef, useState, useEffect, useMemo, useCallback } from "react";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
|
+
function pathHasPrefix(path, prefix) {
|
|
8
|
+
if (typeof path != "string")
|
|
9
|
+
return !1;
|
|
10
|
+
const { pathname } = parsePath(path);
|
|
11
|
+
return pathname === prefix || pathname.startsWith(`${prefix}/`);
|
|
12
|
+
}
|
|
13
|
+
function parsePath(path) {
|
|
14
|
+
const hashIndex = path.indexOf("#"), queryIndex = path.indexOf("?"), hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
|
|
15
|
+
return hasQuery || hashIndex > -1 ? {
|
|
16
|
+
pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),
|
|
17
|
+
query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : void 0) : "",
|
|
18
|
+
hash: hashIndex > -1 ? path.slice(hashIndex) : ""
|
|
19
|
+
} : { pathname: path, query: "", hash: "" };
|
|
20
|
+
}
|
|
21
|
+
function addPathPrefix(path, prefix) {
|
|
22
|
+
if (!path.startsWith("/") || !prefix)
|
|
23
|
+
return path;
|
|
24
|
+
if (path === "/" && prefix)
|
|
25
|
+
return prefix;
|
|
26
|
+
const { pathname, query, hash } = parsePath(path);
|
|
27
|
+
return `${prefix}${pathname}${query}${hash}`;
|
|
28
|
+
}
|
|
29
|
+
function removePathPrefix(path, prefix) {
|
|
30
|
+
if (!pathHasPrefix(path, prefix))
|
|
31
|
+
return path;
|
|
32
|
+
const withoutPrefix = path.slice(prefix.length);
|
|
33
|
+
return withoutPrefix.startsWith("/") ? withoutPrefix : `/${withoutPrefix}`;
|
|
34
|
+
}
|
|
35
|
+
const normalizePathTrailingSlash = (path, trailingSlash) => {
|
|
36
|
+
const { pathname, query, hash } = parsePath(path);
|
|
37
|
+
return trailingSlash ? pathname.endsWith("/") ? `${pathname}${query}${hash}` : `${pathname}/${query}${hash}` : `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
38
|
+
};
|
|
39
|
+
function removeTrailingSlash(route) {
|
|
40
|
+
return route.replace(/\/$/, "") || "/";
|
|
41
|
+
}
|
|
42
|
+
function VisualEditing(props) {
|
|
43
|
+
const { basePath = "", refresh, trailingSlash = !1, zIndex } = props, router = useRouter(), routerRef = useRef(router), [navigate, setNavigate] = useState();
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
routerRef.current = router;
|
|
46
|
+
}, [router]);
|
|
47
|
+
const history = useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
subscribe: (_navigate) => (setNavigate(() => _navigate), () => setNavigate(void 0)),
|
|
50
|
+
update: (update) => {
|
|
51
|
+
switch (update.type) {
|
|
52
|
+
case "push":
|
|
53
|
+
return routerRef.current.push(removePathPrefix(update.url, basePath));
|
|
54
|
+
case "pop":
|
|
55
|
+
return routerRef.current.back();
|
|
56
|
+
case "replace":
|
|
57
|
+
return routerRef.current.replace(removePathPrefix(update.url, basePath));
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unknown update type: ${update.type}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
[basePath]
|
|
64
|
+
), pathname = usePathname(), searchParams = useSearchParams();
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
navigate && navigate({
|
|
67
|
+
type: "push",
|
|
68
|
+
url: normalizePathTrailingSlash(
|
|
69
|
+
addPathPrefix(`${pathname}${searchParams?.size ? `?${searchParams}` : ""}`, basePath),
|
|
70
|
+
trailingSlash
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
}, [basePath, navigate, pathname, searchParams, trailingSlash]);
|
|
74
|
+
const handleRefresh = useCallback(
|
|
75
|
+
(payload) => {
|
|
76
|
+
if (refresh) return refresh(payload);
|
|
77
|
+
const manualFastRefresh = () => (console.debug(
|
|
78
|
+
"Live preview is setup, calling router.refresh() to refresh the server components without refetching cached data"
|
|
79
|
+
), routerRef.current.refresh(), Promise.resolve()), manualFallbackRefresh = () => (console.debug(
|
|
80
|
+
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
81
|
+
), revalidateRootLayout()), mutationFastRefresh = () => (console.debug(
|
|
82
|
+
"Live preview is setup, mutation is skipped assuming its handled by the live preview"
|
|
83
|
+
), !1), mutationFallbackRefresh = () => (console.debug(
|
|
84
|
+
"No loaders in live mode detected, or preview kit setup, revalidating root layout"
|
|
85
|
+
), revalidateRootLayout());
|
|
86
|
+
switch (payload.source) {
|
|
87
|
+
case "manual":
|
|
88
|
+
return payload.livePreviewEnabled ? manualFastRefresh() : manualFallbackRefresh();
|
|
89
|
+
case "mutation":
|
|
90
|
+
return payload.livePreviewEnabled ? mutationFastRefresh() : mutationFallbackRefresh();
|
|
91
|
+
default:
|
|
92
|
+
throw new Error("Unknown refresh source", { cause: payload });
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[refresh]
|
|
96
|
+
), [node, setNode] = useState(null);
|
|
97
|
+
return useEffect(() => {
|
|
98
|
+
const node2 = document.createElement("div");
|
|
99
|
+
return node2.id = "sanity-visual-editing", document.documentElement.appendChild(node2), setNode(node2), () => {
|
|
100
|
+
setNode(null), document.documentElement.contains(node2) && document.documentElement.removeChild(node2);
|
|
101
|
+
};
|
|
102
|
+
}, []), node ? createPortal(
|
|
103
|
+
/* @__PURE__ */ jsx(VisualEditing$1, { history, refresh: handleRefresh, zIndex }),
|
|
104
|
+
node
|
|
105
|
+
) : null;
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
VisualEditing as default
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=VisualEditing.js.map
|
|
@@ -0,0 +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'\nimport {createPortal} from 'react-dom'\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 = '', 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 const [node, setNode] = useState<HTMLDivElement | null>(null)\n useEffect(() => {\n // eslint-disable-next-line no-warning-comments\n // @TODO use 'sanity-visual-editing' instead of 'div'\n // eslint-disable-next-line no-shadow\n const node = document.createElement('div')\n // eslint-disable-next-line no-warning-comments\n // @TODO after the element is `sanity-visual-editing` instead of `div`, stop setting this ID\n node.id = 'sanity-visual-editing'\n document.documentElement.appendChild(node)\n setNode(node)\n return () => {\n setNode(null)\n if (document.documentElement.contains(node)) {\n document.documentElement.removeChild(node)\n }\n }\n }, [])\n\n if (!node) return null\n\n return createPortal(\n <VisualEditingComponent history={history} refresh={handleRefresh} zIndex={zIndex} />,\n node,\n )\n}\n"],"names":["node","VisualEditingComponent"],"mappings":";;;;;;AAQA,SAAS,cAAc,MAAc,QAAyB;AAC5D,MAAI,OAAO,QAAS;AACX,WAAA;AAGT,QAAM,EAAC,SAAA,IAAY,UAAU,IAAI;AACjC,SAAO,aAAa,UAAU,SAAS,WAAW,GAAG,MA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AAAA,QACN;AAAA,MAEK,GAAA,qBAAA,IAEH,sBAAsB,OAE1B,QAAQ;AAAA,QACN;AAAA,MAEK,GAAA,KAEH,0BAA0B,OAE9B,QAAQ;AAAA,QACN;AAAA,MAAA,GAEK,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,QAAQ,CAAA;AAAA,MAC9D;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,KAGJ,CAAC,MAAM,OAAO,IAAI,SAAgC,IAAI;AAmB5D,SAlBA,UAAU,MAAM;AAIRA,UAAAA,QAAO,SAAS,cAAc,KAAK;AAGzCA,WAAAA,MAAK,KAAK,yBACV,SAAS,gBAAgB,YAAYA,KAAI,GACzC,QAAQA,KAAI,GACL,MAAM;AACH,cAAA,IAAI,GACR,SAAS,gBAAgB,SAASA,KAAI,KACxC,SAAS,gBAAgB,YAAYA,KAAI;AAAA,IAAA;AAAA,EAE7C,GACC,CAAE,CAAA,GAEA,OAEE;AAAA,IACJ,oBAAAC,iBAAA,EAAuB,SAAkB,SAAS,eAAe,QAAgB;AAAA,IAClF;AAAA,EAJgB,IAAA;AAMpB;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
14
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
15
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
16
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
17
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
18
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
19
|
-
mod
|
|
20
|
-
));
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
-
var client = require("@sanity/client"), stega = require("@sanity/client/stega"), jsxRuntime = require("react/jsx-runtime"),
|
|
3
|
+
var client = require("@sanity/client"), stega = require("@sanity/client/stega"), jsxRuntime = require("react/jsx-runtime"), VisualEditingComponent = require("next-sanity/visual-editing/client-component"), react = require("@portabletext/react"), groq = require("groq"), createDataAttribute = require("@sanity/visual-editing/create-data-attribute");
|
|
23
4
|
function _interopDefaultCompat(e) {
|
|
24
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
25
6
|
}
|
|
26
|
-
var
|
|
27
|
-
const VisualEditingComponent = dynamic__default.default(
|
|
28
|
-
() => import("next-sanity/visual-editing/client-component"),
|
|
29
|
-
{ ssr: !1 }
|
|
30
|
-
);
|
|
7
|
+
var VisualEditingComponent__default = /* @__PURE__ */ _interopDefaultCompat(VisualEditingComponent), groq__default = /* @__PURE__ */ _interopDefaultCompat(groq);
|
|
31
8
|
function VisualEditing(props) {
|
|
32
9
|
let autoBasePath;
|
|
33
10
|
if (typeof props.basePath != "string")
|
|
@@ -48,7 +25,7 @@ function VisualEditing(props) {
|
|
|
48
25
|
console.error("Failed detecting trailingSlash", err);
|
|
49
26
|
}
|
|
50
27
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
51
|
-
|
|
28
|
+
VisualEditingComponent__default.default,
|
|
52
29
|
{
|
|
53
30
|
...props,
|
|
54
31
|
basePath: props.basePath ?? autoBasePath,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["
|
|
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 {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":["jsx","VisualEditingComponent"],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,aAGtD,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEE,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,aAGhE,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAGA,SAAAA,2BAAA;AAAA,IAACC,gCAAA;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { createClient, unstable__adapter, unstable__environment } from "@sanity/client";
|
|
2
2
|
import { stegaClean } from "@sanity/client/stega";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import
|
|
4
|
+
import VisualEditingComponent from "next-sanity/visual-editing/client-component";
|
|
5
5
|
export * from "@portabletext/react";
|
|
6
6
|
import { defineQuery, default as default2 } from "groq";
|
|
7
7
|
import { createDataAttribute } from "@sanity/visual-editing/create-data-attribute";
|
|
8
|
-
const VisualEditingComponent = dynamic(
|
|
9
|
-
() => import("next-sanity/visual-editing/client-component"),
|
|
10
|
-
{ ssr: !1 }
|
|
11
|
-
);
|
|
12
8
|
function VisualEditing(props) {
|
|
13
9
|
let autoBasePath;
|
|
14
10
|
if (typeof props.basePath != "string")
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/visual-editing/index.tsx"],"sourcesContent":["
|
|
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 {\n type CreateDataAttribute,\n createDataAttribute,\n type CreateDataAttributeProps,\n} from '@sanity/visual-editing/create-data-attribute'\nexport type {VisualEditingProps} from 'next-sanity/visual-editing/client-component'\n"],"names":[],"mappings":";;;;;;;AAMO,SAAS,cAAc,OAA+C;AACvE,MAAA;AACA,MAAA,OAAO,MAAM,YAAa;AACxB,QAAA;AACF,qBAAe,QAAQ,IAAI,wBACvB,gBAEF,QAAQ;AAAA,QACN,6BAA6B,KAAK,UAAU,YAAY,CAAC;AAAA,MAAA;AAAA,aAGtD,KAAK;AACJ,cAAA,MAAM,6BAA6B,GAAG;AAAA,IAChD;AAEE,MAAA;AACA,MAAA,OAAO,MAAM,iBAAkB;AAC7B,QAAA;AACF,0BAAoB,CAAQ,CAAA,QAAQ,IAAI,uBACpC,qBAEF,QAAQ;AAAA,QACN,kCAAkC,KAAK,UAAU,iBAAiB,CAAC;AAAA,MAAA;AAAA,aAGhE,KAAK;AACJ,cAAA,MAAM,kCAAkC,GAAG;AAAA,IACrD;AAGA,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,MAAM,YAAY;AAAA,MAC5B,eAAe,MAAM,iBAAiB;AAAA,IAAA;AAAA,EAAA;AAG5C;"}
|