UNPKG

alinea

Version:
45 lines (43 loc) 1.56 kB
import { unwrap } from "../../../chunks/chunk-WDCPVJJC.js"; import { useAtomValue } from "../../../chunks/chunk-TOJF2G3X.js"; import "../../../chunks/chunk-WJ67RR7S.js"; import "../../../chunks/chunk-NZLE2WMY.js"; // src/dashboard/view/entry/EntryPreview.tsx import { Config } from "alinea/core/Config"; import { useEffect, useState } from "react"; import { useConfig } from "../../hook/UseConfig.js"; import { BrowserPreview } from "../preview/BrowserPreview.js"; import { jsx } from "react/jsx-runtime"; function EntryPreview({ editor, preview }) { if (!preview) return null; if (typeof preview === "boolean") return /* @__PURE__ */ jsx(EntryPreviewUrl, { editor }); return /* @__PURE__ */ jsx(EntryPreviewComponent, { editor, preview }); } function EntryPreviewUrl({ editor }) { const config = useConfig(); const payload = useAtomValue(unwrap(editor.previewPayload)); const previewToken = useAtomValue(editor.previewToken); const previewSearch = `?preview=${previewToken}`; const [api, setApi] = useState(void 0); useEffect(() => { if (payload) api?.preview(payload); }, [payload]); const base = new URL( config.handlerUrl ?? "", Config.baseUrl(config) ?? location.href ); const url = new URL(previewSearch, base); return /* @__PURE__ */ jsx(BrowserPreview, { url: url.toString(), registerLivePreview: setApi }); } function EntryPreviewComponent({ editor, preview }) { const entry = useAtomValue(editor.draftEntry); const Tag = preview; return /* @__PURE__ */ jsx(Tag, { entry }); } export { EntryPreview };