This commit is contained in:
Rizky 2023-10-18 06:18:13 +07:00
parent 2d228cf2f7
commit 4bc0ae6881
7 changed files with 75 additions and 88 deletions

View File

@ -6,7 +6,8 @@ import { EText } from "./e-text";
export const EItem: FC<{
id: string;
fromProp?: boolean;
}> = ({ id, fromProp }) => {
_scopeIndex?: Record<string, any>;
}> = ({ id, fromProp, _scopeIndex }) => {
return (
<ErrorBox id={id}>
<ERender id={id} fromProp={fromProp}>

View File

@ -22,7 +22,8 @@ export const ERender: FC<{
id: string;
children?: (childs: IContent[]) => ReactNode;
fromProp?: boolean;
}> = ({ id, children }) => {
_scopeIndex?: Record<string, any>;
}> = ({ id, children, _scopeIndex }) => {
const p = useGlobal(EditorGlobal, "EDITOR");
const meta = p.treeMeta[id];
@ -31,10 +32,6 @@ export const ERender: FC<{
}
let item = meta.item;
if (item.hidden) {
return null;
}
if (
meta.parent_prop &&
typeof item.adv?.js === "string" &&

View File

@ -9,7 +9,8 @@ import { ERender } from "./e-render";
export const EText: FC<{
id: string;
fromProp?: boolean;
}> = ({ id, fromProp }) => {
_scopeIndex?: Record<string, any>;
}> = ({ id, fromProp, _scopeIndex }) => {
return (
<ErrorBox id={id}>
<ERender id={id} fromProp={fromProp} />

View File

@ -16,6 +16,7 @@ export type ItemMeta = {
mitem?: MContent;
item: IContent;
parent_id: string;
indexedScope: Record<string, any>;
parent_comp?: WithRequired<ItemMeta, "comp"> & { item: IItem };
parent_prop?: ItemMeta;
scope?: any;
@ -150,7 +151,10 @@ export const EditorGlobal = {
text: string;
data: { meta: ItemMeta; idx: number };
}[],
treePending: null as null | Promise<void>,
treeMeta: {} as Record<string, ItemMeta>,
cachedParentID: {} as Record<string, string>,
compInstance: {} as Record<string, Record<string, string>>,
/** components */
comp: null as null | {
@ -177,7 +181,6 @@ export const EditorGlobal = {
},
compDirectEdit: false,
compLoading: {} as Record<string, true>,
compInstance: {} as Record<string, Record<string, string>>,
/** routing */
pagePreload: {} as Record<string, true>,

View File

@ -23,11 +23,7 @@ export const rebuildTree = async (
p: PG,
opt?: { render?: () => void; mode?: REBUILD_MODE; note: string }
) => {
if (p.pendingRebuild || p.focused) {
return;
}
p.pendingRebuild = true;
p.treePending = new Promise<void>(async (resolve) => {
const _render = () => {
if (opt?.render) {
opt?.render();
@ -56,28 +52,6 @@ export const rebuildTree = async (
await mpage?.doc?.transact(async () => {
let parent_id = "root";
let includeTree = p.comp?.id ? false : true;
// const pageName = p.mpage?.getMap("map").get("name") as string;
// if (
// p.layout.section &&
// p.layout.content &&
// !pageName.startsWith("layout:")
// ) {
// await walk(p, mode, {
// item: p.layout.section,
// parent_id: "root",
// depth: 0,
// idx: 0,
// includeTree: false,
// });
// parent_id = p.layout.content.id;
// p.layout.content.type = "item";
// if (p.layout.content.type === "item") {
// p.layout.content.childs = (p.page?.content_tree.childs ||
// []) as unknown as IItem[];
// }
// }
await Promise.all(
mpage?.get("childs")?.map(async (mitem) => {
await walk(p, mode, {
@ -103,8 +77,11 @@ export const rebuildTree = async (
}
}
p.pendingRebuild = false;
resolve();
p.treePending = null;
_render();
});
};
export const walk = async (
@ -125,7 +102,6 @@ export const walk = async (
}
) => {
let item = val.item as IContent;
let mitem = val.mitem;
if (val.mitem) {
@ -172,6 +148,7 @@ export const walk = async (
}
if (item) {
if (item.hidden) return;
let comp: ItemMeta["comp"] = undefined as any;
if (item.type === "item" && item.component?.id) {
@ -242,7 +219,7 @@ export const walk = async (
const meta: ItemMeta = {
mitem: mitem,
item,
parent_id: val.parent_id,
parent_id: p.cachedParentID[item.id] || val.parent_id,
parent_comp: val.parent_comp as any,
depth: val.depth || 0,
elprop: createElProp(item, p),
@ -252,6 +229,7 @@ export const walk = async (
hover: p.item.sideHover ? false : p.item.hover === item.id,
active: p.item.sideHover ? false : p.item.active === item.id,
}),
indexedScope: p.treeMeta[item.id] ? p.treeMeta[item.id].indexedScope : {},
comp,
};

View File

@ -167,10 +167,15 @@ export const ETreeBody: FC<{ tree: NodeModel<NodeMeta>[]; meta?: any }> = ({
[tree]
);
const onOut = useCallback(() => {
p.item.hover = "";
p.softRender.all();
}, []);
useEffect(() => {
(async () => {
if (p.pendingRebuild) {
await waitUntil(() => !p.pendingRebuild);
if (p.treePending) {
await p.treePending;
}
const open = new Set<string>();
@ -252,7 +257,10 @@ export const ETreeBody: FC<{ tree: NodeModel<NodeMeta>[]; meta?: any }> = ({
</div>
)}
<DndProvider backend={MultiBackend} options={getBackendOptions()}>
<div className="flex flex-col items-stretch bg-white right-0 left-0">
<div
className="flex flex-col items-stretch bg-white right-0 left-0"
onPointerOut={onOut}
>
{local.rightClick.node && (
<ETreeRightClick
node={local.rightClick.node}

View File

@ -46,7 +46,6 @@ export const rebuildTree = async (
p.treePending = null;
if (_.render !== false) {
console.log("rendering");
p.render();
}
});
@ -67,7 +66,7 @@ const walk = async (
const treeMeta = val.treeMeta;
let item = val.item as IContent;
if (item.hidden) return;
if (item.hidden === 'all') return;
if (val.parent_comp) {
const pchild_ids = val.parent_comp.comp?.child_ids;