This commit is contained in:
Rizky 2023-12-27 17:28:33 +07:00
parent f222c43426
commit a5954fb0d7
4 changed files with 24 additions and 19 deletions

View File

@ -1,19 +1,10 @@
import { EPage } from "../../../../web/src/nova/ed/logic/ed-global";
import { initLoadComp } from "../../../../web/src/nova/vi/meta/comp/init-comp-load";
import { genMeta } from "../../../../web/src/nova/vi/meta/meta";
import { simplifyMeta } from "../../../../web/src/nova/vi/meta/simplify";
import { GenMetaP, IMeta } from "../../../../web/src/nova/vi/utils/types";
import { IItem } from "../../../../web/src/utils/types/item";
import { DPage } from "../../../../web/src/utils/types/root";
import { SAction } from "../actions";
import { loadComponent, userSyncComponent } from "../editor/load-component";
import { parseJs } from "../editor/parser/parse-js";
import { prepareComponentForPage } from "../editor/prep-comp-page";
import { prepContentTree } from "../editor/prep-page";
import { activity } from "../entity/activity";
import { conns } from "../entity/conn";
import { docs } from "../entity/docs";
import { CompSnapshot, snapshot } from "../entity/snapshot";
import { snapshot } from "../entity/snapshot";
import { user } from "../entity/user";
import { gzipAsync } from "../entity/zlib";
import { sendWS } from "../sync-handler";
@ -123,7 +114,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: page.url,
name: page.name,
snapshot: await gzipAsync(bin),
comps: await prepareComponentForPage(id, this),
comps: await prepareComponentForPage(id, this, false),
};
}
} else if (snap && !ydoc) {
@ -134,6 +125,8 @@ export const page_load: SAction["page"]["load"] = async function (
Y.applyUpdate(doc, snap.bin);
let root = doc.getMap("map");
const comps = await prepareComponentForPage(id, this, true, doc as any);
const um = await createUndoManager(root);
await attachOnUpdate(doc, um);
@ -156,7 +149,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: snap.url,
name: snap.name,
snapshot: await gzipAsync(snap.bin),
comps: await prepareComponentForPage(id, this),
comps,
};
} else if (snap && ydoc) {
await setActivityPage(snap.id_site, id);
@ -174,7 +167,7 @@ export const page_load: SAction["page"]["load"] = async function (
url: snap.url,
name: snap.name,
snapshot: await gzipAsync(snap.bin),
comps: await prepareComponentForPage(id, this),
comps: await prepareComponentForPage(id, this, true),
};
}
};

View File

@ -1,19 +1,30 @@
import { EComp } from "../../../../web/src/nova/ed/logic/ed-global";
import { IRoot } from "../../../../web/src/utils/types/root";
import { DPage, IRoot } from "../../../../web/src/utils/types/root";
import { docs } from "../entity/docs";
import { snapshot } from "../entity/snapshot";
import { gzipAsync } from "../entity/zlib";
import { SyncConnection } from "../type";
import { loadComponent } from "./load-component";
import { loadCompForPage } from "./prep-page";
export const prepareComponentForPage = async (
page_id: string,
sync: SyncConnection
sync: SyncConnection,
reload_components: boolean,
doc?: DPage
) => {
const doc = docs.page[page_id].doc;
const root = doc.getMap("map").get("root")?.toJSON() as IRoot;
const _doc = doc ? doc : docs.page[page_id].doc;
const root = _doc.getMap("map").get("root")?.toJSON() as IRoot;
const result = {} as Record<string, EComp>;
if (reload_components) {
root.component_ids = await loadCompForPage(root, sync);
if (doc) {
_doc.getMap("map").get("root")?.set("component_ids", root.component_ids);
}
}
if (root.component_ids) {
for (const id of root.component_ids) {
if (!docs.comp[id]) {

View File

@ -51,7 +51,7 @@ export const prepContentTree = async (
return root;
};
const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
const meta: GenMetaP["meta"] = {};
const mcomps: GenMetaP["comps"] = {};
const result = new Set<string>();

View File

@ -8,12 +8,13 @@ export type IRoot = {
id_page?: string;
childs: ISection[];
component_ids?: string[];
entry_ids?: string[];
};
export type MRoot = TypedMap<{
id: "root";
id_page?: string;
type: "root";
childs: TypedArray<ISection>;
component_ids?: string[];
}>;
export type DPage = TypedDoc<{