From bae5dddb60d13d63caf983ee6b961add9e2c1053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Sat, 15 Jul 2023 13:20:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(monaco-editor):=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=BE=A7=E8=BE=B9=E6=A0=8F=E7=BC=96=E8=BE=91=E5=99=A8=20|=20Im?= =?UTF-8?q?plement=20sidebar=20editor.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- editor/index.html => iframes/editor.html | 0 package.json | 18 +- public/README.md | 0 public/README_zh_CN.md | 0 public/i18n/en_US.json | 21 +- public/i18n/zh_CHT.json | 21 +- public/i18n/zh_CN.json | 21 +- public/icon.png | Bin 0 -> 4711 bytes public/plugin.json | 39 ++++ src/components/Dock.svelte | 74 +++++++ src/components/Editor.svelte | 220 +++++++++++++++++-- src/configs/default.ts | 64 ++++++ src/constants.ts | 20 ++ src/editor/index.ts | 127 +++++++++++ src/handlers/block.ts | 18 ++ src/index.ts | 263 +++++++++++++++++++++++ src/main.ts | 81 ++++--- src/types/config.d.ts | 49 +++++ src/types/editor.d.ts | 32 +++ tsconfig.json | 17 +- tsconfig.node.json | 17 +- vite.config.ts | 92 ++------ vite.iframes.config.ts | 32 +++ vite.plugin.config.ts | 73 +++++++ vite.share.config.ts | 79 +++++++ 25 files changed, 1225 insertions(+), 153 deletions(-) rename editor/index.html => iframes/editor.html (100%) create mode 100644 public/README.md create mode 100644 public/README_zh_CN.md create mode 100644 public/icon.png create mode 100644 src/components/Dock.svelte create mode 100644 src/configs/default.ts create mode 100644 src/constants.ts create mode 100644 src/editor/index.ts create mode 100644 src/handlers/block.ts create mode 100644 src/types/config.d.ts create mode 100644 src/types/editor.d.ts create mode 100644 vite.iframes.config.ts create mode 100644 vite.plugin.config.ts create mode 100644 vite.share.config.ts diff --git a/editor/index.html b/iframes/editor.html similarity index 100% rename from editor/index.html rename to iframes/editor.html diff --git a/package.json b/package.json index 2c95b22..756961c 100644 --- a/package.json +++ b/package.json @@ -5,29 +5,31 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build", + "build": "npm run build:plugin && npm run build:iframes", + "build:plugin": "vite build --mode plugin", + "build:iframes": "vite build --mode iframes", "preview": "vite preview", "check": "svelte-check --tsconfig ./tsconfig.json" }, "devDependencies": { + "@monaco-editor/loader": "^1.3.3", "@sveltejs/vite-plugin-svelte": "^2.4.2", "@tsconfig/svelte": "^4.0.1", - "@types/node": "^20.4.1", + "@types/node": "^20.4.2", + "deepmerge": "^4.3.1", "less": "^4.1.3", + "monaco-editor": "^0.40.0", "svelte": "^3.59.2", - "svelte-check": "^3.4.5", + "svelte-check": "^3.4.6", "svelte-preprocess-less": "^0.4.0", "tslib": "^2.6.0", "typescript": "^5.1.6", - "vite": "^4.4.2", - "vite-plugin-monaco-editor": "^1.1.0", + "vite": "^4.4.4", "vite-plugin-static-copy": "^0.16.0" }, "dependencies": { - "@monaco-editor/loader": "^1.3.3", "@workspace/components": "workspace:^", "@workspace/types": "workspace:^", - "@workspace/utils": "workspace:^", - "monaco-editor": "^0.40.0" + "@workspace/utils": "workspace:^" } } diff --git a/public/README.md b/public/README.md new file mode 100644 index 0000000..e69de29 diff --git a/public/README_zh_CN.md b/public/README_zh_CN.md new file mode 100644 index 0000000..e69de29 diff --git a/public/i18n/en_US.json b/public/i18n/en_US.json index 6e0d1a6..69ed0dc 100644 --- a/public/i18n/en_US.json +++ b/public/i18n/en_US.json @@ -1,3 +1,22 @@ { - "displayName": "Code Editor" + "displayName": "Code Editor", + "dock": { + "kramdown": { + "ariaLabel": "Edit kramdown" + }, + "title": "Code Edit" + }, + "editor": { + "action": { + "save": { + "label": "Save" + }, + "saveAs": { + "label": "Save As" + }, + "toggleWordWrap": { + "label": "Toggle Word Wrap" + } + } + } } diff --git a/public/i18n/zh_CHT.json b/public/i18n/zh_CHT.json index 50e318d..58a9d6a 100644 --- a/public/i18n/zh_CHT.json +++ b/public/i18n/zh_CHT.json @@ -1,3 +1,22 @@ { - "displayName": "代碼編輯器" + "displayName": "程式碼編輯器", + "dock": { + "kramdown": { + "ariaLabel": "編輯 kramdown" + }, + "title": "程式碼編輯" + }, + "editor": { + "action": { + "save": { + "label": "保存" + }, + "saveAs": { + "label": "另存為" + }, + "toggleWordWrap": { + "label": "切換自動換行" + } + } + } } diff --git a/public/i18n/zh_CN.json b/public/i18n/zh_CN.json index fcd8f06..6cdb14d 100644 --- a/public/i18n/zh_CN.json +++ b/public/i18n/zh_CN.json @@ -1,3 +1,22 @@ { - "displayName": "代码编辑器" + "displayName": "代码编辑器", + "dock": { + "kramdown": { + "ariaLabel": "编辑 kramdown" + }, + "title": "代码编辑" + }, + "editor": { + "action": { + "save": { + "label": "保存" + }, + "saveAs": { + "label": "另存为" + }, + "toggleWordWrap": { + "label": "切换自动换行" + } + } + } } diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fbc5e13b3ec0139bff326cd31bc3e36fac6f151c GIT binary patch literal 4711 zcmZWtcQ_l|_m34psL>*nY6-0nHCrmLT{Ws|)Qml9Q09bV%Xc}GctiJ>TUX02# zek&J@-d|nE1a#5DKu+-&b0*&h7XAPLT=*~11Q)A3zgUC>Xqg8X`?v%I**|jz1O)}b z-Ml^g9qoOc;Xcn?-)t-M0RSA|bTrjWg7dc)LW51#3K(~&)O;P<77lo{)(@jtRI&)f zTURDGSKr}R_pqgu+Lm$a^H$R*$SwCP^zOSHVVbWTnl@vmPpVs^jQT2G>F11oi&ppM zD(9KP;Y?xl8W@pu#m+OjUL*KWey;yIBE9XcimWX47?JMdGIm^WhsyFGO+@Gab~(P+ z6xt8zEoMRbXs2hKczxO+4u8G1;Ur7;TFTrFXpHmqC0oI(OADbCow7zfx6yARx^F^G zd#PL#znRX;$FplnUOtw;uL~Tx!OV;r(->~PBmG4&e8)B81>BST2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=hc%88O3BVA8pEMVoA8>HCh?W`v!_9TyVD3$kkj+DMj8(FDIOsD8~X8gP` z`s5O!=sof`glOKT_m-XWqqai{{l=tKA$ZzN7f)OK;$KVA7s2>Py=#gP ziGq~xlZ+R!m|G`MzsTVkQLXvhvC zGC(}CauC<>#Mf8H?pzUbG?kOe?3VfB8L@gTXK2%ZLzwW+ZP>Y^b+R*Qz3(E+xrfn< zPz{irSPhx3XXr33Z+$PI1{|TU3x61@W6Di?^dLYogdLk553jL&ZG-)uol6~%$pUBT zxR}X@IpH(Z0g@NbBuI$fc-sb>!%3s)QMMmh(9TQ>9XQypaay4oFzQ`0|{7fh@wD*J_?kE zc;@!1FacDNnx`4)NnF9mWNfvdWDN8{O6PI$I$F^S)o(=uZuxb>VI|J?!GPa;kPVOu zjRgwM*M`jN=w%L&$`&*S#q(JFdCE|GVnES?ZADXjM7&w&iBDMonaco Editor to view and edit code.", + "zh_CN": "使用 Monaco Editor 查看与编辑代码。", + "zh_CHT": "使用 Monaco Editor 檢視與編輯程式碼。" + }, + "readme": { + "default": "README.md", + "zh_CN": "README_zh_CN.md", + "zh_CHT": "README_zh_CN.md" + }, + "funding": { + "openCollective": "", + "patreon": "", + "github": "", + "custom": [ + "https://afdian.net/a/zuoqiu", + "https://ko-fi.com/zuoqiu" + ] + } +} diff --git a/src/components/Dock.svelte b/src/components/Dock.svelte new file mode 100644 index 0000000..eb96d7e --- /dev/null +++ b/src/components/Dock.svelte @@ -0,0 +1,74 @@ + + + + + + diff --git a/src/components/Editor.svelte b/src/components/Editor.svelte index 2d10d85..2e9709a 100644 --- a/src/components/Editor.svelte +++ b/src/components/Editor.svelte @@ -16,33 +16,114 @@ --> @@ -69,7 +242,8 @@