From f9e5f9389db5fba43e2ae8e245460d8aa380111e Mon Sep 17 00:00:00 2001 From: Rizky Date: Mon, 20 Nov 2023 14:37:18 +0700 Subject: [PATCH] wip fix script --- .vscode/settings.json | 5 +- app/web/src/nova/ed/ed-base.tsx | 2 + app/web/src/nova/ed/logic/ed-global.ts | 4 + .../src/nova/ed/panel/main/pane-resize.tsx | 4 +- .../src/nova/ed/panel/popup/script/monaco.tsx | 23 +++++ .../src/nova/ed/panel/popup/script/script.tsx | 94 +++++++++++++++++++ .../nova/ed/panel/popup/script/workbench.tsx | 47 ++++++++++ .../nova/ed/panel/tree/node/item/action.tsx | 40 +++++++- .../src/nova/ed/panel/tree/node/render.tsx | 5 + 9 files changed, 217 insertions(+), 7 deletions(-) create mode 100644 app/web/src/nova/ed/panel/popup/script/monaco.tsx create mode 100644 app/web/src/nova/ed/panel/popup/script/script.tsx create mode 100644 app/web/src/nova/ed/panel/popup/script/workbench.tsx diff --git a/.vscode/settings.json b/.vscode/settings.json index 8e1430b5..56d158ae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,5 @@ "**/CVS": true, "**/.DS_Store": true, "**/Thumbs.db": true - }, - "hide-files.files": [] -} \ No newline at end of file + } +} diff --git a/app/web/src/nova/ed/ed-base.tsx b/app/web/src/nova/ed/ed-base.tsx index 2c1215dc..e72a918b 100644 --- a/app/web/src/nova/ed/ed-base.tsx +++ b/app/web/src/nova/ed/ed-base.tsx @@ -12,6 +12,7 @@ import { EdPopCode } from "./panel/popup/code/code"; import { EdPopCompGroup } from "./panel/popup/comp/comp-group"; import { EdPopSite } from "./panel/popup/site/site"; import { EdScriptInit } from "./panel/script/monaco/init"; +import { EdPopScript } from "./panel/popup/script/script"; export const EdBase = () => { const p = useGlobal(EDGlobal, "EDITOR"); @@ -47,6 +48,7 @@ export const EdBase = () => { <> + diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index 3f18a4e8..5bbdfdc4 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -143,6 +143,10 @@ export const EDGlobal = { show_log: false, list: {} as Record, }, + script: { + open: false, + mode: "js" as "js" | "css" | "html", + }, site: null as null | ((site_id: string) => void | Promise), site_form: null as null | { group_id: string; diff --git a/app/web/src/nova/ed/panel/main/pane-resize.tsx b/app/web/src/nova/ed/panel/main/pane-resize.tsx index 51a79b26..3920692b 100644 --- a/app/web/src/nova/ed/panel/main/pane-resize.tsx +++ b/app/web/src/nova/ed/panel/main/pane-resize.tsx @@ -67,8 +67,8 @@ const EdPaneResize = (arg: {
{ arg.onResize(local.default); diff --git a/app/web/src/nova/ed/panel/popup/script/monaco.tsx b/app/web/src/nova/ed/panel/popup/script/monaco.tsx new file mode 100644 index 00000000..84807f40 --- /dev/null +++ b/app/web/src/nova/ed/panel/popup/script/monaco.tsx @@ -0,0 +1,23 @@ +import type { Editor as MonacoEditor, OnMount } from "@monaco-editor/react"; +import { jscript } from "../../../../../utils/script/jscript"; + +export type MonacoEditor = Parameters[0]; +export const ScriptMonaco = () => { + const Editor = jscript.editor; + if (!Editor) return null; + + return ( + + ); +}; diff --git a/app/web/src/nova/ed/panel/popup/script/script.tsx b/app/web/src/nova/ed/panel/popup/script/script.tsx new file mode 100644 index 00000000..0b3eb923 --- /dev/null +++ b/app/web/src/nova/ed/panel/popup/script/script.tsx @@ -0,0 +1,94 @@ +import { useGlobal } from "web-utils"; +import { jscript } from "../../../../../utils/script/jscript"; +import { Loading } from "../../../../../utils/ui/loading"; +import { Modal } from "../../../../../utils/ui/modal"; +import { EDGlobal } from "../../../logic/ed-global"; +import { ScriptMonaco } from "./monaco"; +import { ScriptWorkbench } from "./workbench"; + +export const EdPopScript = () => { + const p = useGlobal(EDGlobal, "EDITOR"); + return ( + <> + { + if (!open) { + p.ui.popup.script.open = false; + p.render(); + } + }} + > +
+
+ {(!jscript.editor || !jscript.build) && ( + <> + {!jscript.editor && !jscript.build && ( + + )} + {!jscript.editor && jscript.build && ( + + )} + {!jscript.build && jscript.editor && ( + + )} + + )} + + {jscript.editor && jscript.build && } +
+
+
+ + ); +}; diff --git a/app/web/src/nova/ed/panel/popup/script/workbench.tsx b/app/web/src/nova/ed/panel/popup/script/workbench.tsx new file mode 100644 index 00000000..2a8d807d --- /dev/null +++ b/app/web/src/nova/ed/panel/popup/script/workbench.tsx @@ -0,0 +1,47 @@ +import { useGlobal } from "web-utils"; +import { ScriptMonaco } from "./monaco"; +import { EDGlobal } from "../../../logic/ed-global"; + +export const ScriptWorkbench = () => { + const p = useGlobal(EDGlobal, "EDITOR"); + return ( +
+
+
+ {[ + { type: "js", color: "#e9522c" }, + { type: "css", color: "#188228" }, + { type: "html", color: "#2c3e83" }, + ].map((e) => { + return ( +
{ + p.ui.popup.script.mode = e.type as any; + p.render(); + }} + > + {e.type} +
+ ); + })} +
+
+ +
+
+
+ ); +}; diff --git a/app/web/src/nova/ed/panel/tree/node/item/action.tsx b/app/web/src/nova/ed/panel/tree/node/item/action.tsx index f80d8bcb..1042646f 100644 --- a/app/web/src/nova/ed/panel/tree/node/item/action.tsx +++ b/app/web/src/nova/ed/panel/tree/node/item/action.tsx @@ -1,5 +1,6 @@ import { NodeModel, RenderParams } from "@minoru/react-dnd-treeview"; -import { EdMeta } from "../../../../logic/ed-global"; +import { EDGlobal, EdMeta } from "../../../../logic/ed-global"; +import { useGlobal } from "web-utils"; export const EdTreeAction = ({ node, @@ -8,5 +9,40 @@ export const EdTreeAction = ({ node: NodeModel; prm: RenderParams; }) => { - return <>; + const p = useGlobal(EDGlobal, "EDITOR"); + const item = node.data?.item; + if (!item) return null; + return ( +
+
{ + p.ui.popup.script.open = true; + p.render(); + }} + > + {""} +
+
+ ); }; diff --git a/app/web/src/nova/ed/panel/tree/node/render.tsx b/app/web/src/nova/ed/panel/tree/node/render.tsx index 77316f87..625325fc 100644 --- a/app/web/src/nova/ed/panel/tree/node/render.tsx +++ b/app/web/src/nova/ed/panel/tree/node/render.tsx @@ -39,6 +39,11 @@ export const nodeRender: NodeRender = (node, prm) => { display: flex; } } + &:hover { + .action-script { + opacity: 0.6; + } + } `, active.item_id === item.id ? ["bg-blue-100"]