From b7a193d909dc5887a970c2a98182e57019b2dea5 Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 16 Oct 2023 14:33:18 +0000 Subject: [PATCH] fix --- app/srv/exports.d.ts | 193 ++++++++++-------- app/srv/exports.ts | 7 + .../editor/panel/script/script-element.tsx | 16 +- 3 files changed, 119 insertions(+), 97 deletions(-) diff --git a/app/srv/exports.d.ts b/app/srv/exports.d.ts index 1bb28505..5f67796d 100644 --- a/app/srv/exports.d.ts +++ b/app/srv/exports.d.ts @@ -1,5 +1,5 @@ -/// /// +/// declare module "app/srv/api/npm-size" { export const _: { url: string; @@ -18,95 +18,6 @@ declare module "app/srv/api/site-dts" { api(site_id: string): Promise; }; } -declare module "app/srv/global" { - import { site, user } from "dbgen"; - import { ExecaChildProcess } from "execa"; - export const glb: { - lastUpdate: Record; - prasiSrv: { - status: Record; - running: Record; - }; - npm: { - page: Record; - site: Record; - }; - }; - export type Session = { - user: user & { - site: site[]; - }; - }; -} -declare module "app/web/src/utils/types/ws" { - export type WS_MSG = WS_MSG_GET_COMP | WS_MSG_SET_COMP | WS_MSG_GET_PAGE | WS_MSG_SET_PAGE | WS_MSG_SV_LOCAL | WS_MSG_SVDIFF_REMOTE | WS_MSG_DIFF_LOCAL | WS_MSG_UNDO | WS_MSG_REDO | WS_MSG_NEW_COMP | WS_SITE_JS | { - type: "ping"; - } | { - type: "pong"; - }; - export type WS_SITE_JS = { - type: "site-js"; - id_site: string; - src: string; - }; - export type WS_MSG_GET_COMP = { - type: "get_comp"; - comp_id: string; - }; - export type WS_MSG_SET_COMP = { - type: "set_comp"; - comp_id: string; - changes: string; - }; - export type WS_MSG_GET_PAGE = { - type: "get_page"; - page_id: string; - }; - export type WS_MSG_SET_PAGE = { - type: "set_page"; - changes: string; - }; - export type WS_MSG_NEW_COMP = { - type: "new_comp"; - id: string; - doc: string; - }; - export type WS_MSG_UNDO = { - type: "undo"; - mode: "page" | "site" | "comp"; - id: string; - }; - export type WS_MSG_REDO = { - type: "redo"; - mode: "page" | "site" | "comp"; - id: string; - }; - export type WS_MSG_SV_LOCAL = { - type: "sv_local"; - mode: "page" | "site" | "comp"; - id: string; - sv_local: string; - }; - export type WS_MSG_SVDIFF_REMOTE = { - type: "svd_remote"; - mode: "page" | "site" | "comp"; - id: string; - sv_remote: string; - diff_remote: string; - }; - export type WS_MSG_DIFF_LOCAL = { - type: "diff_local"; - mode: "page" | "site" | "comp"; - id: string; - diff_local: string; - }; -} declare module "app/web/src/utils/types/meta-fn" { import { TypedMap } from "yjs-types"; import { IItem, MItem } from "app/web/src/utils/types/item"; @@ -398,6 +309,69 @@ declare module "app/web/src/utils/types/general" { item: ITEM; }; } +declare module "app/web/src/utils/types/ws" { + export type WS_MSG = WS_MSG_GET_COMP | WS_MSG_SET_COMP | WS_MSG_GET_PAGE | WS_MSG_SET_PAGE | WS_MSG_SV_LOCAL | WS_MSG_SVDIFF_REMOTE | WS_MSG_DIFF_LOCAL | WS_MSG_UNDO | WS_MSG_REDO | WS_MSG_NEW_COMP | WS_SITE_JS | { + type: "ping"; + } | { + type: "pong"; + }; + export type WS_SITE_JS = { + type: "site-js"; + id_site: string; + src: string; + }; + export type WS_MSG_GET_COMP = { + type: "get_comp"; + comp_id: string; + }; + export type WS_MSG_SET_COMP = { + type: "set_comp"; + comp_id: string; + changes: string; + }; + export type WS_MSG_GET_PAGE = { + type: "get_page"; + page_id: string; + }; + export type WS_MSG_SET_PAGE = { + type: "set_page"; + changes: string; + }; + export type WS_MSG_NEW_COMP = { + type: "new_comp"; + id: string; + doc: string; + }; + export type WS_MSG_UNDO = { + type: "undo"; + mode: "page" | "site" | "comp"; + id: string; + }; + export type WS_MSG_REDO = { + type: "redo"; + mode: "page" | "site" | "comp"; + id: string; + }; + export type WS_MSG_SV_LOCAL = { + type: "sv_local"; + mode: "page" | "site" | "comp"; + id: string; + sv_local: string; + }; + export type WS_MSG_SVDIFF_REMOTE = { + type: "svd_remote"; + mode: "page" | "site" | "comp"; + id: string; + sv_remote: string; + diff_remote: string; + }; + export type WS_MSG_DIFF_LOCAL = { + type: "diff_local"; + mode: "page" | "site" | "comp"; + id: string; + diff_local: string; + }; +} declare module "app/srv/ws/edit/tools/load-page" { import { Page } from "app/web/src/utils/types/general"; export const loadPage: (page_id: string) => Promise; @@ -572,6 +546,38 @@ declare module "app/srv/ws/edit/edit-global" { }; }; } +declare module "app/srv/api/page-reload" { + export const _: { + url: string; + api(page_id: string): Promise; + }; +} +declare module "app/srv/global" { + import { site, user } from "dbgen"; + import { ExecaChildProcess } from "execa"; + export const glb: { + lastUpdate: Record; + prasiSrv: { + status: Record; + running: Record; + }; + npm: { + page: Record; + site: Record; + }; + }; + export type Session = { + user: user & { + site: site[]; + }; + }; +} declare module "app/srv/api/npm-bundle" { export type NPMImportAs = { main: { @@ -634,6 +640,13 @@ declare module "app/srv/exports" { args: string[]; handler: Promise; }; + export const page_reload: { + name: string; + url: string; + path: string; + args: string[]; + handler: Promise; + }; export const npm_bundle: { name: string; url: string; diff --git a/app/srv/exports.ts b/app/srv/exports.ts index 93feaace..0bf7ca95 100644 --- a/app/srv/exports.ts +++ b/app/srv/exports.ts @@ -19,6 +19,13 @@ export const site_dts = { args: ["site_id"], handler: import("./api/site-dts") } +export const page_reload = { + name: "page_reload", + url: "/page-reload/:page_id", + path: "app/srv/api/page-reload.ts", + args: ["page_id"], + handler: import("./api/page-reload") +} export const npm_bundle = { name: "npm_bundle", url: "/npm-bundle/:mode/:id", diff --git a/app/web/src/render/editor/panel/script/script-element.tsx b/app/web/src/render/editor/panel/script/script-element.tsx index 8cd65312..17992400 100644 --- a/app/web/src/render/editor/panel/script/script-element.tsx +++ b/app/web/src/render/editor/panel/script/script-element.tsx @@ -14,12 +14,20 @@ export const jscript = { editor: null as typeof MonacoEditor | null, build: null as null | FBuild, _init: false, + _editor: false, async init() { if (!this._init) { this._init = true; const { sendIPC } = await import("./esbuild/ipc"); await initJS(); + if (!this._editor) { + this._editor = true; + const e = await import("@monaco-editor/react"); + jscript.editor = e.Editor; + e.loader.config({ paths: { vs: "/min/vs" } }); + } + this.build = async (entry, src, files, verbose?: boolean) => { const options: BuildOptions = { entryPoints: [entry], @@ -51,13 +59,7 @@ export const EScriptElement: FC<{}> = ({}) => { const p = useGlobal(EditorGlobal, "EDITOR"); if (!jscript.editor) { - Promise.all([ - import("@monaco-editor/react").then((e) => { - jscript.editor = e.Editor; - e.loader.config({ paths: { vs: "/min/vs" } }); - }), - jscript.init(), - ]).then(() => { + jscript.init().then(() => { p.render(); }); }