import { FC, useEffect } from "react"; import { useGlobal } from "web-utils"; import { produceCSS } from "../../../../../utils/css/gen"; import { IItem } from "../../../../../utils/types/item"; import { IText } from "../../../../../utils/types/text"; import { EDGlobal, PG, active } from "../../../logic/ed-global"; import { loadComponent } from "../../../logic/tree/sync-walk"; import { EdCompPreviewTree } from "./comp-preview-tree"; import { compPicker } from "./comp-reload"; export const EdCompPreview = () => { const p = useGlobal(EDGlobal, "EDITOR"); const comp_id = p.ui.popup.comp.preview_id; const ref = p.comp.list[comp_id]; const item = ref?.doc?.getMap("map").get("root")?.toJSON() as | IItem | undefined; useEffect(() => { if (!p.comp.list[comp_id] && !!comp_id) { loadComponent(p, comp_id).then(() => { p.render(); }); } }, [comp_id]); return (
{comp_id && item && (
Preview
{comp_id}
{ e.stopPropagation(); if (p.ui.popup.comp.open) { p.ui.popup.comp.open(item.id); } p.ui.popup.comp.open = null; active.item_id = compPicker.active_id; compPicker.active_id = ""; p.render(); }} > Select Component
{ e.stopPropagation(); if (confirm("Are you sure to delete this component?")) { await db.component.delete({ where: { id: p.ui.popup.comp.preview_id }, }); const idx = compPicker.tree.findIndex((e) => e.id === comp_id) + 1; if (idx >= 0 && compPicker.tree[idx]) p.ui.popup.comp.preview_id = compPicker.tree[idx].id as any; compPicker.tree = compPicker.tree.filter( (e) => e.id !== comp_id ); p.render(); } }} >
)}
{comp_id ? ( <> {item && ref ? (
) : (
Loading...
)} ) : ( <> Select component
to preview )}
); }; const CItem: FC<{ item: IItem | IText; p: PG }> = ({ item, p }) => { const className = produceCSS(item, { mode: p.mode, }); if (item.type === "item") {
{item.type === "item" && item.childs.map((e) => { return ; })}
; } return (
); }; const DeleteIcon = () => ( );