wip fix code

This commit is contained in:
Rizky 2024-01-10 10:06:55 +07:00
parent 708b79191e
commit 8a28aaf1ca
9 changed files with 45 additions and 15 deletions

View File

@ -26,8 +26,9 @@ export const SyncActionDefinition = {
"info": "15" "info": "15"
}, },
"code": { "code": {
"edit": "16", "load": "16",
"parse": "17" "edit": "17",
"parse": "18"
} }
}; };
export const SyncActionPaths = { export const SyncActionPaths = {
@ -47,6 +48,7 @@ export const SyncActionPaths = {
"13": "yjs.sv_remote", "13": "yjs.sv_remote",
"14": "activity", "14": "activity",
"15": "client.info", "15": "client.info",
"16": "code.edit", "16": "code.load",
"17": "code.parse" "17": "code.edit",
"18": "code.parse"
}; };

View File

@ -8,7 +8,6 @@ import {
import { IItem } from "../../../web/src/utils/types/item"; import { IItem } from "../../../web/src/utils/types/item";
import { site_group } from "./actions/site_group"; import { site_group } from "./actions/site_group";
import { ParsedScope, parseJs } from "./editor/parser/parse-js"; import { ParsedScope, parseJs } from "./editor/parser/parse-js";
import { ISimpleMeta } from "../../../web/src/nova/vi/utils/types";
/* /*
WARNING: WARNING:
@ -96,6 +95,11 @@ export const SyncActions = {
({}) as Record<string, { id: string; username: string }>, ({}) as Record<string, { id: string; username: string }>,
}, },
code: { code: {
load: async (id: string, type: "src" | "built") =>
({}) as {
id: string;
snapshot: null | Uint8Array;
},
edit: async ( edit: async (
arg: arg:
| { | {

View File

@ -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<ReturnType<SAction["code"]["load"]>>;
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;
};

View File

@ -14,5 +14,6 @@ export * from "./yjs_diff_local";
export * from "./yjs_sv_remote"; export * from "./yjs_sv_remote";
export * from "./activity"; export * from "./activity";
export * from "./client_info"; export * from "./client_info";
export * from "./code_load";
export * from "./code_edit"; export * from "./code_edit";
export * from "./code_parse"; export * from "./code_parse";

View File

@ -1,6 +1,6 @@
import { TypedDoc, TypedMap } from "yjs-types"; import { TypedDoc, TypedMap } from "yjs-types";
import { MItem } from "../../../../web/src/utils/types/item"; 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 = { export const docs = {
site: {} as Record< site: {} as Record<
@ -27,4 +27,5 @@ export const docs = {
um: Y.UndoManager; um: Y.UndoManager;
} }
>, >,
code: {} as Record<string, { id: string; src: DCode; built: DCode }>,
}; };

View File

@ -0,0 +1,7 @@
export const isTextEditing = () => {
const el = document.activeElement;
if (el && el.attributes.getNamedItem("contenteditable")) {
return true;
}
return false;
};

View File

@ -7,6 +7,7 @@ import { genMeta } from "../../../vi/meta/meta";
import { IMeta, PG } from "../ed-global"; import { IMeta, PG } from "../ed-global";
import { treeRebuild } from "../tree/build"; import { treeRebuild } from "../tree/build";
import { pushTreeNode } from "../tree/build/push-tree"; import { pushTreeNode } from "../tree/build/push-tree";
import { isTextEditing } from "../active/is-editing";
export const loadcomp = { export const loadcomp = {
timeout: 0 as any, timeout: 0 as any,
@ -98,11 +99,7 @@ export const loadCompSnapshot = async (
p.comp.list[comp_id].tree = updated.tree; p.comp.list[comp_id].tree = updated.tree;
} }
if ( if (isTextEditing()) {
document.activeElement?.attributes.getNamedItem(
"contenteditable"
)
) {
return; return;
} }
treeRebuild(p, { note: "load-comp" }); treeRebuild(p, { note: "load-comp" });

View File

@ -1,4 +1,5 @@
import { compress, decompress } from "wasm-gzip"; import { compress, decompress } from "wasm-gzip";
import { isTextEditing } from "./active/is-editing";
import { loadCompSnapshot } from "./comp/load"; import { loadCompSnapshot } from "./comp/load";
import { PG } from "./ed-global"; import { PG } from "./ed-global";
import { loadSite } from "./ed-site"; 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"); Y.applyUpdate(doc as any, decompress(res.diff), "local");
if ( if (!isTextEditing()) {
!document.activeElement?.attributes.getNamedItem("contenteditable")
) {
await treeRebuild(p, { note: note + " page-on-update" }); await treeRebuild(p, { note: note + " page-on-update" });
} }

View File

@ -20,6 +20,7 @@ export type MRoot = TypedMap<{
export type DPage = TypedDoc<{ export type DPage = TypedDoc<{
map: TypedMap<{ id: string; root: MRoot; ts?: number }>; map: TypedMap<{ id: string; root: MRoot; ts?: number }>;
}>; }>;
export type DComp = TypedDoc<{ export type DComp = TypedDoc<{
map: TypedMap<{ id: string; root: MItem; ts?: number }>; map: TypedMap<{ id: string; root: MItem; ts?: number }>;
}>; }>;
@ -28,6 +29,5 @@ export type DCode = TypedDoc<{
map: TypedMap<{ map: TypedMap<{
id: string; id: string;
files: TypedMap<Record<string, Y.Text>>; files: TypedMap<Record<string, Y.Text>>;
npm: TypedMap<Record<string, string>>;
}>; }>;
}>; }>;