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.page.building = true;
p.render(); p.render();
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
const sections = root.get("childs"); const sections = root.get("childs");
if (sections) { if (sections) {
const loaded = new Set<string>(); 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)) 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( walkMap(
{ meta: p.page.meta, comps: p.comp.map }, { meta: p.page.meta, comps: p.comp.map },
{ {
@ -48,23 +53,30 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
} }
}, },
} }
)
); );
} });
doc.transact(async () => { // 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.entry = [];
p.page.tree = []; p.page.tree = [];
p.page.meta = {}; p.page.meta = {};
}
}
doc.transact(async () => {
const sections = root.get("childs"); const sections = root.get("childs");
if (sections) { if (sections) {
sections.map((e) => { sections.map((e) => {
if (root_id === "root") {
p.page.entry.push(e.get("id")); p.page.entry.push(e.get("id"));
}
syncWalkMap(p, { syncWalkMap(p, {
isLayout: false, isLayout: false,
mitem: e, mitem: e,
parent_item: { id: root_id }, parent_item: { id: root_id },
tree_root_id: root_id,
portal, portal,
}); });
}); });

View File

@ -3,6 +3,7 @@ import { IContent } from "../../../../utils/types/general";
import { IItem } from "../../../../utils/types/item"; import { IItem } from "../../../../utils/types/item";
import { FNComponent } from "../../../../utils/types/meta-fn"; import { FNComponent } from "../../../../utils/types/meta-fn";
import { EdMeta, PG } from "../ed-global"; import { EdMeta, PG } from "../ed-global";
import { deepClone } from "web-utils";
export const walkLoad = async ( export const walkLoad = async (
p: { map: PG["comp"]["map"] }, p: { map: PG["comp"]["map"] },
@ -85,12 +86,12 @@ export const walkMap = (
} }
} }
let item = mapItem(arg.item); let item = arg.item;
if (override_id) { if (override_id) {
item.id = 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") { if (item_comp && item_comp.id && parent_item.id !== "root") {
const comp_ref = p.comps[item_comp.id]; const comp_ref = p.comps[item_comp.id];
@ -108,7 +109,7 @@ export const walkMap = (
item_comp.ref_ids = ref_ids; item_comp.ref_ids = ref_ids;
} }
const original_id = item.id; const original_id = item.id;
item = mapItem(mcomp); item = deepClone(mcomp);
item.id = original_id; item.id = original_id;
const meta: EdMeta = { const meta: EdMeta = {
@ -135,6 +136,7 @@ export const walkMap = (
parent_item: { id: item.id }, parent_item: { id: item.id },
portal: arg.portal, portal: arg.portal,
parent_comp: { id: item.id, comp_id: item_comp.id }, 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 }, parent_item: { id: item.id },
portal: arg.portal, portal: arg.portal,
parent_comp: { id: item.id, comp_id: item_comp.id }, 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); if (arg.each) arg.each(meta);
p.meta[item.id] = meta; p.meta[item.id] = meta;
if (item.type !== "text") {
for (const c of item.childs) { for (const c of item.childs) {
if (c) {
walkMap(p, { walkMap(p, {
isLayout: arg.isLayout, isLayout: arg.isLayout,
item: c, item: c,
parent_item: { id: item.id }, parent_item: { id: item.id },
portal: arg.portal, portal: arg.portal,
parent_comp, 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_item: EdMeta["parent_item"];
parent_mcomp?: EdMeta["parent_mcomp"]; parent_mcomp?: EdMeta["parent_mcomp"];
skip_add_tree?: boolean; skip_add_tree?: boolean;
each?: (meta: EdMeta) => void; tree_root_id: string;
} }
) => { ) => {
const { mitem, parent_item, parent_mcomp } = arg; const { mitem, parent_item, parent_mcomp } = arg;
@ -113,7 +113,7 @@ export const syncWalkMap = (
if (!skip_tree) { if (!skip_tree) {
p.page.tree.push({ p.page.tree.push({
id: item.id, id: item.id,
parent: parent_item.id, parent: arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name, text: item.name,
}); });
} }
@ -154,13 +154,13 @@ export const syncWalkMap = (
if (item.name.startsWith("⮕")) { if (item.name.startsWith("⮕")) {
arg.portal.out[item.name] = meta; arg.portal.out[item.name] = meta;
} }
if (arg.each) arg.each(meta);
p.page.meta[item.id] = meta; p.page.meta[item.id] = meta;
if (!skip_tree) { if (!skip_tree) {
p.page.tree.push({ p.page.tree.push({
id: item.id, id: item.id,
parent: parent_item.id, parent:
arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name, text: item.name,
data: meta, data: meta,
}); });
@ -184,6 +184,7 @@ export const syncWalkMap = (
if (mcontent) { if (mcontent) {
syncWalkMap(p, { syncWalkMap(p, {
isLayout: arg.isLayout, isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: mcontent, mitem: mcontent,
parent_item: { id: item.id, mitem: mitem as MItem }, parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: { mitem: mitem as MItem, mcomp }, parent_mcomp: { mitem: mitem as MItem, mcomp },
@ -201,6 +202,7 @@ export const syncWalkMap = (
for (const e of childs) { for (const e of childs) {
syncWalkMap(p, { syncWalkMap(p, {
isLayout: arg.isLayout, isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: e, mitem: e,
parent_item: { id: item.id, mitem: mitem as MItem }, parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: { mitem: mitem as MItem, mcomp }, parent_mcomp: { mitem: mitem as MItem, mcomp },
@ -230,13 +232,12 @@ export const syncWalkMap = (
if (item.name.startsWith("⮕")) { if (item.name.startsWith("⮕")) {
arg.portal.out[item.name] = meta; arg.portal.out[item.name] = meta;
} }
if (arg.each) arg.each(meta);
p.page.meta[item.id] = meta; p.page.meta[item.id] = meta;
if (!skip_tree) { if (!skip_tree) {
p.page.tree.push({ p.page.tree.push({
id: item.id, id: item.id,
parent: parent_item.id, parent: arg.tree_root_id === parent_item.id ? "root" : parent_item.id,
text: item.name, text: item.name,
data: meta, data: meta,
}); });
@ -246,6 +247,7 @@ export const syncWalkMap = (
for (const e of childs) { for (const e of childs) {
syncWalkMap(p, { syncWalkMap(p, {
isLayout: arg.isLayout, isLayout: arg.isLayout,
tree_root_id: arg.tree_root_id,
mitem: e, mitem: e,
parent_item: { id: item.id, mitem: mitem as MItem }, parent_item: { id: item.id, mitem: mitem as MItem },
parent_mcomp: arg.parent_mcomp, parent_mcomp: arg.parent_mcomp,

View File

@ -2,7 +2,7 @@ import { useGlobal } from "web-utils";
import { Loading } from "../../../../utils/ui/loading"; import { Loading } from "../../../../utils/ui/loading";
import { View } from "../../../view/view"; import { View } from "../../../view/view";
import { EDGlobal, active } from "../../logic/ed-global"; import { EDGlobal, active } from "../../logic/ed-global";
import { loadComponent } from "../../logic/tree/build"; import { loadComponent } from "../../logic/tree/sync-walk";
export const EdMain = () => { export const EdMain = () => {
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");

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 { 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 { VG } from "../../logic/global";
import { ViewMetaChildren } from "./children"; import { ViewMetaChildren } from "./children";
import { produceCSS } from "../../../../utils/css/gen";
export const ViewMetaRender: FC<{ export const ViewMetaRender: FC<{
item: IContent; meta: EdMeta;
v: VG; v: VG;
props?: any; props?: any;
className?: string; className?: string;
}> = ({ item, v, props, className }) => { }> = ({ meta, v, props, className }) => {
let _className = className; let _className = className;
const item = meta.item;
if (meta.isLayout && !v.layout.show) {
return <ViewMetaChildren item={item} />;
}
if (!className) { if (!className) {
_className = produceCSS(item, { _className = produceCSS(item, {
mode: v.mode, mode: v.mode,

View File

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