wip fix layout

This commit is contained in:
Rizky 2023-11-25 10:25:29 +07:00
parent 24adfb9b05
commit 83c6a91b29
11 changed files with 41 additions and 44 deletions

View File

@ -122,10 +122,10 @@ export type EdMeta = {
mcomp: MItem;
};
el?: ReactElement;
isLayout?: boolean;
is_layout?: boolean;
/** script related meta **/
propval?: Record<string, any>;
indexedScope: Record<string, any>;
idexed_scope: Record<string, any>;
memoize?: Record<
string,
{
@ -156,6 +156,7 @@ export const EDGlobal = {
do_edit: async (newval: string, all?: boolean) => {},
},
page: {
root_id: "root",
cur: EmptyPage,
doc: null as null | DPage,
list: {} as Record<

View File

@ -92,7 +92,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
decompress(res.sv)
);
Y.applyUpdate(doc as any, decompress(res.diff), "local");
await treeRebuild(p, { note: "page-on-update" });
await treeRebuild(p, { note: note + " page-on-update" });
await p.sync.yjs.diff_local(
"page",
@ -113,7 +113,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
}
if (p.page.doc) {
await treeRebuild(p, { note: "reload-page-init" });
await treeRebuild(p, { note: note + " page-init" });
}
}
p.status = "ready";

View File

