fix
This commit is contained in:
parent
60f38c778c
commit
883aca22c6
|
|
@ -21,7 +21,10 @@ export const SyncActionDefinition = {
|
||||||
"diff_local": "12",
|
"diff_local": "12",
|
||||||
"sv_remote": "13"
|
"sv_remote": "13"
|
||||||
},
|
},
|
||||||
"activity": "14"
|
"activity": "14",
|
||||||
|
"client": {
|
||||||
|
"info": "15"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
export const SyncActionPaths = {
|
export const SyncActionPaths = {
|
||||||
"0": "site.list",
|
"0": "site.list",
|
||||||
|
|
@ -38,5 +41,6 @@ export const SyncActionPaths = {
|
||||||
"11": "yjs.sv_local",
|
"11": "yjs.sv_local",
|
||||||
"12": "yjs.diff_local",
|
"12": "yjs.diff_local",
|
||||||
"13": "yjs.sv_remote",
|
"13": "yjs.sv_remote",
|
||||||
"14": "activity"
|
"14": "activity",
|
||||||
|
"15": "client.info"
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -75,4 +75,8 @@ export const SyncActions = {
|
||||||
kind: "js" | "css" | "html" | "text",
|
kind: "js" | "css" | "html" | "text",
|
||||||
activity: Activity
|
activity: Activity
|
||||||
) => {},
|
) => {},
|
||||||
|
client: {
|
||||||
|
info: async (client_ids: string[]) =>
|
||||||
|
({}) as Record<string, { id: string; username: string }>,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { validate } from "uuid";
|
import { validate } from "uuid";
|
||||||
import { SAction } from "../actions";
|
import { SAction } from "../actions";
|
||||||
import { actstore, broadcastActivity } from "../entity/actstore";
|
import { Activity, actstore, broadcastActivity } from "../entity/actstore";
|
||||||
import { SyncConnection } from "../type";
|
import { SyncConnection } from "../type";
|
||||||
|
|
||||||
export const activity: SAction["activity"] = async function (
|
export const activity: SAction["activity"] = async function (
|
||||||
|
|
@ -24,7 +24,7 @@ export const activity: SAction["activity"] = async function (
|
||||||
|
|
||||||
const obj = actstore.page[target.page_id][target.item_id][kind];
|
const obj = actstore.page[target.page_id][target.item_id][kind];
|
||||||
if (obj) {
|
if (obj) {
|
||||||
if (act === "-") delete obj[this.client_id];
|
if (act === Activity.Null) delete obj[this.client_id];
|
||||||
else obj[this.client_id] = act;
|
else obj[this.client_id] = act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ export const activity: SAction["activity"] = async function (
|
||||||
|
|
||||||
const obj = actstore.comp[target.comp_id][target.item_id][kind];
|
const obj = actstore.comp[target.comp_id][target.item_id][kind];
|
||||||
if (obj) {
|
if (obj) {
|
||||||
if (act === "-") delete obj[this.client_id];
|
if (act === Activity.Null) delete obj[this.client_id];
|
||||||
else obj[this.client_id] = act;
|
else obj[this.client_id] = act;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { SAction } from "../actions";
|
||||||
|
import { conns } from "../entity/conn";
|
||||||
|
import { SyncConnection } from "../type";
|
||||||
|
|
||||||
|
export const client_info: SAction["client"]["info"] = async function (
|
||||||
|
this: SyncConnection,
|
||||||
|
ids
|
||||||
|
) {
|
||||||
|
const result = {} as any;
|
||||||
|
for (const client_id of ids) {
|
||||||
|
const user = conns.get(client_id)?.user;
|
||||||
|
if (user) {
|
||||||
|
result[client_id] = { id: user.id, username: user.username };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
export * from "./activity";
|
export * from "./activity";
|
||||||
|
export * from "./client_info";
|
||||||
export * from "./site_js";
|
export * from "./site_js";
|
||||||
export * from "./site_load";
|
export * from "./site_load";
|
||||||
export * from "./site_group";
|
export * from "./site_group";
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { user } from "../entity/user";
|
||||||
import { gzipAsync } from "../entity/zlib";
|
import { gzipAsync } from "../entity/zlib";
|
||||||
import { sendWS } from "../sync-handler";
|
import { sendWS } from "../sync-handler";
|
||||||
import { SyncConnection, SyncType } from "../type";
|
import { SyncConnection, SyncType } from "../type";
|
||||||
|
import { Activity, actstore, broadcastActivity } from "../entity/actstore";
|
||||||
|
|
||||||
export const page_load: SAction["page"]["load"] = async function (
|
export const page_load: SAction["page"]["load"] = async function (
|
||||||
this: SyncConnection,
|
this: SyncConnection,
|
||||||
|
|
@ -19,6 +20,26 @@ export const page_load: SAction["page"]["load"] = async function (
|
||||||
if (!conf) return undefined;
|
if (!conf) return undefined;
|
||||||
|
|
||||||
conf.page_id = id;
|
conf.page_id = id;
|
||||||
|
if (!actstore.page[id]) {
|
||||||
|
actstore.page[id] = {
|
||||||
|
load: {
|
||||||
|
root: {
|
||||||
|
[this.client_id]: Activity.Open,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const load = actstore.page[id]["load"];
|
||||||
|
if (load && load.root) {
|
||||||
|
load.root[this.client_id] = Activity.Open;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
broadcastActivity(
|
||||||
|
{
|
||||||
|
page_id: id,
|
||||||
|
},
|
||||||
|
[this.client_id]
|
||||||
|
);
|
||||||
|
|
||||||
const createUndoManager = async (root: Y.Map<any>) => {
|
const createUndoManager = async (root: Y.Map<any>) => {
|
||||||
const um = new Y.UndoManager(root, {
|
const um = new Y.UndoManager(root, {
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,11 @@ type COMP_ID = string;
|
||||||
type ITEM_ID = string;
|
type ITEM_ID = string;
|
||||||
type CLIENT_ID = string;
|
type CLIENT_ID = string;
|
||||||
|
|
||||||
export type Activity = "open" | "-";
|
export enum Activity {
|
||||||
export type ActivityKind = "js" | "css" | "html" | "text";
|
Open,
|
||||||
|
Null,
|
||||||
|
}
|
||||||
|
export type ActivityKind = "root" | "js" | "css" | "html" | "text";
|
||||||
export type ActivityList = Record<
|
export type ActivityList = Record<
|
||||||
ITEM_ID,
|
ITEM_ID,
|
||||||
Partial<Record<ActivityKind, Record<CLIENT_ID, Activity>>>
|
Partial<Record<ActivityKind, Record<CLIENT_ID, Activity>>>
|
||||||
|
|
@ -28,7 +31,7 @@ export const broadcastActivity = (
|
||||||
const wss = new Set<ServerWebSocket<WSData>>();
|
const wss = new Set<ServerWebSocket<WSData>>();
|
||||||
const data = {} as any;
|
const data = {} as any;
|
||||||
if (arg.page_id) {
|
if (arg.page_id) {
|
||||||
data.page = actstore.page[arg.page_id];
|
data.page = actstore.page[arg.page_id] || {};
|
||||||
user.active.findAll({ page_id: arg.page_id }).forEach((u) => {
|
user.active.findAll({ page_id: arg.page_id }).forEach((u) => {
|
||||||
if (u.client_id && (!exclude || !exclude.includes(u.client_id))) {
|
if (u.client_id && (!exclude || !exclude.includes(u.client_id))) {
|
||||||
const ws = conns.get(u.client_id)?.ws;
|
const ws = conns.get(u.client_id)?.ws;
|
||||||
|
|
@ -37,7 +40,7 @@ export const broadcastActivity = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (arg.comp_id) {
|
if (arg.comp_id) {
|
||||||
data.comp = actstore.page[arg.comp_id];
|
data.comp = actstore.page[arg.comp_id] || {};
|
||||||
user.active.findAll({ comp_id: arg.comp_id }).forEach((u) => {
|
user.active.findAll({ comp_id: arg.comp_id }).forEach((u) => {
|
||||||
if (u.client_id && (!exclude || !exclude.includes(u.client_id))) {
|
if (u.client_id && (!exclude || !exclude.includes(u.client_id))) {
|
||||||
const ws = conns.get(u.client_id)?.ws;
|
const ws = conns.get(u.client_id)?.ws;
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,10 @@ export const EDGlobal = {
|
||||||
| "ready",
|
| "ready",
|
||||||
sync: null as unknown as Awaited<ReturnType<typeof clientStartSync>>,
|
sync: null as unknown as Awaited<ReturnType<typeof clientStartSync>>,
|
||||||
site: EmptySite,
|
site: EmptySite,
|
||||||
|
activity: {
|
||||||
|
page: {},
|
||||||
|
comp: {},
|
||||||
|
},
|
||||||
script: { siteTypes: {} as Record<string, string> },
|
script: { siteTypes: {} as Record<string, string> },
|
||||||
page: {
|
page: {
|
||||||
cur: EmptyPage,
|
cur: EmptyPage,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { EdMonaco } from "./monaco/monaco";
|
||||||
import { EDGlobal, active } from "../../logic/ed-global";
|
import { EDGlobal, active } from "../../logic/ed-global";
|
||||||
import { compress } from "wasm-gzip";
|
import { compress } from "wasm-gzip";
|
||||||
import { jscript } from "../../../../utils/script/jscript";
|
import { jscript } from "../../../../utils/script/jscript";
|
||||||
|
import { Activity } from "../../../../../../srv/ws/sync/entity/actstore";
|
||||||
|
|
||||||
export const EdScriptSite = () => {
|
export const EdScriptSite = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -47,7 +48,11 @@ export const EdScriptSite = () => {
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
p.ui.script.site = false;
|
p.ui.script.site = false;
|
||||||
p.sync.activity({ page_id: p.page.cur.id, item_id: "site" }, "js", "-");
|
p.sync.activity(
|
||||||
|
{ page_id: p.page.cur.id, item_id: "site" },
|
||||||
|
"js",
|
||||||
|
Activity.Null
|
||||||
|
);
|
||||||
p.render();
|
p.render();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useGlobal } from "web-utils";
|
import { useGlobal } from "web-utils";
|
||||||
import { TopBtn } from "../top-btn";
|
import { TopBtn } from "../top-btn";
|
||||||
import { EDGlobal, active } from "../../../logic/ed-global";
|
import { EDGlobal, active } from "../../../logic/ed-global";
|
||||||
|
import { Activity } from "../../../../../../../srv/ws/sync/entity/actstore";
|
||||||
|
|
||||||
export const EdSiteJS = () => {
|
export const EdSiteJS = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -12,7 +13,7 @@ export const EdSiteJS = () => {
|
||||||
p.sync.activity(
|
p.sync.activity(
|
||||||
{ page_id: p.page.cur.id, item_id: "site" },
|
{ page_id: p.page.cur.id, item_id: "site" },
|
||||||
"js",
|
"js",
|
||||||
"open"
|
Activity.Open
|
||||||
);
|
);
|
||||||
p.ui.script.site = true;
|
p.ui.script.site = true;
|
||||||
p.render();
|
p.render();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue