This commit is contained in:
Rizky 2024-01-27 15:04:56 +07:00
parent ffd06c73d1
commit e41c3db80a
4 changed files with 54 additions and 8 deletions

View File

@ -22,6 +22,7 @@ export const code_edit: SAction["code"]["edit"] = async function (
let root = undefined as undefined | MRoot | MItem;
let doc = undefined as undefined | Doc;
let save_to = "page";
if (page_id) {
const ref = docs.page[page_id];
if (ref) {
@ -29,6 +30,7 @@ export const code_edit: SAction["code"]["edit"] = async function (
doc = ref.doc as Doc;
}
} else if (comp_id) {
save_to = "comp";
const ref = docs.comp[comp_id];
if (ref) {
root = ref.doc.getMap("map").get("root");
@ -80,6 +82,22 @@ export const code_edit: SAction["code"]["edit"] = async function (
}
}
});
if (save_to === "comp") {
await db.page.update({
where: { id: page_id },
data: {
content_tree: root.toJSON(),
},
});
} else {
await db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
}
} catch (e: any) {
return e.message.toString();
}
@ -101,6 +119,22 @@ export const code_edit: SAction["code"]["edit"] = async function (
mprop.set("value", src);
mprop.set("valueBuilt", res.code.substring(6));
});
if (save_to === "comp") {
await db.page.update({
where: { id: page_id },
data: {
content_tree: root.toJSON(),
},
});
} else {
await db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
}
} catch (e: any) {
return e.message.toString();
}
@ -143,6 +177,12 @@ export const code_edit: SAction["code"]["edit"] = async function (
}
}
});
await db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
} catch (e: any) {
return e.message.toString();
}

View File

@ -13,13 +13,13 @@ export const yjs_diff_local: SAction["yjs"]["diff_local"] = async function (
console.log(`diff_local not found`, mode, id);
return;
}
const doc = docs[mode][id].doc as Y.Doc;
const diff = await gunzipAsync(bin);
const um = docs[mode][id].um;
um.addTrackedOrigin(this.client_id);
Y.applyUpdate(doc, diff, this.client_id);
if (mode === "page" || mode === "comp") {
const doc = docs[mode][id].doc as Y.Doc;
const diff = await gunzipAsync(bin);
const um = docs[mode][id].um;
um.addTrackedOrigin(this.client_id);
Y.applyUpdate(doc, diff, this.client_id);
const root = doc.getMap("map").get("root") as any;
if (root) {
if (mode === "page") {

View File

@ -1,5 +1,4 @@
import { IItem } from "../../../../web/src/utils/types/item";
import { DComp } from "../../../../web/src/utils/types/root";
import { conns } from "../entity/conn";
import { docs } from "../entity/docs";
import { snapshot } from "../entity/snapshot";
@ -57,6 +56,9 @@ export const loadComponent = async (comp_id: string, sync?: SyncConnection) => {
const comp = await db.component.findFirst({ where: { id: comp_id } });
if (comp) {
const item = comp.content_tree as IItem;
if (item.name === "card") {
console.log(item);
}
if (item && item.component?.id !== comp.id) {
item.component = { id: comp.id, props: {} };
}

View File

@ -161,7 +161,11 @@ export const edPageTreeRender: NodeRender<PageItem> = (
if (confirm("Clone page ?")) {
local.render();
const page = (await db.page.findFirst({
where: { id: node.id as string },
where: {
id: node.id as string,
is_deleted: false,
is_default_layout: false,
},
})) as any;
delete page.id;