@ -26,7 +26,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
out: {} as Record<string, EdMeta>,
};
let root_id = "root";
p.page.root_id = "root";
if (p.site.layout && p.site.layout.id !== p.page.cur.id) {
const ldoc = p.page.list[p.site.layout.id];
if (ldoc) {
@ -46,7 +46,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
if (component.pending) await component.pending;
sections.map((e) => {
if (root_id === "root") {
if (p.page.root_id === "root") {
p.page.entry.push(e.get("id"));
}
syncWalkMap(
@ -58,13 +58,13 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
{
isLayout: true,
mitem: e,
parent_item: { id: root_id },
tree_root_id: root_id,
parent_item: { id: p.page.root_id },
tree_root_id: p.page.root_id,
skip_add_tree: true,
portal,
each(meta) {
if (meta.item.name === "content") {
root_id = meta.item.id;
p.page.root_id = meta.item.id;
}
},
}
@ -85,9 +85,9 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
}
}
// if root_id is root, it means content is not found.
// if p.page.root_id is root, it means content is not found.
// if content is not found, do not use layout.
if (root_id === "root") {
if (p.page.root_id === "root") {
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
@ -113,8 +113,13 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
const sections = root.get("childs");
if (sections) {
sections.map((e) => {
if (root_id === "root") {
if (p.page.root_id === "root") {
p.page.entry.push(e.get("id"));
} else {
const meta = p.page.meta[p.page.root_id];
if (meta && meta.item.type === "item") {
meta.item.childs.push({ id: e.get("id") } as any);
}
}
syncWalkMap(
{
@ -126,8 +131,8 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
{
isLayout: false,
mitem: e,
parent_item: { id: root_id },
tree_root_id: root_id,
parent_item: { id: p.page.root_id },
tree_root_id: p.page.root_id,
portal,
}
);

View File

@ -115,8 +115,8 @@ export const walkMap = (
const meta: EdMeta = {
item,
parent_item,
indexedScope: {},
isLayout: arg.isLayout,
idexed_scope: {},
is_layout: arg.isLayout,
};
if (item.name.startsWith("⬅")) {
arg.portal.in[item.name] = meta;
@ -159,9 +159,9 @@ export const walkMap = (
const meta: EdMeta = {
item,
parent_item,
indexedScope: {},
idexed_scope: {},
parent_comp,
isLayout: arg.isLayout,
is_layout: arg.isLayout,
};
if (item.name.startsWith("⬅")) {
arg.portal.in[item.name] = meta;

View File

@ -154,8 +154,8 @@ export const syncWalkMap = (
mitem: mitem as MItem,
parent_item,
parent_mcomp: parent_mcomp,
indexedScope: {},
isLayout: arg.isLayout,
idexed_scope: {},
is_layout: arg.isLayout,
};
if (item.name.startsWith("⬅")) {
arg.portal.in[item.name] = meta;
@ -163,7 +163,6 @@ export const syncWalkMap = (
if (item.name.startsWith("⮕")) {
arg.portal.out[item.name] = meta;
}
if (arg.each) arg.each(meta);
p.meta[item.id] = meta;
@ -232,11 +231,12 @@ export const syncWalkMap = (
}
const meta: EdMeta = {
is_layout: arg.isLayout,
item,
mitem: mitem as MItem,
parent_item,
parent_mcomp: parent_mcomp,
indexedScope: {},
idexed_scope: {},
};
if (item.name.startsWith("⬅")) {

View File

@ -77,10 +77,6 @@ export const EdTreeAction = ({
if (comp_id) {
active.instance.item_id = item.id;
active.instance.comp_id = active.comp_id;
console.log(
active.instance.comp_id,
active.instance.item_id
);
active.comp_id = comp_id || "";
const root = p.comp.list[comp_id].tree.find(

View File

@ -12,7 +12,7 @@ export const ViewMetaRender: FC<{
}> = ({ meta, v, props, className }) => {
let _className = className;
const item = meta.item;
if (meta.isLayout && !v.layout.show) {
if (meta.is_layout && !v.layout.show) {
return <ViewMetaChildren item={item} />;
}

View File

@ -1,4 +1,3 @@
import { deepClone } from "web-utils";
import { createAPI, createDB } from "../../../../../utils/script/init-api";
import { FNCompDef } from "../../../../../utils/types/meta-fn";
import { EdMeta } from "../../../../ed/logic/ed-global";
@ -8,17 +7,13 @@ import { ViewMeta } from "../meta";
import { mergeScopeUpwards } from "./merge-upward";
const jsxProps = {} as Record<string, any>;
export const compPropVal = (
v: VG,
meta: EdMeta,
) => {
export const compPropVal = (v: VG, meta: EdMeta) => {
let props = {} as Record<string, FNCompDef>;
let cprops = {} as [string, FNCompDef][];
const item = meta.item;
if (item.type === "item" && item.component?.id) {
const icomp = item.component;
if (icomp) {
props = deepClone(v.component.map[icomp.id]?.item.component?.props || {});
cprops = Object.entries(props);
if (v.script.api_url) {

View File

@ -41,11 +41,11 @@ export const createLocal = (
}
scope = meta.scope;
} else {
if (!meta.indexedScope) {
meta.indexedScope = {};
if (!meta.idexed_scope) {
meta.idexed_scope = {};
}
if (!meta.indexedScope[local_id]) meta.indexedScope[local_id] = {};
scope = meta.indexedScope[local_id];
if (!meta.idexed_scope[local_id]) meta.idexed_scope[local_id] = {};
scope = meta.idexed_scope[local_id];
}
const render = () => {
@ -80,7 +80,7 @@ export const createLocal = (
let page_id = v.current.page_id || "";
const itemid = meta.item.id + (local_id ? `_${local_id}` : "");
if (meta.isLayout) {
if (meta.is_layout) {
page_id = "layout";
if (cachedLayout[meta.item.id]) {
scope[name] = cachedLocal[page_id][itemid];
@ -129,7 +129,7 @@ export const createLocal = (
useEffect(() => {
if (effect) {
if (meta.isLayout) {
if (meta.is_layout) {
if (cachedLayout[meta.item.id]) {
return;
}

View File

@ -11,11 +11,11 @@ export const createPassProp = (
const meta = v.meta[id];
if (typeof arg.idx !== "undefined" && meta && meta.item && meta.item.id) {
meta.indexedScope[arg.idx] = {};
meta.idexed_scope[arg.idx] = {};
for (const [k, v] of Object.entries(arg)) {
if (k === "children") continue;
meta.indexedScope[arg.idx][k] = v;
meta.idexed_scope[arg.idx][k] = v;
}
const scopeIndex = { ...existingScopeIndex, [meta.item.id]: arg.idx };

View File

@ -21,11 +21,11 @@ export const mergeScopeUpwards = (
let indexedScope = null;
if (cur.indexedScope && scopeIndex) {
if (cur.idexed_scope && scopeIndex) {
const idx = scopeIndex[cur.item.id];
if (typeof idx !== "undefined" && cur.indexedScope[idx]) {
indexedScope = cur.indexedScope[idx];
if (typeof idx !== "undefined" && cur.idexed_scope[idx]) {
indexedScope = cur.idexed_scope[idx];
}
}