fix code
This commit is contained in:
parent
073ca45ab5
commit
bd06f7909f
|
|
@ -60,8 +60,10 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
|||
loader: "tsx",
|
||||
});
|
||||
}
|
||||
let adv = mitem.get("adv");
|
||||
const jscript = parseJs(adv?.get("js")) || false;
|
||||
|
||||
doc?.transact(() => {
|
||||
let adv = mitem.get("adv");
|
||||
if (!adv) {
|
||||
mitem.set("adv", new Y.Map() as any);
|
||||
adv = mitem.get("adv");
|
||||
|
|
@ -80,15 +82,16 @@ export const code_edit: SAction["code"]["edit"] = async function (
|
|||
}
|
||||
|
||||
if (mode === "js") {
|
||||
const res = parseJs(adv.get("js")) || false;
|
||||
if (res) {
|
||||
mitem.set("script", res);
|
||||
if (jscript) {
|
||||
mitem.set("script", jscript);
|
||||
} else {
|
||||
mitem.delete("script");
|
||||
}
|
||||
}
|
||||
|
||||
console.log("once");
|
||||
}
|
||||
});
|
||||
}, "code");
|
||||
|
||||
if (save_to === "comp" && comp_id) {
|
||||
await _db.component.update({
|
||||
|
|
|
|||
|
|
@ -35,19 +35,23 @@ export const page_load: SAction["page"]["load"] = async function (
|
|||
snapshot.set("page", id, "id_doc", um.doc.clientID);
|
||||
|
||||
doc.on("update", async (update: Uint8Array, origin: any) => {
|
||||
console.log(origin);
|
||||
const bin = Y.encodeStateAsUpdate(doc);
|
||||
snapshot.set("page", id, "bin", bin);
|
||||
|
||||
const sv_local = await gzipAsync(update);
|
||||
|
||||
const users = user.active.findAll({ page_id: id });
|
||||
users.map((e) => {
|
||||
const client_ids = new Set<string>();
|
||||
user.active.findAll({ page_id: id }).forEach((e) => {
|
||||
client_ids.add(e.client_id);
|
||||
});
|
||||
|
||||
client_ids.forEach((client_id) => {
|
||||
if (origin !== um) {
|
||||
if (e.client_id === origin) return;
|
||||
if (client_id === origin) return;
|
||||
}
|
||||
|
||||
const ws = conns.get(e.client_id)?.ws;
|
||||
|
||||
const ws = conns.get(client_id)?.ws;
|
||||
if (ws)
|
||||
sendWS(ws, {
|
||||
type: SyncType.Event,
|
||||
|
|
|
|||
|
|
@ -52,15 +52,19 @@ export const prepCodeSnapshot = async (id_site: string, mode: CodeMode) => {
|
|||
}
|
||||
const sv_local = await gzipAsync(bin);
|
||||
|
||||
user.active.findAll({ site_id: id_site }).map((e) => {
|
||||
const ws = conns.get(e.client_id)?.ws;
|
||||
if (ws) {
|
||||
const client_ids = new Set<string>();
|
||||
user.active.findAll({ site_id: id_site }).forEach((e) => {
|
||||
client_ids.add(e.client_id);
|
||||
});
|
||||
|
||||
client_ids.forEach((client_id) => {
|
||||
const ws = conns.get(client_id)?.ws;
|
||||
if (ws)
|
||||
sendWS(ws, {
|
||||
type: SyncType.Event,
|
||||
event: "remote_svlocal",
|
||||
data: { type: "code", sv_local, id: id_site },
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,22 +28,25 @@ export const loadComponent = async (comp_id: string, sync?: SyncConnection) => {
|
|||
|
||||
const sv_local = await gzipAsync(update);
|
||||
|
||||
const all = user.active.findAll({ comp_id: comp_id });
|
||||
user.active.findAll({ comp_id: comp_id });
|
||||
|
||||
all.map((e) => {
|
||||
const client_ids = new Set<string>();
|
||||
user.active.findAll({ comp_id: comp_id }).forEach((e) => {
|
||||
client_ids.add(e.client_id);
|
||||
});
|
||||
|
||||
client_ids.forEach((client_id) => {
|
||||
if (origin !== um) {
|
||||
if (e.client_id === origin) return;
|
||||
if (client_id === origin) return;
|
||||
}
|
||||
|
||||
const ws = conns.get(e.client_id)?.ws;
|
||||
|
||||
if (ws) {
|
||||
const ws = conns.get(client_id)?.ws;
|
||||
if (ws)
|
||||
sendWS(ws, {
|
||||
type: SyncType.Event,
|
||||
event: "remote_svlocal",
|
||||
data: { type: "comp", sv_local, id: comp_id },
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -460,8 +460,8 @@ declare global {
|
|||
applyChanges();
|
||||
p.ui.popup.script.on_close = () => {};
|
||||
};
|
||||
// clearTimeout(scriptEdit.timeout);
|
||||
// scriptEdit.timeout = setTimeout(applyChanges, 1000);
|
||||
clearTimeout(scriptEdit.timeout);
|
||||
scriptEdit.timeout = setTimeout(applyChanges, 2000);
|
||||
}}
|
||||
onMount={async (editor, monaco) => {
|
||||
local.monaco = monaco;
|
||||
|
|
|
|||
Loading…
Reference in New Issue