From 68ef147f13f9d621670f9318c5e0c7f7790b8f9b Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 27 Dec 2023 14:13:18 +0700 Subject: [PATCH] wip fix component --- app/srv/ws/sync/actions/yjs_diff_local.ts | 24 +++++++++---------- app/srv/ws/sync/editor/prep-comp-page.ts | 19 ++++++++++++++- .../src/nova/ed/panel/tree/node/item/name.tsx | 2 +- app/web/src/nova/vi/meta/comp.tsx | 8 ++++++- app/web/src/nova/vi/meta/comp/instantiate.tsx | 7 ++---- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/app/srv/ws/sync/actions/yjs_diff_local.ts b/app/srv/ws/sync/actions/yjs_diff_local.ts index dda8ea46..2a8933d5 100644 --- a/app/srv/ws/sync/actions/yjs_diff_local.ts +++ b/app/srv/ws/sync/actions/yjs_diff_local.ts @@ -23,19 +23,19 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function ( const root = doc.getMap("map").get("root") as any; if (root) { if (mode === "page") { - // await db.page.update({ - // where: { id }, - // data: { - // content_tree: root.toJSON(), - // }, - // }); + await db.page.update({ + where: { id }, + data: { + content_tree: root.toJSON(), + }, + }); } else if (mode === "comp") { - // await db.component.update({ - // where: { id }, - // data: { - // content_tree: root.toJSON(), - // }, - // }); + await db.component.update({ + where: { id }, + data: { + content_tree: root.toJSON(), + }, + }); } } } diff --git a/app/srv/ws/sync/editor/prep-comp-page.ts b/app/srv/ws/sync/editor/prep-comp-page.ts index 62fb6271..03cab4f0 100644 --- a/app/srv/ws/sync/editor/prep-comp-page.ts +++ b/app/srv/ws/sync/editor/prep-comp-page.ts @@ -1,5 +1,22 @@ import { EComp } from "../../../../web/src/nova/ed/logic/ed-global"; +import { IRoot } from "../../../../web/src/utils/types/root"; +import { docs } from "../entity/docs"; +import { snapshot } from "../entity/snapshot"; +import { gzipAsync } from "../entity/zlib"; export const prepareComponentForPage = async (page_id: string) => { - return {} as Record; + const doc = docs.page[page_id].doc; + const root = doc.getMap("map").get("root")?.toJSON() as IRoot; + + const result = {} as Record; + if (root.component_ids) { + for (const id of root.component_ids) { + const snap = snapshot.get("comp", id); + if (snap) { + result[id] = { id, snapshot: await gzipAsync(snap.bin) }; + } + } + } + + return result; }; diff --git a/app/web/src/nova/ed/panel/tree/node/item/name.tsx b/app/web/src/nova/ed/panel/tree/node/item/name.tsx index f50a5b97..1f1972a6 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/name.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/name.tsx @@ -98,7 +98,7 @@ export const EdTreeName = ({ ) : (
-
{node.id} - {item.originalId}
+ {/*
{node.id} - {item.originalId}
*/}
)} diff --git a/app/web/src/nova/vi/meta/comp.tsx b/app/web/src/nova/vi/meta/comp.tsx index 86ffb3e5..0a618343 100644 --- a/app/web/src/nova/vi/meta/comp.tsx +++ b/app/web/src/nova/vi/meta/comp.tsx @@ -25,7 +25,13 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => { } if (instances) { - const instance = instances[item.id]; + let instance = instances[item.id]; + + if (!instances[item.id]) { + instances[item.id] = {}; + instance = instances[item.id]; + } + instantiate({ item, comp: item_comp, diff --git a/app/web/src/nova/vi/meta/comp/instantiate.tsx b/app/web/src/nova/vi/meta/comp/instantiate.tsx index 2bc3bf11..576b8b3d 100644 --- a/app/web/src/nova/vi/meta/comp/instantiate.tsx +++ b/app/web/src/nova/vi/meta/comp/instantiate.tsx @@ -22,7 +22,7 @@ export const instantiate = (arg: { if (item.component.props[k]) { newitem.component.props[k] = item.component.props[k]; } - + const content = newitem.component.props[k].content; if (content) { walkChild(content, ids); @@ -39,10 +39,7 @@ export const instantiate = (arg: { } }; -export const walkChild = ( - item: IItem, - ids: Exclude -) => { +export const walkChild = (item: IItem, ids: Record) => { if (!item.originalId) { item.originalId = item.id; }