diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index a6286bdf..4d7b0bf5 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -3,6 +3,7 @@ import { EComp, EPage, ESite } from "../../../web/src/nova/ed/logic/ed-global"; import { IItem } from "../../../web/src/utils/types/item"; import { site_group } from "./actions/site_group"; import { activity } from "./entity/activity"; +import { parseJs } from "./editor/parser/parse-js"; /* WARNING: @@ -89,10 +90,7 @@ export const SyncActions = { ({}) as Record, }, swc: { - parse: async ( - arg: - | { type: "page", page_id: string; item_id?: string } - | { type: "comp", comp_id: string; item_id?: string } - ) => ({}) as Record, + parse: async (code: string | Record) => + ({}) as Record>, }, }; diff --git a/app/srv/ws/sync/actions/swc_parse.ts b/app/srv/ws/sync/actions/swc_parse.ts index 13cf6787..3b36e23c 100644 --- a/app/srv/ws/sync/actions/swc_parse.ts +++ b/app/srv/ws/sync/actions/swc_parse.ts @@ -1,24 +1,21 @@ import { IContent } from "../../../../web/src/utils/types/general"; import { SAction } from "../actions"; import { parseJs } from "../editor/parser/parse-js"; -import { docs } from "../entity/docs"; import { SyncConnection } from "../type"; export const swc_parse: SAction["swc"]["parse"] = async function ( this: SyncConnection, - arg + code ) { - if (arg.type === "page") { - let ydoc = docs.page[arg.page_id]; - if (ydoc) { - const item = ydoc.doc.getMap("map").get("root")?.toJSON() as IContent; - const res = parseItem(item); - console.log(res); + if (typeof code === "object") { + const result: Record> = {}; + for (const [k, v] of Object.entries(code)) { + result[k] = parseJs(v); } + return result; } - - let result = null as unknown as Awaited>; - return result; + + return { _: parseJs(code) }; }; type ParseParent = Record; diff --git a/app/srv/ws/sync/editor/parser/parse-js.ts b/app/srv/ws/sync/editor/parser/parse-js.ts index b3147892..7a3687f4 100644 --- a/app/srv/ws/sync/editor/parser/parse-js.ts +++ b/app/srv/ws/sync/editor/parser/parse-js.ts @@ -62,8 +62,11 @@ export const parseJs = (code: string) => { }, }); - const result: any = {}; - if (local.name) { + const result = {} as { + local: typeof local | undefined; + passprop: typeof passprop | undefined; + }; + if (!local.name) { result.local = local; } if (Object.keys(passprop).length > 0) { diff --git a/app/web/package.json b/app/web/package.json index 0f61d16a..a77b5551 100644 --- a/app/web/package.json +++ b/app/web/package.json @@ -14,6 +14,7 @@ "@paralleldrive/cuid2": "2.2.2", "@parcel/packager-wasm": "^2.10.1", "@parcel/service-worker": "^2.10.1", + "recast": "^0.23.4", "@qiwi/deep-proxy": "^2.0.3", "algoliasearch": "^4.20.0", "date-fns": "^2.30.0", diff --git a/app/web/src/nova/ed/logic/tree/build.tsx b/app/web/src/nova/ed/logic/tree/build.tsx index 8d6ca891..58d6a23a 100644 --- a/app/web/src/nova/ed/logic/tree/build.tsx +++ b/app/web/src/nova/ed/logic/tree/build.tsx @@ -62,12 +62,10 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => { } } }); - await p.sync.swc.parse({ type: "page", page_id: p.page.cur.id }); p.page.building = false; p.render(); p.page.render(); - } }; diff --git a/bun.lockb b/bun.lockb index 5781147b..a8b5eb1c 100755 Binary files a/bun.lockb and b/bun.lockb differ