This commit is contained in:
Rizky 2024-07-27 13:58:59 +07:00
parent 248dc7d9d0
commit 0532bf3f48
4 changed files with 50 additions and 6 deletions

View File

@ -30,7 +30,7 @@ export const EdMid: FC<{}> = () => {
<div className="border-r border-r-slate-100 text-slate-400 text-[9px] flex items-center px-1 mr-1">
ADD
</div>
{!active.comp_id && <EdAddSection />}
<EdAddSection />
<EdAddItem />
<EdAddText />
<EdCompPicker />
@ -70,7 +70,7 @@ export const EdMid: FC<{}> = () => {
</TopBtn>
</a>
</div>
</div>
</div>
</div>
);
};
};

View File

@ -1,8 +1,42 @@
import { IMeta, PG, active } from "../ed-global";
export const activateMeta = (p: PG, meta: IMeta) => {
export const activateMeta = (p: PG, _meta: IMeta) => {
let meta = _meta;
let parent_comp_id = meta.parent?.comp_id;
if (!active.comp_id && meta.parent?.comp_id) {
let parent = meta.parent;
let is_jsx = false;
let i = 0;
while (parent) {
const meta_parent = p.page.meta[parent.id];
if (meta_parent && meta_parent.parent) {
if (meta_parent.jsx_prop) {
is_jsx = true;
}
parent = meta_parent.parent;
} else {
break;
}
if (i > 10000) {
console.warn("warning cyclic item tree possibility detected.");
break;
}
i++;
}
if (!is_jsx) {
if (meta.parent.instance_id) {
meta = p.page.meta[meta.parent.instance_id];
} else {
return;
}
}
}
if (
active.comp_id &&
meta.item.component?.id === active.comp_id &&

View File

@ -13,7 +13,12 @@ export const EdAddSection = () => {
return (
<TopBtn
style="slim"
onClick={() => {
className={cx(active.comp_id && "opacity-20")}
onClick={async () => {
if (active.comp_id) {
alert("Cannot add section while editing component");
return;
}
const json = {
id: createId(),
name: `New Section`,

View File

@ -16,7 +16,12 @@ export const EdAddText = () => {
return (
<TopBtn
style="slim"
className={cx(active.comp_id && "opacity-20")}
onClick={async () => {
if (active.comp_id) {
alert("Cannot add text while editing component");
return;
}
let meta = getActiveMeta(p);
if (!meta) {
@ -76,7 +81,7 @@ export const EdAddText = () => {
}
if (mitem) {
if (mitem.get("type") === "section") {
if ((mitem as any).get("type") === "section") {
const json = {
id: createId(),
name: `new_item`,