wip fix
This commit is contained in:
parent
7949a36bc7
commit
da1bc214a1
|
|
@ -26,7 +26,7 @@ export const EdBase = () => {
|
||||||
edRoute(p);
|
edRoute(p);
|
||||||
|
|
||||||
if (p.status === "loading") {
|
if (p.status === "loading") {
|
||||||
return <Loading note={`${p.status}-page`} />;
|
return <Loading note={`base-${p.status}-page`} />;
|
||||||
}
|
}
|
||||||
if (p.status === "site-not-found" || p.status === "page-not-found") {
|
if (p.status === "site-not-found" || p.status === "page-not-found") {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { compress, decompress } from "wasm-gzip";
|
import { compress, decompress } from "wasm-gzip";
|
||||||
import { IItem } from "../../../utils/types/item";
|
|
||||||
import { DComp } from "../../../utils/types/root";
|
|
||||||
import { PG } from "./ed-global";
|
import { PG } from "./ed-global";
|
||||||
import { treeRebuild } from "./tree/build";
|
|
||||||
import { loadSite } from "./ed-site";
|
import { loadSite } from "./ed-site";
|
||||||
|
import { treeRebuild } from "./tree/build";
|
||||||
|
import { loadCompSnapshot } from "./tree/sync-walk";
|
||||||
|
|
||||||
export const edRoute = async (p: PG) => {
|
export const edRoute = async (p: PG) => {
|
||||||
if (p.status === "ready" || p.status === "init") {
|
if (p.status === "ready" || p.status === "init") {
|
||||||
|
|
@ -52,15 +51,14 @@ export const reloadPage = async (p: PG, page_id: 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) {
|
||||||
const doc = new Y.Doc() as DComp;
|
|
||||||
if (c.snapshot) {
|
await loadCompSnapshot(
|
||||||
Y.applyUpdate(doc as any, decompress(c.snapshot));
|
p,
|
||||||
// p.comp.list[id_comp] = {
|
id_comp,
|
||||||
// id: id_comp,
|
new Set<string>(),
|
||||||
// item: doc.getMap("map").get("root")?.toJSON() as IItem,
|
c.snapshot,
|
||||||
// };
|
c.scope
|
||||||
// p.comp.list[id_comp] = { comp: c, doc, scope: c.scope };
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { EdMeta, PG } from "../ed-global";
|
import { EdMeta, PG } from "../ed-global";
|
||||||
import { loadComponent, syncWalkLoad, syncWalkMap } from "./sync-walk";
|
import { loadComponent, syncWalkLoad, syncWalkMap } from "./sync-walk";
|
||||||
|
|
||||||
|
export const compLoaded = new Set<string>();
|
||||||
|
|
||||||
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
const doc = p.page.doc;
|
const doc = p.page.doc;
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
|
|
@ -16,11 +18,10 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
|
|
||||||
const sections = root.get("childs");
|
const sections = root.get("childs");
|
||||||
if (sections) {
|
if (sections) {
|
||||||
const loaded = new Set<string>();
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
sections.map((e) => {
|
sections.map((e) => {
|
||||||
return syncWalkLoad(p, e, loaded, (id) => {
|
return syncWalkLoad(p, e, compLoaded, (id) => {
|
||||||
return loadComponent(p, id, loaded);
|
return loadComponent(p, id, compLoaded);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
@ -112,13 +113,15 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
item_loading: p.ui.tree.item_loading,
|
item_loading: p.ui.tree.item_loading,
|
||||||
meta: p.page.meta,
|
meta: p.page.meta,
|
||||||
tree: p.page.tree,
|
tree: p.page.tree,
|
||||||
}, {
|
},
|
||||||
isLayout: false,
|
{
|
||||||
mitem: e,
|
isLayout: false,
|
||||||
parent_item: { id: root_id },
|
mitem: e,
|
||||||
tree_root_id: root_id,
|
parent_item: { id: root_id },
|
||||||
portal,
|
tree_root_id: root_id,
|
||||||
});
|
portal,
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const [k, portal_out] of Object.entries(portal.out)) {
|
for (const [k, portal_out] of Object.entries(portal.out)) {
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,13 @@ import { IItem, MItem } from "../../../../utils/types/item";
|
||||||
import { FNCompDef, FNComponent } from "../../../../utils/types/meta-fn";
|
import { FNCompDef, FNComponent } from "../../../../utils/types/meta-fn";
|
||||||
import { DComp } from "../../../../utils/types/root";
|
import { DComp } from "../../../../utils/types/root";
|
||||||
import { MSection } from "../../../../utils/types/section";
|
import { MSection } from "../../../../utils/types/section";
|
||||||
import { EdMeta, PG } from "../ed-global";
|
import { EdMeta, IScope, PG } from "../ed-global";
|
||||||
import {
|
import {
|
||||||
ensureMItemProps,
|
ensureMItemProps,
|
||||||
ensureMProp,
|
ensureMProp,
|
||||||
ensurePropContent,
|
ensurePropContent,
|
||||||
} from "./sync-walk-utils";
|
} from "./sync-walk-utils";
|
||||||
|
import { waitUntil } from "web-utils";
|
||||||
|
|
||||||
export const syncWalkLoad = async (
|
export const syncWalkLoad = async (
|
||||||
p: PG,
|
p: PG,
|
||||||
|
|
@ -64,6 +65,7 @@ export const syncWalkMap = (
|
||||||
tree?: NodeModel<EdMeta>[];
|
tree?: NodeModel<EdMeta>[];
|
||||||
comps: PG["comp"]["list"];
|
comps: PG["comp"]["list"];
|
||||||
meta: Record<string, EdMeta>;
|
meta: Record<string, EdMeta>;
|
||||||
|
warn_component_loaded?: boolean;
|
||||||
},
|
},
|
||||||
arg: {
|
arg: {
|
||||||
isLayout: boolean;
|
isLayout: boolean;
|
||||||
|
|
@ -127,7 +129,7 @@ export const syncWalkMap = (
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item_comp && item_comp.id && parent_item.id !== "root") {
|
if (item_comp && item_comp.id && parent_item.id !== "root") {
|
||||||
if (!p.comps[item_comp.id]) {
|
if (!p.comps[item_comp.id] && p.warn_component_loaded !== false) {
|
||||||
console.error("Component failed to load: ", item_comp.id);
|
console.error("Component failed to load: ", item_comp.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -271,6 +273,53 @@ export const syncWalkMap = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const loadCompSnapshot = async (
|
||||||
|
p: PG,
|
||||||
|
id_comp: string,
|
||||||
|
loaded: Set<string>,
|
||||||
|
snapshot: Uint8Array,
|
||||||
|
scope: IScope
|
||||||
|
) => {
|
||||||
|
if (loaded.has(id_comp)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const doc = new Y.Doc() as DComp;
|
||||||
|
Y.applyUpdate(doc as any, decompress(snapshot));
|
||||||
|
const mitem = doc.getMap("map").get("root");
|
||||||
|
if (mitem) {
|
||||||
|
await syncWalkLoad(p, mitem, loaded, (id) => loadComponent(p, id, loaded));
|
||||||
|
const tree: NodeModel<EdMeta>[] = [];
|
||||||
|
const meta = {};
|
||||||
|
const portal = {
|
||||||
|
in: {} as Record<string, EdMeta>,
|
||||||
|
out: {} as Record<string, EdMeta>,
|
||||||
|
};
|
||||||
|
syncWalkMap(
|
||||||
|
{
|
||||||
|
comps: p.comp.list,
|
||||||
|
item_loading: p.ui.tree.item_loading,
|
||||||
|
meta,
|
||||||
|
tree,
|
||||||
|
warn_component_loaded: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mitem,
|
||||||
|
isLayout: false,
|
||||||
|
parent_item: { id: "root" },
|
||||||
|
portal,
|
||||||
|
tree_root_id: "root",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
p.comp.list[id_comp] = {
|
||||||
|
comp: { id: id_comp, snapshot },
|
||||||
|
doc,
|
||||||
|
scope: scope,
|
||||||
|
meta,
|
||||||
|
tree,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const loadComponent = async (
|
export const loadComponent = async (
|
||||||
p: PG,
|
p: PG,
|
||||||
id_comp: string,
|
id_comp: string,
|
||||||
|
|
@ -281,19 +330,7 @@ export const loadComponent = async (
|
||||||
if (comps) {
|
if (comps) {
|
||||||
for (const cur of Object.values(comps)) {
|
for (const cur of Object.values(comps)) {
|
||||||
if (cur && cur.snapshot) {
|
if (cur && cur.snapshot) {
|
||||||
const doc = new Y.Doc() as DComp;
|
await loadCompSnapshot(p, id_comp, loaded, cur.snapshot, cur.scope);
|
||||||
if (cur.snapshot) {
|
|
||||||
Y.applyUpdate(doc as any, decompress(cur.snapshot));
|
|
||||||
const mitem = doc.getMap("map").get("root");
|
|
||||||
if (mitem) {
|
|
||||||
await syncWalkLoad(p, mitem, loaded, (id) =>
|
|
||||||
loadComponent(p, id, loaded)
|
|
||||||
);
|
|
||||||
|
|
||||||
// syncWalkMap()
|
|
||||||
// p.comp.list[id_comp] = { comp: cur, doc, scope: cur.scope; };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ 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 { compLoaded } from "../../logic/tree/build";
|
||||||
import { loadComponent } from "../../logic/tree/sync-walk";
|
import { loadComponent } from "../../logic/tree/sync-walk";
|
||||||
|
|
||||||
const compLoaded = new Set<string>();
|
|
||||||
export const EdMain = () => {
|
export const EdMain = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ export const EdTreeAction = ({
|
||||||
content="Edit Component"
|
content="Edit Component"
|
||||||
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"
|
className="flex items-center border border-slate-500 bg-white rounded-sm text-[10px] px-[2px] cursor-pointer hover:bg-purple-100 hover:border-purple-600"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
const comp_id = item.component?.id;
|
const comp_id = item.component?.id;
|
||||||
if (comp_id) {
|
if (comp_id) {
|
||||||
active.comp_id = comp_id;
|
active.comp_id = comp_id;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue