This commit is contained in:
Rizky 2023-11-21 22:53:42 +07:00
parent e4b98b3da2
commit 144ba32027
7 changed files with 60 additions and 45 deletions

View File

@ -11,6 +11,10 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
p.page.building = true;
p.render();
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
const sections = root.get("childs");
if (sections) {
const loaded = new Set<string>();
@ -34,7 +38,8 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
walkLoad(p.comp, e, loaded, (id) => loadComponent(p, id))
)
);
p.site.layout.childs.map((e) =>
p.site.layout.childs.map((e) => {
p.page.entry.push(e.id);
walkMap(
{ meta: p.page.meta, comps: p.comp.map },
{
@ -48,23 +53,30 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
}
},
}
)
);
);
});
// if root_id is root, it means content is not found.
// if content is not found, do not use layout.
if (root_id === "root") {
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
}
}
doc.transact(async () => {
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
const sections = root.get("childs");
if (sections) {
sections.map((e) => {
p.page.entry.push(e.get("id"));
if (root_id === "root") {
p.page.entry.push(e.get("id"));
}
syncWalkMap(p, {
isLayout: false,
mitem: e,
parent_item: { id: root_id },
tree_root_id: root_id,
portal,
});
});

View File

@ -3,6 +3,7 @@ import { IContent } from "../../../../utils/types/general";
import { IItem } from "../../../../utils/types/item";
import { FNComponent } from "../../../../utils/types/meta-fn";
import { EdMeta, PG } from "../ed-global";
import { deepClone } from "web-utils";
export const walkLoad = async (
p: { map: PG["comp"]["map"] },
@ -85,12 +86,12 @@ export const walkMap = (
}
}
let item = mapItem(arg.item);
let item = arg.item;
if (override_id) {
item.id = override_id;
}
const item_comp = item.component;
const item_comp = item.type === "item" ? item.component : null;
if (item_comp && item_comp.id && parent_item.id !== "root") {
const comp_ref = p.comps[item_comp.id];
@ -108,7 +109,7 @@ export const walkMap = (
item_comp.ref_ids = ref_ids;
}
const original_id = item.id;
item = mapItem(mcomp);
item = deepClone(mcomp);
item.id = original_id;
const meta: EdMeta = {
@ -135,6 +136,7 @@ export const walkMap = (
parent_item: { id: item.id },
portal: arg.portal,
parent_comp: { id: item.id, comp_id: item_comp.id },
each: arg.each,
});
}
}
@ -147,6 +149,7 @@ export const walkMap = (
parent_item: { id: item.id },
portal: arg.portal,
parent_comp: { id: item.id, comp_id: item_comp.id },
each: arg.each,
});
}
}
@ -169,25 +172,18 @@ export const walkMap = (
if (arg.each) arg.each(meta);
p.meta[item.id] = meta;
for (const c of item.childs) {
walkMap(p, {
isLayout: arg.isLayout,
item: c,
parent_item: { id: item.id },
portal: arg.portal,
parent_comp,
});
if (item.type !== "text") {
for (const c of item.childs) {
if (c) {
walkMap(p, {
isLayout: arg.isLayout,
item: c,
parent_item: { id: item.id },
portal: arg.portal,
parent_comp,
each: arg.each,
});
}
}
}
};
const mapItem = (item: IContent) => {
return {
...item,
childs:
item.type !== "text"
? (item.childs.map((e) => {
id: e.id;
}) as any)
: undefined,
} as IItem;
};

View File

@ -69,7 +69,7 @@ export const syncWalkMap = (
parent_item: EdMeta["parent_item"];
parent_mcomp?: EdMeta["parent_mcomp"];
skip_add_tree?: boolean;
each?: (meta: EdMeta) => void;
tree_root_id: string;
}
) => {
const { mitem, parent_item, parent_mcomp } = arg;
@ -113,7 +113,7 @@ export const syncWalkMap = (
if (!skip_tree) {
p.page.tree.push({
id: item.id,
parent: parent_item.id,
parent: arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name,
});
}
@ -154,13 +154,13 @@ export const syncWalkMap = (
if (item.name.startsWith("⮕")) {
arg.portal.out[item.name] = meta;
}
if (arg.each) arg.each(meta);
p.page.meta[item.id] = meta;
if (!skip_tree) {
p.page.tree.push({
id: item.id,
parent: parent_item.id,
parent:
arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name,
data: meta,
});
@ -184,6 +184,7 @@ export const syncWalkMap = (
if (mcontent) {
syncWalkMap(p, {
isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: mcontent,
parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: { mitem: mitem as MItem, mcomp },
@ -201,6 +202,7 @@ export const syncWalkMap = (
for (const e of childs) {
syncWalkMap(p, {
isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: e,
parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: { mitem: mitem as MItem, mcomp },
@ -230,13 +232,12 @@ export const syncWalkMap = (
if (item.name.startsWith("⮕")) {
arg.portal.out[item.name] = meta;
}
if (arg.each) arg.each(meta);
p.page.meta[item.id] = meta;
if (!skip_tree) {
p.page.tree.push({
id: item.id,
parent: parent_item.id,
parent: arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name,
data: meta,
});
@ -246,6 +247,7 @@ export const syncWalkMap = (
for (const e of childs) {
syncWalkMap(p, {
isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: e,
parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: arg.parent_mcomp,

View File

@ -2,7 +2,7 @@ import { useGlobal } from "web-utils";
import { Loading } from "../../../../utils/ui/loading";
import { View } from "../../../view/view";
import { EDGlobal, active } from "../../logic/ed-global";
import { loadComponent } from "../../logic/tree/build";
import { loadComponent } from "../../logic/tree/sync-walk";
export const EdMain = () => {
const p = useGlobal(EDGlobal, "EDITOR");
@ -26,7 +26,7 @@ export const EdMain = () => {
meta: p.page.meta,
entry: p.page.entry,
}}
site_id={p.site.id}
site_id={p.site.id}
page_id={p.page.cur.id}
bind={({ render }) => {
p.page.render = render;

View File

@ -34,5 +34,5 @@ export const ViewMeta: FC<{ id: string; scopeIndex?: Record<string, any> }> = ({
}
}
return <ViewMetaRender item={item} v={v} />;
return <ViewMetaRender meta={meta} v={v} />;
};

View File

@ -1,16 +1,21 @@
import { FC } from "react";
import { IContent } from "../../../../utils/types/general";
import { produceCSS } from "../../../../utils/css/gen";
import { EdMeta } from "../../../ed/logic/ed-global";
import { VG } from "../../logic/global";
import { ViewMetaChildren } from "./children";
import { produceCSS } from "../../../../utils/css/gen";
export const ViewMetaRender: FC<{
item: IContent;
meta: EdMeta;
v: VG;
props?: any;
className?: string;
}> = ({ item, v, props, className }) => {
}> = ({ meta, v, props, className }) => {
let _className = className;
const item = meta.item;
if (meta.isLayout && !v.layout.show) {
return <ViewMetaChildren item={item} />;
}
if (!className) {
_className = produceCSS(item, {
mode: v.mode,

View File

@ -26,7 +26,7 @@ export const ViewMetaScript: FC<{
hover: v.view.hover ? v.view.hover.get(item) : undefined,
active: v.view.active ? v.view.active.get(item) : undefined,
});
const children = <ViewMetaRender item={item} v={v} className={className} />;
const children = <ViewMetaRender meta={meta} v={v} className={className} />;
let args = {};
if (js && meta) {