UNPKG

@sanity/visual-editing

Version:

[![npm stat](https://img.shields.io/npm/dm/@sanity/visual-editing.svg?style=flat-square)](https://npm-stat.com/charts.html?package=@sanity/visual-editing) [![npm version](https://img.shields.io/npm/v/@sanity/visual-editing.svg?style=flat-square)](https://

56 lines (55 loc) 3.24 kB
import { c } from "react-compiler-runtime"; import { useRef, useState, useEffect } from "react"; import { useNavigate, useRevalidator, useLocation } from "react-router"; import { enableVisualEditing } from "./enableVisualEditing.js"; function VisualEditingComponent(props) { const $ = c(20), { components, refresh, zIndex } = props, navigateRemix = useNavigate(), navigateRemixRef = useRef(navigateRemix), [navigate, setNavigate] = useState(), revalidator = useRevalidator(), [revalidatorPromise, setRevalidatorPromise] = useState(null), [revalidatorLoading, setRevalidatorLoading] = useState(!1); let t0, t1; $[0] !== navigateRemix ? (t0 = () => { navigateRemixRef.current = navigateRemix; }, t1 = [navigateRemix], $[0] = navigateRemix, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1); let t2, t3; $[3] !== revalidator.state || $[4] !== revalidatorLoading || $[5] !== revalidatorPromise ? (t2 = () => { revalidatorPromise && revalidator.state === "loading" ? setRevalidatorLoading(!0) : revalidatorPromise && revalidatorLoading && revalidator.state === "idle" && (revalidatorPromise(), setRevalidatorPromise(null), setRevalidatorLoading(!1)); }, t3 = [revalidatorLoading, revalidator.state, revalidatorPromise], $[3] = revalidator.state, $[4] = revalidatorLoading, $[5] = revalidatorPromise, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), useEffect(t2, t3); let t4, t5; $[8] !== components || $[9] !== refresh || $[10] !== revalidator || $[11] !== zIndex ? (t4 = () => { const disable = enableVisualEditing({ components, zIndex, refresh: (payload) => { const refreshDefault = function() { return payload.source === "mutation" && payload.livePreviewEnabled ? !1 : new Promise((resolve) => { revalidator.revalidate(), setRevalidatorPromise(() => resolve); }); }; return refresh ? refresh(payload, refreshDefault) : refreshDefault(); }, history: { subscribe: (_navigate) => (setNavigate(() => _navigate), () => setNavigate(void 0)), update: (update) => { update.type === "push" || update.type === "replace" ? navigateRemixRef.current(update.url, { replace: update.type === "replace" }) : update.type === "pop" && navigateRemixRef.current(-1); } } }); return () => disable(); }, t5 = [components, refresh, revalidator, zIndex], $[8] = components, $[9] = refresh, $[10] = revalidator, $[11] = zIndex, $[12] = t4, $[13] = t5) : (t4 = $[12], t5 = $[13]), useEffect(t4, t5); const location = useLocation(); let t6, t7; return $[14] !== location.hash || $[15] !== location.pathname || $[16] !== location.search || $[17] !== navigate ? (t6 = () => { navigate && navigate({ type: "push", url: `${location.pathname}${location.search}${location.hash}` }); }, t7 = [location.hash, location.pathname, location.search, navigate], $[14] = location.hash, $[15] = location.pathname, $[16] = location.search, $[17] = navigate, $[18] = t6, $[19] = t7) : (t6 = $[18], t7 = $[19]), useEffect(t6, t7), null; } export { VisualEditingComponent as default }; //# sourceMappingURL=VisualEditingComponent2.js.map