wip checkpoint

This commit is contained in:
Rizky 2023-12-11 18:32:05 +07:00
parent ec6d906228
commit efafe38cdc
7 changed files with 36 additions and 206 deletions

View File

@ -219,12 +219,12 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => {
} }
const comps: EPage["comps"] = {}; const comps: EPage["comps"] = {};
// for (const [id, v] of Object.entries(mcomps)) { for (const [id, v] of Object.entries(mcomps)) {
// const snap = snapshot.get("comp", id); const snap = snapshot.get("comp", id);
// if (snap) { if (snap) {
// comps[id] = { id, snapshot: await gzipAsync(snap.bin) }; comps[id] = { id, snapshot: await gzipAsync(snap.bin) };
// } }
// } }
return { meta: simplifyMeta(meta), comps, entry }; return { meta: simplifyMeta(meta), comps, entry };
}; };

View File

@ -23,8 +23,15 @@ export const EdRight = () => {
)} )}
> >
{!meta ? ( {!meta ? (
<div className="flex items-center justify-center text-[12px] flex-1"> <div className="flex py-[100px] items-center text-[12px] flex-1 flex-col">
Select an item <img
draggable={false}
src="/img/empty.png"
className={css`
width: 50px;
`}
/>
<div className="mt-[20px] text-[12px]"> Select an Item </div>
</div> </div>
) : ( ) : (
<> <>

View File

@ -1,170 +1,7 @@
import { waitUntil } from "web-utils"; import { PG, active } from "../ed-global";
import { EdMeta, PG, active } from "../ed-global";
import {
loadComponent,
loadcomp,
syncWalkLoad,
syncWalkMap,
} from "./sync-walk";
export const treeRebuild = async (p: PG, arg?: { note?: string }) => { export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
const doc = p.page.doc; console.log(p.comp.list);
if (!doc) return;
const root = doc.getMap("map").get("root");
if (root) {
p.page.building = true;
p.render();
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
const portal = {
in: {} as Record<string, EdMeta>,
out: {} as Record<string, EdMeta>,
};
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) {
const lroot = ldoc.doc.getMap("map").get("root");
if (lroot) {
const sections = lroot.get("childs");
if (sections) {
sections.map((e) => {
return syncWalkLoad(p, e, (id) => {
return loadComponent(p, id);
});
});
if (loadcomp.pending.size > 0) {
await waitUntil(() => {
return loadcomp.pending.size === 0;
});
}
ldoc.doc.transact(() => {
sections.map((e) => {
if (p.page.root_id === "root") {
p.page.entry.push(e.get("id"));
}
syncWalkMap(
{
note: "tree-rebuild layout",
comps: p.comp.list,
item_loading: p.ui.tree.item_loading,
meta: p.page.meta,
scope: p.page.scope,
},
{
is_layout: true,
mitem: e,
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") {
p.page.root_id = meta.item.id;
}
},
}
);
});
});
for (const [k, portal_out] of Object.entries(portal.out)) {
const name = k.replace(/⮕/gi, "").trim();
const portal_in = portal.in[`${name}`];
if (portal_in) {
for (const key of Object.keys(portal_in)) {
delete (portal_in as any)[key];
}
for (const [k, v] of Object.entries(portal_out)) {
(portal_in as any)[k] = v;
}
}
}
}
// if p.page.root_id is root, it means content is not found.
// if content is not found, do not use layout.
if (p.page.root_id === "root") {
p.page.entry = [];
p.page.tree = [];
p.page.meta = {};
}
}
}
}
const sections = root.get("childs");
if (sections) {
sections.map((e) => {
return syncWalkLoad(p, e, (id) => {
return loadComponent(p, id);
});
});
if (loadcomp.pending.size > 0) {
await waitUntil(() => {
return loadcomp.pending.size === 0;
});
}
}
doc.transact(() => {
const sections = root.get("childs");
if (sections) {
sections.map((e) => {
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(
{
note: "tree-rebuild doc",
comps: p.comp.list,
item_loading: p.ui.tree.item_loading,
meta: p.page.meta,
tree: p.page.tree,
scope: p.page.scope,
},
{
is_layout: false,
mitem: e,
parent_item: { id: p.page.root_id },
tree_root_id: p.page.root_id,
portal,
}
);
});
for (const [k, portal_out] of Object.entries(portal.out)) {
const name = k.replace(/⮕/gi, "").trim();
const portal_in = portal.in[`${name}`];
if (portal_in) {
for (const key of Object.keys(portal_in)) {
delete (portal_in as any)[key];
}
for (const [k, v] of Object.entries(portal_out)) {
(portal_in as any)[k] = v;
}
}
}
}
});
p.page.building = false;
p.render();
p.page.render();
}
}; };
export const getMRoot = (p: PG) => { export const getMRoot = (p: PG) => {

View File

@ -9,9 +9,14 @@ export const instantiate = (
mref_ids?: Record<string, string> & TypedMap<Record<string, string>> mref_ids?: Record<string, string> & TypedMap<Record<string, string>>
) => { ) => {
const newitem = structuredClone(comp); const newitem = structuredClone(comp);
if (newitem.component) {
newitem.component.ref_ids = {};
}
if (item.id) { if (item.id) {
newitem.id = item.id; newitem.id = item.id;
} }
if (item.component) { if (item.component) {
newitem.component = item.component; newitem.component = item.component;
} }

View File

@ -57,6 +57,7 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
p.meta[item.id] = meta; p.meta[item.id] = meta;
} }
} }
if (item.childs) { if (item.childs) {
for (const [k, v] of Object.entries(item.childs)) { for (const [k, v] of Object.entries(item.childs)) {
const mchild = mitem?.get("childs")?.get(k as unknown as number); const mchild = mitem?.get("childs")?.get(k as unknown as number);

View File

@ -1,8 +1,6 @@
import { createId } from "@paralleldrive/cuid2"; import { createId } from "@paralleldrive/cuid2";
import { TypedMap } from "yjs-types";
import { IContent, MContent } from "../../../../utils/types/general"; import { IContent, MContent } from "../../../../utils/types/general";
import { IItem } from "../../../../utils/types/item"; import { IItem } from "../../../../utils/types/item";
import set from "lodash.set";
import { ISimpleMeta } from "./types"; import { ISimpleMeta } from "./types";
const timeouts = {} as Record<string, any>; const timeouts = {} as Record<string, any>;
@ -25,28 +23,19 @@ export const applyRefIds = (
if (!ref_ids[item.id]) { if (!ref_ids[item.id]) {
ref_ids[item.id] = createId(); ref_ids[item.id] = createId();
if (mitem) { // if (parentcomp) {
const mitemcomp = mitem.get("component"); // clearTimeout(timeouts[instance.id]);
if (mitemcomp) { // timeouts[instance.id] = setTimeout(() => {
const mref_ids = new Y.Map() as any; // if (mref_ids) {
syncronize(mref_ids, ref_ids); // const mref_ids = new Y.Map() as any;
mitemcomp.set("ref_ids", mref_ids); // syncronize(mref_ids, ref_ids);
} // const parentcomp = parent?.minstance?.get("component");
} // if (parentcomp) {
// parentcomp.set("ref_ids", mref_ids);
if (parentcomp) { // }
clearTimeout(timeouts[instance.id]); // }
timeouts[instance.id] = setTimeout(() => { // }, 50);
if (mref_ids) { // }
const mref_ids = new Y.Map() as any;
syncronize(mref_ids, ref_ids);
const parentcomp = parent?.minstance?.get("component");
if (parentcomp) {
parentcomp.set("ref_ids", mref_ids);
}
}
}, 50);
}
} }
if (ref_ids[item.id]) { if (ref_ids[item.id]) {

View File

@ -41,12 +41,3 @@ export const simplifyMeta = (allmeta: Record<string, IMeta>) => {
return smeta; return smeta;
}; };
function formatBytes(bytes: number, decimals: number) {
if (bytes == 0) return "0 Bytes";
var k = 1024,
dm = decimals || 2,
sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}