wip fix
This commit is contained in:
parent
647f8831ab
commit
f32bdf7d62
|
|
@ -39,6 +39,7 @@ export const EdBase = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col flex-1">
|
<div className="flex flex-col flex-1">
|
||||||
<div className="flex justify-between"></div>
|
<div className="flex justify-between"></div>
|
||||||
|
|
|
||||||
|
|
@ -1,73 +1,107 @@
|
||||||
|
import { TypedMap } from "yjs-types";
|
||||||
import { IItem, MItem } from "../../../../utils/types/item";
|
import { IItem, MItem } from "../../../../utils/types/item";
|
||||||
|
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
import { IMeta, PG } from "../ed-global";
|
import { IMeta, PG } from "../ed-global";
|
||||||
|
|
||||||
export const assignMitem = (arg: {
|
export const assignMitem = (arg: {
|
||||||
p: PG;
|
p: PG;
|
||||||
m: IMeta;
|
m: IMeta;
|
||||||
item: IItem;
|
root: IItem;
|
||||||
mitem: MItem;
|
mitem: MItem;
|
||||||
meta: Record<string, IMeta>;
|
meta: Record<string, IMeta>;
|
||||||
|
new_prop_jsx: (
|
||||||
|
meta: IMeta,
|
||||||
|
mprop: TypedMap<Record<string, FMCompDef>>,
|
||||||
|
prop_name: string,
|
||||||
|
prop_val: FNCompDef
|
||||||
|
) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { p, m, item, mitem, meta } = arg;
|
const { p, m, root, mitem, meta } = arg;
|
||||||
|
|
||||||
if (m.parent) {
|
|
||||||
if (m.parent.id === "root") {
|
|
||||||
if (m.item.id === item.id) {
|
|
||||||
m.mitem = mitem;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const parent = meta[m.parent.id];
|
|
||||||
if (parent.mitem) {
|
|
||||||
parent.mitem.get("childs")?.forEach((child) => {
|
|
||||||
if (child.get("id") === m.item.id) {
|
|
||||||
m.mitem = child;
|
|
||||||
|
|
||||||
if (m.item.component?.props) {
|
|
||||||
for (const [prop_name, v] of Object.entries(
|
|
||||||
m.item.component.props
|
|
||||||
)) {
|
|
||||||
const mprop = m.mitem
|
|
||||||
?.get("component")
|
|
||||||
?.get("props")
|
|
||||||
?.get(prop_name);
|
|
||||||
if (v.content && mprop) {
|
|
||||||
const pmeta = meta[v.content.id];
|
|
||||||
if (pmeta) {
|
|
||||||
pmeta.mitem = mprop.get("content");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m.jsx_prop && m.parent?.instance_id) {
|
if (m.jsx_prop && m.parent?.instance_id) {
|
||||||
const parent = meta[m.parent?.instance_id];
|
const instance_meta = meta[m.parent?.instance_id];
|
||||||
if (parent) {
|
if (instance_meta) {
|
||||||
const prop = parent.item.component?.props[m.jsx_prop.name];
|
if (m.jsx_prop.is_root) {
|
||||||
if (prop) {
|
const prop = instance_meta.item.component?.props[m.jsx_prop.name];
|
||||||
prop.content = m.item;
|
if (prop) {
|
||||||
}
|
prop.content = m.item;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m.parent?.instance_id && m.parent?.instance_id === m.parent?.id) {
|
|
||||||
const parent = meta[m.parent?.instance_id];
|
|
||||||
if (parent.item.component?.id) {
|
|
||||||
const lcomp = p.comp.list[parent.item.component.id];
|
|
||||||
if (lcomp) {
|
|
||||||
const mcomp = lcomp.doc.getMap("map").get("root");
|
|
||||||
if (mcomp) {
|
|
||||||
mcomp.get("childs")?.forEach((e) => {
|
|
||||||
if (e.get("id") === m.item.originalId) {
|
|
||||||
m.mitem = e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m.parent) {
|
||||||
|
if (m.parent.id === "root") {
|
||||||
|
if (m.item.id === root.id) {
|
||||||
|
m.mitem = mitem;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const parent = meta[m.parent.id];
|
||||||
|
|
||||||
|
if (parent.mitem) {
|
||||||
|
if (m.jsx_prop?.is_root === true) {
|
||||||
|
const mprops = parent.mitem.get("component")?.get("props");
|
||||||
|
if (mprops) {
|
||||||
|
const mprop = mprops.get(m.jsx_prop.name);
|
||||||
|
if (mprop) {
|
||||||
|
const mcontent = mprop.get("content");
|
||||||
|
if (mcontent) {
|
||||||
|
m.mitem = mcontent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parent.mitem.get("childs")?.forEach((child) => {
|
||||||
|
if (child.get("id") === m.item.id) {
|
||||||
|
m.mitem = child;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (m.item.component?.props) {
|
||||||
|
// for (const [prop_name, v] of Object.entries(
|
||||||
|
// m.item.component.props
|
||||||
|
// )) {
|
||||||
|
// const mprop = m.mitem
|
||||||
|
// ?.get("component")
|
||||||
|
// ?.get("props")
|
||||||
|
// ?.get(prop_name);
|
||||||
|
|
||||||
|
// if (v.content) {
|
||||||
|
// if (mprop) {
|
||||||
|
// const pmeta = meta[v.content.id];
|
||||||
|
// if (pmeta) {
|
||||||
|
// pmeta.mitem = mprop.get("content");
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// const mprops = m.mitem?.get("component")?.get("props");
|
||||||
|
// if (mprops) {
|
||||||
|
// arg.new_prop_jsx(m, mprops, prop_name, v);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// if (m.parent?.instance_id && m.parent?.instance_id === m.parent?.id) {
|
||||||
|
// const parent = meta[m.parent?.instance_id];
|
||||||
|
// if (parent.item.component?.id) {
|
||||||
|
// const lcomp = p.comp.list[parent.item.component.id];
|
||||||
|
// if (lcomp) {
|
||||||
|
// const mcomp = lcomp.doc.getMap("map").get("root");
|
||||||
|
// if (mcomp) {
|
||||||
|
// mcomp.get("childs")?.forEach((e) => {
|
||||||
|
// if (e.get("id") === m.item.originalId) {
|
||||||
|
// m.mitem = e;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
import { IItem, MItem } from "../../../../utils/types/item";
|
import { IItem, MItem } from "../../../../utils/types/item";
|
||||||
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
import { genMeta } from "../../../vi/meta/meta";
|
import { genMeta } from "../../../vi/meta/meta";
|
||||||
|
|
@ -40,11 +41,28 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
on: {
|
on: {
|
||||||
async visit(m) {
|
async visit(m) {
|
||||||
if (!is_layout) {
|
if (!is_layout) {
|
||||||
if (m.parent?.instance_id !== m.parent?.id) {
|
if (m.parent?.instance_id !== m.parent?.id || m.jsx_prop) {
|
||||||
pushTreeNode(p, m, meta, p.page.tree);
|
pushTreeNode(p, m, meta, p.page.tree);
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
|
|
||||||
assignMitem({ p, m, item, mitem, meta });
|
assignMitem({
|
||||||
|
p,
|
||||||
|
m,
|
||||||
|
root: item,
|
||||||
|
mitem,
|
||||||
|
meta,
|
||||||
|
new_prop_jsx(meta, mprops, prop_name, prop_val) {
|
||||||
|
transact.list.push(() => {
|
||||||
|
const map = new Y.Map();
|
||||||
|
|
||||||
|
if (prop_val.content) prop_val.content.id = createId();
|
||||||
|
|
||||||
|
syncronize(map, prop_val);
|
||||||
|
mprops.set(prop_name, map as any);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -96,31 +114,4 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
|
|
||||||
const transact = {
|
const transact = {
|
||||||
list: [] as (() => void)[],
|
list: [] as (() => void)[],
|
||||||
propContentFromItem: (
|
|
||||||
meta: IMeta,
|
|
||||||
mitem: MItem,
|
|
||||||
name: string,
|
|
||||||
prop: FNCompDef
|
|
||||||
) => {
|
|
||||||
transact.list.push(() => {
|
|
||||||
const mprops = mitem?.get("component")?.get("props");
|
|
||||||
|
|
||||||
if (mprops) {
|
|
||||||
const map = new Y.Map();
|
|
||||||
syncronize(map, prop);
|
|
||||||
mprops.set(name, map as any);
|
|
||||||
console.log(mprops.get(name));
|
|
||||||
const mcontent = mprops.get(name)?.get("content");
|
|
||||||
console.log(mcontent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
jsxContentFromItem(meta: IMeta, content: IItem, mprop: FMCompDef) {
|
|
||||||
transact.list.push(() => {
|
|
||||||
const map = new Y.Map();
|
|
||||||
syncronize(map, content);
|
|
||||||
mprop.set("content", map as any);
|
|
||||||
meta.mitem = mprop.get("content");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export const pushTreeNode = (
|
||||||
data: meta,
|
data: meta,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (meta.jsx_prop) {
|
if (meta.jsx_prop?.is_root) {
|
||||||
tree.push({
|
tree.push({
|
||||||
id: meta.item.id,
|
id: meta.item.id,
|
||||||
parent: meta.parent?.instance_id || "root",
|
parent: meta.parent?.instance_id || "root",
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
import { fillID } from "../../../logic/tree/fill-id";
|
import { fillID } from "../../../logic/tree/fill-id";
|
||||||
import { TopBtn } from "../top-btn";
|
import { TopBtn } from "../top-btn";
|
||||||
import { prepSection } from "./prep-section";
|
import { prepSection } from "./prep-section";
|
||||||
|
import { treeRebuild } from "../../../logic/tree/build";
|
||||||
|
|
||||||
export const EdAddItem = () => {
|
export const EdAddItem = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -68,6 +69,8 @@ export const EdAddItem = () => {
|
||||||
|
|
||||||
active.item_id = map.get("id") || "";
|
active.item_id = map.get("id") || "";
|
||||||
p.render();
|
p.render();
|
||||||
|
|
||||||
|
treeRebuild(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { ISection } from "../../../../../utils/types/section";
|
||||||
import { EDGlobal, active } from "../../../logic/ed-global";
|
import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
import { fillID } from "../../../logic/tree/fill-id";
|
import { fillID } from "../../../logic/tree/fill-id";
|
||||||
import { TopBtn } from "../top-btn";
|
import { TopBtn } from "../top-btn";
|
||||||
|
import { treeRebuild } from "../../../logic/tree/build";
|
||||||
|
|
||||||
export const EdAddSection = () => {
|
export const EdAddSection = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -34,6 +35,7 @@ export const EdAddSection = () => {
|
||||||
childs.push([map]);
|
childs.push([map]);
|
||||||
active.item_id = json.id;
|
active.item_id = json.id;
|
||||||
p.render();
|
p.render();
|
||||||
|
treeRebuild(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
import { fillID } from "../../../logic/tree/fill-id";
|
import { fillID } from "../../../logic/tree/fill-id";
|
||||||
import { TopBtn } from "../top-btn";
|
import { TopBtn } from "../top-btn";
|
||||||
import { prepSection } from "./prep-section";
|
import { prepSection } from "./prep-section";
|
||||||
|
import { treeRebuild } from "../../../logic/tree/build";
|
||||||
|
|
||||||
export const EdAddText = () => {
|
export const EdAddText = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -27,85 +28,90 @@ export const EdAddText = () => {
|
||||||
}
|
}
|
||||||
if (!meta) return null;
|
if (!meta) return null;
|
||||||
|
|
||||||
const json = {
|
meta.mitem?.doc?.transact(() => {
|
||||||
id: createId(),
|
if (!meta) return null;
|
||||||
name: `New Text`,
|
|
||||||
type: "text",
|
|
||||||
dim: { w: "full", h: "full" },
|
|
||||||
layout: { align: "center", dir: "col", gap: 0 },
|
|
||||||
text: "",
|
|
||||||
html: "",
|
|
||||||
adv: {
|
|
||||||
css: "",
|
|
||||||
},
|
|
||||||
} as IText;
|
|
||||||
|
|
||||||
let mitem = meta.mitem as MContent;
|
const json = {
|
||||||
if (mitem) {
|
id: createId(),
|
||||||
const item = meta.item as IContent;
|
name: `New Text`,
|
||||||
|
type: "text",
|
||||||
if (
|
dim: { w: "full", h: "full" },
|
||||||
item.type === "text" ||
|
layout: { align: "center", dir: "col", gap: 0 },
|
||||||
(item.type === "item" && item.component?.id)
|
text: "",
|
||||||
) {
|
html: "",
|
||||||
const parent_id = meta.parent?.id || "root";
|
adv: {
|
||||||
const parent = getMetaById(
|
css: "",
|
||||||
p,
|
},
|
||||||
parent_id === "root" ? item.id : parent_id
|
} as IText;
|
||||||
);
|
|
||||||
if (!parent) {
|
|
||||||
alert("Failed to add text!");
|
|
||||||
} else {
|
|
||||||
mitem = parent.mitem as MContent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let mitem = meta.mitem as MContent;
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
if (mitem.get("type") === "section") {
|
const item = meta.item as IContent;
|
||||||
const json = {
|
|
||||||
id: createId(),
|
|
||||||
name: `New Item`,
|
|
||||||
type: "item",
|
|
||||||
dim: { w: "full", h: "full" },
|
|
||||||
childs: [],
|
|
||||||
adv: {
|
|
||||||
css: "",
|
|
||||||
},
|
|
||||||
} as IItem;
|
|
||||||
|
|
||||||
if (mitem) {
|
if (
|
||||||
const childs = mitem.get("childs");
|
item.type === "text" ||
|
||||||
if (childs) {
|
(item.type === "item" && item.component?.id)
|
||||||
const map = new Y.Map() as MContent;
|
) {
|
||||||
syncronize(map as any, fillID(json));
|
const parent_id = meta.parent?.id || "root";
|
||||||
|
const parent = getMetaById(
|
||||||
|
p,
|
||||||
|
parent_id === "root" ? item.id : parent_id
|
||||||
|
);
|
||||||
|
if (!parent) {
|
||||||
|
alert("Failed to add text!");
|
||||||
|
} else {
|
||||||
|
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");
|
const childs = mitem.get("childs");
|
||||||
if (childs) {
|
if (childs) {
|
||||||
childs.push([map]);
|
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") || "";
|
active.item_id = map.get("id") || "";
|
||||||
mitem = map;
|
mitem = map;
|
||||||
p.render();
|
p.render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
const childs = mitem.get("childs");
|
||||||
if (childs) {
|
if (childs) {
|
||||||
childs.push([map]);
|
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") || "";
|
||||||
|
|
||||||
|
p.render();
|
||||||
|
focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
active.item_id = map.get("id") || "";
|
|
||||||
|
|
||||||
p.render();
|
|
||||||
focus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
treeRebuild(p);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,11 @@ const addComponent = (mitem: MItem | MSection, comp: IItem) => {
|
||||||
const map = new Y.Map() as MContent;
|
const map = new Y.Map() as MContent;
|
||||||
if (map) {
|
if (map) {
|
||||||
comp.originalId = comp.id;
|
comp.originalId = comp.id;
|
||||||
|
|
||||||
|
if (comp.component && !comp.component?.instances) {
|
||||||
|
comp.component.instances = {};
|
||||||
|
}
|
||||||
|
|
||||||
syncronize(map as any, fillID(comp));
|
syncronize(map as any, fillID(comp));
|
||||||
const childs = mitem.get("childs");
|
const childs = mitem.get("childs");
|
||||||
if (childs) {
|
if (childs) {
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ export const mainPerItemVisit = (
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
parts.props.onPointerOver = (e) => {
|
parts.props.onPointerEnter = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
active.hover.id = meta.item.id;
|
active.hover.id = meta.item.id;
|
||||||
active.hover.renderMain();
|
active.hover.renderMain();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { IContent } from "../../../../../../../utils/types/general";
|
import { IContent } from "../../../../../../../utils/types/general";
|
||||||
|
import { IItem, MItem } from "../../../../../../../utils/types/item";
|
||||||
import { getMetaById } from "../../../../../logic/active/get-meta";
|
import { getMetaById } from "../../../../../logic/active/get-meta";
|
||||||
import { PG } from "../../../../../logic/ed-global";
|
import { PG } from "../../../../../logic/ed-global";
|
||||||
import { treeRebuild } from "../../../../../logic/tree/build";
|
import { treeRebuild } from "../../../../../logic/tree/build";
|
||||||
|
|
@ -10,10 +11,9 @@ export const edActionDelete = async (p: PG, item: IContent) => {
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
mitem.parent.forEach((e, k) => {
|
mitem.parent.forEach((e, k) => {
|
||||||
if (e == mitem) {
|
if (e == mitem) {
|
||||||
mitem.parent.delete(k);
|
deleteByParent(p, mitem, k);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await treeRebuild(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -25,10 +25,18 @@ export const edActionDeleteById = async (p: PG, id: string) => {
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
mitem.parent.forEach((e, k) => {
|
mitem.parent.forEach((e, k) => {
|
||||||
if (e == mitem) {
|
if (e == mitem) {
|
||||||
mitem.parent.delete(k);
|
deleteByParent(p, mitem, k);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await treeRebuild(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteByParent = (p: PG, mitem: MItem, index: number) => {
|
||||||
|
const mchild = mitem.parent.get(index);
|
||||||
|
const child = mchild?.toJSON() as IItem;
|
||||||
|
|
||||||
|
console.log(child);
|
||||||
|
mitem.parent.delete(index);
|
||||||
|
treeRebuild(p);
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export const edActionNewComp = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newcomp && newcomp.snapshot) {
|
if (newcomp && newcomp.snapshot) {
|
||||||
await loadCompSnapshot(p, newcomp.id, newcomp.snapshot, newcomp.meta);
|
await loadCompSnapshot(p, newcomp.id, newcomp.snapshot);
|
||||||
await treeRebuild(p);
|
await treeRebuild(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export const EdTreeName = ({
|
||||||
const item = node.data?.item;
|
const item = node.data?.item;
|
||||||
|
|
||||||
if (!item) return <></>;
|
if (!item) return <></>;
|
||||||
const is_jsx_prop = !!node.data?.jsx_prop;
|
const is_jsx_prop = !!node.data?.jsx_prop?.is_root;
|
||||||
|
|
||||||
const isRenaming = p.ui.tree.rename_id === item.id;
|
const isRenaming = p.ui.tree.rename_id === item.id;
|
||||||
return (
|
return (
|
||||||
|
|
@ -98,7 +98,9 @@ export const EdTreeName = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Name name={node.text} is_jsx_prop={is_jsx_prop} />
|
<Name name={node.text} is_jsx_prop={is_jsx_prop} />
|
||||||
{/* <div className={"text-[9px] text-gray-500 -mt-1"}>{node.id} - {item.originalId}</div> */}
|
<div className={"text-[9px] text-gray-500 -mt-1"}>
|
||||||
|
{node.id} - {item.originalId}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { IContent, MContent } from "../../../../../utils/types/general";
|
||||||
import { getMetaById } from "../../../logic/active/get-meta";
|
import { getMetaById } from "../../../logic/active/get-meta";
|
||||||
import { IMeta, PG, active } from "../../../logic/ed-global";
|
import { IMeta, PG, active } from "../../../logic/ed-global";
|
||||||
import { fillID } from "../../../logic/tree/fill-id";
|
import { fillID } from "../../../logic/tree/fill-id";
|
||||||
|
import { treeRebuild } from "../../../logic/tree/build";
|
||||||
|
|
||||||
export const nodeOnDrop: (
|
export const nodeOnDrop: (
|
||||||
p: PG,
|
p: PG,
|
||||||
|
|
@ -51,6 +52,8 @@ export const nodeOnDrop: (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
treeRebuild(p);
|
||||||
|
p.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
const local = useLocal({
|
const local = useLocal({
|
||||||
rightClick: null as null | React.MouseEvent<HTMLDivElement, MouseEvent>,
|
rightClick: null as null | React.MouseEvent<HTMLDivElement, MouseEvent>,
|
||||||
});
|
});
|
||||||
if (!node || !node.data) return <></>;
|
if (!node || !node.data) {
|
||||||
|
console.log("hello", node, prm);
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
const item = node.data?.item;
|
const item = node.data?.item;
|
||||||
const isComponent = item.type === "item" && item.component?.id;
|
const isComponent = item.type === "item" && item.component?.id;
|
||||||
|
|
||||||
|
|
@ -36,6 +39,7 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
const cprop = comp.component?.props[prop_name];
|
const cprop = comp.component?.props[prop_name];
|
||||||
if (cprop && node.data.parent?.instance_id) {
|
if (cprop && node.data.parent?.instance_id) {
|
||||||
const meta = getMetaById(p, node.data.parent.instance_id);
|
const meta = getMetaById(p, node.data.parent.instance_id);
|
||||||
|
|
||||||
if (meta && prop_name) {
|
if (meta && prop_name) {
|
||||||
const props = meta.item.script?.props;
|
const props = meta.item.script?.props;
|
||||||
if (props) {
|
if (props) {
|
||||||
|
|
@ -46,6 +50,11 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
) {
|
) {
|
||||||
hide = false;
|
hide = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const prop = meta.item.component?.props[prop_name];
|
||||||
|
if (prop && (prop.visible || !prop.hasOwnProperty("visible"))) {
|
||||||
|
hide = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,10 +127,10 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onMouseOver={() => {
|
onMouseEnter={() => {
|
||||||
active.hover.id = item.id;
|
active.hover.id = item.id;
|
||||||
active.hover.renderTree();
|
|
||||||
active.hover.renderMain();
|
active.hover.renderMain();
|
||||||
|
active.hover.renderTree();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{active.hover.id === item.id && (
|
{active.hover.id === item.id && (
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,32 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p.on?.visit) {
|
||||||
|
p.on.visit(meta, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const child of Object.values(item.childs)) {
|
||||||
|
if (child.name.startsWith("jsx:")) continue;
|
||||||
|
|
||||||
|
genMeta(
|
||||||
|
{ ...p, mode: "comp" },
|
||||||
|
{
|
||||||
|
item: child,
|
||||||
|
is_root: false,
|
||||||
|
parent: {
|
||||||
|
item,
|
||||||
|
instance_id: item.id,
|
||||||
|
root_instances: instances,
|
||||||
|
comp: item_comp,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
walkProp({
|
walkProp({
|
||||||
item,
|
item,
|
||||||
item_comp: item_comp,
|
item_comp: item_comp,
|
||||||
|
instance: instances ? instances[item.id] : {},
|
||||||
each(name, prop) {
|
each(name, prop) {
|
||||||
const comp_id = item.component?.id;
|
const comp_id = item.component?.id;
|
||||||
|
|
||||||
|
|
@ -84,28 +107,6 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (p.on?.visit) {
|
|
||||||
p.on.visit(meta, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const child of Object.values(item.childs)) {
|
|
||||||
if (child.name.startsWith("jsx:")) continue;
|
|
||||||
|
|
||||||
genMeta(
|
|
||||||
{ ...p, mode: "comp" },
|
|
||||||
{
|
|
||||||
item: child,
|
|
||||||
is_root: false,
|
|
||||||
parent: {
|
|
||||||
item,
|
|
||||||
instance_id: item.id,
|
|
||||||
root_instances: instances,
|
|
||||||
comp: item_comp,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { createId } from "@paralleldrive/cuid2";
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
import { deepClone } from "web-utils";
|
import { deepClone } from "web-utils";
|
||||||
import { IItem } from "../../../../utils/types/item";
|
import { IItem } from "../../../../utils/types/item";
|
||||||
import { FNComponent } from "../../../../utils/types/meta-fn";
|
|
||||||
|
|
||||||
export const instantiate = (arg: {
|
export const instantiate = (arg: {
|
||||||
item: IItem;
|
item: IItem;
|
||||||
|
|
@ -22,11 +21,6 @@ export const instantiate = (arg: {
|
||||||
if (item.component.props[k]) {
|
if (item.component.props[k]) {
|
||||||
newitem.component.props[k] = item.component.props[k];
|
newitem.component.props[k] = item.component.props[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = newitem.component.props[k].content;
|
|
||||||
if (content) {
|
|
||||||
walkChild(content, ids);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,9 +34,7 @@ export const instantiate = (arg: {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const walkChild = (item: IItem, ids: Record<string, string>) => {
|
export const walkChild = (item: IItem, ids: Record<string, string>) => {
|
||||||
if (!item.originalId) {
|
item.originalId = item.id;
|
||||||
item.originalId = item.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ids[item.id]) {
|
if (!ids[item.id]) {
|
||||||
ids[item.id] = createId();
|
ids[item.id] = createId();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
import { deepClone } from "web-utils";
|
import { deepClone } from "web-utils";
|
||||||
import { IItem } from "../../../../utils/types/item";
|
import { IItem } from "../../../../utils/types/item";
|
||||||
import { FNCompDef } from "../../../../utils/types/meta-fn";
|
import { FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
|
|
@ -5,6 +6,7 @@ import { FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
export const walkProp = (arg: {
|
export const walkProp = (arg: {
|
||||||
item: IItem;
|
item: IItem;
|
||||||
item_comp: IItem;
|
item_comp: IItem;
|
||||||
|
instance: Record<string, string>;
|
||||||
each: (name: string, prop: FNCompDef) => void;
|
each: (name: string, prop: FNCompDef) => void;
|
||||||
}) => {
|
}) => {
|
||||||
for (const [k, v] of Object.entries(arg.item_comp.component?.props || {})) {
|
for (const [k, v] of Object.entries(arg.item_comp.component?.props || {})) {
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
|
|
||||||
if (item.childs) {
|
if (item.childs) {
|
||||||
for (const [_, v] of Object.entries(item.childs)) {
|
for (const [_, v] of Object.entries(item.childs)) {
|
||||||
genMeta(p, {
|
const carg: GenMetaArg = {
|
||||||
item: v,
|
item: v,
|
||||||
is_root: false,
|
is_root: false,
|
||||||
parent: {
|
parent: {
|
||||||
|
|
@ -47,7 +47,14 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
comp: arg.parent?.comp,
|
comp: arg.parent?.comp,
|
||||||
root_instances: arg.parent?.root_instances,
|
root_instances: arg.parent?.root_instances,
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
if (arg.jsx_prop) {
|
||||||
|
carg.jsx_prop = {
|
||||||
|
...arg.jsx_prop,
|
||||||
|
is_root: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
genMeta(p, carg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export const ViRender: FC<{
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
passprop?: any;
|
passprop?: any;
|
||||||
}> = ({ meta, children, passprop }) => {
|
}> = ({ meta, children, passprop }) => {
|
||||||
|
|
||||||
if (!meta) return null;
|
if (!meta) return null;
|
||||||
|
|
||||||
if (meta.item.hidden) return null;
|
if (meta.item.hidden) return null;
|
||||||
|
|
|
||||||
|
|
@ -328,16 +328,16 @@ export const walk = async (
|
||||||
let mp = mprops.get(name);
|
let mp = mprops.get(name);
|
||||||
if (mp) {
|
if (mp) {
|
||||||
const mprop = mp?.toJSON() as FNCompDef;
|
const mprop = mp?.toJSON() as FNCompDef;
|
||||||
const jsx_prop = iprops.get(name);
|
const jprop = iprops.get(name);
|
||||||
|
|
||||||
if (jsx_prop) {
|
if (jprop) {
|
||||||
if (mprop.meta?.type === "content-element") {
|
if (mprop.meta?.type === "content-element") {
|
||||||
let mcontent = jsx_prop.get("content");
|
let mcontent = jprop.get("content");
|
||||||
|
|
||||||
let isNew = false;
|
let isNew = false;
|
||||||
if (!mcontent) {
|
if (!mcontent) {
|
||||||
isNew = true;
|
isNew = true;
|
||||||
jsx_prop.set(
|
jprop.set(
|
||||||
"content",
|
"content",
|
||||||
newMap({
|
newMap({
|
||||||
id: createId(),
|
id: createId(),
|
||||||
|
|
@ -350,7 +350,7 @@ export const walk = async (
|
||||||
},
|
},
|
||||||
}) as any
|
}) as any
|
||||||
);
|
);
|
||||||
mcontent = jsx_prop.get("content");
|
mcontent = jprop.get("content");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!mcontent) {
|
if (!!mcontent) {
|
||||||
|
|
@ -372,7 +372,7 @@ export const walk = async (
|
||||||
if (defaultJSX && mcontent) {
|
if (defaultJSX && mcontent) {
|
||||||
syncronize(mcontent as any, defaultJSX);
|
syncronize(mcontent as any, defaultJSX);
|
||||||
}
|
}
|
||||||
mcontent = jsx_prop.get("content");
|
mcontent = jprop.get("content");
|
||||||
}
|
}
|
||||||
if (mcontent) {
|
if (mcontent) {
|
||||||
await walk(p, mode, {
|
await walk(p, mode, {
|
||||||
|
|
|
||||||
|
|
@ -132,11 +132,11 @@ const walk = async (
|
||||||
|
|
||||||
if (cprops && iprops) {
|
if (cprops && iprops) {
|
||||||
for (const [name, mprop] of Object.entries(cprops)) {
|
for (const [name, mprop] of Object.entries(cprops)) {
|
||||||
const jsx_prop = iprops[name];
|
const jprop = iprops[name];
|
||||||
|
|
||||||
if (jsx_prop) {
|
if (jprop) {
|
||||||
if (mprop.meta?.type === "content-element") {
|
if (mprop.meta?.type === "content-element") {
|
||||||
let icontent = jsx_prop.content;
|
let icontent = jprop.content;
|
||||||
|
|
||||||
if (icontent)
|
if (icontent)
|
||||||
await walk(p, {
|
await walk(p, {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue