diff --git a/app/web/src/nova/ed/panel/header/mid/add-text.tsx b/app/web/src/nova/ed/panel/header/mid/add-text.tsx index 01b532e0..062230a0 100644 --- a/app/web/src/nova/ed/panel/header/mid/add-text.tsx +++ b/app/web/src/nova/ed/panel/header/mid/add-text.tsx @@ -7,6 +7,7 @@ import { IText } from "../../../../../utils/types/text"; import { MContent } from "../../../../../utils/types/general"; import { fillID } from "../../../logic/tree/fill-id"; import { prepSection } from "./prep-section"; +import { IItem } from "../../../../../utils/types/item"; export const EdAddText = () => { const p = useGlobal(EDGlobal, "EDITOR"); @@ -37,7 +38,7 @@ export const EdAddText = () => { }, } as IText; - let mitem = meta.mitem; + let mitem = meta.mitem as MContent; if (mitem) { if ( meta.item.type === "text" || @@ -51,11 +52,40 @@ export const EdAddText = () => { if (!parent) { alert("Failed to add text!"); } else { - mitem = parent.mitem; + mitem = parent.mitem as MContent; } } if (mitem) { + if (mitem.get("type") === "section") { + const json = { + id: createId(), + name: `New Item`, + type: "item", + dim: { w: "full", h: "full" }, + childs: [], + adv: { + css: "", + }, + } as IItem; + + if (mitem) { + const childs = mitem.get("childs"); + if (childs) { + const map = new Y.Map() as MContent; + syncronize(map as any, fillID(json)); + const childs = mitem.get("childs"); + if (childs) { + childs.push([map]); + } + + active.item_id = map.get("id") || ""; + mitem = map; + p.render(); + } + } + } + const childs = mitem.get("childs"); if (childs) { const map = new Y.Map() as MContent; diff --git a/app/web/src/nova/ed/panel/tree/body.tsx b/app/web/src/nova/ed/panel/tree/body.tsx index e9e154b7..4aeb909d 100644 --- a/app/web/src/nova/ed/panel/tree/body.tsx +++ b/app/web/src/nova/ed/panel/tree/body.tsx @@ -22,7 +22,6 @@ export const EdTreeBody = () => { expandTreeHook(p, local); - if (active.comp_id && local.comp_id !== active.comp_id) { local.comp_id = active.comp_id; const ref = p.comp.list[active.comp_id]; @@ -42,7 +41,6 @@ export const EdTreeBody = () => { } } - if (tree.length === 0) return (