UNPKG

next-sanity

Version:
68 lines (67 loc) 1.98 kB
import { n as NextStudioLayout, t as NextStudioNoScript } from "./NextStudioNoScript.js"; import { useMemo, useSyncExternalStore } from "react"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import { Studio } from "sanity"; import { createHashHistory } from "history"; function createHashHistoryForStudio() { const history = createHashHistory(); return { get action() { return history.action; }, get location() { return history.location; }, get createHref() { return history.createHref; }, get push() { return history.push; }, get replace() { return history.replace; }, get go() { return history.go; }, get back() { return history.back; }, get forward() { return history.forward; }, get block() { return history.block; }, listen(listener) { return history.listen(({ location }) => { listener(location); }); } }; } function useIsMounted() { return useSyncExternalStore(emptySubscribe, () => true, () => false); } const emptySubscribe = () => () => {}; function NextStudioComponent({ children, config, unstable__noScript = true, scheme, history, ...props }) { const isMounted = useIsMounted(); const unstableHistory = useMemo(() => { if (props.unstable_history && history) throw new Error("Cannot use both `unstable_history` and `history` props at the same time"); if (isMounted && history === "hash") return createHashHistoryForStudio(); return props.unstable_history; }, [ history, isMounted, props.unstable_history ]); return /* @__PURE__ */ jsxs(Fragment, { children: [unstable__noScript && /* @__PURE__ */ jsx(NextStudioNoScript, {}), /* @__PURE__ */ jsx(NextStudioLayout, { children: history === "hash" && !isMounted ? null : children || /* @__PURE__ */ jsx(Studio, { config, scheme, unstable_globalStyles: true, ...props, unstable_history: unstableHistory }) })] }); } export { NextStudioComponent as default }; //# sourceMappingURL=NextStudio.js.map