From 8a28aaf1cace2ceec3d88030b60a69a8aaa8a94f Mon Sep 17 00:00:00 2001 From: Rizky Date: Wed, 10 Jan 2024 10:06:55 +0700 Subject: [PATCH] wip fix code --- app/srv/ws/sync/actions-def.ts | 10 ++++++---- app/srv/ws/sync/actions.ts | 6 +++++- app/srv/ws/sync/actions/code_load.ts | 19 +++++++++++++++++++ app/srv/ws/sync/actions/index.ts | 1 + app/srv/ws/sync/entity/docs.ts | 3 ++- .../src/nova/ed/logic/active/is-editing.ts | 7 +++++++ app/web/src/nova/ed/logic/comp/load.tsx | 7 ++----- app/web/src/nova/ed/logic/ed-route.ts | 5 ++--- app/web/src/utils/types/root.ts | 2 +- 9 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 app/srv/ws/sync/actions/code_load.ts create mode 100644 app/web/src/nova/ed/logic/active/is-editing.ts diff --git a/app/srv/ws/sync/actions-def.ts b/app/srv/ws/sync/actions-def.ts index 2d51294a..e45c9b82 100644 --- a/app/srv/ws/sync/actions-def.ts +++ b/app/srv/ws/sync/actions-def.ts @@ -26,8 +26,9 @@ export const SyncActionDefinition = { "info": "15" }, "code": { - "edit": "16", - "parse": "17" + "load": "16", + "edit": "17", + "parse": "18" } }; export const SyncActionPaths = { @@ -47,6 +48,7 @@ export const SyncActionPaths = { "13": "yjs.sv_remote", "14": "activity", "15": "client.info", - "16": "code.edit", - "17": "code.parse" + "16": "code.load", + "17": "code.edit", + "18": "code.parse" }; diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index 918d2088..a35e77fd 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -8,7 +8,6 @@ import { import { IItem } from "../../../web/src/utils/types/item"; import { site_group } from "./actions/site_group"; import { ParsedScope, parseJs } from "./editor/parser/parse-js"; -import { ISimpleMeta } from "../../../web/src/nova/vi/utils/types"; /* WARNING: @@ -96,6 +95,11 @@ export const SyncActions = { ({}) as Record, }, code: { + load: async (id: string, type: "src" | "built") => + ({}) as { + id: string; + snapshot: null | Uint8Array; + }, edit: async ( arg: | { diff --git a/app/srv/ws/sync/actions/code_load.ts b/app/srv/ws/sync/actions/code_load.ts new file mode 100644 index 00000000..2208814b --- /dev/null +++ b/app/srv/ws/sync/actions/code_load.ts @@ -0,0 +1,19 @@ +import { DCode } from "../../../../web/src/utils/types/root"; +import { SAction } from "../actions"; +import { docs } from "../entity/docs"; +import { SyncConnection } from "../type"; +export const code_load: SAction["code"]["load"] = async function ( + this: SyncConnection, + id, + type +) { + let result = null as unknown as Awaited>; + + if (!docs.code[id]) { + const src_doc = new Y.Doc() as DCode; + const built_doc = new Y.Doc() as DCode; + docs.code[id] = { id, src: src_doc, built: built_doc }; + } + + return result; +}; diff --git a/app/srv/ws/sync/actions/index.ts b/app/srv/ws/sync/actions/index.ts index ccefa424..afd678b5 100644 --- a/app/srv/ws/sync/actions/index.ts +++ b/app/srv/ws/sync/actions/index.ts @@ -14,5 +14,6 @@ export * from "./yjs_diff_local"; export * from "./yjs_sv_remote"; export * from "./activity"; export * from "./client_info"; +export * from "./code_load"; export * from "./code_edit"; export * from "./code_parse"; \ No newline at end of file diff --git a/app/srv/ws/sync/entity/docs.ts b/app/srv/ws/sync/entity/docs.ts index f0f50b54..8faaf75c 100644 --- a/app/srv/ws/sync/entity/docs.ts +++ b/app/srv/ws/sync/entity/docs.ts @@ -1,6 +1,6 @@ import { TypedDoc, TypedMap } from "yjs-types"; import { MItem } from "../../../../web/src/utils/types/item"; -import { DComp, DPage } from "../../../../web/src/utils/types/root"; +import { DCode, DComp, DPage } from "../../../../web/src/utils/types/root"; export const docs = { site: {} as Record< @@ -27,4 +27,5 @@ export const docs = { um: Y.UndoManager; } >, + code: {} as Record, }; diff --git a/app/web/src/nova/ed/logic/active/is-editing.ts b/app/web/src/nova/ed/logic/active/is-editing.ts new file mode 100644 index 00000000..ffc6deb1 --- /dev/null +++ b/app/web/src/nova/ed/logic/active/is-editing.ts @@ -0,0 +1,7 @@ +export const isTextEditing = () => { + const el = document.activeElement; + if (el && el.attributes.getNamedItem("contenteditable")) { + return true; + } + return false; +}; diff --git a/app/web/src/nova/ed/logic/comp/load.tsx b/app/web/src/nova/ed/logic/comp/load.tsx index e174b918..7b7fe9d2 100644 --- a/app/web/src/nova/ed/logic/comp/load.tsx +++ b/app/web/src/nova/ed/logic/comp/load.tsx @@ -7,6 +7,7 @@ import { genMeta } from "../../../vi/meta/meta"; import { IMeta, PG } from "../ed-global"; import { treeRebuild } from "../tree/build"; import { pushTreeNode } from "../tree/build/push-tree"; +import { isTextEditing } from "../active/is-editing"; export const loadcomp = { timeout: 0 as any, @@ -98,11 +99,7 @@ export const loadCompSnapshot = async ( p.comp.list[comp_id].tree = updated.tree; } - if ( - document.activeElement?.attributes.getNamedItem( - "contenteditable" - ) - ) { + if (isTextEditing()) { return; } treeRebuild(p, { note: "load-comp" }); diff --git a/app/web/src/nova/ed/logic/ed-route.ts b/app/web/src/nova/ed/logic/ed-route.ts index 313d28ed..b614a0fb 100644 --- a/app/web/src/nova/ed/logic/ed-route.ts +++ b/app/web/src/nova/ed/logic/ed-route.ts @@ -1,4 +1,5 @@ import { compress, decompress } from "wasm-gzip"; +import { isTextEditing } from "./active/is-editing"; import { loadCompSnapshot } from "./comp/load"; import { PG } from "./ed-global"; import { loadSite } from "./ed-site"; @@ -86,9 +87,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => { ); Y.applyUpdate(doc as any, decompress(res.diff), "local"); - if ( - !document.activeElement?.attributes.getNamedItem("contenteditable") - ) { + if (!isTextEditing()) { await treeRebuild(p, { note: note + " page-on-update" }); } diff --git a/app/web/src/utils/types/root.ts b/app/web/src/utils/types/root.ts index 2402ce9f..38b2bac2 100644 --- a/app/web/src/utils/types/root.ts +++ b/app/web/src/utils/types/root.ts @@ -20,6 +20,7 @@ export type MRoot = TypedMap<{ export type DPage = TypedDoc<{ map: TypedMap<{ id: string; root: MRoot; ts?: number }>; }>; + export type DComp = TypedDoc<{ map: TypedMap<{ id: string; root: MItem; ts?: number }>; }>; @@ -28,6 +29,5 @@ export type DCode = TypedDoc<{ map: TypedMap<{ id: string; files: TypedMap>; - npm: TypedMap>; }>; }>;