wip fix code
This commit is contained in:
parent
708b79191e
commit
8a28aaf1ca
|
|
@ -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"
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<string, { id: string; username: string }>,
|
||||
},
|
||||
code: {
|
||||
load: async (id: string, type: "src" | "built") =>
|
||||
({}) as {
|
||||
id: string;
|
||||
snapshot: null | Uint8Array;
|
||||
},
|
||||
edit: async (
|
||||
arg:
|
||||
| {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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";
|
||||
|
|
@ -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<string, { id: string; src: DCode; built: DCode }>,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
export const isTextEditing = () => {
|
||||
const el = document.activeElement;
|
||||
if (el && el.attributes.getNamedItem("contenteditable")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
@ -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" });
|
||||
|
|
|
|||
|
|
@ -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" });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Record<string, Y.Text>>;
|
||||
npm: TypedMap<Record<string, string>>;
|
||||
}>;
|
||||
}>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue