This commit is contained in:
Rizky 2023-11-21 16:16:30 +07:00
parent 877a816eaa
commit 1938782368
6 changed files with 17 additions and 20 deletions

View File

@ -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 { IItem } from "../../../web/src/utils/types/item";
import { site_group } from "./actions/site_group"; import { site_group } from "./actions/site_group";
import { activity } from "./entity/activity"; import { activity } from "./entity/activity";
import { parseJs } from "./editor/parser/parse-js";
/* /*
WARNING: WARNING:
@ -89,10 +90,7 @@ export const SyncActions = {
({}) as Record<string, { id: string; username: string }>, ({}) as Record<string, { id: string; username: string }>,
}, },
swc: { swc: {
parse: async ( parse: async (code: string | Record<string, string>) =>
arg: ({}) as Record<string, ReturnType<typeof parseJs>>,
| { type: "page", page_id: string; item_id?: string }
| { type: "comp", comp_id: string; item_id?: string }
) => ({}) as Record<string, string>,
}, },
}; };

View File

@ -1,24 +1,21 @@
import { IContent } from "../../../../web/src/utils/types/general"; import { IContent } from "../../../../web/src/utils/types/general";
import { SAction } from "../actions"; import { SAction } from "../actions";
import { parseJs } from "../editor/parser/parse-js"; import { parseJs } from "../editor/parser/parse-js";
import { docs } from "../entity/docs";
import { SyncConnection } from "../type"; import { SyncConnection } from "../type";
export const swc_parse: SAction["swc"]["parse"] = async function ( export const swc_parse: SAction["swc"]["parse"] = async function (
this: SyncConnection, this: SyncConnection,
arg code
) { ) {
if (arg.type === "page") { if (typeof code === "object") {
let ydoc = docs.page[arg.page_id]; const result: Record<string, ReturnType<typeof parseJs>> = {};
if (ydoc) { for (const [k, v] of Object.entries(code)) {
const item = ydoc.doc.getMap("map").get("root")?.toJSON() as IContent; result[k] = parseJs(v);
const res = parseItem(item);
console.log(res);
} }
return result;
} }
let result = null as unknown as Awaited<ReturnType<SAction["swc"]["parse"]>>; return { _: parseJs(code) };
return result;
}; };
type ParseParent = Record<string, {}>; type ParseParent = Record<string, {}>;

View File

@ -62,8 +62,11 @@ export const parseJs = (code: string) => {
}, },
}); });
const result: any = {}; const result = {} as {
if (local.name) { local: typeof local | undefined;
passprop: typeof passprop | undefined;
};
if (!local.name) {
result.local = local; result.local = local;
} }
if (Object.keys(passprop).length > 0) { if (Object.keys(passprop).length > 0) {

View File

@ -14,6 +14,7 @@
"@paralleldrive/cuid2": "2.2.2", "@paralleldrive/cuid2": "2.2.2",
"@parcel/packager-wasm": "^2.10.1", "@parcel/packager-wasm": "^2.10.1",
"@parcel/service-worker": "^2.10.1", "@parcel/service-worker": "^2.10.1",
"recast": "^0.23.4",
"@qiwi/deep-proxy": "^2.0.3", "@qiwi/deep-proxy": "^2.0.3",
"algoliasearch": "^4.20.0", "algoliasearch": "^4.20.0",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",

View File

@ -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.page.building = false;
p.render(); p.render();
p.page.render(); p.page.render();
} }
}; };

BIN
bun.lockb

Binary file not shown.