import { FC } from "react"; import { useGlobal, useLocal } from "web-utils"; import { IItem } from "../../../../utils/types/item"; import { FMCompDef } from "../../../../utils/types/meta-fn"; import { Menu, MenuItem } from "../../../../utils/ui/context-menu"; import { EDGlobal, EdMeta, active } from "../../logic/ed-global"; import { EdPropInstanceCode } from "./prop-instance/prop-code"; import { EdPropInstanceOptions } from "./prop-instance/prop-option"; import { reset } from "./prop-instance/prop-reset"; import { EdPropInstanceText } from "./prop-instance/prop-text"; export const EdSidePropInstance: FC<{ meta: EdMeta }> = ({ meta }) => { const p = useGlobal(EDGlobal, "EDITOR"); const local = useLocal({ rightClickEvent: null as any, reset: { mprop: null as any, name: "" }, showJSX: false, }); const item = meta?.item as IItem; if (!item) return null; let filtered = [] as { mprop: FMCompDef; name: string }[]; const mprops = meta.mitem?.get("component")?.get("props"); const comp_id = meta.mitem?.get("component")?.get("id") || ""; const mcprops = p.comp.list[comp_id].doc .getMap("map") .get("root") ?.get("component") ?.get("props"); if (mprops && meta.mitem && mcprops) { mcprops.forEach((m, key) => { let mprop = mprops.get(key); const type = m.get("meta")?.get("type") || "text"; const visible = mprop?.get("visible") || ""; if (meta.propvis) { if (meta.propvis[key] === false) return; } else if (visible) { return; } if (!local.showJSX && type === "content-element") { return; } if (!mprop) { const json = m.toJSON(); const map = new Y.Map() as any; syncronize(map, json); mprops.set(key, map); filtered.push({ mprop: map, name: key }); } else { filtered.push({ mprop, name: key }); } }); filtered = filtered.sort((a, b) => { const aidx = a.mprop.get("idx") || 0; const bidx = b.mprop.get("idx") || 0; return aidx - bidx; }); } return (
{meta.item.name}
{ const item = meta.item as IItem; const comp_id = item.component?.id; if (comp_id) { active.instance.item_id = item.id; active.instance.comp_id = active.comp_id; active.comp_id = comp_id || ""; const root = p.comp.list[comp_id].tree.find( (e) => e.parent === "root" ); if (root && typeof root.id === "string") { active.item_id = root.id || ""; } p.render(); } }} > Edit Component
{local.rightClickEvent && ( { local.rightClickEvent = null; local.render(); }} > { if (local.reset.name) { reset(p, comp_id, local.reset.mprop, local.reset.name); } }} /> {}} /> )} {filtered.length === 0 && (
No Prop Available
)} {filtered.map(({ name, mprop }) => { const type = mprop.get("meta")?.get("type") || "text"; let hasCode = false; const value = mprop.get("value") || ""; if (!!value && ![`"`, "'", "`"].includes(value[0])) { hasCode = true; } return (
{ e.preventDefault(); local.reset = { mprop, name }; local.rightClickEvent = e; local.render(); }} > {hasCode ? ( <> ) : ( <> {type === "text" && ( )} {type === "option" && ( )} {type === "content-element" && (
{name}
)} )}
); })}
); };