diff --git a/app/srv/ws/sync/actions/page_load.ts b/app/srv/ws/sync/actions/page_load.ts index 13841e4c..04626a49 100644 --- a/app/srv/ws/sync/actions/page_load.ts +++ b/app/srv/ws/sync/actions/page_load.ts @@ -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), }; } }; diff --git a/app/srv/ws/sync/editor/prep-comp-page.ts b/app/srv/ws/sync/editor/prep-comp-page.ts index f5c52d4d..c8ba3181 100644 --- a/app/srv/ws/sync/editor/prep-comp-page.ts +++ b/app/srv/ws/sync/editor/prep-comp-page.ts @@ -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; + + 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]) { diff --git a/app/srv/ws/sync/editor/prep-page.ts b/app/srv/ws/sync/editor/prep-page.ts index ceb8b39e..0a8dfc68 100644 --- a/app/srv/ws/sync/editor/prep-page.ts +++ b/app/srv/ws/sync/editor/prep-page.ts @@ -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(); diff --git a/app/web/src/utils/types/root.ts b/app/web/src/utils/types/root.ts index 3ffc0702..2402ce9f 100644 --- a/app/web/src/utils/types/root.ts +++ b/app/web/src/utils/types/root.ts @@ -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; + component_ids?: string[]; }>; export type DPage = TypedDoc<{