diff --git a/app/srv/ws/sync/actions/comp_load.ts b/app/srv/ws/sync/actions/comp_load.ts index 13ceaa2c..e0eca67d 100644 --- a/app/srv/ws/sync/actions/comp_load.ts +++ b/app/srv/ws/sync/actions/comp_load.ts @@ -44,10 +44,11 @@ export const comp_load: SAction["comp"]["load"] = async function ( { comps: {}, meta, + mode: "comp", on: { visit(meta) { if (typeof meta.item.adv?.js === "string") { - meta.scope.def = parseJs(meta.item.adv?.js); + meta.item.script = parseJs(meta.item.adv?.js); } }, }, @@ -57,7 +58,6 @@ export const comp_load: SAction["comp"]["load"] = async function ( result[id] = { id, - meta, snapshot: await gzipAsync(snap.bin), }; } diff --git a/app/srv/ws/sync/actions/comp_new.ts b/app/srv/ws/sync/actions/comp_new.ts index a3556a4c..df271dee 100644 --- a/app/srv/ws/sync/actions/comp_new.ts +++ b/app/srv/ws/sync/actions/comp_new.ts @@ -88,15 +88,16 @@ export const comp_new: SAction["comp"]["new"] = async function ( if (load) { const mitem = docs.comp[comp.id].doc.getMap("map").get("root"); const citem = mitem?.toJSON() as IItem; - const smeta: Record = {}; + const comp_meta: Record = {}; genMeta( { comps: {}, - meta: smeta, + meta: comp_meta, + mode: "comp", on: { visit(meta) { if (typeof meta.item.adv?.js === "string") { - meta.scope.def = parseJs(meta.item.adv?.js); + meta.item.script = parseJs(meta.item.adv?.js); } }, }, @@ -106,7 +107,7 @@ export const comp_new: SAction["comp"]["new"] = async function ( return { id: comp.id, - meta: simplifyMeta(smeta), + meta: simplifyMeta(comp_meta), snapshot: load.snapshot, }; } diff --git a/app/srv/ws/sync/actions/page_load.ts b/app/srv/ws/sync/actions/page_load.ts index 077f4a53..b40ed179 100644 --- a/app/srv/ws/sync/actions/page_load.ts +++ b/app/srv/ws/sync/actions/page_load.ts @@ -178,107 +178,3 @@ export const page_load: SAction["page"]["load"] = async function ( }; } }; - -// const scanMeta = async (doc: DPage, sync: SyncConnection) => { -// const meta: GenMetaP["meta"] = {}; -// const mcomps: GenMetaP["comps"] = {}; -// const msnap: Record = {}; - -// const loading = {} as Record>; -// const mchilds = doc.getMap("map").get("root")?.get("childs"); -// const entry: string[] = []; -// if (mchilds) { -// const childs = mchilds.map((m) => m); -// for (const mchild of childs) { -// await initLoadComp( -// { comps: mcomps, meta }, -// mchild.toJSON(), -// async (comp_ids) => { -// for (const id of comp_ids) { -// if (!docs.comp[id]) { -// if (typeof loading[id] === "undefined") { -// loading[id] = new Promise(async (resolve) => { -// await loadComponent(id, sync); -// resolve(); -// }); -// } -// await loading[id]; -// } else { -// userSyncComponent(sync, id); -// } - -// const snap = snapshot.get("comp", id); -// if (snap) { -// msnap[id] = snap; -// } - -// if (docs.comp[id]) { -// const mitem = docs.comp[id].doc.getMap("map").get("root"); -// const comp = mitem?.toJSON() as IItem; -// const smeta: Record = {}; -// genMeta( -// { -// comps: {}, -// meta: smeta, -// on: { -// visit(meta) { -// if (typeof meta.item.adv?.js === "string") { -// meta.scope.def = parseJs(meta.item.adv?.js); -// } -// }, -// }, -// }, -// { item: comp, ignore_first_component: true } -// ); -// mcomps[id] = { comp, smeta: simplifyMeta(smeta) }; -// } -// } -// } -// ); -// } - -// const save = { -// instances_check: {} as Record, -// }; - -// for (const mitem of childs) { -// const item = mitem.toJSON() as IItem; -// entry.push(item.id); -// genMeta( -// { -// comps: mcomps, -// meta, -// on: { -// visit_component(item) { -// if (!item.component?.instances) { -// save.instances_check[item.id] = true; -// } -// }, -// visit(m) { -// if (!m.parent?.comp_id) { -// if (typeof m.item.adv?.js === "string") { -// m.scope.def = parseJs(m.item.adv?.js); -// } -// } - -// if (m.item.component?.id) { -// if (save.instances_check[m.item.id]) { -// save.instances_check[m.item.id] = m; -// } -// } -// }, -// }, -// }, -// { item } -// ); -// } -// } - -// const comps: EPage["comps"] = {}; -// for (const [id, snap] of Object.entries(msnap)) { -// const meta = mcomps[id].smeta; -// comps[id] = { id, meta, snapshot: await gzipAsync(snap.bin) }; -// } - -// return { meta: simplifyMeta(meta), comps, entry }; -// }; diff --git a/app/web/src/nova/ed/logic/comp/load.tsx b/app/web/src/nova/ed/logic/comp/load.tsx index 26107f1b..17da800a 100644 --- a/app/web/src/nova/ed/logic/comp/load.tsx +++ b/app/web/src/nova/ed/logic/comp/load.tsx @@ -2,13 +2,11 @@ import { NodeModel } from "@minoru/react-dnd-treeview"; import { compress, decompress } from "wasm-gzip"; import { IItem } from "../../../../utils/types/item"; import { DComp } from "../../../../utils/types/root"; +import { initLoadComp } from "../../../vi/meta/comp/init-comp-load"; 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 { initLoadComp } from "../../../vi/meta/comp/init-comp-load"; -import { ISimpleMeta } from "../../../vi/utils/types"; -import { simplifyMeta } from "../../../vi/meta/simplify"; export const loadcomp = { timeout: 0 as any, @@ -30,7 +28,7 @@ export const loadComponent = async (p: PG, id_comp: string, sync?: boolean) => { for (const [id_comp, comp] of result) { if (comp && comp.snapshot) { - await loadCompSnapshot(p, id_comp, comp.snapshot, comp.meta); + await loadCompSnapshot(p, id_comp, comp.snapshot); } } loadcomp.pending.clear(); @@ -42,8 +40,7 @@ export const loadComponent = async (p: PG, id_comp: string, sync?: boolean) => { export const loadCompSnapshot = async ( p: PG, comp_id: string, - snapshot: Uint8Array, - smeta: Record + snapshot: Uint8Array ) => { if (p.comp.list[comp_id] && p.comp.list[comp_id].doc) { return; @@ -56,16 +53,15 @@ export const loadCompSnapshot = async ( doc.off("update", p.comp.list[comp_id].on_update); } - const updated = await updateComponentMeta(p, doc, comp_id, smeta); + const updated = await updateComponentMeta(p, doc, comp_id); if (updated) { const { meta, tree } = updated; if (p.comp.list[comp_id]) { - p.comp.list[comp_id].comp.meta = smeta; p.comp.list[comp_id].meta = meta; p.comp.list[comp_id].tree = tree; } else { p.comp.list[comp_id] = { - comp: { id: comp_id, snapshot, meta: smeta }, + comp: { id: comp_id, snapshot }, doc, meta, tree, @@ -95,8 +91,7 @@ export const loadCompSnapshot = async ( const updated = await updateComponentMeta( p, p.comp.list[comp_id].doc, - comp_id, - smeta + comp_id ); if (updated) { p.comp.list[comp_id].meta = updated.meta; @@ -117,8 +112,7 @@ export const loadCompSnapshot = async ( export const updateComponentMeta = async ( p: PG, doc: DComp, - comp_id: string, - smeta: Record + comp_id: string ) => { const mitem = doc.getMap("map").get("root"); if (!mitem) return; @@ -127,13 +121,13 @@ export const updateComponentMeta = async ( const tree: NodeModel[] = []; const item = mitem.toJSON() as IItem; - p.comp.loaded[comp_id] = { comp: item, smeta }; + p.comp.loaded[comp_id] = item; await initLoadComp( { comps: p.comp.loaded, meta, set_meta: false, - smeta, + mode: "comp", }, item, async (comp_ids: string[]) => { @@ -143,7 +137,7 @@ export const updateComponentMeta = async ( for (const [id_comp, comp] of result) { if (comp && comp.snapshot) { - await loadCompSnapshot(p, id_comp, comp.snapshot, comp.meta); + await loadCompSnapshot(p, id_comp, comp.snapshot); } } } @@ -153,7 +147,7 @@ export const updateComponentMeta = async ( { comps: p.comp.loaded, meta, - smeta, + mode: "comp", on: { visit(m) { pushTreeNode(p, m, meta, tree); @@ -189,7 +183,7 @@ export const updateComponentMeta = async ( { item, ignore_first_component: true } ); - p.comp.loaded[comp_id] = { comp: item, smeta: simplifyMeta(meta) }; + p.comp.loaded[comp_id] = item; return { meta, tree }; }; diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index d10a2ca2..44eb1662 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -58,7 +58,6 @@ const EmptyPage = { const EmptyComp = { id: "", - meta: {} as Record, snapshot: null as null | Uint8Array, }; @@ -152,7 +151,6 @@ export const EDGlobal = { >, building: false, meta: {} as Record, - smeta: {} as Record, entry: [] as string[], tree: [] as NodeModel[], render: () => {}, diff --git a/app/web/src/nova/ed/logic/ed-route.ts b/app/web/src/nova/ed/logic/ed-route.ts index 883edb37..d99d6141 100644 --- a/app/web/src/nova/ed/logic/ed-route.ts +++ b/app/web/src/nova/ed/logic/ed-route.ts @@ -50,14 +50,11 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => { if (remotePage.comps) { for (const [id_comp, c] of Object.entries(remotePage.comps)) { if (c && c.snapshot) { - await loadCompSnapshot(p, id_comp, c.snapshot, c.meta); + await loadCompSnapshot(p, id_comp, c.snapshot); } } } - p.page.entry = remotePage.entry; - p.page.smeta = remotePage.meta; - p.page.cur = remotePage; if (remotePage.snapshot) { const doc = new Y.Doc(); @@ -107,6 +104,12 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => { if (p.page.doc) { page.page = p.page.cur; page.doc = p.page.doc; + + p.page.entry = p.page.doc + .getMap("map") + .get("root") + ?.get("childs") + ?.map((e) => e.get("id")) as string[]; } if (p.page.doc) { diff --git a/app/web/src/nova/ed/logic/tree/build.tsx b/app/web/src/nova/ed/logic/tree/build.tsx index 09c52334..440806a9 100644 --- a/app/web/src/nova/ed/logic/tree/build.tsx +++ b/app/web/src/nova/ed/logic/tree/build.tsx @@ -16,13 +16,9 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => { const mcomp = v.doc.getMap("map").get("root"); const icomp = mcomp?.toJSON() as IItem | undefined; if (icomp) { - p.comp.loaded[k] = { - comp: icomp, - smeta: v.comp.meta, - }; + p.comp.loaded[k] = icomp; } } - if (v.comp.meta) p.comp.loaded[k].smeta = v.comp.meta; } const mroot = p.page.doc?.getMap("map").get("root"); @@ -40,7 +36,7 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => { note: "tree-rebuild", comps: p.comp.loaded, meta, - smeta: p.page.smeta, + mode: "page", on: { async visit(m) { if (!is_layout) { diff --git a/app/web/src/nova/ed/panel/popup/script/monaco.tsx b/app/web/src/nova/ed/panel/popup/script/monaco.tsx index 9148cdb9..7d521ae7 100644 --- a/app/web/src/nova/ed/panel/popup/script/monaco.tsx +++ b/app/web/src/nova/ed/panel/popup/script/monaco.tsx @@ -229,12 +229,7 @@ export const EdScriptMonaco: FC<{}> = () => { } if (typeof scope === "object") { - if (active.comp_id) { - } else { - p.page.smeta[active.item_id].scope = scope; - if (!meta.scope) meta.scope = {}; - meta.scope.def = scope; - } + meta.item.script = scope; } } }, 1000); diff --git a/app/web/src/nova/ed/panel/popup/script/scope/modify.tsx b/app/web/src/nova/ed/panel/popup/script/scope/modify.tsx index 8413a71b..1a3294f3 100644 --- a/app/web/src/nova/ed/panel/popup/script/scope/modify.tsx +++ b/app/web/src/nova/ed/panel/popup/script/scope/modify.tsx @@ -1,10 +1,6 @@ import { Doc } from "yjs"; import { ISimpleMeta } from "../../../../../vi/utils/types"; -import { - IMeta, - PG, - active -} from "../../../../logic/ed-global"; +import { IMeta, PG, active } from "../../../../logic/ed-global"; import { CodeLoc } from "./type"; const modif = { @@ -50,11 +46,11 @@ const modifyJS = ( const { meta, src, loc } = item; if (loc.type === "item") { const js = meta.item.adv?.js; - if (js) { + const script = meta.item.script; + if (js && script) { const text = extractText(type, src); - const def = meta.scope?.def?.[type]; - const smeta = getSMetaByLoc(p, loc); + const def = script[type]; if (text) { if ( type === "local" && @@ -62,12 +58,8 @@ const modifyJS = ( typeof def.start === "number" && typeof def.end === "number" ) { - const final = replaceRange(js, def.start, def.end, text); + // const final = replaceRange(js, def.start, def.end, text); def.end = def.start + text.length; - - if (smeta && smeta.scope?.local) { - smeta.scope.local.end = def.end; - } } } } @@ -79,22 +71,6 @@ const modifyJS = ( }, 500); }; -const getSMetaByLoc = (p: PG, loc: CodeLoc) => { - let meta = undefined as ISimpleMeta | undefined; - if (!active.comp_id) { - meta = p.page.smeta[loc.item_id]; - } else { - const comp = p.comp.list[active.comp_id].comp.meta; - if (comp[loc.item_id]) { - meta = comp[loc.item_id]; - } - } - - if (loc.type === "item" && meta) { - return meta; - } -}; - const getMetaByLoc = (p: PG, loc: CodeLoc) => { let meta = undefined as IMeta | undefined; if (!active.comp_id) { diff --git a/app/web/src/nova/vi/meta/comp.tsx b/app/web/src/nova/vi/meta/comp.tsx index 692e6bf0..86ffb3e5 100644 --- a/app/web/src/nova/vi/meta/comp.tsx +++ b/app/web/src/nova/vi/meta/comp.tsx @@ -1,5 +1,4 @@ -import { deepClone } from "web-utils"; -import { GenMetaArg, GenMetaP, IMeta, ISimpleMeta } from "../utils/types"; +import { GenMetaArg, GenMetaP, IMeta } from "../utils/types"; import { instantiate } from "./comp/instantiate"; import { walkProp } from "./comp/walk-prop"; import { genMeta } from "./meta"; diff --git a/app/web/src/nova/vi/meta/simplify.tsx b/app/web/src/nova/vi/meta/simplify.tsx index 6752bff4..9e9a25fe 100644 --- a/app/web/src/nova/vi/meta/simplify.tsx +++ b/app/web/src/nova/vi/meta/simplify.tsx @@ -39,7 +39,6 @@ export const simplifyMeta = (allmeta: Record) => { instances: meta.instances, } : undefined, - scope: meta.scope.def, }; }