wip fix comp create + del
This commit is contained in:
parent
3ddf8eb0c4
commit
9bf04504e8
|
|
@ -8,6 +8,7 @@ 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:
|
||||||
|
|
@ -40,7 +41,7 @@ export const SyncActions = {
|
||||||
comp_id?: string;
|
comp_id?: string;
|
||||||
item_id: string;
|
item_id: string;
|
||||||
item: IItem;
|
item: IItem;
|
||||||
}) => {},
|
}) => ({}) as EComp | void,
|
||||||
list: async () =>
|
list: async () =>
|
||||||
({}) as Record<string, Exclude<component, "content_tree">>,
|
({}) as Record<string, Exclude<component, "content_tree">>,
|
||||||
group: async (id_site: string) =>
|
group: async (id_site: string) =>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
import { TypedArray } from "yjs-types";
|
import { TypedArray } from "yjs-types";
|
||||||
import { MItem } from "../../../../web/src/utils/types/item";
|
import { genMeta } from "../../../../web/src/nova/vi/meta/meta";
|
||||||
|
import { simplifyMeta } from "../../../../web/src/nova/vi/meta/simplify";
|
||||||
|
import { IMeta } from "../../../../web/src/nova/vi/utils/types";
|
||||||
|
import { IItem, MItem } from "../../../../web/src/utils/types/item";
|
||||||
import {
|
import {
|
||||||
FMComponent,
|
FMComponent,
|
||||||
FNComponent,
|
FNComponent,
|
||||||
} from "../../../../web/src/utils/types/meta-fn";
|
} from "../../../../web/src/utils/types/meta-fn";
|
||||||
import { MText } from "../../../../web/src/utils/types/text";
|
import { MText } from "../../../../web/src/utils/types/text";
|
||||||
import { SAction } from "../actions";
|
import { SAction } from "../actions";
|
||||||
|
import { loadComponent } from "../editor/load-component";
|
||||||
|
import { parseJs } from "../editor/parser/parse-js";
|
||||||
import { docs } from "../entity/docs";
|
import { docs } from "../entity/docs";
|
||||||
import { SyncConnection } from "../type";
|
import { SyncConnection } from "../type";
|
||||||
|
|
||||||
|
|
@ -61,7 +66,7 @@ export const comp_new: SAction["comp"]["new"] = async function (
|
||||||
walk(e);
|
walk(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, "server: comp_new");
|
});
|
||||||
} else if (comp_id) {
|
} else if (comp_id) {
|
||||||
const doc = docs.comp[comp_id].doc;
|
const doc = docs.comp[comp_id].doc;
|
||||||
doc.transact(() => {
|
doc.transact(() => {
|
||||||
|
|
@ -71,7 +76,37 @@ export const comp_new: SAction["comp"]["new"] = async function (
|
||||||
walk(e);
|
walk(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, "server: comp_new");
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comp) {
|
||||||
|
const load = await loadComponent(comp.id, this);
|
||||||
|
|
||||||
|
if (load) {
|
||||||
|
const mitem = docs.comp[comp.id].doc.getMap("map").get("root");
|
||||||
|
const citem = mitem?.toJSON() as IItem;
|
||||||
|
const smeta: Record<string, IMeta> = {};
|
||||||
|
genMeta(
|
||||||
|
{
|
||||||
|
comps: {},
|
||||||
|
meta: smeta,
|
||||||
|
on: {
|
||||||
|
visit(meta) {
|
||||||
|
if (typeof meta.item.adv?.js === "string") {
|
||||||
|
meta.scope.def = parseJs(meta.item.adv?.js);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ item: citem, ignore_first_component: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: comp.id,
|
||||||
|
meta: simplifyMeta(smeta),
|
||||||
|
snapshot: load.snapshot,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,14 @@ export const page_load: SAction["page"]["load"] = async function (
|
||||||
snapshot.set("page", id, "bin", bin);
|
snapshot.set("page", id, "bin", bin);
|
||||||
|
|
||||||
const sv_local = await gzipAsync(update);
|
const sv_local = await gzipAsync(update);
|
||||||
|
|
||||||
user.active.findAll({ page_id: id }).map((e) => {
|
user.active.findAll({ page_id: id }).map((e) => {
|
||||||
if (origin !== um) {
|
if (origin !== um) {
|
||||||
if (e.client_id === origin) return;
|
if (e.client_id === origin) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ws = conns.get(e.client_id)?.ws;
|
const ws = conns.get(e.client_id)?.ws;
|
||||||
|
|
||||||
if (ws)
|
if (ws)
|
||||||
sendWS(ws, {
|
sendWS(ws, {
|
||||||
type: SyncType.Event,
|
type: SyncType.Event,
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
page.on_update = async (bin: Uint8Array, origin: any) => {
|
page.on_update = async (bin: Uint8Array, origin: any) => {
|
||||||
if (origin === "sv_remote" || origin === "local") return;
|
if (origin === "local") return;
|
||||||
|
|
||||||
const res = await p.sync.yjs.sv_local(
|
const res = await p.sync.yjs.sv_local(
|
||||||
"page",
|
"page",
|
||||||
|
|
@ -88,6 +88,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
decompress(res.sv)
|
decompress(res.sv)
|
||||||
);
|
);
|
||||||
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
Y.applyUpdate(doc as any, decompress(res.diff), "local");
|
||||||
|
|
||||||
await treeRebuild(p, { note: note + " page-on-update" });
|
await treeRebuild(p, { note: note + " page-on-update" });
|
||||||
|
|
||||||
await p.sync.yjs.diff_local(
|
await p.sync.yjs.diff_local(
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ export const addScope = (
|
||||||
if (model) {
|
if (model) {
|
||||||
model.setValue(source);
|
model.setValue(source);
|
||||||
} else {
|
} else {
|
||||||
console.log(filename, source);
|
|
||||||
const model = monaco.editor.createModel(
|
const model = monaco.editor.createModel(
|
||||||
source,
|
source,
|
||||||
"typescript",
|
"typescript",
|
||||||
|
|
@ -22,8 +21,6 @@ export const addScope = (
|
||||||
);
|
);
|
||||||
model.onDidChangeContent((e) => {
|
model.onDidChangeContent((e) => {
|
||||||
const text = model.getValue();
|
const text = model.getValue();
|
||||||
console.log(filename, text);
|
|
||||||
|
|
||||||
// const models = monaco.editor.getModels().filter((e) => {
|
// const models = monaco.editor.getModels().filter((e) => {
|
||||||
// return e.uri.toString().startsWith("ts:scope~");
|
// return e.uri.toString().startsWith("ts:scope~");
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { IItem } from "../../../../../../../utils/types/item";
|
import { IItem } from "../../../../../../../utils/types/item";
|
||||||
import { getMetaById } from "../../../../../logic/active/get-meta";
|
import { getMetaById } from "../../../../../logic/active/get-meta";
|
||||||
import { PG, active } from "../../../../../logic/ed-global";
|
import { loadCompSnapshot } from "../../../../../logic/comp/load";
|
||||||
|
import { EComp, PG, active } from "../../../../../logic/ed-global";
|
||||||
import { treeRebuild } from "../../../../../logic/tree/build";
|
import { treeRebuild } from "../../../../../logic/tree/build";
|
||||||
|
|
||||||
export const edActionNewComp = (
|
export const edActionNewComp = (
|
||||||
|
|
@ -16,16 +17,16 @@ export const edActionNewComp = (
|
||||||
const item = mitem.toJSON() as IItem;
|
const item = mitem.toJSON() as IItem;
|
||||||
let item_id = active.item_id;
|
let item_id = active.item_id;
|
||||||
p.ui.tree.item_loading.push(item_id);
|
p.ui.tree.item_loading.push(item_id);
|
||||||
await treeRebuild(p);
|
let newcomp: void | EComp = undefined;
|
||||||
if (active.comp_id) {
|
if (active.comp_id) {
|
||||||
await p.sync.comp.new({
|
newcomp = await p.sync.comp.new({
|
||||||
group_id,
|
group_id,
|
||||||
item,
|
item,
|
||||||
comp_id: active.comp_id,
|
comp_id: active.comp_id,
|
||||||
item_id: active.item_id,
|
item_id: active.item_id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await p.sync.comp.new({
|
newcomp = await p.sync.comp.new({
|
||||||
group_id,
|
group_id,
|
||||||
item,
|
item,
|
||||||
page_id: p.page.cur.id,
|
page_id: p.page.cur.id,
|
||||||
|
|
@ -33,6 +34,12 @@ export const edActionNewComp = (
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(newcomp);
|
||||||
|
if (newcomp && newcomp.snapshot) {
|
||||||
|
await loadCompSnapshot(p, newcomp.id, newcomp.snapshot, newcomp.meta);
|
||||||
|
await treeRebuild(p);
|
||||||
|
}
|
||||||
|
|
||||||
p.ui.tree.item_loading = p.ui.tree.item_loading.filter(
|
p.ui.tree.item_loading = p.ui.tree.item_loading.filter(
|
||||||
(e) => e !== item_id
|
(e) => e !== item_id
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue