From caba4368ca6d803f840801efecfb3cd108f94a7b Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 30 Oct 2023 08:58:38 +0700 Subject: [PATCH] fix --- app/db/prisma/schema.prisma | 50 ++++++++++++++ app/srv/ws/sync/actions-def.ts | 68 ++++++++++--------- app/srv/ws/sync/actions.ts | 10 ++- .../src/render/ed/panel/popup/code/code.tsx | 0 .../render/ed/panel/popup/npm/npm-import.tsx | 28 +++++--- pkgs/core/utils/sync-def.ts | 25 ++++++- 6 files changed, 137 insertions(+), 44 deletions(-) create mode 100644 app/web/src/render/ed/panel/popup/code/code.tsx diff --git a/app/db/prisma/schema.prisma b/app/db/prisma/schema.prisma index 35102d4e..53dd33dc 100644 --- a/app/db/prisma/schema.prisma +++ b/app/db/prisma/schema.prisma @@ -36,6 +36,7 @@ model component_group { id String @id(map: "site_comp_group_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String shared Boolean @default(false) + code_comp code_comp[] component component[] component_site component_site[] } @@ -223,6 +224,7 @@ model site { is_deleted Boolean @default(false) responsive String @default("all") npm_cache String @default(" ") @db.VarChar + code_site code_site[] component_site component_site[] npm_site npm_site[] page page[] @@ -275,3 +277,51 @@ model user { org_user org_user[] site site[] } + +model code { + id String @id(map: "code_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String @db.Uuid + code_comp code_comp[] + code_file code_file[] + code_npm code_npm[] + code_site code_site[] +} + +model code_comp { + id_code String @db.Uuid + id_comp_group String @db.Uuid + code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction) + component_group component_group @relation(fields: [id_comp_group], references: [id], onDelete: NoAction, onUpdate: NoAction) + + @@id([id_code, id_comp_group], map: "code_comp_id_code_id_comp_group") +} + +model code_npm { + id String @id(map: "code_npm_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid + module String + version String + bundled Boolean + import_as Json @default("{\"main\": {\"mode\": \"default\", \"name\": \"\"}, \"names\": []}") + id_code String @db.Uuid + code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction) +} + +model code_site { + id_code String @db.Uuid + id_site String @db.Uuid + is_main Boolean @default(true) + code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction) + site site @relation(fields: [id_site], references: [id], onDelete: NoAction, onUpdate: NoAction) + + @@id([id_code, id_site], map: "code_site_id_code_id_site") +} + +/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments +model code_file { + id String @id(map: "code_src_id") @default(dbgenerated("gen_random_uuid()")) @db.Uuid + name String + src String + id_code String @db.Uuid + type String @default("f") @db.Char(1) + code code @relation(fields: [id_code], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "code_src_id_code_fkey") +} diff --git a/app/srv/ws/sync/actions-def.ts b/app/srv/ws/sync/actions-def.ts index 0c588fe7..c2fb39ee 100644 --- a/app/srv/ws/sync/actions-def.ts +++ b/app/srv/ws/sync/actions-def.ts @@ -1,46 +1,50 @@ export const SyncActionDefinition = { + "code": { + "create": "0" + }, "site": { - "list": "0", - "group": "1", - "load": "2", - "update": "3" + "list": "1", + "group": "2", + "load": "3", + "update": "4" }, "comp": { - "new": "4", - "list": "5", - "group": "6", - "load": "7" + "new": "5", + "list": "6", + "group": "7", + "load": "8" }, "page": { - "list": "8", - "load": "9" + "list": "9", + "load": "10" }, "yjs": { - "um": "10", - "sv_local": "11", - "diff_local": "12", - "sv_remote": "13" + "um": "11", + "sv_local": "12", + "diff_local": "13", + "sv_remote": "14" }, - "activity": "14", + "activity": "15", "client": { - "info": "15" + "info": "16" } }; export const SyncActionPaths = { - "0": "site.list", - "1": "site.group", - "2": "site.load", - "3": "site.update", - "4": "comp.new", - "5": "comp.list", - "6": "comp.group", - "7": "comp.load", - "8": "page.list", - "9": "page.load", - "10": "yjs.um", - "11": "yjs.sv_local", - "12": "yjs.diff_local", - "13": "yjs.sv_remote", - "14": "activity", - "15": "client.info" + "0": "code.create", + "1": "site.list", + "2": "site.group", + "3": "site.load", + "4": "site.update", + "5": "comp.new", + "6": "comp.list", + "7": "comp.group", + "8": "comp.load", + "9": "page.list", + "10": "page.load", + "11": "yjs.um", + "12": "yjs.sv_local", + "13": "yjs.diff_local", + "14": "yjs.sv_remote", + "15": "activity", + "16": "client.info" }; diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index cf3db50a..0b418222 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -18,6 +18,9 @@ import { Activity, ActivityKind } from "./type"; export type SAction = typeof SyncActions; export const SyncActions = { + code: { + create: async (id_site: string, name: string) => ({}), + }, site: { list: async () => ({}) as Record, @@ -41,13 +44,14 @@ export const SyncActions = { item_id: string; item: IItem; }) => {}, - list: () => ({}) as Record>, + list: async () => + ({}) as Record>, group: async (id_site: string) => ({}) as Record, load: async (id: string) => ({}) as EComp | void, }, page: { - list: (id_site: string) => + list: async (id_site: string) => ({}) as Record>, load: async (id: string) => ({}) as EPage | void, }, @@ -74,7 +78,7 @@ export const SyncActions = { diff: Uint8Array ) => ({}) as { diff: Uint8Array } | void, }, - activity: ( + activity: async ( target: { comp_id?: string; page_id?: string; item_id: string }, kind: ActivityKind, activity: Activity diff --git a/app/web/src/render/ed/panel/popup/code/code.tsx b/app/web/src/render/ed/panel/popup/code/code.tsx new file mode 100644 index 00000000..e69de29b diff --git a/app/web/src/render/ed/panel/popup/npm/npm-import.tsx b/app/web/src/render/ed/panel/popup/npm/npm-import.tsx index 1728c081..fc86ed2b 100644 --- a/app/web/src/render/ed/panel/popup/npm/npm-import.tsx +++ b/app/web/src/render/ed/panel/popup/npm/npm-import.tsx @@ -40,9 +40,14 @@ export const EdNpmImport = ({ mode }: { mode: "page" | "site" }) => { mode, mode === "site" ? p.site.id || "" : p.page.cur.id ); - local.size = parseInt(size) || 0; - local.status = "ready"; - local.render(); + if (size === "bundling") { + local.bundling = true; + local.render(); + } else { + local.size = parseInt(size) || 0; + local.status = "ready"; + local.render(); + } }; useEffect(() => { reload(); @@ -179,8 +184,13 @@ export const EdNpmImport = ({ mode }: { mode: "page" | "site" }) => { )} >
{ - if (local.bundling) return; + onClick={async (e) => { + e.stopPropagation(); + e.preventDefault(); + if (local.bundling) { + console.log("Already bundling"); + return; + } local.bundling = true; local.render(); @@ -217,9 +227,11 @@ export const EdNpmImport = ({ mode }: { mode: "page" | "site" }) => { )}
-
- {formatBytes(local.size)} -
+ {!local.bundling && ( +
+ {formatBytes(local.size)} +
+ )} {local.list.length > 0 && ( diff --git a/pkgs/core/utils/sync-def.ts b/pkgs/core/utils/sync-def.ts index 85f2d797..b62acaaa 100644 --- a/pkgs/core/utils/sync-def.ts +++ b/pkgs/core/utils/sync-def.ts @@ -1,6 +1,6 @@ import { dir } from "dir"; import { SyncActions } from "../../../app/srv/ws/sync/actions"; -import { readAsync, writeAsync } from "fs-jetpack"; +import { existsAsync, readAsync, writeAsync } from "fs-jetpack"; export const syncActionDefinition = async () => { const def: any = {}; @@ -22,6 +22,29 @@ export const syncActionDefinition = async () => { }; walk(SyncActions, def, []); + const index_js = []; + for (const [k, v] of Object.entries(paths)) { + const arr = v.split("."); + const name = arr.join("_"); + const path = dir.path(`app/srv/ws/sync/actions/${name}.ts`); + const saction = arr.map((e) => `["${e}"]`).join(""); + if (!(await existsAsync(path))) { + const code = ` +import { SAction } from "../actions"; +import { SyncConnection } from "../type"; +export const ${name}: SAction${saction} = async function ( + this: SyncConnection, +) { + let result = null as unknown as Awaited< + ReturnType + >; + return result; +}`; + await writeAsync(path, code); + } + index_js.push(`export * from "./${name}";`); + } + const content = `\ export const SyncActionDefinition = ${JSON.stringify(def, null, 2)}; export const SyncActionPaths = ${JSON.stringify(paths, null, 2)};