wip fix component

This commit is contained in:
Rizky 2023-12-27 14:13:18 +07:00
parent e474131a87
commit 68ef147f13
5 changed files with 40 additions and 20 deletions

View File

@ -23,19 +23,19 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function (
const root = doc.getMap("map").get("root") as any; const root = doc.getMap("map").get("root") as any;
if (root) { if (root) {
if (mode === "page") { if (mode === "page") {
// await db.page.update({ await db.page.update({
// where: { id }, where: { id },
// data: { data: {
// content_tree: root.toJSON(), content_tree: root.toJSON(),
// }, },
// }); });
} else if (mode === "comp") { } else if (mode === "comp") {
// await db.component.update({ await db.component.update({
// where: { id }, where: { id },
// data: { data: {
// content_tree: root.toJSON(), content_tree: root.toJSON(),
// }, },
// }); });
} }
} }
} }

View File

@ -1,5 +1,22 @@
import { EComp } from "../../../../web/src/nova/ed/logic/ed-global"; 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) => { export const prepareComponentForPage = async (page_id: string) => {
return {} as Record<string, EComp>; const doc = docs.page[page_id].doc;
const root = doc.getMap("map").get("root")?.toJSON() as IRoot;
const result = {} as Record<string, EComp>;
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;
}; };

View File

@ -98,7 +98,7 @@ export const EdTreeName = ({
) : ( ) : (
<div className="flex flex-col"> <div className="flex flex-col">
<Name name={node.text} is_jsx_prop={is_jsx_prop} /> <Name name={node.text} is_jsx_prop={is_jsx_prop} />
<div className={"text-[9px] text-gray-500 -mt-1"}>{node.id} - {item.originalId}</div> {/* <div className={"text-[9px] text-gray-500 -mt-1"}>{node.id} - {item.originalId}</div> */}
</div> </div>
)} )}
</div> </div>

View File

@ -25,7 +25,13 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
} }
if (instances) { if (instances) {
const instance = instances[item.id]; let instance = instances[item.id];
if (!instances[item.id]) {
instances[item.id] = {};
instance = instances[item.id];
}
instantiate({ instantiate({
item, item,
comp: item_comp, comp: item_comp,

View File

@ -39,10 +39,7 @@ export const instantiate = (arg: {
} }
}; };
export const walkChild = ( export const walkChild = (item: IItem, ids: Record<string, string>) => {
item: IItem,
ids: Exclude<FNComponent["ref_ids"], undefined>
) => {
if (!item.originalId) { if (!item.originalId) {
item.originalId = item.id; item.originalId = item.id;
} }