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