wip checkpoint
This commit is contained in:
parent
ec6d906228
commit
efafe38cdc
|
|
@ -219,12 +219,12 @@ const scanMeta = async (doc: DPage, sync: SyncConnection) => {
|
|||
}
|
||||
|
||||
const comps: EPage["comps"] = {};
|
||||
// for (const [id, v] of Object.entries(mcomps)) {
|
||||
// const snap = snapshot.get("comp", id);
|
||||
// if (snap) {
|
||||
// comps[id] = { id, snapshot: await gzipAsync(snap.bin) };
|
||||
// }
|
||||
// }
|
||||
for (const [id, v] of Object.entries(mcomps)) {
|
||||
const snap = snapshot.get("comp", id);
|
||||
if (snap) {
|
||||
comps[id] = { id, snapshot: await gzipAsync(snap.bin) };
|
||||
}
|
||||
}
|
||||
|
||||
return { meta: simplifyMeta(meta), comps, entry };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,8 +23,15 @@ export const EdRight = () => {
|
|||
)}
|
||||
>
|
||||
{!meta ? (
|
||||
<div className="flex items-center justify-center text-[12px] flex-1">
|
||||
Select an item
|
||||
<div className="flex py-[100px] items-center text-[12px] flex-1 flex-col">
|
||||
<img
|
||||
draggable={false}
|
||||
src="/img/empty.png"
|
||||
className={css`
|
||||
width: 50px;
|
||||
`}
|
||||
/>
|
||||
<div className="mt-[20px] text-[12px]">— Select an Item —</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -1,170 +1,7 @@
|
|||
import { waitUntil } from "web-utils";
|
||||
import { EdMeta, PG, active } from "../ed-global";
|
||||
import {
|
||||
loadComponent,
|
||||
loadcomp,
|
||||
syncWalkLoad,
|
||||
syncWalkMap,
|
||||
} from "./sync-walk";
|
||||
import { PG, active } from "../ed-global";
|
||||
|
||||
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||
const doc = p.page.doc;
|
||||
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();
|
||||
}
|
||||
console.log(p.comp.list);
|
||||
};
|
||||
|
||||
export const getMRoot = (p: PG) => {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,14 @@ export const instantiate = (
|
|||
mref_ids?: Record<string, string> & TypedMap<Record<string, string>>
|
||||
) => {
|
||||
const newitem = structuredClone(comp);
|
||||
if (newitem.component) {
|
||||
newitem.component.ref_ids = {};
|
||||
}
|
||||
|
||||
if (item.id) {
|
||||
newitem.id = item.id;
|
||||
}
|
||||
|
||||
if (item.component) {
|
||||
newitem.component = item.component;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
|
|||
p.meta[item.id] = meta;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.childs) {
|
||||
for (const [k, v] of Object.entries(item.childs)) {
|
||||
const mchild = mitem?.get("childs")?.get(k as unknown as number);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import { createId } from "@paralleldrive/cuid2";
|
||||
import { TypedMap } from "yjs-types";
|
||||
import { IContent, MContent } from "../../../../utils/types/general";
|
||||
import { IItem } from "../../../../utils/types/item";
|
||||
import set from "lodash.set";
|
||||
import { ISimpleMeta } from "./types";
|
||||
|
||||
const timeouts = {} as Record<string, any>;
|
||||
|
|
@ -25,28 +23,19 @@ export const applyRefIds = (
|
|||
if (!ref_ids[item.id]) {
|
||||
ref_ids[item.id] = createId();
|
||||
|
||||
if (mitem) {
|
||||
const mitemcomp = mitem.get("component");
|
||||
if (mitemcomp) {
|
||||
const mref_ids = new Y.Map() as any;
|
||||
syncronize(mref_ids, ref_ids);
|
||||
mitemcomp.set("ref_ids", mref_ids);
|
||||
}
|
||||
}
|
||||
|
||||
if (parentcomp) {
|
||||
clearTimeout(timeouts[instance.id]);
|
||||
timeouts[instance.id] = setTimeout(() => {
|
||||
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 (parentcomp) {
|
||||
// clearTimeout(timeouts[instance.id]);
|
||||
// timeouts[instance.id] = setTimeout(() => {
|
||||
// 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]) {
|
||||
|
|
|
|||
|
|
@ -41,12 +41,3 @@ export const simplifyMeta = (allmeta: Record<string, IMeta>) => {
|
|||
|
||||
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];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue