wip fix
This commit is contained in:
parent
74c194586a
commit
6474630cf5
|
|
@ -37,6 +37,13 @@ const scanMeta = async (id: string, doc: DComp, sync: SyncConnection) => {
|
||||||
mitem,
|
mitem,
|
||||||
parent_item: { id: "root" },
|
parent_item: { id: "root" },
|
||||||
parent_ids: ["root"],
|
parent_ids: ["root"],
|
||||||
|
parent_mcomp: {
|
||||||
|
id,
|
||||||
|
jsx_props: {},
|
||||||
|
mcomp: mitem,
|
||||||
|
mitem,
|
||||||
|
parent_ids: [],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export const extractMItemProps = (arg: {
|
||||||
item_comp: FNComponent;
|
item_comp: FNComponent;
|
||||||
mcomp: MItem;
|
mcomp: MItem;
|
||||||
scope: Exclude<ReturnType<typeof parseJs>, undefined>;
|
scope: Exclude<ReturnType<typeof parseJs>, undefined>;
|
||||||
mcontent: (mcontent: MItem) => void;
|
mcontent: (mcontent: MItem, prop_name: string) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { mitem, item_comp, mcomp, scope } = arg;
|
const { mitem, item_comp, mcomp, scope } = arg;
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ export const extractMItemProps = (arg: {
|
||||||
scope.props[k].value = "null as ReactElement";
|
scope.props[k].value = "null as ReactElement";
|
||||||
const mcontent = ensurePropContent(mprop, k);
|
const mcontent = ensurePropContent(mprop, k);
|
||||||
if (mcontent) {
|
if (mcontent) {
|
||||||
arg.mcontent(mcontent);
|
arg.mcontent(mcontent, k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,11 @@ export const serverWalkLoad = async (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ArgParentMComp = EdMeta["parent_mcomp"] & {
|
||||||
|
id: string;
|
||||||
|
parent_ids: string[];
|
||||||
|
jsx_props: Record<string, { id: string; parent_ids: string[] }>;
|
||||||
|
};
|
||||||
export const serverWalkMap = (
|
export const serverWalkMap = (
|
||||||
p: {
|
p: {
|
||||||
sync: SyncConnection;
|
sync: SyncConnection;
|
||||||
|
|
@ -83,11 +88,8 @@ export const serverWalkMap = (
|
||||||
mitem: MItem;
|
mitem: MItem;
|
||||||
parent_ids: string[];
|
parent_ids: string[];
|
||||||
parent_item: EdMeta["parent_item"];
|
parent_item: EdMeta["parent_item"];
|
||||||
is_prop?: boolean;
|
is_jsx_prop?: boolean;
|
||||||
parent_mcomp?: EdMeta["parent_mcomp"] & {
|
parent_mcomp?: ArgParentMComp;
|
||||||
id: string;
|
|
||||||
parent_ids: string[];
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
const { mitem, parent_item, parent_mcomp } = arg;
|
const { mitem, parent_item, parent_mcomp } = arg;
|
||||||
|
|
@ -180,23 +182,33 @@ export const serverWalkMap = (
|
||||||
undefined
|
undefined
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
const parent_mcomp: ArgParentMComp = {
|
||||||
|
parent_ids: ["root", item.id],
|
||||||
|
id: item_comp.id,
|
||||||
|
mitem: mitem as MItem,
|
||||||
|
mcomp,
|
||||||
|
jsx_props: {},
|
||||||
|
};
|
||||||
extractMItemProps({
|
extractMItemProps({
|
||||||
item_comp,
|
item_comp,
|
||||||
mitem,
|
mitem,
|
||||||
mcomp,
|
mcomp,
|
||||||
scope,
|
scope,
|
||||||
mcontent(mcontent) {
|
mcontent(mcontent, prop_name) {
|
||||||
|
const parent_ids = [...arg.parent_ids, item.id];
|
||||||
|
const id = mcontent.get("id");
|
||||||
|
if (id) {
|
||||||
|
parent_mcomp.jsx_props[prop_name] = {
|
||||||
|
id,
|
||||||
|
parent_ids,
|
||||||
|
};
|
||||||
|
}
|
||||||
serverWalkMap(p, {
|
serverWalkMap(p, {
|
||||||
parent_ids: [...arg.parent_ids, item.id],
|
parent_ids,
|
||||||
mitem: mcontent,
|
mitem: mcontent,
|
||||||
parent_item: { id: item.id, mitem: mitem as MItem },
|
parent_item: { id: item.id, mitem: mitem as MItem },
|
||||||
is_prop: true,
|
is_jsx_prop: true,
|
||||||
parent_mcomp: {
|
parent_mcomp,
|
||||||
parent_ids: ["root", item.id],
|
|
||||||
id: item_comp.id,
|
|
||||||
mitem: mitem as MItem,
|
|
||||||
mcomp,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -234,12 +246,7 @@ export const serverWalkMap = (
|
||||||
id: item.id,
|
id: item.id,
|
||||||
mitem: mitem as MItem,
|
mitem: mitem as MItem,
|
||||||
},
|
},
|
||||||
parent_mcomp: {
|
parent_mcomp,
|
||||||
parent_ids: ["root", item.id],
|
|
||||||
id: item_comp.id,
|
|
||||||
mitem: mitem as MItem,
|
|
||||||
mcomp,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -248,14 +255,25 @@ export const serverWalkMap = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.parent_mcomp && !arg.is_prop) {
|
if (item.name.startsWith("jsx=")) {
|
||||||
|
console.log(
|
||||||
|
item.name,
|
||||||
|
!!arg.parent_mcomp,
|
||||||
|
!arg.is_jsx_prop,
|
||||||
|
arg.parent_item.mitem?.get("name")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.parent_mcomp && !arg.is_jsx_prop) {
|
||||||
let id = item.originalId || item.id;
|
let id = item.originalId || item.id;
|
||||||
const pcomp = p.scope_comps[arg.parent_mcomp.id];
|
const pcomp = p.scope_comps[arg.parent_mcomp.id];
|
||||||
|
|
||||||
pcomp.scope[id] = {
|
pcomp.scope[id] = {
|
||||||
p: arg.parent_mcomp.parent_ids,
|
p: arg.parent_mcomp.parent_ids,
|
||||||
n: item.name,
|
n: item.name,
|
||||||
s: null,
|
s: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const js = item.adv?.js;
|
const js = item.adv?.js;
|
||||||
if (typeof js === "string") {
|
if (typeof js === "string") {
|
||||||
const scope = parseJs(js);
|
const scope = parseJs(js);
|
||||||
|
|
@ -276,9 +294,9 @@ export const serverWalkMap = (
|
||||||
for (const e of childs) {
|
for (const e of childs) {
|
||||||
serverWalkMap(p, {
|
serverWalkMap(p, {
|
||||||
mitem: e,
|
mitem: e,
|
||||||
is_prop: arg.is_prop,
|
is_jsx_prop: arg.is_jsx_prop,
|
||||||
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
|
||||||
? {
|
? {
|
||||||
...arg.parent_mcomp,
|
...arg.parent_mcomp,
|
||||||
parent_ids: [...(arg.parent_mcomp?.parent_ids || []), item.id],
|
parent_ids: [...(arg.parent_mcomp?.parent_ids || []), item.id],
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ export const edRoute = async (p: PG) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loaded = new Set<string>();
|
||||||
export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
p.status = "loading";
|
p.status = "loading";
|
||||||
const remotePage = await p.sync.page.load(page_id);
|
const remotePage = await p.sync.page.load(page_id);
|
||||||
|
|
@ -51,13 +52,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
if (remotePage.scope_comps) {
|
if (remotePage.scope_comps) {
|
||||||
for (const [id_comp, c] of Object.entries(remotePage.scope_comps)) {
|
for (const [id_comp, c] of Object.entries(remotePage.scope_comps)) {
|
||||||
if (c && c.snapshot) {
|
if (c && c.snapshot) {
|
||||||
await loadCompSnapshot(
|
await loadCompSnapshot(p, id_comp, loaded, c.snapshot, c.scope);
|
||||||
p,
|
|
||||||
id_comp,
|
|
||||||
new Set<string>(),
|
|
||||||
c.snapshot,
|
|
||||||
c.scope
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ export const loadCompSnapshot = async (
|
||||||
if (loaded.has(id_comp)) {
|
if (loaded.has(id_comp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
loaded.add(id_comp);
|
||||||
const doc = new Y.Doc() as DComp;
|
const doc = new Y.Doc() as DComp;
|
||||||
Y.applyUpdate(doc as any, decompress(snapshot));
|
Y.applyUpdate(doc as any, decompress(snapshot));
|
||||||
const mitem = doc.getMap("map").get("root");
|
const mitem = doc.getMap("map").get("root");
|
||||||
|
|
@ -24,12 +25,16 @@ export const loadCompSnapshot = async (
|
||||||
doc.off("update", p.comp.list[id_comp].on_update);
|
doc.off("update", p.comp.list[id_comp].on_update);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tree, meta } = await walkCompTree(p, mitem, loaded);
|
|
||||||
|
|
||||||
p.comp.list[id_comp] = {
|
p.comp.list[id_comp] = {
|
||||||
comp: { id: id_comp, snapshot },
|
comp: { id: id_comp, snapshot },
|
||||||
doc,
|
doc,
|
||||||
scope: scope,
|
scope: scope,
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
const { tree, meta } = await walkCompTree(p, mitem, loaded);
|
||||||
|
|
||||||
|
p.comp.list[id_comp] = {
|
||||||
|
...p.comp.list[id_comp],
|
||||||
meta,
|
meta,
|
||||||
tree,
|
tree,
|
||||||
async on_update(bin, origin) {
|
async on_update(bin, origin) {
|
||||||
|
|
|
||||||
|
|
@ -295,6 +295,11 @@ export const loadComponent = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
|
if (p.comp.list[id_comp]) {
|
||||||
|
resolve(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log("loading", id_comp);
|
||||||
loadcomp.pending.add(id_comp);
|
loadcomp.pending.add(id_comp);
|
||||||
clearTimeout(loadcomp.timeout);
|
clearTimeout(loadcomp.timeout);
|
||||||
loadcomp.timeout = setTimeout(async () => {
|
loadcomp.timeout = setTimeout(async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue